2 * (C) Copyright IBM Corp. 1998-2009 - All Rights Reserved
6 #ifndef __OPENTYPELAYOUTENGINE_H
7 #define __OPENTYPELAYOUTENGINE_H
10 #include "LEGlyphFilter.h"
11 #include "LEFontInstance.h"
12 #include "LayoutEngine.h"
14 #include "GlyphSubstitutionTables.h"
15 #include "GlyphDefinitionTables.h"
16 #include "GlyphPositioningTables.h"
21 * OpenTypeLayoutEngine implements complex text layout for OpenType fonts - that is
22 * fonts which have GSUB and GPOS tables associated with them. In order to do this,
23 * the glyph processsing step described for LayoutEngine is further broken into three
26 * 1) Character processing - this step analyses the characters and assigns a list of OpenType
27 * feature tags to each one. It may also change, remove or add characters, and change
30 * 2) Glyph processing - This step performs character to glyph mapping,and uses the GSUB
31 * table associated with the font to perform glyph substitutions, such as ligature substitution.
33 * 3) Glyph post processing - in cases where the font doesn't directly contain a GSUB table,
34 * the previous two steps may have generated "fake" glyph indices to use with a "canned" GSUB
35 * table. This step turns those glyph indices into actual font-specific glyph indices, and may
36 * perform any other adjustments requried by the previous steps.
38 * OpenTypeLayoutEngine will also use the font's GPOS table to apply position adjustments
39 * such as kerning and accent positioning.
45 class U_LAYOUT_API OpenTypeLayoutEngine
: public LayoutEngine
49 * This is the main constructor. It constructs an instance of OpenTypeLayoutEngine for
50 * a particular font, script and language. It takes the GSUB table as a parameter since
51 * LayoutEngine::layoutEngineFactory has to read the GSUB table to know that it has an
54 * @param fontInstance - the font
55 * @param scriptCode - the script
56 * @param langaugeCode - the language
57 * @param gsubTable - the GSUB table
58 * @param success - set to an error code if the operation fails
60 * @see LayoutEngine::layoutEngineFactory
61 * @see ScriptAndLangaugeTags.h for script and language codes
65 OpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
,
66 le_int32 typoFlags
, const GlyphSubstitutionTableHeader
*gsubTable
, LEErrorCode
&success
);
69 * This constructor is used when the font requires a "canned" GSUB table which can't be known
70 * until after this constructor has been invoked.
72 * @param fontInstance - the font
73 * @param scriptCode - the script
74 * @param langaugeCode - the language
75 * @param success - set to an error code if the operation fails
79 OpenTypeLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
,
80 le_int32 typoFlags
, LEErrorCode
&success
);
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.
92 * For Indic languages where multiple script tags exist,
93 * the version 1 (old style) tag is returned.
95 * @param scriptCode - the script code
97 * @return the four byte script tag
101 static LETag
getScriptTag(le_int32 scriptCode
);
103 * A convenience method used to convert the script code into
104 * the four byte script tag required by OpenType.
105 * For Indic languages where multiple script tags exist,
106 * the version 2 tag is returned.
108 * @param scriptCode - the script code
110 * @return the four byte script tag
114 static LETag
getV2ScriptTag(le_int32 scriptCode
);
117 * A convenience method used to convert the langauge code into
118 * the four byte langauge tag required by OpenType.
120 * @param languageCode - the language code
122 * @return the four byte language tag
126 static LETag
getLangSysTag(le_int32 languageCode
);
129 * ICU "poor man's RTTI", returns a UClassID for the actual class.
133 virtual UClassID
getDynamicClassID() const;
136 * ICU "poor man's RTTI", returns a UClassID for this class.
140 static UClassID
getStaticClassID();
143 * The array of language tags, indexed by language code.
147 static const LETag languageTags
[];
152 * This method is used by the constructors to convert the script
153 * and language codes to four byte tags and save them.
155 void setScriptAndLanguageTags();
158 * The array of script tags, indexed by script code.
160 static const LETag scriptTags
[];
164 * A set of "default" features. The default characterProcessing method
165 * will apply all of these features to every glyph.
169 FeatureMask fFeatureMask
;
172 * A set of mappings from feature tags to feature masks. These may
173 * be in the order in which the featues should be applied, but they
178 const FeatureMap
*fFeatureMap
;
181 * The length of the feature map.
185 le_int32 fFeatureMapCount
;
188 * <code>TRUE</code> if the features in the
189 * feature map are in the order in which they
194 le_bool fFeatureOrder
;
197 * The address of the GSUB table.
201 const GlyphSubstitutionTableHeader
*fGSUBTable
;
204 * The address of the GDEF table.
208 const GlyphDefinitionTableHeader
*fGDEFTable
;
211 * The address of the GPOS table.
215 const GlyphPositioningTableHeader
*fGPOSTable
;
218 * An optional filter used to inhibit substitutions
219 * preformed by the GSUB table. This is used for some
220 * "canned" GSUB tables to restrict substitutions to
221 * glyphs that are in the font.
225 LEGlyphFilter
*fSubstitutionFilter
;
228 * The four byte script tag.
235 * The four byte script tag for V2 fonts.
242 * The four byte language tag
249 * This method does the OpenType character processing. It assigns the OpenType feature
250 * tags to the characters, and may generate output characters that differ from the input
251 * charcters due to insertions, deletions, or reorderings. In such cases, it will also
252 * generate an output character index array reflecting these changes.
254 * Subclasses must override this method.
257 * @param chars - the input character context
258 * @param offset - the index of the first character to process
259 * @param count - the number of characters to process
260 * @param max - the number of characters in the input context
261 * @param rightToLeft - TRUE if the characters are in a right to left directional run
264 * @param outChars - the output character array, if different from the input
265 * @param charIndices - the output character index array
266 * @param featureTags - the output feature tag array
267 * @param success - set to an error code if the operation fails
269 * @return the output character count (input character count if no change)
273 virtual le_int32
characterProcessing(const LEUnicode
/*chars*/[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool
/*rightToLeft*/,
274 LEUnicode
*&/*outChars*/, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
277 * This method does character to glyph mapping, and applies the GSUB table. The
278 * default implementation calls mapCharsToGlyphs and then applies the GSUB table,
281 * Note that in the case of "canned" GSUB tables, the output glyph indices may be
282 * "fake" glyph indices that need to be converted to "real" glyph indices by the
283 * glyphPostProcessing method.
286 * @param chars - the input character context
287 * @param offset - the index of the first character to process
288 * @param count - the number of characters to process
289 * @param max - the number of characters in the input context
290 * @param rightToLeft - TRUE if the characters are in a right to left directional run
291 * @param featureTags - the feature tag array
294 * @param glyphs - the output glyph index array
295 * @param charIndices - the output character index array
296 * @param success - set to an error code if the operation fails
298 * @return the number of glyphs in the output glyph index array
300 * Note: if the character index array was already set by the characterProcessing
301 * method, this method won't change it.
305 virtual le_int32
glyphProcessing(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
,
306 LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
308 virtual le_int32
glyphSubstitution(le_int32 count
, le_int32 max
, le_bool rightToLeft
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
311 * This method does any processing necessary to convert "fake"
312 * glyph indices used by the glyphProcessing method into "real" glyph
313 * indices which can be used to render the text. Note that in some
314 * cases, such as CDAC Indic fonts, several "real" glyphs may be needed
315 * to render one "fake" glyph.
317 * The default implementation of this method just returns the input glyph
318 * index and character index arrays, assuming that no "fake" glyph indices
319 * were needed to do GSUB processing.
322 * @param tempGlyphs - the input "fake" glyph index array
323 * @param tempCharIndices - the input "fake" character index array
324 * @param tempGlyphCount - the number of "fake" glyph indices
327 * @param glyphs - the output glyph index array
328 * @param charIndices - the output character index array
329 * @param success - set to an error code if the operation fails
331 * @return the number of glyph indices in the output glyph index array
335 virtual le_int32
glyphPostProcessing(LEGlyphStorage
&tempGlyphStorage
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
338 * This method applies the characterProcessing, glyphProcessing and glyphPostProcessing
339 * methods. Most subclasses will not need to override this method.
342 * @param chars - the input character context
343 * @param offset - the index of the first character to process
344 * @param count - the number of characters to process
345 * @param max - the number of characters in the input context
346 * @param rightToLeft - TRUE if the text is in a right to left directional run
349 * @param glyphs - the glyph index array
350 * @param charIndices - the character index array
351 * @param success - set to an error code if the operation fails
353 * @return the number of glyphs in the glyph index array
355 * @see LayoutEngine::computeGlyphs
359 virtual le_int32
computeGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
362 * This method uses the GPOS table, if there is one, to adjust the glyph positions.
365 * @param glyphs - the input glyph array
366 * @param glyphCount - the number of glyphs in the glyph array
367 * @param x - the starting X position
368 * @param y - the starting Y position
371 * @param positions - the output X and Y positions (two entries per glyph)
372 * @param success - set to an error code if the operation fails
376 virtual void adjustGlyphPositions(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_bool reverse
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
379 * This method frees the feature tag array so that the
380 * OpenTypeLayoutEngine can be reused for different text.
381 * It is also called from our destructor.
385 virtual void reset();