| 1 | /* FriBidi - Library of BiDi algorithm |
---|
| 2 | * Copyright (C) 1999,2000 Dov Grobgeld, and |
---|
| 3 | * Copyright (C) 2001,2002 Behdad Esfahbod. |
---|
| 4 | * |
---|
| 5 | * This library is free software; you can redistribute it and/or |
---|
| 6 | * modify it under the terms of the GNU Lesser General Public |
---|
| 7 | * License as published by the Free Software Foundation; either |
---|
| 8 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This library is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | * Lesser General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU Lesser General Public License |
---|
| 16 | * along with this library, in a file named COPYING; if not, write to the |
---|
| 17 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
---|
| 18 | * Boston, MA 02111-1307, USA |
---|
| 19 | * |
---|
| 20 | * For licensing issues, contact <dov@imagic.weizmann.ac.il> and |
---|
| 21 | * <fwpg@sharif.edu>. |
---|
| 22 | */ |
---|
| 23 | #ifndef FRIBIDI_TYPES_H |
---|
| 24 | #define FRIBIDI_TYPES_H |
---|
| 25 | |
---|
| 26 | #include "fribidi_config.h" |
---|
| 27 | |
---|
| 28 | #define FRIBIDI_INT8 char |
---|
| 29 | #if FRIBIDI_SIZEOF_INT+0 == 2 |
---|
| 30 | # define FRIBIDI_INT16 int |
---|
| 31 | #elif FRIBIDI_SIZEOF_SHORT+0 == 2 |
---|
| 32 | # define FRIBIDI_INT16 short |
---|
| 33 | #else |
---|
| 34 | # error cannot determine a 16-bit integer type. check fribidi_config.h |
---|
| 35 | #endif |
---|
| 36 | #if FRIBIDI_SIZEOF_INT+0 == 4 |
---|
| 37 | # define FRIBIDI_INT32 int |
---|
| 38 | #elif FRIBIDI_SIZEOF_LONG+0 == 4 |
---|
| 39 | # define FRIBIDI_INT32 long |
---|
| 40 | #else |
---|
| 41 | # error cannot determine a 32-bit integer type. check fribidi_config.h |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | #ifdef __cplusplus |
---|
| 46 | extern "C" |
---|
| 47 | { |
---|
| 48 | #endif |
---|
| 49 | |
---|
| 50 | typedef int fribidi_boolean; |
---|
| 51 | |
---|
| 52 | typedef signed FRIBIDI_INT8 fribidi_int8; |
---|
| 53 | typedef unsigned FRIBIDI_INT8 fribidi_uint8; |
---|
| 54 | typedef signed FRIBIDI_INT16 fribidi_int16; |
---|
| 55 | typedef unsigned FRIBIDI_INT16 fribidi_uint16; |
---|
| 56 | typedef signed FRIBIDI_INT32 fribidi_int32; |
---|
| 57 | typedef unsigned FRIBIDI_INT32 fribidi_uint32; |
---|
| 58 | |
---|
| 59 | typedef signed int fribidi_int; |
---|
| 60 | typedef unsigned int fribidi_uint; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | typedef fribidi_int8 FriBidiLevel; |
---|
| 64 | typedef fribidi_uint32 FriBidiChar; |
---|
| 65 | typedef fribidi_int FriBidiStrIndex; |
---|
| 66 | typedef fribidi_int32 FriBidiMaskType; |
---|
| 67 | typedef FriBidiMaskType FriBidiCharType; |
---|
| 68 | |
---|
| 69 | char *fribidi_type_name (FriBidiCharType c); |
---|
| 70 | |
---|
| 71 | /* The following type is used by fribidi_utils */ |
---|
| 72 | typedef struct |
---|
| 73 | { |
---|
| 74 | FriBidiStrIndex length; |
---|
| 75 | void *attribute; |
---|
| 76 | } |
---|
| 77 | FriBidiRunType; |
---|
| 78 | |
---|
| 79 | /* The following type is used by fribdi_utils */ |
---|
| 80 | typedef struct _FriBidiList FriBidiList; |
---|
| 81 | struct _FriBidiList |
---|
| 82 | { |
---|
| 83 | void *data; |
---|
| 84 | FriBidiList *next; |
---|
| 85 | FriBidiList *prev; |
---|
| 86 | }; |
---|
| 87 | |
---|
| 88 | #ifndef FRIBIDI_MAX_STRING_LENGTH |
---|
| 89 | #define FRIBIDI_MAX_STRING_LENGTH (FriBidiStrIndex) \ |
---|
| 90 | (sizeof (FriBidiStrIndex) == 2 ? \ |
---|
| 91 | 0x7FFE : (sizeof (FriBidiStrIndex) == 1 ? \ |
---|
| 92 | 0x7E : 0x7FFFFFFEL)) |
---|
| 93 | #endif |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * Define some bit masks, that character types are based on, each one has |
---|
| 98 | * only one bit on. |
---|
| 99 | */ |
---|
| 100 | |
---|
| 101 | /* Do not use enum, because 16bit processors do not allow 32bit enum values. */ |
---|
| 102 | |
---|
| 103 | #define FRIBIDI_MASK_RTL 0x00000001L /* Is right to left */ |
---|
| 104 | #define FRIBIDI_MASK_ARABIC 0x00000002L /* Is arabic */ |
---|
| 105 | |
---|
| 106 | /* Each char can be only one of the three following. */ |
---|
| 107 | #define FRIBIDI_MASK_STRONG 0x00000010L /* Is strong */ |
---|
| 108 | #define FRIBIDI_MASK_WEAK 0x00000020L /* Is weak */ |
---|
| 109 | #define FRIBIDI_MASK_NEUTRAL 0x00000040L /* Is neutral */ |
---|
| 110 | #define FRIBIDI_MASK_SENTINEL 0x00000080L /* Is sentinel: SOT, EOT */ |
---|
| 111 | /* Sentinels are not valid chars, just identify the start and end of strings. */ |
---|
| 112 | |
---|
| 113 | /* Each char can be only one of the five following. */ |
---|
| 114 | #define FRIBIDI_MASK_LETTER 0x00000100L /* Is letter: L, R, AL */ |
---|
| 115 | #define FRIBIDI_MASK_NUMBER 0x00000200L /* Is number: EN, AN */ |
---|
| 116 | #define FRIBIDI_MASK_NUMSEPTER 0x00000400L /* Is number separator or terminator: ES, ET, CS */ |
---|
| 117 | #define FRIBIDI_MASK_SPACE 0x00000800L /* Is space: BN, BS, SS, WS */ |
---|
| 118 | #define FRIBIDI_MASK_EXPLICIT 0x00001000L /* Is expilict mark: LRE, RLE, LRO, RLO, PDF */ |
---|
| 119 | |
---|
| 120 | /* Can be on only if FRIBIDI_MASK_SPACE is also on. */ |
---|
| 121 | #define FRIBIDI_MASK_SEPARATOR 0x00002000L /* Is test separator: BS, SS */ |
---|
| 122 | /* Can be on only if FRIBIDI_MASK_EXPLICIT is also on. */ |
---|
| 123 | #define FRIBIDI_MASK_OVERRIDE 0x00004000L /* Is explicit override: LRO, RLO */ |
---|
| 124 | |
---|
| 125 | /* The following must be to make types pairwise different, some of them can |
---|
| 126 | be removed but are here because of efficiency (make queries faster). */ |
---|
| 127 | |
---|
| 128 | #define FRIBIDI_MASK_ES 0x00010000L |
---|
| 129 | #define FRIBIDI_MASK_ET 0x00020000L |
---|
| 130 | #define FRIBIDI_MASK_CS 0x00040000L |
---|
| 131 | |
---|
| 132 | #define FRIBIDI_MASK_NSM 0x00080000L |
---|
| 133 | #define FRIBIDI_MASK_BN 0x00100000L |
---|
| 134 | |
---|
| 135 | #define FRIBIDI_MASK_BS 0x00200000L |
---|
| 136 | #define FRIBIDI_MASK_SS 0x00400000L |
---|
| 137 | #define FRIBIDI_MASK_WS 0x00800000L |
---|
| 138 | |
---|
| 139 | /* We reserve the sign bit for user's private use: we will never use it, |
---|
| 140 | then negative character types will be never assigned. */ |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | /* |
---|
| 144 | * Define values for FriBidiCharType |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | /* Strong left to right */ |
---|
| 148 | #define FRIBIDI_TYPE_LTR ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER ) |
---|
| 149 | /* Right to left characters */ |
---|
| 150 | #define FRIBIDI_TYPE_RTL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \ |
---|
| 151 | + FRIBIDI_MASK_RTL) |
---|
| 152 | /* Arabic characters */ |
---|
| 153 | #define FRIBIDI_TYPE_AL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \ |
---|
| 154 | + FRIBIDI_MASK_RTL + FRIBIDI_MASK_ARABIC ) |
---|
| 155 | /* Left-To-Right embedding */ |
---|
| 156 | #define FRIBIDI_TYPE_LRE (FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT) |
---|
| 157 | /* Right-To-Left embedding */ |
---|
| 158 | #define FRIBIDI_TYPE_RLE ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \ |
---|
| 159 | + FRIBIDI_MASK_RTL ) |
---|
| 160 | /* Left-To-Right override */ |
---|
| 161 | #define FRIBIDI_TYPE_LRO ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \ |
---|
| 162 | + FRIBIDI_MASK_OVERRIDE ) |
---|
| 163 | /* Right-To-Left override */ |
---|
| 164 | #define FRIBIDI_TYPE_RLO ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \ |
---|
| 165 | + FRIBIDI_MASK_RTL + FRIBIDI_MASK_OVERRIDE ) |
---|
| 166 | |
---|
| 167 | /* Pop directional override */ |
---|
| 168 | #define FRIBIDI_TYPE_PDF ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_EXPLICIT ) |
---|
| 169 | /* European digit */ |
---|
| 170 | #define FRIBIDI_TYPE_EN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER ) |
---|
| 171 | /* Arabic digit */ |
---|
| 172 | #define FRIBIDI_TYPE_AN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER \ |
---|
| 173 | + FRIBIDI_MASK_ARABIC ) |
---|
| 174 | /* European number separator */ |
---|
| 175 | #define FRIBIDI_TYPE_ES ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \ |
---|
| 176 | + FRIBIDI_MASK_ES ) |
---|
| 177 | /* European number terminator */ |
---|
| 178 | #define FRIBIDI_TYPE_ET ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \ |
---|
| 179 | + FRIBIDI_MASK_ET ) |
---|
| 180 | /* Common Separator */ |
---|
| 181 | #define FRIBIDI_TYPE_CS ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \ |
---|
| 182 | + FRIBIDI_MASK_CS ) |
---|
| 183 | /* Non spacing mark */ |
---|
| 184 | #define FRIBIDI_TYPE_NSM ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NSM ) |
---|
| 185 | /* Boundary neutral */ |
---|
| 186 | #define FRIBIDI_TYPE_BN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_SPACE \ |
---|
| 187 | + FRIBIDI_MASK_BN ) |
---|
| 188 | |
---|
| 189 | /* Block separator */ |
---|
| 190 | #define FRIBIDI_TYPE_BS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \ |
---|
| 191 | + FRIBIDI_MASK_SEPARATOR + FRIBIDI_MASK_BS ) |
---|
| 192 | /* Segment separator */ |
---|
| 193 | #define FRIBIDI_TYPE_SS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \ |
---|
| 194 | + FRIBIDI_MASK_SEPARATOR + FRIBIDI_MASK_SS ) |
---|
| 195 | /* Whitespace */ |
---|
| 196 | #define FRIBIDI_TYPE_WS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \ |
---|
| 197 | + FRIBIDI_MASK_WS ) |
---|
| 198 | /* Other Neutral */ |
---|
| 199 | #define FRIBIDI_TYPE_ON ( FRIBIDI_MASK_NEUTRAL ) |
---|
| 200 | |
---|
| 201 | /* The following are used to identify the paragraph direction, |
---|
| 202 | types L, R, N are not used internally anymore, and recommended to use |
---|
| 203 | LTR, RTL and ON instead, didn't removed because of compatability. */ |
---|
| 204 | #define FRIBIDI_TYPE_L ( FRIBIDI_TYPE_LTR ) |
---|
| 205 | #define FRIBIDI_TYPE_R ( FRIBIDI_TYPE_RTL ) |
---|
| 206 | #define FRIBIDI_TYPE_N ( FRIBIDI_TYPE_ON ) |
---|
| 207 | /* Weak left to right */ |
---|
| 208 | #define FRIBIDI_TYPE_WL ( FRIBIDI_MASK_WEAK ) |
---|
| 209 | /* Weak right to left */ |
---|
| 210 | #define FRIBIDI_TYPE_WR ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_RTL ) |
---|
| 211 | |
---|
| 212 | /* The following are only used internally */ |
---|
| 213 | |
---|
| 214 | /* Start of text */ |
---|
| 215 | #define FRIBIDI_TYPE_SOT ( FRIBIDI_MASK_SENTINEL ) |
---|
| 216 | /* End of text */ |
---|
| 217 | #define FRIBIDI_TYPE_EOT ( FRIBIDI_MASK_SENTINEL + FRIBIDI_MASK_RTL ) |
---|
| 218 | |
---|
| 219 | /* |
---|
| 220 | * End of define values for FriBidiCharType |
---|
| 221 | */ |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | /* |
---|
| 225 | * Defining macros for needed queries, It is fully dependent on the |
---|
| 226 | * implementation of FriBidiCharType. |
---|
| 227 | */ |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | /* Is private-use value? */ |
---|
| 231 | #define FRIBIDI_TYPE_PRIVATE(p) ((p) < 0) |
---|
| 232 | |
---|
| 233 | /* Return the direction of the level number, FRIBIDI_TYPE_LTR for even and |
---|
| 234 | FRIBIDI_TYPE_RTL for odds. */ |
---|
| 235 | #define FRIBIDI_LEVEL_TO_DIR(lev) (FRIBIDI_TYPE_LTR | (lev & 1)) |
---|
| 236 | |
---|
| 237 | /* Return the minimum level of the direction, 0 for FRIBIDI_TYPE_LTR and |
---|
| 238 | 1 for FRIBIDI_TYPE_RTL and FRIBIDI_TYPE_AL. */ |
---|
| 239 | #define FRIBIDI_DIR_TO_LEVEL(dir) ((FriBidiLevel)(dir & 1)) |
---|
| 240 | |
---|
| 241 | /* Is right to left? */ |
---|
| 242 | #define FRIBIDI_IS_RTL(p) ((p) & FRIBIDI_MASK_RTL) |
---|
| 243 | /* Is arabic? */ |
---|
| 244 | #define FRIBIDI_IS_ARABIC(p) ((p) & FRIBIDI_MASK_ARABIC) |
---|
| 245 | |
---|
| 246 | /* Is strong? */ |
---|
| 247 | #define FRIBIDI_IS_STRONG(p) ((p) & FRIBIDI_MASK_STRONG) |
---|
| 248 | /* Is weak? */ |
---|
| 249 | #define FRIBIDI_IS_WEAK(p) ((p) & FRIBIDI_MASK_WEAK) |
---|
| 250 | /* Is neutral? */ |
---|
| 251 | #define FRIBIDI_IS_NEUTRAL(p) ((p) & FRIBIDI_MASK_NEUTRAL) |
---|
| 252 | /* Is sentinel? */ |
---|
| 253 | #define FRIBIDI_IS_SENTINEL(p) ((p) & FRIBIDI_MASK_SENTINEL) |
---|
| 254 | |
---|
| 255 | /* Is letter: L, R, AL? */ |
---|
| 256 | #define FRIBIDI_IS_LETTER(p) ((p) & FRIBIDI_MASK_LETTER) |
---|
| 257 | /* Is number: EN, AN? */ |
---|
| 258 | #define FRIBIDI_IS_NUMBER(p) ((p) & FRIBIDI_MASK_NUMBER) |
---|
| 259 | /* Is number separator or terminator: ES, ET, CS? */ |
---|
| 260 | #define FRIBIDI_IS_NUMBER_SEPARATOR_OR_TERMINATOR(p) \ |
---|
| 261 | ((p) & FRIBIDI_MASK_NUMSEPTER) |
---|
| 262 | /* Is space: BN, BS, SS, WS? */ |
---|
| 263 | #define FRIBIDI_IS_SPACE(p) ((p) & FRIBIDI_MASK_SPACE) |
---|
| 264 | /* Is explicit mark: LRE, RLE, LRO, RLO, PDF? */ |
---|
| 265 | #define FRIBIDI_IS_EXPLICIT(p) ((p) & FRIBIDI_MASK_EXPLICIT) |
---|
| 266 | |
---|
| 267 | /* Is test separator: BS, SS? */ |
---|
| 268 | #define FRIBIDI_IS_SEPARATOR(p) ((p) & FRIBIDI_MASK_SEPARATOR) |
---|
| 269 | |
---|
| 270 | /* Is explicit override: LRO, RLO? */ |
---|
| 271 | #define FRIBIDI_IS_OVERRIDE(p) ((p) & FRIBIDI_MASK_OVERRIDE) |
---|
| 272 | |
---|
| 273 | /* Some more: */ |
---|
| 274 | |
---|
| 275 | /* Is left to right letter: LTR? */ |
---|
| 276 | #define FRIBIDI_IS_LTR_LETTER(p) \ |
---|
| 277 | ((p) & (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL) == FRIBIDI_MASK_LETTER) |
---|
| 278 | |
---|
| 279 | /* Is right to left letter: RTL, AL? */ |
---|
| 280 | #define FRIBIDI_IS_RTL_LETTER(p) \ |
---|
| 281 | ((p) & (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL) \ |
---|
| 282 | == (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL)) |
---|
| 283 | |
---|
| 284 | /* Is ES or CS: ES, CS? */ |
---|
| 285 | #define FRIBIDI_IS_ES_OR_CS(p) \ |
---|
| 286 | ((p) & (FRIBIDI_MASK_ES | FRIBIDI_MASK_CS)) |
---|
| 287 | |
---|
| 288 | /* Is explicit or BN: LRE, RLE, LRO, RLO, PDF, BN? */ |
---|
| 289 | #define FRIBIDI_IS_EXPLICIT_OR_BN(p) \ |
---|
| 290 | ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN)) |
---|
| 291 | |
---|
| 292 | /* Is explicit or separator or BN or WS: LRE, RLE, LRO, RLO, PDF, BS, SS, BN, WS? */ |
---|
| 293 | #define FRIBIDI_IS_EXPLICIT_OR_SEPARATOR_OR_BN_OR_WS(p) \ |
---|
| 294 | ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_SEPARATOR \ |
---|
| 295 | | FRIBIDI_MASK_BN | FRIBIDI_MASK_WS)) |
---|
| 296 | |
---|
| 297 | /* Define some conversions. */ |
---|
| 298 | |
---|
| 299 | /* Change numbers: EN, AN to RTL. */ |
---|
| 300 | #define FRIBIDI_CHANGE_NUMBER_TO_RTL(p) \ |
---|
| 301 | (FRIBIDI_IS_NUMBER(p) ? FRIBIDI_TYPE_RTL : (p)) |
---|
| 302 | |
---|
| 303 | /* Override status of an explicit mark: LRO->LTR, RLO->RTL, otherwise->ON. */ |
---|
| 304 | #define FRIBIDI_EXPLICIT_TO_OVERRIDE_DIR(p) \ |
---|
| 305 | (FRIBIDI_IS_OVERRIDE(p) ? FRIBIDI_LEVEL_TO_DIR(FRIBIDI_DIR_TO_LEVEL(p)) \ |
---|
| 306 | : FRIBIDI_TYPE_ON) |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | /* |
---|
| 310 | * Define character types that char_type_tables use. |
---|
| 311 | * define them to be 0, 1, 2, ... and then in fribidi_char_type.c map them |
---|
| 312 | * to FriBidiCharTypes. |
---|
| 313 | */ |
---|
| 314 | typedef char FriBidiPropCharType; |
---|
| 315 | |
---|
| 316 | enum FriBidiPropEnum |
---|
| 317 | { |
---|
| 318 | #define _FRIBIDI_ADD_TYPE(TYPE) FRIBIDI_PROP_TYPE_##TYPE, |
---|
| 319 | #include "fribidi_types.i" |
---|
| 320 | #undef _FRIBIDI_ADD_TYPE |
---|
| 321 | FRIBIDI_TYPES_COUNT /* Number of different character types */ |
---|
| 322 | }; |
---|
| 323 | |
---|
| 324 | /* Map fribidi_prop_types to fribidi_types */ |
---|
| 325 | extern const FriBidiCharType fribidi_prop_to_type[]; |
---|
| 326 | |
---|
| 327 | #ifdef __cplusplus |
---|
| 328 | } |
---|
| 329 | #endif |
---|
| 330 | |
---|
| 331 | #endif |
---|