summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbehdad <behdad>2004-06-07 20:38:21 +0000
committerbehdad <behdad>2004-06-07 20:38:21 +0000
commit5a52ab708d73f6b8929856ddf7238ecdb04a36b0 (patch)
treec1a36b809dd57f4e7d9072bf0de9107b601cbacd
parent8fee958d0e10db5516f3897e6dc832ef56b13fcd (diff)
downloadfribidi-5a52ab708d73f6b8929856ddf7238ecdb04a36b0.tar.gz
Finally done with the clean API for bidi functionality. The API is not final
yet, but does the job. Also define FriBidiCharType as an enum if possible. Added type FriBidiParType for paragraph direction types.
-rw-r--r--.cvsignore2
-rw-r--r--.indent.pro4
-rw-r--r--TODO2
-rw-r--r--lib/fribidi-bidi-types-list.h11
-rw-r--r--lib/fribidi-bidi-types.h134
-rw-r--r--lib/fribidi-bidi.c314
-rw-r--r--lib/fribidi-bidi.h100
-rw-r--r--lib/fribidi-mirroring.c9
-rw-r--r--lib/fribidi-mirroring.h9
-rw-r--r--lib/fribidi.c170
-rw-r--r--lib/fribidi.def2
-rw-r--r--lib/fribidi.h95
-rw-r--r--test/test_UTF-8_persian.reference16
13 files changed, 541 insertions, 327 deletions
diff --git a/.cvsignore b/.cvsignore
index ce21673..4cae31f 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -1,4 +1,4 @@
-ChangeLog.bak
+ChangeLog
INSTALL
aclocal.m4
autom4te.cache
diff --git a/.indent.pro b/.indent.pro
index 27e1cd5..f4bfeea 100644
--- a/.indent.pro
+++ b/.indent.pro
@@ -2,12 +2,10 @@
-bfda
-bfde
-T FILE
--T LevelInfo
-T FriBidiChar
-T FriBidiStrIndex
--T FriBidiMaskType
-T FriBidiCharType
--T FriBidiPropCharType
+-T FriBidiParType
-T FriBidiLevel
-T FriBidiCharSet
-T FriBidiCharSetHandler
diff --git a/TODO b/TODO
index 6df815e..32c6773 100644
--- a/TODO
+++ b/TODO
@@ -63,6 +63,8 @@ Implementation issues:
* Configure gen.tab/ with host=build to avoid cross-compiling table
generators.
+* Replace Arabic Yeh with Persian Yeh in Hafez piece in test/*.
+
From GNU Coding Standards:
* The distribution should contain a file named `README' which gives the name
diff --git a/lib/fribidi-bidi-types-list.h b/lib/fribidi-bidi-types-list.h
index ead39e7..19f82f8 100644
--- a/lib/fribidi-bidi-types-list.h
+++ b/lib/fribidi-bidi-types-list.h
@@ -2,10 +2,10 @@
/* FriBidi
* fribidi-bidi-types-list.h - list of bidi types
*
- * $Id: fribidi-bidi-types-list.h,v 1.2 2004-06-04 09:41:11 behdad Exp $
+ * $Id: fribidi-bidi-types-list.h,v 1.3 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-06-04 09:41:11 $
- * $Revision: 1.2 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.3 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types-list.h,v $
*
* Author:
@@ -41,8 +41,7 @@
#endif
#if !defined(_FRIBIDI_PAR_TYPES) || defined(_FRIBIDI_ALL_TYPES)
-/* Bidi types from the standard. */
-/* The order of these types is important. Don't change. */
+
_FRIBIDI_ADD_TYPE (LTR, 'L') /* Left-To-Right letter */
_FRIBIDI_ADD_TYPE (RTL, 'R') /* Right-To-Left letter */
_FRIBIDI_ADD_TYPE (AL, 'A') /* Arabic Letter */
@@ -64,8 +63,6 @@ _FRIBIDI_ADD_TYPE (RLO, '+') /* Right-to-Left Override */
_FRIBIDI_ADD_TYPE (PDF, '-') /* Pop Directional Flag */
#if defined(_FRIBIDI_ADD_ALIAS)
-/* The followings are just aliases to types, but with the name that appears in
- * the Unicode database. */
_FRIBIDI_ADD_ALIAS (L, LTR)
_FRIBIDI_ADD_ALIAS (R, RTL)
_FRIBIDI_ADD_ALIAS (B, BS)
diff --git a/lib/fribidi-bidi-types.h b/lib/fribidi-bidi-types.h
index 58ed648..e0a9b53 100644
--- a/lib/fribidi-bidi-types.h
+++ b/lib/fribidi-bidi-types.h
@@ -1,10 +1,10 @@
/* FriBidi
* fribidi-bidi-types.h - character bidi types
*
- * $Id: fribidi-bidi-types.h,v 1.4 2004-06-04 09:41:11 behdad Exp $
+ * $Id: fribidi-bidi-types.h,v 1.5 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-06-04 09:41:11 $
- * $Revision: 1.4 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.5 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.h,v $
*
* Author:
@@ -43,9 +43,6 @@ typedef signed char FriBidiLevel;
typedef struct _FriBidiRun FriBidiRun;
-typedef fribidi_uint32 FriBidiMaskType;
-typedef FriBidiMaskType FriBidiCharType;
-
/*
* Define some bit masks, that character types are based on, each one has
* only one bit on.
@@ -98,84 +95,138 @@ typedef FriBidiMaskType FriBidiCharType;
*/
/* Strong left to right */
-#define FRIBIDI_TYPE_LTR ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER )
+#define FRIBIDI_TYPE_LTR_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER )
/* Right to left characters */
-#define FRIBIDI_TYPE_RTL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \
+#define FRIBIDI_TYPE_RTL_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \
+ FRIBIDI_MASK_RTL)
/* Arabic characters */
-#define FRIBIDI_TYPE_AL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \
+#define FRIBIDI_TYPE_AL_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_LETTER \
+ FRIBIDI_MASK_RTL + FRIBIDI_MASK_ARABIC )
/* Left-To-Right embedding */
-#define FRIBIDI_TYPE_LRE (FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT)
+#define FRIBIDI_TYPE_LRE_VAL (FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT)
/* Right-To-Left embedding */
-#define FRIBIDI_TYPE_RLE ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+#define FRIBIDI_TYPE_RLE_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+ FRIBIDI_MASK_RTL )
/* Left-To-Right override */
-#define FRIBIDI_TYPE_LRO ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+#define FRIBIDI_TYPE_LRO_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+ FRIBIDI_MASK_OVERRIDE )
/* Right-To-Left override */
-#define FRIBIDI_TYPE_RLO ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+#define FRIBIDI_TYPE_RLO_VAL ( FRIBIDI_MASK_STRONG + FRIBIDI_MASK_EXPLICIT \
+ FRIBIDI_MASK_RTL + FRIBIDI_MASK_OVERRIDE )
/* Pop directional override */
-#define FRIBIDI_TYPE_PDF ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_EXPLICIT )
+#define FRIBIDI_TYPE_PDF_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_EXPLICIT )
/* European digit */
-#define FRIBIDI_TYPE_EN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER )
+#define FRIBIDI_TYPE_EN_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER )
/* Arabic digit */
-#define FRIBIDI_TYPE_AN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER \
+#define FRIBIDI_TYPE_AN_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMBER \
+ FRIBIDI_MASK_ARABIC )
/* European number separator */
-#define FRIBIDI_TYPE_ES ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+#define FRIBIDI_TYPE_ES_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+ FRIBIDI_MASK_ES )
/* European number terminator */
-#define FRIBIDI_TYPE_ET ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+#define FRIBIDI_TYPE_ET_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+ FRIBIDI_MASK_ET )
/* Common Separator */
-#define FRIBIDI_TYPE_CS ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+#define FRIBIDI_TYPE_CS_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NUMSEPTER \
+ FRIBIDI_MASK_CS )
/* Non spacing mark */
-#define FRIBIDI_TYPE_NSM ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NSM )
+#define FRIBIDI_TYPE_NSM_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_NSM )
/* Boundary neutral */
-#define FRIBIDI_TYPE_BN ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_SPACE \
+#define FRIBIDI_TYPE_BN_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_SPACE \
+ FRIBIDI_MASK_BN )
/* Block separator */
-#define FRIBIDI_TYPE_BS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+#define FRIBIDI_TYPE_BS_VAL ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+ FRIBIDI_MASK_SEPARATOR + FRIBIDI_MASK_BS )
/* Segment separator */
-#define FRIBIDI_TYPE_SS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+#define FRIBIDI_TYPE_SS_VAL ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+ FRIBIDI_MASK_SEPARATOR + FRIBIDI_MASK_SS )
/* Whitespace */
-#define FRIBIDI_TYPE_WS ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+#define FRIBIDI_TYPE_WS_VAL ( FRIBIDI_MASK_NEUTRAL + FRIBIDI_MASK_SPACE \
+ FRIBIDI_MASK_WS )
/* Other Neutral */
-#define FRIBIDI_TYPE_ON ( FRIBIDI_MASK_NEUTRAL )
+#define FRIBIDI_TYPE_ON_VAL ( FRIBIDI_MASK_NEUTRAL )
-/* The following are used in specifying paragraph direction only, not real
- * types. */
+/* The following are used in specifying paragraph direction only. */
/* Weak left to right */
-#define FRIBIDI_TYPE_WLTR ( FRIBIDI_MASK_WEAK )
+#define FRIBIDI_TYPE_WLTR_VAL ( FRIBIDI_MASK_WEAK )
/* Weak right to left */
-#define FRIBIDI_TYPE_WRTL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_RTL )
-
-
-/* Just for compatibility */
-#define FRIBIDI_TYPE_WL FRIBIDI_TYPE_WLTR
-#define FRIBIDI_TYPE_WR FRIBIDI_TYPE_WRTL
-#define FRIBIDI_TYPE_L FRIBIDI_TYPE_LTR
-#define FRIBIDI_TYPE_R FRIBIDI_TYPE_RTL
-#define FRIBIDI_TYPE_N FRIBIDI_TYPE_ON
+#define FRIBIDI_TYPE_WRTL_VAL ( FRIBIDI_MASK_WEAK + FRIBIDI_MASK_RTL )
/* The following is only used internally */
/* Start or end of text (run list) */
#define FRIBIDI_TYPE_SENTINEL ( FRIBIDI_MASK_SENTINEL )
-/*
- * End of define values for FriBidiCharType
- */
+/* Define values for FriBidiCharType. */
+
+#if defined(__C2MAN__) || (defined(FRIBIDI_SIZEOF_INT) && ((FRIBIDI_SIZEOF_INT <= 4) && (FRIBIDI_SIZEOF_INT >= 4)))
+
+typedef enum
+{
+# define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
+ FRIBIDI_TYPE_##TYPE = FRIBIDI_TYPE_##TYPE##_VAL,
+# include "fribidi-bidi-types-list.h"
+# undef _FRIBIDI_ADD_TYPE
+ _FRIBIDI_TYPE_JUNK
+} FriBidiCharType;
+
+typedef enum
+{
+# define _FRIBIDI_PAR_TYPES
+# define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) \
+ FRIBIDI_PAR_##TYPE = FRIBIDI_TYPE_##TYPE##_VAL,
+# include "fribidi-bidi-types-list.h"
+# undef _FRIBIDI_ADD_TYPE
+# undef _FRIBIDI_PAR_TYPES
+ _FRIBIDI_TYPE_JUNK
+} FriBidiParType;
+
+#else
+
+typedef fribidi_uint32 FriBidiCharType;
+# define FRIBIDI_TYPE_LTR FRIBIDI_TYPE_LTR_VAL
+# define FRIBIDI_TYPE_RTL FRIBIDI_TYPE_RTL_VAL
+# define FRIBIDI_TYPE_AL FRIBIDI_TYPE_AL_VAL
+# define FRIBIDI_TYPE_EN FRIBIDI_TYPE_EN_VAL
+# define FRIBIDI_TYPE_AN FRIBIDI_TYPE_AN_VAL
+# define FRIBIDI_TYPE_ES FRIBIDI_TYPE_ES_VAL
+# define FRIBIDI_TYPE_ET FRIBIDI_TYPE_ET_VAL
+# define FRIBIDI_TYPE_CS FRIBIDI_TYPE_CS_VAL
+# define FRIBIDI_TYPE_NSM FRIBIDI_TYPE_NSM_VAL
+# define FRIBIDI_TYPE_BN FRIBIDI_TYPE_BN_VAL
+# define FRIBIDI_TYPE_BS FRIBIDI_TYPE_BS_VAL
+# define FRIBIDI_TYPE_SS FRIBIDI_TYPE_SS_VAL
+# define FRIBIDI_TYPE_WS FRIBIDI_TYPE_WS_VAL
+# define FRIBIDI_TYPE_ON FRIBIDI_TYPE_ON_VAL
+# define FRIBIDI_TYPE_LRE FRIBIDI_TYPE_LRE_VAL
+# define FRIBIDI_TYPE_RLE FRIBIDI_TYPE_RLE_VAL
+# define FRIBIDI_TYPE_LRO FRIBIDI_TYPE_LRO_VAL
+# define FRIBIDI_TYPE_RLO FRIBIDI_TYPE_RLO_VAL
+# define FRIBIDI_TYPE_PDF FRIBIDI_TYPE_PDF_VAL
+
+typedef fribidi_uint32 FriBidiParType;
+# define FRIBIDI_PAR_LTR FRIBIDI_TYPE_LTR_VAL
+# define FRIBIDI_PAR_RTL FRIBIDI_TYPE_RTL_VAL
+# define FRIBIDI_PAR_ON FRIBIDI_TYPE_ON_VAL
+# define FRIBIDI_PAR_WLTR FRIBIDI_TYPE_WLTR_VAL
+# define FRIBIDI_PAR_WRTL FRIBIDI_TYPE_WRTL_VAL
+
+#endif
+
+/* Just for compatibility */
+#define FRIBIDI_TYPE_WLTR FRIBIDI_PAR_WLTR
+#define FRIBIDI_TYPE_WL FRIBIDI_PAR_WLTR
+#define FRIBIDI_TYPE_WRTL FRIBIDI_PAR_WRTL
+#define FRIBIDI_TYPE_WR FRIBIDI_PAR_WRTL
+#define FRIBIDI_TYPE_L FRIBIDI_PAR_LTR
+#define FRIBIDI_TYPE_R FRIBIDI_PAR_RTL
+#define FRIBIDI_TYPE_N FRIBIDI_PAR_ON
+#define FRIBIDI_TYPE_B FRIBIDI_TYPE_BS
+#define FRIBIDI_TYPE_S FRIBIDI_TYPE_SS
/*
@@ -187,6 +238,9 @@ typedef FriBidiMaskType FriBidiCharType;
/* Is private-use value? */
#define FRIBIDI_TYPE_PRIVATE(p) ((p) < 0)
+/* Is right-to-left level? */
+#define FRIBIDI_LEVEL_IS_RTL(lev) ((lev) & 1)
+
/* Return the direction of the level number, FRIBIDI_TYPE_LTR for even and
FRIBIDI_TYPE_RTL for odds. */
#define FRIBIDI_LEVEL_TO_DIR(lev) (FRIBIDI_TYPE_LTR | ((lev) & 1))
diff --git a/lib/fribidi-bidi.c b/lib/fribidi-bidi.c
index 6cbcf65..ffa1c28 100644
--- a/lib/fribidi-bidi.c
+++ b/lib/fribidi-bidi.c
@@ -1,10 +1,10 @@
/* FriBidi
* fribidi-bidi.c - bidirectional algorithm
*
- * $Id: fribidi-bidi.c,v 1.9 2004-06-04 16:43:51 behdad Exp $
+ * $Id: fribidi-bidi.c,v 1.10 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-06-04 16:43:51 $
- * $Revision: 1.9 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.10 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.c,v $
*
* Authors:
@@ -50,13 +50,6 @@
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif /* !MAX */
-typedef struct
-{
- FriBidiCharType override; /* only LTR, RTL and ON are valid */
- FriBidiLevel level;
-}
-LevelInfo;
-
/* Some convenience macros */
#define RL_TYPE(list) ((list)->type)
#define RL_LEN(list) ((list)->len)
@@ -151,7 +144,7 @@ static char char_from_level_array[] = {
static void
print_types_re (
- FriBidiRun *pp
+ const FriBidiRun *pp
)
{
fribidi_assert (pp);
@@ -167,7 +160,7 @@ print_types_re (
static void
print_resolved_levels (
- FriBidiRun *pp
+ const FriBidiRun *pp
)
{
fribidi_assert (pp);
@@ -175,7 +168,7 @@ print_resolved_levels (
MSG (" Res. levels: ");
for_run_list (pp, pp)
{
- FriBidiStrIndex i;
+ register FriBidiStrIndex i;
for (i = RL_LEN (pp); i; i--)
MSG2 ("%c", fribidi_char_from_level (RL_LEVEL (pp)));
}
@@ -184,7 +177,7 @@ print_resolved_levels (
static void
print_resolved_types (
- FriBidiRun *pp
+ const FriBidiRun *pp
)
{
fribidi_assert (pp);
@@ -203,13 +196,15 @@ static void
print_bidi_string (
/* input */
const FriBidiChar *str,
- FriBidiStrIndex len
+ const FriBidiStrIndex len
)
{
+ register FriBidiStrIndex i;
+
fribidi_assert (str);
MSG (" Org. types : ");
- for (; len; len--)
+ for (i = len; i; i--)
MSG2 ("%c", fribidi_char_from_bidi_type (fribidi_get_bidi_type (*str++)));
MSG ("\n");
}
@@ -306,22 +301,22 @@ print_bidi_string (
FRIBIDI_ENTRY FriBidiLevel
-fribidi_get_embedding_levels (
+fribidi_get_par_embedding_levels (
/* input */
const FriBidiChar *str,
- FriBidiStrIndex len,
+ const FriBidiStrIndex len,
/* input and output */
- FriBidiCharType *pbase_dir,
+ FriBidiParType *pbase_dir,
/* output */
FriBidiLevel *embedding_level_list
)
{
FriBidiLevel base_level, max_level = 0;
- FriBidiCharType base_dir;
+ FriBidiParType base_dir;
FriBidiRun *main_run_list = NULL, *explicits_list = NULL, *pp;
fribidi_boolean status = false;
- DBG ("entering fribidi_get_embedding_levels");
+ DBG ("entering fribidi_get_par_embedding_levels");
fribidi_assert (str);
fribidi_assert (pbase_dir);
@@ -376,7 +371,11 @@ fribidi_get_embedding_levels (
FriBidiCharType override, new_override;
FriBidiStrIndex i;
int stack_size, over_pushed, first_interval;
- LevelInfo *status_stack;
+ struct
+ {
+ FriBidiCharType override; /* only LTR, RTL and ON are valid */
+ FriBidiLevel level;
+ } *status_stack;
FriBidiRun temp_link;
/* explicits_list is a list like main_run_list, that holds the explicit
@@ -398,9 +397,8 @@ fribidi_get_embedding_levels (
stack_size = 0;
over_pushed = 0;
first_interval = 0;
- status_stack =
- (LevelInfo *) fribidi_malloc (sizeof (LevelInfo) *
- FRIBIDI_BIDI_MAX_RESOLVED_LEVELS);
+ status_stack = fribidi_malloc (sizeof (status_stack[0]) *
+ FRIBIDI_BIDI_MAX_RESOLVED_LEVELS);
for_run_list (pp, main_run_list)
{
@@ -795,7 +793,7 @@ fribidi_get_embedding_levels (
status = true;
out:
- DBG ("leaving fribidi_get_embedding_levels");
+ DBG ("leaving fribidi_get_par_embedding_levels");
if (main_run_list)
free_run_list (main_run_list);
@@ -805,10 +803,39 @@ out:
return status ? max_level + 1 : 0;
}
+
+FRIBIDI_ENTRY void
+fribidi_shape_mirroring (
+ /* input */
+ const FriBidiLevel *embedding_level_list,
+ const FriBidiStrIndex len,
+ /* input and output */
+ FriBidiChar *str
+)
+{
+ register FriBidiStrIndex i;
+
+ fribidi_assert (embedding_level_list);
+
+ if UNLIKELY
+ (len == 0 || !str) return;
+
+ /* L4. Mirror all characters that are in odd levels and have mirrors. */
+ for (i = len - 1; i >= 0; i--)
+ if (FRIBIDI_LEVEL_IS_RTL (embedding_level_list[i]))
+ {
+ FriBidiChar mirrored_ch;
+
+ if (fribidi_get_mirror_char (str[i], &mirrored_ch))
+ str[i] = mirrored_ch;
+ }
+}
+
+
static void
bidi_string_reverse (
FriBidiChar *str,
- FriBidiStrIndex len
+ const FriBidiStrIndex len
)
{
FriBidiStrIndex i;
@@ -826,7 +853,7 @@ bidi_string_reverse (
static void
index_array_reverse (
FriBidiStrIndex *arr,
- FriBidiStrIndex len
+ const FriBidiStrIndex len
)
{
FriBidiStrIndex i;
@@ -842,83 +869,24 @@ index_array_reverse (
}
-FRIBIDI_ENTRY FriBidiStrIndex
-fribidi_remove_bidi_marks (
- FriBidiChar *str,
- FriBidiStrIndex length,
- FriBidiStrIndex *position_to_this_list,
- FriBidiStrIndex *position_from_this_list,
- FriBidiLevel *embedding_level_list
-)
-{
- FriBidiStrIndex i, j;
- fribidi_boolean private_from_this = false;
-
- DBG ("entering fribidi_remove_bidi_marks");
-
- /* If to_this is to not NULL, we must have from_this as well. If it is
- not given by the caller, we have to make a private instance of it. */
- if (position_to_this_list && !position_from_this_list)
- {
- private_from_this = true;
- position_from_this_list =
- (FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) *
- length);
- }
-
- j = 0;
- for (i = 0; i < length; i++)
- if (!FRIBIDI_IS_EXPLICIT (fribidi_get_bidi_type (str[i]))
- && str[i] != FRIBIDI_CHAR_LRM && str[i] != FRIBIDI_CHAR_RLM)
- {
- str[j] = str[i];
- if (embedding_level_list)
- embedding_level_list[j] = embedding_level_list[i];
- if (position_from_this_list)
- position_from_this_list[j] = position_from_this_list[i];
- j++;
- }
-
- /* Convert the from_this list to to_this */
- if (position_to_this_list)
- {
- DBG (" converting from_this list to to_this");
- for (i = 0; i < length; i++)
- position_to_this_list[i] = -1;
- for (i = 0; i < length; i++)
- position_to_this_list[position_from_this_list[i]] = i;
- DBG (" converting from_this list to to_this, done");
- }
-
- if (private_from_this)
- fribidi_free (position_from_this_list);
-
- DBG ("leaving fribidi_remove_bidi_marks");
- return j;
-}
-
-
FRIBIDI_ENTRY FriBidiLevel
-fribidi_log2vis (
+fribidi_reorder_line (
/* input */
- const FriBidiChar *str,
- FriBidiStrIndex len,
+ FriBidiLevel *embedding_level_list,
+ const FriBidiStrIndex len,
+ const FriBidiStrIndex off,
/* input and output */
- FriBidiCharType *pbase_dir,
+ FriBidiChar *str,
/* output */
- FriBidiChar *visual_str,
FriBidiStrIndex *position_L_to_V_list,
- FriBidiStrIndex *position_V_to_L_list,
- FriBidiLevel *embedding_level_list
+ FriBidiStrIndex *position_V_to_L_list
)
{
- FriBidiLevel max_level = 0;
fribidi_boolean private_V_to_L = false;
- fribidi_boolean private_embedding_level_list = false;
fribidi_boolean status = false;
+ FriBidiLevel max_level = 0;
- fribidi_assert (str);
- fribidi_assert (pbase_dir);
+ fribidi_assert (embedding_level_list);
if UNLIKELY
(len == 0)
@@ -928,38 +896,24 @@ fribidi_log2vis (
}
if UNLIKELY
- (len > FRIBIDI_MAX_STRING_LENGTH && (position_V_to_L_list ||
- position_L_to_V_list))
+ (off + len > FRIBIDI_MAX_STRING_LENGTH && (position_V_to_L_list ||
+ position_L_to_V_list))
{
# if DEBUG
- MSG2 (FRIBIDI ": cannot handle strings > %ld characters\n",
- (long) FRIBIDI_MAX_STRING_LENGTH);
+ MSG2 (FRIBIDI ": cannot handle strings > %lu characters\n",
+ (unsigned long) FRIBIDI_MAX_STRING_LENGTH);
# endif /* DEBUG */
goto out;
}
- if (!embedding_level_list)
- {
- embedding_level_list = fribidi_malloc (len);
- if (!embedding_level_list)
- goto out;
- private_embedding_level_list = true;
- }
-
- max_level = fribidi_get_embedding_levels (str, len, pbase_dir,
- /* output */
- embedding_level_list) - 1;
- if UNLIKELY
- (max_level < 0) goto out;
-
/* 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. */
if (position_L_to_V_list && !position_V_to_L_list)
{
position_V_to_L_list =
- (FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) * len);
- if (!position_V_to_L_list)
- goto out;
+ fribidi_malloc (sizeof (position_V_to_L_list[0]) * len);
+ if UNLIKELY
+ (!position_V_to_L_list) goto out;
private_V_to_L = true;
}
@@ -969,91 +923,78 @@ fribidi_log2vis (
register FriBidiLevel level;
register FriBidiStrIndex i;
- /* Set up the ordering array to sorted order */
+ /* Set up the ordering array to identity order */
if (position_V_to_L_list)
{
- for (i = len - 1; i >= 0; i--)
+ for (i = off + len - 1; i >= off; i--)
position_V_to_L_list[i] = i;
}
- /* Copy the logical string to the visual */
- if (visual_str)
- {
- for (i = len - 1; i >= 0; i--)
- visual_str[i] = str[i];
- visual_str[len] = 0;
- }
-
- if (fribidi_mirroring_status () && visual_str)
- {
- /* L4. Mirror all characters that are in odd levels and have mirrors. */
- for (i = len - 1; i >= 0; i--)
- if (embedding_level_list[i] & 1)
- {
- FriBidiChar mirrored_ch;
- if (fribidi_get_mirror_char (visual_str[i], &mirrored_ch))
- visual_str[i] = mirrored_ch;
- }
- }
/* Reorder both the outstring and the order array */
- if (visual_str || position_V_to_L_list)
- {
- if (fribidi_reorder_nsm_status ())
- {
- /* L3. Reorder NSMs. */
- for (i = len - 1; i >= 0; i--)
- if ((embedding_level_list[i] & 1)
- && fribidi_get_bidi_type (str[i]) == FRIBIDI_TYPE_NSM)
- {
- register FriBidiStrIndex seq_end = i;
- level = embedding_level_list[i];
-
- for (i--; i >= 0 &&
- FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM (fribidi_get_bidi_type
- (str[i]))
- && embedding_level_list[i] == level; i--)
- ;
-
- if (i < 0 || embedding_level_list[i] != level)
- {
- i++;
- DBG ("warning: NSM(s) at the beggining of level run");
- }
-
- if (visual_str)
- {
- bidi_string_reverse (visual_str + i, seq_end - i + 1);
- }
- if (position_V_to_L_list)
- {
- index_array_reverse (position_V_to_L_list + i,
- seq_end - i + 1);
- }
- }
- }
-
- /* L2. Reorder. */
- for (level = max_level; level > 0; level--)
- for (i = len - 1; i >= 0; i--)
- if (embedding_level_list[i] >= level)
+ {
+ if (fribidi_reorder_nsm_status ())
+ {
+ /* 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)
{
- /* Find all stretches that are >= level_idx */
register FriBidiStrIndex seq_end = i;
- for (i--; i >= 0 && embedding_level_list[i] >= level; i--)
+ level = embedding_level_list[i];
+
+ for (i--; i >= off &&
+ FRIBIDI_IS_EXPLICIT_OR_BN_OR_NSM (fribidi_get_bidi_type
+ (str[i]))
+ && embedding_level_list[i] == level; i--)
;
- if (visual_str)
- bidi_string_reverse (visual_str + i + 1, seq_end - i);
+ if (i < off || embedding_level_list[i] != level)
+ {
+ i++;
+ DBG ("warning: NSM(s) at the beggining of level run");
+ }
+
+ if (str)
+ {
+ bidi_string_reverse (str + i, seq_end - i + 1);
+ }
if (position_V_to_L_list)
- index_array_reverse (position_V_to_L_list + i + 1, seq_end
- - i);
+ {
+ index_array_reverse (position_V_to_L_list + i,
+ seq_end - i + 1);
+ }
}
- }
+ }
+
+ /* Find max_level of the line. We don't reuse the paragraph
+ * max_level, both for a cleaner API, and that the line max_level
+ * may be far less than paragraph max_level. */
+ for (i = off + len - 1; i >= off; i--)
+ if (embedding_level_list[i] > max_level)
+ max_level = embedding_level_list[i];
+
+ /* L2. Reorder. */
+ for (level = max_level; level > 0; level--)
+ for (i = off + len - 1; i >= off; i--)
+ if (embedding_level_list[i] >= level)
+ {
+ /* Find all stretches that are >= level_idx */
+ register FriBidiStrIndex seq_end = i;
+ for (i--; i >= off && embedding_level_list[i] >= level; i--)
+ ;
+
+ if (str)
+ bidi_string_reverse (str + i + 1, seq_end - i);
+ if (position_V_to_L_list)
+ index_array_reverse (position_V_to_L_list + i + 1, seq_end
+ - i);
+ }
+ }
/* Convert the v2l list to l2v */
if (position_L_to_V_list)
{
- for (i = 0; i < len; i++)
+ for (i = off + len - 1; i >= off; i--)
position_L_to_V_list[position_V_to_L_list[i]] = i;
}
}
@@ -1065,9 +1006,6 @@ out:
if (private_V_to_L)
fribidi_free (position_V_to_L_list);
- if (private_embedding_level_list)
- fribidi_free (embedding_level_list);
-
return status ? max_level + 1 : 0;
}
diff --git a/lib/fribidi-bidi.h b/lib/fribidi-bidi.h
index eea6a5d..7829194 100644
--- a/lib/fribidi-bidi.h
+++ b/lib/fribidi-bidi.h
@@ -1,10 +1,10 @@
/* FriBidi
* fribidi-bidi.h - bidirectional algorithm
*
- * $Id: fribidi-bidi.h,v 1.5 2004-06-04 16:43:51 behdad Exp $
+ * $Id: fribidi-bidi.h,v 1.6 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-06-04 16:43:51 $
- * $Revision: 1.5 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.6 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.h,v $
*
* Authors:
@@ -42,35 +42,8 @@
#include "fribidi-begindecls.h"
-#define fribidi_log2vis FRIBIDI_NAMESPACE(log2vis)
-/* fribidi_log2vis - get visual string
- *
- * This function converts the logical input string to the visual output
- * strings as specified by the Unicode Bidirectional Algorithm. As a side
- * effect it also generates mapping lists between the two strings, and the
- * list of embedding levels as defined by the algorithm. If any of the the
- * lists are passed as NULL, the list is ignored and not filled.
- *
- * Returns: Maximum level found plus one, or zero if any error occured
- * (memory allocation failure most probably).
- */
-FRIBIDI_ENTRY FriBidiLevel
-fribidi_log2vis (
- const FriBidiChar *str, /* input logical string */
- FriBidiStrIndex len, /* input string length */
- FriBidiCharType *pbase_dir, /* requested and resolved paragraph
- * base direction */
- FriBidiChar *visual_str, /* output visual string */
- FriBidiStrIndex *position_L_to_V_list, /* output mapping from logical to
- * visual string positions */
- FriBidiStrIndex *position_V_to_L_list, /* output mapping from visual string
- * back to the logical string
- * positions */
- FriBidiLevel *embedding_level_list /* output list of embedding levels */
-) FRIBIDI_GNUC_WARN_UNUSED;
-
-#define fribidi_get_embedding_levels FRIBIDI_NAMESPACE(get_embedding_levels)
-/* fribidi_get_embedding_levels - get bidi embedding levels
+#define fribidi_get_par_embedding_levels FRIBIDI_NAMESPACE(get_par_embedding_levels)
+/* fribidi_get_par_embedding_levels - get bidi embedding levels of a paragraph
*
* This function finds the bidi embedding levels of a single paragraph,
* as defined by the Unicode Bidirectional Algorithm.
@@ -78,10 +51,11 @@ fribidi_log2vis (
* Returns: Maximum level found plus one, or zero if any error occured
* (memory allocation failure most probably).
*/
- FRIBIDI_ENTRY FriBidiLevel fribidi_get_embedding_levels (
- const FriBidiChar *str, /* input logical string */
- FriBidiStrIndex len, /* input string length */
- FriBidiCharType *pbase_dir, /* requested and resolved paragraph
+FRIBIDI_ENTRY FriBidiLevel
+fribidi_get_par_embedding_levels (
+ const FriBidiChar *str, /* input paragraph string */
+ const FriBidiStrIndex len, /* input string length of the paragraph */
+ FriBidiParType *pbase_dir, /* requested and resolved paragraph
* base direction */
FriBidiLevel *embedding_level_list /* output list of embedding levels */
) FRIBIDI_GNUC_WARN_UNUSED;
@@ -90,39 +64,43 @@ fribidi_log2vis (
/* fribidi_shape - do mirroring shaping
*
* This functions replaces mirroring characters on right-to-left embeddings in
- * strint str with their mirrored equivalent as returned by
+ * string str with their mirrored equivalent as returned by
* fribidi_get_mirror_char().
- *
- * Returns: Non-zero if it was successful, or zero if any error occured
- * (memory allocation failure most probably).
*/
- FRIBIDI_ENTRY fribidi_boolean fribidi_shape_mirroring (
- const FriBidiChar *str, /* string to shape */
- FriBidiStrIndex len, /* input string length */
- FriBidiLevel *embedding_level_list /* input list of embedding levels */
-) FRIBIDI_GNUC_WARN_UNUSED;
+ FRIBIDI_ENTRY void fribidi_shape_mirroring (
+ const FriBidiLevel *embedding_level_list, /* input list of embedding
+ levels, as returned by
+ fribidi_get_par_embedding_levels */
+ const FriBidiStrIndex len, /* input string length */
+ FriBidiChar *str /* string to shape */
+);
-#define fribidi_remove_bidi_marks FRIBIDI_NAMESPACE(remove_bidi_marks)
-/* fribidi_remove_bidi_marks - remove bidi marks out an string
+#define fribidi_reorder_line FRIBIDI_NAMESPACE(reorder_line)
+/* fribidi_reorder_line - reorder a line of logical string to visual
*
- * This function removes the bidi marks out of an string and the
- * accompanying lists. If any of the input lists are NULL, the list is
- * skipped.
+ * 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_*.
*
- * Bugs: It is not clear that if the input string is a logical, or visual
- * string. It is know to have problems handling position lists. In short,
- * it should be avoided.
- *
- * Returns: New length of the string.
+ * Returns: Maximum level found in this line plus one, or zero if any error
+ * occured (memory allocation failure most probably).
*/
- FRIBIDI_ENTRY FriBidiStrIndex fribidi_remove_bidi_marks (
- FriBidiChar *str,
- FriBidiStrIndex length,
- FriBidiStrIndex *position_to_this_list,
- FriBidiStrIndex *position_from_this_list,
- FriBidiLevel *embedding_level_list
+ FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line (
+ 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 */
+ FriBidiChar *str, /* string to shape */
+ FriBidiStrIndex *position_L_to_V_list, /* output mapping from logical to
+ visual string positions */
+ FriBidiStrIndex *position_V_to_L_list /* output mapping from visual string
+ back to logical string positions */
) FRIBIDI_GNUC_WARN_UNUSED;
+
#include "fribidi-enddecls.h"
#endif /* !_FRIBIDI_BIDI_H */
diff --git a/lib/fribidi-mirroring.c b/lib/fribidi-mirroring.c
index a19cc32..5b16ed7 100644
--- a/lib/fribidi-mirroring.c
+++ b/lib/fribidi-mirroring.c
@@ -20,12 +20,13 @@
* along with GNU FriBidi; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * For licensing issues, contact <license@farsiweb.info>.
+ * For licensing issues, contact <license@farsiweb.info> or write to
+ * Sharif FarsiWeb, Inc., PO Box 13445-389, Tehran, Iran.
*/
-/* $Id: fribidi-mirroring.c,v 1.7 2004-05-29 11:32:23 behdad Exp $
+/* $Id: fribidi-mirroring.c,v 1.8 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-05-29 11:32:23 $
- * $Revision: 1.7 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.8 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-mirroring.c,v $
*
* Authors:
diff --git a/lib/fribidi-mirroring.h b/lib/fribidi-mirroring.h
index 683ef73..1f0eea2 100644
--- a/lib/fribidi-mirroring.h
+++ b/lib/fribidi-mirroring.h
@@ -20,12 +20,13 @@
* along with GNU FriBidi; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * For licensing issues, contact <license@farsiweb.info>.
+ * For licensing issues, contact <license@farsiweb.info> or write to
+ * Sharif FarsiWeb, Inc., PO Box 13445-389, Tehran, Iran.
*/
-/* $Id: fribidi-mirroring.h,v 1.5 2004-05-29 11:32:23 behdad Exp $
+/* $Id: fribidi-mirroring.h,v 1.6 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-05-29 11:32:23 $
- * $Revision: 1.5 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.6 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-mirroring.h,v $
*
* Authors:
diff --git a/lib/fribidi.c b/lib/fribidi.c
index 0e99872..9e234cb 100644
--- a/lib/fribidi.c
+++ b/lib/fribidi.c
@@ -1,10 +1,10 @@
/* FriBidi
* fribidi.c - Unicode bidirectional and Arabic joining algorithms
*
- * $Id: fribidi.c,v 1.6 2004-05-31 18:39:39 behdad Exp $
+ * $Id: fribidi.c,v 1.7 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-05-31 18:39:39 $
- * $Revision: 1.6 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.7 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi.c,v $
*
* Authors:
@@ -37,6 +37,170 @@
#include <fribidi.h>
+FRIBIDI_ENTRY void
+fribidi_shape (
+ /* input */
+ const FriBidiLevel *embedding_level_list,
+ const FriBidiStrIndex len,
+ /* input and output */
+ FriBidiChar *str
+)
+{
+ fribidi_assert (embedding_level_list);
+
+ if UNLIKELY
+ (len == 0 || !str) return;
+
+ fribidi_shape_mirroring (embedding_level_list, len, str);
+}
+
+
+FRIBIDI_ENTRY FriBidiStrIndex
+fribidi_remove_bidi_marks (
+ FriBidiChar *str,
+ const FriBidiStrIndex len,
+ FriBidiStrIndex *position_to_this_list,
+ FriBidiStrIndex *position_from_this_list,
+ FriBidiLevel *embedding_level_list
+)
+{
+ register FriBidiStrIndex i, j = 0;
+ fribidi_boolean private_from_this = false;
+ fribidi_boolean status = false;
+
+ fribidi_assert (str);
+
+ if UNLIKELY
+ (len == 0)
+ {
+ status = true;
+ goto out;
+ }
+
+ /* If to_this is to not NULL, we must have from_this as well. If it is
+ not given by the caller, we have to make a private instance of it. */
+ if (position_to_this_list && !position_from_this_list)
+ {
+ position_from_this_list = fribidi_malloc (sizeof
+ (position_from_this_list[0]) *
+ len);
+ if UNLIKELY
+ (!position_from_this_list) goto out;
+ private_from_this = true;
+ for (i = len - 1; i >= 0; i--)
+ position_from_this_list[position_to_this_list[i]] = i;
+ }
+
+ for (i = 0; i < len; i++)
+ if (!FRIBIDI_IS_EXPLICIT_OR_BN (fribidi_get_bidi_type (str[i]))
+ && str[i] != FRIBIDI_CHAR_LRM && str[i] != FRIBIDI_CHAR_RLM)
+ {
+ str[j] = str[i];
+ if (embedding_level_list)
+ embedding_level_list[j] = embedding_level_list[i];
+ if (position_from_this_list)
+ position_from_this_list[j] = position_from_this_list[i];
+ j++;
+ }
+
+ /* Convert the from_this list to to_this */
+ if (position_to_this_list)
+ {
+ for (i = 0; i < len; i++)
+ position_to_this_list[i] = -1;
+ for (i = 0; i < len; i++)
+ position_to_this_list[position_from_this_list[i]] = i;
+ }
+
+ status = true;
+
+out:
+
+ if (private_from_this)
+ fribidi_free (position_from_this_list);
+
+ return status ? j : -1;
+}
+
+
+FRIBIDI_ENTRY FriBidiLevel
+fribidi_log2vis (
+ /* input */
+ const FriBidiChar *str,
+ FriBidiStrIndex len,
+ /* input and output */
+ FriBidiParType *pbase_dir,
+ /* output */
+ FriBidiChar *visual_str,
+ FriBidiStrIndex *position_L_to_V_list,
+ FriBidiStrIndex *position_V_to_L_list,
+ FriBidiLevel *embedding_level_list
+)
+{
+ FriBidiLevel max_level = 0;
+ fribidi_boolean private_V_to_L = false;
+ fribidi_boolean private_embedding_level_list = false;
+ fribidi_boolean status = false;
+
+ fribidi_assert (str);
+ fribidi_assert (pbase_dir);
+
+ if UNLIKELY
+ (len == 0)
+ {
+ status = true;
+ goto out;
+ }
+
+ if (!embedding_level_list)
+ {
+ embedding_level_list = fribidi_malloc (len);
+ if (!embedding_level_list)
+ goto out;
+ private_embedding_level_list = true;
+ }
+
+ max_level = fribidi_get_par_embedding_levels (str, len, pbase_dir,
+ embedding_level_list) - 1;
+ if UNLIKELY
+ (max_level < 0) goto out;
+
+ /* 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. */
+ if (position_L_to_V_list && !position_V_to_L_list)
+ {
+ position_V_to_L_list =
+ (FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) * len);
+ if (!position_V_to_L_list)
+ goto out;
+ private_V_to_L = true;
+ }
+
+ if (visual_str)
+ {
+ register FriBidiStrIndex i;
+
+ for (i = len; i >= 0; i--)
+ visual_str[i] = str[i];
+ }
+
+ fribidi_shape (embedding_level_list, len, visual_str);
+
+ status = fribidi_reorder_line (embedding_level_list, len, 0, visual_str,
+ position_L_to_V_list, position_V_to_L_list);
+
+out:
+
+ if (private_V_to_L)
+ fribidi_free (position_V_to_L_list);
+
+ if (private_embedding_level_list)
+ fribidi_free (embedding_level_list);
+
+ return status ? max_level + 1 : 0;
+}
+
+
const char *fribidi_unicode_version = FRIBIDI_UNICODE_VERSION;
const char *fribidi_version_info =
diff --git a/lib/fribidi.def b/lib/fribidi.def
index 8cca5ac..78d7522 100644
--- a/lib/fribidi.def
+++ b/lib/fribidi.def
@@ -4,7 +4,7 @@ fribidi_get_bidi_types
fribidi_get_type
fribidi_get_types
fribidi_log2vis
-fribidi_get_embedding_levels
+fribidi_get_par_embedding_levels
fribidi_remove_bidi_marks
fribidi_get_mirror_char
fribidi_debug_status
diff --git a/lib/fribidi.h b/lib/fribidi.h
index cbc3a23..f246eda 100644
--- a/lib/fribidi.h
+++ b/lib/fribidi.h
@@ -1,10 +1,10 @@
/* FriBidi
* fribidi.h - Unicode bidirectional and Arabic joining algorithms
*
- * $Id: fribidi.h,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: fribidi.h,v 1.2 2004-06-07 20:38:21 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-06-07 20:38:21 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi.h,v $
*
* Author:
@@ -32,16 +32,97 @@
#ifndef _FRIBIDI_H
#define _FRIBIDI_H
-#include "fribidi-bidi.h"
-#include "fribidi-bidi-type.h"
+#include "fribidi-unicode.h"
+#include "fribidi-types.h"
#include "fribidi-env.h"
+#include "fribidi-bidi-type.h"
+#include "fribidi-bidi.h"
#include "fribidi-mirroring.h"
-#include "fribidi-types.h"
-#include "fribidi-unicode.h"
#if FRIBIDI_CHARSETS
# include "fribidi-char-sets.h"
#endif /* FRIBIDI_CHARSETS */
+
+#define fribidi_shape FRIBIDI_NAMESPACE(shape)
+/* fribidi_shape - do bidi-dependent shaping
+ *
+ * This function does all shaping work that depends on the resolved embedding
+ * levels of the characters. Currently it does mirroring and Arabic shaping,
+ * but the list may grow later. Individual shaping features can be turned
+ * on/off using environmental setting functions fribidi_env_*.
+ */
+FRIBIDI_ENTRY void fribidi_shape (
+ const FriBidiLevel *embedding_level_list, /* input list of embedding
+ levels, as returned by
+ fribidi_get_par_embedding_levels */
+ const FriBidiStrIndex len, /* input string length */
+ FriBidiChar *str /* string to shape */
+);
+
+#define fribidi_remove_bidi_marks FRIBIDI_NAMESPACE(remove_bidi_marks)
+/* fribidi_remove_bidi_marks - remove bidi marks out of an string
+ *
+ * This function removes the bidi and boundary-neutral marks out of an string
+ * and the accompanying lists. If any of the input lists are NULL, the list
+ * is skipped. If str is the visual string, then position_to_this_list is
+ * position_L_to_V_list and position_from_this_list is position_V_to_L_list;
+ * if str is the logical string, the other way. Moreover, the position maps
+ * should be filled with valid entries. A position map pointing to a removed
+ * character is filled with -1. By the way, you should not use
+ * embedding_level_list if str is visual string. For best results it should
+ * be run on a whole paragraph, not lines; but feel free to do otherwise if
+ * you know what you are doing.
+ *
+ * Returns: New length of the string, or -1 if an error occured (memory
+ * allocation failure most probably).
+ */
+FRIBIDI_ENTRY FriBidiStrIndex
+fribidi_remove_bidi_marks (
+ FriBidiChar *str, /* input string to clean */
+ const FriBidiStrIndex len, /* input string length */
+ FriBidiStrIndex *position_to_this_list, /* list mapping positions to the
+ order used in str */
+ FriBidiStrIndex *position_from_this_list, /* list mapping positions from the
+ order used in str */
+ FriBidiLevel *embedding_level_list /* list of embedding levels */
+) FRIBIDI_GNUC_WARN_UNUSED;
+
+
+/* Deprecated interface: */
+
+#define fribidi_log2vis FRIBIDI_NAMESPACE(log2vis)
+/* fribidi_log2vis - get visual string
+ *
+ * This function converts the logical input string to the visual output
+ * strings as specified by the Unicode Bidirectional Algorithm. As a side
+ * effect it also generates mapping lists between the two strings, and the
+ * list of embedding levels as defined by the algorithm. If any of the the
+ * lists are passed as NULL, the list is ignored and not filled. This
+ * function is obsolete because it only handles one-line paragraphs.
+ * Please consider using other functions instead. Deprecated.
+ *
+ * Returns: Maximum level found plus one, or zero if any error occured
+ * (memory allocation failure most probably).
+ */
+ FRIBIDI_ENTRY FriBidiLevel fribidi_log2vis (
+ const FriBidiChar *str, /* input logical string */
+ const FriBidiStrIndex len, /* input string length */
+ FriBidiParType *pbase_dir, /* requested and resolved paragraph
+ * base direction */
+ FriBidiChar *visual_str, /* output visual string */
+ FriBidiStrIndex *position_L_to_V_list, /* output mapping from logical to
+ * visual string positions */
+ FriBidiStrIndex *position_V_to_L_list, /* output mapping from visual string
+ * back to the logical string
+ * positions */
+ FriBidiLevel *embedding_level_list /* output list of embedding levels */
+)
+ FRIBIDI_GNUC_WARN_UNUSED FRIBIDI_GNUC_DEPRECATED;
+
+
+#define fribidi_log2vis_get_embedding_levels fribidi_get_par_embedding_levels
+
+
#endif /* !_FRIBIDI_H */
/* Editor directions:
* vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
diff --git a/test/test_UTF-8_persian.reference b/test/test_UTF-8_persian.reference
index cd45ac2..0b0cf6b 100644
--- a/test/test_UTF-8_persian.reference
+++ b/test/test_UTF-8_persian.reference
@@ -1,14 +1,14 @@
الا يا ايها الساقی ادر کاسا و ناولها => اهلوان و اساک ردا یقاسلا اهيا اي الا
-که عشق آسان نمود اول ولی افتاد مشکل‌ها => اه‌لکشم داتفا یلو لوا دومن ناسآ قشع هک
-به بوی نافه‌ای کاخر صبا زان طره بگشايد => دياشگب هرط ناز ابص رخاک یا‌هفان یوب هب
-ز تاب جعد مشکينش چه خون افتاد در دل‌ها => اه‌لد رد داتفا نوخ هچ شنيکشم دعج بات ز
+که عشق آسان نمود اول ولی افتاد مشکل‌ها => اهلکشم داتفا یلو لوا دومن ناسآ قشع هک
+به بوی نافه‌ای کاخر صبا زان طره بگشايد => دياشگب هرط ناز ابص رخاک یاهفان یوب هب
+ز تاب جعد مشکينش چه خون افتاد در دل‌ها => اهلد رد داتفا نوخ هچ شنيکشم دعج بات ز
مرا در منزل جانان چه امن عيش چون هر دم => مد ره نوچ شيع نما هچ ناناج لزنم رد ارم
-جرس فرياد می‌دارد که بربنديد محمل‌ها => اه‌لمحم ديدنبرب هک دراد‌یم دايرف سرج
+جرس فرياد می‌دارد که بربنديد محمل‌ها => اهلمحم ديدنبرب هک درادیم دايرف سرج
به می سجاده رنگين کن گرت پير مغان گويد => ديوگ ناغم ريپ ترگ نک نيگنر هداجس یم هب
-که سالک بی‌خبر نبود ز راه و رسم منزل‌ها => اه‌لزنم مسر و هار ز دوبن ربخ‌یب کلاس هک
+که سالک بی‌خبر نبود ز راه و رسم منزل‌ها => اهلزنم مسر و هار ز دوبن ربخیب کلاس هک
شب تاريک و بيم موج و گردابی چنين هايل => لياه نينچ یبادرگ و جوم ميب و کيرات بش
-کجا دانند حال ما سبکباران ساحل‌ها => اه‌لحاس نارابکبس ام لاح دنناد اجک
+کجا دانند حال ما سبکباران ساحل‌ها => اهلحاس نارابکبس ام لاح دنناد اجک
همه کارم ز خود کامی به بدنامی کشيد آخر => رخآ ديشک یماندب هب یماک دوخ ز مراک همه
-نهان کی ماند آن رازی کز او سازند محفل‌ها => اه‌لفحم دنزاس وا زک یزار نآ دنام یک ناهن
-حضوری گر همی‌خواهی از او غايب مشو حافظ => ظفاح وشم بياغ وا زا یهاوخ‌یمه رگ یروضح
+نهان کی ماند آن رازی کز او سازند محفل‌ها => اهلفحم دنزاس وا زک یزار نآ دنام یک ناهن
+حضوری گر همی‌خواهی از او غايب مشو حافظ => ظفاح وشم بياغ وا زا یهاوخیمه رگ یروضح
متی ما تلق من تهوی دع الدنيا و اهملها => اهلمها و ايندلا عد یوهت نم قلت ام یتم