4 * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved
9 #include "LayoutEngine.h"
10 #include "ThaiLayoutEngine.h"
11 #include "ScriptAndLanguageTags.h"
12 #include "LEGlyphStorage.h"
14 #include "KernTable.h"
16 #include "ThaiShaping.h"
20 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine
)
22 ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance
*fontInstance
, le_int32 scriptCode
, le_int32 languageCode
, le_int32 typoFlags
, LEErrorCode
&success
)
23 : LayoutEngine(fontInstance
, scriptCode
, languageCode
, typoFlags
, success
)
27 // Figure out which presentation forms the font uses
28 if (! fontInstance
->canDisplay(0x0E01)) {
29 // No Thai in font; don't use presentation forms.
31 } else if (fontInstance
->canDisplay(0x0E64)) {
32 // WorldType uses reserved space in Thai block
34 } else if (fontInstance
->canDisplay(0xF701)) {
35 // Microsoft corporate zone
38 if (!fontInstance
->canDisplay(fErrorChar
)) {
41 } else if (fontInstance
->canDisplay(0xF885)) {
42 // Apple corporate zone
45 // no presentation forms in the font
50 ThaiLayoutEngine::~ThaiLayoutEngine()
55 // Input: characters (0..max provided for context)
56 // Output: glyphs, char indices
57 // Returns: the glyph count
58 // NOTE: this assumes that ThaiShaping::compose will allocate the outChars array...
59 le_int32
ThaiLayoutEngine::computeGlyphs(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_int32 max
, le_bool
/*rightToLeft*/, LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
)
61 if (LE_FAILURE(success
)) {
65 if (chars
== NULL
|| offset
< 0 || count
< 0 || max
< 0 || offset
>= max
|| offset
+ count
> max
) {
66 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
73 // This is enough room for the worst-case expansion
75 outChars
= LE_NEW_ARRAY(LEUnicode
, count
* 2);
77 if (outChars
== NULL
) {
78 success
= LE_MEMORY_ALLOCATION_ERROR
;
82 glyphStorage
.allocateGlyphArray(count
* 2, FALSE
, success
);
84 if (LE_FAILURE(success
)) {
85 LE_DELETE_ARRAY(outChars
);
86 success
= LE_MEMORY_ALLOCATION_ERROR
;
90 glyphCount
= ThaiShaping::compose(chars
, offset
, count
, fGlyphSet
, fErrorChar
, outChars
, glyphStorage
);
91 mapCharsToGlyphs(outChars
, 0, glyphCount
, FALSE
, FALSE
, glyphStorage
, success
);
93 LE_DELETE_ARRAY(outChars
);
95 glyphStorage
.adoptGlyphCount(glyphCount
);
99 // This is the same as LayoutEngline::adjustGlyphPositions() except that it doesn't call adjustMarkGlyphs
100 void ThaiLayoutEngine::adjustGlyphPositions(const LEUnicode chars
[], le_int32 offset
, le_int32 count
, le_bool
/*reverse*/,
101 LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
)
103 if (LE_FAILURE(success
)) {
107 if (chars
== NULL
|| offset
< 0 || count
< 0) {
108 success
= LE_ILLEGAL_ARGUMENT_ERROR
;
112 if (fTypoFlags
& 0x1) { /* kerning enabled */
113 static const le_uint32 kernTableTag
= LE_KERN_TABLE_TAG
;
115 KernTable
kt(fFontInstance
, getFontTable(kernTableTag
));
116 kt
.process(glyphStorage
);
119 // default is no adjustments