summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-12-20 04:41:36 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-12-20 04:41:36 +0000
commit6ffa65f461d8a78d9190c0d9903a9ecd7273774a (patch)
treef4245e3e7e13771b62224fbdf473edd96d7e7765 /modules
parent1a603d00f370167b75a965416080f45824d5b515 (diff)
downloadpango-6ffa65f461d8a78d9190c0d9903a9ecd7273774a.tar.gz
Since Xft may only be available statically without shlib deps, check for
Tue Dec 19 22:47:16 2000 Owen Taylor <otaylor@redhat.com> * configure.in pango-config.in pangoxft.pc.in modules/basic/Makefile.am: Since Xft may only be available statically without shlib deps, check for FreeType libs explicitly and include them when linking, otherwise things won't work. Also, define FREETYPE_CFLAGS from freetype-config --cflags. * modules/basic/basic-xft.c pango/pangoxft-font{,map}.c: Fool Xft into not converting glyph indices by loading the face unencoded then calling FT_Set_Charmap ourselves. * pango/Makefile.am pango/pango-ot.h pango/opentype/* :Add start of opentype handling - most of the actually meat of the code here is the OpenType layout code from FreeType 1 ported to freetype2 and adapted slighlty for our purposes. Also, includes a incomplete OpenType-table-dumping code useful for figuring out what is going on. * pango/pangoxft.h pango/pangoxft-font.h: Add calls for getting FT_Face and PangoOTInfo from PangoXftFont. * modules/arabic/{Makefile.am,arabic-ot.[ch],arabic-xft.c}: Initial support for rendering Arabic with OpenType fonts.
Diffstat (limited to 'modules')
-rw-r--r--modules/arabic/Makefile.am15
-rw-r--r--modules/arabic/arabic-fc.c358
-rw-r--r--modules/arabic/arabic-ot.c384
-rw-r--r--modules/arabic/arabic-ot.h72
-rw-r--r--modules/arabic/arabic-xft.c358
-rw-r--r--modules/basic/Makefile.am7
-rw-r--r--modules/basic/basic-fc.c19
-rw-r--r--modules/basic/basic-xft.c19
8 files changed, 1211 insertions, 21 deletions
diff --git a/modules/arabic/Makefile.am b/modules/arabic/Makefile.am
index 9f6e538b..b276f02f 100644
--- a/modules/arabic/Makefile.am
+++ b/modules/arabic/Makefile.am
@@ -1,5 +1,11 @@
## Process this file with automake to create Makefile.in.
+if HAVE_XFT
+XFT_MODULES=pango-arabic-xft.la
+else
+XFT_MODULES=
+endif
+
sources = \
arabic.c \
arconv.c \
@@ -16,14 +22,19 @@ noinst_LTLIBRARIES = libpango-arabic.la
moddefine = -DMODULE_PREFIX
else
moduledir = $(libdir)/pango/modules
-module_LTLIBRARIES = pango-arabic.la
+module_LTLIBRARIES = $(XFT_MODULES) pango-arabic.la
moduleflags = -rpath $(libdir)
endif
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(moddefine)
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(moddefine) $(X_CFLAGS) $(FREETYPE_CFLAGS)
pango_arabic_la_LDFLAGS = $(moduleflags) -export-dynamic -avoid-version -module
pango_arabic_la_SOURCES = $(sources)
libpango_arabic_la_SOURCES = $(sources)
+
+pango_arabic_xft_la_LDFLAGS = -rpath $(libdir) -export-dynamic -avoid-version -module
+pango_arabic_xft_la_LIBADD =
+pango_arabic_xft_la_SOURCES = arabic-xft.c arabic-ot.c arabic-ot.h
+
diff --git a/modules/arabic/arabic-fc.c b/modules/arabic/arabic-fc.c
new file mode 100644
index 00000000..b8f7b5ad
--- /dev/null
+++ b/modules/arabic/arabic-fc.c
@@ -0,0 +1,358 @@
+/* Pango
+ * arabic-xft.h:
+ *
+ * Copyright (C) 2000 Red Hat Software
+ * Author: Owen Taylor <otaylor@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+
+#include "arabic-ot.h"
+
+#include "pangoxft.h"
+#include "pango-utils.h"
+
+static PangoEngineRange arabic_ranges[] = {
+ /* Language characters */
+ { 0x060c, 0x06f9, "*" }, /* Arabic */
+};
+
+static PangoEngineInfo script_engines[] = {
+ {
+ "ArabicScriptEngineXft",
+ PANGO_ENGINE_TYPE_SHAPE,
+ PANGO_RENDER_TYPE_XFT,
+ arabic_ranges, G_N_ELEMENTS(arabic_ranges)
+ }
+};
+
+void
+maybe_add_feature (PangoOTRuleset *ruleset,
+ PangoOTInfo *info,
+ guint script_index,
+ PangoOTTag tag,
+ gulong property_bit)
+{
+ guint feature_index;
+
+ /* 0xffff == default language system */
+ if (pango_ot_info_find_feature (info, PANGO_OT_TABLE_GSUB,
+ tag, script_index, 0xffff, &feature_index))
+ pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GSUB, feature_index,
+ property_bit);
+}
+
+static PangoOTRuleset *
+get_ruleset (PangoFont *font)
+{
+ PangoOTRuleset *ruleset;
+ static GQuark ruleset_quark = 0;
+
+ PangoOTInfo *info = pango_xft_font_get_ot_info (font);
+
+ if (!ruleset_quark)
+ ruleset_quark = g_quark_from_string ("pango-arabic-ruleset");
+
+ if (!info)
+ return NULL;
+
+ ruleset = g_object_get_qdata (G_OBJECT (font), ruleset_quark);
+
+ if (!ruleset)
+ {
+ PangoOTTag arab_tag = FT_MAKE_TAG ('a', 'r', 'a', 'b');
+ guint script_index;
+
+ ruleset = pango_ot_ruleset_new (info);
+
+ if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GSUB,
+ arab_tag, &script_index))
+ {
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('i','s','o','l'), isolated);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('i','n','i','t'), initial);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('m','e','d','i'), medial);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('f','i','n','a'), final);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('l','i','g','a'), 0xFFFF);
+ }
+
+ g_object_set_qdata_full (G_OBJECT (font), ruleset_quark, ruleset,
+ (GDestroyNotify)g_object_unref);
+ }
+
+ return ruleset;
+}
+
+static void
+swap_range (PangoGlyphString *glyphs, int start, int end)
+{
+ int i, j;
+
+ for (i = start, j = end - 1; i < j; i++, j--)
+ {
+ PangoGlyphInfo glyph_info;
+ gint log_cluster;
+
+ glyph_info = glyphs->glyphs[i];
+ glyphs->glyphs[i] = glyphs->glyphs[j];
+ glyphs->glyphs[j] = glyph_info;
+
+ log_cluster = glyphs->log_clusters[i];
+ glyphs->log_clusters[i] = glyphs->log_clusters[j];
+ glyphs->log_clusters[j] = log_cluster;
+ }
+}
+
+static void
+set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph)
+{
+ glyphs->glyphs[i].glyph = glyph;
+ glyphs->log_clusters[i] = offset;
+}
+
+static guint
+find_char (FT_Face face, PangoFont *font, gunichar wc)
+{
+ int index = FT_Get_Char_Index (face, wc);
+
+ if (index && index <= face->num_glyphs)
+ return index;
+ else
+ return 0;
+}
+
+static void
+arabic_engine_shape (PangoFont *font,
+ const char *text,
+ gint length,
+ PangoAnalysis *analysis,
+ PangoGlyphString *glyphs)
+{
+ int n_chars;
+ int i;
+ const char *p;
+ gulong *properties = NULL;
+ gunichar *wcs = NULL;
+ FT_Face face;
+ PangoOTRuleset *ruleset;
+
+ g_return_if_fail (font != NULL);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (length >= 0);
+ g_return_if_fail (analysis != NULL);
+
+ face = pango_xft_font_get_face (font);
+ g_assert (face);
+
+ n_chars = g_utf8_strlen (text, length);
+ pango_glyph_string_set_size (glyphs, n_chars);
+
+ ruleset = get_ruleset (font);
+ if (ruleset)
+ {
+ wcs = g_utf8_to_ucs4 (text, length);
+ properties = g_new0 (gulong, n_chars);
+
+ Assign_Arabic_Properties (wcs, properties, n_chars);
+ }
+
+ p = text;
+ for (i=0; i < n_chars; i++)
+ {
+ gunichar wc;
+ gunichar mirrored_ch;
+ PangoGlyph index;
+ char buf[6];
+ const char *input;
+
+ wc = g_utf8_get_char (p);
+
+ input = p;
+ if (analysis->level % 2)
+ if (pango_get_mirror_char (wc, &mirrored_ch))
+ {
+ wc = mirrored_ch;
+
+ g_unichar_to_utf8 (wc, buf);
+ input = buf;
+ }
+
+ if (wc >= 0x200B && wc <= 0x200F) /* Zero-width characters */
+ {
+ set_glyph (font, glyphs, i, p - text, 0);
+ }
+ else
+ {
+ /* Hack - Microsoft fonts are strange and don't contain the
+ * correct rules to shape ARABIC LETTER FARSI YEH in
+ * medial/initial position. It looks identical to ARABIC LETTER
+ * YEH in these positions, so we substitute
+ */
+ if (wc == 0x6cc && ruleset &&
+ ((properties[i] & (initial | medial)) != (initial | medial)))
+ wc = 0x64a;
+
+ index = find_char (face, font, wc);
+
+ if (!index)
+ {
+ set_glyph (font, glyphs, i, p - text,
+ pango_xft_font_get_unknown_glyph (font, wc));
+ }
+ else
+ {
+ set_glyph (font, glyphs, i, p - text, index);
+
+ if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK)
+ {
+ if (i > 0)
+ {
+ glyphs->log_clusters[i] = glyphs->log_clusters[i-1];
+#if 0
+ PangoRectangle logical_rect, ink_rect;
+
+ glyphs->glyphs[i].geometry.width = MAX (glyphs->glyphs[i-1].geometry.width,
+ glyphs->glyphs[i].geometry.width);
+ glyphs->glyphs[i-1].geometry.width = 0;
+
+ /* Some heuristics to try to guess how overstrike glyphs are
+ * done and compensate
+ */
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, &ink_rect, &logical_rect);
+ if (logical_rect.width == 0 && ink_rect.x == 0)
+ glyphs->glyphs[i].geometry.x_offset = (glyphs->glyphs[i].geometry.width - ink_rect.width) / 2;
+#endif
+ }
+ }
+ }
+ }
+
+ p = g_utf8_next_char (p);
+ }
+
+ ruleset = get_ruleset (font);
+
+ if (ruleset)
+ {
+ pango_ot_ruleset_shape (ruleset, glyphs, properties);
+
+ g_free (wcs);
+ g_free (properties);
+
+ }
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ {
+
+ if (glyphs->glyphs[i].glyph)
+ {
+ PangoRectangle logical_rect;
+
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
+ glyphs->glyphs[i].geometry.width = logical_rect.width;
+ }
+ else
+ glyphs->glyphs[i].geometry.width = 0;
+
+ glyphs->glyphs[i].geometry.x_offset = 0;
+ glyphs->glyphs[i].geometry.y_offset = 0;
+ }
+
+ /* Simple bidi support */
+
+ if (analysis->level % 2)
+ {
+ int start, end;
+
+ /* Swap all glyphs */
+ swap_range (glyphs, 0, glyphs->num_glyphs);
+
+ /* Now reorder glyphs within each cluster back to LTR */
+ for (start=0; start<glyphs->num_glyphs;)
+ {
+ end = start;
+ while (end < glyphs->num_glyphs &&
+ glyphs->log_clusters[end] == glyphs->log_clusters[start])
+ end++;
+
+ if (end > start + 1)
+ swap_range (glyphs, start, end);
+ start = end;
+ }
+ }
+}
+
+static PangoCoverage *
+arabic_engine_get_coverage (PangoFont *font,
+ const char *lang)
+{
+ return pango_font_get_coverage (font, lang);
+}
+
+static PangoEngine *
+arabic_engine_xft_new ()
+{
+ PangoEngineShape *result;
+
+ result = g_new (PangoEngineShape, 1);
+
+ result->engine.id = PANGO_RENDER_TYPE_XFT;
+ result->engine.type = PANGO_ENGINE_TYPE_SHAPE;
+ result->engine.length = sizeof (result);
+ result->script_shape = arabic_engine_shape;
+ result->get_coverage = arabic_engine_get_coverage;
+
+ return (PangoEngine *)result;
+}
+
+/* The following three functions provide the public module API for
+ * Pango. If we are compiling it is a module, then we name the
+ * entry points script_engine_list, etc. But if we are compiling
+ * it for inclusion directly in Pango, then we need them to
+ * to have distinct names for this module, so we prepend
+ * _pango_arabic_
+ */
+#ifdef MODULE_PREFIX
+#define MODULE_ENTRY(func) _pango_arabic_##func
+#else
+#define MODULE_ENTRY(func) func
+#endif
+
+/* List the engines contained within this module
+ */
+void
+MODULE_ENTRY(script_engine_list) (PangoEngineInfo **engines, gint *n_engines)
+{
+ *engines = script_engines;
+ *n_engines = G_N_ELEMENTS (script_engines);
+}
+
+/* Load a particular engine given the ID for the engine
+ */
+PangoEngine *
+MODULE_ENTRY(script_engine_load) (const char *id)
+{
+ if (!strcmp (id, "ArabicScriptEngineXft"))
+ return arabic_engine_xft_new ();
+ else
+ return NULL;
+}
+
+void
+MODULE_ENTRY(script_engine_unload) (PangoEngine *engine)
+{
+}
diff --git a/modules/arabic/arabic-ot.c b/modules/arabic/arabic-ot.c
new file mode 100644
index 00000000..066e0a3e
--- /dev/null
+++ b/modules/arabic/arabic-ot.c
@@ -0,0 +1,384 @@
+/* This file is taken from the FreeType (1) tree. It's been reindented
+ * to roughly match Pango guidelines (in anticipation of future changes),
+ * but not otherwise much altered.
+ */
+
+/****************************************************************************/
+/* */
+/* The FreeType project -- a free and portable quality TrueType renderer. */
+/* */
+/* Copyright 1996-2000 by */
+/* D. Turner, R.Wilhelm, and W. Lemberg */
+/* */
+/* arabic -- An implementation of the contextual algorithm given in the */
+/* Unicode 2.0 book to assign the `isolated', `initial', `medial', and */
+/* `final' properties to an input string of character codes for the Arabic */
+/* script. */
+/* */
+/****************************************************************************/
+
+#include "arabic-ot.h"
+
+
+/*
+ *
+ * Here a table of the joining classes for characters in the range
+ * U+0620 - U+06FF.
+ *
+ * The following character also has a joining class:
+ *
+ * U+200C ZERO WIDTH NON-JOINER -> causing
+ *
+ * All other characters are given the joining class `none'.
+ *
+ */
+
+joining_class arabic[] =
+{
+ /* U+0620 */
+ none, none, right, right,
+ right, right, dual, right,
+ dual, right, dual, dual,
+ dual, dual, dual, right,
+
+ /* U+0630 */
+ right, right, right, dual,
+ dual, dual, dual, dual,
+ dual, dual, dual, none,
+ none, none, none, none,
+
+ /* U+0640 */
+ causing, dual, dual, dual,
+ dual, dual, dual, dual,
+ right, right, dual, transparent,
+ transparent, transparent, transparent, transparent,
+
+ /* U+0650 */
+ transparent, transparent, transparent, none,
+ none, none, none, none,
+ none, none, none, none,
+ none, none, none, none,
+
+ /* U+0660 */
+ none, none, none, none,
+ none, none, none, none,
+ none, none, none, none,
+ none, none, none, none,
+
+ /* U+0670 */
+ transparent, none, right, right,
+ none, right, right, right,
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+
+ /* U+0680 */
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+ right, right, right, right,
+ right, right, right, right,
+
+ /* U+0690 */
+ right, right, right, right,
+ right, right, right, right,
+ right, right, dual, dual,
+ dual, dual, dual, dual,
+
+ /* U+06A0 */
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+
+ /* U+06B0 */
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+ dual, dual, dual, dual,
+
+ /* U+06C0 */
+ right, dual, right, right,
+ right, right, right, right,
+ right, right, right, right,
+ dual, right, dual, right,
+
+ /* U+06D0 */
+ dual, dual, right, right,
+ none, none, none, transparent,
+ transparent, transparent, transparent, transparent,
+ transparent, transparent, transparent, transparent,
+
+ /* U+06E0 */
+ transparent, transparent, transparent, transparent,
+ transparent, none, none, transparent,
+ transparent, none, transparent, transparent,
+ transparent, transparent, none, none,
+
+ /* U+06F0 */
+ none, none, none, none,
+ none, none, none, none,
+ none, none, dual, dual,
+ dual, none, none, none
+};
+
+#if 0
+struct cgc_
+{
+ FT_UShort char_code;
+ FT_UShort glyph_index;
+ FT_UShort class;
+};
+
+typedef struct cgc_ cgc;
+
+int compare_cgc (const void* a,
+ const void* b)
+{
+ return (((cgc*)a)->glyph_index > ((cgc*)b)->glyph_index) ?
+ 1 : ((((cgc*)a)->glyph_index == ((cgc*)b)->glyph_index) ?
+ 0 : -1);
+}
+
+
+TT_Error Build_Arabic_Glyph_Properties (TT_CharMap char_map,
+ TT_UShort max_glyphs,
+ TTO_GDEFHeader** gdef)
+{
+ TT_UShort i, j, num_glyphs;
+
+ cgc Arabic[0x0700 - 0x0620];
+
+ TT_UShort glyph_indices[0x700 - 0x0620];
+ TT_UShort classes[0x700 - 0x0620];
+
+ if (!gdef)
+ return TT_Err_Invalid_Argument;
+
+ j = 0;
+
+ for (i = 0x0620; i < 0x0700; i++)
+ {
+ Arabic[j].char_code = i;
+ Arabic[j].class = (arabic[i - 0x0620] == transparent) ?
+ MARK_GLYPH : SIMPLE_GLYPH;
+ Arabic[j].glyph_index = TT_Char_Index (char_map, i);
+ if (Arabic[j].glyph_index)
+ j++;
+ }
+ num_glyphs = j;
+
+ if (!num_glyphs)
+ {
+ /* no Arabic font */
+ *gdef = NULL;
+ return TT_Err_Ok;
+ }
+
+ /* sort it */
+
+ qsort (Arabic, num_glyphs, sizeof (cgc), compare_cgc);
+
+ /* write it to the arrays, removing duplicates */
+
+ glyph_indices[0] = Arabic[0].glyph_index;
+ classes[0] = Arabic[0].class;
+
+ j = 1;
+
+ for (i = 1; i < num_glyphs; i++)
+ {
+ glyph_indices[j] = Arabic[i].glyph_index;
+ classes[j] = Arabic[i].class;
+
+ if (glyph_indices[j - 1] != glyph_indices[j])
+ j++;
+ }
+ num_glyphs = j;
+
+ TT_GDEF_Build_ClassDefinition (*gdef, max_glyphs, num_glyphs,
+ glyph_indices, classes);
+
+ return TT_Err_Ok;
+}
+#endif
+
+/* The joining rules as given in the Unicode 2.0 book (characters are
+ * here specified as appearing in the byte stream, i.e. *not* in
+ * visual order). Joining classes are given in angle brackets, glyph
+ * forms in square brackets. Glyphs affected by a specific rule are
+ * enclosed with vertical bars.
+ *
+ * Note: The description of the joining algorithm in the book is
+ * severely broken. You can get a corrected version from
+ * www.unicode.org (as of 29-Jun-1999, this hasn't appeared).
+ *
+ * R1: <anything1> <transparent> <anything2>
+ *
+ * apply joining rules for
+ * <anything1> <anything2> -> [shape1] [shape2]
+ *
+ * -> [shape1] [isolated] [shape2]
+ *
+ * R2: <causing|left|dual> |<right>|
+ *
+ * -> [final]
+ *
+ * R3: |<left>| <causing|right|dual>
+ *
+ * -> [initial]
+ *
+ * R4: <causing|left|dual> |<dual>| <causing|right|dual>
+ *
+ * -> [medial]
+ *
+ * R5: <causing|left|dual> |<dual>| <!(causing|right|dual)>
+ *
+ * -> [final]
+ *
+ * R6: <!(causing|left|dual)> |<dual>| <causing|right|dual>
+ *
+ * -> [initial]
+ *
+ * R7: If R1-R6 fail:
+ *
+ * <anything> -> [isolated]
+ */
+
+/* `direction' can be -1, 0, or 1 to indicate the last non-transparent
+ * glyph, the current glyph, and the next non-transparent glyph,
+ * respectively.
+ */
+
+static joining_class Get_Joining_Class (gunichar* string,
+ int pos,
+ int length,
+ int direction)
+{
+ joining_class j;
+
+
+ while (1)
+ {
+ if (pos == 0 && direction < 0)
+ return none;
+
+ pos += direction;
+
+ if (pos >= length)
+ return none;
+
+ if (string[pos] < 0x0620 ||
+ string[pos] >= 0x0700)
+ {
+ if (string[pos] == 0x200C)
+ return causing;
+ else
+ return none;
+ }
+ else
+ j = arabic[string[pos] - 0x0620];
+
+ if (!direction || j != transparent)
+ return j;
+ }
+}
+
+
+FT_Error Assign_Arabic_Properties (gunichar *string,
+ gulong *properties,
+ int length)
+{
+ joining_class previous, current, next;
+
+ int i;
+
+ if (!string || !properties || length == 0)
+ return FT_Err_Invalid_Argument;
+
+ for (i = 0; i < length; i++)
+ {
+ previous = Get_Joining_Class (string, i, length, -1);
+ current = Get_Joining_Class (string, i, length, 0);
+ next = Get_Joining_Class (string, i, length, 1);
+
+ /* R1 */
+
+ if (current == transparent)
+ {
+ properties[i] |= isolated_p;
+ continue;
+ }
+
+ /* R2 */
+
+ if (previous == causing ||
+ previous == left ||
+ previous == dual )
+ if (current == right)
+ {
+ properties[i] |= final_p;
+ continue;
+ }
+
+ /* R3 */
+
+ if (current == left)
+ if (next == causing ||
+ next == right ||
+ next == dual )
+ {
+ properties[i] |= initial_p;
+ continue;
+ }
+
+ /* R4 */
+
+ if (previous == causing ||
+ previous == left ||
+ previous == dual )
+ if (current == dual)
+ if (next == causing ||
+ next == right ||
+ next == dual )
+ {
+ properties[i] |= medial_p;
+ continue;
+ }
+
+ /* R5 */
+
+ if (previous == causing ||
+ previous == left ||
+ previous == dual )
+ if (current == dual)
+ if (!(next == causing ||
+ next == right ||
+ next == dual ))
+ {
+ properties[i] |= final_p;
+ continue;
+ }
+
+ /* R6 */
+
+ if (!(previous == causing ||
+ previous == left ||
+ previous == dual ))
+ if (current == dual)
+ if (next == causing ||
+ next == right ||
+ next == dual )
+ {
+ properties[i] |= initial_p;
+ continue;
+ }
+
+ /* R7 */
+
+ properties[i] |= isolated_p;
+ }
+
+ return FT_Err_Ok;
+}
+
+
+/* End */
diff --git a/modules/arabic/arabic-ot.h b/modules/arabic/arabic-ot.h
new file mode 100644
index 00000000..63b79199
--- /dev/null
+++ b/modules/arabic/arabic-ot.h
@@ -0,0 +1,72 @@
+/* This file is taken from the FreeType (1) tree. It's been reindented
+ * to roughly match Pango guidelines (in anticipation of future changes),
+ * but not otherwise much altered.
+ */
+
+/****************************************************************************/
+/* */
+/* The FreeType project -- a free and portable quality TrueType renderer. */
+/* */
+/* Copyright 1996-2000 by */
+/* D. Turner, R.Wilhelm, and W. Lemberg */
+/* */
+/* arabic -- An implementation of the contextual algorithm given in the */
+/* Unicode 2.0 book to assign the `isolated', `initial', `medial', and */
+/* `final' properties to an input string of character codes for the Arabic */
+/* script. */
+/* */
+/****************************************************************************/
+
+
+#include <pango/pango-ot.h>
+
+
+enum joining_type_
+{
+ isolated = 1, /* nominal */
+ final = 2, /* right_joining */
+ initial = 4, /* left_joining */
+ medial = 8 /* double_joining */
+};
+
+typedef enum joining_type_ joining_type;
+
+
+ /* A glyph's property value as needed by e.g. TT_GSUB_Apply_String()
+ specifies which features should *not* be applied */
+
+enum arabic_glyph_property_
+{
+ isolated_p = final | initial | medial,
+ final_p = isolated | initial | medial,
+ initial_p = isolated | final | medial,
+ medial_p = isolated | final | initial
+};
+
+typedef enum arabic_glyph_property_ arabic_glyph_property;
+
+
+enum joining_class_
+{
+ right,
+ left, /* not used */
+ dual,
+ causing,
+ none,
+ transparent
+};
+
+typedef enum joining_class_ joining_class;
+
+
+FT_Error Assign_Arabic_Properties (gunichar *string,
+ gulong *properties,
+ int length);
+#if 0
+TT_Error Build_Arabic_Glyph_Properties (TT_CharMap char_map,
+ TT_UShort max_glyphs,
+ TTO_GDEFHeader** gdef );
+#endif
+
+
+/* End */
diff --git a/modules/arabic/arabic-xft.c b/modules/arabic/arabic-xft.c
new file mode 100644
index 00000000..b8f7b5ad
--- /dev/null
+++ b/modules/arabic/arabic-xft.c
@@ -0,0 +1,358 @@
+/* Pango
+ * arabic-xft.h:
+ *
+ * Copyright (C) 2000 Red Hat Software
+ * Author: Owen Taylor <otaylor@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+
+#include "arabic-ot.h"
+
+#include "pangoxft.h"
+#include "pango-utils.h"
+
+static PangoEngineRange arabic_ranges[] = {
+ /* Language characters */
+ { 0x060c, 0x06f9, "*" }, /* Arabic */
+};
+
+static PangoEngineInfo script_engines[] = {
+ {
+ "ArabicScriptEngineXft",
+ PANGO_ENGINE_TYPE_SHAPE,
+ PANGO_RENDER_TYPE_XFT,
+ arabic_ranges, G_N_ELEMENTS(arabic_ranges)
+ }
+};
+
+void
+maybe_add_feature (PangoOTRuleset *ruleset,
+ PangoOTInfo *info,
+ guint script_index,
+ PangoOTTag tag,
+ gulong property_bit)
+{
+ guint feature_index;
+
+ /* 0xffff == default language system */
+ if (pango_ot_info_find_feature (info, PANGO_OT_TABLE_GSUB,
+ tag, script_index, 0xffff, &feature_index))
+ pango_ot_ruleset_add_feature (ruleset, PANGO_OT_TABLE_GSUB, feature_index,
+ property_bit);
+}
+
+static PangoOTRuleset *
+get_ruleset (PangoFont *font)
+{
+ PangoOTRuleset *ruleset;
+ static GQuark ruleset_quark = 0;
+
+ PangoOTInfo *info = pango_xft_font_get_ot_info (font);
+
+ if (!ruleset_quark)
+ ruleset_quark = g_quark_from_string ("pango-arabic-ruleset");
+
+ if (!info)
+ return NULL;
+
+ ruleset = g_object_get_qdata (G_OBJECT (font), ruleset_quark);
+
+ if (!ruleset)
+ {
+ PangoOTTag arab_tag = FT_MAKE_TAG ('a', 'r', 'a', 'b');
+ guint script_index;
+
+ ruleset = pango_ot_ruleset_new (info);
+
+ if (pango_ot_info_find_script (info, PANGO_OT_TABLE_GSUB,
+ arab_tag, &script_index))
+ {
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('i','s','o','l'), isolated);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('i','n','i','t'), initial);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('m','e','d','i'), medial);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('f','i','n','a'), final);
+ maybe_add_feature (ruleset, info, script_index, FT_MAKE_TAG ('l','i','g','a'), 0xFFFF);
+ }
+
+ g_object_set_qdata_full (G_OBJECT (font), ruleset_quark, ruleset,
+ (GDestroyNotify)g_object_unref);
+ }
+
+ return ruleset;
+}
+
+static void
+swap_range (PangoGlyphString *glyphs, int start, int end)
+{
+ int i, j;
+
+ for (i = start, j = end - 1; i < j; i++, j--)
+ {
+ PangoGlyphInfo glyph_info;
+ gint log_cluster;
+
+ glyph_info = glyphs->glyphs[i];
+ glyphs->glyphs[i] = glyphs->glyphs[j];
+ glyphs->glyphs[j] = glyph_info;
+
+ log_cluster = glyphs->log_clusters[i];
+ glyphs->log_clusters[i] = glyphs->log_clusters[j];
+ glyphs->log_clusters[j] = log_cluster;
+ }
+}
+
+static void
+set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGlyph glyph)
+{
+ glyphs->glyphs[i].glyph = glyph;
+ glyphs->log_clusters[i] = offset;
+}
+
+static guint
+find_char (FT_Face face, PangoFont *font, gunichar wc)
+{
+ int index = FT_Get_Char_Index (face, wc);
+
+ if (index && index <= face->num_glyphs)
+ return index;
+ else
+ return 0;
+}
+
+static void
+arabic_engine_shape (PangoFont *font,
+ const char *text,
+ gint length,
+ PangoAnalysis *analysis,
+ PangoGlyphString *glyphs)
+{
+ int n_chars;
+ int i;
+ const char *p;
+ gulong *properties = NULL;
+ gunichar *wcs = NULL;
+ FT_Face face;
+ PangoOTRuleset *ruleset;
+
+ g_return_if_fail (font != NULL);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (length >= 0);
+ g_return_if_fail (analysis != NULL);
+
+ face = pango_xft_font_get_face (font);
+ g_assert (face);
+
+ n_chars = g_utf8_strlen (text, length);
+ pango_glyph_string_set_size (glyphs, n_chars);
+
+ ruleset = get_ruleset (font);
+ if (ruleset)
+ {
+ wcs = g_utf8_to_ucs4 (text, length);
+ properties = g_new0 (gulong, n_chars);
+
+ Assign_Arabic_Properties (wcs, properties, n_chars);
+ }
+
+ p = text;
+ for (i=0; i < n_chars; i++)
+ {
+ gunichar wc;
+ gunichar mirrored_ch;
+ PangoGlyph index;
+ char buf[6];
+ const char *input;
+
+ wc = g_utf8_get_char (p);
+
+ input = p;
+ if (analysis->level % 2)
+ if (pango_get_mirror_char (wc, &mirrored_ch))
+ {
+ wc = mirrored_ch;
+
+ g_unichar_to_utf8 (wc, buf);
+ input = buf;
+ }
+
+ if (wc >= 0x200B && wc <= 0x200F) /* Zero-width characters */
+ {
+ set_glyph (font, glyphs, i, p - text, 0);
+ }
+ else
+ {
+ /* Hack - Microsoft fonts are strange and don't contain the
+ * correct rules to shape ARABIC LETTER FARSI YEH in
+ * medial/initial position. It looks identical to ARABIC LETTER
+ * YEH in these positions, so we substitute
+ */
+ if (wc == 0x6cc && ruleset &&
+ ((properties[i] & (initial | medial)) != (initial | medial)))
+ wc = 0x64a;
+
+ index = find_char (face, font, wc);
+
+ if (!index)
+ {
+ set_glyph (font, glyphs, i, p - text,
+ pango_xft_font_get_unknown_glyph (font, wc));
+ }
+ else
+ {
+ set_glyph (font, glyphs, i, p - text, index);
+
+ if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK)
+ {
+ if (i > 0)
+ {
+ glyphs->log_clusters[i] = glyphs->log_clusters[i-1];
+#if 0
+ PangoRectangle logical_rect, ink_rect;
+
+ glyphs->glyphs[i].geometry.width = MAX (glyphs->glyphs[i-1].geometry.width,
+ glyphs->glyphs[i].geometry.width);
+ glyphs->glyphs[i-1].geometry.width = 0;
+
+ /* Some heuristics to try to guess how overstrike glyphs are
+ * done and compensate
+ */
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, &ink_rect, &logical_rect);
+ if (logical_rect.width == 0 && ink_rect.x == 0)
+ glyphs->glyphs[i].geometry.x_offset = (glyphs->glyphs[i].geometry.width - ink_rect.width) / 2;
+#endif
+ }
+ }
+ }
+ }
+
+ p = g_utf8_next_char (p);
+ }
+
+ ruleset = get_ruleset (font);
+
+ if (ruleset)
+ {
+ pango_ot_ruleset_shape (ruleset, glyphs, properties);
+
+ g_free (wcs);
+ g_free (properties);
+
+ }
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ {
+
+ if (glyphs->glyphs[i].glyph)
+ {
+ PangoRectangle logical_rect;
+
+ pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
+ glyphs->glyphs[i].geometry.width = logical_rect.width;
+ }
+ else
+ glyphs->glyphs[i].geometry.width = 0;
+
+ glyphs->glyphs[i].geometry.x_offset = 0;
+ glyphs->glyphs[i].geometry.y_offset = 0;
+ }
+
+ /* Simple bidi support */
+
+ if (analysis->level % 2)
+ {
+ int start, end;
+
+ /* Swap all glyphs */
+ swap_range (glyphs, 0, glyphs->num_glyphs);
+
+ /* Now reorder glyphs within each cluster back to LTR */
+ for (start=0; start<glyphs->num_glyphs;)
+ {
+ end = start;
+ while (end < glyphs->num_glyphs &&
+ glyphs->log_clusters[end] == glyphs->log_clusters[start])
+ end++;
+
+ if (end > start + 1)
+ swap_range (glyphs, start, end);
+ start = end;
+ }
+ }
+}
+
+static PangoCoverage *
+arabic_engine_get_coverage (PangoFont *font,
+ const char *lang)
+{
+ return pango_font_get_coverage (font, lang);
+}
+
+static PangoEngine *
+arabic_engine_xft_new ()
+{
+ PangoEngineShape *result;
+
+ result = g_new (PangoEngineShape, 1);
+
+ result->engine.id = PANGO_RENDER_TYPE_XFT;
+ result->engine.type = PANGO_ENGINE_TYPE_SHAPE;
+ result->engine.length = sizeof (result);
+ result->script_shape = arabic_engine_shape;
+ result->get_coverage = arabic_engine_get_coverage;
+
+ return (PangoEngine *)result;
+}
+
+/* The following three functions provide the public module API for
+ * Pango. If we are compiling it is a module, then we name the
+ * entry points script_engine_list, etc. But if we are compiling
+ * it for inclusion directly in Pango, then we need them to
+ * to have distinct names for this module, so we prepend
+ * _pango_arabic_
+ */
+#ifdef MODULE_PREFIX
+#define MODULE_ENTRY(func) _pango_arabic_##func
+#else
+#define MODULE_ENTRY(func) func
+#endif
+
+/* List the engines contained within this module
+ */
+void
+MODULE_ENTRY(script_engine_list) (PangoEngineInfo **engines, gint *n_engines)
+{
+ *engines = script_engines;
+ *n_engines = G_N_ELEMENTS (script_engines);
+}
+
+/* Load a particular engine given the ID for the engine
+ */
+PangoEngine *
+MODULE_ENTRY(script_engine_load) (const char *id)
+{
+ if (!strcmp (id, "ArabicScriptEngineXft"))
+ return arabic_engine_xft_new ();
+ else
+ return NULL;
+}
+
+void
+MODULE_ENTRY(script_engine_unload) (PangoEngine *engine)
+{
+}
diff --git a/modules/basic/Makefile.am b/modules/basic/Makefile.am
index f0daa7ae..389013aa 100644
--- a/modules/basic/Makefile.am
+++ b/modules/basic/Makefile.am
@@ -18,7 +18,12 @@ module_LTLIBRARIES = $(XFT_MODULES) pango-basic.la
moduleflags=-rpath $(libdir)
endif
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(X_CFLAGS) $(moddefine)
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/pango/ \
+ $(X_CFLAGS) \
+ $(FREETYPE_CFLAGS) \
+ $(moddefine)
pango_basic_la_LDFLAGS = $(moduleflags) -export-dynamic -avoid-version -module
pango_basic_la_LIBADD =
diff --git a/modules/basic/basic-fc.c b/modules/basic/basic-fc.c
index 979a3772..746a687b 100644
--- a/modules/basic/basic-fc.c
+++ b/modules/basic/basic-fc.c
@@ -87,12 +87,12 @@ set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGl
}
static guint
-find_char (Display *display, PangoFont *font, gunichar wc)
+find_char (FT_Face face, PangoFont *font, gunichar wc)
{
- XftFont *xft_font = pango_xft_font_get_font (font);
+ int index = FT_Get_Char_Index (face, wc);
- if (XftGlyphExists (display, xft_font, wc))
- return wc;
+ if (index && index <= face->num_glyphs)
+ return index;
else
return 0;
}
@@ -107,14 +107,15 @@ basic_engine_shape (PangoFont *font,
int n_chars;
int i;
const char *p;
- Display *display;
+ FT_Face face;
g_return_if_fail (font != NULL);
g_return_if_fail (text != NULL);
g_return_if_fail (length >= 0);
g_return_if_fail (analysis != NULL);
- display = pango_xft_font_get_display (font);
+ face = pango_xft_font_get_face (font);
+ g_assert (face);
n_chars = g_utf8_strlen (text, length);
pango_glyph_string_set_size (glyphs, n_chars);
@@ -140,13 +141,13 @@ basic_engine_shape (PangoFont *font,
input = buf;
}
- if (wc == 0x200B || wc == 0x200E || wc == 0x200F) /* Zero-width characters */
+ if (wc >= 0x200B && wc <= 0x200F) /* Zero-width characters */
{
set_glyph (font, glyphs, i, p - text, 0);
}
else
{
- index = find_char (display, font, wc);
+ index = find_char (face, font, wc);
if (!index)
{
@@ -165,7 +166,7 @@ basic_engine_shape (PangoFont *font,
for (j=0; j < len; j++)
{
set_glyph (font, glyphs, i + j,
- p - text, find_char (display, font, buf[j]));
+ p - text, find_char (face, font, buf[j]));
}
i += len - 1;
#endif
diff --git a/modules/basic/basic-xft.c b/modules/basic/basic-xft.c
index 979a3772..746a687b 100644
--- a/modules/basic/basic-xft.c
+++ b/modules/basic/basic-xft.c
@@ -87,12 +87,12 @@ set_glyph (PangoFont *font, PangoGlyphString *glyphs, int i, int offset, PangoGl
}
static guint
-find_char (Display *display, PangoFont *font, gunichar wc)
+find_char (FT_Face face, PangoFont *font, gunichar wc)
{
- XftFont *xft_font = pango_xft_font_get_font (font);
+ int index = FT_Get_Char_Index (face, wc);
- if (XftGlyphExists (display, xft_font, wc))
- return wc;
+ if (index && index <= face->num_glyphs)
+ return index;
else
return 0;
}
@@ -107,14 +107,15 @@ basic_engine_shape (PangoFont *font,
int n_chars;
int i;
const char *p;
- Display *display;
+ FT_Face face;
g_return_if_fail (font != NULL);
g_return_if_fail (text != NULL);
g_return_if_fail (length >= 0);
g_return_if_fail (analysis != NULL);
- display = pango_xft_font_get_display (font);
+ face = pango_xft_font_get_face (font);
+ g_assert (face);
n_chars = g_utf8_strlen (text, length);
pango_glyph_string_set_size (glyphs, n_chars);
@@ -140,13 +141,13 @@ basic_engine_shape (PangoFont *font,
input = buf;
}
- if (wc == 0x200B || wc == 0x200E || wc == 0x200F) /* Zero-width characters */
+ if (wc >= 0x200B && wc <= 0x200F) /* Zero-width characters */
{
set_glyph (font, glyphs, i, p - text, 0);
}
else
{
- index = find_char (display, font, wc);
+ index = find_char (face, font, wc);
if (!index)
{
@@ -165,7 +166,7 @@ basic_engine_shape (PangoFont *font,
for (j=0; j < len; j++)
{
set_glyph (font, glyphs, i + j,
- p - text, find_char (display, font, buf[j]));
+ p - text, find_char (face, font, buf[j]));
}
i += len - 1;
#endif