4 * Copyright (C) 2000, 2003, 2007 Red Hat Software
5 * Copyright (C) 2004 Emil Soleyman-Zomalan
7 * Owen Taylor <otaylor@redhat.com>
8 * Emil Soleyman-Zomalan <emil@soleyman.com>
9 * Behdad Esfahbod <behdad@behdad.org>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
29 #include "syriac-ot.h"
31 #include "pango-engine.h"
32 #include "pango-utils.h"
33 #include "pangofc-font.h"
35 /* No extra fields needed */
36 typedef PangoEngineShape SyriacEngineFc;
37 typedef PangoEngineShapeClass SyriacEngineFcClass ;
39 #define SCRIPT_ENGINE_NAME "SyriacScriptEngineFc"
40 #define RENDER_TYPE PANGO_RENDER_TYPE_FC
42 static PangoEngineScriptInfo syriac_scripts[] = {
43 { PANGO_SCRIPT_SYRIAC, "*" },
46 static PangoEngineInfo script_engines[] = {
49 PANGO_ENGINE_TYPE_SHAPE,
51 syriac_scripts, G_N_ELEMENTS(syriac_scripts)
55 static const PangoOTFeatureMap gsub_features[] =
57 {"ccmp", PANGO_OT_ALL_GLYPHS},
58 {"locl", PANGO_OT_ALL_GLYPHS},
66 {"rlig", PANGO_OT_ALL_GLYPHS},
67 {"calt", PANGO_OT_ALL_GLYPHS},
68 {"liga", PANGO_OT_ALL_GLYPHS},
69 /* 'dlig' should be turned-on/off-able. lets turn off for now. */
70 /* {"dlig", PANGO_OT_ALL_GLYPHS}, */
73 static const PangoOTFeatureMap gpos_features[] =
75 {"kern", PANGO_OT_ALL_GLYPHS},
76 {"mark", PANGO_OT_ALL_GLYPHS},
77 {"mkmk", PANGO_OT_ALL_GLYPHS}
81 syriac_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
85 const PangoAnalysis *analysis,
86 PangoGlyphString *glyphs)
90 PangoOTRulesetDescription desc;
91 const PangoOTRuleset *ruleset;
92 PangoOTBuffer *buffer;
93 gulong *properties = NULL;
100 g_return_if_fail (font != NULL);
101 g_return_if_fail (text != NULL);
102 g_return_if_fail (length >= 0);
103 g_return_if_fail (analysis != NULL);
105 fc_font = PANGO_FC_FONT (font);
106 face = pango_fc_font_lock_face (fc_font);
110 buffer = pango_ot_buffer_new (fc_font);
111 pango_ot_buffer_set_rtl (buffer, analysis->level % 2 != 0);
112 pango_ot_buffer_set_zero_width_marks (buffer, TRUE);
114 wcs = g_utf8_to_ucs4_fast (text, length, &n_chars);
115 properties = g_new0 (gulong, n_chars);
117 syriac_assign_properties (wcs, properties, n_chars);
122 for (i=0; i < n_chars; i++)
127 wc = g_utf8_get_char (p);
129 if (g_unichar_type (wc) != G_UNICODE_NON_SPACING_MARK)
132 if (pango_is_zero_width (wc))
133 glyph = PANGO_GLYPH_EMPTY;
138 if (analysis->level % 2)
139 g_unichar_get_mirror_char (c, &c);
141 glyph = pango_fc_font_get_glyph (fc_font, c);
145 glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
147 pango_ot_buffer_add_glyph (buffer, glyph, properties[i], cluster);
149 p = g_utf8_next_char (p);
154 desc.script = analysis->script;
155 desc.language = analysis->language;
157 desc.n_static_gsub_features = G_N_ELEMENTS (gsub_features);
158 desc.static_gsub_features = gsub_features;
159 desc.n_static_gpos_features = G_N_ELEMENTS (gpos_features);
160 desc.static_gpos_features = gpos_features;
162 /* TODO populate other_features from analysis->extra_attrs */
163 desc.n_other_features = 0;
164 desc.other_features = NULL;
166 ruleset = pango_ot_ruleset_get_for_description (pango_ot_info_get (face), &desc);
168 pango_ot_ruleset_substitute (ruleset, buffer);
169 pango_ot_ruleset_position (ruleset, buffer);
170 pango_ot_buffer_output (buffer, glyphs);
172 pango_ot_buffer_destroy (buffer);
174 pango_fc_font_unlock_face (fc_font);
178 syriac_engine_fc_class_init (PangoEngineShapeClass *class)
180 class->script_shape = syriac_engine_shape;
183 PANGO_ENGINE_SHAPE_DEFINE_TYPE (SyriacEngineFc, syriac_engine_fc,
184 syriac_engine_fc_class_init, NULL)
187 PANGO_MODULE_ENTRY(init) (GTypeModule *module)
189 syriac_engine_fc_register_type (module);
193 PANGO_MODULE_ENTRY(exit) (void)
198 PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines,
201 *engines = script_engines;
202 *n_engines = G_N_ELEMENTS (script_engines);
206 PANGO_MODULE_ENTRY(create) (const char *id)
208 if (!strcmp (id, SCRIPT_ENGINE_NAME))
209 return g_object_new (syriac_engine_fc_type, NULL);