]> granicus.if.org Git - fribidi/commitdiff
fribidi_get_bidi_types is back. Allow passing bidi types to
authorbehdad <behdad>
Mon, 14 Jun 2004 17:00:33 +0000 (17:00 +0000)
committerbehdad <behdad>
Mon, 14 Jun 2004 17:00:33 +0000 (17:00 +0000)
get_par_embedding_levels and reorder_line functions.

lib/bidi-types.h
lib/fribidi-bidi-type.c
lib/fribidi-bidi-type.h
lib/fribidi-bidi.c
lib/fribidi-bidi.h
lib/fribidi-run.c
lib/fribidi.c
lib/run.h

index 26999a3a3d0ef6c9e270b9cce08f1d72c2b442ab..3ae213ea99b59ba476cceef89904b6bb1dc0d82d 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * bidi-types.h - define internal bidi types
  *
- * $Id: bidi-types.h,v 1.4 2004-05-07 06:30:38 behdad Exp $
+ * $Id: bidi-types.h,v 1.5 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-05-07 06:30:38 $
- * $Revision: 1.4 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.5 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/bidi-types.h,v $
  *
  * Author:
@@ -53,6 +53,8 @@ fribidi_char_from_bidi_type (
 
 #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 00d124f7c31704f83fc74a7c0569d9358d61f484..cc22b0fe259630f4e620670ce2b7c559da5fe2dc 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi-type.c - get character bidi type
  *
- * $Id: fribidi-bidi-type.c,v 1.12 2004-06-13 20:11:42 behdad Exp $
+ * $Id: fribidi-bidi-type.c,v 1.13 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-13 20:11:42 $
- * $Revision: 1.12 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.13 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/Attic/fribidi-bidi-type.c,v $
  *
  * Authors:
@@ -60,3 +60,21 @@ fribidi_get_bidi_type (
 {
   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 ab5932b60de07d75a5fc217f6c9db6ed896e07f0..e98722a33b4ad3297c826ba5b2c6336706e08a7f 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi-type.h - get character bidi type
  *
- * $Id: fribidi-bidi-type.h,v 1.5 2004-06-09 14:59:21 behdad Exp $
+ * $Id: fribidi-bidi-type.h,v 1.6 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-09 14:59:21 $
- * $Revision: 1.5 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.6 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/Attic/fribidi-bidi-type.h,v $
  *
  * Author:
@@ -51,6 +51,19 @@ fribidi_get_bidi_type (
   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 ffa1c285fa4ea2d1f1c57ccaa1bfaecf1e713887..ef4ccd66d2e69d8e29772066ee50f1c40b236938 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi.c - bidirectional algorithm
  *
- * $Id: fribidi-bidi.c,v 1.10 2004-06-07 20:38:21 behdad Exp $
+ * $Id: fribidi-bidi.c,v 1.11 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-07 20:38:21 $
- * $Revision: 1.10 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.11 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.c,v $
  *
  * Authors:
@@ -196,16 +196,18 @@ static void
 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 @@ print_bidi_string (
  * 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 @@ fribidi_get_par_embedding_levels (
   /* input */
   const FriBidiChar *str,
   const FriBidiStrIndex len,
+  const FriBidiCharType *bidi_types,
   /* input and output */
   FriBidiParType *pbase_dir,
   /* output */
@@ -318,7 +322,7 @@ fribidi_get_par_embedding_levels (
 
   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 @@ fribidi_get_par_embedding_levels (
   /* 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_get_par_embedding_levels (
     (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 @@ fribidi_get_par_embedding_levels (
   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 @@ fribidi_get_par_embedding_levels (
       {
        /* 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 @@ index_array_reverse (
 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 @@ fribidi_reorder_line (
   FriBidiLevel max_level = 0;
 
   fribidi_assert (embedding_level_list);
+  fribidi_assert (str || bidi_types);
 
   if UNLIKELY
     (len == 0)
@@ -937,14 +945,13 @@ fribidi_reorder_line (
          /* 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 c94bf3fd17f8344d0571bb37c79c881aaa66f5b0..ad1f1286bc4a6fe8895a08893393922c223768bf 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi.h - bidirectional algorithm
  *
- * $Id: fribidi-bidi.h,v 1.7 2004-06-09 14:59:21 behdad Exp $
+ * $Id: fribidi-bidi.h,v 1.8 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-09 14:59:21 $
- * $Revision: 1.7 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.8 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.h,v $
  *
  * Authors:
  * 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_ENTRY FriBidiLevel
 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_get_par_embedding_levels (
 /* 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 f8e52698eae3c0d0946e12e4a7e5718b074fba4c..f4f8319e9fa5abaae02a00aaca73a9cd14d12bac 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-run.c - text run data type
  *
- * $Id: fribidi-run.c,v 1.3 2004-06-04 16:43:51 behdad Exp $
+ * $Id: fribidi-run.c,v 1.4 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-04 16:43:51 $
- * $Revision: 1.3 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.4 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-run.c,v $
  *
  * Authors:
@@ -157,14 +157,15 @@ FriBidiRun *
 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 @@ run_list_encode_bidi_types (
   /* 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 b75db6f281caa564aedd4049a500122d205bf1e6..0af4c93dac53638b12c1c120b5a71abdd1484224 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi.c - Unicode bidirectional and Arabic joining/shaping algorithms
  *
- * $Id: fribidi.c,v 1.8 2004-06-09 14:59:21 behdad Exp $
+ * $Id: fribidi.c,v 1.9 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-09 14:59:21 $
- * $Revision: 1.8 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.9 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi.c,v $
  *
  * Authors:
@@ -160,7 +160,7 @@ fribidi_log2vis (
       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_log2vis (
 
   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 9388048a6b1e45460def9ab9a8f447b35f786950..d284d1dbd91afec889499149fe142a0cab56ac02 100644 (file)
--- a/lib/run.h
+++ b/lib/run.h
@@ -1,10 +1,10 @@
 /* FriBidi
  * run.h - text run data type
  *
- * $Id: run.h,v 1.5 2004-06-13 20:11:42 behdad Exp $
+ * $Id: run.h,v 1.6 2004-06-14 17:00:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-13 20:11:42 $
- * $Revision: 1.5 $
+ * $Date: 2004-06-14 17:00:33 $
+ * $Revision: 1.6 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/run.h,v $
  *
  * Authors:
@@ -83,7 +83,8 @@ new_run (
 #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;