diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 8 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 8 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 8 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 8 | ||||
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | modules/thai/Makefile.am | 34 | ||||
-rw-r--r-- | modules/thai/thai-ft2.c | 270 | ||||
-rw-r--r-- | modules/thai/thai-shaper.c | 121 | ||||
-rw-r--r-- | modules/thai/thai-shaper.h | 18 | ||||
-rw-r--r-- | modules/thai/thai-x.c | 45 | ||||
-rw-r--r-- | modules/thai/thai-xft.c | 74 |
12 files changed, 484 insertions, 121 deletions
@@ -1,3 +1,11 @@ +Wed Apr 30 18:43:59 2003 Owen Taylor <otaylor@redhat.com> + + * configure.in modules/thai/Makefile.am modules + modules/thai/thai-ft2.c modules/thai/thai-shaper.[ch] + modules/thai/thai-x.c modules/thai/thai-xft.c: Patch + from Theppitak Karoonboonyanan to add FT2 shaper + for Thai. (#108582) + Wed Apr 30 16:46:52 2003 Owen Taylor <otaylor@redhat.com> * pango/fonts.c (pango_font_description_hash): Hash diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 9e6f4889..f38f399a 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,11 @@ +Wed Apr 30 18:43:59 2003 Owen Taylor <otaylor@redhat.com> + + * configure.in modules/thai/Makefile.am modules + modules/thai/thai-ft2.c modules/thai/thai-shaper.[ch] + modules/thai/thai-x.c modules/thai/thai-xft.c: Patch + from Theppitak Karoonboonyanan to add FT2 shaper + for Thai. (#108582) + Wed Apr 30 16:46:52 2003 Owen Taylor <otaylor@redhat.com> * pango/fonts.c (pango_font_description_hash): Hash diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index 9e6f4889..f38f399a 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,11 @@ +Wed Apr 30 18:43:59 2003 Owen Taylor <otaylor@redhat.com> + + * configure.in modules/thai/Makefile.am modules + modules/thai/thai-ft2.c modules/thai/thai-shaper.[ch] + modules/thai/thai-x.c modules/thai/thai-xft.c: Patch + from Theppitak Karoonboonyanan to add FT2 shaper + for Thai. (#108582) + Wed Apr 30 16:46:52 2003 Owen Taylor <otaylor@redhat.com> * pango/fonts.c (pango_font_description_hash): Hash diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index 9e6f4889..f38f399a 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,11 @@ +Wed Apr 30 18:43:59 2003 Owen Taylor <otaylor@redhat.com> + + * configure.in modules/thai/Makefile.am modules + modules/thai/thai-ft2.c modules/thai/thai-shaper.[ch] + modules/thai/thai-x.c modules/thai/thai-xft.c: Patch + from Theppitak Karoonboonyanan to add FT2 shaper + for Thai. (#108582) + Wed Apr 30 16:46:52 2003 Owen Taylor <otaylor@redhat.com> * pango/fonts.c (pango_font_description_hash): Hash diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 9e6f4889..f38f399a 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,11 @@ +Wed Apr 30 18:43:59 2003 Owen Taylor <otaylor@redhat.com> + + * configure.in modules/thai/Makefile.am modules + modules/thai/thai-ft2.c modules/thai/thai-shaper.[ch] + modules/thai/thai-x.c modules/thai/thai-xft.c: Patch + from Theppitak Karoonboonyanan to add FT2 shaper + for Thai. (#108582) + Wed Apr 30 16:46:52 2003 Owen Taylor <otaylor@redhat.com> * pango/fonts.c (pango_font_description_hash): Hash diff --git a/configure.in b/configure.in index f3ad5b94..938b56d3 100644 --- a/configure.in +++ b/configure.in @@ -342,7 +342,7 @@ hangul_modules="hangul-x,hangul-xft" hebrew_modules="hebrew-ft2,hebrew-x,hebrew-xft" indic_modules="bengali-x,devanagari-x,gurmukhi-x,gujarati-x,myanmar-x,indic-xft,indic-ft2" tamil_modules="tamil-x" -thai_modules="thai-x,thai-xft" +thai_modules="thai-ft2,thai-x,thai-xft" all_modules="$arabic_modules,$basic_modules,$hangul_modules,$hebrew_modules,$indic_modules,$tamil_modules,$thai_modules" @@ -417,6 +417,7 @@ AM_CONDITIONAL(INCLUDE_TAMIL_X,echo $included_modules | egrep '(^|,)tamil-x($|,) AM_CONDITIONAL(INCLUDE_THAI_X,echo $included_modules | egrep '(^|,)thai-x($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_THAI_XFT,echo $included_modules | egrep '(^|,)thai-xft($|,)' > /dev/null) +AM_CONDITIONAL(INCLUDE_THAI_FT2,echo $included_modules | egrep '(^|,)thai-ft2($|,)' > /dev/null) AM_CONDITIONAL(INCLUDE_INDIC_XFT,echo $included_modules | egrep '(^|,)indic-xft($|,)' > /dev/null) diff --git a/modules/thai/Makefile.am b/modules/thai/Makefile.am index 6e27c439..47d93724 100644 --- a/modules/thai/Makefile.am +++ b/modules/thai/Makefile.am @@ -3,6 +3,7 @@ common_sources = thai-shaper.c thai-shaper.h thai_x_sources = $(common_sources) thai-x.c thai_xft_sources = $(common_sources) thai-xft.c +thai_ft2_sources = $(common_sources) thai-ft2.c pangolibs = $(top_builddir)/pango/libpango-$(PANGO_API_VERSION).la $(FRIBIDI_LIBS) $(GLIB_LIBS) pangoxlibs = $(top_builddir)/pango/libpangox-$(PANGO_API_VERSION).la $(X_LIBS) $(pangolibs) @@ -43,9 +44,30 @@ X_INCLUDED= X_PREFIX= endif -noinst_LTLIBRARIES = $(X_INCLUDED) $(XFT_INCLUDED) -module_LTLIBRARIES = $(X_MODULES) $(XFT_MODULES) -moddefine = $(X_PREFIX) $(XFT_PREFIX) +if HAVE_FREETYPE +if INCLUDE_THAI_FT2 +FT2_MODULES= +FT2_INCLUDED=libpango-thai-ft2.la +FT2_PREFIX=-DFT2_MODULE_PREFIX +else +FT2_MODULES=pango-thai-ft2.la +FT2_INCLUDED= +FT2_PREFIX= +thai_ft2_libadd=$(pangoft2libs) +endif +else +FT2_MODULES= +FT2_INCLUDED= +FT2_PREFIX= +endif + +if PLATFORM_WIN32 +no_undefined = -no-undefined +endif + +noinst_LTLIBRARIES = $(X_INCLUDED) $(XFT_INCLUDED) $(FT2_INCLUDED) +module_LTLIBRARIES = $(X_MODULES) $(XFT_MODULES) $(FT2_MODULES) +moddefine = $(X_PREFIX) $(XFT_PREFIX) $(FT2_PREFIX) moduledir = $(libdir)/pango/$(PANGO_MODULE_VERSION)/modules INCLUDES = \ @@ -72,6 +94,12 @@ pango_thai_xft_la_SOURCES = $(thai_xft_sources) libpango_thai_xft_la_SOURCES = $(thai_xft_sources) +pango_thai_ft2_la_LDFLAGS = -export-dynamic -avoid-version -module $(no_undefined) +pango_thai_ft2_la_LIBADD = $(thai_ft2_libadd) +pango_thai_ft2_la_SOURCES = $(thai_ft2_sources) + +libpango_thai_ft2_la_SOURCES = $(thai_ft2_sources) + included-modules: $(noinst_LTLIBRARIES) .PHONY: included-modules diff --git a/modules/thai/thai-ft2.c b/modules/thai/thai-ft2.c new file mode 100644 index 00000000..964952d0 --- /dev/null +++ b/modules/thai/thai-ft2.c @@ -0,0 +1,270 @@ +/* Pango + * thai-ft2.c: + * + * Copyright (C) 1999 Red Hat Software + * Author: Owen Taylor <otaylor@redhat.com> + * + * Copyright (C) 2002 NECTEC + * Author: Theppitak Karoonboonyanan <thep@links.nectec.or.th> + * + * Copyright (c) 1996-2000 by Sun Microsystems, Inc. + * Author: Chookij Vanatham <Chookij.Vanatham@Eng.Sun.COM> + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include <string.h> + +#include <glib.h> +#include "pango-engine.h" +#include "pangoft2.h" +#include "thai-shaper.h" + +#define SCRIPT_ENGINE_NAME "ThaiScriptEngineFT2" + +/* We handle the range U+0e01 to U+0e5b exactly + */ +static PangoEngineRange thai_ranges[] = { + { 0x0e01, 0x0e5b, "*" }, /* Thai */ +}; + +static PangoEngineInfo script_engines[] = { + { + SCRIPT_ENGINE_NAME, + PANGO_ENGINE_TYPE_SHAPE, + PANGO_RENDER_TYPE_FT2, + thai_ranges, G_N_ELEMENTS(thai_ranges) + } +}; + +/* TIS-to-Unicode glyph maps for characters 0x80-0xff + */ +static int tis620_0[128] = { + /**/ 0, 0, 0, 0, 0, 0, 0, 0, + /**/ 0, 0, 0, 0, 0, 0, 0, 0, + /**/ 0, 0, 0, 0, 0, 0, 0, 0, + /**/ 0, 0, 0, 0, 0, 0, 0, 0, + 0x0020, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, + 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, + 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, + 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, + 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, + 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, + 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, + 0x0e38, 0x0e39, 0x0e3a, 0, 0, 0, 0, 0x0e3f, + 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, + 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, + 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, + 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0, 0, 0, 0 +}; + +static int tis620_1[128] = { + 0x00ab, 0x00bb, 0x2026, 0xf88c, 0xf88f, 0xf892, 0xf895, 0xf898, + 0xf88b, 0xf88e, 0xf891, 0xf894, 0xf897, 0x201c, 0x201d, 0xf899, + /**/ 0, 0x2022, 0xf884, 0xf889, 0xf885, 0xf886, 0xf887, 0xf888, + 0xf88a, 0xf88d, 0xf890, 0xf893, 0xf896, 0x2018, 0x2019, 0, + 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, + 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, + 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, + 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, + 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, + 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, + 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, + 0x0e38, 0x0e39, 0x0e3a, 0xfeff, 0x200b, 0x2013, 0x2014, 0x0e3f, + 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, + 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x2122, 0x0e4f, + 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, + 0x0e58, 0x0e59, 0x00ae, 0x00a9, 0, 0, 0, 0 +}; + +static int tis620_2[128] = { + 0xf700, 0xf701, 0xf702, 0xf703, 0xf704, 0x2026, 0xf705, 0xf706, + 0xf707, 0xf708, 0xf709, 0xf70a, 0xf70b, 0xf70c, 0xf70d, 0xf70e, + 0xf70f, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, + 0xf710, 0xf711, 0xf712, 0xf713, 0xf714, 0xf715, 0xf716, 0xf717, + 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, + 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, + 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, + 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, + 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, + 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, + 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, + 0x0e38, 0x0e39, 0x0e3a, 0, 0, 0, 0, 0x0e3f, + 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, + 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, + 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, + 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0xf718, 0xf719, 0xf71a, 0 +}; + +static int +contain_glyphs(PangoFont *font, const int glyph_map[128]) +{ + unsigned char c; + FT_Face face; + + face = pango_ft2_font_get_face (font); + + for (c = 0; c < 0x80; c++) + { + if (glyph_map[c]) + { + if (!FT_Get_Char_Index (face, glyph_map[c])) + return 0; + } + } + return 1; +} + +static PangoGlyph +thai_ft2_make_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + int index; + PangoGlyph result; + + switch (font_info->font_set) { + case THAI_FONT_ISO10646:index = c; break; + case THAI_FONT_TIS: index = (c & 0x80) ? tis620_0[c & 0x7f] : c; break; + case THAI_FONT_TIS_MAC: index = (c & 0x80) ? tis620_1[c & 0x7f] : c; break; + case THAI_FONT_TIS_WIN: index = (c & 0x80) ? tis620_2[c & 0x7f] : c; break; + default: index = 0; break; + } + + result = FT_Get_Char_Index (pango_ft2_font_get_face (font_info->font), index); + if (result) + return result; + else + return pango_ft2_get_unknown_glyph (font_info->font); +} + +static PangoGlyph +thai_ft2_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + return pango_ft2_get_unknown_glyph (font_info->font); +} + +/* Returns a structure with information we will use to rendering given the + * #PangoFont. This is computed once per font and cached for later retrieval. + */ +static ThaiFontInfo * +thai_ft2_get_font_info (PangoFont *font) +{ + ThaiFontInfo *font_info; + GQuark info_id = g_quark_from_string ("thai-font-info"); + + font_info = g_object_get_qdata (G_OBJECT (font), info_id); + + if (!font_info) + { + /* No cached information not found, so we need to compute it + * from scratch + */ + font_info = g_new (ThaiFontInfo, 1); + font_info->font = font; + + /* detect font set by determining availibility of glyphs */ + if (contain_glyphs(font, tis620_2)) + font_info->font_set = THAI_FONT_TIS_WIN; + else if (contain_glyphs(font, tis620_1)) + font_info->font_set = THAI_FONT_TIS_MAC; + else if (contain_glyphs(font, tis620_0)) + font_info->font_set = THAI_FONT_TIS; + else + font_info->font_set = THAI_FONT_ISO10646; + + font_info->make_glyph = thai_ft2_make_glyph; + font_info->make_unknown_glyph = thai_ft2_make_unknown_glyph; + + g_object_set_qdata_full (G_OBJECT (font), info_id, font_info, (GDestroyNotify)g_free); + } + + return font_info; +} + +static void +thai_engine_ft2_shape (PangoFont *font, + const char *text, + gint length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + ThaiFontInfo *font_info; + + font_info = thai_ft2_get_font_info (font); + thai_engine_shape(font_info, text, length, analysis, glyphs); +} + +static PangoCoverage * +thai_engine_ft2_get_coverage (PangoFont *font, + PangoLanguage *lang) +{ + return pango_font_get_coverage (font, lang); +} + +static PangoEngine * +thai_engine_ft2_new () +{ + PangoEngineShape *result; + + result = g_new (PangoEngineShape, 1); + + result->engine.id = SCRIPT_ENGINE_NAME; + result->engine.type = PANGO_ENGINE_TYPE_SHAPE; + result->engine.length = sizeof (result); + result->script_shape = thai_engine_ft2_shape; + result->get_coverage = thai_engine_ft2_get_coverage; + + return (PangoEngine *)result; +} + +/* The following three functions provide the public module API for + * Pango. If we are compiling it as a module, then we name the + * entry points script_engine_list, etc. But if we are compiling + * it for inclusion directly in Pango, then we need them to + * to have distinct names for this module, so we prepend + * _pango_thai_ft2_ + */ +#ifdef FT2_MODULE_PREFIX +#define MODULE_ENTRY(func) _pango_thai_ft2_##func +#else +#define MODULE_ENTRY(func) func +#endif + +/* List the engines contained within this module + */ +void +MODULE_ENTRY(script_engine_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 * +MODULE_ENTRY(script_engine_load) (const char *id) +{ + if (!strcmp (id, SCRIPT_ENGINE_NAME)) + return thai_engine_ft2_new (); + else + return NULL; +} + +void +MODULE_ENTRY(script_engine_unload) (PangoEngine *engine) +{ +} + diff --git a/modules/thai/thai-shaper.c b/modules/thai/thai-shaper.c index 9822c28b..ef04b229 100644 --- a/modules/thai/thai-shaper.c +++ b/modules/thai/thai-shaper.c @@ -339,17 +339,17 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, if (is_char_type (cluster[0], BelowVowel|BelowDiac|AboveVowel|AboveDiac|Tone)) { if (font_info->font_set == THAI_FONT_TIS) - glyph_lists[0] = thai_make_glyph (font_info, 0x20); + glyph_lists[0] = (*font_info->make_glyph) (font_info, 0x20); else - glyph_lists[0] = thai_make_glyph (font_info, 0x7F); + glyph_lists[0] = (*font_info->make_glyph) (font_info, 0x7F); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); return 2; } else { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); return 1; } break; @@ -359,36 +359,36 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[1], SaraAm)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, 0xED); - glyph_lists[2] = thai_make_glyph (font_info, 0xD2); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, 0xED); + glyph_lists[2] = (*font_info->make_glyph) (font_info, 0xD2); return 3; } else if (is_char_type (cluster[0], UpTailCons) && is_char_type (cluster[1], SaraAm)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftleft_tone_ad (0xED, shaping_table)); - glyph_lists[2] = thai_make_glyph (font_info, 0xD2); + glyph_lists[2] = (*font_info->make_glyph) (font_info, 0xD2); return 3; } else if (is_char_type (cluster[0], NoTailCons|BotTailCons|SpltTailCons) && is_char_type (cluster[1], AboveVowel)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); return 2; } else if (is_char_type (cluster[0], NoTailCons|BotTailCons|SpltTailCons) && is_char_type (cluster[1], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftdown_tone_ad (ucs2tis (cluster[1]), shaping_table)); return 2; } @@ -396,8 +396,8 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[1], AboveVowel)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftleft_av (ucs2tis (cluster[1]), shaping_table)); return 2; } @@ -405,8 +405,8 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[1], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftdownleft_tone_ad (ucs2tis (cluster[1]), shaping_table)); return 2; } @@ -414,40 +414,40 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[1], BelowVowel|BelowDiac)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); return 2; } else if (is_char_type (cluster[0], BotTailCons) && is_char_type (cluster[1], BelowVowel|BelowDiac)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, shiftdown_bv_bd (ucs2tis (cluster[1]), shaping_table)); return 2; } else if (is_char_type (cluster[0], SpltTailCons) && is_char_type (cluster[1], BelowVowel|BelowDiac)) { - glyph_lists[0] = thai_make_glyph (font_info, + glyph_lists[0] = (*font_info->make_glyph) (font_info, tailcutcons (ucs2tis (cluster[0]), shaping_table)); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); return 2; } else { if (font_info->font_set == THAI_FONT_TIS) - glyph_lists[0] = thai_make_glyph (font_info, 0x20); + glyph_lists[0] = (*font_info->make_glyph) (font_info, 0x20); else - glyph_lists[0] = thai_make_glyph (font_info, 0x7F); + glyph_lists[0] = (*font_info->make_glyph) (font_info, 0x7F); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[2] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); return 3; } break; @@ -458,11 +458,11 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], SaraAm)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, 0xED); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, 0xED); glyph_lists[2] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); - glyph_lists[3] = thai_make_glyph (font_info, 0xD2); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); + glyph_lists[3] = (*font_info->make_glyph) (font_info, 0xD2); return 4; } else if (is_char_type (cluster[0], UpTailCons) && @@ -470,12 +470,12 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], SaraAm)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftleft_tone_ad (0xED, shaping_table)); - glyph_lists[2] = thai_make_glyph (font_info, + glyph_lists[2] = (*font_info->make_glyph) (font_info, shiftleft_tone_ad (ucs2tis (cluster[1]), shaping_table)); - glyph_lists[3] = thai_make_glyph (font_info, 0xD2); + glyph_lists[3] = (*font_info->make_glyph) (font_info, 0xD2); return 4; } else if (is_char_type (cluster[0], UpTailCons) && @@ -483,10 +483,10 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftleft_av (ucs2tis (cluster[1]), shaping_table)); - glyph_lists[2] = thai_make_glyph (font_info, + glyph_lists[2] = (*font_info->make_glyph) (font_info, shiftleft_tone_ad (ucs2tis (cluster[2]), shaping_table)); return 3; } @@ -495,10 +495,10 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); - glyph_lists[2] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); + glyph_lists[2] = (*font_info->make_glyph) (font_info, shiftdownleft_tone_ad (ucs2tis (cluster[2]), shaping_table)); return 3; } @@ -507,11 +507,11 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); glyph_lists[2] = - thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, shiftdown_tone_ad (ucs2tis (cluster[2]), shaping_table)); return 3; } @@ -519,11 +519,11 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[1], BelowVowel) && is_char_type (cluster[2], AboveDiac|Tone)) { - glyph_lists[0] = thai_make_glyph (font_info, + glyph_lists[0] = (*font_info->make_glyph) (font_info, tailcutcons (ucs2tis (cluster[0]), shaping_table)); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); - glyph_lists[2] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); + glyph_lists[2] = (*font_info->make_glyph) (font_info, shiftdown_tone_ad (ucs2tis (cluster[2]), shaping_table)); return 3; } @@ -532,21 +532,21 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info, is_char_type (cluster[2], AboveDiac|Tone)) { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); - glyph_lists[1] = thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); + glyph_lists[1] = (*font_info->make_glyph) (font_info, shiftdown_bv_bd (ucs2tis (cluster[1]), shaping_table)); - glyph_lists[2] = thai_make_glyph (font_info, + glyph_lists[2] = (*font_info->make_glyph) (font_info, shiftdown_tone_ad (ucs2tis (cluster[2]), shaping_table)); return 3; } else { glyph_lists[0] = - thai_make_glyph (font_info, ucs2tis (cluster[0])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[0])); glyph_lists[1] = - thai_make_glyph (font_info, ucs2tis (cluster[1])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[1])); glyph_lists[2] = - thai_make_glyph (font_info, ucs2tis (cluster[2])); + (*font_info->make_glyph) (font_info, ucs2tis (cluster[2])); return 3; } break; @@ -569,7 +569,7 @@ get_glyphs_list (ThaiFontInfo *font_info, { case THAI_FONT_NONE: for (i=0; i < num_chrs; i++) - glyph_lists[i] = thai_make_unknown_glyph (font_info, glyph_lists[i]); + glyph_lists[i] = (*font_info->make_unknown_glyph) (font_info, glyph_lists[i]); return num_chrs; case THAI_FONT_XTIS: @@ -581,14 +581,14 @@ get_glyphs_list (ThaiFontInfo *font_info, xtis_index +=8 * group1_map[cluster[1] - 0xe30]; if (cluster[2]) xtis_index += group2_map[cluster[2] - 0xe30]; - glyph = thai_make_glyph (font_info, xtis_index); + glyph = (*font_info->make_glyph) (font_info, xtis_index); if (pango_x_has_glyph (font_info->font, glyph)) { glyph_lists[0] = glyph; return 1; } for (i=0; i < num_chrs; i++) glyph_lists[i] = - thai_make_glyph (font_info, + (*font_info->make_glyph) (font_info, 0x100 * (cluster[i] - 0xe00 + 0x20) + 0x30); return num_chrs; @@ -612,7 +612,7 @@ get_glyphs_list (ThaiFontInfo *font_info, case THAI_FONT_ISO10646: for (i=0; i < num_chrs; i++) - glyph_lists[i] = thai_make_glyph (font_info, cluster[i]); + glyph_lists[i] = (*font_info->make_glyph) (font_info, cluster[i]); return num_chrs; } @@ -692,13 +692,12 @@ get_next_cluster(const char *text, } void -thai_engine_shape (PangoFont *font, +thai_engine_shape (ThaiFontInfo *font_info, const char *text, gint length, PangoAnalysis *analysis, PangoGlyphString *glyphs) { - ThaiFontInfo *font_info; const char *p; const char *log_cluster; gunichar cluster[MAX_CLUSTER_CHRS]; @@ -706,8 +705,6 @@ thai_engine_shape (PangoFont *font, pango_glyph_string_set_size (glyphs, 0); - font_info = thai_get_font_info (font); - p = text; while (p < text + length) { diff --git a/modules/thai/thai-shaper.h b/modules/thai/thai-shaper.h index c9f487fa..e028e3a9 100644 --- a/modules/thai/thai-shaper.h +++ b/modules/thai/thai-shaper.h @@ -29,25 +29,19 @@ struct _ThaiFontInfo PangoFont *font; ThaiFontSet font_set; PangoXSubfont subfont; /* For X backend */ -}; -/* - * Abstract methods (implemented by each shaper module) - */ -ThaiFontInfo * -thai_get_font_info (PangoFont *font); + PangoGlyph + (*make_glyph) (ThaiFontInfo *font_info, unsigned int c); -PangoGlyph -thai_make_glyph (ThaiFontInfo *font_info, unsigned int c); - -PangoGlyph -thai_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c); + PangoGlyph + (*make_unknown_glyph) (ThaiFontInfo *font_info, unsigned int c); +}; /* * Public functions */ void -thai_engine_shape (PangoFont *font, +thai_engine_shape (ThaiFontInfo *font_info, const char *text, gint length, PangoAnalysis *analysis, diff --git a/modules/thai/thai-x.c b/modules/thai/thai-x.c index 5bfd0b09..edf31d54 100644 --- a/modules/thai/thai-x.c +++ b/modules/thai/thai-x.c @@ -51,11 +51,23 @@ static PangoEngineInfo script_engines[] = { } }; +static PangoGlyph +thai_x_make_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + return PANGO_X_MAKE_GLYPH (font_info->subfont, c); +} + +static PangoGlyph +thai_x_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + return pango_x_get_unknown_glyph (font_info->font); +} + /* Returns a structure with information we will use to rendering given the * #PangoFont. This is computed once per font and cached for later retrieval. */ -ThaiFontInfo * -thai_get_font_info (PangoFont *font) +static ThaiFontInfo * +thai_x_get_font_info (PangoFont *font) { static const char *charsets[] = { "tis620-2", @@ -120,30 +132,35 @@ thai_get_font_info (PangoFont *font) g_free (subfont_ids); g_free (subfont_charsets); + + font_info->make_glyph = thai_x_make_glyph; + font_info->make_unknown_glyph = thai_x_make_unknown_glyph; } return font_info; } -PangoGlyph -thai_make_glyph (ThaiFontInfo *font_info, unsigned int c) +static void +thai_engine_x_shape (PangoFont *font, + const char *text, + gint length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) { - return PANGO_X_MAKE_GLYPH (font_info->subfont, c); -} + ThaiFontInfo *font_info; -PangoGlyph -thai_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c) -{ - return pango_x_get_unknown_glyph (font_info->font); + font_info = thai_x_get_font_info (font); + thai_engine_shape(font_info, text, length, analysis, glyphs); } + static PangoCoverage * -thai_engine_get_coverage (PangoFont *font, +thai_engine_x_get_coverage (PangoFont *font, PangoLanguage *lang) { PangoCoverage *result = pango_coverage_new (); - ThaiFontInfo *font_info = thai_get_font_info (font); + ThaiFontInfo *font_info = thai_x_get_font_info (font); if (font_info->font_set != THAI_FONT_NONE) { @@ -168,8 +185,8 @@ thai_engine_x_new () result->engine.id = SCRIPT_ENGINE_NAME; result->engine.type = PANGO_ENGINE_TYPE_SHAPE; result->engine.length = sizeof (result); - result->script_shape = thai_engine_shape; - result->get_coverage = thai_engine_get_coverage; + result->script_shape = thai_engine_x_shape; + result->get_coverage = thai_engine_x_get_coverage; return (PangoEngine *)result; } diff --git a/modules/thai/thai-xft.c b/modules/thai/thai-xft.c index a6ec0c15..dfd3234d 100644 --- a/modules/thai/thai-xft.c +++ b/modules/thai/thai-xft.c @@ -126,11 +126,38 @@ contain_glyphs(PangoFont *font, const int glyph_map[128]) return 1; } +static PangoGlyph +thai_xft_make_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + int index; + PangoGlyph result; + + switch (font_info->font_set) { + case THAI_FONT_ISO10646:index = c; break; + case THAI_FONT_TIS: index = (c & 0x80) ? tis620_0[c & 0x7f] : c; break; + case THAI_FONT_TIS_MAC: index = (c & 0x80) ? tis620_1[c & 0x7f] : c; break; + case THAI_FONT_TIS_WIN: index = (c & 0x80) ? tis620_2[c & 0x7f] : c; break; + default: index = 0; break; + } + + result = pango_xft_font_get_glyph (font_info->font, index); + if (result) + return result; + else + return pango_xft_font_get_unknown_glyph (font_info->font, index); +} + +static PangoGlyph +thai_xft_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c) +{ + return pango_xft_font_get_unknown_glyph (font_info->font, c); +} + /* Returns a structure with information we will use to rendering given the * #PangoFont. This is computed once per font and cached for later retrieval. */ -ThaiFontInfo * -thai_get_font_info (PangoFont *font) +static ThaiFontInfo * +thai_xft_get_font_info (PangoFont *font) { ThaiFontInfo *font_info; GQuark info_id = g_quark_from_string ("thai-font-info"); @@ -155,42 +182,31 @@ thai_get_font_info (PangoFont *font) else font_info->font_set = THAI_FONT_ISO10646; + font_info->make_glyph = thai_xft_make_glyph; + font_info->make_unknown_glyph = thai_xft_make_unknown_glyph; + g_object_set_qdata_full (G_OBJECT (font), info_id, font_info, (GDestroyNotify)g_free); } return font_info; } -PangoGlyph -thai_make_glyph (ThaiFontInfo *font_info, unsigned int c) +static void +thai_engine_xft_shape (PangoFont *font, + const char *text, + gint length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) { - int index; - PangoGlyph result; - - switch (font_info->font_set) { - case THAI_FONT_ISO10646:index = c; break; - case THAI_FONT_TIS: index = (c & 0x80) ? tis620_0[c & 0x7f] : c; break; - case THAI_FONT_TIS_MAC: index = (c & 0x80) ? tis620_1[c & 0x7f] : c; break; - case THAI_FONT_TIS_WIN: index = (c & 0x80) ? tis620_2[c & 0x7f] : c; break; - default: index = 0; break; - } - - result = pango_xft_font_get_glyph (font_info->font, index); - if (result) - return result; - else - return pango_xft_font_get_unknown_glyph (font_info->font, index); -} + ThaiFontInfo *font_info; -PangoGlyph -thai_make_unknown_glyph (ThaiFontInfo *font_info, unsigned int c) -{ - return pango_xft_font_get_unknown_glyph (font_info->font, c); + font_info = thai_xft_get_font_info (font); + thai_engine_shape(font_info, text, length, analysis, glyphs); } static PangoCoverage * -thai_engine_get_coverage (PangoFont *font, - PangoLanguage *lang) +thai_engine_xft_get_coverage (PangoFont *font, + PangoLanguage *lang) { return pango_font_get_coverage (font, lang); } @@ -205,8 +221,8 @@ thai_engine_xft_new () result->engine.id = SCRIPT_ENGINE_NAME; result->engine.type = PANGO_ENGINE_TYPE_SHAPE; result->engine.length = sizeof (result); - result->script_shape = thai_engine_shape; - result->get_coverage = thai_engine_get_coverage; + result->script_shape = thai_engine_xft_shape; + result->get_coverage = thai_engine_xft_get_coverage; return (PangoEngine *)result; } |