2 * (C) Copyright IBM Corp. and others 1998-2014 - All Rights Reserved
5 #ifndef __LAYOUTENGINE_H
6 #define __LAYOUTENGINE_H
12 * \brief C++ API: DEPRECATED: Virtual base class for complex text layout.
22 * NOTE: This class is deprecated, please instead use HarfBuzz.
23 * See: http://www.freedesktop.org/wiki/Software/HarfBuzz/
24 * and http://userguide.icu-project.org/layoutengine
26 * This is a virtual base class used to do complex text layout. The text must all
27 * be in a single font, script, and language. An instance of a LayoutEngine can be
28 * created by calling the layoutEngineFactory method. Fonts are identified by
29 * instances of the LEFontInstance class. Script and language codes are identified
30 * by integer codes, which are defined in ScriptAndLanuageTags.h.
32 * Note that this class is not public API. It is declared public so that it can be
33 * exported from the library that it is a part of.
35 * The input to the layout process is an array of characters in logical order,
36 * and a starting X, Y position for the text. The output is an array of glyph indices,
37 * an array of character indices for the glyphs, and an array of glyph positions.
38 * These arrays are protected members of LayoutEngine which can be retreived by a
39 * public method. The reset method can be called to free these arrays so that the
40 * LayoutEngine can be reused.
42 * The layout process is done in three steps. There is a protected virtual method
43 * for each step. These methods have a default implementation which only does
44 * character to glyph mapping and default positioning using the glyph's advance
45 * widths. Subclasses can override these methods for more advanced layout.
46 * There is a public method which invokes the steps in the correct order.
50 * 1) Glyph processing - character to glyph mapping and any other glyph processing
51 * such as ligature substitution and contextual forms.
53 * 2) Glyph positioning - position the glyphs based on their advance widths.
55 * 3) Glyph position adjustments - adjustment of glyph positions for kerning,
56 * accent placement, etc.
58 * NOTE: in all methods below, output parameters are references to pointers so
59 * the method can allocate and free the storage as needed. All storage allocated
60 * in this way is owned by the object which created it, and will be freed when it
61 * is no longer needed, or when the object's destructor is invoked.
64 * @see ScriptAndLanguageTags.h
66 * @deprecated ICU 54. See {@link icu::LayoutEngine}
67 * Instead, please use HarfBuzz.
68 * see http://www.freedesktop.org/wiki/Software/HarfBuzz/
69 * and http://userguide.icu-project.org/layoutengine
71 class U_LAYOUT_API LayoutEngine
: public UObject
{
73 #ifndef U_HIDE_INTERNAL_API
74 /** @internal Flag to request kerning. Use LE_Kerning_FEATURE_FLAG instead. */
75 static const le_int32 kTypoFlagKern
;
76 /** @internal Flag to request ligatures. Use LE_Ligatures_FEATURE_FLAG instead. */
77 static const le_int32 kTypoFlagLiga
;
78 #endif /* U_HIDE_INTERNAL_API */
82 * The object which holds the glyph storage
86 LEGlyphStorage
*fGlyphStorage
;
89 * The font instance for the text font.
95 const LEFontInstance
*fFontInstance
;
98 * The script code for the text
100 * @see ScriptAndLanguageTags.h for script codes.
104 le_int32 fScriptCode
;
107 * The langauge code for the text
109 * @see ScriptAndLanguageTags.h for language codes.
113 le_int32 fLanguageCode
;
116 * The typographic control flags
123 * <code>TRUE</code> if <code>mapCharsToGlyphs</code> should replace ZWJ / ZWNJ with a glyph
128 le_bool fFilterZeroWidth
;
130 #ifndef U_HIDE_INTERNAL_API
132 * This constructs an instance for a given font, script and language. Subclass constructors
133 * must call this constructor.
135 * @param fontInstance - the font for the text
136 * @param scriptCode - the script for the text
137 * @param languageCode - the language for the text
138 * @param typoFlags - the typographic control flags for the text (a bitfield). Use kTypoFlagKern
139 * if kerning is desired, kTypoFlagLiga if ligature formation is desired. Others are reserved.
140 * @param success - set to an error code if the operation fails
142 * @see LEFontInstance
143 * @see ScriptAndLanguageTags.h
147 LayoutEngine(const LEFontInstance
*fontInstance
,
149 le_int32 languageCode
,
151 LEErrorCode
&success
);
152 #endif /* U_HIDE_INTERNAL_API */
154 // Do not enclose the protected default constructor with #ifndef U_HIDE_INTERNAL_API
155 // or else the compiler will create a public default constructor.
157 * This overrides the default no argument constructor to make it
158 * difficult for clients to call it. Clients are expected to call
159 * layoutEngineFactory.
166 * This method does any required pre-processing to the input characters. It
167 * may generate output characters that differ from the input charcters due to
168 * insertions, deletions, or reorderings. In such cases, it will also generate an
169 * output character index array reflecting these changes.
171 * Subclasses must override this method.
174 * @param chars - the input character context
175 * @param offset - the index of the first character to process
176 * @param count - the number of characters to process
177 * @param max - the number of characters in the input context
178 * @param rightToLeft - TRUE if the characters are in a right to left directional run
179 * @param outChars - the output character array, if different from the input
180 * @param glyphStorage - the object that holds the per-glyph storage. The character index array may be set.
181 * @param success - set to an error code if the operation fails
183 * @return the output character count (input character count if no change)
187 virtual le_int32
characterProcessing(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
,
188 LEUnicode
*&outChars
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
191 * This method does the glyph processing. It converts an array of characters
192 * into an array of glyph indices and character indices. The characters to be
193 * processed are passed in a surrounding context. The context is specified as
194 * a starting address and a maximum character count. An offset and a count are
195 * used to specify the characters to be processed.
197 * The default implementation of this method only does character to glyph mapping.
198 * Subclasses needing more elaborate glyph processing must override this method.
201 * @param chars - the character context
202 * @param offset - the offset of the first character to process
203 * @param count - the number of characters to process
204 * @param max - the number of characters in the context.
205 * @param rightToLeft - TRUE if the text is in a right to left directional run
206 * @param glyphStorage - the object which holds the per-glyph storage. The glyph and char indices arrays
210 * @param success - set to an error code if the operation fails
212 * @return the number of glyphs in the glyph index array
216 virtual le_int32
computeGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
219 * This method does basic glyph positioning. The default implementation positions
220 * the glyphs based on their advance widths. This is sufficient for most uses. It
221 * is not expected that many subclasses will override this method.
224 * @param glyphStorage - the object which holds the per-glyph storage. The glyph position array will be set.
225 * @param x - the starting X position
226 * @param y - the starting Y position
227 * @param success - set to an error code if the operation fails
231 virtual void positionGlyphs(LEGlyphStorage
&glyphStorage
, float x
, float y
, LEErrorCode
&success
);
234 * This method does positioning adjustments like accent positioning and
235 * kerning. The default implementation does nothing. Subclasses needing
236 * position adjustments must override this method.
238 * Note that this method has both characters and glyphs as input so that
239 * it can use the character codes to determine glyph types if that information
240 * isn't directly available. (e.g. Some Arabic OpenType fonts don't have a GDEF
243 * @param chars - the input character context
244 * @param offset - the offset of the first character to process
245 * @param count - the number of characters to process
246 * @param reverse - <code>TRUE</code> if the glyphs in the glyph array have been reordered
247 * @param glyphStorage - the object which holds the per-glyph storage. The glyph positions will be
248 * adjusted as needed.
249 * @param success - output parameter set to an error code if the operation fails
253 virtual void adjustGlyphPositions(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_bool reverse
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
256 * This method gets a table from the font associated with
257 * the text. The default implementation gets the table from
258 * the font instance. Subclasses which need to get the tables
259 * some other way must override this method.
261 * @param tableTag - the four byte table tag.
262 * @param length - length to use
264 * @return the address of the table.
268 virtual const void *getFontTable(LETag tableTag
, size_t &length
) const;
271 * @deprecated ICU 54. See {@link icu::LayoutEngine}
273 virtual const void *getFontTable(LETag tableTag
) const { size_t ignored
; return getFontTable(tableTag
, ignored
); }
276 * This method does character to glyph mapping. The default implementation
277 * uses the font instance to do the mapping. It will allocate the glyph and
278 * character index arrays if they're not already allocated. If it allocates the
279 * character index array, it will fill it it.
281 * This method supports right to left
282 * text with the ability to store the glyphs in reverse order, and by supporting
283 * character mirroring, which will replace a character which has a left and right
284 * form, such as parens, with the opposite form before mapping it to a glyph index.
287 * @param chars - the input character context
288 * @param offset - the offset of the first character to be mapped
289 * @param count - the number of characters to be mapped
290 * @param reverse - if <code>TRUE</code>, the output will be in reverse order
291 * @param mirror - if <code>TRUE</code>, do character mirroring
292 * @param glyphStorage - the object which holds the per-glyph storage. The glyph and char
293 * indices arrays will be filled in.
294 * @param success - set to an error code if the operation fails
296 * @see LEFontInstance
300 virtual void mapCharsToGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_bool reverse
, le_bool mirror
, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
);
302 #ifndef U_HIDE_INTERNAL_API
304 * This is a convenience method that forces the advance width of mark
305 * glyphs to be zero, which is required for proper selection and highlighting.
307 * @param glyphStorage - the object containing the per-glyph storage. The positions array will be modified.
308 * @param markFilter - used to identify mark glyphs
309 * @param success - output parameter set to an error code if the operation fails
315 static void adjustMarkGlyphs(LEGlyphStorage
&glyphStorage
, LEGlyphFilter
*markFilter
, LEErrorCode
&success
);
319 * This is a convenience method that forces the advance width of mark
320 * glyphs to be zero, which is required for proper selection and highlighting.
321 * This method uses the input characters to identify marks. This is required in
322 * cases where the font does not contain enough information to identify them based
325 * @param chars - the array of input characters
326 * @param charCount - the number of input characers
327 * @param glyphStorage - the object containing the per-glyph storage. The positions array will be modified.
328 * @param reverse - <code>TRUE</code> if the glyph array has been reordered
329 * @param markFilter - used to identify mark glyphs
330 * @param success - output parameter set to an error code if the operation fails
336 static void adjustMarkGlyphs(const LEUnicode chars
[], le_int32 charCount
, le_bool reverse
, LEGlyphStorage
&glyphStorage
, LEGlyphFilter
*markFilter
, LEErrorCode
&success
);
337 #endif /* U_HIDE_INTERNAL_API */
341 * The destructor. It will free any storage allocated for the
342 * glyph, character index and position arrays by calling the reset
343 * method. It is declared virtual so that it will be invoked by the
344 * subclass destructors.
346 * @deprecated ICU 54. See {@link icu::LayoutEngine}
348 virtual ~LayoutEngine();
351 * This method will invoke the layout steps in their correct order by calling
352 * the computeGlyphs, positionGlyphs and adjustGlyphPosition methods. It will
353 * compute the glyph, character index and position arrays.
355 * @param chars - the input character context
356 * @param offset - the offset of the first character to process
357 * @param count - the number of characters to process
358 * @param max - the number of characters in the input context
359 * @param rightToLeft - TRUE if the characers are in a right to left directional run
360 * @param x - the initial X position
361 * @param y - the initial Y position
362 * @param success - output parameter set to an error code if the operation fails
364 * @return the number of glyphs in the glyph array
366 * Note: The glyph, character index and position array can be accessed
367 * using the getter methods below.
369 * Note: If you call this method more than once, you must call the reset()
370 * method first to free the glyph, character index and position arrays
371 * allocated by the previous call.
373 * @deprecated ICU 54. See {@link icu::LayoutEngine}
375 virtual le_int32
layoutChars(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool rightToLeft
, float x
, float y
, LEErrorCode
&success
);
378 * This method returns the number of glyphs in the glyph array. Note
379 * that the number of glyphs will be greater than or equal to the number
380 * of characters used to create the LayoutEngine.
382 * @return the number of glyphs in the glyph array
384 * @deprecated ICU 54. See {@link icu::LayoutEngine}
386 le_int32
getGlyphCount() const;
389 * This method copies the glyph array into a caller supplied array.
390 * The caller must ensure that the array is large enough to hold all
393 * @param glyphs - the destiniation glyph array
394 * @param success - set to an error code if the operation fails
396 * @deprecated ICU 54. See {@link icu::LayoutEngine}
398 void getGlyphs(LEGlyphID glyphs
[], LEErrorCode
&success
) const;
401 * This method copies the glyph array into a caller supplied array,
402 * ORing in extra bits. (This functionality is needed by the JDK,
403 * which uses 32 bits pre glyph idex, with the high 16 bits encoding
404 * the composite font slot number)
406 * @param glyphs - the destination (32 bit) glyph array
407 * @param extraBits - this value will be ORed with each glyph index
408 * @param success - set to an error code if the operation fails
410 * @deprecated ICU 54. See {@link icu::LayoutEngine}
412 virtual void getGlyphs(le_uint32 glyphs
[], le_uint32 extraBits
, LEErrorCode
&success
) const;
415 * This method copies the character index array into a caller supplied array.
416 * The caller must ensure that the array is large enough to hold a
417 * character index for each glyph.
419 * @param charIndices - the destiniation character index array
420 * @param success - set to an error code if the operation fails
422 * @deprecated ICU 54. See {@link icu::LayoutEngine}
424 void getCharIndices(le_int32 charIndices
[], LEErrorCode
&success
) const;
427 * This method copies the character index array into a caller supplied array.
428 * The caller must ensure that the array is large enough to hold a
429 * character index for each glyph.
431 * @param charIndices - the destiniation character index array
432 * @param indexBase - an offset which will be added to each index
433 * @param success - set to an error code if the operation fails
435 * @deprecated ICU 54. See {@link icu::LayoutEngine}
437 void getCharIndices(le_int32 charIndices
[], le_int32 indexBase
, LEErrorCode
&success
) const;
440 * This method copies the position array into a caller supplied array.
441 * The caller must ensure that the array is large enough to hold an
442 * X and Y position for each glyph, plus an extra X and Y for the
443 * advance of the last glyph.
445 * @param positions - the destiniation position array
446 * @param success - set to an error code if the operation fails
448 * @deprecated ICU 54. See {@link icu::LayoutEngine}
450 void getGlyphPositions(float positions
[], LEErrorCode
&success
) const;
453 * This method returns the X and Y position of the glyph at
457 * @param glyphIndex - the index of the glyph
460 * @param x - the glyph's X position
461 * @param y - the glyph's Y position
462 * @param success - set to an error code if the operation fails
464 * @deprecated ICU 54. See {@link icu::LayoutEngine}
466 void getGlyphPosition(le_int32 glyphIndex
, float &x
, float &y
, LEErrorCode
&success
) const;
469 * This method frees the glyph, character index and position arrays
470 * so that the LayoutEngine can be reused to layout a different
471 * characer array. (This method is also called by the destructor)
473 * @deprecated ICU 54. See {@link icu::LayoutEngine}
475 virtual void reset();
478 * This method returns a LayoutEngine capable of laying out text
479 * in the given font, script and langauge. Note that the LayoutEngine
480 * returned may be a subclass of LayoutEngine.
482 * @param fontInstance - the font of the text
483 * @param scriptCode - the script of the text
484 * @param languageCode - the language of the text
485 * @param success - output parameter set to an error code if the operation fails
487 * @return a LayoutEngine which can layout text in the given font.
489 * @see LEFontInstance
491 * @deprecated ICU 54. See {@link icu::LayoutEngine}
493 static LayoutEngine
*layoutEngineFactory(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
, LEErrorCode
&success
);
496 * Override of existing call that provides flags to control typography.
497 * @deprecated ICU 54. See {@link icu::LayoutEngine}
499 static LayoutEngine
*layoutEngineFactory(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
, le_int32 typo_flags
, LEErrorCode
&success
);
502 * ICU "poor man's RTTI", returns a UClassID for the actual class.
504 * @deprecated ICU 54. See {@link icu::LayoutEngine}
506 virtual UClassID
getDynamicClassID() const;
509 * ICU "poor man's RTTI", returns a UClassID for this class.
511 * @deprecated ICU 54. See {@link icu::LayoutEngine}
513 static UClassID
getStaticClassID();