2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
|
6 |
* published by the Free Software Foundation. Sun designates this
|
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
|
8 |
* by Sun in the LICENSE file that accompanied this code.
|
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
|
20 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
21 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
22 |
* have any questions.
|
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
/*
|
|
28 |
*
|
|
29 |
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
|
|
33 |
#include "LETypes.h"
|
|
34 |
#include "LayoutEngine.h"
|
|
35 |
#include "ThaiLayoutEngine.h"
|
|
36 |
#include "ScriptAndLanguageTags.h"
|
|
37 |
#include "LEGlyphStorage.h"
|
|
38 |
|
|
39 |
#include "ThaiShaping.h"
|
|
40 |
|
3935
|
41 |
U_NAMESPACE_BEGIN
|
|
42 |
|
|
43 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine)
|
|
44 |
|
|
45 |
ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
|
2
|
46 |
: LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
|
|
47 |
{
|
|
48 |
fErrorChar = 0x25CC;
|
|
49 |
|
|
50 |
// Figure out which presentation forms the font uses
|
|
51 |
if (fontInstance->canDisplay(0x0E64)) {
|
|
52 |
// WorldType uses reserved space in Thai block
|
|
53 |
fGlyphSet = 0;
|
|
54 |
} else if (fontInstance->canDisplay(0xF701)) {
|
|
55 |
// Microsoft corporate zone
|
|
56 |
fGlyphSet = 1;
|
|
57 |
|
|
58 |
if (!fontInstance->canDisplay(fErrorChar)) {
|
|
59 |
fErrorChar = 0xF71B;
|
|
60 |
}
|
|
61 |
} else if (fontInstance->canDisplay(0xF885)) {
|
|
62 |
// Apple corporate zone
|
|
63 |
fGlyphSet = 2;
|
|
64 |
} else {
|
|
65 |
// no presentation forms in the font
|
|
66 |
fGlyphSet = 3;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
ThaiLayoutEngine::~ThaiLayoutEngine()
|
|
71 |
{
|
|
72 |
// nothing to do
|
|
73 |
}
|
|
74 |
|
|
75 |
// Input: characters (0..max provided for context)
|
|
76 |
// Output: glyphs, char indices
|
|
77 |
// Returns: the glyph count
|
|
78 |
// NOTE: this assumes that ThaiShaping::compose will allocate the outChars array...
|
3935
|
79 |
le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
2
|
80 |
{
|
|
81 |
if (LE_FAILURE(success)) {
|
|
82 |
return 0;
|
|
83 |
}
|
|
84 |
|
3935
|
85 |
if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
|
2
|
86 |
success = LE_ILLEGAL_ARGUMENT_ERROR;
|
|
87 |
return 0;
|
|
88 |
}
|
|
89 |
|
|
90 |
LEUnicode *outChars;
|
|
91 |
le_int32 glyphCount;
|
|
92 |
|
|
93 |
// This is enough room for the worst-case expansion
|
|
94 |
// (it says here...)
|
|
95 |
outChars = LE_NEW_ARRAY(LEUnicode, count * 2);
|
|
96 |
|
|
97 |
if (outChars == NULL) {
|
|
98 |
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
99 |
return 0;
|
|
100 |
}
|
|
101 |
|
|
102 |
glyphStorage.allocateGlyphArray(count * 2, FALSE, success);
|
|
103 |
|
|
104 |
if (LE_FAILURE(success)) {
|
|
105 |
LE_DELETE_ARRAY(outChars);
|
|
106 |
success = LE_MEMORY_ALLOCATION_ERROR;
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
|
3935
|
110 |
glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage);
|
2
|
111 |
mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success);
|
|
112 |
|
|
113 |
LE_DELETE_ARRAY(outChars);
|
|
114 |
|
|
115 |
glyphStorage.adoptGlyphCount(glyphCount);
|
|
116 |
return glyphCount;
|
|
117 |
}
|
3935
|
118 |
|
|
119 |
U_NAMESPACE_END
|