[libhandy] Add hdy-bidi



commit 12f103088308df7c9755d2ba0b33f13cbd2f6146
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Jan 26 20:58:20 2021 +0500

    Add hdy-bidi
    
    Copy a private replacement for pango_find_base_dir() from GTK4, since the
    pango function is deprecated. Add fribidi dependency for that.

 doc/meson.build        |  1 +
 src/hdy-bidi-private.h | 21 +++++++++++++++
 src/hdy-bidi.c         | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/meson.build        |  2 ++
 4 files changed, 95 insertions(+)
---
diff --git a/doc/meson.build b/doc/meson.build
index 23f0febd..dd18fca6 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -7,6 +7,7 @@ private_headers = [
     'gtkprogresstrackerprivate.h',
     'gtk-window-private.h',
     'hdy-animation-private.h',
+    'hdy-bidi-private.h',
     'hdy-carousel-box-private.h',
     'hdy-css-private.h',
     'hdy-enums.h',
diff --git a/src/hdy-bidi-private.h b/src/hdy-bidi-private.h
new file mode 100644
index 00000000..2591f303
--- /dev/null
+++ b/src/hdy-bidi-private.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#pragma once
+
+#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
+#error "Only <handy.h> can be included directly."
+#endif
+
+#include <glib.h>
+#include <pango/pango.h>
+
+G_BEGIN_DECLS
+
+PangoDirection hdy_find_base_dir (const gchar *text,
+                                  gint         length);
+
+G_END_DECLS
diff --git a/src/hdy-bidi.c b/src/hdy-bidi.c
new file mode 100644
index 00000000..5e5ae135
--- /dev/null
+++ b/src/hdy-bidi.c
@@ -0,0 +1,71 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/..
+ */
+
+/* Bits taken from GTK 4.0.2 and tweaked to be used by libhandy. */
+
+#include "hdy-bidi-private.h"
+
+#include <fribidi.h>
+
+static PangoDirection
+hdy_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
+hdy_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 = hdy_unichar_direction (wc);
+
+    if (dir != PANGO_DIRECTION_NEUTRAL)
+      break;
+
+    p = g_utf8_next_char (p);
+  }
+
+  return dir;
+}
+
diff --git a/src/meson.build b/src/meson.build
index dc164ca3..7992f72c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -122,6 +122,7 @@ src_sources = [
   'hdy-animation.c',
   'hdy-application-window.c',
   'hdy-avatar.c',
+  'hdy-bidi.c',
   'hdy-carousel.c',
   'hdy-carousel-box.c',
   'hdy-carousel-indicator-dots.c',
@@ -185,6 +186,7 @@ libhandy_deps = [
   dependency('glib-2.0', version: glib_min_version),
   dependency('gio-2.0', version: glib_min_version),
   dependency('gmodule-2.0', version: glib_min_version),
+  dependency('fribidi'),
   dependency('gtk+-3.0', version: '>= 3.24.1'),
   cc.find_library('m', required: false),
   cc.find_library('rt', required: false),


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