summaryrefslogtreecommitdiff
path: root/pango/mini-fribidi/fribidi.patch
blob: 8f4054893a33109bed4e972540a5799b319bd9b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
--- /home/otaylor/cvs/fribidi/fribidi.c	Wed Apr 11 09:30:56 2001
+++ fribidi.c	Mon Apr 16 18:02:02 2001
@@ -21,10 +21,10 @@
  * <fwpg@sharif.edu>.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "fribidi.h"
+#include <glib.h>
+#include "pango/pango-utils.h"
+#include "fribidi_types.h"
+
 #ifdef DEBUG
 #include <stdio.h>
 #endif
@@ -90,30 +90,6 @@
 #endif
 }
 
-static void
-bidi_string_reverse (FriBidiChar *str, gint len)
-{
-  gint i;
-  for (i = 0; i < len / 2; i++)
-    {
-      FriBidiChar tmp = str[i];
-      str[i] = str[len - 1 - i];
-      str[len - 1 - i] = tmp;
-    }
-}
-
-static void
-index_array_reverse (FriBidiStrIndex *arr, gint len)
-{
-  gint i;
-  for (i = 0; i < len / 2; i++)
-    {
-      FriBidiStrIndex tmp = arr[i];
-      arr[i] = arr[len - 1 - i];
-      arr[len - 1 - i] = tmp;
-    }
-}
-
 #ifndef USE_SIMPLE_MALLOC
 static TypeLink *free_type_links = NULL;
 #endif
@@ -595,7 +571,7 @@
   fprintf (stderr, "  Org. types : ");
   for (i = 0; str[i]; i++)
     fprintf (stderr, "%c",
-	     fribidi_char_from_type (fribidi_get_type (str[i])));
+	     fribidi_char_from_type (_pango_fribidi_get_type (str[i])));
   fprintf (stderr, "\n");
 }
 #endif
