4 * Copyright (C) 2003 Theppitak Karoonboonyanan <thep@linux.thai.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <pango/pango-engine.h>
25 #include <pango/pango-break.h>
26 #include <thai/thwchar.h>
27 #include <thai/thbrk.h>
29 /* No extra fields needed */
30 typedef PangoEngineLang ThaiEngineLang;
31 typedef PangoEngineLangClass ThaiEngineLangClass;
33 #define SCRIPT_ENGINE_NAME "ThaiScriptEngineLang"
35 static PangoEngineScriptInfo thai_scripts[] = {
36 { PANGO_SCRIPT_THAI, "*" }
39 static PangoEngineInfo script_engines[] = {
42 PANGO_ENGINE_TYPE_LANG,
43 PANGO_RENDER_TYPE_NONE,
44 thai_scripts, G_N_ELEMENTS(thai_scripts)
49 * tis_text is assumed to be large enough to hold the converted string,
50 * i.e. it must be at least g_utf8_strlen(text, len)+1 bytes.
53 utf8_to_tis (const char *text, int len, thchar_t *tis_text, int *tis_cnt)
59 for (text_p = text; text_p < text + len; text_p = g_utf8_next_char (text_p))
60 *tis_p++ = th_uni2tis (g_utf8_get_char (text_p));
63 *tis_cnt = tis_p - tis_text;
68 thai_engine_break (PangoEngineLang *engine G_GNUC_UNUSED,
71 PangoAnalysis *analysis G_GNUC_UNUSED,
73 int attrs_len G_GNUC_UNUSED)
75 thchar_t tis_stack[512];
83 cnt = g_utf8_strlen (text, len) + 1;
86 if (cnt > (int) G_N_ELEMENTS (tis_stack))
87 tis_text = g_new (thchar_t, cnt);
89 utf8_to_tis (text, len, tis_text, &cnt);
92 if (cnt > (int) G_N_ELEMENTS (brk_stack))
93 brk_pnts = g_new (int, cnt);
95 /* find line break positions */
96 len = th_brk (tis_text, brk_pnts, len);
97 for (cnt = 0; cnt < len; cnt++)
99 attrs[brk_pnts[cnt]].is_line_break = TRUE;
100 attrs[brk_pnts[cnt]].is_word_start = TRUE;
101 attrs[brk_pnts[cnt]].is_word_end = TRUE;
104 if (brk_pnts != brk_stack)
107 if (tis_text != tis_stack)
112 thai_engine_lang_class_init (PangoEngineLangClass *class)
114 class->script_break = thai_engine_break;
117 PANGO_ENGINE_LANG_DEFINE_TYPE (ThaiEngineLang, thai_engine_lang,
118 thai_engine_lang_class_init, NULL);
121 PANGO_MODULE_ENTRY(init) (GTypeModule *module)
123 thai_engine_lang_register_type (module);
127 PANGO_MODULE_ENTRY(exit) (void)
132 PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines, gint *n_engines)
134 *engines = script_engines;
135 *n_engines = G_N_ELEMENTS (script_engines);
138 /* Load a particular engine given the ID for the engine
141 PANGO_MODULE_ENTRY(create) (const char *id)
143 if (!strcmp (id, SCRIPT_ENGINE_NAME))
144 return g_object_new (thai_engine_lang_type, NULL);