2 * fribidi-deprecated.c - deprecated interfaces.
5 * Behdad Esfahbod, 2001, 2002, 2004
6 * Dov Grobgeld, 1999, 2000
8 * Copyright (C) 2004 Sharif FarsiWeb, Inc
9 * Copyright (C) 2001,2002 Behdad Esfahbod
10 * Copyright (C) 1999,2000 Dov Grobgeld
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library, in a file named COPYING; if not, write to the
24 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA
27 * For licensing issues, contact <fribidi.license@gmail.com>.
32 #undef FRIBIDI_NO_DEPRECATED
34 #include <fribidi-deprecated.h>
37 #ifdef FRIBIDI_NO_DEPRECATED
40 static FriBidiFlags flags = FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC;
42 FRIBIDI_ENTRY fribidi_boolean
43 fribidi_set_mirroring (
48 return FRIBIDI_ADJUST_AND_TEST_BITS (flags, FRIBIDI_FLAG_SHAPE_MIRRORING, state);
51 FRIBIDI_ENTRY fribidi_boolean
52 fribidi_mirroring_status (
56 return FRIBIDI_TEST_BITS (flags, FRIBIDI_FLAG_SHAPE_MIRRORING);
59 FRIBIDI_ENTRY fribidi_boolean
60 fribidi_set_reorder_nsm (
65 return FRIBIDI_ADJUST_AND_TEST_BITS (flags, FRIBIDI_FLAG_REORDER_NSM, state);
69 fribidi_reorder_nsm_status (
73 return FRIBIDI_TEST_BITS (flags, FRIBIDI_FLAG_REORDER_NSM);
79 FRIBIDI_ENTRY FriBidiLevel
80 fribidi_log2vis_get_embedding_levels (
81 const FriBidiCharType *bidi_types, /* input list of bidi types as returned by
82 fribidi_get_bidi_types() */
83 const FriBidiStrIndex len, /* input string length of the paragraph */
84 FriBidiParType *pbase_dir, /* requested and resolved paragraph
86 FriBidiLevel *embedding_levels /* output list of embedding levels */
89 return fribidi_get_par_embedding_levels_ex (bidi_types, NULL, len, pbase_dir, embedding_levels);
92 FRIBIDI_ENTRY FriBidiCharType
94 FriBidiChar ch /* input character */
97 return fribidi_get_bidi_type (ch);
100 FRIBIDI_ENTRY FriBidiCharType
101 fribidi_get_type_internal (
102 FriBidiChar ch /* input character */
105 return fribidi_get_bidi_type (ch);
110 FRIBIDI_ENTRY FriBidiStrIndex
111 fribidi_remove_bidi_marks (
113 const FriBidiStrIndex len,
114 FriBidiStrIndex *positions_to_this,
115 FriBidiStrIndex *position_from_this_list,
116 FriBidiLevel *embedding_levels
119 register FriBidiStrIndex i, j = 0;
120 fribidi_boolean private_from_this = false;
121 fribidi_boolean status = false;
130 DBG ("in fribidi_remove_bidi_marks");
132 fribidi_assert (str);
134 /* If to_this is not NULL, we must have from_this as well. If it is
135 not given by the caller, we have to make a private instance of it. */
136 if (positions_to_this && !position_from_this_list)
138 position_from_this_list = fribidi_malloc (sizeof
139 (position_from_this_list[0]) *
142 (!position_from_this_list) goto out;
143 private_from_this = true;
144 for (i = 0; i < len; i++)
145 position_from_this_list[positions_to_this[i]] = i;
148 for (i = 0; i < len; i++)
149 if (!FRIBIDI_IS_EXPLICIT_OR_BN (fribidi_get_bidi_type (str[i]))
150 && !FRIBIDI_IS_ISOLATE (fribidi_get_bidi_type (str[i]))
151 && str[i] != FRIBIDI_CHAR_LRM && str[i] != FRIBIDI_CHAR_RLM)
154 if (embedding_levels)
155 embedding_levels[j] = embedding_levels[i];
156 if (position_from_this_list)
157 position_from_this_list[j] = position_from_this_list[i];
161 /* Convert the from_this list to to_this */
162 if (positions_to_this)
164 for (i = 0; i < len; i++)
165 positions_to_this[i] = -1;
166 for (i = 0; i < len; i++)
167 positions_to_this[position_from_this_list[i]] = i;
174 if (private_from_this)
175 fribidi_free (position_from_this_list);
177 return status ? j : -1;
180 /* Local array size, used for stack-based local arrays */
181 #define LOCAL_LIST_SIZE 128
183 FRIBIDI_ENTRY FriBidiLevel
186 const FriBidiChar *str,
188 /* input and output */
189 FriBidiParType *pbase_dir,
191 FriBidiChar *visual_str,
192 FriBidiStrIndex *positions_L_to_V,
193 FriBidiStrIndex *positions_V_to_L,
194 FriBidiLevel *embedding_levels
197 register FriBidiStrIndex i;
198 FriBidiLevel max_level = 0;
199 fribidi_boolean private_V_to_L = false;
200 fribidi_boolean private_embedding_levels = false;
201 fribidi_boolean status = false;
202 FriBidiArabicProp local_ar_props[LOCAL_LIST_SIZE];
203 FriBidiArabicProp *ar_props = NULL;
204 FriBidiLevel local_embedding_levels[LOCAL_LIST_SIZE];
205 FriBidiCharType local_bidi_types[LOCAL_LIST_SIZE];
206 FriBidiCharType *bidi_types = NULL;
207 FriBidiBracketType local_bracket_types[LOCAL_LIST_SIZE];
208 FriBidiBracketType *bracket_types = NULL;
209 FriBidiStrIndex local_positions_V_to_L[LOCAL_LIST_SIZE];
218 DBG ("in fribidi_log2vis");
220 fribidi_assert (str);
221 fribidi_assert (pbase_dir);
223 if (len < LOCAL_LIST_SIZE)
224 bidi_types = local_bidi_types;
226 bidi_types = fribidi_malloc (len * sizeof bidi_types[0]);
230 fribidi_get_bidi_types (str, len, bidi_types);
232 if (len < LOCAL_LIST_SIZE)
233 bracket_types = local_bracket_types;
235 bracket_types = fribidi_malloc (len * sizeof bracket_types[0]);
240 fribidi_get_bracket_types (str, len, bidi_types,
243 if (!embedding_levels)
245 if (len < LOCAL_LIST_SIZE)
246 embedding_levels = local_embedding_levels;
248 embedding_levels = fribidi_malloc (len * sizeof embedding_levels[0]);
249 if (!embedding_levels)
251 private_embedding_levels = true;
254 max_level = fribidi_get_par_embedding_levels_ex (bidi_types,
258 embedding_levels) - 1;
260 (max_level < 0) goto out;
262 /* If l2v is to be calculated we must have v2l as well. If it is not
263 given by the caller, we have to make a private instance of it. */
264 if (positions_L_to_V && !positions_V_to_L)
266 if (len < LOCAL_LIST_SIZE)
267 positions_V_to_L = local_positions_V_to_L;
270 (FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) * len);
271 if (!positions_V_to_L)
273 private_V_to_L = true;
276 /* Set up the ordering array to identity order */
277 if (positions_V_to_L)
279 for (i = 0; i < len; i++)
280 positions_V_to_L[i] = i;
286 /* Using memcpy instead
287 for (i = len - 1; i >= 0; i--)
288 visual_str[i] = str[i];
290 memcpy (visual_str, str, len * sizeof (*visual_str));
293 if (len < LOCAL_LIST_SIZE)
294 ar_props = local_ar_props;
296 ar_props = fribidi_malloc (len * sizeof ar_props[0]);
297 fribidi_get_joining_types (str, len, ar_props);
298 fribidi_join_arabic (bidi_types, len, embedding_levels, ar_props);
300 fribidi_shape (flags, embedding_levels, len, ar_props, visual_str);
303 /* line breaking goes here, but we assume one line in this function */
305 /* and this should be called once per line, but again, we assume one
306 * line in this deprecated function */
308 fribidi_reorder_line (flags, bidi_types, len, 0, *pbase_dir,
309 embedding_levels, visual_str,
312 /* Convert the v2l list to l2v */
313 if (positions_L_to_V)
315 for (i = 0; i < len; i++)
316 positions_L_to_V[i] = -1;
317 for (i = 0; i < len; i++)
318 positions_L_to_V[positions_V_to_L[i]] = i;
323 if (private_V_to_L && positions_V_to_L != local_positions_V_to_L)
324 fribidi_free (positions_V_to_L);
326 if (private_embedding_levels && embedding_levels != local_embedding_levels)
327 fribidi_free (embedding_levels);
329 if (ar_props && ar_props != local_ar_props)
330 fribidi_free (ar_props);
332 if (bidi_types && bidi_types != local_bidi_types)
333 fribidi_free (bidi_types);
335 if (bracket_types && bracket_types != local_bracket_types)
336 fribidi_free (bracket_types);
338 return status ? max_level + 1 : 0;
341 FRIBIDI_ENTRY FriBidiLevel
342 fribidi_get_par_embedding_levels (
344 const FriBidiCharType *bidi_types,
345 const FriBidiStrIndex len,
346 /* input and output */
347 FriBidiParType *pbase_dir,
349 FriBidiLevel *embedding_levels
352 return fribidi_get_par_embedding_levels_ex (/* input */
354 NULL, /* No bracket_types */
356 /* input and output */
362 #endif /* !FRIBIDI_NO_DEPRECATED */
364 /* Editor directions:
365 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent