From: behdad Date: Mon, 21 Jun 2004 16:15:27 +0000 (+0000) Subject: Fixed a bug in fribidi_log2vis(), also changed fribidi_reorder_line() api to X-Git-Tag: FRIBIDI_0_19_1~60 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1a9af57fe88c46b5f9f7fd47db37895b3e58e78;p=fribidi Fixed a bug in fribidi_log2vis(), also changed fribidi_reorder_line() api to allow not passing visual_str, by passing str instead. --- diff --git a/lib/fribidi-bidi.c b/lib/fribidi-bidi.c index ceabfbb..e2ca739 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.15 2004-06-18 22:41:39 behdad Exp $ + * $Id: fribidi-bidi.c,v 1.16 2004-06-21 16:15:27 behdad Exp $ * $Author: behdad $ - * $Date: 2004-06-18 22:41:39 $ - * $Revision: 1.15 $ + * $Date: 2004-06-21 16:15:27 $ + * $Revision: 1.16 $ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.c,v $ * * Authors: @@ -757,11 +757,11 @@ fribidi_get_par_embedding_levels ( register FriBidiRun *p, *q, *list; /* 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()). */ + 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; @@ -877,8 +877,7 @@ index_array_reverse ( FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line ( - /* input and output */ - FriBidiChar *str, + const FriBidiChar *str, /* input */ const FriBidiStrIndex len, const FriBidiStrIndex off, @@ -886,6 +885,7 @@ fribidi_reorder_line ( const FriBidiParType base_dir, /* input and output */ FriBidiLevel *embedding_levels, + FriBidiChar *visual_str, /* output */ FriBidiStrIndex *positions_L_to_V, FriBidiStrIndex *positions_V_to_L @@ -915,17 +915,20 @@ fribidi_reorder_line ( DBG ("in fribidi_reorder_line"); - fribidi_assert (str || bidi_types); + fribidi_assert (str || visual_str || bidi_types); fribidi_assert (embedding_levels); + if (!str) + str = visual_str; + 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.*/ + 4. any sequence of white space characters at the end of the line. */ for (i = off + len - 1; i >= off && - FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS (BIDI_TYPE (i)); i--) + FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS (BIDI_TYPE (i)); i--) embedding_levels[i] = FRIBIDI_DIR_TO_LEVEL (base_dir); } @@ -975,9 +978,9 @@ fribidi_reorder_line ( DBG ("warning: NSM(s) at the beggining of level run"); } - if (str) + if (visual_str) { - bidi_string_reverse (str + i, seq_end - i + 1); + bidi_string_reverse (visual_str + i, seq_end - i + 1); } if (positions_V_to_L) { @@ -1004,8 +1007,8 @@ fribidi_reorder_line ( for (i--; i >= off && embedding_levels[i] >= level; i--) ; - if (str) - bidi_string_reverse (str + i + 1, seq_end - i); + if (visual_str) + bidi_string_reverse (visual_str + i + 1, seq_end - i); if (positions_V_to_L) index_array_reverse (positions_V_to_L + i + 1, seq_end - i); } diff --git a/lib/fribidi-bidi.h b/lib/fribidi-bidi.h index b0d9c79..90f0763 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.11 2004-06-18 19:21:33 behdad Exp $ + * $Id: fribidi-bidi.h,v 1.12 2004-06-21 16:15:27 behdad Exp $ * $Author: behdad $ - * $Date: 2004-06-18 19:21:33 $ - * $Revision: 1.11 $ + * $Date: 2004-06-21 16:15:27 $ + * $Revision: 1.12 $ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.h,v $ * * Authors: @@ -116,12 +116,19 @@ fribidi_get_par_embedding_levels ( * * As a side effect it also sets position maps if not NULL. * - * You can provide either the string, or the bidi types; or both. If + * You can provide either the string str, 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 neither str nor bidi types are provided, visual_str is used instead. + * Feel free to pass the same string as both str and visual_str, but if you + * done extensive complicated shaping in visual_str, you better provide + * logical string as str. There is no known differences yet between providing + * logical or visual string as 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. + * Providing bidi types if available at your side, saves you a few cycles, and + * you don't need to provide str anymore. * * You should provide the resolved paragraph direction and embedding levels as * set by fribidi_get_par_embedding_levels(). Also note that the embedding @@ -139,15 +146,16 @@ fribidi_get_par_embedding_levels ( * occured (memory allocation failure most probably). */ FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line ( - FriBidiChar *str, /* string to reorder */ + const FriBidiChar *str, /* input string */ 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 */ const FriBidiParType base_dir, /* resolved paragraph base direction */ - FriBidiLevel *embedding_levels, /* input list of embedding levels, + FriBidiLevel *embedding_levels, /* list of embedding levels, as returned by fribidi_get_par_embedding_levels */ + FriBidiChar *visual_str, /* visual string to reorder */ FriBidiStrIndex *positions_L_to_V, /* output mapping from logical to visual string positions */ FriBidiStrIndex *positions_V_to_L /* output mapping from visual string diff --git a/lib/fribidi.c b/lib/fribidi.c index f3d581b..7ed0093 100644 --- a/lib/fribidi.c +++ b/lib/fribidi.c @@ -1,10 +1,10 @@ /* FriBidi * fribidi.c - Unicode bidirectional and Arabic joining/shaping algorithms * - * $Id: fribidi.c,v 1.12 2004-06-18 19:21:33 behdad Exp $ + * $Id: fribidi.c,v 1.13 2004-06-21 16:15:27 behdad Exp $ * $Author: behdad $ - * $Date: 2004-06-18 19:21:33 $ - * $Revision: 1.12 $ + * $Date: 2004-06-21 16:15:27 $ + * $Revision: 1.13 $ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi.c,v $ * * Authors: @@ -172,15 +172,23 @@ fribidi_log2vis ( if UNLIKELY (max_level < 0) goto out; + if (visual_str) + { + register FriBidiStrIndex i; + + for (i = len - 1; i >= 0; i--) + visual_str[i] = str[i]; + #if !FRIBIDI_NO_ARABIC - /* Arabic joining */ - { - ar_props = fribidi_malloc (len * sizeof ar_props[0]); - fribidi_get_joining_types (str, len, ar_props); - fribidi_join_arabic (embedding_levels, len, ar_props); - } + /* Arabic joining */ + ar_props = fribidi_malloc (len * sizeof ar_props[0]); + fribidi_get_joining_types (str, len, ar_props); + fribidi_join_arabic (embedding_levels, len, ar_props); #endif /* !FRIBIDI_NO_ARABIC */ + fribidi_shape (embedding_levels, len, visual_str); + } + /* 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 (positions_L_to_V && !positions_V_to_L) @@ -192,17 +200,10 @@ fribidi_log2vis ( 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_levels, len, visual_str); - - status = fribidi_reorder_line (visual_str, len, 0, NULL, *pbase_dir, embedding_levels, positions_L_to_V, positions_V_to_L); + status = + fribidi_reorder_line (str, len, 0, NULL, *pbase_dir, + embedding_levels, visual_str, + positions_L_to_V, positions_V_to_L); out: