From 4c3646123330086dd6d7508d68b6739826407929 Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Thu, 12 Apr 2018 12:55:26 +0300 Subject: [PATCH] evas: apply fribidi bracket types to show paired bracket properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: The fribidi couldn't reorganize paired brackets (Ex. '(', ')') when there is RTL + LTR text. According to TR9(http://www.unicode.org/reports/tr9/), it has to be shown properly without LRM or RLM. Also, from the fribidi 1.0.0, fribidi_get_par_embedding_levels() was deprecated. It is replaced with fribidi_get_par_embedding_levels_ex() which is including paired brankets rules from TR9. @feature Test Plan: 1. Create a elm_entry. 2. Set a text by calling text_set. elm_entry_entry_set(entry, "مرحبا Hello (40)"); 3. Run and see the results. - Without this patch or fribidi 1.X.X, it will show text like this... "(Hello (40 مرحبا" - With this patch and fribidi >= 1.0.0 "Hello (40) مرحبا" Reviewers: raster, cedric, herdsman, woohyun Reviewed By: herdsman Differential Revision: https://phab.enlightenment.org/D5921 --- .../evas/common/language/evas_bidi_utils.c | 70 ++++++++++++++++--- .../evas/common/language/evas_bidi_utils.h | 3 + 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/lib/evas/common/language/evas_bidi_utils.c b/src/lib/evas/common/language/evas_bidi_utils.c index fc9a35dd9b..a4653416e7 100644 --- a/src/lib/evas/common/language/evas_bidi_utils.c +++ b/src/lib/evas/common/language/evas_bidi_utils.c @@ -234,6 +234,10 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, EvasBiDiLevel *embedding_levels = NULL; const FriBidiChar *ustr; FriBidiChar *base_ustr = NULL; + EvasBiDiLevel ret_level = 0; +#if FRIBIDI_MAJOR_VERSION >= 1 + EvasBiDiBracketType *bracket_types = NULL; +#endif if (!eina_ustr) return NULL; @@ -266,6 +270,15 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, } fribidi_get_bidi_types(ustr, len, char_types); +#if FRIBIDI_MAJOR_VERSION >= 1 + bracket_types = (EvasBiDiBracketType *) malloc(sizeof(EvasBiDiBracketType) * len); + if (!bracket_types) + { + goto cleanup; + } + fribidi_get_bracket_types(ustr, len, char_types, bracket_types); +#endif + embedding_levels = (EvasBiDiLevel *)malloc(sizeof(EvasBiDiLevel) * len); if (!embedding_levels) { @@ -282,10 +295,19 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, for (itr = segment_idxs ; *itr > 0 ; itr++) { direction = base_bidi; - if (!fribidi_get_par_embedding_levels(char_types + pos, - *itr - pos, - &direction, - embedding_levels + pos)) +#if FRIBIDI_MAJOR_VERSION >= 1 + ret_level = fribidi_get_par_embedding_levels_ex(char_types + pos, + bracket_types, + *itr - pos, + &direction, + embedding_levels + pos); +#else + ret_level = fribidi_get_par_embedding_levels(char_types + pos, + *itr - pos, + &direction, + embedding_levels + pos); +#endif + if (!ret_level) { goto cleanup; } @@ -308,10 +330,19 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, } direction = base_bidi; - if (!fribidi_get_par_embedding_levels(char_types + pos, - len - pos, - &direction, - embedding_levels + pos)) +#if FRIBIDI_MAJOR_VERSION >= 1 + ret_level = fribidi_get_par_embedding_levels_ex(char_types + pos, + bracket_types, + len - pos, + &direction, + embedding_levels + pos); +#else + ret_level = fribidi_get_par_embedding_levels(char_types + pos, + len - pos, + &direction, + embedding_levels + pos); +#endif + if (!ret_level) { goto cleanup; } @@ -328,8 +359,19 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, } else { - if (!fribidi_get_par_embedding_levels(char_types, len, - &bidi_props->direction, embedding_levels)) +#if FRIBIDI_MAJOR_VERSION >= 1 + ret_level = fribidi_get_par_embedding_levels_ex(char_types, + bracket_types, + len, + &bidi_props->direction, + embedding_levels); +#else + ret_level = fribidi_get_par_embedding_levels(char_types, + len, + &bidi_props->direction, + embedding_levels); +#endif + if (!ret_level) { goto cleanup; } @@ -352,13 +394,19 @@ evas_bidi_paragraph_props_get(const Eina_Unicode *eina_ustr, size_t len, bidi_props->char_types = char_types; if (base_ustr) free(base_ustr); - +#if FRIBIDI_MAJOR_VERSION >= 1 + /* Currently, bracket_types is not reused in other places. */ + if (bracket_types) free(bracket_types); +#endif return bidi_props; /* Cleanup */ cleanup: if (char_types) free(char_types); +#if FRIBIDI_MAJOR_VERSION >= 1 + if (bracket_types) free(bracket_types); +#endif if (embedding_levels) free(embedding_levels); if (base_ustr) free(base_ustr); if (bidi_props) evas_bidi_paragraph_props_unref(bidi_props); /* Clean up the bidi props */ diff --git a/src/lib/evas/common/language/evas_bidi_utils.h b/src/lib/evas/common/language/evas_bidi_utils.h index dfccec8166..9b4ea68d64 100644 --- a/src/lib/evas/common/language/evas_bidi_utils.h +++ b/src/lib/evas/common/language/evas_bidi_utils.h @@ -56,6 +56,9 @@ _EVAS_BIDI_TYPEDEF(ParType); _EVAS_BIDI_TYPEDEF(StrIndex); _EVAS_BIDI_TYPEDEF(Level); _EVAS_BIDI_TYPEDEF(JoiningType); +#if FRIBIDI_MAJOR_VERSION >= 1 +_EVAS_BIDI_TYPEDEF(BracketType); +#endif typedef struct _Evas_BiDi_Paragraph_Props Evas_BiDi_Paragraph_Props; typedef struct _Evas_BiDi_Props Evas_BiDi_Props;