]> granicus.if.org Git - fribidi/commitdiff
Fixed good catch by Mark Davis that rule L1 is partly done after line
authorbehdad <behdad>
Fri, 18 Jun 2004 19:21:33 +0000 (19:21 +0000)
committerbehdad <behdad>
Fri, 18 Jun 2004 19:21:33 +0000 (19:21 +0000)
breaking.  Also calculate more reasonable levels for explicit marks and BN.

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

index 95bd8ab261a80a6589d4dcc6fe0013debeb67ac7..5fc0c77066c2a9303a8964e78c7ae639da356478 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi-types.h - character bidi types
  *
- * $Id: fribidi-bidi-types.h,v 1.11 2004-06-15 20:54:00 behdad Exp $
+ * $Id: fribidi-bidi-types.h,v 1.12 2004-06-18 19:21:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-15 20:54:00 $
- * $Revision: 1.11 $
+ * $Date: 2004-06-18 19:21:33 $
+ * $Revision: 1.12 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.h,v $
  *
  * Author:
@@ -306,11 +306,14 @@ typedef fribidi_uint32 FriBidiParType;
 #define FRIBIDI_IS_EXPLICIT_OR_BN(p) \
        ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN))
 
-/* Is explicit or BN or NSM: LRE, RLE, LRO, RLO, PDF, BN, NSM?
- * This is a good approximation of being zero-width. */
+/* Is explicit or BN or NSM: LRE, RLE, LRO, RLO, PDF, BN, NSM? */
 #define FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM(p) \
        ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN | FRIBIDI_MASK_NSM))
 
+/* Is explicit or BN or WS: LRE, RLE, LRO, RLO, PDF, BN, WS? */
+#define FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS(p) \
+       ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_BN | FRIBIDI_MASK_WS))
+
 /* Is explicit or separator or BN or WS: LRE, RLE, LRO, RLO, PDF, BS, SS, BN, WS? */
 #define FRIBIDI_IS_EXPLICIT_OR_SEPARATOR_OR_BN_OR_WS(p) \
        ((p) & (FRIBIDI_MASK_EXPLICIT | FRIBIDI_MASK_SEPARATOR \
index a6aec23c6fbce1372f54474479de3de1678d1654..96cb575e028446bda39cb6aaa8117ddaea136585 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi.c - bidirectional algorithm
  *
- * $Id: fribidi-bidi.c,v 1.13 2004-06-15 11:52:02 behdad Exp $
+ * $Id: fribidi-bidi.c,v 1.14 2004-06-18 19:21:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-15 11:52:02 $
- * $Revision: 1.13 $
+ * $Date: 2004-06-18 19:21:33 $
+ * $Revision: 1.14 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.c,v $
  *
  * Authors:
 #include "bidi-types.h"
 #include "run.h"
 
+/*
+ * This file implements most of Unicode Standard Annex #9, Tracking Number 13.
+ */
+
 #ifndef MAX
 # define MAX(a,b) ((a) > (b) ? (a) : (b))
 #endif /* !MAX */
@@ -447,19 +451,27 @@ fribidi_get_par_embedding_levels (
                    FRIBIDI_DIR_TO_LEVEL (this_type);
                  PUSH_STATUS;
                }
+
+             /* Set level to the higher level */
+             RL_LEVEL (pp) = level;
            }
          else if (this_type == FRIBIDI_TYPE_PDF)
            {
+             /* Set level to the higher level */
+             RL_LEVEL (pp) = level;
+
              /* 3. Terminating Embeddings and overrides */
              /*   X7. With each PDF, determine the matching embedding or
                 override code. */
              for (i = RL_LEN (pp); i; i--)
                POP_STATUS;
            }
+         else
+           RL_LEVEL (pp) = level;
+
          /* X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes. */
          /* Remove element and add it to explicits_list */
          temp_link.next = pp->next;
-         pp->level = FRIBIDI_SENTINEL;
          move_node_before (pp, explicits_list);
          pp = &temp_link;
        }
@@ -727,11 +739,13 @@ fribidi_get_par_embedding_levels (
     explicits_list = NULL;
     if UNLIKELY
       (!stat) goto out;
+    /* We don't need this code since we set levels for everything we remove.
     p = main_run_list->next;
     if (p != main_run_list && p->level == FRIBIDI_SENTINEL)
       p->level = base_level;
     for_run_list (p, main_run_list) if (p->level == FRIBIDI_SENTINEL)
       p->level = p->prev->level;
+    */
   }
 
 # if DEBUG
