5 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
9 #ifndef __OPENTYPELAYOUTENGINE_H
10 #define __OPENTYPELAYOUTENGINE_H
13 #include "LEGlyphFilter.h"
14 #include "LEFontInstance.h"
15 #include "LayoutEngine.h"
17 #include "GlyphSubstitutionTables.h"
18 #include "GlyphDefinitionTables.h"
19 #include "GlyphPositioningTables.h"
24 * OpenTypeLayoutEngine implements complex text layout for OpenType fonts - that is
25 * fonts which have GSUB and GPOS tables associated with them. In order to do this,
26 * the glyph processsing step described for LayoutEngine is further broken into three
29 * 1) Character processing - this step analyses the characters and assigns a list of OpenType
30 * feature tags to each one. It may also change, remove or add characters, and change
33 * 2) Glyph processing - This step performs character to glyph mapping,and uses the GSUB
34 * table associated with the font to perform glyph substitutions, such as ligature substitution.
36 * 3) Glyph post processing - in cases where the font doesn't directly contain a GSUB table,
37 * the previous two steps may have generated "fake" glyph indices to use with a "canned" GSUB
38 * table. This step turns those glyph indices into actual font-specific glyph indices, and may
39 * perform any other adjustments requried by the previous steps.
41 * OpenTypeLayoutEngine will also use the font's GPOS table to apply position adjustments
42 * such as kerning and accent positioning.
48 class OpenTypeLayoutEngine
: public LayoutEngine
52 * This is the main constructor. It constructs an instance of OpenTypeLayoutEngine for
53 * a particular font, script and language. It takes the GSUB table as a parameter since
54 * LayoutEngine::layoutEngineFactory has to read the GSUB table to know that it has an
57 * @param fontInstance - the font
58 * @param scriptCode - the script
59 * @param langaugeCode - the language
60 * @param gsubTable - the GSUB table
62 * @see LayoutEngine::layoutEngineFactory
63 * @see ScriptAndLangaugeTags.h for script and language codes
67 OpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
,
68 const GlyphSubstitutionTableHeader
*gsubTable
);
71 * This constructor is used when the font requires a "canned" GSUB table which can't be known
72 * until after this constructor has been invoked.
74 * @param fontInstance - the font
75 * @param scriptCode - the script
76 * @param langaugeCode - the language
80 OpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
);
83 * The destructor, virtual for correct polymorphic invocation.
87 virtual ~OpenTypeLayoutEngine();
90 * A convenience method used to convert the script code into
91 * the four byte script tag required by OpenType.
93 * @param scriptCode - the script code
95 * @return the four byte script tag
99 static LETag
getScriptTag(le_int32 scriptCode
);
102 * A convenience method used to convert the langauge code into
103 * the four byte langauge tag required by OpenType.
105 * @param languageCode - the language code
107 * @return the four byte language tag
111 static LETag
getLangSysTag(le_int32 languageCode
);
114 * ICU "poor man's RTTI", returns a UClassID for the actual class.
118 virtual UClassID
getDynamicClassID() const;
121 * ICU "poor man's RTTI", returns a UClassID for this class.
125 static UClassID
getStaticClassID();
130 * This method is used by the constructors to convert the script
131 * and language codes to four byte tags and save them.
133 void setScriptAndLanguageTags();
136 * The array of script tags, indexed by script code.
138 static const LETag scriptTags
[];
141 * The array of language tags, indexed by language code.
143 static const LETag languageTags
[];
147 * A list of "default" features. The default characterProcessing method
148 * will apply all of these tags to every glyph.
152 const LETag
*fFeatureList
;
155 * A list of tags in the order in which the features in
156 * the font should be applied, as opposed to using the
157 * order of the lookups in the font.
161 const LETag
*fFeatureOrder
;
164 * The address of the GSUB table.
168 const GlyphSubstitutionTableHeader
*fGSUBTable
;
171 * The address of the GDEF table.
175 const GlyphDefinitionTableHeader
*fGDEFTable
;
178 * The address of the GPOS table.
182 const GlyphPositioningTableHeader
*fGPOSTable
;
185 * An optional filter used to inhibit substitutions
186 * preformed by the GSUB table. This is used for some
187 * "canned" GSUB tables to restrict substitutions to
188 * glyphs that are in the font.
192 LEGlyphFilter
*fSubstitutionFilter
;
195 * The four byte script tag.
202 * The four byte language tag
209 * This method does the OpenType character processing. It assigns the OpenType feature
210 * tags to the characters, and may generate output characters that differ from the input
211 * charcters due to insertions, deletions, or reorderings. In such cases, it will also
212 * generate an output character index array reflecting these changes.
214 * Subclasses must override this method.
217 * @param chars - the input character context
218 * @param offset - the index of the first character to process
219 * @param count - the number of characters to process
220 * @param max - the number of characters in the input context
221 * @param rightToLeft - TRUE if the characters are in a right to left directional run
224 * @param outChars - the output character array, if different from the input
225 * @param charIndices - the output character index array
226 * @param featureTags - the output feature tag array
227 * @param success - set to an error code if the operation fails
229 * @return the output character count (input character count if no change)
233 virtual le_int32
characterProcessing(const LEUnicode
/*chars*/[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool
/*rightToLeft*/,
234 LEUnicode
*&/*outChars*/, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
237 * This method does character to glyph mapping, and applies the GSUB table. The
238 * default implementation calls mapCharsToGlyphs and then applies the GSUB table,
241 * Note that in the case of "canned" GSUB tables, the output glyph indices may be
242 * "fake" glyph indices that need to be converted to "real" glyph indices by the
243 * glyphPostProcessing method.
246 * @param chars - the input character context
247 * @param offset - the index of the first character to process
248 * @param count - the number of characters to process
249 * @param max - the number of characters in the input context
250 * @param rightToLeft - TRUE if the characters are in a right to left directional run
251 * @param featureTags - the feature tag array
254 * @param glyphs - the output glyph index array
255 * @param charIndices - the output character index array
256 * @param success - set to an error code if the operation fails
258 * @return the number of glyphs in the output glyph index array
260 * Note: if the character index array was already set by the characterProcessing
261 * method, this method won't change it.
265 virtual le_int32
glyphProcessing(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
,
266 LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
269 * This method does any processing necessary to convert "fake"
270 * glyph indices used by the glyphProcessing method into "real" glyph
271 * indices which can be used to render the text. Note that in some
272 * cases, such as CDAC Indic fonts, several "real" glyphs may be needed
273 * to render one "fake" glyph.
275 * The default implementation of this method just returns the input glyph
276 * index and character index arrays, assuming that no "fake" glyph indices
277 * were needed to do GSUB processing.
280 * @param tempGlyphs - the input "fake" glyph index array
281 * @param tempCharIndices - the input "fake" character index array
282 * @param tempGlyphCount - the number of "fake" glyph indices
285 * @param glyphs - the output glyph index array
286 * @param charIndices - the output character index array
287 * @param success - set to an error code if the operation fails
289 * @return the number of glyph indices in the output glyph index array
293 virtual le_int32
glyphPostProcessing(LEGlyphStorage
&tempGlyphStorage
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
296 * This method applies the characterProcessing, glyphProcessing and glyphPostProcessing
297 * methods. Most subclasses will not need to override this method.
300 * @param chars - the input character context
301 * @param offset - the index of the first character to process
302 * @param count - the number of characters to process
303 * @param max - the number of characters in the input context
304 * @param rightToLeft - TRUE if the text is in a right to left directional run
307 * @param glyphs - the glyph index array
308 * @param charIndices - the character index array
309 * @param success - set to an error code if the operation fails
311 * @return the number of glyphs in the glyph index array
313 * @see LayoutEngine::computeGlyphs
317 virtual le_int32
computeGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
320 * This method uses the GPOS table, if there is one, to adjust the glyph positions.
323 * @param glyphs - the input glyph array
324 * @param glyphCount - the number of glyphs in the glyph array
325 * @param x - the starting X position
326 * @param y - the starting Y position
329 * @param positions - the output X and Y positions (two entries per glyph)
330 * @param success - set to an error code if the operation fails
334 virtual void adjustGlyphPositions(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_bool reverse
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
337 * This method frees the feature tag array so that the
338 * OpenTypeLayoutEngine can be reused for different text.
339 * It is also called from our destructor.
343 virtual void reset();