64
64
class U_LAYOUT_API LayoutEngine
68
* The number of glyphs in the output
68
* The number of glyphs in the output
70
70
le_int32 fGlyphCount;
73
* The output glyph array
73
* The output glyph array
75
75
LEGlyphID *fGlyphs;
78
* The character index array. One entry for each output glyph, giving the index
79
* in the input character array of the character which corresponds to this glyph.
78
* The character index array. One entry for each output glyph, giving the index
79
* in the input character array of the character which corresponds to this glyph.
81
81
le_int32 *fCharIndices;
84
* The glyph position array. There are two entries for each glyph giving the
85
* X and Y positions of the glyph. Thus, for glyph i, the X position is at index
86
* 2i, and the Y position is at index 2i + 1. There are also two entries for the
87
* X and Y position of the advance of the last glyph.
84
* The glyph position array. There are two entries for each glyph giving the
85
* X and Y positions of the glyph. Thus, for glyph i, the X position is at index
86
* 2i, and the Y position is at index 2i + 1. There are also two entries for the
87
* X and Y position of the advance of the last glyph.
92
* The font instance for the text font.
92
* The font instance for the text font.
96
96
const LEFontInstance *fFontInstance;
99
* The script code for the text
101
* @see ScriptAndLanguageTags.h for script codes.
99
* The script code for the text
101
* @see ScriptAndLanguageTags.h for script codes.
103
103
le_int32 fScriptCode;
106
* The langauge code for the text
108
* @see ScriptAndLanguageTags.h for language codes.
106
* The langauge code for the text
108
* @see ScriptAndLanguageTags.h for language codes.
110
110
le_int32 fLanguageCode;
113
* This constructs an instance for a given font, script and language. Subclass constructors
114
* must call this constructor.
116
* @param fontInstance - the font for the text
117
* @param scriptCode - the script for the text
118
* @param langaugeCode - the language for the text
120
* @see LEFontInstance
121
* @see ScriptAndLanguageTags.h
113
* This constructs an instance for a given font, script and language. Subclass constructors
114
* must call this constructor.
116
* @param fontInstance - the font for the text
117
* @param scriptCode - the script for the text
118
* @param langaugeCode - the language for the text
120
* @see LEFontInstance
121
* @see ScriptAndLanguageTags.h
123
123
LayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode);
126
* This overrides the default no argument constructor to make it
127
* difficult for clients to call it. Clients are expected to call
128
* layoutEngineFactory.
126
* This overrides the default no argument constructor to make it
127
* difficult for clients to call it. Clients are expected to call
128
* layoutEngineFactory.
133
* This method does the glyph processing. It converts an array of characters
134
* into an array of glyph indices and character indices. The characters to be
135
* processed are passed in a surrounding context. The context is specified as
136
* a starting address and a maximum character count. An offset and a count are
137
* used to specify the characters to be processed.
139
* The default implementation of this method only does character to glyph mapping.
140
* Subclasses needing more elaborate glyph processing must override this method.
143
* @param chars - the character context
144
* @param offset - the offset of the first character to process
145
* @param count - the number of characters to process
146
* @param max - the number of characters in the context.
147
* @param rightToLeft - true if the text is in a right to left directional run
150
* @param glyphs - the glyph index array
151
* @param charIndices - the character index array
152
* @param success - set to an error code if the operation fails
154
* @return the number of glyphs in the glyph index array
133
* This method does the glyph processing. It converts an array of characters
134
* into an array of glyph indices and character indices. The characters to be
135
* processed are passed in a surrounding context. The context is specified as
136
* a starting address and a maximum character count. An offset and a count are
137
* used to specify the characters to be processed.
139
* The default implementation of this method only does character to glyph mapping.
140
* Subclasses needing more elaborate glyph processing must override this method.
143
* @param chars - the character context
144
* @param offset - the offset of the first character to process
145
* @param count - the number of characters to process
146
* @param max - the number of characters in the context.
147
* @param rightToLeft - true if the text is in a right to left directional run
150
* @param glyphs - the glyph index array
151
* @param charIndices - the character index array
152
* @param success - set to an error code if the operation fails
154
* @return the number of glyphs in the glyph index array
156
156
virtual le_int32 computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, LEGlyphID *&glyphs, le_int32 *&charIndices, LEErrorCode &success);
159
* This method does basic glyph positioning. The default implementation positions
160
* the glyphs based on their advance widths. This is sufficient for most uses. It
161
* is not expected that many subclasses will override this method.
164
* @param glyphs - the input glyph array
165
* @param glyphCount - the number of glyphs in the glyph array
166
* @param x - the starting X position
167
* @param y - the starting Y position
170
* @param positions - the output X and Y positions (two entries per glyph)
159
* This method does basic glyph positioning. The default implementation positions
160
* the glyphs based on their advance widths. This is sufficient for most uses. It
161
* is not expected that many subclasses will override this method.
164
* @param glyphs - the input glyph array
165
* @param glyphCount - the number of glyphs in the glyph array
166
* @param x - the starting X position
167
* @param y - the starting Y position
170
* @param positions - the output X and Y positions (two entries per glyph)
172
172
virtual void positionGlyphs(const LEGlyphID glyphs[], le_int32 glyphCount, float x, float y, float *&positions, LEErrorCode &success);
175
* This method does positioning adjustments like accent positioning and
176
* kerning. The default implementation does nothing. Subclasses needing
177
* position adjustments must override this method.
179
* Note that this method has both characters and glyphs as input so that
180
* it can use the character codes to determine glyph types if that information
181
* isn't directly available. (e.g. Some Arabic OpenType fonts don't have a GDEF
184
* @param chars - the input character context
185
* @param offset - the offset of the first character to process
186
* @param count - the number of characters to process
187
* @param reverse - true if the glyphs in the glyph array have been reordered
188
* @param glyphs - the input glyph array
189
* @param glyphCount - the number of glyphs
190
* @param positions - the position array, will be updated as needed
191
* @param success - output parameter set to an error code if the operation fails
193
* Note: the positions are passed as a plain array because this method should
194
* not need to reallocate them.
175
* This method does positioning adjustments like accent positioning and
176
* kerning. The default implementation does nothing. Subclasses needing
177
* position adjustments must override this method.
179
* Note that this method has both characters and glyphs as input so that
180
* it can use the character codes to determine glyph types if that information
181
* isn't directly available. (e.g. Some Arabic OpenType fonts don't have a GDEF
184
* @param chars - the input character context
185
* @param offset - the offset of the first character to process
186
* @param count - the number of characters to process
187
* @param reverse - true if the glyphs in the glyph array have been reordered
188
* @param glyphs - the input glyph array
189
* @param glyphCount - the number of glyphs
190
* @param positions - the position array, will be updated as needed
191
* @param success - output parameter set to an error code if the operation fails
193
* Note: the positions are passed as a plain array because this method should
194
* not need to reallocate them.
196
196
virtual void adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, LEGlyphID glyphs[], le_int32 glyphCount, float positions[], LEErrorCode &success)
198
if (LE_FAILURE(success)) {
198
if (LE_FAILURE(success)) {
202
if (chars == NULL || glyphs == NULL || positions == NULL || offset < 0 || count < 0) {
203
success = LE_ILLEGAL_ARGUMENT_ERROR;
202
if (chars == NULL || glyphs == NULL || positions == NULL || offset < 0 || count < 0) {
203
success = LE_ILLEGAL_ARGUMENT_ERROR;
207
207
// default is no adjustments
212
* This method gets a table from the font associated with
213
* the text. The default implementation gets the table from
214
* the font instance. Subclasses which need to get the tables
215
* some other way must override this method.
217
* @param tableTag - the four byte table tag.
219
* @return the address of the table.
212
* This method gets a table from the font associated with
213
* the text. The default implementation gets the table from
214
* the font instance. Subclasses which need to get the tables
215
* some other way must override this method.
217
* @param tableTag - the four byte table tag.
219
* @return the address of the table.
221
221
virtual const void *getFontTable(LETag tableTag) const;
224
* This method does character to glyph mapping. The default implementation
225
* uses the font instance to do the mapping. It will allocate the glyph and
226
* character index arrays if they're not already allocated. If it allocates the
227
* character index array, it will fill it it.
229
* This method supports right to left
230
* text with the ability to store the glyphs in reverse order, and by supporting
231
* character mirroring, which will replace a character which has a left and right
232
* form, such as parens, with the opposite form before mapping it to a glyph index.
235
* @param chars - the input character context
236
* @param offset - the offset of the first character to be mapped
237
* @param count - the number of characters to be mapped
238
* @param reverse - if true, the output will be in reverse order
239
* @param mirror - if true, do character mirroring
242
* @param glyphs - the glyph array
243
* @param charIndices - the character index array
244
* @param success - set to an error code if the operation fails
246
* @see LEFontInstance
224
* This method does character to glyph mapping. The default implementation
225
* uses the font instance to do the mapping. It will allocate the glyph and
226
* character index arrays if they're not already allocated. If it allocates the
227
* character index array, it will fill it it.
229
* This method supports right to left
230
* text with the ability to store the glyphs in reverse order, and by supporting
231
* character mirroring, which will replace a character which has a left and right
232
* form, such as parens, with the opposite form before mapping it to a glyph index.
235
* @param chars - the input character context
236
* @param offset - the offset of the first character to be mapped
237
* @param count - the number of characters to be mapped
238
* @param reverse - if true, the output will be in reverse order
239
* @param mirror - if true, do character mirroring
242
* @param glyphs - the glyph array
243
* @param charIndices - the character index array
244
* @param success - set to an error code if the operation fails
246
* @see LEFontInstance
248
248
virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool mirror, LEGlyphID *&glyphs, le_int32 *&charIndices, LEErrorCode &success);
251
* This is a convenience method that forces the advance width of mark
252
* glyphs to be zero, which is required for proper selection and highlighting.
254
* @param glyphs - the glyph array
255
* @param glyphCount - the number of glyphs
256
* @param reverse - true if the glyph array has been reordered
257
* @param markFilter - used to identify mark glyphs
258
* @param positions - the glyph position array - updated as required
259
* @param success - output parameter set to an error code if the operation fails
251
* This is a convenience method that forces the advance width of mark
252
* glyphs to be zero, which is required for proper selection and highlighting.
254
* @param glyphs - the glyph array
255
* @param glyphCount - the number of glyphs
256
* @param reverse - true if the glyph array has been reordered
257
* @param markFilter - used to identify mark glyphs
258
* @param positions - the glyph position array - updated as required
259
* @param success - output parameter set to an error code if the operation fails
263
263
static void adjustMarkGlyphs(const LEGlyphID glyphs[], le_int32 glyphCount, le_bool reverse, LEGlyphFilter *markFilter, float positions[], LEErrorCode &success);
267
* The destructor. It will free any storage allocated for the
268
* glyph, character index and position arrays by calling the reset
269
* method. It is declared virtual so that it will be invoked by the
270
* subclass destructors.
267
* The destructor. It will free any storage allocated for the
268
* glyph, character index and position arrays by calling the reset
269
* method. It is declared virtual so that it will be invoked by the
270
* subclass destructors.
272
272
virtual ~LayoutEngine();
275
* This method will invoke the layout steps in their correct order by calling
276
* the computeGlyphs, positionGlyphs and adjustGlyphPosition methods.. It will
277
* compute the glyph, character index and position arrays.
279
* @param chars - the input character context
280
* @param offset - the offset of the first character to process
281
* @param count - the number of characters to process
282
* @param max - the number of characters in the input context
283
* @param rightToLeft - true if the characers are in a right to left directional run
284
* @param x - the initial X position
285
* @param y - the initial Y position
286
* @param success - output parameter set to an error code if the operation fails
288
* @return the number of glyphs in the glyph array
290
* Note; the glyph, character index and position array can be accessed
291
* using the getter method below.
275
* This method will invoke the layout steps in their correct order by calling
276
* the computeGlyphs, positionGlyphs and adjustGlyphPosition methods.. It will
277
* compute the glyph, character index and position arrays.
279
* @param chars - the input character context
280
* @param offset - the offset of the first character to process
281
* @param count - the number of characters to process
282
* @param max - the number of characters in the input context
283
* @param rightToLeft - true if the characers are in a right to left directional run
284
* @param x - the initial X position
285
* @param y - the initial Y position
286
* @param success - output parameter set to an error code if the operation fails
288
* @return the number of glyphs in the glyph array
290
* Note; the glyph, character index and position array can be accessed
291
* using the getter method below.
293
293
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);
296
* This method returns the number of glyphs in the glyph array. Note
297
* that the number of glyphs will be greater than or equal to the number
298
* of characters used to create the LayoutEngine.
300
* @return the number of glyphs in the glyph array
302
le_int32 getGlyphCount() const
296
* This method returns the number of glyphs in the glyph array. Note
297
* that the number of glyphs will be greater than or equal to the number
298
* of characters used to create the LayoutEngine.
300
* @return the number of glyphs in the glyph array
302
le_int32 getGlyphCount() const
308
* This method copies the glyph array into a caller supplied array.
309
* The caller must ensure that the array is large enough to hold all
312
* @param glyphs - the destiniation glyph array
313
* @param success - set to an error code if the operation fails
308
* This method copies the glyph array into a caller supplied array.
309
* The caller must ensure that the array is large enough to hold all
312
* @param glyphs - the destiniation glyph array
313
* @param success - set to an error code if the operation fails
315
315
void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const
317
if (LE_FAILURE(success)) {
321
if (glyphs == NULL) {
322
success = LE_ILLEGAL_ARGUMENT_ERROR;
326
if (fGlyphs == NULL) {
327
success = LE_NO_LAYOUT_ERROR;
317
if (LE_FAILURE(success)) {
321
if (glyphs == NULL) {
322
success = LE_ILLEGAL_ARGUMENT_ERROR;
326
if (fGlyphs == NULL) {
327
success = LE_NO_LAYOUT_ERROR;
330
330
LE_ARRAY_COPY(glyphs, fGlyphs, fGlyphCount);
334
* This method copies the glyph array into a caller supplied array,
335
* ORing in extra bits. (This functionality is needed by the JDK,
336
* which uses 32 bits pre glyph idex, with the high 16 bits encoding
337
* the composite font slot number)
339
* @param glyphs - the destination (32 bit) glyph array
340
* @param extraBits - this value will be ORed with each glyph index
341
* @param success - set to an error code if the operation fails
334
* This method copies the glyph array into a caller supplied array,
335
* ORing in extra bits. (This functionality is needed by the JDK,
336
* which uses 32 bits pre glyph idex, with the high 16 bits encoding
337
* the composite font slot number)
339
* @param glyphs - the destination (32 bit) glyph array
340
* @param extraBits - this value will be ORed with each glyph index
341
* @param success - set to an error code if the operation fails
343
343
virtual void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
346
* This method copies the character index array into a caller supplied array.
347
* The caller must ensure that the array is large enough to hold a
348
* character index for each glyph.
350
* @param charIndices - the destiniation character index array
351
* @param success - set to an error code if the operation fails
346
* This method copies the character index array into a caller supplied array.
347
* The caller must ensure that the array is large enough to hold a
348
* character index for each glyph.
350
* @param charIndices - the destiniation character index array
351
* @param success - set to an error code if the operation fails
353
353
void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const
355
if LE_FAILURE(success) {
359
if (charIndices == NULL) {
360
success = LE_ILLEGAL_ARGUMENT_ERROR;
364
if (fCharIndices == NULL) {
365
success = LE_NO_LAYOUT_ERROR;
355
if LE_FAILURE(success) {
359
if (charIndices == NULL) {
360
success = LE_ILLEGAL_ARGUMENT_ERROR;
364
if (fCharIndices == NULL) {
365
success = LE_NO_LAYOUT_ERROR;
369
369
LE_ARRAY_COPY(charIndices, fCharIndices, fGlyphCount);
373
* This method copies the character index array into a caller supplied array.
374
* The caller must ensure that the array is large enough to hold a
375
* character index for each glyph.
377
* @param charIndices - the destiniation character index array
378
* @param indexBase - an offset which will be added to each index
379
* @param success - set to an error code if the operation fails
373
* This method copies the character index array into a caller supplied array.
374
* The caller must ensure that the array is large enough to hold a
375
* character index for each glyph.
377
* @param charIndices - the destiniation character index array
378
* @param indexBase - an offset which will be added to each index
379
* @param success - set to an error code if the operation fails
381
381
void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
384
* This method copies the position array into a caller supplied array.
385
* The caller must ensure that the array is large enough to hold an
386
* X and Y position for each glyph, plus an extra X and Y for the
387
* advance of the last glyph.
389
* @param glyphs - the destiniation position array
390
* @param success - set to an error code if the operation fails
384
* This method copies the position array into a caller supplied array.
385
* The caller must ensure that the array is large enough to hold an
386
* X and Y position for each glyph, plus an extra X and Y for the
387
* advance of the last glyph.
389
* @param glyphs - the destiniation position array
390
* @param success - set to an error code if the operation fails
392
392
void getGlyphPositions(float positions[], LEErrorCode &success) const
394
if LE_FAILURE(success) {
398
if (positions == NULL) {
399
success = LE_ILLEGAL_ARGUMENT_ERROR;
403
if (fPositions == NULL) {
404
success = LE_NO_LAYOUT_ERROR;
394
if LE_FAILURE(success) {
398
if (positions == NULL) {
399
success = LE_ILLEGAL_ARGUMENT_ERROR;
403
if (fPositions == NULL) {
404
success = LE_NO_LAYOUT_ERROR;
408
408
LE_ARRAY_COPY(positions, fPositions, fGlyphCount * 2 + 2);
412
* This method returns the X and Y position of the glyph at
416
* @param glyphIndex - the index of the glyph
419
* @param x - the glyph's X position
420
* @param y - the glyph's Y position
421
* @param success - set to an error code if the operation fails
412
* This method returns the X and Y position of the glyph at
416
* @param glyphIndex - the index of the glyph
419
* @param x - the glyph's X position
420
* @param y - the glyph's Y position
421
* @param success - set to an error code if the operation fails
424
424
void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const
426
if (LE_FAILURE(success)) {
430
if (glyphIndex > fGlyphCount) {
431
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
435
if (fPositions == NULL) {
436
success = LE_NO_LAYOUT_ERROR;
426
if (LE_FAILURE(success)) {
430
if (glyphIndex > fGlyphCount) {
431
success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
435
if (fPositions == NULL) {
436
success = LE_NO_LAYOUT_ERROR;
440
440
x = fPositions[glyphIndex * 2];
441
y = fPositions[glyphIndex * 2 + 1];
441
y = fPositions[glyphIndex * 2 + 1];
445
* This method frees the glyph, character index and position arrays
446
* so that the LayoutEngine can be reused to layout a different
447
* characer array. (This method is also called by the destructor)
445
* This method frees the glyph, character index and position arrays
446
* so that the LayoutEngine can be reused to layout a different
447
* characer array. (This method is also called by the destructor)
449
449
virtual void reset();
452
* This method returns a LayoutEngine capable of laying out text
453
* in the given font, script and langauge. Note that the LayoutEngine
454
* returned may be a subclass of LayoutEngine.
456
* @param fontInstance - the font of the text
457
* @param scriptCode - the script of the text
458
* @param langaugeCode - the language of the text
459
* @param success - output parameter set to an error code if the operation fails
461
* @return a LayoutEngine which can layout text in the given font.
463
* @see LEFontInstance
452
* This method returns a LayoutEngine capable of laying out text
453
* in the given font, script and langauge. Note that the LayoutEngine
454
* returned may be a subclass of LayoutEngine.
456
* @param fontInstance - the font of the text
457
* @param scriptCode - the script of the text
458
* @param langaugeCode - the language of the text
459
* @param success - output parameter set to an error code if the operation fails
461
* @return a LayoutEngine which can layout text in the given font.
463
* @see LEFontInstance
465
465
static LayoutEngine *layoutEngineFactory(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, LEErrorCode &success);