From a8915b436b3844d3dc66a8b02d27f8af1d8dfb06 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 16 Sep 2012 08:43:20 +0200 Subject: [PATCH] Synchronize with FreeType. This is the first step to replace the abusal of the load flags with a clean solution, using the new property mechanism of FreeType. Note that we don't actually use properties since we don't have a module interface; instead of passing AF_Module we use our FONT structure. --- doc/ttfautohint-1.pandoc | 2 ++ lib/ta.h | 4 ++-- lib/tabytecode.c | 7 +++---- lib/tacvt.c | 7 +++---- lib/tafont.c | 2 +- lib/taglobal.c | 32 +++++++------------------------- lib/taglobal.h | 20 ++++++++++++++++++++ lib/talatin.c | 2 ++ lib/taloader.c | 29 +++++++++++++++++------------ lib/taloader.h | 23 ++++++++++++++--------- lib/ttfautohint.c | 5 ++--- 11 files changed, 73 insertions(+), 60 deletions(-) diff --git a/doc/ttfautohint-1.pandoc b/doc/ttfautohint-1.pandoc index f29f805..6a57a72 100644 --- a/doc/ttfautohint-1.pandoc +++ b/doc/ttfautohint-1.pandoc @@ -629,10 +629,12 @@ Unicode sense) which have similar typographical properties. `0x2460` - `0x24FF` Enclosed Alphanumerics `0x2C60` - `0x2C7F` Latin Extended-C `0x2DE0` - `0x2DFF` Cyrillic Extended-A + `0x2E00` - `0x2E7F` Supplemental Punctuation `0xA640` - `0xA69F` Cyrillic Extended-B `0xA720` - `0xA7FF` Latin Extended-D `0xFB00` - `0xFB06` Alphabetical Presentation Forms (Latin Ligatures) `0x1D400` - `0x1D7FF` Mathematical Alphanumeric Symbols + `0x1F100` - `0x1F1FF` Enclosed Alphanumeric Supplement If a glyph's character code is not covered by a script range, it is not hinted (or rather, it gets hinted by the 'dummy' auto-hinting module which diff --git a/lib/ta.h b/lib/ta.h index fe5af0c..7d5961c 100644 --- a/lib/ta.h +++ b/lib/ta.h @@ -173,7 +173,7 @@ typedef struct SFNT_ } SFNT; /* our font object */ -typedef struct FONT_ +struct FONT_ { FT_Library lib; @@ -213,7 +213,7 @@ typedef struct FONT_ FT_UInt fallback_script; FT_Bool symbol; FT_Bool debug; -} FONT; +}; #include "tatables.h" diff --git a/lib/tabytecode.c b/lib/tabytecode.c index 2bf3d48..547d5a2 100644 --- a/lib/tabytecode.c +++ b/lib/tabytecode.c @@ -1681,8 +1681,7 @@ TA_sfnt_build_glyph_instructions(SFNT* sfnt, /* XXX: right now, we abuse this flag to control */ /* the global behaviour of the auto-hinter */ - load_flags = font->fallback_script << 30; - load_flags |= 1 << 29; /* vertical hinting only */ + load_flags = 1 << 29; /* vertical hinting only */ /* values 0 and 6-20 compressed to 4 bits */ if (font->increase_x_height) load_flags |= (font->increase_x_height - 5) << 25; @@ -1708,7 +1707,7 @@ TA_sfnt_build_glyph_instructions(SFNT* sfnt, #endif ta_loader_register_hints_recorder(font->loader, NULL, NULL); - error = ta_loader_load_glyph(font->loader, face, (FT_UInt)idx, load_flags); + error = ta_loader_load_glyph(font, face, (FT_UInt)idx, load_flags); #ifdef TA_DEBUG _ta_debug = _ta_debug_save; @@ -1820,7 +1819,7 @@ TA_sfnt_build_glyph_instructions(SFNT* sfnt, /* calling `ta_loader_load_glyph' uses the */ /* `TA_hints_recorder' function as a callback, */ /* modifying `hints_record' */ - error = ta_loader_load_glyph(font->loader, face, idx, load_flags); + error = ta_loader_load_glyph(font, face, idx, load_flags); if (error) goto Err; diff --git a/lib/tacvt.c b/lib/tacvt.c index 50c9a4b..f895846 100644 --- a/lib/tacvt.c +++ b/lib/tacvt.c @@ -26,7 +26,7 @@ TA_sfnt_compute_global_hints(SFNT* sfnt, FT_Int32 load_flags; - error = ta_loader_init(font->loader); + error = ta_loader_init(font); if (error) return error; @@ -55,9 +55,8 @@ TA_sfnt_compute_global_hints(SFNT* sfnt, return TA_Err_Missing_Glyph; } - load_flags = font->fallback_script << 30; - load_flags |= 1 << 29; /* vertical hinting only */ - error = ta_loader_load_glyph(font->loader, face, idx, load_flags); + load_flags = 1 << 29; /* vertical hinting only */ + error = ta_loader_load_glyph(font, face, idx, load_flags); return error; } diff --git a/lib/tafont.c b/lib/tafont.c index c50a742..f64e0e1 100644 --- a/lib/tafont.c +++ b/lib/tafont.c @@ -61,7 +61,7 @@ TA_font_unload(FONT* font, return; if (font->loader) - ta_loader_done(font->loader); + ta_loader_done(font); if (font->tables) { diff --git a/lib/taglobal.c b/lib/taglobal.c index 4053616..1a767e5 100644 --- a/lib/taglobal.c +++ b/lib/taglobal.c @@ -49,24 +49,6 @@ static TA_ScriptClass const ta_script_classes[] = }; -/* a bit mask indicating an uncovered glyph */ -#define TA_SCRIPT_LIST_NONE 0x7F -/* if this flag is set, we have an ASCII digit */ -#define TA_DIGIT 0x80 - - -/* note that glyph_scripts[] is used to map each glyph into */ -/* an index into the `ta_script_classes' array. */ -typedef struct TA_FaceGlobalsRec_ -{ - FT_Face face; - FT_Long glyph_count; /* same as face->num_glyphs */ - FT_Byte* glyph_scripts; - - TA_ScriptMetrics metrics[TA_SCRIPT_MAX]; -} TA_FaceGlobalsRec; - - /* Compute the script index of each glyph within a given face. */ static FT_Error @@ -81,8 +63,8 @@ ta_face_globals_compute_script_coverage(TA_FaceGlobals globals, FT_UInt i; - /* the value TA_SCRIPT_LIST_NONE means `uncovered glyph' */ - memset(globals->glyph_scripts, TA_SCRIPT_LIST_NONE, globals->glyph_count); + /* the value TA_SCRIPT_NONE means `uncovered glyph' */ + memset(globals->glyph_scripts, TA_SCRIPT_NONE, globals->glyph_count); error = FT_Select_Charmap(face, FT_ENCODING_UNICODE); if (error) @@ -115,7 +97,7 @@ ta_face_globals_compute_script_coverage(TA_FaceGlobals globals, if (gindex != 0 && gindex < (FT_ULong)globals->glyph_count - && gscripts[gindex] == TA_SCRIPT_LIST_NONE) + && gscripts[gindex] == TA_SCRIPT_NONE) gscripts[gindex] = (FT_Byte)ss; for (;;) @@ -126,7 +108,7 @@ ta_face_globals_compute_script_coverage(TA_FaceGlobals globals, break; if (gindex < (FT_ULong)globals->glyph_count - && gscripts[gindex] == TA_SCRIPT_LIST_NONE) + && gscripts[gindex] == TA_SCRIPT_NONE) gscripts[gindex] = (FT_Byte)ss; } } @@ -152,9 +134,9 @@ Exit: for (nn = 0; nn < globals->glyph_count; nn++) { - if ((gscripts[nn] & ~TA_DIGIT) == TA_SCRIPT_LIST_NONE) + if ((gscripts[nn] & ~TA_DIGIT) == TA_SCRIPT_NONE) { - gscripts[nn] &= ~TA_SCRIPT_LIST_NONE; + gscripts[nn] &= ~TA_SCRIPT_NONE; gscripts[nn] |= fallback_script; } } @@ -260,7 +242,7 @@ ta_face_globals_get_metrics(TA_FaceGlobals globals, gidx = script; if (gidx == 0 || gidx + 1 >= script_max) - gidx = globals->glyph_scripts[gindex] & TA_SCRIPT_LIST_NONE; + gidx = globals->glyph_scripts[gindex] & TA_SCRIPT_NONE; clazz = ta_script_classes[gidx]; if (script == 0) diff --git a/lib/taglobal.h b/lib/taglobal.h index ed327ef..128e514 100644 --- a/lib/taglobal.h +++ b/lib/taglobal.h @@ -23,6 +23,26 @@ #include "tatypes.h" +/* index of fallback script in `ta_script_classes' */ +#define TA_SCRIPT_FALLBACK 0 +/* a bit mask indicating an uncovered glyph */ +#define TA_SCRIPT_NONE 0x7F +/* if this flag is set, we have an ASCII digit */ +#define TA_DIGIT 0x80 + + +/* note that glyph_scripts[] is used to map each glyph into */ +/* an index into the `ta_script_classes' array. */ +typedef struct TA_FaceGlobalsRec_ +{ + FT_Face face; + FT_Long glyph_count; /* same as face->num_glyphs */ + FT_Byte* glyph_scripts; + + TA_ScriptMetrics metrics[TA_SCRIPT_MAX]; +} TA_FaceGlobalsRec; + + /* this models the global hints data for a given face, */ /* decomposed into script-specific items */ typedef struct TA_FaceGlobalsRec_* TA_FaceGlobals; diff --git a/lib/talatin.c b/lib/talatin.c index 7986a1c..ea79c0d 100644 --- a/lib/talatin.c +++ b/lib/talatin.c @@ -2431,10 +2431,12 @@ static const TA_Script_UniRangeRec ta_latin_uniranges[] = TA_UNIRANGE_REC(0x2460UL, 0x24FFUL), /* Enclosed Alphanumerics */ TA_UNIRANGE_REC(0x2C60UL, 0x2C7FUL), /* Latin Extended-C */ TA_UNIRANGE_REC(0x2DE0UL, 0x2DFFUL), /* Cyrillic Extended-A */ + TA_UNIRANGE_REC(0x2E00UL, 0x2E7FUL), /* Supplemental Punctuation */ TA_UNIRANGE_REC(0xA640UL, 0xA69FUL), /* Cyrillic Extended-B */ TA_UNIRANGE_REC(0xA720UL, 0xA7FFUL), /* Latin Extended-D */ TA_UNIRANGE_REC(0xFB00UL, 0xFB06UL), /* Alphab. Present. Forms (Latin Ligs) */ TA_UNIRANGE_REC(0x1D400UL, 0x1D7FFUL), /* Mathematical Alphanumeric Symbols */ + TA_UNIRANGE_REC(0x1F100UL, 0x1F1FFUL), /* Enclosed Alphanumeric Supplement */ TA_UNIRANGE_REC(0UL, 0UL) }; diff --git a/lib/taloader.c b/lib/taloader.c index c449445..08420d5 100644 --- a/lib/taloader.c +++ b/lib/taloader.c @@ -22,7 +22,7 @@ #include #include FT_GLYPH_H -#include "taloader.h" +#include "ta.h" #include "tahints.h" #include "taglobal.h" @@ -42,8 +42,11 @@ typedef struct FT_Slot_InternalRec_ /* initialize glyph loader */ FT_Error -ta_loader_init(TA_Loader loader) +ta_loader_init(FONT* font) { + TA_Loader loader = font->loader; + + memset(loader, 0, sizeof (TA_LoaderRec)); ta_glyph_hints_init(&loader->hints); @@ -57,11 +60,11 @@ ta_loader_init(TA_Loader loader) /* reset glyph loader and compute globals if necessary */ FT_Error -ta_loader_reset(TA_Loader loader, - FT_Face face, - FT_UInt fallback_script) +ta_loader_reset(FONT* font, + FT_Face face) { FT_Error error = FT_Err_Ok; + TA_Loader loader = font->loader; loader->face = face; @@ -71,7 +74,8 @@ ta_loader_reset(TA_Loader loader, if (loader->globals == NULL) { - error = ta_face_globals_new(face, &loader->globals, fallback_script); + error = ta_face_globals_new(face, &loader->globals, + font->fallback_script); if (!error) { face->autohint.data = (FT_Pointer)loader->globals; @@ -86,8 +90,11 @@ ta_loader_reset(TA_Loader loader, /* finalize glyph loader */ void -ta_loader_done(TA_Loader loader) +ta_loader_done(FONT* font) { + TA_Loader loader = font->loader; + + ta_glyph_hints_done(&loader->hints); loader->face = NULL; @@ -487,15 +494,15 @@ Exit: /* load a glyph */ FT_Error -ta_loader_load_glyph(TA_Loader loader, +ta_loader_load_glyph(FONT* font, FT_Face face, FT_UInt gindex, FT_Int32 load_flags) { FT_Error error; FT_Size size = face->size; + TA_Loader loader = font->loader; TA_ScalerRec scaler; - FT_UInt fallback_script; if (!size) @@ -513,17 +520,15 @@ ta_loader_load_glyph(TA_Loader loader, scaler.flags = 0; /* XXX: fix this */ /* XXX this is an ugly hack of ttfautohint: */ - /* bits 30 and 31 of `load_flags' specify the fallback script, */ /* bit 29 triggers vertical hinting only, */ /* and bits 25-28 give the x height increase limit */ - fallback_script = load_flags >> 30; if (load_flags & (1 << 29)) scaler.flags |= TA_SCALER_FLAG_NO_HORIZONTAL; scaler.flags |= ((load_flags >> 25) & 15) << 3; /* bits 3-6 */ /* note that the fallback script can't be changed anymore */ /* after the first call of `ta_loader_load_glyph' */ - error = ta_loader_reset(loader, face, fallback_script); + error = ta_loader_reset(font, face); if (!error) { TA_ScriptMetrics metrics; diff --git a/lib/taloader.h b/lib/taloader.h index 31b7af6..3124a44 100644 --- a/lib/taloader.h +++ b/lib/taloader.h @@ -25,11 +25,16 @@ #include "tagloadr.h" +typedef struct FONT_ FONT; + typedef struct TA_LoaderRec_ { - FT_Face face; /* current face */ - TA_FaceGlobals globals; /* current face globals */ - TA_GlyphLoader gloader; /* glyph loader */ + /* current face data */ + FT_Face face; + TA_FaceGlobals globals; + + /* current glyph data */ + TA_GlyphLoader gloader; TA_GlyphHintsRec hints; TA_ScriptMetrics metrics; FT_Bool transformed; @@ -42,20 +47,20 @@ typedef struct TA_LoaderRec_ FT_Error -ta_loader_init(TA_Loader loader); +ta_loader_init(FONT* font); FT_Error -ta_loader_reset(TA_Loader loader, - FT_Face face, - FT_UInt fallback_script); +ta_loader_reset(FONT* font, + FT_Face face); + void -ta_loader_done(TA_Loader loader); +ta_loader_done(FONT* font); FT_Error -ta_loader_load_glyph(TA_Loader loader, +ta_loader_load_glyph(FONT* font, FT_Face face, FT_UInt gindex, FT_Int32 load_flags); diff --git a/lib/ttfautohint.c b/lib/ttfautohint.c index e450b72..e32d2e9 100644 --- a/lib/ttfautohint.c +++ b/lib/ttfautohint.c @@ -69,7 +69,7 @@ TTF_autohint(const char* options, FT_Bool ignore_restrictions = 0; FT_Bool pre_hinting = 0; FT_Bool hint_with_components = 0; - FT_UInt fallback_script = 0; + FT_UInt fallback_script = TA_SCRIPT_FALLBACK; FT_Bool symbol = 0; FT_Bool debug = 0; @@ -274,8 +274,7 @@ TTF_autohint(const char* options, font->ignore_restrictions = ignore_restrictions; font->pre_hinting = pre_hinting; font->hint_with_components = hint_with_components; - /* restrict value to two bits */ - font->fallback_script = fallback_script & 3; + font->fallback_script = fallback_script; font->symbol = symbol; font->debug = debug; -- 2.11.4.GIT