diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-10-12 18:45:09 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-10-12 18:45:09 +0000 |
commit | b77f3f9ba3fc98c086d01440eef7771c58f9058d (patch) | |
tree | 073d0fd1b759aa0d117a2c275a13d8fa04dc52a0 /modules/indic | |
parent | f5da10c8c0e064411a5af65484642d302d8b5a00 (diff) | |
download | pango-b77f3f9ba3fc98c086d01440eef7771c58f9058d.tar.gz |
Bug 353877 – Sinhala is_cursor_position and backspace_deletes_character
2006-10-12 Behdad Esfahbod <behdad@gnome.org>
Bug 353877 – Sinhala is_cursor_position and
backspace_deletes_character issues
Patch from Akira TAGOH
* configure.in:
* modules/indic/Makefile.am:
* modules/indic/indic-lang.c: Add a simple Indic language engine.
Diffstat (limited to 'modules/indic')
-rw-r--r-- | modules/indic/Makefile.am | 18 | ||||
-rw-r--r-- | modules/indic/indic-lang.c | 165 |
2 files changed, 183 insertions, 0 deletions
diff --git a/modules/indic/Makefile.am b/modules/indic/Makefile.am index f2b19197..76494e3c 100644 --- a/modules/indic/Makefile.am +++ b/modules/indic/Makefile.am @@ -24,3 +24,21 @@ pango_indic_fc_la_LIBADD = $(pangoft2libs) pango_indic_fc_la_SOURCES = $(fc_sources) libpango_indic_fc_la_SOURCES = $(fc_sources) libpango_indic_fc_la_CFLAGS = -DPANGO_MODULE_PREFIX=_pango_indic_fc + + +if INCLUDE_INDIC_LANG +noinst_LTLIBRARIES += libpango-indic-lang.la +else +if DYNAMIC_INDIC_LANG +module_LTLIBRARIES += pango-indic-lang.la +endif +endif + +lang_sources = \ + indic-lang.c + +pango_indic_lang_la_LDFLAGS = -module $(MODULE_LIBTOOL_OPTIONS) +pango_indic_lang_la_LIBADD = $(pangolibs) +pango_indic_lang_la_SOURCES = $(lang_sources) +libpango_indic_lang_la_SOURCES = $(lang_sources) +libpango_indic_lang_la_CFLAGS = -DPANGO_MODULE_PREFIX=_pango_indic_lang diff --git a/modules/indic/indic-lang.c b/modules/indic/indic-lang.c new file mode 100644 index 00000000..c03b9184 --- /dev/null +++ b/modules/indic/indic-lang.c @@ -0,0 +1,165 @@ +/* Pango + * indic-lang.c: + * + * Copyright (C) 2006 Red Hat Software + * Author: Akira TAGOH <tagoh@redhat.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 <config.h> +#include <string.h> + +#include "pango-engine.h" +#include "pango-break.h" + +typedef PangoEngineLang IndicEngineLang; +typedef PangoEngineLangClass IndicEngineLangClass; + +#define ENGINE_SUFFIX "IndicScriptEngineLang" +#define RENDER_TYPE PANGO_RENDER_TYPE_NONE +#define INDIC_ENGINE_INFO(script) \ + {#script ENGINE_SUFFIX, PANGO_ENGINE_TYPE_LANG, RENDER_TYPE, script##_scripts, G_N_ELEMENTS(script##_scripts)} + + +static PangoEngineScriptInfo deva_scripts[] = { + { PANGO_SCRIPT_DEVANAGARI, "*" } +}; + +static PangoEngineScriptInfo sinh_scripts[] = { + { PANGO_SCRIPT_SINHALA, "*" } +}; + +static PangoEngineInfo script_engines[] = { + INDIC_ENGINE_INFO(deva), + INDIC_ENGINE_INFO(sinh) +}; + + +static void +indic_engine_break (PangoEngineLang *engine, + const char *text, + int length, + PangoAnalysis *analysis, + PangoLogAttr *attrs, + int attrs_len) +{ + const gchar *p, *next = NULL, *next_next; + gunichar prev_wc, this_wc, next_wc, next_next_wc; + gboolean makes_rephaya_syllable = FALSE; + int i; + + for (p = text, prev_wc = 0, i = 0; + p != NULL && p < (text + length); + p = next, prev_wc = this_wc, i++) + { + this_wc = g_utf8_get_char (p); + next = g_utf8_next_char (p); + if (next != NULL && next < (text + length)) + { + next_wc = g_utf8_get_char (next); + next_next = g_utf8_next_char (next); + } + else + { + next_wc = 0; + next_next = NULL; + } + if (next_next != NULL && next_next < (text + length)) + next_next_wc = g_utf8_get_char (next_next); + else + next_next_wc = 0; + + if (prev_wc != 0 && this_wc == 0x0DBB && + next_wc == 0x0DCA && next_next_wc == 0x200D) + { + /* Determine whether or not this forms a Rephaya syllable. + * SINHALA LETTER + U+0DBB U+0DCA U+200D + SINHALA LETTER is + * the kind of Rephaya. + */ + makes_rephaya_syllable = TRUE; + attrs[i].is_cursor_position = FALSE; + attrs[i].is_char_break = FALSE; + attrs[i].is_line_break = FALSE; + attrs[i].is_mandatory_break = FALSE; + } + else if (prev_wc == 0x200D && + (makes_rephaya_syllable || this_wc == 0x0DBB || this_wc == 0x0DBA)) + { + /* fixes the cursor break in Sinhala. + * SINHALA LETTER + SINHALA VOWEL + ZWJ + 0x0DBB/0x0DBA is + * the kind of Rakaransaya/Yansaya. these characters has to + * be dealt as one character. + */ + attrs[i].is_cursor_position = FALSE; + attrs[i].is_char_break = FALSE; + attrs[i].is_line_break = FALSE; + attrs[i].is_mandatory_break = FALSE; + makes_rephaya_syllable = FALSE; + } + else if (this_wc == 0x200D && + ((makes_rephaya_syllable && next_wc != 0) || + (next_wc == 0x0DBB || next_wc == 0x0DBA))) + { + attrs[i].is_cursor_position = FALSE; + attrs[i].is_char_break = FALSE; + attrs[i].is_line_break = FALSE; + attrs[i].is_mandatory_break = FALSE; + } + } +} + +static void +indic_engine_lang_class_init (PangoEngineLangClass *klass) +{ + klass->script_break = indic_engine_break; +} + +PANGO_ENGINE_LANG_DEFINE_TYPE (IndicEngineLang, indic_engine_lang, + indic_engine_lang_class_init, NULL) + +void +PANGO_MODULE_ENTRY(init) (GTypeModule *module) +{ + indic_engine_lang_register_type (module); +} + +void +PANGO_MODULE_ENTRY(exit) (void) +{ +} + +void +PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines, + int *n_engines) +{ + *engines = script_engines; + *n_engines = G_N_ELEMENTS (script_engines); +} + +PangoEngine * +PANGO_MODULE_ENTRY(create) (const char *id) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS(script_engines); i++) + { + if (!strcmp (id, script_engines[i].id)) + return g_object_new (indic_engine_lang_type, NULL); + } + + return NULL; +} |