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"
28 PANGO_DEFINE_TYPE_ABSTRACT (PangoEngine, pango_engine,
32 PANGO_DEFINE_TYPE_ABSTRACT (PangoEngineLang, pango_engine_lang,
36 static PangoCoverageLevel
37 pango_engine_shape_real_covers (PangoEngineShape *engine G_GNUC_UNUSED,
39 PangoLanguage *language,
43 PangoCoverage *coverage = pango_font_get_coverage (font, language);
44 PangoCoverageLevel result = pango_coverage_get (coverage, wc);
46 pango_coverage_unref (coverage);
52 pango_engine_shape_class_init (PangoEngineShapeClass *class)
54 class->covers = pango_engine_shape_real_covers;
57 PANGO_DEFINE_TYPE_ABSTRACT (PangoEngineShape, pango_engine_shape,
58 pango_engine_shape_class_init, NULL,
62 _pango_engine_shape_shape (PangoEngineShape *engine,
66 const PangoAnalysis *analysis,
67 PangoGlyphString *glyphs)
69 glyphs->num_glyphs = 0;
71 PANGO_ENGINE_SHAPE_GET_CLASS (engine)->script_shape (engine,
79 _pango_engine_shape_covers (PangoEngineShape *engine,
81 PangoLanguage *language,
84 g_return_val_if_fail (PANGO_IS_ENGINE_SHAPE (engine), PANGO_COVERAGE_NONE);
85 g_return_val_if_fail (PANGO_IS_FONT (font), PANGO_COVERAGE_NONE);
87 return PANGO_ENGINE_SHAPE_GET_CLASS (engine)->covers (engine,
93 /* No extra fields needed */
94 typedef PangoEngineShape PangoFallbackEngine;
95 typedef PangoEngineShapeClass PangoFallbackEngineClass;
98 fallback_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED,
99 PangoFont *font G_GNUC_UNUSED,
102 const PangoAnalysis *analysis,
103 PangoGlyphString *glyphs)
110 n_chars = text ? pango_utf8_strlen (text, length) : 0;
112 pango_glyph_string_set_size (glyphs, n_chars);
115 for (i = 0; i < n_chars; i++)
119 PangoRectangle logical_rect;
121 wc = g_utf8_get_char (p);
123 if (g_unichar_type (wc) != G_UNICODE_NON_SPACING_MARK)
126 if (pango_is_zero_width (wc))
127 glyph = PANGO_GLYPH_EMPTY;
129 glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
131 pango_font_get_glyph_extents (analysis->font, glyph, NULL, &logical_rect);
133 glyphs->glyphs[i].glyph = glyph;
135 glyphs->glyphs[i].geometry.x_offset = 0;
136 glyphs->glyphs[i].geometry.y_offset = 0;
137 glyphs->glyphs[i].geometry.width = logical_rect.width;
139 glyphs->log_clusters[i] = cluster;
141 p = g_utf8_next_char (p);
144 if (analysis->level & 1)
145 pango_glyph_string_reverse_range (glyphs, 0, glyphs->num_glyphs);
148 static PangoCoverageLevel
149 fallback_engine_covers (PangoEngineShape *engine G_GNUC_UNUSED,
150 PangoFont *font G_GNUC_UNUSED,
151 PangoLanguage *lang G_GNUC_UNUSED,
152 gunichar wc G_GNUC_UNUSED)
154 return PANGO_COVERAGE_NONE;
158 fallback_engine_class_init (PangoEngineShapeClass *class)
160 class->covers = fallback_engine_covers;
161 class->script_shape = fallback_engine_shape;
164 static PANGO_DEFINE_TYPE (PangoFallbackEngine, pango_fallback_engine,
165 fallback_engine_class_init, NULL,
166 PANGO_TYPE_ENGINE_SHAPE)
169 _pango_get_fallback_shaper (void)
171 static PangoEngineShape *fallback_shaper = NULL;
172 if (!fallback_shaper)
173 fallback_shaper = g_object_new (pango_fallback_engine_get_type (), NULL);
175 return fallback_shaper;