[FriBidi-commit] fribidi/lib bidi-types.h, 1.4, 1.5 fribidi-bidi-type.c, 1.12, 1.13 fribidi-bidi-type.h, 1.5, 1.6 fribidi-bidi.c, 1.10, 1.11 fribidi-bidi.h, 1.7, 1.8 fribidi-run.c, 1.3, 1.4 fribidi.c, 1.8, 1.9 run.h, 1.5, 1.6

Behdad Esfahbod behdad at pdx.freedesktop.org
Mon Jun 14 10:00:35 PDT 2004


Update of /cvs/fribidi/fribidi/lib
In directory pdx:/tmp/cvs-serv20554/lib

Modified Files:
	bidi-types.h fribidi-bidi-type.c fribidi-bidi-type.h 
	fribidi-bidi.c fribidi-bidi.h fribidi-run.c fribidi.c run.h 
Log Message:
fribidi_get_bidi_types is back.  Allow passing bidi types to
get_par_embedding_levels and reorder_line functions.


Index: bidi-types.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/bidi-types.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- bidi-types.h	7 May 2004 06:30:38 -0000	1.4
+++ bidi-types.h	14 Jun 2004 17:00:33 -0000	1.5
@@ -53,6 +53,8 @@
 
 #endif /* DEBUG */
 
+#define BIDI_TYPE(i) (bidi_types ? bidi_types[(i)] : fribidi_get_bidi_type(str[(i)]))
+
 #include <fribidi-enddecls.h>
 
 #endif /* !_BIDI_TYPES_H */

Index: fribidi-bidi-type.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi-type.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- fribidi-bidi-type.c	13 Jun 2004 20:11:42 -0000	1.12
+++ fribidi-bidi-type.c	14 Jun 2004 17:00:33 -0000	1.13
@@ -60,3 +60,21 @@
 {
   return linear_enum_to_char_type[FRIBIDI_GET_BIDI_TYPE (ch)];
 }
+
+FRIBIDI_ENTRY void
+fribidi_get_bidi_types (
+  /* input */
+  const FriBidiChar *str,
+  FriBidiStrIndex len,
+  /* output */
+  FriBidiCharType *type
+)
+{
+  register FriBidiStrIndex i = len;
+  for (; i; i--)
+    *type++ = fribidi_get_bidi_type (*str++);
+}
+
+/* Editor directions:
+ * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
+ */

Index: fribidi-bidi-type.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi-type.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- fribidi-bidi-type.h	9 Jun 2004 14:59:21 -0000	1.5
+++ fribidi-bidi-type.h	14 Jun 2004 17:00:33 -0000	1.6
@@ -51,6 +51,19 @@
   FriBidiChar ch		/* input character */
 ) FRIBIDI_GNUC_CONST;
 
+#define fribidi_get_bidi_types FRIBIDI_NAMESPACE(get_bidi_types)
+/* fribidi_get_bidi_types - get bidi types for an string of characters
+ *
+ * This function finds the bidi types of an string of characters.  See
+ * fribidi_get_bidi_type for more about the bidi types returned by this
+ * function.
+ */
+     FRIBIDI_ENTRY void fribidi_get_bidi_types (
+  const FriBidiChar *str,	/* input string */
+  FriBidiStrIndex len,		/* input string length */
+  FriBidiCharType *type		/* output bidi types */
+);
+
 #include "fribidi-enddecls.h"
 
 #endif /* !_FRIBIDI_BIDI_TYPE_H */

