summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu/icu-49.1/layout/IndicReordering.h
blob: 4d61c525220afc2a15a5cc11e06ad1f08e8b29da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
 *
 * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved
 *
 */

#ifndef __INDICREORDERING_H
#define __INDICREORDERING_H

/**
 * \file
 * \internal
 */

#include "LETypes.h"
#include "OpenTypeTables.h"

U_NAMESPACE_BEGIN

// Characters that get refered to by name...
#define C_SIGN_ZWNJ           0x200C
#define C_SIGN_ZWJ            0x200D

// Character class values
#define CC_RESERVED               0U
#define CC_VOWEL_MODIFIER         1U
#define CC_STRESS_MARK            2U
#define CC_INDEPENDENT_VOWEL      3U
#define CC_INDEPENDENT_VOWEL_2    4U
#define CC_INDEPENDENT_VOWEL_3    5U
#define CC_CONSONANT              6U
#define CC_CONSONANT_WITH_NUKTA   7U
#define CC_NUKTA                  8U
#define CC_DEPENDENT_VOWEL        9U
#define CC_SPLIT_VOWEL_PIECE_1   10U
#define CC_SPLIT_VOWEL_PIECE_2   11U
#define CC_SPLIT_VOWEL_PIECE_3   12U
#define CC_VIRAMA                13U
#define CC_ZERO_WIDTH_MARK       14U
#define CC_AL_LAKUNA             15U
#define CC_COUNT                 16U

// Character class flags
#define CF_CLASS_MASK    0x0000FFFFU

#define CF_CONSONANT     0x80000000U

#define CF_REPH          0x40000000U
#define CF_VATTU         0x20000000U
#define CF_BELOW_BASE    0x10000000U
#define CF_POST_BASE     0x08000000U
#define CF_LENGTH_MARK   0x04000000U

#define CF_POS_BEFORE    0x00300000U
#define CF_POS_BELOW     0x00200000U
#define CF_POS_ABOVE     0x00100000U
#define CF_POS_AFTER     0x00000000U
#define CF_POS_MASK      0x00300000U

#define CF_INDEX_MASK    0x000F0000U
#define CF_INDEX_SHIFT   16

// Script flag bits
#define SF_MATRAS_AFTER_BASE     0x80000000U
#define SF_REPH_AFTER_BELOW      0x40000000U
#define SF_EYELASH_RA            0x20000000U
#define SF_MPRE_FIXUP            0x10000000U
#define SF_FILTER_ZERO_WIDTH     0x08000000U

#define SF_POST_BASE_LIMIT_MASK  0x0000FFFFU
#define SF_NO_POST_BASE_LIMIT    0x00007FFFU

#define SM_MAX_PIECES 3

typedef LEUnicode SplitMatra[SM_MAX_PIECES];

class MPreFixups;
class LEGlyphStorage;

// Dynamic Properties ( v2 fonts only )
typedef le_uint32 DynamicProperties;

#define DP_REPH               0x80000000U
#define DP_HALF               0x40000000U
#define DP_PREF               0x20000000U
#define DP_BLWF               0x10000000U
#define DP_PSTF               0x08000000U

struct IndicClassTable
{
    typedef le_uint32 CharClass;
    typedef le_uint32 ScriptFlags;
    
    LEUnicode firstChar;
    LEUnicode lastChar;
    le_int32 worstCaseExpansion;
    ScriptFlags scriptFlags;
    const CharClass *classTable;
    const SplitMatra *splitMatraTable;

    inline le_int32 getWorstCaseExpansion() const;
    inline le_bool getFilterZeroWidth() const;

    CharClass getCharClass(LEUnicode ch) const;

    inline const SplitMatra *getSplitMatra(CharClass charClass) const;

