4 * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
8 #ifndef __SCRIPTCOMPOSITEFONTINSTANCE_H
9 #define __SCRIPTCOMPOSITEFONTINSTANCE_H
11 #include "layout/LETypes.h"
12 #include "layout/LEFontInstance.h"
18 class ScriptCompositeFontInstance
: public LEFontInstance
22 ScriptCompositeFontInstance(FontMap
*fontMap
);
24 virtual ~ScriptCompositeFontInstance();
27 * Get a physical font which can render the given text. For composite fonts,
28 * if there is no single physical font which can render all of the text,
29 * return a physical font which can render an initial substring of the text,
30 * and set the <code>offset</code> parameter to the end of that substring.
32 * Internally, the LayoutEngine works with runs of text all in the same
33 * font and script, so it is best to call this method with text which is
34 * in a single script, passing the script code in as a hint. If you don't
35 * know the script of the text, you can use zero, which is the script code
36 * for characters used in more than one script.
38 * The default implementation of this method is intended for instances of
39 * <code>LEFontInstance</code> which represent a physical font. It returns
40 * <code>this</code> and indicates that the entire string can be rendered.
42 * This method will return a valid <code>LEFontInstance</code> unless you
43 * have passed illegal parameters, or an internal error has been encountered.
44 * For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>
45 * to indicate that the returned font may not be able to render all of
46 * the text. Whenever a valid font is returned, the <code>offset</code> parameter
47 * will be advanced by at least one.
49 * Subclasses which implement composite fonts must override this method.
50 * Where it makes sense, they should use the script code as a hint to render
51 * characters from the COMMON script in the font which is used for the given
52 * script. For example, if the input text is a series of Arabic words separated
53 * by spaces, and the script code passed in is <code>arabScriptCode</code> you
54 * should return the font used for Arabic characters for all of the input text,
55 * including the spaces. If, on the other hand, the input text contains characters
56 * which cannot be rendered by the font used for Arabic characters, but which can
57 * be rendered by another font, you should return that font for those characters.
59 * @param chars - the array of Unicode characters.
60 * @param offset - a pointer to the starting offset in the text. On exit this
61 * will be set the the limit offset of the text which can be
62 * rendered using the returned font.
63 * @param limit - the limit offset for the input text.
64 * @param script - the script hint.
65 * @param success - set to an error code if the arguments are illegal, or no font
66 * can be returned for some reason. May also be set to
67 * <code>LE_NO_SUBFONT_WARNING</code> if the subfont which
68 * was returned cannot render all of the text.
70 * @return an <code>LEFontInstance</code> for the sub font which can render the characters, or
71 * <code>NULL</code> if there is an error.
75 virtual const LEFontInstance
*getSubFont(const LEUnicode chars
[], le_int32
*offset
, le_int32 limit
, le_int32 script
, LEErrorCode
&success
) const;
78 * This method maps a single character to a glyph index, using the
79 * font's charcter to glyph map.
81 * @param ch - the character
83 * @return the glyph index
85 virtual LEGlyphID
mapCharToGlyph(LEUnicode32 ch
) const;
87 virtual const void *getFontTable(LETag tableTag
) const;
89 virtual le_int32
getUnitsPerEM() const;
91 virtual le_int32
getAscent() const;
93 virtual le_int32
getDescent() const;
95 virtual le_int32
getLeading() const;
97 virtual void getGlyphAdvance(LEGlyphID glyph
, LEPoint
&advance
) const;
99 virtual le_bool
getGlyphPoint(LEGlyphID glyph
, le_int32 pointNumber
, LEPoint
&point
) const;
101 float getXPixelsPerEm() const;
103 float getYPixelsPerEm() const;
105 float getScaleFactorX() const;
107 float getScaleFactorY() const;
110 * ICU "poor man's RTTI", returns a UClassID for the actual class.
112 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
115 * ICU "poor man's RTTI", returns a UClassID for this class.
117 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
125 * The address of this static class variable serves as this class's ID
126 * for ICU "poor man's RTTI".
128 static const char fgClassID
;
131 inline const void *ScriptCompositeFontInstance::getFontTable(LETag
/*tableTag*/) const
136 // Can't get units per EM without knowing which sub-font, so
137 // return a value that will make units == points
138 inline le_int32
ScriptCompositeFontInstance::getUnitsPerEM() const
143 inline le_int32
ScriptCompositeFontInstance::getAscent() const
145 return fFontMap
->getAscent();
148 inline le_int32
ScriptCompositeFontInstance::getDescent() const
150 return fFontMap
->getDescent();
153 inline le_int32
ScriptCompositeFontInstance::getLeading() const
155 return fFontMap
->getLeading();
158 inline float ScriptCompositeFontInstance::getXPixelsPerEm() const
160 return fFontMap
->getPointSize();
163 inline float ScriptCompositeFontInstance::getYPixelsPerEm() const
165 return fFontMap
->getPointSize();
168 // Can't get a scale factor without knowing the sub-font, so
170 inline float ScriptCompositeFontInstance::getScaleFactorX() const
175 // Can't get a scale factor without knowing the sub-font, so
177 inline float ScriptCompositeFontInstance::getScaleFactorY() const