@@ -744,13 +758,18 @@ fribidi_get_par_embedding_levels (
     }
 # endif        /* DEBUG */
 
-  DBG ("reset the embedding levels");
+  DBG ("reset the embedding levels, 1, 2, 3.");
   {
     register int j, state, pos;
     register FriBidiCharType char_type;
     register FriBidiRun *p, *q, *list;
 
-    /* L1. Reset the embedding levels of some chars. */
+    /* L1. Reset the embedding levels of some chars:
+           1. segment separators,
+           2. paragraph separators,
+           3. any sequence of whitespace characters preceding a segment
+              separator or paragraph separator, and
+          ... (to be continued in fribidi_reorder_line()). */
     list = new_run_list ();
     if UNLIKELY
       (!list) goto out;
@@ -759,11 +778,9 @@ fribidi_get_par_embedding_levels (
     pos = len - 1;
     for (j = len - 1; j >= -1; j--)
       {
-       /* if state is on at the very first of the string, do this too. */
+       /* close up the open link at the end */
        if (j >= 0)
-         {
-           char_type = BIDI_TYPE (j);
-         }
+         char_type = BIDI_TYPE (j);
        else
          char_type = FRIBIDI_TYPE_ON;
        if (!state && FRIBIDI_IS_SEPARATOR (char_type))
@@ -868,13 +885,15 @@ index_array_reverse (
 
 FRIBIDI_ENTRY FriBidiLevel
 fribidi_reorder_line (
+  /* input and output */
+  FriBidiChar *str,
   /* input */
-  const FriBidiLevel *embedding_levels,
   const FriBidiStrIndex len,
   const FriBidiStrIndex off,
   const FriBidiCharType *bidi_types,
+  const FriBidiParType base_dir,
   /* input and output */
-  FriBidiChar *str,
+  FriBidiLevel *embedding_levels,
   /* output */
   FriBidiStrIndex *positions_L_to_V,
   FriBidiStrIndex *positions_V_to_L
@@ -904,8 +923,19 @@ fribidi_reorder_line (
 
   DBG ("in fribidi_reorder_line");
 
-  fribidi_assert (embedding_levels);
   fribidi_assert (str || bidi_types);
+  fribidi_assert (embedding_levels);
+
+  DBG ("reset the embedding levels, 4. whitespace at the end of line");
+  {
+    register FriBidiStrIndex i;
+
+    /* L1. Reset the embedding levels of some chars:
+           4. any sequence of white space characters at the end of the line.*/
+    for (i = len - 1; i >= 0 &&
+       FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS (BIDI_TYPE (i)); i--)
+      embedding_levels[i] = FRIBIDI_DIR_TO_LEVEL (base_dir);
+  }
 
   /* If l2v is to be calculated we must have v2l as well. If it is not
      given by the caller, we have to make a private instance of it. */
index 8b42f471cf5af8e2acbf1da0ce5c5bcded7bdd83..b0d9c793f60f6bbade164aa83b014283e480d7e1 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-bidi.h - bidirectional algorithm
  *
- * $Id: fribidi-bidi.h,v 1.10 2004-06-15 11:52:02 behdad Exp $
+ * $Id: fribidi-bidi.h,v 1.11 2004-06-18 19:21:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-15 11:52:02 $
- * $Revision: 1.10 $
+ * $Date: 2004-06-18 19:21:33 $
+ * $Revision: 1.11 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.h,v $
  *
  * Authors:
@@ -80,8 +80,9 @@ FRIBIDI_ENTRY FriBidiParType fribidi_get_par_direction (
  * This function finds the bidi embedding levels of a single paragraph,
  * as defined by the Unicode Bidirectional Algorithm available at
  * http://www.unicode.org/reports/tr9/.  This function implements rules P2 to
- * L1 inclusive, except for rule X9 which is implemented in
- * fribidi_remove_bidi_marks().
+ * I1 inclusive, and parts 1 to 3 of L1, except for rule X9 which is
+ *  implemented in fribidi_remove_bidi_marks().  Part 4 of L1 is implemented
+ *  in fribidi_reorder_line().
  *
  * 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
@@ -109,8 +110,8 @@ 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.  This function implements rules L2 and L3 of the
- * Unicode Bidirectional Algorithm available at
+ * final visual order.  This function implements part 4 of rule L1, and rules
+ * L2 and L3 of the Unicode Bidirectional Algorithm available at
  * http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels.
  *
  * As a side effect it also sets position maps if not NULL.
@@ -122,6 +123,12 @@ fribidi_get_par_embedding_levels (
  * should provide the same types to this function for valid resutls.
  * Providing bidi types if available at your side, saves you a few cycles.
  *
+ * You should provide the resolved paragraph direction and embedding levels as
+ * set by fribidi_get_par_embedding_levels().  Also note that the embedding
+ * levels may change a bit.  To be exact, the embedding level of any sequence
+ * of white space at the end of line is reset to the paragraph embedding level
+ * (That is part 4 of rule L1).
+ *
  * 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.
  *
@@ -132,14 +139,15 @@ fribidi_get_par_embedding_levels (
  * occured (memory allocation failure most probably).
  */
      FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line (
-  const FriBidiLevel *embedding_levels,        /* input list of embedding levels,
-                                          as returned by
-                                          fribidi_get_par_embedding_levels */
+  FriBidiChar *str,            /* string to reorder */
   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 */
+  const FriBidiParType base_dir,       /* resolved paragraph base direction */
+  FriBidiLevel *embedding_levels,      /* input list of embedding levels,
+                                          as returned by
+                                          fribidi_get_par_embedding_levels */
   FriBidiStrIndex *positions_L_to_V,   /* output mapping from logical to
                                           visual string positions */
   FriBidiStrIndex *positions_V_to_L    /* output mapping from visual string
index 613c4f5ebfafaf461a18e931983f816b36313479..e56b5f7bcf71e8da00de3b61fdc3955b4634dd3d 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi-types.h - define data types for the rest of the library
  *
- * $Id: fribidi-types.h,v 1.7 2004-06-15 11:52:02 behdad Exp $
+ * $Id: fribidi-types.h,v 1.8 2004-06-18 19:21:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-15 11:52:02 $
- * $Revision: 1.7 $
+ * $Date: 2004-06-18 19:21:33 $
+ * $Revision: 1.8 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-types.h,v $
  *
  * Author:
@@ -139,8 +139,8 @@ typedef FRIBIDI_STR_INDEX FriBidiStrIndex;
 
 #ifndef FRIBIDI_MAX_STRING_LENGTH
 # define FRIBIDI_MAX_STRING_LENGTH (sizeof (FriBidiStrIndex) == 2 ?    \
-               0x7FFE : (sizeof (FriBidiStrIndex) == 1 ? \
-               0x7E : 0x8FFFFFFEL))
+               0xFFFF : (sizeof (FriBidiStrIndex) == 1 ? \
+               0xFF : 0xFFFFFFFFL))
 #endif
 
 /* A few macros for working with bits */
index 729b58bc33fcec42cfd6a4a51c0b943547c041bc..f3d581ba14d5d6d8f11536b1269a161efb6d0d82 100644 (file)
@@ -1,10 +1,10 @@
 /* FriBidi
  * fribidi.c - Unicode bidirectional and Arabic joining/shaping algorithms
  *
- * $Id: fribidi.c,v 1.11 2004-06-15 11:52:02 behdad Exp $
+ * $Id: fribidi.c,v 1.12 2004-06-18 19:21:33 behdad Exp $
  * $Author: behdad $
- * $Date: 2004-06-15 11:52:02 $
- * $Revision: 1.11 $
+ * $Date: 2004-06-18 19:21:33 $
+ * $Revision: 1.12 $
  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi.c,v $
  *
  * Authors:
@@ -202,9 +202,7 @@ fribidi_log2vis (
 
   fribidi_shape (embedding_levels, len, visual_str);
 
-  status =
-    fribidi_reorder_line (embedding_levels, len, 0, NULL, visual_str,
-                         positions_L_to_V, positions_V_to_L);
+  status = fribidi_reorder_line (visual_str, len, 0, NULL, *pbase_dir, embedding_levels, positions_L_to_V, positions_V_to_L);
 
 out: