summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Davis <christopherdavis@gnome.org>2022-09-02 13:17:05 -0400
committerChristopher Davis <christopherdavis@gnome.org>2022-09-02 13:17:05 -0400
commit78f36e377d321f00f2132d1033dc37098d561fcd (patch)
tree4e68e45290702b4b211ee76c477f3285f03ec8c6
parente8866f035986ae29b2033bc583121c0b61c20984 (diff)
downloadgnome-font-viewer-78f36e377d321f00f2132d1033dc37098d561fcd.tar.gz
sushi-font-widget: Copy deprecated pango direction API
These APIs are still useful for us, so we want to continue to use them. Since pango intends to remove them in the future, we can simply copy them in-tree.
-rw-r--r--meson.build1
-rw-r--r--src/meson.build12
-rw-r--r--src/sushi-font-widget.c65
3 files changed, 76 insertions, 2 deletions
diff --git a/meson.build b/meson.build
index a0a88f0..8f9d254 100644
--- a/meson.build
+++ b/meson.build
@@ -34,6 +34,7 @@ harfbuzz_dep = dependency('harfbuzz', version: harfbuzz_req_version)
fontconfig_dep = dependency('fontconfig')
freetype2_dep = dependency('freetype2')
gnomedesktop_dep = dependency('gnome-desktop-4')
+fribidi_dep = dependency('fribidi')
mathlib_dep = cc.find_library('m')
if get_option('profile') == 'development'
diff --git a/src/meson.build b/src/meson.build
index 396c8b2..a6c1f4b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -31,7 +31,17 @@ executable('gnome-thumbnail-font', thumbnail_sources,
executable('gnome-font-viewer', viewer_sources + resources,
include_directories: [ root_inc, include_directories('.') ],
- dependencies: [ mathlib_dep, glib_dep, gtk_dep, libadwaita_dep, harfbuzz_dep, fontconfig_dep, freetype2_dep, gnomedesktop_dep ],
+ dependencies: [
+ mathlib_dep,
+ glib_dep,
+ gtk_dep,
+ libadwaita_dep,
+ harfbuzz_dep,
+ fontconfig_dep,
+ freetype2_dep,
+ gnomedesktop_dep,
+ fribidi_dep,
+ ],
install: true)
desktop_file = 'org.gnome.font-viewer.desktop'
diff --git a/src/sushi-font-widget.c b/src/sushi-font-widget.c
index bb6a4b3..863902b 100644
--- a/src/sushi-font-widget.c
+++ b/src/sushi-font-widget.c
@@ -30,6 +30,7 @@
#include <graphene.h>
#include <hb-glib.h>
#include <math.h>
+#include <fribidi.h>
enum {
PROP_URI = 1,
@@ -75,6 +76,68 @@ static const gchar lowercase_text_stock[] = "abcdefghijklmnopqrstuvwxyz";
static const gchar uppercase_text_stock[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const gchar punctuation_text_stock[] = "0123456789.:,;(*!?')";
+/*
+ * Copied from https://gitlab.gnome.org/GNOME/pango/-/blob/eb973b9bdfd11467f63f1626f16d5d4005eb82a7/pango/pango-bidi-type.c#L259-274
+ *
+ * This function is needed for `fonts_find_base_dir()`, but Pango
+ * has deprecated this function and scheduled it for removal.
+ *
+ * (C) 2004 Red Hat, Owen Taylor <otaylor@redhat.com>
+ *
+ * License: LGPL-2.0-or-later
+ */
+static PangoDirection
+fonts_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;
+}
+
+/*
+ * Copied from https://gitlab.gnome.org/GNOME/pango/-/blob/eb973b9bdfd11467f63f1626f16d5d4005eb82a7/pango/pango-utils.c#L866-889
+ *
+ * This function is needed for our `text_to_glyphs ()` function, but Pango
+ * has deprecated this function and scheduled it for removal.
+ *
+ * (C) 2004 Red Hat, Owen Taylor <otaylor@redhat.com>
+ *
+ * License: LGPL-2.0-or-later
+ */
+static PangoDirection
+fonts_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, dir);
+
+ p = text;
+ while ((length < 0 || p < text + length) && *p)
+ {
+ gunichar wc = g_utf8_get_char (p);
+
+ dir = fonts_unichar_direction (wc);
+
+ if (dir != PANGO_DIRECTION_NEUTRAL)
+ break;
+
+ p = g_utf8_next_char (p);
+ }
+
+ return dir;
+}
+
static void
text_to_glyphs (cairo_t *cr,
const gchar *text,
@@ -96,7 +159,7 @@ text_to_glyphs (cairo_t *cr,
*num_glyphs = 0;
*glyphs = NULL;
- base_dir = pango_find_base_dir (text, -1);
+ base_dir = fonts_find_base_dir (text, -1);
cairo_scaled_font_t *cr_font = cairo_get_scaled_font (cr);
ft_face = cairo_ft_scaled_font_lock_face (cr_font);