    inline le_bool isVowelModifier(LEUnicode ch) const;
    inline le_bool isStressMark(LEUnicode ch) const;
    inline le_bool isConsonant(LEUnicode ch) const;
    inline le_bool isReph(LEUnicode ch) const;
    inline le_bool isVirama(LEUnicode ch) const;
    inline le_bool isAlLakuna(LEUnicode ch) const;
    inline le_bool isNukta(LEUnicode ch) const;
    inline le_bool isVattu(LEUnicode ch) const;
    inline le_bool isMatra(LEUnicode ch) const;
    inline le_bool isSplitMatra(LEUnicode ch) const;
    inline le_bool isLengthMark(LEUnicode ch) const;
    inline le_bool hasPostOrBelowBaseForm(LEUnicode ch) const;
    inline le_bool hasPostBaseForm(LEUnicode ch) const;
    inline le_bool hasBelowBaseForm(LEUnicode ch) const;
    inline le_bool hasAboveBaseForm(LEUnicode ch) const;

    inline static le_bool isVowelModifier(CharClass charClass);
    inline static le_bool isStressMark(CharClass charClass);
    inline static le_bool isConsonant(CharClass charClass);
    inline static le_bool isReph(CharClass charClass);
    inline static le_bool isVirama(CharClass charClass);
    inline static le_bool isAlLakuna(CharClass charClass);
    inline static le_bool isNukta(CharClass charClass);
    inline static le_bool isVattu(CharClass charClass);
    inline static le_bool isMatra(CharClass charClass);
    inline static le_bool isSplitMatra(CharClass charClass);
    inline static le_bool isLengthMark(CharClass charClass);
    inline static le_bool hasPostOrBelowBaseForm(CharClass charClass);
    inline static le_bool hasPostBaseForm(CharClass charClass);
    inline static le_bool hasBelowBaseForm(CharClass charClass);
    inline static le_bool hasAboveBaseForm(CharClass charClass);

    static const IndicClassTable *getScriptClassTable(le_int32 scriptCode);
};

class IndicReordering /* not : public UObject because all methods are static */ {
public:
    static le_int32 getWorstCaseExpansion(le_int32 scriptCode);

    static le_bool getFilterZeroWidth(le_int32 scriptCode);

    static le_int32 reorder(const LEUnicode *theChars, le_int32 charCount, le_int32 scriptCode,
        LEUnicode *outChars, LEGlyphStorage &glyphStorage,
        MPreFixups **outMPreFixups, LEErrorCode& success);

    static void adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage, LEErrorCode& success);

    static le_int32 v2process(const LEUnicode *theChars, le_int32 charCount, le_int32 scriptCode,
        LEUnicode *outChars, LEGlyphStorage &glyphStorage);

    static const FeatureMap *getFeatureMap(le_int32 &count);

	static const FeatureMap *getv2FeatureMap(le_int32 &count);

    static void applyPresentationForms(LEGlyphStorage &glyphStorage, le_int32 count);

    static void finalReordering(LEGlyphStorage &glyphStorage, le_int32 count);

    static void getDynamicProperties(DynamicProperties *dProps, const IndicClassTable *classTable);

private:
    // do not instantiate
    IndicReordering();

    static le_int32 findSyllable(const IndicClassTable *classTable, const LEUnicode *chars, le_int32 prev, le_int32 charCount);

};

inline le_int32 IndicClassTable::getWorstCaseExpansion() const
{
    return worstCaseExpansion;
}

inline le_bool IndicClassTable::getFilterZeroWidth() const
{
    return (scriptFlags & SF_FILTER_ZERO_WIDTH) != 0;
}

inline const SplitMatra *IndicClassTable::getSplitMatra(CharClass charClass) const
{
    le_int32 index = (charClass & CF_INDEX_MASK) >> CF_INDEX_SHIFT;

    return &splitMatraTable[index - 1];
}

inline le_bool IndicClassTable::isVowelModifier(CharClass charClass)
{
    return (charClass & CF_CLASS_MASK) == CC_VOWEL_MODIFIER;
}

inline le_bool IndicClassTable::isStressMark(CharClass charClass)
{
    return (charClass & CF_CLASS_MASK) == CC_STRESS_MARK;
}

inline le_bool IndicClassTable::isConsonant(CharClass charClass)
{
    return (charClass & CF_CONSONANT) != 0;
}

inline le_bool IndicClassTable::isReph(CharClass charClass)
{
    return (charClass & CF_REPH) != 0;
}

