]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
3 | * | |
4 | * Copyright (C) 1999-2001, International Business Machines | |
5 | * Corporation and others. All Rights Reserved. | |
6 | * | |
7 | ****************************************************************************** | |
8 | * file name: ubidiimp.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 1999aug06 | |
14 | * created by: Markus W. Scherer | |
15 | */ | |
16 | ||
17 | #ifndef UBIDIIMP_H | |
18 | #define UBIDIIMP_H | |
19 | ||
20 | /* set import/export definitions */ | |
21 | #ifdef U_COMMON_IMPLEMENTATION | |
22 | ||
23 | #include "unicode/utypes.h" | |
24 | #include "unicode/uchar.h" | |
25 | ||
26 | /* miscellaneous definitions ---------------------------------------------- */ | |
27 | ||
28 | typedef uint8_t DirProp; | |
29 | typedef uint32_t Flags; | |
30 | ||
31 | /* Comparing the description of the BiDi algorithm with this implementation | |
32 | is easier with the same names for the BiDi types in the code as there. | |
33 | See UCharDirection in uchar.h . | |
34 | */ | |
35 | enum { | |
36 | L= U_LEFT_TO_RIGHT, | |
37 | R= U_RIGHT_TO_LEFT, | |
38 | EN= U_EUROPEAN_NUMBER, | |
39 | ES= U_EUROPEAN_NUMBER_SEPARATOR, | |
40 | ET= U_EUROPEAN_NUMBER_TERMINATOR, | |
41 | AN= U_ARABIC_NUMBER, | |
42 | CS= U_COMMON_NUMBER_SEPARATOR, | |
43 | B= U_BLOCK_SEPARATOR, | |
44 | S= U_SEGMENT_SEPARATOR, | |
45 | WS= U_WHITE_SPACE_NEUTRAL, | |
46 | ON= U_OTHER_NEUTRAL, | |
47 | LRE=U_LEFT_TO_RIGHT_EMBEDDING, | |
48 | LRO=U_LEFT_TO_RIGHT_OVERRIDE, | |
49 | AL= U_RIGHT_TO_LEFT_ARABIC, | |
50 | RLE=U_RIGHT_TO_LEFT_EMBEDDING, | |
51 | RLO=U_RIGHT_TO_LEFT_OVERRIDE, | |
52 | PDF=U_POP_DIRECTIONAL_FORMAT, | |
53 | NSM=U_DIR_NON_SPACING_MARK, | |
54 | BN= U_BOUNDARY_NEUTRAL, | |
55 | dirPropCount | |
56 | }; | |
57 | ||
58 | /* | |
59 | * Sometimes, bit values are more appropriate | |
60 | * to deal with directionality properties. | |
61 | * Abbreviations in these macro names refer to names | |
62 | * used in the BiDi algorithm. | |
63 | */ | |
64 | #define DIRPROP_FLAG(dir) (1UL<<(dir)) | |
65 | ||
66 | /* special flag for multiple runs from explicit embedding codes */ | |
67 | #define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) | |
68 | ||
69 | /* are there any characters that are LTR or RTL? */ | |
70 | #define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) | |
71 | #define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) | |
72 | ||
73 | /* explicit embedding codes */ | |
74 | #define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) | |
75 | #define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) | |
76 | #define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO)) | |
77 | ||
78 | #define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF)) | |
79 | #define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) | |
80 | ||
81 | /* paragraph and segment separators */ | |
82 | #define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) | |
83 | ||
84 | /* all types that are counted as White Space or Neutral in some steps */ | |
85 | #define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT) | |
86 | #define MASK_N (DIRPROP_FLAG(ON)|MASK_WS) | |
87 | ||
88 | /* all types that are included in a sequence of European Terminators for (W5) */ | |
89 | #define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT) | |
90 | ||
91 | /* types that are neutrals or could becomes neutrals in (Wn) */ | |
92 | #define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N) | |
93 | ||
94 | /* | |
95 | * These types may be changed to "e", | |
96 | * the embedding type (L or R) of the run, | |
97 | * in the BiDi algorithm (N2) | |
98 | */ | |
99 | #define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) | |
100 | ||
101 | /* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */ | |
102 | #define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) | |
103 | ||
104 | #define IS_DEFAULT_LEVEL(level) (((level)&0xfe)==0xfe) | |
105 | ||
106 | /* Run structure for reordering --------------------------------------------- */ | |
107 | ||
108 | typedef struct Run { | |
109 | int32_t logicalStart, /* first character of the run; b31 indicates even/odd level */ | |
110 | visualLimit; /* last visual position of the run +1 */ | |
111 | } Run; | |
112 | ||
113 | /* in a Run, logicalStart will get this bit set if the run level is odd */ | |
114 | #define INDEX_ODD_BIT (1UL<<31) | |
115 | ||
116 | #define MAKE_INDEX_ODD_PAIR(index, level) (index|((int32_t)level<<31)) | |
117 | #define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((int32_t)level<<31)) | |
118 | #define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT) | |
119 | ||
120 | #define GET_INDEX(x) (x&~INDEX_ODD_BIT) | |
121 | #define GET_ODD_BIT(x) ((uint32_t)x>>31) | |
122 | #define IS_ODD_RUN(x) ((x&INDEX_ODD_BIT)!=0) | |
123 | #define IS_EVEN_RUN(x) ((x&INDEX_ODD_BIT)==0) | |
124 | ||
125 | U_CFUNC UBool | |
126 | ubidi_getRuns(UBiDi *pBiDi); | |
127 | ||
128 | /* UBiDi structure ----------------------------------------------------------- */ | |
129 | ||
130 | struct UBiDi { | |
131 | /* alias pointer to the current text */ | |
132 | const UChar *text; | |
133 | ||
134 | /* length of the current text */ | |
135 | int32_t length; | |
136 | ||
137 | /* memory sizes in bytes */ | |
138 | int32_t dirPropsSize, levelsSize, runsSize; | |
139 | ||
140 | /* allocated memory */ | |
141 | DirProp *dirPropsMemory; | |
142 | UBiDiLevel *levelsMemory; | |
143 | Run *runsMemory; | |
144 | ||
145 | /* indicators for whether memory may be allocated after ubidi_open() */ | |
146 | UBool mayAllocateText, mayAllocateRuns; | |
147 | ||
148 | /* arrays with one value per text-character */ | |
149 | const DirProp *dirProps; | |
150 | UBiDiLevel *levels; | |
151 | ||
152 | /* are we performing an approximation of the "inverse BiDi" algorithm? */ | |
153 | UBool isInverse; | |
154 | ||
155 | /* the paragraph level */ | |
156 | UBiDiLevel paraLevel; | |
157 | ||
158 | /* the overall paragraph or line directionality - see UBiDiDirection */ | |
159 | UBiDiDirection direction; | |
160 | ||
161 | /* flags is a bit set for which directional properties are in the text */ | |
162 | Flags flags; | |
163 | ||
164 | /* characters after trailingWSStart are WS and are */ | |
165 | /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ | |
166 | int32_t trailingWSStart; | |
167 | ||
168 | /* fields for line reordering */ | |
169 | int32_t runCount; /* ==-1: runs not set up yet */ | |
170 | Run *runs; | |
171 | ||
172 | /* for non-mixed text, we only need a tiny array of runs (no malloc()) */ | |
173 | Run simpleRuns[1]; | |
174 | }; | |
175 | ||
176 | /* helper function to (re)allocate memory if allowed */ | |
177 | U_CFUNC UBool | |
178 | ubidi_getMemory(void **pMemory, int32_t *pSize, UBool mayAllocate, int32_t sizeNeeded); | |
179 | ||
180 | /* helper macros for each allocated array in UBiDi */ | |
181 | #define getDirPropsMemory(pBiDi, length) \ | |
182 | ubidi_getMemory((void **)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \ | |
183 | (pBiDi)->mayAllocateText, (length)) | |
184 | ||
185 | #define getLevelsMemory(pBiDi, length) \ | |
186 | ubidi_getMemory((void **)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \ | |
187 | (pBiDi)->mayAllocateText, (length)) | |
188 | ||
189 | #define getRunsMemory(pBiDi, length) \ | |
190 | ubidi_getMemory((void **)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \ | |
191 | (pBiDi)->mayAllocateRuns, (length)*sizeof(Run)) | |
192 | ||
193 | /* additional macros used by ubidi_open() - always allow allocation */ | |
194 | #define getInitialDirPropsMemory(pBiDi, length) \ | |
195 | ubidi_getMemory((void **)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \ | |
196 | TRUE, (length)) | |
197 | ||
198 | #define getInitialLevelsMemory(pBiDi, length) \ | |
199 | ubidi_getMemory((void **)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \ | |
200 | TRUE, (length)) | |
201 | ||
202 | #define getInitialRunsMemory(pBiDi, length) \ | |
203 | ubidi_getMemory((void **)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \ | |
204 | TRUE, (length)*sizeof(Run)) | |
205 | ||
206 | #endif | |
207 | ||
208 | #endif |