From: behdad Date: Mon, 14 Jun 2004 17:00:33 +0000 (+0000) Subject: fribidi_get_bidi_types is back. Allow passing bidi types to X-Git-Tag: FRIBIDI_0_19_1~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e32eff3de2d41d4a1674e28991eb82c1d00dd79;p=fribidi fribidi_get_bidi_types is back. Allow passing bidi types to get_par_embedding_levels and reorder_line functions. --- diff --git a/lib/bidi-types.h b/lib/bidi-types.h index 26999a3..3ae213e 100644 --- a/lib/bidi-types.h +++ b/lib/bidi-types.h @@ -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 #endif /* !_BIDI_TYPES_H */ diff --git a/lib/fribidi-bidi-type.c b/lib/fribidi-bidi-type.c index 00d124f..cc22b0f 100644 --- a/lib/fribidi-bidi-type.c +++ b/lib/fribidi-bidi-type.c @@ -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 + */ diff --git a/lib/fribidi-bidi-type.h b/lib/fribidi-bidi-type.h index ab5932b..e98722a 100644 --- a/lib/fribidi-bidi-type.h +++ b/lib/fribidi-bidi-type.h @@ -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 */ diff --git a/lib/fribidi-bidi.c b/lib/fribidi-bidi.c index ffa1c28..ef4ccd6 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.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--) ; diff --git a/lib/fribidi-bidi.h b/lib/fribidi-bidi.h index c94bf3f..ad1f128 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.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: @@ -48,6 +48,12 @@ * 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 */ diff --git a/lib/fribidi-run.c b/lib/fribidi-run.c index f8e5269..f4f8319 100644 --- a/lib/fribidi-run.c +++ b/lib/fribidi-run.c @@ -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 (); diff --git a/lib/fribidi.c b/lib/fribidi.c index b75db6f..0af4c93 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.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: diff --git a/lib/run.h b/lib/run.h index 9388048..d284d1d 100644 --- 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;