diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2017-11-14 15:12:23 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2018-02-04 02:46:36 +0200 |
commit | 526c9b586a32ebee2e269ecd41652b215cd21274 (patch) | |
tree | 72ee209d07c577b917217826a2a4ede6701711eb | |
parent | 0a71013dfc3a5199f0632bb99410523949bf49d7 (diff) | |
download | pango-526c9b586a32ebee2e269ecd41652b215cd21274.tar.gz |
Avoid converting to UTF-32 for FriBiDi
Can’t tell if this is any faster, but does not look like a complex
thing to do, so why not.
-rw-r--r-- | pango/pango-bidi-type.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c index b363ca89..6eb9eb51 100644 --- a/pango/pango-bidi-type.c +++ b/pango/pango-bidi-type.c @@ -125,8 +125,12 @@ pango_log2vis_get_embedding_levels (const gchar *text, int length, PangoDirection *pbase_dir) { - FriBidiParType fribidi_base_dir; + glong n_chars, i; guint8 *embedding_levels_list; + const gchar *p; + FriBidiParType fribidi_base_dir; + FriBidiCharType *bidi_types; + FriBidiLevel max_level; G_STATIC_ASSERT (sizeof (FriBidiLevel) == sizeof (guint8)); G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar)); @@ -151,38 +155,32 @@ pango_log2vis_get_embedding_levels (const gchar *text, break; } -#ifdef FRIBIDI_HAVE_UTF8 - { - if (length < 0) - length = strlen (text); - embedding_levels_list = (guint8 *) fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, &fribidi_base_dir); - } -#else - { - gunichar *text_ucs4; - glong n_chars; - FriBidiCharType *bidi_types; - FriBidiLevel max_level; - - text_ucs4 = g_utf8_to_ucs4_fast (text, length, &n_chars); - bidi_types = g_new (FriBidiCharType, n_chars); - embedding_levels_list = g_new (guint8, n_chars); - - fribidi_get_bidi_types (text_ucs4, n_chars, bidi_types); - max_level = fribidi_get_par_embedding_levels (bidi_types, n_chars, - &fribidi_base_dir, - (FriBidiLevel*)embedding_levels_list); - if (G_UNLIKELY(max_level == 0)) - { - /* fribidi_get_par_embedding_levels() failed, - * is this the best thing to do? */ - memset (embedding_levels_list, 0, length); - } - - g_free (text_ucs4); - g_free (bidi_types); - } -#endif + if (length < 0) + length = strlen (text); + + n_chars = g_utf8_strlen (text, length); + + bidi_types = g_new (FriBidiCharType, n_chars); + embedding_levels_list = g_new (guint8, n_chars); + + for (i = 0, p = text; p < text + length; p = g_utf8_next_char(p), i++) + { + gunichar ch = g_utf8_get_char (p); + bidi_types[i] = fribidi_get_bidi_type (ch); + } + + max_level = fribidi_get_par_embedding_levels (bidi_types, n_chars, + &fribidi_base_dir, + (FriBidiLevel*)embedding_levels_list); + + g_free (bidi_types); + + if (G_UNLIKELY(max_level == 0)) + { + /* fribidi_get_par_embedding_levels() failed, + * is this the best thing to do? */ + memset (embedding_levels_list, 0, length); + } *pbase_dir = (fribidi_base_dir == FRIBIDI_PAR_LTR) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; |