summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2018-04-11 13:52:07 +0200
committerKhaled Hosny <khaledhosny@eglug.org>2018-04-11 13:52:07 +0200
commit63e1fc9b23b4f0e8eaacd151ad39403eaa2b48ef (patch)
tree999cbe0dc28e7627f7e44b77ad04d18bf6a2f330
parent5d46e21df66a11233186ddf27ca8c70149307871 (diff)
downloadpango-63e1fc9b23b4f0e8eaacd151ad39403eaa2b48ef.tar.gz
Use non-deprecated libthai API when available
I’m assuming the new API is thread-safe as claimed.
-rw-r--r--configure.ac4
-rw-r--r--meson.build4
-rw-r--r--pango/break-thai.c16
3 files changed, 19 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index be20dce3..5e879a82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -487,6 +487,10 @@ have_libthai=false
PKG_CHECK_MODULES(LIBTHAI, libthai >= $LIBTHAI_REQUIRED_VERSION, have_libthai=true, :)
if $have_libthai; then
AC_DEFINE(HAVE_LIBTHAI, 1, [Whether libthai is available])
+ pango_save_libs=$LIBS
+ LIBS="$LIBS $LIBTHAI_LIBS"
+ AC_CHECK_FUNCS(th_brk_find_breaks)
+ LIBS=$pango_save_libs
fi
#
diff --git a/meson.build b/meson.build
index a00d4b06..9a5a4c72 100644
--- a/meson.build
+++ b/meson.build
@@ -216,6 +216,10 @@ thai_dep = dependency('libthai', version: libthai_req_version, required: false)
if thai_dep.found()
pango_conf.set('HAVE_LIBTHAI', 1)
pango_deps += thai_dep
+
+ if cc.has_function('th_brk_find_breaks', dependencies: thai_dep)
+ pango_conf.set('HAVE_TH_BRK_FIND_BREAKS', 1)
+ endif
endif
# These are for the various .pc files so that things will link
diff --git a/pango/break-thai.c b/pango/break-thai.c
index c9bf3e81..4a6c4278 100644
--- a/pango/break-thai.c
+++ b/pango/break-thai.c
@@ -27,12 +27,9 @@
#include <thai/thwchar.h>
#include <thai/thbrk.h>
-/* TODO
- * LibThai 0.1.23 claims to be thread-safe.
- * Check that and avoid locking?
- * http://linux.thai.net/node/286
- */
+#ifndef HAVE_TH_BRK_FIND_BREAKS
G_LOCK_DEFINE_STATIC (th_brk);
+#endif
/*
* tis_text is assumed to be large enough to hold the converted string,
@@ -67,6 +64,9 @@ break_thai (const char *text,
thchar_t *tis_text;
int *brk_pnts;
int cnt;
+#ifdef HAVE_TH_BRK_FIND_BREAKS
+ ThBrk* brk;
+#endif
cnt = pango_utf8_strlen (text, len) + 1;
@@ -82,9 +82,15 @@ break_thai (const char *text,
/* find line break positions */
+#ifdef HAVE_TH_BRK_FIND_BREAKS
+ brk = th_brk_new(NULL);
+ len = th_brk_find_breaks(brk, tis_text, brk_pnts, cnt);
+ th_brk_delete(brk);
+#else
G_LOCK (th_brk);
len = th_brk (tis_text, brk_pnts, cnt);
G_UNLOCK (th_brk);
+#endif
for (cnt = 0; cnt < len; cnt++)
if (attrs[brk_pnts[cnt]].is_char_break)
{