inline le_bool IndicClassTable::isNukta(CharClass charClass)
{
    return (charClass & CF_CLASS_MASK) == CC_NUKTA;
}

inline le_bool IndicClassTable::isVirama(CharClass charClass)
{
    return (charClass & CF_CLASS_MASK) == CC_VIRAMA;
}

inline le_bool IndicClassTable::isAlLakuna(CharClass charClass)
{
    return (charClass & CF_CLASS_MASK) == CC_AL_LAKUNA;
}

inline le_bool IndicClassTable::isVattu(CharClass charClass)
{
    return (charClass & CF_VATTU) != 0;
}

inline le_bool IndicClassTable::isMatra(CharClass charClass)
{
    charClass &= CF_CLASS_MASK;

    return charClass >= CC_DEPENDENT_VOWEL && charClass <= CC_SPLIT_VOWEL_PIECE_3;
}

inline le_bool IndicClassTable::isSplitMatra(CharClass charClass)
{
    return (charClass & CF_INDEX_MASK) != 0;
}

inline le_bool IndicClassTable::isLengthMark(CharClass charClass)
{
    return (charClass & CF_LENGTH_MARK) != 0;
}

inline le_bool IndicClassTable::hasPostOrBelowBaseForm(CharClass charClass)
{
    return (charClass & (CF_POST_BASE | CF_BELOW_BASE)) != 0;
}

inline le_bool IndicClassTable::hasPostBaseForm(CharClass charClass)
{
    return (charClass & CF_POST_BASE) != 0;
}

inline le_bool IndicClassTable::hasBelowBaseForm(CharClass charClass)
{
    return (charClass & CF_BELOW_BASE) != 0;
}

inline le_bool IndicClassTable::hasAboveBaseForm(CharClass charClass)
{
    return ((charClass & CF_POS_MASK) == CF_POS_ABOVE);
}

inline le_bool IndicClassTable::isVowelModifier(LEUnicode ch) const
{
    return isVowelModifier(getCharClass(ch));
}

inline le_bool IndicClassTable::isStressMark(LEUnicode ch) const
{
    return isStressMark(getCharClass(ch));
}

inline le_bool IndicClassTable::isConsonant(LEUnicode ch) const
{
    return isConsonant(getCharClass(ch));
}

inline le_bool IndicClassTable::isReph(LEUnicode ch) const
{
    return isReph(getCharClass(ch));
}

inline le_bool IndicClassTable::isVirama(LEUnicode ch) const
{
    return isVirama(getCharClass(ch));
}

inline le_bool IndicClassTable::isAlLakuna(LEUnicode ch) const
{
    return isAlLakuna(getCharClass(ch));
}

inline le_bool IndicClassTable::isNukta(LEUnicode ch) const
{
    return isNukta(getCharClass(ch));
}

inline le_bool IndicClassTable::isVattu(LEUnicode ch) const
{
    return isVattu(getCharClass(ch));
}

inline le_bool IndicClassTable::isMatra(LEUnicode ch) const
{
    return isMatra(getCharClass(ch));
}

inline le_bool IndicClassTable::isSplitMatra(LEUnicode ch) const
{
    return isSplitMatra(getCharClass(ch));
}

inline le_bool IndicClassTable::isLengthMark(LEUnicode ch) const
{
    return isLengthMark(getCharClass(ch));
}

inline le_bool IndicClassTable::hasPostOrBelowBaseForm(LEUnicode ch) const
{
    return hasPostOrBelowBaseForm(getCharClass(ch));
}

inline le_bool IndicClassTable::hasPostBaseForm(LEUnicode ch) const
{
    return hasPostBaseForm(getCharClass(ch));
}

inline le_bool IndicClassTable::hasBelowBaseForm(LEUnicode ch) const
{
    return hasBelowBaseForm(getCharClass(ch));
}

inline le_bool IndicClassTable::hasAboveBaseForm(LEUnicode ch) const
{
    return hasAboveBaseForm(getCharClass(ch));
}
U_NAMESPACE_END
#endif