breaking. Also calculate more reasonable levels for explicit marks and BN.
/* 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:
#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 \
/* 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 */
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;
}
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
}
# 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;
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))
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
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. */
/* 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:
* 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
/* 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.
* 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.
*
* 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
/* 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:
#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 */
/* 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:
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: