4 * © 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html#License
7 * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
11 #ifndef __SCRIPTCOMPOSITEFONTINSTANCE_H
12 #define __SCRIPTCOMPOSITEFONTINSTANCE_H
14 #include "layout/LETypes.h"
15 #include "layout/LEFontInstance.h"
21 class ScriptCompositeFontInstance
: public LEFontInstance
25 ScriptCompositeFontInstance(FontMap
*fontMap
);
27 virtual ~ScriptCompositeFontInstance();
30 * Get a physical font which can render the given text. For composite fonts,
31 * if there is no single physical font which can render all of the text,
32 * return a physical font which can render an initial substring of the text,
33 * and set the <code>offset</code> parameter to the end of that substring.
35 * Internally, the LayoutEngine works with runs of text all in the same
36 * font and script, so it is best to call this method with text which is
37 * in a single script, passing the script code in as a hint. If you don't
38 * know the script of the text, you can use zero, which is the script code
39 * for characters used in more than one script.
41 * The default implementation of this method is intended for instances of
42 * <code>LEFontInstance</code> which represent a physical font. It returns
43 * <code>this</code> and indicates that the entire string can be rendered.
45 * This method will return a valid <code>LEFontInstance</code> unless you
46 * have passed illegal parameters, or an internal error has been encountered.
47 * For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>
48 * to indicate that the returned font may not be able to render all of
49 * the text. Whenever a valid font is returned, the <code>offset</code> parameter
50 * will be advanced by at least one.
52 * Subclasses which implement composite fonts must override this method.
53 * Where it makes sense, they should use the script code as a hint to render
54 * characters from the COMMON script in the font which is used for the given
55 * script. For example, if the input text is a series of Arabic words separated
56 * by spaces, and the script code passed in is <code>arabScriptCode</code> you
57 * should return the font used for Arabic characters for all of the input text,
58 * including the spaces. If, on the other hand, the input text contains characters
59 * which cannot be rendered by the font used for Arabic characters, but which can
60 * be rendered by another font, you should return that font for those characters.
62 * @param chars - the array of Unicode characters.
63 * @param offset - a pointer to the starting offset in the text. On exit this
64 * will be set the the limit offset of the text which can be
65 * rendered using the returned font.
66 * @param limit - the limit offset for the input text.
67 * @param script - the script hint.
68 * @param success - set to an error code if the arguments are illegal, or no font
69 * can be returned for some reason. May also be set to
70 * <code>LE_NO_SUBFONT_WARNING</code> if the subfont which
71 * was returned cannot render all of the text.
73 * @return an <code>LEFontInstance</code> for the sub font which can render the characters, or
74 * <code>NULL</code> if there is an error.
78 virtual const LEFontInstance
*getSubFont(const LEUnicode chars
[], le_int32
*offset
, le_int32 limit
, le_int32 script
, LEErrorCode
&success
) const;
81 * This method maps a single character to a glyph index, using the
82 * font's charcter to glyph map.
84 * @param ch - the character
86 * @return the glyph index
88 virtual LEGlyphID
mapCharToGlyph(LEUnicode32 ch
) const;
90 virtual const void *getFontTable(LETag tableTag
) const;
92 virtual le_int32
getUnitsPerEM() const;
94 virtual le_int32
getAscent() const;
96 virtual le_int32
getDescent() const;
98 virtual le_int32
getLeading() const;
100 virtual void getGlyphAdvance(LEGlyphID glyph
, LEPoint
&advance
) const;
102 virtual le_bool
getGlyphPoint(LEGlyphID glyph
, le_int32 pointNumber
, LEPoint
&point
) const;
104 float getXPixelsPerEm() const;
106 float getYPixelsPerEm() const;
108 float getScaleFactorX() const;
110 float getScaleFactorY() const;
113 * ICU "poor man's RTTI", returns a UClassID for the actual class.
115 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
118 * ICU "poor man's RTTI", returns a UClassID for this class.
120 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
128 * The address of this static class variable serves as this class's ID
129 * for ICU "poor man's RTTI".
131 static const char fgClassID
;
134 inline const void *ScriptCompositeFontInstance::getFontTable(LETag
/*tableTag*/) const
139 // Can't get units per EM without knowing which sub-font, so
140 // return a value that will make units == points
141 inline le_int32
ScriptCompositeFontInstance::getUnitsPerEM() const
146 inline le_int32
ScriptCompositeFontInstance::getAscent() const
148 return fFontMap
->getAscent();
151 inline le_int32
ScriptCompositeFontInstance::getDescent() const
153 return fFontMap
->getDescent();
156 inline le_int32
ScriptCompositeFontInstance::getLeading() const
158 return fFontMap
->getLeading();
161 inline float ScriptCompositeFontInstance::getXPixelsPerEm() const
163 return fFontMap
->getPointSize();
166 inline float ScriptCompositeFontInstance::getYPixelsPerEm() const
168 return fFontMap
->getPointSize();
171 // Can't get a scale factor without knowing the sub-font, so
173 inline float ScriptCompositeFontInstance::getScaleFactorX() const
178 // Can't get a scale factor without knowing the sub-font, so
180 inline float ScriptCompositeFontInstance::getScaleFactorY() const