@@ -622,7 +598,7 @@
   {
     FriBidiCharType char_type[len];
     for (i = 0; i < len; i++)
-      char_type[i] = fribidi_get_type (str[i]);
+      char_type[i] = _pango_fribidi_get_type (str[i]);
 
     /* Run length encode the character types */
     type_rl_list = run_length_encode_types (char_type, len);
@@ -1000,7 +976,7 @@
       {
 	/* if state is on at the very first of string, do this too. */
 	if (j >= 0)
-	  k = fribidi_get_type (str[j]);
+	  k = _pango_fribidi_get_type (str[j]);
 	else
 	  k = FRIBIDI_TYPE_ON;
 	if (!state && FRIBIDI_IS_SEPARATOR (k))
@@ -1100,209 +1076,31 @@
  *----------------------------------------------------------------------*/
 
 /*======================================================================
- *  fribidi_remove_explicits() removes explicit marks, and returns the
- *  new length.
- *----------------------------------------------------------------------*/
-gint
-fribidi_remove_explicits (FriBidiChar *str, gint length)
-{
-  gint i, j;
-
-  DBG ("Entering fribidi_remove_explicits()\n");
-  j = 0;
-  for (i = 0; i < length; i++)
-    if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type (str[i]))
-	&& str[i] != UNI_LRM && str[i] != UNI_RLM)
-      str[j++] = str[i];
-
-  DBG ("Leaving fribidi_remove_explicits()\n");
-  return j;
-}
-
-/*======================================================================
- *  fribidi_log2vis() calls the function_analyse_string() and then
- *  does reordering and fills in the output strings.
- *----------------------------------------------------------------------*/
-gboolean
-fribidi_log2vis (		/* input */
-		  FriBidiChar *str, gint len, FriBidiCharType *pbase_dir,
-		  /* output */
-		  FriBidiChar *visual_str,
-		  FriBidiStrIndex *position_L_to_V_list,
-		  FriBidiStrIndex *position_V_to_L_list,
-		  guint8 *embedding_level_list)
-{
-  TypeLink *type_rl_list, *pp = NULL;
-  gint max_level;
-  gboolean private_V_to_L = FALSE;
-
-  DBG ("Entering fribidi_log2vis()\n");
-
-  if (len == 0)
-    {
-      DBG ("Leaving fribidi_log2vis()\n");
-      return TRUE;
-    }
-
-  /* If l2v is to be calculated we must have l2v as well. If it is not
-     given by the caller, we have to make a private instance of it. */
-  if (position_L_to_V_list && !position_V_to_L_list)
-    {
-      private_V_to_L = TRUE;
-      position_V_to_L_list = g_new (FriBidiStrIndex, len + 1);
-    }
-
-  if (len > FRIBIDI_MAX_STRING_LENGTH && position_V_to_L_list)
-    {
-#ifdef DEBUG
-      fprintf (stderr, "%s: cannot handle strings > %d characters\n",
-	       PACKAGE, FRIBIDI_MAX_STRING_LENGTH);
-#endif
-      return FALSE;
-    }
-  fribidi_analyse_string (str, len, pbase_dir,
-			  /* output */
-			  &type_rl_list, &max_level);
-
-  /* 7. Reordering resolved levels */
-  DBG ("Reordering resolved levels\n");
-  {
-    gint level_idx;
-    gint i;
-
-    /* TBD: L3 */
-
-    /* Set up the ordering array to sorted order */
-    if (position_V_to_L_list)
-      {
-	DBG ("  Initialize position_V_to_L_list\n");
-	for (i = 0; i < len; i++)
-	  position_V_to_L_list[i] = i;
-	DBG ("  Initialize position_V_to_L_list, Done\n");
-      }
-    /* Copy the logical string to the visual */
-    if (visual_str)
-      {
-	DBG ("  Initialize visual_str\n");
-	for (i = 0; i <= len; i++)
-	  visual_str[i] = str[i];
-	visual_str[len] = 0;
-	DBG ("  Initialize visual_str, Done\n");
-      }
-
-    /* Assign the embedding level array */
-    if (embedding_level_list)
-      {
-	DBG ("  Fill the embedding levels array\n");
-	for (pp = type_rl_list->next; pp->next; pp = pp->next)
-	  {
-	    gint i, pos, len, level;
-
-	    pos = pp->pos;
-	    len = pp->len;
-	    level = pp->level;
-	    for (i = 0; i < len; i++)
-	      embedding_level_list[pos + i] = level;
-	  }
-	DBG ("  Fill the embedding levels array, Done\n");
-      }
-
-    /* Reorder both the outstring and the order array */
-    if (visual_str || position_V_to_L_list)
-      {
-	if (mirroring && visual_str)
-	  {
-	    /* L4. Mirror all characters that are in odd levels and have mirrors. */
-	    DBG ("  Mirroring\n");
-	    for (pp = type_rl_list->next; pp->next; pp = pp->next)
-	      {
-		if (pp->level & 1)
-		  {
-		    gint i;
-		    for (i = RL_POS (pp); i < RL_POS (pp) + RL_LEN (pp); i++)
-		      {
-			FriBidiChar mirrored_ch;
-			if (fribidi_get_mirror_char
-			    (visual_str[i], &mirrored_ch))
-			  visual_str[i] = mirrored_ch;
-		      }
-		  }
-	      }
-	    DBG ("  Mirroring, Done\n");
-	  }
-
-	/* L2. Reorder. */
-	DBG ("  Reordering\n");
-	for (level_idx = max_level; level_idx > 0; level_idx--)
-	  {
-	    for (pp = type_rl_list->next; pp->next; pp = pp->next)
-	      {
-		if (RL_LEVEL (pp) >= level_idx)
-		  {
-		    /* Find all stretches that are >= level_idx */
-		    gint len = RL_LEN (pp);
-		    gint pos = RL_POS (pp);
-		    TypeLink *pp1 = pp->next;
-		    while (pp1->next && RL_LEVEL (pp1) >= level_idx)
-		      {
-			len += RL_LEN (pp1);
-			pp1 = pp1->next;
-		      }
-		    pp = pp1->prev;
-		    if (visual_str)
-		      bidi_string_reverse (visual_str + pos, len);
-		    if (position_V_to_L_list)
-		      index_array_reverse (position_V_to_L_list + pos, len);
-		  }
-	      }
-	  }
-	DBG ("  Reordering, Done\n");
-      }
-
-    /* Convert the v2l list to l2v */
-    if (position_L_to_V_list)
-      {
-	DBG ("  Converting v2l list to l2v\n");
-	for (i = 0; i <= len; i++)
-	  position_L_to_V_list[position_V_to_L_list[i]] = i;
-	DBG ("  Converting v2l list to l2v, Done\n");
-      }
-  }
-  DBG ("Reordering resolved levels, Done\n");
-
-  if (private_V_to_L)
-    g_free (position_V_to_L_list);
-
-  free_rl_list (type_rl_list);
-
-  DBG ("Leaving fribidi_log2vis()\n");
-  return TRUE;
-
-}
-
-/*======================================================================
  *  fribidi_log2vis_get_embedding_levels() is used in order to just get
  *  the embedding levels.
  *----------------------------------------------------------------------*/
 gboolean