Index: fribidi-bidi.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- fribidi-bidi.c	7 Jun 2004 20:38:21 -0000	1.10
+++ fribidi-bidi.c	14 Jun 2004 17:00:33 -0000	1.11
@@ -196,16 +196,18 @@
 print_bidi_string (
   /* input */
   const FriBidiChar *str,
-  const FriBidiStrIndex len
+  const FriBidiStrIndex len,
+  const FriBidiCharType *bidi_types
 )
 {
   register FriBidiStrIndex i;
 
-  fribidi_assert (str);
+  fribidi_assert (str || bidi_types);
 
   MSG ("  Org. types : ");
-  for (i = len; i; i--)
-    MSG2 ("%c", fribidi_char_from_bidi_type (fribidi_get_bidi_type (*str++)));
+  if (bidi_types)
+  for (i = 0; i < len; i++)
+    MSG2 ("%c", fribidi_char_from_bidi_type (BIDI_TYPE(i)));
   MSG ("\n");
 }
 #endif /* DEBUG */
@@ -215,22 +217,23 @@
  * define macros for push and pop the status in to / out of the stack
  *-------------------------------------------------------------------------*/
 
-/* There's some little points in pushing and poping into the status stack:
+/* There are a few little points in pushing into and poping from the status
+   stack:
    1. when the embedding level is not valid (more than
    FRIBIDI_BIDI_MAX_EXPLICIT_LEVEL=61), you must reject it, and not to push
    into the stack, but when you see a PDF, you must find the matching code,
    and if it was pushed in the stack, pop it, it means you must pop if and
    only if you have pushed the matching code, the over_pushed var counts the
-   number of rejected codes yet.
+   number of rejected codes so far.
    2. there's a more confusing point too, when the embedding level is exactly
-   FRIBIDI_BIDI_MAX_EXPLICIT_LEVEL-1=60, an LRO or LRE must be rejected
+   FRIBIDI_BIDI_MAX_EXPLICIT_LEVEL-1=60, an LRO or LRE is rejected
    because the new level would be FRIBIDI_BIDI_MAX_EXPLICIT_LEVEL+1=62, that
-   is invalid, but an RLO or RLE must be accepted because the new level is
+   is invalid; but an RLO or RLE is accepted because the new level is
    FRIBIDI_BIDI_MAX_EXPLICIT_LEVEL=61, that is valid, so the rejected codes
-   may be not continuous in the logical order, in fact there is at most two
-   continuous intervals of codes, with a RLO or RLE between them.  To support
+   may be not continuous in the logical order, in fact there are at most two
+   continuous intervals of codes, with an RLO or RLE between them.  To support
    this case, the first_interval var counts the number of rejected codes in
-   the first interval, when it is 0, means that there is only one interval yet.
+   the first interval, when it is 0, means that there is only one interval.
 */
 
 /* a. If this new level would be valid, then this embedding code is valid.
@@ -305,6 +308,7 @@
   /* input */
   const FriBidiChar *str,
   const FriBidiStrIndex len,
+  const FriBidiCharType *bidi_types,
   /* input and output */
   FriBidiParType *pbase_dir,
   /* output */
@@ -318,7 +322,7 @@
 
   DBG ("entering fribidi_get_par_embedding_levels");
 
-  fribidi_assert (str);
+  fribidi_assert (str || bidi_types);
   fribidi_assert (pbase_dir);
   fribidi_assert (embedding_level_list);
 
@@ -332,7 +336,7 @@
   /* Determinate character types */
   {
     /* Get run-length encoded character types */
-    main_run_list = run_list_encode_bidi_types (str, len);
+    main_run_list = run_list_encode_bidi_types (str, len, bidi_types);
     if UNLIKELY
       (!main_run_list) goto out;
   }
@@ -485,7 +489,7 @@
     (fribidi_debug_status ())
     {
       print_types_re (main_run_list);
-      print_bidi_string (str, len);
+      print_bidi_string (str, len, bidi_types);
       print_resolved_levels (main_run_list);
       print_resolved_types (main_run_list);
     }
@@ -688,7 +692,7 @@
   if UNLIKELY
     (fribidi_debug_status ())
     {
-      print_bidi_string (str, len);
+      print_bidi_string (str, len, bidi_types);
       print_resolved_levels (main_run_list);
       print_resolved_types (main_run_list);
     }
