From 02280535bea08395871722f733aaaed70c992260 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 10 Dec 2018 14:59:49 +0100 Subject: Update bundled Freetype to 2.9.1 This is required to support the new emoji font on Android 9. [ChangeLog][Freetype] Upgraded bundled Freetype version to 2.9.1. This also adds support for the latest emoji font in use on Android 9. Fixes: QTBUG-70657 Change-Id: I99be72f0d23c20aca122b8fdadd4ded87b2edce1 Reviewed-by: Konstantin Ritt --- src/3rdparty/freetype/src/cid/Jamfile | 2 +- src/3rdparty/freetype/src/cid/ciderrs.h | 10 +- src/3rdparty/freetype/src/cid/cidgload.c | 123 ++++++++++++++++++---- src/3rdparty/freetype/src/cid/cidgload.h | 8 +- src/3rdparty/freetype/src/cid/cidload.c | 171 ++++++++++++++++++++++++++++--- src/3rdparty/freetype/src/cid/cidload.h | 8 +- src/3rdparty/freetype/src/cid/cidobjs.c | 50 +++++++-- src/3rdparty/freetype/src/cid/cidobjs.h | 8 +- src/3rdparty/freetype/src/cid/cidparse.c | 93 ++++++++++++----- src/3rdparty/freetype/src/cid/cidparse.h | 8 +- src/3rdparty/freetype/src/cid/cidriver.c | 82 +++++++++------ src/3rdparty/freetype/src/cid/cidriver.h | 8 +- src/3rdparty/freetype/src/cid/cidtoken.h | 2 +- src/3rdparty/freetype/src/cid/module.mk | 2 +- src/3rdparty/freetype/src/cid/rules.mk | 2 +- src/3rdparty/freetype/src/cid/type1cid.c | 8 +- 16 files changed, 454 insertions(+), 131 deletions(-) (limited to 'src/3rdparty/freetype/src/cid') diff --git a/src/3rdparty/freetype/src/cid/Jamfile b/src/3rdparty/freetype/src/cid/Jamfile index 64e1523157..1c232fda3f 100644 --- a/src/3rdparty/freetype/src/cid/Jamfile +++ b/src/3rdparty/freetype/src/cid/Jamfile @@ -1,6 +1,6 @@ # FreeType 2 src/cid Jamfile # -# Copyright 2001-2015 by +# Copyright 2001-2018 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, diff --git a/src/3rdparty/freetype/src/cid/ciderrs.h b/src/3rdparty/freetype/src/cid/ciderrs.h index 5e0e776ee1..a5a86e3fc6 100644 --- a/src/3rdparty/freetype/src/cid/ciderrs.h +++ b/src/3rdparty/freetype/src/cid/ciderrs.h @@ -4,7 +4,7 @@ /* */ /* CID error codes (specification only). */ /* */ -/* Copyright 2001-2015 by */ +/* Copyright 2001-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -22,12 +22,12 @@ /* */ /*************************************************************************/ -#ifndef __CIDERRS_H__ -#define __CIDERRS_H__ +#ifndef CIDERRS_H_ +#define CIDERRS_H_ #include FT_MODULE_ERRORS_H -#undef __FTERRORS_H__ +#undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX CID_Err_ @@ -35,7 +35,7 @@ #include FT_ERRORS_H -#endif /* __CIDERRS_H__ */ +#endif /* CIDERRS_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidgload.c b/src/3rdparty/freetype/src/cid/cidgload.c index d00674fe0d..d14f9a2cc9 100644 --- a/src/3rdparty/freetype/src/cid/cidgload.c +++ b/src/3rdparty/freetype/src/cid/cidgload.c @@ -4,7 +4,7 @@ /* */ /* CID-keyed Type1 Glyph Loader (body). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -24,6 +24,10 @@ #include FT_OUTLINE_H #include FT_INTERNAL_CALC_H +#include FT_INTERNAL_POSTSCRIPT_AUX_H +#include FT_INTERNAL_CFF_TYPES_H +#include FT_DRIVER_H + #include "ciderrs.h" @@ -52,9 +56,11 @@ FT_ULong glyph_length = 0; PSAux_Service psaux = (PSAux_Service)face->psaux; + FT_Bool force_scaling = FALSE; + #ifdef FT_CONFIG_OPTION_INCREMENTAL - FT_Incremental_InterfaceRec *inc = - face->root.internal->incremental_interface; + FT_Incremental_InterfaceRec *inc = + face->root.internal->incremental_interface; #endif @@ -100,7 +106,7 @@ /* and charstring offset from the CIDMap. */ { FT_UInt entry_len = (FT_UInt)( cid->fd_bytes + cid->gd_bytes ); - FT_ULong off1; + FT_ULong off1, off2; if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + @@ -108,18 +114,23 @@ FT_FRAME_ENTER( 2 * entry_len ) ) goto Exit; - p = (FT_Byte*)stream->cursor; - fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); - off1 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); - p += cid->fd_bytes; - glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1; + p = (FT_Byte*)stream->cursor; + fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); + off1 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); + p += cid->fd_bytes; + off2 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); FT_FRAME_EXIT(); - if ( fd_select >= (FT_ULong)cid->num_dicts ) + if ( fd_select >= (FT_ULong)cid->num_dicts || + off2 > stream->size || + off1 > off2 ) { + FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" )); error = FT_THROW( Invalid_Offset ); goto Exit; } + + glyph_length = off2 - off1; if ( glyph_length == 0 ) goto Exit; if ( FT_ALLOC( charstring, glyph_length ) ) @@ -137,9 +148,10 @@ /* Set up subrs */ - decoder->num_subrs = cid_subrs->num_subrs; - decoder->subrs = cid_subrs->code; - decoder->subrs_len = 0; + decoder->num_subrs = cid_subrs->num_subrs; + decoder->subrs = cid_subrs->code; + decoder->subrs_len = 0; + decoder->subrs_hash = NULL; /* Set up font matrix */ dict = cid->font_dicts + fd_select; @@ -152,18 +164,70 @@ /* Adjustment for seed bytes. */ cs_offset = decoder->lenIV >= 0 ? (FT_UInt)decoder->lenIV : 0; + if ( cs_offset > glyph_length ) + { + FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" )); + error = FT_THROW( Invalid_Offset ); + goto Exit; + } /* Decrypt only if lenIV >= 0. */ if ( decoder->lenIV >= 0 ) psaux->t1_decrypt( charstring, glyph_length, 4330 ); - error = decoder->funcs.parse_charstrings( - decoder, charstring + cs_offset, - glyph_length - cs_offset ); + /* choose which renderer to use */ +#ifdef T1_CONFIG_OPTION_OLD_ENGINE + if ( ( (PS_Driver)FT_FACE_DRIVER( face ) )->hinting_engine == + FT_HINTING_FREETYPE || + decoder->builder.metrics_only ) + error = psaux->t1_decoder_funcs->parse_charstrings_old( + decoder, + charstring + cs_offset, + glyph_length - cs_offset ); +#else + if ( decoder->builder.metrics_only ) + error = psaux->t1_decoder_funcs->parse_metrics( + decoder, + charstring + cs_offset, + glyph_length - cs_offset ); +#endif + else + { + PS_Decoder psdecoder; + CFF_SubFontRec subfont; + + + psaux->ps_decoder_init( &psdecoder, decoder, TRUE ); + + psaux->t1_make_subfont( FT_FACE( face ), + &dict->private_dict, + &subfont ); + psdecoder.current_subfont = &subfont; + + error = psaux->t1_decoder_funcs->parse_charstrings( + &psdecoder, + charstring + cs_offset, + glyph_length - cs_offset ); + + /* Adobe's engine uses 16.16 numbers everywhere; */ + /* as a consequence, glyphs larger than 2000ppem get rejected */ + if ( FT_ERR_EQ( error, Glyph_Too_Big ) ) + { + /* this time, we retry unhinted and scale up the glyph later on */ + /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */ + /* 0x400 for both `x_scale' and `y_scale' in this case) */ + ((CID_GlyphSlot)decoder->builder.glyph)->hint = FALSE; + + force_scaling = TRUE; + + error = psaux->t1_decoder_funcs->parse_charstrings( + &psdecoder, + charstring + cs_offset, + glyph_length - cs_offset ); + } + } } - FT_FREE( charstring ); - #ifdef FT_CONFIG_OPTION_INCREMENTAL /* Incremental fonts can optionally override the metrics. */ @@ -188,6 +252,10 @@ #endif /* FT_CONFIG_OPTION_INCREMENTAL */ Exit: + FT_FREE( charstring ); + + ((CID_GlyphSlot)decoder->builder.glyph)->scaled = force_scaling; + return error; } @@ -276,10 +344,12 @@ T1_DecoderRec decoder; CID_Face face = (CID_Face)cidglyph->face; FT_Bool hinting; + FT_Bool scaled; PSAux_Service psaux = (PSAux_Service)face->psaux; FT_Matrix font_matrix; FT_Vector font_offset; + FT_Bool must_finish_decoder = FALSE; if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) @@ -299,7 +369,10 @@ hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 && ( load_flags & FT_LOAD_NO_HINTING ) == 0 ); + scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ); + glyph->hint = hinting; + glyph->scaled = scaled; cidglyph->format = FT_GLYPH_FORMAT_OUTLINE; error = psaux->t1_decoder_funcs->init( &decoder, @@ -317,6 +390,8 @@ /* TODO: initialize decoder.len_buildchar and decoder.buildchar */ /* if we ever support CID-keyed multiple master fonts */ + must_finish_decoder = TRUE; + /* set up the decoder */ decoder.builder.no_recurse = FT_BOOL( ( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) ); @@ -325,12 +400,18 @@ if ( error ) goto Exit; + /* copy flags back for forced scaling */ + hinting = glyph->hint; + scaled = glyph->scaled; + font_matrix = decoder.font_matrix; font_offset = decoder.font_offset; /* save new glyph tables */ psaux->t1_decoder_funcs->done( &decoder ); + must_finish_decoder = FALSE; + /* now set the metrics -- this is rather simple, as */ /* the left side bearing is the xMin, and the top side */ /* bearing the yMax */ @@ -398,7 +479,7 @@ metrics->vertAdvance += font_offset.y; } - if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ) + if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || scaled ) { /* scale the outline and the metrics */ FT_Int n; @@ -439,6 +520,10 @@ } Exit: + + if ( must_finish_decoder ) + psaux->t1_decoder_funcs->done( &decoder ); + return error; } diff --git a/src/3rdparty/freetype/src/cid/cidgload.h b/src/3rdparty/freetype/src/cid/cidgload.h index 4a10ce505c..4811852ae4 100644 --- a/src/3rdparty/freetype/src/cid/cidgload.h +++ b/src/3rdparty/freetype/src/cid/cidgload.h @@ -4,7 +4,7 @@ /* */ /* OpenType Glyph Loader (specification). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,8 +16,8 @@ /***************************************************************************/ -#ifndef __CIDGLOAD_H__ -#define __CIDGLOAD_H__ +#ifndef CIDGLOAD_H_ +#define CIDGLOAD_H_ #include @@ -45,7 +45,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __CIDGLOAD_H__ */ +#endif /* CIDGLOAD_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidload.c b/src/3rdparty/freetype/src/cid/cidload.c index e23b82f673..27cd09b3c3 100644 --- a/src/3rdparty/freetype/src/cid/cidload.c +++ b/src/3rdparty/freetype/src/cid/cidload.c @@ -4,7 +4,7 @@ /* */ /* CID-keyed Type1 font loader (body). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -215,6 +215,7 @@ { CID_FaceInfo cid = &face->cid; FT_Memory memory = face->root.memory; + FT_Stream stream = parser->stream; FT_Error error = FT_Err_Ok; FT_Long num_dicts; @@ -227,6 +228,31 @@ goto Exit; } + /* + * A single entry in the FDArray must (at least) contain the following + * structure elements. + * + * %ADOBeginFontDict 18 + * X dict begin 13 + * /FontMatrix [X X X X] 22 + * /Private X dict begin 22 + * end 4 + * end 4 + * %ADOEndFontDict 16 + * + * This needs 18+13+22+22+4+4+16=99 bytes or more. Normally, you also + * need a `dup X' at the very beginning and a `put' at the end, so a + * rough guess using 100 bytes as the minimum is justified. + */ + if ( (FT_ULong)num_dicts > stream->size / 100 ) + { + FT_TRACE0(( "parse_fd_array: adjusting FDArray size" + " (from %d to %d)\n", + num_dicts, + stream->size / 100 )); + num_dicts = (FT_Long)( stream->size / 100 ); + } + if ( !cid->font_dicts ) { FT_Int n; @@ -395,7 +421,14 @@ cur = parser->root.cursor; } + + if ( !face->cid.num_dicts ) + { + FT_ERROR(( "cid_parse_dict: No font dictionary found\n" )); + return FT_THROW( Invalid_File_Format ); + } } + return parser->root.error; } @@ -428,12 +461,8 @@ FT_Byte* p; - /* Check for possible overflow. */ - if ( num_subrs == FT_UINT_MAX ) - { - error = FT_THROW( Syntax_Error ); - goto Fail; - } + if ( !num_subrs ) + continue; /* reallocate offsets array if needed */ if ( num_subrs + 1 > max_offsets ) @@ -467,14 +496,25 @@ /* offsets must be ordered */ for ( count = 1; count <= num_subrs; count++ ) if ( offsets[count - 1] > offsets[count] ) + { + FT_ERROR(( "cid_read_subrs: offsets are not ordered\n" )); + error = FT_THROW( Invalid_File_Format ); goto Fail; + } + + if ( offsets[num_subrs] > stream->size - cid->data_offset ) + { + FT_ERROR(( "cid_read_subrs: too large `subrs' offsets\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } /* now, compute the size of subrs charstrings, */ /* allocate, and read them */ data_len = offsets[num_subrs] - offsets[0]; if ( FT_NEW_ARRAY( subr->code, num_subrs + 1 ) || - FT_ALLOC( subr->code[0], data_len ) ) + FT_ALLOC( subr->code[0], data_len ) ) goto Fail; if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) || @@ -533,7 +573,7 @@ { FT_UNUSED( face ); - FT_MEM_ZERO( loader, sizeof ( *loader ) ); + FT_ZERO( loader ); } @@ -654,6 +694,12 @@ CID_Parser* parser; FT_Memory memory = face->root.memory; FT_Error error; + FT_Int n; + + CID_FaceInfo cid = &face->cid; + + FT_ULong binary_length; + FT_ULong entry_len; cid_init_loader( &loader, face ); @@ -678,22 +724,117 @@ if ( parser->binary_length ) { + if ( parser->binary_length > + face->root.stream->size - parser->data_offset ) + { + FT_TRACE0(( "cid_face_open: adjusting length of binary data\n" + " (from %d to %d bytes)\n", + parser->binary_length, + face->root.stream->size - parser->data_offset )); + parser->binary_length = face->root.stream->size - + parser->data_offset; + } + /* we must convert the data section from hexadecimal to binary */ - if ( FT_ALLOC( face->binary_data, parser->binary_length ) || - cid_hex_to_binary( face->binary_data, parser->binary_length, - parser->data_offset, face ) ) + if ( FT_ALLOC( face->binary_data, parser->binary_length ) || + FT_SET_ERROR( cid_hex_to_binary( face->binary_data, + parser->binary_length, + parser->data_offset, + face ) ) ) goto Exit; FT_Stream_OpenMemory( face->cid_stream, face->binary_data, parser->binary_length ); - face->cid.data_offset = 0; + cid->data_offset = 0; } else { - *face->cid_stream = *face->root.stream; - face->cid.data_offset = loader.parser.data_offset; + *face->cid_stream = *face->root.stream; + cid->data_offset = loader.parser.data_offset; + } + + /* sanity tests */ + + if ( cid->fd_bytes < 0 || cid->gd_bytes < 1 ) + { + FT_ERROR(( "cid_parse_dict:" + " Invalid `FDBytes' or `GDBytes' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + /* allow at most 32bit offsets */ + if ( cid->fd_bytes > 4 || cid->gd_bytes > 4 ) + { + FT_ERROR(( "cid_parse_dict:" + " Values of `FDBytes' or `GDBytes' larger than 4\n" + " " + " are not supported\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + binary_length = face->cid_stream->size - cid->data_offset; + entry_len = (FT_ULong)( cid->fd_bytes + cid->gd_bytes ); + + for ( n = 0; n < cid->num_dicts; n++ ) + { + CID_FaceDict dict = cid->font_dicts + n; + + + if ( dict->sd_bytes < 0 || + ( dict->num_subrs && dict->sd_bytes < 1 ) ) + { + FT_ERROR(( "cid_parse_dict: Invalid `SDBytes' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + if ( dict->sd_bytes > 4 ) + { + FT_ERROR(( "cid_parse_dict:" + " Values of `SDBytes' larger than 4" + " are not supported\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + if ( dict->subrmap_offset > binary_length ) + { + FT_ERROR(( "cid_parse_dict: Invalid `SubrMapOffset' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + /* `num_subrs' is scanned as a signed integer */ + if ( (FT_Int)dict->num_subrs < 0 || + ( dict->sd_bytes && + dict->num_subrs > ( binary_length - dict->subrmap_offset ) / + (FT_UInt)dict->sd_bytes ) ) + { + FT_ERROR(( "cid_parse_dict: Invalid `SubrCount' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + } + + if ( cid->cidmap_offset > binary_length ) + { + FT_ERROR(( "cid_parse_dict: Invalid `CIDMapOffset' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + if ( entry_len && + cid->cid_count > + ( binary_length - cid->cidmap_offset ) / entry_len ) + { + FT_ERROR(( "cid_parse_dict: Invalid `CIDCount' value\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; } + /* we can now safely proceed */ error = cid_read_subrs( face ); Exit: diff --git a/src/3rdparty/freetype/src/cid/cidload.h b/src/3rdparty/freetype/src/cid/cidload.h index d7776d2f88..3f8bd08620 100644 --- a/src/3rdparty/freetype/src/cid/cidload.h +++ b/src/3rdparty/freetype/src/cid/cidload.h @@ -4,7 +4,7 @@ /* */ /* CID-keyed Type1 font loader (specification). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,8 +16,8 @@ /***************************************************************************/ -#ifndef __CIDLOAD_H__ -#define __CIDLOAD_H__ +#ifndef CIDLOAD_H_ +#define CIDLOAD_H_ #include @@ -47,7 +47,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __CIDLOAD_H__ */ +#endif /* CIDLOAD_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidobjs.c b/src/3rdparty/freetype/src/cid/cidobjs.c index bf1519bc6e..77afe1c875 100644 --- a/src/3rdparty/freetype/src/cid/cidobjs.c +++ b/src/3rdparty/freetype/src/cid/cidobjs.c @@ -4,7 +4,7 @@ /* */ /* CID objects manager (body). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -26,6 +26,7 @@ #include FT_SERVICE_POSTSCRIPT_CMAPS_H #include FT_INTERNAL_POSTSCRIPT_AUX_H #include FT_INTERNAL_POSTSCRIPT_HINTS_H +#include FT_DRIVER_H #include "ciderrs.h" @@ -113,16 +114,16 @@ CID_Size size = (CID_Size)cidsize; - if ( cidsize->internal ) + if ( cidsize->internal->module_data ) { PSH_Globals_Funcs funcs; funcs = cid_size_get_globals_funcs( size ); if ( funcs ) - funcs->destroy( (PSH_Globals)cidsize->internal ); + funcs->destroy( (PSH_Globals)cidsize->internal->module_data ); - cidsize->internal = NULL; + cidsize->internal->module_data = NULL; } } @@ -145,7 +146,7 @@ error = funcs->create( cidsize->face->memory, priv, &globals ); if ( !error ) - cidsize->internal = (FT_Size_Internal)(void*)globals; + cidsize->internal->module_data = globals; } return error; @@ -164,7 +165,7 @@ funcs = cid_size_get_globals_funcs( (CID_Size)size ); if ( funcs ) - funcs->set_scale( (PSH_Globals)size->internal, + funcs->set_scale( (PSH_Globals)size->internal->module_data, size->metrics.x_scale, size->metrics.y_scale, 0, 0 ); @@ -463,9 +464,42 @@ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) - cid_driver_init( FT_Module driver ) + cid_driver_init( FT_Module module ) { - FT_UNUSED( driver ); + PS_Driver driver = (PS_Driver)module; + + FT_UInt32 seed; + + + /* set default property values, cf. `ftt1drv.h' */ +#ifdef T1_CONFIG_OPTION_OLD_ENGINE + driver->hinting_engine = FT_HINTING_FREETYPE; +#else + driver->hinting_engine = FT_HINTING_ADOBE; +#endif + + driver->no_stem_darkening = TRUE; + + driver->darken_params[0] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1; + driver->darken_params[1] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1; + driver->darken_params[2] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2; + driver->darken_params[3] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2; + driver->darken_params[4] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3; + driver->darken_params[5] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3; + driver->darken_params[6] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4; + driver->darken_params[7] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4; + + /* compute random seed from some memory addresses */ + seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^ + (FT_Offset)(char*)&module ^ + (FT_Offset)(char*)module->memory ); + seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 ); + + driver->random_seed = (FT_Int32)seed; + if ( driver->random_seed < 0 ) + driver->random_seed = -driver->random_seed; + else if ( driver->random_seed == 0 ) + driver->random_seed = 123456789; return FT_Err_Ok; } diff --git a/src/3rdparty/freetype/src/cid/cidobjs.h b/src/3rdparty/freetype/src/cid/cidobjs.h index e9095ca68e..0221f017dd 100644 --- a/src/3rdparty/freetype/src/cid/cidobjs.h +++ b/src/3rdparty/freetype/src/cid/cidobjs.h @@ -4,7 +4,7 @@ /* */ /* CID objects manager (specification). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,8 +16,8 @@ /***************************************************************************/ -#ifndef __CIDOBJS_H__ -#define __CIDOBJS_H__ +#ifndef CIDOBJS_H_ +#define CIDOBJS_H_ #include @@ -148,7 +148,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __CIDOBJS_H__ */ +#endif /* CIDOBJS_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidparse.c b/src/3rdparty/freetype/src/cid/cidparse.c index c276949779..b1c7f3cb2c 100644 --- a/src/3rdparty/freetype/src/cid/cidparse.c +++ b/src/3rdparty/freetype/src/cid/cidparse.c @@ -4,7 +4,7 @@ /* */ /* CID-keyed Type1 parser (body). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -47,6 +47,12 @@ /*************************************************************************/ +#define STARTDATA "StartData" +#define STARTDATA_LEN ( sizeof ( STARTDATA ) - 1 ) +#define SFNTS "/sfnts" +#define SFNTS_LEN ( sizeof ( SFNTS ) - 1 ) + + FT_LOCAL_DEF( FT_Error ) cid_parser_new( CID_Parser* parser, FT_Stream stream, @@ -59,7 +65,7 @@ FT_Byte *arg1, *arg2; - FT_MEM_ZERO( parser, sizeof ( *parser ) ); + FT_ZERO( parser ); psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; @@ -85,9 +91,29 @@ /* now, read the rest of the file until we find */ /* `StartData' or `/sfnts' */ { - FT_Byte buffer[256 + 10]; - FT_ULong read_len = 256 + 10; - FT_Byte* p = buffer; + /* + * The algorithm is as follows (omitting the case with less than 256 + * bytes to fill for simplicity). + * + * 1. Fill the buffer with 256 + STARTDATA_LEN bytes. + * + * 2. Search for the STARTDATA and SFNTS strings at positions + * buffer[0], buffer[1], ..., + * buffer[255 + STARTDATA_LEN - SFNTS_LEN]. + * + * 3. Move the last STARTDATA_LEN bytes to buffer[0]. + * + * 4. Fill the buffer with 256 bytes, starting at STARTDATA_LEN. + * + * 5. Repeat with step 2. + * + */ + FT_Byte buffer[256 + STARTDATA_LEN + 1]; + + /* values for the first loop */ + FT_ULong read_len = 256 + STARTDATA_LEN; + FT_ULong read_offset = 0; + FT_Byte* p = buffer; for ( offset = FT_STREAM_POS(); ; offset += 256 ) @@ -96,40 +122,48 @@ stream_len = stream->size - FT_STREAM_POS(); - if ( stream_len == 0 ) - { - FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" )); - error = FT_THROW( Invalid_File_Format ); - goto Exit; - } read_len = FT_MIN( read_len, stream_len ); if ( FT_STREAM_READ( p, read_len ) ) goto Exit; - if ( read_len < 256 ) - p[read_len] = '\0'; + /* ensure that we do not compare with data beyond the buffer */ + p[read_len] = '\0'; - limit = p + read_len - 10; + limit = p + read_len - SFNTS_LEN; for ( p = buffer; p < limit; p++ ) { - if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 ) + if ( p[0] == 'S' && + ft_strncmp( (char*)p, STARTDATA, STARTDATA_LEN ) == 0 ) { /* save offset of binary data after `StartData' */ - offset += (FT_ULong)( p - buffer + 10 ); + offset += (FT_ULong)( p - buffer ) + STARTDATA_LEN + 1; goto Found; } - else if ( p[1] == 's' && ft_strncmp( (char*)p, "/sfnts", 6 ) == 0 ) + else if ( p[1] == 's' && + ft_strncmp( (char*)p, SFNTS, SFNTS_LEN ) == 0 ) { - offset += (FT_ULong)( p - buffer + 7 ); + offset += (FT_ULong)( p - buffer ) + SFNTS_LEN + 1; goto Found; } } - FT_MEM_MOVE( buffer, p, 10 ); - read_len = 256; - p = buffer + 10; + if ( read_offset + read_len < STARTDATA_LEN ) + { + FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + FT_MEM_MOVE( buffer, + buffer + read_offset + read_len - STARTDATA_LEN, + STARTDATA_LEN ); + + /* values for the next loop */ + read_len = 256; + read_offset = STARTDATA_LEN; + p = buffer + read_offset; } } @@ -165,7 +199,7 @@ limit = parser->root.limit; cur = parser->root.cursor; - while ( cur < limit ) + while ( cur <= limit - SFNTS_LEN ) { if ( parser->root.error ) { @@ -173,11 +207,13 @@ goto Exit; } - if ( cur[0] == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 ) + if ( cur[0] == 'S' && + cur <= limit - STARTDATA_LEN && + ft_strncmp( (char*)cur, STARTDATA, STARTDATA_LEN ) == 0 ) { if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 ) { - FT_Long tmp = ft_atol( (const char *)arg2 ); + FT_Long tmp = ft_strtol( (const char *)arg2, NULL, 10 ); if ( tmp < 0 ) @@ -191,7 +227,8 @@ goto Exit; } - else if ( cur[1] == 's' && ft_strncmp( (char*)cur, "/sfnts", 6 ) == 0 ) + else if ( cur[1] == 's' && + ft_strncmp( (char*)cur, SFNTS, SFNTS_LEN ) == 0 ) { FT_TRACE2(( "cid_parser_new: cannot handle Type 11 fonts\n" )); error = FT_THROW( Unknown_File_Format ); @@ -216,6 +253,12 @@ } +#undef STARTDATA +#undef STARTDATA_LEN +#undef SFNTS +#undef SFNTS_LEN + + FT_LOCAL_DEF( void ) cid_parser_done( CID_Parser* parser ) { diff --git a/src/3rdparty/freetype/src/cid/cidparse.h b/src/3rdparty/freetype/src/cid/cidparse.h index f581bb43ff..61602f7674 100644 --- a/src/3rdparty/freetype/src/cid/cidparse.h +++ b/src/3rdparty/freetype/src/cid/cidparse.h @@ -4,7 +4,7 @@ /* */ /* CID-keyed Type1 parser (specification). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,8 +16,8 @@ /***************************************************************************/ -#ifndef __CIDPARSE_H__ -#define __CIDPARSE_H__ +#ifndef CIDPARSE_H_ +#define CIDPARSE_H_ #include @@ -117,7 +117,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __CIDPARSE_H__ */ +#endif /* CIDPARSE_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidriver.c b/src/3rdparty/freetype/src/cid/cidriver.c index 07c4cc410b..d9faf353ea 100644 --- a/src/3rdparty/freetype/src/cid/cidriver.c +++ b/src/3rdparty/freetype/src/cid/cidriver.c @@ -4,7 +4,7 @@ /* */ /* CID driver interface (body). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -20,6 +20,7 @@ #include "cidriver.h" #include "cidgload.h" #include FT_INTERNAL_DEBUG_H +#include FT_INTERNAL_POSTSCRIPT_PROPS_H #include "ciderrs.h" @@ -27,6 +28,10 @@ #include FT_SERVICE_FONT_FORMAT_H #include FT_SERVICE_POSTSCRIPT_INFO_H #include FT_SERVICE_CID_H +#include FT_SERVICE_PROPERTIES_H +#include FT_DRIVER_H + +#include FT_INTERNAL_POSTSCRIPT_AUX_H /*************************************************************************/ @@ -59,7 +64,7 @@ static const FT_Service_PsFontNameRec cid_service_ps_name = { - (FT_PsName_GetFunc) cid_get_postscript_name + (FT_PsName_GetFunc)cid_get_postscript_name /* get_ps_font_name */ }; @@ -88,11 +93,14 @@ static const FT_Service_PsInfoRec cid_service_ps_info = { - (PS_GetFontInfoFunc) cid_ps_get_font_info, - (PS_GetFontExtraFunc) cid_ps_get_font_extra, - (PS_HasGlyphNamesFunc) NULL, /* unsupported with CID fonts */ - (PS_GetFontPrivateFunc)NULL, /* unsupported */ - (PS_GetFontValueFunc) NULL /* not implemented */ + (PS_GetFontInfoFunc) cid_ps_get_font_info, /* ps_get_font_info */ + (PS_GetFontExtraFunc) cid_ps_get_font_extra, /* ps_get_font_extra */ + /* unsupported with CID fonts */ + (PS_HasGlyphNamesFunc) NULL, /* ps_has_glyph_names */ + /* unsupported */ + (PS_GetFontPrivateFunc)NULL, /* ps_get_font_private */ + /* not implemented */ + (PS_GetFontValueFunc) NULL /* ps_get_font_value */ }; @@ -155,12 +163,27 @@ static const FT_Service_CIDRec cid_service_cid_info = { - (FT_CID_GetRegistryOrderingSupplementFunc)cid_get_ros, - (FT_CID_GetIsInternallyCIDKeyedFunc) cid_get_is_cid, - (FT_CID_GetCIDFromGlyphIndexFunc) cid_get_cid_from_glyph_index + (FT_CID_GetRegistryOrderingSupplementFunc) + cid_get_ros, /* get_ros */ + (FT_CID_GetIsInternallyCIDKeyedFunc) + cid_get_is_cid, /* get_is_cid */ + (FT_CID_GetCIDFromGlyphIndexFunc) + cid_get_cid_from_glyph_index /* get_cid_from_glyph_index */ }; + /* + * PROPERTY SERVICE + * + */ + + FT_DEFINE_SERVICE_PROPERTIESREC( + cid_service_properties, + + (FT_Properties_SetFunc)ps_property_set, /* set_property */ + (FT_Properties_GetFunc)ps_property_get ) /* get_property */ + + /* * SERVICE LIST * @@ -172,6 +195,7 @@ { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name }, { FT_SERVICE_ID_POSTSCRIPT_INFO, &cid_service_ps_info }, { FT_SERVICE_ID_CID, &cid_service_cid_info }, + { FT_SERVICE_ID_PROPERTIES, &cid_service_properties }, { NULL, NULL } }; @@ -190,46 +214,42 @@ FT_CALLBACK_TABLE_DEF const FT_Driver_ClassRec t1cid_driver_class = { - /* first of all, the FT_Module_Class fields */ { FT_MODULE_FONT_DRIVER | FT_MODULE_DRIVER_SCALABLE | FT_MODULE_DRIVER_HAS_HINTER, + sizeof ( PS_DriverRec ), - sizeof ( FT_DriverRec ), "t1cid", /* module name */ 0x10000L, /* version 1.0 of driver */ 0x20000L, /* requires FreeType 2.0 */ - 0, + NULL, /* module-specific interface */ - cid_driver_init, - cid_driver_done, - cid_get_interface + cid_driver_init, /* FT_Module_Constructor module_init */ + cid_driver_done, /* FT_Module_Destructor module_done */ + cid_get_interface /* FT_Module_Requester get_interface */ }, - /* then the other font drivers fields */ sizeof ( CID_FaceRec ), sizeof ( CID_SizeRec ), sizeof ( CID_GlyphSlotRec ), - cid_face_init, - cid_face_done, - - cid_size_init, - cid_size_done, - cid_slot_init, - cid_slot_done, - - cid_slot_load_glyph, + cid_face_init, /* FT_Face_InitFunc init_face */ + cid_face_done, /* FT_Face_DoneFunc done_face */ + cid_size_init, /* FT_Size_InitFunc init_size */ + cid_size_done, /* FT_Size_DoneFunc done_size */ + cid_slot_init, /* FT_Slot_InitFunc init_slot */ + cid_slot_done, /* FT_Slot_DoneFunc done_slot */ - 0, /* FT_Face_GetKerningFunc */ - 0, /* FT_Face_AttachFunc */ + cid_slot_load_glyph, /* FT_Slot_LoadFunc load_glyph */ - 0, /* FT_Face_GetAdvancesFunc */ + NULL, /* FT_Face_GetKerningFunc get_kerning */ + NULL, /* FT_Face_AttachFunc attach_file */ + NULL, /* FT_Face_GetAdvancesFunc get_advances */ - cid_size_request, - 0 /* FT_Size_SelectFunc */ + cid_size_request, /* FT_Size_RequestFunc request_size */ + NULL /* FT_Size_SelectFunc select_size */ }; diff --git a/src/3rdparty/freetype/src/cid/cidriver.h b/src/3rdparty/freetype/src/cid/cidriver.h index e5b8678464..59d9ded901 100644 --- a/src/3rdparty/freetype/src/cid/cidriver.h +++ b/src/3rdparty/freetype/src/cid/cidriver.h @@ -4,7 +4,7 @@ /* */ /* High-level CID driver interface (specification). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -16,8 +16,8 @@ /***************************************************************************/ -#ifndef __CIDRIVER_H__ -#define __CIDRIVER_H__ +#ifndef CIDRIVER_H_ +#define CIDRIVER_H_ #include @@ -37,7 +37,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __CIDRIVER_H__ */ +#endif /* CIDRIVER_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/cid/cidtoken.h b/src/3rdparty/freetype/src/cid/cidtoken.h index 82eae0ca6b..b0e2dac6aa 100644 --- a/src/3rdparty/freetype/src/cid/cidtoken.h +++ b/src/3rdparty/freetype/src/cid/cidtoken.h @@ -4,7 +4,7 @@ /* */ /* CID token definitions (specification only). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ diff --git a/src/3rdparty/freetype/src/cid/module.mk b/src/3rdparty/freetype/src/cid/module.mk index e312a3ca1a..9010e339a4 100644 --- a/src/3rdparty/freetype/src/cid/module.mk +++ b/src/3rdparty/freetype/src/cid/module.mk @@ -3,7 +3,7 @@ # -# Copyright 1996-2015 by +# Copyright 1996-2018 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, diff --git a/src/3rdparty/freetype/src/cid/rules.mk b/src/3rdparty/freetype/src/cid/rules.mk index 282f2aad7a..94333bda06 100644 --- a/src/3rdparty/freetype/src/cid/rules.mk +++ b/src/3rdparty/freetype/src/cid/rules.mk @@ -3,7 +3,7 @@ # -# Copyright 1996-2015 by +# Copyright 1996-2018 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, diff --git a/src/3rdparty/freetype/src/cid/type1cid.c b/src/3rdparty/freetype/src/cid/type1cid.c index 0d54ca7f44..61770e3f1e 100644 --- a/src/3rdparty/freetype/src/cid/type1cid.c +++ b/src/3rdparty/freetype/src/cid/type1cid.c @@ -4,7 +4,7 @@ /* */ /* FreeType OpenType driver component (body only). */ /* */ -/* Copyright 1996-2015 by */ +/* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,13 +17,13 @@ #define FT_MAKE_OPTION_SINGLE_OBJECT - #include -#include "cidparse.c" + +#include "cidgload.c" #include "cidload.c" #include "cidobjs.c" +#include "cidparse.c" #include "cidriver.c" -#include "cidgload.c" /* END */ -- cgit v1.2.3