]> git.saurik.com Git - apple/icu.git/blob - icuSources/layout/ThaiLayoutEngine.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / layout / ThaiLayoutEngine.cpp
1
2 /*
3 * @(#)ThaiLayoutEngine.cpp 1.2 00/03/15
4 *
5 * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
6 *
7 */
8
9 #include "LETypes.h"
10 #include "LayoutEngine.h"
11 #include "ThaiLayoutEngine.h"
12 #include "ScriptAndLanguageTags.h"
13
14 #include "ThaiShaping.h"
15
16 U_NAMESPACE_BEGIN
17
18 const char ThaiLayoutEngine::fgClassID=0;
19
20 ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode)
21 : LayoutEngine(fontInstance, scriptCode, languageCode)
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*/, LEGlyphID *&glyphs, le_int32 *&charIndices, 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 charIndices = LE_NEW_ARRAY(le_int32, count * 2);
78
79 if (charIndices == NULL) {
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, charIndices);
86 mapCharsToGlyphs(outChars, 0, glyphCount, false, false, glyphs, charIndices, success);
87
88 LE_DELETE_ARRAY(outChars);
89
90 return glyphCount;
91 }
92
93 U_NAMESPACE_END