[gtk/pango-deprecation: 2/4] gdk: Add a copy of some deprecated pango api



commit 2350d0945a5fe185e4911dcad59d5f5ab2626853
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 31 14:03:49 2019 -0500

    gdk: Add a copy of some deprecated pango api
    
    We use pango_find_base_dir() in a few places, and
    this api has been deprecated.

 gdk/gdk-private.h  |  4 ++++
 gdk/gdk.c          | 44 ++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkinternals.h |  1 -
 3 files changed, 48 insertions(+), 1 deletion(-)
---
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__ */
diff --git a/gdk/gdk.c b/gdk/gdk.c
index d623afabf9..6954ef772e 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]