• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * %W% %E%
3  *
4  * © 2016 and later: Unicode, Inc. and others.
5  * License & terms of use: http://www.unicode.org/copyright.html#License
6  *
7  * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
8  *
9  */
10 
11 #ifndef __SCRIPTCOMPOSITEFONTINSTANCE_H
12 #define __SCRIPTCOMPOSITEFONTINSTANCE_H
13 
14 #include "layout/LETypes.h"
15 #include "layout/LEFontInstance.h"
16 
17 #include "FontMap.h"
18 
19 // U_NAMESPACE_BEGIN
20 
21 class ScriptCompositeFontInstance : public LEFontInstance
22 {
23 public:
24 
25     ScriptCompositeFontInstance(FontMap *fontMap);
26 
27     virtual ~ScriptCompositeFontInstance();
28 
29       /**
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.
34      *
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.
40      *
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.
44      *
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.
51      *
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.
61      *
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.
72      *
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.
75      *
76      * @see LEScripts.h
77      */
78     virtual const LEFontInstance *getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const;
79 
80     /**
81      * This method maps a single character to a glyph index, using the
82      * font's charcter to glyph map.
83      *
84      * @param ch - the character
85      *
86      * @return the glyph index
87      */
88     virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
89 
90     virtual const void *getFontTable(LETag tableTag) const;
91 
92     virtual le_int32 getUnitsPerEM() const;
93 
94     virtual le_int32 getAscent() const;
95 
96     virtual le_int32 getDescent() const;
97 
98     virtual le_int32 getLeading() const;
99 
100     virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
101 
102     virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
103 
104     float getXPixelsPerEm() const;
105 
106     float getYPixelsPerEm() const;
107 
108     float getScaleFactorX() const;
109 
110     float getScaleFactorY() const;
111 
112     /**
113      * ICU "poor man's RTTI", returns a UClassID for the actual class.
114      */
getDynamicClassID()115     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
116 
117     /**
118      * ICU "poor man's RTTI", returns a UClassID for this class.
119      */
getStaticClassID()120     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
121 
122 protected:
123     FontMap *fFontMap;
124 
125 private:
126 
127     /**
128      * The address of this static class variable serves as this class's ID
129      * for ICU "poor man's RTTI".
130      */
131     static const char fgClassID;
132 };
133 
getFontTable(LETag)134 inline const void *ScriptCompositeFontInstance::getFontTable(LETag /*tableTag*/) const
135 {
136     return NULL;
137 }
138 
139 // Can't get units per EM without knowing which sub-font, so
140 // return a value that will make units == points
getUnitsPerEM()141 inline le_int32 ScriptCompositeFontInstance::getUnitsPerEM() const
142 {
143     return 1;
144 }
145 
getAscent()146 inline le_int32 ScriptCompositeFontInstance::getAscent() const
147 {
148     return fFontMap->getAscent();
149 }
150 
getDescent()151 inline le_int32 ScriptCompositeFontInstance::getDescent() const
152 {
153     return fFontMap->getDescent();
154 }
155 
getLeading()156 inline le_int32 ScriptCompositeFontInstance::getLeading() const
157 {
158     return fFontMap->getLeading();
159 }
160 
getXPixelsPerEm()161 inline float ScriptCompositeFontInstance::getXPixelsPerEm() const
162 {
163     return fFontMap->getPointSize();
164 }
165 
getYPixelsPerEm()166 inline float ScriptCompositeFontInstance::getYPixelsPerEm() const
167 {
168     return fFontMap->getPointSize();
169 }
170 
171 // Can't get a scale factor without knowing the sub-font, so
172 // return 1.0.
getScaleFactorX()173 inline float ScriptCompositeFontInstance::getScaleFactorX() const
174 {
175     return 1.0;
176 }
177 
178 // Can't get a scale factor without knowing the sub-font, so
179 // return 1.0
getScaleFactorY()180 inline float ScriptCompositeFontInstance::getScaleFactorY() const
181 {
182     return 1.0;
183 }
184 
185 // U_NAMESPACE_END
186 #endif
187