summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-05-16 01:46:05 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-05-16 01:46:05 +0000
commitdefbcdeb2101cd054d2a629a3eb88cb8572c848a (patch)
tree176e9e149a8d7bfd34f38abb05e1093e7e4c4740 /modules
parent1190fec1855ac8e663b827bae442d154bb60881c (diff)
downloadpango-defbcdeb2101cd054d2a629a3eb88cb8572c848a.tar.gz
Port to new OpenType APIs and cleanup a bit. Add standard features.
2007-05-15 Behdad Esfahbod <behdad@gnome.org> * modules/thai/Makefile.am: * modules/thai/thai-fc.c (thai_get_font_info), (thai_engine_shape), (thai_make_unknown_glyph): * modules/thai/thai-shaper.c (get_glyphs_list), (add_cluster), (thai_set_glyphs): * modules/thai/thai-shaper.h: Port to new OpenType APIs and cleanup a bit. Add standard features. * modules/thai/thai-ot.c: * modules/thai/thai-ot.h: Removed. Not needed anymore. svn path=/trunk/; revision=2309
Diffstat (limited to 'modules')
-rw-r--r--modules/thai/Makefile.am2
-rw-r--r--modules/thai/thai-fc.c91
-rw-r--r--modules/thai/thai-ot.c253
-rw-r--r--modules/thai/thai-ot.h36
-rw-r--r--modules/thai/thai-shaper.c32
-rw-r--r--modules/thai/thai-shaper.h18
6 files changed, 101 insertions, 331 deletions
diff --git a/modules/thai/Makefile.am b/modules/thai/Makefile.am
index 9a8c2140..e46f2573 100644
--- a/modules/thai/Makefile.am
+++ b/modules/thai/Makefile.am
@@ -13,7 +13,7 @@ endif
endif
endif
-thai_fc_sources = $(shaper_sources) thai-fc.c thai-ot.c thai-ot.h
+thai_fc_sources = $(shaper_sources) thai-fc.c
pango_thai_fc_la_LDFLAGS = -module $(MODULE_LIBTOOL_OPTIONS)
pango_thai_fc_la_LIBADD = $(pangoft2libs)
diff --git a/modules/thai/thai-fc.c b/modules/thai/thai-fc.c
index 40ba8842..68459926 100644
--- a/modules/thai/thai-fc.c
+++ b/modules/thai/thai-fc.c
@@ -31,11 +31,11 @@
#include <string.h>
#include <glib.h>
+#include "pango-ot.h"
#include "pango-engine.h"
#include "pangofc-font.h"
#include "thai-shaper.h"
-#include "thai-ot.h"
/* No extra fields needed */
typedef PangoEngineShape ThaiEngineFc;
@@ -157,15 +157,19 @@ contain_glyphs(PangoFont *font, const int glyph_map[128])
/* 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_get_font_info (PangoFont *font,
+ const PangoOTRuleset *ruleset)
{
ThaiFontInfo *font_info;
- GQuark info_id = g_quark_from_string ("thai-font-info");
+ static GQuark info_id = 0;
+
+ if (G_UNLIKELY (!info_id))
+ info_id = g_quark_from_string ("thai-font-info");
font_info = g_object_get_qdata (G_OBJECT (font), info_id);
- if (!font_info)
+ if (G_UNLIKELY (!font_info))
{
/* No cached information not found, so we need to compute it
* from scratch
@@ -174,7 +178,7 @@ thai_get_font_info (PangoFont *font)
font_info->font = font;
/* detect font set by determining availibility of OT ruleset & glyphs */
- if (thai_ot_get_ruleset (font))
+ if (pango_ot_ruleset_get_feature_count (ruleset, NULL, NULL))
font_info->font_set = THAI_FONT_TIS;
else if (contain_glyphs(font, tis620_2))
font_info->font_set = THAI_FONT_TIS_WIN;
@@ -234,10 +238,83 @@ thai_make_glyph_uni (ThaiFontInfo *font_info, gunichar uc)
return PANGO_GET_UNKNOWN_GLYPH ( uc);
}
+static const PangoOTFeatureMap gsub_features[] =
+{
+ {"ccmp", PANGO_OT_ALL_GLYPHS},
+ {"locl", PANGO_OT_ALL_GLYPHS},
+ {"liga", PANGO_OT_ALL_GLYPHS},
+};
+
+static const PangoOTFeatureMap gpos_features[] =
+{
+ {"kern", PANGO_OT_ALL_GLYPHS},
+ {"mark", PANGO_OT_ALL_GLYPHS},
+ {"mkmk", PANGO_OT_ALL_GLYPHS}
+};
+
+static void
+thai_engine_shape (PangoEngineShape *engine,
+ PangoFont *font,
+ const char *text,
+ gint length,
+ const PangoAnalysis *analysis,
+ PangoGlyphString *glyphs)
+{
+ PangoFcFont *fc_font;
+ FT_Face face;
+ PangoOTRulesetDescription desc;
+ const PangoOTRuleset *ruleset;
+ PangoOTBuffer *buffer;
+ gint i;
+ ThaiFontInfo *font_info;
+
+ g_return_if_fail (font != NULL);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (length >= 0);
+ g_return_if_fail (analysis != NULL);
+
+ fc_font = PANGO_FC_FONT (font);
+ face = pango_fc_font_lock_face (fc_font);
+ if (!face)
+ return;
+
+ desc.script = analysis->script;
+ desc.language = analysis->language;
+
+ desc.n_static_gsub_features = G_N_ELEMENTS (gsub_features);
+ desc.static_gsub_features = gsub_features;
+ desc.n_static_gpos_features = G_N_ELEMENTS (gpos_features);
+ desc.static_gpos_features = gpos_features;
+
+ /* TODO populate other_features from analysis->extra_attrs */
+ desc.n_other_features = 0;
+ desc.other_features = NULL;
+
+ ruleset = pango_ot_ruleset_get_for (pango_ot_info_get (face), &desc);
+
+ font_info = thai_get_font_info (font, ruleset);
+
+ thai_set_glyphs (font_info, text, length, analysis->script, glyphs);
+
+ buffer = pango_ot_buffer_new (PANGO_FC_FONT (font));
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ pango_ot_buffer_add_glyph (buffer,
+ glyphs->glyphs[i].glyph,
+ 0,
+ glyphs->log_clusters[i]);
+
+ pango_ot_ruleset_substitute (ruleset, buffer);
+ pango_ot_ruleset_position (ruleset, buffer);
+
+ pango_ot_buffer_output (buffer, glyphs);
+ pango_ot_buffer_destroy (buffer);
+}
+
PangoGlyph
thai_make_unknown_glyph (ThaiFontInfo *font_info, gunichar uc)
{
- return PANGO_GET_UNKNOWN_GLYPH ( uc);
+ return PANGO_GET_UNKNOWN_GLYPH (uc);
}
static void
diff --git a/modules/thai/thai-ot.c b/modules/thai/thai-ot.c
deleted file mode 100644
index d947d1f7..00000000
--- a/modules/thai/thai-ot.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/* Pango
- * thai-ot.c:
- *
- * Copyright (C) 2004 Theppitak Karoonboonyanan
- * Author: 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include <config.h>
-#include <string.h>
-
-#include "thai-ot.h"
-
-static gint
-maybe_add_gsub_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_GSUB,
- feature_tag, script_index, PANGO_OT_DEFAULT_LANGUAGE, &feature_index))
- {
- pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GSUB, feature_index,
- property_bit);
- return 1;
- }
- return 0;
-}
-
-static gint
-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, PANGO_OT_DEFAULT_LANGUAGE, &feature_index))
- {
- pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GPOS, feature_index,
- property_bit);
- return 1;
- }
- return 0;
-}
-
-PangoOTRuleset *
-thai_ot_get_ruleset (PangoFont *font)
-{
- PangoFcFont *fc_font;
- FT_Face face;
- PangoOTInfo *info;
- PangoOTRuleset *ruleset = NULL;
-
- g_return_val_if_fail (font != NULL, NULL);
-
- fc_font = PANGO_FC_FONT (font);
- face = pango_fc_font_lock_face (fc_font);
- if (!face)
- return NULL;
-
- info = pango_ot_info_get (face);
- if (info != NULL)
- {
- static GQuark ruleset_quark = 0;
-
- if (!ruleset_quark)
- ruleset_quark = g_quark_from_string ("thai-ot-ruleset");
-
- ruleset = g_object_get_qdata (G_OBJECT (info), ruleset_quark);
- if (!ruleset)
- {
- PangoOTTag thai_tag = FT_MAKE_TAG ('t', 'h', 'a', 'i');
- guint script_index;
- gint n = 0;
-
- ruleset = pango_ot_ruleset_new (info);
-
- if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GSUB,
- thai_tag, &script_index))
- {
- n += maybe_add_gsub_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('c','c','m','p'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gsub_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('l','i','g','a'),
- PANGO_OT_ALL_GLYPHS);
- }
-
- if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GPOS,
- thai_tag, &script_index))
- {
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('k','e','r','n'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('m','a','r','k'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('m','k','m','k'),
- PANGO_OT_ALL_GLYPHS);
- }
-
- if (n > 0)
- g_object_set_qdata_full (G_OBJECT (info), ruleset_quark, ruleset,
- (GDestroyNotify)g_object_unref);
- else
- {
- g_object_unref (ruleset);
- ruleset = NULL;
- }
- }
- }
-
- pango_fc_font_unlock_face (fc_font);
-
- return ruleset;
-}
-
-static PangoOTRuleset *
-lao_ot_get_ruleset (PangoFont *font)
-{
- PangoFcFont *fc_font;
- FT_Face face;
- PangoOTInfo *info;
- PangoOTRuleset *ruleset = NULL;
-
- g_return_val_if_fail (font != NULL, NULL);
-
- fc_font = PANGO_FC_FONT (font);
- face = pango_fc_font_lock_face (fc_font);
- if (!face)
- return NULL;
-
- info = pango_ot_info_get (face);
- if (info != NULL)
- {
- static GQuark ruleset_quark = 0;
-
- if (!ruleset_quark)
- ruleset_quark = g_quark_from_string ("lao-ot-ruleset");
-
- ruleset = g_object_get_qdata (G_OBJECT (info), ruleset_quark);
- if (!ruleset)
- {
- PangoOTTag thai_tag = FT_MAKE_TAG ('l', 'a', 'o', ' ');
- guint script_index;
- gint n = 0;
-
- ruleset = pango_ot_ruleset_new (info);
-
- if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GSUB,
- thai_tag, &script_index))
- {
- n += maybe_add_gsub_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('c','c','m','p'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gsub_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('l','i','g','a'),
- PANGO_OT_ALL_GLYPHS);
- }
-
- if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GPOS,
- thai_tag, &script_index))
- {
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('k','e','r','n'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('m','a','r','k'),
- PANGO_OT_ALL_GLYPHS);
- n += maybe_add_gpos_feature (ruleset, info, script_index,
- FT_MAKE_TAG ('m','k','m','k'),
- PANGO_OT_ALL_GLYPHS);
- }
-
- if (n > 0)
- g_object_set_qdata_full (G_OBJECT (info), ruleset_quark, ruleset,
- (GDestroyNotify)g_object_unref);
- else
- {
- g_object_unref (ruleset);
- ruleset = NULL;
- }
- }
- }
-
- pango_fc_font_unlock_face (fc_font);
-
- return ruleset;
-}
-
-
-void
-thai_ot_shape (PangoFont *font,
- PangoGlyphString *glyphs)
-{
- PangoOTRuleset *th_ruleset;
- PangoOTRuleset *lo_ruleset;
-
- th_ruleset = thai_ot_get_ruleset (font);
- lo_ruleset = lao_ot_get_ruleset (font);
-
- if (th_ruleset != NULL || lo_ruleset != NULL)
- {
- gint i;
- PangoOTBuffer *buffer;
-
- /* prepare ot buffer */
- buffer = pango_ot_buffer_new (PANGO_FC_FONT (font));
- for (i = 0; i < glyphs->num_glyphs; i++)
- {
- pango_ot_buffer_add_glyph (buffer,
- glyphs->glyphs[i].glyph,
- 0,
- glyphs->log_clusters[i]);
- }
-
- if (th_ruleset != NULL)
- {
- pango_ot_ruleset_substitute (th_ruleset, buffer);
- pango_ot_ruleset_position (th_ruleset, buffer);
- }
- if (lo_ruleset != NULL)
- {
- pango_ot_ruleset_substitute (lo_ruleset, buffer);
- pango_ot_ruleset_position (lo_ruleset, buffer);
- }
-
- pango_ot_buffer_output (buffer, glyphs);
- pango_ot_buffer_destroy (buffer);
- }
-}
-
diff --git a/modules/thai/thai-ot.h b/modules/thai/thai-ot.h
deleted file mode 100644
index 21f713c5..00000000
--- a/modules/thai/thai-ot.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Pango
- * thai-ot.h:
- *
- * Copyright (C) 2004 Theppitak Karoonboonyanan
- * Author: 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __THAI_OT_H__
-#define __THAI_OT_H__
-
-#include "pango-ot.h"
-
-PangoOTRuleset *
-thai_ot_get_ruleset (PangoFont *font);
-
-void
-thai_ot_shape (PangoFont *font,
- PangoGlyphString *glyphs);
-
-#endif /* __THAI_OT_H__ */
-
diff --git a/modules/thai/thai-shaper.c b/modules/thai/thai-shaper.c
index 91cdbf89..580f1462 100644
--- a/modules/thai/thai-shaper.c
+++ b/modules/thai/thai-shaper.c
@@ -33,7 +33,6 @@
#include "pango-engine.h"
#include "thai-charprop.h"
#include "thai-shaper.h"
-#include "thai-ot.h"
#define MAX_CLUSTER_CHRS 256
#define MAX_GLYPHS 256
@@ -392,13 +391,14 @@ get_adjusted_glyphs_list (ThaiFontInfo *font_info,
static gint
get_glyphs_list (ThaiFontInfo *font_info,
+ PangoScript script,
gunichar *cluster,
gint num_chrs,
PangoGlyph *glyph_lists)
{
gint i;
- switch (pango_script_for_unichar (cluster[0]))
+ switch (script)
{
case PANGO_SCRIPT_THAI:
switch (font_info->font_set)
@@ -444,6 +444,7 @@ get_glyphs_list (ThaiFontInfo *font_info,
static void
add_cluster (ThaiFontInfo *font_info,
+ PangoScript script,
PangoGlyphString *glyphs,
gint cluster_start,
gunichar *cluster,
@@ -455,14 +456,14 @@ add_cluster (ThaiFontInfo *font_info,
if (isthai (cluster[0]))
{
- num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, glyphs_list);
+ num_glyphs = get_glyphs_list(font_info, script, cluster, num_chrs, glyphs_list);
for (i=0; i<num_glyphs; i++)
add_glyph (font_info, glyphs, cluster_start, glyphs_list[i],
i == 0 ? FALSE : TRUE);
}
else if (islao (cluster[0]))
{
- num_glyphs = get_glyphs_list(font_info, cluster, num_chrs, glyphs_list);
+ num_glyphs = get_glyphs_list(font_info, script, cluster, num_chrs, glyphs_list);
for (i=0; i<num_glyphs; i++)
add_glyph (font_info, glyphs, cluster_start, glyphs_list[i],
i == 0 ? FALSE : TRUE);
@@ -524,35 +525,24 @@ get_next_cluster(const char *text,
}
void
-thai_engine_shape (PangoEngineShape *engine,
- PangoFont *font,
- const char *text,
- gint length,
- const PangoAnalysis *analysis,
- PangoGlyphString *glyphs)
+thai_set_glyphs (ThaiFontInfo *font_info,
+ const char *text,
+ gint length,
+ PangoScript script,
+ PangoGlyphString *glyphs)
{
gint n_chars;
const char *p;
- ThaiFontInfo *font_info;
const char *log_cluster;
gunichar cluster[MAX_CLUSTER_CHRS];
- g_return_if_fail (font != NULL);
- g_return_if_fail (text != NULL);
- g_return_if_fail (length >= 0);
- g_return_if_fail (analysis != NULL);
-
pango_glyph_string_set_size (glyphs, 0);
- font_info = thai_get_font_info (font);
-
p = text;
while (p < text + length)
{
log_cluster = p;
p = get_next_cluster (p, text + length - p, cluster, &n_chars);
- add_cluster (font_info, glyphs, log_cluster - text, cluster, n_chars);
+ add_cluster (font_info, script, glyphs, log_cluster - text, cluster, n_chars);
}
- thai_ot_shape (font, glyphs);
}
-
diff --git a/modules/thai/thai-shaper.h b/modules/thai/thai-shaper.h
index ea3c4039..cb2f7edc 100644
--- a/modules/thai/thai-shaper.h
+++ b/modules/thai/thai-shaper.h
@@ -55,9 +55,6 @@ struct _ThaiFontInfo
/*
* Abstract methods (implemented by each shaper module)
*/
-ThaiFontInfo *
-thai_get_font_info (PangoFont *font);
-
PangoGlyph
thai_get_glyph_tis (ThaiFontInfo *font_info, guchar c);
@@ -73,16 +70,11 @@ thai_make_glyph_uni (ThaiFontInfo *font_info, gunichar uc);
PangoGlyph
thai_make_unknown_glyph (ThaiFontInfo *font_info, gunichar uc);
-/*
- * Public functions
- */
void
-thai_engine_shape (PangoEngineShape *engine,
- PangoFont *font,
- const char *text,
- gint length,
- const PangoAnalysis *analysis,
- PangoGlyphString *glyphs);
+thai_set_glyphs (ThaiFontInfo *font_info,
+ const char *text,
+ gint length,
+ PangoScript script,
+ PangoGlyphString *glyphs);
#endif /* __THAI_SHAPER_H__ */
-