|
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 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved |
|
29 * |
|
30 * This file is a modification of the ICU file IndicLayoutEngine.cpp |
|
31 * by Jens Herden and Javier Sola for Khmer language |
|
32 * |
|
33 */ |
|
34 |
|
35 |
|
36 #include "OpenTypeLayoutEngine.h" |
|
37 #include "KhmerLayoutEngine.h" |
|
38 #include "LEGlyphStorage.h" |
|
39 #include "KhmerReordering.h" |
|
40 |
|
41 KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, |
|
42 le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, |
|
43 const GlyphSubstitutionTableHeader *gsubTable) |
|
44 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable) |
|
45 { |
|
46 fFeatureMap = KhmerReordering::getFeatureMap(fFeatureMapCount); |
|
47 fFeatureOrder = TRUE; |
|
48 } |
|
49 |
|
50 KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, |
|
51 le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags) |
|
52 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags) |
|
53 { |
|
54 fFeatureMap = KhmerReordering::getFeatureMap(fFeatureMapCount); |
|
55 fFeatureOrder = TRUE; |
|
56 } |
|
57 |
|
58 KhmerOpenTypeLayoutEngine::~KhmerOpenTypeLayoutEngine() |
|
59 { |
|
60 // nothing to do |
|
61 } |
|
62 |
|
63 // Input: characters |
|
64 // Output: characters, char indices, tags |
|
65 // Returns: output character count |
|
66 le_int32 KhmerOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], |
|
67 le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, |
|
68 LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success) |
|
69 { |
|
70 if (LE_FAILURE(success)) { |
|
71 return 0; |
|
72 } |
|
73 |
|
74 if (chars == NULL || offset < 0 || count < 0 || max < 0 || |
|
75 offset >= max || offset + count > max) { |
|
76 success = LE_ILLEGAL_ARGUMENT_ERROR; |
|
77 return 0; |
|
78 } |
|
79 |
|
80 le_int32 worstCase = count * 3; // worst case is 3 for Khmer TODO check if 2 is enough |
|
81 |
|
82 outChars = LE_NEW_ARRAY(LEUnicode, worstCase); |
|
83 |
|
84 if (outChars == NULL) { |
|
85 success = LE_MEMORY_ALLOCATION_ERROR; |
|
86 return 0; |
|
87 } |
|
88 |
|
89 glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success); |
|
90 glyphStorage.allocateAuxData(success); |
|
91 |
|
92 if (LE_FAILURE(success)) { |
|
93 LE_DELETE_ARRAY(outChars); |
|
94 return 0; |
|
95 } |
|
96 |
|
97 // NOTE: assumes this allocates featureTags... |
|
98 // (probably better than doing the worst case stuff here...) |
|
99 le_int32 outCharCount = KhmerReordering::reorder(&chars[offset], count, |
|
100 fScriptCode, outChars, glyphStorage); |
|
101 |
|
102 glyphStorage.adoptGlyphCount(outCharCount); |
|
103 return outCharCount; |
|
104 } |