add packaging
[platform/upstream/fribidi.git] / lib / fribidi-deprecated.c
1 /* FriBidi
2  * fribidi-deprecated.c - deprecated interfaces.
3  *
4  * $Id: fribidi-deprecated.c,v 1.6 2006-06-01 22:53:55 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2006-06-01 22:53:55 $
7  * $Revision: 1.6 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-deprecated.c,v $
9  *
10  * Authors:
11  *   Behdad Esfahbod, 2001, 2002, 2004
12  *   Dov Grobgeld, 1999, 2000
13  *
14  * Copyright (C) 2004 Sharif FarsiWeb, Inc
15  * Copyright (C) 2001,2002 Behdad Esfahbod
16  * Copyright (C) 1999,2000 Dov Grobgeld
17  * 
18  * This library is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU Lesser General Public
20  * License as published by the Free Software Foundation; either
21  * version 2.1 of the License, or (at your option) any later version.
22  * 
23  * This library is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26  * Lesser General Public License for more details.
27  * 
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with this library, in a file named COPYING; if not, write to the
30  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31  * Boston, MA 02110-1301, USA
32  * 
33  * For licensing issues, contact <license@farsiweb.info>.
34  */
35
36 #include "common.h"
37
38 #undef FRIBIDI_NO_DEPRECATED
39
40 #include <fribidi-deprecated.h>
41 #include <fribidi.h>
42
43 #if FRIBIDI_NO_DEPRECATED+0
44 #else
45
46 static FriBidiFlags flags = FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC;
47
48 FRIBIDI_ENTRY fribidi_boolean
49 fribidi_set_mirroring (
50   /* input */
51   fribidi_boolean state
52 )
53 {
54   return FRIBIDI_ADJUST_AND_TEST_BITS (flags, FRIBIDI_FLAG_SHAPE_MIRRORING, state);
55 }
56
57 FRIBIDI_ENTRY fribidi_boolean
58 fribidi_mirroring_status (
59   void
60 )
61 {
62   return FRIBIDI_TEST_BITS (flags, FRIBIDI_FLAG_SHAPE_MIRRORING);
63 }
64
65 FRIBIDI_ENTRY fribidi_boolean
66 fribidi_set_reorder_nsm (
67   /* input */
68   fribidi_boolean state
69 )
70 {
71   return FRIBIDI_ADJUST_AND_TEST_BITS (flags, FRIBIDI_FLAG_REORDER_NSM, state);
72 }
73
74 fribidi_boolean
75 fribidi_reorder_nsm_status (
76   void
77 )
78 {
79   return FRIBIDI_TEST_BITS (flags, FRIBIDI_FLAG_REORDER_NSM);
80 }
81
82
83
84
85 FRIBIDI_ENTRY FriBidiLevel
86 fribidi_log2vis_get_embedding_levels (
87   const FriBidiCharType *bidi_types,    /* input list of bidi types as returned by
88                                            fribidi_get_bidi_types() */
89   const FriBidiStrIndex len,    /* input string length of the paragraph */
90   FriBidiParType *pbase_dir,    /* requested and resolved paragraph
91                                  * base direction */
92   FriBidiLevel *embedding_levels        /* output list of embedding levels */
93 )
94 {
95   return fribidi_get_par_embedding_levels (bidi_types, len, pbase_dir, embedding_levels);
96 }
97
98 FRIBIDI_ENTRY FriBidiCharType
99 fribidi_get_type (
100   FriBidiChar ch                /* input character */
101 )
102 {
103   return fribidi_get_bidi_type (ch);
104 }
105
106 FRIBIDI_ENTRY FriBidiCharType
107 fribidi_get_type_internal (
108   FriBidiChar ch                /* input character */
109 )
110 {
111   return fribidi_get_bidi_type (ch);
112 }
113
114
115
116 FRIBIDI_ENTRY FriBidiStrIndex
117 fribidi_remove_bidi_marks (
118   FriBidiChar *str,
119   const FriBidiStrIndex len,
120   FriBidiStrIndex *positions_to_this,
121   FriBidiStrIndex *position_from_this_list,
122   FriBidiLevel *embedding_levels
123 )
124 {
125   register FriBidiStrIndex i, j = 0;
126   fribidi_boolean private_from_this = false;
127   fribidi_boolean status = false;
128
129   if UNLIKELY
130     (len == 0)
131     {
132       status = true;
133       goto out;
134     }
135
136   DBG ("in fribidi_remove_bidi_marks");
137
138   fribidi_assert (str);
139
140   /* If to_this is not NULL, we must have from_this as well. If it is
141      not given by the caller, we have to make a private instance of it. */
142   if (positions_to_this && !position_from_this_list)
143     {
144       position_from_this_list = fribidi_malloc (sizeof
145                                                 (position_from_this_list[0]) *
146                                                 len);
147       if UNLIKELY
148         (!position_from_this_list) goto out;
149       private_from_this = true;
150       for (i = 0; i < len; i++)
151         position_from_this_list[positions_to_this[i]] = i;
152     }
153
154   for (i = 0; i < len; i++)
155     if (!FRIBIDI_IS_EXPLICIT_OR_BN (fribidi_get_bidi_type (str[i]))
156         && str[i] != FRIBIDI_CHAR_LRM && str[i] != FRIBIDI_CHAR_RLM)
157       {
158         str[j] = str[i];
159         if (embedding_levels)
160           embedding_levels[j] = embedding_levels[i];
161         if (position_from_this_list)
162           position_from_this_list[j] = position_from_this_list[i];
163         j++;
164       }
165
166   /* Convert the from_this list to to_this */
167   if (positions_to_this)
168     {
169       for (i = 0; i < len; i++)
170         positions_to_this[i] = -1;
171       for (i = 0; i < len; i++)
172         positions_to_this[position_from_this_list[i]] = i;
173     }
174
175   status = true;
176
177 out:
178
179   if (private_from_this)
180     fribidi_free (position_from_this_list);
181
182   return status ? j : -1;
183 }
184
185
186
187 FRIBIDI_ENTRY FriBidiLevel
188 fribidi_log2vis (
189   /* input */
190   const FriBidiChar *str,
191   FriBidiStrIndex len,
192   /* input and output */
193   FriBidiParType *pbase_dir,
194   /* output */
195   FriBidiChar *visual_str,
196   FriBidiStrIndex *positions_L_to_V,
197   FriBidiStrIndex *positions_V_to_L,
198   FriBidiLevel *embedding_levels
199 )
200 {
201   register FriBidiStrIndex i;
202   FriBidiLevel max_level = 0;
203   fribidi_boolean private_V_to_L = false;
204   fribidi_boolean private_embedding_levels = false;
205   fribidi_boolean status = false;
206   FriBidiArabicProp *ar_props = NULL;
207   FriBidiCharType *bidi_types = NULL;
208
209   if UNLIKELY
210     (len == 0)
211     {
212       status = true;
213       goto out;
214     }
215
216   DBG ("in fribidi_log2vis");
217
218   fribidi_assert (str);
219   fribidi_assert (pbase_dir);
220
221   bidi_types = fribidi_malloc (len * sizeof bidi_types[0]);
222   if (!bidi_types)
223     goto out;
224
225   fribidi_get_bidi_types (str, len, bidi_types);
226
227   if (!embedding_levels)
228     {
229       embedding_levels = fribidi_malloc (len * sizeof embedding_levels[0]);
230       if (!embedding_levels)
231         goto out;
232       private_embedding_levels = true;
233     }
234
235   max_level = fribidi_get_par_embedding_levels (bidi_types, len, pbase_dir,
236                                                 embedding_levels) - 1;
237   if UNLIKELY
238     (max_level < 0) goto out;
239
240   /* If l2v is to be calculated we must have v2l as well. If it is not
241      given by the caller, we have to make a private instance of it. */
242   if (positions_L_to_V && !positions_V_to_L)
243     {
244       positions_V_to_L =
245         (FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) * len);
246       if (!positions_V_to_L)
247         goto out;
248       private_V_to_L = true;
249     }
250
251   /* Set up the ordering array to identity order */
252   if (positions_V_to_L)
253     {
254       for (i = 0; i < len; i++)
255         positions_V_to_L[i] = i;
256     }
257
258
259   if (visual_str)
260     {
261       /* Using memcpy instead
262       for (i = len - 1; i >= 0; i--)
263         visual_str[i] = str[i];
264       */
265       memcpy (visual_str, str, len * sizeof (*visual_str));
266
267       /* Arabic joining */
268       ar_props = fribidi_malloc (len * sizeof ar_props[0]);
269       fribidi_get_joining_types (str, len, ar_props);
270       fribidi_join_arabic (bidi_types, len, embedding_levels, ar_props);
271
272       fribidi_shape (flags, embedding_levels, len, ar_props, visual_str);
273     }
274
275   /* line breaking goes here, but we assume one line in this function */
276
277   /* and this should be called once per line, but again, we assume one
278    * line in this deprecated function */
279   status =
280     fribidi_reorder_line (flags, bidi_types, len, 0, *pbase_dir,
281                           embedding_levels, visual_str,
282                           positions_V_to_L);
283
284   /* Convert the v2l list to l2v */
285   if (positions_L_to_V)
286     {
287       for (i = 0; i < len; i++)
288         positions_L_to_V[i] = -1;
289       for (i = 0; i < len; i++)
290         positions_L_to_V[positions_V_to_L[i]] = i;
291     }
292
293 out:
294
295   if (private_V_to_L)
296     fribidi_free (positions_V_to_L);
297
298   if (private_embedding_levels)
299     fribidi_free (embedding_levels);
300
301   if (ar_props)
302     fribidi_free (ar_props);
303
304   if (bidi_types)
305     fribidi_free (bidi_types);
306
307   return status ? max_level + 1 : 0;
308 }
309
310 #endif /* !FRIBIDI_NO_DEPRECATED */
311
312 /* Editor directions:
313  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
314  */