2 * fribidi-joining-types.h - character joining types
5 * Behdad Esfahbod, 2001, 2002, 2004
7 * Copyright (C) 2004 Sharif FarsiWeb, Inc.
8 * Copyright (C) 2001,2002 Behdad Esfahbod
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library, in a file named COPYING; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA
25 * For licensing issues, contact <fribidi.license@gmail.com>.
27 #ifndef _FRIBIDI_JOINING_TYPES_H
28 #define _FRIBIDI_JOINING_TYPES_H
30 #include "fribidi-common.h"
32 #include "fribidi-types.h"
34 #include "fribidi-begindecls.h"
37 * Define bit masks that joining types are based on, each mask has
41 #define FRIBIDI_MASK_JOINS_RIGHT 0x01 /* May join to right */
42 #define FRIBIDI_MASK_JOINS_LEFT 0x02 /* May join to right */
43 #define FRIBIDI_MASK_ARAB_SHAPES 0x04 /* May Arabic shape */
44 #define FRIBIDI_MASK_TRANSPARENT 0x08 /* Is transparent */
45 #define FRIBIDI_MASK_IGNORED 0x10 /* Is ignored */
46 #define FRIBIDI_MASK_LIGATURED 0x20 /* Is ligatured */
49 * Define values for FriBidiJoiningType
53 #define FRIBIDI_JOINING_TYPE_U_VAL ( 0 )
56 #define FRIBIDI_JOINING_TYPE_R_VAL \
57 ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_ARAB_SHAPES )
60 #define FRIBIDI_JOINING_TYPE_D_VAL \
61 ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT \
62 | FRIBIDI_MASK_ARAB_SHAPES )
65 #define FRIBIDI_JOINING_TYPE_C_VAL \
66 ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT )
69 #define FRIBIDI_JOINING_TYPE_L_VAL \
70 ( FRIBIDI_MASK_JOINS_LEFT | FRIBIDI_MASK_ARAB_SHAPES )
73 #define FRIBIDI_JOINING_TYPE_T_VAL \
74 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_ARAB_SHAPES )
77 #define FRIBIDI_JOINING_TYPE_G_VAL ( FRIBIDI_MASK_IGNORED )
80 enum _FriBidiJoiningTypeEnum
82 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
83 FRIBIDI_JOINING_TYPE_##TYPE = FRIBIDI_JOINING_TYPE_##TYPE##_VAL,
84 # include "fribidi-joining-types-list.h"
85 # undef _FRIBIDI_ADD_TYPE
86 _FRIBIDI_JOINING_TYPE_JUNK /* Don't use this */
90 typedef enum _FriBidiJoiningTypeEnum FriBidiJoiningType;
91 #else /* !__FRIBIDI_DOC */
92 typedef uint8_t FriBidiJoiningType;
93 #endif /* !__FRIBIDI_DOC */
95 /* FriBidiArabicProp is essentially the same type as FriBidiJoiningType, but
96 * not limited to the few values returned by fribidi_get_joining_type. */
97 typedef uint8_t FriBidiArabicProp;
100 * The equivalent of JoiningType values for ArabicProp
103 /* Primary Arabic Joining Classes (Table 8-2) */
106 #define FRIBIDI_IS_JOINING_TYPE_U(p) \
108 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
109 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
112 #define FRIBIDI_IS_JOINING_TYPE_R(p) \
113 ( FRIBIDI_MASK_JOINS_RIGHT == ( (p) & \
114 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
115 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
118 #define FRIBIDI_IS_JOINING_TYPE_D(p) \
119 ( ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT \
120 | FRIBIDI_MASK_ARAB_SHAPES ) == ( (p) & \
121 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
122 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT \
123 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
126 #define FRIBIDI_IS_JOINING_TYPE_C(p) \
127 ( ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) == ( (p) & \
128 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
129 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT \
130 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
133 #define FRIBIDI_IS_JOINING_TYPE_L(p) \
134 ( FRIBIDI_MASK_JOINS_LEFT == ( (p) & \
135 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
136 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
139 #define FRIBIDI_IS_JOINING_TYPE_T(p) \
140 ( FRIBIDI_MASK_TRANSPARENT == ( (p) & \
141 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED ) ) )
144 #define FRIBIDI_IS_JOINING_TYPE_G(p) \
145 ( FRIBIDI_MASK_IGNORED == ( (p) & \
146 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED ) ) )
148 /* and for Derived Arabic Joining Classes (Table 8-3) */
150 /* Right join-Causing */
151 #define FRIBIDI_IS_JOINING_TYPE_RC(p) \
152 ( FRIBIDI_MASK_JOINS_RIGHT == ( (p) & \
153 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
154 | FRIBIDI_MASK_JOINS_RIGHT ) ) )
156 /* Left join-Causing */
157 #define FRIBIDI_IS_JOINING_TYPE_LC(p) \
158 ( FRIBIDI_MASK_JOINS_LEFT == ( (p) & \
159 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
160 | FRIBIDI_MASK_JOINS_LEFT ) ) )
164 * Defining macros for needed queries, It is fully dependent on the
165 * implementation of FriBidiJoiningType.
168 /* Joins to right: R, D, C? */
169 #define FRIBIDI_JOINS_RIGHT(p) ((p) & FRIBIDI_MASK_JOINS_RIGHT)
171 /* Joins to left: L, D, C? */
172 #define FRIBIDI_JOINS_LEFT(p) ((p) & FRIBIDI_MASK_JOINS_LEFT)
174 /* May shape: R, D, L, T? */
175 #define FRIBIDI_ARAB_SHAPES(p) ((p) & FRIBIDI_MASK_ARAB_SHAPES)
177 /* Is skipped in joining: T, G? */
178 #define FRIBIDI_IS_JOIN_SKIPPED(p) \
179 ((p) & (FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED))
181 /* Is base that will be shaped: R, D, L? */
182 #define FRIBIDI_IS_JOIN_BASE_SHAPES(p) \
183 ( FRIBIDI_MASK_ARAB_SHAPES == ( (p) & \
184 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED \
185 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
187 #define FRIBIDI_JOINS_PRECEDING_MASK(level) \
188 (FRIBIDI_LEVEL_IS_RTL (level) ? FRIBIDI_MASK_JOINS_RIGHT \
189 : FRIBIDI_MASK_JOINS_LEFT)
191 #define FRIBIDI_JOINS_FOLLOWING_MASK(level) \
192 (FRIBIDI_LEVEL_IS_RTL (level) ? FRIBIDI_MASK_JOINS_LEFT \
193 : FRIBIDI_MASK_JOINS_RIGHT)
195 #define FRIBIDI_JOIN_SHAPE(p) \
196 ((p) & ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ))
198 /* Functions finally */
201 /* fribidi_get_joining_type - get character joining type
203 * This function returns the joining type of a character as defined in Table
204 * 8-2 Primary Arabic Joining Classes of the Unicode standard available at
205 * http://www.unicode.org/versions/Unicode4.0.0/ch08.pdf#G7462, using data
206 * provided in file ArabicShaping.txt and UnicodeData.txt of the Unicode
207 * Character Database available at
208 * http://www.unicode.org/Public/UNIDATA/ArabicShaping.txt and
209 * http://www.unicode.org/Public/UNIDATA/UnicodeData.txt.
211 * There are a few macros defined in fribidi-joining-types.h for querying a
214 FRIBIDI_ENTRY FriBidiJoiningType
215 fribidi_get_joining_type (
216 FriBidiChar ch /* input character */
217 ) FRIBIDI_GNUC_CONST;
219 /* fribidi_get_joining_types - get joining types for an string of characters
221 * This function finds the joining types of an string of characters. See
222 * fribidi_get_joining_type for more information about the joining types
223 * returned by this function.
225 FRIBIDI_ENTRY void fribidi_get_joining_types (
226 const FriBidiChar *str, /* input string */
227 const FriBidiStrIndex len, /* input string length */
228 FriBidiJoiningType *jtypes /* output joining types */
231 /* fribidi_get_joining_type_name - get joining type name
233 * This function returns the joining type name of a joining type. The
234 * returned string is a static string and should not be freed.
236 * The type names are the same as ones defined in Table 8-2 Primary Arabic
237 * Joining Classes of the Unicode standard available at
238 * http://www.unicode.org/versions/Unicode4.0.0/ch08.pdf#G7462.
240 FRIBIDI_ENTRY const char *fribidi_get_joining_type_name (
241 FriBidiJoiningType j /* input joining type */
242 ) FRIBIDI_GNUC_CONST;
244 #include "fribidi-enddecls.h"
246 #endif /* !_FRIBIDI_JOINING_TYPES_H */
247 /* Editor directions:
248 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent