2 * arabic-fc.c: Arabic shaper for FreeType-based backends
4 * Copyright (C) 2000, 2003, 2007 Red Hat Software
6 * Owen Taylor <otaylor@redhat.com>
7 * Behdad Esfahbod <behdad@behdad.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
28 #include "arabic-ot.h"
30 #include "pango-engine.h"
31 #include "pango-utils.h"
32 #include "pangofc-font.h"
34 /* No extra fields needed */
35 typedef PangoEngineShape ArabicEngineFc;
36 typedef PangoEngineShapeClass ArabicEngineFcClass ;
38 #define SCRIPT_ENGINE_NAME "ArabicScriptEngineFc"
39 #define RENDER_TYPE PANGO_RENDER_TYPE_FC
41 static PangoEngineScriptInfo arabic_scripts[] = {
42 { PANGO_SCRIPT_ARABIC, "*" },
43 { PANGO_SCRIPT_NKO, "*" }
46 static PangoEngineInfo script_engines[] = {
49 PANGO_ENGINE_TYPE_SHAPE,
51 arabic_scripts, G_N_ELEMENTS(arabic_scripts)
55 static const PangoOTFeatureMap gsub_features[] =
57 {"ccmp", PANGO_OT_ALL_GLYPHS},
58 {"locl", PANGO_OT_ALL_GLYPHS},
63 {"rlig", PANGO_OT_ALL_GLYPHS},
64 {"calt", PANGO_OT_ALL_GLYPHS},
65 {"liga", PANGO_OT_ALL_GLYPHS},
66 /* 'dlig' should be turned-on/off-able. lets turn off for now. */
67 /* {"dlig", PANGO_OT_ALL_GLYPHS}, */
68 {"cswh", PANGO_OT_ALL_GLYPHS},
69 {"mset", PANGO_OT_ALL_GLYPHS}
72 static const PangoOTFeatureMap gpos_features[] =
74 {"curs", PANGO_OT_ALL_GLYPHS},
75 {"kern", PANGO_OT_ALL_GLYPHS},
76 {"mark", PANGO_OT_ALL_GLYPHS},
77 {"mkmk", PANGO_OT_ALL_GLYPHS}
81 arabic_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;
98 gboolean rtl = analysis->level % 2 != 0;
102 g_return_if_fail (font != NULL);
103 g_return_if_fail (text != NULL);
104 g_return_if_fail (length >= 0);
105 g_return_if_fail (analysis != NULL);
107 fc_font = PANGO_FC_FONT (font);
108 face = pango_fc_font_lock_face (fc_font);
112 buffer = pango_ot_buffer_new (fc_font);
113 pango_ot_buffer_set_rtl (buffer, rtl);
114 pango_ot_buffer_set_zero_width_marks (buffer, TRUE);
116 wcs = g_utf8_to_ucs4_fast (text, length, &n_chars);
117 properties = g_new0 (gulong, n_chars);
119 reverse = !rtl ^ (analysis->gravity == PANGO_GRAVITY_NORTH || analysis->gravity == PANGO_GRAVITY_WEST);
120 Arabic_Assign_Properties (wcs, properties, n_chars, reverse);
125 for (i=0; i < n_chars; i++)
130 wc = g_utf8_get_char (p);
132 if (g_unichar_type (wc) != G_UNICODE_NON_SPACING_MARK)
135 if (pango_is_zero_width (wc))
136 glyph = PANGO_GLYPH_EMPTY;
141 if (analysis->level % 2)
142 g_unichar_get_mirror_char (c, &c);
144 /* Hack - Microsoft fonts are strange and don't contain the
145 * correct rules to shape ARABIC LETTER FARSI YEH in
146 * medial/initial position. It looks identical to ARABIC LETTER
147 * YEH in these positions, so we substitute if the font contains
151 ((properties[i] & (initial | medial)) != (initial | medial)) &&
152 pango_fc_font_has_char (fc_font, 0x64a))
155 glyph = pango_fc_font_get_glyph (fc_font, c);
159 glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
161 pango_ot_buffer_add_glyph (buffer, glyph, properties[i], cluster);
163 p = g_utf8_next_char (p);
168 desc.script = analysis->script;
169 desc.language = analysis->language;
171 desc.n_static_gsub_features = G_N_ELEMENTS (gsub_features);
172 desc.static_gsub_features = gsub_features;
173 desc.n_static_gpos_features = G_N_ELEMENTS (gpos_features);
174 desc.static_gpos_features = gpos_features;
176 /* TODO populate other_features from analysis->extra_attrs */
177 desc.n_other_features = 0;
178 desc.other_features = NULL;
180 ruleset = pango_ot_ruleset_get_for_description (pango_ot_info_get (face), &desc);
182 pango_ot_ruleset_substitute (ruleset, buffer);
183 pango_ot_ruleset_position (ruleset, buffer);
184 pango_ot_buffer_output (buffer, glyphs);
186 pango_ot_buffer_destroy (buffer);
188 pango_fc_font_unlock_face (fc_font);
192 arabic_engine_fc_class_init (PangoEngineShapeClass *class)
194 class->script_shape = arabic_engine_shape;
197 PANGO_ENGINE_SHAPE_DEFINE_TYPE (ArabicEngineFc, arabic_engine_fc,
198 arabic_engine_fc_class_init, NULL)
201 PANGO_MODULE_ENTRY(init) (GTypeModule *module)
203 arabic_engine_fc_register_type (module);
207 PANGO_MODULE_ENTRY(exit) (void)
212 PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines,
215 *engines = script_engines;
216 *n_engines = G_N_ELEMENTS (script_engines);
220 PANGO_MODULE_ENTRY(create) (const char *id)
222 if (!strcmp (id, SCRIPT_ENGINE_NAME))
223 return g_object_new (arabic_engine_fc_type, NULL);