aboutsummaryrefslogtreecommitdiff
path: root/freetype/src/autofit/afglobal.c
diff options
context:
space:
mode:
Diffstat (limited to 'freetype/src/autofit/afglobal.c')
-rw-r--r--freetype/src/autofit/afglobal.c355
1 files changed, 257 insertions, 98 deletions
diff --git a/freetype/src/autofit/afglobal.c b/freetype/src/autofit/afglobal.c
index 3e4146575..7aa2e1102 100644
--- a/freetype/src/autofit/afglobal.c
+++ b/freetype/src/autofit/afglobal.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter routines to compute global hinting values (body). */
/* */
-/* Copyright 2003-2013 by */
+/* Copyright 2003-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -17,107 +17,214 @@
#include "afglobal.h"
-#include "afdummy.h"
-#include "aflatin.h"
-#include "afcjk.h"
-#include "afindic.h"
-#include "afpic.h"
+#include "afranges.h"
+#include "hbshim.h"
+#include FT_INTERNAL_DEBUG_H
+
+
+ /*************************************************************************/
+ /* */
+ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
+ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
+ /* messages during execution. */
+ /* */
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_afglobal
+
+
+ /* get writing system specific header files */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) /* empty */
+#include "afwrtsys.h"
#include "aferrors.h"
+#include "afpic.h"
+
+
+#undef SCRIPT
+#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"
+
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ AF_DEFINE_STYLE_CLASS( \
+ af_ ## s ## _style_class, \
+ AF_STYLE_ ## S, \
+ ws, \
+ sc, \
+ ss, \
+ c )
+
+#include "afstyles.h"
-#ifdef FT_OPTION_AUTOFIT2
-#include "aflatin2.h"
-#endif
#ifndef FT_CONFIG_OPTION_PIC
- /* when updating this table, don't forget to update */
- /* AF_SCRIPT_CLASSES_COUNT and autofit_module_class_pic_init */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) \
+ &af_ ## ws ## _writing_system_class,
- /* populate this list when you add new scripts */
- static AF_ScriptClass const af_script_classes[] =
+ FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass )
+ af_writing_system_classes[] =
{
- &af_dummy_script_class,
-#ifdef FT_OPTION_AUTOFIT2
- &af_latin2_script_class,
-#endif
- &af_latin_script_class,
- &af_cjk_script_class,
- &af_indic_script_class,
+
+#include "afwrtsys.h"
+
+ NULL /* do not remove */
+ };
+
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ &af_ ## s ## _script_class,
+
+ FT_LOCAL_ARRAY_DEF( AF_ScriptClass )
+ af_script_classes[] =
+ {
+
+#include "afscript.h"
+
+ NULL /* do not remove */
+ };
+
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ &af_ ## s ## _style_class,
+
+ FT_LOCAL_ARRAY_DEF( AF_StyleClass )
+ af_style_classes[] =
+ {
+
+#include "afstyles.h"
+
NULL /* do not remove */
};
#endif /* !FT_CONFIG_OPTION_PIC */
- /* Compute the script index of each glyph within a given face. */
+#ifdef FT_DEBUG_LEVEL_TRACE
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) #s,
+
+ FT_LOCAL_ARRAY_DEF( char* )
+ af_style_names[] =
+ {
+
+#include "afstyles.h"
+
+ };
+
+#endif /* FT_DEBUG_LEVEL_TRACE */
+
+
+ /* Compute the style index of each glyph within a given face. */
static FT_Error
- af_face_globals_compute_script_coverage( AF_FaceGlobals globals )
+ af_face_globals_compute_style_coverage( AF_FaceGlobals globals )
{
FT_Error error;
FT_Face face = globals->face;
FT_CharMap old_charmap = face->charmap;
- FT_Byte* gscripts = globals->glyph_scripts;
+ FT_Byte* gstyles = globals->glyph_styles;
FT_UInt ss;
FT_UInt i;
+ FT_UInt dflt = -1;
- /* the value AF_SCRIPT_NONE means `uncovered glyph' */
- FT_MEM_SET( globals->glyph_scripts,
- AF_SCRIPT_NONE,
+ /* the value AF_STYLE_UNASSIGNED means `uncovered glyph' */
+ FT_MEM_SET( globals->glyph_styles,
+ AF_STYLE_UNASSIGNED,
globals->glyph_count );
error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
if ( error )
{
- /*
- * Ignore this error; we simply use the fallback script.
- * XXX: Shouldn't we rather disable hinting?
- */
+ /*
+ * Ignore this error; we simply use the fallback style.
+ * XXX: Shouldn't we rather disable hinting?
+ */
error = FT_Err_Ok;
goto Exit;
}
- /* scan each script in a Unicode charmap */
- for ( ss = 0; AF_SCRIPT_CLASSES_GET[ss]; ss++ )
+ /* scan each style in a Unicode charmap */
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
- AF_ScriptClass clazz = AF_SCRIPT_CLASSES_GET[ss];
+ AF_StyleClass style_class =
+ AF_STYLE_CLASSES_GET[ss];
+ AF_ScriptClass script_class =
+ AF_SCRIPT_CLASSES_GET[style_class->script];
AF_Script_UniRange range;
- if ( clazz->script_uni_ranges == NULL )
+ if ( script_class->script_uni_ranges == NULL )
continue;
/*
* Scan all Unicode points in the range and set the corresponding
- * glyph script index.
+ * glyph style index.
*/
- for ( range = clazz->script_uni_ranges; range->first != 0; range++ )
+ if ( style_class->coverage == AF_COVERAGE_DEFAULT )
{
- FT_ULong charcode = range->first;
- FT_UInt gindex;
+ if ( style_class->script == globals->module->default_script )
+ dflt = ss;
+
+ for ( range = script_class->script_uni_ranges;
+ range->first != 0;
+ range++ )
+ {
+ FT_ULong charcode = range->first;
+ FT_UInt gindex;
- gindex = FT_Get_Char_Index( face, charcode );
+ gindex = FT_Get_Char_Index( face, charcode );
- if ( gindex != 0 &&
- gindex < (FT_ULong)globals->glyph_count &&
- gscripts[gindex] == AF_SCRIPT_NONE )
- gscripts[gindex] = (FT_Byte)ss;
+ if ( gindex != 0 &&
+ gindex < (FT_ULong)globals->glyph_count &&
+ gstyles[gindex] == AF_STYLE_UNASSIGNED )
+ gstyles[gindex] = (FT_Byte)ss;
- for (;;)
- {
- charcode = FT_Get_Next_Char( face, charcode, &gindex );
+ for (;;)
+ {
+ charcode = FT_Get_Next_Char( face, charcode, &gindex );
- if ( gindex == 0 || charcode > range->last )
- break;
+ if ( gindex == 0 || charcode > range->last )
+ break;
- if ( gindex < (FT_ULong)globals->glyph_count &&
- gscripts[gindex] == AF_SCRIPT_NONE )
- gscripts[gindex] = (FT_Byte)ss;
+ if ( gindex < (FT_ULong)globals->glyph_count &&
+ gstyles[gindex] == AF_STYLE_UNASSIGNED )
+ gstyles[gindex] = (FT_Byte)ss;
+ }
}
}
+ else
+ {
+ /* get glyphs not directly addressable by cmap */
+ af_get_coverage( globals, style_class, gstyles );
+ }
+ }
+
+ /* handle the default OpenType features of the default script ... */
+ af_get_coverage( globals, AF_STYLE_CLASSES_GET[dflt], gstyles );
+
+ /* ... and the remaining default OpenType features */
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
+ {
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
+
+
+ if ( ss != dflt && style_class->coverage == AF_COVERAGE_DEFAULT )
+ af_get_coverage( globals, style_class, gstyles );
}
/* mark ASCII digits */
@@ -127,29 +234,68 @@
if ( gindex != 0 && gindex < (FT_ULong)globals->glyph_count )
- gscripts[gindex] |= AF_DIGIT;
+ gstyles[gindex] |= AF_DIGIT;
}
Exit:
/*
- * By default, all uncovered glyphs are set to the fallback script.
+ * By default, all uncovered glyphs are set to the fallback style.
* XXX: Shouldn't we disable hinting or do something similar?
*/
- if ( globals->module->fallback_script != AF_SCRIPT_NONE )
+ if ( globals->module->fallback_style != AF_STYLE_UNASSIGNED )
{
FT_Long nn;
for ( nn = 0; nn < globals->glyph_count; nn++ )
{
- if ( ( gscripts[nn] & ~AF_DIGIT ) == AF_SCRIPT_NONE )
+ if ( ( gstyles[nn] & ~AF_DIGIT ) == AF_STYLE_UNASSIGNED )
+ {
+ gstyles[nn] &= ~AF_STYLE_UNASSIGNED;
+ gstyles[nn] |= globals->module->fallback_style;
+ }
+ }
+ }
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+
+ FT_TRACE4(( "\n"
+ "style coverage\n"
+ "==============\n"
+ "\n" ));
+
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
+ {
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
+ FT_UInt count = 0;
+ FT_Long idx;
+
+
+ FT_TRACE4(( "%s:\n", af_style_names[style_class->style] ));
+
+ for ( idx = 0; idx < globals->glyph_count; idx++ )
+ {
+ if ( ( gstyles[idx] & ~AF_DIGIT ) == style_class->style )
{
- gscripts[nn] &= ~AF_SCRIPT_NONE;
- gscripts[nn] |= globals->module->fallback_script;
+ if ( !( count % 10 ) )
+ FT_TRACE4(( " " ));
+
+ FT_TRACE4(( " %d", idx ));
+ count++;
+
+ if ( !( count % 10 ) )
+ FT_TRACE4(( "\n" ));
}
}
+
+ if ( !count )
+ FT_TRACE4(( " (none)\n" ));
+ if ( count % 10 )
+ FT_TRACE4(( "\n" ));
}
+#endif /* FT_DEBUG_LEVEL_TRACE */
+
FT_Set_Charmap( face, old_charmap );
return error;
}
@@ -171,12 +317,16 @@
face->num_glyphs * sizeof ( FT_Byte ) ) )
goto Exit;
- globals->face = face;
- globals->glyph_count = face->num_glyphs;
- globals->glyph_scripts = (FT_Byte*)( globals + 1 );
- globals->module = module;
+ globals->face = face;
+ globals->glyph_count = face->num_glyphs;
+ globals->glyph_styles = (FT_Byte*)( globals + 1 );
+ globals->module = module;
- error = af_face_globals_compute_script_coverage( globals );
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ globals->hb_font = hb_ft_font_create( face, NULL );
+#endif
+
+ error = af_face_globals_compute_style_coverage( globals );
if ( error )
{
af_face_globals_free( globals );
@@ -200,25 +350,31 @@
FT_UInt nn;
- for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ )
+ for ( nn = 0; nn < AF_STYLE_MAX; nn++ )
{
if ( globals->metrics[nn] )
{
- AF_ScriptClass clazz = AF_SCRIPT_CLASSES_GET[nn];
-
+ AF_StyleClass style_class =
+ AF_STYLE_CLASSES_GET[nn];
+ AF_WritingSystemClass writing_system_class =
+ AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
- FT_ASSERT( globals->metrics[nn]->clazz == clazz );
- if ( clazz->script_metrics_done )
- clazz->script_metrics_done( globals->metrics[nn] );
+ if ( writing_system_class->style_metrics_done )
+ writing_system_class->style_metrics_done( globals->metrics[nn] );
FT_FREE( globals->metrics[nn] );
}
}
- globals->glyph_count = 0;
- globals->glyph_scripts = NULL; /* no need to free this one! */
- globals->face = NULL;
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ hb_font_destroy( globals->hb_font );
+ globals->hb_font = NULL;
+#endif
+
+ globals->glyph_count = 0;
+ globals->glyph_styles = NULL; /* no need to free this one! */
+ globals->face = NULL;
FT_FREE( globals );
}
@@ -226,18 +382,18 @@
FT_LOCAL_DEF( FT_Error )
- af_face_globals_get_metrics( AF_FaceGlobals globals,
- FT_UInt gindex,
- FT_UInt options,
- AF_ScriptMetrics *ametrics )
+ af_face_globals_get_metrics( AF_FaceGlobals globals,
+ FT_UInt gindex,
+ FT_UInt options,
+ AF_StyleMetrics *ametrics )
{
- AF_ScriptMetrics metrics = NULL;
- FT_UInt gidx;
- AF_ScriptClass clazz;
- FT_UInt script = options & 15;
- const FT_Offset script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
- sizeof ( AF_SCRIPT_CLASSES_GET[0] );
- FT_Error error = FT_Err_Ok;
+ AF_StyleMetrics metrics = NULL;
+
+ AF_Style style = (AF_Style)options;
+ AF_WritingSystemClass writing_system_class;
+ AF_StyleClass style_class;
+
+ FT_Error error = FT_Err_Ok;
if ( gindex >= (FT_ULong)globals->glyph_count )
@@ -246,41 +402,44 @@
goto Exit;
}
- gidx = script;
- if ( gidx == 0 || gidx + 1 >= script_max )
- gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_NONE;
+ /* if we have a forced style (via `options'), use it, */
+ /* otherwise look into `glyph_styles' array */
+ if ( style == AF_STYLE_NONE_DFLT || style + 1 >= AF_STYLE_MAX )
+ style = (AF_Style)( globals->glyph_styles[gindex] &
+ AF_STYLE_UNASSIGNED );
- clazz = AF_SCRIPT_CLASSES_GET[gidx];
- if ( script == 0 )
- script = clazz->script;
+ style_class = AF_STYLE_CLASSES_GET[style];
+ writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
+ [style_class->writing_system];
- metrics = globals->metrics[clazz->script];
+ metrics = globals->metrics[style];
if ( metrics == NULL )
{
/* create the global metrics object if necessary */
FT_Memory memory = globals->face->memory;
- if ( FT_ALLOC( metrics, clazz->script_metrics_size ) )
+ if ( FT_ALLOC( metrics, writing_system_class->style_metrics_size ) )
goto Exit;
- metrics->clazz = clazz;
- metrics->globals = globals;
+ metrics->style_class = style_class;
+ metrics->globals = globals;
- if ( clazz->script_metrics_init )
+ if ( writing_system_class->style_metrics_init )
{
- error = clazz->script_metrics_init( metrics, globals->face );
+ error = writing_system_class->style_metrics_init( metrics,
+ globals->face );
if ( error )
{
- if ( clazz->script_metrics_done )
- clazz->script_metrics_done( metrics );
+ if ( writing_system_class->style_metrics_done )
+ writing_system_class->style_metrics_done( metrics );
FT_FREE( metrics );
goto Exit;
}
}
- globals->metrics[clazz->script] = metrics;
+ globals->metrics[style] = metrics;
}
Exit:
@@ -295,7 +454,7 @@
FT_UInt gindex )
{
if ( gindex < (FT_ULong)globals->glyph_count )
- return (FT_Bool)( globals->glyph_scripts[gindex] & AF_DIGIT );
+ return (FT_Bool)( globals->glyph_styles[gindex] & AF_DIGIT );
return (FT_Bool)0;
}