summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-01-14 16:02:58 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-01-14 16:02:58 +0000
commitdfaf3021ff105a1c1f138f665fccce70034de261 (patch)
tree8afde7eadef66992c59c32cc826e9e172a47864d
parent37418105bd27c1cdc9261b3bd2747c9fb15c60f0 (diff)
downloadpango-dfaf3021ff105a1c1f138f665fccce70034de261.tar.gz
Export TT_New_GDEF_Table to create an empty GDEF table.
Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com> * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table to create an empty GDEF table. * pango/opentype/pango-ot-info.c: If the font doesn't have a class definition table, synthesize one using the charmap and the unicode properties of characters in the charmap. (Needed to make things work with various old Arabic fonts, such as the KACST fonts)
-rw-r--r--ChangeLog10
-rw-r--r--ChangeLog.pre-1-1010
-rw-r--r--ChangeLog.pre-1-410
-rw-r--r--ChangeLog.pre-1-610
-rw-r--r--ChangeLog.pre-1-810
-rw-r--r--modules/arabic/arabic.c361
-rw-r--r--pango/opentype/ftxgdef.c46
-rw-r--r--pango/opentype/ftxgdef.h4
-rw-r--r--pango/opentype/pango-ot-info.c108
9 files changed, 194 insertions, 375 deletions
diff --git a/ChangeLog b/ChangeLog
index e69de29b..5fd99d48 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,10 @@
+Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com>
+
+ * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table
+ to create an empty GDEF table.
+
+ * pango/opentype/pango-ot-info.c: If the font doesn't
+ have a class definition table, synthesize one using
+ the charmap and the unicode properties of characters
+ in the charmap. (Needed to make things work with various
+ old Arabic fonts, such as the KACST fonts)
diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10
index e69de29b..5fd99d48 100644
--- a/ChangeLog.pre-1-10
+++ b/ChangeLog.pre-1-10
@@ -0,0 +1,10 @@
+Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com>
+
+ * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table
+ to create an empty GDEF table.
+
+ * pango/opentype/pango-ot-info.c: If the font doesn't
+ have a class definition table, synthesize one using
+ the charmap and the unicode properties of characters
+ in the charmap. (Needed to make things work with various
+ old Arabic fonts, such as the KACST fonts)
diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4
index e69de29b..5fd99d48 100644
--- a/ChangeLog.pre-1-4
+++ b/ChangeLog.pre-1-4
@@ -0,0 +1,10 @@
+Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com>
+
+ * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table
+ to create an empty GDEF table.
+
+ * pango/opentype/pango-ot-info.c: If the font doesn't
+ have a class definition table, synthesize one using
+ the charmap and the unicode properties of characters
+ in the charmap. (Needed to make things work with various
+ old Arabic fonts, such as the KACST fonts)
diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6
index e69de29b..5fd99d48 100644
--- a/ChangeLog.pre-1-6
+++ b/ChangeLog.pre-1-6
@@ -0,0 +1,10 @@
+Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com>
+
+ * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table
+ to create an empty GDEF table.
+
+ * pango/opentype/pango-ot-info.c: If the font doesn't
+ have a class definition table, synthesize one using
+ the charmap and the unicode properties of characters
+ in the charmap. (Needed to make things work with various
+ old Arabic fonts, such as the KACST fonts)
diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8
index e69de29b..5fd99d48 100644
--- a/ChangeLog.pre-1-8
+++ b/ChangeLog.pre-1-8
@@ -0,0 +1,10 @@
+Fri Jan 10 18:56:36 2003 Owen Taylor <otaylor@redhat.com>
+
+ * pango/opentype/ftxgdef.c: Export TT_New_GDEF_Table
+ to create an empty GDEF table.
+
+ * pango/opentype/pango-ot-info.c: If the font doesn't
+ have a class definition table, synthesize one using
+ the charmap and the unicode properties of characters
+ in the charmap. (Needed to make things work with various
+ old Arabic fonts, such as the KACST fonts)
diff --git a/modules/arabic/arabic.c b/modules/arabic/arabic.c
deleted file mode 100644
index 74131bff..00000000
--- a/modules/arabic/arabic.c
+++ /dev/null
@@ -1,361 +0,0 @@
-/* Pango - Arabic module
- * arabic module
- *
- * (C) 2000 Karl Koehler<koehler@or.uni-bonn.de>
- * Owen Taylor <otaylor@redhat.com>
- *
- */
-
-#include <stdio.h>
-#include <glib.h>
-#include <string.h>
-#include "pango-engine.h"
-#include "pangox.h"
-
-#include "arconv.h"
-#include "mulefont.h"
-#include "langboxfont.h"
-#include "naqshfont.h"
-
-/* #define DEBUG */
-#ifdef DEBUG
-#include <stdio.h>
-#endif
-
-
-static PangoEngineRange arabic_range[] = {
- { 0x060B, 0x06D3, "*" } /* 0x060B, 0x06D3 */
-};
-
-static PangoEngineInfo script_engines[] = {
- {
- "ArabicScriptEngineX",
- PANGO_ENGINE_TYPE_SHAPE,
- PANGO_RENDER_TYPE_X,
- arabic_range, G_N_ELEMENTS(arabic_range)
- }
-};
-
-static gint n_script_engines = G_N_ELEMENTS (script_engines);
-
-/*
- * X window system script engine portion
- */
-
-static ArabicFontInfo*
-arabic_unicodeinit(PangoFont *font, PangoXSubfont subfont)
-{
- ArabicFontInfo *fs = NULL;
-
- if (subfont != 0)
- {
- if ( pango_x_has_glyph /* Alif-Madda */
- (font,PANGO_X_MAKE_GLYPH(subfont,0xFE81)))
- {
- fs = g_new (ArabicFontInfo,1);
- fs->level = ar_standard | ar_unifont;
- fs->subfonts[0] = subfont;
-
- if ( pango_x_has_glyph /* Shadda+Kasra */
- (font,PANGO_X_MAKE_GLYPH(subfont,0xFC62)))
- {
- fs->level |= ar_composedtashkeel;
- /* extra vowels in font, hopefully */
- }
- if ( pango_x_has_glyph /* Lam-Min alone */
- (font,PANGO_X_MAKE_GLYPH(subfont,0xFC42)))
- {
- fs->level |= ar_lig;
- /* extra ligatures in font, hopefully */
- }
- }
- }
- return fs;
-}
-
-static ArabicFontInfo*
-find_unic_font (PangoFont *font)
-{
- static char *charsets[] = {
- "iso10646-1",
- "iso8859-6.8x",
- "mulearabic-2",
- "urdunaqsh-0",
-/* "symbol-0" */
- };
-
- ArabicFontInfo *fs = NULL;
- PangoXSubfont *subfonts;
- int *subfont_charsets;
- int n_subfonts;
- int i;
-
- GQuark info_id = g_quark_from_string ("arabic-font-info");
- fs = g_object_get_qdata (G_OBJECT (font), info_id);
- if (fs) return fs;
-
- n_subfonts = pango_x_list_subfonts (font, charsets, 4,
- &subfonts, &subfont_charsets);
-
- for (i=0; i < n_subfonts; i++)
- {
- if ( !strcmp (charsets[subfont_charsets[i]], "mulearabic-2"))
- {
-#ifdef DEBUG
- if (getenv("PANGO_AR_NOMULEFONT") == NULL )
-#endif
- fs = arabic_muleinit(font);
- }
- else if ( !strcmp (charsets[subfont_charsets[i]], "iso8859-6.8x"))
- {
-#ifdef DEBUG
- if (getenv("PANGO_AR_NOLBOXFONT") == NULL )
-#endif
- fs = arabic_lboxinit(font);
- }
- else if ( !strcmp (charsets[subfont_charsets[i]], "urdunaqsh-0"))
- {
-#ifdef DEBUG
- if (getenv("PANGO_AR_NONQFONT") == NULL )
-#endif
- fs = urdu_naqshinit(font);
- }
- else
- {
-#ifdef DEBUG
- if (getenv("PANGO_AR_NOUNIFONT") == NULL )
-#endif
- fs = arabic_unicodeinit(font,subfonts[i]);
- }
- if (fs){
- g_object_set_qdata_full (G_OBJECT (font), info_id,
- fs, (GDestroyNotify)g_free);
- break;
- }
- }
-
- g_free (subfonts);
- g_free (subfont_charsets);
-
- return fs;
-}
-
-
-
-static void
-set_glyph (PangoGlyphString *glyphs,
- PangoFont *font, PangoXSubfont subfont,
- int i, int cluster_start, int glyph, int is_vowel)
-{
- PangoRectangle logical_rect;
-
- glyphs->glyphs[i].glyph = PANGO_X_MAKE_GLYPH (subfont, glyph);
-
- glyphs->glyphs[i].geometry.x_offset = 0;
- glyphs->glyphs[i].geometry.y_offset = 0;
-
- pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
- glyphs->log_clusters[i] = cluster_start;
- if (is_vowel)
- {
- glyphs->glyphs[i].geometry.width = 0;
- }
- else
- {
- glyphs->glyphs[i].geometry.width = logical_rect.width;
- }
-}
-
-
-/* The following thing is actually critical ... */
-
-static void
-arabic_engine_shape (PangoFont *font,
- const char *text,
- int length,
- PangoAnalysis *analysis,
- PangoGlyphString *glyphs)
-{
- PangoXSubfont subfont;
- int n_chars;
- int i;
- ArabicFontInfo *fs;
- const char *p;
- const char *pold;
- gunichar *wc;
-
- g_return_if_fail (font != NULL);
- g_return_if_fail (text != NULL);
- g_return_if_fail (length >= 0);
- g_return_if_fail (analysis != NULL);
-
- /* We hope there is a suitible font installed ..
- */
-
- if (! (fs = find_unic_font (font)) )
- {
-
- PangoGlyph unknown_glyph = pango_x_get_unknown_glyph (font);
-
- n_chars = g_utf8_strlen(text,length);
- pango_glyph_string_set_size (glyphs, n_chars);
-
- p = text;
- for (i=0; i<n_chars; i++)
- {
- set_glyph (glyphs, font,
- PANGO_X_GLYPH_SUBFONT (unknown_glyph), i,
- p - text, PANGO_X_GLYPH_INDEX (unknown_glyph),0);
- p = g_utf8_next_char (p);
- }
- return;
- }
-
-
- p = text;
- if (analysis->level % 2 == 0)
- {
- wc = g_utf8_to_ucs4_fast(text,length,&n_chars);
- /* We were called on a LTR directional run (e.g. some numbers);
- fallback as simple as possible */
- pango_glyph_string_set_size (glyphs, n_chars);
-
- }
- else
- {
- wc = (gunichar *)g_malloc(sizeof(gunichar)* (length) ); /* length is succicient: all arabic chars use at
- least 2 bytes in utf-8 encoding */
- n_chars = length;
- arabic_reshape(&n_chars,text,wc,fs->level);
- pango_glyph_string_set_size (glyphs, n_chars);
- };
-
-
- p = text;
- pold = p;
- i = 0;
- subfont = fs->subfonts[0];
-
- while(i < n_chars)
- {
- if (wc[i] == 0)
- {
- p = g_utf8_next_char (p);
-#ifdef DEBUG
- fprintf(stderr,"NULL-character detected in generated string.!");
-#endif
- i++;
- }
- else
- {
- int cluster_start ;
- int is_vowel = arabic_isvowel(wc[i]);
- cluster_start = is_vowel ? pold - text : p - text;
-
- if ( fs->level & ar_mulefont )
- {
- arabic_mule_recode(&subfont,&(wc[i]),
- fs->subfonts);
- }
- else if ( fs->level & ar_lboxfont )
- {
- if (( i < n_chars-1 )&&(wc[i+1] == 0))
- {
- arabic_lbox_recode(&subfont,&(wc[i]),
- &(wc[i+1]),
- fs->subfonts);
- }
- else
- arabic_lbox_recode(&subfont,&(wc[i]),NULL,
- fs->subfonts);
- }
- else if ( fs->level & ar_naqshfont )
- {
- if (( i < n_chars-1 )&&(wc[i+1] == 0))
- {
- urdu_naqsh_recode(&subfont,&(wc[i]),
- &(wc[i+1]),
- fs->subfonts);
- }
- else
- urdu_naqsh_recode(&subfont,&(wc[i]),NULL,
- fs->subfonts);
- }
-
- set_glyph(glyphs, font, subfont, n_chars - i - 1,
- cluster_start, wc[i], is_vowel);
-
- pold = p;
- p = g_utf8_next_char (p);
- i++;
- }
- }
-
- g_free(wc);
-}
-
-
-static PangoCoverage *
-arabic_engine_get_coverage (PangoFont *font,
- const char *lang)
-{
- gunichar i;
- PangoCoverage *result = pango_coverage_new ();
-
- for (i = 0x60B; i <= 0x66D; i++)
- pango_coverage_set (result, i, PANGO_COVERAGE_EXACT);
- for (i = 0x670; i <= 0x6D3; i++)
- pango_coverage_set (result, i, PANGO_COVERAGE_EXACT);
-
- return result;
-}
-
-static PangoEngine *
-arabic_engine_x_new ()
-{
- PangoEngineShape *result;
-
- result = g_new (PangoEngineShape, 1);
-
- result->engine.id = "ArabicScriptEngine";
- 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
- */
-#ifdef MODULE_PREFIX
-#define MODULE_ENTRY(func) _pango_arabic_##func
-#else
-#define MODULE_ENTRY(func) func
-#endif
-
-void
-MODULE_ENTRY(script_engine_list) (PangoEngineInfo **engines, int *n_engines)
-{
- *engines = script_engines;
- *n_engines = n_script_engines;
-}
-
-PangoEngine *
-MODULE_ENTRY(script_engine_load) (const char *id)
-{
- if (!strcmp (id, "ArabicScriptEngineX"))
- return arabic_engine_x_new ();
- else
- return NULL;
-}
-
-void
-MODULE_ENTRY(script_engine_unload) (PangoEngine *engine)
-{
-}
diff --git a/pango/opentype/ftxgdef.c b/pango/opentype/ftxgdef.c
index 67b268e9..e7e02f13 100644
--- a/pango/opentype/ftxgdef.c
+++ b/pango/opentype/ftxgdef.c
@@ -133,6 +133,37 @@
#endif
EXPORT_FUNC
+ FT_Error TT_New_GDEF_Table( FT_Face face,
+ TTO_GDEFHeader** retptr )
+ {
+ FT_Error error;
+ FT_Memory memory = face->memory;
+
+ TTO_GDEFHeader* gdef;
+
+ if ( !retptr )
+ return TT_Err_Invalid_Argument;
+
+ if ( ALLOC( gdef, sizeof( *gdef ) ) )
+ return error;
+
+ gdef->memory = face->memory;
+
+ gdef->GlyphClassDef.loaded = FALSE;
+ gdef->AttachList.loaded = FALSE;
+ gdef->LigCaretList.loaded = FALSE;
+ gdef->MarkAttachClassDef_offset = 0;
+ gdef->MarkAttachClassDef.loaded = FALSE;
+
+ gdef->LastGlyph = 0;
+ gdef->NewGlyphClasses = NULL;
+
+ *retptr = gdef;
+
+ return TT_Err_Ok;
+ }
+
+ EXPORT_FUNC
FT_Error TT_Load_GDEF_Table( FT_Face face,
TTO_GDEFHeader** retptr )
{
@@ -151,11 +182,9 @@
if (( error = tt_face->goto_table( tt_face, TTAG_GDEF, stream, 0 ) ))
return error;
- if ( ALLOC( gdef, sizeof( *gdef ) ) )
+ if (( error = TT_New_GDEF_Table ( face, &gdef ) ))
return error;
- gdef->memory = face->memory;
-
base_offset = FILE_Pos();
/* skip version */
@@ -183,8 +212,6 @@
goto Fail0;
(void)FILE_Seek( cur_offset );
}
- else
- gdef->GlyphClassDef.loaded = FALSE;
if ( ACCESS_Frame( 2L ) )
goto Fail1;
@@ -204,8 +231,6 @@
goto Fail1;
(void)FILE_Seek( cur_offset );
}
- else
- gdef->AttachList.loaded = FALSE;
if ( ACCESS_Frame( 2L ) )
goto Fail2;
@@ -225,8 +250,6 @@
goto Fail2;
(void)FILE_Seek( cur_offset );
}
- else
- gdef->LigCaretList.loaded = FALSE;
/* OpenType 1.2 has introduced the `MarkAttachClassDef' field. We
first have to scan the LookupFlag values to find out whether we
@@ -244,11 +267,6 @@
else
gdef->MarkAttachClassDef_offset = 0;
- gdef->MarkAttachClassDef.loaded = FALSE;
-
- gdef->LastGlyph = 0;
- gdef->NewGlyphClasses = NULL;
-
*retptr = gdef;
return TT_Err_Ok;
diff --git a/pango/opentype/ftxgdef.h b/pango/opentype/ftxgdef.h
index 6395bf38..f22438eb 100644
--- a/pango/opentype/ftxgdef.h
+++ b/pango/opentype/ftxgdef.h
@@ -191,6 +191,10 @@ extern "C" {
/* EXPORT_DEF
FT_Error TT_Init_GDEF_Extension( TT_Engine engine ); */
+ EXPORT_FUNC
+ FT_Error TT_New_GDEF_Table( FT_Face face,
+ TTO_GDEFHeader** retptr );
+
EXPORT_DEF
FT_Error TT_Load_GDEF_Table( FT_Face face,
TTO_GDEFHeader** gdef );
diff --git a/pango/opentype/pango-ot-info.c b/pango/opentype/pango-ot-info.c
index 2152e084..1a4251a3 100644
--- a/pango/opentype/pango-ot-info.c
+++ b/pango/opentype/pango-ot-info.c
@@ -140,6 +140,108 @@ is_truetype (FT_Face face)
return strcmp (FT_MODULE_CLASS (face->driver)->module_name, "truetype") == 0;
}
+typedef struct _GlyphInfo GlyphInfo;
+
+struct _GlyphInfo {
+ FT_UShort glyph;
+ FT_UShort class;
+};
+
+static int
+compare_glyph_info (gconstpointer a,
+ gconstpointer b)
+{
+ const GlyphInfo *info_a = a;
+ const GlyphInfo *info_b = b;
+
+ return (info_a->glyph < info_b->glyph) ? -1 :
+ (info_a->glyph == info_b->glyph) ? 0 : 1;
+}
+
+/* Make a guess at the appropriate class for a glyph given
+ * a character code that maps to the glyph
+ */
+static FT_UShort
+get_glyph_class (gunichar charcode)
+{
+ switch (g_unichar_type (charcode))
+ {
+ case G_UNICODE_COMBINING_MARK:
+ case G_UNICODE_ENCLOSING_MARK:
+ case G_UNICODE_NON_SPACING_MARK:
+ return 3; /* Mark glyph (non-spacing combining glyph) */
+ default:
+ return 1; /* Base glyph (single character, spacing glyph) */
+ }
+}
+
+/* Synthesize a GDEF table using the font's charmap and the
+ * unicode property database. We'll fill in class definitions
+ * for glyphs not in the charmap as we walk through the tables.
+ */
+static void
+synthesize_class_def (PangoOTInfo *info)
+{
+ GArray *glyph_infos;
+ FT_UShort *glyph_indices;
+ FT_UShort *classes;
+ FT_ULong charcode;
+ FT_UInt glyph;
+ int i, j;
+
+ if (info->face->charmap->encoding != ft_encoding_unicode)
+ return;
+
+ glyph_infos = g_array_new (FALSE, FALSE, sizeof (GlyphInfo));
+
+ /* Collect all the glyphs in the charmap, and guess
+ * the appropriate classes for them
+ */
+ charcode = FT_Get_First_Char (info->face, &glyph);
+ while (glyph != 0)
+ {
+ GlyphInfo glyph_info;
+
+ if (glyph > 65535)
+ continue;
+
+ glyph_info.glyph = glyph;
+ glyph_info.class = get_glyph_class (charcode);
+
+ g_array_append_val (glyph_infos, glyph_info);
+
+ charcode = FT_Get_Next_Char (info->face, charcode, &glyph);
+ }
+
+ /* Sort and remove duplicates
+ */
+ g_array_sort (glyph_infos, compare_glyph_info);
+
+ glyph_indices = g_new (FT_UShort, glyph_infos->len);
+ classes = g_new (FT_UShort, glyph_infos->len);
+
+ for (i = 0, j = 0; i < glyph_infos->len; i++)
+ {
+ GlyphInfo *info = &g_array_index (glyph_infos, GlyphInfo, i);
+
+ if (j == 0 || info->glyph != glyph_indices[j - 1])
+ {
+ glyph_indices[j] = info->glyph;
+ classes[j] = info->class;
+
+ j++;
+ }
+ }
+
+ g_array_free (glyph_infos, TRUE);
+
+ TT_GDEF_Build_ClassDefinition (info->gdef, info->face->num_glyphs, j,
+ glyph_indices, classes);
+
+ g_free (glyph_indices);
+ g_free (classes);
+}
+
TTO_GDEF
pango_ot_info_get_gdef (PangoOTInfo *info)
{
@@ -157,6 +259,12 @@ pango_ot_info_get_gdef (PangoOTInfo *info)
if (error && error != TT_Err_Table_Missing)
g_warning ("Error loading GDEF table %d", error);
+
+ if (!info->gdef)
+ error = TT_New_GDEF_Table (info->face, &info->gdef);
+
+ if (info->gdef && !info->gdef->GlyphClassDef.loaded)
+ synthesize_class_def (info);
}
}