|
1 |
|
2 /* |
|
3 * |
|
4 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved |
|
5 * |
|
6 */ |
|
7 |
|
8 #include "LETypes.h" |
|
9 #include "LayoutEngine.h" |
|
10 #include "ThaiLayoutEngine.h" |
|
11 #include "ScriptAndLanguageTags.h" |
|
12 #include "LEGlyphStorage.h" |
|
13 |
|
14 #include "ThaiShaping.h" |
|
15 |
|
16 U_NAMESPACE_BEGIN |
|
17 |
|
18 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine) |
|
19 |
|
20 ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags) |
|
21 : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags) |
|
22 { |
|
23 fErrorChar = 0x25CC; |
|
24 |
|
25 // Figure out which presentation forms the font uses |
|
26 if (fontInstance->canDisplay(0x0E64)) { |
|
27 // WorldType uses reserved space in Thai block |
|
28 fGlyphSet = 0; |
|
29 } else if (fontInstance->canDisplay(0xF701)) { |
|
30 // Microsoft corporate zone |
|
31 fGlyphSet = 1; |
|
32 |
|
33 if (!fontInstance->canDisplay(fErrorChar)) { |
|
34 fErrorChar = 0xF71B; |
|
35 } |
|
36 } else if (fontInstance->canDisplay(0xF885)) { |
|
37 // Apple corporate zone |
|
38 fGlyphSet = 2; |
|
39 } else { |
|
40 // no presentation forms in the font |
|
41 fGlyphSet = 3; |
|
42 } |
|
43 } |
|
44 |
|
45 ThaiLayoutEngine::~ThaiLayoutEngine() |
|
46 { |
|
47 // nothing to do |
|
48 } |
|
49 |
|
50 // Input: characters (0..max provided for context) |
|
51 // Output: glyphs, char indices |
|
52 // Returns: the glyph count |
|
53 // NOTE: this assumes that ThaiShaping::compose will allocate the outChars array... |
|
54 le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success) |
|
55 { |
|
56 if (LE_FAILURE(success)) { |
|
57 return 0; |
|
58 } |
|
59 |
|
60 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) { |
|
61 success = LE_ILLEGAL_ARGUMENT_ERROR; |
|
62 return 0; |
|
63 } |
|
64 |
|
65 LEUnicode *outChars; |
|
66 le_int32 glyphCount; |
|
67 |
|
68 // This is enough room for the worst-case expansion |
|
69 // (it says here...) |
|
70 outChars = LE_NEW_ARRAY(LEUnicode, count * 2); |
|
71 |
|
72 if (outChars == NULL) { |
|
73 success = LE_MEMORY_ALLOCATION_ERROR; |
|
74 return 0; |
|
75 } |
|
76 |
|
77 glyphStorage.allocateGlyphArray(count * 2, FALSE, success); |
|
78 |
|
79 if (LE_FAILURE(success)) { |
|
80 LE_DELETE_ARRAY(outChars); |
|
81 success = LE_MEMORY_ALLOCATION_ERROR; |
|
82 return 0; |
|
83 } |
|
84 |
|
85 glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage); |
|
86 mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success); |
|
87 |
|
88 LE_DELETE_ARRAY(outChars); |
|
89 |
|
90 glyphStorage.adoptGlyphCount(glyphCount); |
|
91 return glyphCount; |
|
92 } |
|
93 |
|
94 U_NAMESPACE_END |