]> git.saurik.com Git - apple/icu.git/blob - icuSources/layout/IndicReordering.h
ICU-400.42.tar.gz
[apple/icu.git] / icuSources / layout / IndicReordering.h
1 /*
2 *
3 * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved
4 *
5 */
6
7 #ifndef __INDICREORDERING_H
8 #define __INDICREORDERING_H
9
10 /**
11 * \file
12 * \internal
13 */
14
15 #include "LETypes.h"
16 #include "OpenTypeTables.h"
17
18 U_NAMESPACE_BEGIN
19
20 // Characters that get refered to by name...
21 #define C_SIGN_ZWNJ 0x200C
22 #define C_SIGN_ZWJ 0x200D
23
24 // Character class values
25 #define CC_RESERVED 0U
26 #define CC_VOWEL_MODIFIER 1U
27 #define CC_STRESS_MARK 2U
28 #define CC_INDEPENDENT_VOWEL 3U
29 #define CC_INDEPENDENT_VOWEL_2 4U
30 #define CC_INDEPENDENT_VOWEL_3 5U
31 #define CC_CONSONANT 6U
32 #define CC_CONSONANT_WITH_NUKTA 7U
33 #define CC_NUKTA 8U
34 #define CC_DEPENDENT_VOWEL 9U
35 #define CC_SPLIT_VOWEL_PIECE_1 10U
36 #define CC_SPLIT_VOWEL_PIECE_2 11U
37 #define CC_SPLIT_VOWEL_PIECE_3 12U
38 #define CC_VIRAMA 13U
39 #define CC_ZERO_WIDTH_MARK 14U
40 #define CC_AL_LAKUNA 15U
41 #define CC_COUNT 16U
42
43 // Character class flags
44 #define CF_CLASS_MASK 0x0000FFFFU
45
46 #define CF_CONSONANT 0x80000000U
47
48 #define CF_REPH 0x40000000U
49 #define CF_VATTU 0x20000000U
50 #define CF_BELOW_BASE 0x10000000U
51 #define CF_POST_BASE 0x08000000U
52 #define CF_LENGTH_MARK 0x04000000U
53
54 #define CF_POS_BEFORE 0x00300000U
55 #define CF_POS_BELOW 0x00200000U
56 #define CF_POS_ABOVE 0x00100000U
57 #define CF_POS_AFTER 0x00000000U
58 #define CF_POS_MASK 0x00300000U
59
60 #define CF_INDEX_MASK 0x000F0000U
61 #define CF_INDEX_SHIFT 16
62
63 // Script flag bits
64 #define SF_MATRAS_AFTER_BASE 0x80000000U
65 #define SF_REPH_AFTER_BELOW 0x40000000U
66 #define SF_EYELASH_RA 0x20000000U
67 #define SF_MPRE_FIXUP 0x10000000U
68 #define SF_FILTER_ZERO_WIDTH 0x08000000U
69
70 #define SF_POST_BASE_LIMIT_MASK 0x0000FFFFU
71 #define SF_NO_POST_BASE_LIMIT 0x00007FFFU
72
73 typedef LEUnicode SplitMatra[3];
74
75 class MPreFixups;
76 class LEGlyphStorage;
77
78 struct IndicClassTable
79 {
80 typedef le_uint32 CharClass;
81 typedef le_uint32 ScriptFlags;
82
83 LEUnicode firstChar;
84 LEUnicode lastChar;
85 le_int32 worstCaseExpansion;
86 ScriptFlags scriptFlags;
87 const CharClass *classTable;
88 const SplitMatra *splitMatraTable;
89
90 inline le_int32 getWorstCaseExpansion() const;
91 inline le_bool getFilterZeroWidth() const;
92
93 CharClass getCharClass(LEUnicode ch) const;
94
95 inline const SplitMatra *getSplitMatra(CharClass charClass) const;
96
97 inline le_bool isVowelModifier(LEUnicode ch) const;
98 inline le_bool isStressMark(LEUnicode ch) const;
99 inline le_bool isConsonant(LEUnicode ch) const;
100 inline le_bool isReph(LEUnicode ch) const;
101 inline le_bool isVirama(LEUnicode ch) const;
102 inline le_bool isAlLakuna(LEUnicode ch) const;
103 inline le_bool isNukta(LEUnicode ch) const;
104 inline le_bool isVattu(LEUnicode ch) const;
105 inline le_bool isMatra(LEUnicode ch) const;
106 inline le_bool isSplitMatra(LEUnicode ch) const;
107 inline le_bool isLengthMark(LEUnicode ch) const;
108 inline le_bool hasPostOrBelowBaseForm(LEUnicode ch) const;
109 inline le_bool hasPostBaseForm(LEUnicode ch) const;
110 inline le_bool hasBelowBaseForm(LEUnicode ch) const;
111
112 inline static le_bool isVowelModifier(CharClass charClass);
113 inline static le_bool isStressMark(CharClass charClass);
114 inline static le_bool isConsonant(CharClass charClass);
115 inline static le_bool isReph(CharClass charClass);
116 inline static le_bool isVirama(CharClass charClass);
117 inline static le_bool isAlLakuna(CharClass charClass);
118 inline static le_bool isNukta(CharClass charClass);
119 inline static le_bool isVattu(CharClass charClass);
120 inline static le_bool isMatra(CharClass charClass);
121 inline static le_bool isSplitMatra(CharClass charClass);
122 inline static le_bool isLengthMark(CharClass charClass);
123 inline static le_bool hasPostOrBelowBaseForm(CharClass charClass);
124 inline static le_bool hasPostBaseForm(CharClass charClass);
125 inline static le_bool hasBelowBaseForm(CharClass charClass);
126
127 static const IndicClassTable *getScriptClassTable(le_int32 scriptCode);
128 };
129
130 class IndicReordering /* not : public UObject because all methods are static */ {
131 public:
132 static le_int32 getWorstCaseExpansion(le_int32 scriptCode);
133
134 static le_bool getFilterZeroWidth(le_int32 scriptCode);
135
136 static le_int32 reorder(const LEUnicode *theChars, le_int32 charCount, le_int32 scriptCode,
137 LEUnicode *outChars, LEGlyphStorage &glyphStorage,
138 MPreFixups **outMPreFixups);
139
140 static void adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage);
141
142 static const FeatureMap *getFeatureMap(le_int32 &count);
143
144 private:
145 // do not instantiate
146 IndicReordering();
147
148 static le_int32 findSyllable(const IndicClassTable *classTable, const LEUnicode *chars, le_int32 prev, le_int32 charCount);
149
150 };
151
152 inline le_int32 IndicClassTable::getWorstCaseExpansion() const
153 {
154 return worstCaseExpansion;
155 }
156
157 inline le_bool IndicClassTable::getFilterZeroWidth() const
158 {
159 return (scriptFlags & SF_FILTER_ZERO_WIDTH) != 0;
160 }
161
162 inline const SplitMatra *IndicClassTable::getSplitMatra(CharClass charClass) const
163 {
164 le_int32 index = (charClass & CF_INDEX_MASK) >> CF_INDEX_SHIFT;
165
166 return &splitMatraTable[index - 1];
167 }
168
169 inline le_bool IndicClassTable::isVowelModifier(CharClass charClass)
170 {
171 return (charClass & CF_CLASS_MASK) == CC_VOWEL_MODIFIER;
172 }
173
174 inline le_bool IndicClassTable::isStressMark(CharClass charClass)
175 {
176 return (charClass & CF_CLASS_MASK) == CC_STRESS_MARK;
177 }
178
179 inline le_bool IndicClassTable::isConsonant(CharClass charClass)
180 {
181 return (charClass & CF_CONSONANT) != 0;
182 }
183
184 inline le_bool IndicClassTable::isReph(CharClass charClass)
185 {
186 return (charClass & CF_REPH) != 0;
187 }
188
189 inline le_bool IndicClassTable::isNukta(CharClass charClass)
190 {
191 return (charClass & CF_CLASS_MASK) == CC_NUKTA;
192 }
193
194 inline le_bool IndicClassTable::isVirama(CharClass charClass)
195 {
196 return (charClass & CF_CLASS_MASK) == CC_VIRAMA;
197 }
198
199 inline le_bool IndicClassTable::isAlLakuna(CharClass charClass)
200 {
201 return (charClass & CF_CLASS_MASK) == CC_AL_LAKUNA;
202 }
203
204 inline le_bool IndicClassTable::isVattu(CharClass charClass)
205 {
206 return (charClass & CF_VATTU) != 0;
207 }
208
209 inline le_bool IndicClassTable::isMatra(CharClass charClass)
210 {
211 charClass &= CF_CLASS_MASK;
212
213 return charClass >= CC_DEPENDENT_VOWEL && charClass <= CC_SPLIT_VOWEL_PIECE_3;
214 }
215
216 inline le_bool IndicClassTable::isSplitMatra(CharClass charClass)
217 {
218 return (charClass & CF_INDEX_MASK) != 0;
219 }
220
221 inline le_bool IndicClassTable::isLengthMark(CharClass charClass)
222 {
223 return (charClass & CF_LENGTH_MARK) != 0;
224 }
225
226 inline le_bool IndicClassTable::hasPostOrBelowBaseForm(CharClass charClass)
227 {
228 return (charClass & (CF_POST_BASE | CF_BELOW_BASE)) != 0;
229 }
230
231 inline le_bool IndicClassTable::hasPostBaseForm(CharClass charClass)
232 {
233 return (charClass & CF_POST_BASE) != 0;
234 }
235
236 inline le_bool IndicClassTable::hasBelowBaseForm(CharClass charClass)
237 {
238 return (charClass & CF_BELOW_BASE) != 0;
239 }
240
241 inline le_bool IndicClassTable::isVowelModifier(LEUnicode ch) const
242 {
243 return isVowelModifier(getCharClass(ch));
244 }
245
246 inline le_bool IndicClassTable::isStressMark(LEUnicode ch) const
247 {
248 return isStressMark(getCharClass(ch));
249 }
250
251 inline le_bool IndicClassTable::isConsonant(LEUnicode ch) const
252 {
253 return isConsonant(getCharClass(ch));
254 }
255
256 inline le_bool IndicClassTable::isReph(LEUnicode ch) const
257 {
258 return isReph(getCharClass(ch));
259 }
260
261 inline le_bool IndicClassTable::isVirama(LEUnicode ch) const
262 {
263 return isVirama(getCharClass(ch));
264 }
265
266 inline le_bool IndicClassTable::isAlLakuna(LEUnicode ch) const
267 {
268 return isAlLakuna(getCharClass(ch));
269 }
270
271 inline le_bool IndicClassTable::isNukta(LEUnicode ch) const
272 {
273 return isNukta(getCharClass(ch));
274 }
275
276 inline le_bool IndicClassTable::isVattu(LEUnicode ch) const
277 {
278 return isVattu(getCharClass(ch));
279 }
280
281 inline le_bool IndicClassTable::isMatra(LEUnicode ch) const
282 {
283 return isMatra(getCharClass(ch));
284 }
285
286 inline le_bool IndicClassTable::isSplitMatra(LEUnicode ch) const
287 {
288 return isSplitMatra(getCharClass(ch));
289 }
290
291 inline le_bool IndicClassTable::isLengthMark(LEUnicode ch) const
292 {
293 return isLengthMark(getCharClass(ch));
294 }
295
296 inline le_bool IndicClassTable::hasPostOrBelowBaseForm(LEUnicode ch) const
297 {
298 return hasPostOrBelowBaseForm(getCharClass(ch));
299 }
300
301 inline le_bool IndicClassTable::hasPostBaseForm(LEUnicode ch) const
302 {
303 return hasPostBaseForm(getCharClass(ch));
304 }
305
306 inline le_bool IndicClassTable::hasBelowBaseForm(LEUnicode ch) const
307 {
308 return hasBelowBaseForm(getCharClass(ch));
309 }
310
311 U_NAMESPACE_END
312 #endif