From 2eaf0cf8fd6e7c290497fedb08134a89e7b49b1d Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 19 Mar 2015 17:34:42 +0400 Subject: Update bundled FreeType to 2.5.5 Removed everything, imported with help of import_from_tarball.sh script, and then added a pre-generated builds/unix/ftconfig.h Task-number: QTBUG-44648 Change-Id: Iea948e41f7761f1580382b3763d04c7a61383382 Reviewed-by: Lars Knoll --- src/3rdparty/freetype/src/truetype/rules.mk | 12 +- src/3rdparty/freetype/src/truetype/truetype.c | 3 +- src/3rdparty/freetype/src/truetype/ttdriver.c | 186 +- src/3rdparty/freetype/src/truetype/tterrors.h | 3 +- src/3rdparty/freetype/src/truetype/ttgload.c | 890 +++++--- src/3rdparty/freetype/src/truetype/ttgload.h | 5 +- src/3rdparty/freetype/src/truetype/ttgxvar.c | 130 +- src/3rdparty/freetype/src/truetype/ttinterp.c | 2678 ++++++++++++++++++------- src/3rdparty/freetype/src/truetype/ttinterp.h | 111 +- src/3rdparty/freetype/src/truetype/ttobjs.c | 545 ++++- src/3rdparty/freetype/src/truetype/ttobjs.h | 43 +- src/3rdparty/freetype/src/truetype/ttpic.c | 74 +- src/3rdparty/freetype/src/truetype/ttpic.h | 48 +- src/3rdparty/freetype/src/truetype/ttpload.c | 83 +- src/3rdparty/freetype/src/truetype/ttsubpix.c | 1011 ++++++++++ src/3rdparty/freetype/src/truetype/ttsubpix.h | 110 + 16 files changed, 4629 insertions(+), 1303 deletions(-) create mode 100644 src/3rdparty/freetype/src/truetype/ttsubpix.c create mode 100644 src/3rdparty/freetype/src/truetype/ttsubpix.h (limited to 'src/3rdparty/freetype/src/truetype') diff --git a/src/3rdparty/freetype/src/truetype/rules.mk b/src/3rdparty/freetype/src/truetype/rules.mk index 74684260ed..d4b69f578b 100644 --- a/src/3rdparty/freetype/src/truetype/rules.mk +++ b/src/3rdparty/freetype/src/truetype/rules.mk @@ -3,7 +3,7 @@ # -# Copyright 1996-2000, 2001, 2003, 2004 by +# Copyright 1996-2001, 2003-2004, 2011-2012 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, @@ -25,12 +25,14 @@ TT_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(TT_DIR)) # TrueType driver sources (i.e., C files) # -TT_DRV_SRC := $(TT_DIR)/ttobjs.c \ - $(TT_DIR)/ttpload.c \ +TT_DRV_SRC := $(TT_DIR)/ttdriver.c \ $(TT_DIR)/ttgload.c \ + $(TT_DIR)/ttgxvar.c \ $(TT_DIR)/ttinterp.c \ - $(TT_DIR)/ttgxvar.c \ - $(TT_DIR)/ttdriver.c + $(TT_DIR)/ttobjs.c \ + $(TT_DIR)/ttpic.c \ + $(TT_DIR)/ttpload.c \ + $(TT_DIR)/ttsubpix.c # TrueType driver headers # diff --git a/src/3rdparty/freetype/src/truetype/truetype.c b/src/3rdparty/freetype/src/truetype/truetype.c index 4bd1209787..576912b219 100644 --- a/src/3rdparty/freetype/src/truetype/truetype.c +++ b/src/3rdparty/freetype/src/truetype/truetype.c @@ -4,7 +4,7 @@ /* */ /* FreeType TrueType driver component (body only). */ /* */ -/* Copyright 1996-2001, 2004, 2006 by */ +/* Copyright 1996-2001, 2004, 2006, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -27,6 +27,7 @@ #ifdef TT_USE_BYTECODE_INTERPRETER #include "ttinterp.c" +#include "ttsubpix.c" #endif #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT diff --git a/src/3rdparty/freetype/src/truetype/ttdriver.c b/src/3rdparty/freetype/src/truetype/ttdriver.c index d723b57ae9..ecf4cdcb41 100644 --- a/src/3rdparty/freetype/src/truetype/ttdriver.c +++ b/src/3rdparty/freetype/src/truetype/ttdriver.c @@ -4,8 +4,7 @@ /* */ /* TrueType font driver implementation (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */ -/* 2010 by */ +/* Copyright 1996-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -30,6 +29,8 @@ #include FT_SERVICE_TRUETYPE_ENGINE_H #include FT_SERVICE_TRUETYPE_GLYF_H +#include FT_SERVICE_PROPERTIES_H +#include FT_TRUETYPE_DRIVER_H #include "ttdriver.h" #include "ttgload.h" @@ -53,6 +54,73 @@ #define FT_COMPONENT trace_ttdriver + /* + * PROPERTY SERVICE + * + */ + static FT_Error + tt_property_set( FT_Module module, /* TT_Driver */ + const char* property_name, + const void* value ) + { + FT_Error error = FT_Err_Ok; + TT_Driver driver = (TT_Driver)module; + + + if ( !ft_strcmp( property_name, "interpreter-version" ) ) + { + FT_UInt* interpreter_version = (FT_UInt*)value; + + +#ifndef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( *interpreter_version != TT_INTERPRETER_VERSION_35 ) + error = FT_ERR( Unimplemented_Feature ); + else +#endif + driver->interpreter_version = *interpreter_version; + + return error; + } + + FT_TRACE0(( "tt_property_set: missing property `%s'\n", + property_name )); + return FT_THROW( Missing_Property ); + } + + + static FT_Error + tt_property_get( FT_Module module, /* TT_Driver */ + const char* property_name, + const void* value ) + { + FT_Error error = FT_Err_Ok; + TT_Driver driver = (TT_Driver)module; + + FT_UInt interpreter_version = driver->interpreter_version; + + + if ( !ft_strcmp( property_name, "interpreter-version" ) ) + { + FT_UInt* val = (FT_UInt*)value; + + + *val = interpreter_version; + + return error; + } + + FT_TRACE0(( "tt_property_get: missing property `%s'\n", + property_name )); + return FT_THROW( Missing_Property ); + } + + + FT_DEFINE_SERVICE_PROPERTIESREC( + tt_service_properties, + (FT_Properties_SetFunc)tt_property_set, + (FT_Properties_GetFunc)tt_property_get ) + + /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ @@ -135,8 +203,6 @@ { FT_UInt nn; TT_Face face = (TT_Face) ttface; - FT_Bool check = FT_BOOL( - !( flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) ); /* XXX: TODO: check for sbits */ @@ -149,7 +215,8 @@ FT_UShort ah; - TT_Get_VMetrics( face, start + nn, check, &tsb, &ah ); + /* since we don't need `tsb', we use zero for `yMax' parameter */ + TT_Get_VMetrics( face, start + nn, 0, &tsb, &ah ); advances[nn] = ah; } } @@ -161,12 +228,12 @@ FT_UShort aw; - TT_Get_HMetrics( face, start + nn, check, &lsb, &aw ); + TT_Get_HMetrics( face, start + nn, &lsb, &aw ); advances[nn] = aw; } } - return TT_Err_Ok; + return FT_Err_Ok; } /*************************************************************************/ @@ -190,7 +257,7 @@ { TT_Face ttface = (TT_Face)size->face; TT_Size ttsize = (TT_Size)size; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; ttsize->strike_index = strike_index; @@ -200,7 +267,7 @@ /* use the scaled metrics, even when tt_size_reset fails */ FT_Select_Metrics( size->face, strike_index ); - tt_size_reset( ttsize ); + tt_size_reset( ttsize ); /* ignore return value */ } else { @@ -224,7 +291,7 @@ FT_Size_Request req ) { TT_Size ttsize = (TT_Size)size; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS @@ -249,7 +316,10 @@ FT_Request_Metrics( size->face, req ); if ( FT_IS_SCALABLE( size->face ) ) + { error = tt_size_reset( ttsize ); + ttsize->root.metrics = ttsize->metrics; + } return error; } @@ -258,7 +328,7 @@ /*************************************************************************/ /* */ /* */ - /* Load_Glyph */ + /* tt_glyph_load */ /* */ /* */ /* A driver method used to load a glyph within a given glyph slot. */ @@ -282,10 +352,10 @@ /* FreeType error code. 0 means success. */ /* */ static FT_Error - Load_Glyph( FT_GlyphSlot ttslot, /* TT_GlyphSlot */ - FT_Size ttsize, /* TT_Size */ - FT_UInt glyph_index, - FT_Int32 load_flags ) + tt_glyph_load( FT_GlyphSlot ttslot, /* TT_GlyphSlot */ + FT_Size ttsize, /* TT_Size */ + FT_UInt glyph_index, + FT_Int32 load_flags ) { TT_GlyphSlot slot = (TT_GlyphSlot)ttslot; TT_Size size = (TT_Size)ttsize; @@ -294,13 +364,13 @@ if ( !slot ) - return TT_Err_Invalid_Slot_Handle; + return FT_THROW( Invalid_Slot_Handle ); if ( !size ) - return TT_Err_Invalid_Size_Handle; + return FT_THROW( Invalid_Size_Handle ); if ( !face ) - return TT_Err_Invalid_Argument; + return FT_THROW( Invalid_Face_Handle ); #ifdef FT_CONFIG_OPTION_INCREMENTAL if ( glyph_index >= (FT_UInt)face->num_glyphs && @@ -308,12 +378,12 @@ #else if ( glyph_index >= (FT_UInt)face->num_glyphs ) #endif - return TT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( load_flags & FT_LOAD_NO_HINTING ) { /* both FT_LOAD_NO_HINTING and FT_LOAD_NO_AUTOHINT */ - /* are necessary to disable hinting for tricky fonts */ + /* are necessary to disable hinting for tricky fonts */ if ( FT_IS_TRICKY( face ) ) load_flags &= ~FT_LOAD_NO_HINTING; @@ -353,13 +423,13 @@ /*************************************************************************/ #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - FT_DEFINE_SERVICE_MULTIMASTERSREC(tt_service_gx_multi_masters, + FT_DEFINE_SERVICE_MULTIMASTERSREC( + tt_service_gx_multi_masters, (FT_Get_MM_Func) NULL, (FT_Set_MM_Design_Func) NULL, (FT_Set_MM_Blend_Func) TT_Set_MM_Blend, (FT_Get_MM_Var_Func) TT_Get_MM_Var, - (FT_Set_Var_Design_Func)TT_Set_Var_Design - ) + (FT_Set_Var_Design_Func)TT_Set_Var_Design ) #endif static const FT_Service_TrueTypeEngineRec tt_service_truetype_engine = @@ -379,42 +449,61 @@ #endif /* TT_USE_BYTECODE_INTERPRETER */ }; - FT_DEFINE_SERVICE_TTGLYFREC(tt_service_truetype_glyf, - (TT_Glyf_GetLocationFunc)tt_face_get_location - ) + FT_DEFINE_SERVICE_TTGLYFREC( + tt_service_truetype_glyf, + (TT_Glyf_GetLocationFunc)tt_face_get_location ) #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - FT_DEFINE_SERVICEDESCREC4(tt_services, + FT_DEFINE_SERVICEDESCREC5( + tt_services, FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE, - FT_SERVICE_ID_MULTI_MASTERS, &FT_TT_SERVICE_GX_MULTI_MASTERS_GET, + FT_SERVICE_ID_MULTI_MASTERS, &TT_SERVICE_GX_MULTI_MASTERS_GET, FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine, - FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET - ) + FT_SERVICE_ID_TT_GLYF, &TT_SERVICE_TRUETYPE_GLYF_GET, + FT_SERVICE_ID_PROPERTIES, &TT_SERVICE_PROPERTIES_GET ) #else - FT_DEFINE_SERVICEDESCREC3(tt_services, + FT_DEFINE_SERVICEDESCREC4( + tt_services, FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE, FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine, - FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET - ) + FT_SERVICE_ID_TT_GLYF, &TT_SERVICE_TRUETYPE_GLYF_GET, + FT_SERVICE_ID_PROPERTIES, &TT_SERVICE_PROPERTIES_GET ) #endif + FT_CALLBACK_DEF( FT_Module_Interface ) tt_get_interface( FT_Module driver, /* TT_Driver */ const char* tt_interface ) { + FT_Library library; FT_Module_Interface result; FT_Module sfntd; SFNT_Service sfnt; - result = ft_service_list_lookup( FT_TT_SERVICES_GET, tt_interface ); + + /* TT_SERVICES_GET dereferences `library' in PIC mode */ +#ifdef FT_CONFIG_OPTION_PIC + if ( !driver ) + return NULL; + library = driver->library; + if ( !library ) + return NULL; +#endif + + result = ft_service_list_lookup( TT_SERVICES_GET, tt_interface ); if ( result != NULL ) return result; +#ifndef FT_CONFIG_OPTION_PIC if ( !driver ) return NULL; + library = driver->library; + if ( !library ) + return NULL; +#endif /* only return the default interface from the SFNT module */ - sfntd = FT_Get_Module( driver->library, "sfnt" ); + sfntd = FT_Get_Module( library, "sfnt" ); if ( sfntd ) { sfnt = (SFNT_Service)( sfntd->clazz->module_interface ); @@ -429,22 +518,22 @@ /* The FT_DriverInterface structure is defined in ftdriver.h. */ #ifdef TT_USE_BYTECODE_INTERPRETER -#define TT_HINTER_FLAG FT_MODULE_DRIVER_HAS_HINTER +#define TT_HINTER_FLAG FT_MODULE_DRIVER_HAS_HINTER #else -#define TT_HINTER_FLAG 0 +#define TT_HINTER_FLAG 0 #endif #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS -#define TT_SIZE_SELECT tt_size_select +#define TT_SIZE_SELECT tt_size_select #else -#define TT_SIZE_SELECT 0 +#define TT_SIZE_SELECT 0 #endif - FT_DEFINE_DRIVER(tt_driver_class, - - - FT_MODULE_FONT_DRIVER | - FT_MODULE_DRIVER_SCALABLE | + FT_DEFINE_DRIVER( + tt_driver_class, + + FT_MODULE_FONT_DRIVER | + FT_MODULE_DRIVER_SCALABLE | TT_HINTER_FLAG, sizeof ( TT_DriverRec ), @@ -468,15 +557,12 @@ tt_size_init, tt_size_done, tt_slot_init, - 0, /* FT_Slot_DoneFunc */ - - ft_stub_set_char_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */ - ft_stub_set_pixel_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */ + 0, /* FT_Slot_DoneFunc */ - Load_Glyph, + tt_glyph_load, tt_get_kerning, - 0, /* FT_Face_AttachFunc */ + 0, /* FT_Face_AttachFunc */ tt_get_advances, tt_size_request, diff --git a/src/3rdparty/freetype/src/truetype/tterrors.h b/src/3rdparty/freetype/src/truetype/tterrors.h index d317c70e0e..78d138fab2 100644 --- a/src/3rdparty/freetype/src/truetype/tterrors.h +++ b/src/3rdparty/freetype/src/truetype/tterrors.h @@ -4,7 +4,7 @@ /* */ /* TrueType error codes (specification only). */ /* */ -/* Copyright 2001 by */ +/* Copyright 2001, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -30,6 +30,7 @@ #undef __FTERRORS_H__ +#undef FT_ERR_PREFIX #define FT_ERR_PREFIX TT_Err_ #define FT_ERR_BASE FT_Mod_Err_TrueType diff --git a/src/3rdparty/freetype/src/truetype/ttgload.c b/src/3rdparty/freetype/src/truetype/ttgload.c index 57ea0baa77..c5841c301d 100644 --- a/src/3rdparty/freetype/src/truetype/ttgload.c +++ b/src/3rdparty/freetype/src/truetype/ttgload.c @@ -4,8 +4,7 @@ /* */ /* TrueType Glyph Loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ -/* 2010 by */ +/* Copyright 1996-2014 */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -24,6 +23,7 @@ #include FT_INTERNAL_SFNT_H #include FT_TRUETYPE_TAGS_H #include FT_OUTLINE_H +#include FT_TRUETYPE_DRIVER_H #include "ttgload.h" #include "ttpload.h" @@ -33,6 +33,7 @@ #endif #include "tterrors.h" +#include "ttsubpix.h" /*************************************************************************/ @@ -47,7 +48,7 @@ /*************************************************************************/ /* */ - /* Composite font flags. */ + /* Composite glyph flags. */ /* */ #define ARGS_ARE_WORDS 0x0001 #define ARGS_ARE_XY_VALUES 0x0002 @@ -66,22 +67,16 @@ /*************************************************************************/ /* */ - /* Returns the horizontal metrics in font units for a given glyph. If */ - /* `check' is true, take care of monospaced fonts by returning the */ - /* advance width maximum. */ + /* Return the horizontal metrics in font units for a given glyph. */ /* */ FT_LOCAL_DEF( void ) TT_Get_HMetrics( TT_Face face, FT_UInt idx, - FT_Bool check, FT_Short* lsb, FT_UShort* aw ) { ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw ); - if ( check && face->postscript.isFixedPitch ) - *aw = face->horizontal.advance_Width_Max; - FT_TRACE5(( " advance width (font units): %d\n", *aw )); FT_TRACE5(( " left side bearing (font units): %d\n", *lsb )); } @@ -89,80 +84,106 @@ /*************************************************************************/ /* */ - /* Returns the vertical metrics in font units for a given glyph. */ - /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */ - /* table, typoAscender/Descender from the `OS/2' table would be used */ - /* instead, and if there were no `OS/2' table, use ascender/descender */ - /* from the `hhea' table. But that is not what Microsoft's rasterizer */ - /* apparently does: It uses the ppem value as the advance height, and */ - /* sets the top side bearing to be zero. */ - /* */ - /* The monospace `check' is probably not meaningful here, but we leave */ - /* it in for a consistent interface. */ + /* Return the vertical metrics in font units for a given glyph. */ + /* See macro `TT_LOADER_SET_PP' below for explanations. */ /* */ FT_LOCAL_DEF( void ) TT_Get_VMetrics( TT_Face face, FT_UInt idx, - FT_Bool check, + FT_Pos yMax, FT_Short* tsb, FT_UShort* ah ) { - FT_UNUSED( check ); - if ( face->vertical_info ) ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah ); -#if 1 /* Empirically determined, at variance with what MS said */ - - else - { - *tsb = 0; - *ah = face->root.units_per_EM; - } - -#else /* This is what MS said to do. It isn't what they do, however. */ - else if ( face->os2.version != 0xFFFFU ) { - *tsb = face->os2.sTypoAscender; + *tsb = (FT_Short)( face->os2.sTypoAscender - yMax ); *ah = face->os2.sTypoAscender - face->os2.sTypoDescender; } + else { - *tsb = face->horizontal.Ascender; + *tsb = (FT_Short)( face->horizontal.Ascender - yMax ); *ah = face->horizontal.Ascender - face->horizontal.Descender; } -#endif - FT_TRACE5(( " advance height (font units): %d\n", *ah )); FT_TRACE5(( " top side bearing (font units): %d\n", *tsb )); } - static void + static FT_Error tt_get_metrics( TT_Loader loader, FT_UInt glyph_index ) { - TT_Face face = (TT_Face)loader->face; + TT_Face face = (TT_Face)loader->face; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); +#endif + + FT_Error error; + FT_Stream stream = loader->stream; FT_Short left_bearing = 0, top_bearing = 0; FT_UShort advance_width = 0, advance_height = 0; + /* we must preserve the stream position */ + /* (which gets altered by the metrics functions) */ + FT_ULong pos = FT_STREAM_POS(); + TT_Get_HMetrics( face, glyph_index, - (FT_Bool)!( loader->load_flags & - FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), &left_bearing, &advance_width ); TT_Get_VMetrics( face, glyph_index, - (FT_Bool)!( loader->load_flags & - FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), + loader->bbox.yMax, &top_bearing, &advance_height ); + if ( FT_STREAM_SEEK( pos ) ) + return error; + + loader->left_bearing = left_bearing; + loader->advance = advance_width; + loader->top_bearing = top_bearing; + loader->vadvance = advance_height; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) + { + if ( loader->exec ) + loader->exec->sph_tweak_flags = 0; + + /* this may not be the right place for this, but it works */ + if ( loader->exec && loader->exec->ignore_x_mode ) + sph_set_tweaks( loader, glyph_index ); + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + if ( !loader->linear_def ) + { + loader->linear_def = 1; + loader->linear = advance_width; + } + + return FT_Err_Ok; + } + + #ifdef FT_CONFIG_OPTION_INCREMENTAL + static void + tt_get_metrics_incr_overrides( TT_Loader loader, + FT_UInt glyph_index ) + { + TT_Face face = (TT_Face)loader->face; + + FT_Short left_bearing = 0, top_bearing = 0; + FT_UShort advance_width = 0, advance_height = 0; + + /* If this is an incrementally loaded font check whether there are */ /* overriding metrics for this glyph. */ if ( face->root.internal->incremental_interface && @@ -172,9 +193,9 @@ FT_Error error; - metrics.bearing_x = left_bearing; + metrics.bearing_x = loader->left_bearing; metrics.bearing_y = 0; - metrics.advance = advance_width; + metrics.advance = loader->advance; metrics.advance_v = 0; error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( @@ -190,8 +211,8 @@ /* GWW: Do I do the same for vertical metrics? */ metrics.bearing_x = 0; - metrics.bearing_y = top_bearing; - metrics.advance = advance_height; + metrics.bearing_y = loader->top_bearing; + metrics.advance = loader->vadvance; error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( face->root.internal->incremental_interface->object, @@ -204,24 +225,24 @@ #endif /* 0 */ + loader->left_bearing = left_bearing; + loader->advance = advance_width; + loader->top_bearing = top_bearing; + loader->vadvance = advance_height; + + if ( !loader->linear_def ) + { + loader->linear_def = 1; + loader->linear = advance_width; + } } Exit: + return; + } #endif /* FT_CONFIG_OPTION_INCREMENTAL */ - loader->left_bearing = left_bearing; - loader->advance = advance_width; - loader->top_bearing = top_bearing; - loader->vadvance = advance_height; - - if ( !loader->linear_def ) - { - loader->linear_def = 1; - loader->linear = advance_width; - } - } - /*************************************************************************/ /* */ @@ -246,10 +267,6 @@ } -#undef IS_HINTED -#define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) - - /*************************************************************************/ /* */ /* The following functions are used by default with TrueType fonts. */ @@ -271,7 +288,7 @@ FT_UNUSED( glyph_index ); - FT_TRACE5(( "Glyph %ld\n", glyph_index )); + FT_TRACE4(( "Glyph %ld\n", glyph_index )); /* the following line sets the `error' variable through macros! */ if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( byte_count ) ) @@ -280,7 +297,7 @@ loader->cursor = stream->cursor; loader->limit = stream->limit; - return TT_Err_Ok; + return FT_Err_Ok; } @@ -302,7 +319,7 @@ if ( p + 10 > limit ) - return TT_Err_Invalid_Outline; + return FT_THROW( Invalid_Outline ); loader->n_contours = FT_NEXT_SHORT( p ); @@ -318,7 +335,7 @@ loader->bbox.yMax )); loader->cursor = p; - return TT_Err_Ok; + return FT_Err_Ok; } @@ -331,9 +348,9 @@ FT_GlyphLoader gloader = load->gloader; FT_Int n_contours = load->n_contours; FT_Outline* outline; - TT_Face face = (TT_Face)load->face; FT_UShort n_ins; FT_Int n_points; + FT_ULong tmp; FT_Byte *flag, *flag_limit; FT_Byte c, count; @@ -356,19 +373,21 @@ if ( n_contours >= 0xFFF || p + ( n_contours + 1 ) * 2 > limit ) goto Invalid_Outline; - prev_cont = FT_NEXT_USHORT( p ); + prev_cont = FT_NEXT_SHORT( p ); if ( n_contours > 0 ) cont[0] = prev_cont; + if ( prev_cont < 0 ) + goto Invalid_Outline; + for ( cont++; cont < cont_limit; cont++ ) { - cont[0] = FT_NEXT_USHORT( p ); + cont[0] = FT_NEXT_SHORT( p ); if ( cont[0] <= prev_cont ) { /* unordered contours: this is invalid */ - error = FT_Err_Invalid_Table; - goto Fail; + goto Invalid_Outline; } prev_cont = cont[0]; } @@ -386,13 +405,6 @@ if ( error ) goto Fail; - /* we'd better check the contours table right now */ - outline = &gloader->current.outline; - - for ( cont = outline->contours + 1; cont < cont_limit; cont++ ) - if ( cont[-1] >= cont[0] ) - goto Invalid_Outline; - /* reading the bytecode instructions */ load->glyph->control_len = 0; load->glyph->control_data = 0; @@ -404,18 +416,11 @@ FT_TRACE5(( " Instructions size: %u\n", n_ins )); - if ( n_ins > face->max_profile.maxSizeOfInstructions ) - { - FT_TRACE0(( "TT_Load_Simple_Glyph: too many instructions (%d)\n", - n_ins )); - error = TT_Err_Too_Many_Hints; - goto Fail; - } - + /* check it */ if ( ( limit - p ) < n_ins ) { FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" )); - error = TT_Err_Too_Many_Hints; + error = FT_THROW( Too_Many_Hints ); goto Fail; } @@ -423,6 +428,20 @@ if ( IS_HINTED( load->load_flags ) ) { + /* we don't trust `maxSizeOfInstructions' in the `maxp' table */ + /* and thus update the bytecode array size by ourselves */ + + tmp = load->exec->glyphSize; + error = Update_Max( load->exec->memory, + &tmp, + sizeof ( FT_Byte ), + (void*)&load->exec->glyphIns, + n_ins ); + + load->exec->glyphSize = (FT_UShort)tmp; + if ( error ) + return error; + load->glyph->control_len = n_ins; load->glyph->control_data = load->exec->glyphIns; @@ -433,6 +452,8 @@ p += n_ins; + outline = &gloader->current.outline; + /* reading the point tags */ flag = (FT_Byte*)outline->tags; flag_limit = flag + n_points; @@ -543,7 +564,7 @@ return error; Invalid_Outline: - error = TT_Err_Invalid_Outline; + error = FT_THROW( Invalid_Outline ); goto Fail; } @@ -664,7 +685,7 @@ return error; Invalid_Composite: - error = TT_Err_Invalid_Composite; + error = FT_THROW( Invalid_Composite ); goto Fail; } @@ -711,8 +732,12 @@ TT_Hint_Glyph( TT_Loader loader, FT_Bool is_composite ) { +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Face face = (TT_Face)loader->face; + TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); +#endif + TT_GlyphZone zone = &loader->zone; - FT_Pos origin; #ifdef TT_USE_BYTECODE_INTERPRETER FT_UInt n_ins; @@ -724,19 +749,12 @@ #ifdef TT_USE_BYTECODE_INTERPRETER if ( loader->glyph->control_len > 0xFFFFL ) { - FT_TRACE1(( "TT_Hint_Glyph: too long instructions " )); - FT_TRACE1(( "(0x%lx byte) is truncated\n", + FT_TRACE1(( "TT_Hint_Glyph: too long instructions" )); + FT_TRACE1(( " (0x%lx byte) is truncated\n", loader->glyph->control_len )); } n_ins = (FT_UInt)( loader->glyph->control_len ); -#endif - origin = zone->cur[zone->n_points - 4].x; - origin = FT_PIX_ROUND( origin ) - origin; - if ( origin ) - translate_array( zone->n_points, zone->cur, origin, 0 ); - -#ifdef TT_USE_BYTECODE_INTERPRETER /* save original point position in org */ if ( n_ins > 0 ) FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points ); @@ -762,9 +780,13 @@ } #endif - /* round pp2 and pp4 */ + /* round phantom points */ + zone->cur[zone->n_points - 4].x = + FT_PIX_ROUND( zone->cur[zone->n_points - 4].x ); zone->cur[zone->n_points - 3].x = FT_PIX_ROUND( zone->cur[zone->n_points - 3].x ); + zone->cur[zone->n_points - 2].y = + FT_PIX_ROUND( zone->cur[zone->n_points - 2].y ); zone->cur[zone->n_points - 1].y = FT_PIX_ROUND( zone->cur[zone->n_points - 1].y ); @@ -779,10 +801,8 @@ FT_Outline current_outline = gloader->current.outline; - error = TT_Set_CodeRange( loader->exec, tt_coderange_glyph, - loader->exec->glyphIns, n_ins ); - if ( error ) - return error; + TT_Set_CodeRange( loader->exec, tt_coderange_glyph, + loader->exec->glyphIns, n_ins ); loader->exec->is_composite = is_composite; loader->exec->pts = *zone; @@ -802,15 +822,23 @@ #endif /* save glyph phantom points */ - if ( !loader->preserve_pps ) + loader->pp1 = zone->cur[zone->n_points - 4]; + loader->pp2 = zone->cur[zone->n_points - 3]; + loader->pp3 = zone->cur[zone->n_points - 2]; + loader->pp4 = zone->cur[zone->n_points - 1]; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) { - loader->pp1 = zone->cur[zone->n_points - 4]; - loader->pp2 = zone->cur[zone->n_points - 3]; - loader->pp3 = zone->cur[zone->n_points - 2]; - loader->pp4 = zone->cur[zone->n_points - 1]; + if ( loader->exec->sph_tweak_flags & SPH_TWEAK_DEEMBOLDEN ) + FT_Outline_EmboldenXY( &loader->gloader->current.outline, -24, 0 ); + + else if ( loader->exec->sph_tweak_flags & SPH_TWEAK_EMBOLDEN ) + FT_Outline_EmboldenXY( &loader->gloader->current.outline, 24, 0 ); } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ - return TT_Err_Ok; + return FT_Err_Ok; } @@ -828,7 +856,7 @@ TT_Process_Simple_Glyph( TT_Loader loader ) { FT_GlyphLoader gloader = loader->gloader; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Outline* outline; FT_Int n_points; @@ -886,25 +914,83 @@ loader->zone.n_points + 4 ); } - /* scale the glyph */ - if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { - FT_Vector* vec = outline->points; - FT_Vector* limit = outline->points + n_points; - FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale; - FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Face face = (TT_Face)loader->face; + TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); + + FT_String* family = face->root.family_name; + FT_Int ppem = loader->size->metrics.x_ppem; + FT_String* style = face->root.style_name; + FT_Int x_scale_factor = 1000; +#endif + + FT_Vector* vec = outline->points; + FT_Vector* limit = outline->points + n_points; + FT_Fixed x_scale = 0; /* pacify compiler */ + FT_Fixed y_scale = 0; - for ( ; vec < limit; vec++ ) + FT_Bool do_scale = FALSE; + + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) { - vec->x = FT_MulFix( vec->x, x_scale ); - vec->y = FT_MulFix( vec->y, y_scale ); + /* scale, but only if enabled and only if TT hinting is being used */ + if ( IS_HINTED( loader->load_flags ) ) + x_scale_factor = sph_test_tweak_x_scaling( face, + family, + ppem, + style, + loader->glyph_index ); + /* scale the glyph */ + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 || + x_scale_factor != 1000 ) + { + x_scale = FT_MulDiv( ((TT_Size)loader->size)->metrics.x_scale, + x_scale_factor, 1000 ); + y_scale = ((TT_Size)loader->size)->metrics.y_scale; + + /* compensate for any scaling by de/emboldening; */ + /* the amount was determined via experimentation */ + if ( x_scale_factor != 1000 && ppem > 11 ) + FT_Outline_EmboldenXY( outline, + FT_MulFix( 1280 * ppem, + 1000 - x_scale_factor ), + 0 ); + do_scale = TRUE; + } + } + else + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + { + /* scale the glyph */ + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) + { + x_scale = ((TT_Size)loader->size)->metrics.x_scale; + y_scale = ((TT_Size)loader->size)->metrics.y_scale; + + do_scale = TRUE; + } } - loader->pp1 = outline->points[n_points - 4]; - loader->pp2 = outline->points[n_points - 3]; - loader->pp3 = outline->points[n_points - 2]; - loader->pp4 = outline->points[n_points - 1]; + if ( do_scale ) + { + for ( ; vec < limit; vec++ ) + { + vec->x = FT_MulFix( vec->x, x_scale ); + vec->y = FT_MulFix( vec->y, y_scale ); + } + + loader->pp1 = outline->points[n_points - 4]; + loader->pp2 = outline->points[n_points - 3]; + loader->pp3 = outline->points[n_points - 2]; + loader->pp4 = outline->points[n_points - 1]; + } } if ( IS_HINTED( loader->load_flags ) ) @@ -971,7 +1057,7 @@ l += num_base_points; if ( k >= num_base_points || l >= num_points ) - return TT_Err_Invalid_Composite; + return FT_THROW( Invalid_Composite ); p1 = gloader->base.outline.points + k; p2 = gloader->base.outline.points + l; @@ -985,11 +1071,11 @@ y = subglyph->arg2; if ( !x && !y ) - return TT_Err_Ok; + return FT_Err_Ok; - /* Use a default value dependent on */ - /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */ - /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */ + /* Use a default value dependent on */ + /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old */ + /* TT fonts which don't set the xxx_COMPONENT_OFFSET bit. */ if ( have_scale && #ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED @@ -1001,10 +1087,10 @@ #if 0 - /*************************************************************************/ - /* */ - /* This algorithm is what Apple documents. But it doesn't work. */ - /* */ + /*******************************************************************/ + /* */ + /* This algorithm is what Apple documents. But it doesn't work. */ + /* */ int a = subglyph->transform.xx > 0 ? subglyph->transform.xx : -subglyph->transform.xx; int b = subglyph->transform.yx > 0 ? subglyph->transform.yx @@ -1024,28 +1110,22 @@ x = FT_MulFix( x, m ); y = FT_MulFix( y, n ); -#else /* 0 */ +#else /* 1 */ - /*************************************************************************/ - /* */ - /* This algorithm is a guess and works much better than the above. */ - /* */ - FT_Fixed mac_xscale = FT_SqrtFixed( - (FT_Int32)FT_MulFix( subglyph->transform.xx, - subglyph->transform.xx ) + - (FT_Int32)FT_MulFix( subglyph->transform.xy, - subglyph->transform.xy ) ); - FT_Fixed mac_yscale = FT_SqrtFixed( - (FT_Int32)FT_MulFix( subglyph->transform.yy, - subglyph->transform.yy ) + - (FT_Int32)FT_MulFix( subglyph->transform.yx, - subglyph->transform.yx ) ); + /*******************************************************************/ + /* */ + /* This algorithm is a guess and works much better than the above. */ + /* */ + FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx, + subglyph->transform.xy ); + FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy, + subglyph->transform.yx ); x = FT_MulFix( x, mac_xscale ); y = FT_MulFix( y, mac_yscale ); -#endif /* 0 */ +#endif /* 1 */ } @@ -1071,7 +1151,7 @@ base_vec + num_base_points, x, y ); - return TT_Err_Ok; + return FT_Err_Ok; } @@ -1118,7 +1198,8 @@ { FT_Stream stream = loader->stream; - FT_UShort n_ins; + FT_UShort n_ins, max_ins; + FT_ULong tmp; /* TT_Load_Composite_Glyph only gives us the offset of instructions */ @@ -1130,15 +1211,32 @@ FT_TRACE5(( " Instructions size = %d\n", n_ins )); /* check it */ - if ( n_ins > ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions ) + max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions; + if ( n_ins > max_ins ) { - FT_TRACE0(( "TT_Process_Composite_Glyph: too many instructions (%d)\n", - n_ins )); + /* don't trust `maxSizeOfInstructions'; */ + /* only do a rough safety check */ + if ( (FT_Int)n_ins > loader->byte_len ) + { + FT_TRACE1(( "TT_Process_Composite_Glyph:" + " too many instructions (%d) for glyph with length %d\n", + n_ins, loader->byte_len )); + return FT_THROW( Too_Many_Hints ); + } - return TT_Err_Too_Many_Hints; + tmp = loader->exec->glyphSize; + error = Update_Max( loader->exec->memory, + &tmp, + sizeof ( FT_Byte ), + (void*)&loader->exec->glyphIns, + n_ins ); + + loader->exec->glyphSize = (FT_UShort)tmp; + if ( error ) + return error; } else if ( n_ins == 0 ) - return TT_Err_Ok; + return FT_Err_Ok; if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) ) return error; @@ -1154,7 +1252,7 @@ /* Some points are likely touched during execution of */ /* instructions on components. So let's untouch them. */ - for ( i = start_point; i < loader->zone.n_points; i++ ) + for ( i = 0; i < loader->zone.n_points; i++ ) loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; loader->zone.n_points += 4; @@ -1163,21 +1261,131 @@ } - /* Calculate the four phantom points. */ - /* The first two stand for horizontal origin and advance. */ - /* The last two stand for vertical origin and advance. */ + /* + * Calculate the phantom points + * + * Defining the right side bearing (rsb) as + * + * rsb = aw - (lsb + xmax - xmin) + * + * (with `aw' the advance width, `lsb' the left side bearing, and `xmin' + * and `xmax' the glyph's minimum and maximum x value), the OpenType + * specification defines the initial position of horizontal phantom points + * as + * + * pp1 = (round(xmin - lsb), 0) , + * pp2 = (round(pp1 + aw), 0) . + * + * Note that the rounding to the grid (in the device space) is not + * documented currently in the specification. + * + * However, the specification lacks the precise definition of vertical + * phantom points. Greg Hitchcock provided the following explanation. + * + * - a `vmtx' table is present + * + * For any glyph, the minimum and maximum y values (`ymin' and `ymax') + * are given in the `glyf' table, the top side bearing (tsb) and advance + * height (ah) are given in the `vmtx' table. The bottom side bearing + * (bsb) is then calculated as + * + * bsb = ah - (tsb + ymax - ymin) , + * + * and the initial position of vertical phantom points is + * + * pp3 = (x, round(ymax + tsb)) , + * pp4 = (x, round(pp3 - ah)) . + * + * See below for value `x'. + * + * - no `vmtx' table in the font + * + * If there is an `OS/2' table, we set + * + * DefaultAscender = sTypoAscender , + * DefaultDescender = sTypoDescender , + * + * otherwise we use data from the `hhea' table: + * + * DefaultAscender = Ascender , + * DefaultDescender = Descender . + * + * With these two variables we can now set + * + * ah = DefaultAscender - sDefaultDescender , + * tsb = DefaultAscender - yMax , + * + * and proceed as if a `vmtx' table was present. + * + * Usually we have + * + * x = aw / 2 , (1) + * + * but there is one compatibility case where it can be set to + * + * x = -DefaultDescender - + * ((DefaultAscender - DefaultDescender - aw) / 2) . (2) + * + * and another one with + * + * x = 0 . (3) + * + * In Windows, the history of those values is quite complicated, + * depending on the hinting engine (that is, the graphics framework). + * + * framework from to formula + * ---------------------------------------------------------- + * GDI Windows 98 current (1) + * (Windows 2000 for NT) + * GDI+ Windows XP Windows 7 (2) + * GDI+ Windows 8 current (3) + * DWrite Windows 7 current (3) + * + * For simplicity, FreeType uses (1) for grayscale subpixel hinting and + * (3) for everything else. + * + */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + +#define TT_LOADER_SET_PP( loader ) \ + do \ + { \ + FT_Bool subpixel_ = loader->exec ? loader->exec->subpixel \ + : 0; \ + FT_Bool grayscale_ = loader->exec ? loader->exec->grayscale \ + : 0; \ + FT_Bool use_aw_2_ = (FT_Bool)( subpixel_ && grayscale_ ); \ + \ + \ + (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ + (loader)->pp1.y = 0; \ + (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ + (loader)->pp2.y = 0; \ + \ + (loader)->pp3.x = use_aw_2_ ? (loader)->advance / 2 : 0; \ + (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \ + (loader)->pp4.x = use_aw_2_ ? (loader)->advance / 2 : 0; \ + (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ + } while ( 0 ) + +#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + #define TT_LOADER_SET_PP( loader ) \ - do { \ + do \ + { \ (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ (loader)->pp1.y = 0; \ (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ (loader)->pp2.y = 0; \ + \ (loader)->pp3.x = 0; \ - (loader)->pp3.y = (loader)->top_bearing + (loader)->bbox.yMax; \ + (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \ (loader)->pp4.x = 0; \ (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ } while ( 0 ) +#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + /*************************************************************************/ /* */ @@ -1194,7 +1402,7 @@ FT_UInt recurse_count, FT_Bool header_only ) { - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Fixed x_scale, y_scale; FT_ULong offset; TT_Face face = (TT_Face)loader->face; @@ -1217,14 +1425,14 @@ if ( recurse_count > 1 && recurse_count > face->max_profile.maxComponentDepth ) { - error = TT_Err_Invalid_Composite; + error = FT_THROW( Invalid_Composite ); goto Exit; } /* check glyph index */ if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) { - error = TT_Err_Invalid_Glyph_Index; + error = FT_THROW( Invalid_Glyph_Index ); goto Exit; } @@ -1241,8 +1449,6 @@ y_scale = 0x10000L; } - tt_get_metrics( loader, glyph_index ); - /* Set `offset' to the start of the glyph relative to the start of */ /* the `glyf' table, and `byte_len' to the length of the glyph in */ /* bytes. */ @@ -1288,7 +1494,7 @@ #endif /* FT_CONFIG_OPTION_INCREMENTAL */ { FT_TRACE2(( "no `glyf' table but non-zero `loca' entry\n" )); - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Exit; } @@ -1302,7 +1508,17 @@ /* read glyph header first */ error = face->read_glyph_header( loader ); - if ( error || header_only ) + if ( error ) + goto Exit; + + /* the metrics must be computed after loading the glyph header */ + /* since we need the glyph's `yMax' value in case the vertical */ + /* metrics must be emulated */ + error = tt_get_metrics( loader, glyph_index ); + if ( error ) + goto Exit; + + if ( header_only ) goto Exit; } @@ -1313,11 +1529,21 @@ loader->bbox.yMin = 0; loader->bbox.yMax = 0; + error = tt_get_metrics( loader, glyph_index ); + if ( error ) + goto Exit; + if ( header_only ) goto Exit; + /* must initialize points before (possibly) overriding */ + /* glyph metrics from the incremental interface */ TT_LOADER_SET_PP( loader ); +#ifdef FT_CONFIG_OPTION_INCREMENTAL + tt_get_metrics_incr_overrides( loader, glyph_index ); +#endif + #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT if ( ((TT_Face)(loader->face))->doblend ) @@ -1331,30 +1557,47 @@ if ( error ) goto Exit; - loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y; - loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y; - loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y; - loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y; + loader->pp1.x += deltas[0].x; + loader->pp1.y += deltas[0].y; + loader->pp2.x += deltas[1].x; + loader->pp2.y += deltas[1].y; + + loader->pp3.x += deltas[2].x; + loader->pp3.y += deltas[2].y; + loader->pp4.x += deltas[3].x; + loader->pp4.y += deltas[3].y; FT_FREE( deltas ); } -#endif +#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ + /* scale phantom points, if necessary; */ + /* they get rounded in `TT_Hint_Glyph' */ if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); + /* pp1.y and pp2.y are always zero */ + + loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); + loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); } - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } + /* must initialize phantom points before (possibly) overriding */ + /* glyph metrics from the incremental interface */ TT_LOADER_SET_PP( loader ); +#ifdef FT_CONFIG_OPTION_INCREMENTAL + tt_get_metrics_incr_overrides( loader, glyph_index ); +#endif + /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ @@ -1421,7 +1664,7 @@ face, glyph_index, &deltas, - gloader->current.num_subglyphs + 4 )) != 0 ) + gloader->current.num_subglyphs + 4 ) ) != 0 ) goto Exit; subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs; @@ -1439,21 +1682,32 @@ } } - loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y; - loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y; - loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y; - loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y; + loader->pp1.x += deltas[i + 0].x; + loader->pp1.y += deltas[i + 0].y; + loader->pp2.x += deltas[i + 1].x; + loader->pp2.y += deltas[i + 1].y; + + loader->pp3.x += deltas[i + 2].x; + loader->pp3.y += deltas[i + 2].y; + loader->pp4.x += deltas[i + 3].x; + loader->pp4.y += deltas[i + 3].y; FT_FREE( deltas ); } #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ + /* scale phantom points, if necessary; */ + /* they get rounded in `TT_Hint_Glyph' */ if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); + /* pp1.y and pp2.y are always zero */ + + loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); + loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); } @@ -1481,6 +1735,7 @@ FT_UInt num_base_subgs = gloader->base.num_subglyphs; FT_Stream old_stream = loader->stream; + FT_Int old_byte_len = loader->byte_len; FT_GlyphLoader_Add( gloader ); @@ -1512,6 +1767,7 @@ /* restore subglyph pointer */ subglyph = gloader->base.subglyphs + num_base_subgs + n; + /* restore phantom points if necessary */ if ( !( subglyph->flags & USE_MY_METRICS ) ) { loader->pp1 = pp[0]; @@ -1531,31 +1787,37 @@ /* (1): exists from the beginning */ /* (2): components that have been loaded so far */ /* (3): the newly loaded component */ - TT_Process_Composite_Component( loader, subglyph, start_point, - num_base_points ); + error = TT_Process_Composite_Component( loader, + subglyph, + start_point, + num_base_points ); + if ( error ) + goto Exit; } - loader->stream = old_stream; + loader->stream = old_stream; + loader->byte_len = old_byte_len; /* process the glyph */ loader->ins_pos = ins_pos; if ( IS_HINTED( loader->load_flags ) && - #ifdef TT_USE_BYTECODE_INTERPRETER - subglyph->flags & WE_HAVE_INSTR && - #endif - num_points > start_point ) - TT_Process_Composite_Glyph( loader, start_point, start_contour ); - + { + error = TT_Process_Composite_Glyph( loader, + start_point, + start_contour ); + if ( error ) + goto Exit; + } } } else { /* invalid composite count (negative but not -1) */ - error = TT_Err_Invalid_Outline; + error = FT_THROW( Invalid_Outline ); goto Exit; } @@ -1585,11 +1847,15 @@ compute_glyph_metrics( TT_Loader loader, FT_UInt glyph_index ) { + TT_Face face = (TT_Face)loader->face; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); +#endif + FT_BBox bbox; - TT_Face face = (TT_Face)loader->face; FT_Fixed y_scale; TT_GlyphSlot glyph = loader->glyph; - TT_Size size = (TT_Size)loader->size; + TT_Size size = (TT_Size)loader->size; y_scale = 0x10000L; @@ -1603,23 +1869,7 @@ /* get the device-independent horizontal advance; it is scaled later */ /* by the base layer. */ - { - FT_Pos advance = loader->linear; - - - /* the flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH was introduced to */ - /* correctly support DynaLab fonts, which have an incorrect */ - /* `advance_Width_Max' field! It is used, to my knowledge, */ - /* exclusively in the X-TrueType font server. */ - /* */ - if ( face->postscript.isFixedPitch && - ( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 ) - advance = face->horizontal.advance_Width_Max; - - /* we need to return the advance in font units in linearHoriAdvance, */ - /* it will be scaled later by the base layer. */ - glyph->linearHoriAdvance = advance; - } + glyph->linearHoriAdvance = loader->linear; glyph->metrics.horiBearingX = bbox.xMin; glyph->metrics.horiBearingY = bbox.yMax; @@ -1636,8 +1886,30 @@ size->root.metrics.x_ppem, glyph_index ); - if ( widthp ) - glyph->metrics.horiAdvance = *widthp << 6; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) + { + FT_Bool ignore_x_mode; + + + ignore_x_mode = FT_BOOL( FT_LOAD_TARGET_MODE( loader->load_flags ) != + FT_RENDER_MODE_MONO ); + + if ( widthp && + ( ( ignore_x_mode && loader->exec->compatible_widths ) || + !ignore_x_mode || + SPH_OPTION_BITMAP_WIDTHS ) ) + glyph->metrics.horiAdvance = *widthp << 6; + } + else + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + { + if ( widthp ) + glyph->metrics.horiAdvance = *widthp << 6; + } } /* set glyph dimensions */ @@ -1814,8 +2086,13 @@ FT_Int32 load_flags, FT_Bool glyf_table_only ) { + FT_Error error; + TT_Face face; FT_Stream stream; +#ifdef TT_USE_BYTECODE_INTERPRETER + FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); +#endif face = (TT_Face)glyph->face; @@ -1831,37 +2108,153 @@ TT_ExecContext exec; FT_Bool grayscale; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); + + FT_Bool subpixel = FALSE; + +#if 0 + /* not used yet */ + FT_Bool compatible_widths; + FT_Bool symmetrical_smoothing; + FT_Bool bgr; + FT_Bool subpixel_positioned; +#endif +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + FT_Bool reexecute = FALSE; - if ( !size->cvt_ready ) + + if ( size->bytecode_ready < 0 || size->cvt_ready < 0 ) { - FT_Error error = tt_size_ready_bytecode( size ); + error = tt_size_ready_bytecode( size, pedantic ); if ( error ) return error; } + else if ( size->bytecode_ready ) + return size->bytecode_ready; + else if ( size->cvt_ready ) + return size->cvt_ready; /* query new execution context */ exec = size->debug ? size->context : ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; if ( !exec ) - return TT_Err_Could_Not_Find_Context; + return FT_THROW( Could_Not_Find_Context ); - grayscale = - FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING - TT_Load_Context( exec, face, size ); + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) + { + subpixel = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags ) != + FT_RENDER_MODE_MONO ) && + SPH_OPTION_SET_SUBPIXEL ); + + if ( subpixel ) + grayscale = FALSE; + else if ( SPH_OPTION_SET_GRAYSCALE ) + { + grayscale = TRUE; + subpixel = FALSE; + } + else + grayscale = FALSE; + + if ( FT_IS_TRICKY( glyph->face ) ) + subpixel = FALSE; + + exec->ignore_x_mode = subpixel || grayscale; + exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; + if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 ) + exec->rasterizer_version = TT_INTERPRETER_VERSION_35; + +#if 1 + exec->compatible_widths = SPH_OPTION_SET_COMPATIBLE_WIDTHS; + exec->symmetrical_smoothing = FALSE; + exec->bgr = FALSE; + exec->subpixel_positioned = TRUE; +#else /* 0 */ + exec->compatible_widths = + FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != + TT_LOAD_COMPATIBLE_WIDTHS ); + exec->symmetrical_smoothing = + FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != + TT_LOAD_SYMMETRICAL_SMOOTHING ); + exec->bgr = + FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != + TT_LOAD_BGR ); + exec->subpixel_positioned = + FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != + TT_LOAD_SUBPIXEL_POSITIONED ); +#endif /* 0 */ + + } + else + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ - /* a change from mono to grayscale rendering (and vice versa) */ - /* requires a re-execution of the CVT program */ - if ( grayscale != exec->grayscale ) { - FT_UInt i; + grayscale = FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != + FT_RENDER_MODE_MONO ); + } + error = TT_Load_Context( exec, face, size ); + if ( error ) + return error; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) + { + /* a change from mono to subpixel rendering (and vice versa) */ + /* requires a re-execution of the CVT program */ + if ( subpixel != exec->subpixel ) + { + FT_TRACE4(( "tt_loader_init: subpixel hinting change," + " re-executing `prep' table\n" )); + + exec->subpixel = subpixel; + reexecute = TRUE; + } + + /* a change from mono to grayscale rendering (and vice versa) */ + /* requires a re-execution of the CVT program */ + if ( grayscale != exec->grayscale ) + { + FT_TRACE4(( "tt_loader_init: grayscale hinting change," + " re-executing `prep' table\n" )); + + exec->grayscale = grayscale; + reexecute = TRUE; + } + } + else + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + { + /* a change from mono to grayscale rendering (and vice versa) */ + /* requires a re-execution of the CVT program */ + if ( grayscale != exec->grayscale ) + { + FT_TRACE4(( "tt_loader_init: grayscale change," + " re-executing `prep' table\n" )); + + exec->grayscale = grayscale; + reexecute = TRUE; + } + } + + if ( reexecute ) + { + FT_UInt i; - exec->grayscale = grayscale; for ( i = 0; i < size->cvt_size; i++ ) size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); - tt_size_run_prep( size ); + error = tt_size_run_prep( size, pedantic ); + if ( error ) + return error; } /* see whether the cvt program has disabled hinting */ @@ -1892,10 +2285,9 @@ #endif { - FT_Error error = face->goto_table( face, TTAG_glyf, stream, 0 ); - + error = face->goto_table( face, TTAG_glyf, stream, 0 ); - if ( error == TT_Err_Table_Missing ) + if ( FT_ERR_EQ( error, Table_Missing ) ) loader->glyf_offset = 0; else if ( error ) { @@ -1923,7 +2315,7 @@ loader->glyph = (FT_GlyphSlot)glyph; loader->stream = stream; - return TT_Err_Ok; + return FT_Err_Ok; } @@ -1960,13 +2352,11 @@ FT_UInt glyph_index, FT_Int32 load_flags ) { - TT_Face face; FT_Error error; TT_LoaderRec loader; - face = (TT_Face)glyph->face; - error = TT_Err_Ok; + FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index )); #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS @@ -1980,23 +2370,27 @@ error = load_sbit_image( size, glyph, glyph_index, load_flags ); if ( !error ) { - FT_Face root = &face->root; - - - if ( FT_IS_SCALABLE( root ) ) + if ( FT_IS_SCALABLE( glyph->face ) ) { /* for the bbox we need the header only */ (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE ); (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE ); glyph->linearHoriAdvance = loader.linear; - glyph->linearVertAdvance = loader.top_bearing + loader.bbox.yMax - - loader.vadvance; - if ( face->postscript.isFixedPitch && - ( load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 ) - glyph->linearHoriAdvance = face->horizontal.advance_Width_Max; + glyph->linearVertAdvance = loader.vadvance; + + /* sanity checks: if `xxxAdvance' in the sbit metric */ + /* structure isn't set, use `linearXXXAdvance' */ + if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance ) + glyph->metrics.horiAdvance = + FT_MulFix( glyph->linearHoriAdvance, + size->root.metrics.x_scale ); + if ( !glyph->metrics.vertAdvance && glyph->linearVertAdvance ) + glyph->metrics.vertAdvance = + FT_MulFix( glyph->linearVertAdvance, + size->root.metrics.y_scale ); } - return TT_Err_Ok; + return FT_Err_Ok; } } @@ -2004,10 +2398,10 @@ /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */ if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid ) - return TT_Err_Invalid_Size_Handle; + return FT_THROW( Invalid_Size_Handle ); if ( load_flags & FT_LOAD_SBITS_ONLY ) - return TT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); error = tt_loader_init( &loader, size, glyph, load_flags, FALSE ); if ( error ) @@ -2031,9 +2425,11 @@ glyph->outline = loader.gloader->base.outline; glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS; - /* In case bit 1 of the `flags' field in the `head' table isn't */ - /* set, translate array so that (0,0) is the glyph's origin. */ - if ( ( face->header.Flags & 2 ) == 0 && loader.pp1.x ) + /* Translate array so that (0,0) is the glyph's origin. Note */ + /* that this behaviour is independent on the value of bit 1 of */ + /* the `flags' field in the `head' table -- at least major */ + /* applications like Acroread indicate that. */ + if ( loader.pp1.x ) FT_Outline_Translate( &glyph->outline, -loader.pp1.x, 0 ); } @@ -2071,7 +2467,7 @@ #endif /* TT_USE_BYTECODE_INTERPRETER */ - compute_glyph_metrics( &loader, glyph_index ); + error = compute_glyph_metrics( &loader, glyph_index ); } /* Set the `high precision' bit flag. */ diff --git a/src/3rdparty/freetype/src/truetype/ttgload.h b/src/3rdparty/freetype/src/truetype/ttgload.h index 958d67d20d..3f1699e686 100644 --- a/src/3rdparty/freetype/src/truetype/ttgload.h +++ b/src/3rdparty/freetype/src/truetype/ttgload.h @@ -4,7 +4,7 @@ /* */ /* TrueType Glyph Loader (specification). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */ +/* Copyright 1996-2006, 2008, 2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -37,14 +37,13 @@ FT_BEGIN_HEADER FT_LOCAL( void ) TT_Get_HMetrics( TT_Face face, FT_UInt idx, - FT_Bool check, FT_Short* lsb, FT_UShort* aw ); FT_LOCAL( void ) TT_Get_VMetrics( TT_Face face, FT_UInt idx, - FT_Bool check, + FT_Pos yMax, FT_Short* tsb, FT_UShort* ah ); diff --git a/src/3rdparty/freetype/src/truetype/ttgxvar.c b/src/3rdparty/freetype/src/truetype/ttgxvar.c index ef25aafb5b..1b35539fe1 100644 --- a/src/3rdparty/freetype/src/truetype/ttgxvar.c +++ b/src/3rdparty/freetype/src/truetype/ttgxvar.c @@ -4,7 +4,7 @@ /* */ /* TrueType GX Font Variation loader */ /* */ -/* Copyright 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 2004-2014 by */ /* David Turner, Robert Wilhelm, Werner Lemberg, and George Williams. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -61,9 +61,9 @@ #define FT_Stream_FTell( stream ) \ - ( (stream)->cursor - (stream)->base ) + (FT_ULong)( (stream)->cursor - (stream)->base ) #define FT_Stream_SeekSet( stream, off ) \ - ( (stream)->cursor = (stream)->base+(off) ) + ( (stream)->cursor = (stream)->base + (off) ) /*************************************************************************/ @@ -91,7 +91,9 @@ /* indicates that there is a delta for every point without needing to */ /* enumerate all of them. */ /* */ -#define ALL_POINTS (FT_UShort*)( -1 ) + + /* ensure that value `0' has the same width as a pointer */ +#define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0 #define GX_PT_POINTS_ARE_WORDS 0x80 @@ -123,14 +125,14 @@ ft_var_readpackedpoints( FT_Stream stream, FT_UInt *point_cnt ) { - FT_UShort *points; + FT_UShort *points = NULL; FT_Int n; FT_Int runcnt; FT_Int i; FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +156,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +167,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j ) @@ -210,12 +212,12 @@ ft_var_readpackeddeltas( FT_Stream stream, FT_Offset delta_cnt ) { - FT_Short *deltas; + FT_Short *deltas = NULL; FT_UInt runcnt; FT_Offset i; FT_UInt j; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_UNUSED( error ); @@ -283,7 +285,7 @@ FT_Memory memory = stream->memory; GX_Blend blend = face->blend; GX_AVarSegment segment; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_ULong version; FT_Long axisCount; FT_Int i, j; @@ -412,7 +414,7 @@ if ( gvar_head.version != (FT_Long)0x00010000L || gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis ) { - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Exit; } @@ -501,11 +503,9 @@ FT_Fixed* im_end_coords ) { FT_UInt i; - FT_Fixed apply; - FT_Fixed temp; + FT_Fixed apply = 0x10000L; - apply = 0x10000L; for ( i = 0; i < blend->num_axis; ++i ) { if ( tuple_coords[i] == 0 ) @@ -525,11 +525,10 @@ else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) /* not an intermediate tuple */ - apply = FT_MulDiv( apply, + apply = FT_MulFix( apply, blend->normalizedcoords[i] > 0 ? blend->normalizedcoords[i] - : -blend->normalizedcoords[i], - 0x10000L ); + : -blend->normalizedcoords[i] ); else if ( blend->normalizedcoords[i] <= im_start_coords[i] || blend->normalizedcoords[i] >= im_end_coords[i] ) @@ -539,20 +538,14 @@ } else if ( blend->normalizedcoords[i] < tuple_coords[i] ) - { - temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i], - 0x10000L, - tuple_coords[i] - im_start_coords[i]); - apply = FT_MulDiv( apply, temp, 0x10000L ); - } + apply = FT_MulDiv( apply, + blend->normalizedcoords[i] - im_start_coords[i], + tuple_coords[i] - im_start_coords[i] ); else - { - temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i], - 0x10000L, - im_end_coords[i] - tuple_coords[i] ); - apply = FT_MulDiv( apply, temp, 0x10000L ); - } + apply = FT_MulDiv( apply, + im_end_coords[i] - blend->normalizedcoords[i], + im_end_coords[i] - tuple_coords[i] ); } return apply; @@ -619,10 +612,10 @@ FT_Stream stream = face->root.stream; FT_Memory memory = face->root.memory; FT_ULong table_len; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_ULong fvar_start; FT_Int i, j; - FT_MM_Var* mmvar; + FT_MM_Var* mmvar = NULL; FT_Fixed* next_coords; FT_String* next_name; FT_Var_Axis* a; @@ -682,18 +675,22 @@ if ( fvar_head.version != (FT_Long)0x00010000L || fvar_head.countSizePairs != 2 || fvar_head.axisSize != 20 || + /* axisCount limit implied by 16-bit instanceSize */ + fvar_head.axisCount > 0x3FFE || fvar_head.instanceSize != 4 + 4 * fvar_head.axisCount || + /* instanceCount limit implied by limited range of name IDs */ + fvar_head.instanceCount > 0x7EFF || fvar_head.offsetToData + fvar_head.axisCount * 20U + fvar_head.instanceCount * fvar_head.instanceSize > table_len ) { - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Exit; } if ( FT_NEW( face->blend ) ) goto Exit; - /* XXX: TODO - check for overflows */ + /* cannot overflow 32-bit arithmetic because of limits above */ face->blend->mmvar_len = sizeof ( FT_MM_Var ) + fvar_head.axisCount * sizeof ( FT_Var_Axis ) + @@ -708,7 +705,7 @@ mmvar->num_axis = fvar_head.axisCount; mmvar->num_designs = - (FT_UInt)-1; /* meaningless in this context; each glyph */ + ~0U; /* meaningless in this context; each glyph */ /* may have a different number of designs */ /* (or tuples, as called by Apple) */ mmvar->num_namedstyles = @@ -852,7 +849,7 @@ FT_UInt num_coords, FT_Fixed* coords ) { - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; GX_Blend blend; FT_MM_Var* mmvar; FT_UInt i; @@ -880,14 +877,14 @@ if ( num_coords != mmvar->num_axis ) { - error = TT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } for ( i = 0; i < num_coords; ++i ) if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L ) { - error = TT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -941,13 +938,13 @@ FT_FREE( face->cvt ); face->cvt = NULL; - tt_face_load_cvt( face, face->root.stream ); + error = tt_face_load_cvt( face, face->root.stream ); break; case mcvt_modify: /* The original cvt table is in memory. All we need to do is */ /* apply the `cvar' table (if any). */ - tt_face_vary_cvt( face, face->root.stream ); + error = tt_face_vary_cvt( face, face->root.stream ); break; case mcvt_retain: @@ -988,7 +985,7 @@ FT_UInt num_coords, FT_Fixed* coords ) { - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Fixed* normalized = NULL; GX_Blend blend; FT_MM_Var* mmvar; @@ -1009,7 +1006,7 @@ if ( num_coords != mmvar->num_axis ) { - error = TT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -1025,24 +1022,16 @@ { if ( coords[i] > a->maximum || coords[i] < a->minimum ) { - error = TT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } if ( coords[i] < a->def ) - { - normalized[i] = -FT_MulDiv( coords[i] - a->def, - 0x10000L, - a->minimum - a->def ); - } + normalized[i] = -FT_DivFix( coords[i] - a->def, a->minimum - a->def ); else if ( a->maximum == a->def ) normalized[i] = 0; else - { - normalized[i] = FT_MulDiv( coords[i] - a->def, - 0x10000L, - a->maximum - a->def ); - } + normalized[i] = FT_DivFix( coords[i] - a->def, a->maximum - a->def ); } if ( !blend->avar_checked ) @@ -1057,15 +1046,11 @@ if ( normalized[i] < av->correspondence[j].fromCoord ) { normalized[i] = - FT_MulDiv( - FT_MulDiv( - normalized[i] - av->correspondence[j - 1].fromCoord, - 0x10000L, - av->correspondence[j].fromCoord - - av->correspondence[j - 1].fromCoord ), - av->correspondence[j].toCoord - - av->correspondence[j - 1].toCoord, - 0x10000L ) + + FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord, + av->correspondence[j].toCoord - + av->correspondence[j - 1].toCoord, + av->correspondence[j].fromCoord - + av->correspondence[j - 1].fromCoord ) + av->correspondence[j - 1].toCoord; break; } @@ -1137,7 +1122,7 @@ { FT_TRACE2(( "tt_face_vary_cvt: no blend specified\n" )); - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } @@ -1145,7 +1130,7 @@ { FT_TRACE2(( "tt_face_vary_cvt: no `cvt ' table\n" )); - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } @@ -1154,13 +1139,13 @@ { FT_TRACE2(( "is missing\n" )); - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } if ( FT_FRAME_ENTER( table_len ) ) { - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } @@ -1169,7 +1154,7 @@ { FT_TRACE2(( "bad table version\n" )); - error = TT_Err_Ok; + error = FT_Err_Ok; goto FExit; } @@ -1321,7 +1306,7 @@ FT_Stream stream = face->root.stream; FT_Memory memory = stream->memory; GX_Blend blend = face->blend; - FT_Vector* delta_xy; + FT_Vector* delta_xy = NULL; FT_Error error; FT_ULong glyph_start; @@ -1340,7 +1325,7 @@ if ( !face->doblend || blend == NULL ) - return TT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* to be freed by the caller */ if ( FT_NEW_ARRAY( delta_xy, n_points ) ) @@ -1350,7 +1335,7 @@ if ( glyph_index >= blend->gv_glyphcnt || blend->glyphoffsets[glyph_index] == blend->glyphoffsets[glyph_index + 1] ) - return TT_Err_Ok; /* no variation data for this glyph */ + return FT_Err_Ok; /* no variation data for this glyph */ if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) || FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] - @@ -1400,7 +1385,7 @@ } else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount ) { - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Fail3; } else @@ -1470,6 +1455,9 @@ { for ( j = 0; j < point_count; ++j ) { + if ( localpoints[j] >= n_points ) + continue; + delta_xy[localpoints[j]].x += FT_MulFix( deltas_x[j], apply ); delta_xy[localpoints[j]].y += FT_MulFix( deltas_y[j], apply ); } diff --git a/src/3rdparty/freetype/src/truetype/ttinterp.c b/src/3rdparty/freetype/src/truetype/ttinterp.c index d1769b8d2a..eccd4aaccb 100644 --- a/src/3rdparty/freetype/src/truetype/ttinterp.c +++ b/src/3rdparty/freetype/src/truetype/ttinterp.c @@ -4,8 +4,8 @@ /* */ /* TrueType bytecode interpreter (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* Copyright 1996-2014 */ +/* by 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 */ @@ -16,25 +16,25 @@ /***************************************************************************/ +/* Greg Hitchcock from Microsoft has helped a lot in resolving unclear */ +/* issues; many thanks! */ + + #include #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_CALC_H #include FT_TRIGONOMETRY_H #include FT_SYSTEM_H +#include FT_TRUETYPE_DRIVER_H #include "ttinterp.h" - #include "tterrors.h" +#include "ttsubpix.h" #ifdef TT_USE_BYTECODE_INTERPRETER -#define TT_MULFIX FT_MulFix -#define TT_MULDIV FT_MulDiv -#define TT_MULDIV_NO_ROUND FT_MulDiv_No_Round - - /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ @@ -48,7 +48,7 @@ /* */ /* In order to detect infinite loops in the code, we set up a counter */ /* within the run loop. A single stroke of interpretation is now */ - /* limited to a maximal number of opcodes defined below. */ + /* limited to a maximum number of opcodes defined below. */ /* */ #define MAX_RUNNABLE_OPCODES 1000000L @@ -132,6 +132,11 @@ #define FT_UNUSED_ARG FT_UNUSED_EXEC; FT_UNUSED( args ) +#define SUBPIXEL_HINTING \ + ( ((TT_Driver)FT_FACE_DRIVER( CUR.face ))->interpreter_version == \ + TT_INTERPRETER_VERSION_38 ) + + /*************************************************************************/ /* */ /* The following macros hide the use of EXEC_ARG and EXEC_ARG_ to */ @@ -167,6 +172,9 @@ #define CUR_Func_round( d, c ) \ CUR.func_round( EXEC_ARG_ d, c ) +#define CUR_Func_cur_ppem() \ + CUR.func_cur_ppem( EXEC_ARG ) + #define CUR_Func_read_cvt( index ) \ CUR.func_read_cvt( EXEC_ARG_ index ) @@ -179,12 +187,6 @@ #define CURRENT_Ratio() \ Current_Ratio( EXEC_ARG ) -#define CURRENT_Ppem() \ - Current_Ppem( EXEC_ARG ) - -#define CUR_Ppem() \ - Cur_PPEM( EXEC_ARG ) - #define INS_SxVTL( a, b, c, d ) \ Ins_SxVTL( EXEC_ARG_ a, b, c, d ) @@ -223,9 +225,18 @@ /*************************************************************************/ /* */ - /* A simple bounds-checking macro. */ + /* Two simple bounds-checking macros. */ + /* */ +#define BOUNDS( x, n ) ( (FT_UInt)(x) >= (FT_UInt)(n) ) +#define BOUNDSL( x, n ) ( (FT_ULong)(x) >= (FT_ULong)(n) ) + + /*************************************************************************/ + /* */ + /* This macro computes (a*2^14)/b and complements TT_MulFix14. */ /* */ -#define BOUNDS( x, n ) ( (FT_UInt)(x) >= (FT_UInt)(n) ) +#define TT_DivFix14( a, b ) \ + FT_DivFix( a, (b) << 2 ) + #undef SUCCESS #define SUCCESS 0 @@ -268,10 +279,7 @@ /* */ /* exec :: The target execution context. */ /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) + FT_LOCAL_DEF( void ) TT_Goto_CodeRange( TT_ExecContext exec, FT_Int range, FT_Long IP ) @@ -295,8 +303,6 @@ exec->codeSize = coderange->size; exec->IP = IP; exec->curRange = range; - - return TT_Err_Ok; } @@ -318,10 +324,7 @@ /* */ /* exec :: The target execution context. */ /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) + FT_LOCAL_DEF( void ) TT_Set_CodeRange( TT_ExecContext exec, FT_Int range, void* base, @@ -331,8 +334,6 @@ exec->codeRangeTable[range - 1].base = (FT_Byte*)base; exec->codeRangeTable[range - 1].size = length; - - return TT_Err_Ok; } @@ -350,13 +351,7 @@ /* */ /* exec :: The target execution context. */ /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - /* */ - /* Does not set the Error variable. */ - /* */ - FT_LOCAL_DEF( FT_Error ) + FT_LOCAL_DEF( void ) TT_Clear_CodeRange( TT_ExecContext exec, FT_Int range ) { @@ -364,8 +359,6 @@ exec->codeRangeTable[range - 1].base = NULL; exec->codeRangeTable[range - 1].size = 0; - - return TT_Err_Ok; } @@ -389,13 +382,10 @@ /* */ /* memory :: A handle to the parent memory object. */ /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ /* */ /* Only the glyph loader and debugger should call this function. */ /* */ - FT_LOCAL_DEF( FT_Error ) + FT_LOCAL_DEF( void ) TT_Done_Context( TT_ExecContext exec ) { FT_Memory memory = exec->memory; @@ -422,8 +412,6 @@ exec->face = NULL; FT_FREE( exec ); - - return TT_Err_Ok; } @@ -473,11 +461,10 @@ exec->face = NULL; exec->size = NULL; - return TT_Err_Ok; + return FT_Err_Ok; Fail_Memory: - FT_ERROR(( "Init_Context: not enough memory for 0x%08lx\n", - (FT_Long)exec )); + FT_ERROR(( "Init_Context: not enough memory for %p\n", exec )); TT_Done_Context( exec ); return error; @@ -508,7 +495,7 @@ /* */ /* FreeType error code. 0 means success. */ /* */ - static FT_Error + FT_LOCAL_DEF( FT_Error ) Update_Max( FT_Memory memory, FT_ULong* size, FT_Long multiplier, @@ -526,7 +513,7 @@ *size = new_max; } - return TT_Err_Ok; + return FT_Err_Ok; } @@ -594,6 +581,12 @@ exec->storage = size->storage; exec->twilight = size->twilight; + + /* In case of multi-threading it can happen that the old size object */ + /* no longer exists, thus we must clear all glyph zone references. */ + ft_memset( &exec->zp0, 0, sizeof ( exec->zp0 ) ); + exec->zp1 = exec->zp0; + exec->zp2 = exec->zp0; } /* XXX: We reserve a little more elements on the stack to deal safely */ @@ -627,7 +620,7 @@ exec->instruction_trap = FALSE; - return TT_Err_Ok; + return FT_Err_Ok; } @@ -645,22 +638,19 @@ /* */ /* size :: A handle to the target size object. */ /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ /* */ /* Only the glyph loader and debugger should call this function. */ /* */ - FT_LOCAL_DEF( FT_Error ) + FT_LOCAL_DEF( void ) TT_Save_Context( TT_ExecContext exec, TT_Size size ) { FT_Int i; - /* XXXX: Will probably disappear soon with all the code range */ - /* management, which is now rather obsolete. */ - /* */ + /* XXX: Will probably disappear soon with all the code range */ + /* management, which is now rather obsolete. */ + /* */ size->num_function_defs = exec->numFDefs; size->num_instruction_defs = exec->numIDefs; @@ -669,8 +659,6 @@ for ( i = 0; i < TT_MAX_CODE_RANGES; i++ ) size->codeRangeTable[i] = exec->codeRangeTable[i]; - - return TT_Err_Ok; } @@ -702,12 +690,7 @@ TT_Run_Context( TT_ExecContext exec, FT_Bool debug ) { - FT_Error error; - - - if ( ( error = TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ) ) - != TT_Err_Ok ) - return error; + TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ); exec->zp0 = exec->pts; exec->zp1 = exec->pts; @@ -743,7 +726,7 @@ if ( !debug ) return TT_RunIns( exec ); else - return TT_Err_Ok; + return FT_Err_Ok; #endif } @@ -777,16 +760,18 @@ FT_EXPORT_DEF( TT_ExecContext ) TT_New_Context( TT_Driver driver ) { - TT_ExecContext exec; - FT_Memory memory; + FT_Memory memory; + + if ( !driver ) + goto Fail; memory = driver->root.root.memory; - exec = driver->context; if ( !driver->context ) { - FT_Error error; + FT_Error error; + TT_ExecContext exec; /* allocate object */ @@ -805,7 +790,6 @@ return driver->context; Fail: - FT_FREE( exec ); return NULL; } @@ -980,8 +964,8 @@ /* INS_$83 */ PACK( 0, 0 ), /* INS_$84 */ PACK( 0, 0 ), /* ScanCTRL */ PACK( 1, 0 ), - /* SDVPTL[0] */ PACK( 2, 0 ), - /* SDVPTL[1] */ PACK( 2, 0 ), + /* SDPVTL[0] */ PACK( 2, 0 ), + /* SDPVTL[1] */ PACK( 2, 0 ), /* GetINFO */ PACK( 1, 1 ), /* IDEF */ PACK( 1, 0 ), /* ROLL */ PACK( 3, 3 ), @@ -1112,6 +1096,287 @@ }; +#ifdef FT_DEBUG_LEVEL_TRACE + + static + const char* const opcode_name[256] = + { + "SVTCA y", + "SVTCA x", + "SPvTCA y", + "SPvTCA x", + "SFvTCA y", + "SFvTCA x", + "SPvTL ||", + "SPvTL +", + "SFvTL ||", + "SFvTL +", + "SPvFS", + "SFvFS", + "GPV", + "GFV", + "SFvTPv", + "ISECT", + + "SRP0", + "SRP1", + "SRP2", + "SZP0", + "SZP1", + "SZP2", + "SZPS", + "SLOOP", + "RTG", + "RTHG", + "SMD", + "ELSE", + "JMPR", + "SCvTCi", + "SSwCi", + "SSW", + + "DUP", + "POP", + "CLEAR", + "SWAP", + "DEPTH", + "CINDEX", + "MINDEX", + "AlignPTS", + "INS_$28", + "UTP", + "LOOPCALL", + "CALL", + "FDEF", + "ENDF", + "MDAP[0]", + "MDAP[1]", + + "IUP[0]", + "IUP[1]", + "SHP[0]", + "SHP[1]", + "SHC[0]", + "SHC[1]", + "SHZ[0]", + "SHZ[1]", + "SHPIX", + "IP", + "MSIRP[0]", + "MSIRP[1]", + "AlignRP", + "RTDG", + "MIAP[0]", + "MIAP[1]", + + "NPushB", + "NPushW", + "WS", + "RS", + "WCvtP", + "RCvt", + "GC[0]", + "GC[1]", + "SCFS", + "MD[0]", + "MD[1]", + "MPPEM", + "MPS", + "FlipON", + "FlipOFF", + "DEBUG", + + "LT", + "LTEQ", + "GT", + "GTEQ", + "EQ", + "NEQ", + "ODD", + "EVEN", + "IF", + "EIF", + "AND", + "OR", + "NOT", + "DeltaP1", + "SDB", + "SDS", + + "ADD", + "SUB", + "DIV", + "MUL", + "ABS", + "NEG", + "FLOOR", + "CEILING", + "ROUND[0]", + "ROUND[1]", + "ROUND[2]", + "ROUND[3]", + "NROUND[0]", + "NROUND[1]", + "NROUND[2]", + "NROUND[3]", + + "WCvtF", + "DeltaP2", + "DeltaP3", + "DeltaCn[0]", + "DeltaCn[1]", + "DeltaCn[2]", + "SROUND", + "S45Round", + "JROT", + "JROF", + "ROFF", + "INS_$7B", + "RUTG", + "RDTG", + "SANGW", + "AA", + + "FlipPT", + "FlipRgON", + "FlipRgOFF", + "INS_$83", + "INS_$84", + "ScanCTRL", + "SDVPTL[0]", + "SDVPTL[1]", + "GetINFO", + "IDEF", + "ROLL", + "MAX", + "MIN", + "ScanTYPE", + "InstCTRL", + "INS_$8F", + + "INS_$90", + "INS_$91", + "INS_$92", + "INS_$93", + "INS_$94", + "INS_$95", + "INS_$96", + "INS_$97", + "INS_$98", + "INS_$99", + "INS_$9A", + "INS_$9B", + "INS_$9C", + "INS_$9D", + "INS_$9E", + "INS_$9F", + + "INS_$A0", + "INS_$A1", + "INS_$A2", + "INS_$A3", + "INS_$A4", + "INS_$A5", + "INS_$A6", + "INS_$A7", + "INS_$A8", + "INS_$A9", + "INS_$AA", + "INS_$AB", + "INS_$AC", + "INS_$AD", + "INS_$AE", + "INS_$AF", + + "PushB[0]", + "PushB[1]", + "PushB[2]", + "PushB[3]", + "PushB[4]", + "PushB[5]", + "PushB[6]", + "PushB[7]", + "PushW[0]", + "PushW[1]", + "PushW[2]", + "PushW[3]", + "PushW[4]", + "PushW[5]", + "PushW[6]", + "PushW[7]", + + "MDRP[00]", + "MDRP[01]", + "MDRP[02]", + "MDRP[03]", + "MDRP[04]", + "MDRP[05]", + "MDRP[06]", + "MDRP[07]", + "MDRP[08]", + "MDRP[09]", + "MDRP[10]", + "MDRP[11]", + "MDRP[12]", + "MDRP[13]", + "MDRP[14]", + "MDRP[15]", + + "MDRP[16]", + "MDRP[17]", + "MDRP[18]", + "MDRP[19]", + "MDRP[20]", + "MDRP[21]", + "MDRP[22]", + "MDRP[23]", + "MDRP[24]", + "MDRP[25]", + "MDRP[26]", + "MDRP[27]", + "MDRP[28]", + "MDRP[29]", + "MDRP[30]", + "MDRP[31]", + + "MIRP[00]", + "MIRP[01]", + "MIRP[02]", + "MIRP[03]", + "MIRP[04]", + "MIRP[05]", + "MIRP[06]", + "MIRP[07]", + "MIRP[08]", + "MIRP[09]", + "MIRP[10]", + "MIRP[11]", + "MIRP[12]", + "MIRP[13]", + "MIRP[14]", + "MIRP[15]", + + "MIRP[16]", + "MIRP[17]", + "MIRP[18]", + "MIRP[19]", + "MIRP[20]", + "MIRP[21]", + "MIRP[22]", + "MIRP[23]", + "MIRP[24]", + "MIRP[25]", + "MIRP[26]", + "MIRP[27]", + "MIRP[28]", + "MIRP[29]", + "MIRP[30]", + "MIRP[31]" + }; + +#endif /* FT_DEBUG_LEVEL_TRACE */ + + static const FT_Char opcode_length[256] = { @@ -1138,8 +1403,107 @@ #undef PACK -#if 1 +#ifndef FT_CONFIG_OPTION_NO_ASSEMBLER + +#if defined( __arm__ ) && \ + ( defined( __thumb2__ ) || !defined( __thumb__ ) ) + +#define TT_MulFix14 TT_MulFix14_arm + + static FT_Int32 + TT_MulFix14_arm( FT_Int32 a, + FT_Int b ) + { + FT_Int32 t, t2; + + +#if defined( __CC_ARM ) || defined( __ARMCC__ ) + + __asm + { + smull t2, t, b, a /* (lo=t2,hi=t) = a*b */ + mov a, t, asr #31 /* a = (hi >> 31) */ + add a, a, #0x2000 /* a += 0x2000 */ + adds t2, t2, a /* t2 += a */ + adc t, t, #0 /* t += carry */ + mov a, t2, lsr #14 /* a = t2 >> 14 */ + orr a, a, t, lsl #18 /* a |= t << 18 */ + } + +#elif defined( __GNUC__ ) + + __asm__ __volatile__ ( + "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */ + "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */ +#if defined( __clang__ ) && defined( __thumb2__ ) + "add.w %0, %0, #0x2000\n\t" /* %0 += 0x2000 */ +#else + "add %0, %0, #0x2000\n\t" /* %0 += 0x2000 */ +#endif + "adds %1, %1, %0\n\t" /* %1 += %0 */ + "adc %2, %2, #0\n\t" /* %2 += carry */ + "mov %0, %1, lsr #14\n\t" /* %0 = %1 >> 16 */ + "orr %0, %0, %2, lsl #18\n\t" /* %0 |= %2 << 16 */ + : "=r"(a), "=&r"(t2), "=&r"(t) + : "r"(a), "r"(b) + : "cc" ); + +#endif + + return a; + } + +#endif /* __arm__ && ( __thumb2__ || !__thumb__ ) */ + +#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */ + + +#if defined( __GNUC__ ) && \ + ( defined( __i386__ ) || defined( __x86_64__ ) ) + +#define TT_MulFix14 TT_MulFix14_long_long + + /* Temporarily disable the warning that C90 doesn't support `long long'. */ +#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406 +#pragma GCC diagnostic push +#endif +#pragma GCC diagnostic ignored "-Wlong-long" + + /* This is declared `noinline' because inlining the function results */ + /* in slower code. The `pure' attribute indicates that the result */ + /* only depends on the parameters. */ + static __attribute__(( noinline )) + __attribute__(( pure )) FT_Int32 + TT_MulFix14_long_long( FT_Int32 a, + FT_Int b ) + { + + long long ret = (long long)a * b; + + /* The following line assumes that right shifting of signed values */ + /* will actually preserve the sign bit. The exact behaviour is */ + /* undefined, but this is true on x86 and x86_64. */ + long long tmp = ret >> 63; + + + ret += 0x2000 + tmp; + + return (FT_Int32)( ret >> 14 ); + } + +#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406 +#pragma GCC diagnostic pop +#endif + +#endif /* __GNUC__ && ( __i386__ || __x86_64__ ) */ + + +#ifndef TT_MulFix14 + + /* Compute (a*b)/2^14 with maximum accuracy and rounding. */ + /* This is optimized to be faster than calling FT_MulFix() */ + /* for platforms where sizeof(int) == 2. */ static FT_Int32 TT_MulFix14( FT_Int32 a, FT_Int b ) @@ -1171,39 +1535,52 @@ return sign >= 0 ? (FT_Int32)mid : -(FT_Int32)mid; } -#else +#endif /* !TT_MulFix14 */ - /* compute (a*b)/2^14 with maximal accuracy and rounding */ - static FT_Int32 - TT_MulFix14( FT_Int32 a, - FT_Int b ) - { - FT_Int32 m, s, hi; - FT_UInt32 l, lo; +#if defined( __GNUC__ ) && \ + ( defined( __i386__ ) || \ + defined( __x86_64__ ) || \ + defined( __arm__ ) ) - /* compute ax*bx as 64-bit value */ - l = (FT_UInt32)( ( a & 0xFFFFU ) * b ); - m = ( a >> 16 ) * b; +#define TT_DotFix14 TT_DotFix14_long_long - lo = l + (FT_UInt32)( m << 16 ); - hi = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo < l ); +#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406 +#pragma GCC diagnostic push +#endif +#pragma GCC diagnostic ignored "-Wlong-long" - /* divide the result by 2^14 with rounding */ - s = hi >> 31; - l = lo + (FT_UInt32)s; - hi += s + ( l < lo ); - lo = l; + static __attribute__(( pure )) FT_Int32 + TT_DotFix14_long_long( FT_Int32 ax, + FT_Int32 ay, + FT_Int bx, + FT_Int by ) + { + /* Temporarily disable the warning that C90 doesn't support */ + /* `long long'. */ - l = lo + 0x2000U; - hi += l < lo; + long long temp1 = (long long)ax * bx; + long long temp2 = (long long)ay * by; + + + temp1 += temp2; + temp2 = temp1 >> 63; + temp1 += 0x2000 + temp2; + + return (FT_Int32)( temp1 >> 14 ); - return ( hi << 18 ) | ( l >> 14 ); } + +#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406 +#pragma GCC diagnostic pop #endif +#endif /* __GNUC__ && (__arm__ || __i386__ || __x86_64__) */ - /* compute (ax*bx+ay*by)/2^14 with maximal accuracy and rounding */ + +#ifndef TT_DotFix14 + + /* compute (ax*bx+ay*by)/2^14 with maximum accuracy and rounding */ static FT_Int32 TT_DotFix14( FT_Int32 ax, FT_Int32 ay, @@ -1218,14 +1595,14 @@ l = (FT_UInt32)( ( ax & 0xFFFFU ) * bx ); m = ( ax >> 16 ) * bx; - lo1 = l + (FT_UInt32)( m << 16 ); + lo1 = l + ( (FT_UInt32)m << 16 ); hi1 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo1 < l ); /* compute ay*by as 64-bit value */ l = (FT_UInt32)( ( ay & 0xFFFFU ) * by ); m = ( ay >> 16 ) * by; - lo2 = l + (FT_UInt32)( m << 16 ); + lo2 = l + ( (FT_UInt32)m << 16 ); hi2 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo2 < l ); /* add them */ @@ -1241,98 +1618,10 @@ l = lo + 0x2000U; hi += ( l < lo ); - return ( hi << 18 ) | ( l >> 14 ); - } - - - /* return length of given vector */ - -#if 0 - - static FT_Int32 - TT_VecLen( FT_Int32 x, - FT_Int32 y ) - { - FT_Int32 m, hi1, hi2, hi; - FT_UInt32 l, lo1, lo2, lo; - - - /* compute x*x as 64-bit value */ - lo = (FT_UInt32)( x & 0xFFFFU ); - hi = x >> 16; - - l = lo * lo; - m = hi * lo; - hi = hi * hi; - - lo1 = l + (FT_UInt32)( m << 17 ); - hi1 = hi + ( m >> 15 ) + ( lo1 < l ); - - /* compute y*y as 64-bit value */ - lo = (FT_UInt32)( y & 0xFFFFU ); - hi = y >> 16; - - l = lo * lo; - m = hi * lo; - hi = hi * hi; - - lo2 = l + (FT_UInt32)( m << 17 ); - hi2 = hi + ( m >> 15 ) + ( lo2 < l ); - - /* add them to get 'x*x+y*y' as 64-bit value */ - lo = lo1 + lo2; - hi = hi1 + hi2 + ( lo < lo1 ); - - /* compute the square root of this value */ - { - FT_UInt32 root, rem, test_div; - FT_Int count; - - - root = 0; - - { - rem = 0; - count = 32; - do - { - rem = ( rem << 2 ) | ( (FT_UInt32)hi >> 30 ); - hi = ( hi << 2 ) | ( lo >> 30 ); - lo <<= 2; - root <<= 1; - test_div = ( root << 1 ) + 1; - - if ( rem >= test_div ) - { - rem -= test_div; - root += 1; - } - } while ( --count ); - } - - return (FT_Int32)root; - } - } - -#else - - /* this version uses FT_Vector_Length which computes the same value */ - /* much, much faster.. */ - /* */ - static FT_F26Dot6 - TT_VecLen( FT_F26Dot6 X, - FT_F26Dot6 Y ) - { - FT_Vector v; - - - v.x = X; - v.y = Y; - - return FT_Vector_Length( &v ); + return (FT_Int32)( ( (FT_UInt32)hi << 18 ) | ( l >> 14 ) ); } -#endif +#endif /* TT_DotFix14 */ /*************************************************************************/ @@ -1371,14 +1660,14 @@ else { - FT_Long x, y; + FT_F26Dot6 x, y; - x = TT_MULDIV( CUR.GS.projVector.x, - CUR.tt_metrics.x_ratio, 0x4000 ); - y = TT_MULDIV( CUR.GS.projVector.y, - CUR.tt_metrics.y_ratio, 0x4000 ); - CUR.tt_metrics.ratio = TT_VecLen( x, y ); + x = TT_MulFix14( CUR.tt_metrics.x_ratio, + CUR.GS.projVector.x ); + y = TT_MulFix14( CUR.tt_metrics.y_ratio, + CUR.GS.projVector.y ); + CUR.tt_metrics.ratio = FT_Hypot( x, y ); } } } @@ -1386,10 +1675,17 @@ } - static FT_Long + FT_CALLBACK_DEF( FT_Long ) Current_Ppem( EXEC_OP ) { - return TT_MULFIX( CUR.tt_metrics.ppem, CURRENT_Ratio() ); + return CUR.tt_metrics.ppem; + } + + + FT_CALLBACK_DEF( FT_Long ) + Current_Ppem_Stretched( EXEC_OP ) + { + return FT_MulFix( CUR.tt_metrics.ppem, CURRENT_Ratio() ); } @@ -1410,7 +1706,7 @@ FT_CALLBACK_DEF( FT_F26Dot6 ) Read_CVT_Stretched( EXEC_OP_ FT_ULong idx ) { - return TT_MULFIX( CUR.cvt[idx], CURRENT_Ratio() ); + return FT_MulFix( CUR.cvt[idx], CURRENT_Ratio() ); } @@ -1496,7 +1792,7 @@ if ( aRange < 1 || aRange > 3 ) { - CUR.error = TT_Err_Bad_Argument; + CUR.error = FT_THROW( Bad_Argument ); return FAILURE; } @@ -1504,17 +1800,17 @@ if ( range->base == NULL ) /* invalid coderange */ { - CUR.error = TT_Err_Invalid_CodeRange; + CUR.error = FT_THROW( Invalid_CodeRange ); return FAILURE; } /* NOTE: Because the last instruction of a program may be a CALL */ /* which will return to the first byte *after* the code */ - /* range, we test for AIP <= Size, instead of AIP < Size. */ + /* range, we test for aIP <= Size, instead of aIP < Size. */ if ( aIP > range->size ) { - CUR.error = TT_Err_Code_Overflow; + CUR.error = FT_THROW( Code_Overflow ); return FAILURE; } @@ -1560,9 +1856,12 @@ if ( v != 0 ) { - zone->cur[point].x += TT_MULDIV( distance, - v * 0x10000L, - CUR.F_dot_P ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( !SUBPIXEL_HINTING || + ( !CUR.ignore_x_mode || + ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_DMOVE ) ) ) +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + zone->cur[point].x += FT_MulDiv( distance, v, CUR.F_dot_P ); zone->tags[point] |= FT_CURVE_TAG_TOUCH_X; } @@ -1571,9 +1870,7 @@ if ( v != 0 ) { - zone->cur[point].y += TT_MULDIV( distance, - v * 0x10000L, - CUR.F_dot_P ); + zone->cur[point].y += FT_MulDiv( distance, v, CUR.F_dot_P ); zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y; } @@ -1612,16 +1909,12 @@ v = CUR.GS.freeVector.x; if ( v != 0 ) - zone->org[point].x += TT_MULDIV( distance, - v * 0x10000L, - CUR.F_dot_P ); + zone->org[point].x += FT_MulDiv( distance, v, CUR.F_dot_P ); v = CUR.GS.freeVector.y; if ( v != 0 ) - zone->org[point].y += TT_MULDIV( distance, - v * 0x10000L, - CUR.F_dot_P ); + zone->org[point].y += FT_MulDiv( distance, v, CUR.F_dot_P ); } @@ -1642,7 +1935,12 @@ { FT_UNUSED_EXEC; - zone->cur[point].x += distance; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( !SUBPIXEL_HINTING || + !CUR.ignore_x_mode ) +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + zone->cur[point].x += distance; + zone->tags[point] |= FT_CURVE_TAG_TOUCH_X; } @@ -1725,10 +2023,11 @@ if ( distance >= 0 ) { val = distance + compensation; - if ( distance && val < 0 ) + if ( val < 0 ) val = 0; } - else { + else + { val = distance - compensation; if ( val > 0 ) val = 0; @@ -1764,10 +2063,8 @@ if ( distance >= 0 ) { - val = distance + compensation + 32; - if ( distance && val > 0 ) - val &= ~63; - else + val = FT_PIX_ROUND( distance + compensation ); + if ( val < 0 ) val = 0; } else @@ -1809,14 +2106,14 @@ if ( distance >= 0 ) { val = FT_PIX_FLOOR( distance + compensation ) + 32; - if ( distance && val < 0 ) - val = 0; + if ( val < 0 ) + val = 32; } else { val = -( FT_PIX_FLOOR( compensation - distance ) + 32 ); if ( val > 0 ) - val = 0; + val = -32; } return val; @@ -1850,15 +2147,13 @@ if ( distance >= 0 ) { - val = distance + compensation; - if ( distance && val > 0 ) - val &= ~63; - else + val = FT_PIX_FLOOR( distance + compensation ); + if ( val < 0 ) val = 0; } else { - val = -( ( compensation - distance ) & -64 ); + val = -FT_PIX_FLOOR( compensation - distance ); if ( val > 0 ) val = 0; } @@ -1894,15 +2189,13 @@ if ( distance >= 0 ) { - val = distance + compensation + 63; - if ( distance && val > 0 ) - val &= ~63; - else + val = FT_PIX_CEIL( distance + compensation ); + if ( val < 0 ) val = 0; } else { - val = - FT_PIX_CEIL( compensation - distance ); + val = -FT_PIX_CEIL( compensation - distance ); if ( val > 0 ) val = 0; } @@ -1938,10 +2231,8 @@ if ( distance >= 0 ) { - val = distance + compensation + 16; - if ( distance && val > 0 ) - val &= ~31; - else + val = FT_PAD_ROUND( distance + compensation, 32 ); + if ( val < 0 ) val = 0; } else @@ -1988,17 +2279,17 @@ { val = ( distance - CUR.phase + CUR.threshold + compensation ) & -CUR.period; - if ( distance && val < 0 ) - val = 0; val += CUR.phase; + if ( val < 0 ) + val = CUR.phase; } else { val = -( ( CUR.threshold - CUR.phase - distance + compensation ) & -CUR.period ); - if ( val > 0 ) - val = 0; val -= CUR.phase; + if ( val > 0 ) + val = -CUR.phase; } return val; @@ -2036,17 +2327,17 @@ { val = ( ( distance - CUR.phase + CUR.threshold + compensation ) / CUR.period ) * CUR.period; - if ( distance && val < 0 ) - val = 0; val += CUR.phase; + if ( val < 0 ) + val = CUR.phase; } else { val = -( ( ( CUR.threshold - CUR.phase - distance + compensation ) / CUR.period ) * CUR.period ); - if ( val > 0 ) - val = 0; val -= CUR.phase; + if ( val > 0 ) + val = -CUR.phase; } return val; @@ -2113,8 +2404,9 @@ /* Sets Super Round parameters. */ /* */ /* */ - /* GridPeriod :: Grid period */ - /* selector :: SROUND opcode */ + /* GridPeriod :: The grid period. */ + /* */ + /* selector :: The SROUND opcode. */ /* */ static void SetSuperRound( EXEC_OP_ FT_F26Dot6 GridPeriod, @@ -2326,13 +2618,10 @@ if ( CUR.GS.dualVector.x == 0x4000 ) CUR.func_dualproj = Project_x; + else if ( CUR.GS.dualVector.y == 0x4000 ) + CUR.func_dualproj = Project_y; else - { - if ( CUR.GS.dualVector.y == 0x4000 ) - CUR.func_dualproj = Project_y; - else - CUR.func_dualproj = Dual_Project; - } + CUR.func_dualproj = Dual_Project; /* Force recalculation of cached aspect ratio */ CUR.tt_metrics.ratio = 0; @@ -2342,61 +2631,50 @@ #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING */ if ( CUR.GS.freeVector.x == 0x4000 ) - CUR.F_dot_P = CUR.GS.projVector.x * 0x10000L; + CUR.F_dot_P = CUR.GS.projVector.x; + else if ( CUR.GS.freeVector.y == 0x4000 ) + CUR.F_dot_P = CUR.GS.projVector.y; else - { - if ( CUR.GS.freeVector.y == 0x4000 ) - CUR.F_dot_P = CUR.GS.projVector.y * 0x10000L; - else - CUR.F_dot_P = (FT_Long)CUR.GS.projVector.x * CUR.GS.freeVector.x * 4 + - (FT_Long)CUR.GS.projVector.y * CUR.GS.freeVector.y * 4; - } + CUR.F_dot_P = ( (FT_Long)CUR.GS.projVector.x * CUR.GS.freeVector.x + + (FT_Long)CUR.GS.projVector.y * CUR.GS.freeVector.y ) >> + 14; if ( CUR.GS.projVector.x == 0x4000 ) CUR.func_project = (TT_Project_Func)Project_x; + else if ( CUR.GS.projVector.y == 0x4000 ) + CUR.func_project = (TT_Project_Func)Project_y; else - { - if ( CUR.GS.projVector.y == 0x4000 ) - CUR.func_project = (TT_Project_Func)Project_y; - else - CUR.func_project = (TT_Project_Func)Project; - } + CUR.func_project = (TT_Project_Func)Project; if ( CUR.GS.dualVector.x == 0x4000 ) CUR.func_dualproj = (TT_Project_Func)Project_x; + else if ( CUR.GS.dualVector.y == 0x4000 ) + CUR.func_dualproj = (TT_Project_Func)Project_y; else - { - if ( CUR.GS.dualVector.y == 0x4000 ) - CUR.func_dualproj = (TT_Project_Func)Project_y; - else - CUR.func_dualproj = (TT_Project_Func)Dual_Project; - } + CUR.func_dualproj = (TT_Project_Func)Dual_Project; CUR.func_move = (TT_Move_Func)Direct_Move; CUR.func_move_orig = (TT_Move_Func)Direct_Move_Orig; - if ( CUR.F_dot_P == 0x40000000L ) + if ( CUR.F_dot_P == 0x4000L ) { if ( CUR.GS.freeVector.x == 0x4000 ) { CUR.func_move = (TT_Move_Func)Direct_Move_X; CUR.func_move_orig = (TT_Move_Func)Direct_Move_Orig_X; } - else + else if ( CUR.GS.freeVector.y == 0x4000 ) { - if ( CUR.GS.freeVector.y == 0x4000 ) - { - CUR.func_move = (TT_Move_Func)Direct_Move_Y; - CUR.func_move_orig = (TT_Move_Func)Direct_Move_Orig_Y; - } + CUR.func_move = (TT_Move_Func)Direct_Move_Y; + CUR.func_move_orig = (TT_Move_Func)Direct_Move_Orig_Y; } } /* at small sizes, F_dot_P can become too small, resulting */ /* in overflows and `spikes' in a number of glyphs like `w'. */ - if ( FT_ABS( CUR.F_dot_P ) < 0x4000000L ) - CUR.F_dot_P = 0x40000000L; + if ( FT_ABS( CUR.F_dot_P ) < 0x400L ) + CUR.F_dot_P = 0x4000L; /* Disable cached aspect ratio */ CUR.tt_metrics.ratio = 0; @@ -2425,98 +2703,33 @@ /* In case Vx and Vy are both zero, Normalize() returns SUCCESS, and */ /* R is undefined. */ /* */ - - static FT_Bool Normalize( EXEC_OP_ FT_F26Dot6 Vx, FT_F26Dot6 Vy, FT_UnitVector* R ) { FT_F26Dot6 W; - FT_Bool S1, S2; FT_UNUSED_EXEC; - if ( FT_ABS( Vx ) < 0x10000L && FT_ABS( Vy ) < 0x10000L ) + if ( FT_ABS( Vx ) < 0x4000L && FT_ABS( Vy ) < 0x4000L ) { - Vx *= 0x100; - Vy *= 0x100; - - W = TT_VecLen( Vx, Vy ); - - if ( W == 0 ) + if ( Vx == 0 && Vy == 0 ) { /* XXX: UNDOCUMENTED! It seems that it is possible to try */ /* to normalize the vector (0,0). Return immediately. */ return SUCCESS; } - R->x = (FT_F2Dot14)FT_MulDiv( Vx, 0x4000L, W ); - R->y = (FT_F2Dot14)FT_MulDiv( Vy, 0x4000L, W ); - - return SUCCESS; - } - - W = TT_VecLen( Vx, Vy ); - - Vx = FT_MulDiv( Vx, 0x4000L, W ); - Vy = FT_MulDiv( Vy, 0x4000L, W ); - - W = Vx * Vx + Vy * Vy; - - /* Now, we want that Sqrt( W ) = 0x4000 */ - /* Or 0x10000000 <= W < 0x10004000 */ - - if ( Vx < 0 ) - { - Vx = -Vx; - S1 = TRUE; - } - else - S1 = FALSE; - - if ( Vy < 0 ) - { - Vy = -Vy; - S2 = TRUE; - } - else - S2 = FALSE; - - while ( W < 0x10000000L ) - { - /* We need to increase W by a minimal amount */ - if ( Vx < Vy ) - Vx++; - else - Vy++; - - W = Vx * Vx + Vy * Vy; - } - - while ( W >= 0x10004000L ) - { - /* We need to decrease W by a minimal amount */ - if ( Vx < Vy ) - Vx--; - else - Vy--; - - W = Vx * Vx + Vy * Vy; + Vx *= 0x4000; + Vy *= 0x4000; } - /* Note that in various cases, we can only */ - /* compute a Sqrt(W) of 0x3FFF, eg. Vx = Vy */ - - if ( S1 ) - Vx = -Vx; + W = FT_Hypot( Vx, Vy ); - if ( S2 ) - Vy = -Vy; - - R->x = (FT_F2Dot14)Vx; /* Type conversion */ - R->y = (FT_F2Dot14)Vy; /* Type conversion */ + R->x = (FT_F2Dot14)TT_DivFix14( Vx, W ); + R->y = (FT_F2Dot14)TT_DivFix14( Vy, W ); return SUCCESS; } @@ -2544,7 +2757,7 @@ BOUNDS( aIdx2, CUR.zp1.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return FAILURE; } @@ -2554,6 +2767,17 @@ A = p1->x - p2->x; B = p1->y - p2->y; + /* If p1 == p2, SPVTL and SFVTL behave the same as */ + /* SPVTCA[X] and SFVTCA[X], respectively. */ + /* */ + /* Confirmed by Greg Hitchcock. */ + + if ( A == 0 && B == 0 ) + { + A = 0x4000; + aOpc = 0; + } + if ( ( aOpc & 1 ) != 0 ) { C = B; /* counter clockwise rotation */ @@ -2789,10 +3013,10 @@ CUR.func_round = (TT_Round_Func)Round_Super_45; -#define DO_SLOOP \ - if ( args[0] < 0 ) \ - CUR.error = TT_Err_Bad_Argument; \ - else \ +#define DO_SLOOP \ + if ( args[0] < 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + else \ CUR.GS.loop = args[0]; @@ -2808,14 +3032,9 @@ CUR.GS.single_width_cutin = (FT_F26Dot6)args[0]; - /* XXX: UNDOCUMENTED! or bug in the Windows engine? */ - /* */ - /* It seems that the value that is read here is */ - /* expressed in 16.16 format rather than in font */ - /* units. */ - /* */ -#define DO_SSW \ - CUR.GS.single_width_value = (FT_F26Dot6)( args[0] >> 10 ); +#define DO_SSW \ + CUR.GS.single_width_value = FT_MulFix( args[0], \ + CUR.tt_metrics.scale ); #define DO_FLIPON \ @@ -2826,19 +3045,22 @@ CUR.GS.auto_flip = FALSE; -#define DO_SDB \ - CUR.GS.delta_base = (FT_Short)args[0]; +#define DO_SDB \ + CUR.GS.delta_base = (FT_UShort)args[0]; -#define DO_SDS \ - CUR.GS.delta_shift = (FT_Short)args[0]; +#define DO_SDS \ + if ( (FT_ULong)args[0] > 6UL ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + else \ + CUR.GS.delta_shift = (FT_UShort)args[0]; #define DO_MD /* nothing */ -#define DO_MPPEM \ - args[0] = CURRENT_Ppem(); +#define DO_MPPEM \ + args[0] = CUR_Func_cur_ppem(); /* Note: The pointSize should be irrelevant in a given font program; */ @@ -2850,8 +3072,8 @@ #else -#define DO_MPS \ - args[0] = CURRENT_Ppem(); +#define DO_MPS \ + args[0] = CUR_Func_cur_ppem(); #endif /* 0 */ @@ -2879,38 +3101,60 @@ args[0] = CUR.top; -#define DO_CINDEX \ - { \ - FT_Long L; \ - \ - \ - L = args[0]; \ - \ - if ( L <= 0 || L > CUR.args ) \ - CUR.error = TT_Err_Invalid_Reference; \ - else \ - args[0] = CUR.stack[CUR.args - L]; \ - } - - -#define DO_JROT \ - if ( args[1] != 0 ) \ - { \ - CUR.IP += args[0]; \ - CUR.step_ins = FALSE; \ - } - - -#define DO_JMPR \ - CUR.IP += args[0]; \ +#define DO_CINDEX \ + { \ + FT_Long L; \ + \ + \ + L = args[0]; \ + \ + if ( L <= 0 || L > CUR.args ) \ + { \ + if ( CUR.pedantic_hinting ) \ + CUR.error = FT_THROW( Invalid_Reference ); \ + args[0] = 0; \ + } \ + else \ + args[0] = CUR.stack[CUR.args - L]; \ + } + + +#define DO_JROT \ + if ( args[1] != 0 ) \ + { \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.step_ins = FALSE; \ + } + + +#define DO_JMPR \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ CUR.step_ins = FALSE; -#define DO_JROF \ - if ( args[1] == 0 ) \ - { \ - CUR.IP += args[0]; \ - CUR.step_ins = FALSE; \ +#define DO_JROF \ + if ( args[1] == 0 ) \ + { \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.step_ins = FALSE; \ } @@ -2968,13 +3212,13 @@ #define DO_DIV \ if ( args[1] == 0 ) \ - CUR.error = TT_Err_Divide_By_Zero; \ + CUR.error = FT_THROW( Divide_By_Zero ); \ else \ - args[0] = TT_MULDIV_NO_ROUND( args[0], 64L, args[1] ); + args[0] = FT_MulDiv_No_Round( args[0], 64L, args[1] ); #define DO_MUL \ - args[0] = TT_MULDIV( args[0], args[1], 64L ); + args[0] = FT_MulDiv( args[0], args[1], 64L ); #define DO_ABS \ @@ -2992,40 +3236,81 @@ #define DO_CEILING \ args[0] = FT_PIX_CEIL( args[0] ); - -#define DO_RS \ - { \ - FT_ULong I = (FT_ULong)args[0]; \ - \ - \ - if ( BOUNDS( I, CUR.storeSize ) ) \ - { \ - if ( CUR.pedantic_hinting ) \ - { \ - ARRAY_BOUND_ERROR; \ - } \ - else \ - args[0] = 0; \ - } \ - else \ - args[0] = CUR.storage[I]; \ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + +#define DO_RS \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDSL( I, CUR.storeSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + ARRAY_BOUND_ERROR; \ + else \ + args[0] = 0; \ + } \ + else \ + { \ + /* subpixel hinting - avoid Typeman Dstroke and */ \ + /* IStroke and Vacuform rounds */ \ + \ + if ( SUBPIXEL_HINTING && \ + CUR.ignore_x_mode && \ + ( ( I == 24 && \ + ( CUR.face->sph_found_func_flags & \ + ( SPH_FDEF_SPACING_1 | \ + SPH_FDEF_SPACING_2 ) ) ) || \ + ( I == 22 && \ + ( CUR.sph_in_func_flags & \ + SPH_FDEF_TYPEMAN_STROKES ) ) || \ + ( I == 8 && \ + ( CUR.face->sph_found_func_flags & \ + SPH_FDEF_VACUFORM_ROUND_1 ) && \ + CUR.iup_called ) ) ) \ + args[0] = 0; \ + else \ + args[0] = CUR.storage[I]; \ + } \ } +#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + +#define DO_RS \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDSL( I, CUR.storeSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + else \ + args[0] = 0; \ + } \ + else \ + args[0] = CUR.storage[I]; \ + } -#define DO_WS \ - { \ - FT_ULong I = (FT_ULong)args[0]; \ - \ - \ - if ( BOUNDS( I, CUR.storeSize ) ) \ - { \ - if ( CUR.pedantic_hinting ) \ - { \ - ARRAY_BOUND_ERROR; \ - } \ - } \ - else \ - CUR.storage[I] = args[1]; \ +#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + +#define DO_WS \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDSL( I, CUR.storeSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + } \ + else \ + CUR.storage[I] = args[1]; \ } @@ -3034,7 +3319,7 @@ FT_ULong I = (FT_ULong)args[0]; \ \ \ - if ( BOUNDS( I, CUR.cvtSize ) ) \ + if ( BOUNDSL( I, CUR.cvtSize ) ) \ { \ if ( CUR.pedantic_hinting ) \ { \ @@ -3053,7 +3338,7 @@ FT_ULong I = (FT_ULong)args[0]; \ \ \ - if ( BOUNDS( I, CUR.cvtSize ) ) \ + if ( BOUNDSL( I, CUR.cvtSize ) ) \ { \ if ( CUR.pedantic_hinting ) \ { \ @@ -3070,7 +3355,7 @@ FT_ULong I = (FT_ULong)args[0]; \ \ \ - if ( BOUNDS( I, CUR.cvtSize ) ) \ + if ( BOUNDSL( I, CUR.cvtSize ) ) \ { \ if ( CUR.pedantic_hinting ) \ { \ @@ -3078,12 +3363,12 @@ } \ } \ else \ - CUR.cvt[I] = TT_MULFIX( args[1], CUR.tt_metrics.scale ); \ + CUR.cvt[I] = FT_MulFix( args[1], CUR.tt_metrics.scale ); \ } -#define DO_DEBUG \ - CUR.error = TT_Err_Debug_OpCode; +#define DO_DEBUG \ + CUR.error = FT_THROW( Debug_OpCode ); #define DO_ROUND \ @@ -3111,10 +3396,10 @@ #undef ARRAY_BOUND_ERROR -#define ARRAY_BOUND_ERROR \ - { \ - CUR.error = TT_Err_Invalid_Reference; \ - return; \ +#define ARRAY_BOUND_ERROR \ + { \ + CUR.error = FT_THROW( Invalid_Reference ); \ + return; \ } @@ -4092,17 +4377,19 @@ if ( L <= 0 || L > CUR.args ) { - CUR.error = TT_Err_Invalid_Reference; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Invalid_Reference ); } + else + { + K = CUR.stack[CUR.args - L]; - K = CUR.stack[CUR.args - L]; - - FT_ARRAY_MOVE( &CUR.stack[CUR.args - L ], - &CUR.stack[CUR.args - L + 1], - ( L - 1 ) ); + FT_ARRAY_MOVE( &CUR.stack[CUR.args - L ], + &CUR.stack[CUR.args - L + 1], + ( L - 1 ) ); - CUR.stack[CUR.args - 1] = K; + CUR.stack[CUR.args - 1] = K; + } } @@ -4151,7 +4438,7 @@ CUR.length = opcode_length[CUR.opcode]; if ( CUR.length < 0 ) { - if ( CUR.IP + 1 > CUR.codeSize ) + if ( CUR.IP + 1 >= CUR.codeSize ) goto Fail_Overflow; CUR.length = 2 - CUR.length * CUR.code[CUR.IP + 1]; } @@ -4161,7 +4448,7 @@ } Fail_Overflow: - CUR.error = TT_Err_Code_Overflow; + CUR.error = FT_THROW( Code_Overflow ); return FAILURE; } @@ -4266,6 +4553,106 @@ TT_DefRecord* rec; TT_DefRecord* limit; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* arguments to opcodes are skipped by `SKIP_Code' */ + FT_Byte opcode_pattern[9][12] = { + /* #0 inline delta function 1 */ + { + 0x4B, /* PPEM */ + 0x53, /* GTEQ */ + 0x23, /* SWAP */ + 0x4B, /* PPEM */ + 0x51, /* LTEQ */ + 0x5A, /* AND */ + 0x58, /* IF */ + 0x38, /* SHPIX */ + 0x1B, /* ELSE */ + 0x21, /* POP */ + 0x21, /* POP */ + 0x59 /* EIF */ + }, + /* #1 inline delta function 2 */ + { + 0x4B, /* PPEM */ + 0x54, /* EQ */ + 0x58, /* IF */ + 0x38, /* SHPIX */ + 0x1B, /* ELSE */ + 0x21, /* POP */ + 0x21, /* POP */ + 0x59 /* EIF */ + }, + /* #2 diagonal stroke function */ + { + 0x20, /* DUP */ + 0x20, /* DUP */ + 0xB0, /* PUSHB_1 */ + /* 1 */ + 0x60, /* ADD */ + 0x46, /* GC_cur */ + 0xB0, /* PUSHB_1 */ + /* 64 */ + 0x23, /* SWAP */ + 0x42 /* WS */ + }, + /* #3 VacuFormRound function */ + { + 0x45, /* RCVT */ + 0x23, /* SWAP */ + 0x46, /* GC_cur */ + 0x60, /* ADD */ + 0x20, /* DUP */ + 0xB0 /* PUSHB_1 */ + /* 38 */ + }, + /* #4 TTFautohint bytecode (old) */ + { + 0x20, /* DUP */ + 0x64, /* ABS */ + 0xB0, /* PUSHB_1 */ + /* 32 */ + 0x60, /* ADD */ + 0x66, /* FLOOR */ + 0x23, /* SWAP */ + 0xB0 /* PUSHB_1 */ + }, + /* #5 spacing function 1 */ + { + 0x01, /* SVTCA_x */ + 0xB0, /* PUSHB_1 */ + /* 24 */ + 0x43, /* RS */ + 0x58 /* IF */ + }, + /* #6 spacing function 2 */ + { + 0x01, /* SVTCA_x */ + 0x18, /* RTG */ + 0xB0, /* PUSHB_1 */ + /* 24 */ + 0x43, /* RS */ + 0x58 /* IF */ + }, + /* #7 TypeMan Talk DiagEndCtrl function */ + { + 0x01, /* SVTCA_x */ + 0x20, /* DUP */ + 0xB0, /* PUSHB_1 */ + /* 3 */ + 0x25, /* CINDEX */ + }, + /* #8 TypeMan Talk Align */ + { + 0x06, /* SPVTL */ + 0x7D, /* RDTG */ + }, + }; + FT_UShort opcode_patterns = 9; + FT_UShort opcode_pointer[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FT_UShort opcode_size[9] = { 12, 8, 8, 6, 7, 4, 5, 4, 2 }; + FT_UShort i; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + /* some font programs are broken enough to redefine functions! */ /* We will then parse the current table. */ @@ -4285,7 +4672,7 @@ /* check that there is enough room for new functions */ if ( CUR.numFDefs >= CUR.maxFDefs ) { - CUR.error = TT_Err_Too_Many_Function_Defs; + CUR.error = FT_THROW( Too_Many_Function_Defs ); return; } CUR.numFDefs++; @@ -4295,31 +4682,153 @@ /* func # must be within unsigned 16-bit integer */ if ( n > 0xFFFFU ) { - CUR.error = TT_Err_Too_Many_Function_Defs; + CUR.error = FT_THROW( Too_Many_Function_Defs ); return; } - rec->range = CUR.curRange; - rec->opc = (FT_UInt16)n; - rec->start = CUR.IP + 1; - rec->active = TRUE; + rec->range = CUR.curRange; + rec->opc = (FT_UInt16)n; + rec->start = CUR.IP + 1; + rec->active = TRUE; + rec->inline_delta = FALSE; + rec->sph_fdef_flags = 0x0000; if ( n > CUR.maxFunc ) CUR.maxFunc = (FT_UInt16)n; - /* Now skip the whole function definition. */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* We don't know for sure these are typeman functions, */ + /* however they are only active when RS 22 is called */ + if ( n >= 64 && n <= 66 ) + rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_STROKES; +#endif + + /* Now skip the whole function definition. */ /* We don't allow nested IDEFS & FDEFs. */ while ( SKIP_Code() == SUCCESS ) { + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( SUBPIXEL_HINTING ) + { + for ( i = 0; i < opcode_patterns; i++ ) + { + if ( opcode_pointer[i] < opcode_size[i] && + CUR.opcode == opcode_pattern[i][opcode_pointer[i]] ) + { + opcode_pointer[i] += 1; + + if ( opcode_pointer[i] == opcode_size[i] ) + { + FT_TRACE7(( "sph: Function %d, opcode ptrn: %d, %s %s\n", + i, n, + CUR.face->root.family_name, + CUR.face->root.style_name )); + + switch ( i ) + { + case 0: + rec->sph_fdef_flags |= SPH_FDEF_INLINE_DELTA_1; + CUR.face->sph_found_func_flags |= SPH_FDEF_INLINE_DELTA_1; + break; + + case 1: + rec->sph_fdef_flags |= SPH_FDEF_INLINE_DELTA_2; + CUR.face->sph_found_func_flags |= SPH_FDEF_INLINE_DELTA_2; + break; + + case 2: + switch ( n ) + { + /* needs to be implemented still */ + case 58: + rec->sph_fdef_flags |= SPH_FDEF_DIAGONAL_STROKE; + CUR.face->sph_found_func_flags |= SPH_FDEF_DIAGONAL_STROKE; + } + break; + + case 3: + switch ( n ) + { + case 0: + rec->sph_fdef_flags |= SPH_FDEF_VACUFORM_ROUND_1; + CUR.face->sph_found_func_flags |= SPH_FDEF_VACUFORM_ROUND_1; + } + break; + + case 4: + /* probably not necessary to detect anymore */ + rec->sph_fdef_flags |= SPH_FDEF_TTFAUTOHINT_1; + CUR.face->sph_found_func_flags |= SPH_FDEF_TTFAUTOHINT_1; + break; + + case 5: + switch ( n ) + { + case 0: + case 1: + case 2: + case 4: + case 7: + case 8: + rec->sph_fdef_flags |= SPH_FDEF_SPACING_1; + CUR.face->sph_found_func_flags |= SPH_FDEF_SPACING_1; + } + break; + + case 6: + switch ( n ) + { + case 0: + case 1: + case 2: + case 4: + case 7: + case 8: + rec->sph_fdef_flags |= SPH_FDEF_SPACING_2; + CUR.face->sph_found_func_flags |= SPH_FDEF_SPACING_2; + } + break; + + case 7: + rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; + CUR.face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; + break; + + case 8: +#if 0 + rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; + CUR.face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; +#endif + break; + } + opcode_pointer[i] = 0; + } + } + + else + opcode_pointer[i] = 0; + } + + /* Set sph_compatibility_mode only when deltas are detected */ + CUR.face->sph_compatibility_mode = + ( ( CUR.face->sph_found_func_flags & SPH_FDEF_INLINE_DELTA_1 ) | + ( CUR.face->sph_found_func_flags & SPH_FDEF_INLINE_DELTA_2 ) ); + } + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + switch ( CUR.opcode ) { case 0x89: /* IDEF */ case 0x2C: /* FDEF */ - CUR.error = TT_Err_Nested_DEFS; + CUR.error = FT_THROW( Nested_DEFS ); return; case 0x2D: /* ENDF */ + rec->end = CUR.IP; return; } } @@ -4340,9 +4849,13 @@ FT_UNUSED_ARG; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + CUR.sph_in_func_flags = 0x0000; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + if ( CUR.callTop <= 0 ) /* We encountered an ENDF without a call */ { - CUR.error = TT_Err_ENDF_In_Exec_Stream; + CUR.error = FT_THROW( ENDF_In_Exec_Stream ); return; } @@ -4357,7 +4870,7 @@ if ( pRec->Cur_Count > 0 ) { CUR.callTop++; - CUR.IP = pRec->Cur_Restart; + CUR.IP = pRec->Def->start; } else /* Loop through the current function */ @@ -4391,7 +4904,7 @@ /* first of all, check the index */ F = args[0]; - if ( BOUNDS( F, CUR.maxFunc + 1 ) ) + if ( BOUNDSL( F, CUR.maxFunc + 1 ) ) goto Fail; /* Except for some old Apple fonts, all functions in a TrueType */ @@ -4424,10 +4937,21 @@ if ( !def->active ) goto Fail; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + ( ( CUR.iup_called && + ( CUR.sph_tweak_flags & SPH_TWEAK_NO_CALL_AFTER_IUP ) ) || + ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 ) ) ) + goto Fail; + else + CUR.sph_in_func_flags = def->sph_fdef_flags; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + /* check the call stack */ if ( CUR.callTop >= CUR.callSize ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4436,7 +4960,7 @@ pCrec->Caller_Range = CUR.curRange; pCrec->Caller_IP = CUR.IP + 1; pCrec->Cur_Count = 1; - pCrec->Cur_Restart = def->start; + pCrec->Def = def; CUR.callTop++; @@ -4444,10 +4968,11 @@ def->start ); CUR.step_ins = FALSE; + return; Fail: - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); } @@ -4467,7 +4992,7 @@ /* first of all, check the index */ F = args[1]; - if ( BOUNDS( F, CUR.maxFunc + 1 ) ) + if ( BOUNDSL( F, CUR.maxFunc + 1 ) ) goto Fail; /* Except for some old Apple fonts, all functions in a TrueType */ @@ -4500,10 +5025,19 @@ if ( !def->active ) goto Fail; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 ) ) + goto Fail; + else + CUR.sph_in_func_flags = def->sph_fdef_flags; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + /* check stack */ if ( CUR.callTop >= CUR.callSize ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4514,7 +5048,7 @@ pCrec->Caller_Range = CUR.curRange; pCrec->Caller_IP = CUR.IP + 1; pCrec->Cur_Count = (FT_Int)args[0]; - pCrec->Cur_Restart = def->start; + pCrec->Def = def; CUR.callTop++; @@ -4522,10 +5056,11 @@ CUR.step_ins = FALSE; } + return; Fail: - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); } @@ -4556,7 +5091,7 @@ /* check that there is enough room for a new instruction */ if ( CUR.numIDefs >= CUR.maxIDefs ) { - CUR.error = TT_Err_Too_Many_Instruction_Defs; + CUR.error = FT_THROW( Too_Many_Instruction_Defs ); return; } CUR.numIDefs++; @@ -4565,12 +5100,12 @@ /* opcode must be unsigned 8-bit integer */ if ( 0 > args[0] || args[0] > 0x00FF ) { - CUR.error = TT_Err_Too_Many_Instruction_Defs; + CUR.error = FT_THROW( Too_Many_Instruction_Defs ); return; } def->opc = (FT_Byte)args[0]; - def->start = CUR.IP+1; + def->start = CUR.IP + 1; def->range = CUR.curRange; def->active = TRUE; @@ -4586,7 +5121,7 @@ { case 0x89: /* IDEF */ case 0x2C: /* FDEF */ - CUR.error = TT_Err_Nested_DEFS; + CUR.error = FT_THROW( Nested_DEFS ); return; case 0x2D: /* ENDF */ return; @@ -4620,7 +5155,7 @@ if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4647,7 +5182,7 @@ if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4677,7 +5212,7 @@ if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4702,7 +5237,7 @@ if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } @@ -4730,8 +5265,8 @@ /* Opcode range: 0x46-0x47 */ /* Stack: uint32 --> f26.6 */ /* */ - /* BULLSHIT: Measures from the original glyph must be taken along the */ - /* dual projection vector! */ + /* XXX: UNDOCUMENTED: Measures from the original glyph must be taken */ + /* along the dual projection vector! */ /* */ static void Ins_GC( INS_ARG ) @@ -4742,15 +5277,11 @@ L = (FT_ULong)args[0]; - if ( BOUNDS( L, CUR.zp2.n_points ) ) + if ( BOUNDSL( L, CUR.zp2.n_points ) ) { if ( CUR.pedantic_hinting ) - { - CUR.error = TT_Err_Invalid_Reference; - return; - } - else - R = 0; + CUR.error = FT_THROW( Invalid_Reference ); + R = 0; } else { @@ -4786,7 +5317,7 @@ if ( BOUNDS( L, CUR.zp2.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -4794,8 +5325,8 @@ CUR_Func_move( &CUR.zp2, L, args[1] - K ); - /* not part of the specs, but here for safety */ - + /* UNDOCUMENTED! The MS rasterizer does that with */ + /* twilight points (confirmed by Greg Hitchcock) */ if ( CUR.GS.gep2 == 0 ) CUR.zp2.org[L] = CUR.zp2.cur[L]; } @@ -4807,14 +5338,14 @@ /* Opcode range: 0x49-0x4A */ /* Stack: uint32 uint32 --> f26.6 */ /* */ - /* BULLSHIT: Measure taken in the original glyph must be along the dual */ - /* projection vector. */ + /* XXX: UNDOCUMENTED: Measure taken in the original glyph must be along */ + /* the dual projection vector. */ /* */ - /* Second BULLSHIT: Flag attributes are inverted! */ - /* 0 => measure distance in original outline */ - /* 1 => measure distance in grid-fitted outline */ + /* XXX: UNDOCUMENTED: Flag attributes are inverted! */ + /* 0 => measure distance in original outline */ + /* 1 => measure distance in grid-fitted outline */ /* */ - /* Third one: `zp0 - zp1', and not `zp2 - zp1! */ + /* XXX: UNDOCUMENTED: `zp0 - zp1', and not `zp2 - zp1! */ /* */ static void Ins_MD( INS_ARG ) @@ -4826,14 +5357,11 @@ K = (FT_UShort)args[1]; L = (FT_UShort)args[0]; - if( BOUNDS( L, CUR.zp0.n_points ) || - BOUNDS( K, CUR.zp1.n_points ) ) + if ( BOUNDS( L, CUR.zp0.n_points ) || + BOUNDS( K, CUR.zp1.n_points ) ) { if ( CUR.pedantic_hinting ) - { - CUR.error = TT_Err_Invalid_Reference; - return; - } + CUR.error = FT_THROW( Invalid_Reference ); D = 0; } else @@ -4842,29 +5370,49 @@ D = CUR_Func_project( CUR.zp0.cur + L, CUR.zp1.cur + K ); else { - FT_Vector* vec1 = CUR.zp0.orus + L; - FT_Vector* vec2 = CUR.zp1.orus + K; + /* XXX: UNDOCUMENTED: twilight zone special case */ - - if ( CUR.metrics.x_scale == CUR.metrics.y_scale ) + if ( CUR.GS.gep0 == 0 || CUR.GS.gep1 == 0 ) { - /* this should be faster */ + FT_Vector* vec1 = CUR.zp0.org + L; + FT_Vector* vec2 = CUR.zp1.org + K; + + D = CUR_Func_dualproj( vec1, vec2 ); - D = TT_MULFIX( D, CUR.metrics.x_scale ); } else { - FT_Vector vec; + FT_Vector* vec1 = CUR.zp0.orus + L; + FT_Vector* vec2 = CUR.zp1.orus + K; + + + if ( CUR.metrics.x_scale == CUR.metrics.y_scale ) + { + /* this should be faster */ + D = CUR_Func_dualproj( vec1, vec2 ); + D = FT_MulFix( D, CUR.metrics.x_scale ); + } + else + { + FT_Vector vec; - vec.x = TT_MULFIX( vec1->x - vec2->x, CUR.metrics.x_scale ); - vec.y = TT_MULFIX( vec1->y - vec2->y, CUR.metrics.y_scale ); + vec.x = FT_MulFix( vec1->x - vec2->x, CUR.metrics.x_scale ); + vec.y = FT_MulFix( vec1->y - vec2->y, CUR.metrics.y_scale ); - D = CUR_fast_dualproj( &vec ); + D = CUR_fast_dualproj( &vec ); + } } } } +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* Disable Type 2 Vacuform Rounds - e.g. Arial Narrow */ + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && FT_ABS( D ) == 64 ) + D += 1; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + args[0] = D; } @@ -4879,7 +5427,8 @@ Ins_SDPVTL( INS_ARG ) { FT_Long A, B, C; - FT_UShort p1, p2; /* was FT_Int in pas type ERROR */ + FT_UShort p1, p2; /* was FT_Int in pas type ERROR */ + FT_Int aOpc = CUR.opcode; p1 = (FT_UShort)args[1]; @@ -4889,7 +5438,7 @@ BOUNDS( p1, CUR.zp2.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -4900,9 +5449,20 @@ A = v1->x - v2->x; B = v1->y - v2->y; + + /* If v1 == v2, SDPVTL behaves the same as */ + /* SVTCA[X], respectively. */ + /* */ + /* Confirmed by Greg Hitchcock. */ + + if ( A == 0 && B == 0 ) + { + A = 0x4000; + aOpc = 0; + } } - if ( ( CUR.opcode & 1 ) != 0 ) + if ( ( aOpc & 1 ) != 0 ) { C = B; /* counter clockwise rotation */ B = A; @@ -4918,9 +5478,15 @@ A = v1->x - v2->x; B = v1->y - v2->y; + + if ( A == 0 && B == 0 ) + { + A = 0x4000; + aOpc = 0; + } } - if ( ( CUR.opcode & 1 ) != 0 ) + if ( ( aOpc & 1 ) != 0 ) { C = B; /* counter clockwise rotation */ B = A; @@ -4956,7 +5522,7 @@ default: if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -4985,7 +5551,7 @@ default: if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5014,7 +5580,7 @@ default: if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5043,7 +5609,7 @@ default: if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5059,7 +5625,7 @@ /*************************************************************************/ /* */ /* INSTCTRL[]: INSTruction ConTRoL */ - /* Opcode range: 0x8e */ + /* Opcode range: 0x8E */ /* Stack: int32 int32 --> */ /* */ static void @@ -5074,7 +5640,7 @@ if ( K < 1 || K > 2 ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5171,8 +5737,9 @@ if ( CUR.top < CUR.GS.loop ) { - CUR.error = TT_Err_Too_Few_Arguments; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Too_Few_Arguments ); + goto Fail; } while ( CUR.GS.loop > 0 ) @@ -5185,7 +5752,7 @@ { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } } @@ -5195,6 +5762,7 @@ CUR.GS.loop--; } + Fail: CUR.GS.loop = 1; CUR.new_top = CUR.args; } @@ -5219,7 +5787,7 @@ BOUNDS( L, CUR.pts.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5247,7 +5815,7 @@ BOUNDS( L, CUR.pts.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5281,7 +5849,7 @@ if ( BOUNDS( p, zp.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); *refp = 0; return FAILURE; } @@ -5308,12 +5876,8 @@ else #endif { - *x = TT_MULDIV( d, - (FT_Long)CUR.GS.freeVector.x * 0x10000L, - CUR.F_dot_P ); - *y = TT_MULDIV( d, - (FT_Long)CUR.GS.freeVector.y * 0x10000L, - CUR.F_dot_P ); + *x = FT_MulDiv( d, (FT_Long)CUR.GS.freeVector.x, CUR.F_dot_P ); + *y = FT_MulDiv( d, (FT_Long)CUR.GS.freeVector.y, CUR.F_dot_P ); } return SUCCESS; @@ -5382,8 +5946,9 @@ if ( CUR.top < CUR.GS.loop ) { - CUR.error = TT_Err_Invalid_Reference; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) ) @@ -5398,17 +5963,24 @@ { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } } else - /* XXX: UNDOCUMENTED! SHP touches the points */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* doesn't follow Cleartype spec but produces better result */ + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode ) + MOVE_Zp2_Point( point, 0, dy, TRUE ); + else +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ MOVE_Zp2_Point( point, dx, dy, TRUE ); CUR.GS.loop--; } + Fail: CUR.GS.loop = 1; CUR.new_top = CUR.args; } @@ -5420,24 +5992,28 @@ /* Opcode range: 0x34-35 */ /* Stack: uint32 --> */ /* */ + /* UNDOCUMENTED: According to Greg Hitchcock, there is one (virtual) */ + /* contour in the twilight zone, namely contour number */ + /* zero which includes all points of it. */ + /* */ static void Ins_SHC( INS_ARG ) { - TT_GlyphZoneRec zp; - FT_UShort refp; - FT_F26Dot6 dx, - dy; + TT_GlyphZoneRec zp; + FT_UShort refp; + FT_F26Dot6 dx, dy; - FT_Short contour; - FT_UShort first_point, last_point, i; + FT_Short contour, bounds; + FT_UShort start, limit, i; contour = (FT_UShort)args[0]; + bounds = ( CUR.GS.gep2 == 0 ) ? 1 : CUR.zp2.n_contours; - if ( BOUNDS( contour, CUR.pts.n_contours ) ) + if ( BOUNDS( contour, bounds ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -5445,26 +6021,19 @@ return; if ( contour == 0 ) - first_point = 0; + start = 0; else - first_point = (FT_UShort)( CUR.pts.contours[contour - 1] + 1 - - CUR.pts.first_point ); + start = (FT_UShort)( CUR.zp2.contours[contour - 1] + 1 - + CUR.zp2.first_point ); - last_point = (FT_UShort)( CUR.pts.contours[contour] - - CUR.pts.first_point ); - - /* XXX: this is probably wrong... at least it prevents memory */ - /* corruption when zp2 is the twilight zone */ - if ( BOUNDS( last_point, CUR.zp2.n_points ) ) - { - if ( CUR.zp2.n_points > 0 ) - last_point = (FT_UShort)(CUR.zp2.n_points - 1); - else - last_point = 0; - } + /* we use the number of points if in the twilight zone */ + if ( CUR.GS.gep2 == 0 ) + limit = CUR.zp2.n_points; + else + limit = (FT_UShort)( CUR.zp2.contours[contour] - + CUR.zp2.first_point + 1 ); - /* XXX: UNDOCUMENTED! SHC touches the points */ - for ( i = first_point; i <= last_point; i++ ) + for ( i = start; i < limit; i++ ) { if ( zp.cur != CUR.zp2.cur || refp != i ) MOVE_Zp2_Point( i, dx, dy, TRUE ); @@ -5481,37 +6050,37 @@ static void Ins_SHZ( INS_ARG ) { - TT_GlyphZoneRec zp; - FT_UShort refp; - FT_F26Dot6 dx, - dy; + TT_GlyphZoneRec zp; + FT_UShort refp; + FT_F26Dot6 dx, + dy; - FT_UShort last_point, i; + FT_UShort limit, i; if ( BOUNDS( args[0], 2 ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) ) return; - /* XXX: UNDOCUMENTED! SHZ doesn't move the phantom points. */ - /* Twilight zone has no contours, so use `n_points'. */ - /* Normal zone's `n_points' includes phantoms, so must */ - /* use end of last contour. */ - if ( CUR.GS.gep2 == 0 && CUR.zp2.n_points > 0 ) - last_point = (FT_UShort)( CUR.zp2.n_points - 1 ); + /* XXX: UNDOCUMENTED! SHZ doesn't move the phantom points. */ + /* Twilight zone has no real contours, so use `n_points'. */ + /* Normal zone's `n_points' includes phantoms, so must */ + /* use end of last contour. */ + if ( CUR.GS.gep2 == 0 ) + limit = (FT_UShort)CUR.zp2.n_points; else if ( CUR.GS.gep2 == 1 && CUR.zp2.n_contours > 0 ) - last_point = (FT_UShort)( CUR.zp2.contours[CUR.zp2.n_contours - 1] ); + limit = (FT_UShort)( CUR.zp2.contours[CUR.zp2.n_contours - 1] + 1 ); else - last_point = 0; + limit = 0; /* XXX: UNDOCUMENTED! SHZ doesn't touch the points */ - for ( i = 0; i <= last_point; i++ ) + for ( i = 0; i < limit; i++ ) { if ( zp.cur != CUR.zp2.cur || refp != i ) MOVE_Zp2_Point( i, dx, dy, FALSE ); @@ -5530,12 +6099,16 @@ { FT_F26Dot6 dx, dy; FT_UShort point; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + FT_Int B1, B2; +#endif if ( CUR.top < CUR.GS.loop + 1 ) { - CUR.error = TT_Err_Invalid_Reference; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING @@ -5543,13 +6116,13 @@ { if ( CUR.GS.both_x_axis ) { - dx = TT_MulFix14( (FT_UInt32)args[0], 0x4000 ); + dx = (FT_UInt32)args[0]; dy = 0; } else { dx = 0; - dy = TT_MulFix14( (FT_UInt32)args[0], 0x4000 ); + dy = (FT_UInt32)args[0]; } } else @@ -5569,16 +6142,99 @@ { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } } else +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + { + /* If not using ignore_x_mode rendering, allow ZP2 move. */ + /* If inline deltas aren't allowed, skip ZP2 move. */ + /* If using ignore_x_mode rendering, allow ZP2 point move if: */ + /* - freedom vector is y and sph_compatibility_mode is off */ + /* - the glyph is composite and the move is in the Y direction */ + /* - the glyph is specifically set to allow SHPIX moves */ + /* - the move is on a previously Y-touched point */ + + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode ) + { + /* save point for later comparison */ + if ( CUR.GS.freeVector.y != 0 ) + B1 = CUR.zp2.cur[point].y; + else + B1 = CUR.zp2.cur[point].x; + + if ( !CUR.face->sph_compatibility_mode && + CUR.GS.freeVector.y != 0 ) + { + MOVE_Zp2_Point( point, dx, dy, TRUE ); + + /* save new point */ + if ( CUR.GS.freeVector.y != 0 ) + { + B2 = CUR.zp2.cur[point].y; + + /* reverse any disallowed moves */ + if ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) && + ( B1 & 63 ) != 0 && + ( B2 & 63 ) != 0 && + B1 != B2 ) + MOVE_Zp2_Point( point, -dx, -dy, TRUE ); + } + } + else if ( CUR.face->sph_compatibility_mode ) + { + if ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) + { + dx = FT_PIX_ROUND( B1 + dx ) - B1; + dy = FT_PIX_ROUND( B1 + dy ) - B1; + } + + /* skip post-iup deltas */ + if ( CUR.iup_called && + ( ( CUR.sph_in_func_flags & SPH_FDEF_INLINE_DELTA_1 ) || + ( CUR.sph_in_func_flags & SPH_FDEF_INLINE_DELTA_2 ) ) ) + goto Skip; + + if ( !( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) && + ( ( CUR.is_composite && CUR.GS.freeVector.y != 0 ) || + ( CUR.zp2.tags[point] & FT_CURVE_TAG_TOUCH_Y ) || + ( CUR.sph_tweak_flags & SPH_TWEAK_DO_SHPIX ) ) ) + MOVE_Zp2_Point( point, 0, dy, TRUE ); + + /* save new point */ + if ( CUR.GS.freeVector.y != 0 ) + { + B2 = CUR.zp2.cur[point].y; + + /* reverse any disallowed moves */ + if ( ( B1 & 63 ) == 0 && + ( B2 & 63 ) != 0 && + B1 != B2 ) + MOVE_Zp2_Point( point, 0, -dy, TRUE ); + } + } + else if ( CUR.sph_in_func_flags & SPH_FDEF_TYPEMAN_DIAGENDCTRL ) + MOVE_Zp2_Point( point, dx, dy, TRUE ); + } + else + MOVE_Zp2_Point( point, dx, dy, TRUE ); + } + + Skip: + +#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + MOVE_Zp2_Point( point, dx, dy, TRUE ); +#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + CUR.GS.loop--; } + Fail: CUR.GS.loop = 1; CUR.new_top = CUR.args; } @@ -5596,6 +6252,21 @@ FT_UShort point; FT_F26Dot6 distance; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + FT_F26Dot6 control_value_cutin = 0; /* pacify compiler */ + + + if ( SUBPIXEL_HINTING ) + { + control_value_cutin = CUR.GS.control_value_cutin; + + if ( CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 && + !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) + control_value_cutin = 0; + } + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ point = (FT_UShort)args[0]; @@ -5603,13 +6274,13 @@ BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } - /* XXX: UNDOCUMENTED! behaviour */ - if ( CUR.GS.gep1 == 0 ) /* if the point that is to be moved */ - /* is in twilight zone */ + /* UNDOCUMENTED! The MS rasterizer does that with */ + /* twilight points (confirmed by Greg Hitchcock) */ + if ( CUR.GS.gep1 == 0 ) { CUR.zp1.org[point] = CUR.zp0.org[CUR.GS.rp0]; CUR_Func_move_orig( &CUR.zp1, point, args[1] ); @@ -5619,6 +6290,15 @@ distance = CUR_Func_project( CUR.zp1.cur + point, CUR.zp0.cur + CUR.GS.rp0 ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* subpixel hinting - make MSIRP respect CVT cut-in; */ + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 && + FT_ABS( distance - args[1] ) >= control_value_cutin ) + distance = args[1]; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + CUR_Func_move( &CUR.zp1, point, args[1] - distance ); CUR.GS.rp1 = CUR.GS.rp0; @@ -5639,8 +6319,8 @@ Ins_MDAP( INS_ARG ) { FT_UShort point; - FT_F26Dot6 cur_dist, - distance; + FT_F26Dot6 cur_dist; + FT_F26Dot6 distance; point = (FT_UShort)args[0]; @@ -5648,17 +6328,25 @@ if ( BOUNDS( point, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } - /* XXX: Is there some undocumented feature while in the */ - /* twilight zone? ? */ if ( ( CUR.opcode & 1 ) != 0 ) { cur_dist = CUR_fast_project( &CUR.zp0.cur[point] ); - distance = CUR_Func_round( cur_dist, - CUR.tt_metrics.compensations[0] ) - cur_dist; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 ) + distance = ROUND_None( + cur_dist, + CUR.tt_metrics.compensations[0] ) - cur_dist; + else +#endif + distance = CUR_Func_round( + cur_dist, + CUR.tt_metrics.compensations[0] ) - cur_dist; } else distance = 0; @@ -5681,64 +6369,100 @@ { FT_ULong cvtEntry; FT_UShort point; - FT_F26Dot6 distance, - org_dist; + FT_F26Dot6 distance; + FT_F26Dot6 org_dist; + FT_F26Dot6 control_value_cutin; + + control_value_cutin = CUR.GS.control_value_cutin; + cvtEntry = (FT_ULong)args[1]; + point = (FT_UShort)args[0]; - cvtEntry = (FT_ULong)args[1]; - point = (FT_UShort)args[0]; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 && + CUR.GS.freeVector.y == 0 && + !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) + control_value_cutin = 0; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ - if ( BOUNDS( point, CUR.zp0.n_points ) || - BOUNDS( cvtEntry, CUR.cvtSize ) ) + if ( BOUNDS( point, CUR.zp0.n_points ) || + BOUNDSL( cvtEntry, CUR.cvtSize ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; - return; + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } - /* XXX: UNDOCUMENTED! */ - /* */ - /* The behaviour of an MIAP instruction is quite */ - /* different when used in the twilight zone. */ - /* */ - /* First, no control value cut-in test is performed */ - /* as it would fail anyway. Second, the original */ - /* point, i.e. (org_x,org_y) of zp0.point, is set */ - /* to the absolute, unrounded distance found in */ - /* the CVT. */ - /* */ - /* This is used in the CVT programs of the Microsoft */ - /* fonts Arial, Times, etc., in order to re-adjust */ - /* some key font heights. It allows the use of the */ - /* IP instruction in the twilight zone, which */ - /* otherwise would be `illegal' according to the */ - /* specification. */ - /* */ - /* We implement it with a special sequence for the */ - /* twilight zone. This is a bad hack, but it seems */ - /* to work. */ + /* UNDOCUMENTED! */ + /* */ + /* The behaviour of an MIAP instruction is quite different when used */ + /* in the twilight zone. */ + /* */ + /* First, no control value cut-in test is performed as it would fail */ + /* anyway. Second, the original point, i.e. (org_x,org_y) of */ + /* zp0.point, is set to the absolute, unrounded distance found in the */ + /* CVT. */ + /* */ + /* This is used in the CVT programs of the Microsoft fonts Arial, */ + /* Times, etc., in order to re-adjust some key font heights. It */ + /* allows the use of the IP instruction in the twilight zone, which */ + /* otherwise would be invalid according to the specification. */ + /* */ + /* We implement it with a special sequence for the twilight zone. */ + /* This is a bad hack, but it seems to work. */ + /* */ + /* Confirmed by Greg Hitchcock. */ distance = CUR_Func_read_cvt( cvtEntry ); if ( CUR.GS.gep0 == 0 ) /* If in twilight zone */ { - CUR.zp0.org[point].x = TT_MulFix14( (FT_UInt32)distance, CUR.GS.freeVector.x ); - CUR.zp0.org[point].y = TT_MulFix14( (FT_UInt32)distance, CUR.GS.freeVector.y ), +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* Only adjust if not in sph_compatibility_mode or ignore_x_mode. */ + /* Determined via experimentation and may be incorrect... */ + if ( !SUBPIXEL_HINTING || + ( !CUR.ignore_x_mode || + !CUR.face->sph_compatibility_mode ) ) +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + CUR.zp0.org[point].x = TT_MulFix14( (FT_UInt32)distance, + CUR.GS.freeVector.x ); + CUR.zp0.org[point].y = TT_MulFix14( (FT_UInt32)distance, + CUR.GS.freeVector.y ), CUR.zp0.cur[point] = CUR.zp0.org[point]; } +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + ( CUR.sph_tweak_flags & SPH_TWEAK_MIAP_HACK ) && + distance > 0 && + CUR.GS.freeVector.y != 0 ) + distance = 0; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ org_dist = CUR_fast_project( &CUR.zp0.cur[point] ); - if ( ( CUR.opcode & 1 ) != 0 ) /* rounding and control cutin flag */ + if ( ( CUR.opcode & 1 ) != 0 ) /* rounding and control cut-in flag */ { - if ( FT_ABS( distance - org_dist ) > CUR.GS.control_value_cutin ) + if ( FT_ABS( distance - org_dist ) > control_value_cutin ) distance = org_dist; - distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 ) + distance = ROUND_None( distance, + CUR.tt_metrics.compensations[0] ); + else +#endif + distance = CUR_Func_round( distance, + CUR.tt_metrics.compensations[0] ); } CUR_Func_move( &CUR.zp0, point, distance - org_dist ); + Fail: CUR.GS.rp0 = point; CUR.GS.rp1 = point; } @@ -5754,8 +6478,18 @@ Ins_MDRP( INS_ARG ) { FT_UShort point; - FT_F26Dot6 org_dist, distance; + FT_F26Dot6 org_dist, distance, minimum_distance; + + minimum_distance = CUR.GS.minimum_distance; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 && + !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) + minimum_distance = 0; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ point = (FT_UShort)args[0]; @@ -5763,8 +6497,8 @@ BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; - return; + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } /* XXX: Is there some undocumented feature while in the */ @@ -5790,15 +6524,15 @@ { /* this should be faster */ org_dist = CUR_Func_dualproj( vec1, vec2 ); - org_dist = TT_MULFIX( org_dist, CUR.metrics.x_scale ); + org_dist = FT_MulFix( org_dist, CUR.metrics.x_scale ); } else { FT_Vector vec; - vec.x = TT_MULFIX( vec1->x - vec2->x, CUR.metrics.x_scale ); - vec.y = TT_MULFIX( vec1->y - vec2->y, CUR.metrics.y_scale ); + vec.x = FT_MulFix( vec1->x - vec2->x, CUR.metrics.x_scale ); + vec.y = FT_MulFix( vec1->y - vec2->y, CUR.metrics.y_scale ); org_dist = CUR_fast_dualproj( &vec ); } @@ -5818,9 +6552,20 @@ /* round flag */ if ( ( CUR.opcode & 4 ) != 0 ) + { +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 ) + distance = ROUND_None( + org_dist, + CUR.tt_metrics.compensations[CUR.opcode & 3] ); + else +#endif distance = CUR_Func_round( org_dist, CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } else distance = ROUND_None( org_dist, @@ -5832,13 +6577,13 @@ { if ( org_dist >= 0 ) { - if ( distance < CUR.GS.minimum_distance ) - distance = CUR.GS.minimum_distance; + if ( distance < minimum_distance ) + distance = minimum_distance; } else { - if ( distance > -CUR.GS.minimum_distance ) - distance = -CUR.GS.minimum_distance; + if ( distance > -minimum_distance ) + distance = -minimum_distance; } } @@ -5849,6 +6594,7 @@ CUR_Func_move( &CUR.zp1, point, distance - org_dist ); + Fail: CUR.GS.rp1 = CUR.GS.rp0; CUR.GS.rp2 = point; @@ -5872,21 +6618,38 @@ FT_F26Dot6 cvt_dist, distance, cur_dist, - org_dist; - - - point = (FT_UShort)args[0]; - cvtEntry = (FT_ULong)( args[1] + 1 ); + org_dist, + control_value_cutin, + minimum_distance; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + FT_Int B1 = 0; /* pacify compiler */ + FT_Int B2 = 0; + FT_Bool reverse_move = FALSE; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + + minimum_distance = CUR.GS.minimum_distance; + control_value_cutin = CUR.GS.control_value_cutin; + point = (FT_UShort)args[0]; + cvtEntry = (FT_ULong)( args[1] + 1 ); + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.x != 0 && + !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) + control_value_cutin = minimum_distance = 0; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ /* XXX: UNDOCUMENTED! cvt[-1] = 0 always */ if ( BOUNDS( point, CUR.zp1.n_points ) || - BOUNDS( cvtEntry, CUR.cvtSize + 1 ) || + BOUNDSL( cvtEntry, CUR.cvtSize + 1 ) || BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; - return; + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } if ( !cvtEntry ) @@ -5905,19 +6668,17 @@ cvt_dist = -CUR.GS.single_width_value; } - /* XXX: UNDOCUMENTED! -- twilight zone */ - + /* UNDOCUMENTED! The MS rasterizer does that with */ + /* twilight points (confirmed by Greg Hitchcock) */ if ( CUR.GS.gep1 == 0 ) { CUR.zp1.org[point].x = CUR.zp0.org[CUR.GS.rp0].x + TT_MulFix14( (FT_UInt32)cvt_dist, CUR.GS.freeVector.x ); - CUR.zp1.org[point].y = CUR.zp0.org[CUR.GS.rp0].y + TT_MulFix14( (FT_UInt32)cvt_dist, CUR.GS.freeVector.y ); - - CUR.zp1.cur[point] = CUR.zp0.cur[point]; + CUR.zp1.cur[point] = CUR.zp1.org[point]; } org_dist = CUR_Func_dualproj( &CUR.zp1.org[point], @@ -5933,7 +6694,20 @@ cvt_dist = -cvt_dist; } - /* control value cutin and round */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.freeVector.y != 0 && + ( CUR.sph_tweak_flags & SPH_TWEAK_TIMES_NEW_ROMAN_HACK ) ) + { + if ( cur_dist < -64 ) + cvt_dist -= 16; + else if ( cur_dist > 64 && cur_dist < 84 ) + cvt_dist += 32; + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + /* control value cut-in and round */ if ( ( CUR.opcode & 4 ) != 0 ) { @@ -5941,17 +6715,45 @@ /* refer to the same zone. */ if ( CUR.GS.gep0 == CUR.GS.gep1 ) - if ( FT_ABS( cvt_dist - org_dist ) >= CUR.GS.control_value_cutin ) + { + /* XXX: According to Greg Hitchcock, the following wording is */ + /* the right one: */ + /* */ + /* When the absolute difference between the value in */ + /* the table [CVT] and the measurement directly from */ + /* the outline is _greater_ than the cut_in value, the */ + /* outline measurement is used. */ + /* */ + /* This is from `instgly.doc'. The description in */ + /* `ttinst2.doc', version 1.66, is thus incorrect since */ + /* it implies `>=' instead of `>'. */ + + if ( FT_ABS( cvt_dist - org_dist ) > control_value_cutin ) cvt_dist = org_dist; + } distance = CUR_Func_round( cvt_dist, CUR.tt_metrics.compensations[CUR.opcode & 3] ); } else + { + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /* do cvt cut-in always in MIRP for sph */ + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.GS.gep0 == CUR.GS.gep1 ) + { + if ( FT_ABS( cvt_dist - org_dist ) > control_value_cutin ) + cvt_dist = org_dist; + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + distance = ROUND_None( cvt_dist, CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } /* minimum distance test */ @@ -5959,24 +6761,71 @@ { if ( org_dist >= 0 ) { - if ( distance < CUR.GS.minimum_distance ) - distance = CUR.GS.minimum_distance; + if ( distance < minimum_distance ) + distance = minimum_distance; } else { - if ( distance > -CUR.GS.minimum_distance ) - distance = -CUR.GS.minimum_distance; + if ( distance > -minimum_distance ) + distance = -minimum_distance; } } +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING ) + { + B1 = CUR.zp1.cur[point].y; + + /* Round moves if necessary */ + if ( CUR.ignore_x_mode && + CUR.GS.freeVector.y != 0 && + ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) ) + distance = FT_PIX_ROUND( B1 + distance - cur_dist ) - B1 + cur_dist; + + if ( CUR.ignore_x_mode && + CUR.GS.freeVector.y != 0 && + ( CUR.opcode & 16 ) == 0 && + ( CUR.opcode & 8 ) == 0 && + ( CUR.sph_tweak_flags & SPH_TWEAK_COURIER_NEW_2_HACK ) ) + distance += 64; + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + CUR_Func_move( &CUR.zp1, point, distance - cur_dist ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING ) + { + B2 = CUR.zp1.cur[point].y; + + /* Reverse move if necessary */ + if ( CUR.ignore_x_mode ) + { + if ( CUR.face->sph_compatibility_mode && + CUR.GS.freeVector.y != 0 && + ( B1 & 63 ) == 0 && + ( B2 & 63 ) != 0 ) + reverse_move = TRUE; + + if ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) && + CUR.GS.freeVector.y != 0 && + ( B2 & 63 ) != 0 && + ( B1 & 63 ) != 0 ) + reverse_move = TRUE; + } + + if ( reverse_move ) + CUR_Func_move( &CUR.zp1, point, -( distance - cur_dist ) ); + } + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + Fail: CUR.GS.rp1 = CUR.GS.rp0; if ( ( CUR.opcode & 16 ) != 0 ) CUR.GS.rp0 = point; - /* XXX: UNDOCUMENTED! */ CUR.GS.rp2 = point; } @@ -5996,12 +6845,23 @@ FT_UNUSED_ARG; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.iup_called && + ( CUR.sph_tweak_flags & SPH_TWEAK_NO_ALIGNRP_AFTER_IUP ) ) + { + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + if ( CUR.top < CUR.GS.loop || BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; - return; + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } while ( CUR.GS.loop > 0 ) @@ -6014,7 +6874,7 @@ { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } } @@ -6029,6 +6889,7 @@ CUR.GS.loop--; } + Fail: CUR.GS.loop = 1; CUR.new_top = CUR.args; } @@ -6047,7 +6908,7 @@ a0, a1, b0, b1; - FT_F26Dot6 discriminant; + FT_F26Dot6 discriminant, dotproduct; FT_F26Dot6 dx, dy, dax, day, @@ -6072,10 +6933,12 @@ BOUNDS( point, CUR.zp2.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } + /* Cramer's rule */ + dbx = CUR.zp0.cur[b1].x - CUR.zp0.cur[b0].x; dby = CUR.zp0.cur[b1].y - CUR.zp0.cur[b0].y; @@ -6087,15 +6950,25 @@ CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_BOTH; - discriminant = TT_MULDIV( dax, -dby, 0x40 ) + - TT_MULDIV( day, dbx, 0x40 ); + discriminant = FT_MulDiv( dax, -dby, 0x40 ) + + FT_MulDiv( day, dbx, 0x40 ); + dotproduct = FT_MulDiv( dax, dbx, 0x40 ) + + FT_MulDiv( day, dby, 0x40 ); - if ( FT_ABS( discriminant ) >= 0x40 ) + /* The discriminant above is actually a cross product of vectors */ + /* da and db. Together with the dot product, they can be used as */ + /* surrogates for sine and cosine of the angle between the vectors. */ + /* Indeed, */ + /* dotproduct = |da||db|cos(angle) */ + /* discriminant = |da||db|sin(angle) . */ + /* We use these equations to reject grazing intersections by */ + /* thresholding abs(tan(angle)) at 1/19, corresponding to 3 degrees. */ + if ( 19 * FT_ABS( discriminant ) > FT_ABS( dotproduct ) ) { - val = TT_MULDIV( dx, -dby, 0x40 ) + TT_MULDIV( dy, dbx, 0x40 ); + val = FT_MulDiv( dx, -dby, 0x40 ) + FT_MulDiv( dy, dbx, 0x40 ); - R.x = TT_MULDIV( val, dax, discriminant ); - R.y = TT_MULDIV( val, day, discriminant ); + R.x = FT_MulDiv( val, dax, discriminant ); + R.y = FT_MulDiv( val, day, discriminant ); CUR.zp2.cur[point].x = CUR.zp1.cur[a0].x + R.x; CUR.zp2.cur[point].y = CUR.zp1.cur[a0].y + R.y; @@ -6132,11 +7005,11 @@ p1 = (FT_UShort)args[0]; p2 = (FT_UShort)args[1]; - if ( BOUNDS( args[0], CUR.zp1.n_points ) || - BOUNDS( args[1], CUR.zp0.n_points ) ) + if ( BOUNDS( p1, CUR.zp1.n_points ) || + BOUNDS( p2, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -6170,8 +7043,9 @@ if ( CUR.top < CUR.GS.loop ) { - CUR.error = TT_Err_Invalid_Reference; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } /* @@ -6184,8 +7058,8 @@ if ( BOUNDS( CUR.GS.rp1, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; - return; + CUR.error = FT_THROW( Invalid_Reference ); + goto Fail; } if ( twilight ) @@ -6210,9 +7084,21 @@ if ( twilight ) old_range = CUR_Func_dualproj( &CUR.zp1.org[CUR.GS.rp2], orus_base ); - else + else if ( CUR.metrics.x_scale == CUR.metrics.y_scale ) old_range = CUR_Func_dualproj( &CUR.zp1.orus[CUR.GS.rp2], orus_base ); + else + { + FT_Vector vec; + + + vec.x = FT_MulFix( CUR.zp1.orus[CUR.GS.rp2].x - orus_base->x, + CUR.metrics.x_scale ); + vec.y = FT_MulFix( CUR.zp1.orus[CUR.GS.rp2].y - orus_base->y, + CUR.metrics.y_scale ); + + old_range = CUR_fast_dualproj( &vec ); + } cur_range = CUR_Func_project ( &CUR.zp1.cur[CUR.GS.rp2], cur_base ); } @@ -6228,7 +7114,7 @@ { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } continue; @@ -6236,20 +7122,55 @@ if ( twilight ) org_dist = CUR_Func_dualproj( &CUR.zp2.org[point], orus_base ); - else + else if ( CUR.metrics.x_scale == CUR.metrics.y_scale ) org_dist = CUR_Func_dualproj( &CUR.zp2.orus[point], orus_base ); + else + { + FT_Vector vec; - cur_dist = CUR_Func_project ( &CUR.zp2.cur[point], cur_base ); + + vec.x = FT_MulFix( CUR.zp2.orus[point].x - orus_base->x, + CUR.metrics.x_scale ); + vec.y = FT_MulFix( CUR.zp2.orus[point].y - orus_base->y, + CUR.metrics.y_scale ); + + org_dist = CUR_fast_dualproj( &vec ); + } + + cur_dist = CUR_Func_project( &CUR.zp2.cur[point], cur_base ); if ( org_dist ) - new_dist = ( old_range != 0 ) - ? TT_MULDIV( org_dist, cur_range, old_range ) - : cur_dist; + { + if ( old_range ) + new_dist = FT_MulDiv( org_dist, cur_range, old_range ); + else + { + /* This is the same as what MS does for the invalid case: */ + /* */ + /* delta = (Original_Pt - Original_RP1) - */ + /* (Current_Pt - Current_RP1) ; */ + /* */ + /* In FreeType speak: */ + /* */ + /* delta = org_dist - cur_dist . */ + /* */ + /* We move `point' by `new_dist - cur_dist' after leaving */ + /* this block, thus we have */ + /* */ + /* new_dist - cur_dist = delta , */ + /* new_dist - cur_dist = org_dist - cur_dist , */ + /* new_dist = org_dist . */ + + new_dist = org_dist; + } + } else new_dist = 0; CUR_Func_move( &CUR.zp2, (FT_UShort)point, new_dist - cur_dist ); } + + Fail: CUR.GS.loop = 1; CUR.new_top = CUR.args; } @@ -6273,7 +7194,7 @@ if ( BOUNDS( point, CUR.zp0.n_points ) ) { if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } @@ -6402,12 +7323,12 @@ if ( !scale_valid ) { scale_valid = 1; - scale = TT_MULDIV( org2 + delta2 - ( org1 + delta1 ), - 0x10000L, orus2 - orus1 ); + scale = FT_DivFix( org2 + delta2 - ( org1 + delta1 ), + orus2 - orus1 ); } x = ( org1 + delta1 ) + - TT_MULFIX( worker->orus[i].x - orus1, scale ); + FT_MulFix( worker->orus[i].x - orus1, scale ); } worker->curs[i].x = x; } @@ -6462,13 +7383,23 @@ contour = 0; point = 0; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode ) + { + CUR.iup_called = TRUE; + if ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_IUP ) + return; + } +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + do { end_point = CUR.pts.contours[contour] - CUR.pts.first_point; first_point = point; - if ( CUR.pts.n_points <= end_point ) - end_point = CUR.pts.n_points; + if ( BOUNDS ( end_point, CUR.pts.n_points ) ) + end_point = CUR.pts.n_points - 1; while ( point <= end_point && ( CUR.pts.tags[point] & mask ) == 0 ) point++; @@ -6484,12 +7415,11 @@ { if ( ( CUR.pts.tags[point] & mask ) != 0 ) { - if ( point > 0 ) - _iup_worker_interpolate( &V, - cur_touched + 1, - point - 1, - cur_touched, - point ); + _iup_worker_interpolate( &V, + cur_touched + 1, + point - 1, + cur_touched, + point ); cur_touched = point; } @@ -6528,10 +7458,20 @@ static void Ins_DELTAP( INS_ARG ) { - FT_ULong k, nump; + FT_ULong nump, k; FT_UShort A; - FT_ULong C; + FT_ULong C, P; FT_Long B; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + FT_UShort B1, B2; + + + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.iup_called && + ( CUR.sph_tweak_flags & SPH_TWEAK_NO_DELTAP_AFTER_IUP ) ) + goto Fail; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING @@ -6543,8 +7483,9 @@ if ( CUR.args < n ) { - CUR.error = TT_Err_Too_Few_Arguments; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Too_Few_Arguments ); + n = CUR.args; } CUR.args -= n; @@ -6553,6 +7494,7 @@ } #endif + P = (FT_ULong)CUR_Func_cur_ppem(); nump = (FT_ULong)args[0]; /* some points theoretically may occur more than once, thus UShort isn't enough */ @@ -6560,8 +7502,10 @@ { if ( CUR.args < 2 ) { - CUR.error = TT_Err_Too_Few_Arguments; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Too_Few_Arguments ); + CUR.args = 0; + goto Fail; } CUR.args -= 2; @@ -6595,21 +7539,83 @@ C += CUR.GS.delta_base; - if ( CURRENT_Ppem() == (FT_Long)C ) + if ( P == C ) { B = ( (FT_ULong)B & 0xF ) - 8; if ( B >= 0 ) B++; - B = B * 64 / ( 1L << CUR.GS.delta_shift ); + B *= 1L << ( 6 - CUR.GS.delta_shift ); + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( SUBPIXEL_HINTING ) + { + /* + * Allow delta move if + * + * - not using ignore_x_mode rendering, + * - glyph is specifically set to allow it, or + * - glyph is composite and freedom vector is not in subpixel + * direction. + */ + if ( !CUR.ignore_x_mode || + ( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_DO_DELTAP ) || + ( CUR.is_composite && CUR.GS.freeVector.y != 0 ) ) + CUR_Func_move( &CUR.zp0, A, B ); + + /* Otherwise, apply subpixel hinting and compatibility mode */ + /* rules, always skipping deltas in subpixel direction. */ + else if ( CUR.ignore_x_mode && CUR.GS.freeVector.y != 0 ) + { + /* save the y value of the point now; compare after move */ + B1 = (FT_UShort)CUR.zp0.cur[A].y; + + /* Standard subpixel hinting: Allow y move for y-touched */ + /* points. This messes up DejaVu ... */ + if ( !CUR.face->sph_compatibility_mode && + ( CUR.zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) ) + CUR_Func_move( &CUR.zp0, A, B ); + + /* compatibility mode */ + else if ( CUR.face->sph_compatibility_mode && + !( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) ) + { + if ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) + B = FT_PIX_ROUND( B1 + B ) - B1; + + /* Allow delta move if using sph_compatibility_mode, */ + /* IUP has not been called, and point is touched on Y. */ + if ( !CUR.iup_called && + ( CUR.zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) ) + CUR_Func_move( &CUR.zp0, A, B ); + } + + B2 = (FT_UShort)CUR.zp0.cur[A].y; + + /* Reverse this move if it results in a disallowed move */ + if ( CUR.GS.freeVector.y != 0 && + ( ( CUR.face->sph_compatibility_mode && + ( B1 & 63 ) == 0 && + ( B2 & 63 ) != 0 ) || + ( ( CUR.sph_tweak_flags & + SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP ) && + ( B1 & 63 ) != 0 && + ( B2 & 63 ) != 0 ) ) ) + CUR_Func_move( &CUR.zp0, A, -B ); + } + } + else +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ - CUR_Func_move( &CUR.zp0, A, B ); + CUR_Func_move( &CUR.zp0, A, B ); } } else if ( CUR.pedantic_hinting ) - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); } + Fail: CUR.new_top = CUR.args; } @@ -6624,7 +7630,7 @@ Ins_DELTAC( INS_ARG ) { FT_ULong nump, k; - FT_ULong A, C; + FT_ULong A, C, P; FT_Long B; @@ -6637,8 +7643,9 @@ if ( CUR.args < n ) { - CUR.error = TT_Err_Too_Few_Arguments; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Too_Few_Arguments ); + n = CUR.args; } CUR.args -= n; @@ -6647,14 +7654,17 @@ } #endif + P = (FT_ULong)CUR_Func_cur_ppem(); nump = (FT_ULong)args[0]; for ( k = 1; k <= nump; k++ ) { if ( CUR.args < 2 ) { - CUR.error = TT_Err_Too_Few_Arguments; - return; + if ( CUR.pedantic_hinting ) + CUR.error = FT_THROW( Too_Few_Arguments ); + CUR.args = 0; + goto Fail; } CUR.args -= 2; @@ -6662,11 +7672,11 @@ A = (FT_ULong)CUR.stack[CUR.args + 1]; B = CUR.stack[CUR.args]; - if ( BOUNDS( A, CUR.cvtSize ) ) + if ( BOUNDSL( A, CUR.cvtSize ) ) { if ( CUR.pedantic_hinting ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); return; } } @@ -6690,18 +7700,19 @@ C += CUR.GS.delta_base; - if ( CURRENT_Ppem() == (FT_Long)C ) + if ( P == C ) { B = ( (FT_ULong)B & 0xF ) - 8; if ( B >= 0 ) B++; - B = B * 64 / ( 1L << CUR.GS.delta_shift ); + B *= 1L << ( 6 - CUR.GS.delta_shift ); CUR_Func_move_cvt( A, B ); } } } + Fail: CUR.new_top = CUR.args; } @@ -6727,22 +7738,109 @@ K = 0; - /* We return MS rasterizer version 1.7 for the font scaler. */ - if ( ( args[0] & 1 ) != 0 ) - K = 35; - - /* Has the glyph been rotated? */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + /********************************/ + /* RASTERIZER VERSION */ + /* Selector Bit: 0 */ + /* Return Bit(s): 0-7 */ + /* */ + if ( SUBPIXEL_HINTING && + ( args[0] & 1 ) != 0 && + CUR.ignore_x_mode ) + { + K = CUR.rasterizer_version; + FT_TRACE7(( "Setting rasterizer version %d\n", + CUR.rasterizer_version )); + } + else +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + if ( ( args[0] & 1 ) != 0 ) + K = TT_INTERPRETER_VERSION_35; + + /********************************/ + /* GLYPH ROTATED */ + /* Selector Bit: 1 */ + /* Return Bit(s): 8 */ + /* */ if ( ( args[0] & 2 ) != 0 && CUR.tt_metrics.rotated ) K |= 0x80; - /* Has the glyph been stretched? */ + /********************************/ + /* GLYPH STRETCHED */ + /* Selector Bit: 2 */ + /* Return Bit(s): 9 */ + /* */ if ( ( args[0] & 4 ) != 0 && CUR.tt_metrics.stretched ) K |= 1 << 8; - /* Are we hinting for grayscale? */ + /********************************/ + /* HINTING FOR GRAYSCALE */ + /* Selector Bit: 5 */ + /* Return Bit(s): 12 */ + /* */ if ( ( args[0] & 32 ) != 0 && CUR.grayscale ) K |= 1 << 12; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( SUBPIXEL_HINTING && + CUR.ignore_x_mode && + CUR.rasterizer_version >= TT_INTERPRETER_VERSION_35 ) + { + + if ( CUR.rasterizer_version >= 37 ) + { + /********************************/ + /* HINTING FOR SUBPIXEL */ + /* Selector Bit: 6 */ + /* Return Bit(s): 13 */ + /* */ + if ( ( args[0] & 64 ) != 0 && CUR.subpixel ) + K |= 1 << 13; + + /********************************/ + /* COMPATIBLE WIDTHS ENABLED */ + /* Selector Bit: 7 */ + /* Return Bit(s): 14 */ + /* */ + /* Functionality still needs to be added */ + if ( ( args[0] & 128 ) != 0 && CUR.compatible_widths ) + K |= 1 << 14; + + /********************************/ + /* SYMMETRICAL SMOOTHING */ + /* Selector Bit: 8 */ + /* Return Bit(s): 15 */ + /* */ + /* Functionality still needs to be added */ + if ( ( args[0] & 256 ) != 0 && CUR.symmetrical_smoothing ) + K |= 1 << 15; + + /********************************/ + /* HINTING FOR BGR? */ + /* Selector Bit: 9 */ + /* Return Bit(s): 16 */ + /* */ + /* Functionality still needs to be added */ + if ( ( args[0] & 512 ) != 0 && CUR.bgr ) + K |= 1 << 16; + + if ( CUR.rasterizer_version >= 38 ) + { + /********************************/ + /* SUBPIXEL POSITIONED? */ + /* Selector Bit: 10 */ + /* Return Bit(s): 17 */ + /* */ + /* Functionality still needs to be added */ + if ( ( args[0] & 1024 ) != 0 && CUR.subpixel_positioned ) + K |= 1 << 17; + } + } + } + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + args[0] = K; } @@ -6765,16 +7863,16 @@ if ( CUR.callTop >= CUR.callSize ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); return; } call = CUR.callStack + CUR.callTop++; call->Caller_Range = CUR.curRange; - call->Caller_IP = CUR.IP+1; + call->Caller_IP = CUR.IP + 1; call->Cur_Count = 1; - call->Cur_Restart = def->start; + call->Def = def; INS_Goto_CodeRange( def->range, def->start ); @@ -6783,7 +7881,7 @@ } } - CUR.error = TT_Err_Invalid_Opcode; + CUR.error = FT_THROW( Invalid_Opcode ); } @@ -7110,18 +8208,40 @@ FT_EXPORT_DEF( FT_Error ) TT_RunIns( TT_ExecContext exc ) { - FT_Long ins_counter = 0; /* executed instructions counter */ + FT_Long ins_counter = 0; /* executed instructions counter */ + FT_UShort i; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + FT_Byte opcode_pattern[1][2] = { + /* #8 TypeMan Talk Align */ + { + 0x06, /* SPVTL */ + 0x7D, /* RDTG */ + }, + }; + FT_UShort opcode_patterns = 1; + FT_UShort opcode_pointer[1] = { 0 }; + FT_UShort opcode_size[1] = { 1 }; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ #ifdef TT_CONFIG_OPTION_STATIC_RASTER + if ( !exc ) + return FT_THROW( Invalid_Argument ); + cur = *exc; #endif - /* set CVT functions */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + CUR.iup_called = FALSE; +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + /* set PPEM and CVT functions */ CUR.tt_metrics.ratio = 0; if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem ) { /* non-square pixels, use the stretched routines */ + CUR.func_cur_ppem = Current_Ppem_Stretched; CUR.func_read_cvt = Read_CVT_Stretched; CUR.func_write_cvt = Write_CVT_Stretched; CUR.func_move_cvt = Move_CVT_Stretched; @@ -7129,6 +8249,7 @@ else { /* square pixels, use normal routines */ + CUR.func_cur_ppem = Current_Ppem; CUR.func_read_cvt = Read_CVT; CUR.func_write_cvt = Write_CVT; CUR.func_move_cvt = Move_CVT; @@ -7141,9 +8262,13 @@ { CUR.opcode = CUR.code[CUR.IP]; + FT_TRACE7(( " " )); + FT_TRACE7(( opcode_name[CUR.opcode] )); + FT_TRACE7(( "\n" )); + if ( ( CUR.length = opcode_length[CUR.opcode] ) < 0 ) { - if ( CUR.IP + 1 > CUR.codeSize ) + if ( CUR.IP + 1 >= CUR.codeSize ) goto LErrorCodeOverflow_; CUR.length = 2 - CUR.length * CUR.code[CUR.IP + 1]; @@ -7159,8 +8284,16 @@ /* One can also interpret it as the index of the last argument. */ if ( CUR.args < 0 ) { - CUR.error = TT_Err_Too_Few_Arguments; - goto LErrorLabel_; + if ( CUR.pedantic_hinting ) + { + CUR.error = FT_THROW( Too_Few_Arguments ); + goto LErrorLabel_; + } + + /* push zeroes onto the stack */ + for ( i = 0; i < Pop_Push_Count[CUR.opcode] >> 4; i++ ) + CUR.stack[i] = 0; + CUR.args = 0; } CUR.new_top = CUR.args + ( Pop_Push_Count[CUR.opcode] & 15 ); @@ -7170,12 +8303,45 @@ /* statement. */ if ( CUR.new_top > CUR.stackSize ) { - CUR.error = TT_Err_Stack_Overflow; + CUR.error = FT_THROW( Stack_Overflow ); goto LErrorLabel_; } CUR.step_ins = TRUE; - CUR.error = TT_Err_Ok; + CUR.error = FT_Err_Ok; + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + if ( SUBPIXEL_HINTING ) + { + for ( i = 0; i < opcode_patterns; i++ ) + { + if ( opcode_pointer[i] < opcode_size[i] && + CUR.opcode == opcode_pattern[i][opcode_pointer[i]] ) + { + opcode_pointer[i] += 1; + + if ( opcode_pointer[i] == opcode_size[i] ) + { + FT_TRACE7(( "sph: opcode ptrn: %d, %s %s\n", + i, + CUR.face->root.family_name, + CUR.face->root.style_name )); + + switch ( i ) + { + case 0: + break; + } + opcode_pointer[i] = 0; + } + } + else + opcode_pointer[i] = 0; + } + } + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ #ifdef TT_CONFIG_OPTION_INTERPRETER_SWITCH @@ -7197,7 +8363,7 @@ case 0x04: /* SFvTCA y */ case 0x05: /* SFvTCA x */ { - FT_Short AA, BB; + FT_Short AA, BB; AA = (FT_Short)( ( opcode & 1 ) << 14 ); @@ -7389,7 +8555,6 @@ Ins_MDAP( EXEC_ARG_ args ); break; - case 0x30: /* IUP */ case 0x31: /* IUP */ Ins_IUP( EXEC_ARG_ args ); @@ -7449,7 +8614,7 @@ break; Set_Invalid_Ref: - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); break; case 0x43: /* RS */ @@ -7739,11 +8904,12 @@ #endif /* TT_CONFIG_OPTION_INTERPRETER_SWITCH */ - if ( CUR.error != TT_Err_Ok ) + if ( CUR.error ) { switch ( CUR.error ) { - case TT_Err_Invalid_Opcode: /* looking for redefined instructions */ + /* looking for redefined instructions */ + case FT_ERR( Invalid_Opcode ): { TT_DefRecord* def = CUR.IDefs; TT_DefRecord* limit = def + CUR.numIDefs; @@ -7758,7 +8924,7 @@ if ( CUR.callTop >= CUR.callSize ) { - CUR.error = TT_Err_Invalid_Reference; + CUR.error = FT_THROW( Invalid_Reference ); goto LErrorLabel_; } @@ -7767,7 +8933,7 @@ callrec->Caller_Range = CUR.curRange; callrec->Caller_IP = CUR.IP + 1; callrec->Cur_Count = 1; - callrec->Cur_Restart = def->start; + callrec->Def = def; if ( INS_Goto_CodeRange( def->range, def->start ) == FAILURE ) goto LErrorLabel_; @@ -7777,7 +8943,7 @@ } } - CUR.error = TT_Err_Invalid_Opcode; + CUR.error = FT_THROW( Invalid_Opcode ); goto LErrorLabel_; #if 0 @@ -7803,14 +8969,14 @@ /* increment instruction counter and check if we didn't */ /* run this program for too long (e.g. infinite loops). */ if ( ++ins_counter > MAX_RUNNABLE_OPCODES ) - return TT_Err_Execution_Too_Long; + return FT_THROW( Execution_Too_Long ); LSuiteLabel_: if ( CUR.IP >= CUR.codeSize ) { if ( CUR.callTop > 0 ) { - CUR.error = TT_Err_Code_Overflow; + CUR.error = FT_THROW( Code_Overflow ); goto LErrorLabel_; } else @@ -7824,10 +8990,10 @@ *exc = cur; #endif - return TT_Err_Ok; + return FT_Err_Ok; LErrorCodeOverflow_: - CUR.error = TT_Err_Code_Overflow; + CUR.error = FT_THROW( Code_Overflow ); LErrorLabel_: @@ -7835,6 +9001,18 @@ *exc = cur; #endif + /* If any errors have occurred, function tables may be broken. */ + /* Force a re-execution of `prep' and `fpgm' tables if no */ + /* bytecode debugger is run. */ + if ( CUR.error && + !CUR.instruction_trap && + CUR.curRange == tt_coderange_glyph ) + { + FT_TRACE1(( " The interpreter returned error 0x%x\n", CUR.error )); + exc->size->bytecode_ready = -1; + exc->size->cvt_ready = -1; + } + return CUR.error; } diff --git a/src/3rdparty/freetype/src/truetype/ttinterp.h b/src/3rdparty/freetype/src/truetype/ttinterp.h index 07a8972cb3..333decc6a6 100644 --- a/src/3rdparty/freetype/src/truetype/ttinterp.h +++ b/src/3rdparty/freetype/src/truetype/ttinterp.h @@ -4,7 +4,7 @@ /* */ /* TrueType bytecode interpreter (specification). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 1996-2007, 2010, 2012-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -81,6 +81,10 @@ FT_BEGIN_HEADER (*TT_Project_Func)( EXEC_OP_ FT_Pos dx, FT_Pos dy ); + /* getting current ppem. Take care of non-square pixels if necessary */ + typedef FT_Long + (*TT_Cur_Ppem_Func)( EXEC_OP ); + /* reading a cvt value. Take care of non-square pixels if necessary */ typedef FT_F26Dot6 (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong idx ); @@ -101,11 +105,54 @@ FT_BEGIN_HEADER FT_Int Caller_Range; FT_Long Caller_IP; FT_Long Cur_Count; - FT_Long Cur_Restart; + + TT_DefRecord *Def; /* either FDEF or IDEF */ } TT_CallRec, *TT_CallStack; +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + /*************************************************************************/ + /* */ + /* These structures define rules used to tweak subpixel hinting for */ + /* various fonts. "", 0, "", NULL value indicates to match any value. */ + /* */ + +#define SPH_MAX_NAME_SIZE 32 +#define SPH_MAX_CLASS_MEMBERS 100 + + typedef struct SPH_TweakRule_ + { + const char family[SPH_MAX_NAME_SIZE]; + const FT_UInt ppem; + const char style[SPH_MAX_NAME_SIZE]; + const FT_ULong glyph; + + } SPH_TweakRule; + + + typedef struct SPH_ScaleRule_ + { + const char family[SPH_MAX_NAME_SIZE]; + const FT_UInt ppem; + const char style[SPH_MAX_NAME_SIZE]; + const FT_ULong glyph; + const FT_ULong scale; + + } SPH_ScaleRule; + + + typedef struct SPH_Font_Class_ + { + const char name[SPH_MAX_NAME_SIZE]; + const char member[SPH_MAX_CLASS_MEMBERS][SPH_MAX_NAME_SIZE]; + + } SPH_Font_Class; + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + /*************************************************************************/ /* */ /* The main structure for the interpreter which collects all necessary */ @@ -150,7 +197,7 @@ FT_BEGIN_HEADER FT_Bool step_ins; /* true if the interpreter must */ /* increment IP after ins. exec */ - FT_Long cvtSize; + FT_ULong cvtSize; FT_Long* cvt; FT_UInt glyphSize; /* glyph instructions buffer size */ @@ -185,11 +232,6 @@ FT_BEGIN_HEADER FT_F26Dot6 phase; /* `SuperRounding' */ FT_F26Dot6 threshold; -#if 0 - /* this seems to be unused */ - FT_Int cur_ppem; /* ppem along the current proj vector */ -#endif - FT_Bool instruction_trap; /* If `True', the interpreter will */ /* exit after each instruction */ @@ -211,34 +253,74 @@ FT_BEGIN_HEADER TT_Move_Func func_move; /* current point move function */ TT_Move_Func func_move_orig; /* move original position function */ + TT_Cur_Ppem_Func func_cur_ppem; /* get current proj. ppem value */ + TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */ TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */ TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */ FT_Bool grayscale; /* are we hinting for grayscale? */ +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + TT_Round_Func func_round_sphn; /* subpixel rounding function */ + + FT_Bool subpixel; /* Using subpixel hinting? */ + FT_Bool ignore_x_mode; /* Standard rendering mode for */ + /* subpixel hinting. On if gray */ + /* or subpixel hinting is on. */ + + /* The following 4 aren't fully implemented but here for MS rasterizer */ + /* compatibility. */ + FT_Bool compatible_widths; /* compatible widths? */ + FT_Bool symmetrical_smoothing; /* symmetrical_smoothing? */ + FT_Bool bgr; /* bgr instead of rgb? */ + FT_Bool subpixel_positioned; /* subpixel positioned */ + /* (DirectWrite ClearType)? */ + + FT_Int rasterizer_version; /* MS rasterizer version */ + + FT_Bool iup_called; /* IUP called for glyph? */ + + FT_ULong sph_tweak_flags; /* flags to control */ + /* hint tweaks */ + + FT_ULong sph_in_func_flags; /* flags to indicate if in */ + /* special functions */ + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + } TT_ExecContextRec; extern const TT_GraphicsState tt_default_graphics_state; - FT_LOCAL( FT_Error ) +#ifdef TT_USE_BYTECODE_INTERPRETER + FT_LOCAL( void ) TT_Goto_CodeRange( TT_ExecContext exec, FT_Int range, FT_Long IP ); - FT_LOCAL( FT_Error ) + FT_LOCAL( void ) TT_Set_CodeRange( TT_ExecContext exec, FT_Int range, void* base, FT_Long length ); - FT_LOCAL( FT_Error ) + FT_LOCAL( void ) TT_Clear_CodeRange( TT_ExecContext exec, FT_Int range ); + FT_LOCAL( FT_Error ) + Update_Max( FT_Memory memory, + FT_ULong* size, + FT_Long multiplier, + void* _pbuff, + FT_ULong new_max ); +#endif /* TT_USE_BYTECODE_INTERPRETER */ + + /*************************************************************************/ /* */ /* */ @@ -261,7 +343,9 @@ FT_BEGIN_HEADER FT_EXPORT( TT_ExecContext ) TT_New_Context( TT_Driver driver ); - FT_LOCAL( FT_Error ) + +#ifdef TT_USE_BYTECODE_INTERPRETER + FT_LOCAL( void ) TT_Done_Context( TT_ExecContext exec ); FT_LOCAL( FT_Error ) @@ -269,13 +353,14 @@ FT_BEGIN_HEADER TT_Face face, TT_Size size ); - FT_LOCAL( FT_Error ) + FT_LOCAL( void ) TT_Save_Context( TT_ExecContext exec, TT_Size ins ); FT_LOCAL( FT_Error ) TT_Run_Context( TT_ExecContext exec, FT_Bool debug ); +#endif /* TT_USE_BYTECODE_INTERPRETER */ /*************************************************************************/ diff --git a/src/3rdparty/freetype/src/truetype/ttobjs.c b/src/3rdparty/freetype/src/truetype/ttobjs.c index 11d662d2d4..4707dfe159 100644 --- a/src/3rdparty/freetype/src/truetype/ttobjs.c +++ b/src/3rdparty/freetype/src/truetype/ttobjs.c @@ -4,7 +4,7 @@ /* */ /* Objects manager (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2013 */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -21,6 +21,7 @@ #include FT_INTERNAL_STREAM_H #include FT_TRUETYPE_TAGS_H #include FT_INTERNAL_SFNT_H +#include FT_TRUETYPE_DRIVER_H #include "ttgload.h" #include "ttpload.h" @@ -146,28 +147,29 @@ /* This list shall be expanded as we find more of them. */ static FT_Bool - tt_check_trickyness( FT_String* name ) + tt_check_trickyness_family( FT_String* name ) { -#define TRICK_NAMES_MAX_CHARACTERS 16 -#define TRICK_NAMES_COUNT 7 - static const char trick_names[TRICK_NAMES_COUNT][TRICK_NAMES_MAX_CHARACTERS+1] = + +#define TRICK_NAMES_MAX_CHARACTERS 19 +#define TRICK_NAMES_COUNT 9 + + static const char trick_names[TRICK_NAMES_COUNT] + [TRICK_NAMES_MAX_CHARACTERS + 1] = { - "DFKaiSho-SB", /* dfkaisb.ttf */ + "DFKaiSho-SB", /* dfkaisb.ttf */ "DFKaiShu", - "DFKai-SB", /* kaiu.ttf */ - "HuaTianSongTi?", /* htst3.ttf */ - "MingLiU", /* mingliu.ttf & mingliu.ttc */ - "PMingLiU", /* mingliu.ttc */ - "MingLi43", /* mingli.ttf */ + "DFKai-SB", /* kaiu.ttf */ + "HuaTianKaiTi?", /* htkt2.ttf */ + "HuaTianSongTi?", /* htst3.ttf */ + "Ming(for ISO10646)", /* hkscsiic.ttf & iicore.ttf */ + "MingLiU", /* mingliu.ttf & mingliu.ttc */ + "PMingLiU", /* mingliu.ttc */ + "MingLi43", /* mingli.ttf */ }; - int nn; + int nn; - if ( !name ) - return FALSE; - /* Note that we only check the face name at the moment; it might */ - /* be worth to do more checks for a few special cases. */ for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ ) if ( ft_strstr( name, trick_names[nn] ) ) return TRUE; @@ -176,6 +178,307 @@ } + /* XXX: This function should be in the `sfnt' module. */ + + /* Some PDF generators clear the checksums in the TrueType header table. */ + /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF */ + /* Printer clears the entries for subsetted subtables. We thus have to */ + /* recalculate the checksums where necessary. */ + + static FT_UInt32 + tt_synth_sfnt_checksum( FT_Stream stream, + FT_ULong length ) + { + FT_Error error; + FT_UInt32 checksum = 0; + int i; + + + if ( FT_FRAME_ENTER( length ) ) + return 0; + + for ( ; length > 3; length -= 4 ) + checksum += (FT_UInt32)FT_GET_ULONG(); + + for ( i = 3; length > 0; length --, i-- ) + checksum += (FT_UInt32)( FT_GET_BYTE() << ( i * 8 ) ); + + FT_FRAME_EXIT(); + + return checksum; + } + + + /* XXX: This function should be in the `sfnt' module. */ + + static FT_ULong + tt_get_sfnt_checksum( TT_Face face, + FT_UShort i ) + { +#if 0 /* if we believe the written value, use following part. */ + if ( face->dir_tables[i].CheckSum ) + return face->dir_tables[i].CheckSum; +#endif + + if ( !face->goto_table ) + return 0; + + if ( face->goto_table( face, + face->dir_tables[i].Tag, + face->root.stream, + NULL ) ) + return 0; + + return (FT_ULong)tt_synth_sfnt_checksum( face->root.stream, + face->dir_tables[i].Length ); + } + + + typedef struct tt_sfnt_id_rec_ + { + FT_ULong CheckSum; + FT_ULong Length; + + } tt_sfnt_id_rec; + + + static FT_Bool + tt_check_trickyness_sfnt_ids( TT_Face face ) + { +#define TRICK_SFNT_IDS_PER_FACE 3 +#define TRICK_SFNT_IDS_NUM_FACES 17 + + static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES] + [TRICK_SFNT_IDS_PER_FACE] = { + +#define TRICK_SFNT_ID_cvt 0 +#define TRICK_SFNT_ID_fpgm 1 +#define TRICK_SFNT_ID_prep 2 + + { /* MingLiU 1995 */ + { 0x05BCF058UL, 0x000002E4UL }, /* cvt */ + { 0x28233BF1UL, 0x000087C4UL }, /* fpgm */ + { 0xA344A1EAUL, 0x000001E1UL } /* prep */ + }, + { /* MingLiU 1996- */ + { 0x05BCF058UL, 0x000002E4UL }, /* cvt */ + { 0x28233BF1UL, 0x000087C4UL }, /* fpgm */ + { 0xA344A1EBUL, 0x000001E1UL } /* prep */ + }, + { /* DFKaiShu */ + { 0x11E5EAD4UL, 0x00000350UL }, /* cvt */ + { 0x5A30CA3BUL, 0x00009063UL }, /* fpgm */ + { 0x13A42602UL, 0x0000007EUL } /* prep */ + }, + { /* HuaTianKaiTi */ + { 0xFFFBFFFCUL, 0x00000008UL }, /* cvt */ + { 0x9C9E48B8UL, 0x0000BEA2UL }, /* fpgm */ + { 0x70020112UL, 0x00000008UL } /* prep */ + }, + { /* HuaTianSongTi */ + { 0xFFFBFFFCUL, 0x00000008UL }, /* cvt */ + { 0x0A5A0483UL, 0x00017C39UL }, /* fpgm */ + { 0x70020112UL, 0x00000008UL } /* prep */ + }, + { /* NEC fadpop7.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x40C92555UL, 0x000000E5UL }, /* fpgm */ + { 0xA39B58E3UL, 0x0000117CUL } /* prep */ + }, + { /* NEC fadrei5.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x33C41652UL, 0x000000E5UL }, /* fpgm */ + { 0x26D6C52AUL, 0x00000F6AUL } /* prep */ + }, + { /* NEC fangot7.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x6DB1651DUL, 0x0000019DUL }, /* fpgm */ + { 0x6C6E4B03UL, 0x00002492UL } /* prep */ + }, + { /* NEC fangyo5.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x40C92555UL, 0x000000E5UL }, /* fpgm */ + { 0xDE51FAD0UL, 0x0000117CUL } /* prep */ + }, + { /* NEC fankyo5.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x85E47664UL, 0x000000E5UL }, /* fpgm */ + { 0xA6C62831UL, 0x00001CAAUL } /* prep */ + }, + { /* NEC fanrgo5.ttf */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x2D891CFDUL, 0x0000019DUL }, /* fpgm */ + { 0xA0604633UL, 0x00001DE8UL } /* prep */ + }, + { /* NEC fangot5.ttc */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x40AA774CUL, 0x000001CBUL }, /* fpgm */ + { 0x9B5CAA96UL, 0x00001F9AUL } /* prep */ + }, + { /* NEC fanmin3.ttc */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x0D3DE9CBUL, 0x00000141UL }, /* fpgm */ + { 0xD4127766UL, 0x00002280UL } /* prep */ + }, + { /* NEC FA-Gothic, 1996 */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x4A692698UL, 0x000001F0UL }, /* fpgm */ + { 0x340D4346UL, 0x00001FCAUL } /* prep */ + }, + { /* NEC FA-Minchou, 1996 */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0xCD34C604UL, 0x00000166UL }, /* fpgm */ + { 0x6CF31046UL, 0x000022B0UL } /* prep */ + }, + { /* NEC FA-RoundGothicB, 1996 */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0x5DA75315UL, 0x0000019DUL }, /* fpgm */ + { 0x40745A5FUL, 0x000022E0UL } /* prep */ + }, + { /* NEC FA-RoundGothicM, 1996 */ + { 0x00000000UL, 0x00000000UL }, /* cvt */ + { 0xF055FC48UL, 0x000001C2UL }, /* fpgm */ + { 0x3900DED3UL, 0x00001E18UL } /* prep */ + } + }; + + FT_ULong checksum; + int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES]; + FT_Bool has_cvt, has_fpgm, has_prep; + FT_UShort i; + int j, k; + + + FT_MEM_SET( num_matched_ids, 0, + sizeof ( int ) * TRICK_SFNT_IDS_NUM_FACES ); + has_cvt = FALSE; + has_fpgm = FALSE; + has_prep = FALSE; + + for ( i = 0; i < face->num_tables; i++ ) + { + checksum = 0; + + switch( face->dir_tables[i].Tag ) + { + case TTAG_cvt: + k = TRICK_SFNT_ID_cvt; + has_cvt = TRUE; + break; + + case TTAG_fpgm: + k = TRICK_SFNT_ID_fpgm; + has_fpgm = TRUE; + break; + + case TTAG_prep: + k = TRICK_SFNT_ID_prep; + has_prep = TRUE; + break; + + default: + continue; + } + + for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ ) + if ( face->dir_tables[i].Length == sfnt_id[j][k].Length ) + { + if ( !checksum ) + checksum = tt_get_sfnt_checksum( face, i ); + + if ( sfnt_id[j][k].CheckSum == checksum ) + num_matched_ids[j]++; + + if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE ) + return TRUE; + } + } + + for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ ) + { + if ( !has_cvt && !sfnt_id[j][TRICK_SFNT_ID_cvt].Length ) + num_matched_ids[j] ++; + if ( !has_fpgm && !sfnt_id[j][TRICK_SFNT_ID_fpgm].Length ) + num_matched_ids[j] ++; + if ( !has_prep && !sfnt_id[j][TRICK_SFNT_ID_prep].Length ) + num_matched_ids[j] ++; + if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE ) + return TRUE; + } + + return FALSE; + } + + + static FT_Bool + tt_check_trickyness( FT_Face face ) + { + if ( !face ) + return FALSE; + + /* For first, check the face name for quick check. */ + if ( face->family_name && + tt_check_trickyness_family( face->family_name ) ) + return TRUE; + + /* Type42 fonts may lack `name' tables, we thus try to identify */ + /* tricky fonts by checking the checksums of Type42-persistent */ + /* sfnt tables (`cvt', `fpgm', and `prep'). */ + if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) ) + return TRUE; + + return FALSE; + } + + + /* Check whether `.notdef' is the only glyph in the `loca' table. */ + static FT_Bool + tt_check_single_notdef( FT_Face ttface ) + { + FT_Bool result = FALSE; + + TT_Face face = (TT_Face)ttface; + FT_UInt asize; + FT_ULong i; + FT_ULong glyph_index = 0; + FT_UInt count = 0; + + + for( i = 0; i < face->num_locations; i++ ) + { + tt_face_get_location( face, i, &asize ); + if ( asize > 0 ) + { + count += 1; + if ( count > 1 ) + break; + glyph_index = i; + } + } + + /* Only have a single outline. */ + if ( count == 1 ) + { + if ( glyph_index == 0 ) + result = TRUE; + else + { + /* FIXME: Need to test glyphname == .notdef ? */ + FT_Error error; + char buf[8]; + + + error = FT_Get_Glyph_Name( ttface, glyph_index, buf, 8 ); + if ( !error && + buf[0] == '.' && !ft_strncmp( buf, ".notdef", 8 ) ) + result = TRUE; + } + } + + return result; + } + + /*************************************************************************/ /* */ /* */ @@ -212,10 +515,17 @@ TT_Face face = (TT_Face)ttface; + FT_TRACE2(( "TTF driver\n" )); + library = ttface->driver->root.library; - sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); + + sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) - goto Bad_Format; + { + FT_ERROR(( "tt_face_init: cannot access `sfnt' module\n" )); + error = FT_THROW( Missing_Module ); + goto Exit; + } /* create input stream from resource */ if ( FT_STREAM_SEEK( 0 ) ) @@ -223,6 +533,10 @@ /* check that we have a valid TrueType file */ error = sfnt->init_face( stream, face, face_index, num_params, params ); + + /* Stream may have changed. */ + stream = face->root.stream; + if ( error ) goto Exit; @@ -233,7 +547,7 @@ face->format_tag != 0x00020000L && /* CJK fonts for Win 3.1 */ face->format_tag != TTAG_true ) /* Mac fonts */ { - FT_TRACE2(( "[not a valid TTF font]\n" )); + FT_TRACE2(( " not a TTF font\n" )); goto Bad_Format; } @@ -243,14 +557,14 @@ /* If we are performing a simple font format check, exit immediately. */ if ( face_index < 0 ) - return TT_Err_Ok; + return FT_Err_Ok; /* Load font directory */ error = sfnt->load_face( stream, face, face_index, num_params, params ); if ( error ) goto Exit; - if ( tt_check_trickyness( ttface->family_name ) ) + if ( tt_check_trickyness( ttface ) ) ttface->face_flags |= FT_FACE_FLAG_TRICKY; error = tt_face_load_hdmx( face, stream ); @@ -271,6 +585,20 @@ if ( !error ) error = tt_face_load_prep( face, stream ); + /* Check the scalable flag based on `loca'. */ + if ( !ttface->internal->incremental_interface && + ttface->num_fixed_sizes && + face->glyph_locations && + tt_check_single_notdef( ttface ) ) + { + FT_TRACE5(( "tt_face_init:" + " Only the `.notdef' glyph has an outline.\n" + " " + " Resetting scalable flag to FALSE.\n" )); + + ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE; + } + #else if ( !error ) @@ -282,6 +610,19 @@ if ( !error ) error = tt_face_load_prep( face, stream ); + /* Check the scalable flag based on `loca'. */ + if ( ttface->num_fixed_sizes && + face->glyph_locations && + tt_check_single_notdef( ttface ) ) + { + FT_TRACE5(( "tt_face_init:" + " Only the `.notdef' glyph has an outline.\n" + " " + " Resetting scalable flag to FALSE.\n" )); + + ttface->face_flags &= ~FT_FACE_FLAG_SCALABLE; + } + #endif } @@ -316,7 +657,7 @@ return error; Bad_Format: - error = TT_Err_Unknown_File_Format; + error = FT_THROW( Unknown_File_Format ); goto Exit; } @@ -394,13 +735,16 @@ /* Run the font program. */ /* */ /* */ - /* size :: A handle to the size object. */ + /* size :: A handle to the size object. */ + /* */ + /* pedantic :: Set if bytecode execution should be pedantic. */ /* */ /* */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) - tt_size_run_fpgm( TT_Size size ) + tt_size_run_fpgm( TT_Size size, + FT_Bool pedantic ) { TT_Face face = (TT_Face)size->root.face; TT_ExecContext exec; @@ -414,19 +758,23 @@ exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; if ( !exec ) - return TT_Err_Could_Not_Find_Context; + return FT_THROW( Could_Not_Find_Context ); - TT_Load_Context( exec, face, size ); + error = TT_Load_Context( exec, face, size ); + if ( error ) + return error; - exec->callTop = 0; - exec->top = 0; + exec->callTop = 0; + exec->top = 0; exec->period = 64; exec->phase = 0; exec->threshold = 0; exec->instruction_trap = FALSE; - exec->F_dot_P = 0x10000L; + exec->F_dot_P = 0x4000L; + + exec->pedantic_hinting = pedantic; { FT_Size_Metrics* metrics = &exec->metrics; @@ -455,13 +803,15 @@ if ( face->font_program_size > 0 ) { - error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 ); + TT_Goto_CodeRange( exec, tt_coderange_font, 0 ); - if ( !error ) - error = face->interpreter( exec ); + FT_TRACE4(( "Executing `fpgm' table.\n" )); + error = face->interpreter( exec ); } else - error = TT_Err_Ok; + error = FT_Err_Ok; + + size->bytecode_ready = error; if ( !error ) TT_Save_Context( exec, size ); @@ -479,13 +829,16 @@ /* Run the control value program. */ /* */ /* */ - /* size :: A handle to the size object. */ + /* size :: A handle to the size object. */ + /* */ + /* pedantic :: Set if bytecode execution should be pedantic. */ /* */ /* */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) - tt_size_run_prep( TT_Size size ) + tt_size_run_prep( TT_Size size, + FT_Bool pedantic ) { TT_Face face = (TT_Face)size->root.face; TT_ExecContext exec; @@ -499,15 +852,19 @@ exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; if ( !exec ) - return TT_Err_Could_Not_Find_Context; + return FT_THROW( Could_Not_Find_Context ); - TT_Load_Context( exec, face, size ); + error = TT_Load_Context( exec, face, size ); + if ( error ) + return error; exec->callTop = 0; exec->top = 0; exec->instruction_trap = FALSE; + exec->pedantic_hinting = pedantic; + TT_Set_CodeRange( exec, tt_coderange_cvt, face->cvt_program, @@ -517,13 +874,39 @@ if ( face->cvt_program_size > 0 ) { - error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 ); + TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 ); + + if ( !size->debug ) + { + FT_TRACE4(( "Executing `prep' table.\n" )); - if ( !error && !size->debug ) error = face->interpreter( exec ); + } } else - error = TT_Err_Ok; + error = FT_Err_Ok; + + size->cvt_ready = error; + + /* UNDOCUMENTED! The MS rasterizer doesn't allow the following */ + /* graphics state variables to be modified by the CVT program. */ + + exec->GS.dualVector.x = 0x4000; + exec->GS.dualVector.y = 0; + exec->GS.projVector.x = 0x4000; + exec->GS.projVector.y = 0x0; + exec->GS.freeVector.x = 0x4000; + exec->GS.freeVector.y = 0x0; + + exec->GS.rp0 = 0; + exec->GS.rp1 = 0; + exec->GS.rp2 = 0; + + exec->GS.gep0 = 1; + exec->GS.gep1 = 1; + exec->GS.gep2 = 1; + + exec->GS.loop = 1; /* save as default graphics state */ size->GS = exec->GS; @@ -533,10 +916,6 @@ return error; } -#endif /* TT_USE_BYTECODE_INTERPRETER */ - - -#ifdef TT_USE_BYTECODE_INTERPRETER static void tt_size_done_bytecode( FT_Size ftsize ) @@ -574,28 +953,28 @@ size->max_func = 0; size->max_ins = 0; - size->bytecode_ready = 0; - size->cvt_ready = 0; + size->bytecode_ready = -1; + size->cvt_ready = -1; } /* Initialize bytecode-related fields in the size object. */ /* We do this only if bytecode interpretation is really needed. */ static FT_Error - tt_size_init_bytecode( FT_Size ftsize ) + tt_size_init_bytecode( FT_Size ftsize, + FT_Bool pedantic ) { FT_Error error; TT_Size size = (TT_Size)ftsize; TT_Face face = (TT_Face)ftsize->face; FT_Memory memory = face->root.memory; - FT_Int i; FT_UShort n_twilight; TT_MaxProfile* maxp = &face->max_profile; - size->bytecode_ready = 1; - size->cvt_ready = 0; + size->bytecode_ready = -1; + size->cvt_ready = -1; size->max_function_defs = maxp->maxFunctionDefs; size->max_instruction_defs = maxp->maxInstructionDefs; @@ -617,9 +996,11 @@ metrics->rotated = FALSE; metrics->stretched = FALSE; - /* set default compensation (all 0) */ - for ( i = 0; i < 4; i++ ) - metrics->compensations[i] = 0; + /* set default engine compensation */ + metrics->compensations[0] = 0; /* gray */ + metrics->compensations[1] = 0; /* black */ + metrics->compensations[2] = 0; /* white */ + metrics->compensations[3] = 0; /* reserved */ } /* allocate function defs, instruction defs, cvt, and storage area */ @@ -655,7 +1036,7 @@ } /* Fine, now run the font program! */ - error = tt_size_run_fpgm( size ); + error = tt_size_run_fpgm( size, pedantic ); Exit: if ( error ) @@ -666,20 +1047,20 @@ FT_LOCAL_DEF( FT_Error ) - tt_size_ready_bytecode( TT_Size size ) + tt_size_ready_bytecode( TT_Size size, + FT_Bool pedantic ) { - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; - if ( !size->bytecode_ready ) - { - error = tt_size_init_bytecode( (FT_Size)size ); - if ( error ) - goto Exit; - } + if ( size->bytecode_ready < 0 ) + error = tt_size_init_bytecode( (FT_Size)size, pedantic ); + + if ( error || size->bytecode_ready ) + goto Exit; /* rescale CVT when needed */ - if ( !size->cvt_ready ) + if ( size->cvt_ready < 0 ) { FT_UInt i; TT_Face face = (TT_Face)size->root.face; @@ -705,9 +1086,7 @@ size->GS = tt_default_graphics_state; - error = tt_size_run_prep( size ); - if ( !error ) - size->cvt_ready = 1; + error = tt_size_run_prep( size, pedantic ); } Exit: @@ -735,11 +1114,12 @@ tt_size_init( FT_Size ttsize ) /* TT_Size */ { TT_Size size = (TT_Size)ttsize; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; + #ifdef TT_USE_BYTECODE_INTERPRETER - size->bytecode_ready = 0; - size->cvt_ready = 0; + size->bytecode_ready = -1; + size->cvt_ready = -1; #endif size->ttmetrics.valid = FALSE; @@ -767,8 +1147,7 @@ #ifdef TT_USE_BYTECODE_INTERPRETER - if ( size->bytecode_ready ) - tt_size_done_bytecode( ttsize ); + tt_size_done_bytecode( ttsize ); #endif size->ttmetrics.valid = FALSE; @@ -791,7 +1170,7 @@ tt_size_reset( TT_Size size ) { TT_Face face; - FT_Error error = TT_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Size_Metrics* metrics; @@ -805,7 +1184,7 @@ *metrics = size->root.metrics; if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 ) - return TT_Err_Invalid_PPem; + return FT_THROW( Invalid_PPem ); /* This bit flag, if set, indicates that the ppems must be */ /* rounded to integers. Nearly all TrueType fonts have this bit */ @@ -835,22 +1214,20 @@ size->ttmetrics.scale = metrics->x_scale; size->ttmetrics.ppem = metrics->x_ppem; size->ttmetrics.x_ratio = 0x10000L; - size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem, - 0x10000L, + size->ttmetrics.y_ratio = FT_DivFix( metrics->y_ppem, metrics->x_ppem ); } else { size->ttmetrics.scale = metrics->y_scale; size->ttmetrics.ppem = metrics->y_ppem; - size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem, - 0x10000L, + size->ttmetrics.x_ratio = FT_DivFix( metrics->x_ppem, metrics->y_ppem ); size->ttmetrics.y_ratio = 0x10000L; } #ifdef TT_USE_BYTECODE_INTERPRETER - size->cvt_ready = 0; + size->cvt_ready = -1; #endif /* TT_USE_BYTECODE_INTERPRETER */ if ( !error ) @@ -884,15 +1261,21 @@ if ( !TT_New_Context( driver ) ) - return TT_Err_Could_Not_Find_Context; + return FT_THROW( Could_Not_Find_Context ); +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + driver->interpreter_version = TT_INTERPRETER_VERSION_38; #else + driver->interpreter_version = TT_INTERPRETER_VERSION_35; +#endif + +#else /* !TT_USE_BYTECODE_INTERPRETER */ FT_UNUSED( ttdriver ); -#endif +#endif /* !TT_USE_BYTECODE_INTERPRETER */ - return TT_Err_Ok; + return FT_Err_Ok; } diff --git a/src/3rdparty/freetype/src/truetype/ttobjs.h b/src/3rdparty/freetype/src/truetype/ttobjs.h index 30c8669cb2..859164f86b 100644 --- a/src/3rdparty/freetype/src/truetype/ttobjs.h +++ b/src/3rdparty/freetype/src/truetype/ttobjs.h @@ -4,7 +4,7 @@ /* */ /* Objects manager (specification). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2009, 2011-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -95,8 +95,8 @@ FT_BEGIN_HEADER FT_F26Dot6 control_value_cutin; FT_F26Dot6 single_width_cutin; FT_F26Dot6 single_width_value; - FT_Short delta_base; - FT_Short delta_shift; + FT_UShort delta_base; + FT_UShort delta_shift; FT_Byte instruct_control; /* According to Greg Hitchcock from Microsoft, the `scan_control' */ @@ -173,10 +173,13 @@ FT_BEGIN_HEADER /* */ typedef struct TT_DefRecord_ { - FT_Int range; /* in which code range is it located? */ - FT_Long start; /* where does it start? */ - FT_UInt opc; /* function #, or instruction code */ - FT_Bool active; /* is it active? */ + FT_Int range; /* in which code range is it located? */ + FT_Long start; /* where does it start? */ + FT_Long end; /* where does it end? */ + FT_UInt opc; /* function #, or instruction code */ + FT_Bool active; /* is it active? */ + FT_Bool inline_delta; /* is function that defines inline delta? */ + FT_ULong sph_fdef_flags; /* flags to identify special functions */ } TT_DefRecord, *TT_DefArray; @@ -189,7 +192,7 @@ FT_BEGIN_HEADER { FT_Fixed xx, xy; /* transformation matrix coefficients */ FT_Fixed yx, yy; - FT_F26Dot6 ox, oy; /* offsets */ + FT_F26Dot6 ox, oy; /* offsets */ } TT_Transform; @@ -330,8 +333,10 @@ FT_BEGIN_HEADER FT_Bool debug; TT_ExecContext context; - FT_Bool bytecode_ready; - FT_Bool cvt_ready; + /* if negative, `fpgm' (resp. `prep'), wasn't executed yet; */ + /* otherwise it is the returned error code */ + FT_Error bytecode_ready; + FT_Error cvt_ready; #endif /* TT_USE_BYTECODE_INTERPRETER */ @@ -344,11 +349,12 @@ FT_BEGIN_HEADER /* */ typedef struct TT_DriverRec_ { - FT_DriverRec root; + FT_DriverRec root; + TT_ExecContext context; /* execution context */ TT_GlyphZoneRec zone; /* glyph loader points zone */ - void* extension_component; + FT_UInt interpreter_version; } TT_DriverRec; @@ -390,13 +396,16 @@ FT_BEGIN_HEADER #ifdef TT_USE_BYTECODE_INTERPRETER FT_LOCAL( FT_Error ) - tt_size_run_fpgm( TT_Size size ); + tt_size_run_fpgm( TT_Size size, + FT_Bool pedantic ); FT_LOCAL( FT_Error ) - tt_size_run_prep( TT_Size size ); + tt_size_run_prep( TT_Size size, + FT_Bool pedantic ); FT_LOCAL( FT_Error ) - tt_size_ready_bytecode( TT_Size size ); + tt_size_ready_bytecode( TT_Size size, + FT_Bool pedantic ); #endif /* TT_USE_BYTECODE_INTERPRETER */ @@ -423,6 +432,10 @@ FT_BEGIN_HEADER tt_slot_init( FT_GlyphSlot slot ); + /* auxiliary */ +#define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) + + FT_END_HEADER #endif /* __TTOBJS_H__ */ diff --git a/src/3rdparty/freetype/src/truetype/ttpic.c b/src/3rdparty/freetype/src/truetype/ttpic.c index 27ec4a1d5e..edefae72c5 100644 --- a/src/3rdparty/freetype/src/truetype/ttpic.c +++ b/src/3rdparty/freetype/src/truetype/ttpic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for truetype module. */ /* */ -/* Copyright 2009 by */ +/* Copyright 2009, 2010, 2012, 2013 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -20,56 +20,78 @@ #include FT_FREETYPE_H #include FT_INTERNAL_OBJECTS_H #include "ttpic.h" +#include "tterrors.h" + #ifdef FT_CONFIG_OPTION_PIC /* forward declaration of PIC init functions from ttdriver.c */ - FT_Error FT_Create_Class_tt_services( FT_Library, FT_ServiceDescRec**); - void FT_Destroy_Class_tt_services( FT_Library, FT_ServiceDescRec*); - void FT_Init_Class_tt_service_gx_multi_masters(FT_Service_MultiMastersRec*); - void FT_Init_Class_tt_service_truetype_glyf(FT_Service_TTGlyfRec*); + FT_Error + FT_Create_Class_tt_services( FT_Library library, + FT_ServiceDescRec** output_class ); + void + FT_Destroy_Class_tt_services( FT_Library library, + FT_ServiceDescRec* clazz ); + void + FT_Init_Class_tt_service_gx_multi_masters( + FT_Service_MultiMastersRec* sv_mm ); + void + FT_Init_Class_tt_service_truetype_glyf( + FT_Service_TTGlyfRec* sv_ttglyf ); + void - tt_driver_class_pic_free( FT_Library library ) + tt_driver_class_pic_free( FT_Library library ) { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Memory memory = library->memory; + FT_PIC_Container* pic_container = &library->pic_container; + FT_Memory memory = library->memory; + + if ( pic_container->truetype ) { - TTModulePIC* container = (TTModulePIC*)pic_container->truetype; - if(container->tt_services) - FT_Destroy_Class_tt_services(library, container->tt_services); + TTModulePIC* container = (TTModulePIC*)pic_container->truetype; + + + if ( container->tt_services ) + FT_Destroy_Class_tt_services( library, container->tt_services ); container->tt_services = NULL; FT_FREE( container ); pic_container->truetype = NULL; } } + FT_Error - tt_driver_class_pic_init( FT_Library library ) + tt_driver_class_pic_init( FT_Library library ) { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error = FT_Err_Ok; - TTModulePIC* container; - FT_Memory memory = library->memory; + FT_PIC_Container* pic_container = &library->pic_container; + FT_Error error = FT_Err_Ok; + TTModulePIC* container = NULL; + FT_Memory memory = library->memory; + /* allocate pointer, clear and set global container pointer */ - if ( FT_ALLOC ( container, sizeof ( *container ) ) ) + if ( FT_ALLOC( container, sizeof ( *container ) ) ) return error; - FT_MEM_SET( container, 0, sizeof(*container) ); + FT_MEM_SET( container, 0, sizeof ( *container ) ); pic_container->truetype = container; - /* initialize pointer table - this is how the module usually expects this data */ - error = FT_Create_Class_tt_services(library, &container->tt_services); - if(error) + /* initialize pointer table - this is how the module usually */ + /* expects this data */ + error = FT_Create_Class_tt_services( library, + &container->tt_services ); + if ( error ) goto Exit; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - FT_Init_Class_tt_service_gx_multi_masters(&container->tt_service_gx_multi_masters); + FT_Init_Class_tt_service_gx_multi_masters( + &container->tt_service_gx_multi_masters ); #endif - FT_Init_Class_tt_service_truetype_glyf(&container->tt_service_truetype_glyf); -Exit: - if(error) - tt_driver_class_pic_free(library); + FT_Init_Class_tt_service_truetype_glyf( + &container->tt_service_truetype_glyf ); + + Exit: + if ( error ) + tt_driver_class_pic_free( library ); return error; } diff --git a/src/3rdparty/freetype/src/truetype/ttpic.h b/src/3rdparty/freetype/src/truetype/ttpic.h index 84de0fee9e..cfb4ee6281 100644 --- a/src/3rdparty/freetype/src/truetype/ttpic.h +++ b/src/3rdparty/freetype/src/truetype/ttpic.h @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for truetype module. */ /* */ -/* Copyright 2009 by */ +/* Copyright 2009, 2012, 2013 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -19,38 +19,60 @@ #ifndef __TTPIC_H__ #define __TTPIC_H__ - + FT_BEGIN_HEADER #ifndef FT_CONFIG_OPTION_PIC -#define FT_TT_SERVICES_GET tt_services -#define FT_TT_SERVICE_GX_MULTI_MASTERS_GET tt_service_gx_multi_masters -#define FT_TT_SERVICE_TRUETYPE_GLYF_GET tt_service_truetype_glyf + +#define TT_SERVICES_GET tt_services +#define TT_SERVICE_GX_MULTI_MASTERS_GET tt_service_gx_multi_masters +#define TT_SERVICE_TRUETYPE_GLYF_GET tt_service_truetype_glyf +#define TT_SERVICE_PROPERTIES_GET tt_service_properties #else /* FT_CONFIG_OPTION_PIC */ #include FT_MULTIPLE_MASTERS_H #include FT_SERVICE_MULTIPLE_MASTERS_H #include FT_SERVICE_TRUETYPE_GLYF_H +#include FT_SERVICE_PROPERTIES_H + - typedef struct TTModulePIC_ + typedef struct TTModulePIC_ { - FT_ServiceDescRec* tt_services; + FT_ServiceDescRec* tt_services; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - FT_Service_MultiMastersRec tt_service_gx_multi_masters; + FT_Service_MultiMastersRec tt_service_gx_multi_masters; #endif - FT_Service_TTGlyfRec tt_service_truetype_glyf; + FT_Service_TTGlyfRec tt_service_truetype_glyf; + FT_Service_PropertiesRec tt_service_properties; + } TTModulePIC; -#define GET_PIC(lib) ((TTModulePIC*)((lib)->pic_container.truetype)) -#define FT_TT_SERVICES_GET (GET_PIC(library)->tt_services) -#define FT_TT_SERVICE_GX_MULTI_MASTERS_GET (GET_PIC(library)->tt_service_gx_multi_masters) -#define FT_TT_SERVICE_TRUETYPE_GLYF_GET (GET_PIC(library)->tt_service_truetype_glyf) + +#define GET_PIC( lib ) \ + ( (TTModulePIC*)((lib)->pic_container.truetype) ) +#define TT_SERVICES_GET \ + ( GET_PIC( library )->tt_services ) +#define TT_SERVICE_GX_MULTI_MASTERS_GET \ + ( GET_PIC( library )->tt_service_gx_multi_masters ) +#define TT_SERVICE_TRUETYPE_GLYF_GET \ + ( GET_PIC( library )->tt_service_truetype_glyf ) +#define TT_SERVICE_PROPERTIES_GET \ + ( GET_PIC( library )->tt_service_properties ) + + + /* see ttpic.c for the implementation */ + void + tt_driver_class_pic_free( FT_Library library ); + + FT_Error + tt_driver_class_pic_init( FT_Library library ); #endif /* FT_CONFIG_OPTION_PIC */ /* */ + FT_END_HEADER #endif /* __TTPIC_H__ */ diff --git a/src/3rdparty/freetype/src/truetype/ttpload.c b/src/3rdparty/freetype/src/truetype/ttpload.c index ecdd7376e1..9991925425 100644 --- a/src/3rdparty/freetype/src/truetype/ttpload.c +++ b/src/3rdparty/freetype/src/truetype/ttpload.c @@ -4,7 +4,7 @@ /* */ /* TrueType-specific tables loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2002, 2004-2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -72,7 +72,7 @@ /* it is possible that a font doesn't have a glyf table at all */ /* or its size is zero */ - if ( error == TT_Err_Table_Missing ) + if ( FT_ERR_EQ( error, Table_Missing ) ) face->glyf_len = 0; else if ( error ) goto Exit; @@ -81,7 +81,7 @@ error = face->goto_table( face, TTAG_loca, stream, &table_len ); if ( error ) { - error = TT_Err_Locations_Missing; + error = FT_THROW( Locations_Missing ); goto Exit; } @@ -92,7 +92,7 @@ if ( table_len >= 0x40000L ) { FT_TRACE2(( "table too large\n" )); - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Exit; } face->num_locations = table_len >> shift; @@ -104,21 +104,22 @@ if ( table_len >= 0x20000L ) { FT_TRACE2(( "table too large\n" )); - error = TT_Err_Invalid_Table; + error = FT_THROW( Invalid_Table ); goto Exit; } face->num_locations = table_len >> shift; } - if ( face->num_locations != (FT_ULong)face->root.num_glyphs ) + if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 ) { FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n", - face->num_locations, face->root.num_glyphs )); + face->num_locations - 1, face->root.num_glyphs )); /* we only handle the case where `maxp' gives a larger value */ - if ( face->num_locations < (FT_ULong)face->root.num_glyphs ) + if ( face->num_locations <= (FT_ULong)face->root.num_glyphs ) { - FT_Long new_loca_len = (FT_Long)face->root.num_glyphs << shift; + FT_Long new_loca_len = + ( (FT_Long)( face->root.num_glyphs ) + 1 ) << shift; TT_Table entry = face->dir_tables; TT_Table limit = entry + face->num_tables; @@ -137,9 +138,15 @@ dist = diff; } + if ( entry == limit ) + { + /* `loca' is the last table */ + dist = stream->size - pos; + } + if ( new_loca_len <= dist ) { - face->num_locations = face->root.num_glyphs; + face->num_locations = face->root.num_glyphs + 1; table_len = new_loca_len; FT_TRACE2(( "adjusting num_locations to %d\n", @@ -203,6 +210,26 @@ } } + /* Check broken location data */ + if ( pos1 > face->glyf_len ) + { + FT_TRACE1(( "tt_face_get_location:" + " too large offset=0x%08lx found for gid=0x%04lx," + " exceeding the end of glyf table (0x%08lx)\n", + pos1, gindex, face->glyf_len )); + *asize = 0; + return 0; + } + + if ( pos2 > face->glyf_len ) + { + FT_TRACE1(( "tt_face_get_location:" + " too large offset=0x%08lx found for gid=0x%04lx," + " truncate at the end of glyf table (0x%08lx)\n", + pos2, gindex + 1, face->glyf_len )); + pos2 = face->glyf_len; + } + /* The `loca' table must be ordered; it refers to the length of */ /* an entry as the difference between the current and the next */ /* position. However, there do exist (malformed) fonts which */ @@ -269,7 +296,7 @@ face->cvt_size = 0; face->cvt = NULL; - error = TT_Err_Ok; + error = FT_Err_Ok; goto Exit; } @@ -287,7 +314,7 @@ FT_Short* limit = cur + face->cvt_size; - for ( ; cur < limit; cur++ ) + for ( ; cur < limit; cur++ ) *cur = FT_GET_SHORT(); } @@ -307,7 +334,7 @@ FT_UNUSED( face ); FT_UNUSED( stream ); - return TT_Err_Ok; + return FT_Err_Ok; #endif } @@ -348,7 +375,7 @@ { face->font_program = NULL; face->font_program_size = 0; - error = TT_Err_Ok; + error = FT_Err_Ok; FT_TRACE2(( "is missing\n" )); } @@ -369,7 +396,7 @@ FT_UNUSED( face ); FT_UNUSED( stream ); - return TT_Err_Ok; + return FT_Err_Ok; #endif } @@ -409,7 +436,7 @@ { face->cvt_program = NULL; face->cvt_program_size = 0; - error = TT_Err_Ok; + error = FT_Err_Ok; FT_TRACE2(( "is missing\n" )); } @@ -430,7 +457,7 @@ FT_UNUSED( face ); FT_UNUSED( stream ); - return TT_Err_Ok; + return FT_Err_Ok; #endif } @@ -468,7 +495,7 @@ /* this table is optional */ error = face->goto_table( face, TTAG_hdmx, stream, &table_size ); if ( error || table_size < 8 ) - return TT_Err_Ok; + return FT_Err_Ok; if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) ) goto Exit; @@ -481,9 +508,9 @@ record_size = FT_NEXT_ULONG( p ); /* The maximum number of bytes in an hdmx device record is the */ - /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */ - /* the reason why `record_size' is a long (which we read as */ - /* unsigned long for convenience). In practice, two bytes */ + /* maximum number of glyphs + 2; this is 0xFFFF + 2, thus */ + /* explaining why `record_size' is a long (which we read as */ + /* unsigned long for convenience). In practice, two bytes are */ /* sufficient to hold the size value. */ /* */ /* There are at least two fonts, HANNOM-A and HANNOM-B version */ @@ -495,10 +522,12 @@ record_size &= 0xFFFFU; /* The limit for `num_records' is a heuristic value. */ - - if ( version != 0 || num_records > 255 || record_size > 0x10001L ) + if ( version != 0 || + num_records > 255 || + record_size > 0x10001L || + record_size < 4 ) { - error = TT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -532,10 +561,10 @@ tt_face_free_hdmx( TT_Face face ) { FT_Stream stream = face->root.stream; - FT_Memory memory = stream ? stream->memory : NULL; + FT_Memory memory = stream->memory; + - if ( face->hdmx_record_sizes ) - FT_FREE( face->hdmx_record_sizes ); + FT_FREE( face->hdmx_record_sizes ); FT_FRAME_RELEASE( face->hdmx_table ); } diff --git a/src/3rdparty/freetype/src/truetype/ttsubpix.c b/src/3rdparty/freetype/src/truetype/ttsubpix.c new file mode 100644 index 0000000000..ca604518cf --- /dev/null +++ b/src/3rdparty/freetype/src/truetype/ttsubpix.c @@ -0,0 +1,1011 @@ +/***************************************************************************/ +/* */ +/* ttsubpix.c */ +/* */ +/* TrueType Subpixel Hinting. */ +/* */ +/* Copyright 2010-2013 by */ +/* 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. */ +/* */ +/***************************************************************************/ + +#include +#include FT_INTERNAL_DEBUG_H +#include FT_INTERNAL_CALC_H +#include FT_INTERNAL_STREAM_H +#include FT_INTERNAL_SFNT_H +#include FT_TRUETYPE_TAGS_H +#include FT_OUTLINE_H +#include FT_TRUETYPE_DRIVER_H + +#include "ttsubpix.h" + + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + /*************************************************************************/ + /* */ + /* These rules affect how the TT Interpreter does hinting, with the */ + /* goal of doing subpixel hinting by (in general) ignoring x moves. */ + /* Some of these rules are fixes that go above and beyond the */ + /* stated techniques in the MS whitepaper on Cleartype, due to */ + /* artifacts in many glyphs. So, these rules make some glyphs render */ + /* better than they do in the MS rasterizer. */ + /* */ + /* "" string or 0 int/char indicates to apply to all glyphs. */ + /* "-" used as dummy placeholders, but any non-matching string works. */ + /* */ + /* Some of this could arguably be implemented in fontconfig, however: */ + /* */ + /* - Fontconfig can't set things on a glyph-by-glyph basis. */ + /* - The tweaks that happen here are very low-level, from an average */ + /* user's point of view and are best implemented in the hinter. */ + /* */ + /* The goal is to make the subpixel hinting techniques as generalized */ + /* as possible across all fonts to prevent the need for extra rules such */ + /* as these. */ + /* */ + /* The rule structure is designed so that entirely new rules can easily */ + /* be added when a new compatibility feature is discovered. */ + /* */ + /* The rule structures could also use some enhancement to handle ranges. */ + /* */ + /* ****************** WORK IN PROGRESS ******************* */ + /* */ + + /* These are `classes' of fonts that can be grouped together and used in */ + /* rules below. A blank entry "" is required at the end of these! */ +#define FAMILY_CLASS_RULES_SIZE 7 + + static const SPH_Font_Class FAMILY_CLASS_Rules + [FAMILY_CLASS_RULES_SIZE] = + { + { "MS Legacy Fonts", + { "Aharoni", + "Andale Mono", + "Andalus", + "Angsana New", + "AngsanaUPC", + "Arabic Transparent", + "Arial Black", + "Arial Narrow", + "Arial Unicode MS", + "Arial", + "Batang", + "Browallia New", + "BrowalliaUPC", + "Comic Sans MS", + "Cordia New", + "CordiaUPC", + "Courier New", + "DFKai-SB", + "David Transparent", + "David", + "DilleniaUPC", + "Estrangelo Edessa", + "EucrosiaUPC", + "FangSong_GB2312", + "Fixed Miriam Transparent", + "FrankRuehl", + "Franklin Gothic Medium", + "FreesiaUPC", + "Garamond", + "Gautami", + "Georgia", + "Gulim", + "Impact", + "IrisUPC", + "JasmineUPC", + "KaiTi_GB2312", + "KodchiangUPC", + "Latha", + "Levenim MT", + "LilyUPC", + "Lucida Console", + "Lucida Sans Unicode", + "MS Gothic", + "MS Mincho", + "MV Boli", + "Mangal", + "Marlett", + "Microsoft Sans Serif", + "Mingliu", + "Miriam Fixed", + "Miriam Transparent", + "Miriam", + "Narkisim", + "Palatino Linotype", + "Raavi", + "Rod Transparent", + "Rod", + "Shruti", + "SimHei", + "Simplified Arabic Fixed", + "Simplified Arabic", + "Simsun", + "Sylfaen", + "Symbol", + "Tahoma", + "Times New Roman", + "Traditional Arabic", + "Trebuchet MS", + "Tunga", + "Verdana", + "Webdings", + "Wingdings", + "", + }, + }, + { "Core MS Legacy Fonts", + { "Arial Black", + "Arial Narrow", + "Arial Unicode MS", + "Arial", + "Comic Sans MS", + "Courier New", + "Garamond", + "Georgia", + "Impact", + "Lucida Console", + "Lucida Sans Unicode", + "Microsoft Sans Serif", + "Palatino Linotype", + "Tahoma", + "Times New Roman", + "Trebuchet MS", + "Verdana", + "", + }, + }, + { "Apple Legacy Fonts", + { "Geneva", + "Times", + "Monaco", + "Century", + "Chalkboard", + "Lobster", + "Century Gothic", + "Optima", + "Lucida Grande", + "Gill Sans", + "Baskerville", + "Helvetica", + "Helvetica Neue", + "", + }, + }, + { "Legacy Sans Fonts", + { "Andale Mono", + "Arial Unicode MS", + "Arial", + "Century Gothic", + "Comic Sans MS", + "Franklin Gothic Medium", + "Geneva", + "Lucida Console", + "Lucida Grande", + "Lucida Sans Unicode", + "Lucida Sans Typewriter", + "Microsoft Sans Serif", + "Monaco", + "Tahoma", + "Trebuchet MS", + "Verdana", + "", + }, + }, + + { "Misc Legacy Fonts", + { "Dark Courier", "", }, }, + { "Verdana Clones", + { "DejaVu Sans", + "Bitstream Vera Sans", "", }, }, + { "Verdana and Clones", + { "DejaVu Sans", + "Bitstream Vera Sans", + "Verdana", "", }, }, + }; + + + /* Define this to force natural (i.e. not bitmap-compatible) widths. */ + /* The default leans strongly towards natural widths except for a few */ + /* legacy fonts where a selective combination produces nicer results. */ +/* #define FORCE_NATURAL_WIDTHS */ + + + /* Define `classes' of styles that can be grouped together and used in */ + /* rules below. A blank entry "" is required at the end of these! */ +#define STYLE_CLASS_RULES_SIZE 5 + + const SPH_Font_Class STYLE_CLASS_Rules + [STYLE_CLASS_RULES_SIZE] = + { + { "Regular Class", + { "Regular", + "Book", + "Medium", + "Roman", + "Normal", + "", + }, + }, + { "Regular/Italic Class", + { "Regular", + "Book", + "Medium", + "Italic", + "Oblique", + "Roman", + "Normal", + "", + }, + }, + { "Bold/BoldItalic Class", + { "Bold", + "Bold Italic", + "Black", + "", + }, + }, + { "Bold/Italic/BoldItalic Class", + { "Bold", + "Bold Italic", + "Black", + "Italic", + "Oblique", + "", + }, + }, + { "Regular/Bold Class", + { "Regular", + "Book", + "Medium", + "Normal", + "Roman", + "Bold", + "Black", + "", + }, + }, + }; + + + /* Force special legacy fixes for fonts. */ +#define COMPATIBILITY_MODE_RULES_SIZE 1 + + const SPH_TweakRule COMPATIBILITY_MODE_Rules + [COMPATIBILITY_MODE_RULES_SIZE] = + { + { "Verdana Clones", 0, "", 0 }, + }; + + + /* Don't do subpixel (ignore_x_mode) hinting; do normal hinting. */ +#define PIXEL_HINTING_RULES_SIZE 2 + + const SPH_TweakRule PIXEL_HINTING_Rules + [PIXEL_HINTING_RULES_SIZE] = + { + /* these characters are almost always safe */ + { "Courier New", 12, "Italic", 'z' }, + { "Courier New", 11, "Italic", 'z' }, + }; + + + /* Subpixel hinting ignores SHPIX rules on X. Force SHPIX for these. */ +#define DO_SHPIX_RULES_SIZE 1 + + const SPH_TweakRule DO_SHPIX_Rules + [DO_SHPIX_RULES_SIZE] = + { + { "-", 0, "", 0 }, + }; + + + /* Skip Y moves that start with a point that is not on a Y pixel */ + /* boundary and don't move that point to a Y pixel boundary. */ +#define SKIP_NONPIXEL_Y_MOVES_RULES_SIZE 4 + + const SPH_TweakRule SKIP_NONPIXEL_Y_MOVES_Rules + [SKIP_NONPIXEL_Y_MOVES_RULES_SIZE] = + { + /* fix vwxyz thinness*/ + { "Consolas", 0, "", 0 }, + /* Fix thin middle stems */ + { "Core MS Legacy Fonts", 0, "Regular", 0 }, + /* Cyrillic small letter I */ + { "Legacy Sans Fonts", 0, "", 0 }, + /* Fix artifacts with some Regular & Bold */ + { "Verdana Clones", 0, "", 0 }, + }; + + +#define SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE 1 + + const SPH_TweakRule SKIP_NONPIXEL_Y_MOVES_Rules_Exceptions + [SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] = + { + /* Fixes < and > */ + { "Courier New", 0, "Regular", 0 }, + }; + + + /* Skip Y moves that start with a point that is not on a Y pixel */ + /* boundary and don't move that point to a Y pixel boundary. */ +#define SKIP_NONPIXEL_Y_MOVES_DELTAP_RULES_SIZE 2 + + const SPH_TweakRule SKIP_NONPIXEL_Y_MOVES_DELTAP_Rules + [SKIP_NONPIXEL_Y_MOVES_DELTAP_RULES_SIZE] = + { + /* Maintain thickness of diagonal in 'N' */ + { "Times New Roman", 0, "Regular/Bold Class", 'N' }, + { "Georgia", 0, "Regular/Bold Class", 'N' }, + }; + + + /* Skip Y moves that move a point off a Y pixel boundary. */ +#define SKIP_OFFPIXEL_Y_MOVES_RULES_SIZE 1 + + const SPH_TweakRule SKIP_OFFPIXEL_Y_MOVES_Rules + [SKIP_OFFPIXEL_Y_MOVES_RULES_SIZE] = + { + { "-", 0, "", 0 }, + }; + + +#define SKIP_OFFPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE 1 + + const SPH_TweakRule SKIP_OFFPIXEL_Y_MOVES_Rules_Exceptions + [SKIP_OFFPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] = + { + { "-", 0, "", 0 }, + }; + + + /* Round moves that don't move a point to a Y pixel boundary. */ +#define ROUND_NONPIXEL_Y_MOVES_RULES_SIZE 2 + + const SPH_TweakRule ROUND_NONPIXEL_Y_MOVES_Rules + [ROUND_NONPIXEL_Y_MOVES_RULES_SIZE] = + { + /* Droid font instructions don't snap Y to pixels */ + { "Droid Sans", 0, "Regular/Italic Class", 0 }, + { "Droid Sans Mono", 0, "", 0 }, + }; + + +#define ROUND_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE 1 + + const SPH_TweakRule ROUND_NONPIXEL_Y_MOVES_Rules_Exceptions + [ROUND_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] = + { + { "-", 0, "", 0 }, + }; + + + /* Allow a Direct_Move along X freedom vector if matched. */ +#define ALLOW_X_DMOVE_RULES_SIZE 1 + + const SPH_TweakRule ALLOW_X_DMOVE_Rules + [ALLOW_X_DMOVE_RULES_SIZE] = + { + /* Fixes vanishing diagonal in 4 */ + { "Verdana", 0, "Regular", '4' }, + }; + + + /* Return MS rasterizer version 35 if matched. */ +#define RASTERIZER_35_RULES_SIZE 8 + + const SPH_TweakRule RASTERIZER_35_Rules + [RASTERIZER_35_RULES_SIZE] = + { + /* This seems to be the only way to make these look good */ + { "Times New Roman", 0, "Regular", 'i' }, + { "Times New Roman", 0, "Regular", 'j' }, + { "Times New Roman", 0, "Regular", 'm' }, + { "Times New Roman", 0, "Regular", 'r' }, + { "Times New Roman", 0, "Regular", 'a' }, + { "Times New Roman", 0, "Regular", 'n' }, + { "Times New Roman", 0, "Regular", 'p' }, + { "Times", 0, "", 0 }, + }; + + + /* Don't round to the subpixel grid. Round to pixel grid. */ +#define NORMAL_ROUND_RULES_SIZE 1 + + const SPH_TweakRule NORMAL_ROUND_Rules + [NORMAL_ROUND_RULES_SIZE] = + { + /* Fix serif thickness for certain ppems */ + /* Can probably be generalized somehow */ + { "Courier New", 0, "", 0 }, + }; + + + /* Skip IUP instructions if matched. */ +#define SKIP_IUP_RULES_SIZE 1 + + const SPH_TweakRule SKIP_IUP_Rules + [SKIP_IUP_RULES_SIZE] = + { + { "Arial", 13, "Regular", 'a' }, + }; + + + /* Skip MIAP Twilight hack if matched. */ +#define MIAP_HACK_RULES_SIZE 1 + + const SPH_TweakRule MIAP_HACK_Rules + [MIAP_HACK_RULES_SIZE] = + { + { "Geneva", 12, "", 0 }, + }; + + + /* Skip DELTAP instructions if matched. */ +#define ALWAYS_SKIP_DELTAP_RULES_SIZE 23 + + const SPH_TweakRule ALWAYS_SKIP_DELTAP_Rules + [ALWAYS_SKIP_DELTAP_RULES_SIZE] = + { + { "Georgia", 0, "Regular", 'k' }, + /* fix various problems with e in different versions */ + { "Trebuchet MS", 14, "Regular", 'e' }, + { "Trebuchet MS", 13, "Regular", 'e' }, + { "Trebuchet MS", 15, "Regular", 'e' }, + { "Trebuchet MS", 0, "Italic", 'v' }, + { "Trebuchet MS", 0, "Italic", 'w' }, + { "Trebuchet MS", 0, "Regular", 'Y' }, + { "Arial", 11, "Regular", 's' }, + /* prevent problems with '3' and others */ + { "Verdana", 10, "Regular", 0 }, + { "Verdana", 9, "Regular", 0 }, + /* Cyrillic small letter short I */ + { "Legacy Sans Fonts", 0, "", 0x438 }, + { "Legacy Sans Fonts", 0, "", 0x439 }, + { "Arial", 10, "Regular", '6' }, + { "Arial", 0, "Bold/BoldItalic Class", 'a' }, + /* Make horizontal stems consistent with the rest */ + { "Arial", 24, "Bold", 'a' }, + { "Arial", 25, "Bold", 'a' }, + { "Arial", 24, "Bold", 's' }, + { "Arial", 25, "Bold", 's' }, + { "Arial", 34, "Bold", 's' }, + { "Arial", 35, "Bold", 's' }, + { "Arial", 36, "Bold", 's' }, + { "Arial", 25, "Regular", 's' }, + { "Arial", 26, "Regular", 's' }, + }; + + + /* Always do DELTAP instructions if matched. */ +#define ALWAYS_DO_DELTAP_RULES_SIZE 1 + + const SPH_TweakRule ALWAYS_DO_DELTAP_Rules + [ALWAYS_DO_DELTAP_RULES_SIZE] = + { + { "-", 0, "", 0 }, + }; + + + /* Don't allow ALIGNRP after IUP. */ +#define NO_ALIGNRP_AFTER_IUP_RULES_SIZE 1 + + static const SPH_TweakRule NO_ALIGNRP_AFTER_IUP_Rules + [NO_ALIGNRP_AFTER_IUP_RULES_SIZE] = + { + /* Prevent creation of dents in outline */ + { "-", 0, "", 0 }, + }; + + + /* Don't allow DELTAP after IUP. */ +#define NO_DELTAP_AFTER_IUP_RULES_SIZE 1 + + static const SPH_TweakRule NO_DELTAP_AFTER_IUP_Rules + [NO_DELTAP_AFTER_IUP_RULES_SIZE] = + { + { "-", 0, "", 0 }, + }; + + + /* Don't allow CALL after IUP. */ +#define NO_CALL_AFTER_IUP_RULES_SIZE 1 + + static const SPH_TweakRule NO_CALL_AFTER_IUP_Rules + [NO_CALL_AFTER_IUP_RULES_SIZE] = + { + /* Prevent creation of dents in outline */ + { "-", 0, "", 0 }, + }; + + + /* De-embolden these glyphs slightly. */ +#define DEEMBOLDEN_RULES_SIZE 9 + + static const SPH_TweakRule DEEMBOLDEN_Rules + [DEEMBOLDEN_RULES_SIZE] = + { + { "Courier New", 0, "Bold", 'A' }, + { "Courier New", 0, "Bold", 'W' }, + { "Courier New", 0, "Bold", 'w' }, + { "Courier New", 0, "Bold", 'M' }, + { "Courier New", 0, "Bold", 'X' }, + { "Courier New", 0, "Bold", 'K' }, + { "Courier New", 0, "Bold", 'x' }, + { "Courier New", 0, "Bold", 'z' }, + { "Courier New", 0, "Bold", 'v' }, + }; + + + /* Embolden these glyphs slightly. */ +#define EMBOLDEN_RULES_SIZE 2 + + static const SPH_TweakRule EMBOLDEN_Rules + [EMBOLDEN_RULES_SIZE] = + { + { "Courier New", 0, "Regular", 0 }, + { "Courier New", 0, "Italic", 0 }, + }; + + + /* This is a CVT hack that makes thick horizontal stems on 2, 5, 7 */ + /* similar to Windows XP. */ +#define TIMES_NEW_ROMAN_HACK_RULES_SIZE 12 + + static const SPH_TweakRule TIMES_NEW_ROMAN_HACK_Rules + [TIMES_NEW_ROMAN_HACK_RULES_SIZE] = + { + { "Times New Roman", 16, "Italic", '2' }, + { "Times New Roman", 16, "Italic", '5' }, + { "Times New Roman", 16, "Italic", '7' }, + { "Times New Roman", 16, "Regular", '2' }, + { "Times New Roman", 16, "Regular", '5' }, + { "Times New Roman", 16, "Regular", '7' }, + { "Times New Roman", 17, "Italic", '2' }, + { "Times New Roman", 17, "Italic", '5' }, + { "Times New Roman", 17, "Italic", '7' }, + { "Times New Roman", 17, "Regular", '2' }, + { "Times New Roman", 17, "Regular", '5' }, + { "Times New Roman", 17, "Regular", '7' }, + }; + + + /* This fudges distance on 2 to get rid of the vanishing stem issue. */ + /* A real solution to this is certainly welcome. */ +#define COURIER_NEW_2_HACK_RULES_SIZE 15 + + static const SPH_TweakRule COURIER_NEW_2_HACK_Rules + [COURIER_NEW_2_HACK_RULES_SIZE] = + { + { "Courier New", 10, "Regular", '2' }, + { "Courier New", 11, "Regular", '2' }, + { "Courier New", 12, "Regular", '2' }, + { "Courier New", 13, "Regular", '2' }, + { "Courier New", 14, "Regular", '2' }, + { "Courier New", 15, "Regular", '2' }, + { "Courier New", 16, "Regular", '2' }, + { "Courier New", 17, "Regular", '2' }, + { "Courier New", 18, "Regular", '2' }, + { "Courier New", 19, "Regular", '2' }, + { "Courier New", 20, "Regular", '2' }, + { "Courier New", 21, "Regular", '2' }, + { "Courier New", 22, "Regular", '2' }, + { "Courier New", 23, "Regular", '2' }, + { "Courier New", 24, "Regular", '2' }, + }; + + +#ifndef FORCE_NATURAL_WIDTHS + + /* Use compatible widths with these glyphs. Compatible widths is always */ + /* on when doing B/W TrueType instructing, but is used selectively here, */ + /* typically on glyphs with 3 or more vertical stems. */ +#define COMPATIBLE_WIDTHS_RULES_SIZE 38 + + static const SPH_TweakRule COMPATIBLE_WIDTHS_Rules + [COMPATIBLE_WIDTHS_RULES_SIZE] = + { + { "Arial Unicode MS", 12, "Regular Class", 'm' }, + { "Arial Unicode MS", 14, "Regular Class", 'm' }, + /* Cyrillic small letter sha */ + { "Arial", 10, "Regular Class", 0x448 }, + { "Arial", 11, "Regular Class", 'm' }, + { "Arial", 12, "Regular Class", 'm' }, + /* Cyrillic small letter sha */ + { "Arial", 12, "Regular Class", 0x448 }, + { "Arial", 13, "Regular Class", 0x448 }, + { "Arial", 14, "Regular Class", 'm' }, + /* Cyrillic small letter sha */ + { "Arial", 14, "Regular Class", 0x448 }, + { "Arial", 15, "Regular Class", 0x448 }, + { "Arial", 17, "Regular Class", 'm' }, + { "DejaVu Sans", 15, "Regular Class", 0 }, + { "Microsoft Sans Serif", 11, "Regular Class", 0 }, + { "Microsoft Sans Serif", 12, "Regular Class", 0 }, + { "Segoe UI", 11, "Regular Class", 0 }, + { "Monaco", 0, "Regular Class", 0 }, + { "Segoe UI", 12, "Regular Class", 'm' }, + { "Segoe UI", 14, "Regular Class", 'm' }, + { "Tahoma", 11, "Regular Class", 0 }, + { "Times New Roman", 16, "Regular Class", 'c' }, + { "Times New Roman", 16, "Regular Class", 'm' }, + { "Times New Roman", 16, "Regular Class", 'o' }, + { "Times New Roman", 16, "Regular Class", 'w' }, + { "Trebuchet MS", 11, "Regular Class", 0 }, + { "Trebuchet MS", 12, "Regular Class", 0 }, + { "Trebuchet MS", 14, "Regular Class", 0 }, + { "Trebuchet MS", 15, "Regular Class", 0 }, + { "Ubuntu", 12, "Regular Class", 'm' }, + /* Cyrillic small letter sha */ + { "Verdana", 10, "Regular Class", 0x448 }, + { "Verdana", 11, "Regular Class", 0x448 }, + { "Verdana and Clones", 12, "Regular Class", 'i' }, + { "Verdana and Clones", 12, "Regular Class", 'j' }, + { "Verdana and Clones", 12, "Regular Class", 'l' }, + { "Verdana and Clones", 12, "Regular Class", 'm' }, + { "Verdana and Clones", 13, "Regular Class", 'i' }, + { "Verdana and Clones", 13, "Regular Class", 'j' }, + { "Verdana and Clones", 13, "Regular Class", 'l' }, + { "Verdana and Clones", 14, "Regular Class", 'm' }, + }; + + + /* Scaling slightly in the x-direction prior to hinting results in */ + /* more visually pleasing glyphs in certain cases. */ + /* This sometimes needs to be coordinated with compatible width rules. */ + /* A value of 1000 corresponds to a scaled value of 1.0. */ + +#define X_SCALING_RULES_SIZE 50 + + static const SPH_ScaleRule X_SCALING_Rules[X_SCALING_RULES_SIZE] = + { + { "DejaVu Sans", 12, "Regular Class", 'm', 950 }, + { "Verdana and Clones", 12, "Regular Class", 'a', 1100 }, + { "Verdana and Clones", 13, "Regular Class", 'a', 1050 }, + { "Arial", 11, "Regular Class", 'm', 975 }, + { "Arial", 12, "Regular Class", 'm', 1050 }, + /* Cyrillic small letter el */ + { "Arial", 13, "Regular Class", 0x43B, 950 }, + { "Arial", 13, "Regular Class", 'o', 950 }, + { "Arial", 13, "Regular Class", 'e', 950 }, + { "Arial", 14, "Regular Class", 'm', 950 }, + /* Cyrillic small letter el */ + { "Arial", 15, "Regular Class", 0x43B, 925 }, + { "Bitstream Vera Sans", 10, "Regular/Italic Class", 0, 1100 }, + { "Bitstream Vera Sans", 12, "Regular/Italic Class", 0, 1050 }, + { "Bitstream Vera Sans", 16, "Regular Class", 0, 1050 }, + { "Bitstream Vera Sans", 9, "Regular/Italic Class", 0, 1050 }, + { "DejaVu Sans", 12, "Regular Class", 'l', 975 }, + { "DejaVu Sans", 12, "Regular Class", 'i', 975 }, + { "DejaVu Sans", 12, "Regular Class", 'j', 975 }, + { "DejaVu Sans", 13, "Regular Class", 'l', 950 }, + { "DejaVu Sans", 13, "Regular Class", 'i', 950 }, + { "DejaVu Sans", 13, "Regular Class", 'j', 950 }, + { "DejaVu Sans", 10, "Regular/Italic Class", 0, 1100 }, + { "DejaVu Sans", 12, "Regular/Italic Class", 0, 1050 }, + { "Georgia", 10, "", 0, 1050 }, + { "Georgia", 11, "", 0, 1100 }, + { "Georgia", 12, "", 0, 1025 }, + { "Georgia", 13, "", 0, 1050 }, + { "Georgia", 16, "", 0, 1050 }, + { "Georgia", 17, "", 0, 1030 }, + { "Liberation Sans", 12, "Regular Class", 'm', 1100 }, + { "Lucida Grande", 11, "Regular Class", 'm', 1100 }, + { "Microsoft Sans Serif", 11, "Regular Class", 'm', 950 }, + { "Microsoft Sans Serif", 12, "Regular Class", 'm', 1050 }, + { "Segoe UI", 12, "Regular Class", 'H', 1050 }, + { "Segoe UI", 12, "Regular Class", 'm', 1050 }, + { "Segoe UI", 14, "Regular Class", 'm', 1050 }, + { "Tahoma", 11, "Regular Class", 'i', 975 }, + { "Tahoma", 11, "Regular Class", 'l', 975 }, + { "Tahoma", 11, "Regular Class", 'j', 900 }, + { "Tahoma", 11, "Regular Class", 'm', 918 }, + { "Verdana", 10, "Regular/Italic Class", 0, 1100 }, + { "Verdana", 12, "Regular Class", 'm', 975 }, + { "Verdana", 12, "Regular/Italic Class", 0, 1050 }, + { "Verdana", 13, "Regular/Italic Class", 'i', 950 }, + { "Verdana", 13, "Regular/Italic Class", 'j', 950 }, + { "Verdana", 13, "Regular/Italic Class", 'l', 950 }, + { "Verdana", 16, "Regular Class", 0, 1050 }, + { "Verdana", 9, "Regular/Italic Class", 0, 1050 }, + { "Times New Roman", 16, "Regular Class", 'm', 918 }, + { "Trebuchet MS", 11, "Regular Class", 'm', 800 }, + { "Trebuchet MS", 12, "Regular Class", 'm', 800 }, + }; + +#else + +#define COMPATIBLE_WIDTHS_RULES_SIZE 1 + + static const SPH_TweakRule COMPATIBLE_WIDTHS_Rules + [COMPATIBLE_WIDTHS_RULES_SIZE] = + { + { "-", 0, "", 0 }, + }; + + +#define X_SCALING_RULES_SIZE 1 + + static const SPH_ScaleRule X_SCALING_Rules + [X_SCALING_RULES_SIZE] = + { + { "-", 0, "", 0, 1000 }, + }; + +#endif /* FORCE_NATURAL_WIDTHS */ + + + FT_LOCAL_DEF( FT_Bool ) + is_member_of_family_class( const FT_String* detected_font_name, + const FT_String* rule_font_name ) + { + FT_UInt i, j; + + + /* Does font name match rule family? */ + if ( strcmp( detected_font_name, rule_font_name ) == 0 ) + return TRUE; + + /* Is font name a wildcard ""? */ + if ( strcmp( rule_font_name, "" ) == 0 ) + return TRUE; + + /* Is font name contained in a class list? */ + for ( i = 0; i < FAMILY_CLASS_RULES_SIZE; i++ ) + { + if ( strcmp( FAMILY_CLASS_Rules[i].name, rule_font_name ) == 0 ) + { + for ( j = 0; j < SPH_MAX_CLASS_MEMBERS; j++ ) + { + if ( strcmp( FAMILY_CLASS_Rules[i].member[j], "" ) == 0 ) + continue; + if ( strcmp( FAMILY_CLASS_Rules[i].member[j], + detected_font_name ) == 0 ) + return TRUE; + } + } + } + + return FALSE; + } + + + FT_LOCAL_DEF( FT_Bool ) + is_member_of_style_class( const FT_String* detected_font_style, + const FT_String* rule_font_style ) + { + FT_UInt i, j; + + + /* Does font style match rule style? */ + if ( strcmp( detected_font_style, rule_font_style ) == 0 ) + return TRUE; + + /* Is font style a wildcard ""? */ + if ( strcmp( rule_font_style, "" ) == 0 ) + return TRUE; + + /* Is font style contained in a class list? */ + for ( i = 0; i < STYLE_CLASS_RULES_SIZE; i++ ) + { + if ( strcmp( STYLE_CLASS_Rules[i].name, rule_font_style ) == 0 ) + { + for ( j = 0; j < SPH_MAX_CLASS_MEMBERS; j++ ) + { + if ( strcmp( STYLE_CLASS_Rules[i].member[j], "" ) == 0 ) + continue; + if ( strcmp( STYLE_CLASS_Rules[i].member[j], + detected_font_style ) == 0 ) + return TRUE; + } + } + } + + return FALSE; + } + + + FT_LOCAL_DEF( FT_Bool ) + sph_test_tweak( TT_Face face, + const FT_String* family, + FT_UInt ppem, + const FT_String* style, + FT_UInt glyph_index, + const SPH_TweakRule* rule, + FT_UInt num_rules ) + { + FT_UInt i; + + + /* rule checks may be able to be optimized further */ + for ( i = 0; i < num_rules; i++ ) + { + if ( family && + ( is_member_of_family_class ( family, rule[i].family ) ) ) + if ( rule[i].ppem == 0 || + rule[i].ppem == ppem ) + if ( style && + is_member_of_style_class ( style, rule[i].style ) ) + if ( rule[i].glyph == 0 || + FT_Get_Char_Index( (FT_Face)face, + rule[i].glyph ) == glyph_index ) + return TRUE; + } + + return FALSE; + } + + + static FT_UInt + scale_test_tweak( TT_Face face, + const FT_String* family, + FT_UInt ppem, + const FT_String* style, + FT_UInt glyph_index, + const SPH_ScaleRule* rule, + FT_UInt num_rules ) + { + FT_UInt i; + + + /* rule checks may be able to be optimized further */ + for ( i = 0; i < num_rules; i++ ) + { + if ( family && + ( is_member_of_family_class ( family, rule[i].family ) ) ) + if ( rule[i].ppem == 0 || + rule[i].ppem == ppem ) + if ( style && + is_member_of_style_class( style, rule[i].style ) ) + if ( rule[i].glyph == 0 || + FT_Get_Char_Index( (FT_Face)face, + rule[i].glyph ) == glyph_index ) + return rule[i].scale; + } + + return 1000; + } + + + FT_LOCAL_DEF( FT_UInt ) + sph_test_tweak_x_scaling( TT_Face face, + const FT_String* family, + FT_UInt ppem, + const FT_String* style, + FT_UInt glyph_index ) + { + return scale_test_tweak( face, family, ppem, style, glyph_index, + X_SCALING_Rules, X_SCALING_RULES_SIZE ); + } + + +#define TWEAK_RULES( x ) \ + if ( sph_test_tweak( face, family, ppem, style, glyph_index, \ + x##_Rules, x##_RULES_SIZE ) ) \ + loader->exec->sph_tweak_flags |= SPH_TWEAK_##x; + +#define TWEAK_RULES_EXCEPTIONS( x ) \ + if ( sph_test_tweak( face, family, ppem, style, glyph_index, \ + x##_Rules_Exceptions, x##_RULES_EXCEPTIONS_SIZE ) ) \ + loader->exec->sph_tweak_flags &= ~SPH_TWEAK_##x; + + + FT_LOCAL_DEF( void ) + sph_set_tweaks( TT_Loader loader, + FT_UInt glyph_index ) + { + TT_Face face = (TT_Face)loader->face; + FT_String* family = face->root.family_name; + int ppem = loader->size->metrics.x_ppem; + FT_String* style = face->root.style_name; + + + /* don't apply rules if style isn't set */ + if ( !face->root.style_name ) + return; + +#ifdef SPH_DEBUG_MORE_VERBOSE + printf( "%s,%d,%s,%c=%d ", + family, ppem, style, glyph_index, glyph_index ); +#endif + + TWEAK_RULES( PIXEL_HINTING ); + + if ( loader->exec->sph_tweak_flags & SPH_TWEAK_PIXEL_HINTING ) + { + loader->exec->ignore_x_mode = FALSE; + return; + } + + TWEAK_RULES( ALLOW_X_DMOVE ); + TWEAK_RULES( ALWAYS_DO_DELTAP ); + TWEAK_RULES( ALWAYS_SKIP_DELTAP ); + TWEAK_RULES( DEEMBOLDEN ); + TWEAK_RULES( DO_SHPIX ); + TWEAK_RULES( EMBOLDEN ); + TWEAK_RULES( MIAP_HACK ); + TWEAK_RULES( NORMAL_ROUND ); + TWEAK_RULES( NO_ALIGNRP_AFTER_IUP ); + TWEAK_RULES( NO_CALL_AFTER_IUP ); + TWEAK_RULES( NO_DELTAP_AFTER_IUP ); + TWEAK_RULES( RASTERIZER_35 ); + TWEAK_RULES( SKIP_IUP ); + + TWEAK_RULES( SKIP_OFFPIXEL_Y_MOVES ); + TWEAK_RULES_EXCEPTIONS( SKIP_OFFPIXEL_Y_MOVES ); + + TWEAK_RULES( SKIP_NONPIXEL_Y_MOVES_DELTAP ); + + TWEAK_RULES( SKIP_NONPIXEL_Y_MOVES ); + TWEAK_RULES_EXCEPTIONS( SKIP_NONPIXEL_Y_MOVES ); + + TWEAK_RULES( ROUND_NONPIXEL_Y_MOVES ); + TWEAK_RULES_EXCEPTIONS( ROUND_NONPIXEL_Y_MOVES ); + + if ( loader->exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 ) + { + if ( loader->exec->rasterizer_version != TT_INTERPRETER_VERSION_35 ) + { + loader->exec->rasterizer_version = TT_INTERPRETER_VERSION_35; + loader->exec->size->cvt_ready = -1; + + tt_size_ready_bytecode( + loader->exec->size, + FT_BOOL( loader->load_flags & FT_LOAD_PEDANTIC ) ); + } + else + loader->exec->rasterizer_version = TT_INTERPRETER_VERSION_35; + } + else + { + if ( loader->exec->rasterizer_version != + SPH_OPTION_SET_RASTERIZER_VERSION ) + { + loader->exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; + loader->exec->size->cvt_ready = -1; + + tt_size_ready_bytecode( + loader->exec->size, + FT_BOOL( loader->load_flags & FT_LOAD_PEDANTIC ) ); + } + else + loader->exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; + } + + if ( IS_HINTED( loader->load_flags ) ) + { + TWEAK_RULES( TIMES_NEW_ROMAN_HACK ); + TWEAK_RULES( COURIER_NEW_2_HACK ); + } + + if ( sph_test_tweak( face, family, ppem, style, glyph_index, + COMPATIBILITY_MODE_Rules, COMPATIBILITY_MODE_RULES_SIZE ) ) + loader->exec->face->sph_compatibility_mode = TRUE; + + + if ( IS_HINTED( loader->load_flags ) ) + { + if ( sph_test_tweak( face, family, ppem, style, glyph_index, + COMPATIBLE_WIDTHS_Rules, COMPATIBLE_WIDTHS_RULES_SIZE ) ) + loader->exec->compatible_widths |= TRUE; + } + } + +#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + /* ANSI C doesn't like empty source files */ + typedef int _tt_subpix_dummy; + +#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + +/* END */ diff --git a/src/3rdparty/freetype/src/truetype/ttsubpix.h b/src/3rdparty/freetype/src/truetype/ttsubpix.h new file mode 100644 index 0000000000..8a54fc7cc7 --- /dev/null +++ b/src/3rdparty/freetype/src/truetype/ttsubpix.h @@ -0,0 +1,110 @@ +/***************************************************************************/ +/* */ +/* ttsubpix.h */ +/* */ +/* TrueType Subpixel Hinting. */ +/* */ +/* Copyright 2010-2013 by */ +/* 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. */ +/* */ +/***************************************************************************/ + + +#ifndef __TTSUBPIX_H__ +#define __TTSUBPIX_H__ + +#include +#include "ttobjs.h" +#include "ttinterp.h" + + +FT_BEGIN_HEADER + + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING + + /*************************************************************************/ + /* */ + /* ID flags to identify special functions at FDEF and runtime. */ + /* */ + /* */ +#define SPH_FDEF_INLINE_DELTA_1 0x0000001 +#define SPH_FDEF_INLINE_DELTA_2 0x0000002 +#define SPH_FDEF_DIAGONAL_STROKE 0x0000004 +#define SPH_FDEF_VACUFORM_ROUND_1 0x0000008 +#define SPH_FDEF_TTFAUTOHINT_1 0x0000010 +#define SPH_FDEF_SPACING_1 0x0000020 +#define SPH_FDEF_SPACING_2 0x0000040 +#define SPH_FDEF_TYPEMAN_STROKES 0x0000080 +#define SPH_FDEF_TYPEMAN_DIAGENDCTRL 0x0000100 + + + /*************************************************************************/ + /* */ + /* Tweak flags that are set for each glyph by the below rules. */ + /* */ + /* */ +#define SPH_TWEAK_ALLOW_X_DMOVE 0x0000001 +#define SPH_TWEAK_ALWAYS_DO_DELTAP 0x0000002 +#define SPH_TWEAK_ALWAYS_SKIP_DELTAP 0x0000004 +#define SPH_TWEAK_COURIER_NEW_2_HACK 0x0000008 +#define SPH_TWEAK_DEEMBOLDEN 0x0000010 +#define SPH_TWEAK_DO_SHPIX 0x0000020 +#define SPH_TWEAK_EMBOLDEN 0x0000040 +#define SPH_TWEAK_MIAP_HACK 0x0000080 +#define SPH_TWEAK_NORMAL_ROUND 0x0000100 +#define SPH_TWEAK_NO_ALIGNRP_AFTER_IUP 0x0000200 +#define SPH_TWEAK_NO_CALL_AFTER_IUP 0x0000400 +#define SPH_TWEAK_NO_DELTAP_AFTER_IUP 0x0000800 +#define SPH_TWEAK_PIXEL_HINTING 0x0001000 +#define SPH_TWEAK_RASTERIZER_35 0x0002000 +#define SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES 0x0004000 +#define SPH_TWEAK_SKIP_IUP 0x0008000 +#define SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES 0x0010000 +#define SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES 0x0020000 +#define SPH_TWEAK_TIMES_NEW_ROMAN_HACK 0x0040000 +#define SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP 0x0080000 + + + FT_LOCAL( FT_Bool ) + sph_test_tweak( TT_Face face, + const FT_String* family, + FT_UInt ppem, + const FT_String* style, + FT_UInt glyph_index, + const SPH_TweakRule* rule, + FT_UInt num_rules ); + + FT_LOCAL( FT_UInt ) + sph_test_tweak_x_scaling( TT_Face face, + const FT_String* family, + FT_UInt ppem, + const FT_String* style, + FT_UInt glyph_index ); + + FT_LOCAL( void ) + sph_set_tweaks( TT_Loader loader, + FT_UInt glyph_index ); + + + /* These macros are defined absent a method for setting them */ +#define SPH_OPTION_BITMAP_WIDTHS FALSE +#define SPH_OPTION_SET_SUBPIXEL TRUE +#define SPH_OPTION_SET_GRAYSCALE FALSE +#define SPH_OPTION_SET_COMPATIBLE_WIDTHS FALSE +#define SPH_OPTION_SET_RASTERIZER_VERSION 38 + +#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ + + +FT_END_HEADER + +#endif /* __TTSUBPIX_H__ */ + +/* END */ -- cgit v1.2.3