Git init
[external/pango1.0.git] / modules / syriac / syriac-fc.c
1 /* Pango
2  * syriac-fc.h:
3  *
4  * Copyright (C) 2000, 2003, 2007 Red Hat Software
5  * Copyright (C) 2004 Emil Soleyman-Zomalan
6  * Authors:
7  *   Owen Taylor <otaylor@redhat.com>
8  *   Emil Soleyman-Zomalan <emil@soleyman.com>
9  *   Behdad Esfahbod <behdad@behdad.org>
10  *
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.
15  *
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.
20  *
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.
25  */
26 #include "config.h"
27 #include <string.h>
28
29 #include "syriac-ot.h"
30
31 #include "pango-engine.h"
32 #include "pango-utils.h"
33 #include "pangofc-font.h"
34
35 /* No extra fields needed */
36 typedef PangoEngineShape      SyriacEngineFc;
37 typedef PangoEngineShapeClass SyriacEngineFcClass ;
38
39 #define SCRIPT_ENGINE_NAME "SyriacScriptEngineFc"
40 #define RENDER_TYPE PANGO_RENDER_TYPE_FC
41
42 static PangoEngineScriptInfo syriac_scripts[] = {
43   { PANGO_SCRIPT_SYRIAC, "*" },
44 };
45
46 static PangoEngineInfo script_engines[] = {
47   {
48     SCRIPT_ENGINE_NAME,
49     PANGO_ENGINE_TYPE_SHAPE,
50     RENDER_TYPE,
51     syriac_scripts, G_N_ELEMENTS(syriac_scripts)
52   }
53 };
54
55 static const PangoOTFeatureMap gsub_features[] =
56 {
57   {"ccmp", PANGO_OT_ALL_GLYPHS},
58   {"locl", PANGO_OT_ALL_GLYPHS},
59   {"isol", isolated},
60   {"fina", final},
61   {"fin2", final2},
62   {"fin3", final3},
63   {"medi", medial},
64   {"med2", medial2},
65   {"init", initial},
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}, */
71 };
72
73 static const PangoOTFeatureMap gpos_features[] =
74 {
75   {"kern", PANGO_OT_ALL_GLYPHS},
76   {"mark", PANGO_OT_ALL_GLYPHS},
77   {"mkmk", PANGO_OT_ALL_GLYPHS}
78 };
79
80 static void
81 syriac_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
82                      PangoFont        *font,
83                      const char       *text,
84                      gint              length,
85                      const PangoAnalysis *analysis,
86                      PangoGlyphString *glyphs)
87 {
88   PangoFcFont *fc_font;
89   FT_Face face;
90   PangoOTRulesetDescription desc;
91   const PangoOTRuleset *ruleset;
92   PangoOTBuffer *buffer;
93   gulong *properties = NULL;
94   glong n_chars;
95   gunichar *wcs;
96   const char *p;
97   int cluster = 0;
98   int i;
99
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);
104
105   fc_font = PANGO_FC_FONT (font);
106   face = pango_fc_font_lock_face (fc_font);
107   if (!face)
108     return;
109
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);
113
114   wcs = g_utf8_to_ucs4_fast (text, length, &n_chars);
115   properties = g_new0 (gulong, n_chars);
116
117   syriac_assign_properties (wcs, properties, n_chars);
118
119   g_free (wcs);
120
121   p = text;
122   for (i=0; i < n_chars; i++)
123     {
124       gunichar wc;
125       PangoGlyph glyph;
126
127       wc = g_utf8_get_char (p);
128
129       if (g_unichar_type (wc) != G_UNICODE_NON_SPACING_MARK)
130         cluster = p - text;
131
132       if (pango_is_zero_width (wc))
133         glyph = PANGO_GLYPH_EMPTY;
134       else
135         {
136           gunichar c = wc;
137
138           if (analysis->level % 2)
139             g_unichar_get_mirror_char (c, &c);
140
141           glyph = pango_fc_font_get_glyph (fc_font, c);
142         }
143
144       if (!glyph)
145         glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
146
147       pango_ot_buffer_add_glyph (buffer, glyph, properties[i], cluster);
148
149       p = g_utf8_next_char (p);
150     }
151
152   g_free (properties);
153
154   desc.script = analysis->script;
155   desc.language = analysis->language;
156
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;
161
162   /* TODO populate other_features from analysis->extra_attrs */
163   desc.n_other_features = 0;
164   desc.other_features = NULL;
165
166   ruleset = pango_ot_ruleset_get_for_description (pango_ot_info_get (face), &desc);
167
168   pango_ot_ruleset_substitute (ruleset, buffer);
169   pango_ot_ruleset_position (ruleset, buffer);
170   pango_ot_buffer_output (buffer, glyphs);
171
172   pango_ot_buffer_destroy (buffer);
173
174   pango_fc_font_unlock_face (fc_font);
175 }
176
177 static void
178 syriac_engine_fc_class_init (PangoEngineShapeClass *class)
179 {
180   class->script_shape = syriac_engine_shape;
181 }
182
183 PANGO_ENGINE_SHAPE_DEFINE_TYPE (SyriacEngineFc, syriac_engine_fc,
184                                 syriac_engine_fc_class_init, NULL)
185
186 void
187 PANGO_MODULE_ENTRY(init) (GTypeModule *module)
188 {
189   syriac_engine_fc_register_type (module);
190 }
191
192 void
193 PANGO_MODULE_ENTRY(exit) (void)
194 {
195 }
196
197 void
198 PANGO_MODULE_ENTRY(list) (PangoEngineInfo **engines,
199                           int              *n_engines)
200 {
201   *engines = script_engines;
202   *n_engines = G_N_ELEMENTS (script_engines);
203 }
204
205 PangoEngine *
206 PANGO_MODULE_ENTRY(create) (const char *id)
207 {
208   if (!strcmp (id, SCRIPT_ENGINE_NAME))
209     return g_object_new (syriac_engine_fc_type, NULL);
210   else
211     return NULL;
212 }