diff options
author | Owen Taylor <otaylor@redhat.com> | 2004-12-16 00:08:00 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2004-12-16 00:08:00 +0000 |
commit | 02cee907a827e0fd8cd78237c9bc1c4618b9e660 (patch) | |
tree | e6e68da322832c15c8c8f655aa7ce2e205919a13 /modules | |
parent | 542a8cadcb9049d2d812d3adfd4df59532b06d9e (diff) | |
download | pango-02cee907a827e0fd8cd78237c9bc1c4618b9e660.tar.gz |
Add simple tibetan module. (#148566, G Karunakar)
Wed Dec 15 11:15:37 2004 Owen Taylor <otaylor@redhat.com>
* configure.in modules/Makefile.am modules/tibetan/*:
Add simple tibetan module. (#148566, G Karunakar)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/Makefile.am | 5 | ||||
-rw-r--r-- | modules/tibetan/.cvsignore | 2 | ||||
-rw-r--r-- | modules/tibetan/Makefile.am | 42 | ||||
-rw-r--r-- | modules/tibetan/tibetan-fc.c | 315 |
4 files changed, 362 insertions, 2 deletions
diff --git a/modules/Makefile.am b/modules/Makefile.am index 8b67df8b..f1ff5d30 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -4,10 +4,11 @@ SUBDIRS = \ arabic \ basic \ hangul \ + hebrew \ indic \ + syriac \ thai \ - hebrew \ - syriac + tibetan EXTRA_DIST = \ module.def diff --git a/modules/tibetan/.cvsignore b/modules/tibetan/.cvsignore new file mode 100644 index 00000000..282522db --- /dev/null +++ b/modules/tibetan/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/modules/tibetan/Makefile.am b/modules/tibetan/Makefile.am new file mode 100644 index 00000000..e4f3096f --- /dev/null +++ b/modules/tibetan/Makefile.am @@ -0,0 +1,42 @@ +## Process this file with automake to create Makefile.in. + +pangolibs = $(top_builddir)/pango/libpango-$(PANGO_API_VERSION).la $(GLIB_LIBS) +pangoft2libs = $(top_builddir)/pango/libpangoft2-$(PANGO_API_VERSION).la $(FREETYPE_LIBS) $(pangolibs) + +INCLUDES = \ + -DPANGO_ENABLE_ENGINE \ + -DG_DISABLE_DEPRECATED \ + $(PANGO_DEBUG_FLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/pango/ \ + $(GLIB_CFLAGS) + +if PLATFORM_WIN32 +no_undefined = -no-undefined +endif + +moduledir = $(libdir)/pango/$(PANGO_MODULE_VERSION)/modules +module_LTLIBRARIES = +noinst_LTLIBRARIES = + +if HAVE_FREETYPE +INCLUDES += $(FREETYPE_CFLAGS) +if INCLUDE_TIBETAN_FC +noinst_LTLIBRARIES += libpango-tibetan-fc.la +else +module_LTLIBRARIES += pango-tibetan-fc.la +endif +endif + +tibetan_fc_sources = $(common_sources) tibetan-fc.c + +pango_tibetan_fc_la_LDFLAGS = -export-dynamic -avoid-version -module $(no_undefined) +pango_tibetan_fc_la_LIBADD = $(pangoft2libs) +pango_tibetan_fc_la_SOURCES = $(tibetan_fc_sources) +libpango_tibetan_fc_la_SOURCES = $(tibetan_fc_sources) +libpango_tibetan_fc_la_CFLAGS = -DPANGO_MODULE_PREFIX=_pango_tibetan_fc + + +included-modules: $(noinst_LTLIBRARIES) + +.PHONY: included-modules diff --git a/modules/tibetan/tibetan-fc.c b/modules/tibetan/tibetan-fc.c new file mode 100644 index 00000000..642f9f87 --- /dev/null +++ b/modules/tibetan/tibetan-fc.c @@ -0,0 +1,315 @@ +/* Pango + * tibetan-fc.c: Shaper for Tibetan script + * based on thai-fc.c and basic-fc.c + * + * Copyright (C) 1999-2004 Red Hat Software + * Author: Owen Taylor <otaylor@redhat.com> + * + * Copyright (C) 2004 Theppitak Karoonboonyanan <thep@linux.thai.net> + * + * Copyright (C) 2004 G Karunakar <karunakar@freedomink.org> + * + * 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 "pango-ot.h" +#include "pangofc-font.h" + +typedef PangoEngineShape TibetanEngineFc; +typedef PangoEngineShapeClass TibetanEngineFcClass; + +#define SCRIPT_ENGINE_NAME "TibetanScriptEngineFc" +#define RENDER_TYPE PANGO_RENDER_TYPE_FC + +static PangoEngineScriptInfo tibetan_scripts[] = { + { PANGO_SCRIPT_TIBETAN, "*" } +}; + +static PangoEngineInfo script_engines[] = { + { + SCRIPT_ENGINE_NAME, + PANGO_ENGINE_TYPE_SHAPE, + RENDER_TYPE, + tibetan_scripts, G_N_ELEMENTS(tibetan_scripts) + } +}; + +/* GPOS tables are not present in Joyig font */ +#undef DO_GPOS + +static void +maybe_add_gsub_feature (PangoOTRuleset *ruleset, + PangoOTInfo *info, + guint script_index, + PangoOTTag feature_tag, + gulong property_bit) +{ + guint feature_index; + + /* 0xffff == default language system */ + if (pango_ot_info_find_feature (info, PANGO_OT_TABLE_GSUB, + feature_tag, script_index, 0xffff, &feature_index)) + { + pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GSUB, feature_index, + property_bit); + } +} + +#ifdef DO_GPOS +static void +maybe_add_gpos_feature (PangoOTRuleset *ruleset, + PangoOTInfo *info, + guint script_index, + PangoOTTag feature_tag, + gulong property_bit) +{ + guint feature_index; + + if (pango_ot_info_find_feature (info, PANGO_OT_TABLE_GPOS, + feature_tag, script_index, 0xffff, &feature_index)) + { + pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GPOS, feature_index, + property_bit); + } +} +#endif + +static PangoOTRuleset * +get_gsub_ruleset (FT_Face face) +{ + PangoOTInfo *info = pango_ot_info_get (face); + GQuark ruleset_quark = g_quark_from_string ("tibetan-gsub-ruleset"); + PangoOTRuleset *ruleset; + + if (!info) + return NULL; + + ruleset = g_object_get_qdata (G_OBJECT (info), ruleset_quark); + + if (!ruleset) + { + PangoOTTag tibt_tag = FT_MAKE_TAG ('t', 'i', 'b', 't'); + guint script_index; + + ruleset = pango_ot_ruleset_new (info); + + if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GSUB, + tibt_tag, &script_index)) + { + maybe_add_gsub_feature (ruleset, info, script_index, FT_MAKE_TAG ('c','c','m','p'), 0xFFFF); + maybe_add_gsub_feature (ruleset, info, script_index, FT_MAKE_TAG ('b','l','w','s'), 0xFFFF); + maybe_add_gsub_feature (ruleset, info, script_index, FT_MAKE_TAG ('a','b','v','s'), 0xFFFF); + } + + g_object_set_qdata_full (G_OBJECT (info), ruleset_quark, ruleset, + (GDestroyNotify)g_object_unref); + } + + return ruleset; +} + +static PangoOTRuleset * +get_gpos_ruleset (FT_Face face) +{ +#ifdef DO_GPOS + PangoOTInfo *info = pango_ot_info_get (face); + GQuark ruleset_quark = g_quark_from_string ("tibetan-gpos-ruleset"); + PangoOTRuleset *ruleset; + + if (!info) + return NULL; + + ruleset = g_object_get_qdata (G_OBJECT (info), ruleset_quark); + + if (!ruleset) + { + PangoOTTag tibetan_tag = FT_MAKE_TAG ('t', 'i', 'b', 't'); + guint script_index; + + ruleset = pango_ot_ruleset_new (info); + + if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GPOS, + tibetan_tag, &script_index)) + { + maybe_add_gpos_feature (ruleset, info, script_index, FT_MAKE_TAG ('k','e','r','n'), 0xFFFF); + maybe_add_gpos_feature (ruleset, info, script_index, FT_MAKE_TAG ('m','a','r','k'), 0xFFFF); + maybe_add_gpos_feature (ruleset, info, script_index, FT_MAKE_TAG ('m','k','m','k'), 0xFFFF); + } + + g_object_set_qdata_full (G_OBJECT (info), ruleset_quark, ruleset, + (GDestroyNotify)g_object_unref); + } + + return ruleset; +#else + return NULL; +#endif +} + +static void +set_glyph (PangoFont *font, + PangoGlyphString *glyphs, + int i, + int offset, + PangoGlyph glyph) +{ + PangoRectangle logical_rect; + + glyphs->glyphs[i].glyph = glyph; + + glyphs->glyphs[i].geometry.x_offset = 0; + glyphs->glyphs[i].geometry.y_offset = 0; + + glyphs->log_clusters[i] = offset; + + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, + &logical_rect); + glyphs->glyphs[i].geometry.width = logical_rect.width; +} + +static void +fallback_shape (PangoFont *font, + const char *text, + gint length, + PangoGlyphString *glyphs) +{ + PangoFcFont *fc_font = PANGO_FC_FONT (font); + const char *p; + long n_chars, i; + + n_chars = g_utf8_strlen (text, length); + pango_glyph_string_set_size (glyphs, n_chars); + + for (i = 0, p = text; i < n_chars; i++, p = g_utf8_next_char (p)) + { + gunichar wc; + PangoGlyph index; + + wc = g_utf8_get_char (p); + + index = pango_fc_font_get_glyph (fc_font, wc); + if (!index) + index = pango_fc_font_get_unknown_glyph (fc_font, wc); + + set_glyph (font, glyphs, i, p - text, index); + } +} + +static void +ot_shape (PangoFont *font, + PangoOTRuleset *gsub_ruleset, + PangoOTRuleset *gpos_ruleset, + const char *text, + gint length, + PangoGlyphString *glyphs) +{ + PangoFcFont *fc_font = PANGO_FC_FONT(font); + PangoOTBuffer *buffer = pango_ot_buffer_new (fc_font); + const char *p; + + for (p = text; p - text < length; p = g_utf8_next_char (p)) + { + gunichar wc; + PangoGlyph index; + + wc = g_utf8_get_char (p); + + index = pango_fc_font_get_glyph (fc_font, wc); + if (!index) + index = pango_fc_font_get_unknown_glyph (fc_font, wc); + + pango_ot_buffer_add_glyph (buffer, index, 0, p - text); + } + + if (gsub_ruleset != NULL) + pango_ot_ruleset_substitute (gsub_ruleset, buffer); + + if (gpos_ruleset != NULL) + pango_ot_ruleset_position (gpos_ruleset, buffer); + + pango_ot_buffer_output (buffer, glyphs); + pango_ot_buffer_destroy (buffer); +} + +static void +tibetan_engine_shape (PangoEngineShape *engine, + PangoFont *font, + const char *text, + int length, + PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + PangoFcFont *fc_font = PANGO_FC_FONT(font); + PangoOTRuleset *gsub_ruleset; + PangoOTRuleset *gpos_ruleset; + FT_Face face; + + g_return_if_fail (length >= 0); + + face = pango_fc_font_lock_face (fc_font); + g_assert (face != NULL); + + gsub_ruleset = get_gsub_ruleset (face); + gpos_ruleset = get_gpos_ruleset (face); + + if (gsub_ruleset != NULL) + ot_shape (font, gsub_ruleset, gpos_ruleset, text, length, glyphs); + else + fallback_shape (font, text, length, glyphs); + + pango_fc_font_unlock_face (fc_font); +} + +static void +tibetan_engine_fc_class_init (PangoEngineShapeClass *class) +{ + class->script_shape = tibetan_engine_shape; +} + +PANGO_ENGINE_SHAPE_DEFINE_TYPE (TibetanEngineFc, tibetan_engine_fc, + tibetan_engine_fc_class_init, NULL); + +void +PANGO_MODULE_ENTRY(init) (GTypeModule *module) +{ + tibetan_engine_fc_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) +{ + if (!strcmp (id, SCRIPT_ENGINE_NAME)) + return g_object_new (tibetan_engine_fc_type, NULL); + else + return NULL; +} |