2005-03-03 18:09:08 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* afglobal.c */
|
|
|
|
/* */
|
|
|
|
/* Auto-fitter routines to compute global hinting values (body). */
|
|
|
|
/* */
|
2013-03-14 10:27:35 +01:00
|
|
|
/* Copyright 2003-2013 by */
|
2005-03-03 18:09:08 +01:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
#include "afglobal.h"
|
2013-08-02 19:51:17 +02:00
|
|
|
|
|
|
|
/* get writing system specific header files */
|
|
|
|
#undef WRITING_SYSTEM
|
|
|
|
#define WRITING_SYSTEM( ws, WS ) /* empty */
|
|
|
|
#include "afwrtsys.h"
|
2007-06-26 06:44:35 +02:00
|
|
|
|
2005-03-23 17:45:24 +01:00
|
|
|
#include "aferrors.h"
|
2013-08-02 19:51:17 +02:00
|
|
|
#include "afpic.h"
|
|
|
|
|
2009-04-05 17:23:38 +02:00
|
|
|
|
2013-09-25 23:32:25 +02:00
|
|
|
#ifndef FT_CONFIG_OPTION_PIC
|
2013-07-31 22:49:29 +02:00
|
|
|
|
2013-08-02 19:51:17 +02:00
|
|
|
#undef WRITING_SYSTEM
|
|
|
|
#define WRITING_SYSTEM( ws, WS ) \
|
|
|
|
&af_ ## ws ## _writing_system_class,
|
|
|
|
|
2013-08-02 14:50:23 +02:00
|
|
|
FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass )
|
|
|
|
af_writing_system_classes[] =
|
2013-07-31 22:49:29 +02:00
|
|
|
{
|
2013-08-02 19:51:17 +02:00
|
|
|
|
|
|
|
#include "afwrtsys.h"
|
|
|
|
|
2013-07-31 22:49:29 +02:00
|
|
|
NULL /* do not remove */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-02 20:25:21 +02:00
|
|
|
#undef SCRIPT
|
2013-10-17 11:08:25 +02:00
|
|
|
#define SCRIPT( s, S, d ) \
|
2013-08-02 20:25:21 +02:00
|
|
|
&af_ ## s ## _script_class,
|
2009-04-05 17:23:38 +02:00
|
|
|
|
2013-08-02 14:50:23 +02:00
|
|
|
FT_LOCAL_ARRAY_DEF( AF_ScriptClass )
|
|
|
|
af_script_classes[] =
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2013-08-02 20:25:21 +02:00
|
|
|
|
|
|
|
#include "afscript.h"
|
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
NULL /* do not remove */
|
|
|
|
};
|
|
|
|
|
2011-01-23 12:42:23 +01:00
|
|
|
#endif /* !FT_CONFIG_OPTION_PIC */
|
2009-04-05 17:23:38 +02:00
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2013-08-27 18:37:39 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
|
|
|
|
#undef SCRIPT
|
2013-10-17 11:08:25 +02:00
|
|
|
#define SCRIPT( s, S, d ) #s,
|
2013-08-27 18:37:39 +02:00
|
|
|
|
|
|
|
FT_LOCAL_ARRAY_DEF( char* )
|
|
|
|
af_script_names[] =
|
|
|
|
{
|
|
|
|
|
|
|
|
#include "afscript.h"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FT_DEBUG_LEVEL_TRACE */
|
|
|
|
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
/* Compute the script index of each glyph within a given face. */
|
2003-11-23 22:39:51 +01:00
|
|
|
|
|
|
|
static FT_Error
|
2012-09-18 15:23:41 +02:00
|
|
|
af_face_globals_compute_script_coverage( AF_FaceGlobals globals )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Error error;
|
2003-11-23 22:39:51 +01:00
|
|
|
FT_Face face = globals->face;
|
|
|
|
FT_CharMap old_charmap = face->charmap;
|
|
|
|
FT_Byte* gscripts = globals->glyph_scripts;
|
2012-07-06 19:38:44 +02:00
|
|
|
FT_UInt ss;
|
|
|
|
FT_UInt i;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2012-09-12 17:45:39 +02:00
|
|
|
/* the value AF_SCRIPT_NONE means `uncovered glyph' */
|
2003-11-23 22:39:51 +01:00
|
|
|
FT_MEM_SET( globals->glyph_scripts,
|
2012-09-12 17:45:39 +02:00
|
|
|
AF_SCRIPT_NONE,
|
2003-11-23 22:39:51 +01:00
|
|
|
globals->glyph_count );
|
|
|
|
|
|
|
|
error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
|
|
|
|
if ( error )
|
|
|
|
{
|
2005-03-03 18:09:08 +01:00
|
|
|
/*
|
2012-09-15 18:26:28 +02:00
|
|
|
* Ignore this error; we simply use the fallback script.
|
2008-05-15 01:05:38 +02:00
|
|
|
* XXX: Shouldn't we rather disable hinting?
|
2003-11-23 22:39:51 +01:00
|
|
|
*/
|
2013-03-14 11:21:17 +01:00
|
|
|
error = FT_Err_Ok;
|
2003-11-23 22:39:51 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
/* scan each script in a Unicode charmap */
|
2009-04-05 17:23:38 +02:00
|
|
|
for ( ss = 0; AF_SCRIPT_CLASSES_GET[ss]; ss++ )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2013-07-30 23:17:04 +02:00
|
|
|
AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET[ss];
|
2003-11-23 22:39:51 +01:00
|
|
|
AF_Script_UniRange range;
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2013-07-30 23:17:04 +02:00
|
|
|
if ( script_class->script_uni_ranges == NULL )
|
2004-02-23 22:08:37 +01:00
|
|
|
continue;
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
/*
|
2012-07-06 19:38:44 +02:00
|
|
|
* Scan all Unicode points in the range and set the corresponding
|
2005-03-03 18:09:08 +01:00
|
|
|
* glyph script index.
|
|
|
|
*/
|
2013-07-30 23:17:04 +02:00
|
|
|
for ( range = script_class->script_uni_ranges;
|
|
|
|
range->first != 0;
|
|
|
|
range++ )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
|
|
|
FT_ULong charcode = range->first;
|
|
|
|
FT_UInt gindex;
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
gindex = FT_Get_Char_Index( face, charcode );
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
if ( gindex != 0 &&
|
2009-07-31 17:32:08 +02:00
|
|
|
gindex < (FT_ULong)globals->glyph_count &&
|
2012-09-12 17:45:39 +02:00
|
|
|
gscripts[gindex] == AF_SCRIPT_NONE )
|
2005-03-03 18:09:08 +01:00
|
|
|
gscripts[gindex] = (FT_Byte)ss;
|
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
charcode = FT_Get_Next_Char( face, charcode, &gindex );
|
|
|
|
|
|
|
|
if ( gindex == 0 || charcode > range->last )
|
|
|
|
break;
|
|
|
|
|
2009-07-31 17:32:08 +02:00
|
|
|
if ( gindex < (FT_ULong)globals->glyph_count &&
|
2012-09-12 17:45:39 +02:00
|
|
|
gscripts[gindex] == AF_SCRIPT_NONE )
|
2005-03-03 18:09:08 +01:00
|
|
|
gscripts[gindex] = (FT_Byte)ss;
|
2003-11-23 22:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-27 19:40:35 +02:00
|
|
|
/* mark ASCII digits */
|
|
|
|
for ( i = 0x30; i <= 0x39; i++ )
|
|
|
|
{
|
|
|
|
FT_UInt gindex = FT_Get_Char_Index( face, i );
|
|
|
|
|
|
|
|
|
2009-07-31 17:37:54 +02:00
|
|
|
if ( gindex != 0 && gindex < (FT_ULong)globals->glyph_count )
|
2009-04-27 19:40:35 +02:00
|
|
|
gscripts[gindex] |= AF_DIGIT;
|
|
|
|
}
|
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
Exit:
|
2005-03-03 18:09:08 +01:00
|
|
|
/*
|
2012-09-15 18:26:28 +02:00
|
|
|
* By default, all uncovered glyphs are set to the fallback script.
|
2007-01-31 00:08:50 +01:00
|
|
|
* XXX: Shouldn't we disable hinting or do something similar?
|
2005-03-03 18:09:08 +01:00
|
|
|
*/
|
2012-09-29 22:40:40 +02:00
|
|
|
if ( globals->module->fallback_script != AF_SCRIPT_NONE )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2009-07-31 17:32:08 +02:00
|
|
|
FT_Long nn;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
for ( nn = 0; nn < globals->glyph_count; nn++ )
|
|
|
|
{
|
2012-09-12 17:45:39 +02:00
|
|
|
if ( ( gscripts[nn] & ~AF_DIGIT ) == AF_SCRIPT_NONE )
|
2010-06-15 08:29:30 +02:00
|
|
|
{
|
2012-09-12 17:45:39 +02:00
|
|
|
gscripts[nn] &= ~AF_SCRIPT_NONE;
|
2012-09-18 15:23:41 +02:00
|
|
|
gscripts[nn] |= globals->module->fallback_script;
|
2010-06-15 08:29:30 +02:00
|
|
|
}
|
2003-11-23 22:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FT_Set_Charmap( face, old_charmap );
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
af_face_globals_new( FT_Face face,
|
2012-09-15 10:33:43 +02:00
|
|
|
AF_FaceGlobals *aglobals,
|
2012-09-18 15:23:41 +02:00
|
|
|
AF_Module module )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory;
|
2010-07-12 21:13:22 +02:00
|
|
|
AF_FaceGlobals globals = NULL;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
memory = face->memory;
|
|
|
|
|
2012-07-06 19:38:44 +02:00
|
|
|
if ( FT_ALLOC( globals, sizeof ( *globals ) +
|
|
|
|
face->num_glyphs * sizeof ( FT_Byte ) ) )
|
|
|
|
goto Exit;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2012-07-06 19:38:44 +02:00
|
|
|
globals->face = face;
|
|
|
|
globals->glyph_count = face->num_glyphs;
|
|
|
|
globals->glyph_scripts = (FT_Byte*)( globals + 1 );
|
2012-09-18 15:23:41 +02:00
|
|
|
globals->module = module;
|
2012-07-06 19:38:44 +02:00
|
|
|
|
2012-09-18 15:23:41 +02:00
|
|
|
error = af_face_globals_compute_script_coverage( globals );
|
2012-07-06 19:38:44 +02:00
|
|
|
if ( error )
|
|
|
|
{
|
|
|
|
af_face_globals_free( globals );
|
|
|
|
globals = NULL;
|
2003-11-23 22:39:51 +01:00
|
|
|
}
|
|
|
|
|
2012-09-18 23:26:37 +02:00
|
|
|
globals->increase_x_height = AF_PROP_INCREASE_X_HEIGHT_MAX;
|
|
|
|
|
2012-07-06 19:38:44 +02:00
|
|
|
Exit:
|
2003-11-23 22:39:51 +01:00
|
|
|
*aglobals = globals;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( void )
|
|
|
|
af_face_globals_free( AF_FaceGlobals globals )
|
|
|
|
{
|
|
|
|
if ( globals )
|
|
|
|
{
|
|
|
|
FT_Memory memory = globals->face->memory;
|
|
|
|
FT_UInt nn;
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ )
|
|
|
|
{
|
|
|
|
if ( globals->metrics[nn] )
|
|
|
|
{
|
2013-07-31 22:49:29 +02:00
|
|
|
AF_ScriptClass script_class =
|
|
|
|
AF_SCRIPT_CLASSES_GET[nn];
|
|
|
|
AF_WritingSystemClass writing_system_class =
|
|
|
|
AF_WRITING_SYSTEM_CLASSES_GET[script_class->writing_system];
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2013-07-31 22:49:29 +02:00
|
|
|
if ( writing_system_class->script_metrics_done )
|
|
|
|
writing_system_class->script_metrics_done( globals->metrics[nn] );
|
2003-11-23 22:39:51 +01:00
|
|
|
|
|
|
|
FT_FREE( globals->metrics[nn] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-24 19:42:04 +01:00
|
|
|
globals->glyph_count = 0;
|
2005-03-03 18:09:08 +01:00
|
|
|
globals->glyph_scripts = NULL; /* no need to free this one! */
|
2003-11-23 22:39:51 +01:00
|
|
|
globals->face = NULL;
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
FT_FREE( globals );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
af_face_globals_get_metrics( AF_FaceGlobals globals,
|
|
|
|
FT_UInt gindex,
|
2007-06-11 07:37:35 +02:00
|
|
|
FT_UInt options,
|
2003-11-23 22:39:51 +01:00
|
|
|
AF_ScriptMetrics *ametrics )
|
|
|
|
{
|
|
|
|
AF_ScriptMetrics metrics = NULL;
|
2013-07-31 22:49:29 +02:00
|
|
|
|
2013-08-28 17:34:01 +02:00
|
|
|
AF_Script script = (AF_Script)( options & 15 );
|
2013-07-31 22:49:29 +02:00
|
|
|
AF_WritingSystemClass writing_system_class;
|
|
|
|
AF_ScriptClass script_class;
|
|
|
|
|
2013-08-26 09:58:50 +02:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2009-07-31 17:32:08 +02:00
|
|
|
if ( gindex >= (FT_ULong)globals->glyph_count )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Argument );
|
2003-11-23 22:39:51 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:58:50 +02:00
|
|
|
/* if we have a forced script (via `options'), use it, */
|
|
|
|
/* otherwise look into `glyph_scripts' array */
|
|
|
|
if ( script == AF_SCRIPT_DFLT || script + 1 >= AF_SCRIPT_MAX )
|
2013-08-28 17:34:01 +02:00
|
|
|
script = (AF_Script)( globals->glyph_scripts[gindex] & AF_SCRIPT_NONE );
|
2007-06-11 07:37:35 +02:00
|
|
|
|
2013-08-26 09:58:50 +02:00
|
|
|
script_class = AF_SCRIPT_CLASSES_GET[script];
|
2013-07-31 22:49:29 +02:00
|
|
|
writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
|
|
|
|
[script_class->writing_system];
|
2007-06-11 07:37:35 +02:00
|
|
|
|
2013-08-26 09:58:50 +02:00
|
|
|
metrics = globals->metrics[script];
|
2003-11-23 22:39:51 +01:00
|
|
|
if ( metrics == NULL )
|
|
|
|
{
|
2012-07-06 19:38:44 +02:00
|
|
|
/* create the global metrics object if necessary */
|
2004-01-16 10:51:00 +01:00
|
|
|
FT_Memory memory = globals->face->memory;
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2013-07-31 22:49:29 +02:00
|
|
|
if ( FT_ALLOC( metrics, writing_system_class->script_metrics_size ) )
|
2003-11-23 22:39:51 +01:00
|
|
|
goto Exit;
|
|
|
|
|
2013-07-30 23:17:04 +02:00
|
|
|
metrics->script_class = script_class;
|
|
|
|
metrics->globals = globals;
|
2003-11-23 22:39:51 +01:00
|
|
|
|
2013-07-31 22:49:29 +02:00
|
|
|
if ( writing_system_class->script_metrics_init )
|
2003-11-23 22:39:51 +01:00
|
|
|
{
|
2013-07-31 22:49:29 +02:00
|
|
|
error = writing_system_class->script_metrics_init( metrics,
|
|
|
|
globals->face );
|
2003-11-23 22:39:51 +01:00
|
|
|
if ( error )
|
|
|
|
{
|
2013-07-31 22:49:29 +02:00
|
|
|
if ( writing_system_class->script_metrics_done )
|
|
|
|
writing_system_class->script_metrics_done( metrics );
|
2003-11-23 22:39:51 +01:00
|
|
|
|
|
|
|
FT_FREE( metrics );
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:58:50 +02:00
|
|
|
globals->metrics[script] = metrics;
|
2003-11-23 22:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
*ametrics = metrics;
|
2005-03-03 18:09:08 +01:00
|
|
|
|
2003-11-23 22:39:51 +01:00
|
|
|
return error;
|
|
|
|
}
|
2005-03-03 18:09:08 +01:00
|
|
|
|
|
|
|
|
2009-04-27 19:40:35 +02:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
|
|
|
af_face_globals_is_digit( AF_FaceGlobals globals,
|
|
|
|
FT_UInt gindex )
|
|
|
|
{
|
2009-07-31 17:37:54 +02:00
|
|
|
if ( gindex < (FT_ULong)globals->glyph_count )
|
2009-04-27 19:40:35 +02:00
|
|
|
return (FT_Bool)( globals->glyph_scripts[gindex] & AF_DIGIT );
|
|
|
|
|
|
|
|
return (FT_Bool)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-03 18:09:08 +01:00
|
|
|
/* END */
|