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