[balsa/wip/gtk4] Pango deprecated bidi apis



commit 17fef5a0dc8b0038d3181eca0f20ed389f797f92
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Nov 24 15:54:48 2018 -0500

    Pango deprecated bidi apis
    
    https://gitlab.gnome.org/GNOME/pango/commit/b7b0f74b98b1279a86efe05e6b21f2c2f7fc0d14
    "We agreed that people should just use fribidi for this
    information."
    
    * configure.ac, meson.build: add fribidi dependency
    * libbalsa/mime.c: use it

 configure.ac    |  1 +
 libbalsa/mime.c | 42 ++++++++++++++++++++++++++++++++----------
 meson.build     |  4 +++-
 3 files changed, 36 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4752af9ce..7ac60a70e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,6 +235,7 @@ gmime-2.6
 gio-2.0
 gthread-2.0
 gnutls
+fribidi
 ])
 
 PKG_CHECK_MODULES(BALSA_AB, [
diff --git a/libbalsa/mime.c b/libbalsa/mime.c
index f7ef62b13..83f36a084 100644
--- a/libbalsa/mime.c
+++ b/libbalsa/mime.c
@@ -24,6 +24,7 @@
 
 #include <string.h>
 #include <ctype.h>
+#include <fribidi/fribidi.h>
 
 #include "libbalsa.h"
 #include "misc.h"
@@ -1203,6 +1204,35 @@ libbalsa_html_encode_hyperlinks(GString * paragraph)
     return retval;
 }
 
+static gboolean
+text_is_rtl(const gchar *text)
+{
+    FriBidiChar *str;
+    FriBidiStrIndex len;
+    FriBidiStrIndex i;
+    FriBidiCharType *bidi_types;
+    gboolean is_rtl;
+
+    if (!g_utf8_validate(text, -1, NULL))
+        return FALSE;
+
+    len = g_utf8_strlen(text, -1);
+    str = g_new(FriBidiChar, len);
+
+    for (i = 0; i < len; i++) {
+        str[i] = g_utf8_get_char(text);
+        text = g_utf8_next_char(text);
+    }
+
+    bidi_types = g_new(FriBidiCharType, len);
+    fribidi_get_bidi_types(str, len, bidi_types);
+    g_free(str);
+
+    is_rtl = FRIBIDI_IS_RTL(fribidi_get_par_direction(bidi_types, len));
+    g_free(bidi_types);
+
+    return is_rtl;
+}
 
 gchar *
 libbalsa_text_to_html(const gchar * title, const gchar * body, const gchar * lang)
@@ -1235,22 +1265,14 @@ libbalsa_text_to_html(const gchar * title, const gchar * body, const gchar * lan
     g_free(html_lang);
 
     /* add the lines of the message body */
-    while (*start) {
+    while (*start != '\0') {
         const gchar * eol = strchr(start, '\n');
-        const gchar * p = start;
-        PangoDirection direction = PANGO_DIRECTION_NEUTRAL;
         GString * html;
         gsize idx;
 
         if (!eol)
             eol = start + strlen(start);
 
-        /* find the first real char to determine the paragraph direction */
-        while (p < eol && direction == PANGO_DIRECTION_NEUTRAL) {
-            direction = pango_unichar_direction(g_utf8_get_char(p));
-            p = g_utf8_next_char(p);
-        }
-
         /* html escape the line */
         html = g_string_new_len(start, eol - start);
 
@@ -1270,7 +1292,7 @@ libbalsa_text_to_html(const gchar * title, const gchar * body, const gchar * lan
 
         /* append the paragraph, always stating the proper direction */
         g_string_append_printf(html_body, "<p dir=\"%s\">%s</p>\n",
-                               direction == PANGO_DIRECTION_RTL ? "rtl" : "ltr",
+                               text_is_rtl(start) ? "rtl" : "ltr",
                                *html->str ? html->str : "&nbsp;");
         g_string_free(html, TRUE);
 
diff --git a/meson.build b/meson.build
index 8c4f7091d..1b120fc65 100644
--- a/meson.build
+++ b/meson.build
@@ -133,6 +133,7 @@ gmime_dep   = dependency('gmime-2.6')
 gio_dep     = dependency('gio-2.0')
 gthread_dep = dependency('gthread-2.0')
 gnutls_dep  = dependency('gnutls')
+fribidi_dep = dependency('fribidi')
 
 # Dependencies for balsa
 balsa_deps = [glib_dep,
@@ -140,7 +141,8 @@ balsa_deps = [glib_dep,
               gmime_dep,
               gio_dep,
               gthread_dep,
-              gnutls_dep]
+              gnutls_dep,
+              fribidi_dep]
 
 # Dependencies for balsa_ab:
 balsa_ab_deps = [glib_dep,


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