[pango/wip/khaled/fribidi: 2/5] Switch to using external FriBiDi



commit 508e722ff4532e5677775e77e76cdc0922fad58e
Author: Khaled Hosny <khaledhosny eglug org>
Date:   Mon Nov 13 15:25:35 2017 +0200

    Switch to using external FriBiDi

 configure.ac            |    4 +++
 meson.build             |    6 ++++-
 pango/Makefile.am       |   14 +++--------
 pango/meson.build       |    4 +--
 pango/pango-bidi-type.c |   54 +++++++++++++++++++++++++++++++++-------------
 5 files changed, 53 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6255531..c02c69d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -456,6 +456,10 @@ PKG_CHECK_MODULES(GLIB, $GLIB_MODULES, :,
 GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
 AC_SUBST(GLIB_MKENUMS)
 
+# Checks for FriBiDi
+FRIBIDI_REQUIRED_VERSION=0.19.7
+PKG_CHECK_MODULES(FRIBIDI, fribidi >= $FRIBIDI_REQUIRED_VERSION)
+
 #
 # Checks for LibThai
 #
diff --git a/meson.build b/meson.build
index ea7f5ff..d450731 100644
--- a/meson.build
+++ b/meson.build
@@ -97,7 +97,7 @@ elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
     '-Werror=pointer-to-int-cast',
     '-Werror=empty-body',
     '-Werror=write-strings',
-    '-Werror=undef',
+#   '-Werror=undef', # breaks in fribidi headers
   ]
 
   if host_system == 'windows'
@@ -194,6 +194,7 @@ endif
 pango_deps = []
 
 glib_req_version = '>= 2.33.12'
+fribidi_req_version = '>= 0.19.7'
 libthai_req_version = '>= 0.1.9'
 harfbuzz_req_version = '>= 1.2.3'
 fontconfig_req_version = '>= 2.10.91'
@@ -208,6 +209,9 @@ pango_deps += mathlib_dep
 gobject_dep = dependency('gobject-2.0', version: glib_req_version)
 pango_deps += gobject_dep
 
+fribidi_dep = dependency('fribidi', version: fribidi_req_version)
+pango_deps += fribidi_dep
+
 thai_dep = dependency('libthai', version: libthai_req_version, required: false)
 if thai_dep.found()
   pango_conf.set('HAVE_LIBTHAI', 1)
diff --git a/pango/Makefile.am b/pango/Makefile.am
index ac88915..0ce8435 100644
--- a/pango/Makefile.am
+++ b/pango/Makefile.am
@@ -11,7 +11,7 @@ INTROSPECTION_SCANNER_ARGS = --warn-all --add-include-path=$(srcdir) --add-inclu
 INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) --includedir=.
 INTROSPECTION_SCANNER_ENV = CC="$(CC)"
 
-SUBDIRS = mini-fribidi
+SUBDIRS =
 
 INCLUDES =                                             \
        -DG_LOG_DOMAIN=\"Pango\"                        \
@@ -29,6 +29,7 @@ INCLUDES =                                            \
        $(HARFBUZZ_CFLAGS)                              \
        $(FREETYPE_CFLAGS)                              \
        $(FONTCONFIG_CFLAGS)                            \
+       $(FRIBIDI_CFLAGS)                               \
        $(LIBTHAI_CFLAGS)                                       \
        $(X_CFLAGS)                                     \
        $(PANGO_HIDDEN_VISIBILITY_CFLAGS)
@@ -51,10 +52,9 @@ libpango_1_0_la_LDFLAGS = $(LIBRARY_LIBTOOL_OPTIONS)
 libpango_1_0_la_LIBADD =               \
        $(GLIB_LIBS)                    \
        $(LIBTHAI_LIBS)                 \
+       $(FRIBIDI_LIBS)                 \
        $(libm)
-
-libpango_1_0_la_LIBADD += mini-fribidi/libmini-fribidi.la
-libpango_1_0_la_DEPENDENCIES = mini-fribidi/libmini-fribidi.la
+libpango_1_0_la_DEPENDENCIES =
 
 if PLATFORM_WIN32
 libpango_1_0_la_LDFLAGS += -Wl,pango-win32-res.o
@@ -460,15 +460,9 @@ DISTCLEANFILES =           \
 
 # ------------------- MSVC Build Items ----------------
 
-extra_fribidi_srcs_for_msvc =  \
-       mini-fribidi/fribidi.c                  \
-       mini-fribidi/fribidi_char_type.c        \
-       mini-fribidi/fribidi_types.c
-
 MSVCPROJS = pango pangowin32 pangoft2 pangocairo
 
 pango_FILES =  \
-       $(extra_fribidi_srcs_for_msvc)  \
        $(libpango_1_0_la_SOURCES)
 pango_EXCLUDES = dummy
 pango_HEADERS_DIR = $(pangoincludedir)
