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