From a3364001122a10b5dde340637ba19f6d27063250 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 26 Jan 2014 09:45:23 +0100 Subject: [PATCH] [autofit] Introduce two more slots for standard characters. This is useful for OpenType features like `c2sc' (caps to small caps) that don't have lowercase letters by definition, or other features that mainly operate on numerals. * src/autofit/afscript.h: Add more standard characters. * src/autofit/aftypes.h: Update use of `SCRIPT' macro. (AF_ScriptClassRec): Add members to hold two more standard characters. (AF_DEFINE_SCRIPT_CLASS): Updated. * src/autofit/afglobal.c, src/autofit/afglobal.h, * src/autofit/afpic.c, src/autofit/afranges.h, src/autofit/hbshim.c: Update use of `SCRIPT' macro. * src/autofit/afcjk.c (af_cjk_metrics_init_widths), src/autofit/aflatin.c (af_latin_metrics_init_widths): Scan two more standard characters. --- ChangeLog | 23 +++++++++++++++++++ src/autofit/afcjk.c | 36 +++++++++++++++++++++++++++--- src/autofit/afglobal.c | 14 ++++++------ src/autofit/afglobal.h | 4 ++-- src/autofit/aflatin.c | 46 +++++++++++++++++++++++++++++++++----- src/autofit/afpic.c | 4 ++-- src/autofit/afranges.h | 4 ++-- src/autofit/afscript.h | 50 +++++++++++++++++++++--------------------- src/autofit/aftypes.h | 23 ++++++++++++++----- src/autofit/hbshim.c | 2 +- 10 files changed, 152 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 918e86caf..61ca9d51b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2014-01-26 Werner Lemberg + + [autofit] Introduce two more slots for standard characters. + + This is useful for OpenType features like `c2sc' (caps to small + caps) that don't have lowercase letters by definition, or other + features that mainly operate on numerals. + + * src/autofit/afscript.h: Add more standard characters. + + * src/autofit/aftypes.h: Update use of `SCRIPT' macro. + (AF_ScriptClassRec): Add members to hold two more standard + characters. + (AF_DEFINE_SCRIPT_CLASS): Updated. + + * src/autofit/afglobal.c, src/autofit/afglobal.h, + * src/autofit/afpic.c, src/autofit/afranges.h, src/autofit/hbshim.c: + Update use of `SCRIPT' macro. + + * src/autofit/afcjk.c (af_cjk_metrics_init_widths), + src/autofit/aflatin.c (af_latin_metrics_init_widths): Scan two more + standard characters. + 2014-01-24 Werner Lemberg Fix Savannah bug #41320. diff --git a/src/autofit/afcjk.c b/src/autofit/afcjk.c index a1f0dca1d..96a209349 100644 --- a/src/autofit/afcjk.c +++ b/src/autofit/afcjk.c @@ -101,16 +101,46 @@ AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET [style_class->script]; + FT_UInt32 standard_char; + af_get_char_index( &metrics->root, - script_class->standard_char, + script_class->standard_char1, &glyph_index, &y_offset ); if ( glyph_index == 0 ) - goto Exit; + { + if ( script_class->standard_char2 ) + { + af_get_char_index( &metrics->root, + script_class->standard_char2, + &glyph_index, + &y_offset ); + if ( glyph_index == 0 ) + { + if ( script_class->standard_char3 ) + { + af_get_char_index( &metrics->root, + script_class->standard_char3, + &glyph_index, + &y_offset ); + if ( glyph_index == 0 ) + goto Exit; + else + standard_char = script_class->standard_char3; + } + } + else + standard_char = script_class->standard_char2; + } + else + goto Exit; + } + else + standard_char = script_class->standard_char1; FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n", - script_class->standard_char, glyph_index )); + standard_char, glyph_index )); error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); if ( error || face->glyph->outline.n_points <= 0 ) diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c index b587a90bf..7aa2e1102 100644 --- a/src/autofit/afglobal.c +++ b/src/autofit/afglobal.c @@ -42,12 +42,12 @@ #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ - AF_DEFINE_SCRIPT_CLASS( \ - af_ ## s ## _script_class, \ - AF_SCRIPT_ ## S, \ - af_ ## s ## _uniranges, \ - dc ) +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ + AF_DEFINE_SCRIPT_CLASS( \ + af_ ## s ## _script_class, \ + AF_SCRIPT_ ## S, \ + af_ ## s ## _uniranges, \ + sc1, sc2, sc3 ) #include "afscript.h" @@ -82,7 +82,7 @@ #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ &af_ ## s ## _script_class, FT_LOCAL_ARRAY_DEF( AF_ScriptClass ) diff --git a/src/autofit/afglobal.h b/src/autofit/afglobal.h index 0a7d273d8..d2da40e3c 100644 --- a/src/autofit/afglobal.h +++ b/src/autofit/afglobal.h @@ -5,7 +5,7 @@ /* Auto-fitter routines to compute global hinting values */ /* (specification). */ /* */ -/* Copyright 2003-2005, 2007, 2009, 2011-2013 by */ +/* Copyright 2003-2005, 2007, 2009, 2011-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -34,7 +34,7 @@ FT_BEGIN_HEADER #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ AF_DECLARE_SCRIPT_CLASS( af_ ## s ## _script_class ) #include "afscript.h" diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c index 8dac2209b..13351c2fe 100644 --- a/src/autofit/aflatin.c +++ b/src/autofit/aflatin.c @@ -88,19 +88,53 @@ AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET [style_class->script]; + FT_UInt32 standard_char; + + + /* + * We check more than a single standard character to catch features + * like `c2sc' (small caps from caps) that don't contain lowercase + * letters by definition, or other features that mainly operate on + * numerals. + */ - /* XXX: Extend this with a list of possible standard characters: */ - /* Especially in non-default coverages, a single standard */ - /* character may not be available. */ af_get_char_index( &metrics->root, - script_class->standard_char, + script_class->standard_char1, &glyph_index, &y_offset ); if ( glyph_index == 0 ) - goto Exit; + { + if ( script_class->standard_char2 ) + { + af_get_char_index( &metrics->root, + script_class->standard_char2, + &glyph_index, + &y_offset ); + if ( glyph_index == 0 ) + { + if ( script_class->standard_char3 ) + { + af_get_char_index( &metrics->root, + script_class->standard_char3, + &glyph_index, + &y_offset ); + if ( glyph_index == 0 ) + goto Exit; + else + standard_char = script_class->standard_char3; + } + } + else + standard_char = script_class->standard_char2; + } + else + goto Exit; + } + else + standard_char = script_class->standard_char1; FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n", - script_class->standard_char, glyph_index )); + standard_char, glyph_index )); error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); if ( error || face->glyph->outline.n_points <= 0 ) diff --git a/src/autofit/afpic.c b/src/autofit/afpic.c index 3980307f2..cb29fd79f 100644 --- a/src/autofit/afpic.c +++ b/src/autofit/afpic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for autofit module. */ /* */ -/* Copyright 2009-2013 by */ +/* Copyright 2009-2014 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -122,7 +122,7 @@ #include "afwrtsys.h" #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ FT_Init_Class_af_ ## s ## _script_class( \ &container->af_script_classes_rec[ss++] ); diff --git a/src/autofit/afranges.h b/src/autofit/afranges.h index cb04a3b9f..fe5b2aa7c 100644 --- a/src/autofit/afranges.h +++ b/src/autofit/afranges.h @@ -4,7 +4,7 @@ /* */ /* Auto-fitter Unicode script ranges (specification). */ /* */ -/* Copyright 2013 by */ +/* Copyright 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -26,7 +26,7 @@ FT_BEGIN_HEADER #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ extern const AF_Script_UniRangeRec af_ ## s ## _uniranges[]; #include "afscript.h" diff --git a/src/autofit/afscript.h b/src/autofit/afscript.h index 562e15bb3..ae209322e 100644 --- a/src/autofit/afscript.h +++ b/src/autofit/afscript.h @@ -20,108 +20,108 @@ /* Define `SCRIPT' as needed. */ - /* Add new scripts here. The first and second arguments are the */ - /* script name in lowercase and uppercase, respectively, followed */ - /* by a description string. Then comes the corresponding HarfBuzz */ - /* script name tag, followed by the default character (to derive */ - /* the standard width and height of stems). */ + /* Add new scripts here. The first and second arguments are the */ + /* script name in lowercase and uppercase, respectively, followed */ + /* by a description string. Then comes the corresponding HarfBuzz */ + /* script name tag, followed by a string of standard characters (to */ + /* derive the standard width and height of stems). */ SCRIPT( cyrl, CYRL, "Cyrillic", HB_SCRIPT_CYRILLIC, - 0x43E ) /* о */ + 0x43E, 0x41E, 0x0 ) /* оО */ SCRIPT( grek, GREK, "Greek", HB_SCRIPT_GREEK, - 0x3BF ) /* ο */ + 0x3BF, 0x39F, 0x0 ) /* οΟ */ SCRIPT( hebr, HEBR, "Hebrew", HB_SCRIPT_HEBREW, - 0x5DD ) /* ם */ + 0x5DD, 0x0, 0x0 ) /* ם */ SCRIPT( latn, LATN, "Latin", HB_SCRIPT_LATIN, - 'o' ) + 'o', 'O', '0' ) SCRIPT( none, NONE, "no script", HB_SCRIPT_INVALID, - '\0' ) + 0x0, 0x0, 0x0 ) #ifdef AF_CONFIG_OPTION_INDIC SCRIPT( beng, BENG, "Bengali", HB_SCRIPT_BENGALI, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( deva, DEVA, "Devanagari", HB_SCRIPT_DEVANAGARI, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( gujr, GUJR, "Gujarati", HB_SCRIPT_GUJARATI, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( guru, GURU, "Gurmukhi", HB_SCRIPT_GURMUKHI, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( knda, KNDA, "Kannada", HB_SCRIPT_KANNADA, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( limb, LIMB, "Limbu", HB_SCRIPT_LIMBU, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( mlym, MLYM, "Malayalam", HB_SCRIPT_MALAYALAM, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( orya, ORYA, "Oriya", HB_SCRIPT_ORIYA, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( sinh, SINH, "Sinhala", HB_SCRIPT_SINHALA, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( sund, SUND, "Sundanese", HB_SCRIPT_SUNDANESE, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( sylo, SYLO, "Syloti Nagri", HB_SCRIPT_SYLOTI_NAGRI, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( taml, TAML, "Tamil", HB_SCRIPT_TAMIL, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( telu, TELU, "Telugu", HB_SCRIPT_TELUGU, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ SCRIPT( tibt, TIBT, "Tibetan", HB_SCRIPT_TIBETAN, - 'o' ) /* XXX */ + 'o', 0x0, 0x0 ) /* XXX */ #endif /* AF_CONFIG_OPTION_INDIC */ @@ -130,7 +130,7 @@ SCRIPT( hani, HANI, "CJKV ideographs", HB_SCRIPT_HAN, - 0x7530 ) /* 田 */ + 0x7530, 0x56D7, 0x0 ) /* 田囗 */ #endif /* AF_CONFIG_OPTION_CJK */ diff --git a/src/autofit/aftypes.h b/src/autofit/aftypes.h index 0f599f7cb..61badd1b8 100644 --- a/src/autofit/aftypes.h +++ b/src/autofit/aftypes.h @@ -303,7 +303,7 @@ extern void* _af_debug_hints; */ #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) \ +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \ AF_SCRIPT_ ## S, /* The list of known scripts. */ @@ -334,7 +334,10 @@ extern void* _af_debug_hints; AF_Script script; AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */ - FT_UInt32 standard_char; /* for default width and height */ + + FT_UInt32 standard_char1; /* for default width and height */ + FT_UInt32 standard_char2; /* ditto */ + FT_UInt32 standard_char3; /* ditto */ } AF_ScriptClassRec; @@ -510,13 +513,17 @@ extern void* _af_debug_hints; script_class, \ script, \ ranges, \ - std_char ) \ + std_char1, \ + std_char2, \ + std_char3 ) \ FT_CALLBACK_TABLE_DEF \ const AF_ScriptClassRec script_class = \ { \ script, \ ranges, \ - std_char \ + std_char1, \ + std_char2, \ + std_char3 \ }; @@ -580,13 +587,17 @@ extern void* _af_debug_hints; script_class, \ script_, \ ranges, \ - std_char ) \ + std_char1, \ + std_char2, \ + std_char3 ) \ FT_LOCAL_DEF( void ) \ FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac ) \ { \ ac->script = script_; \ ac->script_uni_ranges = ranges; \ - ac->standard_char = std_char; \ + ac->standard_char1 = std_char1; \ + ac->standard_char2 = std_char2; \ + ac->standard_char3 = std_char3; \ } diff --git a/src/autofit/hbshim.c b/src/autofit/hbshim.c index 35cf1d341..812cd53d8 100644 --- a/src/autofit/hbshim.c +++ b/src/autofit/hbshim.c @@ -84,7 +84,7 @@ /* load HarfBuzz script tags */ #undef SCRIPT -#define SCRIPT( s, S, d, h, dc ) h, +#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) h, static const hb_tag_t scripts[] =