summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-11-27 22:03:30 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-11-27 22:03:30 +0000
commit93d18a9135830d74bec50f04ca1723cb68c4ff1d (patch)
treee3c90745ee362565eda1c2a9503038e3a9990d5d
parent7d36abc19331579d1a9d0df8b2c41a9bf57dd669 (diff)
downloadpango-93d18a9135830d74bec50f04ca1723cb68c4ff1d.tar.gz
Bug 371388 – Add Thai langauage engine Patch from Theppitak
2006-11-27 Behdad Esfahbod <behdad@gnome.org> Bug 371388 – Add Thai langauage engine Patch from Theppitak Karoonboonyanan * configure.in: Look for libthai and enable thai-lang module. * modules/thai/Makefile.am: Hook thai-lang module. * modules/thai/thai-lang.c: New Thai language engine that uses libthai to do dictionary-based Thai line-breaking. * examples/test-thai.txt: Improved.
-rw-r--r--ChangeLog13
-rw-r--r--configure.in12
-rw-r--r--examples/test-thai.txt4
-rw-r--r--modules/thai/Makefile.am22
-rw-r--r--modules/thai/thai-lang.c139
5 files changed, 186 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 24649ac4..883e8acc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-11-27 Behdad Esfahbod <behdad@gnome.org>
+
+ Bug 371388 – Add Thai langauage engine
+ Patch from Theppitak Karoonboonyanan
+
+ * configure.in: Look for libthai and enable thai-lang module.
+ * modules/thai/Makefile.am: Hook thai-lang module.
+
+ * modules/thai/thai-lang.c: New Thai language engine that uses libthai
+ to do dictionary-based Thai line-breaking.
+
+ * examples/test-thai.txt: Improved.
+
2006-11-25 Behdad Esfahbod <behdad@gnome.org>
* pango/pangocairo-render.c (acquire_renderer), (release_renderer),
diff --git a/configure.in b/configure.in
index 1919c1d5..8af8586b 100644
--- a/configure.in
+++ b/configure.in
@@ -390,6 +390,12 @@ if test "x$GLIB_VERSION_MAJOR_MINOR" = "x$GLIB_REQUIRED_VERSION_MAJOR_MINOR"; th
GLIB_CFLAGS="-DG_DISABLE_DEPRECATED $GLIB_CFLAGS"
fi
+#
+# Checks for LibThai
+#
+have_libthai=false
+LIBTHAI_REQUIRED_VERSION=0.1.3
+PKG_CHECK_MODULES(LIBTHAI, libthai >= $LIBTHAI_REQUIRED_VERSION, have_libthai=true, :)
#
# Modules to build
@@ -404,6 +410,10 @@ syriac_modules="syriac-fc"
thai_modules="thai-fc"
tibetan_modules="tibetan-fc"
+if $have_libthai ; then
+ thai_modules="$thai_modules,thai-lang"
+fi
+
all_modules="$arabic_modules,$basic_modules,$hangul_modules,$hebrew_modules,$indic_modules,$khmer_modules,$syriac_modules,$thai_modules,$tibetan_modules"
#
@@ -487,6 +497,7 @@ AM_CONDITIONAL(INCLUDE_INDIC_LANG, echo $included_modules | egrep '(^|,)indic-la
AM_CONDITIONAL(INCLUDE_KHMER_FC, echo $included_modules | egrep '(^|,)khmer-fc($|,)' > /dev/null)
AM_CONDITIONAL(INCLUDE_SYRIAC_FC, echo $included_modules | egrep '(^|,)syriac-fc($|,)' > /dev/null)
AM_CONDITIONAL(INCLUDE_THAI_FC, echo $included_modules | egrep '(^|,)thai-fc($|,)' > /dev/null)
+AM_CONDITIONAL(INCLUDE_THAI_LANG, echo $included_modules | egrep '(^|,)thai-lang($|,)' > /dev/null)
AM_CONDITIONAL(INCLUDE_TIBETAN_FC, echo $included_modules | egrep '(^|,)tibetan-fc($|,)' > /dev/null)
AM_CONDITIONAL(DYNAMIC_ARABIC_FC, echo $dynamic_modules | egrep '(^|,)arabic-fc($|,)' > /dev/null)
@@ -502,6 +513,7 @@ AM_CONDITIONAL(DYNAMIC_INDIC_LANG, echo $dynamic_modules | egrep '(^|,)indic-lan
AM_CONDITIONAL(DYNAMIC_KHMER_FC, echo $dynamic_modules | egrep '(^|,)khmer-fc($|,)' > /dev/null)
AM_CONDITIONAL(DYNAMIC_SYRIAC_FC, echo $dynamic_modules | egrep '(^|,)syriac-fc($|,)' > /dev/null)
AM_CONDITIONAL(DYNAMIC_THAI_FC, echo $dynamic_modules | egrep '(^|,)thai-fc($|,)' > /dev/null)
+AM_CONDITIONAL(DYNAMIC_THAI_LANG, echo $dynamic_modules | egrep '(^|,)thai-lang($|,)' > /dev/null)
AM_CONDITIONAL(DYNAMIC_TIBETAN_FC, echo $dynamic_modules | egrep '(^|,)tibetan-fc($|,)' > /dev/null)
#
diff --git a/examples/test-thai.txt b/examples/test-thai.txt
index 74023406..4bb8d2e0 100644
--- a/examples/test-thai.txt
+++ b/examples/test-thai.txt
@@ -1,10 +1,10 @@
ลำดับนั้น เทวดากล่าวคาถากะพระมหาสัตว์ว่า:
-"การงานอันใด ยังไม่ถึงที่สุดด้วยความพยายาม การงานอันนั้นก็ไร้ผล มีความลำบากเกิดขึ้น การทำความพยายามในฐานะอันไม่สมควรใด จนความตายปรากฏขึ้น ความพยายามในฐานะอันไม่สมควรนั้น จะมีประโยชน์อะไร"
+“การงานอันใด ยังไม่ถึงที่สุดด้วยความพยายาม การงานอันนั้นก็ไร้ผล มีความลำบากเกิดขึ้น การทำความพยายามในฐานะอันไม่สมควรใด จนความตายปรากฏขึ้น ความพยายามในฐานะอันไม่สมควรนั้น จะมีประโยชน์อะไร”
เมื่อนางมณีเมขลากล่าวอย่างนี้แล้ว พระมหาสัตว์เมื่อจะทำนางมณีเมขลาให้จำนนต่อถ้อยคำ จึงได้ตรัสคาถาต่อไปว่า:
-"ดูก่อนเทวดา ผู้ใดรู้แจ้งการงานที่ทำจะไม่ลุล่วงไปได้จริง ๆ ชื่อว่าไม่รักษาชีวิตของตน ถ้าผู้นั้นละความเพียรในฐานะเช่นนั้นเสีย ก็จะพึงรู้ผลแห่งความเกียจคร้าน ดูก่อนเทวดา คนบางพวกในโลกนี้เห็นผลแห่งความประสงค์ของตน จึงประกอบการงานทั้งหลาย การงานเหล่านั้นจะสำเร็จหรือไม่ก็ตาม ดูก่อนเทวดา ท่านก็เห็นผลแห่งกรรมประจักษ์แก่ตนแล้วมิใช่หรือ คนอื่น ๆ จมในมหาสมุทรหมด เราคนเดียวยังว่ายข้ามอยู่ และได้เห็น ท่าน มาสถิตอยู่ใกล้ ๆ เรา เรานั้นจักพยายามตามสติกำลัง จักทำความเพียรที่บุรุษควรทำ ไปให้ถึงฝั่งแห่งมหาสมุทร"
+“ดูก่อนเทวดา ผู้ใดรู้แจ้งการงานที่ทำจะไม่ลุล่วงไปได้จริง ๆ ชื่อว่าไม่รักษาชีวิตของตน ถ้าผู้นั้นละความเพียรในฐานะเช่นนั้นเสีย ก็จะพึงรู้ผลแห่งความเกียจคร้าน ดูก่อนเทวดา คนบางพวกในโลกนี้เห็นผลแห่งความประสงค์ของตน จึงประกอบการงานทั้งหลาย การงานเหล่านั้นจะสำเร็จหรือไม่ก็ตาม ดูก่อนเทวดา ท่านก็เห็นผลแห่งกรรมประจักษ์แก่ตนแล้วมิใช่หรือ คนอื่น ๆ จมในมหาสมุทรหมด เราคนเดียวยังว่ายข้ามอยู่ และได้เห็น ท่าน มาสถิตอยู่ใกล้ ๆ เรา เรานั้นจักพยายามตามสติกำลัง จักทำความเพียรที่บุรุษควรทำ ไปให้ถึงฝั่งแห่งมหาสมุทร”
--
พระมหาชนก
diff --git a/modules/thai/Makefile.am b/modules/thai/Makefile.am
index 1b401357..40f2315c 100644
--- a/modules/thai/Makefile.am
+++ b/modules/thai/Makefile.am
@@ -1,6 +1,6 @@
include $(top_srcdir)/modules/Module.mk
-common_sources = thai-charprop.c thai-charprop.h thai-shaper.c thai-shaper.h
+shaper_sources = thai-charprop.c thai-charprop.h thai-shaper.c thai-shaper.h
if HAVE_FREETYPE
INCLUDES += $(FREETYPE_CFLAGS)
@@ -13,10 +13,28 @@ endif
endif
endif
-thai_fc_sources = $(common_sources) thai-fc.c thai-ot.c thai-ot.h
+thai_fc_sources = $(shaper_sources) thai-fc.c thai-ot.c thai-ot.h
pango_thai_fc_la_LDFLAGS = -module $(MODULE_LIBTOOL_OPTIONS)
pango_thai_fc_la_LIBADD = $(pangoft2libs)
pango_thai_fc_la_SOURCES = $(thai_fc_sources)
libpango_thai_fc_la_SOURCES = $(thai_fc_sources)
libpango_thai_fc_la_CFLAGS = -DPANGO_MODULE_PREFIX=_pango_thai_fc
+
+
+if INCLUDE_THAI_LANG
+noinst_LTLIBRARIES += libpango-thai-lang.la
+else
+if DYNAMIC_THAI_LANG
+module_LTLIBRARIES += pango-thai-lang.la
+endif
+endif
+
+lang_sources = \
+ thai-lang.c
+
+pango_thai_lang_la_LDFLAGS = -module $(MODULE_LIBTOOL_OPTIONS)
+pango_thai_lang_la_LIBADD = $(pangolibs) $(LIBTHAI_LIBS)
+pango_thai_lang_la_SOURCES = $(lang_sources)
+libpango_thai_lang_la_SOURCES = $(lang_sources)
+libpango_thai_lang_la_CFLAGS = -DPANGO_MODULE_PREFIX=_pango_thai_lang $(LIBTHAI_CFLAGS)
diff --git a/modules/thai/thai-lang.c b/modules/thai/thai-lang.c
new file mode 100644
index 00000000..37c1a2c8
--- /dev/null
+++ b/modules/thai/thai-lang.c
@@ -0,0 +1,139 @@
+/* Pango
+ * thai-lang.c:
+ *
+ * Copyright (C) 2003 Theppitak Karoonboonyanan <thep@linux.thai.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include <string.h>
+#include <glib.h>
+#include <pango/pango-engine.h>
+#include <pango/pango-break.h>
+#include <thai/thwchar.h>
+#include <thai/thbrk.h>
+
+/* No extra fields needed */
+typedef PangoEngineLang ThaiEngineLang;
+typedef PangoEngineLangClass ThaiEngineLangClass;
+
+#define SCRIPT_ENGINE_NAME "ThaiScriptEngineLang"
+
+static PangoEngineScriptInfo thai_scripts[] = {
+ { PANGO_SCRIPT_THAI, "*" }
+};
+
+static PangoEngineInfo script_engines[] = {
+ {
+ SCRIPT_ENGINE_NAME,
+ PANGO_ENGINE_TYPE_LANG,
+ PANGO_RENDER_TYPE_NONE,
+ thai_scripts, G_N_ELEMENTS(thai_scripts)
+ }
+};
+
+static thchar_t *
+utf8_to_tis (const char *text, int len)
+{
+ thchar_t *tis_text;
+ thchar_t *tis_p;
+ const char *text_p;
+
+ if (len < 0)
+ len = strlen (text);
+
+ tis_text = g_new (thchar_t, g_utf8_strlen (text, len) + 1);
+ if (!tis_text)
+ return NULL;
+
+ tis_p = tis_text;
+ for (text_p = text; text_p < text + len; text_p = g_utf8_next_char (text_p))
+ *tis_p++ = th_uni2tis (g_utf8_get_char (text_p));
+ *tis_p = '\0';
+
+ return tis_text;
+}
+
+static void
+thai_engine_break (PangoEngineLang *engine,
+ const char *text,
+ int len,
+ PangoAnalysis *analysis,
+ PangoLogAttr *attrs,
+ int attrs_len)
+{
+ thchar_t *tis_text;
+
+ tis_text = utf8_to_tis (text, len);
+ if (tis_text)
+ {
+ int brk_len = strlen ((const char*)tis_text) + 1;
+ int *brk_pnts = g_new (int, brk_len);
+ int brk_n;
+ int i;
+
+ /* find line break positions */
+ brk_n = th_brk (tis_text, brk_pnts, brk_len);
+ for (i = 0; i < brk_n; i++)
+ {
+ attrs[brk_pnts[i]].is_line_break = TRUE;
+ attrs[brk_pnts[i]].is_word_start = TRUE;
+ attrs[brk_pnts[i]].is_word_end = TRUE;
+ }
+
+ g_free (brk_pnts);
+ g_free (tis_text);
+ }
+}
+
+static void
+thai_engine_lang_class_init (PangoEngineLangClass *class)
+{
+ class->script_break = thai_engine_break;
+}
+
+PANGO_ENGINE_LANG_DEFINE_TYPE (ThaiEngineLang, thai_engine_lang,
+ thai_engine_lang_class_init, NULL);
+
+void
+PANGO_MODULE_ENTRY(init) (GTypeModule *module)
+{
+ thai_engine_lang_register_type (module);
+}
+
+void
+PANGO_MODULE_ENTRY(exit) (void)
+{
+}
+
+void
+PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines, gint *n_engines)
+{
+ *engines = script_engines;
+ *n_engines = G_N_ELEMENTS (script_engines);
+}
+
+/* Load a particular engine given the ID for the engine
+ */
+PangoEngine *
+PANGO_MODULE_ENTRY(create) (const char *id)
+{
+ if (!strcmp (id, SCRIPT_ENGINE_NAME))
+ return g_object_new (thai_engine_lang_type, NULL);
+ else
+ return NULL;
+}
+