diff options
-rw-r--r-- | gdk/gdk-private.h | 4 | ||||
-rw-r--r-- | gdk/gdk.c | 44 | ||||
-rw-r--r-- | gdk/gdkinternals.h | 1 |
3 files changed, 48 insertions, 1 deletions
diff --git a/gdk/gdk-private.h b/gdk/gdk-private.h index 0c83002bfc..551ecac9aa 100644 --- a/gdk/gdk-private.h +++ b/gdk/gdk-private.h @@ -36,4 +36,8 @@ gboolean gdk_should_use_portal (void); const gchar * gdk_get_startup_notification_id (void); +PangoDirection gdk_unichar_direction (gunichar ch); +PangoDirection gdk_find_base_dir (const char *text, + int len); + #endif /* __GDK__PRIVATE_H__ */ @@ -40,6 +40,8 @@ #include <string.h> #include <stdlib.h> +#include <fribidi.h> + /** * SECTION:general @@ -343,3 +345,45 @@ gdk_should_use_portal (void) * management for you. */ +PangoDirection +gdk_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 +gdk_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 = gdk_unichar_direction (wc); + + if (dir != PANGO_DIRECTION_NEUTRAL) + break; + + p = g_utf8_next_char (p); + } + + return dir; +} + diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index f64f38dd4b..a8c4bb6176 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -351,7 +351,6 @@ void gdk_synthesize_surface_state (GdkSurface *surface, GdkSurfaceState unset_flags, GdkSurfaceState set_flags); - G_END_DECLS #endif /* __GDK_INTERNALS_H__ */ |