]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | |
2 | /* | |
b75a7d8f | 3 | * |
57a6839d | 4 | * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved |
b75a7d8f A |
5 | * |
6 | */ | |
7 | ||
8 | #include "LETypes.h" | |
9 | #include "LayoutEngine.h" | |
10 | #include "ThaiLayoutEngine.h" | |
11 | #include "ScriptAndLanguageTags.h" | |
374ca955 | 12 | #include "LEGlyphStorage.h" |
b75a7d8f | 13 | |
46f4442e A |
14 | #include "KernTable.h" |
15 | ||
b75a7d8f A |
16 | #include "ThaiShaping.h" |
17 | ||
18 | U_NAMESPACE_BEGIN | |
19 | ||
374ca955 | 20 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine) |
b75a7d8f | 21 | |
729e4ab9 A |
22 | ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, LEErrorCode &success) |
23 | : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success) | |
b75a7d8f A |
24 | { |
25 | fErrorChar = 0x25CC; | |
26 | ||
27 | // Figure out which presentation forms the font uses | |
46f4442e A |
28 | if (! fontInstance->canDisplay(0x0E01)) { |
29 | // No Thai in font; don't use presentation forms. | |
30 | fGlyphSet = 3; | |
31 | } else if (fontInstance->canDisplay(0x0E64)) { | |
b75a7d8f A |
32 | // WorldType uses reserved space in Thai block |
33 | fGlyphSet = 0; | |
34 | } else if (fontInstance->canDisplay(0xF701)) { | |
35 | // Microsoft corporate zone | |
36 | fGlyphSet = 1; | |
37 | ||
38 | if (!fontInstance->canDisplay(fErrorChar)) { | |
39 | fErrorChar = 0xF71B; | |
40 | } | |
41 | } else if (fontInstance->canDisplay(0xF885)) { | |
42 | // Apple corporate zone | |
43 | fGlyphSet = 2; | |
44 | } else { | |
45 | // no presentation forms in the font | |
46 | fGlyphSet = 3; | |
47 | } | |
48 | } | |
49 | ||
50 | ThaiLayoutEngine::~ThaiLayoutEngine() | |
51 | { | |
52 | // nothing to do | |
53 | } | |
54 | ||
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... | |
374ca955 | 59 | le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success) |
b75a7d8f A |
60 | { |
61 | if (LE_FAILURE(success)) { | |
62 | return 0; | |
63 | } | |
64 | ||
65 | if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) { | |
66 | success = LE_ILLEGAL_ARGUMENT_ERROR; | |
67 | return 0; | |
68 | } | |
69 | ||
70 | LEUnicode *outChars; | |
71 | le_int32 glyphCount; | |
72 | ||
73 | // This is enough room for the worst-case expansion | |
74 | // (it says here...) | |
75 | outChars = LE_NEW_ARRAY(LEUnicode, count * 2); | |
76 | ||
77 | if (outChars == NULL) { | |
78 | success = LE_MEMORY_ALLOCATION_ERROR; | |
79 | return 0; | |
80 | } | |
81 | ||
374ca955 | 82 | glyphStorage.allocateGlyphArray(count * 2, FALSE, success); |
b75a7d8f | 83 | |
374ca955 | 84 | if (LE_FAILURE(success)) { |
b75a7d8f A |
85 | LE_DELETE_ARRAY(outChars); |
86 | success = LE_MEMORY_ALLOCATION_ERROR; | |
87 | return 0; | |
88 | } | |
89 | ||
374ca955 | 90 | glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage); |
46f4442e | 91 | mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success); |
b75a7d8f A |
92 | |
93 | LE_DELETE_ARRAY(outChars); | |
94 | ||
374ca955 | 95 | glyphStorage.adoptGlyphCount(glyphCount); |
b75a7d8f A |
96 | return glyphCount; |
97 | } | |
98 | ||
46f4442e A |
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) | |
102 | { | |
103 | if (LE_FAILURE(success)) { | |
104 | return; | |
105 | } | |
106 | ||
107 | if (chars == NULL || offset < 0 || count < 0) { | |
108 | success = LE_ILLEGAL_ARGUMENT_ERROR; | |
109 | return; | |
110 | } | |
111 | ||
57a6839d A |
112 | if (fTypoFlags & LE_Kerning_FEATURE_FLAG) { /* kerning enabled */ |
113 | LETableReference kernTable(fFontInstance, LE_KERN_TABLE_TAG, success); | |
114 | KernTable kt(kernTable, success); | |
115 | kt.process(glyphStorage, success); | |
46f4442e A |
116 | } |
117 | ||
118 | // default is no adjustments | |
119 | return; | |
120 | } | |
121 | ||
b75a7d8f | 122 | U_NAMESPACE_END |