2 * fribidi-bidi-types.h - character bidi types
4 * $Id: fribidi-bidi-types.h,v 1.15 2008-11-24 17:48:31 behdad Exp $
6 * $Date: 2008-11-24 17:48:31 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.h,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
13 * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14 * Copyright (C) 2001,2002 Behdad Esfahbod
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library, in a file named COPYING; if not, write to the
28 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA
31 * For licensing issues, contact <license@farsiweb.info>.
33 #ifndef _FRIBIDI_BIDI_TYPES_H
34 #define _FRIBIDI_BIDI_TYPES_H
36 #include "fribidi-common.h"
38 #include "fribidi-types.h"
40 #include "fribidi-begindecls.h"
42 typedef signed char FriBidiLevel;
45 * Define bit masks that bidi types are based on, each mask has
49 /* RTL mask better be the least significant bit. */
50 #define FRIBIDI_MASK_RTL 0x00000001L /* Is right to left */
51 #define FRIBIDI_MASK_ARABIC 0x00000002L /* Is arabic */
53 /* Each char can be only one of the three following. */
54 #define FRIBIDI_MASK_STRONG 0x00000010L /* Is strong */
55 #define FRIBIDI_MASK_WEAK 0x00000020L /* Is weak */
56 #define FRIBIDI_MASK_NEUTRAL 0x00000040L /* Is neutral */
57 #define FRIBIDI_MASK_SENTINEL 0x00000080L /* Is sentinel */
58 /* Sentinels are not valid chars, just identify the start/end of strings. */
60 /* Each char can be only one of the five following. */
61 #define FRIBIDI_MASK_LETTER 0x00000100L /* Is letter: L, R, AL */
62 #define FRIBIDI_MASK_NUMBER 0x00000200L /* Is number: EN, AN */
63 #define FRIBIDI_MASK_NUMSEPTER 0x00000400L /* Is separator or terminator: ES, ET, CS */
64 #define FRIBIDI_MASK_SPACE 0x00000800L /* Is space: BN, BS, SS, WS */
65 #define FRIBIDI_MASK_EXPLICIT 0x00001000L /* Is expilict mark: LRE, RLE, LRO, RLO, PDF */
67 /* Can be set only if FRIBIDI_MASK_SPACE is also set. */
68 #define FRIBIDI_MASK_SEPARATOR 0x00002000L /* Is text separator: BS, SS */
69 /* Can be set only if FRIBIDI_MASK_EXPLICIT is also set. */
70 #define FRIBIDI_MASK_OVERRIDE 0x00004000L /* Is explicit override: LRO, RLO */
72 /* The following exist to make types pairwise different, some of them can
73 * be removed but are here because of efficiency (make queries faster). */
75 #define FRIBIDI_MASK_ES 0x00010000L
76 #define FRIBIDI_MASK_ET 0x00020000L
77 #define FRIBIDI_MASK_CS 0x00040000L
79 #define FRIBIDI_MASK_NSM 0x00080000L
80 #define FRIBIDI_MASK_BN 0x00100000L
82 #define FRIBIDI_MASK_BS 0x00200000L
83 #define FRIBIDI_MASK_SS 0x00400000L
84 #define FRIBIDI_MASK_WS 0x00800000L
86 /* We reserve a single bit for user's private use: we will never use it. */
87 #define FRIBIDI_MASK_PRIVATE 0x01000000L
91 * Define values for FriBidiCharType
96 /* Left-To-Right letter */
97 #define FRIBIDI_TYPE_LTR_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_LETTER )
98 /* Right-To-Left letter */
99 #define FRIBIDI_TYPE_RTL_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_LETTER \
102 #define FRIBIDI_TYPE_AL_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_LETTER \
103 | FRIBIDI_MASK_RTL | FRIBIDI_MASK_ARABIC )
104 /* Left-to-Right Embedding */
105 #define FRIBIDI_TYPE_LRE_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_EXPLICIT)
106 /* Right-to-Left Embedding */
107 #define FRIBIDI_TYPE_RLE_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_EXPLICIT \
109 /* Left-to-Right Override */
110 #define FRIBIDI_TYPE_LRO_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_EXPLICIT \
111 | FRIBIDI_MASK_OVERRIDE )
112 /* Right-to-Left Override */
113 #define FRIBIDI_TYPE_RLO_VAL ( FRIBIDI_MASK_STRONG | FRIBIDI_MASK_EXPLICIT \
114 | FRIBIDI_MASK_RTL | FRIBIDI_MASK_OVERRIDE )
118 /* Pop Directional Flag*/
119 #define FRIBIDI_TYPE_PDF_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_EXPLICIT )
120 /* European Numeral */
121 #define FRIBIDI_TYPE_EN_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NUMBER )
123 #define FRIBIDI_TYPE_AN_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NUMBER \
124 | FRIBIDI_MASK_ARABIC )
125 /* European number Separator */
126 #define FRIBIDI_TYPE_ES_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NUMSEPTER \
128 /* European number Terminator */
129 #define FRIBIDI_TYPE_ET_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NUMSEPTER \
131 /* Common Separator */
132 #define FRIBIDI_TYPE_CS_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NUMSEPTER \
134 /* Non Spacing Mark */
135 #define FRIBIDI_TYPE_NSM_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_NSM )
136 /* Boundary Neutral */
137 #define FRIBIDI_TYPE_BN_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_SPACE \
142 /* Block Separator */
143 #define FRIBIDI_TYPE_BS_VAL ( FRIBIDI_MASK_NEUTRAL | FRIBIDI_MASK_SPACE \
144 | FRIBIDI_MASK_SEPARATOR | FRIBIDI_MASK_BS )
145 /* Segment Separator */
146 #define FRIBIDI_TYPE_SS_VAL ( FRIBIDI_MASK_NEUTRAL | FRIBIDI_MASK_SPACE \
147 | FRIBIDI_MASK_SEPARATOR | FRIBIDI_MASK_SS )
149 #define FRIBIDI_TYPE_WS_VAL ( FRIBIDI_MASK_NEUTRAL | FRIBIDI_MASK_SPACE \
152 #define FRIBIDI_TYPE_ON_VAL ( FRIBIDI_MASK_NEUTRAL )
155 /* The following are used in specifying paragraph direction only. */
157 /* Weak Left-To-Right */
158 #define FRIBIDI_TYPE_WLTR_VAL ( FRIBIDI_MASK_WEAK )
159 /* Weak Right-To-Left */
160 #define FRIBIDI_TYPE_WRTL_VAL ( FRIBIDI_MASK_WEAK | FRIBIDI_MASK_RTL )
162 /* start or end of text (run list) SENTINEL. Only used internally */
163 #define FRIBIDI_TYPE_SENTINEL ( FRIBIDI_MASK_SENTINEL )
165 /* Private types for applications. More private types can be obtained by
166 * summing up from this one. */
167 #define FRIBIDI_TYPE_PRIVATE ( FRIBIDI_MASK_PRIVATE )
170 /* Define Enums only if sizeof(int) == 4 (UTF-32), and not compiling C++.
171 * The problem with C++ is that then casts between int32 and enum will fail!
173 #if defined(__FRIBIDI_DOC) || (FRIBIDI_SIZEOF_INT+0 == 4 && !defined(__cplusplus))
177 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
178 FRIBIDI_TYPE_##TYPE = FRIBIDI_TYPE_##TYPE##_VAL,
179 # include "fribidi-bidi-types-list.h"
180 # undef _FRIBIDI_ADD_TYPE
181 _FRIBIDI_TYPE_SENTINEL = FRIBIDI_TYPE_SENTINEL /* Don't use this */
186 # define _FRIBIDI_PAR_TYPES
187 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
188 FRIBIDI_PAR_##TYPE = FRIBIDI_TYPE_##TYPE##_VAL,
189 # include "fribidi-bidi-types-list.h"
190 # undef _FRIBIDI_ADD_TYPE
191 # undef _FRIBIDI_PAR_TYPES
192 _FRIBIDI_PAR_SENTINEL = FRIBIDI_TYPE_SENTINEL /* Don't use this */
197 typedef fribidi_uint32 FriBidiCharType;
198 # define FRIBIDI_TYPE_LTR FRIBIDI_TYPE_LTR_VAL
199 # define FRIBIDI_TYPE_RTL FRIBIDI_TYPE_RTL_VAL
200 # define FRIBIDI_TYPE_AL FRIBIDI_TYPE_AL_VAL
201 # define FRIBIDI_TYPE_EN FRIBIDI_TYPE_EN_VAL
202 # define FRIBIDI_TYPE_AN FRIBIDI_TYPE_AN_VAL
203 # define FRIBIDI_TYPE_ES FRIBIDI_TYPE_ES_VAL
204 # define FRIBIDI_TYPE_ET FRIBIDI_TYPE_ET_VAL
205 # define FRIBIDI_TYPE_CS FRIBIDI_TYPE_CS_VAL
206 # define FRIBIDI_TYPE_NSM FRIBIDI_TYPE_NSM_VAL
207 # define FRIBIDI_TYPE_BN FRIBIDI_TYPE_BN_VAL
208 # define FRIBIDI_TYPE_BS FRIBIDI_TYPE_BS_VAL
209 # define FRIBIDI_TYPE_SS FRIBIDI_TYPE_SS_VAL
210 # define FRIBIDI_TYPE_WS FRIBIDI_TYPE_WS_VAL
211 # define FRIBIDI_TYPE_ON FRIBIDI_TYPE_ON_VAL
212 # define FRIBIDI_TYPE_LRE FRIBIDI_TYPE_LRE_VAL
213 # define FRIBIDI_TYPE_RLE FRIBIDI_TYPE_RLE_VAL
214 # define FRIBIDI_TYPE_LRO FRIBIDI_TYPE_LRO_VAL
215 # define FRIBIDI_TYPE_RLO FRIBIDI_TYPE_RLO_VAL
216 # define FRIBIDI_TYPE_PDF FRIBIDI_TYPE_PDF_VAL
218 typedef fribidi_uint32 FriBidiParType;
219 # define FRIBIDI_PAR_LTR FRIBIDI_TYPE_LTR_VAL
220 # define FRIBIDI_PAR_RTL FRIBIDI_TYPE_RTL_VAL
221 # define FRIBIDI_PAR_ON FRIBIDI_TYPE_ON_VAL
222 # define FRIBIDI_PAR_WLTR FRIBIDI_TYPE_WLTR_VAL
223 # define FRIBIDI_PAR_WRTL FRIBIDI_TYPE_WRTL_VAL
227 /* Please don't use these two type names, use FRIBIDI_PAR_* form instead. */
228 #define FRIBIDI_TYPE_WLTR FRIBIDI_PAR_WLTR
229 #define FRIBIDI_TYPE_WRTL FRIBIDI_PAR_WRTL
233 * Defining macros for needed queries, It is fully dependent on the
234 * implementation of FriBidiCharType.
238 /* Is right-to-left level? */
239 #define FRIBIDI_LEVEL_IS_RTL(lev) ((lev) & 1)
241 /* Return the bidi type corresponding to the direction of the level number,
242 FRIBIDI_TYPE_LTR for evens and FRIBIDI_TYPE_RTL for odds. */
243 #define FRIBIDI_LEVEL_TO_DIR(lev) \
244 (FRIBIDI_LEVEL_IS_RTL (lev) ? FRIBIDI_TYPE_RTL : FRIBIDI_TYPE_LTR)
246 /* Return the minimum level of the direction, 0 for FRIBIDI_TYPE_LTR and
247 1 for FRIBIDI_TYPE_RTL and FRIBIDI_TYPE_AL. */
248 #define FRIBIDI_DIR_TO_LEVEL(dir) \
249 ((FriBidiLevel) (FRIBIDI_IS_RTL (dir) ? 1 : 0))
251 /* Is right to left: RTL, AL, RLE, RLO? */
252 #define FRIBIDI_IS_RTL(p) ((p) & FRIBIDI_MASK_RTL)
253 /* Is arabic: AL, AN? */
254 #define FRIBIDI_IS_ARABIC(p) ((p) & FRIBIDI_MASK_ARABIC)
257 #define FRIBIDI_IS_STRONG(p) ((p) & FRIBIDI_MASK_STRONG)
259 #define FRIBIDI_IS_WEAK(p) ((p) & FRIBIDI_MASK_WEAK)
261 #define FRIBIDI_IS_NEUTRAL(p) ((p) & FRIBIDI_MASK_NEUTRAL)
263 #define FRIBIDI_IS_SENTINEL(p) ((p) & FRIBIDI_MASK_SENTINEL)
265 /* Is letter: L, R, AL? */
266 #define FRIBIDI_IS_LETTER(p) ((p) & FRIBIDI_MASK_LETTER)
267 /* Is number: EN, AN? */
268 #define FRIBIDI_IS_NUMBER(p) ((p) & FRIBIDI_MASK_NUMBER)
269 /* Is number separator or terminator: ES, ET, CS? */
270 #define FRIBIDI_IS_NUMBER_SEPARATOR_OR_TERMINATOR(p) \
271 ((p) & FRIBIDI_MASK_NUMSEPTER)
272 /* Is space: BN, BS, SS, WS? */
273 #define FRIBIDI_IS_SPACE(p) ((p) & FRIBIDI_MASK_SPACE)
274 /* Is explicit mark: LRE, RLE, LRO, RLO, PDF? */
275 #define FRIBIDI_IS_EXPLICIT(p) ((p) & FRIBIDI_MASK_EXPLICIT)
277 /* Is text separator: BS, SS? */
278 #define FRIBIDI_IS_SEPARATOR(p) ((p) & FRIBIDI_MASK_SEPARATOR)
280 /* Is explicit override: LRO, RLO? */
281 #define FRIBIDI_IS_OVERRIDE(p) ((p) & FRIBIDI_MASK_OVERRIDE)
285 /* Is left to right letter: LTR? */
286 #define FRIBIDI_IS_LTR_LETTER(p) \
287 ((p) & (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL) == FRIBIDI_MASK_LETTER)
289 /* Is right to left letter: RTL, AL? */
290 #define FRIBIDI_IS_RTL_LETTER(p) \
291 ((p) & (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL) \
292 == (FRIBIDI_MASK_LETTER | FRIBIDI_MASK_RTL))
294 /* Is ES or CS: ES, CS? */
295 #define FRIBIDI_IS_ES_OR_CS(p) \
296 ((p) & (FRIBIDI_MASK_ES | FRIBIDI_MASK_CS))
298 /* Is explicit or BN: LRE, RLE, LRO, RLO, PDF, BN? */
299 #define FRIBIDI_IS_EXPLICIT_OR_BN(p) \
300 ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN))
302 /* Is explicit or BN or NSM: LRE, RLE, LRO, RLO, PDF, BN, NSM? */
303 #define FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM(p) \
304 ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN | FRIBIDI_MASK_NSM))
306 /* Is explicit or BN or WS: LRE, RLE, LRO, RLO, PDF, BN, WS? */
307 #define FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS(p) \
308 ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN | FRIBIDI_MASK_WS))
310 /* Is explicit or separator or BN or WS: LRE, RLE, LRO, RLO, PDF, BS, SS, BN, WS? */
311 #define FRIBIDI_IS_EXPLICIT_OR_SEPARATOR_OR_BN_OR_WS(p) \
312 ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_SEPARATOR \
313 | FRIBIDI_MASK_BN | FRIBIDI_MASK_WS))
315 /* Is private-use type for application? */
316 #define FRIBIDI_IS_PRIVATE(p) ((p) & FRIBIDI_MASK_PRIVATE)
318 /* Define some conversions. */
320 /* Change numbers to RTL: EN,AN -> RTL. */
321 #define FRIBIDI_CHANGE_NUMBER_TO_RTL(p) \
322 (FRIBIDI_IS_NUMBER(p) ? FRIBIDI_TYPE_RTL : (p))
324 /* Override status of an explicit mark:
325 * LRO,LRE->LTR, RLO,RLE->RTL, otherwise->ON. */
326 #define FRIBIDI_EXPLICIT_TO_OVERRIDE_DIR(p) \
327 (FRIBIDI_IS_OVERRIDE(p) ? FRIBIDI_LEVEL_TO_DIR(FRIBIDI_DIR_TO_LEVEL(p)) \
330 /* Weaken type for paragraph fallback purposes:
331 * LTR->WLTR, RTL->WRTL. */
332 #define FRIBIDI_WEAK_PARAGRAPH(p) (FRIBIDI_PAR_WLTR | ((p) & FRIBIDI_MASK_RTL))
335 /* Functions finally */
338 #define fribidi_get_bidi_type FRIBIDI_NAMESPACE(get_bidi_type)
339 /* fribidi_get_bidi_type - get character bidi type
341 * This function returns the bidi type of a character as defined in Table 3.7
342 * Bidirectional Character Types of the Unicode Bidirectional Algorithm
344 * http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types, using
345 * data provided in file UnicodeData.txt of the Unicode Character Database
346 * available at http://www.unicode.org/Public/UNIDATA/UnicodeData.txt.
348 * There are a few macros defined in fribidi-bidi-types.h for querying a bidi
351 FRIBIDI_ENTRY FriBidiCharType
352 fribidi_get_bidi_type (
353 FriBidiChar ch /* input character */
354 ) FRIBIDI_GNUC_CONST;
356 #define fribidi_get_bidi_types FRIBIDI_NAMESPACE(get_bidi_types)
357 /* fribidi_get_bidi_types - get bidi types for an string of characters
359 * This function finds the bidi types of an string of characters. See
360 * fribidi_get_bidi_type() for more information about the bidi types returned
363 FRIBIDI_ENTRY void fribidi_get_bidi_types (
364 const FriBidiChar *str, /* input string */
365 const FriBidiStrIndex len, /* input string length */
366 FriBidiCharType *btypes /* output bidi types */
369 #define fribidi_get_bidi_type_name FRIBIDI_NAMESPACE(get_bidi_type_name)
370 /* fribidi_get_bidi_type_name - get bidi type name
372 * This function returns the bidi type name of a character type. The
373 * returned string is a static string and should not be freed.
375 * The type names are the same as ones defined in Table 3.7 Bidirectional
376 * Character Types of the Unicode Bidirectional Algorithm available at
377 * http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types, with a
378 * few modifications: L->LTR, R->RTL, B->BS, S->SS.
380 FRIBIDI_ENTRY const char *fribidi_get_bidi_type_name (
381 FriBidiCharType t /* input bidi type */
382 ) FRIBIDI_GNUC_CONST;
384 #include "fribidi-enddecls.h"
386 #endif /* !_FRIBIDI_BIDI_TYPES_H */
387 /* Editor directions:
388 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent