]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/ThaiLayoutEngine.cpp
ICU-6.2.16.tar.gz
[apple/icu.git] / icuSources / layout / ThaiLayoutEngine.cpp
CommitLineData
b75a7d8f
A
1
2/*
b75a7d8f 3 *
374ca955 4 * (C) Copyright IBM Corp. 1998-2004 - 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
A
13
14#include "ThaiShaping.h"
15
16U_NAMESPACE_BEGIN
17
374ca955 18UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine)
b75a7d8f
A
19
20ThaiLayoutEngine::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
45ThaiLayoutEngine::~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...
374ca955 54le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
b75a7d8f
A
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
374ca955 77 glyphStorage.allocateGlyphArray(count * 2, FALSE, success);
b75a7d8f 78
374ca955 79 if (LE_FAILURE(success)) {
b75a7d8f
A
80 LE_DELETE_ARRAY(outChars);
81 success = LE_MEMORY_ALLOCATION_ERROR;
82 return 0;
83 }
84
374ca955
A
85 glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage);
86 mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success);
b75a7d8f
A
87
88 LE_DELETE_ARRAY(outChars);
89
374ca955 90 glyphStorage.adoptGlyphCount(glyphCount);
b75a7d8f
A
91 return glyphCount;
92}
93
94U_NAMESPACE_END