|
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. Oracle designates this |
|
7 * particular file as subject to the "Classpath" exception as provided |
|
8 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 * |
|
24 */ |
|
25 |
|
26 /* |
|
27 * |
|
28 * (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved |
|
29 * |
|
30 * Developed at DIT - Government of Bhutan |
|
31 * |
|
32 * Contact person: Pema Geyleg - <pema_geyleg@druknet.bt> |
|
33 * |
|
34 * This file is a modification of the ICU file KhmerReordering.cpp |
|
35 * by Jens Herden and Javier Sola who have given all their possible rights to IBM and the Governement of Bhutan |
|
36 * A first module for Dzongkha was developed by Karunakar under Panlocalisation funding. |
|
37 * Assistance for this module has been received from Namgay Thinley, Christopher Fynn and Javier Sola |
|
38 * |
|
39 */ |
|
40 |
|
41 |
|
42 #include "OpenTypeLayoutEngine.h" |
|
43 #include "TibetanLayoutEngine.h" |
|
44 #include "LEGlyphStorage.h" |
|
45 #include "TibetanReordering.h" |
|
46 |
|
47 U_NAMESPACE_BEGIN |
|
48 |
|
49 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TibetanOpenTypeLayoutEngine) |
|
50 |
|
51 TibetanOpenTypeLayoutEngine::TibetanOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, |
|
52 le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable, LEErrorCode &success) |
|
53 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success) |
|
54 { |
|
55 fFeatureMap = TibetanReordering::getFeatureMap(fFeatureMapCount); |
|
56 fFeatureOrder = TRUE; |
|
57 } |
|
58 |
|
59 TibetanOpenTypeLayoutEngine::TibetanOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, |
|
60 le_int32 typoFlags, LEErrorCode &success) |
|
61 : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success) |
|
62 { |
|
63 fFeatureMap = TibetanReordering::getFeatureMap(fFeatureMapCount); |
|
64 fFeatureOrder = TRUE; |
|
65 } |
|
66 |
|
67 TibetanOpenTypeLayoutEngine::~TibetanOpenTypeLayoutEngine() |
|
68 { |
|
69 // nothing to do |
|
70 } |
|
71 |
|
72 // Input: characters |
|
73 // Output: characters, char indices, tags |
|
74 // Returns: output character count |
|
75 le_int32 TibetanOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, |
|
76 LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success) |
|
77 { |
|
78 if (LE_FAILURE(success)) { |
|
79 return 0; |
|
80 } |
|
81 |
|
82 if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) { |
|
83 success = LE_ILLEGAL_ARGUMENT_ERROR; |
|
84 return 0; |
|
85 } |
|
86 |
|
87 le_int32 worstCase = count * 3; // worst case is 3 for Khmer TODO check if 2 is enough |
|
88 |
|
89 outChars = LE_NEW_ARRAY(LEUnicode, worstCase); |
|
90 |
|
91 if (outChars == NULL) { |
|
92 success = LE_MEMORY_ALLOCATION_ERROR; |
|
93 return 0; |
|
94 } |
|
95 |
|
96 glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success); |
|
97 glyphStorage.allocateAuxData(success); |
|
98 |
|
99 if (LE_FAILURE(success)) { |
|
100 LE_DELETE_ARRAY(outChars); |
|
101 return 0; |
|
102 } |
|
103 |
|
104 // NOTE: assumes this allocates featureTags... |
|
105 // (probably better than doing the worst case stuff here...) |
|
106 le_int32 outCharCount = TibetanReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage); |
|
107 |
|
108 glyphStorage.adoptGlyphCount(outCharCount); |
|
109 return outCharCount; |
|
110 } |
|
111 |
|
112 U_NAMESPACE_END |