diff --git a/pango/meson.build b/pango/meson.build
index 9c6fbec..6301410 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -1,5 +1,3 @@
-subdir('mini-fribidi')
-
 pango_sources = [
   'break.c',
   'ellipsize.c',
@@ -109,7 +107,7 @@ libpango = shared_library('pango-@0@'.format(pango_api_version),
                           version: pango_libversion,
                           soversion: pango_soversion,
                           install: true,
-                          dependencies: [ gobject_dep, mathlib_dep, thai_dep, mini_fribidi_dep ],
+                          dependencies: [ gobject_dep, mathlib_dep, thai_dep, fribidi_dep ],
                           include_directories: [ root_inc, pango_inc ],
                           c_args: common_cflags + pango_debug_cflags + pango_cflags,
                           link_args: common_ldflags)
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c
index 462e7b0..b363ca8 100644
--- a/pango/pango-bidi-type.c
+++ b/pango/pango-bidi-type.c
@@ -41,12 +41,11 @@
 
 #include <string.h>
 
+#include <fribidi.h>
+
 #include "pango-bidi-type.h"
 #include "pango-utils.h"
 
-#include "mini-fribidi/fribidi.h"
-
-
 
 /**
  * pango_bidi_type_for_unichar:
@@ -66,7 +65,11 @@
 PangoBidiType
 pango_bidi_type_for_unichar (gunichar ch)
 {
-  FriBidiCharType fribidi_ch_type = fribidi_get_type (ch);
+  FriBidiCharType fribidi_ch_type;
+
+  G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar));
+
+  fribidi_ch_type = fribidi_get_bidi_type (ch);
 
   switch (fribidi_ch_type)
     {
@@ -122,26 +125,29 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
                                    int             length,
                                    PangoDirection *pbase_dir)
 {
-  FriBidiCharType fribidi_base_dir;
+  FriBidiParType fribidi_base_dir;
   guint8 *embedding_levels_list;
 
+  G_STATIC_ASSERT (sizeof (FriBidiLevel) == sizeof (guint8));
+  G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar));
+
   switch (*pbase_dir)
     {
     case PANGO_DIRECTION_LTR:
     case PANGO_DIRECTION_TTB_RTL:
-      fribidi_base_dir = FRIBIDI_TYPE_L;
+      fribidi_base_dir = FRIBIDI_PAR_LTR;
       break;
     case PANGO_DIRECTION_RTL:
     case PANGO_DIRECTION_TTB_LTR:
-      fribidi_base_dir = FRIBIDI_TYPE_R;
+      fribidi_base_dir = FRIBIDI_PAR_RTL;
       break;
     case PANGO_DIRECTION_WEAK_RTL:
-      fribidi_base_dir = FRIBIDI_TYPE_WR;
+      fribidi_base_dir = FRIBIDI_PAR_WRTL;
       break;
     case PANGO_DIRECTION_WEAK_LTR:
     case PANGO_DIRECTION_NEUTRAL:
     default:
-      fribidi_base_dir = FRIBIDI_TYPE_WL;
+      fribidi_base_dir = FRIBIDI_PAR_WLTR;
       break;
     }
 
@@ -154,17 +160,31 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
 #else
   {
     gunichar *text_ucs4;
-    int n_chars;
+    glong n_chars;
+    FriBidiCharType *bidi_types;
+    FriBidiLevel max_level;
+
     text_ucs4 = g_utf8_to_ucs4_fast (text, length, &n_chars);
+    bidi_types = g_new (FriBidiCharType, n_chars);
     embedding_levels_list = g_new (guint8, n_chars);
-    fribidi_log2vis_get_embedding_levels ((FriBidiChar*)text_ucs4, n_chars,
-                                         &fribidi_base_dir,
-                                         (FriBidiLevel*)embedding_levels_list);
+
+    fribidi_get_bidi_types (text_ucs4, n_chars, bidi_types);
+    max_level = fribidi_get_par_embedding_levels (bidi_types, n_chars,
+                                                 &fribidi_base_dir,
+                                                 (FriBidiLevel*)embedding_levels_list);
+    if (G_UNLIKELY(max_level == 0))
+      {
+        /* fribidi_get_par_embedding_levels() failed,
+         * is this the best thing to do? */
+        memset (embedding_levels_list, 0, length);
+      }
+
     g_free (text_ucs4);
+    g_free (bidi_types);
   }
 #endif
 
-  *pbase_dir = (fribidi_base_dir == FRIBIDI_TYPE_L) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
+  *pbase_dir = (fribidi_base_dir == FRIBIDI_PAR_LTR) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
 
   return embedding_levels_list;
 }
@@ -187,7 +207,11 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
 PangoDirection
 pango_unichar_direction (gunichar ch)
 {
-  FriBidiCharType fribidi_ch_type = fribidi_get_type (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;


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