2 * pango-engine.c: Engines for script and language specific processing
4 * Copyright (C) 2003 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include "pango-engine.h"
25 #include "pango-engine-private.h"
26 #include "pango-impl-utils.h"
29 G_DEFINE_ABSTRACT_TYPE (PangoEngine, pango_engine, G_TYPE_OBJECT);
32 pango_engine_init (PangoEngine *self)
37 pango_engine_class_init (PangoEngineClass *klass)
42 G_DEFINE_ABSTRACT_TYPE (PangoEngineLang, pango_engine_lang, PANGO_TYPE_ENGINE);
45 pango_engine_lang_init (PangoEngineLang *self)
50 pango_engine_lang_class_init (PangoEngineLangClass *klass)
55 static PangoCoverageLevel
56 pango_engine_shape_real_covers (PangoEngineShape *engine G_GNUC_UNUSED,
58 PangoLanguage *language,
62 PangoCoverage *coverage = pango_font_get_coverage (font, language);
63 PangoCoverageLevel result = pango_coverage_get (coverage, wc);
65 pango_coverage_unref (coverage);
71 G_DEFINE_ABSTRACT_TYPE (PangoEngineShape, pango_engine_shape, PANGO_TYPE_ENGINE);
74 pango_engine_shape_init (PangoEngineShape *klass)
79 pango_engine_shape_class_init (PangoEngineShapeClass *class)
81 class->covers = pango_engine_shape_real_covers;
85 _pango_engine_shape_shape (PangoEngineShape *engine,
89 const PangoAnalysis *analysis,
90 PangoGlyphString *glyphs)
92 glyphs->num_glyphs = 0;
94 PANGO_ENGINE_SHAPE_GET_CLASS (engine)->script_shape (engine,
102 _pango_engine_shape_covers (PangoEngineShape *engine,
104 PangoLanguage *language,
107 g_return_val_if_fail (PANGO_IS_ENGINE_SHAPE (engine), PANGO_COVERAGE_NONE);
108 g_return_val_if_fail (PANGO_IS_FONT (font), PANGO_COVERAGE_NONE);
110 return PANGO_ENGINE_SHAPE_GET_CLASS (engine)->covers (engine,
116 /* No extra fields needed */
117 typedef PangoEngineShape PangoFallbackEngine;
118 typedef PangoEngineShapeClass PangoFallbackEngineClass;
121 fallback_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
122 PangoFont *font G_GNUC_UNUSED,
125 const PangoAnalysis *analysis,
126 PangoGlyphString *glyphs)
133 n_chars = text ? pango_utf8_strlen (text, length) : 0;
135 pango_glyph_string_set_size (glyphs, n_chars);
138 for (i = 0; i < n_chars; i++)
142 PangoRectangle logical_rect;
144 wc = g_utf8_get_char (p);
146 if (g_unichar_type (wc) != G_UNICODE_NON_SPACING_MARK)
149 if (pango_is_zero_width (wc))
150 glyph = PANGO_GLYPH_EMPTY;
152 glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
154 pango_font_get_glyph_extents (analysis->font, glyph, NULL, &logical_rect);
156 glyphs->glyphs[i].glyph = glyph;
158 glyphs->glyphs[i].geometry.x_offset = 0;
159 glyphs->glyphs[i].geometry.y_offset = 0;
160 glyphs->glyphs[i].geometry.width = logical_rect.width;
162 glyphs->log_clusters[i] = cluster;
164 p = g_utf8_next_char (p);
167 if (analysis->level & 1)
168 pango_glyph_string_reverse_range (glyphs, 0, glyphs->num_glyphs);
171 static PangoCoverageLevel
172 fallback_engine_covers (PangoEngineShape *engine G_GNUC_UNUSED,
173 PangoFont *font G_GNUC_UNUSED,
174 PangoLanguage *lang G_GNUC_UNUSED,
175 gunichar wc G_GNUC_UNUSED)
177 return PANGO_COVERAGE_NONE;
181 static GType pango_fallback_engine_get_type (void);
183 G_DEFINE_TYPE (PangoFallbackEngine, pango_fallback_engine, PANGO_TYPE_ENGINE_SHAPE);
186 pango_fallback_engine_init (PangoFallbackEngine *self)
191 pango_fallback_engine_class_init (PangoFallbackEngineClass *class)
193 class->covers = fallback_engine_covers;
194 class->script_shape = fallback_engine_shape;
198 _pango_get_fallback_shaper (void)
200 static PangoEngineShape *fallback_shaper = NULL;
201 if (!fallback_shaper)
202 fallback_shaper = g_object_new (pango_fallback_engine_get_type (), NULL);
204 return fallback_shaper;