Imported Upstream version 0.19.7
[platform/upstream/fribidi.git] / lib / fribidi-joining-types.h
1 /* FriBidi
2  * fribidi-joining-types.h - character joining types
3  *
4  * $Id: fribidi-joining-types.h,v 1.5 2005-11-03 01:39:01 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2005-11-03 01:39:01 $
7  * $Revision: 1.5 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-joining-types.h,v $
9  *
10  * Author:
11  *   Behdad Esfahbod, 2001, 2002, 2004
12  *
13  * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14  * Copyright (C) 2001,2002 Behdad Esfahbod
15  * 
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.
20  * 
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.
25  * 
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
30  *
31  * For licensing issues, contact <license@farsiweb.info>.
32  */
33 #ifndef _FRIBIDI_JOINING_TYPES_H
34 #define _FRIBIDI_JOINING_TYPES_H
35
36 #include "fribidi-common.h"
37
38 #include "fribidi-types.h"
39
40 #include "fribidi-begindecls.h"
41
42 /* 
43  * Define bit masks that joining types are based on, each mask has
44  * only one bit set.
45  */
46
47 #define FRIBIDI_MASK_JOINS_RIGHT        0x01    /* May join to right */
48 #define FRIBIDI_MASK_JOINS_LEFT         0x02    /* May join to right */
49 #define FRIBIDI_MASK_ARAB_SHAPES        0x04    /* May Arabic shape */
50 #define FRIBIDI_MASK_TRANSPARENT        0x08    /* Is transparent */
51 #define FRIBIDI_MASK_IGNORED            0x10    /* Is ignored */
52 #define FRIBIDI_MASK_LIGATURED          0x20    /* Is ligatured */
53
54 /*
55  * Define values for FriBidiJoiningType
56  */
57
58 /* nUn-joining */
59 #define FRIBIDI_JOINING_TYPE_U_VAL      ( 0 )
60
61 /* Right-joining */
62 #define FRIBIDI_JOINING_TYPE_R_VAL      \
63         ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_ARAB_SHAPES )
64
65 /* Dual-joining */
66 #define FRIBIDI_JOINING_TYPE_D_VAL      \
67         ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT \
68         | FRIBIDI_MASK_ARAB_SHAPES )
69
70 /* join-Causing */
71 #define FRIBIDI_JOINING_TYPE_C_VAL      \
72         ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT )
73
74 /* Left-joining */
75 #define FRIBIDI_JOINING_TYPE_L_VAL      \
76         ( FRIBIDI_MASK_JOINS_LEFT | FRIBIDI_MASK_ARAB_SHAPES )
77
78 /* Transparent */
79 #define FRIBIDI_JOINING_TYPE_T_VAL      \
80         ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_ARAB_SHAPES )
81
82 /* iGnored */
83 #define FRIBIDI_JOINING_TYPE_G_VAL      ( FRIBIDI_MASK_IGNORED )
84
85
86 enum _FriBidiJoiningTypeEnum
87 {
88 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
89         FRIBIDI_JOINING_TYPE_##TYPE = FRIBIDI_JOINING_TYPE_##TYPE##_VAL,
90 # include "fribidi-joining-types-list.h"
91 # undef _FRIBIDI_ADD_TYPE
92   _FRIBIDI_JOINING_TYPE_JUNK    /* Don't use this */
93 };
94
95 #ifdef __FRIBIDI_DOC
96 typedef enum _FriBidiJoiningTypeEnum FriBidiJoiningType;
97 #else /* !__FRIBIDI_DOC */
98 typedef fribidi_uint8 FriBidiJoiningType;
99 #endif /* !__FRIBIDI_DOC */
100
101 /* FriBidiArabicProp is essentially the same type as FriBidiJoiningType, but
102  * not limited to the few values returned by fribidi_get_joining_type. */
103 typedef fribidi_uint8 FriBidiArabicProp;
104
105 /*
106  * The equivalent of JoiningType values for ArabicProp
107  */
108
109 /* Primary Arabic Joining Classes (Table 8-2) */
110
111 /* nUn-joining */
112 #define FRIBIDI_IS_JOINING_TYPE_U(p)    \
113         ( 0 == ( (p) &  \
114                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
115                 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
116
117 /* Right-joining */
118 #define FRIBIDI_IS_JOINING_TYPE_R(p)    \
119         ( FRIBIDI_MASK_JOINS_RIGHT == ( (p) &   \
120                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
121                 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
122
123 /* Dual-joining */
124 #define FRIBIDI_IS_JOINING_TYPE_D(p)    \
125         ( ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT  \
126           | FRIBIDI_MASK_ARAB_SHAPES ) == ( (p) &       \
127                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
128                 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT    \
129                 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
130
131 /* join-Causing */
132 #define FRIBIDI_IS_JOINING_TYPE_C(p)    \
133         ( ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) == ( (p) & \
134                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
135                 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT    \
136                 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
137
138 /* Left-joining */
139 #define FRIBIDI_IS_JOINING_TYPE_L(p)    \
140         ( FRIBIDI_MASK_JOINS_LEFT == ( (p) &    \
141                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
142                 | FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ) ) )
143
144 /* Transparent */
145 #define FRIBIDI_IS_JOINING_TYPE_T(p)    \
146         ( FRIBIDI_MASK_TRANSPARENT == ( (p) &   \
147                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED ) ) )
148
149 /* iGnored */
150 #define FRIBIDI_IS_JOINING_TYPE_G(p)    \
151         ( FRIBIDI_MASK_IGNORED == ( (p) &       \
152                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED ) ) )
153
154 /* and for Derived Arabic Joining Classes (Table 8-3) */
155
156 /* Right join-Causing */
157 #define FRIBIDI_IS_JOINING_TYPE_RC(p)   \
158         ( FRIBIDI_MASK_JOINS_RIGHT == ( (p) &   \
159                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
160                 | FRIBIDI_MASK_JOINS_RIGHT ) ) )
161
162 /* Left join-Causing */
163 #define FRIBIDI_IS_JOINING_TYPE_LC(p)   \
164         ( FRIBIDI_MASK_JOINS_LEFT == ( (p) &    \
165                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
166                 | FRIBIDI_MASK_JOINS_LEFT ) ) )
167
168
169 /*
170  * Defining macros for needed queries, It is fully dependent on the 
171  * implementation of FriBidiJoiningType.
172  */
173
174 /* Joins to right: R, D, C? */
175 #define FRIBIDI_JOINS_RIGHT(p)  ((p) & FRIBIDI_MASK_JOINS_RIGHT)
176
177 /* Joins to left: L, D, C? */
178 #define FRIBIDI_JOINS_LEFT(p)   ((p) & FRIBIDI_MASK_JOINS_LEFT)
179
180 /* May shape: R, D, L, T? */
181 #define FRIBIDI_ARAB_SHAPES(p)  ((p) & FRIBIDI_MASK_ARAB_SHAPES)
182
183 /* Is skipped in joining: T, G? */
184 #define FRIBIDI_IS_JOIN_SKIPPED(p)      \
185         ((p) & (FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED))
186
187 /* Is base that will be shaped: R, D, L? */
188 #define FRIBIDI_IS_JOIN_BASE_SHAPES(p)  \
189         ( FRIBIDI_MASK_ARAB_SHAPES == ( (p) &   \
190                 ( FRIBIDI_MASK_TRANSPARENT | FRIBIDI_MASK_IGNORED       \
191                 | FRIBIDI_MASK_ARAB_SHAPES ) ) )
192
193 #define FRIBIDI_JOINS_PRECEDING_MASK(level)     \
194         (FRIBIDI_LEVEL_IS_RTL (level) ? FRIBIDI_MASK_JOINS_RIGHT        \
195                                       : FRIBIDI_MASK_JOINS_LEFT)
196
197 #define FRIBIDI_JOINS_FOLLOWING_MASK(level)     \
198         (FRIBIDI_LEVEL_IS_RTL (level) ? FRIBIDI_MASK_JOINS_LEFT \
199                                       : FRIBIDI_MASK_JOINS_RIGHT)
200
201 #define FRIBIDI_JOIN_SHAPE(p)   \
202         ((p) & ( FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT ))
203
204 /* Functions finally */
205
206
207 #define fribidi_get_joining_type FRIBIDI_NAMESPACE(get_joining_type)
208 /* fribidi_get_joining_type - get character joining type
209  *
210  * This function returns the joining type of a character as defined in Table
211  * 8-2 Primary Arabic Joining Classes of the Unicode standard available at
212  * http://www.unicode.org/versions/Unicode4.0.0/ch08.pdf#G7462, using data
213  * provided in file ArabicShaping.txt and UnicodeData.txt of the Unicode
214  * Character Database available at
215  * http://www.unicode.org/Public/UNIDATA/ArabicShaping.txt and
216  * http://www.unicode.org/Public/UNIDATA/UnicodeData.txt. 
217  *
218  * There are a few macros defined in fribidi-joining-types.h for querying a
219  * joining type.
220  */
221 FRIBIDI_ENTRY FriBidiJoiningType
222 fribidi_get_joining_type (
223   FriBidiChar ch                /* input character */
224 ) FRIBIDI_GNUC_CONST;
225
226 #define fribidi_get_joining_types FRIBIDI_NAMESPACE(get_joining_types)
227 /* fribidi_get_joining_types - get joining types for an string of characters
228  *
229  * This function finds the joining types of an string of characters.  See
230  * fribidi_get_joining_type for more information about the joining types
231  * returned by this function.
232  */
233      FRIBIDI_ENTRY void fribidi_get_joining_types (
234   const FriBidiChar *str,       /* input string */
235   const FriBidiStrIndex len,    /* input string length */
236   FriBidiJoiningType *jtypes    /* output joining types */
237 );
238
239 #define fribidi_get_joining_type_name FRIBIDI_NAMESPACE(get_joining_type_name)
240 /* fribidi_get_joining_type_name - get joining type name
241  *
242  * This function returns the joining type name of a joining type.  The
243  * returned string is a static string and should not be freed.
244  *
245  * The type names are the same as ones defined in Table 8-2  Primary Arabic
246  * Joining Classes of the Unicode standard available at
247  * http://www.unicode.org/versions/Unicode4.0.0/ch08.pdf#G7462.
248  */
249      FRIBIDI_ENTRY const char *fribidi_get_joining_type_name (
250   FriBidiJoiningType j          /* input joining type */
251 ) FRIBIDI_GNUC_CONST;
252
253 #include "fribidi-enddecls.h"
254
255 #endif /* !_FRIBIDI_JOINING_TYPES_H */
256 /* Editor directions:
257  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
258  */