-fribidi_log2vis_get_embedding_levels (	/* input */
-				       FriBidiChar *str,
-				       gint len, FriBidiCharType *pbase_dir,
+pango_log2vis_get_embedding_levels (	/* input */
+				       gunichar *str,
+				       int len, PangoDirection *pbase_dir,
 				       /* output */
 				       guint8 *embedding_level_list)
 {
   TypeLink *type_rl_list, *pp;
   gint max_level;
+  FriBidiCharType fribidi_base_dir;
 
   DBG ("Entering fribidi_log2vis_get_embedding_levels()\n");
 
+  fribidi_base_dir = (*pbase_dir == PANGO_DIRECTION_LTR) ? FRIBIDI_TYPE_L : FRIBIDI_TYPE_R;
+
   if (len == 0)
     {
       DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
       return TRUE;
     }
 
-  fribidi_analyse_string (str, len, pbase_dir,
+  fribidi_analyse_string (str, len, &fribidi_base_dir,
 			  /* output */
 			  &type_rl_list, &max_level);
 
@@ -1317,31 +1115,9 @@
     }
 
   free_rl_list (type_rl_list);
+    
+  *pbase_dir = (fribidi_base_dir == FRIBIDI_TYPE_L) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
 
   DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
   return TRUE;
 }
-
-gchar *fribidi_version_info =
-  "Copyright (C) 2001 FriBidi Project.\n"
-  PACKAGE " comes with NO WARRANTY, to the extent permitted by law.\n"
-  "You may redistribute copies of " PACKAGE " under the terms of\n"
-  "the GNU General Public License.\n"
-  "For more information about these matters, see the files named COPYING.\n"
-#if (defined(MEM_OPTIMIZED) || defined(DEBUG) || defined(USE_SIMPLE_MALLOC) \
-    || defined(FRIBIDI_USE_MINI_GLIB))
-  "This " PACKAGE " is compiled with following options:\n"
-#if (defined(MEM_OPTIMIZED))
-  "MEM_OPTIMIZED\n"
-#endif
-#if (defined(DEBUG))
-  "DEBUG\n"
-#endif
-#if (defined(USE_SIMPLE_MALLOC))
-  "USE_SIMPLE_MALLOC\n"
-#endif
-#if (defined(FRIBIDI_USE_MINI_GLIB))
-  "FRIBIDI_USE_MINI_GLIB\n"
-#endif
-#endif
- ;
--- /home/otaylor/cvs/fribidi/fribidi_get_type.c	Mon Apr  9 08:40:57 2001
+++ fribidi_get_type.c	Mon Apr 16 17:50:54 2001
@@ -23,7 +23,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "fribidi.h"
+#include <glib.h>
+#include "pango/pango-utils.h"
+#include "fribidi_types.h"
 #include "fribidi_tables.i"
 
 #ifdef MEM_OPTIMIZED
@@ -34,7 +36,7 @@
  *  fribidi_get_type() returns the bidi type of a character.
  *----------------------------------------------------------------------*/
 FriBidiCharType
-fribidi_get_type (FriBidiChar uch)
+_pango_fribidi_get_type(FriBidiChar uch)
 {
   int i = uch % 256, j = uch / 256;
   FriBidiPropCharType *block = FriBidiPropertyBlocks[j];
@@ -81,10 +83,10 @@
 }
 
 gboolean
-fribidi_get_mirror_char (	/* Input */
-			  FriBidiChar ch,
-			  /* Output */
-			  FriBidiChar *mirrored_ch)
+pango_get_mirror_char (	/* Input */
+		       FriBidiChar ch,
+		       /* Output */
+		       FriBidiChar * mirrored_ch)
 {
   int pos, step;
   gboolean found;
--- /home/otaylor/cvs/fribidi/fribidi_tables.i	Sat Apr  7 14:54:47 2001
+++ fribidi_tables.i	Mon Apr 16 17:53:51 2001
@@ -4,8 +4,6 @@
  *----------------------------------------------------------------------*/
 /* *INDENT-OFF* */
 
-#include "fribidi.h"
-
 #define WS FRIBIDI_PROP_TYPE_WS
 #define BS FRIBIDI_PROP_TYPE_BS
 #define EO FRIBIDI_PROP_TYPE_EO
--- /home/otaylor/cvs/fribidi/fribidi_types.h	Mon Apr  9 08:40:57 2001
+++ fribidi_types.h	Mon Apr 16 17:52:01 2001
@@ -279,4 +279,6 @@
 #define FRIBIDI_MAX_STRING_LENGTH 65535
 #endif
 
+FriBidiCharType _pango_fribidi_get_type(FriBidiChar uch);
+
 #endif