diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h index a5cd1fa19..d4706808e 100644 --- a/clutter/clutter/clutter-private.h +++ b/clutter/clutter/clutter-private.h @@ -303,6 +303,11 @@ gboolean _clutter_util_matrix_decompose (const ClutterMatrix *src, ClutterVertex *translate_p, ClutterVertex4 *perspective_p); +PangoDirection _clutter_pango_unichar_direction (gunichar ch); + +PangoDirection _clutter_pango_find_base_dir (const gchar *text, + gint length); + typedef struct _ClutterPlane { float v0[3]; diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index fb9d926df..9222cedfc 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -751,7 +751,7 @@ clutter_text_create_layout_no_cache (ClutterText *text, if (priv->password_char != 0) pango_dir = PANGO_DIRECTION_NEUTRAL; else - pango_dir = pango_find_base_dir (contents, contents_len); + pango_dir = _clutter_pango_find_base_dir (contents, contents_len); if (pango_dir == PANGO_DIRECTION_NEUTRAL) { diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c index ed52b6977..05d5d0e4c 100644 --- a/clutter/clutter/clutter-util.c +++ b/clutter/clutter/clutter-util.c @@ -32,6 +32,7 @@ #include "clutter-build-config.h" +#include #include #include "clutter-debug.h" @@ -696,3 +697,45 @@ clutter_interval_register_progress_func (GType value_type, G_UNLOCK (progress_funcs); } + +PangoDirection +_clutter_pango_unichar_direction (gunichar ch) +{ + FriBidiCharType fribidi_ch_type; + + G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar)); + + fribidi_ch_type = fribidi_get_bidi_type (ch); + + if (!FRIBIDI_IS_STRONG (fribidi_ch_type)) + return PANGO_DIRECTION_NEUTRAL; + else if (FRIBIDI_IS_RTL (fribidi_ch_type)) + return PANGO_DIRECTION_RTL; + else + return PANGO_DIRECTION_LTR; +} + +PangoDirection +_clutter_pango_find_base_dir (const gchar *text, + gint length) +{ + PangoDirection dir = PANGO_DIRECTION_NEUTRAL; + const gchar *p; + + g_return_val_if_fail (text != NULL || length == 0, PANGO_DIRECTION_NEUTRAL); + + p = text; + while ((length < 0 || p < text + length) && *p) + { + gunichar wc = g_utf8_get_char (p); + + dir = _clutter_pango_unichar_direction (wc); + + if (dir != PANGO_DIRECTION_NEUTRAL) + break; + + p = g_utf8_next_char (p); + } + + return dir; +} diff --git a/clutter/clutter/x11/clutter-keymap-x11.c b/clutter/clutter/x11/clutter-keymap-x11.c index f0c57d2cd..b92ba70bc 100644 --- a/clutter/clutter/x11/clutter-keymap-x11.c +++ b/clutter/clutter/x11/clutter-keymap-x11.c @@ -250,7 +250,8 @@ get_direction (XkbDescPtr xkb, { int level = 0; KeySym sym = XkbKeySymEntry (xkb, code, level, group); - PangoDirection dir = pango_unichar_direction (clutter_keysym_to_unicode (sym)); + PangoDirection dir = + _clutter_pango_unichar_direction (clutter_keysym_to_unicode (sym)); switch (dir) { diff --git a/clutter/meson.build b/clutter/meson.build index 0db934209..ab34c74c4 100644 --- a/clutter/meson.build +++ b/clutter/meson.build @@ -38,6 +38,7 @@ clutter_pkg_deps = [ ] clutter_pkg_private_deps = [ + fribidi_dep, gdk_pixbuf_dep, gthread_dep, gmodule_no_export_dep, diff --git a/meson.build b/meson.build index 01e843d41..9d600377f 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ mutter_plugin_api_version = '3' libmutter_api_version = '4' # generic version requirements +fribidi_req = '>= 1.0.0' glib_req = '>= 2.53.2' gi_req = '>= 0.9.5' gtk3_req = '>= 3.19.8' @@ -86,6 +87,7 @@ pango_dep = dependency('pango', version: pango_req) cairo_dep = dependency('cairo', version: cairo_req) cairo_gobject_dep = dependency('cairo-gobject', version: cairo_req) pangocairo_dep = dependency('pangocairo', version: pangocairo_req) +fribidi_dep = dependency('fribidi', version: fribidi_req) gsettings_desktop_schemas_dep = dependency('gsettings-desktop-schemas', version: gsettings_desktop_schemas_req) glib_dep = dependency('glib-2.0', version: glib_req)