@@ -738,7 +742,9 @@
       {
 	/* if state is on at the very first of the string, do this too. */
 	if (j >= 0)
-	  char_type = fribidi_get_bidi_type (str[j]);
+	{
+	  char_type = BIDI_TYPE(j);
+	}
 	else
 	  char_type = FRIBIDI_TYPE_ON;
 	if (!state && FRIBIDI_IS_SEPARATOR (char_type))
@@ -872,9 +878,10 @@
 FRIBIDI_ENTRY FriBidiLevel
 fribidi_reorder_line (
   /* input */
-  FriBidiLevel *embedding_level_list,
+  const FriBidiLevel *embedding_level_list,
   const FriBidiStrIndex len,
   const FriBidiStrIndex off,
+  const FriBidiCharType *bidi_types,
   /* input and output */
   FriBidiChar *str,
   /* output */
@@ -887,6 +894,7 @@
   FriBidiLevel max_level = 0;
 
   fribidi_assert (embedding_level_list);
+  fribidi_assert (str || bidi_types);
 
   if UNLIKELY
     (len == 0)
@@ -937,14 +945,13 @@
 	  /* L3. Reorder NSMs. */
 	  for (i = off + len - 1; i >= off; i--)
 	    if (FRIBIDI_LEVEL_IS_RTL (embedding_level_list[i])
-		&& fribidi_get_bidi_type (str[i]) == FRIBIDI_TYPE_NSM)
+		&& BIDI_TYPE(i) == FRIBIDI_TYPE_NSM)
 	      {
 		register FriBidiStrIndex seq_end = i;
 		level = embedding_level_list[i];
 
 		for (i--; i >= off &&
-		     FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM (fribidi_get_bidi_type
-						       (str[i]))
+		     FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM (BIDI_TYPE (i))
 		     && embedding_level_list[i] == level; i--)
 		  ;
 

Index: fribidi-bidi.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- fribidi-bidi.h	9 Jun 2004 14:59:21 -0000	1.7
+++ fribidi-bidi.h	14 Jun 2004 17:00:33 -0000	1.8
@@ -48,6 +48,12 @@
  * This function finds the bidi embedding levels of a single paragraph,
  * as defined by the Unicode Bidirectional Algorithm.
  *
+ * You can provide either the string, or the bidi types; or both.  If bidi_types are
+ * provided, they are used as the bidi types of characters in the string, otherwise
+ * the types are computed from the characters in str.  Providing bidi types if
+ * available at your side, saves you a few cycles.  Bidi types can be obtained
+ * by calling fribidi_get_bidi_types.
+ *
  * Returns: Maximum level found plus one, or zero if any error occured
  * (memory allocation failure most probably).
  */
@@ -55,6 +61,7 @@
 fribidi_get_par_embedding_levels (
   const FriBidiChar *str,	/* input paragraph string */
   const FriBidiStrIndex len,	/* input string length of the paragraph */
+  const FriBidiCharType *bidi_types, /* input bidi types */
   FriBidiParType *pbase_dir,	/* requested and resolved paragraph
 				 * base direction */
   FriBidiLevel *embedding_level_list	/* output list of embedding levels */
@@ -79,20 +86,32 @@
 /* fribidi_reorder_line - reorder a line of logical string to visual
  *
  * This function reorders the characters in a line of text from logical
- * to final visual order.  Also sets position maps if not NULL.  You can leave
- * str NULL if all you need is the maps.  Some features of this function can
- * be turned on/off using environmental settings functions fribidi_env_*.
+ * to final visual order.  Also sets position maps if not NULL.
+ *
+ * You can provide either the string, or the bidi types; or both.  If bidi_types are
+ * provided, they are used as the bidi types of characters in the string, otherwise
+ * the types are computed from the characters in str.  If you have obtained
+ * the embedding levels using custom bidi types, you should provide the same
+ * types to this function for valid resutls.  Providing bidi types if
+ * available at your side, saves you a few cycles.
+ *
+ * Note that the bidi types and embedding levels are not reordered.  You can
+ * reorder these (or any other) arrays using the position_L_to_V_map later.
+ *
+ * Some features of this function can be turned on/off using environmental settings
+ * functions fribidi_env_*.
  *
  * Returns: Maximum level found in this line plus one, or zero if any error
  * occured (memory allocation failure most probably).
  */
      FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line (
-  FriBidiLevel *embedding_level_list,	/* input list of embedding levels,
+  const FriBidiLevel *embedding_level_list,	/* input list of embedding levels,
 					   as returned by
 					   fribidi_get_par_embedding_levels */
   const FriBidiStrIndex len,	/* input length of the line */
   const FriBidiStrIndex off,	/* input offset of the beginning of the line
 				   in the paragraph */
+  const FriBidiCharType *bidi_types,	/* input bidi types */
   FriBidiChar *str,		/* string to shape */
   FriBidiStrIndex *position_L_to_V_list,	/* output mapping from logical to
 						   visual string positions */

Index: fribidi-run.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-run.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- fribidi-run.c	4 Jun 2004 16:43:51 -0000	1.3
+++ fribidi-run.c	14 Jun 2004 17:00:33 -0000	1.4
@@ -157,14 +157,15 @@
 run_list_encode_bidi_types (
   /* input */
   const FriBidiChar *str,
-  FriBidiStrIndex len
+  const FriBidiStrIndex len,
+  const FriBidiCharType *bidi_types
 )
 {
   FriBidiRun *list, *last;
   register FriBidiRun *run = NULL;
   FriBidiStrIndex i;
 
-  fribidi_assert (str);
+  fribidi_assert (str || bidi_types);
 
   /* Create the list sentinel */
   list = new_run_list ();
@@ -175,7 +176,7 @@
   /* Scan over the character types */
   for (i = 0; i < len; i++)
     {
-      register FriBidiCharType char_type = fribidi_get_bidi_type (str[i]);
+      register FriBidiCharType char_type = BIDI_TYPE (i);
       if (char_type != last->type)
 	{
 	  run = new_run ();

Index: fribidi.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- fribidi.c	9 Jun 2004 14:59:21 -0000	1.8
+++ fribidi.c	14 Jun 2004 17:00:33 -0000	1.9
@@ -160,7 +160,7 @@
       private_embedding_level_list = true;
     }
 
-  max_level = fribidi_get_par_embedding_levels (str, len, pbase_dir,
+  max_level = fribidi_get_par_embedding_levels (str, len, NULL, pbase_dir,
 						embedding_level_list) - 1;
   if UNLIKELY
     (max_level < 0) goto out;
@@ -186,7 +186,7 @@
 
   fribidi_shape (embedding_level_list, len, visual_str);
 
-  status = fribidi_reorder_line (embedding_level_list, len, 0, visual_str,
+  status = fribidi_reorder_line (embedding_level_list, len, 0, NULL, visual_str,
 				 position_L_to_V_list, position_V_to_L_list);
 
 out:

Index: run.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/run.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- run.h	13 Jun 2004 20:11:42 -0000	1.5
+++ run.h	14 Jun 2004 17:00:33 -0000	1.6
@@ -83,7 +83,8 @@
 #define run_list_encode_bidi_types FRIBIDI_PRIVATESPACE(run_list_encode_bidi_types)
      FriBidiRun *run_list_encode_bidi_types (
   const FriBidiChar *str,
-  FriBidiStrIndex len
+  const FriBidiStrIndex len,
+  const FriBidiCharType *bidi_types
 )
      FRIBIDI_GNUC_HIDDEN FRIBIDI_GNUC_WARN_UNUSED;
 




More information about the FriBidi-Commit mailing list