| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1999-2013, International Business Machines | 4 * Copyright (C) 1999-2014, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * file name: ubidiimp.h | 8 * file name: ubidiimp.h |
| 9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
| 10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
| 11 * indentation:4 | 11 * indentation:4 |
| 12 * | 12 * |
| 13 * created on: 1999aug06 | 13 * created on: 1999aug06 |
| 14 * created by: Markus W. Scherer, updated by Matitiahu Allouche | 14 * created by: Markus W. Scherer, updated by Matitiahu Allouche |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 #ifndef UBIDIIMP_H | 17 #ifndef UBIDIIMP_H |
| 18 #define UBIDIIMP_H | 18 #define UBIDIIMP_H |
| 19 | 19 |
| 20 /* set import/export definitions */ | 20 /* set import/export definitions */ |
| 21 #ifdef U_COMMON_IMPLEMENTATION | 21 #ifdef U_COMMON_IMPLEMENTATION |
| 22 | 22 |
| 23 #include "unicode/utypes.h" | 23 #include "unicode/utypes.h" |
| 24 #include "unicode/uchar.h" | 24 #include "unicode/uchar.h" |
| 25 #include "ubidi_props.h" | 25 #include "ubidi_props.h" |
| 26 | 26 |
| 27 /* miscellaneous definitions ---------------------------------------------- */ | 27 /* miscellaneous definitions ---------------------------------------------- */ |
| 28 | 28 |
| 29 typedef uint8_t DirProp; | 29 typedef uint8_t DirProp; |
| 30 typedef uint32_t Flags; | 30 typedef uint32_t Flags; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 AL= U_RIGHT_TO_LEFT_ARABIC, /* 13 */ | 50 AL= U_RIGHT_TO_LEFT_ARABIC, /* 13 */ |
| 51 RLE=U_RIGHT_TO_LEFT_EMBEDDING, /* 14 */ | 51 RLE=U_RIGHT_TO_LEFT_EMBEDDING, /* 14 */ |
| 52 RLO=U_RIGHT_TO_LEFT_OVERRIDE, /* 15 */ | 52 RLO=U_RIGHT_TO_LEFT_OVERRIDE, /* 15 */ |
| 53 PDF=U_POP_DIRECTIONAL_FORMAT, /* 16 */ | 53 PDF=U_POP_DIRECTIONAL_FORMAT, /* 16 */ |
| 54 NSM=U_DIR_NON_SPACING_MARK, /* 17 */ | 54 NSM=U_DIR_NON_SPACING_MARK, /* 17 */ |
| 55 BN= U_BOUNDARY_NEUTRAL, /* 18 */ | 55 BN= U_BOUNDARY_NEUTRAL, /* 18 */ |
| 56 FSI=U_FIRST_STRONG_ISOLATE, /* 19 */ | 56 FSI=U_FIRST_STRONG_ISOLATE, /* 19 */ |
| 57 LRI=U_LEFT_TO_RIGHT_ISOLATE, /* 20 */ | 57 LRI=U_LEFT_TO_RIGHT_ISOLATE, /* 20 */ |
| 58 RLI=U_RIGHT_TO_LEFT_ISOLATE, /* 21 */ | 58 RLI=U_RIGHT_TO_LEFT_ISOLATE, /* 21 */ |
| 59 PDI=U_POP_DIRECTIONAL_ISOLATE, /* 22 */ | 59 PDI=U_POP_DIRECTIONAL_ISOLATE, /* 22 */ |
| 60 ENL, /* 23 */ | 60 ENL, /* EN after W7 */ /* 23 */ |
| 61 ENR, /* 24 */ | 61 ENR, /* EN not subject to W7 */ /* 24 */ |
| 62 dirPropCount | 62 dirPropCount |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 /* | 65 /* Sometimes, bit values are more appropriate |
| 66 * Sometimes, bit values are more appropriate | 66 to deal with directionality properties. |
| 67 * to deal with directionality properties. | 67 Abbreviations in these macro names refer to names |
| 68 * Abbreviations in these macro names refer to names | 68 used in the BiDi algorithm. |
| 69 * used in the BiDi algorithm. | 69 */ |
| 70 */ | |
| 71 #define DIRPROP_FLAG(dir) (1UL<<(dir)) | 70 #define DIRPROP_FLAG(dir) (1UL<<(dir)) |
| 71 #define PURE_DIRPROP(prop) ((prop)&~0xE0) ????????????????????????? |
| 72 | 72 |
| 73 /* special flag for multiple runs from explicit embedding codes */ | 73 /* special flag for multiple runs from explicit embedding codes */ |
| 74 #define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) | 74 #define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) |
| 75 | 75 |
| 76 /* are there any characters that are LTR or RTL? */ | 76 /* are there any characters that are LTR or RTL? */ |
| 77 #define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG
(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(LRI)) | 77 #define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(ENL)|DIRPROP_FLA
G(ENR)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(LRI)) |
| 78 #define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLA
G(RLO)|DIRPROP_FLAG(RLI)) | 78 #define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLA
G(RLO)|DIRPROP_FLAG(RLI)) |
| 79 #define MASK_R_AL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)) | 79 #define MASK_R_AL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)) |
| 80 #define MASK_STRONG_EN_AN (DIRPROP_FLAG(L)|DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRP
ROP_FLAG(EN)|DIRPROP_FLAG(AN)) | 80 #define MASK_STRONG_EN_AN (DIRPROP_FLAG(L)|DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRP
ROP_FLAG(EN)|DIRPROP_FLAG(AN)) |
| 81 | 81 |
| 82 /* explicit embedding codes */ | 82 /* explicit embedding codes */ |
| 83 #define MASK_EXPLICIT (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLE)|DIR
PROP_FLAG(RLO)|DIRPROP_FLAG(PDF)) | 83 #define MASK_EXPLICIT (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLE)|DIR
PROP_FLAG(RLO)|DIRPROP_FLAG(PDF)) |
| 84 | 84 |
| 85 /* explicit isolate codes */ | 85 /* explicit isolate codes */ |
| 86 #define MASK_ISO (DIRPROP_FLAG(LRI)|DIRPROP_FLAG(RLI)|DIRPROP_FLAG(FSI)|DIRPROP_
FLAG(PDI)) | 86 #define MASK_ISO (DIRPROP_FLAG(LRI)|DIRPROP_FLAG(RLI)|DIRPROP_FLAG(FSI)|DIRPROP_
FLAG(PDI)) |
| 87 | 87 |
| 88 #define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) | 88 #define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) |
| 89 | 89 |
| 90 /* paragraph and segment separators */ | 90 /* paragraph and segment separators */ |
| 91 #define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) | 91 #define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) |
| 92 | 92 |
| 93 /* all types that are counted as White Space or Neutral in some steps */ | 93 /* all types that are counted as White Space or Neutral in some steps */ |
| 94 #define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT|MASK_ISO) | 94 #define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT|MASK_ISO) |
| 95 | 95 |
| 96 /* types that are neutrals or could becomes neutrals in (Wn) */ | 96 /* types that are neutrals or could becomes neutrals in (Wn) */ |
| 97 #define MASK_POSSIBLE_N (DIRPROP_FLAG(ON)|DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRP
ROP_FLAG(ET)|MASK_WS) | 97 #define MASK_POSSIBLE_N (DIRPROP_FLAG(ON)|DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRP
ROP_FLAG(ET)|MASK_WS) |
| 98 | 98 |
| 99 /* | 99 /* |
| 100 * These types may be changed to "e", | 100 * These types may be changed to "e", |
| 101 * the embedding type (L or R) of the run, | 101 * the embedding type (L or R) of the run, |
| 102 * in the BiDi algorithm (N2) | 102 * in the BiDi algorithm (N2) |
| 103 */ | 103 */ |
| 104 #define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) | 104 #define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) |
| 105 | 105 |
| 106 /* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */ | 106 /* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */ |
| 107 #define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) | 107 #define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) |
| 108 | 108 |
| 109 #define IS_DEFAULT_LEVEL(level) ((level)>=0xfe) | 109 #define IS_DEFAULT_LEVEL(level) ((level)>=0xfe) |
| 110 | 110 |
| 111 /* | 111 /* |
| 112 * The following bit is ORed to the property of directional control | 112 * The following bit is used for the directional isolate status. |
| 113 * characters which are ignored: unmatched PDF or PDI; LRx, RLx or FSI | 113 * Stack entries corresponding to isolate sequences are greater than ISOLATE. |
| 114 * which would exceed the maximum explicit bidi level. | |
| 115 */ | |
| 116 #define IGNORE_CC 0x40 | |
| 117 | |
| 118 #define PURE_DIRPROP(prop) ((prop)&~IGNORE_CC) | |
| 119 | |
| 120 /* | |
| 121 * The following bit is used for the directional isolate status. | |
| 122 * Stack entries corresponding to isolate sequences are greater than ISOLATE. | |
| 123 */ | 114 */ |
| 124 #define ISOLATE 0x0100 | 115 #define ISOLATE 0x0100 |
| 125 | 116 |
| 126 U_CFUNC UBiDiLevel | 117 U_CFUNC UBiDiLevel |
| 127 ubidi_getParaLevelAtIndex(const UBiDi *pBiDi, int32_t index); | 118 ubidi_getParaLevelAtIndex(const UBiDi *pBiDi, int32_t index); |
| 128 | 119 |
| 129 #define GET_PARALEVEL(ubidi, index) \ | 120 #define GET_PARALEVEL(ubidi, index) \ |
| 130 ((UBiDiLevel)(!(ubidi)->defaultParaLevel || (index)<(ubidi)->paras[0
].limit ? \ | 121 ((UBiDiLevel)(!(ubidi)->defaultParaLevel || (index)<(ubidi)->paras[0
].limit ? \ |
| 131 (ubidi)->paraLevel : ubidi_getParaLevelAtIndex((ubidi),
(index)))) | 122 (ubidi)->paraLevel : ubidi_getParaLevelAtIndex((ubidi),
(index)))) |
| 132 | 123 |
| 133 /* number of paras entries allocated initially without malloc */ | 124 /* number of paras entries allocated initially without malloc */ |
| 134 #define SIMPLE_PARAS_SIZE 10 | 125 #define SIMPLE_PARAS_COUNT 10 |
| 135 /* number of isolate entries allocated initially without malloc */ | 126 /* number of isolate entries allocated initially without malloc */ |
| 136 #define SIMPLE_ISOLATES_SIZE 5 | 127 #define SIMPLE_ISOLATES_COUNT 5 |
| 137 /* number of isolate run entries for paired brackets allocated initially without
malloc */ | 128 /* number of isolate run entries for paired brackets allocated initially without
malloc */ |
| 138 #define SIMPLE_OPENINGS_SIZE 20 | 129 #define SIMPLE_OPENINGS_COUNT 20 |
| 139 | 130 |
| 140 #define CR 0x000D | 131 #define CR 0x000D |
| 141 #define LF 0x000A | 132 #define LF 0x000A |
| 142 | 133 |
| 143 /* Run structure for reordering --------------------------------------------- */ | 134 /* Run structure for reordering --------------------------------------------- */ |
| 144 enum { | 135 enum { |
| 145 LRM_BEFORE=1, | 136 LRM_BEFORE=1, |
| 146 LRM_AFTER=2, | 137 LRM_AFTER=2, |
| 147 RLM_BEFORE=4, | 138 RLM_BEFORE=4, |
| 148 RLM_AFTER=8 | 139 RLM_AFTER=8 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 161 typedef struct Opening { | 152 typedef struct Opening { |
| 162 int32_t position; /* position of opening bracket */ | 153 int32_t position; /* position of opening bracket */ |
| 163 int32_t match; /* matching char or -position of closing
bracket */ | 154 int32_t match; /* matching char or -position of closing
bracket */ |
| 164 int32_t contextPos; /* position of last strong char found be
fore opening */ | 155 int32_t contextPos; /* position of last strong char found be
fore opening */ |
| 165 uint16_t flags; /* bits for L or R/AL found within the p
air */ | 156 uint16_t flags; /* bits for L or R/AL found within the p
air */ |
| 166 UBiDiDirection contextDir; /* L or R according to last strong char
before opening */ | 157 UBiDiDirection contextDir; /* L or R according to last strong char
before opening */ |
| 167 uint8_t filler; /* to complete a nice multiple of 4 char
s */ | 158 uint8_t filler; /* to complete a nice multiple of 4 char
s */ |
| 168 } Opening; | 159 } Opening; |
| 169 | 160 |
| 170 typedef struct IsoRun { | 161 typedef struct IsoRun { |
| 171 int32_t lastStrongPos; /* position of last strong char found in
this run */ | 162 int32_t contextPos; /* position of char determining context
*/ |
| 172 int32_t contextPos; /* position of last char defining contex
t */ | |
| 173 uint16_t start; /* index of first opening entry for this
run */ | 163 uint16_t start; /* index of first opening entry for this
run */ |
| 174 uint16_t limit; /* index after last opening entry for th
is run */ | 164 uint16_t limit; /* index after last opening entry for th
is run */ |
| 175 UBiDiLevel level; /* level of this run */ | 165 UBiDiLevel level; /* level of this run */ |
| 176 DirProp lastStrong; /* bidi class of last strong char found
in this run */ | 166 DirProp lastStrong; /* bidi class of last strong char found
in this run */ |
| 167 DirProp lastBase; /* bidi class of last base char found in
this run */ |
| 177 UBiDiDirection contextDir; /* L or R to use as context for followin
g openings */ | 168 UBiDiDirection contextDir; /* L or R to use as context for followin
g openings */ |
| 178 uint8_t filler; /* to complete a nice multiple of 4 char
s */ | |
| 179 } IsoRun; | 169 } IsoRun; |
| 180 | 170 |
| 181 typedef struct BracketData { | 171 typedef struct BracketData { |
| 182 UBiDi *pBiDi; | 172 UBiDi *pBiDi; |
| 183 /* array of opening entries which should be enough in most cases; no malloc(
) */ | 173 /* array of opening entries which should be enough in most cases; no malloc(
) */ |
| 184 Opening simpleOpenings[SIMPLE_OPENINGS_SIZE]; | 174 Opening simpleOpenings[SIMPLE_OPENINGS_COUNT]; |
| 185 Opening *openings; /* pointer to current array of entries *
/ | 175 Opening *openings; /* pointer to current array of entries *
/ |
| 186 int32_t openingsCount; /* number of allocated entries */ | 176 int32_t openingsCount; /* number of allocated entries */ |
| 187 int32_t isoRunLast; /* index of last used entry */ | 177 int32_t isoRunLast; /* index of last used entry */ |
| 188 /* array of nested isolated sequence entries; can never excess UBIDI_MAX_EXP
LICIT_LEVEL | 178 /* array of nested isolated sequence entries; can never excess UBIDI_MAX_EXP
LICIT_LEVEL |
| 189 + 1 for index 0, + 1 for before the first isolated sequence */ | 179 + 1 for index 0, + 1 for before the first isolated sequence */ |
| 190 IsoRun isoRuns[UBIDI_MAX_EXPLICIT_LEVEL+2]; | 180 IsoRun isoRuns[UBIDI_MAX_EXPLICIT_LEVEL+2]; |
| 191 UBool isNumbersSpecial; /* reordering mode for NUMBERS_SPECIAL *
/ | 181 UBool isNumbersSpecial; /* reordering mode for NUMBERS_SPECIAL *
/ |
| 192 } BracketData; | 182 } BracketData; |
| 193 | 183 |
| 194 typedef struct Isolate { | 184 typedef struct Isolate { |
| 185 int32_t startON; |
| 195 int32_t start1; | 186 int32_t start1; |
| 196 int16_t stateImp; | 187 int16_t stateImp; |
| 197 int16_t state; | 188 int16_t state; |
| 198 } Isolate; | 189 } Isolate; |
| 199 | 190 |
| 200 typedef struct Run { | 191 typedef struct Run { |
| 201 int32_t logicalStart, /* first character of the run; b31 indicates even/od
d level */ | 192 int32_t logicalStart, /* first character of the run; b31 indicates even/od
d level */ |
| 202 visualLimit, /* last visual position of the run +1 */ | 193 visualLimit, /* last visual position of the run +1 */ |
| 203 insertRemove; /* if >0, flags for inserting LRM/RLM before/after r
un, | 194 insertRemove; /* if >0, flags for inserting LRM/RLM before/after r
un, |
| 204 if <0, count of bidi controls within run
*/ | 195 if <0, count of bidi controls within run
*/ |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 /* characters after trailingWSStart are WS and are */ | 338 /* characters after trailingWSStart are WS and are */ |
| 348 /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ | 339 /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ |
| 349 int32_t trailingWSStart; | 340 int32_t trailingWSStart; |
| 350 | 341 |
| 351 /* fields for paragraph handling */ | 342 /* fields for paragraph handling */ |
| 352 int32_t paraCount; /* set in getDirProps() */ | 343 int32_t paraCount; /* set in getDirProps() */ |
| 353 /* filled in getDirProps() */ | 344 /* filled in getDirProps() */ |
| 354 Para *paras; | 345 Para *paras; |
| 355 | 346 |
| 356 /* for relatively short text, we only need a tiny array of paras (no malloc(
)) */ | 347 /* for relatively short text, we only need a tiny array of paras (no malloc(
)) */ |
| 357 Para simpleParas[SIMPLE_PARAS_SIZE]; | 348 Para simpleParas[SIMPLE_PARAS_COUNT]; |
| 358 | 349 |
| 359 /* fields for line reordering */ | 350 /* fields for line reordering */ |
| 360 int32_t runCount; /* ==-1: runs not set up yet */ | 351 int32_t runCount; /* ==-1: runs not set up yet */ |
| 361 Run *runs; | 352 Run *runs; |
| 362 | 353 |
| 363 /* for non-mixed text, we only need a tiny array of runs (no malloc()) */ | 354 /* for non-mixed text, we only need a tiny array of runs (no malloc()) */ |
| 364 Run simpleRuns[1]; | 355 Run simpleRuns[1]; |
| 365 | 356 |
| 366 /* maximum or current nesting depth of isolate sequences */ | 357 /* maximum or current nesting depth of isolate sequences */ |
| 367 /* Within resolveExplicitLevels() and checkExplicitLevels(), this is the max
imal | 358 /* Within resolveExplicitLevels() and checkExplicitLevels(), this is the max
imal |
| 368 nesting encountered. | 359 nesting encountered. |
| 369 Within resolveImplicitLevels(), this is the index of the current isolates | 360 Within resolveImplicitLevels(), this is the index of the current isolates |
| 370 stack entry. */ | 361 stack entry. */ |
| 371 int32_t isolateCount; | 362 int32_t isolateCount; |
| 372 Isolate *isolates; | 363 Isolate *isolates; |
| 373 | 364 |
| 374 /* for simple text, have a small stack (no malloc()) */ | 365 /* for simple text, have a small stack (no malloc()) */ |
| 375 Isolate simpleIsolates[SIMPLE_ISOLATES_SIZE]; | 366 Isolate simpleIsolates[SIMPLE_ISOLATES_COUNT]; |
| 376 | 367 |
| 377 /* for inverse Bidi with insertion of directional marks */ | 368 /* for inverse Bidi with insertion of directional marks */ |
| 378 InsertPoints insertPoints; | 369 InsertPoints insertPoints; |
| 379 | 370 |
| 380 /* for option UBIDI_OPTION_REMOVE_CONTROLS */ | 371 /* for option UBIDI_OPTION_REMOVE_CONTROLS */ |
| 381 int32_t controlCount; | 372 int32_t controlCount; |
| 382 | 373 |
| 383 /* for Bidi class callback */ | 374 /* for Bidi class callback */ |
| 384 UBiDiClassCallback *fnClassCallback; /* action pointer */ | 375 UBiDiClassCallback *fnClassCallback; /* action pointer */ |
| 385 const void *coClassCallback; /* context pointer */ | 376 const void *coClassCallback; /* context pointer */ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi
)->runsSize, \ | 463 ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi
)->runsSize, \ |
| 473 TRUE, (length)*sizeof(Run)) | 464 TRUE, (length)*sizeof(Run)) |
| 474 | 465 |
| 475 #define getInitialIsolatesMemory(pBiDi, length) \ | 466 #define getInitialIsolatesMemory(pBiDi, length) \ |
| 476 ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->isolatesMemory, &(p
BiDi)->isolatesSize, \ | 467 ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->isolatesMemory, &(p
BiDi)->isolatesSize, \ |
| 477 TRUE, (length)*sizeof(Isolate)) | 468 TRUE, (length)*sizeof(Isolate)) |
| 478 | 469 |
| 479 #endif | 470 #endif |
| 480 | 471 |
| 481 #endif | 472 #endif |
| OLD | NEW |