code
stringlengths
0
56.1M
repo_name
stringlengths
3
57
path
stringlengths
2
176
language
stringclasses
672 values
license
stringclasses
8 values
size
int64
0
56.8M
/**************************************************************************** * * t1cmap.c * * Type 1 character map support (body). * * Copyright (C) 2002-2022 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 "t1cmap.h" #include <freetype/internal/ftdebug.h> #include "psauxerr.h" /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void t1_cmap_std_init( T1_CMapStd cmap, FT_Int is_expert ) { T1_Face face = (T1_Face)FT_CMAP_FACE( cmap ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; cmap->num_glyphs = (FT_UInt)face->type1.num_glyphs; cmap->glyph_names = (const char* const*)face->type1.glyph_names; cmap->sid_to_string = psnames->adobe_std_strings; cmap->code_to_sid = is_expert ? psnames->adobe_expert_encoding : psnames->adobe_std_encoding; FT_ASSERT( cmap->code_to_sid ); } FT_CALLBACK_DEF( void ) t1_cmap_std_done( T1_CMapStd cmap ) { cmap->num_glyphs = 0; cmap->glyph_names = NULL; cmap->sid_to_string = NULL; cmap->code_to_sid = NULL; } FT_CALLBACK_DEF( FT_UInt ) t1_cmap_std_char_index( T1_CMapStd cmap, FT_UInt32 char_code ) { FT_UInt result = 0; if ( char_code < 256 ) { FT_UInt code, n; const char* glyph_name; /* convert character code to Adobe SID string */ code = cmap->code_to_sid[char_code]; glyph_name = cmap->sid_to_string( code ); /* look for the corresponding glyph name */ for ( n = 0; n < cmap->num_glyphs; n++ ) { const char* gname = cmap->glyph_names[n]; if ( gname && gname[0] == glyph_name[0] && ft_strcmp( gname, glyph_name ) == 0 ) { result = n; break; } } } return result; } FT_CALLBACK_DEF( FT_UInt32 ) t1_cmap_std_char_next( T1_CMapStd cmap, FT_UInt32 *pchar_code ) { FT_UInt result = 0; FT_UInt32 char_code = *pchar_code + 1; while ( char_code < 256 ) { result = t1_cmap_std_char_index( cmap, char_code ); if ( result != 0 ) goto Exit; char_code++; } char_code = 0; Exit: *pchar_code = char_code; return result; } FT_CALLBACK_DEF( FT_Error ) t1_cmap_standard_init( T1_CMapStd cmap, FT_Pointer pointer ) { FT_UNUSED( pointer ); t1_cmap_std_init( cmap, 0 ); return 0; } FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec t1_cmap_standard_class_rec = { sizeof ( T1_CMapStdRec ), (FT_CMap_InitFunc) t1_cmap_standard_init, /* init */ (FT_CMap_DoneFunc) t1_cmap_std_done, /* done */ (FT_CMap_CharIndexFunc)t1_cmap_std_char_index, /* char_index */ (FT_CMap_CharNextFunc) t1_cmap_std_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */ }; FT_CALLBACK_DEF( FT_Error ) t1_cmap_expert_init( T1_CMapStd cmap, FT_Pointer pointer ) { FT_UNUSED( pointer ); t1_cmap_std_init( cmap, 1 ); return 0; } FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec t1_cmap_expert_class_rec = { sizeof ( T1_CMapStdRec ), (FT_CMap_InitFunc) t1_cmap_expert_init, /* init */ (FT_CMap_DoneFunc) t1_cmap_std_done, /* done */ (FT_CMap_CharIndexFunc)t1_cmap_std_char_index, /* char_index */ (FT_CMap_CharNextFunc) t1_cmap_std_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */ }; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 CUSTOM ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_CALLBACK_DEF( FT_Error ) t1_cmap_custom_init( T1_CMapCustom cmap, FT_Pointer pointer ) { T1_Face face = (T1_Face)FT_CMAP_FACE( cmap ); T1_Encoding encoding = &face->type1.encoding; FT_UNUSED( pointer ); cmap->first = (FT_UInt)encoding->code_first; cmap->count = (FT_UInt)encoding->code_last - cmap->first; cmap->indices = encoding->char_index; FT_ASSERT( cmap->indices ); FT_ASSERT( encoding->code_first <= encoding->code_last ); return 0; } FT_CALLBACK_DEF( void ) t1_cmap_custom_done( T1_CMapCustom cmap ) { cmap->indices = NULL; cmap->first = 0; cmap->count = 0; } FT_CALLBACK_DEF( FT_UInt ) t1_cmap_custom_char_index( T1_CMapCustom cmap, FT_UInt32 char_code ) { FT_UInt result = 0; if ( ( char_code >= cmap->first ) && ( char_code < ( cmap->first + cmap->count ) ) ) result = cmap->indices[char_code]; return result; } FT_CALLBACK_DEF( FT_UInt32 ) t1_cmap_custom_char_next( T1_CMapCustom cmap, FT_UInt32 *pchar_code ) { FT_UInt result = 0; FT_UInt32 char_code = *pchar_code; char_code++; if ( char_code < cmap->first ) char_code = cmap->first; for ( ; char_code < ( cmap->first + cmap->count ); char_code++ ) { result = cmap->indices[char_code]; if ( result != 0 ) goto Exit; } char_code = 0; Exit: *pchar_code = char_code; return result; } FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec t1_cmap_custom_class_rec = { sizeof ( T1_CMapCustomRec ), (FT_CMap_InitFunc) t1_cmap_custom_init, /* init */ (FT_CMap_DoneFunc) t1_cmap_custom_done, /* done */ (FT_CMap_CharIndexFunc)t1_cmap_custom_char_index, /* char_index */ (FT_CMap_CharNextFunc) t1_cmap_custom_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */ }; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_CALLBACK_DEF( const char * ) psaux_get_glyph_name( T1_Face face, FT_UInt idx ) { return face->type1.glyph_names[idx]; } FT_CALLBACK_DEF( FT_Error ) t1_cmap_unicode_init( PS_Unicodes unicodes, FT_Pointer pointer ) { T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes ); FT_Memory memory = FT_FACE_MEMORY( face ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; FT_UNUSED( pointer ); if ( !psnames->unicodes_init ) return FT_THROW( Unimplemented_Feature ); return psnames->unicodes_init( memory, unicodes, (FT_UInt)face->type1.num_glyphs, (PS_GetGlyphNameFunc)&psaux_get_glyph_name, (PS_FreeGlyphNameFunc)NULL, (FT_Pointer)face ); } FT_CALLBACK_DEF( void ) t1_cmap_unicode_done( PS_Unicodes unicodes ) { FT_Face face = FT_CMAP_FACE( unicodes ); FT_Memory memory = FT_FACE_MEMORY( face ); FT_FREE( unicodes->maps ); unicodes->num_maps = 0; } FT_CALLBACK_DEF( FT_UInt ) t1_cmap_unicode_char_index( PS_Unicodes unicodes, FT_UInt32 char_code ) { T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; return psnames->unicodes_char_index( unicodes, char_code ); } FT_CALLBACK_DEF( FT_UInt32 ) t1_cmap_unicode_char_next( PS_Unicodes unicodes, FT_UInt32 *pchar_code ) { T1_Face face = (T1_Face)FT_CMAP_FACE( unicodes ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; return psnames->unicodes_char_next( unicodes, pchar_code ); } FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec t1_cmap_unicode_class_rec = { sizeof ( PS_UnicodesRec ), (FT_CMap_InitFunc) t1_cmap_unicode_init, /* init */ (FT_CMap_DoneFunc) t1_cmap_unicode_done, /* done */ (FT_CMap_CharIndexFunc)t1_cmap_unicode_char_index, /* char_index */ (FT_CMap_CharNextFunc) t1_cmap_unicode_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL /* variantchar_list */ }; /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psaux/t1cmap.c
C++
gpl-3.0
11,076
/**************************************************************************** * * t1cmap.h * * Type 1 character map support (specification). * * Copyright (C) 2002-2022 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 T1CMAP_H_ #define T1CMAP_H_ #include <freetype/internal/ftobjs.h> #include <freetype/internal/t1types.h> FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* standard (and expert) encoding cmaps */ typedef struct T1_CMapStdRec_* T1_CMapStd; typedef struct T1_CMapStdRec_ { FT_CMapRec cmap; const FT_UShort* code_to_sid; PS_Adobe_Std_StringsFunc sid_to_string; FT_UInt num_glyphs; const char* const* glyph_names; } T1_CMapStdRec; FT_CALLBACK_TABLE const FT_CMap_ClassRec t1_cmap_standard_class_rec; FT_CALLBACK_TABLE const FT_CMap_ClassRec t1_cmap_expert_class_rec; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 CUSTOM ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct T1_CMapCustomRec_* T1_CMapCustom; typedef struct T1_CMapCustomRec_ { FT_CMapRec cmap; FT_UInt first; FT_UInt count; FT_UShort* indices; } T1_CMapCustomRec; FT_CALLBACK_TABLE const FT_CMap_ClassRec t1_cmap_custom_class_rec; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* unicode (synthetic) cmaps */ FT_CALLBACK_TABLE const FT_CMap_ClassRec t1_cmap_unicode_class_rec; /* */ FT_END_HEADER #endif /* T1CMAP_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psaux/t1cmap.h
C++
gpl-3.0
3,282
/**************************************************************************** * * t1decode.c * * PostScript Type 1 decoding routines (body). * * Copyright (C) 2000-2022 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 <freetype/internal/ftcalc.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/pshints.h> #include <freetype/internal/fthash.h> #include <freetype/ftoutln.h> #include "t1decode.h" #include "psobjs.h" #include "psauxerr.h" /* ensure proper sign extension */ #define Fix2Int( f ) ( (FT_Int) (FT_Short)( (f) >> 16 ) ) #define Fix2UInt( f ) ( (FT_UInt)(FT_Short)( (f) >> 16 ) ) /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT t1decode typedef enum T1_Operator_ { op_none = 0, op_endchar, op_hsbw, op_seac, op_sbw, op_closepath, op_hlineto, op_hmoveto, op_hvcurveto, op_rlineto, op_rmoveto, op_rrcurveto, op_vhcurveto, op_vlineto, op_vmoveto, op_dotsection, op_hstem, op_hstem3, op_vstem, op_vstem3, op_div, op_callothersubr, op_callsubr, op_pop, op_return, op_setcurrentpoint, op_unknown15, op_max /* never remove this one */ } T1_Operator; static const FT_Int t1_args_count[op_max] = { 0, /* none */ 0, /* endchar */ 2, /* hsbw */ 5, /* seac */ 4, /* sbw */ 0, /* closepath */ 1, /* hlineto */ 1, /* hmoveto */ 4, /* hvcurveto */ 2, /* rlineto */ 2, /* rmoveto */ 6, /* rrcurveto */ 4, /* vhcurveto */ 1, /* vlineto */ 1, /* vmoveto */ 0, /* dotsection */ 2, /* hstem */ 6, /* hstem3 */ 2, /* vstem */ 6, /* vstem3 */ 2, /* div */ -1, /* callothersubr */ 1, /* callsubr */ 0, /* pop */ 0, /* return */ 2, /* setcurrentpoint */ 2 /* opcode 15 (undocumented and obsolete) */ }; /************************************************************************** * * @Function: * t1_lookup_glyph_by_stdcharcode_ps * * @Description: * Looks up a given glyph by its StandardEncoding charcode. Used to * implement the SEAC Type 1 operator in the Adobe engine * * @Input: * face :: * The current face object. * * charcode :: * The character code to look for. * * @Return: * A glyph index in the font face. Returns -1 if the corresponding * glyph wasn't found. */ FT_LOCAL_DEF( FT_Int ) t1_lookup_glyph_by_stdcharcode_ps( PS_Decoder* decoder, FT_Int charcode ) { FT_UInt n; const FT_String* glyph_name; FT_Service_PsCMaps psnames = decoder->psnames; /* check range of standard char code */ if ( charcode < 0 || charcode > 255 ) return -1; glyph_name = psnames->adobe_std_strings( psnames->adobe_std_encoding[charcode]); for ( n = 0; n < decoder->num_glyphs; n++ ) { FT_String* name = (FT_String*)decoder->glyph_names[n]; if ( name && name[0] == glyph_name[0] && ft_strcmp( name, glyph_name ) == 0 ) return (FT_Int)n; } return -1; } #ifdef T1_CONFIG_OPTION_OLD_ENGINE /************************************************************************** * * @Function: * t1_lookup_glyph_by_stdcharcode * * @Description: * Looks up a given glyph by its StandardEncoding charcode. Used to * implement the SEAC Type 1 operator. * * @Input: * face :: * The current face object. * * charcode :: * The character code to look for. * * @Return: * A glyph index in the font face. Returns -1 if the corresponding * glyph wasn't found. */ static FT_Int t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder, FT_Int charcode ) { FT_UInt n; const FT_String* glyph_name; FT_Service_PsCMaps psnames = decoder->psnames; /* check range of standard char code */ if ( charcode < 0 || charcode > 255 ) return -1; glyph_name = psnames->adobe_std_strings( psnames->adobe_std_encoding[charcode]); for ( n = 0; n < decoder->num_glyphs; n++ ) { FT_String* name = (FT_String*)decoder->glyph_names[n]; if ( name && name[0] == glyph_name[0] && ft_strcmp( name, glyph_name ) == 0 ) return (FT_Int)n; } return -1; } /* parse a single Type 1 glyph */ FT_LOCAL_DEF( FT_Error ) t1_decoder_parse_glyph( T1_Decoder decoder, FT_UInt glyph ) { return decoder->parse_callback( decoder, glyph ); } /************************************************************************** * * @Function: * t1operator_seac * * @Description: * Implements the `seac' Type 1 operator for a Type 1 decoder. * * @Input: * decoder :: * The current CID decoder. * * asb :: * The accent's side bearing. * * adx :: * The horizontal offset of the accent. * * ady :: * The vertical offset of the accent. * * bchar :: * The base character's StandardEncoding charcode. * * achar :: * The accent character's StandardEncoding charcode. * * @Return: * FreeType error code. 0 means success. */ static FT_Error t1operator_seac( T1_Decoder decoder, FT_Pos asb, FT_Pos adx, FT_Pos ady, FT_Int bchar, FT_Int achar ) { FT_Error error; FT_Int bchar_index, achar_index; #if 0 FT_Int n_base_points; FT_Outline* base = decoder->builder.base; #endif FT_Vector left_bearing, advance; #ifdef FT_CONFIG_OPTION_INCREMENTAL T1_Face face = (T1_Face)decoder->builder.face; #endif if ( decoder->seac ) { FT_ERROR(( "t1operator_seac: invalid nested seac\n" )); return FT_THROW( Syntax_Error ); } if ( decoder->builder.metrics_only ) { FT_ERROR(( "t1operator_seac: unexpected seac\n" )); return FT_THROW( Syntax_Error ); } /* seac weirdness */ adx += decoder->builder.left_bearing.x; /* `glyph_names' is set to 0 for CID fonts which do not */ /* include an encoding. How can we deal with these? */ #ifdef FT_CONFIG_OPTION_INCREMENTAL if ( decoder->glyph_names == 0 && !face->root.internal->incremental_interface ) #else if ( decoder->glyph_names == 0 ) #endif /* FT_CONFIG_OPTION_INCREMENTAL */ { FT_ERROR(( "t1operator_seac:" " glyph names table not available in this font\n" )); return FT_THROW( Syntax_Error ); } #ifdef FT_CONFIG_OPTION_INCREMENTAL if ( face->root.internal->incremental_interface ) { /* the caller must handle the font encoding also */ bchar_index = bchar; achar_index = achar; } else #endif { bchar_index = t1_lookup_glyph_by_stdcharcode( decoder, bchar ); achar_index = t1_lookup_glyph_by_stdcharcode( decoder, achar ); } if ( bchar_index < 0 || achar_index < 0 ) { FT_ERROR(( "t1operator_seac:" " invalid seac character code arguments\n" )); return FT_THROW( Syntax_Error ); } /* if we are trying to load a composite glyph, do not load the */ /* accent character and return the array of subglyphs. */ if ( decoder->builder.no_recurse ) { FT_GlyphSlot glyph = (FT_GlyphSlot)decoder->builder.glyph; FT_GlyphLoader loader = glyph->internal->loader; FT_SubGlyph subg; /* reallocate subglyph array if necessary */ error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 ); if ( error ) goto Exit; subg = loader->current.subglyphs; /* subglyph 0 = base character */ subg->index = bchar_index; subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES | FT_SUBGLYPH_FLAG_USE_MY_METRICS; subg->arg1 = 0; subg->arg2 = 0; subg++; /* subglyph 1 = accent character */ subg->index = achar_index; subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES; subg->arg1 = (FT_Int)FIXED_TO_INT( adx - asb ); subg->arg2 = (FT_Int)FIXED_TO_INT( ady ); /* set up remaining glyph fields */ glyph->num_subglyphs = 2; glyph->subglyphs = loader->base.subglyphs; glyph->format = FT_GLYPH_FORMAT_COMPOSITE; loader->current.num_subglyphs = 2; goto Exit; } /* First load `bchar' in builder */ /* now load the unscaled outline */ FT_GlyphLoader_Prepare( decoder->builder.loader ); /* prepare loader */ /* save the left bearing and width of the SEAC */ /* glyph as they will be erased by the next load */ left_bearing = decoder->builder.left_bearing; advance = decoder->builder.advance; /* the seac operator must not be nested */ decoder->seac = TRUE; error = t1_decoder_parse_glyph( decoder, (FT_UInt)bchar_index ); decoder->seac = FALSE; if ( error ) goto Exit; /* If the SEAC glyph doesn't have a (H)SBW of its */ /* own use the values from the base glyph. */ if ( decoder->builder.parse_state != T1_Parse_Have_Width ) { left_bearing = decoder->builder.left_bearing; advance = decoder->builder.advance; } decoder->builder.left_bearing.x = 0; decoder->builder.left_bearing.y = 0; decoder->builder.pos_x = adx - asb; decoder->builder.pos_y = ady; /* Now load `achar' on top of */ /* the base outline */ /* the seac operator must not be nested */ decoder->seac = TRUE; error = t1_decoder_parse_glyph( decoder, (FT_UInt)achar_index ); decoder->seac = FALSE; if ( error ) goto Exit; /* restore the left side bearing and advance width */ /* of the SEAC glyph or base character (saved above) */ decoder->builder.left_bearing = left_bearing; decoder->builder.advance = advance; decoder->builder.pos_x = 0; decoder->builder.pos_y = 0; Exit: return error; } /************************************************************************** * * @Function: * t1_decoder_parse_charstrings * * @Description: * Parses a given Type 1 charstrings program. * * @Input: * decoder :: * The current Type 1 decoder. * * charstring_base :: * The base address of the charstring stream. * * charstring_len :: * The length in bytes of the charstring stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) t1_decoder_parse_charstrings( T1_Decoder decoder, FT_Byte* charstring_base, FT_UInt charstring_len ) { FT_Error error; T1_Decoder_Zone zone; FT_Byte* ip; FT_Byte* limit; T1_Builder builder = &decoder->builder; FT_Pos x, y, orig_x, orig_y; FT_Int known_othersubr_result_cnt = 0; FT_Int unknown_othersubr_result_cnt = 0; FT_Bool large_int; FT_Fixed seed; T1_Hints_Funcs hinter; #ifdef FT_DEBUG_LEVEL_TRACE FT_Bool bol = TRUE; #endif /* compute random seed from stack address of parameter */ seed = (FT_Fixed)( ( (FT_Offset)(char*)&seed ^ (FT_Offset)(char*)&decoder ^ (FT_Offset)(char*)&charstring_base ) & FT_ULONG_MAX ); seed = ( seed ^ ( seed >> 10 ) ^ ( seed >> 20 ) ) & 0xFFFFL; if ( seed == 0 ) seed = 0x7384; /* First of all, initialize the decoder */ decoder->top = decoder->stack; decoder->zone = decoder->zones; zone = decoder->zones; builder->parse_state = T1_Parse_Start; hinter = (T1_Hints_Funcs)builder->hints_funcs; /* a font that reads BuildCharArray without setting */ /* its values first is buggy, but ... */ FT_ASSERT( ( decoder->len_buildchar == 0 ) == ( decoder->buildchar == NULL ) ); if ( decoder->buildchar && decoder->len_buildchar > 0 ) FT_ARRAY_ZERO( decoder->buildchar, decoder->len_buildchar ); zone->base = charstring_base; limit = zone->limit = charstring_base + charstring_len; ip = zone->cursor = zone->base; error = FT_Err_Ok; x = orig_x = builder->pos_x; y = orig_y = builder->pos_y; /* begin hints recording session, if any */ if ( hinter ) hinter->open( hinter->hints ); large_int = FALSE; /* now, execute loop */ while ( ip < limit ) { FT_Long* top = decoder->top; T1_Operator op = op_none; FT_Int32 value = 0; FT_ASSERT( known_othersubr_result_cnt == 0 || unknown_othersubr_result_cnt == 0 ); #ifdef FT_DEBUG_LEVEL_TRACE if ( bol ) { FT_TRACE5(( " (%ld)", decoder->top - decoder->stack )); bol = FALSE; } #endif /********************************************************************** * * Decode operator or operand * */ /* first of all, decompress operator or value */ switch ( *ip++ ) { case 1: op = op_hstem; break; case 3: op = op_vstem; break; case 4: op = op_vmoveto; break; case 5: op = op_rlineto; break; case 6: op = op_hlineto; break; case 7: op = op_vlineto; break; case 8: op = op_rrcurveto; break; case 9: op = op_closepath; break; case 10: op = op_callsubr; break; case 11: op = op_return; break; case 13: op = op_hsbw; break; case 14: op = op_endchar; break; case 15: /* undocumented, obsolete operator */ op = op_unknown15; break; case 21: op = op_rmoveto; break; case 22: op = op_hmoveto; break; case 30: op = op_vhcurveto; break; case 31: op = op_hvcurveto; break; case 12: if ( ip >= limit ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " invalid escape (12+EOF)\n" )); goto Syntax_Error; } switch ( *ip++ ) { case 0: op = op_dotsection; break; case 1: op = op_vstem3; break; case 2: op = op_hstem3; break; case 6: op = op_seac; break; case 7: op = op_sbw; break; case 12: op = op_div; break; case 16: op = op_callothersubr; break; case 17: op = op_pop; break; case 33: op = op_setcurrentpoint; break; default: FT_ERROR(( "t1_decoder_parse_charstrings:" " invalid escape (12+%d)\n", ip[-1] )); goto Syntax_Error; } break; case 255: /* four bytes integer */ if ( ip + 4 > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected EOF in integer\n" )); goto Syntax_Error; } value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) | ( (FT_UInt32)ip[1] << 16 ) | ( (FT_UInt32)ip[2] << 8 ) | (FT_UInt32)ip[3] ); ip += 4; /* According to the specification, values > 32000 or < -32000 must */ /* be followed by a `div' operator to make the result be in the */ /* range [-32000;32000]. We expect that the second argument of */ /* `div' is not a large number. Additionally, we don't handle */ /* stuff like `<large1> <large2> <num> div <num> div' or */ /* <large1> <large2> <num> div div'. This is probably not allowed */ /* anyway. */ if ( value > 32000 || value < -32000 ) { if ( large_int ) FT_ERROR(( "t1_decoder_parse_charstrings:" " no `div' after large integer\n" )); else large_int = TRUE; } else { if ( !large_int ) value = (FT_Int32)( (FT_UInt32)value << 16 ); } break; default: if ( ip[-1] >= 32 ) { if ( ip[-1] < 247 ) value = (FT_Int32)ip[-1] - 139; else { if ( ++ip > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected EOF in integer\n" )); goto Syntax_Error; } if ( ip[-2] < 251 ) value = ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108; else value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 ); } if ( !large_int ) value = (FT_Int32)( (FT_UInt32)value << 16 ); } else { FT_ERROR(( "t1_decoder_parse_charstrings:" " invalid byte (%d)\n", ip[-1] )); goto Syntax_Error; } } if ( unknown_othersubr_result_cnt > 0 ) { switch ( op ) { case op_callsubr: case op_return: case op_none: case op_pop: break; default: /* all operands have been transferred by previous pops */ unknown_othersubr_result_cnt = 0; break; } } if ( large_int && !( op == op_none || op == op_div ) ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " no `div' after large integer\n" )); large_int = FALSE; } /********************************************************************** * * Push value on stack, or process operator * */ if ( op == op_none ) { if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS ) { FT_ERROR(( "t1_decoder_parse_charstrings: stack overflow\n" )); goto Syntax_Error; } #ifdef FT_DEBUG_LEVEL_TRACE if ( large_int ) FT_TRACE4(( " %d", value )); else FT_TRACE4(( " %d", value / 65536 )); #endif *top++ = value; decoder->top = top; } else if ( op == op_callothersubr ) /* callothersubr */ { FT_Int subr_no; FT_Int arg_cnt; #ifdef FT_DEBUG_LEVEL_TRACE FT_TRACE4(( " callothersubr\n" )); bol = TRUE; #endif if ( top - decoder->stack < 2 ) goto Stack_Underflow; top -= 2; subr_no = Fix2Int( top[1] ); arg_cnt = Fix2Int( top[0] ); /************************************************************ * * remove all operands to callothersubr from the stack * * for handled othersubrs, where we know the number of * arguments, we increase the stack by the value of * known_othersubr_result_cnt * * for unhandled othersubrs the following pops adjust the * stack pointer as necessary */ if ( arg_cnt > top - decoder->stack ) goto Stack_Underflow; top -= arg_cnt; known_othersubr_result_cnt = 0; unknown_othersubr_result_cnt = 0; /* XXX TODO: The checks to `arg_count == <whatever>' */ /* might not be correct; an othersubr expects a certain */ /* number of operands on the PostScript stack (as opposed */ /* to the T1 stack) but it doesn't have to put them there */ /* by itself; previous othersubrs might have left the */ /* operands there if they were not followed by an */ /* appropriate number of pops */ /* */ /* On the other hand, Adobe Reader 7.0.8 for Linux doesn't */ /* accept a font that contains charstrings like */ /* */ /* 100 200 2 20 callothersubr */ /* 300 1 20 callothersubr pop */ /* */ /* Perhaps this is the reason why BuildCharArray exists. */ switch ( subr_no ) { case 0: /* end flex feature */ if ( arg_cnt != 3 ) goto Unexpected_OtherSubr; if ( !decoder->flex_state || decoder->num_flex_vectors != 7 ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected flex end\n" )); goto Syntax_Error; } /* the two `results' are popped by the following setcurrentpoint */ top[0] = x; top[1] = y; known_othersubr_result_cnt = 2; break; case 1: /* start flex feature */ if ( arg_cnt != 0 ) goto Unexpected_OtherSubr; if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) || FT_SET_ERROR( t1_builder_check_points( builder, 6 ) ) ) goto Fail; decoder->flex_state = 1; decoder->num_flex_vectors = 0; break; case 2: /* add flex vectors */ { FT_Int idx; if ( arg_cnt != 0 ) goto Unexpected_OtherSubr; if ( !decoder->flex_state ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " missing flex start\n" )); goto Syntax_Error; } /* note that we should not add a point for index 0; */ /* this will move our current position to the flex */ /* point without adding any point to the outline */ idx = decoder->num_flex_vectors++; if ( idx > 0 && idx < 7 ) { /* in malformed fonts it is possible to have other */ /* opcodes in the middle of a flex (which don't */ /* increase `num_flex_vectors'); we thus have to */ /* check whether we can add a point */ if ( FT_SET_ERROR( t1_builder_check_points( builder, 1 ) ) ) goto Syntax_Error; t1_builder_add_point( builder, x, y, (FT_Byte)( idx == 3 || idx == 6 ) ); } } break; case 3: /* change hints */ if ( arg_cnt != 1 ) goto Unexpected_OtherSubr; known_othersubr_result_cnt = 1; if ( hinter ) hinter->reset( hinter->hints, (FT_UInt)builder->current->n_points ); break; case 12: case 13: /* counter control hints, clear stack */ top = decoder->stack; break; case 14: case 15: case 16: case 17: case 18: /* multiple masters */ { PS_Blend blend = decoder->blend; FT_UInt num_points, nn, mm; FT_Long* delta; FT_Long* values; if ( !blend ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected multiple masters operator\n" )); goto Syntax_Error; } num_points = (FT_UInt)subr_no - 13 + ( subr_no == 18 ); if ( arg_cnt != (FT_Int)( num_points * blend->num_designs ) ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " incorrect number of multiple masters arguments\n" )); goto Syntax_Error; } /* We want to compute */ /* */ /* a0*w0 + a1*w1 + ... + ak*wk */ /* */ /* but we only have a0, a1-a0, a2-a0, ..., ak-a0. */ /* */ /* However, given that w0 + w1 + ... + wk == 1, we can */ /* rewrite it easily as */ /* */ /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + ... + (ak-a0)*wk */ /* */ /* where k == num_designs-1. */ /* */ /* I guess that's why it's written in this `compact' */ /* form. */ /* */ delta = top + num_points; values = top; for ( nn = 0; nn < num_points; nn++ ) { FT_Long tmp = values[0]; for ( mm = 1; mm < blend->num_designs; mm++ ) tmp = ADD_LONG( tmp, FT_MulFix( *delta++, blend->weight_vector[mm] ) ); *values++ = tmp; } known_othersubr_result_cnt = (FT_Int)num_points; break; } case 19: /* <idx> 1 19 callothersubr */ /* => replace elements starting from index cvi( <idx> ) */ /* of BuildCharArray with WeightVector */ { FT_Int idx; PS_Blend blend = decoder->blend; if ( arg_cnt != 1 || !blend ) goto Unexpected_OtherSubr; idx = Fix2Int( top[0] ); if ( idx < 0 || (FT_UInt)idx + blend->num_designs > decoder->len_buildchar ) goto Unexpected_OtherSubr; ft_memcpy( &decoder->buildchar[idx], blend->weight_vector, blend->num_designs * sizeof ( blend->weight_vector[0] ) ); } break; case 20: /* <arg1> <arg2> 2 20 callothersubr pop */ /* ==> push <arg1> + <arg2> onto T1 stack */ if ( arg_cnt != 2 ) goto Unexpected_OtherSubr; top[0] = ADD_LONG( top[0], top[1] ); known_othersubr_result_cnt = 1; break; case 21: /* <arg1> <arg2> 2 21 callothersubr pop */ /* ==> push <arg1> - <arg2> onto T1 stack */ if ( arg_cnt != 2 ) goto Unexpected_OtherSubr; top[0] = SUB_LONG( top[0], top[1] ); known_othersubr_result_cnt = 1; break; case 22: /* <arg1> <arg2> 2 22 callothersubr pop */ /* ==> push <arg1> * <arg2> onto T1 stack */ if ( arg_cnt != 2 ) goto Unexpected_OtherSubr; top[0] = FT_MulFix( top[0], top[1] ); known_othersubr_result_cnt = 1; break; case 23: /* <arg1> <arg2> 2 23 callothersubr pop */ /* ==> push <arg1> / <arg2> onto T1 stack */ if ( arg_cnt != 2 || top[1] == 0 ) goto Unexpected_OtherSubr; top[0] = FT_DivFix( top[0], top[1] ); known_othersubr_result_cnt = 1; break; case 24: /* <val> <idx> 2 24 callothersubr */ /* ==> set BuildCharArray[cvi( <idx> )] = <val> */ { FT_UInt idx; PS_Blend blend = decoder->blend; if ( arg_cnt != 2 || !blend ) goto Unexpected_OtherSubr; idx = Fix2UInt( top[1] ); if ( idx >= decoder->len_buildchar ) goto Unexpected_OtherSubr; decoder->buildchar[idx] = top[0]; } break; case 25: /* <idx> 1 25 callothersubr pop */ /* ==> push BuildCharArray[cvi( idx )] */ /* onto T1 stack */ { FT_UInt idx; PS_Blend blend = decoder->blend; if ( arg_cnt != 1 || !blend ) goto Unexpected_OtherSubr; idx = Fix2UInt( top[0] ); if ( idx >= decoder->len_buildchar ) goto Unexpected_OtherSubr; top[0] = decoder->buildchar[idx]; } known_othersubr_result_cnt = 1; break; #if 0 case 26: /* <val> mark <idx> ==> set BuildCharArray[cvi( <idx> )] = <val>, */ /* leave mark on T1 stack */ /* <val> <idx> ==> set BuildCharArray[cvi( <idx> )] = <val> */ XXX which routine has left its mark on the (PostScript) stack?; break; #endif case 27: /* <res1> <res2> <val1> <val2> 4 27 callothersubr pop */ /* ==> push <res1> onto T1 stack if <val1> <= <val2>, */ /* otherwise push <res2> */ if ( arg_cnt != 4 ) goto Unexpected_OtherSubr; if ( top[2] > top[3] ) top[0] = top[1]; known_othersubr_result_cnt = 1; break; case 28: /* 0 28 callothersubr pop */ /* => push random value from interval [0, 1) onto stack */ if ( arg_cnt != 0 ) goto Unexpected_OtherSubr; { FT_Fixed Rand; Rand = seed; if ( Rand >= 0x8000L ) Rand++; top[0] = Rand; seed = FT_MulFix( seed, 0x10000L - seed ); if ( seed == 0 ) seed += 0x2873; } known_othersubr_result_cnt = 1; break; default: if ( arg_cnt >= 0 && subr_no >= 0 ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unknown othersubr [%d %d], wish me luck\n", arg_cnt, subr_no )); unknown_othersubr_result_cnt = arg_cnt; break; } /* fall through */ Unexpected_OtherSubr: FT_ERROR(( "t1_decoder_parse_charstrings:" " invalid othersubr [%d %d]\n", arg_cnt, subr_no )); goto Syntax_Error; } top += known_othersubr_result_cnt; decoder->top = top; } else /* general operator */ { FT_Int num_args = t1_args_count[op]; FT_ASSERT( num_args >= 0 ); if ( top - decoder->stack < num_args ) goto Stack_Underflow; /* XXX Operators usually take their operands from the */ /* bottom of the stack, i.e., the operands are */ /* decoder->stack[0], ..., decoder->stack[num_args - 1]; */ /* only div, callsubr, and callothersubr are different. */ /* In practice it doesn't matter (?). */ #ifdef FT_DEBUG_LEVEL_TRACE switch ( op ) { case op_callsubr: case op_div: case op_callothersubr: case op_pop: case op_return: break; default: if ( top - decoder->stack != num_args ) FT_TRACE0(( "t1_decoder_parse_charstrings:" " too much operands on the stack" " (seen %ld, expected %d)\n", top - decoder->stack, num_args )); break; } #endif /* FT_DEBUG_LEVEL_TRACE */ top -= num_args; switch ( op ) { case op_endchar: FT_TRACE4(( " endchar\n" )); t1_builder_close_contour( builder ); /* close hints recording session */ if ( hinter ) { if ( hinter->close( hinter->hints, (FT_UInt)builder->current->n_points ) ) goto Syntax_Error; /* apply hints to the loaded glyph outline now */ error = hinter->apply( hinter->hints, builder->current, (PSH_Globals)builder->hints_globals, decoder->hint_mode ); if ( error ) goto Fail; } /* add current outline to the glyph slot */ FT_GlyphLoader_Add( builder->loader ); /* the compiler should optimize away this empty loop but ... */ #ifdef FT_DEBUG_LEVEL_TRACE if ( decoder->len_buildchar > 0 ) { FT_UInt i; FT_TRACE4(( "BuildCharArray = [ " )); for ( i = 0; i < decoder->len_buildchar; i++ ) FT_TRACE4(( "%ld ", decoder->buildchar[i] )); FT_TRACE4(( "]\n" )); } #endif /* FT_DEBUG_LEVEL_TRACE */ FT_TRACE4(( "\n" )); /* return now! */ return FT_Err_Ok; case op_hsbw: FT_TRACE4(( " hsbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x = ADD_LONG( builder->left_bearing.x, top[0] ); builder->advance.x = top[1]; builder->advance.y = 0; orig_x = x = ADD_LONG( builder->pos_x, top[0] ); orig_y = y = builder->pos_y; FT_UNUSED( orig_y ); /* `metrics_only' indicates that we only want to compute the */ /* glyph's metrics (lsb + advance width) without loading the */ /* rest of it; so exit immediately */ if ( builder->metrics_only ) { FT_TRACE4(( "\n" )); return FT_Err_Ok; } break; case op_seac: return t1operator_seac( decoder, top[0], top[1], top[2], Fix2Int( top[3] ), Fix2Int( top[4] ) ); case op_sbw: FT_TRACE4(( " sbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x = ADD_LONG( builder->left_bearing.x, top[0] ); builder->left_bearing.y = ADD_LONG( builder->left_bearing.y, top[1] ); builder->advance.x = top[2]; builder->advance.y = top[3]; x = ADD_LONG( builder->pos_x, top[0] ); y = ADD_LONG( builder->pos_y, top[1] ); /* `metrics_only' indicates that we only want to compute the */ /* glyph's metrics (lsb + advance width) without loading the */ /* rest of it; so exit immediately */ if ( builder->metrics_only ) { FT_TRACE4(( "\n" )); return FT_Err_Ok; } break; case op_closepath: FT_TRACE4(( " closepath" )); /* if there is no path, `closepath' is a no-op */ if ( builder->parse_state == T1_Parse_Have_Path || builder->parse_state == T1_Parse_Have_Moveto ) t1_builder_close_contour( builder ); builder->parse_state = T1_Parse_Have_Width; break; case op_hlineto: FT_TRACE4(( " hlineto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ) goto Fail; x = ADD_LONG( x, top[0] ); goto Add_Line; case op_hmoveto: FT_TRACE4(( " hmoveto" )); x = ADD_LONG( x, top[0] ); if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_hvcurveto: FT_TRACE4(( " hvcurveto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) || FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) ) goto Fail; x = ADD_LONG( x, top[0] ); t1_builder_add_point( builder, x, y, 0 ); x = ADD_LONG( x, top[1] ); y = ADD_LONG( y, top[2] ); t1_builder_add_point( builder, x, y, 0 ); y = ADD_LONG( y, top[3] ); t1_builder_add_point( builder, x, y, 1 ); break; case op_rlineto: FT_TRACE4(( " rlineto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ) goto Fail; x = ADD_LONG( x, top[0] ); y = ADD_LONG( y, top[1] ); Add_Line: if ( FT_SET_ERROR( t1_builder_add_point1( builder, x, y ) ) ) goto Fail; break; case op_rmoveto: FT_TRACE4(( " rmoveto" )); x = ADD_LONG( x, top[0] ); y = ADD_LONG( y, top[1] ); if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_rrcurveto: FT_TRACE4(( " rrcurveto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) || FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) ) goto Fail; x = ADD_LONG( x, top[0] ); y = ADD_LONG( y, top[1] ); t1_builder_add_point( builder, x, y, 0 ); x = ADD_LONG( x, top[2] ); y = ADD_LONG( y, top[3] ); t1_builder_add_point( builder, x, y, 0 ); x = ADD_LONG( x, top[4] ); y = ADD_LONG( y, top[5] ); t1_builder_add_point( builder, x, y, 1 ); break; case op_vhcurveto: FT_TRACE4(( " vhcurveto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) || FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) ) goto Fail; y = ADD_LONG( y, top[0] ); t1_builder_add_point( builder, x, y, 0 ); x = ADD_LONG( x, top[1] ); y = ADD_LONG( y, top[2] ); t1_builder_add_point( builder, x, y, 0 ); x = ADD_LONG( x, top[3] ); t1_builder_add_point( builder, x, y, 1 ); break; case op_vlineto: FT_TRACE4(( " vlineto" )); if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ) goto Fail; y = ADD_LONG( y, top[0] ); goto Add_Line; case op_vmoveto: FT_TRACE4(( " vmoveto" )); y = ADD_LONG( y, top[0] ); if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_div: FT_TRACE4(( " div" )); /* if `large_int' is set, we divide unscaled numbers; */ /* otherwise, we divide numbers in 16.16 format -- */ /* in both cases, it is the same operation */ *top = FT_DivFix( top[0], top[1] ); top++; large_int = FALSE; break; case op_callsubr: { FT_Int idx; FT_TRACE4(( " callsubr" )); idx = Fix2Int( top[0] ); if ( decoder->subrs_hash ) { size_t* val = ft_hash_num_lookup( idx, decoder->subrs_hash ); if ( val ) idx = *val; else idx = -1; } if ( idx < 0 || idx >= decoder->num_subrs ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " invalid subrs index\n" )); goto Syntax_Error; } if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " too many nested subrs\n" )); goto Syntax_Error; } zone->cursor = ip; /* save current instruction pointer */ zone++; /* The Type 1 driver stores subroutines without the seed bytes. */ /* The CID driver stores subroutines with seed bytes. This */ /* case is taken care of when decoder->subrs_len == 0. */ zone->base = decoder->subrs[idx]; if ( decoder->subrs_len ) zone->limit = zone->base + decoder->subrs_len[idx]; else { /* We are using subroutines from a CID font. We must adjust */ /* for the seed bytes. */ zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); zone->limit = decoder->subrs[idx + 1]; } zone->cursor = zone->base; if ( !zone->base ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " invoking empty subrs\n" )); goto Syntax_Error; } decoder->zone = zone; ip = zone->base; limit = zone->limit; break; } case op_pop: FT_TRACE4(( " pop" )); if ( known_othersubr_result_cnt > 0 ) { known_othersubr_result_cnt--; /* ignore, we pushed the operands ourselves */ break; } if ( unknown_othersubr_result_cnt == 0 ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " no more operands for othersubr\n" )); goto Syntax_Error; } unknown_othersubr_result_cnt--; top++; /* `push' the operand to callothersubr onto the stack */ break; case op_return: FT_TRACE4(( " return" )); if ( zone <= decoder->zones ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected return\n" )); goto Syntax_Error; } zone--; ip = zone->cursor; limit = zone->limit; decoder->zone = zone; break; case op_dotsection: FT_TRACE4(( " dotsection" )); break; case op_hstem: FT_TRACE4(( " hstem" )); /* record horizontal hint */ if ( hinter ) { /* top[0] += builder->left_bearing.y; */ hinter->stem( hinter->hints, 1, top ); } break; case op_hstem3: FT_TRACE4(( " hstem3" )); /* record horizontal counter-controlled hints */ if ( hinter ) hinter->stem3( hinter->hints, 1, top ); break; case op_vstem: FT_TRACE4(( " vstem" )); /* record vertical hint */ if ( hinter ) { top[0] = ADD_LONG( top[0], orig_x ); hinter->stem( hinter->hints, 0, top ); } break; case op_vstem3: FT_TRACE4(( " vstem3" )); /* record vertical counter-controlled hints */ if ( hinter ) { FT_Pos dx = orig_x; top[0] = ADD_LONG( top[0], dx ); top[2] = ADD_LONG( top[2], dx ); top[4] = ADD_LONG( top[4], dx ); hinter->stem3( hinter->hints, 0, top ); } break; case op_setcurrentpoint: FT_TRACE4(( " setcurrentpoint" )); /* From the T1 specification, section 6.4: */ /* */ /* The setcurrentpoint command is used only in */ /* conjunction with results from OtherSubrs procedures. */ /* known_othersubr_result_cnt != 0 is already handled */ /* above. */ /* Note, however, that both Ghostscript and Adobe */ /* Distiller handle this situation by silently ignoring */ /* the inappropriate `setcurrentpoint' instruction. So */ /* we do the same. */ #if 0 if ( decoder->flex_state != 1 ) { FT_ERROR(( "t1_decoder_parse_charstrings:" " unexpected `setcurrentpoint'\n" )); goto Syntax_Error; } else ... #endif x = top[0]; y = top[1]; decoder->flex_state = 0; break; case op_unknown15: FT_TRACE4(( " opcode_15" )); /* nothing to do except to pop the two arguments */ break; default: FT_ERROR(( "t1_decoder_parse_charstrings:" " unhandled opcode %d\n", op )); goto Syntax_Error; } /* XXX Operators usually clear the operand stack; */ /* only div, callsubr, callothersubr, pop, and */ /* return are different. */ /* In practice it doesn't matter (?). */ decoder->top = top; #ifdef FT_DEBUG_LEVEL_TRACE FT_TRACE4(( "\n" )); bol = TRUE; #endif } /* general operator processing */ } /* while ip < limit */ FT_TRACE4(( "..end..\n" )); FT_TRACE4(( "\n" )); Fail: return error; Syntax_Error: return FT_THROW( Syntax_Error ); Stack_Underflow: return FT_THROW( Stack_Underflow ); } #else /* !T1_CONFIG_OPTION_OLD_ENGINE */ /************************************************************************** * * @Function: * t1_decoder_parse_metrics * * @Description: * Parses a given Type 1 charstrings program to extract width * * @Input: * decoder :: * The current Type 1 decoder. * * charstring_base :: * The base address of the charstring stream. * * charstring_len :: * The length in bytes of the charstring stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) t1_decoder_parse_metrics( T1_Decoder decoder, FT_Byte* charstring_base, FT_UInt charstring_len ) { T1_Decoder_Zone zone; FT_Byte* ip; FT_Byte* limit; T1_Builder builder = &decoder->builder; FT_Bool large_int; #ifdef FT_DEBUG_LEVEL_TRACE FT_Bool bol = TRUE; #endif /* First of all, initialize the decoder */ decoder->top = decoder->stack; decoder->zone = decoder->zones; zone = decoder->zones; builder->parse_state = T1_Parse_Start; zone->base = charstring_base; limit = zone->limit = charstring_base + charstring_len; ip = zone->cursor = zone->base; large_int = FALSE; /* now, execute loop */ while ( ip < limit ) { FT_Long* top = decoder->top; T1_Operator op = op_none; FT_Int32 value = 0; #ifdef FT_DEBUG_LEVEL_TRACE if ( bol ) { FT_TRACE5(( " (%ld)", decoder->top - decoder->stack )); bol = FALSE; } #endif /********************************************************************** * * Decode operator or operand * */ /* first of all, decompress operator or value */ switch ( *ip++ ) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 14: case 15: case 21: case 22: case 30: case 31: goto No_Width; case 10: op = op_callsubr; break; case 11: op = op_return; break; case 13: op = op_hsbw; break; case 12: if ( ip >= limit ) { FT_ERROR(( "t1_decoder_parse_metrics:" " invalid escape (12+EOF)\n" )); goto Syntax_Error; } switch ( *ip++ ) { case 7: op = op_sbw; break; case 12: op = op_div; break; default: goto No_Width; } break; case 255: /* four bytes integer */ if ( ip + 4 > limit ) { FT_ERROR(( "t1_decoder_parse_metrics:" " unexpected EOF in integer\n" )); goto Syntax_Error; } value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) | ( (FT_UInt32)ip[1] << 16 ) | ( (FT_UInt32)ip[2] << 8 ) | (FT_UInt32)ip[3] ); ip += 4; /* According to the specification, values > 32000 or < -32000 must */ /* be followed by a `div' operator to make the result be in the */ /* range [-32000;32000]. We expect that the second argument of */ /* `div' is not a large number. Additionally, we don't handle */ /* stuff like `<large1> <large2> <num> div <num> div' or */ /* <large1> <large2> <num> div div'. This is probably not allowed */ /* anyway. */ if ( value > 32000 || value < -32000 ) { if ( large_int ) { FT_ERROR(( "t1_decoder_parse_metrics:" " no `div' after large integer\n" )); goto Syntax_Error; } else large_int = TRUE; } else { if ( !large_int ) value = (FT_Int32)( (FT_UInt32)value << 16 ); } break; default: if ( ip[-1] >= 32 ) { if ( ip[-1] < 247 ) value = (FT_Int32)ip[-1] - 139; else { if ( ++ip > limit ) { FT_ERROR(( "t1_decoder_parse_metrics:" " unexpected EOF in integer\n" )); goto Syntax_Error; } if ( ip[-2] < 251 ) value = ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108; else value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 ); } if ( !large_int ) value = (FT_Int32)( (FT_UInt32)value << 16 ); } else { FT_ERROR(( "t1_decoder_parse_metrics:" " invalid byte (%d)\n", ip[-1] )); goto Syntax_Error; } } if ( large_int && !( op == op_none || op == op_div ) ) { FT_ERROR(( "t1_decoder_parse_metrics:" " no `div' after large integer\n" )); goto Syntax_Error; } /********************************************************************** * * Push value on stack, or process operator * */ if ( op == op_none ) { if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS ) { FT_ERROR(( "t1_decoder_parse_metrics: stack overflow\n" )); goto Syntax_Error; } #ifdef FT_DEBUG_LEVEL_TRACE if ( large_int ) FT_TRACE4(( " %d", value )); else FT_TRACE4(( " %d", value / 65536 )); #endif *top++ = value; decoder->top = top; } else /* general operator */ { FT_Int num_args = t1_args_count[op]; FT_ASSERT( num_args >= 0 ); if ( top - decoder->stack < num_args ) goto Stack_Underflow; #ifdef FT_DEBUG_LEVEL_TRACE switch ( op ) { case op_callsubr: case op_div: case op_return: break; default: if ( top - decoder->stack != num_args ) FT_TRACE0(( "t1_decoder_parse_metrics:" " too much operands on the stack" " (seen %ld, expected %d)\n", top - decoder->stack, num_args )); break; } #endif /* FT_DEBUG_LEVEL_TRACE */ top -= num_args; switch ( op ) { case op_hsbw: FT_TRACE4(( " hsbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x = ADD_LONG( builder->left_bearing.x, top[0] ); builder->advance.x = top[1]; builder->advance.y = 0; /* we only want to compute the glyph's metrics */ /* (lsb + advance width) without loading the */ /* rest of it; so exit immediately */ FT_TRACE4(( "\n" )); return FT_Err_Ok; case op_sbw: FT_TRACE4(( " sbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x = ADD_LONG( builder->left_bearing.x, top[0] ); builder->left_bearing.y = ADD_LONG( builder->left_bearing.y, top[1] ); builder->advance.x = top[2]; builder->advance.y = top[3]; /* we only want to compute the glyph's metrics */ /* (lsb + advance width), without loading the */ /* rest of it; so exit immediately */ FT_TRACE4(( "\n" )); return FT_Err_Ok; case op_div: FT_TRACE4(( " div" )); /* if `large_int' is set, we divide unscaled numbers; */ /* otherwise, we divide numbers in 16.16 format -- */ /* in both cases, it is the same operation */ *top = FT_DivFix( top[0], top[1] ); top++; large_int = FALSE; break; case op_callsubr: { FT_Int idx; FT_TRACE4(( " callsubr" )); idx = Fix2Int( top[0] ); if ( decoder->subrs_hash ) { size_t* val = ft_hash_num_lookup( idx, decoder->subrs_hash ); if ( val ) idx = *val; else idx = -1; } if ( idx < 0 || idx >= decoder->num_subrs ) { FT_ERROR(( "t1_decoder_parse_metrics:" " invalid subrs index\n" )); goto Syntax_Error; } if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS ) { FT_ERROR(( "t1_decoder_parse_metrics:" " too many nested subrs\n" )); goto Syntax_Error; } zone->cursor = ip; /* save current instruction pointer */ zone++; /* The Type 1 driver stores subroutines without the seed bytes. */ /* The CID driver stores subroutines with seed bytes. This */ /* case is taken care of when decoder->subrs_len == 0. */ zone->base = decoder->subrs[idx]; if ( decoder->subrs_len ) zone->limit = zone->base + decoder->subrs_len[idx]; else { /* We are using subroutines from a CID font. We must adjust */ /* for the seed bytes. */ zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); zone->limit = decoder->subrs[idx + 1]; } zone->cursor = zone->base; if ( !zone->base ) { FT_ERROR(( "t1_decoder_parse_metrics:" " invoking empty subrs\n" )); goto Syntax_Error; } decoder->zone = zone; ip = zone->base; limit = zone->limit; break; } case op_return: FT_TRACE4(( " return" )); if ( zone <= decoder->zones ) { FT_ERROR(( "t1_decoder_parse_metrics:" " unexpected return\n" )); goto Syntax_Error; } zone--; ip = zone->cursor; limit = zone->limit; decoder->zone = zone; break; default: FT_ERROR(( "t1_decoder_parse_metrics:" " unhandled opcode %d\n", op )); goto Syntax_Error; } decoder->top = top; } /* general operator processing */ } /* while ip < limit */ FT_TRACE4(( "..end..\n" )); FT_TRACE4(( "\n" )); No_Width: FT_ERROR(( "t1_decoder_parse_metrics:" " no width, found op %d instead\n", ip[-1] )); Syntax_Error: return FT_THROW( Syntax_Error ); Stack_Underflow: return FT_THROW( Stack_Underflow ); } #endif /* !T1_CONFIG_OPTION_OLD_ENGINE */ /* initialize T1 decoder */ FT_LOCAL_DEF( FT_Error ) t1_decoder_init( T1_Decoder decoder, FT_Face face, FT_Size size, FT_GlyphSlot slot, FT_Byte** glyph_names, PS_Blend blend, FT_Bool hinting, FT_Render_Mode hint_mode, T1_Decoder_Callback parse_callback ) { FT_ZERO( decoder ); /* retrieve `psnames' interface from list of current modules */ { FT_Service_PsCMaps psnames; FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); if ( !psnames ) { FT_ERROR(( "t1_decoder_init:" " the `psnames' module is not available\n" )); return FT_THROW( Unimplemented_Feature ); } decoder->psnames = psnames; } t1_builder_init( &decoder->builder, face, size, slot, hinting ); /* decoder->buildchar and decoder->len_buildchar have to be */ /* initialized by the caller since we cannot know the length */ /* of the BuildCharArray */ decoder->num_glyphs = (FT_UInt)face->num_glyphs; decoder->glyph_names = glyph_names; decoder->hint_mode = hint_mode; decoder->blend = blend; decoder->parse_callback = parse_callback; decoder->funcs = t1_decoder_funcs; return FT_Err_Ok; } /* finalize T1 decoder */ FT_LOCAL_DEF( void ) t1_decoder_done( T1_Decoder decoder ) { FT_Memory memory = decoder->builder.memory; t1_builder_done( &decoder->builder ); if ( decoder->cf2_instance.finalizer ) { decoder->cf2_instance.finalizer( decoder->cf2_instance.data ); FT_FREE( decoder->cf2_instance.data ); } } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psaux/t1decode.c
C++
gpl-3.0
60,726
/**************************************************************************** * * t1decode.h * * PostScript Type 1 decoding routines (specification). * * Copyright (C) 2000-2022 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 T1DECODE_H_ #define T1DECODE_H_ #include <freetype/internal/psaux.h> #include <freetype/internal/t1types.h> FT_BEGIN_HEADER FT_CALLBACK_TABLE const T1_Decoder_FuncsRec t1_decoder_funcs; FT_LOCAL( FT_Int ) t1_lookup_glyph_by_stdcharcode_ps( PS_Decoder* decoder, FT_Int charcode ); #ifdef T1_CONFIG_OPTION_OLD_ENGINE FT_LOCAL( FT_Error ) t1_decoder_parse_glyph( T1_Decoder decoder, FT_UInt glyph_index ); FT_LOCAL( FT_Error ) t1_decoder_parse_charstrings( T1_Decoder decoder, FT_Byte* base, FT_UInt len ); #else FT_LOCAL( FT_Error ) t1_decoder_parse_metrics( T1_Decoder decoder, FT_Byte* charstring_base, FT_UInt charstring_len ); #endif FT_LOCAL( FT_Error ) t1_decoder_init( T1_Decoder decoder, FT_Face face, FT_Size size, FT_GlyphSlot slot, FT_Byte** glyph_names, PS_Blend blend, FT_Bool hinting, FT_Render_Mode hint_mode, T1_Decoder_Callback parse_glyph ); FT_LOCAL( void ) t1_decoder_done( T1_Decoder decoder ); FT_END_HEADER #endif /* T1DECODE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psaux/t1decode.h
C++
gpl-3.0
2,024
# # FreeType 2 PSHinter module definition # # Copyright (C) 1996-2022 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. FTMODULE_H_COMMANDS += PSHINTER_MODULE define PSHINTER_MODULE $(OPEN_DRIVER) FT_Module_Class, pshinter_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)pshinter $(ECHO_DRIVER_DESC)Postscript hinter module$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/module.mk
mk
gpl-3.0
662
/**************************************************************************** * * pshalgo.c * * PostScript hinting algorithm (body). * * Copyright (C) 2001-2022 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 <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftcalc.h> #include "pshalgo.h" #include "pshnterr.h" #undef FT_COMPONENT #define FT_COMPONENT pshalgo #ifdef DEBUG_HINTER PSH_Hint_Table ps_debug_hint_table = NULL; PSH_HintFunc ps_debug_hint_func = NULL; PSH_Glyph ps_debug_glyph = NULL; #endif #define COMPUTE_INFLEXS /* compute inflection points to optimize `S' */ /* and similar glyphs */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** BASIC HINTS RECORDINGS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* return true if two stem hints overlap */ static FT_Int psh_hint_overlap( PSH_Hint hint1, PSH_Hint hint2 ) { return ADD_INT( hint1->org_pos, hint1->org_len ) >= hint2->org_pos && ADD_INT( hint2->org_pos, hint2->org_len ) >= hint1->org_pos; } /* destroy hints table */ static void psh_hint_table_done( PSH_Hint_Table table, FT_Memory memory ) { FT_FREE( table->zones ); table->num_zones = 0; table->zone = NULL; FT_FREE( table->sort ); FT_FREE( table->hints ); table->num_hints = 0; table->max_hints = 0; table->sort_global = NULL; } /* deactivate all hints in a table */ static void psh_hint_table_deactivate( PSH_Hint_Table table ) { FT_UInt count = table->max_hints; PSH_Hint hint = table->hints; for ( ; count > 0; count--, hint++ ) { psh_hint_deactivate( hint ); hint->order = -1; } } /* internal function to record a new hint */ static void psh_hint_table_record( PSH_Hint_Table table, FT_UInt idx ) { PSH_Hint hint = table->hints + idx; if ( idx >= table->max_hints ) { FT_TRACE0(( "psh_hint_table_record: invalid hint index %d\n", idx )); return; } /* ignore active hints */ if ( psh_hint_is_active( hint ) ) return; psh_hint_activate( hint ); /* now scan the current active hint set to check */ /* whether `hint' overlaps with another hint */ { PSH_Hint* sorted = table->sort_global; FT_UInt count = table->num_hints; PSH_Hint hint2; hint->parent = NULL; for ( ; count > 0; count--, sorted++ ) { hint2 = sorted[0]; if ( psh_hint_overlap( hint, hint2 ) ) { hint->parent = hint2; break; } } } if ( table->num_hints < table->max_hints ) table->sort_global[table->num_hints++] = hint; else FT_TRACE0(( "psh_hint_table_record: too many sorted hints! BUG!\n" )); } static void psh_hint_table_record_mask( PSH_Hint_Table table, PS_Mask hint_mask ) { FT_Int mask = 0, val = 0; FT_Byte* cursor = hint_mask->bytes; FT_UInt idx, limit; limit = hint_mask->num_bits; for ( idx = 0; idx < limit; idx++ ) { if ( mask == 0 ) { val = *cursor++; mask = 0x80; } if ( val & mask ) psh_hint_table_record( table, idx ); mask >>= 1; } } /* create hints table */ static FT_Error psh_hint_table_init( PSH_Hint_Table table, PS_Hint_Table hints, PS_Mask_Table hint_masks, PS_Mask_Table counter_masks, FT_Memory memory ) { FT_UInt count; FT_Error error; FT_UNUSED( counter_masks ); count = hints->num_hints; /* allocate our tables */ if ( FT_QNEW_ARRAY( table->sort, 2 * count ) || FT_QNEW_ARRAY( table->hints, count ) || FT_QNEW_ARRAY( table->zones, 2 * count + 1 ) ) goto Exit; table->max_hints = count; table->sort_global = FT_OFFSET( table->sort, count ); table->num_hints = 0; table->num_zones = 0; table->zone = NULL; /* initialize the `table->hints' array */ { PSH_Hint write = table->hints; PS_Hint read = hints->hints; for ( ; count > 0; count--, write++, read++ ) { write->org_pos = read->pos; write->org_len = read->len; write->flags = read->flags; } } /* we now need to determine the initial `parent' stems; first */ /* activate the hints that are given by the initial hint masks */ if ( hint_masks ) { PS_Mask mask = hint_masks->masks; count = hint_masks->num_masks; table->hint_masks = hint_masks; for ( ; count > 0; count--, mask++ ) psh_hint_table_record_mask( table, mask ); } /* finally, do a linear parse in case some hints were left alone */ if ( table->num_hints != table->max_hints ) { FT_UInt idx; FT_TRACE0(( "psh_hint_table_init: missing/incorrect hint masks\n" )); count = table->max_hints; for ( idx = 0; idx < count; idx++ ) psh_hint_table_record( table, idx ); } Exit: return error; } static void psh_hint_table_activate_mask( PSH_Hint_Table table, PS_Mask hint_mask ) { FT_Int mask = 0, val = 0; FT_Byte* cursor = hint_mask->bytes; FT_UInt idx, limit, count; limit = hint_mask->num_bits; count = 0; psh_hint_table_deactivate( table ); for ( idx = 0; idx < limit; idx++ ) { if ( mask == 0 ) { val = *cursor++; mask = 0x80; } if ( val & mask ) { PSH_Hint hint = &table->hints[idx]; if ( !psh_hint_is_active( hint ) ) { FT_UInt count2; #if 0 PSH_Hint* sort = table->sort; PSH_Hint hint2; for ( count2 = count; count2 > 0; count2--, sort++ ) { hint2 = sort[0]; if ( psh_hint_overlap( hint, hint2 ) ) FT_TRACE0(( "psh_hint_table_activate_mask:" " found overlapping hints\n" )) } #else count2 = 0; #endif if ( count2 == 0 ) { psh_hint_activate( hint ); if ( count < table->max_hints ) table->sort[count++] = hint; else FT_TRACE0(( "psh_hint_tableactivate_mask:" " too many active hints\n" )); } } } mask >>= 1; } table->num_hints = count; /* now, sort the hints; they are guaranteed to not overlap */ /* so we can compare their "org_pos" field directly */ { FT_UInt i1, i2; PSH_Hint hint1, hint2; PSH_Hint* sort = table->sort; /* a simple bubble sort will do, since in 99% of cases, the hints */ /* will be already sorted -- and the sort will be linear */ for ( i1 = 1; i1 < count; i1++ ) { hint1 = sort[i1]; /* this loop stops when i2 wraps around after reaching 0 */ for ( i2 = i1 - 1; i2 < i1; i2-- ) { hint2 = sort[i2]; if ( hint2->org_pos < hint1->org_pos ) break; sort[i2 + 1] = hint2; sort[i2] = hint1; } } } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** HINTS GRID-FITTING AND OPTIMIZATION *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #if 1 static FT_Pos psh_dimension_quantize_len( PSH_Dimension dim, FT_Pos len, FT_Bool do_snapping ) { if ( len <= 64 ) len = 64; else { FT_Pos delta = len - dim->stdw.widths[0].cur; if ( delta < 0 ) delta = -delta; if ( delta < 40 ) { len = dim->stdw.widths[0].cur; if ( len < 48 ) len = 48; } if ( len < 3 * 64 ) { delta = ( len & 63 ); len &= -64; if ( delta < 10 ) len += delta; else if ( delta < 32 ) len += 10; else if ( delta < 54 ) len += 54; else len += delta; } else len = FT_PIX_ROUND( len ); } if ( do_snapping ) len = FT_PIX_ROUND( len ); return len; } #endif /* 0 */ #ifdef DEBUG_HINTER static void ps_simple_scale( PSH_Hint_Table table, FT_Fixed scale, FT_Fixed delta, FT_Int dimension ) { FT_UInt count; for ( count = 0; count < table->max_hints; count++ ) { PSH_Hint hint = table->hints + count; hint->cur_pos = FT_MulFix( hint->org_pos, scale ) + delta; hint->cur_len = FT_MulFix( hint->org_len, scale ); if ( ps_debug_hint_func ) ps_debug_hint_func( hint, dimension ); } } #endif /* DEBUG_HINTER */ static FT_Fixed psh_hint_snap_stem_side_delta( FT_Fixed pos, FT_Fixed len ) { FT_Fixed delta1 = FT_PIX_ROUND( pos ) - pos; FT_Fixed delta2 = FT_PIX_ROUND( pos + len ) - pos - len; if ( FT_ABS( delta1 ) <= FT_ABS( delta2 ) ) return delta1; else return delta2; } static void psh_hint_align( PSH_Hint hint, PSH_Globals globals, FT_Int dimension, PSH_Glyph glyph ) { PSH_Dimension dim = &globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Fixed delta = dim->scale_delta; if ( !psh_hint_is_fitted( hint ) ) { FT_Pos pos = FT_MulFix( hint->org_pos, scale ) + delta; FT_Pos len = FT_MulFix( hint->org_len, scale ); FT_Int do_snapping; FT_Pos fit_len; PSH_AlignmentRec align; /* ignore stem alignments when requested through the hint flags */ if ( ( dimension == 0 && !glyph->do_horz_hints ) || ( dimension == 1 && !glyph->do_vert_hints ) ) { hint->cur_pos = pos; hint->cur_len = len; psh_hint_set_fitted( hint ); return; } /* perform stem snapping when requested - this is necessary * for monochrome and LCD hinting modes only */ do_snapping = ( dimension == 0 && glyph->do_horz_snapping ) || ( dimension == 1 && glyph->do_vert_snapping ); hint->cur_len = fit_len = len; /* check blue zones for horizontal stems */ align.align = PSH_BLUE_ALIGN_NONE; align.align_bot = align.align_top = 0; if ( dimension == 1 ) psh_blues_snap_stem( &globals->blues, ADD_INT( hint->org_pos, hint->org_len ), hint->org_pos, &align ); switch ( align.align ) { case PSH_BLUE_ALIGN_TOP: /* the top of the stem is aligned against a blue zone */ hint->cur_pos = align.align_top - fit_len; break; case PSH_BLUE_ALIGN_BOT: /* the bottom of the stem is aligned against a blue zone */ hint->cur_pos = align.align_bot; break; case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT: /* both edges of the stem are aligned against blue zones */ hint->cur_pos = align.align_bot; hint->cur_len = align.align_top - align.align_bot; break; default: { PSH_Hint parent = hint->parent; if ( parent ) { FT_Pos par_org_center, par_cur_center; FT_Pos cur_org_center, cur_delta; /* ensure that parent is already fitted */ if ( !psh_hint_is_fitted( parent ) ) psh_hint_align( parent, globals, dimension, glyph ); /* keep original relation between hints, this is, use the */ /* scaled distance between the centers of the hints to */ /* compute the new position */ par_org_center = parent->org_pos + ( parent->org_len >> 1 ); par_cur_center = parent->cur_pos + ( parent->cur_len >> 1 ); cur_org_center = hint->org_pos + ( hint->org_len >> 1 ); cur_delta = FT_MulFix( cur_org_center - par_org_center, scale ); pos = par_cur_center + cur_delta - ( len >> 1 ); } hint->cur_pos = pos; hint->cur_len = fit_len; /* Stem adjustment tries to snap stem widths to standard * ones. This is important to prevent unpleasant rounding * artefacts. */ if ( glyph->do_stem_adjust ) { if ( len <= 64 ) { /* the stem is less than one pixel; we will center it * around the nearest pixel center */ if ( len >= 32 ) { /* This is a special case where we also widen the stem * and align it to the pixel grid. * * stem_center = pos + (len/2) * nearest_pixel_center = FT_ROUND(stem_center-32)+32 * new_pos = nearest_pixel_center-32 * = FT_ROUND(stem_center-32) * = FT_FLOOR(stem_center-32+32) * = FT_FLOOR(stem_center) * new_len = 64 */ pos = FT_PIX_FLOOR( pos + ( len >> 1 ) ); len = 64; } else if ( len > 0 ) { /* This is a very small stem; we simply align it to the * pixel grid, trying to find the minimum displacement. * * left = pos * right = pos + len * left_nearest_edge = ROUND(pos) * right_nearest_edge = ROUND(right) * * if ( ABS(left_nearest_edge - left) <= * ABS(right_nearest_edge - right) ) * new_pos = left * else * new_pos = right */ FT_Pos left_nearest = FT_PIX_ROUND( pos ); FT_Pos right_nearest = FT_PIX_ROUND( pos + len ); FT_Pos left_disp = left_nearest - pos; FT_Pos right_disp = right_nearest - ( pos + len ); if ( left_disp < 0 ) left_disp = -left_disp; if ( right_disp < 0 ) right_disp = -right_disp; if ( left_disp <= right_disp ) pos = left_nearest; else pos = right_nearest; } else { /* this is a ghost stem; we simply round it */ pos = FT_PIX_ROUND( pos ); } } else { len = psh_dimension_quantize_len( dim, len, 0 ); } } /* now that we have a good hinted stem width, try to position */ /* the stem along a pixel grid integer coordinate */ hint->cur_pos = pos + psh_hint_snap_stem_side_delta( pos, len ); hint->cur_len = len; } } if ( do_snapping ) { pos = hint->cur_pos; len = hint->cur_len; if ( len < 64 ) len = 64; else len = FT_PIX_ROUND( len ); switch ( align.align ) { case PSH_BLUE_ALIGN_TOP: hint->cur_pos = align.align_top - len; hint->cur_len = len; break; case PSH_BLUE_ALIGN_BOT: hint->cur_len = len; break; case PSH_BLUE_ALIGN_BOT | PSH_BLUE_ALIGN_TOP: /* don't touch */ break; default: hint->cur_len = len; if ( len & 64 ) pos = FT_PIX_FLOOR( pos + ( len >> 1 ) ) + 32; else pos = FT_PIX_ROUND( pos + ( len >> 1 ) ); hint->cur_pos = pos - ( len >> 1 ); hint->cur_len = len; } } psh_hint_set_fitted( hint ); #ifdef DEBUG_HINTER if ( ps_debug_hint_func ) ps_debug_hint_func( hint, dimension ); #endif } } #if 0 /* not used for now, experimental */ /* * A variant to perform "light" hinting (i.e. FT_RENDER_MODE_LIGHT) * of stems */ static void psh_hint_align_light( PSH_Hint hint, PSH_Globals globals, FT_Int dimension, PSH_Glyph glyph ) { PSH_Dimension dim = &globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Fixed delta = dim->scale_delta; if ( !psh_hint_is_fitted( hint ) ) { FT_Pos pos = FT_MulFix( hint->org_pos, scale ) + delta; FT_Pos len = FT_MulFix( hint->org_len, scale ); FT_Pos fit_len; PSH_AlignmentRec align; /* ignore stem alignments when requested through the hint flags */ if ( ( dimension == 0 && !glyph->do_horz_hints ) || ( dimension == 1 && !glyph->do_vert_hints ) ) { hint->cur_pos = pos; hint->cur_len = len; psh_hint_set_fitted( hint ); return; } fit_len = len; hint->cur_len = fit_len; /* check blue zones for horizontal stems */ align.align = PSH_BLUE_ALIGN_NONE; align.align_bot = align.align_top = 0; if ( dimension == 1 ) psh_blues_snap_stem( &globals->blues, ADD_INT( hint->org_pos, hint->org_len ), hint->org_pos, &align ); switch ( align.align ) { case PSH_BLUE_ALIGN_TOP: /* the top of the stem is aligned against a blue zone */ hint->cur_pos = align.align_top - fit_len; break; case PSH_BLUE_ALIGN_BOT: /* the bottom of the stem is aligned against a blue zone */ hint->cur_pos = align.align_bot; break; case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT: /* both edges of the stem are aligned against blue zones */ hint->cur_pos = align.align_bot; hint->cur_len = align.align_top - align.align_bot; break; default: { PSH_Hint parent = hint->parent; if ( parent ) { FT_Pos par_org_center, par_cur_center; FT_Pos cur_org_center, cur_delta; /* ensure that parent is already fitted */ if ( !psh_hint_is_fitted( parent ) ) psh_hint_align_light( parent, globals, dimension, glyph ); par_org_center = parent->org_pos + ( parent->org_len / 2 ); par_cur_center = parent->cur_pos + ( parent->cur_len / 2 ); cur_org_center = hint->org_pos + ( hint->org_len / 2 ); cur_delta = FT_MulFix( cur_org_center - par_org_center, scale ); pos = par_cur_center + cur_delta - ( len >> 1 ); } /* Stems less than one pixel wide are easy -- we want to * make them as dark as possible, so they must fall within * one pixel. If the stem is split between two pixels * then snap the edge that is nearer to the pixel boundary * to the pixel boundary. */ if ( len <= 64 ) { if ( ( pos + len + 63 ) / 64 != pos / 64 + 1 ) pos += psh_hint_snap_stem_side_delta ( pos, len ); } /* Position stems other to minimize the amount of mid-grays. * There are, in general, two positions that do this, * illustrated as A) and B) below. * * + + + + * * A) |--------------------------------| * B) |--------------------------------| * C) |--------------------------------| * * Position A) (split the excess stem equally) should be better * for stems of width N + f where f < 0.5. * * Position B) (split the deficiency equally) should be better * for stems of width N + f where f > 0.5. * * It turns out though that minimizing the total number of lit * pixels is also important, so position C), with one edge * aligned with a pixel boundary is actually preferable * to A). There are also more possible positions for C) than * for A) or B), so it involves less distortion of the overall * character shape. */ else /* len > 64 */ { FT_Fixed frac_len = len & 63; FT_Fixed center = pos + ( len >> 1 ); FT_Fixed delta_a, delta_b; if ( ( len / 64 ) & 1 ) { delta_a = FT_PIX_FLOOR( center ) + 32 - center; delta_b = FT_PIX_ROUND( center ) - center; } else { delta_a = FT_PIX_ROUND( center ) - center; delta_b = FT_PIX_FLOOR( center ) + 32 - center; } /* We choose between B) and C) above based on the amount * of fractional stem width; for small amounts, choose * C) always, for large amounts, B) always, and inbetween, * pick whichever one involves less stem movement. */ if ( frac_len < 32 ) { pos += psh_hint_snap_stem_side_delta ( pos, len ); } else if ( frac_len < 48 ) { FT_Fixed side_delta = psh_hint_snap_stem_side_delta ( pos, len ); if ( FT_ABS( side_delta ) < FT_ABS( delta_b ) ) pos += side_delta; else pos += delta_b; } else { pos += delta_b; } } hint->cur_pos = pos; } } /* switch */ psh_hint_set_fitted( hint ); #ifdef DEBUG_HINTER if ( ps_debug_hint_func ) ps_debug_hint_func( hint, dimension ); #endif } } #endif /* 0 */ static void psh_hint_table_align_hints( PSH_Hint_Table table, PSH_Globals globals, FT_Int dimension, PSH_Glyph glyph ) { PSH_Hint hint; FT_UInt count; #ifdef DEBUG_HINTER PSH_Dimension dim = &globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Fixed delta = dim->scale_delta; if ( ps_debug_no_vert_hints && dimension == 0 ) { ps_simple_scale( table, scale, delta, dimension ); return; } if ( ps_debug_no_horz_hints && dimension == 1 ) { ps_simple_scale( table, scale, delta, dimension ); return; } #endif /* DEBUG_HINTER */ hint = table->hints; count = table->max_hints; for ( ; count > 0; count--, hint++ ) psh_hint_align( hint, globals, dimension, glyph ); } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** POINTS INTERPOLATION ROUTINES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define xxDEBUG_ZONES #ifdef DEBUG_ZONES #include FT_CONFIG_STANDARD_LIBRARY_H static void psh_print_zone( PSH_Zone zone ) { printf( "zone [scale,delta,min,max] = [%.5f,%.2f,%d,%d]\n", zone->scale / 65536.0, zone->delta / 64.0, zone->min, zone->max ); } #endif /* DEBUG_ZONES */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** HINTER GLYPH MANAGEMENT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define psh_corner_is_flat ft_corner_is_flat #define psh_corner_orientation ft_corner_orientation #ifdef COMPUTE_INFLEXS /* compute all inflex points in a given glyph */ static void psh_glyph_compute_inflections( PSH_Glyph glyph ) { FT_UInt n; for ( n = 0; n < glyph->num_contours; n++ ) { PSH_Point first, start, end, before, after; FT_Pos in_x, in_y, out_x, out_y; FT_Int orient_prev, orient_cur; FT_Int finished = 0; /* we need at least 4 points to create an inflection point */ if ( glyph->contours[n].count < 4 ) continue; /* compute first segment in contour */ first = glyph->contours[n].start; start = end = first; do { end = end->next; if ( end == first ) goto Skip; in_x = end->org_u - start->org_u; in_y = end->org_v - start->org_v; } while ( in_x == 0 && in_y == 0 ); /* extend the segment start whenever possible */ before = start; do { do { start = before; before = before->prev; if ( before == first ) goto Skip; out_x = start->org_u - before->org_u; out_y = start->org_v - before->org_v; } while ( out_x == 0 && out_y == 0 ); orient_prev = psh_corner_orientation( in_x, in_y, out_x, out_y ); } while ( orient_prev == 0 ); first = start; in_x = out_x; in_y = out_y; /* now, process all segments in the contour */ do { /* first, extend current segment's end whenever possible */ after = end; do { do { end = after; after = after->next; if ( after == first ) finished = 1; out_x = after->org_u - end->org_u; out_y = after->org_v - end->org_v; } while ( out_x == 0 && out_y == 0 ); orient_cur = psh_corner_orientation( in_x, in_y, out_x, out_y ); } while ( orient_cur == 0 ); if ( ( orient_cur ^ orient_prev ) < 0 ) { do { psh_point_set_inflex( start ); start = start->next; } while ( start != end ); psh_point_set_inflex( start ); } start = end; end = after; orient_prev = orient_cur; in_x = out_x; in_y = out_y; } while ( !finished ); Skip: ; } } #endif /* COMPUTE_INFLEXS */ static void psh_glyph_done( PSH_Glyph glyph ) { FT_Memory memory = glyph->memory; psh_hint_table_done( &glyph->hint_tables[1], memory ); psh_hint_table_done( &glyph->hint_tables[0], memory ); FT_FREE( glyph->points ); FT_FREE( glyph->contours ); glyph->num_points = 0; glyph->num_contours = 0; glyph->memory = NULL; } static PSH_Dir psh_compute_dir( FT_Pos dx, FT_Pos dy ) { FT_Pos ax, ay; PSH_Dir result = PSH_DIR_NONE; ax = FT_ABS( dx ); ay = FT_ABS( dy ); if ( ay * 12 < ax ) { /* |dy| <<< |dx| means a near-horizontal segment */ result = ( dx >= 0 ) ? PSH_DIR_RIGHT : PSH_DIR_LEFT; } else if ( ax * 12 < ay ) { /* |dx| <<< |dy| means a near-vertical segment */ result = ( dy >= 0 ) ? PSH_DIR_UP : PSH_DIR_DOWN; } return result; } /* load outline point coordinates into hinter glyph */ static void psh_glyph_load_points( PSH_Glyph glyph, FT_Int dimension ) { FT_Vector* vec = glyph->outline->points; PSH_Point point = glyph->points; FT_UInt count = glyph->num_points; for ( ; count > 0; count--, point++, vec++ ) { point->flags2 = 0; point->hint = NULL; if ( dimension == 0 ) { point->org_u = vec->x; point->org_v = vec->y; } else { point->org_u = vec->y; point->org_v = vec->x; } #ifdef DEBUG_HINTER point->org_x = vec->x; point->org_y = vec->y; #endif } } /* save hinted point coordinates back to outline */ static void psh_glyph_save_points( PSH_Glyph glyph, FT_Int dimension ) { FT_UInt n; PSH_Point point = glyph->points; FT_Vector* vec = glyph->outline->points; char* tags = glyph->outline->tags; for ( n = 0; n < glyph->num_points; n++ ) { if ( dimension == 0 ) vec[n].x = point->cur_u; else vec[n].y = point->cur_u; if ( psh_point_is_strong( point ) ) tags[n] |= (char)( ( dimension == 0 ) ? 32 : 64 ); #ifdef DEBUG_HINTER if ( dimension == 0 ) { point->cur_x = point->cur_u; point->flags_x = point->flags2 | point->flags; } else { point->cur_y = point->cur_u; point->flags_y = point->flags2 | point->flags; } #endif point++; } } static FT_Error psh_glyph_init( PSH_Glyph glyph, FT_Outline* outline, PS_Hints ps_hints, PSH_Globals globals ) { FT_Error error; FT_Memory memory; /* clear all fields */ FT_ZERO( glyph ); memory = glyph->memory = globals->memory; /* allocate and setup points + contours arrays */ if ( FT_QNEW_ARRAY( glyph->points, outline->n_points ) || FT_QNEW_ARRAY( glyph->contours, outline->n_contours ) ) goto Exit; glyph->num_points = (FT_UInt)outline->n_points; glyph->num_contours = (FT_UInt)outline->n_contours; { FT_UInt first = 0, next, n; PSH_Point points = glyph->points; PSH_Contour contour = glyph->contours; for ( n = 0; n < glyph->num_contours; n++ ) { FT_UInt count; PSH_Point point; next = (FT_UInt)outline->contours[n] + 1; count = next - first; contour->start = points + first; contour->count = count; if ( count > 0 ) { point = points + first; point->prev = points + next - 1; point->contour = contour; for ( ; count > 1; count-- ) { point[0].next = point + 1; point[1].prev = point; point++; point->contour = contour; } point->next = points + first; } contour++; first = next; } } { PSH_Point points = glyph->points; PSH_Point point = points; FT_Vector* vec = outline->points; FT_UInt n; for ( n = 0; n < glyph->num_points; n++, point++ ) { FT_Int n_prev = (FT_Int)( point->prev - points ); FT_Int n_next = (FT_Int)( point->next - points ); FT_Pos dxi, dyi, dxo, dyo; point->flags = 0; if ( !( outline->tags[n] & FT_CURVE_TAG_ON ) ) psh_point_set_off( point ); dxi = vec[n].x - vec[n_prev].x; dyi = vec[n].y - vec[n_prev].y; point->dir_in = psh_compute_dir( dxi, dyi ); dxo = vec[n_next].x - vec[n].x; dyo = vec[n_next].y - vec[n].y; point->dir_out = psh_compute_dir( dxo, dyo ); /* detect smooth points */ if ( psh_point_is_off( point ) ) psh_point_set_smooth( point ); else if ( point->dir_in == point->dir_out ) { if ( point->dir_out != PSH_DIR_NONE || psh_corner_is_flat( dxi, dyi, dxo, dyo ) ) psh_point_set_smooth( point ); } } } glyph->outline = outline; glyph->globals = globals; #ifdef COMPUTE_INFLEXS psh_glyph_load_points( glyph, 0 ); psh_glyph_compute_inflections( glyph ); #endif /* COMPUTE_INFLEXS */ /* now deal with hints tables */ error = psh_hint_table_init( &glyph->hint_tables [0], &ps_hints->dimension[0].hints, &ps_hints->dimension[0].masks, &ps_hints->dimension[0].counters, memory ); if ( error ) goto Exit; error = psh_hint_table_init( &glyph->hint_tables [1], &ps_hints->dimension[1].hints, &ps_hints->dimension[1].masks, &ps_hints->dimension[1].counters, memory ); if ( error ) goto Exit; Exit: return error; } /* compute all extrema in a glyph for a given dimension */ static void psh_glyph_compute_extrema( PSH_Glyph glyph ) { FT_UInt n; /* first of all, compute all local extrema */ for ( n = 0; n < glyph->num_contours; n++ ) { PSH_Point first = glyph->contours[n].start; PSH_Point point, before, after; if ( glyph->contours[n].count == 0 ) continue; point = first; before = point; do { before = before->prev; if ( before == first ) goto Skip; } while ( before->org_u == point->org_u ); first = point = before->next; for (;;) { after = point; do { after = after->next; if ( after == first ) goto Next; } while ( after->org_u == point->org_u ); if ( before->org_u < point->org_u ) { if ( after->org_u < point->org_u ) { /* local maximum */ goto Extremum; } } else /* before->org_u > point->org_u */ { if ( after->org_u > point->org_u ) { /* local minimum */ Extremum: do { psh_point_set_extremum( point ); point = point->next; } while ( point != after ); } } before = after->prev; point = after; } /* for */ Next: ; } /* for each extremum, determine its direction along the */ /* orthogonal axis */ for ( n = 0; n < glyph->num_points; n++ ) { PSH_Point point, before, after; point = &glyph->points[n]; before = point; after = point; if ( psh_point_is_extremum( point ) ) { do { before = before->prev; if ( before == point ) goto Skip; } while ( before->org_v == point->org_v ); do { after = after->next; if ( after == point ) goto Skip; } while ( after->org_v == point->org_v ); } if ( before->org_v < point->org_v && after->org_v > point->org_v ) { psh_point_set_positive( point ); } else if ( before->org_v > point->org_v && after->org_v < point->org_v ) { psh_point_set_negative( point ); } Skip: ; } } /* the min and max are based on contour orientation and fill rule */ static void psh_hint_table_find_strong_points( PSH_Hint_Table table, PSH_Point point, FT_UInt count, FT_Int threshold, PSH_Dir major_dir ) { PSH_Hint* sort = table->sort; FT_UInt num_hints = table->num_hints; for ( ; count > 0; count--, point++ ) { PSH_Dir point_dir; FT_Pos org_u = point->org_u; if ( psh_point_is_strong( point ) ) continue; point_dir = (PSH_Dir)( ( point->dir_in | point->dir_out ) & major_dir ); if ( point_dir & ( PSH_DIR_DOWN | PSH_DIR_RIGHT ) ) { FT_UInt nn; for ( nn = 0; nn < num_hints; nn++ ) { PSH_Hint hint = sort[nn]; FT_Pos d = org_u - hint->org_pos; if ( d < threshold && -d < threshold ) { psh_point_set_strong( point ); point->flags2 |= PSH_POINT_EDGE_MIN; point->hint = hint; break; } } } else if ( point_dir & ( PSH_DIR_UP | PSH_DIR_LEFT ) ) { FT_UInt nn; for ( nn = 0; nn < num_hints; nn++ ) { PSH_Hint hint = sort[nn]; FT_Pos d = org_u - hint->org_pos - hint->org_len; if ( d < threshold && -d < threshold ) { psh_point_set_strong( point ); point->flags2 |= PSH_POINT_EDGE_MAX; point->hint = hint; break; } } } #if 1 else if ( psh_point_is_extremum( point ) ) { /* treat extrema as special cases for stem edge alignment */ FT_UInt nn, min_flag, max_flag; if ( major_dir == PSH_DIR_HORIZONTAL ) { min_flag = PSH_POINT_POSITIVE; max_flag = PSH_POINT_NEGATIVE; } else { min_flag = PSH_POINT_NEGATIVE; max_flag = PSH_POINT_POSITIVE; } if ( point->flags2 & min_flag ) { for ( nn = 0; nn < num_hints; nn++ ) { PSH_Hint hint = sort[nn]; FT_Pos d = org_u - hint->org_pos; if ( d < threshold && -d < threshold ) { point->flags2 |= PSH_POINT_EDGE_MIN; point->hint = hint; psh_point_set_strong( point ); break; } } } else if ( point->flags2 & max_flag ) { for ( nn = 0; nn < num_hints; nn++ ) { PSH_Hint hint = sort[nn]; FT_Pos d = org_u - hint->org_pos - hint->org_len; if ( d < threshold && -d < threshold ) { point->flags2 |= PSH_POINT_EDGE_MAX; point->hint = hint; psh_point_set_strong( point ); break; } } } if ( !point->hint ) { for ( nn = 0; nn < num_hints; nn++ ) { PSH_Hint hint = sort[nn]; if ( org_u >= hint->org_pos && org_u <= ADD_INT( hint->org_pos, hint->org_len ) ) { point->hint = hint; break; } } } } #endif /* 1 */ } } /* the accepted shift for strong points in fractional pixels */ #define PSH_STRONG_THRESHOLD 32 /* the maximum shift value in font units tuned to distinguish */ /* between stems and serifs in URW+ font collection */ #define PSH_STRONG_THRESHOLD_MAXIMUM 12 /* find strong points in a glyph */ static void psh_glyph_find_strong_points( PSH_Glyph glyph, FT_Int dimension ) { /* a point is `strong' if it is located on a stem edge and */ /* has an `in' or `out' tangent parallel to the hint's direction */ PSH_Hint_Table table = &glyph->hint_tables[dimension]; PS_Mask mask = table->hint_masks->masks; FT_UInt num_masks = table->hint_masks->num_masks; FT_UInt first = 0; PSH_Dir major_dir = ( dimension == 0 ) ? PSH_DIR_VERTICAL : PSH_DIR_HORIZONTAL; PSH_Dimension dim = &glyph->globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Int threshold; threshold = (FT_Int)FT_DivFix( PSH_STRONG_THRESHOLD, scale ); if ( threshold > PSH_STRONG_THRESHOLD_MAXIMUM ) threshold = PSH_STRONG_THRESHOLD_MAXIMUM; /* process secondary hints to `selected' points */ if ( num_masks > 1 && glyph->num_points > 0 ) { /* the `endchar' op can reduce the number of points */ first = mask->end_point > glyph->num_points ? glyph->num_points : mask->end_point; mask++; for ( ; num_masks > 1; num_masks--, mask++ ) { FT_UInt next = FT_MIN( mask->end_point, glyph->num_points ); if ( next > first ) { FT_UInt count = next - first; PSH_Point point = glyph->points + first; psh_hint_table_activate_mask( table, mask ); psh_hint_table_find_strong_points( table, point, count, threshold, major_dir ); } first = next; } } /* process primary hints for all points */ if ( num_masks == 1 ) { FT_UInt count = glyph->num_points; PSH_Point point = glyph->points; psh_hint_table_activate_mask( table, table->hint_masks->masks ); psh_hint_table_find_strong_points( table, point, count, threshold, major_dir ); } /* now, certain points may have been attached to a hint and */ /* not marked as strong; update their flags then */ { FT_UInt count = glyph->num_points; PSH_Point point = glyph->points; for ( ; count > 0; count--, point++ ) if ( point->hint && !psh_point_is_strong( point ) ) psh_point_set_strong( point ); } } /* find points in a glyph which are in a blue zone and have `in' or */ /* `out' tangents parallel to the horizontal axis */ static void psh_glyph_find_blue_points( PSH_Blues blues, PSH_Glyph glyph ) { PSH_Blue_Table table; PSH_Blue_Zone zone; FT_UInt glyph_count = glyph->num_points; FT_UInt blue_count; PSH_Point point = glyph->points; for ( ; glyph_count > 0; glyph_count--, point++ ) { FT_Pos y; /* check tangents */ if ( !( point->dir_in & PSH_DIR_HORIZONTAL ) && !( point->dir_out & PSH_DIR_HORIZONTAL ) ) continue; /* skip strong points */ if ( psh_point_is_strong( point ) ) continue; y = point->org_u; /* look up top zones */ table = &blues->normal_top; blue_count = table->count; zone = table->zones; for ( ; blue_count > 0; blue_count--, zone++ ) { FT_Pos delta = y - zone->org_bottom; if ( delta < -blues->blue_fuzz ) break; if ( y <= zone->org_top + blues->blue_fuzz ) if ( blues->no_overshoots || delta <= blues->blue_threshold ) { point->cur_u = zone->cur_bottom; psh_point_set_strong( point ); psh_point_set_fitted( point ); } } /* look up bottom zones */ table = &blues->normal_bottom; blue_count = table->count; zone = table->zones + blue_count - 1; for ( ; blue_count > 0; blue_count--, zone-- ) { FT_Pos delta = zone->org_top - y; if ( delta < -blues->blue_fuzz ) break; if ( y >= zone->org_bottom - blues->blue_fuzz ) if ( blues->no_overshoots || delta < blues->blue_threshold ) { point->cur_u = zone->cur_top; psh_point_set_strong( point ); psh_point_set_fitted( point ); } } } } /* interpolate strong points with the help of hinted coordinates */ static void psh_glyph_interpolate_strong_points( PSH_Glyph glyph, FT_Int dimension ) { PSH_Dimension dim = &glyph->globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_UInt count = glyph->num_points; PSH_Point point = glyph->points; for ( ; count > 0; count--, point++ ) { PSH_Hint hint = point->hint; if ( hint ) { FT_Pos delta; if ( psh_point_is_edge_min( point ) ) point->cur_u = hint->cur_pos; else if ( psh_point_is_edge_max( point ) ) point->cur_u = hint->cur_pos + hint->cur_len; else { delta = point->org_u - hint->org_pos; if ( delta <= 0 ) point->cur_u = hint->cur_pos + FT_MulFix( delta, scale ); else if ( delta >= hint->org_len ) point->cur_u = hint->cur_pos + hint->cur_len + FT_MulFix( delta - hint->org_len, scale ); else /* hint->org_len > 0 */ point->cur_u = hint->cur_pos + FT_MulDiv( delta, hint->cur_len, hint->org_len ); } psh_point_set_fitted( point ); } } } #define PSH_MAX_STRONG_INTERNAL 16 static void psh_glyph_interpolate_normal_points( PSH_Glyph glyph, FT_Int dimension ) { #if 1 /* first technique: a point is strong if it is a local extremum */ PSH_Dimension dim = &glyph->globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Memory memory = glyph->memory; PSH_Point* strongs = NULL; PSH_Point strongs_0[PSH_MAX_STRONG_INTERNAL]; FT_UInt num_strongs = 0; PSH_Point points = glyph->points; PSH_Point points_end = points + glyph->num_points; PSH_Point point; /* first count the number of strong points */ for ( point = points; point < points_end; point++ ) { if ( psh_point_is_strong( point ) ) num_strongs++; } if ( num_strongs == 0 ) /* nothing to do here */ return; /* allocate an array to store a list of points, */ /* stored in increasing org_u order */ if ( num_strongs <= PSH_MAX_STRONG_INTERNAL ) strongs = strongs_0; else { FT_Error error; if ( FT_QNEW_ARRAY( strongs, num_strongs ) ) return; } num_strongs = 0; for ( point = points; point < points_end; point++ ) { PSH_Point* insert; if ( !psh_point_is_strong( point ) ) continue; for ( insert = strongs + num_strongs; insert > strongs; insert-- ) { if ( insert[-1]->org_u <= point->org_u ) break; insert[0] = insert[-1]; } insert[0] = point; num_strongs++; } /* now try to interpolate all normal points */ for ( point = points; point < points_end; point++ ) { if ( psh_point_is_strong( point ) ) continue; /* sometimes, some local extrema are smooth points */ if ( psh_point_is_smooth( point ) ) { if ( point->dir_in == PSH_DIR_NONE || point->dir_in != point->dir_out ) continue; if ( !psh_point_is_extremum( point ) && !psh_point_is_inflex( point ) ) continue; point->flags &= ~PSH_POINT_SMOOTH; } /* find best enclosing point coordinates then interpolate */ { PSH_Point before, after; FT_UInt nn; for ( nn = 0; nn < num_strongs; nn++ ) if ( strongs[nn]->org_u > point->org_u ) break; if ( nn == 0 ) /* point before the first strong point */ { after = strongs[0]; point->cur_u = after->cur_u + FT_MulFix( point->org_u - after->org_u, scale ); } else { before = strongs[nn - 1]; for ( nn = num_strongs; nn > 0; nn-- ) if ( strongs[nn - 1]->org_u < point->org_u ) break; if ( nn == num_strongs ) /* point is after last strong point */ { before = strongs[nn - 1]; point->cur_u = before->cur_u + FT_MulFix( point->org_u - before->org_u, scale ); } else { FT_Pos u; after = strongs[nn]; /* now interpolate point between before and after */ u = point->org_u; if ( u == before->org_u ) point->cur_u = before->cur_u; else if ( u == after->org_u ) point->cur_u = after->cur_u; else point->cur_u = before->cur_u + FT_MulDiv( u - before->org_u, after->cur_u - before->cur_u, after->org_u - before->org_u ); } } psh_point_set_fitted( point ); } } if ( strongs != strongs_0 ) FT_FREE( strongs ); #endif /* 1 */ } /* interpolate other points */ static void psh_glyph_interpolate_other_points( PSH_Glyph glyph, FT_Int dimension ) { PSH_Dimension dim = &glyph->globals->dimension[dimension]; FT_Fixed scale = dim->scale_mult; FT_Fixed delta = dim->scale_delta; PSH_Contour contour = glyph->contours; FT_UInt num_contours = glyph->num_contours; for ( ; num_contours > 0; num_contours--, contour++ ) { PSH_Point start = contour->start; PSH_Point first, next, point; FT_UInt fit_count; /* count the number of strong points in this contour */ next = start + contour->count; fit_count = 0; first = NULL; for ( point = start; point < next; point++ ) if ( psh_point_is_fitted( point ) ) { if ( !first ) first = point; fit_count++; } /* if there are less than 2 fitted points in the contour, we */ /* simply scale and eventually translate the contour points */ if ( fit_count < 2 ) { if ( fit_count == 1 ) delta = first->cur_u - FT_MulFix( first->org_u, scale ); for ( point = start; point < next; point++ ) if ( point != first ) point->cur_u = FT_MulFix( point->org_u, scale ) + delta; goto Next_Contour; } /* there are more than 2 strong points in this contour; we */ /* need to interpolate weak points between them */ start = first; do { /* skip consecutive fitted points */ for (;;) { next = first->next; if ( next == start ) goto Next_Contour; if ( !psh_point_is_fitted( next ) ) break; first = next; } /* find next fitted point after unfitted one */ for (;;) { next = next->next; if ( psh_point_is_fitted( next ) ) break; } /* now interpolate between them */ { FT_Pos org_a, org_ab, cur_a, cur_ab; FT_Pos org_c, org_ac, cur_c; FT_Fixed scale_ab; if ( first->org_u <= next->org_u ) { org_a = first->org_u; cur_a = first->cur_u; org_ab = next->org_u - org_a; cur_ab = next->cur_u - cur_a; } else { org_a = next->org_u; cur_a = next->cur_u; org_ab = first->org_u - org_a; cur_ab = first->cur_u - cur_a; } scale_ab = 0x10000L; if ( org_ab > 0 ) scale_ab = FT_DivFix( cur_ab, org_ab ); point = first->next; do { org_c = point->org_u; org_ac = org_c - org_a; if ( org_ac <= 0 ) { /* on the left of the interpolation zone */ cur_c = cur_a + FT_MulFix( org_ac, scale ); } else if ( org_ac >= org_ab ) { /* on the right on the interpolation zone */ cur_c = cur_a + cur_ab + FT_MulFix( org_ac - org_ab, scale ); } else { /* within the interpolation zone */ cur_c = cur_a + FT_MulFix( org_ac, scale_ab ); } point->cur_u = cur_c; point = point->next; } while ( point != next ); } /* keep going until all points in the contours have been processed */ first = next; } while ( first != start ); Next_Contour: ; } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** HIGH-LEVEL INTERFACE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_Error ps_hints_apply( PS_Hints ps_hints, FT_Outline* outline, PSH_Globals globals, FT_Render_Mode hint_mode ) { PSH_GlyphRec glyphrec; PSH_Glyph glyph = &glyphrec; FT_Error error; #ifdef DEBUG_HINTER FT_Memory memory; #endif FT_Int dimension; /* something to do? */ if ( outline->n_points == 0 || outline->n_contours == 0 ) return FT_Err_Ok; #ifdef DEBUG_HINTER memory = globals->memory; if ( ps_debug_glyph ) { psh_glyph_done( ps_debug_glyph ); FT_FREE( ps_debug_glyph ); } if ( FT_NEW( glyph ) ) return error; ps_debug_glyph = glyph; #endif /* DEBUG_HINTER */ error = psh_glyph_init( glyph, outline, ps_hints, globals ); if ( error ) goto Exit; /* try to optimize the y_scale so that the top of non-capital letters * is aligned on a pixel boundary whenever possible */ { PSH_Dimension dim_x = &glyph->globals->dimension[0]; PSH_Dimension dim_y = &glyph->globals->dimension[1]; FT_Fixed x_scale = dim_x->scale_mult; FT_Fixed y_scale = dim_y->scale_mult; FT_Fixed old_x_scale = x_scale; FT_Fixed old_y_scale = y_scale; FT_Fixed scaled = 0; FT_Fixed fitted = 0; FT_Bool rescale = FALSE; if ( globals->blues.normal_top.count ) { scaled = FT_MulFix( globals->blues.normal_top.zones->org_ref, y_scale ); fitted = FT_PIX_ROUND( scaled ); } if ( fitted != 0 && scaled != fitted ) { rescale = TRUE; y_scale = FT_MulDiv( y_scale, fitted, scaled ); if ( fitted < scaled ) x_scale -= x_scale / 50; psh_globals_set_scale( glyph->globals, x_scale, y_scale, 0, 0 ); } glyph->do_horz_hints = 1; glyph->do_vert_hints = 1; glyph->do_horz_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO || hint_mode == FT_RENDER_MODE_LCD ); glyph->do_vert_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO || hint_mode == FT_RENDER_MODE_LCD_V ); glyph->do_stem_adjust = FT_BOOL( hint_mode != FT_RENDER_MODE_LIGHT ); for ( dimension = 0; dimension < 2; dimension++ ) { /* load outline coordinates into glyph */ psh_glyph_load_points( glyph, dimension ); /* compute local extrema */ psh_glyph_compute_extrema( glyph ); /* compute aligned stem/hints positions */ psh_hint_table_align_hints( &glyph->hint_tables[dimension], glyph->globals, dimension, glyph ); /* find strong points, align them, then interpolate others */ psh_glyph_find_strong_points( glyph, dimension ); if ( dimension == 1 ) psh_glyph_find_blue_points( &globals->blues, glyph ); psh_glyph_interpolate_strong_points( glyph, dimension ); psh_glyph_interpolate_normal_points( glyph, dimension ); psh_glyph_interpolate_other_points( glyph, dimension ); /* save hinted coordinates back to outline */ psh_glyph_save_points( glyph, dimension ); if ( rescale ) psh_globals_set_scale( glyph->globals, old_x_scale, old_y_scale, 0, 0 ); } } Exit: #ifndef DEBUG_HINTER psh_glyph_done( glyph ); #endif return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshalgo.c
C++
gpl-3.0
58,961
/**************************************************************************** * * pshalgo.h * * PostScript hinting algorithm (specification). * * Copyright (C) 2001-2022 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 PSHALGO_H_ #define PSHALGO_H_ #include "pshrec.h" #include "pshglob.h" FT_BEGIN_HEADER /* handle to Hint structure */ typedef struct PSH_HintRec_* PSH_Hint; /* hint bit-flags */ #define PSH_HINT_GHOST PS_HINT_FLAG_GHOST #define PSH_HINT_BOTTOM PS_HINT_FLAG_BOTTOM #define PSH_HINT_ACTIVE 4U #define PSH_HINT_FITTED 8U #define psh_hint_is_active( x ) ( ( (x)->flags & PSH_HINT_ACTIVE ) != 0 ) #define psh_hint_is_ghost( x ) ( ( (x)->flags & PSH_HINT_GHOST ) != 0 ) #define psh_hint_is_fitted( x ) ( ( (x)->flags & PSH_HINT_FITTED ) != 0 ) #define psh_hint_activate( x ) (x)->flags |= PSH_HINT_ACTIVE #define psh_hint_deactivate( x ) (x)->flags &= ~PSH_HINT_ACTIVE #define psh_hint_set_fitted( x ) (x)->flags |= PSH_HINT_FITTED /* hint structure */ typedef struct PSH_HintRec_ { FT_Int org_pos; FT_Int org_len; FT_Pos cur_pos; FT_Pos cur_len; FT_UInt flags; PSH_Hint parent; FT_Int order; } PSH_HintRec; /* this is an interpolation zone used for strong points; */ /* weak points are interpolated according to their strong */ /* neighbours */ typedef struct PSH_ZoneRec_ { FT_Fixed scale; FT_Fixed delta; FT_Pos min; FT_Pos max; } PSH_ZoneRec, *PSH_Zone; typedef struct PSH_Hint_TableRec_ { FT_UInt max_hints; FT_UInt num_hints; PSH_Hint hints; PSH_Hint* sort; PSH_Hint* sort_global; FT_UInt num_zones; PSH_ZoneRec* zones; PSH_Zone zone; PS_Mask_Table hint_masks; PS_Mask_Table counter_masks; } PSH_Hint_TableRec, *PSH_Hint_Table; typedef struct PSH_PointRec_* PSH_Point; typedef struct PSH_ContourRec_* PSH_Contour; typedef enum PSH_Dir_ { PSH_DIR_NONE = 0, PSH_DIR_UP = 1, PSH_DIR_DOWN = 2, PSH_DIR_VERTICAL = 1 | 2, PSH_DIR_LEFT = 4, PSH_DIR_RIGHT = 8, PSH_DIR_HORIZONTAL = 4 | 8 } PSH_Dir; /* the following bit-flags are computed once by the glyph */ /* analyzer, for both dimensions */ #define PSH_POINT_OFF 1U /* point is off the curve */ #define PSH_POINT_SMOOTH 2U /* point is smooth */ #define PSH_POINT_INFLEX 4U /* point is inflection */ #define psh_point_is_smooth( p ) ( (p)->flags & PSH_POINT_SMOOTH ) #define psh_point_is_off( p ) ( (p)->flags & PSH_POINT_OFF ) #define psh_point_is_inflex( p ) ( (p)->flags & PSH_POINT_INFLEX ) #define psh_point_set_smooth( p ) (p)->flags |= PSH_POINT_SMOOTH #define psh_point_set_off( p ) (p)->flags |= PSH_POINT_OFF #define psh_point_set_inflex( p ) (p)->flags |= PSH_POINT_INFLEX /* the following bit-flags are re-computed for each dimension */ #define PSH_POINT_STRONG 16U /* point is strong */ #define PSH_POINT_FITTED 32U /* point is already fitted */ #define PSH_POINT_EXTREMUM 64U /* point is local extremum */ #define PSH_POINT_POSITIVE 128U /* extremum has positive contour flow */ #define PSH_POINT_NEGATIVE 256U /* extremum has negative contour flow */ #define PSH_POINT_EDGE_MIN 512U /* point is aligned to left/bottom stem edge */ #define PSH_POINT_EDGE_MAX 1024U /* point is aligned to top/right stem edge */ #define psh_point_is_strong( p ) ( (p)->flags2 & PSH_POINT_STRONG ) #define psh_point_is_fitted( p ) ( (p)->flags2 & PSH_POINT_FITTED ) #define psh_point_is_extremum( p ) ( (p)->flags2 & PSH_POINT_EXTREMUM ) #define psh_point_is_positive( p ) ( (p)->flags2 & PSH_POINT_POSITIVE ) #define psh_point_is_negative( p ) ( (p)->flags2 & PSH_POINT_NEGATIVE ) #define psh_point_is_edge_min( p ) ( (p)->flags2 & PSH_POINT_EDGE_MIN ) #define psh_point_is_edge_max( p ) ( (p)->flags2 & PSH_POINT_EDGE_MAX ) #define psh_point_set_strong( p ) (p)->flags2 |= PSH_POINT_STRONG #define psh_point_set_fitted( p ) (p)->flags2 |= PSH_POINT_FITTED #define psh_point_set_extremum( p ) (p)->flags2 |= PSH_POINT_EXTREMUM #define psh_point_set_positive( p ) (p)->flags2 |= PSH_POINT_POSITIVE #define psh_point_set_negative( p ) (p)->flags2 |= PSH_POINT_NEGATIVE #define psh_point_set_edge_min( p ) (p)->flags2 |= PSH_POINT_EDGE_MIN #define psh_point_set_edge_max( p ) (p)->flags2 |= PSH_POINT_EDGE_MAX typedef struct PSH_PointRec_ { PSH_Point prev; PSH_Point next; PSH_Contour contour; FT_UInt flags; FT_UInt flags2; PSH_Dir dir_in; PSH_Dir dir_out; PSH_Hint hint; FT_Pos org_u; FT_Pos org_v; FT_Pos cur_u; #ifdef DEBUG_HINTER FT_Pos org_x; FT_Pos cur_x; FT_Pos org_y; FT_Pos cur_y; FT_UInt flags_x; FT_UInt flags_y; #endif } PSH_PointRec; typedef struct PSH_ContourRec_ { PSH_Point start; FT_UInt count; } PSH_ContourRec; typedef struct PSH_GlyphRec_ { FT_UInt num_points; FT_UInt num_contours; PSH_Point points; PSH_Contour contours; FT_Memory memory; FT_Outline* outline; PSH_Globals globals; PSH_Hint_TableRec hint_tables[2]; FT_Bool do_horz_hints; FT_Bool do_vert_hints; FT_Bool do_horz_snapping; FT_Bool do_vert_snapping; FT_Bool do_stem_adjust; } PSH_GlyphRec, *PSH_Glyph; #ifdef DEBUG_HINTER extern PSH_Hint_Table ps_debug_hint_table; typedef void (*PSH_HintFunc)( PSH_Hint hint, FT_Bool vertical ); extern PSH_HintFunc ps_debug_hint_func; extern PSH_Glyph ps_debug_glyph; #endif extern FT_Error ps_hints_apply( PS_Hints ps_hints, FT_Outline* outline, PSH_Globals globals, FT_Render_Mode hint_mode ); FT_END_HEADER #endif /* PSHALGO_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshalgo.h
C++
gpl-3.0
6,616
/**************************************************************************** * * pshglob.c * * PostScript hinter global hinting management (body). * Inspired by the new auto-hinter module. * * Copyright (C) 2001-2022 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 <freetype/freetype.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftcalc.h> #include "pshglob.h" #ifdef DEBUG_HINTER PSH_Globals ps_debug_globals = NULL; #endif /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** STANDARD WIDTHS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* scale the widths/heights table */ static void psh_globals_scale_widths( PSH_Globals globals, FT_UInt direction ) { PSH_Dimension dim = &globals->dimension[direction]; PSH_Widths stdw = &dim->stdw; FT_UInt count = stdw->count; PSH_Width width = stdw->widths; PSH_Width stand = width; /* standard width/height */ FT_Fixed scale = dim->scale_mult; if ( count > 0 ) { width->cur = FT_MulFix( width->org, scale ); width->fit = FT_PIX_ROUND( width->cur ); width++; count--; for ( ; count > 0; count--, width++ ) { FT_Pos w, dist; w = FT_MulFix( width->org, scale ); dist = w - stand->cur; if ( dist < 0 ) dist = -dist; if ( dist < 128 ) w = stand->cur; width->cur = w; width->fit = FT_PIX_ROUND( w ); } } } #if 0 /* org_width is in font units, result in device pixels, 26.6 format */ FT_LOCAL_DEF( FT_Pos ) psh_dimension_snap_width( PSH_Dimension dimension, FT_Int org_width ) { FT_UInt n; FT_Pos width = FT_MulFix( org_width, dimension->scale_mult ); FT_Pos best = 64 + 32 + 2; FT_Pos reference = width; for ( n = 0; n < dimension->stdw.count; n++ ) { FT_Pos w; FT_Pos dist; w = dimension->stdw.widths[n].cur; dist = width - w; if ( dist < 0 ) dist = -dist; if ( dist < best ) { best = dist; reference = w; } } if ( width >= reference ) { width -= 0x21; if ( width < reference ) width = reference; } else { width += 0x21; if ( width > reference ) width = reference; } return width; } #endif /* 0 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** BLUE ZONES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void psh_blues_set_zones_0( PSH_Blues target, FT_Bool is_others, FT_UInt read_count, FT_Short* read, PSH_Blue_Table top_table, PSH_Blue_Table bot_table ) { FT_UInt count_top = top_table->count; FT_UInt count_bot = bot_table->count; FT_Bool first = 1; FT_UNUSED( target ); for ( ; read_count > 1; read_count -= 2 ) { FT_Int reference, delta; FT_UInt count; PSH_Blue_Zone zones, zone; FT_Bool top; /* read blue zone entry, and select target top/bottom zone */ top = 0; if ( first || is_others ) { reference = read[1]; delta = read[0] - reference; zones = bot_table->zones; count = count_bot; first = 0; } else { reference = read[0]; delta = read[1] - reference; zones = top_table->zones; count = count_top; top = 1; } /* insert into sorted table */ zone = zones; for ( ; count > 0; count--, zone++ ) { if ( reference < zone->org_ref ) break; if ( reference == zone->org_ref ) { FT_Int delta0 = zone->org_delta; /* we have two zones on the same reference position -- */ /* only keep the largest one */ if ( delta < 0 ) { if ( delta < delta0 ) zone->org_delta = delta; } else { if ( delta > delta0 ) zone->org_delta = delta; } goto Skip; } } for ( ; count > 0; count-- ) zone[count] = zone[count-1]; zone->org_ref = reference; zone->org_delta = delta; if ( top ) count_top++; else count_bot++; Skip: read += 2; } top_table->count = count_top; bot_table->count = count_bot; } /* Re-read blue zones from the original fonts and store them into our */ /* private structure. This function re-orders, sanitizes, and */ /* fuzz-expands the zones as well. */ static void psh_blues_set_zones( PSH_Blues target, FT_UInt count, FT_Short* blues, FT_UInt count_others, FT_Short* other_blues, FT_Int fuzz, FT_Int family ) { PSH_Blue_Table top_table, bot_table; FT_UInt count_top, count_bot; if ( family ) { top_table = &target->family_top; bot_table = &target->family_bottom; } else { top_table = &target->normal_top; bot_table = &target->normal_bottom; } /* read the input blue zones, and build two sorted tables */ /* (one for the top zones, the other for the bottom zones) */ top_table->count = 0; bot_table->count = 0; /* first, the blues */ psh_blues_set_zones_0( target, 0, count, blues, top_table, bot_table ); psh_blues_set_zones_0( target, 1, count_others, other_blues, top_table, bot_table ); count_top = top_table->count; count_bot = bot_table->count; /* sanitize top table */ if ( count_top > 0 ) { PSH_Blue_Zone zone = top_table->zones; for ( count = count_top; count > 0; count--, zone++ ) { FT_Int delta; if ( count > 1 ) { delta = zone[1].org_ref - zone[0].org_ref; if ( zone->org_delta > delta ) zone->org_delta = delta; } zone->org_bottom = zone->org_ref; zone->org_top = zone->org_delta + zone->org_ref; } } /* sanitize bottom table */ if ( count_bot > 0 ) { PSH_Blue_Zone zone = bot_table->zones; for ( count = count_bot; count > 0; count--, zone++ ) { FT_Int delta; if ( count > 1 ) { delta = zone[0].org_ref - zone[1].org_ref; if ( zone->org_delta < delta ) zone->org_delta = delta; } zone->org_top = zone->org_ref; zone->org_bottom = zone->org_delta + zone->org_ref; } } /* expand top and bottom tables with blue fuzz */ { FT_Int dim, top, bot, delta; PSH_Blue_Zone zone; zone = top_table->zones; count = count_top; for ( dim = 1; dim >= 0; dim-- ) { if ( count > 0 ) { /* expand the bottom of the lowest zone normally */ zone->org_bottom -= fuzz; /* expand the top and bottom of intermediate zones; */ /* checking that the interval is smaller than the fuzz */ top = zone->org_top; for ( count--; count > 0; count-- ) { bot = zone[1].org_bottom; delta = bot - top; if ( delta / 2 < fuzz ) zone[0].org_top = zone[1].org_bottom = top + delta / 2; else { zone[0].org_top = top + fuzz; zone[1].org_bottom = bot - fuzz; } zone++; top = zone->org_top; } /* expand the top of the highest zone normally */ zone->org_top = top + fuzz; } zone = bot_table->zones; count = count_bot; } } } /* reset the blues table when the device transform changes */ static void psh_blues_scale_zones( PSH_Blues blues, FT_Fixed scale, FT_Pos delta ) { FT_UInt count; FT_UInt num; PSH_Blue_Table table = NULL; /* */ /* Determine whether we need to suppress overshoots or */ /* not. We simply need to compare the vertical scale */ /* parameter to the raw bluescale value. Here is why: */ /* */ /* We need to suppress overshoots for all pointsizes. */ /* At 300dpi that satisfies: */ /* */ /* pointsize < 240*bluescale + 0.49 */ /* */ /* This corresponds to: */ /* */ /* pixelsize < 1000*bluescale + 49/24 */ /* */ /* scale*EM_Size < 1000*bluescale + 49/24 */ /* */ /* However, for normal Type 1 fonts, EM_Size is 1000! */ /* We thus only check: */ /* */ /* scale < bluescale + 49/24000 */ /* */ /* which we shorten to */ /* */ /* "scale < bluescale" */ /* */ /* Note that `blue_scale' is stored 1000 times its real */ /* value, and that `scale' converts from font units to */ /* fractional pixels. */ /* */ /* 1000 / 64 = 125 / 8 */ if ( scale >= 0x20C49BAL ) blues->no_overshoots = FT_BOOL( scale < blues->blue_scale * 8 / 125 ); else blues->no_overshoots = FT_BOOL( scale * 125 < blues->blue_scale * 8 ); /* */ /* The blue threshold is the font units distance under */ /* which overshoots are suppressed due to the BlueShift */ /* even if the scale is greater than BlueScale. */ /* */ /* It is the smallest distance such that */ /* */ /* dist <= BlueShift && dist*scale <= 0.5 pixels */ /* */ { FT_Int threshold = blues->blue_shift; while ( threshold > 0 && FT_MulFix( threshold, scale ) > 32 ) threshold--; blues->blue_threshold = threshold; } for ( num = 0; num < 4; num++ ) { PSH_Blue_Zone zone; switch ( num ) { case 0: table = &blues->normal_top; break; case 1: table = &blues->normal_bottom; break; case 2: table = &blues->family_top; break; default: table = &blues->family_bottom; break; } zone = table->zones; count = table->count; for ( ; count > 0; count--, zone++ ) { zone->cur_top = FT_MulFix( zone->org_top, scale ) + delta; zone->cur_bottom = FT_MulFix( zone->org_bottom, scale ) + delta; zone->cur_ref = FT_MulFix( zone->org_ref, scale ) + delta; zone->cur_delta = FT_MulFix( zone->org_delta, scale ); /* round scaled reference position */ zone->cur_ref = FT_PIX_ROUND( zone->cur_ref ); #if 0 if ( zone->cur_ref > zone->cur_top ) zone->cur_ref -= 64; else if ( zone->cur_ref < zone->cur_bottom ) zone->cur_ref += 64; #endif } } /* process the families now */ for ( num = 0; num < 2; num++ ) { PSH_Blue_Zone zone1, zone2; FT_UInt count1, count2; PSH_Blue_Table normal, family; switch ( num ) { case 0: normal = &blues->normal_top; family = &blues->family_top; break; default: normal = &blues->normal_bottom; family = &blues->family_bottom; } zone1 = normal->zones; count1 = normal->count; for ( ; count1 > 0; count1--, zone1++ ) { /* try to find a family zone whose reference position is less */ /* than 1 pixel far from the current zone */ zone2 = family->zones; count2 = family->count; for ( ; count2 > 0; count2--, zone2++ ) { FT_Pos Delta; Delta = zone1->org_ref - zone2->org_ref; if ( Delta < 0 ) Delta = -Delta; if ( FT_MulFix( Delta, scale ) < 64 ) { zone1->cur_top = zone2->cur_top; zone1->cur_bottom = zone2->cur_bottom; zone1->cur_ref = zone2->cur_ref; zone1->cur_delta = zone2->cur_delta; break; } } } } } /* calculate the maximum height of given blue zones */ static FT_Short psh_calc_max_height( FT_UInt num, const FT_Short* values, FT_Short cur_max ) { FT_UInt count; for ( count = 0; count < num; count += 2 ) { FT_Short cur_height = values[count + 1] - values[count]; if ( cur_height > cur_max ) cur_max = cur_height; } return cur_max; } FT_LOCAL_DEF( void ) psh_blues_snap_stem( PSH_Blues blues, FT_Int stem_top, FT_Int stem_bot, PSH_Alignment alignment ) { PSH_Blue_Table table; FT_UInt count; FT_Pos delta; PSH_Blue_Zone zone; FT_Int no_shoots; alignment->align = PSH_BLUE_ALIGN_NONE; no_shoots = blues->no_overshoots; /* look up stem top in top zones table */ table = &blues->normal_top; count = table->count; zone = table->zones; for ( ; count > 0; count--, zone++ ) { delta = SUB_LONG( stem_top, zone->org_bottom ); if ( delta < -blues->blue_fuzz ) break; if ( stem_top <= zone->org_top + blues->blue_fuzz ) { if ( no_shoots || delta <= blues->blue_threshold ) { alignment->align |= PSH_BLUE_ALIGN_TOP; alignment->align_top = zone->cur_ref; } break; } } /* look up stem bottom in bottom zones table */ table = &blues->normal_bottom; count = table->count; zone = table->zones + count-1; for ( ; count > 0; count--, zone-- ) { delta = SUB_LONG( zone->org_top, stem_bot ); if ( delta < -blues->blue_fuzz ) break; if ( stem_bot >= zone->org_bottom - blues->blue_fuzz ) { if ( no_shoots || delta < blues->blue_threshold ) { alignment->align |= PSH_BLUE_ALIGN_BOT; alignment->align_bot = zone->cur_ref; } break; } } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** GLOBAL HINTS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void psh_globals_destroy( PSH_Globals globals ) { if ( globals ) { FT_Memory memory; memory = globals->memory; globals->dimension[0].stdw.count = 0; globals->dimension[1].stdw.count = 0; globals->blues.normal_top.count = 0; globals->blues.normal_bottom.count = 0; globals->blues.family_top.count = 0; globals->blues.family_bottom.count = 0; FT_FREE( globals ); #ifdef DEBUG_HINTER ps_debug_globals = NULL; #endif } } static FT_Error psh_globals_new( FT_Memory memory, T1_Private* priv, PSH_Globals *aglobals ) { PSH_Globals globals = NULL; FT_Error error; if ( !FT_QNEW( globals ) ) { FT_UInt count; FT_Short* read; globals->memory = memory; /* copy standard widths */ { PSH_Dimension dim = &globals->dimension[1]; PSH_Width write = dim->stdw.widths; write->org = priv->standard_width[0]; write++; read = priv->snap_widths; for ( count = priv->num_snap_widths; count > 0; count-- ) { write->org = *read; write++; read++; } dim->stdw.count = priv->num_snap_widths + 1; } /* copy standard heights */ { PSH_Dimension dim = &globals->dimension[0]; PSH_Width write = dim->stdw.widths; write->org = priv->standard_height[0]; write++; read = priv->snap_heights; for ( count = priv->num_snap_heights; count > 0; count-- ) { write->org = *read; write++; read++; } dim->stdw.count = priv->num_snap_heights + 1; } /* copy blue zones */ psh_blues_set_zones( &globals->blues, priv->num_blue_values, priv->blue_values, priv->num_other_blues, priv->other_blues, priv->blue_fuzz, 0 ); psh_blues_set_zones( &globals->blues, priv->num_family_blues, priv->family_blues, priv->num_family_other_blues, priv->family_other_blues, priv->blue_fuzz, 1 ); /* limit the BlueScale value to `1 / max_of_blue_zone_heights' */ { FT_Fixed max_scale; FT_Short max_height = 1; max_height = psh_calc_max_height( priv->num_blue_values, priv->blue_values, max_height ); max_height = psh_calc_max_height( priv->num_other_blues, priv->other_blues, max_height ); max_height = psh_calc_max_height( priv->num_family_blues, priv->family_blues, max_height ); max_height = psh_calc_max_height( priv->num_family_other_blues, priv->family_other_blues, max_height ); /* BlueScale is scaled 1000 times */ max_scale = FT_DivFix( 1000, max_height ); globals->blues.blue_scale = priv->blue_scale < max_scale ? priv->blue_scale : max_scale; } globals->blues.blue_shift = priv->blue_shift; globals->blues.blue_fuzz = priv->blue_fuzz; globals->dimension[0].scale_mult = 0; globals->dimension[0].scale_delta = 0; globals->dimension[1].scale_mult = 0; globals->dimension[1].scale_delta = 0; #ifdef DEBUG_HINTER ps_debug_globals = globals; #endif } *aglobals = globals; return error; } FT_LOCAL_DEF( void ) psh_globals_set_scale( PSH_Globals globals, FT_Fixed x_scale, FT_Fixed y_scale, FT_Fixed x_delta, FT_Fixed y_delta ) { PSH_Dimension dim; dim = &globals->dimension[0]; if ( x_scale != dim->scale_mult || x_delta != dim->scale_delta ) { dim->scale_mult = x_scale; dim->scale_delta = x_delta; psh_globals_scale_widths( globals, 0 ); } dim = &globals->dimension[1]; if ( y_scale != dim->scale_mult || y_delta != dim->scale_delta ) { dim->scale_mult = y_scale; dim->scale_delta = y_delta; psh_globals_scale_widths( globals, 1 ); psh_blues_scale_zones( &globals->blues, y_scale, y_delta ); } } FT_LOCAL_DEF( void ) psh_globals_funcs_init( PSH_Globals_FuncsRec* funcs ) { funcs->create = psh_globals_new; funcs->set_scale = psh_globals_set_scale; funcs->destroy = psh_globals_destroy; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshglob.c
C++
gpl-3.0
22,377
/**************************************************************************** * * pshglob.h * * PostScript hinter global hinting management. * * Copyright (C) 2001-2022 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 PSHGLOB_H_ #define PSHGLOB_H_ #include <freetype/freetype.h> #include <freetype/internal/pshints.h> FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** GLOBAL HINTS INTERNALS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * @constant: * PS_GLOBALS_MAX_BLUE_ZONES * * @description: * The maximum number of blue zones in a font global hints structure. * See @PS_Globals_BluesRec. */ #define PS_GLOBALS_MAX_BLUE_ZONES 16 /************************************************************************** * * @constant: * PS_GLOBALS_MAX_STD_WIDTHS * * @description: * The maximum number of standard and snap widths in either the * horizontal or vertical direction. See @PS_Globals_WidthsRec. */ #define PS_GLOBALS_MAX_STD_WIDTHS 16 /* standard and snap width */ typedef struct PSH_WidthRec_ { FT_Int org; FT_Pos cur; FT_Pos fit; } PSH_WidthRec, *PSH_Width; /* standard and snap widths table */ typedef struct PSH_WidthsRec_ { FT_UInt count; PSH_WidthRec widths[PS_GLOBALS_MAX_STD_WIDTHS]; } PSH_WidthsRec, *PSH_Widths; typedef struct PSH_DimensionRec_ { PSH_WidthsRec stdw; FT_Fixed scale_mult; FT_Fixed scale_delta; } PSH_DimensionRec, *PSH_Dimension; /* blue zone descriptor */ typedef struct PSH_Blue_ZoneRec_ { FT_Int org_ref; FT_Int org_delta; FT_Int org_top; FT_Int org_bottom; FT_Pos cur_ref; FT_Pos cur_delta; FT_Pos cur_bottom; FT_Pos cur_top; } PSH_Blue_ZoneRec, *PSH_Blue_Zone; typedef struct PSH_Blue_TableRec_ { FT_UInt count; PSH_Blue_ZoneRec zones[PS_GLOBALS_MAX_BLUE_ZONES]; } PSH_Blue_TableRec, *PSH_Blue_Table; /* blue zones table */ typedef struct PSH_BluesRec_ { PSH_Blue_TableRec normal_top; PSH_Blue_TableRec normal_bottom; PSH_Blue_TableRec family_top; PSH_Blue_TableRec family_bottom; FT_Fixed blue_scale; FT_Int blue_shift; FT_Int blue_threshold; FT_Int blue_fuzz; FT_Bool no_overshoots; } PSH_BluesRec, *PSH_Blues; /* font globals. */ /* dimension 0 => X coordinates + vertical hints/stems */ /* dimension 1 => Y coordinates + horizontal hints/stems */ typedef struct PSH_GlobalsRec_ { FT_Memory memory; PSH_DimensionRec dimension[2]; PSH_BluesRec blues; } PSH_GlobalsRec; #define PSH_BLUE_ALIGN_NONE 0 #define PSH_BLUE_ALIGN_TOP 1 #define PSH_BLUE_ALIGN_BOT 2 typedef struct PSH_AlignmentRec_ { int align; FT_Pos align_top; FT_Pos align_bot; } PSH_AlignmentRec, *PSH_Alignment; FT_LOCAL( void ) psh_globals_funcs_init( PSH_Globals_FuncsRec* funcs ); #if 0 /* snap a stem width to fitter coordinates. `org_width' is in font */ /* units. The result is in device pixels (26.6 format). */ FT_LOCAL( FT_Pos ) psh_dimension_snap_width( PSH_Dimension dimension, FT_Int org_width ); #endif FT_LOCAL( void ) psh_globals_set_scale( PSH_Globals globals, FT_Fixed x_scale, FT_Fixed y_scale, FT_Fixed x_delta, FT_Fixed y_delta ); /* snap a stem to one or two blue zones */ FT_LOCAL( void ) psh_blues_snap_stem( PSH_Blues blues, FT_Int stem_top, FT_Int stem_bot, PSH_Alignment alignment ); /* */ #ifdef DEBUG_HINTER extern PSH_Globals ps_debug_globals; #endif FT_END_HEADER #endif /* PSHGLOB_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshglob.h
C++
gpl-3.0
4,860
/**************************************************************************** * * pshinter.c * * FreeType PostScript Hinting module * * Copyright (C) 2001-2022 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "pshalgo.c" #include "pshglob.c" #include "pshmod.c" #include "pshrec.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshinter.c
C++
gpl-3.0
671
/**************************************************************************** * * pshmod.c * * FreeType PostScript hinter module implementation (body). * * Copyright (C) 2001-2022 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 <freetype/internal/ftobjs.h> #include "pshrec.h" #include "pshalgo.h" #include "pshmod.h" /* the Postscript Hinter module structure */ typedef struct PS_Hinter_Module_Rec_ { FT_ModuleRec root; PS_HintsRec ps_hints; PSH_Globals_FuncsRec globals_funcs; T1_Hints_FuncsRec t1_funcs; T2_Hints_FuncsRec t2_funcs; } PS_Hinter_ModuleRec, *PS_Hinter_Module; /* finalize module */ FT_CALLBACK_DEF( void ) ps_hinter_done( PS_Hinter_Module module ) { module->t1_funcs.hints = NULL; module->t2_funcs.hints = NULL; ps_hints_done( &module->ps_hints ); } /* initialize module, create hints recorder and the interface */ FT_CALLBACK_DEF( FT_Error ) ps_hinter_init( PS_Hinter_Module module ) { FT_Memory memory = module->root.memory; void* ph = &module->ps_hints; ps_hints_init( &module->ps_hints, memory ); psh_globals_funcs_init( &module->globals_funcs ); t1_hints_funcs_init( &module->t1_funcs ); module->t1_funcs.hints = (T1_Hints)ph; t2_hints_funcs_init( &module->t2_funcs ); module->t2_funcs.hints = (T2_Hints)ph; return 0; } /* returns global hints interface */ FT_CALLBACK_DEF( PSH_Globals_Funcs ) pshinter_get_globals_funcs( FT_Module module ) { return &((PS_Hinter_Module)module)->globals_funcs; } /* return Type 1 hints interface */ FT_CALLBACK_DEF( T1_Hints_Funcs ) pshinter_get_t1_funcs( FT_Module module ) { return &((PS_Hinter_Module)module)->t1_funcs; } /* return Type 2 hints interface */ FT_CALLBACK_DEF( T2_Hints_Funcs ) pshinter_get_t2_funcs( FT_Module module ) { return &((PS_Hinter_Module)module)->t2_funcs; } FT_DEFINE_PSHINTER_INTERFACE( pshinter_interface, pshinter_get_globals_funcs, pshinter_get_t1_funcs, pshinter_get_t2_funcs ) FT_DEFINE_MODULE( pshinter_module_class, 0, sizeof ( PS_Hinter_ModuleRec ), "pshinter", 0x10000L, 0x20000L, &pshinter_interface, /* module-specific interface */ (FT_Module_Constructor)ps_hinter_init, /* module_init */ (FT_Module_Destructor) ps_hinter_done, /* module_done */ (FT_Module_Requester) NULL /* get_interface */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshmod.c
C++
gpl-3.0
2,843
/**************************************************************************** * * pshmod.h * * PostScript hinter module interface (specification). * * Copyright (C) 2001-2022 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 PSHMOD_H_ #define PSHMOD_H_ #include <freetype/ftmodapi.h> FT_BEGIN_HEADER FT_DECLARE_MODULE( pshinter_module_class ) FT_END_HEADER #endif /* PSHMOD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshmod.h
C++
gpl-3.0
741
/**************************************************************************** * * pshnterr.h * * PS Hinter error codes (specification only). * * Copyright (C) 2003-2022 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. * */ /************************************************************************** * * This file is used to define the PSHinter error enumeration constants. * */ #ifndef PSHNTERR_H_ #define PSHNTERR_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX PSH_Err_ #define FT_ERR_BASE FT_Mod_Err_PShinter #include <freetype/fterrors.h> #endif /* PSHNTERR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshnterr.h
C++
gpl-3.0
978
/**************************************************************************** * * pshrec.c * * FreeType PostScript hints recorder (body). * * Copyright (C) 2001-2022 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 <freetype/freetype.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftcalc.h> #include "pshrec.h" #include "pshalgo.h" #include "pshnterr.h" #undef FT_COMPONENT #define FT_COMPONENT pshrec #ifdef DEBUG_HINTER PS_Hints ps_debug_hints = NULL; int ps_debug_no_horz_hints = 0; int ps_debug_no_vert_hints = 0; #endif /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** PS_HINT MANAGEMENT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* destroy hints table */ static void ps_hint_table_done( PS_Hint_Table table, FT_Memory memory ) { FT_FREE( table->hints ); table->num_hints = 0; table->max_hints = 0; } /* ensure that a table can contain "count" elements */ static FT_Error ps_hint_table_ensure( PS_Hint_Table table, FT_UInt count, FT_Memory memory ) { FT_UInt old_max = table->max_hints; FT_UInt new_max = count; FT_Error error; /* try to grow the table */ new_max = FT_PAD_CEIL( new_max, 8 ); if ( !FT_QRENEW_ARRAY( table->hints, old_max, new_max ) ) table->max_hints = new_max; return error; } static FT_Error ps_hint_table_alloc( PS_Hint_Table table, FT_Memory memory, PS_Hint *ahint ) { FT_Error error = FT_Err_Ok; FT_UInt count; PS_Hint hint = NULL; count = table->num_hints; count++; if ( count > table->max_hints ) { error = ps_hint_table_ensure( table, count, memory ); if ( error ) goto Exit; } hint = table->hints + count - 1; /* initialized upstream */ table->num_hints = count; Exit: *ahint = hint; return error; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** PS_MASK MANAGEMENT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* destroy mask */ static void ps_mask_done( PS_Mask mask, FT_Memory memory ) { FT_FREE( mask->bytes ); mask->num_bits = 0; mask->max_bits = 0; mask->end_point = 0; } /* ensure that a mask can contain "count" bits */ static FT_Error ps_mask_ensure( PS_Mask mask, FT_UInt count, FT_Memory memory ) { FT_UInt old_max = mask->max_bits >> 3; FT_UInt new_max = ( count + 7 ) >> 3; FT_Error error = FT_Err_Ok; if ( new_max > old_max ) { new_max = FT_PAD_CEIL( new_max, 8 ); /* added bytes are zeroed here */ if ( !FT_RENEW_ARRAY( mask->bytes, old_max, new_max ) ) mask->max_bits = new_max * 8; } return error; } /* test a bit value in a given mask */ static FT_Int ps_mask_test_bit( PS_Mask mask, FT_UInt idx ) { if ( idx >= mask->num_bits ) return 0; return mask->bytes[idx >> 3] & ( 0x80 >> ( idx & 7 ) ); } /* set a given bit, possibly grow the mask */ static FT_Error ps_mask_set_bit( PS_Mask mask, FT_UInt idx, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_Byte* p; if ( idx >= mask->num_bits ) { error = ps_mask_ensure( mask, idx + 1, memory ); if ( error ) goto Exit; mask->num_bits = idx + 1; } p = mask->bytes + ( idx >> 3 ); p[0] = (FT_Byte)( p[0] | ( 0x80 >> ( idx & 7 ) ) ); Exit: return error; } /* destroy mask table */ static void ps_mask_table_done( PS_Mask_Table table, FT_Memory memory ) { FT_UInt count = table->max_masks; PS_Mask mask = table->masks; for ( ; count > 0; count--, mask++ ) ps_mask_done( mask, memory ); FT_FREE( table->masks ); table->num_masks = 0; table->max_masks = 0; } /* ensure that a mask table can contain "count" masks */ static FT_Error ps_mask_table_ensure( PS_Mask_Table table, FT_UInt count, FT_Memory memory ) { FT_UInt old_max = table->max_masks; FT_UInt new_max = count; FT_Error error = FT_Err_Ok; if ( new_max > old_max ) { new_max = FT_PAD_CEIL( new_max, 8 ); if ( !FT_RENEW_ARRAY( table->masks, old_max, new_max ) ) table->max_masks = new_max; } return error; } /* allocate a new mask in a table */ static FT_Error ps_mask_table_alloc( PS_Mask_Table table, FT_Memory memory, PS_Mask *amask ) { FT_UInt count; FT_Error error = FT_Err_Ok; PS_Mask mask = NULL; count = table->num_masks; count++; if ( count > table->max_masks ) { error = ps_mask_table_ensure( table, count, memory ); if ( error ) goto Exit; } mask = table->masks + count - 1; mask->num_bits = 0; mask->end_point = 0; /* reused mask must be cleared */ if ( mask->max_bits ) FT_MEM_ZERO( mask->bytes, mask->max_bits >> 3 ); table->num_masks = count; Exit: *amask = mask; return error; } /* return last hint mask in a table, create one if the table is empty */ static FT_Error ps_mask_table_last( PS_Mask_Table table, FT_Memory memory, PS_Mask *amask ) { FT_Error error = FT_Err_Ok; FT_UInt count; PS_Mask mask; count = table->num_masks; if ( count == 0 ) { error = ps_mask_table_alloc( table, memory, &mask ); if ( error ) goto Exit; } else mask = table->masks + count - 1; Exit: *amask = mask; return error; } /* set a new mask to a given bit range */ static FT_Error ps_mask_table_set_bits( PS_Mask_Table table, const FT_Byte* source, FT_UInt bit_pos, FT_UInt bit_count, FT_Memory memory ) { FT_Error error; PS_Mask mask; error = ps_mask_table_last( table, memory, &mask ); if ( error ) goto Exit; error = ps_mask_ensure( mask, bit_count, memory ); if ( error ) goto Exit; mask->num_bits = bit_count; /* now, copy bits */ { FT_Byte* read = (FT_Byte*)source + ( bit_pos >> 3 ); FT_Int rmask = 0x80 >> ( bit_pos & 7 ); FT_Byte* write = mask->bytes; FT_Int wmask = 0x80; FT_Int val; for ( ; bit_count > 0; bit_count-- ) { val = write[0] & ~wmask; if ( read[0] & rmask ) val |= wmask; write[0] = (FT_Byte)val; rmask >>= 1; if ( rmask == 0 ) { read++; rmask = 0x80; } wmask >>= 1; if ( wmask == 0 ) { write++; wmask = 0x80; } } } Exit: return error; } /* test whether two masks in a table intersect */ static FT_Int ps_mask_table_test_intersect( PS_Mask_Table table, FT_UInt index1, FT_UInt index2 ) { PS_Mask mask1 = table->masks + index1; PS_Mask mask2 = table->masks + index2; FT_Byte* p1 = mask1->bytes; FT_Byte* p2 = mask2->bytes; FT_UInt count1 = mask1->num_bits; FT_UInt count2 = mask2->num_bits; FT_UInt count; count = FT_MIN( count1, count2 ); for ( ; count >= 8; count -= 8 ) { if ( p1[0] & p2[0] ) return 1; p1++; p2++; } if ( count == 0 ) return 0; return ( p1[0] & p2[0] ) & ~( 0xFF >> count ); } /* merge two masks, used by ps_mask_table_merge_all */ static FT_Error ps_mask_table_merge( PS_Mask_Table table, FT_UInt index1, FT_UInt index2, FT_Memory memory ) { FT_Error error = FT_Err_Ok; /* swap index1 and index2 so that index1 < index2 */ if ( index1 > index2 ) { FT_UInt temp; temp = index1; index1 = index2; index2 = temp; } if ( index1 < index2 && index2 < table->num_masks ) { /* we need to merge the bitsets of index1 and index2 with a */ /* simple union */ PS_Mask mask1 = table->masks + index1; PS_Mask mask2 = table->masks + index2; FT_UInt count1 = mask1->num_bits; FT_UInt count2 = mask2->num_bits; FT_UInt delta; if ( count2 > 0 ) { FT_UInt pos; FT_Byte* read; FT_Byte* write; /* if "count2" is greater than "count1", we need to grow the */ /* first bitset */ if ( count2 > count1 ) { error = ps_mask_ensure( mask1, count2, memory ); if ( error ) goto Exit; mask1->num_bits = count2; } /* merge (unite) the bitsets */ read = mask2->bytes; write = mask1->bytes; pos = ( count2 + 7 ) >> 3; for ( ; pos > 0; pos-- ) { write[0] = (FT_Byte)( write[0] | read[0] ); write++; read++; } } /* Now, remove "mask2" from the list. We need to keep the masks */ /* sorted in order of importance, so move table elements. */ mask2->num_bits = 0; mask2->end_point = 0; /* number of masks to move */ delta = table->num_masks - 1 - index2; if ( delta > 0 ) { /* move to end of table for reuse */ PS_MaskRec dummy = *mask2; ft_memmove( mask2, mask2 + 1, delta * sizeof ( PS_MaskRec ) ); mask2[delta] = dummy; } table->num_masks--; } else FT_TRACE0(( "ps_mask_table_merge: ignoring invalid indices (%d,%d)\n", index1, index2 )); Exit: return error; } /* Try to merge all masks in a given table. This is used to merge */ /* all counter masks into independent counter "paths". */ /* */ static FT_Error ps_mask_table_merge_all( PS_Mask_Table table, FT_Memory memory ) { FT_UInt index1, index2; FT_Error error = FT_Err_Ok; /* the loops stop when unsigned indices wrap around after 0 */ for ( index1 = table->num_masks - 1; index1 < table->num_masks; index1-- ) { for ( index2 = index1 - 1; index2 < index1; index2-- ) { if ( ps_mask_table_test_intersect( table, index1, index2 ) ) { error = ps_mask_table_merge( table, index2, index1, memory ); if ( error ) goto Exit; break; } } } Exit: return error; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** PS_DIMENSION MANAGEMENT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* finalize a given dimension */ static void ps_dimension_done( PS_Dimension dimension, FT_Memory memory ) { ps_mask_table_done( &dimension->counters, memory ); ps_mask_table_done( &dimension->masks, memory ); ps_hint_table_done( &dimension->hints, memory ); } /* initialize a given dimension */ static void ps_dimension_init( PS_Dimension dimension ) { dimension->hints.num_hints = 0; dimension->masks.num_masks = 0; dimension->counters.num_masks = 0; } #if 0 /* set a bit at a given index in the current hint mask */ static FT_Error ps_dimension_set_mask_bit( PS_Dimension dim, FT_UInt idx, FT_Memory memory ) { PS_Mask mask; FT_Error error = FT_Err_Ok; /* get last hint mask */ error = ps_mask_table_last( &dim->masks, memory, &mask ); if ( error ) goto Exit; error = ps_mask_set_bit( mask, idx, memory ); Exit: return error; } #endif /* set the end point in a mask, called from "End" & "Reset" methods */ static void ps_dimension_end_mask( PS_Dimension dim, FT_UInt end_point ) { FT_UInt count = dim->masks.num_masks; if ( count > 0 ) { PS_Mask mask = dim->masks.masks + count - 1; mask->end_point = end_point; } } /* set the end point in the current mask, then create a new empty one */ /* (called by "Reset" method) */ static FT_Error ps_dimension_reset_mask( PS_Dimension dim, FT_UInt end_point, FT_Memory memory ) { PS_Mask mask; /* end current mask */ ps_dimension_end_mask( dim, end_point ); /* allocate new one */ return ps_mask_table_alloc( &dim->masks, memory, &mask ); } /* set a new mask, called from the "T2Stem" method */ static FT_Error ps_dimension_set_mask_bits( PS_Dimension dim, const FT_Byte* source, FT_UInt source_pos, FT_UInt source_bits, FT_UInt end_point, FT_Memory memory ) { FT_Error error; /* reset current mask, if any */ error = ps_dimension_reset_mask( dim, end_point, memory ); if ( error ) goto Exit; /* set bits in new mask */ error = ps_mask_table_set_bits( &dim->masks, source, source_pos, source_bits, memory ); Exit: return error; } /* add a new single stem (called from "T1Stem" method) */ static FT_Error ps_dimension_add_t1stem( PS_Dimension dim, FT_Int pos, FT_Int len, FT_Memory memory, FT_UInt *aindex ) { FT_Error error = FT_Err_Ok; FT_UInt flags = 0; /* detect ghost stem */ if ( len < 0 ) { flags |= PS_HINT_FLAG_GHOST; if ( len == -21 ) { flags |= PS_HINT_FLAG_BOTTOM; pos = ADD_INT( pos, len ); } len = 0; } /* now, lookup stem in the current hints table */ { PS_Mask mask; FT_UInt idx; FT_UInt max = dim->hints.num_hints; PS_Hint hint = dim->hints.hints; for ( idx = 0; idx < max; idx++, hint++ ) { if ( hint->pos == pos && hint->len == len ) break; } /* we need to create a new hint in the table */ if ( idx >= max ) { error = ps_hint_table_alloc( &dim->hints, memory, &hint ); if ( error ) goto Exit; hint->pos = pos; hint->len = len; hint->flags = flags; } /* now, store the hint in the current mask */ error = ps_mask_table_last( &dim->masks, memory, &mask ); if ( error ) goto Exit; error = ps_mask_set_bit( mask, idx, memory ); if ( error ) goto Exit; if ( aindex ) *aindex = idx; } Exit: return error; } /* add a "hstem3/vstem3" counter to our dimension table */ static FT_Error ps_dimension_add_counter( PS_Dimension dim, FT_UInt hint1, FT_UInt hint2, FT_UInt hint3, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_UInt count = dim->counters.num_masks; PS_Mask counter = dim->counters.masks; /* try to find an existing counter mask that already uses */ /* one of these stems here */ for ( ; count > 0; count--, counter++ ) { if ( ps_mask_test_bit( counter, hint1 ) || ps_mask_test_bit( counter, hint2 ) || ps_mask_test_bit( counter, hint3 ) ) break; } /* create a new counter when needed */ if ( count == 0 ) { error = ps_mask_table_alloc( &dim->counters, memory, &counter ); if ( error ) goto Exit; } /* now, set the bits for our hints in the counter mask */ error = ps_mask_set_bit( counter, hint1, memory ); if ( error ) goto Exit; error = ps_mask_set_bit( counter, hint2, memory ); if ( error ) goto Exit; error = ps_mask_set_bit( counter, hint3, memory ); if ( error ) goto Exit; Exit: return error; } /* end of recording session for a given dimension */ static FT_Error ps_dimension_end( PS_Dimension dim, FT_UInt end_point, FT_Memory memory ) { /* end hint mask table */ ps_dimension_end_mask( dim, end_point ); /* merge all counter masks into independent "paths" */ return ps_mask_table_merge_all( &dim->counters, memory ); } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** PS_RECORDER MANAGEMENT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* destroy hints */ FT_LOCAL( void ) ps_hints_done( PS_Hints hints ) { FT_Memory memory = hints->memory; ps_dimension_done( &hints->dimension[0], memory ); ps_dimension_done( &hints->dimension[1], memory ); hints->error = FT_Err_Ok; hints->memory = NULL; } FT_LOCAL( void ) ps_hints_init( PS_Hints hints, FT_Memory memory ) { FT_ZERO( hints ); hints->memory = memory; } /* initialize a hints for a new session */ static void ps_hints_open( PS_Hints hints, PS_Hint_Type hint_type ) { hints->error = FT_Err_Ok; hints->hint_type = hint_type; ps_dimension_init( &hints->dimension[0] ); ps_dimension_init( &hints->dimension[1] ); } /* add one or more stems to the current hints table */ static void ps_hints_stem( PS_Hints hints, FT_UInt dimension, FT_Int count, FT_Long* stems ) { PS_Dimension dim; if ( hints->error ) return; /* limit "dimension" to 0..1 */ if ( dimension > 1 ) { FT_TRACE0(( "ps_hints_stem: invalid dimension (%d) used\n", dimension )); dimension = ( dimension != 0 ); } /* record the stems in the current hints/masks table */ /* (Type 1 & 2's `hstem' or `vstem' operators) */ dim = &hints->dimension[dimension]; for ( ; count > 0; count--, stems += 2 ) { FT_Error error; FT_Memory memory = hints->memory; error = ps_dimension_add_t1stem( dim, (FT_Int)stems[0], (FT_Int)stems[1], memory, NULL ); if ( error ) { FT_ERROR(( "ps_hints_stem: could not add stem" " (%ld,%ld) to hints table\n", stems[0], stems[1] )); hints->error = error; return; } } } /* add one Type1 counter stem to the current hints table */ static void ps_hints_t1stem3( PS_Hints hints, FT_UInt dimension, FT_Fixed* stems ) { FT_Error error = FT_Err_Ok; if ( !hints->error ) { PS_Dimension dim; FT_Memory memory = hints->memory; FT_Int count; FT_UInt idx[3]; /* limit "dimension" to 0..1 */ if ( dimension > 1 ) { FT_TRACE0(( "ps_hints_t1stem3: invalid dimension (%d) used\n", dimension )); dimension = ( dimension != 0 ); } dim = &hints->dimension[dimension]; /* there must be 6 elements in the 'stem' array */ if ( hints->hint_type == PS_HINT_TYPE_1 ) { /* add the three stems to our hints/masks table */ for ( count = 0; count < 3; count++, stems += 2 ) { error = ps_dimension_add_t1stem( dim, (FT_Int)FIXED_TO_INT( stems[0] ), (FT_Int)FIXED_TO_INT( stems[1] ), memory, &idx[count] ); if ( error ) goto Fail; } /* now, add the hints to the counters table */ error = ps_dimension_add_counter( dim, idx[0], idx[1], idx[2], memory ); if ( error ) goto Fail; } else { FT_ERROR(( "ps_hints_t1stem3: called with invalid hint type\n" )); error = FT_THROW( Invalid_Argument ); goto Fail; } } return; Fail: FT_ERROR(( "ps_hints_t1stem3: could not add counter stems to table\n" )); hints->error = error; } /* reset hints (only with Type 1 hints) */ static void ps_hints_t1reset( PS_Hints hints, FT_UInt end_point ) { FT_Error error = FT_Err_Ok; if ( !hints->error ) { FT_Memory memory = hints->memory; if ( hints->hint_type == PS_HINT_TYPE_1 ) { error = ps_dimension_reset_mask( &hints->dimension[0], end_point, memory ); if ( error ) goto Fail; error = ps_dimension_reset_mask( &hints->dimension[1], end_point, memory ); if ( error ) goto Fail; } else { /* invalid hint type */ error = FT_THROW( Invalid_Argument ); goto Fail; } } return; Fail: hints->error = error; } /* Type2 "hintmask" operator, add a new hintmask to each direction */ static void ps_hints_t2mask( PS_Hints hints, FT_UInt end_point, FT_UInt bit_count, const FT_Byte* bytes ) { FT_Error error; if ( !hints->error ) { PS_Dimension dim = hints->dimension; FT_Memory memory = hints->memory; FT_UInt count1 = dim[0].hints.num_hints; FT_UInt count2 = dim[1].hints.num_hints; /* check bit count; must be equal to current total hint count */ if ( bit_count != count1 + count2 ) { FT_TRACE0(( "ps_hints_t2mask:" " called with invalid bitcount %d (instead of %d)\n", bit_count, count1 + count2 )); /* simply ignore the operator */ return; } /* set-up new horizontal and vertical hint mask now */ error = ps_dimension_set_mask_bits( &dim[0], bytes, count2, count1, end_point, memory ); if ( error ) goto Fail; error = ps_dimension_set_mask_bits( &dim[1], bytes, 0, count2, end_point, memory ); if ( error ) goto Fail; } return; Fail: hints->error = error; } static void ps_hints_t2counter( PS_Hints hints, FT_UInt bit_count, const FT_Byte* bytes ) { FT_Error error; if ( !hints->error ) { PS_Dimension dim = hints->dimension; FT_Memory memory = hints->memory; FT_UInt count1 = dim[0].hints.num_hints; FT_UInt count2 = dim[1].hints.num_hints; /* check bit count, must be equal to current total hint count */ if ( bit_count != count1 + count2 ) { FT_TRACE0(( "ps_hints_t2counter:" " called with invalid bitcount %d (instead of %d)\n", bit_count, count1 + count2 )); /* simply ignore the operator */ return; } /* set-up new horizontal and vertical hint mask now */ error = ps_dimension_set_mask_bits( &dim[0], bytes, 0, count1, 0, memory ); if ( error ) goto Fail; error = ps_dimension_set_mask_bits( &dim[1], bytes, count1, count2, 0, memory ); if ( error ) goto Fail; } return; Fail: hints->error = error; } /* end recording session */ static FT_Error ps_hints_close( PS_Hints hints, FT_UInt end_point ) { FT_Error error; error = hints->error; if ( !error ) { FT_Memory memory = hints->memory; PS_Dimension dim = hints->dimension; error = ps_dimension_end( &dim[0], end_point, memory ); if ( !error ) { error = ps_dimension_end( &dim[1], end_point, memory ); } } #ifdef DEBUG_HINTER if ( !error ) ps_debug_hints = hints; #endif return error; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE 1 HINTS RECORDING INTERFACE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void t1_hints_open( T1_Hints hints ) { ps_hints_open( (PS_Hints)hints, PS_HINT_TYPE_1 ); } static void t1_hints_stem( T1_Hints hints, FT_UInt dimension, FT_Fixed* coords ) { FT_Pos stems[2]; stems[0] = FIXED_TO_INT( coords[0] ); stems[1] = FIXED_TO_INT( coords[1] ); ps_hints_stem( (PS_Hints)hints, dimension, 1, stems ); } FT_LOCAL_DEF( void ) t1_hints_funcs_init( T1_Hints_FuncsRec* funcs ) { FT_ZERO( funcs ); funcs->open = (T1_Hints_OpenFunc) t1_hints_open; funcs->close = (T1_Hints_CloseFunc) ps_hints_close; funcs->stem = (T1_Hints_SetStemFunc) t1_hints_stem; funcs->stem3 = (T1_Hints_SetStem3Func)ps_hints_t1stem3; funcs->reset = (T1_Hints_ResetFunc) ps_hints_t1reset; funcs->apply = (T1_Hints_ApplyFunc) ps_hints_apply; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE 2 HINTS RECORDING INTERFACE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void t2_hints_open( T2_Hints hints ) { ps_hints_open( (PS_Hints)hints, PS_HINT_TYPE_2 ); } static void t2_hints_stems( T2_Hints hints, FT_UInt dimension, FT_Int count, FT_Fixed* coords ) { FT_Pos stems[32], y; FT_Int total = count, n; y = 0; while ( total > 0 ) { /* determine number of stems to write */ count = total; if ( count > 16 ) count = 16; /* compute integer stem positions in font units */ for ( n = 0; n < count * 2; n++ ) { y = ADD_LONG( y, coords[n] ); stems[n] = FIXED_TO_INT( y ); } /* compute lengths */ for ( n = 0; n < count * 2; n += 2 ) stems[n + 1] = stems[n + 1] - stems[n]; /* add them to the current dimension */ ps_hints_stem( (PS_Hints)hints, dimension, count, stems ); total -= count; } } FT_LOCAL_DEF( void ) t2_hints_funcs_init( T2_Hints_FuncsRec* funcs ) { FT_ZERO( funcs ); funcs->open = (T2_Hints_OpenFunc) t2_hints_open; funcs->close = (T2_Hints_CloseFunc) ps_hints_close; funcs->stems = (T2_Hints_StemsFunc) t2_hints_stems; funcs->hintmask= (T2_Hints_MaskFunc) ps_hints_t2mask; funcs->counter = (T2_Hints_CounterFunc)ps_hints_t2counter; funcs->apply = (T2_Hints_ApplyFunc) ps_hints_apply; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshrec.c
C++
gpl-3.0
30,632
/**************************************************************************** * * pshrec.h * * Postscript (Type1/Type2) hints recorder (specification). * * Copyright (C) 2001-2022 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. * */ /*************************************************************************** * * The functions defined here are called from the Type 1, CID and CFF * font drivers to record the hints of a given character/glyph. * * The hints are recorded in a unified format, and are later processed * by the `optimizer' and `fitter' to adjust the outlines to the pixel * grid. * */ #ifndef PSHREC_H_ #define PSHREC_H_ #include <freetype/internal/pshints.h> #include "pshglob.h" FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** GLYPH HINTS RECORDER INTERNALS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* handle to hint record */ typedef struct PS_HintRec_* PS_Hint; /* hint types */ typedef enum PS_Hint_Type_ { PS_HINT_TYPE_1 = 1, PS_HINT_TYPE_2 = 2 } PS_Hint_Type; /* hint flags */ #define PS_HINT_FLAG_GHOST 1U #define PS_HINT_FLAG_BOTTOM 2U /* hint descriptor */ typedef struct PS_HintRec_ { FT_Int pos; FT_Int len; FT_UInt flags; } PS_HintRec; #define ps_hint_is_active( x ) ( (x)->flags & PS_HINT_FLAG_ACTIVE ) #define ps_hint_is_ghost( x ) ( (x)->flags & PS_HINT_FLAG_GHOST ) #define ps_hint_is_bottom( x ) ( (x)->flags & PS_HINT_FLAG_BOTTOM ) /* hints table descriptor */ typedef struct PS_Hint_TableRec_ { FT_UInt num_hints; FT_UInt max_hints; PS_Hint hints; } PS_Hint_TableRec, *PS_Hint_Table; /* hint and counter mask descriptor */ typedef struct PS_MaskRec_ { FT_UInt num_bits; FT_UInt max_bits; FT_Byte* bytes; FT_UInt end_point; } PS_MaskRec, *PS_Mask; /* masks and counters table descriptor */ typedef struct PS_Mask_TableRec_ { FT_UInt num_masks; FT_UInt max_masks; PS_Mask masks; } PS_Mask_TableRec, *PS_Mask_Table; /* dimension-specific hints descriptor */ typedef struct PS_DimensionRec_ { PS_Hint_TableRec hints; PS_Mask_TableRec masks; PS_Mask_TableRec counters; } PS_DimensionRec, *PS_Dimension; /* glyph hints descriptor */ /* dimension 0 => X coordinates + vertical hints/stems */ /* dimension 1 => Y coordinates + horizontal hints/stems */ typedef struct PS_HintsRec_ { FT_Memory memory; FT_Error error; FT_UInt32 magic; PS_Hint_Type hint_type; PS_DimensionRec dimension[2]; } PS_HintsRec, *PS_Hints; /* */ /* initialize hints recorder */ FT_LOCAL( void ) ps_hints_init( PS_Hints hints, FT_Memory memory ); /* finalize hints recorder */ FT_LOCAL( void ) ps_hints_done( PS_Hints hints ); /* initialize Type1 hints recorder interface */ FT_LOCAL( void ) t1_hints_funcs_init( T1_Hints_FuncsRec* funcs ); /* initialize Type2 hints recorder interface */ FT_LOCAL( void ) t2_hints_funcs_init( T2_Hints_FuncsRec* funcs ); #ifdef DEBUG_HINTER extern PS_Hints ps_debug_hints; extern int ps_debug_no_horz_hints; extern int ps_debug_no_vert_hints; #endif /* */ FT_END_HEADER #endif /* PSHREC_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/pshrec.h
C++
gpl-3.0
4,103
# # FreeType 2 PSHinter driver configuration rules # # Copyright (C) 2001-2022 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. # PSHINTER driver directory # PSHINTER_DIR := $(SRC_DIR)/pshinter # compilation flags for the driver # PSHINTER_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(PSHINTER_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # PSHINTER driver sources (i.e., C files) # PSHINTER_DRV_SRC := $(PSHINTER_DIR)/pshalgo.c \ $(PSHINTER_DIR)/pshglob.c \ $(PSHINTER_DIR)/pshmod.c \ $(PSHINTER_DIR)/pshrec.c # PSHINTER driver headers # PSHINTER_DRV_H := $(PSHINTER_DRV_SRC:%c=%h) \ $(PSHINTER_DIR)/pshnterr.h # PSHINTER driver object(s) # # PSHINTER_DRV_OBJ_M is used during `multi' builds. # PSHINTER_DRV_OBJ_S is used during `single' builds. # PSHINTER_DRV_OBJ_M := $(PSHINTER_DRV_SRC:$(PSHINTER_DIR)/%.c=$(OBJ_DIR)/%.$O) PSHINTER_DRV_OBJ_S := $(OBJ_DIR)/pshinter.$O # PSHINTER driver source file for single build # PSHINTER_DRV_SRC_S := $(PSHINTER_DIR)/pshinter.c # PSHINTER driver - single object # $(PSHINTER_DRV_OBJ_S): $(PSHINTER_DRV_SRC_S) $(PSHINTER_DRV_SRC) \ $(FREETYPE_H) $(PSHINTER_DRV_H) $(PSHINTER_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(PSHINTER_DRV_SRC_S)) # PSHINTER driver - multiple objects # $(OBJ_DIR)/%.$O: $(PSHINTER_DIR)/%.c $(FREETYPE_H) $(PSHINTER_DRV_H) $(PSHINTER_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(PSHINTER_DRV_OBJ_S) DRV_OBJS_M += $(PSHINTER_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/pshinter/rules.mk
mk
gpl-3.0
2,041
# # FreeType 2 PSnames module definition # # Copyright (C) 1996-2022 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. FTMODULE_H_COMMANDS += PSNAMES_MODULE define PSNAMES_MODULE $(OPEN_DRIVER) FT_Module_Class, psnames_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)psnames $(ECHO_DRIVER_DESC)Postscript & Unicode Glyph name handling$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/module.mk
mk
gpl-3.0
674
/**************************************************************************** * * psmodule.c * * psnames module implementation (body). * * Copyright (C) 1996-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/services/svpscmap.h> #include "psmodule.h" /* * The file `pstables.h' with its arrays and its function * `ft_get_adobe_glyph_index' is useful for other projects also (for * example, `pdfium' is using it). However, if used as a C++ header, * including it in two different source files makes it necessary to use * `extern const' for the declaration of its arrays, otherwise the data * would be duplicated as mandated by the C++ standard. * * For this reason, we use `DEFINE_PS_TABLES' to guard the function * definitions, and `DEFINE_PS_TABLES_DATA' to provide both proper array * declarations and definitions. */ #include "pstables.h" #define DEFINE_PS_TABLES #define DEFINE_PS_TABLES_DATA #include "pstables.h" #include "psnamerr.h" #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES #ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST #define VARIANT_BIT 0x80000000UL #define BASE_GLYPH( code ) ( (FT_UInt32)( (code) & ~VARIANT_BIT ) ) /* Return the Unicode value corresponding to a given glyph. Note that */ /* we do deal with glyph variants by detecting a non-initial dot in */ /* the name, as in `A.swash' or `e.final'; in this case, the */ /* VARIANT_BIT is set in the return value. */ /* */ static FT_UInt32 ps_unicode_value( const char* glyph_name ) { /* If the name begins with `uni', then the glyph name may be a */ /* hard-coded unicode character code. */ if ( glyph_name[0] == 'u' && glyph_name[1] == 'n' && glyph_name[2] == 'i' ) { /* determine whether the next four characters following are */ /* hexadecimal. */ /* XXX: Add code to deal with ligatures, i.e. glyph names like */ /* `uniXXXXYYYYZZZZ'... */ FT_Int count; FT_UInt32 value = 0; const char* p = glyph_name + 3; for ( count = 4; count > 0; count--, p++ ) { char c = *p; unsigned int d; d = (unsigned char)c - '0'; if ( d >= 10 ) { d = (unsigned char)c - 'A'; if ( d >= 6 ) d = 16; else d += 10; } /* Exit if a non-uppercase hexadecimal character was found */ /* -- this also catches character codes below `0' since such */ /* negative numbers cast to `unsigned int' are far too big. */ if ( d >= 16 ) break; value = ( value << 4 ) + d; } /* there must be exactly four hex digits */ if ( count == 0 ) { if ( *p == '\0' ) return value; if ( *p == '.' ) return (FT_UInt32)( value | VARIANT_BIT ); } } /* If the name begins with `u', followed by four to six uppercase */ /* hexadecimal digits, it is a hard-coded unicode character code. */ if ( glyph_name[0] == 'u' ) { FT_Int count; FT_UInt32 value = 0; const char* p = glyph_name + 1; for ( count = 6; count > 0; count--, p++ ) { char c = *p; unsigned int d; d = (unsigned char)c - '0'; if ( d >= 10 ) { d = (unsigned char)c - 'A'; if ( d >= 6 ) d = 16; else d += 10; } if ( d >= 16 ) break; value = ( value << 4 ) + d; } if ( count <= 2 ) { if ( *p == '\0' ) return value; if ( *p == '.' ) return (FT_UInt32)( value | VARIANT_BIT ); } } /* Look for a non-initial dot in the glyph name in order to */ /* find variants like `A.swash', `e.final', etc. */ { FT_UInt32 value = 0; const char* p = glyph_name; for ( ; *p && *p != '.'; p++ ) ; /* now look up the glyph in the Adobe Glyph List; */ /* `.notdef', `.null' and the empty name are short cut */ if ( p > glyph_name ) { value = (FT_UInt32)ft_get_adobe_glyph_index( glyph_name, p ); if ( *p == '.' ) value |= (FT_UInt32)VARIANT_BIT; } return value; } } /* ft_qsort callback to sort the unicode map */ FT_COMPARE_DEF( int ) compare_uni_maps( const void* a, const void* b ) { PS_UniMap* map1 = (PS_UniMap*)a; PS_UniMap* map2 = (PS_UniMap*)b; FT_UInt32 unicode1 = BASE_GLYPH( map1->unicode ); FT_UInt32 unicode2 = BASE_GLYPH( map2->unicode ); /* sort base glyphs before glyph variants */ if ( unicode1 == unicode2 ) { if ( map1->unicode > map2->unicode ) return 1; else if ( map1->unicode < map2->unicode ) return -1; else return 0; } else { if ( unicode1 > unicode2 ) return 1; else if ( unicode1 < unicode2 ) return -1; else return 0; } } /* support for extra glyphs not handled (well) in AGL; */ /* we add extra mappings for them if necessary */ #define EXTRA_GLYPH_LIST_SIZE 10 static const FT_UInt32 ft_extra_glyph_unicodes[EXTRA_GLYPH_LIST_SIZE] = { /* WGL 4 */ 0x0394, 0x03A9, 0x2215, 0x00AD, 0x02C9, 0x03BC, 0x2219, 0x00A0, /* Romanian */ 0x021A, 0x021B }; static const char ft_extra_glyph_names[] = { 'D','e','l','t','a',0, 'O','m','e','g','a',0, 'f','r','a','c','t','i','o','n',0, 'h','y','p','h','e','n',0, 'm','a','c','r','o','n',0, 'm','u',0, 'p','e','r','i','o','d','c','e','n','t','e','r','e','d',0, 's','p','a','c','e',0, 'T','c','o','m','m','a','a','c','c','e','n','t',0, 't','c','o','m','m','a','a','c','c','e','n','t',0 }; static const FT_Int ft_extra_glyph_name_offsets[EXTRA_GLYPH_LIST_SIZE] = { 0, 6, 12, 21, 28, 35, 38, 53, 59, 72 }; static void ps_check_extra_glyph_name( const char* gname, FT_UInt glyph, FT_UInt* extra_glyphs, FT_UInt *states ) { FT_UInt n; for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ ) { if ( ft_strcmp( ft_extra_glyph_names + ft_extra_glyph_name_offsets[n], gname ) == 0 ) { if ( states[n] == 0 ) { /* mark this extra glyph as a candidate for the cmap */ states[n] = 1; extra_glyphs[n] = glyph; } return; } } } static void ps_check_extra_glyph_unicode( FT_UInt32 uni_char, FT_UInt *states ) { FT_UInt n; for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ ) { if ( uni_char == ft_extra_glyph_unicodes[n] ) { /* disable this extra glyph from being added to the cmap */ states[n] = 2; return; } } } /* Build a table that maps Unicode values to glyph indices. */ static FT_Error ps_unicodes_init( FT_Memory memory, PS_Unicodes table, FT_UInt num_glyphs, PS_GetGlyphNameFunc get_glyph_name, PS_FreeGlyphNameFunc free_glyph_name, FT_Pointer glyph_data ) { FT_Error error; FT_UInt extra_glyph_list_states[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; FT_UInt extra_glyphs[EXTRA_GLYPH_LIST_SIZE]; /* we first allocate the table */ table->num_maps = 0; if ( !FT_QNEW_ARRAY( table->maps, num_glyphs + EXTRA_GLYPH_LIST_SIZE ) ) { FT_UInt n; FT_UInt count; PS_UniMap* map; FT_UInt32 uni_char; map = table->maps; for ( n = 0; n < num_glyphs; n++ ) { const char* gname = get_glyph_name( glyph_data, n ); if ( gname && *gname ) { ps_check_extra_glyph_name( gname, n, extra_glyphs, extra_glyph_list_states ); uni_char = ps_unicode_value( gname ); if ( BASE_GLYPH( uni_char ) != 0 ) { ps_check_extra_glyph_unicode( uni_char, extra_glyph_list_states ); map->unicode = uni_char; map->glyph_index = n; map++; } if ( free_glyph_name ) free_glyph_name( glyph_data, gname ); } } for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ ) { if ( extra_glyph_list_states[n] == 1 ) { /* This glyph name has an additional representation. */ /* Add it to the cmap. */ map->unicode = ft_extra_glyph_unicodes[n]; map->glyph_index = extra_glyphs[n]; map++; } } /* now compress the table a bit */ count = (FT_UInt)( map - table->maps ); if ( count == 0 ) { /* No unicode chars here! */ FT_FREE( table->maps ); if ( !error ) error = FT_THROW( No_Unicode_Glyph_Name ); } else { /* Reallocate if the number of used entries is much smaller. */ if ( count < num_glyphs / 2 ) { FT_MEM_QRENEW_ARRAY( table->maps, num_glyphs + EXTRA_GLYPH_LIST_SIZE, count ); error = FT_Err_Ok; } /* Sort the table in increasing order of unicode values, */ /* taking care of glyph variants. */ ft_qsort( table->maps, count, sizeof ( PS_UniMap ), compare_uni_maps ); } table->num_maps = count; } return error; } static FT_UInt ps_unicodes_char_index( PS_Unicodes table, FT_UInt32 unicode ) { PS_UniMap *min, *max, *mid, *result = NULL; /* Perform a binary search on the table. */ min = table->maps; max = min + table->num_maps - 1; while ( min <= max ) { FT_UInt32 base_glyph; mid = min + ( ( max - min ) >> 1 ); if ( mid->unicode == unicode ) { result = mid; break; } base_glyph = BASE_GLYPH( mid->unicode ); if ( base_glyph == unicode ) result = mid; /* remember match but continue search for base glyph */ if ( min == max ) break; if ( base_glyph < unicode ) min = mid + 1; else max = mid - 1; } if ( result ) return result->glyph_index; else return 0; } static FT_UInt32 ps_unicodes_char_next( PS_Unicodes table, FT_UInt32 *unicode ) { FT_UInt result = 0; FT_UInt32 char_code = *unicode + 1; { FT_UInt min = 0; FT_UInt max = table->num_maps; FT_UInt mid; PS_UniMap* map; FT_UInt32 base_glyph; while ( min < max ) { mid = min + ( ( max - min ) >> 1 ); map = table->maps + mid; if ( map->unicode == char_code ) { result = map->glyph_index; goto Exit; } base_glyph = BASE_GLYPH( map->unicode ); if ( base_glyph == char_code ) result = map->glyph_index; if ( base_glyph < char_code ) min = mid + 1; else max = mid; } if ( result ) goto Exit; /* we have a variant glyph */ /* we didn't find it; check whether we have a map just above it */ char_code = 0; if ( min < table->num_maps ) { map = table->maps + min; result = map->glyph_index; char_code = BASE_GLYPH( map->unicode ); } } Exit: *unicode = char_code; return result; } #endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */ static const char* ps_get_macintosh_name( FT_UInt name_index ) { if ( name_index >= FT_NUM_MAC_NAMES ) name_index = 0; return ft_standard_glyph_names + ft_mac_names[name_index]; } static const char* ps_get_standard_strings( FT_UInt sid ) { if ( sid >= FT_NUM_SID_NAMES ) return 0; return ft_standard_glyph_names + ft_sid_names[sid]; } #ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST FT_DEFINE_SERVICE_PSCMAPSREC( pscmaps_interface, (PS_Unicode_ValueFunc) ps_unicode_value, /* unicode_value */ (PS_Unicodes_InitFunc) ps_unicodes_init, /* unicodes_init */ (PS_Unicodes_CharIndexFunc)ps_unicodes_char_index, /* unicodes_char_index */ (PS_Unicodes_CharNextFunc) ps_unicodes_char_next, /* unicodes_char_next */ (PS_Macintosh_NameFunc) ps_get_macintosh_name, /* macintosh_name */ (PS_Adobe_Std_StringsFunc) ps_get_standard_strings, /* adobe_std_strings */ t1_standard_encoding, /* adobe_std_encoding */ t1_expert_encoding /* adobe_expert_encoding */ ) #else FT_DEFINE_SERVICE_PSCMAPSREC( pscmaps_interface, NULL, /* unicode_value */ NULL, /* unicodes_init */ NULL, /* unicodes_char_index */ NULL, /* unicodes_char_next */ (PS_Macintosh_NameFunc) ps_get_macintosh_name, /* macintosh_name */ (PS_Adobe_Std_StringsFunc) ps_get_standard_strings, /* adobe_std_strings */ t1_standard_encoding, /* adobe_std_encoding */ t1_expert_encoding /* adobe_expert_encoding */ ) #endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */ FT_DEFINE_SERVICEDESCREC1( pscmaps_services, FT_SERVICE_ID_POSTSCRIPT_CMAPS, &pscmaps_interface ) static FT_Pointer psnames_get_service( FT_Module module, const char* service_id ) { FT_UNUSED( module ); return ft_service_list_lookup( pscmaps_services, service_id ); } #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ #ifndef FT_CONFIG_OPTION_POSTSCRIPT_NAMES #define PUT_PS_NAMES_SERVICE( a ) NULL #else #define PUT_PS_NAMES_SERVICE( a ) a #endif FT_DEFINE_MODULE( psnames_module_class, 0, /* this is not a font driver, nor a renderer */ sizeof ( FT_ModuleRec ), "psnames", /* driver name */ 0x10000L, /* driver version */ 0x20000L, /* driver requires FreeType 2 or above */ PUT_PS_NAMES_SERVICE( (void*)&pscmaps_interface ), /* module specific interface */ (FT_Module_Constructor)NULL, /* module_init */ (FT_Module_Destructor) NULL, /* module_done */ (FT_Module_Requester) PUT_PS_NAMES_SERVICE( psnames_get_service ) /* get_interface */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/psmodule.c
C++
gpl-3.0
15,896
/**************************************************************************** * * psmodule.h * * High-level psnames module interface (specification). * * Copyright (C) 1996-2022 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 PSMODULE_H_ #define PSMODULE_H_ #include <freetype/ftmodapi.h> FT_BEGIN_HEADER FT_DECLARE_MODULE( psnames_module_class ) FT_END_HEADER #endif /* PSMODULE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/psmodule.h
C++
gpl-3.0
748
/**************************************************************************** * * psnamerr.h * * PS names module error codes (specification only). * * Copyright (C) 2001-2022 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. * */ /************************************************************************** * * This file is used to define the PS names module error enumeration * constants. * */ #ifndef PSNAMERR_H_ #define PSNAMERR_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX PSnames_Err_ #define FT_ERR_BASE FT_Mod_Err_PSnames #include <freetype/fterrors.h> #endif /* PSNAMERR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/psnamerr.h
C++
gpl-3.0
999
/**************************************************************************** * * psnames.c * * FreeType psnames module component (body only). * * Copyright (C) 1996-2022 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "psmodule.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/psnames.c
C++
gpl-3.0
622
/**************************************************************************** * * pstables.h * * PostScript glyph names. * * Copyright (C) 2005-2022 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. * */ /* This file has been generated automatically -- do not edit! */ #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const char ft_standard_glyph_names[3696] #ifdef DEFINE_PS_TABLES_DATA = { '.','n','u','l','l', 0, 'n','o','n','m','a','r','k','i','n','g','r','e','t','u','r','n', 0, 'n','o','t','e','q','u','a','l', 0, 'i','n','f','i','n','i','t','y', 0, 'l','e','s','s','e','q','u','a','l', 0, 'g','r','e','a','t','e','r','e','q','u','a','l', 0, 'p','a','r','t','i','a','l','d','i','f','f', 0, 's','u','m','m','a','t','i','o','n', 0, 'p','r','o','d','u','c','t', 0, 'p','i', 0, 'i','n','t','e','g','r','a','l', 0, 'O','m','e','g','a', 0, 'r','a','d','i','c','a','l', 0, 'a','p','p','r','o','x','e','q','u','a','l', 0, 'D','e','l','t','a', 0, 'n','o','n','b','r','e','a','k','i','n','g','s','p','a','c','e', 0, 'l','o','z','e','n','g','e', 0, 'a','p','p','l','e', 0, 'f','r','a','n','c', 0, 'G','b','r','e','v','e', 0, 'g','b','r','e','v','e', 0, 'I','d','o','t','a','c','c','e','n','t', 0, 'S','c','e','d','i','l','l','a', 0, 's','c','e','d','i','l','l','a', 0, 'C','a','c','u','t','e', 0, 'c','a','c','u','t','e', 0, 'C','c','a','r','o','n', 0, 'c','c','a','r','o','n', 0, 'd','c','r','o','a','t', 0, '.','n','o','t','d','e','f', 0, 's','p','a','c','e', 0, 'e','x','c','l','a','m', 0, 'q','u','o','t','e','d','b','l', 0, 'n','u','m','b','e','r','s','i','g','n', 0, 'd','o','l','l','a','r', 0, 'p','e','r','c','e','n','t', 0, 'a','m','p','e','r','s','a','n','d', 0, 'q','u','o','t','e','r','i','g','h','t', 0, 'p','a','r','e','n','l','e','f','t', 0, 'p','a','r','e','n','r','i','g','h','t', 0, 'a','s','t','e','r','i','s','k', 0, 'p','l','u','s', 0, 'c','o','m','m','a', 0, 'h','y','p','h','e','n', 0, 'p','e','r','i','o','d', 0, 's','l','a','s','h', 0, 'z','e','r','o', 0, 'o','n','e', 0, 't','w','o', 0, 't','h','r','e','e', 0, 'f','o','u','r', 0, 'f','i','v','e', 0, 's','i','x', 0, 's','e','v','e','n', 0, 'e','i','g','h','t', 0, 'n','i','n','e', 0, 'c','o','l','o','n', 0, 's','e','m','i','c','o','l','o','n', 0, 'l','e','s','s', 0, 'e','q','u','a','l', 0, 'g','r','e','a','t','e','r', 0, 'q','u','e','s','t','i','o','n', 0, 'a','t', 0, 'A', 0, 'B', 0, 'C', 0, 'D', 0, 'E', 0, 'F', 0, 'G', 0, 'H', 0, 'I', 0, 'J', 0, 'K', 0, 'L', 0, 'M', 0, 'N', 0, 'O', 0, 'P', 0, 'Q', 0, 'R', 0, 'S', 0, 'T', 0, 'U', 0, 'V', 0, 'W', 0, 'X', 0, 'Y', 0, 'Z', 0, 'b','r','a','c','k','e','t','l','e','f','t', 0, 'b','a','c','k','s','l','a','s','h', 0, 'b','r','a','c','k','e','t','r','i','g','h','t', 0, 'a','s','c','i','i','c','i','r','c','u','m', 0, 'u','n','d','e','r','s','c','o','r','e', 0, 'q','u','o','t','e','l','e','f','t', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g', 0, 'h', 0, 'i', 0, 'j', 0, 'k', 0, 'l', 0, 'm', 0, 'n', 0, 'o', 0, 'p', 0, 'q', 0, 'r', 0, 's', 0, 't', 0, 'u', 0, 'v', 0, 'w', 0, 'x', 0, 'y', 0, 'z', 0, 'b','r','a','c','e','l','e','f','t', 0, 'b','a','r', 0, 'b','r','a','c','e','r','i','g','h','t', 0, 'a','s','c','i','i','t','i','l','d','e', 0, 'e','x','c','l','a','m','d','o','w','n', 0, 'c','e','n','t', 0, 's','t','e','r','l','i','n','g', 0, 'f','r','a','c','t','i','o','n', 0, 'y','e','n', 0, 'f','l','o','r','i','n', 0, 's','e','c','t','i','o','n', 0, 'c','u','r','r','e','n','c','y', 0, 'q','u','o','t','e','s','i','n','g','l','e', 0, 'q','u','o','t','e','d','b','l','l','e','f','t', 0, 'g','u','i','l','l','e','m','o','t','l','e','f','t', 0, 'g','u','i','l','s','i','n','g','l','l','e','f','t', 0, 'g','u','i','l','s','i','n','g','l','r','i','g','h','t', 0, 'f','i', 0, 'f','l', 0, 'e','n','d','a','s','h', 0, 'd','a','g','g','e','r', 0, 'd','a','g','g','e','r','d','b','l', 0, 'p','e','r','i','o','d','c','e','n','t','e','r','e','d', 0, 'p','a','r','a','g','r','a','p','h', 0, 'b','u','l','l','e','t', 0, 'q','u','o','t','e','s','i','n','g','l','b','a','s','e', 0, 'q','u','o','t','e','d','b','l','b','a','s','e', 0, 'q','u','o','t','e','d','b','l','r','i','g','h','t', 0, 'g','u','i','l','l','e','m','o','t','r','i','g','h','t', 0, 'e','l','l','i','p','s','i','s', 0, 'p','e','r','t','h','o','u','s','a','n','d', 0, 'q','u','e','s','t','i','o','n','d','o','w','n', 0, 'g','r','a','v','e', 0, 'a','c','u','t','e', 0, 'c','i','r','c','u','m','f','l','e','x', 0, 't','i','l','d','e', 0, 'm','a','c','r','o','n', 0, 'b','r','e','v','e', 0, 'd','o','t','a','c','c','e','n','t', 0, 'd','i','e','r','e','s','i','s', 0, 'r','i','n','g', 0, 'c','e','d','i','l','l','a', 0, 'h','u','n','g','a','r','u','m','l','a','u','t', 0, 'o','g','o','n','e','k', 0, 'c','a','r','o','n', 0, 'e','m','d','a','s','h', 0, 'A','E', 0, 'o','r','d','f','e','m','i','n','i','n','e', 0, 'L','s','l','a','s','h', 0, 'O','s','l','a','s','h', 0, 'O','E', 0, 'o','r','d','m','a','s','c','u','l','i','n','e', 0, 'a','e', 0, 'd','o','t','l','e','s','s','i', 0, 'l','s','l','a','s','h', 0, 'o','s','l','a','s','h', 0, 'o','e', 0, 'g','e','r','m','a','n','d','b','l','s', 0, 'o','n','e','s','u','p','e','r','i','o','r', 0, 'l','o','g','i','c','a','l','n','o','t', 0, 'm','u', 0, 't','r','a','d','e','m','a','r','k', 0, 'E','t','h', 0, 'o','n','e','h','a','l','f', 0, 'p','l','u','s','m','i','n','u','s', 0, 'T','h','o','r','n', 0, 'o','n','e','q','u','a','r','t','e','r', 0, 'd','i','v','i','d','e', 0, 'b','r','o','k','e','n','b','a','r', 0, 'd','e','g','r','e','e', 0, 't','h','o','r','n', 0, 't','h','r','e','e','q','u','a','r','t','e','r','s', 0, 't','w','o','s','u','p','e','r','i','o','r', 0, 'r','e','g','i','s','t','e','r','e','d', 0, 'm','i','n','u','s', 0, 'e','t','h', 0, 'm','u','l','t','i','p','l','y', 0, 't','h','r','e','e','s','u','p','e','r','i','o','r', 0, 'c','o','p','y','r','i','g','h','t', 0, 'A','a','c','u','t','e', 0, 'A','c','i','r','c','u','m','f','l','e','x', 0, 'A','d','i','e','r','e','s','i','s', 0, 'A','g','r','a','v','e', 0, 'A','r','i','n','g', 0, 'A','t','i','l','d','e', 0, 'C','c','e','d','i','l','l','a', 0, 'E','a','c','u','t','e', 0, 'E','c','i','r','c','u','m','f','l','e','x', 0, 'E','d','i','e','r','e','s','i','s', 0, 'E','g','r','a','v','e', 0, 'I','a','c','u','t','e', 0, 'I','c','i','r','c','u','m','f','l','e','x', 0, 'I','d','i','e','r','e','s','i','s', 0, 'I','g','r','a','v','e', 0, 'N','t','i','l','d','e', 0, 'O','a','c','u','t','e', 0, 'O','c','i','r','c','u','m','f','l','e','x', 0, 'O','d','i','e','r','e','s','i','s', 0, 'O','g','r','a','v','e', 0, 'O','t','i','l','d','e', 0, 'S','c','a','r','o','n', 0, 'U','a','c','u','t','e', 0, 'U','c','i','r','c','u','m','f','l','e','x', 0, 'U','d','i','e','r','e','s','i','s', 0, 'U','g','r','a','v','e', 0, 'Y','a','c','u','t','e', 0, 'Y','d','i','e','r','e','s','i','s', 0, 'Z','c','a','r','o','n', 0, 'a','a','c','u','t','e', 0, 'a','c','i','r','c','u','m','f','l','e','x', 0, 'a','d','i','e','r','e','s','i','s', 0, 'a','g','r','a','v','e', 0, 'a','r','i','n','g', 0, 'a','t','i','l','d','e', 0, 'c','c','e','d','i','l','l','a', 0, 'e','a','c','u','t','e', 0, 'e','c','i','r','c','u','m','f','l','e','x', 0, 'e','d','i','e','r','e','s','i','s', 0, 'e','g','r','a','v','e', 0, 'i','a','c','u','t','e', 0, 'i','c','i','r','c','u','m','f','l','e','x', 0, 'i','d','i','e','r','e','s','i','s', 0, 'i','g','r','a','v','e', 0, 'n','t','i','l','d','e', 0, 'o','a','c','u','t','e', 0, 'o','c','i','r','c','u','m','f','l','e','x', 0, 'o','d','i','e','r','e','s','i','s', 0, 'o','g','r','a','v','e', 0, 'o','t','i','l','d','e', 0, 's','c','a','r','o','n', 0, 'u','a','c','u','t','e', 0, 'u','c','i','r','c','u','m','f','l','e','x', 0, 'u','d','i','e','r','e','s','i','s', 0, 'u','g','r','a','v','e', 0, 'y','a','c','u','t','e', 0, 'y','d','i','e','r','e','s','i','s', 0, 'z','c','a','r','o','n', 0, 'e','x','c','l','a','m','s','m','a','l','l', 0, 'H','u','n','g','a','r','u','m','l','a','u','t','s','m','a','l','l', 0, 'd','o','l','l','a','r','o','l','d','s','t','y','l','e', 0, 'd','o','l','l','a','r','s','u','p','e','r','i','o','r', 0, 'a','m','p','e','r','s','a','n','d','s','m','a','l','l', 0, 'A','c','u','t','e','s','m','a','l','l', 0, 'p','a','r','e','n','l','e','f','t','s','u','p','e','r','i','o','r', 0, 'p','a','r','e','n','r','i','g','h','t','s','u','p','e','r','i','o','r', 0, 't','w','o','d','o','t','e','n','l','e','a','d','e','r', 0, 'o','n','e','d','o','t','e','n','l','e','a','d','e','r', 0, 'z','e','r','o','o','l','d','s','t','y','l','e', 0, 'o','n','e','o','l','d','s','t','y','l','e', 0, 't','w','o','o','l','d','s','t','y','l','e', 0, 't','h','r','e','e','o','l','d','s','t','y','l','e', 0, 'f','o','u','r','o','l','d','s','t','y','l','e', 0, 'f','i','v','e','o','l','d','s','t','y','l','e', 0, 's','i','x','o','l','d','s','t','y','l','e', 0, 's','e','v','e','n','o','l','d','s','t','y','l','e', 0, 'e','i','g','h','t','o','l','d','s','t','y','l','e', 0, 'n','i','n','e','o','l','d','s','t','y','l','e', 0, 'c','o','m','m','a','s','u','p','e','r','i','o','r', 0, 't','h','r','e','e','q','u','a','r','t','e','r','s','e','m','d','a','s','h', 0, 'p','e','r','i','o','d','s','u','p','e','r','i','o','r', 0, 'q','u','e','s','t','i','o','n','s','m','a','l','l', 0, 'a','s','u','p','e','r','i','o','r', 0, 'b','s','u','p','e','r','i','o','r', 0, 'c','e','n','t','s','u','p','e','r','i','o','r', 0, 'd','s','u','p','e','r','i','o','r', 0, 'e','s','u','p','e','r','i','o','r', 0, 'i','s','u','p','e','r','i','o','r', 0, 'l','s','u','p','e','r','i','o','r', 0, 'm','s','u','p','e','r','i','o','r', 0, 'n','s','u','p','e','r','i','o','r', 0, 'o','s','u','p','e','r','i','o','r', 0, 'r','s','u','p','e','r','i','o','r', 0, 's','s','u','p','e','r','i','o','r', 0, 't','s','u','p','e','r','i','o','r', 0, 'f','f', 0, 'f','f','i', 0, 'f','f','l', 0, 'p','a','r','e','n','l','e','f','t','i','n','f','e','r','i','o','r', 0, 'p','a','r','e','n','r','i','g','h','t','i','n','f','e','r','i','o','r', 0, 'C','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'h','y','p','h','e','n','s','u','p','e','r','i','o','r', 0, 'G','r','a','v','e','s','m','a','l','l', 0, 'A','s','m','a','l','l', 0, 'B','s','m','a','l','l', 0, 'C','s','m','a','l','l', 0, 'D','s','m','a','l','l', 0, 'E','s','m','a','l','l', 0, 'F','s','m','a','l','l', 0, 'G','s','m','a','l','l', 0, 'H','s','m','a','l','l', 0, 'I','s','m','a','l','l', 0, 'J','s','m','a','l','l', 0, 'K','s','m','a','l','l', 0, 'L','s','m','a','l','l', 0, 'M','s','m','a','l','l', 0, 'N','s','m','a','l','l', 0, 'O','s','m','a','l','l', 0, 'P','s','m','a','l','l', 0, 'Q','s','m','a','l','l', 0, 'R','s','m','a','l','l', 0, 'S','s','m','a','l','l', 0, 'T','s','m','a','l','l', 0, 'U','s','m','a','l','l', 0, 'V','s','m','a','l','l', 0, 'W','s','m','a','l','l', 0, 'X','s','m','a','l','l', 0, 'Y','s','m','a','l','l', 0, 'Z','s','m','a','l','l', 0, 'c','o','l','o','n','m','o','n','e','t','a','r','y', 0, 'o','n','e','f','i','t','t','e','d', 0, 'r','u','p','i','a','h', 0, 'T','i','l','d','e','s','m','a','l','l', 0, 'e','x','c','l','a','m','d','o','w','n','s','m','a','l','l', 0, 'c','e','n','t','o','l','d','s','t','y','l','e', 0, 'L','s','l','a','s','h','s','m','a','l','l', 0, 'S','c','a','r','o','n','s','m','a','l','l', 0, 'Z','c','a','r','o','n','s','m','a','l','l', 0, 'D','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'B','r','e','v','e','s','m','a','l','l', 0, 'C','a','r','o','n','s','m','a','l','l', 0, 'D','o','t','a','c','c','e','n','t','s','m','a','l','l', 0, 'M','a','c','r','o','n','s','m','a','l','l', 0, 'f','i','g','u','r','e','d','a','s','h', 0, 'h','y','p','h','e','n','i','n','f','e','r','i','o','r', 0, 'O','g','o','n','e','k','s','m','a','l','l', 0, 'R','i','n','g','s','m','a','l','l', 0, 'C','e','d','i','l','l','a','s','m','a','l','l', 0, 'q','u','e','s','t','i','o','n','d','o','w','n','s','m','a','l','l', 0, 'o','n','e','e','i','g','h','t','h', 0, 't','h','r','e','e','e','i','g','h','t','h','s', 0, 'f','i','v','e','e','i','g','h','t','h','s', 0, 's','e','v','e','n','e','i','g','h','t','h','s', 0, 'o','n','e','t','h','i','r','d', 0, 't','w','o','t','h','i','r','d','s', 0, 'z','e','r','o','s','u','p','e','r','i','o','r', 0, 'f','o','u','r','s','u','p','e','r','i','o','r', 0, 'f','i','v','e','s','u','p','e','r','i','o','r', 0, 's','i','x','s','u','p','e','r','i','o','r', 0, 's','e','v','e','n','s','u','p','e','r','i','o','r', 0, 'e','i','g','h','t','s','u','p','e','r','i','o','r', 0, 'n','i','n','e','s','u','p','e','r','i','o','r', 0, 'z','e','r','o','i','n','f','e','r','i','o','r', 0, 'o','n','e','i','n','f','e','r','i','o','r', 0, 't','w','o','i','n','f','e','r','i','o','r', 0, 't','h','r','e','e','i','n','f','e','r','i','o','r', 0, 'f','o','u','r','i','n','f','e','r','i','o','r', 0, 'f','i','v','e','i','n','f','e','r','i','o','r', 0, 's','i','x','i','n','f','e','r','i','o','r', 0, 's','e','v','e','n','i','n','f','e','r','i','o','r', 0, 'e','i','g','h','t','i','n','f','e','r','i','o','r', 0, 'n','i','n','e','i','n','f','e','r','i','o','r', 0, 'c','e','n','t','i','n','f','e','r','i','o','r', 0, 'd','o','l','l','a','r','i','n','f','e','r','i','o','r', 0, 'p','e','r','i','o','d','i','n','f','e','r','i','o','r', 0, 'c','o','m','m','a','i','n','f','e','r','i','o','r', 0, 'A','g','r','a','v','e','s','m','a','l','l', 0, 'A','a','c','u','t','e','s','m','a','l','l', 0, 'A','c','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'A','t','i','l','d','e','s','m','a','l','l', 0, 'A','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'A','r','i','n','g','s','m','a','l','l', 0, 'A','E','s','m','a','l','l', 0, 'C','c','e','d','i','l','l','a','s','m','a','l','l', 0, 'E','g','r','a','v','e','s','m','a','l','l', 0, 'E','a','c','u','t','e','s','m','a','l','l', 0, 'E','c','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'E','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'I','g','r','a','v','e','s','m','a','l','l', 0, 'I','a','c','u','t','e','s','m','a','l','l', 0, 'I','c','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'I','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'E','t','h','s','m','a','l','l', 0, 'N','t','i','l','d','e','s','m','a','l','l', 0, 'O','g','r','a','v','e','s','m','a','l','l', 0, 'O','a','c','u','t','e','s','m','a','l','l', 0, 'O','c','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'O','t','i','l','d','e','s','m','a','l','l', 0, 'O','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'O','E','s','m','a','l','l', 0, 'O','s','l','a','s','h','s','m','a','l','l', 0, 'U','g','r','a','v','e','s','m','a','l','l', 0, 'U','a','c','u','t','e','s','m','a','l','l', 0, 'U','c','i','r','c','u','m','f','l','e','x','s','m','a','l','l', 0, 'U','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, 'Y','a','c','u','t','e','s','m','a','l','l', 0, 'T','h','o','r','n','s','m','a','l','l', 0, 'Y','d','i','e','r','e','s','i','s','s','m','a','l','l', 0, '0','0','1','.','0','0','0', 0, '0','0','1','.','0','0','1', 0, '0','0','1','.','0','0','2', 0, '0','0','1','.','0','0','3', 0, 'B','l','a','c','k', 0, 'B','o','l','d', 0, 'B','o','o','k', 0, 'L','i','g','h','t', 0, 'M','e','d','i','u','m', 0, 'R','e','g','u','l','a','r', 0, 'R','o','m','a','n', 0, 'S','e','m','i','b','o','l','d', 0, } #endif /* DEFINE_PS_TABLES_DATA */ ; #define FT_NUM_MAC_NAMES 258 /* Values are offsets into the `ft_standard_glyph_names' table */ #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const short ft_mac_names[FT_NUM_MAC_NAMES] #ifdef DEFINE_PS_TABLES_DATA = { 253, 0, 6, 261, 267, 274, 283, 294, 301, 309, 758, 330, 340, 351, 360, 365, 371, 378, 385, 391, 396, 400, 404, 410, 415, 420, 424, 430, 436, 441, 447, 457, 462, 468, 476, 485, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 552, 562, 575, 587, 979, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 670, 674, 685, 1375,1392,1405,1414,1486,1512,1562,1603,1632,1610,1622,1645,1639,1652, 1661,1690,1668,1680,1697,1726,1704,1716,1733,1740,1769,1747,1759,1776, 1790,1819,1797,1809, 839,1263, 707, 712, 741, 881, 871,1160,1302,1346, 1197, 985,1031, 23,1086,1108, 32,1219, 41, 51, 730,1194, 64, 76, 86, 94, 97,1089,1118, 106,1131,1150, 966, 696,1183, 112, 734, 120, 132, 783, 930, 945, 138,1385,1398,1529,1115,1157, 832,1079, 770, 916, 598, 319,1246, 155,1833,1586, 721, 749, 797, 811, 826, 829, 846, 856, 888, 903, 954,1363,1421,1356,1433,1443,1450,1457,1469,1479,1493,1500, 163,1522,1543,1550,1572,1134, 991,1002,1008,1015,1021,1040,1045,1053, 1066,1073,1101,1143,1536,1783,1596,1843,1253,1207,1319,1579,1826,1229, 1270,1313,1323,1171,1290,1332,1211,1235,1276, 169, 175, 182, 189, 200, 209, 218, 225, 232, 239, 246 } #endif /* DEFINE_PS_TABLES_DATA */ ; #define FT_NUM_SID_NAMES 391 /* Values are offsets into the `ft_standard_glyph_names' table */ #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const short ft_sid_names[FT_NUM_SID_NAMES] #ifdef DEFINE_PS_TABLES_DATA = { 253, 261, 267, 274, 283, 294, 301, 309, 319, 330, 340, 351, 360, 365, 371, 378, 385, 391, 396, 400, 404, 410, 415, 420, 424, 430, 436, 441, 447, 457, 462, 468, 476, 485, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 552, 562, 575, 587, 598, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 670, 674, 685, 696, 707, 712, 721, 730, 734, 741, 749, 758, 770, 783, 797, 811, 826, 829, 832, 839, 846, 856, 871, 881, 888, 903, 916, 930, 945, 954, 966, 979, 985, 991,1002,1008,1015,1021,1031,1040,1045,1053,1066,1073,1079,1086,1089, 1101,1108,1115,1118,1131,1134,1143,1150,1157,1160,1171,1183,1194,1197, 1207,1211,1219,1229,1235,1246,1253,1263,1270,1276,1290,1302,1313,1319, 1323,1332,1346,1356,1363,1375,1385,1392,1398,1405,1414,1421,1433,1443, 1450,1457,1469,1479,1486,1493,1500,1512,1522,1529,1536,1543,1550,1562, 1572,1579,1586,1596,1603,1610,1622,1632,1639,1645,1652,1661,1668,1680, 1690,1697,1704,1716,1726,1733,1740,1747,1759,1769,1776,1783,1790,1797, 1809,1819,1826,1833,1843,1850,1862,1880,1895,1910,1925,1936,1954,1973, 1988,2003,2016,2028,2040,2054,2067,2080,2092,2106,2120,2133,2147,2167, 2182,2196,2206,2216,2229,2239,2249,2259,2269,2279,2289,2299,2309,2319, 2329,2332,2336,2340,2358,2377,2393,2408,2419,2426,2433,2440,2447,2454, 2461,2468,2475,2482,2489,2496,2503,2510,2517,2524,2531,2538,2545,2552, 2559,2566,2573,2580,2587,2594,2601,2615,2625,2632,2643,2659,2672,2684, 2696,2708,2722,2733,2744,2759,2771,2782,2797,2809,2819,2832,2850,2860, 2873,2885,2898,2907,2917,2930,2943,2956,2968,2982,2996,3009,3022,3034, 3046,3060,3073,3086,3098,3112,3126,3139,3152,3167,3182,3196,3208,3220, 3237,3249,3264,3275,3283,3297,3309,3321,3338,3353,3365,3377,3394,3409, 3418,3430,3442,3454,3471,3483,3498,3506,3518,3530,3542,3559,3574,3586, 3597,3612,3620,3628,3636,3644,3650,3655,3660,3666,3673,3681,3687 } #endif /* DEFINE_PS_TABLES_DATA */ ; /* the following are indices into the SID name table */ #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const unsigned short t1_standard_encoding[256] #ifdef DEFINE_PS_TABLES_DATA = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110, 0,111,112,113,114, 0,115,116,117,118,119,120,121,122, 0,123, 0,124,125,126,127,128,129,130,131, 0,132,133, 0,134,135,136, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,138, 0,139, 0, 0, 0, 0,140,141,142,143, 0, 0, 0, 0, 0,144, 0, 0, 0,145, 0, 0,146,147,148,149, 0, 0, 0, 0 } #endif /* DEFINE_PS_TABLES_DATA */ ; /* the following are indices into the SID name table */ #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const unsigned short t1_expert_encoding[256] #ifdef DEFINE_PS_TABLES_DATA = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,229,230, 0,231,232,233,234,235,236,237,238, 13, 14, 15, 99, 239,240,241,242,243,244,245,246,247,248, 27, 28,249,250,251,252, 0,253,254,255,256,257, 0, 0, 0,258, 0, 0,259,260,261,262, 0, 0,263,264,265, 0,266,109,110,267,268,269, 0,270,271,272, 273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288, 289,290,291,292,293,294,295,296,297,298,299,300,301,302,303, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,304,305,306, 0, 0,307,308,309,310,311, 0,312, 0, 0,313, 0, 0,314,315, 0, 0,316,317,318, 0, 0, 0,158,155,163,319, 320,321,322,323,324,325, 0, 0,326,150,164,169,327,328,329,330, 331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346, 347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362, 363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378 } #endif /* DEFINE_PS_TABLES_DATA */ ; /* * This table is a compressed version of the Adobe Glyph List (AGL), * optimized for efficient searching. It has been generated by the * `glnames.py' python script located in the `src/tools' directory. * * The lookup function to get the Unicode value for a given string * is defined below the table. */ #ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST #ifndef DEFINE_PS_TABLES_DATA #ifdef __cplusplus extern "C" #else extern #endif #endif const unsigned char ft_adobe_glyph_list[55997L] #ifdef DEFINE_PS_TABLES_DATA = { 0, 52, 0,106, 2,167, 3, 63, 4,220, 6,125, 9,143, 10, 23, 11,137, 12,199, 14,246, 15, 87, 16,233, 17,219, 18,104, 19, 88, 22,110, 23, 32, 23, 71, 24, 77, 27,156, 29, 73, 31,247, 32,107, 32,222, 33, 55, 34,154, 35,218, 58, 10, 64,122, 72,188, 80,109, 88,104, 93, 61, 98,168,106, 91,114,111,115,237,122,180,127,255, 135,164,143,132,149,213,158,108,161,115,168,175,183,147,197,199, 202, 25,204,166,208,209,209, 81,215, 26, 65,143, 0, 65, 0,140, 0,175, 0,193, 1, 15, 1,147, 1,233, 1,251, 2, 7, 2, 40, 2, 57, 2, 82, 2, 91, 2,128, 2,136, 2,154, 69,131, 0,198, 0,150, 0,158, 0,167,225,227,245,244,101,128, 1,252,237,225, 227,242,239,110,128, 1,226,243,237,225,236,108,128,247,230,225, 227,245,244,101,129, 0,193, 0,185,243,237,225,236,108,128,247, 225,226,242,229,246,101,134, 1, 2, 0,213, 0,221, 0,232, 0, 243, 0,251, 1, 7,225,227,245,244,101,128, 30,174,227,249,242, 233,236,236,233, 99,128, 4,208,228,239,244,226,229,236,239,119, 128, 30,182,231,242,225,246,101,128, 30,176,232,239,239,235,225, 226,239,246,101,128, 30,178,244,233,236,228,101,128, 30,180, 99, 4, 1, 25, 1, 32, 1,121, 1,137,225,242,239,110,128, 1,205, 233,242, 99, 2, 1, 40, 1, 45,236,101,128, 36,182,245,237,230, 236,229,120,134, 0,194, 1, 66, 1, 74, 1, 85, 1, 93, 1,105, 1,113,225,227,245,244,101,128, 30,164,228,239,244,226,229,236, 239,119,128, 30,172,231,242,225,246,101,128, 30,166,232,239,239, 235,225,226,239,246,101,128, 30,168,243,237,225,236,108,128,247, 226,244,233,236,228,101,128, 30,170,245,244,101,129,246,201, 1, 129,243,237,225,236,108,128,247,180,249,242,233,236,236,233, 99, 128, 4, 16,100, 3, 1,155, 1,165, 1,209,226,236,231,242,225, 246,101,128, 2, 0,233,229,242,229,243,233,115,131, 0,196, 1, 181, 1,192, 1,201,227,249,242,233,236,236,233, 99,128, 4,210, 237,225,227,242,239,110,128, 1,222,243,237,225,236,108,128,247, 228,239,116, 2, 1,216, 1,224,226,229,236,239,119,128, 30,160, 237,225,227,242,239,110,128, 1,224,231,242,225,246,101,129, 0, 192, 1,243,243,237,225,236,108,128,247,224,232,239,239,235,225, 226,239,246,101,128, 30,162,105, 2, 2, 13, 2, 25,229,227,249, 242,233,236,236,233, 99,128, 4,212,238,246,229,242,244,229,228, 226,242,229,246,101,128, 2, 2,236,240,232, 97,129, 3,145, 2, 49,244,239,238,239,115,128, 3,134,109, 2, 2, 63, 2, 71,225, 227,242,239,110,128, 1, 0,239,238,239,243,240,225,227,101,128, 255, 33,239,231,239,238,229,107,128, 1, 4,242,233,238,103,131, 0,197, 2,104, 2,112, 2,120,225,227,245,244,101,128, 1,250, 226,229,236,239,119,128, 30, 0,243,237,225,236,108,128,247,229, 243,237,225,236,108,128,247, 97,244,233,236,228,101,129, 0,195, 2,146,243,237,225,236,108,128,247,227,249,226,225,242,237,229, 238,233,225,110,128, 5, 49, 66,137, 0, 66, 2,189, 2,198, 2, 223, 3, 3, 3, 10, 3, 22, 3, 34, 3, 46, 3, 54,227,233,242, 227,236,101,128, 36,183,228,239,116, 2, 2,206, 2,215,225,227, 227,229,238,116,128, 30, 2,226,229,236,239,119,128, 30, 4,101, 3, 2,231, 2,242, 2,254,227,249,242,233,236,236,233, 99,128, 4, 17,238,225,242,237,229,238,233,225,110,128, 5, 50,244, 97, 128, 3,146,232,239,239,107,128, 1,129,236,233,238,229,226,229, 236,239,119,128, 30, 6,237,239,238,239,243,240,225,227,101,128, 255, 34,242,229,246,229,243,237,225,236,108,128,246,244,243,237, 225,236,108,128,247, 98,244,239,240,226,225,114,128, 1,130, 67, 137, 0, 67, 3, 85, 3,127, 3,193, 3,210, 3,224, 4,171, 4, 188, 4,200, 4,212, 97, 3, 3, 93, 3,104, 3,111,225,242,237, 229,238,233,225,110,128, 5, 62,227,245,244,101,128, 1, 6,242, 239,110,129,246,202, 3,119,243,237,225,236,108,128,246,245, 99, 3, 3,135, 3,142, 3,171,225,242,239,110,128, 1, 12,229,228, 233,236,236, 97,130, 0,199, 3,155, 3,163,225,227,245,244,101, 128, 30, 8,243,237,225,236,108,128,247,231,233,242, 99, 2, 3, 179, 3,184,236,101,128, 36,184,245,237,230,236,229,120,128, 1, 8,228,239,116,129, 1, 10, 3,201,225,227,227,229,238,116,128, 1, 10,229,228,233,236,236,225,243,237,225,236,108,128,247,184, 104, 4, 3,234, 3,246, 4,161, 4,165,225,225,242,237,229,238, 233,225,110,128, 5, 73,101, 6, 4, 4, 4, 24, 4, 35, 4,103, 4,115, 4,136,225,226,235,232,225,243,233,225,238,227,249,242, 233,236,236,233, 99,128, 4,188,227,249,242,233,236,236,233, 99, 128, 4, 39,100, 2, 4, 41, 4, 85,229,243,227,229,238,228,229, 114, 2, 4, 54, 4, 74,225,226,235,232,225,243,233,225,238,227, 249,242,233,236,236,233, 99,128, 4,190,227,249,242,233,236,236, 233, 99,128, 4,182,233,229,242,229,243,233,243,227,249,242,233, 236,236,233, 99,128, 4,244,232,225,242,237,229,238,233,225,110, 128, 5, 67,235,232,225,235,225,243,243,233,225,238,227,249,242, 233,236,236,233, 99,128, 4,203,246,229,242,244,233,227,225,236, 243,244,242,239,235,229,227,249,242,233,236,236,233, 99,128, 4, 184,105,128, 3,167,239,239,107,128, 1,135,233,242,227,245,237, 230,236,229,248,243,237,225,236,108,128,246,246,237,239,238,239, 243,240,225,227,101,128,255, 35,239,225,242,237,229,238,233,225, 110,128, 5, 81,243,237,225,236,108,128,247, 99, 68,142, 0, 68, 4,252, 5, 10, 5, 36, 5, 96, 5,121, 5,166, 5,173, 5,231, 5,244, 6, 0, 6, 12, 6, 28, 6, 48, 6, 57, 90,129, 1,241, 5, 2,227,225,242,239,110,128, 1,196, 97, 2, 5, 16, 5, 27, 225,242,237,229,238,233,225,110,128, 5, 52,230,242,233,227,225, 110,128, 1,137, 99, 4, 5, 46, 5, 53, 5, 62, 5, 89,225,242, 239,110,128, 1, 14,229,228,233,236,236, 97,128, 30, 16,233,242, 99, 2, 5, 70, 5, 75,236,101,128, 36,185,245,237,230,236,229, 248,226,229,236,239,119,128, 30, 18,242,239,225,116,128, 1, 16, 228,239,116, 2, 5,104, 5,113,225,227,227,229,238,116,128, 30, 10,226,229,236,239,119,128, 30, 12,101, 3, 5,129, 5,140, 5, 150,227,249,242,233,236,236,233, 99,128, 4, 20,233,227,239,240, 244,233, 99,128, 3,238,236,244, 97,129, 34, 6, 5,158,231,242, 229,229,107,128, 3,148,232,239,239,107,128, 1,138,105, 2, 5, 179, 5,218,229,242,229,243,233,115,131,246,203, 5,194, 5,202, 5,210,193,227,245,244,101,128,246,204,199,242,225,246,101,128, 246,205,243,237,225,236,108,128,247,168,231,225,237,237,225,231, 242,229,229,107,128, 3,220,234,229,227,249,242,233,236,236,233, 99,128, 4, 2,236,233,238,229,226,229,236,239,119,128, 30, 14, 237,239,238,239,243,240,225,227,101,128,255, 36,239,244,225,227, 227,229,238,244,243,237,225,236,108,128,246,247,115, 2, 6, 34, 6, 41,236,225,243,104,128, 1, 16,237,225,236,108,128,247,100, 244,239,240,226,225,114,128, 1,139,122,131, 1,242, 6, 67, 6, 75, 6,112,227,225,242,239,110,128, 1,197,101, 2, 6, 81, 6, 101,225,226,235,232,225,243,233,225,238,227,249,242,233,236,236, 233, 99,128, 4,224,227,249,242,233,236,236,233, 99,128, 4, 5, 232,229,227,249,242,233,236,236,233, 99,128, 4, 15, 69,146, 0, 69, 6,165, 6,183, 6,191, 7, 89, 7,153, 7,165, 7,183, 7, 211, 8, 7, 8, 36, 8, 94, 8,169, 8,189, 8,208, 8,248, 9, 44, 9,109, 9,115,225,227,245,244,101,129, 0,201, 6,175,243, 237,225,236,108,128,247,233,226,242,229,246,101,128, 1, 20, 99, 5, 6,203, 6,210, 6,224, 6,236, 7, 79,225,242,239,110,128, 1, 26,229,228,233,236,236,225,226,242,229,246,101,128, 30, 28, 232,225,242,237,229,238,233,225,110,128, 5, 53,233,242, 99, 2, 6,244, 6,249,236,101,128, 36,186,245,237,230,236,229,120,135, 0,202, 7, 16, 7, 24, 7, 32, 7, 43, 7, 51, 7, 63, 7, 71, 225,227,245,244,101,128, 30,190,226,229,236,239,119,128, 30, 24, 228,239,244,226,229,236,239,119,128, 30,198,231,242,225,246,101, 128, 30,192,232,239,239,235,225,226,239,246,101,128, 30,194,243, 237,225,236,108,128,247,234,244,233,236,228,101,128, 30,196,249, 242,233,236,236,233, 99,128, 4, 4,100, 3, 7, 97, 7,107, 7, 127,226,236,231,242,225,246,101,128, 2, 4,233,229,242,229,243, 233,115,129, 0,203, 7,119,243,237,225,236,108,128,247,235,239, 116,130, 1, 22, 7,136, 7,145,225,227,227,229,238,116,128, 1, 22,226,229,236,239,119,128, 30,184,230,227,249,242,233,236,236, 233, 99,128, 4, 36,231,242,225,246,101,129, 0,200, 7,175,243, 237,225,236,108,128,247,232,104, 2, 7,189, 7,200,225,242,237, 229,238,233,225,110,128, 5, 55,239,239,235,225,226,239,246,101, 128, 30,186,105, 3, 7,219, 7,230, 7,245,231,232,244,242,239, 237,225,110,128, 33,103,238,246,229,242,244,229,228,226,242,229, 246,101,128, 2, 6,239,244,233,230,233,229,228,227,249,242,233, 236,236,233, 99,128, 4,100,108, 2, 8, 13, 8, 24,227,249,242, 233,236,236,233, 99,128, 4, 27,229,246,229,238,242,239,237,225, 110,128, 33,106,109, 3, 8, 44, 8, 72, 8, 83,225,227,242,239, 110,130, 1, 18, 8, 56, 8, 64,225,227,245,244,101,128, 30, 22, 231,242,225,246,101,128, 30, 20,227,249,242,233,236,236,233, 99, 128, 4, 28,239,238,239,243,240,225,227,101,128,255, 37,110, 4, 8,104, 8,115, 8,135, 8,154,227,249,242,233,236,236,233, 99, 128, 4, 29,228,229,243,227,229,238,228,229,242,227,249,242,233, 236,236,233, 99,128, 4,162,103,129, 1, 74, 8,141,232,229,227, 249,242,233,236,236,233, 99,128, 4,164,232,239,239,235,227,249, 242,233,236,236,233, 99,128, 4,199,111, 2, 8,175, 8,183,231, 239,238,229,107,128, 1, 24,240,229,110,128, 1,144,240,243,233, 236,239,110,129, 3,149, 8,200,244,239,238,239,115,128, 3,136, 114, 2, 8,214, 8,225,227,249,242,233,236,236,233, 99,128, 4, 32,229,246,229,242,243,229,100,129, 1,142, 8,237,227,249,242, 233,236,236,233, 99,128, 4, 45,115, 4, 9, 2, 9, 13, 9, 33, 9, 37,227,249,242,233,236,236,233, 99,128, 4, 33,228,229,243, 227,229,238,228,229,242,227,249,242,233,236,236,233, 99,128, 4, 170,104,128, 1,169,237,225,236,108,128,247,101,116, 3, 9, 52, 9, 78, 9, 92, 97,130, 3,151, 9, 60, 9, 70,242,237,229,238, 233,225,110,128, 5, 56,244,239,238,239,115,128, 3,137,104,129, 0,208, 9, 84,243,237,225,236,108,128,247,240,233,236,228,101, 129, 30,188, 9,101,226,229,236,239,119,128, 30, 26,245,242,111, 128, 32,172,250,104,130, 1,183, 9,124, 9,132,227,225,242,239, 110,128, 1,238,242,229,246,229,242,243,229,100,128, 1,184, 70, 136, 0, 70, 9,163, 9,172, 9,184, 9,212, 9,219, 9,248, 10, 4, 10, 15,227,233,242,227,236,101,128, 36,187,228,239,244,225, 227,227,229,238,116,128, 30, 30,101, 2, 9,190, 9,202,232,225, 242,237,229,238,233,225,110,128, 5, 86,233,227,239,240,244,233, 99,128, 3,228,232,239,239,107,128, 1,145,105, 2, 9,225, 9, 238,244,225,227,249,242,233,236,236,233, 99,128, 4,114,246,229, 242,239,237,225,110,128, 33,100,237,239,238,239,243,240,225,227, 101,128,255, 38,239,245,242,242,239,237,225,110,128, 33, 99,243, 237,225,236,108,128,247,102, 71,140, 0, 71, 10, 51, 10, 61, 10, 107, 10,115, 10,176, 10,193, 10,205, 11, 39, 11, 52, 11, 65, 11, 90, 11,107,194,243,241,245,225,242,101,128, 51,135, 97, 3, 10, 69, 10, 76, 10, 94,227,245,244,101,128, 1,244,237,237, 97,129, 3,147, 10, 84,225,230,242,233,227,225,110,128, 1,148,238,231, 233,225,227,239,240,244,233, 99,128, 3,234,226,242,229,246,101, 128, 1, 30, 99, 4, 10,125, 10,132, 10,141, 10,163,225,242,239, 110,128, 1,230,229,228,233,236,236, 97,128, 1, 34,233,242, 99, 2, 10,149, 10,154,236,101,128, 36,188,245,237,230,236,229,120, 128, 1, 28,239,237,237,225,225,227,227,229,238,116,128, 1, 34, 228,239,116,129, 1, 32, 10,184,225,227,227,229,238,116,128, 1, 32,229,227,249,242,233,236,236,233, 99,128, 4, 19,104, 3, 10, 213, 10,226, 11, 33,225,228,225,242,237,229,238,233,225,110,128, 5, 66,101, 3, 10,234, 10,255, 11, 16,237,233,228,228,236,229, 232,239,239,235,227,249,242,233,236,236,233, 99,128, 4,148,243, 244,242,239,235,229,227,249,242,233,236,236,233, 99,128, 4,146, 245,240,244,245,242,238,227,249,242,233,236,236,233, 99,128, 4, 144,239,239,107,128, 1,147,233,237,225,242,237,229,238,233,225, 110,128, 5, 51,234,229,227,249,242,233,236,236,233, 99,128, 4, 3,109, 2, 11, 71, 11, 79,225,227,242,239,110,128, 30, 32,239, 238,239,243,240,225,227,101,128,255, 39,242,225,246,101,129,246, 206, 11, 99,243,237,225,236,108,128,247, 96,115, 2, 11,113, 11, 129,237,225,236,108,129,247,103, 11,122,232,239,239,107,128, 2, 155,244,242,239,235,101,128, 1,228, 72,140, 0, 72, 11,165, 11, 190, 11,198, 11,208, 12, 17, 12, 40, 12, 77, 12,117, 12,129, 12, 157, 12,165, 12,189,177,184, 53, 3, 11,175, 11,180, 11,185,179, 51,128, 37,207,180, 51,128, 37,170,181, 49,128, 37,171,178,178, 176,183, 51,128, 37,161,208,243,241,245,225,242,101,128, 51,203, 97, 3, 11,216, 11,236, 12, 0,225,226,235,232,225,243,233,225, 238,227,249,242,233,236,236,233, 99,128, 4,168,228,229,243,227, 229,238,228,229,242,227,249,242,233,236,236,233, 99,128, 4,178, 242,228,243,233,231,238,227,249,242,233,236,236,233, 99,128, 4, 42, 98, 2, 12, 23, 12, 28,225,114,128, 1, 38,242,229,246,229, 226,229,236,239,119,128, 30, 42, 99, 2, 12, 46, 12, 55,229,228, 233,236,236, 97,128, 30, 40,233,242, 99, 2, 12, 63, 12, 68,236, 101,128, 36,189,245,237,230,236,229,120,128, 1, 36,100, 2, 12, 83, 12, 93,233,229,242,229,243,233,115,128, 30, 38,239,116, 2, 12,100, 12,109,225,227,227,229,238,116,128, 30, 34,226,229,236, 239,119,128, 30, 36,237,239,238,239,243,240,225,227,101,128,255, 40,111, 2, 12,135, 12,146,225,242,237,229,238,233,225,110,128, 5, 64,242,233,227,239,240,244,233, 99,128, 3,232,243,237,225, 236,108,128,247,104,245,238,231,225,242,245,237,236,225,245,116, 129,246,207, 12,181,243,237,225,236,108,128,246,248,250,243,241, 245,225,242,101,128, 51,144, 73,146, 0, 73, 12,239, 12,251, 12, 255, 13, 11, 13, 29, 13, 37, 13, 94, 13,181, 13,214, 13,224, 13, 242, 13,254, 14, 48, 14, 86, 14, 99, 14,166, 14,187, 14,205,193, 227,249,242,233,236,236,233, 99,128, 4, 47, 74,128, 1, 50,213, 227,249,242,233,236,236,233, 99,128, 4, 46,225,227,245,244,101, 129, 0,205, 13, 21,243,237,225,236,108,128,247,237,226,242,229, 246,101,128, 1, 44, 99, 3, 13, 45, 13, 52, 13, 84,225,242,239, 110,128, 1,207,233,242, 99, 2, 13, 60, 13, 65,236,101,128, 36, 190,245,237,230,236,229,120,129, 0,206, 13, 76,243,237,225,236, 108,128,247,238,249,242,233,236,236,233, 99,128, 4, 6,100, 3, 13,102, 13,112, 13,155,226,236,231,242,225,246,101,128, 2, 8, 233,229,242,229,243,233,115,131, 0,207, 13,128, 13,136, 13,147, 225,227,245,244,101,128, 30, 46,227,249,242,233,236,236,233, 99, 128, 4,228,243,237,225,236,108,128,247,239,239,116,130, 1, 48, 13,164, 13,173,225,227,227,229,238,116,128, 1, 48,226,229,236, 239,119,128, 30,202,101, 2, 13,187, 13,203,226,242,229,246,229, 227,249,242,233,236,236,233, 99,128, 4,214,227,249,242,233,236, 236,233, 99,128, 4, 21,230,242,225,235,244,245,114,128, 33, 17, 231,242,225,246,101,129, 0,204, 13,234,243,237,225,236,108,128, 247,236,232,239,239,235,225,226,239,246,101,128, 30,200,105, 3, 14, 6, 14, 17, 14, 32,227,249,242,233,236,236,233, 99,128, 4, 24,238,246,229,242,244,229,228,226,242,229,246,101,128, 2, 10, 243,232,239,242,244,227,249,242,233,236,236,233, 99,128, 4, 25, 109, 2, 14, 54, 14, 75,225,227,242,239,110,129, 1, 42, 14, 64, 227,249,242,233,236,236,233, 99,128, 4,226,239,238,239,243,240, 225,227,101,128,255, 41,238,233,225,242,237,229,238,233,225,110, 128, 5, 59,111, 3, 14,107, 14,118, 14,126,227,249,242,233,236, 236,233, 99,128, 4, 1,231,239,238,229,107,128, 1, 46,244, 97, 131, 3,153, 14,137, 14,147, 14,158,225,230,242,233,227,225,110, 128, 1,150,228,233,229,242,229,243,233,115,128, 3,170,244,239, 238,239,115,128, 3,138,115, 2, 14,172, 14,179,237,225,236,108, 128,247,105,244,242,239,235,101,128, 1,151,244,233,236,228,101, 129, 1, 40, 14,197,226,229,236,239,119,128, 30, 44,250,232,233, 244,243, 97, 2, 14,216, 14,227,227,249,242,233,236,236,233, 99, 128, 4,116,228,226,236,231,242,225,246,229,227,249,242,233,236, 236,233, 99,128, 4,118, 74,134, 0, 74, 15, 6, 15, 18, 15, 41, 15, 53, 15, 67, 15, 79,225,225,242,237,229,238,233,225,110,128, 5, 65,227,233,242, 99, 2, 15, 27, 15, 32,236,101,128, 36,191, 245,237,230,236,229,120,128, 1, 52,229,227,249,242,233,236,236, 233, 99,128, 4, 8,232,229,232,225,242,237,229,238,233,225,110, 128, 5, 75,237,239,238,239,243,240,225,227,101,128,255, 42,243, 237,225,236,108,128,247,106, 75,140, 0, 75, 15,115, 15,125, 15, 135, 16, 18, 16, 65, 16, 76, 16,106, 16,143, 16,156, 16,168, 16, 180, 16,208,194,243,241,245,225,242,101,128, 51,133,203,243,241, 245,225,242,101,128, 51,205, 97, 7, 15,151, 15,169, 15,191, 15, 211, 15,226, 15,232, 15,249,226,225,243,232,235,233,242,227,249, 242,233,236,236,233, 99,128, 4,160, 99, 2, 15,175, 15,181,245, 244,101,128, 30, 48,249,242,233,236,236,233, 99,128, 4, 26,228, 229,243,227,229,238,228,229,242,227,249,242,233,236,236,233, 99, 128, 4,154,232,239,239,235,227,249,242,233,236,236,233, 99,128, 4,195,240,240, 97,128, 3,154,243,244,242,239,235,229,227,249, 242,233,236,236,233, 99,128, 4,158,246,229,242,244,233,227,225, 236,243,244,242,239,235,229,227,249,242,233,236,236,233, 99,128, 4,156, 99, 4, 16, 28, 16, 35, 16, 44, 16, 52,225,242,239,110, 128, 1,232,229,228,233,236,236, 97,128, 1, 54,233,242,227,236, 101,128, 36,192,239,237,237,225,225,227,227,229,238,116,128, 1, 54,228,239,244,226,229,236,239,119,128, 30, 50,101, 2, 16, 82, 16, 94,232,225,242,237,229,238,233,225,110,128, 5, 84,238,225, 242,237,229,238,233,225,110,128, 5, 63,104, 3, 16,114, 16,126, 16,137,225,227,249,242,233,236,236,233, 99,128, 4, 37,229,233, 227,239,240,244,233, 99,128, 3,230,239,239,107,128, 1,152,234, 229,227,249,242,233,236,236,233, 99,128, 4, 12,236,233,238,229, 226,229,236,239,119,128, 30, 52,237,239,238,239,243,240,225,227, 101,128,255, 43,239,240,240, 97, 2, 16,189, 16,200,227,249,242, 233,236,236,233, 99,128, 4,128,231,242,229,229,107,128, 3,222, 115, 2, 16,214, 16,226,233,227,249,242,233,236,236,233, 99,128, 4,110,237,225,236,108,128,247,107, 76,138, 0, 76, 17, 1, 17, 5, 17, 9, 17, 29, 17, 95, 17,133, 17,147, 17,165, 17,177, 17, 189, 74,128, 1,199, 76,128,246,191, 97, 2, 17, 15, 17, 22,227, 245,244,101,128, 1, 57,237,226,228, 97,128, 3,155, 99, 4, 17, 39, 17, 46, 17, 55, 17, 82,225,242,239,110,128, 1, 61,229,228, 233,236,236, 97,128, 1, 59,233,242, 99, 2, 17, 63, 17, 68,236, 101,128, 36,193,245,237,230,236,229,248,226,229,236,239,119,128, 30, 60,239,237,237,225,225,227,227,229,238,116,128, 1, 59,228, 239,116,130, 1, 63, 17,105, 17,114,225,227,227,229,238,116,128, 1, 63,226,229,236,239,119,129, 30, 54, 17,124,237,225,227,242, 239,110,128, 30, 56,233,247,238,225,242,237,229,238,233,225,110, 128, 5, 60,106,129, 1,200, 17,153,229,227,249,242,233,236,236, 233, 99,128, 4, 9,236,233,238,229,226,229,236,239,119,128, 30, 58,237,239,238,239,243,240,225,227,101,128,255, 44,115, 2, 17, 195, 17,212,236,225,243,104,129, 1, 65, 17,204,243,237,225,236, 108,128,246,249,237,225,236,108,128,247,108, 77,137, 0, 77, 17, 241, 17,251, 18, 24, 18, 33, 18, 58, 18, 71, 18, 83, 18, 91, 18, 100,194,243,241,245,225,242,101,128, 51,134,225, 99, 2, 18, 2, 18, 18,242,239,110,129,246,208, 18, 10,243,237,225,236,108,128, 247,175,245,244,101,128, 30, 62,227,233,242,227,236,101,128, 36, 194,228,239,116, 2, 18, 41, 18, 50,225,227,227,229,238,116,128, 30, 64,226,229,236,239,119,128, 30, 66,229,238,225,242,237,229, 238,233,225,110,128, 5, 68,237,239,238,239,243,240,225,227,101, 128,255, 45,243,237,225,236,108,128,247,109,244,245,242,238,229, 100,128, 1,156,117,128, 3,156, 78,141, 0, 78, 18,134, 18,138, 18,146, 18,212, 18,237, 18,248, 19, 3, 19, 21, 19, 33, 19, 45, 19, 58, 19, 66, 19, 84, 74,128, 1,202,225,227,245,244,101,128, 1, 67, 99, 4, 18,156, 18,163, 18,172, 18,199,225,242,239,110, 128, 1, 71,229,228,233,236,236, 97,128, 1, 69,233,242, 99, 2, 18,180, 18,185,236,101,128, 36,195,245,237,230,236,229,248,226, 229,236,239,119,128, 30, 74,239,237,237,225,225,227,227,229,238, 116,128, 1, 69,228,239,116, 2, 18,220, 18,229,225,227,227,229, 238,116,128, 30, 68,226,229,236,239,119,128, 30, 70,232,239,239, 235,236,229,230,116,128, 1,157,233,238,229,242,239,237,225,110, 128, 33,104,106,129, 1,203, 19, 9,229,227,249,242,233,236,236, 233, 99,128, 4, 10,236,233,238,229,226,229,236,239,119,128, 30, 72,237,239,238,239,243,240,225,227,101,128,255, 46,239,247,225, 242,237,229,238,233,225,110,128, 5, 70,243,237,225,236,108,128, 247,110,244,233,236,228,101,129, 0,209, 19, 76,243,237,225,236, 108,128,247,241,117,128, 3,157, 79,141, 0, 79, 19,118, 19,132, 19,150, 19,203, 20, 78, 20,152, 20,187, 21, 48, 21, 69, 21,213, 21,223, 21,254, 22, 53, 69,129, 1, 82, 19,124,243,237,225,236, 108,128,246,250,225,227,245,244,101,129, 0,211, 19,142,243,237, 225,236,108,128,247,243, 98, 2, 19,156, 19,196,225,242,242,229, 100, 2, 19,166, 19,177,227,249,242,233,236,236,233, 99,128, 4, 232,228,233,229,242,229,243,233,243,227,249,242,233,236,236,233, 99,128, 4,234,242,229,246,101,128, 1, 78, 99, 4, 19,213, 19, 220, 19,235, 20, 68,225,242,239,110,128, 1,209,229,238,244,229, 242,229,228,244,233,236,228,101,128, 1,159,233,242, 99, 2, 19, 243, 19,248,236,101,128, 36,196,245,237,230,236,229,120,134, 0, 212, 20, 13, 20, 21, 20, 32, 20, 40, 20, 52, 20, 60,225,227,245, 244,101,128, 30,208,228,239,244,226,229,236,239,119,128, 30,216, 231,242,225,246,101,128, 30,210,232,239,239,235,225,226,239,246, 101,128, 30,212,243,237,225,236,108,128,247,244,244,233,236,228, 101,128, 30,214,249,242,233,236,236,233, 99,128, 4, 30,100, 3, 20, 86, 20,109, 20,142,226,108, 2, 20, 93, 20,101,225,227,245, 244,101,128, 1, 80,231,242,225,246,101,128, 2, 12,233,229,242, 229,243,233,115,130, 0,214, 20,123, 20,134,227,249,242,233,236, 236,233, 99,128, 4,230,243,237,225,236,108,128,247,246,239,244, 226,229,236,239,119,128, 30,204,103, 2, 20,158, 20,170,239,238, 229,235,243,237,225,236,108,128,246,251,242,225,246,101,129, 0, 210, 20,179,243,237,225,236,108,128,247,242,104, 4, 20,197, 20, 208, 20,212, 21, 34,225,242,237,229,238,233,225,110,128, 5, 85, 109,128, 33, 38,111, 2, 20,218, 20,228,239,235,225,226,239,246, 101,128, 30,206,242,110,133, 1,160, 20,243, 20,251, 21, 6, 21, 14, 21, 26,225,227,245,244,101,128, 30,218,228,239,244,226,229, 236,239,119,128, 30,226,231,242,225,246,101,128, 30,220,232,239, 239,235,225,226,239,246,101,128, 30,222,244,233,236,228,101,128, 30,224,245,238,231,225,242,245,237,236,225,245,116,128, 1, 80, 105,129, 1,162, 21, 54,238,246,229,242,244,229,228,226,242,229, 246,101,128, 2, 14,109, 4, 21, 79, 21,107, 21,184, 21,202,225, 227,242,239,110,130, 1, 76, 21, 91, 21, 99,225,227,245,244,101, 128, 30, 82,231,242,225,246,101,128, 30, 80,229,231, 97,132, 33, 38, 21,121, 21,132, 21,140, 21,156,227,249,242,233,236,236,233, 99,128, 4, 96,231,242,229,229,107,128, 3,169,242,239,245,238, 228,227,249,242,233,236,236,233, 99,128, 4,122,116, 2, 21,162, 21,177,233,244,236,239,227,249,242,233,236,236,233, 99,128, 4, 124,239,238,239,115,128, 3,143,233,227,242,239,110,129, 3,159, 21,194,244,239,238,239,115,128, 3,140,239,238,239,243,240,225, 227,101,128,255, 47,238,229,242,239,237,225,110,128, 33, 96,111, 2, 21,229, 21,248,231,239,238,229,107,129, 1,234, 21,239,237, 225,227,242,239,110,128, 1,236,240,229,110,128, 1,134,115, 3, 22, 6, 22, 33, 22, 40,236,225,243,104,130, 0,216, 22, 17, 22, 25,225,227,245,244,101,128, 1,254,243,237,225,236,108,128,247, 248,237,225,236,108,128,247,111,244,242,239,235,229,225,227,245, 244,101,128, 1,254,116, 2, 22, 59, 22, 70,227,249,242,233,236, 236,233, 99,128, 4,126,233,236,228,101,131, 0,213, 22, 83, 22, 91, 22,102,225,227,245,244,101,128, 30, 76,228,233,229,242,229, 243,233,115,128, 30, 78,243,237,225,236,108,128,247,245, 80,136, 0, 80, 22,130, 22,138, 22,147, 22,159, 22,211, 22,227, 22,246, 23, 2,225,227,245,244,101,128, 30, 84,227,233,242,227,236,101, 128, 36,197,228,239,244,225,227,227,229,238,116,128, 30, 86,101, 3, 22,167, 22,178, 22,190,227,249,242,233,236,236,233, 99,128, 4, 31,232,225,242,237,229,238,233,225,110,128, 5, 74,237,233, 228,228,236,229,232,239,239,235,227,249,242,233,236,236,233, 99, 128, 4,166,104, 2, 22,217, 22,221,105,128, 3,166,239,239,107, 128, 1,164,105,129, 3,160, 22,233,247,242,225,242,237,229,238, 233,225,110,128, 5, 83,237,239,238,239,243,240,225,227,101,128, 255, 48,115, 2, 23, 8, 23, 25,105,129, 3,168, 23, 14,227,249, 242,233,236,236,233, 99,128, 4,112,237,225,236,108,128,247,112, 81,131, 0, 81, 23, 42, 23, 51, 23, 63,227,233,242,227,236,101, 128, 36,198,237,239,238,239,243,240,225,227,101,128,255, 49,243, 237,225,236,108,128,247,113, 82,138, 0, 82, 23, 95, 23,119, 23, 166, 23,217, 23,230, 23,240, 23,245, 24, 19, 24, 31, 24, 43, 97, 2, 23,101, 23,112,225,242,237,229,238,233,225,110,128, 5, 76, 227,245,244,101,128, 1, 84, 99, 4, 23,129, 23,136, 23,145, 23, 153,225,242,239,110,128, 1, 88,229,228,233,236,236, 97,128, 1, 86,233,242,227,236,101,128, 36,199,239,237,237,225,225,227,227, 229,238,116,128, 1, 86,100, 2, 23,172, 23,182,226,236,231,242, 225,246,101,128, 2, 16,239,116, 2, 23,189, 23,198,225,227,227, 229,238,116,128, 30, 88,226,229,236,239,119,129, 30, 90, 23,208, 237,225,227,242,239,110,128, 30, 92,229,232,225,242,237,229,238, 233,225,110,128, 5, 80,230,242,225,235,244,245,114,128, 33, 28, 232,111,128, 3,161,233,110, 2, 23,252, 24, 5,231,243,237,225, 236,108,128,246,252,246,229,242,244,229,228,226,242,229,246,101, 128, 2, 18,236,233,238,229,226,229,236,239,119,128, 30, 94,237, 239,238,239,243,240,225,227,101,128,255, 50,243,237,225,236,108, 129,247,114, 24, 53,233,238,246,229,242,244,229,100,129, 2,129, 24, 66,243,245,240,229,242,233,239,114,128, 2,182, 83,139, 0, 83, 24,103, 26, 17, 26, 55, 26,182, 26,221, 26,250, 27, 84, 27, 105, 27,117, 27,135, 27,143, 70, 6, 24,117, 24,209, 24,241, 25, 77, 25,119, 25,221, 48, 9, 24,137, 24,145, 24,153, 24,161, 24, 169, 24,177, 24,185, 24,193, 24,201,177,176,176,176, 48,128, 37, 12,178,176,176,176, 48,128, 37, 20,179,176,176,176, 48,128, 37, 16,180,176,176,176, 48,128, 37, 24,181,176,176,176, 48,128, 37, 60,182,176,176,176, 48,128, 37, 44,183,176,176,176, 48,128, 37, 52,184,176,176,176, 48,128, 37, 28,185,176,176,176, 48,128, 37, 36, 49, 3, 24,217, 24,225, 24,233,176,176,176,176, 48,128, 37, 0,177,176,176,176, 48,128, 37, 2,185,176,176,176, 48,128, 37, 97, 50, 9, 25, 5, 25, 13, 25, 21, 25, 29, 25, 37, 25, 45, 25, 53, 25, 61, 25, 69,176,176,176,176, 48,128, 37, 98,177,176,176, 176, 48,128, 37, 86,178,176,176,176, 48,128, 37, 85,179,176,176, 176, 48,128, 37, 99,180,176,176,176, 48,128, 37, 81,181,176,176, 176, 48,128, 37, 87,182,176,176,176, 48,128, 37, 93,183,176,176, 176, 48,128, 37, 92,184,176,176,176, 48,128, 37, 91, 51, 4, 25, 87, 25, 95, 25,103, 25,111,182,176,176,176, 48,128, 37, 94,183, 176,176,176, 48,128, 37, 95,184,176,176,176, 48,128, 37, 90,185, 176,176,176, 48,128, 37, 84, 52, 10, 25,141, 25,149, 25,157, 25, 165, 25,173, 25,181, 25,189, 25,197, 25,205, 25,213,176,176,176, 176, 48,128, 37,105,177,176,176,176, 48,128, 37,102,178,176,176, 176, 48,128, 37, 96,179,176,176,176, 48,128, 37, 80,180,176,176, 176, 48,128, 37,108,181,176,176,176, 48,128, 37,103,182,176,176, 176, 48,128, 37,104,183,176,176,176, 48,128, 37,100,184,176,176, 176, 48,128, 37,101,185,176,176,176, 48,128, 37, 89, 53, 5, 25, 233, 25,241, 25,249, 26, 1, 26, 9,176,176,176,176, 48,128, 37, 88,177,176,176,176, 48,128, 37, 82,178,176,176,176, 48,128, 37, 83,179,176,176,176, 48,128, 37,107,180,176,176,176, 48,128, 37, 106, 97, 2, 26, 23, 26, 44,227,245,244,101,129, 1, 90, 26, 32, 228,239,244,225,227,227,229,238,116,128, 30,100,237,240,233,231, 242,229,229,107,128, 3,224, 99, 5, 26, 67, 26, 98, 26,107, 26, 147, 26,169,225,242,239,110,130, 1, 96, 26, 78, 26, 90,228,239, 244,225,227,227,229,238,116,128, 30,102,243,237,225,236,108,128, 246,253,229,228,233,236,236, 97,128, 1, 94,232,247, 97,130, 1, 143, 26,117, 26,128,227,249,242,233,236,236,233, 99,128, 4,216, 228,233,229,242,229,243,233,243,227,249,242,233,236,236,233, 99, 128, 4,218,233,242, 99, 2, 26,155, 26,160,236,101,128, 36,200, 245,237,230,236,229,120,128, 1, 92,239,237,237,225,225,227,227, 229,238,116,128, 2, 24,228,239,116, 2, 26,190, 26,199,225,227, 227,229,238,116,128, 30, 96,226,229,236,239,119,129, 30, 98, 26, 209,228,239,244,225,227,227,229,238,116,128, 30,104,101, 2, 26, 227, 26,239,232,225,242,237,229,238,233,225,110,128, 5, 77,246, 229,238,242,239,237,225,110,128, 33,102,104, 5, 27, 6, 27, 34, 27, 48, 27, 59, 27, 72, 97, 2, 27, 12, 27, 23,225,242,237,229, 238,233,225,110,128, 5, 71,227,249,242,233,236,236,233, 99,128, 4, 40,227,232,225,227,249,242,233,236,236,233, 99,128, 4, 41, 229,233,227,239,240,244,233, 99,128, 3,226,232,225,227,249,242, 233,236,236,233, 99,128, 4,186,233,237,225,227,239,240,244,233, 99,128, 3,236,105, 2, 27, 90, 27, 96,231,237, 97,128, 3,163, 248,242,239,237,225,110,128, 33,101,237,239,238,239,243,240,225, 227,101,128,255, 51,239,230,244,243,233,231,238,227,249,242,233, 236,236,233, 99,128, 4, 44,243,237,225,236,108,128,247,115,244, 233,231,237,225,231,242,229,229,107,128, 3,218, 84,141, 0, 84, 27,186, 27,191, 27,197, 28, 7, 28, 32, 28, 96, 28,147, 28,177, 28,189, 28,201, 28,246, 29, 6, 29, 46,225,117,128, 3,164,226, 225,114,128, 1,102, 99, 4, 27,207, 27,214, 27,223, 27,250,225, 242,239,110,128, 1,100,229,228,233,236,236, 97,128, 1, 98,233, 242, 99, 2, 27,231, 27,236,236,101,128, 36,201,245,237,230,236, 229,248,226,229,236,239,119,128, 30,112,239,237,237,225,225,227, 227,229,238,116,128, 1, 98,228,239,116, 2, 28, 15, 28, 24,225, 227,227,229,238,116,128, 30,106,226,229,236,239,119,128, 30,108, 101, 4, 28, 42, 28, 53, 28, 73, 28, 82,227,249,242,233,236,236, 233, 99,128, 4, 34,228,229,243,227,229,238,228,229,242,227,249, 242,233,236,236,233, 99,128, 4,172,238,242,239,237,225,110,128, 33,105,244,243,229,227,249,242,233,236,236,233, 99,128, 4,180, 104, 3, 28,104, 28,110, 28,136,229,244, 97,128, 3,152,111, 2, 28,116, 28,121,239,107,128, 1,172,242,110,129, 0,222, 28,128, 243,237,225,236,108,128,247,254,242,229,229,242,239,237,225,110, 128, 33, 98,105, 2, 28,153, 28,164,236,228,229,243,237,225,236, 108,128,246,254,247,238,225,242,237,229,238,233,225,110,128, 5, 79,236,233,238,229,226,229,236,239,119,128, 30,110,237,239,238, 239,243,240,225,227,101,128,255, 52,111, 2, 28,207, 28,218,225, 242,237,229,238,233,225,110,128, 5, 57,238,101, 3, 28,227, 28, 234, 28,240,230,233,246,101,128, 1,188,243,233,120,128, 1,132, 244,247,111,128, 1,167,242,229,244,242,239,230,236,229,248,232, 239,239,107,128, 1,174,115, 3, 29, 14, 29, 26, 29, 39,229,227, 249,242,233,236,236,233, 99,128, 4, 38,232,229,227,249,242,233, 236,236,233, 99,128, 4, 11,237,225,236,108,128,247,116,119, 2, 29, 52, 29, 64,229,236,246,229,242,239,237,225,110,128, 33,107, 239,242,239,237,225,110,128, 33, 97, 85,142, 0, 85, 29,105, 29, 123, 29,131, 29,198, 30, 69, 30, 87, 30,198, 30,214, 30,226, 31, 21, 31, 30, 31,142, 31,149, 31,219,225,227,245,244,101,129, 0, 218, 29,115,243,237,225,236,108,128,247,250,226,242,229,246,101, 128, 1,108, 99, 3, 29,139, 29,146, 29,188,225,242,239,110,128, 1,211,233,242, 99, 2, 29,154, 29,159,236,101,128, 36,202,245, 237,230,236,229,120,130, 0,219, 29,172, 29,180,226,229,236,239, 119,128, 30,118,243,237,225,236,108,128,247,251,249,242,233,236, 236,233, 99,128, 4, 35,100, 3, 29,206, 29,229, 30, 59,226,108, 2, 29,213, 29,221,225,227,245,244,101,128, 1,112,231,242,225, 246,101,128, 2, 20,233,229,242,229,243,233,115,134, 0,220, 29, 251, 30, 3, 30, 11, 30, 34, 30, 42, 30, 51,225,227,245,244,101, 128, 1,215,226,229,236,239,119,128, 30,114, 99, 2, 30, 17, 30, 24,225,242,239,110,128, 1,217,249,242,233,236,236,233, 99,128, 4,240,231,242,225,246,101,128, 1,219,237,225,227,242,239,110, 128, 1,213,243,237,225,236,108,128,247,252,239,244,226,229,236, 239,119,128, 30,228,231,242,225,246,101,129, 0,217, 30, 79,243, 237,225,236,108,128,247,249,104, 2, 30, 93, 30,171,111, 2, 30, 99, 30,109,239,235,225,226,239,246,101,128, 30,230,242,110,133, 1,175, 30,124, 30,132, 30,143, 30,151, 30,163,225,227,245,244, 101,128, 30,232,228,239,244,226,229,236,239,119,128, 30,240,231, 242,225,246,101,128, 30,234,232,239,239,235,225,226,239,246,101, 128, 30,236,244,233,236,228,101,128, 30,238,245,238,231,225,242, 245,237,236,225,245,116,129, 1,112, 30,187,227,249,242,233,236, 236,233, 99,128, 4,242,233,238,246,229,242,244,229,228,226,242, 229,246,101,128, 2, 22,235,227,249,242,233,236,236,233, 99,128, 4,120,109, 2, 30,232, 31, 10,225,227,242,239,110,130, 1,106, 30,244, 30,255,227,249,242,233,236,236,233, 99,128, 4,238,228, 233,229,242,229,243,233,115,128, 30,122,239,238,239,243,240,225, 227,101,128,255, 53,239,231,239,238,229,107,128, 1,114,240,243, 233,236,239,110,133, 3,165, 31, 49, 31, 53, 31, 90, 31,121, 31, 134, 49,128, 3,210, 97, 2, 31, 59, 31, 81,227,245,244,229,232, 239,239,235,243,249,237,226,239,236,231,242,229,229,107,128, 3, 211,230,242,233,227,225,110,128, 1,177,228,233,229,242,229,243, 233,115,129, 3,171, 31,103,232,239,239,235,243,249,237,226,239, 236,231,242,229,229,107,128, 3,212,232,239,239,235,243,249,237, 226,239,108,128, 3,210,244,239,238,239,115,128, 3,142,242,233, 238,103,128, 1,110,115, 3, 31,157, 31,172, 31,179,232,239,242, 244,227,249,242,233,236,236,233, 99,128, 4, 14,237,225,236,108, 128,247,117,244,242,225,233,231,232,116, 2, 31,191, 31,202,227, 249,242,233,236,236,233, 99,128, 4,174,243,244,242,239,235,229, 227,249,242,233,236,236,233, 99,128, 4,176,244,233,236,228,101, 130, 1,104, 31,231, 31,239,225,227,245,244,101,128, 30,120,226, 229,236,239,119,128, 30,116, 86,136, 0, 86, 32, 11, 32, 20, 32, 31, 32, 60, 32, 67, 32, 79, 32, 91, 32, 99,227,233,242,227,236, 101,128, 36,203,228,239,244,226,229,236,239,119,128, 30,126,101, 2, 32, 37, 32, 48,227,249,242,233,236,236,233, 99,128, 4, 18, 247,225,242,237,229,238,233,225,110,128, 5, 78,232,239,239,107, 128, 1,178,237,239,238,239,243,240,225,227,101,128,255, 54,239, 225,242,237,229,238,233,225,110,128, 5, 72,243,237,225,236,108, 128,247,118,244,233,236,228,101,128, 30,124, 87,134, 0, 87, 32, 123, 32,131, 32,154, 32,194, 32,202, 32,214,225,227,245,244,101, 128, 30,130,227,233,242, 99, 2, 32,140, 32,145,236,101,128, 36, 204,245,237,230,236,229,120,128, 1,116,100, 2, 32,160, 32,170, 233,229,242,229,243,233,115,128, 30,132,239,116, 2, 32,177, 32, 186,225,227,227,229,238,116,128, 30,134,226,229,236,239,119,128, 30,136,231,242,225,246,101,128, 30,128,237,239,238,239,243,240, 225,227,101,128,255, 55,243,237,225,236,108,128,247,119, 88,134, 0, 88, 32,238, 32,247, 33, 18, 33, 31, 33, 35, 33, 47,227,233, 242,227,236,101,128, 36,205,100, 2, 32,253, 33, 7,233,229,242, 229,243,233,115,128, 30,140,239,244,225,227,227,229,238,116,128, 30,138,229,232,225,242,237,229,238,233,225,110,128, 5, 61,105, 128, 3,158,237,239,238,239,243,240,225,227,101,128,255, 56,243, 237,225,236,108,128,247,120, 89,139, 0, 89, 33, 81, 33,116, 33, 139, 33,189, 33,228, 33,236, 33,253, 34, 40, 34, 52, 34, 60, 34, 68, 97, 2, 33, 87, 33,104,227,245,244,101,129, 0,221, 33, 96, 243,237,225,236,108,128,247,253,244,227,249,242,233,236,236,233, 99,128, 4, 98,227,233,242, 99, 2, 33,125, 33,130,236,101,128, 36,206,245,237,230,236,229,120,128, 1,118,100, 2, 33,145, 33, 165,233,229,242,229,243,233,115,129, 1,120, 33,157,243,237,225, 236,108,128,247,255,239,116, 2, 33,172, 33,181,225,227,227,229, 238,116,128, 30,142,226,229,236,239,119,128, 30,244,229,114, 2, 33,196, 33,208,233,227,249,242,233,236,236,233, 99,128, 4, 43, 245,228,233,229,242,229,243,233,243,227,249,242,233,236,236,233, 99,128, 4,248,231,242,225,246,101,128, 30,242,232,239,239,107, 129, 1,179, 33,245,225,226,239,246,101,128, 30,246,105, 3, 34, 5, 34, 16, 34, 27,225,242,237,229,238,233,225,110,128, 5, 69, 227,249,242,233,236,236,233, 99,128, 4, 7,247,238,225,242,237, 229,238,233,225,110,128, 5, 82,237,239,238,239,243,240,225,227, 101,128,255, 57,243,237,225,236,108,128,247,121,244,233,236,228, 101,128, 30,248,245,115, 2, 34, 75, 34,113,226,233,103, 2, 34, 83, 34, 94,227,249,242,233,236,236,233, 99,128, 4,106,233,239, 244,233,230,233,229,228,227,249,242,233,236,236,233, 99,128, 4, 108,236,233,244,244,236,101, 2, 34,124, 34,135,227,249,242,233, 236,236,233, 99,128, 4,102,233,239,244,233,230,233,229,228,227, 249,242,233,236,236,233, 99,128, 4,104, 90,136, 0, 90, 34,174, 34,198, 34,243, 35, 14, 35, 81, 35,173, 35,185, 35,197, 97, 2, 34,180, 34,191,225,242,237,229,238,233,225,110,128, 5, 54,227, 245,244,101,128, 1,121, 99, 2, 34,204, 34,221,225,242,239,110, 129, 1,125, 34,213,243,237,225,236,108,128,246,255,233,242, 99, 2, 34,229, 34,234,236,101,128, 36,207,245,237,230,236,229,120, 128, 30,144,228,239,116,130, 1,123, 34,253, 35, 6,225,227,227, 229,238,116,128, 1,123,226,229,236,239,119,128, 30,146,101, 3, 35, 22, 35, 33, 35, 76,227,249,242,233,236,236,233, 99,128, 4, 23,100, 2, 35, 39, 35, 58,229,243,227,229,238,228,229,242,227, 249,242,233,236,236,233, 99,128, 4,152,233,229,242,229,243,233, 243,227,249,242,233,236,236,233, 99,128, 4,222,244, 97,128, 3, 150,232,101, 4, 35, 92, 35,103, 35,119, 35,130,225,242,237,229, 238,233,225,110,128, 5, 58,226,242,229,246,229,227,249,242,233, 236,236,233, 99,128, 4,193,227,249,242,233,236,236,233, 99,128, 4, 22,100, 2, 35,136, 35,155,229,243,227,229,238,228,229,242, 227,249,242,233,236,236,233, 99,128, 4,150,233,229,242,229,243, 233,243,227,249,242,233,236,236,233, 99,128, 4,220,236,233,238, 229,226,229,236,239,119,128, 30,148,237,239,238,239,243,240,225, 227,101,128,255, 58,115, 2, 35,203, 35,210,237,225,236,108,128, 247,122,244,242,239,235,101,128, 1,181, 97,158, 0, 97, 36, 26, 38,154, 39, 4, 39, 68, 39,132, 39,196, 40, 4, 40, 68, 40,126, 40,190, 41, 70, 41,217, 42,137, 42,237, 43, 17, 49,192, 49,229, 50, 0, 50,225, 51, 7, 52, 96, 52,168, 53,123, 53,132, 54, 5, 56, 13, 57, 3, 57, 50, 57,201, 57,215, 49,138, 39, 1, 36, 50, 36,114, 36,154, 36,218, 37, 26, 37, 90, 37,154, 37,218, 38, 26, 38, 90, 48,138, 39, 33, 36, 74, 36, 78, 36, 82, 36, 86, 36, 90, 36, 94, 36, 98, 36,102, 36,106, 36,110, 48,128, 39, 94, 49,128, 39, 97, 50,128, 39, 98, 51,128, 39, 99, 52,128, 39,100, 53,128, 39, 16, 54,128, 39,101, 55,128, 39,102, 56,128, 39,103, 57,128, 38, 96, 49,134, 38, 27, 36,130, 36,134, 36,138, 36,142, 36,146, 36,150, 48,128, 38,101, 49,128, 38,102, 50,128, 38, 99, 55,128, 39, 9, 56,128, 39, 8, 57,128, 39, 7, 50,138, 38, 30, 36,178, 36,182, 36,186, 36,190, 36,194, 36,198, 36,202, 36,206, 36,210, 36,214, 48,128, 36, 96, 49,128, 36, 97, 50,128, 36, 98, 51,128, 36, 99, 52,128, 36,100, 53,128, 36,101, 54,128, 36,102, 55,128, 36,103, 56,128, 36,104, 57,128, 36,105, 51,138, 39, 12, 36,242, 36,246, 36,250, 36,254, 37, 2, 37, 6, 37, 10, 37, 14, 37, 18, 37, 22, 48,128, 39,118, 49,128, 39,119, 50,128, 39,120, 51,128, 39,121, 52,128, 39,122, 53,128, 39,123, 54,128, 39,124, 55,128, 39,125, 56,128, 39,126, 57,128, 39,127, 52,138, 39, 13, 37, 50, 37, 54, 37, 58, 37, 62, 37, 66, 37, 70, 37, 74, 37, 78, 37, 82, 37, 86, 48,128, 39,128, 49,128, 39,129, 50,128, 39,130, 51,128, 39,131, 52,128, 39,132, 53,128, 39,133, 54,128, 39,134, 55,128, 39,135, 56,128, 39,136, 57,128, 39,137, 53,138, 39, 14, 37,114, 37,118, 37,122, 37,126, 37,130, 37,134, 37,138, 37,142, 37,146, 37,150, 48,128, 39,138, 49,128, 39,139, 50,128, 39,140, 51,128, 39,141, 52,128, 39,142, 53,128, 39,143, 54,128, 39,144, 55,128, 39,145, 56,128, 39,146, 57,128, 39,147, 54,138, 39, 15, 37,178, 37,182, 37,186, 37,190, 37,194, 37,198, 37,202, 37,206, 37,210, 37,214, 48,128, 39,148, 49,128, 33,146, 50,128, 39,163, 51,128, 33,148, 52,128, 33,149, 53,128, 39,153, 54,128, 39,155, 55,128, 39,156, 56,128, 39,157, 57,128, 39,158, 55,138, 39, 17, 37,242, 37,246, 37,250, 37,254, 38, 2, 38, 6, 38, 10, 38, 14, 38, 18, 38, 22, 48,128, 39,159, 49,128, 39,160, 50,128, 39,161, 51,128, 39,162, 52,128, 39,164, 53,128, 39,165, 54,128, 39,166, 55,128, 39,167, 56,128, 39,168, 57,128, 39,169, 56,138, 39, 18, 38, 50, 38, 54, 38, 58, 38, 62, 38, 66, 38, 70, 38, 74, 38, 78, 38, 82, 38, 86, 48,128, 39,171, 49,128, 39,173, 50,128, 39,175, 51,128, 39,178, 52,128, 39,179, 53,128, 39,181, 54,128, 39,184, 55,128, 39,186, 56,128, 39,187, 57,128, 39,188, 57,138, 39, 19, 38,114, 38,118, 38,122, 38,126, 38,130, 38,134, 38,138, 38,142, 38,146, 38,150, 48,128, 39,189, 49,128, 39,190, 50,128, 39,154, 51,128, 39,170, 52,128, 39,182, 53,128, 39,185, 54,128, 39,152, 55,128, 39,180, 56,128, 39,183, 57,128, 39,172, 50,138, 39, 2, 38,178, 38,224, 38,228, 38,232, 38,236, 38,240, 38,244, 38,248, 38,252, 39, 0, 48,135, 39, 20, 38,196, 38,200, 38,204, 38,208, 38,212, 38,216, 38,220, 48,128, 39,174, 49,128, 39,177, 50,128, 39, 3, 51,128, 39, 80, 52,128, 39, 82, 53,128, 39,110, 54,128, 39,112, 49,128, 39, 21, 50,128, 39, 22, 51,128, 39, 23, 52,128, 39, 24, 53,128, 39, 25, 54,128, 39, 26, 55,128, 39, 27, 56,128, 39, 28, 57,128, 39, 34, 51,138, 39, 4, 39, 28, 39, 32, 39, 36, 39, 40, 39, 44, 39, 48, 39, 52, 39, 56, 39, 60, 39, 64, 48,128, 39, 35, 49,128, 39, 36, 50,128, 39, 37, 51,128, 39, 38, 52,128, 39, 39, 53,128, 38, 5, 54,128, 39, 41, 55,128, 39, 42, 56,128, 39, 43, 57,128, 39, 44, 52,138, 38, 14, 39, 92, 39, 96, 39,100, 39,104, 39,108, 39,112, 39,116, 39,120, 39,124, 39,128, 48,128, 39, 45, 49,128, 39, 46, 50,128, 39, 47, 51,128, 39, 48, 52,128, 39, 49, 53,128, 39, 50, 54,128, 39, 51, 55,128, 39, 52, 56,128, 39, 53, 57,128, 39, 54, 53,138, 39, 6, 39,156, 39,160, 39,164, 39,168, 39,172, 39,176, 39,180, 39,184, 39,188, 39,192, 48,128, 39, 55, 49,128, 39, 56, 50,128, 39, 57, 51,128, 39, 58, 52,128, 39, 59, 53,128, 39, 60, 54,128, 39, 61, 55,128, 39, 62, 56,128, 39, 63, 57,128, 39, 64, 54,138, 39, 29, 39,220, 39,224, 39,228, 39,232, 39,236, 39,240, 39,244, 39,248, 39,252, 40, 0, 48,128, 39, 65, 49,128, 39, 66, 50,128, 39, 67, 51,128, 39, 68, 52,128, 39, 69, 53,128, 39, 70, 54,128, 39, 71, 55,128, 39, 72, 56,128, 39, 73, 57,128, 39, 74, 55,138, 39, 30, 40, 28, 40, 32, 40, 36, 40, 40, 40, 44, 40, 48, 40, 52, 40, 56, 40, 60, 40, 64, 48,128, 39, 75, 49,128, 37,207, 50,128, 39, 77, 51,128, 37,160, 52,128, 39, 79, 53,128, 39, 81, 54,128, 37,178, 55,128, 37,188, 56,128, 37,198, 57,128, 39, 86, 56,137, 39, 31, 40, 90, 40, 94, 40, 98, 40,102, 40,106, 40,110, 40,114, 40,118, 40,122, 49,128, 37,215, 50,128, 39, 88, 51,128, 39, 89, 52,128, 39, 90, 53,128, 39,111, 54,128, 39,113, 55,128, 39,114, 56,128, 39,115, 57,128, 39,104, 57,138, 39, 32, 40,150, 40,154, 40,158, 40,162, 40,166, 40,170, 40,174, 40,178, 40,182, 40,186, 48,128, 39,105, 49,128, 39,108, 50,128, 39,109, 51,128, 39,106, 52,128, 39,107, 53,128, 39,116, 54,128, 39,117, 55,128, 39, 91, 56,128, 39, 92, 57,128, 39, 93, 97, 7, 40,206, 40,216, 40,223, 40,230, 40,255, 41, 15, 41, 26,226,229, 238,231,225,236,105,128, 9,134,227,245,244,101,128, 0,225,228, 229,246, 97,128, 9, 6,231,117, 2, 40,237, 40,246,234,225,242, 225,244,105,128, 10,134,242,237,245,235,232,105,128, 10, 6,237, 225,244,242,225,231,245,242,237,245,235,232,105,128, 10, 62,242, 245,243,241,245,225,242,101,128, 51, 3,246,239,247,229,236,243, 233,231,110, 3, 41, 42, 41, 52, 41, 59,226,229,238,231,225,236, 105,128, 9,190,228,229,246, 97,128, 9, 62,231,245,234,225,242, 225,244,105,128, 10,190, 98, 4, 41, 80, 41,121, 41,130, 41,140, 226,242,229,246,233,225,244,233,239,110, 2, 41, 95, 41,110,237, 225,242,235,225,242,237,229,238,233,225,110,128, 5, 95,243,233, 231,238,228,229,246, 97,128, 9,112,229,238,231,225,236,105,128, 9,133,239,240,239,237,239,230,111,128, 49, 26,242,229,246,101, 134, 1, 3, 41,159, 41,167, 41,178, 41,189, 41,197, 41,209,225, 227,245,244,101,128, 30,175,227,249,242,233,236,236,233, 99,128, 4,209,228,239,244,226,229,236,239,119,128, 30,183,231,242,225, 246,101,128, 30,177,232,239,239,235,225,226,239,246,101,128, 30, 179,244,233,236,228,101,128, 30,181, 99, 4, 41,227, 41,234, 42, 57, 42,127,225,242,239,110,128, 1,206,233,242, 99, 2, 41,242, 41,247,236,101,128, 36,208,245,237,230,236,229,120,133, 0,226, 42, 10, 42, 18, 42, 29, 42, 37, 42, 49,225,227,245,244,101,128, 30,165,228,239,244,226,229,236,239,119,128, 30,173,231,242,225, 246,101,128, 30,167,232,239,239,235,225,226,239,246,101,128, 30, 169,244,233,236,228,101,128, 30,171,245,244,101,133, 0,180, 42, 73, 42, 84, 42,101, 42,108, 42,117,226,229,236,239,247,227,237, 98,128, 3, 23, 99, 2, 42, 90, 42, 95,237, 98,128, 3, 1,239, 237, 98,128, 3, 1,228,229,246, 97,128, 9, 84,236,239,247,237, 239,100,128, 2,207,244,239,238,229,227,237, 98,128, 3, 65,249, 242,233,236,236,233, 99,128, 4, 48,100, 5, 42,149, 42,159, 42, 173, 42,179, 42,213,226,236,231,242,225,246,101,128, 2, 1,228, 225,235,231,245,242,237,245,235,232,105,128, 10,113,229,246, 97, 128, 9, 5,233,229,242,229,243,233,115,130, 0,228, 42,193, 42, 204,227,249,242,233,236,236,233, 99,128, 4,211,237,225,227,242, 239,110,128, 1,223,239,116, 2, 42,220, 42,228,226,229,236,239, 119,128, 30,161,237,225,227,242,239,110,128, 1,225,101,131, 0, 230, 42,247, 42,255, 43, 8,225,227,245,244,101,128, 1,253,235, 239,242,229,225,110,128, 49, 80,237,225,227,242,239,110,128, 1, 227,230,233,105, 6, 43, 33, 43, 53, 45,246, 45,252, 46, 11, 49, 111, 48, 2, 43, 39, 43, 46,176,178,176, 56,128, 32, 21,184,185, 180, 49,128, 32,164,177, 48, 3, 43, 62, 45, 86, 45,221, 48, 9, 43, 82, 43,102, 43,164, 43,226, 44, 32, 44, 94, 44,156, 44,218, 45, 24, 49, 3, 43, 90, 43, 94, 43, 98, 55,128, 4, 16, 56,128, 4, 17, 57,128, 4, 18, 50, 10, 43,124, 43,128, 43,132, 43,136, 43,140, 43,144, 43,148, 43,152, 43,156, 43,160, 48,128, 4, 19, 49,128, 4, 20, 50,128, 4, 21, 51,128, 4, 1, 52,128, 4, 22, 53,128, 4, 23, 54,128, 4, 24, 55,128, 4, 25, 56,128, 4, 26, 57,128, 4, 27, 51, 10, 43,186, 43,190, 43,194, 43,198, 43,202, 43,206, 43,210, 43,214, 43,218, 43,222, 48,128, 4, 28, 49,128, 4, 29, 50,128, 4, 30, 51,128, 4, 31, 52,128, 4, 32, 53,128, 4, 33, 54,128, 4, 34, 55,128, 4, 35, 56,128, 4, 36, 57,128, 4, 37, 52, 10, 43,248, 43,252, 44, 0, 44, 4, 44, 8, 44, 12, 44, 16, 44, 20, 44, 24, 44, 28, 48,128, 4, 38, 49,128, 4, 39, 50,128, 4, 40, 51,128, 4, 41, 52,128, 4, 42, 53,128, 4, 43, 54,128, 4, 44, 55,128, 4, 45, 56,128, 4, 46, 57,128, 4, 47, 53, 10, 44, 54, 44, 58, 44, 62, 44, 66, 44, 70, 44, 74, 44, 78, 44, 82, 44, 86, 44, 90, 48,128, 4,144, 49,128, 4, 2, 50,128, 4, 3, 51,128, 4, 4, 52,128, 4, 5, 53,128, 4, 6, 54,128, 4, 7, 55,128, 4, 8, 56,128, 4, 9, 57,128, 4, 10, 54, 10, 44,116, 44,120, 44,124, 44,128, 44,132, 44,136, 44,140, 44,144, 44,148, 44,152, 48,128, 4, 11, 49,128, 4, 12, 50,128, 4, 14, 51,128,246,196, 52,128,246,197, 53,128, 4, 48, 54,128, 4, 49, 55,128, 4, 50, 56,128, 4, 51, 57,128, 4, 52, 55, 10, 44,178, 44,182, 44,186, 44,190, 44,194, 44,198, 44,202, 44,206, 44,210, 44,214, 48,128, 4, 53, 49,128, 4, 81, 50,128, 4, 54, 51,128, 4, 55, 52,128, 4, 56, 53,128, 4, 57, 54,128, 4, 58, 55,128, 4, 59, 56,128, 4, 60, 57,128, 4, 61, 56, 10, 44,240, 44,244, 44,248, 44,252, 45, 0, 45, 4, 45, 8, 45, 12, 45, 16, 45, 20, 48,128, 4, 62, 49,128, 4, 63, 50,128, 4, 64, 51,128, 4, 65, 52,128, 4, 66, 53,128, 4, 67, 54,128, 4, 68, 55,128, 4, 69, 56,128, 4, 70, 57,128, 4, 71, 57, 10, 45, 46, 45, 50, 45, 54, 45, 58, 45, 62, 45, 66, 45, 70, 45, 74, 45, 78, 45, 82, 48,128, 4, 72, 49,128, 4, 73, 50,128, 4, 74, 51,128, 4, 75, 52,128, 4, 76, 53,128, 4, 77, 54,128, 4, 78, 55,128, 4, 79, 56,128, 4,145, 57,128, 4, 82, 49, 4, 45, 96, 45,158, 45,163, 45,189, 48, 10, 45,118, 45,122, 45,126, 45,130, 45,134, 45,138, 45,142, 45,146, 45,150, 45,154, 48,128, 4, 83, 49,128, 4, 84, 50,128, 4, 85, 51,128, 4, 86, 52,128, 4, 87, 53,128, 4, 88, 54,128, 4, 89, 55,128, 4, 90, 56,128, 4, 91, 57,128, 4, 92,177, 48, 128, 4, 94, 52, 4, 45,173, 45,177, 45,181, 45,185, 53,128, 4, 15, 54,128, 4, 98, 55,128, 4,114, 56,128, 4,116, 57, 5, 45, 201, 45,205, 45,209, 45,213, 45,217, 50,128,246,198, 51,128, 4, 95, 52,128, 4, 99, 53,128, 4,115, 54,128, 4,117, 56, 2, 45, 227, 45,241, 51, 2, 45,233, 45,237, 49,128,246,199, 50,128,246, 200,180, 54,128, 4,217,178,185, 57,128, 32, 14,179, 48, 2, 46, 3, 46, 7, 48,128, 32, 15, 49,128, 32, 13,181, 55, 7, 46, 28, 46, 98, 47,163, 47,240, 48,197, 49, 34, 49,105, 51, 2, 46, 34, 46, 48, 56, 2, 46, 40, 46, 44, 49,128, 6,106, 56,128, 6, 12, 57, 8, 46, 66, 46, 70, 46, 74, 46, 78, 46, 82, 46, 86, 46, 90, 46, 94, 50,128, 6, 96, 51,128, 6, 97, 52,128, 6, 98, 53,128, 6, 99, 54,128, 6,100, 55,128, 6,101, 56,128, 6,102, 57,128, 6,103, 52, 7, 46,114, 46,146, 46,208, 47, 14, 47, 46, 47,102, 47,158, 48, 5, 46,126, 46,130, 46,134, 46,138, 46,142, 48,128, 6,104, 49,128, 6,105, 51,128, 6, 27, 55,128, 6, 31, 57,128, 6, 33, 49, 10, 46,168, 46,172, 46,176, 46,180, 46,184, 46,188, 46,192, 46,196, 46,200, 46,204, 48,128, 6, 34, 49,128, 6, 35, 50,128, 6, 36, 51,128, 6, 37, 52,128, 6, 38, 53,128, 6, 39, 54,128, 6, 40, 55,128, 6, 41, 56,128, 6, 42, 57,128, 6, 43, 50, 10, 46,230, 46,234, 46,238, 46,242, 46,246, 46,250, 46,254, 47, 2, 47, 6, 47, 10, 48,128, 6, 44, 49,128, 6, 45, 50,128, 6, 46, 51,128, 6, 47, 52,128, 6, 48, 53,128, 6, 49, 54,128, 6, 50, 55,128, 6, 51, 56,128, 6, 52, 57,128, 6, 53, 51, 5, 47, 26, 47, 30, 47, 34, 47, 38, 47, 42, 48,128, 6, 54, 49,128, 6, 55, 50,128, 6, 56, 51,128, 6, 57, 52,128, 6, 58, 52, 9, 47, 66, 47, 70, 47, 74, 47, 78, 47, 82, 47, 86, 47, 90, 47, 94, 47, 98, 48,128, 6, 64, 49,128, 6, 65, 50,128, 6, 66, 51,128, 6, 67, 52,128, 6, 68, 53,128, 6, 69, 54,128, 6, 70, 56,128, 6, 72, 57,128, 6, 73, 53, 9, 47,122, 47,126, 47,130, 47,134, 47,138, 47,142, 47,146, 47,150, 47,154, 48,128, 6, 74, 49,128, 6, 75, 50,128, 6, 76, 51,128, 6, 77, 52,128, 6, 78, 53,128, 6, 79, 54,128, 6, 80, 55,128, 6, 81, 56,128, 6, 82,183, 48, 128, 6, 71, 53, 3, 47,171, 47,203, 47,235, 48, 5, 47,183, 47, 187, 47,191, 47,195, 47,199, 53,128, 6,164, 54,128, 6,126, 55, 128, 6,134, 56,128, 6,152, 57,128, 6,175, 49, 5, 47,215, 47, 219, 47,223, 47,227, 47,231, 49,128, 6,121, 50,128, 6,136, 51, 128, 6,145, 52,128, 6,186, 57,128, 6,210,179, 52,128, 6,213, 54, 7, 48, 0, 48, 5, 48, 10, 48, 15, 48, 53, 48,115, 48,177, 179, 54,128, 32,170,180, 53,128, 5,190,181, 56,128, 5,195, 54, 6, 48, 29, 48, 33, 48, 37, 48, 41, 48, 45, 48, 49, 52,128, 5, 208, 53,128, 5,209, 54,128, 5,210, 55,128, 5,211, 56,128, 5, 212, 57,128, 5,213, 55, 10, 48, 75, 48, 79, 48, 83, 48, 87, 48, 91, 48, 95, 48, 99, 48,103, 48,107, 48,111, 48,128, 5,214, 49, 128, 5,215, 50,128, 5,216, 51,128, 5,217, 52,128, 5,218, 53, 128, 5,219, 54,128, 5,220, 55,128, 5,221, 56,128, 5,222, 57, 128, 5,223, 56, 10, 48,137, 48,141, 48,145, 48,149, 48,153, 48, 157, 48,161, 48,165, 48,169, 48,173, 48,128, 5,224, 49,128, 5, 225, 50,128, 5,226, 51,128, 5,227, 52,128, 5,228, 53,128, 5, 229, 54,128, 5,230, 55,128, 5,231, 56,128, 5,232, 57,128, 5, 233, 57, 3, 48,185, 48,189, 48,193, 48,128, 5,234, 52,128,251, 42, 53,128,251, 43, 55, 4, 48,207, 48,221, 48,241, 48,246, 48, 2, 48,213, 48,217, 48,128,251, 75, 53,128,251, 31, 49, 3, 48, 229, 48,233, 48,237, 54,128, 5,240, 55,128, 5,241, 56,128, 5, 242,178, 51,128,251, 53, 57, 7, 49, 6, 49, 10, 49, 14, 49, 18, 49, 22, 49, 26, 49, 30, 51,128, 5,180, 52,128, 5,181, 53,128, 5,182, 54,128, 5,187, 55,128, 5,184, 56,128, 5,183, 57,128, 5,176, 56, 3, 49, 42, 49, 86, 49, 91, 48, 7, 49, 58, 49, 62, 49, 66, 49, 70, 49, 74, 49, 78, 49, 82, 48,128, 5,178, 49,128, 5,177, 50,128, 5,179, 51,128, 5,194, 52,128, 5,193, 54,128, 5,185, 55,128, 5,188,179, 57,128, 5,189, 52, 2, 49, 97, 49, 101, 49,128, 5,191, 50,128, 5,192,185,178, 57,128, 2,188, 54, 3, 49,119, 49,178, 49,185, 49, 4, 49,129, 49,145, 49,151, 49, 172, 50, 2, 49,135, 49,140,180, 56,128, 33, 5,184, 57,128, 33, 19,179,181, 50,128, 33, 22,181, 55, 3, 49,160, 49,164, 49,168, 51,128, 32, 44, 52,128, 32, 45, 53,128, 32, 46,182,182, 52,128, 32, 12,179,177,182, 55,128, 6,109,180,185,179, 55,128, 2,189, 103, 2, 49,198, 49,205,242,225,246,101,128, 0,224,117, 2, 49, 211, 49,220,234,225,242,225,244,105,128, 10,133,242,237,245,235, 232,105,128, 10, 5,104, 2, 49,235, 49,245,233,242,225,231,225, 238, 97,128, 48, 66,239,239,235,225,226,239,246,101,128, 30,163, 105, 7, 50, 16, 50, 41, 50, 48, 50, 60, 50, 85, 50,101, 50,181, 98, 2, 50, 22, 50, 31,229,238,231,225,236,105,128, 9,144,239, 240,239,237,239,230,111,128, 49, 30,228,229,246, 97,128, 9, 16, 229,227,249,242,233,236,236,233, 99,128, 4,213,231,117, 2, 50, 67, 50, 76,234,225,242,225,244,105,128, 10,144,242,237,245,235, 232,105,128, 10, 16,237,225,244,242,225,231,245,242,237,245,235, 232,105,128, 10, 72,110, 5, 50,113, 50,122, 50,136, 50,152, 50, 167,225,242,225,226,233, 99,128, 6, 57,230,233,238,225,236,225, 242,225,226,233, 99,128,254,202,233,238,233,244,233,225,236,225, 242,225,226,233, 99,128,254,203,237,229,228,233,225,236,225,242, 225,226,233, 99,128,254,204,246,229,242,244,229,228,226,242,229, 246,101,128, 2, 3,246,239,247,229,236,243,233,231,110, 3, 50, 197, 50,207, 50,214,226,229,238,231,225,236,105,128, 9,200,228, 229,246, 97,128, 9, 72,231,245,234,225,242,225,244,105,128, 10, 200,107, 2, 50,231, 50,255,225,244,225,235,225,238, 97,129, 48, 162, 50,243,232,225,236,230,247,233,228,244,104,128,255,113,239, 242,229,225,110,128, 49, 79,108, 3, 51, 15, 52, 71, 52, 80,101, 2, 51, 21, 52, 66,102,136, 5,208, 51, 41, 51, 50, 51, 65, 51, 79, 51,168, 51,182, 52, 37, 52, 51,225,242,225,226,233, 99,128, 6, 39,228,225,231,229,243,232,232,229,226,242,229,119,128,251, 48,230,233,238,225,236,225,242,225,226,233, 99,128,254,142,104, 2, 51, 85, 51,160,225,237,250, 97, 2, 51, 94, 51,127,225,226, 239,246,101, 2, 51,104, 51,113,225,242,225,226,233, 99,128, 6, 35,230,233,238,225,236,225,242,225,226,233, 99,128,254,132,226, 229,236,239,119, 2, 51,137, 51,146,225,242,225,226,233, 99,128, 6, 37,230,233,238,225,236,225,242,225,226,233, 99,128,254,136, 229,226,242,229,119,128, 5,208,236,225,237,229,228,232,229,226, 242,229,119,128,251, 79,237, 97, 2, 51,189, 51,225,228,228,225, 225,226,239,246,101, 2, 51,202, 51,211,225,242,225,226,233, 99, 128, 6, 34,230,233,238,225,236,225,242,225,226,233, 99,128,254, 130,235,243,245,242, 97, 4, 51,239, 51,248, 52, 6, 52, 22,225, 242,225,226,233, 99,128, 6, 73,230,233,238,225,236,225,242,225, 226,233, 99,128,254,240,233,238,233,244,233,225,236,225,242,225, 226,233, 99,128,254,243,237,229,228,233,225,236,225,242,225,226, 233, 99,128,254,244,240,225,244,225,232,232,229,226,242,229,119, 128,251, 46,241,225,237,225,244,243,232,229,226,242,229,119,128, 251, 47,240,104,128, 33, 53,236,229,241,245,225,108,128, 34, 76, 240,232, 97,129, 3,177, 52, 88,244,239,238,239,115,128, 3,172, 109, 4, 52,106, 52,114, 52,125, 52,159,225,227,242,239,110,128, 1, 1,239,238,239,243,240,225,227,101,128,255, 65,240,229,242, 243,225,238,100,130, 0, 38, 52,139, 52,151,237,239,238,239,243, 240,225,227,101,128,255, 6,243,237,225,236,108,128,247, 38,243, 241,245,225,242,101,128, 51,194,110, 4, 52,178, 52,189, 53, 55, 53, 65,226,239,240,239,237,239,230,111,128, 49, 34,103, 4, 52, 199, 52,210, 52,224, 53, 47,226,239,240,239,237,239,230,111,128, 49, 36,235,232,225,238,235,232,245,244,232,225,105,128, 14, 90, 236,101,131, 34, 32, 52,235, 53, 32, 53, 39,226,242,225,227,235, 229,116, 2, 52,247, 53, 11,236,229,230,116,129, 48, 8, 53, 0, 246,229,242,244,233,227,225,108,128,254, 63,242,233,231,232,116, 129, 48, 9, 53, 21,246,229,242,244,233,227,225,108,128,254, 64, 236,229,230,116,128, 35, 41,242,233,231,232,116,128, 35, 42,243, 244,242,239,109,128, 33, 43,239,244,229,236,229,233, 97,128, 3, 135,117, 2, 53, 71, 53, 83,228,225,244,244,225,228,229,246, 97, 128, 9, 82,243,246,225,242, 97, 3, 53, 95, 53,105, 53,112,226, 229,238,231,225,236,105,128, 9,130,228,229,246, 97,128, 9, 2, 231,245,234,225,242,225,244,105,128, 10,130,239,231,239,238,229, 107,128, 1, 5,112, 3, 53,140, 53,164, 53,194, 97, 2, 53,146, 53,158,225,244,239,243,241,245,225,242,101,128, 51, 0,242,229, 110,128, 36,156,239,243,244,242,239,240,232,101, 2, 53,177, 53, 188,225,242,237,229,238,233,225,110,128, 5, 90,237,239,100,128, 2,188,112, 2, 53,200, 53,205,236,101,128,248,255,242,111, 2, 53,212, 53,220,225,227,232,229,115,128, 34, 80,120, 2, 53,226, 53,246,229,241,245,225,108,129, 34, 72, 53,236,239,242,233,237, 225,231,101,128, 34, 82,233,237,225,244,229,236,249,229,241,245, 225,108,128, 34, 69,114, 4, 54, 15, 54, 42, 54, 46, 54, 91,225, 229, 97, 2, 54, 23, 54, 33,229,235,239,242,229,225,110,128, 49, 142,235,239,242,229,225,110,128, 49,141, 99,128, 35, 18,105, 2, 54, 52, 54, 66,231,232,244,232,225,236,230,242,233,238,103,128, 30,154,238,103,130, 0,229, 54, 75, 54, 83,225,227,245,244,101, 128, 1,251,226,229,236,239,119,128, 30, 1,242,239,119, 8, 54, 111, 54,118, 54,247, 55, 57, 55,107, 55,162, 55,185, 56, 4,226, 239,244,104,128, 33,148,100, 3, 54,126, 54,165, 54,212,225,243, 104, 4, 54,138, 54,145, 54,152, 54,160,228,239,247,110,128, 33, 227,236,229,230,116,128, 33,224,242,233,231,232,116,128, 33,226, 245,112,128, 33,225,226,108, 5, 54,178, 54,185, 54,192, 54,199, 54,207,226,239,244,104,128, 33,212,228,239,247,110,128, 33,211, 236,229,230,116,128, 33,208,242,233,231,232,116,128, 33,210,245, 112,128, 33,209,239,247,110,131, 33,147, 54,224, 54,231, 54,239, 236,229,230,116,128, 33,153,242,233,231,232,116,128, 33,152,247, 232,233,244,101,128, 33,233,104, 2, 54,253, 55, 48,229,225,100, 4, 55, 9, 55, 19, 55, 29, 55, 40,228,239,247,238,237,239,100, 128, 2,197,236,229,230,244,237,239,100,128, 2,194,242,233,231, 232,244,237,239,100,128, 2,195,245,240,237,239,100,128, 2,196, 239,242,233,250,229,120,128,248,231,236,229,230,116,131, 33,144, 55, 70, 55, 87, 55, 99,228,226,108,129, 33,208, 55, 78,243,244, 242,239,235,101,128, 33,205,239,246,229,242,242,233,231,232,116, 128, 33,198,247,232,233,244,101,128, 33,230,242,233,231,232,116, 132, 33,146, 55,123, 55,135, 55,143, 55,154,228,226,236,243,244, 242,239,235,101,128, 33,207,232,229,225,246,121,128, 39,158,239, 246,229,242,236,229,230,116,128, 33,196,247,232,233,244,101,128, 33,232,244,225, 98, 2, 55,170, 55,177,236,229,230,116,128, 33, 228,242,233,231,232,116,128, 33,229,245,112,132, 33,145, 55,198, 55,226, 55,244, 55,252,100, 2, 55,204, 55,216,110,129, 33,149, 55,210,226,243,101,128, 33,168,239,247,238,226,225,243,101,128, 33,168,236,229,230,116,129, 33,150, 55,235,239,230,228,239,247, 110,128, 33,197,242,233,231,232,116,128, 33,151,247,232,233,244, 101,128, 33,231,246,229,242,244,229,120,128,248,230,115, 5, 56, 25, 56,101, 56,146, 56,229, 56,239, 99, 2, 56, 31, 56, 83,233, 105, 2, 56, 38, 56, 61,227,233,242,227,245,109,129, 0, 94, 56, 49,237,239,238,239,243,240,225,227,101,128,255, 62,244,233,236, 228,101,129, 0,126, 56, 71,237,239,238,239,243,240,225,227,101, 128,255, 94,242,233,240,116,129, 2, 81, 56, 92,244,245,242,238, 229,100,128, 2, 82,237,225,236,108, 2, 56,110, 56,121,232,233, 242,225,231,225,238, 97,128, 48, 65,235,225,244,225,235,225,238, 97,129, 48,161, 56,134,232,225,236,230,247,233,228,244,104,128, 255,103,244,229,242,233,115, 2, 56,156, 56,225,107,131, 0, 42, 56,166, 56,194, 56,217, 97, 2, 56,172, 56,186,236,244,239,238, 229,225,242,225,226,233, 99,128, 6,109,242,225,226,233, 99,128, 6,109,109, 2, 56,200, 56,206,225,244,104,128, 34, 23,239,238, 239,243,240,225,227,101,128,255, 10,243,237,225,236,108,128,254, 97,109,128, 32, 66,245,240,229,242,233,239,114,128,246,233,249, 237,240,244,239,244,233,227,225,236,236,249,229,241,245,225,108, 128, 34, 67,116,132, 0, 64, 57, 15, 57, 22, 57, 34, 57, 42,233, 236,228,101,128, 0,227,237,239,238,239,243,240,225,227,101,128, 255, 32,243,237,225,236,108,128,254,107,245,242,238,229,100,128, 2, 80,117, 6, 57, 64, 57, 89, 57, 96, 57,121, 57,141, 57,157, 98, 2, 57, 70, 57, 79,229,238,231,225,236,105,128, 9,148,239, 240,239,237,239,230,111,128, 49, 32,228,229,246, 97,128, 9, 20, 231,117, 2, 57,103, 57,112,234,225,242,225,244,105,128, 10,148, 242,237,245,235,232,105,128, 10, 20,236,229,238,231,244,232,237, 225,242,235,226,229,238,231,225,236,105,128, 9,215,237,225,244, 242,225,231,245,242,237,245,235,232,105,128, 10, 76,246,239,247, 229,236,243,233,231,110, 3, 57,173, 57,183, 57,190,226,229,238, 231,225,236,105,128, 9,204,228,229,246, 97,128, 9, 76,231,245, 234,225,242,225,244,105,128, 10,204,246,225,231,242,225,232,225, 228,229,246, 97,128, 9, 61,121, 2, 57,221, 57,233,226,225,242, 237,229,238,233,225,110,128, 5, 97,233,110,130, 5,226, 57,242, 58, 1,225,236,244,239,238,229,232,229,226,242,229,119,128,251, 32,232,229,226,242,229,119,128, 5,226, 98,144, 0, 98, 58, 46, 58,181, 58,192, 58,201, 58,226, 60, 11, 60, 73, 60,146, 62, 72, 62, 84, 62,127, 62,135, 62,145, 64, 15, 64, 39, 64, 48, 97, 7, 58, 62, 58, 72, 58, 96, 58,103, 58,128, 58,152, 58,163,226,229, 238,231,225,236,105,128, 9,172,227,235,243,236,225,243,104,129, 0, 92, 58, 84,237,239,238,239,243,240,225,227,101,128,255, 60, 228,229,246, 97,128, 9, 44,231,117, 2, 58,110, 58,119,234,225, 242,225,244,105,128, 10,172,242,237,245,235,232,105,128, 10, 44, 104, 2, 58,134, 58,144,233,242,225,231,225,238, 97,128, 48,112, 244,244,232,225,105,128, 14, 63,235,225,244,225,235,225,238, 97, 128, 48,208,114,129, 0,124, 58,169,237,239,238,239,243,240,225, 227,101,128,255, 92,226,239,240,239,237,239,230,111,128, 49, 5, 227,233,242,227,236,101,128, 36,209,228,239,116, 2, 58,209, 58, 218,225,227,227,229,238,116,128, 30, 3,226,229,236,239,119,128, 30, 5,101, 6, 58,240, 59, 5, 59, 28, 59,170, 59,181, 59,193, 225,237,229,228,243,233,248,244,229,229,238,244,232,238,239,244, 229,115,128, 38,108, 99, 2, 59, 11, 59, 18,225,245,243,101,128, 34, 53,249,242,233,236,236,233, 99,128, 4, 49,104, 5, 59, 40, 59, 49, 59, 63, 59, 93, 59,152,225,242,225,226,233, 99,128, 6, 40,230,233,238,225,236,225,242,225,226,233, 99,128,254,144,105, 2, 59, 69, 59, 84,238,233,244,233,225,236,225,242,225,226,233, 99,128,254,145,242,225,231,225,238, 97,128, 48,121,237,101, 2, 59,100, 59,113,228,233,225,236,225,242,225,226,233, 99,128,254, 146,229,237,105, 2, 59,121, 59,136,238,233,244,233,225,236,225, 242,225,226,233, 99,128,252,159,243,239,236,225,244,229,228,225, 242,225,226,233, 99,128,252, 8,238,239,239,238,230,233,238,225, 236,225,242,225,226,233, 99,128,252,109,235,225,244,225,235,225, 238, 97,128, 48,217,238,225,242,237,229,238,233,225,110,128, 5, 98,116,132, 5,209, 59,205, 59,225, 59,245, 59,254, 97,129, 3, 178, 59,211,243,249,237,226,239,236,231,242,229,229,107,128, 3, 208,228,225,231,229,243,104,129,251, 49, 59,236,232,229,226,242, 229,119,128,251, 49,232,229,226,242,229,119,128, 5,209,242,225, 230,229,232,229,226,242,229,119,128,251, 76,104, 2, 60, 17, 60, 67, 97, 3, 60, 25, 60, 35, 60, 42,226,229,238,231,225,236,105, 128, 9,173,228,229,246, 97,128, 9, 45,231,117, 2, 60, 49, 60, 58,234,225,242,225,244,105,128, 10,173,242,237,245,235,232,105, 128, 10, 45,239,239,107,128, 2, 83,105, 5, 60, 85, 60, 96, 60, 107, 60,121, 60,135,232,233,242,225,231,225,238, 97,128, 48,115, 235,225,244,225,235,225,238, 97,128, 48,211,236,225,226,233,225, 236,227,236,233,227,107,128, 2,152,238,228,233,231,245,242,237, 245,235,232,105,128, 10, 2,242,245,243,241,245,225,242,101,128, 51, 49,108, 3, 60,154, 62, 55, 62, 66, 97, 2, 60,160, 62, 50, 227,107, 6, 60,175, 60,184, 60,221, 61,114, 61,169, 61,221,227, 233,242,227,236,101,128, 37,207,100, 2, 60,190, 60,199,233,225, 237,239,238,100,128, 37,198,239,247,238,240,239,233,238,244,233, 238,231,244,242,233,225,238,231,236,101,128, 37,188,108, 2, 60, 227, 61, 74,101, 2, 60,233, 61, 13,230,244,240,239,233,238,244, 233,238,103, 2, 60,248, 61, 2,240,239,233,238,244,229,114,128, 37,196,244,242,233,225,238,231,236,101,128, 37,192,238,244,233, 227,245,236,225,242,226,242,225,227,235,229,116, 2, 61, 33, 61, 53,236,229,230,116,129, 48, 16, 61, 42,246,229,242,244,233,227, 225,108,128,254, 59,242,233,231,232,116,129, 48, 17, 61, 63,246, 229,242,244,233,227,225,108,128,254, 60,239,247,229,114, 2, 61, 83, 61, 98,236,229,230,244,244,242,233,225,238,231,236,101,128, 37,227,242,233,231,232,244,244,242,233,225,238,231,236,101,128, 37,226,114, 2, 61,120, 61,131,229,227,244,225,238,231,236,101, 128, 37,172,233,231,232,244,240,239,233,238,244,233,238,103, 2, 61,148, 61,158,240,239,233,238,244,229,114,128, 37,186,244,242, 233,225,238,231,236,101,128, 37,182,115, 3, 61,177, 61,207, 61, 215,109, 2, 61,183, 61,195,225,236,236,243,241,245,225,242,101, 128, 37,170,233,236,233,238,231,230,225,227,101,128, 38, 59,241, 245,225,242,101,128, 37,160,244,225,114,128, 38, 5,245,240,112, 2, 61,229, 62, 11,229,114, 2, 61,236, 61,251,236,229,230,244, 244,242,233,225,238,231,236,101,128, 37,228,242,233,231,232,244, 244,242,233,225,238,231,236,101,128, 37,229,239,233,238,244,233, 238,103, 2, 62, 23, 62, 39,243,237,225,236,236,244,242,233,225, 238,231,236,101,128, 37,180,244,242,233,225,238,231,236,101,128, 37,178,238,107,128, 36, 35,233,238,229,226,229,236,239,119,128, 30, 7,239,227,107,128, 37,136,237,239,238,239,243,240,225,227, 101,128,255, 66,111, 3, 62, 92, 62,105, 62,116,226,225,233,237, 225,233,244,232,225,105,128, 14, 26,232,233,242,225,231,225,238, 97,128, 48,124,235,225,244,225,235,225,238, 97,128, 48,220,240, 225,242,229,110,128, 36,157,241,243,241,245,225,242,101,128, 51, 195,114, 4, 62,155, 63,149, 63,222, 64, 5,225, 99, 2, 62,162, 63, 56,101, 3, 62,170, 62,175, 62,243,229,120,128,248,244,236, 229,230,116,133, 0,123, 62,192, 62,197, 62,219, 62,227, 62,232, 226,116,128,248,243,109, 2, 62,203, 62,208,233,100,128,248,242, 239,238,239,243,240,225,227,101,128,255, 91,243,237,225,236,108, 128,254, 91,244,112,128,248,241,246,229,242,244,233,227,225,108, 128,254, 55,242,233,231,232,116,133, 0,125, 63, 5, 63, 10, 63, 32, 63, 40, 63, 45,226,116,128,248,254,109, 2, 63, 16, 63, 21, 233,100,128,248,253,239,238,239,243,240,225,227,101,128,255, 93, 243,237,225,236,108,128,254, 92,244,112,128,248,252,246,229,242, 244,233,227,225,108,128,254, 56,235,229,116, 2, 63, 64, 63,106, 236,229,230,116,132, 0, 91, 63, 79, 63, 84, 63, 89, 63,101,226, 116,128,248,240,229,120,128,248,239,237,239,238,239,243,240,225, 227,101,128,255, 59,244,112,128,248,238,242,233,231,232,116,132, 0, 93, 63,122, 63,127, 63,132, 63,144,226,116,128,248,251,229, 120,128,248,250,237,239,238,239,243,240,225,227,101,128,255, 61, 244,112,128,248,249,229,246,101,131, 2,216, 63,161, 63,172, 63, 178,226,229,236,239,247,227,237, 98,128, 3, 46,227,237, 98,128, 3, 6,233,238,246,229,242,244,229,100, 3, 63,193, 63,204, 63, 210,226,229,236,239,247,227,237, 98,128, 3, 47,227,237, 98,128, 3, 17,228,239,245,226,236,229,227,237, 98,128, 3, 97,233,228, 231,101, 2, 63,231, 63,242,226,229,236,239,247,227,237, 98,128, 3, 42,233,238,246,229,242,244,229,228,226,229,236,239,247,227, 237, 98,128, 3, 58,239,235,229,238,226,225,114,128, 0,166,115, 2, 64, 21, 64, 29,244,242,239,235,101,128, 1,128,245,240,229, 242,233,239,114,128,246,234,244,239,240,226,225,114,128, 1,131, 117, 3, 64, 56, 64, 67, 64, 78,232,233,242,225,231,225,238, 97, 128, 48,118,235,225,244,225,235,225,238, 97,128, 48,214,236,108, 2, 64, 85, 64,115,229,116,130, 32, 34, 64, 94, 64,104,233,238, 246,229,242,243,101,128, 37,216,239,240,229,242,225,244,239,114, 128, 34, 25,243,229,249,101,128, 37,206, 99,143, 0, 99, 64,156, 65,105, 65,116, 65,180, 65,211, 66, 48, 67,215, 68,199, 69, 43, 69, 92, 72, 84, 72, 92, 72,102, 72,114, 72,147, 97, 9, 64,176, 64,187, 64,197, 64,204, 64,211, 64,236, 64,246, 65, 42, 65, 51, 225,242,237,229,238,233,225,110,128, 5,110,226,229,238,231,225, 236,105,128, 9,154,227,245,244,101,128, 1, 7,228,229,246, 97, 128, 9, 26,231,117, 2, 64,218, 64,227,234,225,242,225,244,105, 128, 10,154,242,237,245,235,232,105,128, 10, 26,236,243,241,245, 225,242,101,128, 51,136,238,228,242,225,226,233,238,228,117, 4, 65, 8, 65, 18, 65, 24, 65, 31,226,229,238,231,225,236,105,128, 9,129,227,237, 98,128, 3, 16,228,229,246, 97,128, 9, 1,231, 245,234,225,242,225,244,105,128, 10,129,240,243,236,239,227,107, 128, 33,234,114, 3, 65, 59, 65, 65, 65, 91,229,239,102,128, 33, 5,239,110,130, 2,199, 65, 74, 65, 85,226,229,236,239,247,227, 237, 98,128, 3, 44,227,237, 98,128, 3, 12,242,233,225,231,229, 242,229,244,245,242,110,128, 33,181,226,239,240,239,237,239,230, 111,128, 49, 24, 99, 4, 65,126, 65,133, 65,152, 65,174,225,242, 239,110,128, 1, 13,229,228,233,236,236, 97,129, 0,231, 65,144, 225,227,245,244,101,128, 30, 9,233,242, 99, 2, 65,160, 65,165, 236,101,128, 36,210,245,237,230,236,229,120,128, 1, 9,245,242, 108,128, 2, 85,100, 2, 65,186, 65,202,239,116,129, 1, 11, 65, 193,225,227,227,229,238,116,128, 1, 11,243,241,245,225,242,101, 128, 51,197,101, 2, 65,217, 65,233,228,233,236,236, 97,129, 0, 184, 65,227,227,237, 98,128, 3, 39,238,116,132, 0,162, 65,246, 66, 14, 66, 26, 66, 37,105, 2, 65,252, 66, 4,231,242,225,228, 101,128, 33, 3,238,230,229,242,233,239,114,128,246,223,237,239, 238,239,243,240,225,227,101,128,255,224,239,236,228,243,244,249, 236,101,128,247,162,243,245,240,229,242,233,239,114,128,246,224, 104, 5, 66, 60, 66,123, 66,134, 67, 62, 67,154, 97, 4, 66, 70, 66, 81, 66, 91, 66, 98,225,242,237,229,238,233,225,110,128, 5, 121,226,229,238,231,225,236,105,128, 9,155,228,229,246, 97,128, 9, 27,231,117, 2, 66,105, 66,114,234,225,242,225,244,105,128, 10,155,242,237,245,235,232,105,128, 10, 27,226,239,240,239,237, 239,230,111,128, 49, 20,101, 6, 66,148, 66,168, 66,192, 67, 4, 67, 16, 67, 37,225,226,235,232,225,243,233,225,238,227,249,242, 233,236,236,233, 99,128, 4,189, 99, 2, 66,174, 66,182,235,237, 225,242,107,128, 39, 19,249,242,233,236,236,233, 99,128, 4, 71, 100, 2, 66,198, 66,242,229,243,227,229,238,228,229,114, 2, 66, 211, 66,231,225,226,235,232,225,243,233,225,238,227,249,242,233, 236,236,233, 99,128, 4,191,227,249,242,233,236,236,233, 99,128, 4,183,233,229,242,229,243,233,243,227,249,242,233,236,236,233, 99,128, 4,245,232,225,242,237,229,238,233,225,110,128, 5,115, 235,232,225,235,225,243,243,233,225,238,227,249,242,233,236,236, 233, 99,128, 4,204,246,229,242,244,233,227,225,236,243,244,242, 239,235,229,227,249,242,233,236,236,233, 99,128, 4,185,105,129, 3,199, 67, 68,229,245,227,104, 4, 67, 81, 67,116, 67,131, 67, 140, 97, 2, 67, 87, 67,102,227,233,242,227,236,229,235,239,242, 229,225,110,128, 50,119,240,225,242,229,238,235,239,242,229,225, 110,128, 50, 23,227,233,242,227,236,229,235,239,242,229,225,110, 128, 50,105,235,239,242,229,225,110,128, 49, 74,240,225,242,229, 238,235,239,242,229,225,110,128, 50, 9,111, 2, 67,160, 67,210, 227,104, 3, 67,169, 67,191, 67,201,225,110, 2, 67,176, 67,184, 231,244,232,225,105,128, 14, 10,244,232,225,105,128, 14, 8,233, 238,231,244,232,225,105,128, 14, 9,239,229,244,232,225,105,128, 14, 12,239,107,128, 1,136,105, 2, 67,221, 68, 67,229,245, 99, 5, 67,235, 68, 14, 68, 29, 68, 38, 68, 52, 97, 2, 67,241, 68, 0,227,233,242,227,236,229,235,239,242,229,225,110,128, 50,118, 240,225,242,229,238,235,239,242,229,225,110,128, 50, 22,227,233, 242,227,236,229,235,239,242,229,225,110,128, 50,104,235,239,242, 229,225,110,128, 49, 72,240,225,242,229,238,235,239,242,229,225, 110,128, 50, 8,245,240,225,242,229,238,235,239,242,229,225,110, 128, 50, 28,242, 99, 2, 68, 74, 68,169,236,101,132, 37,203, 68, 87, 68, 98, 68,103, 68,127,237,245,236,244,233,240,236,121,128, 34,151,239,116,128, 34,153,112, 2, 68,109, 68,115,236,245,115, 128, 34,149,239,243,244,225,236,237,225,242,107,128, 48, 54,247, 233,244,104, 2, 68,136, 68,152,236,229,230,244,232,225,236,230, 226,236,225,227,107,128, 37,208,242,233,231,232,244,232,225,236, 230,226,236,225,227,107,128, 37,209,245,237,230,236,229,120,130, 2,198, 68,182, 68,193,226,229,236,239,247,227,237, 98,128, 3, 45,227,237, 98,128, 3, 2,108, 3, 68,207, 68,213, 69, 11,229, 225,114,128, 35, 39,233,227,107, 4, 68,225, 68,236, 68,245, 68, 255,225,236,246,229,239,236,225,114,128, 1,194,228,229,238,244, 225,108,128, 1,192,236,225,244,229,242,225,108,128, 1,193,242, 229,244,242,239,230,236,229,120,128, 1,195,245, 98,129, 38, 99, 69, 18,243,245,233,116, 2, 69, 27, 69, 35,226,236,225,227,107, 128, 38, 99,247,232,233,244,101,128, 38,103,109, 3, 69, 51, 69, 65, 69, 76,227,245,226,229,228,243,241,245,225,242,101,128, 51, 164,239,238,239,243,240,225,227,101,128,255, 67,243,241,245,225, 242,229,228,243,241,245,225,242,101,128, 51,160,111, 8, 69,110, 69,121, 69,208, 70,150, 71,179, 71,210, 72, 61, 72, 70,225,242, 237,229,238,233,225,110,128, 5,129,236,239,110,131, 0, 58, 69, 133, 69,158, 69,177,237,239,110, 2, 69,141, 69,149,229,244,225, 242,121,128, 32,161,239,243,240,225,227,101,128,255, 26,115, 2, 69,164, 69,170,233,231,110,128, 32,161,237,225,236,108,128,254, 85,244,242,233,225,238,231,245,236,225,114, 2, 69,192, 69,202, 232,225,236,230,237,239,100,128, 2,209,237,239,100,128, 2,208, 109, 2, 69,214, 70,143,237, 97,134, 0, 44, 69,231, 70, 39, 70, 50, 70, 62, 70, 92, 70,115, 97, 3, 69,239, 70, 9, 70, 17,226, 239,246,101, 2, 69,248, 69,254,227,237, 98,128, 3, 19,242,233, 231,232,244,227,237, 98,128, 3, 21,227,227,229,238,116,128,246, 195,114, 2, 70, 23, 70, 30,225,226,233, 99,128, 6, 12,237,229, 238,233,225,110,128, 5, 93,233,238,230,229,242,233,239,114,128, 246,225,237,239,238,239,243,240,225,227,101,128,255, 12,242,229, 246,229,242,243,229,100, 2, 70, 75, 70, 86,225,226,239,246,229, 227,237, 98,128, 3, 20,237,239,100,128, 2,189,115, 2, 70, 98, 70,105,237,225,236,108,128,254, 80,245,240,229,242,233,239,114, 128,246,226,244,245,242,238,229,100, 2, 70,126, 70,137,225,226, 239,246,229,227,237, 98,128, 3, 18,237,239,100,128, 2,187,240, 225,243,115,128, 38, 60,110, 2, 70,156, 70,165,231,242,245,229, 238,116,128, 34, 69,116, 2, 70,171, 70,185,239,245,242,233,238, 244,229,231,242,225,108,128, 34, 46,242,239,108,142, 35, 3, 70, 219, 70,225, 70,240, 70,255, 71, 43, 71, 88, 71,102, 71,107, 71, 112, 71,117, 71,123, 71,128, 71,169, 71,174,193,195, 75,128, 0, 6, 66, 2, 70,231, 70,236,197, 76,128, 0, 7, 83,128, 0, 8, 67, 2, 70,246, 70,251,193, 78,128, 0, 24, 82,128, 0, 13, 68, 3, 71, 7, 71, 33, 71, 38, 67, 4, 71, 17, 71, 21, 71, 25, 71, 29, 49,128, 0, 17, 50,128, 0, 18, 51,128, 0, 19, 52,128, 0, 20,197, 76,128, 0,127,204, 69,128, 0, 16, 69, 5, 71, 55, 71, 59, 71, 64, 71, 69, 71, 74, 77,128, 0, 25,206, 81,128, 0, 5, 207, 84,128, 0, 4,211, 67,128, 0, 27, 84, 2, 71, 80, 71, 84, 66,128, 0, 23, 88,128, 0, 3, 70, 2, 71, 94, 71, 98, 70,128, 0, 12, 83,128, 0, 28,199, 83,128, 0, 29,200, 84,128, 0, 9, 204, 70,128, 0, 10,206,193, 75,128, 0, 21,210, 83,128, 0, 30, 83, 5, 71,140, 71,144, 71,154, 71,159, 71,164, 73,128, 0, 15, 79,129, 0, 14, 71,150, 84,128, 0, 2,212, 88,128, 0, 1,213, 66,128, 0, 26,217, 78,128, 0, 22,213, 83,128, 0, 31,214, 84, 128, 0, 11,240,249,242,233,231,232,116,129, 0,169, 71,191,115, 2, 71,197, 71,203,225,238,115,128,248,233,229,242,233,102,128, 246,217,114, 2, 71,216, 72, 44,238,229,242,226,242,225,227,235, 229,116, 2, 71,231, 72, 9,236,229,230,116,130, 48, 12, 71,242, 71,254,232,225,236,230,247,233,228,244,104,128,255, 98,246,229, 242,244,233,227,225,108,128,254, 65,242,233,231,232,116,130, 48, 13, 72, 21, 72, 33,232,225,236,230,247,233,228,244,104,128,255, 99,246,229,242,244,233,227,225,108,128,254, 66,240,239,242,225, 244,233,239,238,243,241,245,225,242,101,128, 51,127,243,241,245, 225,242,101,128, 51,199,246,229,242,235,231,243,241,245,225,242, 101,128, 51,198,240,225,242,229,110,128, 36,158,242,245,250,229, 233,242,111,128, 32,162,243,244,242,229,244,227,232,229,100,128, 2,151,245,114, 2, 72,121, 72,139,236,121, 2, 72,128, 72,134, 225,238,100,128, 34,207,239,114,128, 34,206,242,229,238,227,121, 128, 0,164,249,114, 4, 72,158, 72,166, 72,173, 72,181,194,242, 229,246,101,128,246,209,198,236,229,120,128,246,210,226,242,229, 246,101,128,246,212,230,236,229,120,128,246,213,100,146, 0,100, 72,228, 74,110, 75,134, 75,194, 76,114, 77, 68, 77,130, 78, 59, 78, 72, 78, 81, 78,107, 78,132, 78,141, 79,208, 79,216, 79,227, 79,247, 80, 19, 97, 11, 72,252, 73, 7, 73, 17, 73, 89, 73,152, 73,163, 73,174, 73,243, 74, 49, 74, 55, 74, 85,225,242,237,229, 238,233,225,110,128, 5,100,226,229,238,231,225,236,105,128, 9, 166,100, 5, 73, 29, 73, 38, 73, 44, 73, 58, 73, 74,225,242,225, 226,233, 99,128, 6, 54,229,246, 97,128, 9, 38,230,233,238,225, 236,225,242,225,226,233, 99,128,254,190,233,238,233,244,233,225, 236,225,242,225,226,233, 99,128,254,191,237,229,228,233,225,236, 225,242,225,226,233, 99,128,254,192,103, 3, 73, 97, 73,114, 73, 128,229,243,104,129, 5,188, 73,105,232,229,226,242,229,119,128, 5,188,231,229,114,129, 32, 32, 73,122,228,226,108,128, 32, 33, 117, 2, 73,134, 73,143,234,225,242,225,244,105,128, 10,166,242, 237,245,235,232,105,128, 10, 38,232,233,242,225,231,225,238, 97, 128, 48, 96,235,225,244,225,235,225,238, 97,128, 48,192,108, 3, 73,182, 73,191, 73,229,225,242,225,226,233, 99,128, 6, 47,229, 116,130, 5,211, 73,200, 73,220,228,225,231,229,243,104,129,251, 51, 73,211,232,229,226,242,229,119,128,251, 51,232,229,226,242, 229,119,128, 5,211,230,233,238,225,236,225,242,225,226,233, 99, 128,254,170,237,237, 97, 3, 73,253, 74, 6, 74, 18,225,242,225, 226,233, 99,128, 6, 79,236,239,247,225,242,225,226,233, 99,128, 6, 79,244,225,238, 97, 2, 74, 27, 74, 41,236,244,239,238,229, 225,242,225,226,233, 99,128, 6, 76,242,225,226,233, 99,128, 6, 76,238,228, 97,128, 9,100,242,231, 97, 2, 74, 63, 74, 72,232, 229,226,242,229,119,128, 5,167,236,229,230,244,232,229,226,242, 229,119,128, 5,167,243,233,225,240,238,229,245,237,225,244,225, 227,249,242,233,236,236,233,227,227,237, 98,128, 4,133, 98, 3, 74,118, 75,115, 75,125,108, 9, 74,138, 74,146, 75, 3, 75, 11, 75, 27, 75, 38, 75, 56, 75, 70, 75, 81,199,242,225,246,101,128, 246,211, 97, 2, 74,152, 74,209,238,231,236,229,226,242,225,227, 235,229,116, 2, 74,168, 74,188,236,229,230,116,129, 48, 10, 74, 177,246,229,242,244,233,227,225,108,128,254, 61,242,233,231,232, 116,129, 48, 11, 74,198,246,229,242,244,233,227,225,108,128,254, 62,114, 2, 74,215, 74,236,227,232,233,238,246,229,242,244,229, 228,226,229,236,239,247,227,237, 98,128, 3, 43,242,239,119, 2, 74,244, 74,251,236,229,230,116,128, 33,212,242,233,231,232,116, 128, 33,210,228,225,238,228, 97,128, 9,101,231,242,225,246,101, 129,246,214, 75, 21,227,237, 98,128, 3, 15,233,238,244,229,231, 242,225,108,128, 34, 44,236,239,247,236,233,238,101,129, 32, 23, 75, 50,227,237, 98,128, 3, 51,239,246,229,242,236,233,238,229, 227,237, 98,128, 3, 63,240,242,233,237,229,237,239,100,128, 2, 186,246,229,242,244,233,227,225,108, 2, 75, 94, 75,100,226,225, 114,128, 32, 22,236,233,238,229,225,226,239,246,229,227,237, 98, 128, 3, 14,239,240,239,237,239,230,111,128, 49, 9,243,241,245, 225,242,101,128, 51,200, 99, 4, 75,144, 75,151, 75,160, 75,187, 225,242,239,110,128, 1, 15,229,228,233,236,236, 97,128, 30, 17, 233,242, 99, 2, 75,168, 75,173,236,101,128, 36,211,245,237,230, 236,229,248,226,229,236,239,119,128, 30, 19,242,239,225,116,128, 1, 17,100, 4, 75,204, 76, 29, 76, 39, 76, 90, 97, 4, 75,214, 75,224, 75,231, 76, 0,226,229,238,231,225,236,105,128, 9,161, 228,229,246, 97,128, 9, 33,231,117, 2, 75,238, 75,247,234,225, 242,225,244,105,128, 10,161,242,237,245,235,232,105,128, 10, 33, 108, 2, 76, 6, 76, 15,225,242,225,226,233, 99,128, 6,136,230, 233,238,225,236,225,242,225,226,233, 99,128,251,137,228,232,225, 228,229,246, 97,128, 9, 92,232, 97, 3, 76, 48, 76, 58, 76, 65, 226,229,238,231,225,236,105,128, 9,162,228,229,246, 97,128, 9, 34,231,117, 2, 76, 72, 76, 81,234,225,242,225,244,105,128, 10, 162,242,237,245,235,232,105,128, 10, 34,239,116, 2, 76, 97, 76, 106,225,227,227,229,238,116,128, 30, 11,226,229,236,239,119,128, 30, 13,101, 8, 76,132, 76,185, 76,192, 76,217, 76,227, 76,238, 77, 27, 77, 63, 99, 2, 76,138, 76,175,233,237,225,236,243,229, 240,225,242,225,244,239,114, 2, 76,156, 76,165,225,242,225,226, 233, 99,128, 6,107,240,229,242,243,233,225,110,128, 6,107,249, 242,233,236,236,233, 99,128, 4, 52,231,242,229,101,128, 0,176, 232,105, 2, 76,199, 76,208,232,229,226,242,229,119,128, 5,173, 242,225,231,225,238, 97,128, 48,103,233,227,239,240,244,233, 99, 128, 3,239,235,225,244,225,235,225,238, 97,128, 48,199,108, 2, 76,244, 77, 11,229,244,101, 2, 76,252, 77, 3,236,229,230,116, 128, 35, 43,242,233,231,232,116,128, 35, 38,244, 97,129, 3,180, 77, 18,244,245,242,238,229,100,128, 1,141,238,239,237,233,238, 225,244,239,242,237,233,238,245,243,239,238,229,238,245,237,229, 242,225,244,239,242,226,229,238,231,225,236,105,128, 9,248,250, 104,128, 2,164,104, 2, 77, 74, 77,124, 97, 3, 77, 82, 77, 92, 77, 99,226,229,238,231,225,236,105,128, 9,167,228,229,246, 97, 128, 9, 39,231,117, 2, 77,106, 77,115,234,225,242,225,244,105, 128, 10,167,242,237,245,235,232,105,128, 10, 39,239,239,107,128, 2, 87,105, 6, 77,144, 77,193, 77,253, 78, 8, 78, 19, 78, 29, 97, 2, 77,150, 77,172,236,249,244,233,235,225,244,239,238,239, 115,129, 3,133, 77,166,227,237, 98,128, 3, 68,237,239,238,100, 129, 38,102, 77,181,243,245,233,244,247,232,233,244,101,128, 38, 98,229,242,229,243,233,115,133, 0,168, 77,212, 77,220, 77,231, 77,237, 77,245,225,227,245,244,101,128,246,215,226,229,236,239, 247,227,237, 98,128, 3, 36,227,237, 98,128, 3, 8,231,242,225, 246,101,128,246,216,244,239,238,239,115,128, 3,133,232,233,242, 225,231,225,238, 97,128, 48, 98,235,225,244,225,235,225,238, 97, 128, 48,194,244,244,239,237,225,242,107,128, 48, 3,246,105, 2, 78, 36, 78, 47,228,101,129, 0,247, 78, 43,115,128, 34, 35,243, 233,239,238,243,236,225,243,104,128, 34, 21,234,229,227,249,242, 233,236,236,233, 99,128, 4, 82,235,243,232,225,228,101,128, 37, 147,108, 2, 78, 87, 78, 98,233,238,229,226,229,236,239,119,128, 30, 15,243,241,245,225,242,101,128, 51,151,109, 2, 78,113, 78, 121,225,227,242,239,110,128, 1, 17,239,238,239,243,240,225,227, 101,128,255, 68,238,226,236,239,227,107,128, 37,132,111, 10, 78, 163, 78,175, 78,185, 78,196, 78,207, 79, 23, 79, 28, 79, 39, 79, 154, 79,180,227,232,225,228,225,244,232,225,105,128, 14, 14,228, 229,235,244,232,225,105,128, 14, 20,232,233,242,225,231,225,238, 97,128, 48,105,235,225,244,225,235,225,238, 97,128, 48,201,236, 236,225,114,132, 0, 36, 78,222, 78,233, 78,245, 79, 0,233,238, 230,229,242,233,239,114,128,246,227,237,239,238,239,243,240,225, 227,101,128,255, 4,239,236,228,243,244,249,236,101,128,247, 36, 115, 2, 79, 6, 79, 13,237,225,236,108,128,254,105,245,240,229, 242,233,239,114,128,246,228,238,103,128, 32,171,242,245,243,241, 245,225,242,101,128, 51, 38,116, 6, 79, 53, 79, 70, 79, 92, 79, 103, 79,135, 79,142,225,227,227,229,238,116,129, 2,217, 79, 64, 227,237, 98,128, 3, 7,226,229,236,239,247, 99, 2, 79, 81, 79, 86,237, 98,128, 3, 35,239,237, 98,128, 3, 35,235,225,244,225, 235,225,238, 97,128, 48,251,236,229,243,115, 2, 79,112, 79,116, 105,128, 1, 49,106,129,246,190, 79,122,243,244,242,239,235,229, 232,239,239,107,128, 2,132,237,225,244,104,128, 34,197,244,229, 228,227,233,242,227,236,101,128, 37,204,245,226,236,229,249,239, 228,240,225,244,225,104,129,251, 31, 79,171,232,229,226,242,229, 119,128,251, 31,247,238,244,225,227,107, 2, 79,191, 79,202,226, 229,236,239,247,227,237, 98,128, 3, 30,237,239,100,128, 2,213, 240,225,242,229,110,128, 36,159,243,245,240,229,242,233,239,114, 128,246,235,116, 2, 79,233, 79,239,225,233,108,128, 2, 86,239, 240,226,225,114,128, 1,140,117, 2, 79,253, 80, 8,232,233,242, 225,231,225,238, 97,128, 48,101,235,225,244,225,235,225,238, 97, 128, 48,197,122,132, 1,243, 80, 31, 80, 40, 80, 59, 80, 96,225, 236,244,239,238,101,128, 2,163, 99, 2, 80, 46, 80, 53,225,242, 239,110,128, 1,198,245,242,108,128, 2,165,101, 2, 80, 65, 80, 85,225,226,235,232,225,243,233,225,238,227,249,242,233,236,236, 233, 99,128, 4,225,227,249,242,233,236,236,233, 99,128, 4, 85, 232,229,227,249,242,233,236,236,233, 99,128, 4, 95,101,151, 0, 101, 80,159, 80,178, 80,212, 81,186, 81,248, 82, 25, 82, 37, 82, 60, 82,113, 83,225, 84, 27, 84,129, 84,245, 85,124, 85,199, 85, 230, 86, 36, 86, 89, 87, 24, 87,157, 87,177, 87,221, 88, 56, 97, 2, 80,165, 80,172,227,245,244,101,128, 0,233,242,244,104,128, 38, 65, 98, 3, 80,186, 80,195, 80,205,229,238,231,225,236,105, 128, 9,143,239,240,239,237,239,230,111,128, 49, 28,242,229,246, 101,128, 1, 21, 99, 5, 80,224, 81, 41, 81, 55, 81, 87, 81,176, 97, 2, 80,230, 81, 35,238,228,242, 97, 3, 80,241, 80,248, 81, 3,228,229,246, 97,128, 9, 13,231,245,234,225,242,225,244,105, 128, 10,141,246,239,247,229,236,243,233,231,110, 2, 81, 17, 81, 24,228,229,246, 97,128, 9, 69,231,245,234,225,242,225,244,105, 128, 10,197,242,239,110,128, 1, 27,229,228,233,236,236,225,226, 242,229,246,101,128, 30, 29,104, 2, 81, 61, 81, 72,225,242,237, 229,238,233,225,110,128, 5,101,249,233,247,238,225,242,237,229, 238,233,225,110,128, 5,135,233,242, 99, 2, 81, 95, 81,100,236, 101,128, 36,212,245,237,230,236,229,120,134, 0,234, 81,121, 81, 129, 81,137, 81,148, 81,156, 81,168,225,227,245,244,101,128, 30, 191,226,229,236,239,119,128, 30, 25,228,239,244,226,229,236,239, 119,128, 30,199,231,242,225,246,101,128, 30,193,232,239,239,235, 225,226,239,246,101,128, 30,195,244,233,236,228,101,128, 30,197, 249,242,233,236,236,233, 99,128, 4, 84,100, 4, 81,196, 81,206, 81,212, 81,222,226,236,231,242,225,246,101,128, 2, 5,229,246, 97,128, 9, 15,233,229,242,229,243,233,115,128, 0,235,239,116, 130, 1, 23, 81,231, 81,240,225,227,227,229,238,116,128, 1, 23, 226,229,236,239,119,128, 30,185,101, 2, 81,254, 82, 9,231,245, 242,237,245,235,232,105,128, 10, 15,237,225,244,242,225,231,245, 242,237,245,235,232,105,128, 10, 71,230,227,249,242,233,236,236, 233, 99,128, 4, 68,103, 2, 82, 43, 82, 50,242,225,246,101,128, 0,232,245,234,225,242,225,244,105,128, 10,143,104, 4, 82, 70, 82, 81, 82, 92, 82,102,225,242,237,229,238,233,225,110,128, 5, 103,226,239,240,239,237,239,230,111,128, 49, 29,233,242,225,231, 225,238, 97,128, 48, 72,239,239,235,225,226,239,246,101,128, 30, 187,105, 4, 82,123, 82,134, 83,192, 83,207,226,239,240,239,237, 239,230,111,128, 49, 31,231,232,116,142, 0, 56, 82,168, 82,177, 82,187, 82,217, 82,224, 83, 6, 83, 31, 83, 76, 83,110, 83,122, 83,133, 83,166, 83,174, 83,185,225,242,225,226,233, 99,128, 6, 104,226,229,238,231,225,236,105,128, 9,238,227,233,242,227,236, 101,129, 36,103, 82,198,233,238,246,229,242,243,229,243,225,238, 243,243,229,242,233,102,128, 39,145,228,229,246, 97,128, 9,110, 229,229,110, 2, 82,232, 82,241,227,233,242,227,236,101,128, 36, 113,112, 2, 82,247, 82,254,225,242,229,110,128, 36,133,229,242, 233,239,100,128, 36,153,231,117, 2, 83, 13, 83, 22,234,225,242, 225,244,105,128, 10,238,242,237,245,235,232,105,128, 10,110,104, 2, 83, 37, 83, 63, 97, 2, 83, 43, 83, 54,227,235,225,242,225, 226,233, 99,128, 6,104,238,231,250,232,239,117,128, 48, 40,238, 239,244,229,226,229,225,237,229,100,128, 38,107,105, 2, 83, 82, 83,100,228,229,239,231,242,225,240,232,233,227,240,225,242,229, 110,128, 50, 39,238,230,229,242,233,239,114,128, 32,136,237,239, 238,239,243,240,225,227,101,128,255, 24,239,236,228,243,244,249, 236,101,128,247, 56,112, 2, 83,139, 83,146,225,242,229,110,128, 36,123,229,114, 2, 83,153, 83,159,233,239,100,128, 36,143,243, 233,225,110,128, 6,248,242,239,237,225,110,128, 33,119,243,245, 240,229,242,233,239,114,128, 32,120,244,232,225,105,128, 14, 88, 238,246,229,242,244,229,228,226,242,229,246,101,128, 2, 7,239, 244,233,230,233,229,228,227,249,242,233,236,236,233, 99,128, 4, 101,107, 2, 83,231, 83,255,225,244,225,235,225,238, 97,129, 48, 168, 83,243,232,225,236,230,247,233,228,244,104,128,255,116,111, 2, 84, 5, 84, 20,238,235,225,242,231,245,242,237,245,235,232, 105,128, 10,116,242,229,225,110,128, 49, 84,108, 3, 84, 35, 84, 46, 84,107,227,249,242,233,236,236,233, 99,128, 4, 59,101, 2, 84, 52, 84, 59,237,229,238,116,128, 34, 8,246,229,110, 3, 84, 69, 84, 78, 84, 99,227,233,242,227,236,101,128, 36,106,112, 2, 84, 84, 84, 91,225,242,229,110,128, 36,126,229,242,233,239,100, 128, 36,146,242,239,237,225,110,128, 33,122,236,233,240,243,233, 115,129, 32, 38, 84,118,246,229,242,244,233,227,225,108,128, 34, 238,109, 5, 84,141, 84,169, 84,180, 84,200, 84,211,225,227,242, 239,110,130, 1, 19, 84,153, 84,161,225,227,245,244,101,128, 30, 23,231,242,225,246,101,128, 30, 21,227,249,242,233,236,236,233, 99,128, 4, 60,228,225,243,104,129, 32, 20, 84,189,246,229,242, 244,233,227,225,108,128,254, 49,239,238,239,243,240,225,227,101, 128,255, 69,112, 2, 84,217, 84,237,232,225,243,233,243,237,225, 242,235,225,242,237,229,238,233,225,110,128, 5, 91,244,249,243, 229,116,128, 34, 5,110, 6, 85, 3, 85, 14, 85, 25, 85, 69, 85, 101, 85,116,226,239,240,239,237,239,230,111,128, 49, 35,227,249, 242,233,236,236,233, 99,128, 4, 61,100, 2, 85, 31, 85, 50,225, 243,104,129, 32, 19, 85, 39,246,229,242,244,233,227,225,108,128, 254, 50,229,243,227,229,238,228,229,242,227,249,242,233,236,236, 233, 99,128, 4,163,103,130, 1, 75, 85, 77, 85, 88,226,239,240, 239,237,239,230,111,128, 49, 37,232,229,227,249,242,233,236,236, 233, 99,128, 4,165,232,239,239,235,227,249,242,233,236,236,233, 99,128, 4,200,243,240,225,227,101,128, 32, 2,111, 3, 85,132, 85,140, 85,149,231,239,238,229,107,128, 1, 25,235,239,242,229, 225,110,128, 49, 83,240,229,110,130, 2, 91, 85,159, 85,168,227, 236,239,243,229,100,128, 2,154,242,229,246,229,242,243,229,100, 130, 2, 92, 85,183, 85,192,227,236,239,243,229,100,128, 2, 94, 232,239,239,107,128, 2, 93,112, 2, 85,205, 85,212,225,242,229, 110,128, 36,160,243,233,236,239,110,129, 3,181, 85,222,244,239, 238,239,115,128, 3,173,241,117, 2, 85,237, 86, 25,225,108,130, 0, 61, 85,246, 86, 2,237,239,238,239,243,240,225,227,101,128, 255, 29,115, 2, 86, 8, 86, 15,237,225,236,108,128,254,102,245, 240,229,242,233,239,114,128, 32,124,233,246,225,236,229,238,227, 101,128, 34, 97,114, 3, 86, 44, 86, 55, 86, 66,226,239,240,239, 237,239,230,111,128, 49, 38,227,249,242,233,236,236,233, 99,128, 4, 64,229,246,229,242,243,229,100,129, 2, 88, 86, 78,227,249, 242,233,236,236,233, 99,128, 4, 77,115, 6, 86,103, 86,114, 86, 134, 86,215, 87, 4, 87, 14,227,249,242,233,236,236,233, 99,128, 4, 65,228,229,243,227,229,238,228,229,242,227,249,242,233,236, 236,233, 99,128, 4,171,104,132, 2,131, 86,146, 86,153, 86,184, 86,199,227,245,242,108,128, 2,134,239,242,116, 2, 86,161, 86, 168,228,229,246, 97,128, 9, 14,246,239,247,229,236,243,233,231, 238,228,229,246, 97,128, 9, 70,242,229,246,229,242,243,229,228, 236,239,239,112,128, 1,170,243,241,245,225,244,242,229,246,229, 242,243,229,100,128, 2,133,237,225,236,108, 2, 86,224, 86,235, 232,233,242,225,231,225,238, 97,128, 48, 71,235,225,244,225,235, 225,238, 97,129, 48,167, 86,248,232,225,236,230,247,233,228,244, 104,128,255,106,244,233,237,225,244,229,100,128, 33, 46,245,240, 229,242,233,239,114,128,246,236,116, 5, 87, 36, 87, 62, 87, 66, 87, 83, 87,149, 97,130, 3,183, 87, 44, 87, 54,242,237,229,238, 233,225,110,128, 5,104,244,239,238,239,115,128, 3,174,104,128, 0,240,233,236,228,101,129, 30,189, 87, 75,226,229,236,239,119, 128, 30, 27,238,225,232,244, 97, 3, 87, 95, 87,127, 87,136,230, 239,245,235,104, 2, 87,105, 87,114,232,229,226,242,229,119,128, 5,145,236,229,230,244,232,229,226,242,229,119,128, 5,145,232, 229,226,242,229,119,128, 5,145,236,229,230,244,232,229,226,242, 229,119,128, 5,145,245,242,238,229,100,128, 1,221,117, 2, 87, 163, 87,172,235,239,242,229,225,110,128, 49, 97,242,111,128, 32, 172,246,239,247,229,236,243,233,231,110, 3, 87,193, 87,203, 87, 210,226,229,238,231,225,236,105,128, 9,199,228,229,246, 97,128, 9, 71,231,245,234,225,242,225,244,105,128, 10,199,120, 2, 87, 227, 88, 44,227,236,225,109,132, 0, 33, 87,242, 87,253, 88, 24, 88, 36,225,242,237,229,238,233,225,110,128, 5, 92,100, 2, 88, 3, 88, 8,226,108,128, 32, 60,239,247,110,129, 0,161, 88, 16, 243,237,225,236,108,128,247,161,237,239,238,239,243,240,225,227, 101,128,255, 1,243,237,225,236,108,128,247, 33,233,243,244,229, 238,244,233,225,108,128, 34, 3,250,104,131, 2,146, 88, 67, 88, 86, 88, 97, 99, 2, 88, 73, 88, 80,225,242,239,110,128, 1,239, 245,242,108,128, 2,147,242,229,246,229,242,243,229,100,128, 1, 185,244,225,233,108,128, 1,186,102,140, 0,102, 88,132, 88,214, 88,225, 88,234, 88,246, 89, 93, 89,109, 91,117, 91,130, 91,156, 93, 33, 93, 41, 97, 4, 88,142, 88,149, 88,160, 88,171,228,229, 246, 97,128, 9, 94,231,245,242,237,245,235,232,105,128, 10, 94, 232,242,229,238,232,229,233,116,128, 33, 9,244,232, 97, 3, 88, 181, 88,190, 88,202,225,242,225,226,233, 99,128, 6, 78,236,239, 247,225,242,225,226,233, 99,128, 6, 78,244,225,238,225,242,225, 226,233, 99,128, 6, 75,226,239,240,239,237,239,230,111,128, 49, 8,227,233,242,227,236,101,128, 36,213,228,239,244,225,227,227, 229,238,116,128, 30, 31,101, 3, 88,254, 89, 76, 89, 86,104, 4, 89, 8, 89, 31, 89, 45, 89, 61,225,114, 2, 89, 15, 89, 22,225, 226,233, 99,128, 6, 65,237,229,238,233,225,110,128, 5,134,230, 233,238,225,236,225,242,225,226,233, 99,128,254,210,233,238,233, 244,233,225,236,225,242,225,226,233, 99,128,254,211,237,229,228, 233,225,236,225,242,225,226,233, 99,128,254,212,233,227,239,240, 244,233, 99,128, 3,229,237,225,236,101,128, 38, 64,102,130,251, 0, 89,101, 89,105,105,128,251, 3,108,128,251, 4,105,136,251, 1, 89,129, 89,169, 89,180, 89,202, 90, 68, 90, 85, 90, 93, 90, 106,230,244,229,229,110, 2, 89,139, 89,148,227,233,242,227,236, 101,128, 36,110,112, 2, 89,154, 89,161,225,242,229,110,128, 36, 130,229,242,233,239,100,128, 36,150,231,245,242,229,228,225,243, 104,128, 32, 18,236,236,229,100, 2, 89,189, 89,195,226,239,120, 128, 37,160,242,229,227,116,128, 37,172,238,225,108, 5, 89,216, 89,255, 90, 16, 90, 33, 90, 49,235,225,102,130, 5,218, 89,226, 89,246,228,225,231,229,243,104,129,251, 58, 89,237,232,229,226, 242,229,119,128,251, 58,232,229,226,242,229,119,128, 5,218,237, 229,109,129, 5,221, 90, 7,232,229,226,242,229,119,128, 5,221, 238,245,110,129, 5,223, 90, 24,232,229,226,242,229,119,128, 5, 223,240,101,129, 5,227, 90, 40,232,229,226,242,229,119,128, 5, 227,244,243,225,228,105,129, 5,229, 90, 59,232,229,226,242,229, 119,128, 5,229,242,243,244,244,239,238,229,227,232,233,238,229, 243,101,128, 2,201,243,232,229,249,101,128, 37,201,244,225,227, 249,242,233,236,236,233, 99,128, 4,115,246,101,142, 0, 53, 90, 139, 90,148, 90,158, 90,188, 90,195, 90,205, 90,230, 91, 1, 91, 35, 91, 47, 91, 58, 91, 91, 91, 99, 91,110,225,242,225,226,233, 99,128, 6,101,226,229,238,231,225,236,105,128, 9,235,227,233, 242,227,236,101,129, 36,100, 90,169,233,238,246,229,242,243,229, 243,225,238,243,243,229,242,233,102,128, 39,142,228,229,246, 97, 128, 9,107,229,233,231,232,244,232,115,128, 33, 93,231,117, 2, 90,212, 90,221,234,225,242,225,244,105,128, 10,235,242,237,245, 235,232,105,128, 10,107,232, 97, 2, 90,237, 90,248,227,235,225, 242,225,226,233, 99,128, 6,101,238,231,250,232,239,117,128, 48, 37,105, 2, 91, 7, 91, 25,228,229,239,231,242,225,240,232,233, 227,240,225,242,229,110,128, 50, 36,238,230,229,242,233,239,114, 128, 32,133,237,239,238,239,243,240,225,227,101,128,255, 21,239, 236,228,243,244,249,236,101,128,247, 53,112, 2, 91, 64, 91, 71, 225,242,229,110,128, 36,120,229,114, 2, 91, 78, 91, 84,233,239, 100,128, 36,140,243,233,225,110,128, 6,245,242,239,237,225,110, 128, 33,116,243,245,240,229,242,233,239,114,128, 32,117,244,232, 225,105,128, 14, 85,108,129,251, 2, 91,123,239,242,233,110,128, 1,146,109, 2, 91,136, 91,147,239,238,239,243,240,225,227,101, 128,255, 70,243,241,245,225,242,101,128, 51,153,111, 4, 91,166, 91,188, 91,200, 91,207,230, 97, 2, 91,173, 91,181,238,244,232, 225,105,128, 14, 31,244,232,225,105,128, 14, 29,238,231,237,225, 238,244,232,225,105,128, 14, 79,242,225,236,108,128, 34, 0,245, 114,142, 0, 52, 91,240, 91,249, 92, 3, 92, 33, 92, 40, 92, 65, 92, 92, 92,126, 92,138, 92,157, 92,168, 92,201, 92,209, 92,220, 225,242,225,226,233, 99,128, 6,100,226,229,238,231,225,236,105, 128, 9,234,227,233,242,227,236,101,129, 36, 99, 92, 14,233,238, 246,229,242,243,229,243,225,238,243,243,229,242,233,102,128, 39, 141,228,229,246, 97,128, 9,106,231,117, 2, 92, 47, 92, 56,234, 225,242,225,244,105,128, 10,234,242,237,245,235,232,105,128, 10, 106,232, 97, 2, 92, 72, 92, 83,227,235,225,242,225,226,233, 99, 128, 6,100,238,231,250,232,239,117,128, 48, 36,105, 2, 92, 98, 92,116,228,229,239,231,242,225,240,232,233,227,240,225,242,229, 110,128, 50, 35,238,230,229,242,233,239,114,128, 32,132,237,239, 238,239,243,240,225,227,101,128,255, 20,238,245,237,229,242,225, 244,239,242,226,229,238,231,225,236,105,128, 9,247,239,236,228, 243,244,249,236,101,128,247, 52,112, 2, 92,174, 92,181,225,242, 229,110,128, 36,119,229,114, 2, 92,188, 92,194,233,239,100,128, 36,139,243,233,225,110,128, 6,244,242,239,237,225,110,128, 33, 115,243,245,240,229,242,233,239,114,128, 32,116,116, 2, 92,226, 93, 8,229,229,110, 2, 92,234, 92,243,227,233,242,227,236,101, 128, 36,109,112, 2, 92,249, 93, 0,225,242,229,110,128, 36,129, 229,242,233,239,100,128, 36,149,104, 2, 93, 14, 93, 19,225,105, 128, 14, 84,244,239,238,229,227,232,233,238,229,243,101,128, 2, 203,240,225,242,229,110,128, 36,161,242, 97, 2, 93, 48, 93, 56, 227,244,233,239,110,128, 32, 68,238, 99,128, 32,163,103,144, 0, 103, 93, 97, 94, 43, 94, 66, 94,127, 94,144, 95, 65, 96, 58, 96, 143, 96,156, 97, 14, 97, 39, 97, 67, 97, 89, 98, 34, 98, 56, 98, 158, 97, 9, 93,117, 93,127, 93,134, 93,141, 93,205, 93,230, 93, 241, 93,252, 94, 30,226,229,238,231,225,236,105,128, 9,151,227, 245,244,101,128, 1,245,228,229,246, 97,128, 9, 23,102, 4, 93, 151, 93,160, 93,174, 93,190,225,242,225,226,233, 99,128, 6,175, 230,233,238,225,236,225,242,225,226,233, 99,128,251,147,233,238, 233,244,233,225,236,225,242,225,226,233, 99,128,251,148,237,229, 228,233,225,236,225,242,225,226,233, 99,128,251,149,231,117, 2, 93,212, 93,221,234,225,242,225,244,105,128, 10,151,242,237,245, 235,232,105,128, 10, 23,232,233,242,225,231,225,238, 97,128, 48, 76,235,225,244,225,235,225,238, 97,128, 48,172,237,237, 97,130, 3,179, 94, 6, 94, 19,236,225,244,233,238,243,237,225,236,108, 128, 2, 99,243,245,240,229,242,233,239,114,128, 2,224,238,231, 233,225,227,239,240,244,233, 99,128, 3,235, 98, 2, 94, 49, 94, 59,239,240,239,237,239,230,111,128, 49, 13,242,229,246,101,128, 1, 31, 99, 4, 94, 76, 94, 83, 94, 92, 94,114,225,242,239,110, 128, 1,231,229,228,233,236,236, 97,128, 1, 35,233,242, 99, 2, 94,100, 94,105,236,101,128, 36,214,245,237,230,236,229,120,128, 1, 29,239,237,237,225,225,227,227,229,238,116,128, 1, 35,228, 239,116,129, 1, 33, 94,135,225,227,227,229,238,116,128, 1, 33, 101, 6, 94,158, 94,169, 94,180, 94,191, 94,210, 95, 56,227,249, 242,233,236,236,233, 99,128, 4, 51,232,233,242,225,231,225,238, 97,128, 48, 82,235,225,244,225,235,225,238, 97,128, 48,178,239, 237,229,244,242,233,227,225,236,236,249,229,241,245,225,108,128, 34, 81,114, 3, 94,218, 95, 11, 95, 21,229,243,104, 3, 94,228, 94,243, 94,252,225,227,227,229,238,244,232,229,226,242,229,119, 128, 5,156,232,229,226,242,229,119,128, 5,243,237,245,241,228, 225,237,232,229,226,242,229,119,128, 5,157,237,225,238,228,226, 236,115,128, 0,223,243,232,225,249,233,109, 2, 95, 32, 95, 47, 225,227,227,229,238,244,232,229,226,242,229,119,128, 5,158,232, 229,226,242,229,119,128, 5,244,244,225,237,225,242,107,128, 48, 19,104, 5, 95, 77, 95,210, 96, 17, 96, 42, 96, 48, 97, 4, 95, 87, 95, 97, 95,120, 95,145,226,229,238,231,225,236,105,128, 9, 152,100, 2, 95,103, 95,114,225,242,237,229,238,233,225,110,128, 5,114,229,246, 97,128, 9, 24,231,117, 2, 95,127, 95,136,234, 225,242,225,244,105,128, 10,152,242,237,245,235,232,105,128, 10, 24,233,110, 4, 95,156, 95,165, 95,179, 95,195,225,242,225,226, 233, 99,128, 6, 58,230,233,238,225,236,225,242,225,226,233, 99, 128,254,206,233,238,233,244,233,225,236,225,242,225,226,233, 99, 128,254,207,237,229,228,233,225,236,225,242,225,226,233, 99,128, 254,208,101, 3, 95,218, 95,239, 96, 0,237,233,228,228,236,229, 232,239,239,235,227,249,242,233,236,236,233, 99,128, 4,149,243, 244,242,239,235,229,227,249,242,233,236,236,233, 99,128, 4,147, 245,240,244,245,242,238,227,249,242,233,236,236,233, 99,128, 4, 145,232, 97, 2, 96, 24, 96, 31,228,229,246, 97,128, 9, 90,231, 245,242,237,245,235,232,105,128, 10, 90,239,239,107,128, 2, 96, 250,243,241,245,225,242,101,128, 51,147,105, 3, 96, 66, 96, 77, 96, 88,232,233,242,225,231,225,238, 97,128, 48, 78,235,225,244, 225,235,225,238, 97,128, 48,174,109, 2, 96, 94, 96,105,225,242, 237,229,238,233,225,110,128, 5, 99,229,108,130, 5,210, 96,114, 96,134,228,225,231,229,243,104,129,251, 50, 96,125,232,229,226, 242,229,119,128,251, 50,232,229,226,242,229,119,128, 5,210,234, 229,227,249,242,233,236,236,233, 99,128, 4, 83,236,239,244,244, 225,108, 2, 96,167, 96,184,233,238,246,229,242,244,229,228,243, 244,242,239,235,101,128, 1,190,243,244,239,112,132, 2,148, 96, 199, 96,210, 96,216, 96,248,233,238,246,229,242,244,229,100,128, 2,150,237,239,100,128, 2,192,242,229,246,229,242,243,229,100, 130, 2,149, 96,231, 96,237,237,239,100,128, 2,193,243,245,240, 229,242,233,239,114,128, 2,228,243,244,242,239,235,101,129, 2, 161, 97, 3,242,229,246,229,242,243,229,100,128, 2,162,109, 2, 97, 20, 97, 28,225,227,242,239,110,128, 30, 33,239,238,239,243, 240,225,227,101,128,255, 71,111, 2, 97, 45, 97, 56,232,233,242, 225,231,225,238, 97,128, 48, 84,235,225,244,225,235,225,238, 97, 128, 48,180,240, 97, 2, 97, 74, 97, 80,242,229,110,128, 36,162, 243,241,245,225,242,101,128, 51,172,114, 2, 97, 95, 97,192, 97, 2, 97,101, 97,109,228,233,229,238,116,128, 34, 7,246,101,134, 0, 96, 97,126, 97,137, 97,154, 97,161, 97,170, 97,182,226,229, 236,239,247,227,237, 98,128, 3, 22, 99, 2, 97,143, 97,148,237, 98,128, 3, 0,239,237, 98,128, 3, 0,228,229,246, 97,128, 9, 83,236,239,247,237,239,100,128, 2,206,237,239,238,239,243,240, 225,227,101,128,255, 64,244,239,238,229,227,237, 98,128, 3, 64, 229,225,244,229,114,132, 0, 62, 97,208, 97,227, 97,239, 98, 26, 229,241,245,225,108,129, 34,101, 97,218,239,242,236,229,243,115, 128, 34,219,237,239,238,239,243,240,225,227,101,128,255, 30,111, 2, 97,245, 98, 15,114, 2, 97,251, 98, 8,229,241,245,233,246, 225,236,229,238,116,128, 34,115,236,229,243,115,128, 34,119,246, 229,242,229,241,245,225,108,128, 34,103,243,237,225,236,108,128, 254,101,115, 2, 98, 40, 98, 48,227,242,233,240,116,128, 2, 97, 244,242,239,235,101,128, 1,229,117, 4, 98, 66, 98, 77, 98,134, 98,145,232,233,242,225,231,225,238, 97,128, 48, 80,233,108, 2, 98, 84, 98,109,236,229,237,239,116, 2, 98, 94, 98,101,236,229, 230,116,128, 0,171,242,233,231,232,116,128, 0,187,243,233,238, 231,108, 2, 98,119, 98,126,236,229,230,116,128, 32, 57,242,233, 231,232,116,128, 32, 58,235,225,244,225,235,225,238, 97,128, 48, 176,242,225,237,245,243,241,245,225,242,101,128, 51, 24,249,243, 241,245,225,242,101,128, 51,201,104,144, 0,104, 98,204,101, 90, 101,125,101,162,101,202,103, 90,103,110,104, 75,104, 87,104, 99, 105,167,105,175,105,186,105,195,106, 19,106, 23, 97, 13, 98,232, 99, 15, 99, 25, 99, 55, 99, 80, 99,158, 99,170, 99,195, 99,210, 99,239, 99,252,100, 54,100, 63, 97, 2, 98,238, 99, 1,226,235, 232,225,243,233,225,238,227,249,242,233,236,236,233, 99,128, 4, 169,236,244,239,238,229,225,242,225,226,233, 99,128, 6,193,226, 229,238,231,225,236,105,128, 9,185,228,101, 2, 99, 32, 99, 50, 243,227,229,238,228,229,242,227,249,242,233,236,236,233, 99,128, 4,179,246, 97,128, 9, 57,231,117, 2, 99, 62, 99, 71,234,225, 242,225,244,105,128, 10,185,242,237,245,235,232,105,128, 10, 57, 104, 4, 99, 90, 99, 99, 99,113, 99,143,225,242,225,226,233, 99, 128, 6, 45,230,233,238,225,236,225,242,225,226,233, 99,128,254, 162,105, 2, 99,119, 99,134,238,233,244,233,225,236,225,242,225, 226,233, 99,128,254,163,242,225,231,225,238, 97,128, 48,111,237, 229,228,233,225,236,225,242,225,226,233, 99,128,254,164,233,244, 245,243,241,245,225,242,101,128, 51, 42,235,225,244,225,235,225, 238, 97,129, 48,207, 99,183,232,225,236,230,247,233,228,244,104, 128,255,138,236,225,238,244,231,245,242,237,245,235,232,105,128, 10, 77,237,250, 97, 2, 99,218, 99,227,225,242,225,226,233, 99, 128, 6, 33,236,239,247,225,242,225,226,233, 99,128, 6, 33,238, 231,245,236,230,233,236,236,229,114,128, 49,100,114, 2,100, 2, 100, 18,228,243,233,231,238,227,249,242,233,236,236,233, 99,128, 4, 74,240,239,239,110, 2,100, 27,100, 40,236,229,230,244,226, 225,242,226,245,112,128, 33,188,242,233,231,232,244,226,225,242, 226,245,112,128, 33,192,243,241,245,225,242,101,128, 51,202,244, 225,102, 3,100, 73,100,165,101, 0,240,225,244,225,104,134, 5, 178,100, 93,100, 98,100,112,100,121,100,136,100,152,177, 54,128, 5,178, 50, 2,100,104,100,108, 51,128, 5,178,102,128, 5,178, 232,229,226,242,229,119,128, 5,178,238,225,242,242,239,247,232, 229,226,242,229,119,128, 5,178,241,245,225,242,244,229,242,232, 229,226,242,229,119,128, 5,178,247,233,228,229,232,229,226,242, 229,119,128, 5,178,241,225,237,225,244,115,135, 5,179,100,188, 100,193,100,198,100,203,100,212,100,227,100,243,177, 98,128, 5, 179,178, 56,128, 5,179,179, 52,128, 5,179,232,229,226,242,229, 119,128, 5,179,238,225,242,242,239,247,232,229,226,242,229,119, 128, 5,179,241,245,225,242,244,229,242,232,229,226,242,229,119, 128, 5,179,247,233,228,229,232,229,226,242,229,119,128, 5,179, 243,229,231,239,108,135, 5,177,101, 22,101, 27,101, 32,101, 37, 101, 46,101, 61,101, 77,177, 55,128, 5,177,178, 52,128, 5,177, 179, 48,128, 5,177,232,229,226,242,229,119,128, 5,177,238,225, 242,242,239,247,232,229,226,242,229,119,128, 5,177,241,245,225, 242,244,229,242,232,229,226,242,229,119,128, 5,177,247,233,228, 229,232,229,226,242,229,119,128, 5,177, 98, 3,101, 98,101,103, 101,113,225,114,128, 1, 39,239,240,239,237,239,230,111,128, 49, 15,242,229,246,229,226,229,236,239,119,128, 30, 43, 99, 2,101, 131,101,140,229,228,233,236,236, 97,128, 30, 41,233,242, 99, 2, 101,148,101,153,236,101,128, 36,215,245,237,230,236,229,120,128, 1, 37,100, 2,101,168,101,178,233,229,242,229,243,233,115,128, 30, 39,239,116, 2,101,185,101,194,225,227,227,229,238,116,128, 30, 35,226,229,236,239,119,128, 30, 37,101,136, 5,212,101,222, 101,255,102, 19,102,248,103, 8,103, 53,103, 62,103, 75,225,242, 116,129, 38,101,101,230,243,245,233,116, 2,101,239,101,247,226, 236,225,227,107,128, 38,101,247,232,233,244,101,128, 38, 97,228, 225,231,229,243,104,129,251, 52,102, 10,232,229,226,242,229,119, 128,251, 52,104, 6,102, 33,102, 61,102, 69,102,119,102,165,102, 214, 97, 2,102, 39,102, 53,236,244,239,238,229,225,242,225,226, 233, 99,128, 6,193,242,225,226,233, 99,128, 6, 71,229,226,242, 229,119,128, 5,212,230,233,238,225,236, 97, 2,102, 80,102,111, 236,116, 2,102, 87,102, 99,239,238,229,225,242,225,226,233, 99, 128,251,167,244,247,239,225,242,225,226,233, 99,128,254,234,242, 225,226,233, 99,128,254,234,232,225,237,250,225,225,226,239,246, 101, 2,102,134,102,148,230,233,238,225,236,225,242,225,226,233, 99,128,251,165,233,243,239,236,225,244,229,228,225,242,225,226, 233, 99,128,251,164,105, 2,102,171,102,205,238,233,244,233,225, 236, 97, 2,102,183,102,197,236,244,239,238,229,225,242,225,226, 233, 99,128,251,168,242,225,226,233, 99,128,254,235,242,225,231, 225,238, 97,128, 48,120,237,229,228,233,225,236, 97, 2,102,226, 102,240,236,244,239,238,229,225,242,225,226,233, 99,128,251,169, 242,225,226,233, 99,128,254,236,233,243,229,233,229,242,225,243, 241,245,225,242,101,128, 51,123,107, 2,103, 14,103, 38,225,244, 225,235,225,238, 97,129, 48,216,103, 26,232,225,236,230,247,233, 228,244,104,128,255,141,245,244,225,225,242,245,243,241,245,225, 242,101,128, 51, 54,238,231,232,239,239,107,128, 2,103,242,245, 244,245,243,241,245,225,242,101,128, 51, 57,116,129, 5,215,103, 81,232,229,226,242,229,119,128, 5,215,232,239,239,107,129, 2, 102,103, 99,243,245,240,229,242,233,239,114,128, 2,177,105, 4, 103,120,103,205,103,216,103,241,229,245,104, 4,103,132,103,167, 103,182,103,191, 97, 2,103,138,103,153,227,233,242,227,236,229, 235,239,242,229,225,110,128, 50,123,240,225,242,229,238,235,239, 242,229,225,110,128, 50, 27,227,233,242,227,236,229,235,239,242, 229,225,110,128, 50,109,235,239,242,229,225,110,128, 49, 78,240, 225,242,229,238,235,239,242,229,225,110,128, 50, 13,232,233,242, 225,231,225,238, 97,128, 48,114,235,225,244,225,235,225,238, 97, 129, 48,210,103,229,232,225,236,230,247,233,228,244,104,128,255, 139,242,233,113,134, 5,180,104, 3,104, 8,104, 22,104, 31,104, 46,104, 62,177, 52,128, 5,180, 50, 2,104, 14,104, 18, 49,128, 5,180,100,128, 5,180,232,229,226,242,229,119,128, 5,180,238, 225,242,242,239,247,232,229,226,242,229,119,128, 5,180,241,245, 225,242,244,229,242,232,229,226,242,229,119,128, 5,180,247,233, 228,229,232,229,226,242,229,119,128, 5,180,236,233,238,229,226, 229,236,239,119,128, 30,150,237,239,238,239,243,240,225,227,101, 128,255, 72,111, 9,104,119,104,130,104,154,104,179,105, 11,105, 24,105,110,105,150,105,161,225,242,237,229,238,233,225,110,128, 5,112,232,105, 2,104,137,104,145,240,244,232,225,105,128, 14, 43,242,225,231,225,238, 97,128, 48,123,235,225,244,225,235,225, 238, 97,129, 48,219,104,167,232,225,236,230,247,233,228,244,104, 128,255,142,236,225,109,135, 5,185,104,199,104,204,104,209,104, 214,104,223,104,238,104,254,177, 57,128, 5,185,178, 54,128, 5, 185,179, 50,128, 5,185,232,229,226,242,229,119,128, 5,185,238, 225,242,242,239,247,232,229,226,242,229,119,128, 5,185,241,245, 225,242,244,229,242,232,229,226,242,229,119,128, 5,185,247,233, 228,229,232,229,226,242,229,119,128, 5,185,238,239,235,232,245, 235,244,232,225,105,128, 14, 46,111, 2,105, 30,105,100,107, 4, 105, 40,105, 52,105, 58,105, 80,225,226,239,246,229,227,239,237, 98,128, 3, 9,227,237, 98,128, 3, 9,240,225,236,225,244,225, 236,233,250,229,228,226,229,236,239,247,227,237, 98,128, 3, 33, 242,229,244,242,239,230,236,229,248,226,229,236,239,247,227,237, 98,128, 3, 34,238,243,241,245,225,242,101,128, 51, 66,114, 2, 105,116,105,143,105, 2,105,122,105,131,227,239,240,244,233, 99, 128, 3,233,250,239,238,244,225,236,226,225,114,128, 32, 21,238, 227,237, 98,128, 3, 27,244,243,240,242,233,238,231,115,128, 38, 104,245,243,101,128, 35, 2,240,225,242,229,110,128, 36,163,243, 245,240,229,242,233,239,114,128, 2,176,244,245,242,238,229,100, 128, 2,101,117, 4,105,205,105,216,105,229,105,254,232,233,242, 225,231,225,238, 97,128, 48,117,233,233,244,239,243,241,245,225, 242,101,128, 51, 51,235,225,244,225,235,225,238, 97,129, 48,213, 105,242,232,225,236,230,247,233,228,244,104,128,255,140,238,231, 225,242,245,237,236,225,245,116,129, 2,221,106, 13,227,237, 98, 128, 3, 11,118,128, 1,149,249,240,232,229,110,132, 0, 45,106, 39,106, 50,106, 62,106, 85,233,238,230,229,242,233,239,114,128, 246,229,237,239,238,239,243,240,225,227,101,128,255, 13,115, 2, 106, 68,106, 75,237,225,236,108,128,254, 99,245,240,229,242,233, 239,114,128,246,230,244,247,111,128, 32, 16,105,149, 0,105,106, 137,106,160,106,194,106,241,110,123,110,243,111, 24,111, 51,111, 213,111,217,111,255,112, 21,112,105,113, 14,113, 89,113, 97,113, 110,113,197,113,254,114, 26,114, 70,225, 99, 2,106,144,106,150, 245,244,101,128, 0,237,249,242,233,236,236,233, 99,128, 4, 79, 98, 3,106,168,106,177,106,187,229,238,231,225,236,105,128, 9, 135,239,240,239,237,239,230,111,128, 49, 39,242,229,246,101,128, 1, 45, 99, 3,106,202,106,209,106,231,225,242,239,110,128, 1, 208,233,242, 99, 2,106,217,106,222,236,101,128, 36,216,245,237, 230,236,229,120,128, 0,238,249,242,233,236,236,233, 99,128, 4, 86,100, 4,106,251,107, 5,110, 80,110,113,226,236,231,242,225, 246,101,128, 2, 9,101, 2,107, 11,110, 75,239,231,242,225,240, 104, 7,107, 32,107, 46,107, 59,109,244,110, 19,110, 32,110, 44, 229,225,242,244,232,227,233,242,227,236,101,128, 50,143,230,233, 242,229,227,233,242,227,236,101,128, 50,139,233, 99, 14,107, 90, 107,106,107,205,108, 3,108, 69,108, 98,108,114,108,171,108,220, 108,232,109, 3,109, 70,109,208,109,237,225,236,236,233,225,238, 227,229,240,225,242,229,110,128, 50, 63, 99, 4,107,116,107,127, 107,141,107,148,225,236,236,240,225,242,229,110,128, 50, 58,229, 238,244,242,229,227,233,242,227,236,101,128, 50,165,236,239,243, 101,128, 48, 6,111, 3,107,156,107,171,107,191,237,237, 97,129, 48, 1,107,164,236,229,230,116,128,255,100,238,231,242,225,244, 245,236,225,244,233,239,238,240,225,242,229,110,128, 50, 55,242, 242,229,227,244,227,233,242,227,236,101,128, 50,163,101, 3,107, 213,107,225,107,242,225,242,244,232,240,225,242,229,110,128, 50, 47,238,244,229,242,240,242,233,243,229,240,225,242,229,110,128, 50, 61,248,227,229,236,236,229,238,244,227,233,242,227,236,101, 128, 50,157,102, 2,108, 9,108, 24,229,243,244,233,246,225,236, 240,225,242,229,110,128, 50, 64,105, 2,108, 30,108, 59,238,225, 238,227,233,225,108, 2,108, 42,108, 51,227,233,242,227,236,101, 128, 50,150,240,225,242,229,110,128, 50, 54,242,229,240,225,242, 229,110,128, 50, 43,104, 2,108, 75,108, 86,225,246,229,240,225, 242,229,110,128, 50, 50,233,231,232,227,233,242,227,236,101,128, 50,164,233,244,229,242,225,244,233,239,238,237,225,242,107,128, 48, 5,108, 3,108,122,108,148,108,160,225,226,239,114, 2,108, 131,108,140,227,233,242,227,236,101,128, 50,152,240,225,242,229, 110,128, 50, 56,229,230,244,227,233,242,227,236,101,128, 50,167, 239,247,227,233,242,227,236,101,128, 50,166,109, 2,108,177,108, 209,101, 2,108,183,108,198,228,233,227,233,238,229,227,233,242, 227,236,101,128, 50,169,244,225,236,240,225,242,229,110,128, 50, 46,239,239,238,240,225,242,229,110,128, 50, 42,238,225,237,229, 240,225,242,229,110,128, 50, 52,112, 2,108,238,108,246,229,242, 233,239,100,128, 48, 2,242,233,238,244,227,233,242,227,236,101, 128, 50,158,114, 2,109, 9,109, 57,101, 3,109, 17,109, 28,109, 43,225,227,232,240,225,242,229,110,128, 50, 67,240,242,229,243, 229,238,244,240,225,242,229,110,128, 50, 57,243,239,245,242,227, 229,240,225,242,229,110,128, 50, 62,233,231,232,244,227,233,242, 227,236,101,128, 50,168,115, 5,109, 82,109,111,109,125,109,150, 109,178,101, 2,109, 88,109,101,227,242,229,244,227,233,242,227, 236,101,128, 50,153,236,230,240,225,242,229,110,128, 50, 66,239, 227,233,229,244,249,240,225,242,229,110,128, 50, 51,112, 2,109, 131,109,137,225,227,101,128, 48, 0,229,227,233,225,236,240,225, 242,229,110,128, 50, 53,116, 2,109,156,109,167,239,227,235,240, 225,242,229,110,128, 50, 49,245,228,249,240,225,242,229,110,128, 50, 59,117, 2,109,184,109,193,238,240,225,242,229,110,128, 50, 48,240,229,242,246,233,243,229,240,225,242,229,110,128, 50, 60, 119, 2,109,214,109,226,225,244,229,242,240,225,242,229,110,128, 50, 44,239,239,228,240,225,242,229,110,128, 50, 45,250,229,242, 111,128, 48, 7,109, 2,109,250,110, 7,229,244,225,236,227,233, 242,227,236,101,128, 50,142,239,239,238,227,233,242,227,236,101, 128, 50,138,238,225,237,229,227,233,242,227,236,101,128, 50,148, 243,245,238,227,233,242,227,236,101,128, 50,144,119, 2,110, 50, 110, 63,225,244,229,242,227,233,242,227,236,101,128, 50,140,239, 239,228,227,233,242,227,236,101,128, 50,141,246, 97,128, 9, 7, 233,229,242,229,243,233,115,130, 0,239,110, 94,110,102,225,227, 245,244,101,128, 30, 47,227,249,242,233,236,236,233, 99,128, 4, 229,239,244,226,229,236,239,119,128, 30,203,101, 3,110,131,110, 147,110,158,226,242,229,246,229,227,249,242,233,236,236,233, 99, 128, 4,215,227,249,242,233,236,236,233, 99,128, 4, 53,245,238, 103, 4,110,170,110,205,110,220,110,229, 97, 2,110,176,110,191, 227,233,242,227,236,229,235,239,242,229,225,110,128, 50,117,240, 225,242,229,238,235,239,242,229,225,110,128, 50, 21,227,233,242, 227,236,229,235,239,242,229,225,110,128, 50,103,235,239,242,229, 225,110,128, 49, 71,240,225,242,229,238,235,239,242,229,225,110, 128, 50, 7,103, 2,110,249,111, 0,242,225,246,101,128, 0,236, 117, 2,111, 6,111, 15,234,225,242,225,244,105,128, 10,135,242, 237,245,235,232,105,128, 10, 7,104, 2,111, 30,111, 40,233,242, 225,231,225,238, 97,128, 48, 68,239,239,235,225,226,239,246,101, 128, 30,201,105, 8,111, 69,111, 79,111, 90,111, 97,111,122,111, 138,111,153,111,169,226,229,238,231,225,236,105,128, 9,136,227, 249,242,233,236,236,233, 99,128, 4, 56,228,229,246, 97,128, 9, 8,231,117, 2,111,104,111,113,234,225,242,225,244,105,128, 10, 136,242,237,245,235,232,105,128, 10, 8,237,225,244,242,225,231, 245,242,237,245,235,232,105,128, 10, 64,238,246,229,242,244,229, 228,226,242,229,246,101,128, 2, 11,243,232,239,242,244,227,249, 242,233,236,236,233, 99,128, 4, 57,246,239,247,229,236,243,233, 231,110, 3,111,185,111,195,111,202,226,229,238,231,225,236,105, 128, 9,192,228,229,246, 97,128, 9, 64,231,245,234,225,242,225, 244,105,128, 10,192,106,128, 1, 51,107, 2,111,223,111,247,225, 244,225,235,225,238, 97,129, 48,164,111,235,232,225,236,230,247, 233,228,244,104,128,255,114,239,242,229,225,110,128, 49, 99,108, 2,112, 5,112, 10,228,101,128, 2,220,245,249,232,229,226,242, 229,119,128, 5,172,109, 2,112, 27,112, 94, 97, 3,112, 35,112, 55,112, 80,227,242,239,110,129, 1, 43,112, 44,227,249,242,233, 236,236,233, 99,128, 4,227,231,229,239,242,225,240,240,242,239, 248,233,237,225,244,229,236,249,229,241,245,225,108,128, 34, 83, 244,242,225,231,245,242,237,245,235,232,105,128, 10, 63,239,238, 239,243,240,225,227,101,128,255, 73,110, 5,112,117,112,127,112, 136,112,148,112,232,227,242,229,237,229,238,116,128, 34, 6,230, 233,238,233,244,121,128, 34, 30,233,225,242,237,229,238,233,225, 110,128, 5,107,116, 2,112,154,112,222,101, 2,112,160,112,211, 231,242,225,108,131, 34, 43,112,173,112,191,112,196, 98, 2,112, 179,112,187,239,244,244,239,109,128, 35, 33,116,128, 35, 33,229, 120,128,248,245,116, 2,112,202,112,207,239,112,128, 35, 32,112, 128, 35, 32,242,243,229,227,244,233,239,110,128, 34, 41,233,243, 241,245,225,242,101,128, 51, 5,118, 3,112,240,112,249,113, 2, 226,245,236,236,229,116,128, 37,216,227,233,242,227,236,101,128, 37,217,243,237,233,236,229,230,225,227,101,128, 38, 59,111, 3, 113, 22,113, 33,113, 41,227,249,242,233,236,236,233, 99,128, 4, 81,231,239,238,229,107,128, 1, 47,244, 97,131, 3,185,113, 52, 113, 73,113, 81,228,233,229,242,229,243,233,115,129, 3,202,113, 65,244,239,238,239,115,128, 3,144,236,225,244,233,110,128, 2, 105,244,239,238,239,115,128, 3,175,240,225,242,229,110,128, 36, 164,242,233,231,245,242,237,245,235,232,105,128, 10,114,115, 4, 113,120,113,165,113,179,113,187,237,225,236,108, 2,113,129,113, 140,232,233,242,225,231,225,238, 97,128, 48, 67,235,225,244,225, 235,225,238, 97,129, 48,163,113,153,232,225,236,230,247,233,228, 244,104,128,255,104,243,232,225,242,226,229,238,231,225,236,105, 128, 9,250,244,242,239,235,101,128, 2,104,245,240,229,242,233, 239,114,128,246,237,116, 2,113,203,113,237,229,242,225,244,233, 239,110, 2,113,215,113,226,232,233,242,225,231,225,238, 97,128, 48,157,235,225,244,225,235,225,238, 97,128, 48,253,233,236,228, 101,129, 1, 41,113,246,226,229,236,239,119,128, 30, 45,117, 2, 114, 4,114, 15,226,239,240,239,237,239,230,111,128, 49, 41,227, 249,242,233,236,236,233, 99,128, 4, 78,246,239,247,229,236,243, 233,231,110, 3,114, 42,114, 52,114, 59,226,229,238,231,225,236, 105,128, 9,191,228,229,246, 97,128, 9, 63,231,245,234,225,242, 225,244,105,128, 10,191,250,232,233,244,243, 97, 2,114, 81,114, 92,227,249,242,233,236,236,233, 99,128, 4,117,228,226,236,231, 242,225,246,229,227,249,242,233,236,236,233, 99,128, 4,119,106, 138, 0,106,114,135,114,198,114,209,115, 3,115, 19,115,132,115, 201,115,206,115,218,115,226, 97, 4,114,145,114,156,114,166,114, 173,225,242,237,229,238,233,225,110,128, 5,113,226,229,238,231, 225,236,105,128, 9,156,228,229,246, 97,128, 9, 28,231,117, 2, 114,180,114,189,234,225,242,225,244,105,128, 10,156,242,237,245, 235,232,105,128, 10, 28,226,239,240,239,237,239,230,111,128, 49, 16, 99, 3,114,217,114,224,114,246,225,242,239,110,128, 1,240, 233,242, 99, 2,114,232,114,237,236,101,128, 36,217,245,237,230, 236,229,120,128, 1, 53,242,239,243,243,229,228,244,225,233,108, 128, 2,157,228,239,244,236,229,243,243,243,244,242,239,235,101, 128, 2, 95,101, 3,115, 27,115, 38,115,103,227,249,242,233,236, 236,233, 99,128, 4, 88,229,109, 4,115, 49,115, 58,115, 72,115, 88,225,242,225,226,233, 99,128, 6, 44,230,233,238,225,236,225, 242,225,226,233, 99,128,254,158,233,238,233,244,233,225,236,225, 242,225,226,233, 99,128,254,159,237,229,228,233,225,236,225,242, 225,226,233, 99,128,254,160,104, 2,115,109,115,118,225,242,225, 226,233, 99,128, 6,152,230,233,238,225,236,225,242,225,226,233, 99,128,251,139,104, 2,115,138,115,188, 97, 3,115,146,115,156, 115,163,226,229,238,231,225,236,105,128, 9,157,228,229,246, 97, 128, 9, 29,231,117, 2,115,170,115,179,234,225,242,225,244,105, 128, 10,157,242,237,245,235,232,105,128, 10, 29,229,232,225,242, 237,229,238,233,225,110,128, 5,123,233,115,128, 48, 4,237,239, 238,239,243,240,225,227,101,128,255, 74,240,225,242,229,110,128, 36,165,243,245,240,229,242,233,239,114,128, 2,178,107,146, 0, 107,116, 21,118,110,118,121,118,183,118,194,119, 28,119, 42,120, 150,121, 90,121,103,121,129,121,178,122, 60,122, 82,122, 95,122, 118,122,160,122,170, 97, 12,116, 47,116, 79,116,101,116,131,116, 245,117, 14,117, 44,117, 69,117,175,117,189,118, 56,118, 85, 98, 2,116, 53,116, 70,225,243,232,235,233,242,227,249,242,233,236, 236,233, 99,128, 4,161,229,238,231,225,236,105,128, 9,149, 99, 2,116, 85,116, 91,245,244,101,128, 30, 49,249,242,233,236,236, 233, 99,128, 4, 58,228,101, 2,116,108,116,126,243,227,229,238, 228,229,242,227,249,242,233,236,236,233, 99,128, 4,155,246, 97, 128, 9, 21,102,135, 5,219,116,149,116,158,116,178,116,192,116, 201,116,217,116,232,225,242,225,226,233, 99,128, 6, 67,228,225, 231,229,243,104,129,251, 59,116,169,232,229,226,242,229,119,128, 251, 59,230,233,238,225,236,225,242,225,226,233, 99,128,254,218, 232,229,226,242,229,119,128, 5,219,233,238,233,244,233,225,236, 225,242,225,226,233, 99,128,254,219,237,229,228,233,225,236,225, 242,225,226,233, 99,128,254,220,242,225,230,229,232,229,226,242, 229,119,128,251, 77,231,117, 2,116,252,117, 5,234,225,242,225, 244,105,128, 10,149,242,237,245,235,232,105,128, 10, 21,104, 2, 117, 20,117, 30,233,242,225,231,225,238, 97,128, 48, 75,239,239, 235,227,249,242,233,236,236,233, 99,128, 4,196,235,225,244,225, 235,225,238, 97,129, 48,171,117, 57,232,225,236,230,247,233,228, 244,104,128,255,118,112, 2,117, 75,117, 96,240, 97,129, 3,186, 117, 82,243,249,237,226,239,236,231,242,229,229,107,128, 3,240, 249,229,239,245,110, 3,117,108,117,122,117,156,237,233,229,245, 237,235,239,242,229,225,110,128, 49,113,112, 2,117,128,117,143, 232,233,229,245,240,232,235,239,242,229,225,110,128, 49,132,233, 229,245,240,235,239,242,229,225,110,128, 49,120,243,243,225,238, 231,240,233,229,245,240,235,239,242,229,225,110,128, 49,121,242, 239,242,233,233,243,241,245,225,242,101,128, 51, 13,115, 5,117, 201,117,245,118, 4,118, 12,118, 40,232,233,228,225,225,245,244, 111, 2,117,214,117,223,225,242,225,226,233, 99,128, 6, 64,238, 239,243,233,228,229,226,229,225,242,233,238,231,225,242,225,226, 233, 99,128, 6, 64,237,225,236,236,235,225,244,225,235,225,238, 97,128, 48,245,241,245,225,242,101,128, 51,132,242, 97, 2,118, 19,118, 28,225,242,225,226,233, 99,128, 6, 80,244,225,238,225, 242,225,226,233, 99,128, 6, 77,244,242,239,235,229,227,249,242, 233,236,236,233, 99,128, 4,159,244,225,232,233,242,225,240,242, 239,236,239,238,231,237,225,242,235,232,225,236,230,247,233,228, 244,104,128,255,112,246,229,242,244,233,227,225,236,243,244,242, 239,235,229,227,249,242,233,236,236,233, 99,128, 4,157,226,239, 240,239,237,239,230,111,128, 49, 14, 99, 4,118,131,118,153,118, 162,118,170, 97, 2,118,137,118,147,236,243,241,245,225,242,101, 128, 51,137,242,239,110,128, 1,233,229,228,233,236,236, 97,128, 1, 55,233,242,227,236,101,128, 36,218,239,237,237,225,225,227, 227,229,238,116,128, 1, 55,228,239,244,226,229,236,239,119,128, 30, 51,101, 4,118,204,118,231,119, 0,119, 12,104, 2,118,210, 118,221,225,242,237,229,238,233,225,110,128, 5,132,233,242,225, 231,225,238, 97,128, 48, 81,235,225,244,225,235,225,238, 97,129, 48,177,118,244,232,225,236,230,247,233,228,244,104,128,255,121, 238,225,242,237,229,238,233,225,110,128, 5,111,243,237,225,236, 236,235,225,244,225,235,225,238, 97,128, 48,246,231,242,229,229, 238,236,225,238,228,233, 99,128, 1, 56,104, 6,119, 56,119,185, 119,196,119,221,120, 52,120,140, 97, 5,119, 68,119, 78,119, 89, 119, 96,119,121,226,229,238,231,225,236,105,128, 9,150,227,249, 242,233,236,236,233, 99,128, 4, 69,228,229,246, 97,128, 9, 22, 231,117, 2,119,103,119,112,234,225,242,225,244,105,128, 10,150, 242,237,245,235,232,105,128, 10, 22,104, 4,119,131,119,140,119, 154,119,170,225,242,225,226,233, 99,128, 6, 46,230,233,238,225, 236,225,242,225,226,233, 99,128,254,166,233,238,233,244,233,225, 236,225,242,225,226,233, 99,128,254,167,237,229,228,233,225,236, 225,242,225,226,233, 99,128,254,168,229,233,227,239,240,244,233, 99,128, 3,231,232, 97, 2,119,203,119,210,228,229,246, 97,128, 9, 89,231,245,242,237,245,235,232,105,128, 10, 89,233,229,245, 235,104, 4,119,235,120, 14,120, 29,120, 38, 97, 2,119,241,120, 0,227,233,242,227,236,229,235,239,242,229,225,110,128, 50,120, 240,225,242,229,238,235,239,242,229,225,110,128, 50, 24,227,233, 242,227,236,229,235,239,242,229,225,110,128, 50,106,235,239,242, 229,225,110,128, 49, 75,240,225,242,229,238,235,239,242,229,225, 110,128, 50, 10,111, 4,120, 62,120,111,120,121,120,126,235,104, 4,120, 73,120, 82,120, 91,120,101,225,233,244,232,225,105,128, 14, 2,239,238,244,232,225,105,128, 14, 5,245,225,244,244,232, 225,105,128, 14, 3,247,225,233,244,232,225,105,128, 14, 4,237, 245,244,244,232,225,105,128, 14, 91,239,107,128, 1,153,242,225, 235,232,225,238,231,244,232,225,105,128, 14, 6,250,243,241,245, 225,242,101,128, 51,145,105, 4,120,160,120,171,120,196,120,245, 232,233,242,225,231,225,238, 97,128, 48, 77,235,225,244,225,235, 225,238, 97,129, 48,173,120,184,232,225,236,230,247,233,228,244, 104,128,255,119,242,111, 3,120,205,120,220,120,236,231,245,242, 225,237,245,243,241,245,225,242,101,128, 51, 21,237,229,229,244, 239,242,245,243,241,245,225,242,101,128, 51, 22,243,241,245,225, 242,101,128, 51, 20,249,229,239,107, 5,121, 4,121, 39,121, 54, 121, 63,121, 77, 97, 2,121, 10,121, 25,227,233,242,227,236,229, 235,239,242,229,225,110,128, 50,110,240,225,242,229,238,235,239, 242,229,225,110,128, 50, 14,227,233,242,227,236,229,235,239,242, 229,225,110,128, 50, 96,235,239,242,229,225,110,128, 49, 49,240, 225,242,229,238,235,239,242,229,225,110,128, 50, 0,243,233,239, 243,235,239,242,229,225,110,128, 49, 51,234,229,227,249,242,233, 236,236,233, 99,128, 4, 92,108, 2,121,109,121,120,233,238,229, 226,229,236,239,119,128, 30, 53,243,241,245,225,242,101,128, 51, 152,109, 3,121,137,121,151,121,162,227,245,226,229,228,243,241, 245,225,242,101,128, 51,166,239,238,239,243,240,225,227,101,128, 255, 75,243,241,245,225,242,229,228,243,241,245,225,242,101,128, 51,162,111, 5,121,190,121,216,121,254,122, 10,122, 24,104, 2, 121,196,121,206,233,242,225,231,225,238, 97,128, 48, 83,237,243, 241,245,225,242,101,128, 51,192,235, 97, 2,121,223,121,231,233, 244,232,225,105,128, 14, 1,244,225,235,225,238, 97,129, 48,179, 121,242,232,225,236,230,247,233,228,244,104,128,255,122,239,240, 239,243,241,245,225,242,101,128, 51, 30,240,240,225,227,249,242, 233,236,236,233, 99,128, 4,129,114, 2,122, 30,122, 50,229,225, 238,243,244,225,238,228,225,242,228,243,249,237,226,239,108,128, 50,127,239,238,233,243,227,237, 98,128, 3, 67,240, 97, 2,122, 67,122, 73,242,229,110,128, 36,166,243,241,245,225,242,101,128, 51,170,243,233,227,249,242,233,236,236,233, 99,128, 4,111,116, 2,122,101,122,110,243,241,245,225,242,101,128, 51,207,245,242, 238,229,100,128, 2,158,117, 2,122,124,122,135,232,233,242,225, 231,225,238, 97,128, 48, 79,235,225,244,225,235,225,238, 97,129, 48,175,122,148,232,225,236,230,247,233,228,244,104,128,255,120, 246,243,241,245,225,242,101,128, 51,184,247,243,241,245,225,242, 101,128, 51,190,108,146, 0,108,122,220,124,247,125, 20,125, 86, 125,124,126, 20,126, 29,126, 45,126, 69,126, 87,126,205,126,246, 127,125,127,133,127,166,127,175,127,183,127,245, 97, 7,122,236, 122,246,122,253,123, 4,123, 29,123, 45,124,235,226,229,238,231, 225,236,105,128, 9,178,227,245,244,101,128, 1, 58,228,229,246, 97,128, 9, 50,231,117, 2,123, 11,123, 20,234,225,242,225,244, 105,128, 10,178,242,237,245,235,232,105,128, 10, 50,235,235,232, 225,238,231,249,225,239,244,232,225,105,128, 14, 69,109, 10,123, 67,124, 6,124, 23,124, 61,124, 75,124, 94,124,110,124,130,124, 150,124,173, 97, 2,123, 73,123,254,236,229,102, 4,123, 85,123, 99,123,191,123,208,230,233,238,225,236,225,242,225,226,233, 99, 128,254,252,232,225,237,250, 97, 2,123,109,123,150,225,226,239, 246,101, 2,123,119,123,133,230,233,238,225,236,225,242,225,226, 233, 99,128,254,248,233,243,239,236,225,244,229,228,225,242,225, 226,233, 99,128,254,247,226,229,236,239,119, 2,123,160,123,174, 230,233,238,225,236,225,242,225,226,233, 99,128,254,250,233,243, 239,236,225,244,229,228,225,242,225,226,233, 99,128,254,249,233, 243,239,236,225,244,229,228,225,242,225,226,233, 99,128,254,251, 237,225,228,228,225,225,226,239,246,101, 2,123,223,123,237,230, 233,238,225,236,225,242,225,226,233, 99,128,254,246,233,243,239, 236,225,244,229,228,225,242,225,226,233, 99,128,254,245,242,225, 226,233, 99,128, 6, 68,226,228, 97,129, 3,187,124, 14,243,244, 242,239,235,101,128, 1,155,229,100,130, 5,220,124, 32,124, 52, 228,225,231,229,243,104,129,251, 60,124, 43,232,229,226,242,229, 119,128,251, 60,232,229,226,242,229,119,128, 5,220,230,233,238, 225,236,225,242,225,226,233, 99,128,254,222,232,225,232,233,238, 233,244,233,225,236,225,242,225,226,233, 99,128,252,202,233,238, 233,244,233,225,236,225,242,225,226,233, 99,128,254,223,234,229, 229,237,233,238,233,244,233,225,236,225,242,225,226,233, 99,128, 252,201,235,232,225,232,233,238,233,244,233,225,236,225,242,225, 226,233, 99,128,252,203,236,225,237,232,229,232,233,243,239,236, 225,244,229,228,225,242,225,226,233, 99,128,253,242,237,101, 2, 124,180,124,193,228,233,225,236,225,242,225,226,233, 99,128,254, 224,229,109, 2,124,200,124,219,232,225,232,233,238,233,244,233, 225,236,225,242,225,226,233, 99,128,253,136,233,238,233,244,233, 225,236,225,242,225,226,233, 99,128,252,204,242,231,229,227,233, 242,227,236,101,128, 37,239, 98, 3,124,255,125, 4,125, 10,225, 114,128, 1,154,229,236,116,128, 2,108,239,240,239,237,239,230, 111,128, 49, 12, 99, 4,125, 30,125, 37,125, 46,125, 73,225,242, 239,110,128, 1, 62,229,228,233,236,236, 97,128, 1, 60,233,242, 99, 2,125, 54,125, 59,236,101,128, 36,219,245,237,230,236,229, 248,226,229,236,239,119,128, 30, 61,239,237,237,225,225,227,227, 229,238,116,128, 1, 60,228,239,116,130, 1, 64,125, 96,125,105, 225,227,227,229,238,116,128, 1, 64,226,229,236,239,119,129, 30, 55,125,115,237,225,227,242,239,110,128, 30, 57,101, 3,125,132, 125,170,126, 15,230,116, 2,125,139,125,155,225,238,231,236,229, 225,226,239,246,229,227,237, 98,128, 3, 26,244,225,227,235,226, 229,236,239,247,227,237, 98,128, 3, 24,243,115,132, 0, 60,125, 183,125,205,125,217,126, 7,229,241,245,225,108,129, 34,100,125, 193,239,242,231,242,229,225,244,229,114,128, 34,218,237,239,238, 239,243,240,225,227,101,128,255, 28,111, 2,125,223,125,252,114, 2,125,229,125,242,229,241,245,233,246,225,236,229,238,116,128, 34,114,231,242,229,225,244,229,114,128, 34,118,246,229,242,229, 241,245,225,108,128, 34,102,243,237,225,236,108,128,254,100,250, 104,128, 2,110,230,226,236,239,227,107,128, 37,140,232,239,239, 235,242,229,244,242,239,230,236,229,120,128, 2,109,105, 2,126, 51,126, 56,242, 97,128, 32,164,247,238,225,242,237,229,238,233, 225,110,128, 5,108,106,129, 1,201,126, 75,229,227,249,242,233, 236,236,233, 99,128, 4, 89,108,132,246,192,126, 99,126,123,126, 134,126,143, 97, 2,126,105,126,112,228,229,246, 97,128, 9, 51, 231,245,234,225,242,225,244,105,128, 10,179,233,238,229,226,229, 236,239,119,128, 30, 59,236,225,228,229,246, 97,128, 9, 52,246, 239,227,225,236,233, 99, 3,126,157,126,167,126,174,226,229,238, 231,225,236,105,128, 9,225,228,229,246, 97,128, 9, 97,246,239, 247,229,236,243,233,231,110, 2,126,188,126,198,226,229,238,231, 225,236,105,128, 9,227,228,229,246, 97,128, 9, 99,109, 3,126, 213,126,226,126,237,233,228,228,236,229,244,233,236,228,101,128, 2,107,239,238,239,243,240,225,227,101,128,255, 76,243,241,245, 225,242,101,128, 51,208,111, 6,127, 4,127, 16,127, 58,127, 69, 127, 75,127,117,227,232,245,236,225,244,232,225,105,128, 14, 44, 231,233,227,225,108, 3,127, 28,127, 34,127, 53,225,238,100,128, 34, 39,238,239,116,129, 0,172,127, 42,242,229,246,229,242,243, 229,100,128, 35, 16,239,114,128, 34, 40,236,233,238,231,244,232, 225,105,128, 14, 37,238,231,115,128, 1,127,247,236,233,238,101, 2,127, 85,127,108, 99, 2,127, 91,127,103,229,238,244,229,242, 236,233,238,101,128,254, 78,237, 98,128, 3, 50,228,225,243,232, 229,100,128,254, 77,250,229,238,231,101,128, 37,202,240,225,242, 229,110,128, 36,167,115, 3,127,141,127,148,127,156,236,225,243, 104,128, 1, 66,241,245,225,242,101,128, 33, 19,245,240,229,242, 233,239,114,128,246,238,244,243,232,225,228,101,128, 37,145,245, 244,232,225,105,128, 14, 38,246,239,227,225,236,233, 99, 3,127, 197,127,207,127,214,226,229,238,231,225,236,105,128, 9,140,228, 229,246, 97,128, 9, 12,246,239,247,229,236,243,233,231,110, 2, 127,228,127,238,226,229,238,231,225,236,105,128, 9,226,228,229, 246, 97,128, 9, 98,248,243,241,245,225,242,101,128, 51,211,109, 144, 0,109,128, 35,130,144,130,169,130,196,130,221,132, 18,132, 40,133, 95,133,125,133,174,134, 25,134, 47,134, 72,134, 81,135, 108,135,136, 97, 12,128, 61,128, 71,128,135,128,142,128,167,128, 215,130, 51,130, 76,130, 81,130, 95,130,107,130,112,226,229,238, 231,225,236,105,128, 9,174, 99, 2,128, 77,128,129,242,239,110, 132, 0,175,128, 91,128,102,128,108,128,117,226,229,236,239,247, 227,237, 98,128, 3, 49,227,237, 98,128, 3, 4,236,239,247,237, 239,100,128, 2,205,237,239,238,239,243,240,225,227,101,128,255, 227,245,244,101,128, 30, 63,228,229,246, 97,128, 9, 46,231,117, 2,128,149,128,158,234,225,242,225,244,105,128, 10,174,242,237, 245,235,232,105,128, 10, 46,104, 2,128,173,128,205,225,240,225, 235,104, 2,128,183,128,192,232,229,226,242,229,119,128, 5,164, 236,229,230,244,232,229,226,242,229,119,128, 5,164,233,242,225, 231,225,238, 97,128, 48,126,105, 5,128,227,129, 40,129,103,129, 133,130, 39,227,232,225,244,244,225,247, 97, 3,128,242,129, 17, 129, 24,236,239,119, 2,128,250,129, 5,236,229,230,244,244,232, 225,105,128,248,149,242,233,231,232,244,244,232,225,105,128,248, 148,244,232,225,105,128, 14, 75,245,240,240,229,242,236,229,230, 244,244,232,225,105,128,248,147,229,107, 3,129, 49,129, 80,129, 87,236,239,119, 2,129, 57,129, 68,236,229,230,244,244,232,225, 105,128,248,140,242,233,231,232,244,244,232,225,105,128,248,139, 244,232,225,105,128, 14, 72,245,240,240,229,242,236,229,230,244, 244,232,225,105,128,248,138,232,225,238,225,235,225,116, 2,129, 115,129,126,236,229,230,244,244,232,225,105,128,248,132,244,232, 225,105,128, 14, 49,116, 3,129,141,129,169,129,232,225,233,235, 232,117, 2,129,151,129,162,236,229,230,244,244,232,225,105,128, 248,137,244,232,225,105,128, 14, 71,232,111, 3,129,178,129,209, 129,216,236,239,119, 2,129,186,129,197,236,229,230,244,244,232, 225,105,128,248,143,242,233,231,232,244,244,232,225,105,128,248, 142,244,232,225,105,128, 14, 73,245,240,240,229,242,236,229,230, 244,244,232,225,105,128,248,141,242,105, 3,129,241,130, 16,130, 23,236,239,119, 2,129,249,130, 4,236,229,230,244,244,232,225, 105,128,248,146,242,233,231,232,244,244,232,225,105,128,248,145, 244,232,225,105,128, 14, 74,245,240,240,229,242,236,229,230,244, 244,232,225,105,128,248,144,249,225,237,239,235,244,232,225,105, 128, 14, 70,235,225,244,225,235,225,238, 97,129, 48,222,130, 64, 232,225,236,230,247,233,228,244,104,128,255,143,236,101,128, 38, 66,238,243,249,239,238,243,241,245,225,242,101,128, 51, 71,241, 225,230,232,229,226,242,229,119,128, 5,190,242,115,128, 38, 66, 115, 2,130,118,130,136,239,242,225,227,233,242,227,236,229,232, 229,226,242,229,119,128, 5,175,241,245,225,242,101,128, 51,131, 98, 2,130,150,130,160,239,240,239,237,239,230,111,128, 49, 7, 243,241,245,225,242,101,128, 51,212, 99, 2,130,175,130,183,233, 242,227,236,101,128, 36,220,245,226,229,228,243,241,245,225,242, 101,128, 51,165,228,239,116, 2,130,204,130,213,225,227,227,229, 238,116,128, 30, 65,226,229,236,239,119,128, 30, 67,101, 7,130, 237,131,108,131,119,131,134,131,159,131,196,131,208,101, 2,130, 243,131, 95,109, 4,130,253,131, 6,131, 20,131, 36,225,242,225, 226,233, 99,128, 6, 69,230,233,238,225,236,225,242,225,226,233, 99,128,254,226,233,238,233,244,233,225,236,225,242,225,226,233, 99,128,254,227,237,101, 2,131, 43,131, 56,228,233,225,236,225, 242,225,226,233, 99,128,254,228,229,237,105, 2,131, 64,131, 79, 238,233,244,233,225,236,225,242,225,226,233, 99,128,252,209,243, 239,236,225,244,229,228,225,242,225,226,233, 99,128,252, 72,244, 239,242,245,243,241,245,225,242,101,128, 51, 77,232,233,242,225, 231,225,238, 97,128, 48,129,233,250,233,229,242,225,243,241,245, 225,242,101,128, 51,126,235,225,244,225,235,225,238, 97,129, 48, 225,131,147,232,225,236,230,247,233,228,244,104,128,255,146,109, 130, 5,222,131,167,131,187,228,225,231,229,243,104,129,251, 62, 131,178,232,229,226,242,229,119,128,251, 62,232,229,226,242,229, 119,128, 5,222,238,225,242,237,229,238,233,225,110,128, 5,116, 242,235,232, 97, 3,131,219,131,228,132, 5,232,229,226,242,229, 119,128, 5,165,235,229,230,245,236, 97, 2,131,239,131,248,232, 229,226,242,229,119,128, 5,166,236,229,230,244,232,229,226,242, 229,119,128, 5,166,236,229,230,244,232,229,226,242,229,119,128, 5,165,104, 2,132, 24,132, 30,239,239,107,128, 2,113,250,243, 241,245,225,242,101,128, 51,146,105, 6,132, 54,132, 91,132,228, 132,239,133, 8,133, 65,228,100, 2,132, 61,132, 86,236,229,228, 239,244,235,225,244,225,235,225,238,225,232,225,236,230,247,233, 228,244,104,128,255,101,239,116,128, 0,183,229,245,109, 5,132, 105,132,140,132,155,132,164,132,215, 97, 2,132,111,132,126,227, 233,242,227,236,229,235,239,242,229,225,110,128, 50,114,240,225, 242,229,238,235,239,242,229,225,110,128, 50, 18,227,233,242,227, 236,229,235,239,242,229,225,110,128, 50,100,235,239,242,229,225, 110,128, 49, 65,112, 2,132,170,132,202, 97, 2,132,176,132,190, 238,243,233,239,243,235,239,242,229,225,110,128, 49,112,242,229, 238,235,239,242,229,225,110,128, 50, 4,233,229,245,240,235,239, 242,229,225,110,128, 49,110,243,233,239,243,235,239,242,229,225, 110,128, 49,111,232,233,242,225,231,225,238, 97,128, 48,127,235, 225,244,225,235,225,238, 97,129, 48,223,132,252,232,225,236,230, 247,233,228,244,104,128,255,144,238,117, 2,133, 15,133, 60,115, 132, 34, 18,133, 27,133, 38,133, 47,133, 53,226,229,236,239,247, 227,237, 98,128, 3, 32,227,233,242,227,236,101,128, 34,150,237, 239,100,128, 2,215,240,236,245,115,128, 34, 19,244,101,128, 32, 50,242,105, 2,133, 72,133, 86,226,225,225,242,245,243,241,245, 225,242,101,128, 51, 74,243,241,245,225,242,101,128, 51, 73,108, 2,133,101,133,116,239,238,231,236,229,231,244,245,242,238,229, 100,128, 2,112,243,241,245,225,242,101,128, 51,150,109, 3,133, 133,133,147,133,158,227,245,226,229,228,243,241,245,225,242,101, 128, 51,163,239,238,239,243,240,225,227,101,128,255, 77,243,241, 245,225,242,229,228,243,241,245,225,242,101,128, 51,159,111, 5, 133,186,133,212,133,237,133,247,134, 0,104, 2,133,192,133,202, 233,242,225,231,225,238, 97,128, 48,130,237,243,241,245,225,242, 101,128, 51,193,235,225,244,225,235,225,238, 97,129, 48,226,133, 225,232,225,236,230,247,233,228,244,104,128,255,147,236,243,241, 245,225,242,101,128, 51,214,237,225,244,232,225,105,128, 14, 33, 246,229,242,243,243,241,245,225,242,101,129, 51,167,134, 15,228, 243,241,245,225,242,101,128, 51,168,240, 97, 2,134, 32,134, 38, 242,229,110,128, 36,168,243,241,245,225,242,101,128, 51,171,115, 2,134, 53,134, 62,243,241,245,225,242,101,128, 51,179,245,240, 229,242,233,239,114,128,246,239,244,245,242,238,229,100,128, 2, 111,117,141, 0,181,134,111,134,115,134,125,134,149,134,159,134, 181,134,192,134,217,134,240,134,250,135, 24,135, 88,135, 98, 49, 128, 0,181,225,243,241,245,225,242,101,128, 51,130,227,104, 2, 134,132,134,142,231,242,229,225,244,229,114,128, 34,107,236,229, 243,115,128, 34,106,230,243,241,245,225,242,101,128, 51,140,103, 2,134,165,134,172,242,229,229,107,128, 3,188,243,241,245,225, 242,101,128, 51,141,232,233,242,225,231,225,238, 97,128, 48,128, 235,225,244,225,235,225,238, 97,129, 48,224,134,205,232,225,236, 230,247,233,228,244,104,128,255,145,108, 2,134,223,134,232,243, 241,245,225,242,101,128, 51,149,244,233,240,236,121,128, 0,215, 237,243,241,245,225,242,101,128, 51,155,238,225,104, 2,135, 2, 135, 11,232,229,226,242,229,119,128, 5,163,236,229,230,244,232, 229,226,242,229,119,128, 5,163,115, 2,135, 30,135, 79,233, 99, 3,135, 39,135, 56,135, 67,225,236,238,239,244,101,129, 38,106, 135, 50,228,226,108,128, 38,107,230,236,225,244,243,233,231,110, 128, 38,109,243,232,225,242,240,243,233,231,110,128, 38,111,243, 241,245,225,242,101,128, 51,178,246,243,241,245,225,242,101,128, 51,182,247,243,241,245,225,242,101,128, 51,188,118, 2,135,114, 135,127,237,229,231,225,243,241,245,225,242,101,128, 51,185,243, 241,245,225,242,101,128, 51,183,119, 2,135,142,135,155,237,229, 231,225,243,241,245,225,242,101,128, 51,191,243,241,245,225,242, 101,128, 51,189,110,150, 0,110,135,212,136, 90,136,114,136,180, 136,205,137, 7,137, 17,137, 84,137,127,139,161,139,179,139,204, 139,235,140, 5,140, 70,142, 52,142, 60,142, 85,142, 93,143, 61, 143, 71,143, 81, 97, 8,135,230,135,250,136, 1,136, 8,136, 33, 136, 44,136, 69,136, 81, 98, 2,135,236,135,245,229,238,231,225, 236,105,128, 9,168,236, 97,128, 34, 7,227,245,244,101,128, 1, 68,228,229,246, 97,128, 9, 40,231,117, 2,136, 15,136, 24,234, 225,242,225,244,105,128, 10,168,242,237,245,235,232,105,128, 10, 40,232,233,242,225,231,225,238, 97,128, 48,106,235,225,244,225, 235,225,238, 97,129, 48,202,136, 57,232,225,236,230,247,233,228, 244,104,128,255,133,240,239,243,244,242,239,240,232,101,128, 1, 73,243,241,245,225,242,101,128, 51,129, 98, 2,136, 96,136,106, 239,240,239,237,239,230,111,128, 49, 11,243,240,225,227,101,128, 0,160, 99, 4,136,124,136,131,136,140,136,167,225,242,239,110, 128, 1, 72,229,228,233,236,236, 97,128, 1, 70,233,242, 99, 2, 136,148,136,153,236,101,128, 36,221,245,237,230,236,229,248,226, 229,236,239,119,128, 30, 75,239,237,237,225,225,227,227,229,238, 116,128, 1, 70,228,239,116, 2,136,188,136,197,225,227,227,229, 238,116,128, 30, 69,226,229,236,239,119,128, 30, 71,101, 3,136, 213,136,224,136,249,232,233,242,225,231,225,238, 97,128, 48,109, 235,225,244,225,235,225,238, 97,129, 48,205,136,237,232,225,236, 230,247,233,228,244,104,128,255,136,247,243,232,229,241,229,236, 243,233,231,110,128, 32,170,230,243,241,245,225,242,101,128, 51, 139,103, 2,137, 23,137, 73, 97, 3,137, 31,137, 41,137, 48,226, 229,238,231,225,236,105,128, 9,153,228,229,246, 97,128, 9, 25, 231,117, 2,137, 55,137, 64,234,225,242,225,244,105,128, 10,153, 242,237,245,235,232,105,128, 10, 25,239,238,231,245,244,232,225, 105,128, 14, 7,104, 2,137, 90,137,100,233,242,225,231,225,238, 97,128, 48,147,239,239,107, 2,137,108,137,115,236,229,230,116, 128, 2,114,242,229,244,242,239,230,236,229,120,128, 2,115,105, 4,137,137,138, 50,138, 61,138,119,229,245,110, 7,137,155,137, 190,137,222,137,236,137,245,138, 22,138, 35, 97, 2,137,161,137, 176,227,233,242,227,236,229,235,239,242,229,225,110,128, 50,111, 240,225,242,229,238,235,239,242,229,225,110,128, 50, 15,227,105, 2,137,197,137,209,229,245,227,235,239,242,229,225,110,128, 49, 53,242,227,236,229,235,239,242,229,225,110,128, 50, 97,232,233, 229,245,232,235,239,242,229,225,110,128, 49, 54,235,239,242,229, 225,110,128, 49, 52,240, 97, 2,137,252,138, 10,238,243,233,239, 243,235,239,242,229,225,110,128, 49,104,242,229,238,235,239,242, 229,225,110,128, 50, 1,243,233,239,243,235,239,242,229,225,110, 128, 49,103,244,233,235,229,245,244,235,239,242,229,225,110,128, 49,102,232,233,242,225,231,225,238, 97,128, 48,107,107, 2,138, 67,138, 91,225,244,225,235,225,238, 97,129, 48,203,138, 79,232, 225,236,230,247,233,228,244,104,128,255,134,232,225,232,233,116, 2,138,101,138,112,236,229,230,244,244,232,225,105,128,248,153, 244,232,225,105,128, 14, 77,238,101,141, 0, 57,138,150,138,159, 138,169,138,199,138,206,138,231,139, 2,139, 36,139, 48,139, 59, 139, 92,139,100,139,111,225,242,225,226,233, 99,128, 6,105,226, 229,238,231,225,236,105,128, 9,239,227,233,242,227,236,101,129, 36,104,138,180,233,238,246,229,242,243,229,243,225,238,243,243, 229,242,233,102,128, 39,146,228,229,246, 97,128, 9,111,231,117, 2,138,213,138,222,234,225,242,225,244,105,128, 10,239,242,237, 245,235,232,105,128, 10,111,232, 97, 2,138,238,138,249,227,235, 225,242,225,226,233, 99,128, 6,105,238,231,250,232,239,117,128, 48, 41,105, 2,139, 8,139, 26,228,229,239,231,242,225,240,232, 233,227,240,225,242,229,110,128, 50, 40,238,230,229,242,233,239, 114,128, 32,137,237,239,238,239,243,240,225,227,101,128,255, 25, 239,236,228,243,244,249,236,101,128,247, 57,112, 2,139, 65,139, 72,225,242,229,110,128, 36,124,229,114, 2,139, 79,139, 85,233, 239,100,128, 36,144,243,233,225,110,128, 6,249,242,239,237,225, 110,128, 33,120,243,245,240,229,242,233,239,114,128, 32,121,116, 2,139,117,139,155,229,229,110, 2,139,125,139,134,227,233,242, 227,236,101,128, 36,114,112, 2,139,140,139,147,225,242,229,110, 128, 36,134,229,242,233,239,100,128, 36,154,232,225,105,128, 14, 89,106,129, 1,204,139,167,229,227,249,242,233,236,236,233, 99, 128, 4, 90,235,225,244,225,235,225,238, 97,129, 48,243,139,192, 232,225,236,230,247,233,228,244,104,128,255,157,108, 2,139,210, 139,224,229,231,242,233,231,232,244,236,239,238,103,128, 1,158, 233,238,229,226,229,236,239,119,128, 30, 73,109, 2,139,241,139, 252,239,238,239,243,240,225,227,101,128,255, 78,243,241,245,225, 242,101,128, 51,154,110, 2,140, 11,140, 61, 97, 3,140, 19,140, 29,140, 36,226,229,238,231,225,236,105,128, 9,163,228,229,246, 97,128, 9, 35,231,117, 2,140, 43,140, 52,234,225,242,225,244, 105,128, 10,163,242,237,245,235,232,105,128, 10, 35,238,225,228, 229,246, 97,128, 9, 41,111, 6,140, 84,140, 95,140,120,140,161, 141,113,142, 40,232,233,242,225,231,225,238, 97,128, 48,110,235, 225,244,225,235,225,238, 97,129, 48,206,140,108,232,225,236,230, 247,233,228,244,104,128,255,137,110, 3,140,128,140,144,140,153, 226,242,229,225,235,233,238,231,243,240,225,227,101,128, 0,160, 229,238,244,232,225,105,128, 14, 19,245,244,232,225,105,128, 14, 25,239,110, 7,140,178,140,187,140,201,140,235,140,251,141, 36, 141, 95,225,242,225,226,233, 99,128, 6, 70,230,233,238,225,236, 225,242,225,226,233, 99,128,254,230,231,232,245,238,238, 97, 2, 140,212,140,221,225,242,225,226,233, 99,128, 6,186,230,233,238, 225,236,225,242,225,226,233, 99,128,251,159,233,238,233,244,233, 225,236,225,242,225,226,233, 99,128,254,231,234,229,229,237,105, 2,141, 5,141, 20,238,233,244,233,225,236,225,242,225,226,233, 99,128,252,210,243,239,236,225,244,229,228,225,242,225,226,233, 99,128,252, 75,237,101, 2,141, 43,141, 56,228,233,225,236,225, 242,225,226,233, 99,128,254,232,229,237,105, 2,141, 64,141, 79, 238,233,244,233,225,236,225,242,225,226,233, 99,128,252,213,243, 239,236,225,244,229,228,225,242,225,226,233, 99,128,252, 78,238, 239,239,238,230,233,238,225,236,225,242,225,226,233, 99,128,252, 141,116, 7,141,129,141,140,141,169,141,204,141,216,141,236,142, 6,227,239,238,244,225,233,238,115,128, 34, 12,101, 2,141,146, 141,162,236,229,237,229,238,116,129, 34, 9,141,157,239,102,128, 34, 9,241,245,225,108,128, 34, 96,231,242,229,225,244,229,114, 129, 34,111,141,181,238,239,114, 2,141,189,141,197,229,241,245, 225,108,128, 34,113,236,229,243,115,128, 34,121,233,228,229,238, 244,233,227,225,108,128, 34, 98,236,229,243,115,129, 34,110,141, 225,238,239,242,229,241,245,225,108,128, 34,112,112, 2,141,242, 141,252,225,242,225,236,236,229,108,128, 34, 38,242,229,227,229, 228,229,115,128, 34,128,243,117, 3,142, 15,142, 22,142, 31,226, 243,229,116,128, 34,132,227,227,229,229,228,115,128, 34,129,240, 229,242,243,229,116,128, 34,133,247,225,242,237,229,238,233,225, 110,128, 5,118,240,225,242,229,110,128, 36,169,115, 2,142, 66, 142, 75,243,241,245,225,242,101,128, 51,177,245,240,229,242,233, 239,114,128, 32,127,244,233,236,228,101,128, 0,241,117,132, 3, 189,142,105,142,116,142,197,143, 24,232,233,242,225,231,225,238, 97,128, 48,108,107, 2,142,122,142,146,225,244,225,235,225,238, 97,129, 48,204,142,134,232,225,236,230,247,233,228,244,104,128, 255,135,244, 97, 3,142,155,142,165,142,172,226,229,238,231,225, 236,105,128, 9,188,228,229,246, 97,128, 9, 60,231,117, 2,142, 179,142,188,234,225,242,225,244,105,128, 10,188,242,237,245,235, 232,105,128, 10, 60,109, 2,142,203,142,237,226,229,242,243,233, 231,110,130, 0, 35,142,217,142,229,237,239,238,239,243,240,225, 227,101,128,255, 3,243,237,225,236,108,128,254, 95,229,114, 2, 142,244,143, 20,225,236,243,233,231,110, 2,142,255,143, 7,231, 242,229,229,107,128, 3,116,236,239,247,229,242,231,242,229,229, 107,128, 3,117,111,128, 33, 22,110,130, 5,224,143, 32,143, 52, 228,225,231,229,243,104,129,251, 64,143, 43,232,229,226,242,229, 119,128,251, 64,232,229,226,242,229,119,128, 5,224,246,243,241, 245,225,242,101,128, 51,181,247,243,241,245,225,242,101,128, 51, 187,249, 97, 3,143, 90,143,100,143,107,226,229,238,231,225,236, 105,128, 9,158,228,229,246, 97,128, 9, 30,231,117, 2,143,114, 143,123,234,225,242,225,244,105,128, 10,158,242,237,245,235,232, 105,128, 10, 30,111,147, 0,111,143,174,143,196,144, 18,144,188, 145, 4,145, 19,145, 59,145,182,145,203,145,241,145,252,146,174, 148, 8,148, 72,148,105,148,151,149, 24,149, 71,149, 83, 97, 2, 143,180,143,187,227,245,244,101,128, 0,243,238,231,244,232,225, 105,128, 14, 45, 98, 4,143,206,143,248,144, 1,144, 11,225,242, 242,229,100,130, 2,117,143,218,143,229,227,249,242,233,236,236, 233, 99,128, 4,233,228,233,229,242,229,243,233,243,227,249,242, 233,236,236,233, 99,128, 4,235,229,238,231,225,236,105,128, 9, 147,239,240,239,237,239,230,111,128, 49, 27,242,229,246,101,128, 1, 79, 99, 3,144, 26,144, 99,144,178, 97, 2,144, 32,144, 93, 238,228,242, 97, 3,144, 43,144, 50,144, 61,228,229,246, 97,128, 9, 17,231,245,234,225,242,225,244,105,128, 10,145,246,239,247, 229,236,243,233,231,110, 2,144, 75,144, 82,228,229,246, 97,128, 9, 73,231,245,234,225,242,225,244,105,128, 10,201,242,239,110, 128, 1,210,233,242, 99, 2,144,107,144,112,236,101,128, 36,222, 245,237,230,236,229,120,133, 0,244,144,131,144,139,144,150,144, 158,144,170,225,227,245,244,101,128, 30,209,228,239,244,226,229, 236,239,119,128, 30,217,231,242,225,246,101,128, 30,211,232,239, 239,235,225,226,239,246,101,128, 30,213,244,233,236,228,101,128, 30,215,249,242,233,236,236,233, 99,128, 4, 62,100, 4,144,198, 144,221,144,227,144,250,226,108, 2,144,205,144,213,225,227,245, 244,101,128, 1, 81,231,242,225,246,101,128, 2, 13,229,246, 97, 128, 9, 19,233,229,242,229,243,233,115,129, 0,246,144,239,227, 249,242,233,236,236,233, 99,128, 4,231,239,244,226,229,236,239, 119,128, 30,205,101,129, 1, 83,145, 10,235,239,242,229,225,110, 128, 49, 90,103, 3,145, 27,145, 42,145, 49,239,238,229,107,129, 2,219,145, 36,227,237, 98,128, 3, 40,242,225,246,101,128, 0, 242,245,234,225,242,225,244,105,128, 10,147,104, 4,145, 69,145, 80,145, 90,145,168,225,242,237,229,238,233,225,110,128, 5,133, 233,242,225,231,225,238, 97,128, 48, 74,111, 2,145, 96,145,106, 239,235,225,226,239,246,101,128, 30,207,242,110,133, 1,161,145, 121,145,129,145,140,145,148,145,160,225,227,245,244,101,128, 30, 219,228,239,244,226,229,236,239,119,128, 30,227,231,242,225,246, 101,128, 30,221,232,239,239,235,225,226,239,246,101,128, 30,223, 244,233,236,228,101,128, 30,225,245,238,231,225,242,245,237,236, 225,245,116,128, 1, 81,105,129, 1,163,145,188,238,246,229,242, 244,229,228,226,242,229,246,101,128, 2, 15,107, 2,145,209,145, 233,225,244,225,235,225,238, 97,129, 48,170,145,221,232,225,236, 230,247,233,228,244,104,128,255,117,239,242,229,225,110,128, 49, 87,236,229,232,229,226,242,229,119,128, 5,171,109, 6,146, 10, 146, 38,146, 45,146,134,146,145,146,163,225,227,242,239,110,130, 1, 77,146, 22,146, 30,225,227,245,244,101,128, 30, 83,231,242, 225,246,101,128, 30, 81,228,229,246, 97,128, 9, 80,229,231, 97, 133, 3,201,146, 61,146, 65,146, 76,146, 90,146,106, 49,128, 3, 214,227,249,242,233,236,236,233, 99,128, 4, 97,236,225,244,233, 238,227,236,239,243,229,100,128, 2,119,242,239,245,238,228,227, 249,242,233,236,236,233, 99,128, 4,123,116, 2,146,112,146,127, 233,244,236,239,227,249,242,233,236,236,233, 99,128, 4,125,239, 238,239,115,128, 3,206,231,245,234,225,242,225,244,105,128, 10, 208,233,227,242,239,110,129, 3,191,146,155,244,239,238,239,115, 128, 3,204,239,238,239,243,240,225,227,101,128,255, 79,238,101, 145, 0, 49,146,213,146,222,146,232,147, 6,147, 31,147, 40,147, 49,147, 74,147,108,147,142,147,154,147,173,147,184,147,217,147, 227,147,235,147,246,225,242,225,226,233, 99,128, 6, 97,226,229, 238,231,225,236,105,128, 9,231,227,233,242,227,236,101,129, 36, 96,146,243,233,238,246,229,242,243,229,243,225,238,243,243,229, 242,233,102,128, 39,138,100, 2,147, 12,147, 18,229,246, 97,128, 9,103,239,244,229,238,236,229,225,228,229,114,128, 32, 36,229, 233,231,232,244,104,128, 33, 91,230,233,244,244,229,100,128,246, 220,231,117, 2,147, 56,147, 65,234,225,242,225,244,105,128, 10, 231,242,237,245,235,232,105,128, 10,103,232, 97, 3,147, 83,147, 94,147, 99,227,235,225,242,225,226,233, 99,128, 6, 97,236,102, 128, 0,189,238,231,250,232,239,117,128, 48, 33,105, 2,147,114, 147,132,228,229,239,231,242,225,240,232,233,227,240,225,242,229, 110,128, 50, 32,238,230,229,242,233,239,114,128, 32,129,237,239, 238,239,243,240,225,227,101,128,255, 17,238,245,237,229,242,225, 244,239,242,226,229,238,231,225,236,105,128, 9,244,239,236,228, 243,244,249,236,101,128,247, 49,112, 2,147,190,147,197,225,242, 229,110,128, 36,116,229,114, 2,147,204,147,210,233,239,100,128, 36,136,243,233,225,110,128, 6,241,241,245,225,242,244,229,114, 128, 0,188,242,239,237,225,110,128, 33,112,243,245,240,229,242, 233,239,114,128, 0,185,244,104, 2,147,253,148, 2,225,105,128, 14, 81,233,242,100,128, 33, 83,111, 3,148, 16,148, 50,148, 66, 103, 2,148, 22,148, 40,239,238,229,107,129, 1,235,148, 31,237, 225,227,242,239,110,128, 1,237,245,242,237,245,235,232,105,128, 10, 19,237,225,244,242,225,231,245,242,237,245,235,232,105,128, 10, 75,240,229,110,128, 2, 84,112, 3,148, 80,148, 87,148, 98, 225,242,229,110,128, 36,170,229,238,226,245,236,236,229,116,128, 37,230,244,233,239,110,128, 35, 37,114, 2,148,111,148,140,100, 2,148,117,148,128,230,229,237,233,238,233,238,101,128, 0,170, 237,225,243,227,245,236,233,238,101,128, 0,186,244,232,239,231, 239,238,225,108,128, 34, 31,115, 5,148,163,148,195,148,212,149, 1,149, 14,232,239,242,116, 2,148,172,148,179,228,229,246, 97, 128, 9, 18,246,239,247,229,236,243,233,231,238,228,229,246, 97, 128, 9, 74,236,225,243,104,129, 0,248,148,204,225,227,245,244, 101,128, 1,255,237,225,236,108, 2,148,221,148,232,232,233,242, 225,231,225,238, 97,128, 48, 73,235,225,244,225,235,225,238, 97, 129, 48,169,148,245,232,225,236,230,247,233,228,244,104,128,255, 107,244,242,239,235,229,225,227,245,244,101,128, 1,255,245,240, 229,242,233,239,114,128,246,240,116, 2,149, 30,149, 41,227,249, 242,233,236,236,233, 99,128, 4,127,233,236,228,101,130, 0,245, 149, 52,149, 60,225,227,245,244,101,128, 30, 77,228,233,229,242, 229,243,233,115,128, 30, 79,245,226,239,240,239,237,239,230,111, 128, 49, 33,118, 2,149, 89,149,170,229,114, 2,149, 96,149,162, 236,233,238,101,131, 32, 62,149,109,149,132,149,155, 99, 2,149, 115,149,127,229,238,244,229,242,236,233,238,101,128,254, 74,237, 98,128, 3, 5,100, 2,149,138,149,146,225,243,232,229,100,128, 254, 73,226,236,247,225,246,121,128,254, 76,247,225,246,121,128, 254, 75,243,227,239,242,101,128, 0,175,239,247,229,236,243,233, 231,110, 3,149,185,149,195,149,202,226,229,238,231,225,236,105, 128, 9,203,228,229,246, 97,128, 9, 75,231,245,234,225,242,225, 244,105,128, 10,203,112,145, 0,112,149,251,152,123,152,134,152, 143,152,155,154, 80,154, 90,155, 82,156,101,156,191,156,217,157, 92,157,100,158, 2,158, 60,158, 88,158, 98, 97, 14,150, 25,150, 57,150, 67,150, 74,150, 81,150,129,150,140,150,154,150,165,150, 212,150,226,151,238,152, 21,152,111, 97, 2,150, 31,150, 43,237, 240,243,243,241,245,225,242,101,128, 51,128,243,229,238,244,239, 243,241,245,225,242,101,128, 51, 43,226,229,238,231,225,236,105, 128, 9,170,227,245,244,101,128, 30, 85,228,229,246, 97,128, 9, 42,103, 2,150, 87,150,105,101, 2,150, 93,150,100,228,239,247, 110,128, 33,223,245,112,128, 33,222,117, 2,150,111,150,120,234, 225,242,225,244,105,128, 10,170,242,237,245,235,232,105,128, 10, 42,232,233,242,225,231,225,238, 97,128, 48,113,233,249,225,238, 238,239,233,244,232,225,105,128, 14, 47,235,225,244,225,235,225, 238, 97,128, 48,209,108, 2,150,171,150,196,225,244,225,236,233, 250,225,244,233,239,238,227,249,242,233,236,236,233,227,227,237, 98,128, 4,132,239,227,232,235,225,227,249,242,233,236,236,233, 99,128, 4,192,238,243,233,239,243,235,239,242,229,225,110,128, 49,127,114, 3,150,234,150,255,151,227, 97, 2,150,240,150,248, 231,242,225,240,104,128, 0,182,236,236,229,108,128, 34, 37,229, 110, 2,151, 6,151,116,236,229,230,116,136, 0, 40,151, 29,151, 44,151, 49,151, 54,151, 65,151, 77,151,100,151,105,225,236,244, 239,238,229,225,242,225,226,233, 99,128,253, 62,226,116,128,248, 237,229,120,128,248,236,233,238,230,229,242,233,239,114,128, 32, 141,237,239,238,239,243,240,225,227,101,128,255, 8,115, 2,151, 83,151, 90,237,225,236,108,128,254, 89,245,240,229,242,233,239, 114,128, 32,125,244,112,128,248,235,246,229,242,244,233,227,225, 108,128,254, 53,242,233,231,232,116,136, 0, 41,151,140,151,155, 151,160,151,165,151,176,151,188,151,211,151,216,225,236,244,239, 238,229,225,242,225,226,233, 99,128,253, 63,226,116,128,248,248, 229,120,128,248,247,233,238,230,229,242,233,239,114,128, 32,142, 237,239,238,239,243,240,225,227,101,128,255, 9,115, 2,151,194, 151,201,237,225,236,108,128,254, 90,245,240,229,242,233,239,114, 128, 32,126,244,112,128,248,246,246,229,242,244,233,227,225,108, 128,254, 54,244,233,225,236,228,233,230,102,128, 34, 2,115, 3, 151,246,152, 1,152, 13,229,241,232,229,226,242,229,119,128, 5, 192,232,244,225,232,229,226,242,229,119,128, 5,153,241,245,225, 242,101,128, 51,169,244,225,104,134, 5,183,152, 39,152, 53,152, 58,152, 67,152, 82,152, 98, 49, 2,152, 45,152, 49, 49,128, 5, 183,100,128, 5,183,178, 97,128, 5,183,232,229,226,242,229,119, 128, 5,183,238,225,242,242,239,247,232,229,226,242,229,119,128, 5,183,241,245,225,242,244,229,242,232,229,226,242,229,119,128, 5,183,247,233,228,229,232,229,226,242,229,119,128, 5,183,250, 229,242,232,229,226,242,229,119,128, 5,161,226,239,240,239,237, 239,230,111,128, 49, 6,227,233,242,227,236,101,128, 36,223,228, 239,244,225,227,227,229,238,116,128, 30, 87,101,137, 5,228,152, 177,152,188,152,208,152,220,152,240,153, 86,153, 97,153,118,154, 73,227,249,242,233,236,236,233, 99,128, 4, 63,228,225,231,229, 243,104,129,251, 68,152,199,232,229,226,242,229,119,128,251, 68, 229,250,233,243,241,245,225,242,101,128, 51, 59,230,233,238,225, 236,228,225,231,229,243,232,232,229,226,242,229,119,128,251, 67, 104, 5,152,252,153, 19,153, 27,153, 41,153, 71,225,114, 2,153, 3,153, 10,225,226,233, 99,128, 6,126,237,229,238,233,225,110, 128, 5,122,229,226,242,229,119,128, 5,228,230,233,238,225,236, 225,242,225,226,233, 99,128,251, 87,105, 2,153, 47,153, 62,238, 233,244,233,225,236,225,242,225,226,233, 99,128,251, 88,242,225, 231,225,238, 97,128, 48,122,237,229,228,233,225,236,225,242,225, 226,233, 99,128,251, 89,235,225,244,225,235,225,238, 97,128, 48, 218,237,233,228,228,236,229,232,239,239,235,227,249,242,233,236, 236,233, 99,128, 4,167,114, 5,153,130,153,142,153,184,154, 49, 154, 62,225,230,229,232,229,226,242,229,119,128,251, 78,227,229, 238,116,131, 0, 37,153,155,153,164,153,176,225,242,225,226,233, 99,128, 6,106,237,239,238,239,243,240,225,227,101,128,255, 5, 243,237,225,236,108,128,254,106,105, 2,153,190,154, 31,239,100, 134, 0, 46,153,207,153,218,153,229,153,241,153,252,154, 8,225, 242,237,229,238,233,225,110,128, 5,137,227,229,238,244,229,242, 229,100,128, 0,183,232,225,236,230,247,233,228,244,104,128,255, 97,233,238,230,229,242,233,239,114,128,246,231,237,239,238,239, 243,240,225,227,101,128,255, 14,115, 2,154, 14,154, 21,237,225, 236,108,128,254, 82,245,240,229,242,233,239,114,128,246,232,243, 240,239,237,229,238,233,231,242,229,229,235,227,237, 98,128, 3, 66,240,229,238,228,233,227,245,236,225,114,128, 34,165,244,232, 239,245,243,225,238,100,128, 32, 48,243,229,244, 97,128, 32,167, 230,243,241,245,225,242,101,128, 51,138,104, 3,154, 98,154,148, 155, 29, 97, 3,154,106,154,116,154,123,226,229,238,231,225,236, 105,128, 9,171,228,229,246, 97,128, 9, 43,231,117, 2,154,130, 154,139,234,225,242,225,244,105,128, 10,171,242,237,245,235,232, 105,128, 10, 43,105,133, 3,198,154,162,154,166,154,252,155, 4, 155, 15, 49,128, 3,213,229,245,240,104, 4,154,179,154,214,154, 229,154,238, 97, 2,154,185,154,200,227,233,242,227,236,229,235, 239,242,229,225,110,128, 50,122,240,225,242,229,238,235,239,242, 229,225,110,128, 50, 26,227,233,242,227,236,229,235,239,242,229, 225,110,128, 50,108,235,239,242,229,225,110,128, 49, 77,240,225, 242,229,238,235,239,242,229,225,110,128, 50, 12,236,225,244,233, 110,128, 2,120,238,244,232,245,244,232,225,105,128, 14, 58,243, 249,237,226,239,236,231,242,229,229,107,128, 3,213,111, 3,155, 37,155, 42,155, 68,239,107,128, 1,165,240,104, 2,155, 49,155, 58,225,238,244,232,225,105,128, 14, 30,245,238,231,244,232,225, 105,128, 14, 28,243,225,237,240,232,225,239,244,232,225,105,128, 14, 32,105,133, 3,192,155, 96,156, 52,156, 63,156, 74,156, 88, 229,245,112, 6,155,112,155,147,155,179,155,207,155,221,156, 17, 97, 2,155,118,155,133,227,233,242,227,236,229,235,239,242,229, 225,110,128, 50,115,240,225,242,229,238,235,239,242,229,225,110, 128, 50, 19,227,105, 2,155,154,155,166,229,245,227,235,239,242, 229,225,110,128, 49,118,242,227,236,229,235,239,242,229,225,110, 128, 50,101,107, 2,155,185,155,199,233,249,229,239,235,235,239, 242,229,225,110,128, 49,114,239,242,229,225,110,128, 49, 66,240, 225,242,229,238,235,239,242,229,225,110,128, 50, 5,243,233,239, 115, 2,155,230,156, 2,107, 2,155,236,155,250,233,249,229,239, 235,235,239,242,229,225,110,128, 49,116,239,242,229,225,110,128, 49, 68,244,233,235,229,245,244,235,239,242,229,225,110,128, 49, 117,116, 2,156, 23,156, 38,232,233,229,245,244,232,235,239,242, 229,225,110,128, 49,119,233,235,229,245,244,235,239,242,229,225, 110,128, 49,115,232,233,242,225,231,225,238, 97,128, 48,116,235, 225,244,225,235,225,238, 97,128, 48,212,243,249,237,226,239,236, 231,242,229,229,107,128, 3,214,247,242,225,242,237,229,238,233, 225,110,128, 5,131,236,245,115,132, 0, 43,156,115,156,126,156, 135,156,168,226,229,236,239,247,227,237, 98,128, 3, 31,227,233, 242,227,236,101,128, 34,149,109, 2,156,141,156,148,233,238,245, 115,128, 0,177,111, 2,156,154,156,158,100,128, 2,214,238,239, 243,240,225,227,101,128,255, 11,115, 2,156,174,156,181,237,225, 236,108,128,254, 98,245,240,229,242,233,239,114,128, 32,122,109, 2,156,197,156,208,239,238,239,243,240,225,227,101,128,255, 80, 243,241,245,225,242,101,128, 51,216,111, 5,156,229,156,240,157, 51,157, 62,157, 72,232,233,242,225,231,225,238, 97,128, 48,125, 233,238,244,233,238,231,233,238,228,229,120, 4,157, 4,157, 16, 157, 28,157, 41,228,239,247,238,247,232,233,244,101,128, 38, 31, 236,229,230,244,247,232,233,244,101,128, 38, 28,242,233,231,232, 244,247,232,233,244,101,128, 38, 30,245,240,247,232,233,244,101, 128, 38, 29,235,225,244,225,235,225,238, 97,128, 48,221,240,236, 225,244,232,225,105,128, 14, 27,243,244,225,236,237,225,242,107, 129, 48, 18,157, 85,230,225,227,101,128, 48, 32,240,225,242,229, 110,128, 36,171,114, 3,157,108,157,134,157,159,101, 2,157,114, 157,122,227,229,228,229,115,128, 34,122,243,227,242,233,240,244, 233,239,110,128, 33, 30,233,237,101, 2,157,142,157,148,237,239, 100,128, 2,185,242,229,246,229,242,243,229,100,128, 32, 53,111, 4,157,169,157,176,157,186,157,199,228,245,227,116,128, 34, 15, 234,229,227,244,233,246,101,128, 35, 5,236,239,238,231,229,228, 235,225,238, 97,128, 48,252,112, 2,157,205,157,242,101, 2,157, 211,157,218,236,236,239,114,128, 35, 24,242,243,117, 2,157,226, 157,233,226,243,229,116,128, 34,130,240,229,242,243,229,116,128, 34,131,239,242,244,233,239,110,129, 34, 55,157,253,225,108,128, 34, 29,115, 2,158, 8,158, 51,105,130, 3,200,158, 16,158, 27, 227,249,242,233,236,236,233, 99,128, 4,113,236,233,240,238,229, 245,237,225,244,225,227,249,242,233,236,236,233,227,227,237, 98, 128, 4,134,243,241,245,225,242,101,128, 51,176,117, 2,158, 66, 158, 77,232,233,242,225,231,225,238, 97,128, 48,119,235,225,244, 225,235,225,238, 97,128, 48,215,246,243,241,245,225,242,101,128, 51,180,247,243,241,245,225,242,101,128, 51,186,113,136, 0,113, 158,128,159,177,159,188,159,197,159,204,159,216,159,254,160, 6, 97, 4,158,138,158,161,158,225,159,160,100, 2,158,144,158,150, 229,246, 97,128, 9, 88,237,225,232,229,226,242,229,119,128, 5, 168,102, 4,158,171,158,180,158,194,158,210,225,242,225,226,233, 99,128, 6, 66,230,233,238,225,236,225,242,225,226,233, 99,128, 254,214,233,238,233,244,233,225,236,225,242,225,226,233, 99,128, 254,215,237,229,228,233,225,236,225,242,225,226,233, 99,128,254, 216,237,225,244,115,136, 5,184,158,248,159, 12,159, 26,159, 31, 159, 36,159, 45,159, 60,159,147, 49, 3,159, 0,159, 4,159, 8, 48,128, 5,184, 97,128, 5,184, 99,128, 5,184, 50, 2,159, 18, 159, 22, 55,128, 5,184, 57,128, 5,184,179, 51,128, 5,184,228, 101,128, 5,184,232,229,226,242,229,119,128, 5,184,238,225,242, 242,239,247,232,229,226,242,229,119,128, 5,184,113, 2,159, 66, 159,132,225,244,225,110, 4,159, 79,159, 88,159,103,159,119,232, 229,226,242,229,119,128, 5,184,238,225,242,242,239,247,232,229, 226,242,229,119,128, 5,184,241,245,225,242,244,229,242,232,229, 226,242,229,119,128, 5,184,247,233,228,229,232,229,226,242,229, 119,128, 5,184,245,225,242,244,229,242,232,229,226,242,229,119, 128, 5,184,247,233,228,229,232,229,226,242,229,119,128, 5,184, 242,238,229,249,240,225,242,225,232,229,226,242,229,119,128, 5, 159,226,239,240,239,237,239,230,111,128, 49, 17,227,233,242,227, 236,101,128, 36,224,232,239,239,107,128, 2,160,237,239,238,239, 243,240,225,227,101,128,255, 81,239,102,130, 5,231,159,225,159, 245,228,225,231,229,243,104,129,251, 71,159,236,232,229,226,242, 229,119,128,251, 71,232,229,226,242,229,119,128, 5,231,240,225, 242,229,110,128, 36,172,117, 4,160, 16,160, 28,160,117,160,204, 225,242,244,229,242,238,239,244,101,128, 38,105,226,245,244,115, 135, 5,187,160, 49,160, 54,160, 59,160, 64,160, 73,160, 88,160, 104,177, 56,128, 5,187,178, 53,128, 5,187,179, 49,128, 5,187, 232,229,226,242,229,119,128, 5,187,238,225,242,242,239,247,232, 229,226,242,229,119,128, 5,187,241,245,225,242,244,229,242,232, 229,226,242,229,119,128, 5,187,247,233,228,229,232,229,226,242, 229,119,128, 5,187,229,243,244,233,239,110,133, 0, 63,160,136, 160,159,160,176,160,184,160,196,225,114, 2,160,143,160,150,225, 226,233, 99,128, 6, 31,237,229,238,233,225,110,128, 5, 94,228, 239,247,110,129, 0,191,160,168,243,237,225,236,108,128,247,191, 231,242,229,229,107,128, 3,126,237,239,238,239,243,240,225,227, 101,128,255, 31,243,237,225,236,108,128,247, 63,239,244,101, 4, 160,216,161, 31,161, 51,161, 80,228,226,108,133, 0, 34,160,232, 160,239,160,246,161, 2,161, 23,226,225,243,101,128, 32, 30,236, 229,230,116,128, 32, 28,237,239,238,239,243,240,225,227,101,128, 255, 2,240,242,233,237,101,129, 48, 30,161, 12,242,229,246,229, 242,243,229,100,128, 48, 29,242,233,231,232,116,128, 32, 29,236, 229,230,116,129, 32, 24,161, 40,242,229,246,229,242,243,229,100, 128, 32, 27,114, 2,161, 57,161, 67,229,246,229,242,243,229,100, 128, 32, 27,233,231,232,116,129, 32, 25,161, 76,110,128, 1, 73, 243,233,238,231,108, 2,161, 90,161, 97,226,225,243,101,128, 32, 26,101,129, 0, 39,161,103,237,239,238,239,243,240,225,227,101, 128,255, 7,114,145, 0,114,161,153,162,157,162,168,162,215,163, 10,164, 27,164, 51,164,146,166,180,166,217,166,229,167, 27,167, 35,167,197,167,208,167,243,168, 87, 97, 11,161,177,161,188,161, 198,161,205,162, 14,162, 30,162, 55,162, 66,162, 91,162,114,162, 151,225,242,237,229,238,233,225,110,128, 5,124,226,229,238,231, 225,236,105,128, 9,176,227,245,244,101,128, 1, 85,100, 4,161, 215,161,221,161,235,162, 5,229,246, 97,128, 9, 48,233,227,225, 108,129, 34, 26,161,230,229,120,128,248,229,239,246,229,242,243, 243,241,245,225,242,101,129, 51,174,161,251,228,243,241,245,225, 242,101,128, 51,175,243,241,245,225,242,101,128, 51,173,230,101, 129, 5,191,162, 21,232,229,226,242,229,119,128, 5,191,231,117, 2,162, 37,162, 46,234,225,242,225,244,105,128, 10,176,242,237, 245,235,232,105,128, 10, 48,232,233,242,225,231,225,238, 97,128, 48,137,235,225,244,225,235,225,238, 97,129, 48,233,162, 79,232, 225,236,230,247,233,228,244,104,128,255,151,236,239,247,229,242, 228,233,225,231,239,238,225,236,226,229,238,231,225,236,105,128, 9,241,109, 2,162,120,162,143,233,228,228,236,229,228,233,225, 231,239,238,225,236,226,229,238,231,225,236,105,128, 9,240,243, 232,239,242,110,128, 2,100,244,233,111,128, 34, 54,226,239,240, 239,237,239,230,111,128, 49, 22, 99, 4,162,178,162,185,162,194, 162,202,225,242,239,110,128, 1, 89,229,228,233,236,236, 97,128, 1, 87,233,242,227,236,101,128, 36,225,239,237,237,225,225,227, 227,229,238,116,128, 1, 87,100, 2,162,221,162,231,226,236,231, 242,225,246,101,128, 2, 17,239,116, 2,162,238,162,247,225,227, 227,229,238,116,128, 30, 89,226,229,236,239,119,129, 30, 91,163, 1,237,225,227,242,239,110,128, 30, 93,101, 6,163, 24,163, 69, 163,104,163,159,163,184,163,217,102, 2,163, 30,163, 43,229,242, 229,238,227,229,237,225,242,107,128, 32, 59,236,229,248,243,117, 2,163, 53,163, 60,226,243,229,116,128, 34,134,240,229,242,243, 229,116,128, 34,135,231,233,243,244,229,114, 2,163, 80,163, 85, 229,100,128, 0,174,115, 2,163, 91,163, 97,225,238,115,128,248, 232,229,242,233,102,128,246,218,104, 3,163,112,163,135,163,149, 225,114, 2,163,119,163,126,225,226,233, 99,128, 6, 49,237,229, 238,233,225,110,128, 5,128,230,233,238,225,236,225,242,225,226, 233, 99,128,254,174,233,242,225,231,225,238, 97,128, 48,140,235, 225,244,225,235,225,238, 97,129, 48,236,163,172,232,225,236,230, 247,233,228,244,104,128,255,154,243,104,130, 5,232,163,193,163, 208,228,225,231,229,243,232,232,229,226,242,229,119,128,251, 72, 232,229,226,242,229,119,128, 5,232,118, 3,163,225,163,238,164, 14,229,242,243,229,228,244,233,236,228,101,128, 34, 61,233, 97, 2,163,245,163,254,232,229,226,242,229,119,128, 5,151,237,245, 231,242,225,243,232,232,229,226,242,229,119,128, 5,151,236,239, 231,233,227,225,236,238,239,116,128, 35, 16,230,233,243,232,232, 239,239,107,129, 2,126,164, 40,242,229,246,229,242,243,229,100, 128, 2,127,104, 2,164, 57,164, 80, 97, 2,164, 63,164, 73,226, 229,238,231,225,236,105,128, 9,221,228,229,246, 97,128, 9, 93, 111,131, 3,193,164, 90,164,119,164,133,239,107,129, 2,125,164, 97,244,245,242,238,229,100,129, 2,123,164,108,243,245,240,229, 242,233,239,114,128, 2,181,243,249,237,226,239,236,231,242,229, 229,107,128, 3,241,244,233,227,232,239,239,235,237,239,100,128, 2,222,105, 6,164,160,165,204,165,250,166, 5,166, 30,166,166, 229,245,108, 9,164,182,164,217,164,232,164,246,165, 36,165, 50, 165,136,165,149,165,184, 97, 2,164,188,164,203,227,233,242,227, 236,229,235,239,242,229,225,110,128, 50,113,240,225,242,229,238, 235,239,242,229,225,110,128, 50, 17,227,233,242,227,236,229,235, 239,242,229,225,110,128, 50, 99,232,233,229,245,232,235,239,242, 229,225,110,128, 49, 64,107, 2,164,252,165, 28,233,249,229,239, 107, 2,165, 6,165, 15,235,239,242,229,225,110,128, 49, 58,243, 233,239,243,235,239,242,229,225,110,128, 49,105,239,242,229,225, 110,128, 49, 57,237,233,229,245,237,235,239,242,229,225,110,128, 49, 59,112, 3,165, 58,165, 90,165,105, 97, 2,165, 64,165, 78, 238,243,233,239,243,235,239,242,229,225,110,128, 49,108,242,229, 238,235,239,242,229,225,110,128, 50, 3,232,233,229,245,240,232, 235,239,242,229,225,110,128, 49, 63,233,229,245,112, 2,165,114, 165,123,235,239,242,229,225,110,128, 49, 60,243,233,239,243,235, 239,242,229,225,110,128, 49,107,243,233,239,243,235,239,242,229, 225,110,128, 49, 61,116, 2,165,155,165,170,232,233,229,245,244, 232,235,239,242,229,225,110,128, 49, 62,233,235,229,245,244,235, 239,242,229,225,110,128, 49,106,249,229,239,242,233,238,232,233, 229,245,232,235,239,242,229,225,110,128, 49,109,231,232,116, 2, 165,212,165,220,225,238,231,236,101,128, 34, 31,116, 2,165,226, 165,240,225,227,235,226,229,236,239,247,227,237, 98,128, 3, 25, 242,233,225,238,231,236,101,128, 34,191,232,233,242,225,231,225, 238, 97,128, 48,138,235,225,244,225,235,225,238, 97,129, 48,234, 166, 18,232,225,236,230,247,233,228,244,104,128,255,152,110, 2, 166, 36,166,152,103,131, 2,218,166, 46,166, 57,166, 63,226,229, 236,239,247,227,237, 98,128, 3, 37,227,237, 98,128, 3, 10,232, 225,236,102, 2,166, 72,166,118,236,229,230,116,131, 2,191,166, 85,166, 96,166,107,225,242,237,229,238,233,225,110,128, 5, 89, 226,229,236,239,247,227,237, 98,128, 3, 28,227,229,238,244,229, 242,229,100,128, 2,211,242,233,231,232,116,130, 2,190,166,130, 166,141,226,229,236,239,247,227,237, 98,128, 3, 57,227,229,238, 244,229,242,229,100,128, 2,210,246,229,242,244,229,228,226,242, 229,246,101,128, 2, 19,244,244,239,242,245,243,241,245,225,242, 101,128, 51, 81,108, 2,166,186,166,197,233,238,229,226,229,236, 239,119,128, 30, 95,239,238,231,236,229,103,129, 2,124,166,208, 244,245,242,238,229,100,128, 2,122,237,239,238,239,243,240,225, 227,101,128,255, 82,111, 3,166,237,166,248,167, 17,232,233,242, 225,231,225,238, 97,128, 48,141,235,225,244,225,235,225,238, 97, 129, 48,237,167, 5,232,225,236,230,247,233,228,244,104,128,255, 155,242,245,225,244,232,225,105,128, 14, 35,240,225,242,229,110, 128, 36,173,114, 3,167, 43,167, 79,167,109, 97, 3,167, 51,167, 61,167, 68,226,229,238,231,225,236,105,128, 9,220,228,229,246, 97,128, 9, 49,231,245,242,237,245,235,232,105,128, 10, 92,229, 104, 2,167, 86,167, 95,225,242,225,226,233, 99,128, 6,145,230, 233,238,225,236,225,242,225,226,233, 99,128,251,141,246,239,227, 225,236,233, 99, 4,167,125,167,135,167,142,167,153,226,229,238, 231,225,236,105,128, 9,224,228,229,246, 97,128, 9, 96,231,245, 234,225,242,225,244,105,128, 10,224,246,239,247,229,236,243,233, 231,110, 3,167,169,167,179,167,186,226,229,238,231,225,236,105, 128, 9,196,228,229,246, 97,128, 9, 68,231,245,234,225,242,225, 244,105,128, 10,196,243,245,240,229,242,233,239,114,128,246,241, 116, 2,167,214,167,222,226,236,239,227,107,128, 37,144,245,242, 238,229,100,129, 2,121,167,232,243,245,240,229,242,233,239,114, 128, 2,180,117, 4,167,253,168, 8,168, 33,168, 80,232,233,242, 225,231,225,238, 97,128, 48,139,235,225,244,225,235,225,238, 97, 129, 48,235,168, 21,232,225,236,230,247,233,228,244,104,128,255, 153,112, 2,168, 39,168, 74,229,101, 2,168, 46,168, 60,237,225, 242,235,226,229,238,231,225,236,105,128, 9,242,243,233,231,238, 226,229,238,231,225,236,105,128, 9,243,233,225,104,128,246,221, 244,232,225,105,128, 14, 36,246,239,227,225,236,233, 99, 4,168, 103,168,113,168,120,168,131,226,229,238,231,225,236,105,128, 9, 139,228,229,246, 97,128, 9, 11,231,245,234,225,242,225,244,105, 128, 10,139,246,239,247,229,236,243,233,231,110, 3,168,147,168, 157,168,164,226,229,238,231,225,236,105,128, 9,195,228,229,246, 97,128, 9, 67,231,245,234,225,242,225,244,105,128, 10,195,115, 147, 0,115,168,217,170,187,170,198,171, 68,171,107,174, 49,174, 60,176,203,179, 85,179,131,179,158,180, 93,180,160,181,193,181, 203,182,133,182,206,183,120,183,130, 97, 9,168,237,168,247,169, 12,169, 84,169,109,169,120,169,145,169,177,169,217,226,229,238, 231,225,236,105,128, 9,184,227,245,244,101,129, 1, 91,169, 0, 228,239,244,225,227,227,229,238,116,128, 30,101,100, 5,169, 24, 169, 33,169, 39,169, 53,169, 69,225,242,225,226,233, 99,128, 6, 53,229,246, 97,128, 9, 56,230,233,238,225,236,225,242,225,226, 233, 99,128,254,186,233,238,233,244,233,225,236,225,242,225,226, 233, 99,128,254,187,237,229,228,233,225,236,225,242,225,226,233, 99,128,254,188,231,117, 2,169, 91,169,100,234,225,242,225,244, 105,128, 10,184,242,237,245,235,232,105,128, 10, 56,232,233,242, 225,231,225,238, 97,128, 48, 85,235,225,244,225,235,225,238, 97, 129, 48,181,169,133,232,225,236,230,247,233,228,244,104,128,255, 123,236,236,225,236,236,225,232,239,245,225,236,225,249,232,229, 247,225,243,225,236,236,225,237,225,242,225,226,233, 99,128,253, 250,237,229,235,104,130, 5,225,169,188,169,208,228,225,231,229, 243,104,129,251, 65,169,199,232,229,226,242,229,119,128,251, 65, 232,229,226,242,229,119,128, 5,225,242, 97, 5,169,230,170, 48, 170, 56,170,106,170,114, 97, 5,169,242,169,250,170, 2,170, 33, 170, 41,225,244,232,225,105,128, 14, 50,229,244,232,225,105,128, 14, 65,233,237,225,233,109, 2,170, 12,170, 23,225,236,225,233, 244,232,225,105,128, 14, 68,245,225,238,244,232,225,105,128, 14, 67,237,244,232,225,105,128, 14, 51,244,232,225,105,128, 14, 48, 229,244,232,225,105,128, 14, 64,105, 3,170, 64,170, 88,170, 99, 105, 2,170, 70,170, 81,236,229,230,244,244,232,225,105,128,248, 134,244,232,225,105,128, 14, 53,236,229,230,244,244,232,225,105, 128,248,133,244,232,225,105,128, 14, 52,239,244,232,225,105,128, 14, 66,117, 3,170,122,170,172,170,179,101, 3,170,130,170,154, 170,165,101, 2,170,136,170,147,236,229,230,244,244,232,225,105, 128,248,136,244,232,225,105,128, 14, 55,236,229,230,244,244,232, 225,105,128,248,135,244,232,225,105,128, 14, 54,244,232,225,105, 128, 14, 56,245,244,232,225,105,128, 14, 57,226,239,240,239,237, 239,230,111,128, 49, 25, 99, 5,170,210,170,231,170,240,171, 33, 171, 55,225,242,239,110,129, 1, 97,170,219,228,239,244,225,227, 227,229,238,116,128, 30,103,229,228,233,236,236, 97,128, 1, 95, 232,247, 97,131, 2, 89,170,252,171, 7,171, 26,227,249,242,233, 236,236,233, 99,128, 4,217,228,233,229,242,229,243,233,243,227, 249,242,233,236,236,233, 99,128, 4,219,232,239,239,107,128, 2, 90,233,242, 99, 2,171, 41,171, 46,236,101,128, 36,226,245,237, 230,236,229,120,128, 1, 93,239,237,237,225,225,227,227,229,238, 116,128, 2, 25,228,239,116, 2,171, 76,171, 85,225,227,227,229, 238,116,128, 30, 97,226,229,236,239,119,129, 30, 99,171, 95,228, 239,244,225,227,227,229,238,116,128, 30,105,101, 9,171,127,171, 143,171,178,171,243,172, 90,172,117,172,142,172,223,172,250,225, 231,245,236,236,226,229,236,239,247,227,237, 98,128, 3, 60, 99, 2,171,149,171,171,239,238,100,129, 32, 51,171,157,244,239,238, 229,227,232,233,238,229,243,101,128, 2,202,244,233,239,110,128, 0,167,229,110, 4,171,189,171,198,171,212,171,228,225,242,225, 226,233, 99,128, 6, 51,230,233,238,225,236,225,242,225,226,233, 99,128,254,178,233,238,233,244,233,225,236,225,242,225,226,233, 99,128,254,179,237,229,228,233,225,236,225,242,225,226,233, 99, 128,254,180,231,239,108,135, 5,182,172, 7,172, 21,172, 26,172, 35,172, 50,172, 66,172, 77, 49, 2,172, 13,172, 17, 51,128, 5, 182,102,128, 5,182,178, 99,128, 5,182,232,229,226,242,229,119, 128, 5,182,238,225,242,242,239,247,232,229,226,242,229,119,128, 5,182,241,245,225,242,244,229,242,232,229,226,242,229,119,128, 5,182,244,225,232,229,226,242,229,119,128, 5,146,247,233,228, 229,232,229,226,242,229,119,128, 5,182,104, 2,172, 96,172,107, 225,242,237,229,238,233,225,110,128, 5,125,233,242,225,231,225, 238, 97,128, 48, 91,235,225,244,225,235,225,238, 97,129, 48,187, 172,130,232,225,236,230,247,233,228,244,104,128,255,126,237,105, 2,172,149,172,192,227,239,236,239,110,131, 0, 59,172,163,172, 172,172,184,225,242,225,226,233, 99,128, 6, 27,237,239,238,239, 243,240,225,227,101,128,255, 27,243,237,225,236,108,128,254, 84, 246,239,233,227,229,228,237,225,242,235,235,225,238, 97,129, 48, 156,172,211,232,225,236,230,247,233,228,244,104,128,255,159,238, 116, 2,172,230,172,240,233,243,241,245,225,242,101,128, 51, 34, 239,243,241,245,225,242,101,128, 51, 35,246,229,110,142, 0, 55, 173, 28,173, 37,173, 47,173, 77,173, 84,173, 94,173,119,173,146, 173,180,173,192,173,203,173,236,173,244,173,255,225,242,225,226, 233, 99,128, 6,103,226,229,238,231,225,236,105,128, 9,237,227, 233,242,227,236,101,129, 36,102,173, 58,233,238,246,229,242,243, 229,243,225,238,243,243,229,242,233,102,128, 39,144,228,229,246, 97,128, 9,109,229,233,231,232,244,232,115,128, 33, 94,231,117, 2,173,101,173,110,234,225,242,225,244,105,128, 10,237,242,237, 245,235,232,105,128, 10,109,232, 97, 2,173,126,173,137,227,235, 225,242,225,226,233, 99,128, 6,103,238,231,250,232,239,117,128, 48, 39,105, 2,173,152,173,170,228,229,239,231,242,225,240,232, 233,227,240,225,242,229,110,128, 50, 38,238,230,229,242,233,239, 114,128, 32,135,237,239,238,239,243,240,225,227,101,128,255, 23, 239,236,228,243,244,249,236,101,128,247, 55,112, 2,173,209,173, 216,225,242,229,110,128, 36,122,229,114, 2,173,223,173,229,233, 239,100,128, 36,142,243,233,225,110,128, 6,247,242,239,237,225, 110,128, 33,118,243,245,240,229,242,233,239,114,128, 32,119,116, 2,174, 5,174, 43,229,229,110, 2,174, 13,174, 22,227,233,242, 227,236,101,128, 36,112,112, 2,174, 28,174, 35,225,242,229,110, 128, 36,132,229,242,233,239,100,128, 36,152,232,225,105,128, 14, 87,230,244,232,249,240,232,229,110,128, 0,173,104, 7,174, 76, 175, 50,175, 61,175, 75,176, 20,176, 33,176,197, 97, 6,174, 90, 174,101,174,111,174,122,175, 9,175, 34,225,242,237,229,238,233, 225,110,128, 5,119,226,229,238,231,225,236,105,128, 9,182,227, 249,242,233,236,236,233, 99,128, 4, 72,100, 2,174,128,174,224, 228, 97, 4,174,139,174,148,174,179,174,193,225,242,225,226,233, 99,128, 6, 81,228,225,237,237, 97, 2,174,158,174,167,225,242, 225,226,233, 99,128,252, 97,244,225,238,225,242,225,226,233, 99, 128,252, 94,230,225,244,232,225,225,242,225,226,233, 99,128,252, 96,235,225,243,242, 97, 2,174,203,174,212,225,242,225,226,233, 99,128,252, 98,244,225,238,225,242,225,226,233, 99,128,252, 95, 101,132, 37,146,174,236,174,243,174,251,175, 4,228,225,242,107, 128, 37,147,236,233,231,232,116,128, 37,145,237,229,228,233,245, 109,128, 37,146,246, 97,128, 9, 54,231,117, 2,175, 16,175, 25, 234,225,242,225,244,105,128, 10,182,242,237,245,235,232,105,128, 10, 54,236,243,232,229,236,229,244,232,229,226,242,229,119,128, 5,147,226,239,240,239,237,239,230,111,128, 49, 21,227,232,225, 227,249,242,233,236,236,233, 99,128, 4, 73,101, 4,175, 85,175, 150,175,160,175,177,229,110, 4,175, 96,175,105,175,119,175,135, 225,242,225,226,233, 99,128, 6, 52,230,233,238,225,236,225,242, 225,226,233, 99,128,254,182,233,238,233,244,233,225,236,225,242, 225,226,233, 99,128,254,183,237,229,228,233,225,236,225,242,225, 226,233, 99,128,254,184,233,227,239,240,244,233, 99,128, 3,227, 241,229,108,129, 32,170,175,168,232,229,226,242,229,119,128, 32, 170,246, 97,134, 5,176,175,194,175,209,175,223,175,232,175,247, 176, 7, 49, 2,175,200,175,205,177, 53,128, 5,176, 53,128, 5, 176, 50, 2,175,215,175,219, 50,128, 5,176,101,128, 5,176,232, 229,226,242,229,119,128, 5,176,238,225,242,242,239,247,232,229, 226,242,229,119,128, 5,176,241,245,225,242,244,229,242,232,229, 226,242,229,119,128, 5,176,247,233,228,229,232,229,226,242,229, 119,128, 5,176,232,225,227,249,242,233,236,236,233, 99,128, 4, 187,105, 2,176, 39,176, 50,237,225,227,239,240,244,233, 99,128, 3,237,110,131, 5,233,176, 60,176,143,176,152,100, 2,176, 66, 176,132,225,231,229,243,104,130,251, 73,176, 78,176, 87,232,229, 226,242,229,119,128,251, 73,115, 2,176, 93,176,113,232,233,238, 228,239,116,129,251, 44,176,104,232,229,226,242,229,119,128,251, 44,233,238,228,239,116,129,251, 45,176,123,232,229,226,242,229, 119,128,251, 45,239,244,232,229,226,242,229,119,128, 5,193,232, 229,226,242,229,119,128, 5,233,115, 2,176,158,176,178,232,233, 238,228,239,116,129,251, 42,176,169,232,229,226,242,229,119,128, 251, 42,233,238,228,239,116,129,251, 43,176,188,232,229,226,242, 229,119,128,251, 43,239,239,107,128, 2,130,105, 8,176,221,177, 9,177, 20,177, 45,177, 75,177, 83,177, 96,178, 11,231,237, 97, 131, 3,195,176,233,176,237,176,245, 49,128, 3,194,230,233,238, 225,108,128, 3,194,236,245,238,225,244,229,243,249,237,226,239, 236,231,242,229,229,107,128, 3,242,232,233,242,225,231,225,238, 97,128, 48, 87,235,225,244,225,235,225,238, 97,129, 48,183,177, 33,232,225,236,230,247,233,228,244,104,128,255,124,236,245,113, 2,177, 53,177, 62,232,229,226,242,229,119,128, 5,189,236,229, 230,244,232,229,226,242,229,119,128, 5,189,237,233,236,225,114, 128, 34, 60,238,228,239,244,232,229,226,242,229,119,128, 5,194, 239,115, 6,177,111,177,146,177,178,177,206,177,220,177,252, 97, 2,177,117,177,132,227,233,242,227,236,229,235,239,242,229,225, 110,128, 50,116,240,225,242,229,238,235,239,242,229,225,110,128, 50, 20,227,105, 2,177,153,177,165,229,245,227,235,239,242,229, 225,110,128, 49,126,242,227,236,229,235,239,242,229,225,110,128, 50,102,107, 2,177,184,177,198,233,249,229,239,235,235,239,242, 229,225,110,128, 49,122,239,242,229,225,110,128, 49, 69,238,233, 229,245,238,235,239,242,229,225,110,128, 49,123,112, 2,177,226, 177,239,225,242,229,238,235,239,242,229,225,110,128, 50, 6,233, 229,245,240,235,239,242,229,225,110,128, 49,125,244,233,235,229, 245,244,235,239,242,229,225,110,128, 49,124,120,141, 0, 54,178, 41,178, 50,178, 60,178, 90,178, 97,178,122,178,149,178,183,178, 195,178,206,178,239,178,247,179, 2,225,242,225,226,233, 99,128, 6,102,226,229,238,231,225,236,105,128, 9,236,227,233,242,227, 236,101,129, 36,101,178, 71,233,238,246,229,242,243,229,243,225, 238,243,243,229,242,233,102,128, 39,143,228,229,246, 97,128, 9, 108,231,117, 2,178,104,178,113,234,225,242,225,244,105,128, 10, 236,242,237,245,235,232,105,128, 10,108,232, 97, 2,178,129,178, 140,227,235,225,242,225,226,233, 99,128, 6,102,238,231,250,232, 239,117,128, 48, 38,105, 2,178,155,178,173,228,229,239,231,242, 225,240,232,233,227,240,225,242,229,110,128, 50, 37,238,230,229, 242,233,239,114,128, 32,134,237,239,238,239,243,240,225,227,101, 128,255, 22,239,236,228,243,244,249,236,101,128,247, 54,112, 2, 178,212,178,219,225,242,229,110,128, 36,121,229,114, 2,178,226, 178,232,233,239,100,128, 36,141,243,233,225,110,128, 6,246,242, 239,237,225,110,128, 33,117,243,245,240,229,242,233,239,114,128, 32,118,116, 2,179, 8,179, 79,229,229,110, 2,179, 16,179, 58, 99, 2,179, 22,179, 30,233,242,227,236,101,128, 36,111,245,242, 242,229,238,227,249,228,229,238,239,237,233,238,225,244,239,242, 226,229,238,231,225,236,105,128, 9,249,112, 2,179, 64,179, 71, 225,242,229,110,128, 36,131,229,242,233,239,100,128, 36,151,232, 225,105,128, 14, 86,108, 2,179, 91,179,111,225,243,104,129, 0, 47,179, 99,237,239,238,239,243,240,225,227,101,128,255, 15,239, 238,103,129, 1,127,179,119,228,239,244,225,227,227,229,238,116, 128, 30,155,109, 2,179,137,179,147,233,236,229,230,225,227,101, 128, 38, 58,239,238,239,243,240,225,227,101,128,255, 83,111, 6, 179,172,179,222,179,233,180, 2,180, 47,180, 58,102, 2,179,178, 179,192,240,225,243,245,241,232,229,226,242,229,119,128, 5,195, 116, 2,179,198,179,207,232,249,240,232,229,110,128, 0,173,243, 233,231,238,227,249,242,233,236,236,233, 99,128, 4, 76,232,233, 242,225,231,225,238, 97,128, 48, 93,235,225,244,225,235,225,238, 97,129, 48,189,179,246,232,225,236,230,247,233,228,244,104,128, 255,127,236,233,228,245,115, 2,180, 12,180, 29,236,239,238,231, 239,246,229,242,236,225,249,227,237, 98,128, 3, 56,243,232,239, 242,244,239,246,229,242,236,225,249,227,237, 98,128, 3, 55,242, 245,243,233,244,232,225,105,128, 14, 41,115, 3,180, 66,180, 76, 180, 84,225,236,225,244,232,225,105,128, 14, 40,239,244,232,225, 105,128, 14, 11,245,225,244,232,225,105,128, 14, 42,240, 97, 3, 180,102,180,122,180,154,227,101,129, 0, 32,180,109,232,225,227, 235,225,242,225,226,233, 99,128, 0, 32,228,101,129, 38, 96,180, 129,243,245,233,116, 2,180,138,180,146,226,236,225,227,107,128, 38, 96,247,232,233,244,101,128, 38,100,242,229,110,128, 36,174, 241,245,225,242,101, 11,180,188,180,199,180,213,180,238,180,255, 181, 25,181, 40,181, 73,181,100,181,156,181,171,226,229,236,239, 247,227,237, 98,128, 3, 59, 99, 2,180,205,180,209, 99,128, 51, 196,109,128, 51,157,228,233,225,231,239,238,225,236,227,242,239, 243,243,232,225,244,227,232,230,233,236,108,128, 37,169,232,239, 242,233,250,239,238,244,225,236,230,233,236,108,128, 37,164,107, 2,181, 5,181, 9,103,128, 51,143,109,129, 51,158,181, 15,227, 225,240,233,244,225,108,128, 51,206,108, 2,181, 31,181, 35,110, 128, 51,209,239,103,128, 51,210,109, 4,181, 50,181, 54,181, 59, 181, 63,103,128, 51,142,233,108,128, 51,213,109,128, 51,156,243, 241,245,225,242,229,100,128, 51,161,239,242,244,232,239,231,239, 238,225,236,227,242,239,243,243,232,225,244,227,232,230,233,236, 108,128, 37,166,245,240,240,229,114, 2,181,110,181,133,236,229, 230,244,244,239,236,239,247,229,242,242,233,231,232,244,230,233, 236,108,128, 37,167,242,233,231,232,244,244,239,236,239,247,229, 242,236,229,230,244,230,233,236,108,128, 37,168,246,229,242,244, 233,227,225,236,230,233,236,108,128, 37,165,247,232,233,244,229, 247,233,244,232,243,237,225,236,236,226,236,225,227,107,128, 37, 163,242,243,241,245,225,242,101,128, 51,219,115, 2,181,209,182, 123, 97, 4,181,219,181,229,181,236,181,247,226,229,238,231,225, 236,105,128, 9,183,228,229,246, 97,128, 9, 55,231,245,234,225, 242,225,244,105,128, 10,183,238,103, 8,182, 10,182, 24,182, 38, 182, 52,182, 67,182, 81,182, 95,182,108,227,233,229,245,227,235, 239,242,229,225,110,128, 49, 73,232,233,229,245,232,235,239,242, 229,225,110,128, 49,133,233,229,245,238,231,235,239,242,229,225, 110,128, 49,128,235,233,249,229,239,235,235,239,242,229,225,110, 128, 49, 50,238,233,229,245,238,235,239,242,229,225,110,128, 49, 101,240,233,229,245,240,235,239,242,229,225,110,128, 49, 67,243, 233,239,243,235,239,242,229,225,110,128, 49, 70,244,233,235,229, 245,244,235,239,242,229,225,110,128, 49, 56,245,240,229,242,233, 239,114,128,246,242,116, 2,182,139,182,162,229,242,236,233,238, 103,129, 0,163,182,150,237,239,238,239,243,240,225,227,101,128, 255,225,242,239,235,101, 2,182,171,182,188,236,239,238,231,239, 246,229,242,236,225,249,227,237, 98,128, 3, 54,243,232,239,242, 244,239,246,229,242,236,225,249,227,237, 98,128, 3, 53,117, 7, 182,222,182,254,183, 20,183, 31,183, 72,183, 82,183, 86,226,243, 229,116,130, 34,130,182,233,182,244,238,239,244,229,241,245,225, 108,128, 34,138,239,242,229,241,245,225,108,128, 34,134, 99, 2, 183, 4,183, 12,227,229,229,228,115,128, 34,123,232,244,232,225, 116,128, 34, 11,232,233,242,225,231,225,238, 97,128, 48, 89,107, 2,183, 37,183, 61,225,244,225,235,225,238, 97,129, 48,185,183, 49,232,225,236,230,247,233,228,244,104,128,255,125,245,238,225, 242,225,226,233, 99,128, 6, 82,237,237,225,244,233,239,110,128, 34, 17,110,128, 38, 60,240,229,242,243,229,116,130, 34,131,183, 99,183,110,238,239,244,229,241,245,225,108,128, 34,139,239,242, 229,241,245,225,108,128, 34,135,246,243,241,245,225,242,101,128, 51,220,249,239,245,247,225,229,242,225,243,241,245,225,242,101, 128, 51,124,116,144, 0,116,183,183,184,192,184,213,185,100,185, 140,187,188,191, 70,192,145,192,157,192,169,193,202,193,227,194, 57,194,237,195,165,195,255, 97, 10,183,205,183,215,183,236,183, 243,184, 12,184, 90,184,107,184,132,184,146,184,150,226,229,238, 231,225,236,105,128, 9,164,227,107, 2,183,222,183,229,228,239, 247,110,128, 34,164,236,229,230,116,128, 34,163,228,229,246, 97, 128, 9, 36,231,117, 2,183,250,184, 3,234,225,242,225,244,105, 128, 10,164,242,237,245,235,232,105,128, 10, 36,104, 4,184, 22, 184, 31,184, 45,184, 75,225,242,225,226,233, 99,128, 6, 55,230, 233,238,225,236,225,242,225,226,233, 99,128,254,194,105, 2,184, 51,184, 66,238,233,244,233,225,236,225,242,225,226,233, 99,128, 254,195,242,225,231,225,238, 97,128, 48, 95,237,229,228,233,225, 236,225,242,225,226,233, 99,128,254,196,233,243,249,239,245,229, 242,225,243,241,245,225,242,101,128, 51,125,235,225,244,225,235, 225,238, 97,129, 48,191,184,120,232,225,236,230,247,233,228,244, 104,128,255,128,244,247,229,229,236,225,242,225,226,233, 99,128, 6, 64,117,128, 3,196,118,130, 5,234,184,158,184,183,228,225, 231,229,115,129,251, 74,184,168,104,129,251, 74,184,174,232,229, 226,242,229,119,128,251, 74,232,229,226,242,229,119,128, 5,234, 98, 2,184,198,184,203,225,114,128, 1,103,239,240,239,237,239, 230,111,128, 49, 10, 99, 6,184,227,184,234,184,241,184,250,185, 60,185, 87,225,242,239,110,128, 1,101,227,245,242,108,128, 2, 168,229,228,233,236,236, 97,128, 1, 99,232,229,104, 4,185, 6, 185, 15,185, 29,185, 45,225,242,225,226,233, 99,128, 6,134,230, 233,238,225,236,225,242,225,226,233, 99,128,251,123,233,238,233, 244,233,225,236,225,242,225,226,233, 99,128,251,124,237,229,228, 233,225,236,225,242,225,226,233, 99,128,251,125,233,242, 99, 2, 185, 68,185, 73,236,101,128, 36,227,245,237,230,236,229,248,226, 229,236,239,119,128, 30,113,239,237,237,225,225,227,227,229,238, 116,128, 1, 99,100, 2,185,106,185,116,233,229,242,229,243,233, 115,128, 30,151,239,116, 2,185,123,185,132,225,227,227,229,238, 116,128, 30,107,226,229,236,239,119,128, 30,109,101, 9,185,160, 185,171,185,191,186,201,186,226,187, 34,187,101,187,106,187,158, 227,249,242,233,236,236,233, 99,128, 4, 66,228,229,243,227,229, 238,228,229,242,227,249,242,233,236,236,233, 99,128, 4,173,104, 7,185,207,185,216,185,230,186, 14,186, 44,186, 85,186,183,225, 242,225,226,233, 99,128, 6, 42,230,233,238,225,236,225,242,225, 226,233, 99,128,254,150,232,225,232,105, 2,185,239,185,254,238, 233,244,233,225,236,225,242,225,226,233, 99,128,252,162,243,239, 236,225,244,229,228,225,242,225,226,233, 99,128,252, 12,105, 2, 186, 20,186, 35,238,233,244,233,225,236,225,242,225,226,233, 99, 128,254,151,242,225,231,225,238, 97,128, 48,102,234,229,229,237, 105, 2,186, 54,186, 69,238,233,244,233,225,236,225,242,225,226, 233, 99,128,252,161,243,239,236,225,244,229,228,225,242,225,226, 233, 99,128,252, 11,109, 2,186, 91,186,125,225,242,226,245,244, 97, 2,186,102,186,111,225,242,225,226,233, 99,128, 6, 41,230, 233,238,225,236,225,242,225,226,233, 99,128,254,148,101, 2,186, 131,186,144,228,233,225,236,225,242,225,226,233, 99,128,254,152, 229,237,105, 2,186,152,186,167,238,233,244,233,225,236,225,242, 225,226,233, 99,128,252,164,243,239,236,225,244,229,228,225,242, 225,226,233, 99,128,252, 14,238,239,239,238,230,233,238,225,236, 225,242,225,226,233, 99,128,252,115,235,225,244,225,235,225,238, 97,129, 48,198,186,214,232,225,236,230,247,233,228,244,104,128, 255,131,108, 2,186,232,186,251,229,240,232,239,238,101,129, 33, 33,186,243,226,236,225,227,107,128, 38, 14,233,243,232, 97, 2, 187, 4,187, 19,231,229,228,239,236,225,232,229,226,242,229,119, 128, 5,160,241,229,244,225,238,225,232,229,226,242,229,119,128, 5,169,110, 4,187, 44,187, 53,187, 72,187, 93,227,233,242,227, 236,101,128, 36,105,233,228,229,239,231,242,225,240,232,233,227, 240,225,242,229,110,128, 50, 41,112, 2,187, 78,187, 85,225,242, 229,110,128, 36,125,229,242,233,239,100,128, 36,145,242,239,237, 225,110,128, 33,121,243,104,128, 2,167,116,131, 5,216,187,116, 187,136,187,145,228,225,231,229,243,104,129,251, 56,187,127,232, 229,226,242,229,119,128,251, 56,232,229,226,242,229,119,128, 5, 216,243,229,227,249,242,233,236,236,233, 99,128, 4,181,246,233, 114, 2,187,166,187,175,232,229,226,242,229,119,128, 5,155,236, 229,230,244,232,229,226,242,229,119,128, 5,155,104, 6,187,202, 188, 98,188,220,189, 96,190, 3,191, 60, 97, 5,187,214,187,224, 187,231,188, 0,188, 29,226,229,238,231,225,236,105,128, 9,165, 228,229,246, 97,128, 9, 37,231,117, 2,187,238,187,247,234,225, 242,225,244,105,128, 10,165,242,237,245,235,232,105,128, 10, 37, 108, 2,188, 6,188, 15,225,242,225,226,233, 99,128, 6, 48,230, 233,238,225,236,225,242,225,226,233, 99,128,254,172,238,244,232, 225,235,232,225,116, 3,188, 44,188, 75,188, 82,236,239,119, 2, 188, 52,188, 63,236,229,230,244,244,232,225,105,128,248,152,242, 233,231,232,244,244,232,225,105,128,248,151,244,232,225,105,128, 14, 76,245,240,240,229,242,236,229,230,244,244,232,225,105,128, 248,150,101, 3,188,106,188,170,188,193,104, 4,188,116,188,125, 188,139,188,155,225,242,225,226,233, 99,128, 6, 43,230,233,238, 225,236,225,242,225,226,233, 99,128,254,154,233,238,233,244,233, 225,236,225,242,225,226,233, 99,128,254,155,237,229,228,233,225, 236,225,242,225,226,233, 99,128,254,156,242,101, 2,188,177,188, 186,229,248,233,243,244,115,128, 34, 3,230,239,242,101,128, 34, 52,244, 97,130, 3,184,188,202,188,206, 49,128, 3,209,243,249, 237,226,239,236,231,242,229,229,107,128, 3,209,105, 2,188,226, 189, 56,229,245,244,104, 4,188,239,189, 18,189, 33,189, 42, 97, 2,188,245,189, 4,227,233,242,227,236,229,235,239,242,229,225, 110,128, 50,121,240,225,242,229,238,235,239,242,229,225,110,128, 50, 25,227,233,242,227,236,229,235,239,242,229,225,110,128, 50, 107,235,239,242,229,225,110,128, 49, 76,240,225,242,229,238,235, 239,242,229,225,110,128, 50, 11,242,244,229,229,110, 2,189, 66, 189, 75,227,233,242,227,236,101,128, 36,108,112, 2,189, 81,189, 88,225,242,229,110,128, 36,128,229,242,233,239,100,128, 36,148, 111, 6,189,110,189,127,189,132,189,146,189,151,189,204,238,225, 238,231,237,239,238,244,232,239,244,232,225,105,128, 14, 17,239, 107,128, 1,173,240,232,245,244,232,225,239,244,232,225,105,128, 14, 18,242,110,128, 0,254,244,104, 3,189,160,189,184,189,194, 97, 2,189,166,189,176,232,225,238,244,232,225,105,128, 14, 23, 238,244,232,225,105,128, 14, 16,239,238,231,244,232,225,105,128, 14, 24,245,238,231,244,232,225,105,128, 14, 22,245,243,225,238, 100, 2,189,214,189,225,227,249,242,233,236,236,233, 99,128, 4, 130,243,243,229,240,225,242,225,244,239,114, 2,189,240,189,249, 225,242,225,226,233, 99,128, 6,108,240,229,242,243,233,225,110, 128, 6,108,242,229,101,144, 0, 51,190, 41,190, 50,190, 60,190, 90,190, 97,190,107,190,132,190,159,190,193,190,205,190,224,190, 235,191, 12,191, 34,191, 42,191, 53,225,242,225,226,233, 99,128, 6, 99,226,229,238,231,225,236,105,128, 9,233,227,233,242,227, 236,101,129, 36, 98,190, 71,233,238,246,229,242,243,229,243,225, 238,243,243,229,242,233,102,128, 39,140,228,229,246, 97,128, 9, 105,229,233,231,232,244,232,115,128, 33, 92,231,117, 2,190,114, 190,123,234,225,242,225,244,105,128, 10,233,242,237,245,235,232, 105,128, 10,105,232, 97, 2,190,139,190,150,227,235,225,242,225, 226,233, 99,128, 6, 99,238,231,250,232,239,117,128, 48, 35,105, 2,190,165,190,183,228,229,239,231,242,225,240,232,233,227,240, 225,242,229,110,128, 50, 34,238,230,229,242,233,239,114,128, 32, 131,237,239,238,239,243,240,225,227,101,128,255, 19,238,245,237, 229,242,225,244,239,242,226,229,238,231,225,236,105,128, 9,246, 239,236,228,243,244,249,236,101,128,247, 51,112, 2,190,241,190, 248,225,242,229,110,128, 36,118,229,114, 2,190,255,191, 5,233, 239,100,128, 36,138,243,233,225,110,128, 6,243,241,245,225,242, 244,229,242,115,129, 0,190,191, 25,229,237,228,225,243,104,128, 246,222,242,239,237,225,110,128, 33,114,243,245,240,229,242,233, 239,114,128, 0,179,244,232,225,105,128, 14, 83,250,243,241,245, 225,242,101,128, 51,148,105, 7,191, 86,191, 97,191,212,192, 54, 192, 66,192,115,192,132,232,233,242,225,231,225,238, 97,128, 48, 97,107, 2,191,103,191,127,225,244,225,235,225,238, 97,129, 48, 193,191,115,232,225,236,230,247,233,228,244,104,128,255,129,229, 245,116, 4,191,139,191,174,191,189,191,198, 97, 2,191,145,191, 160,227,233,242,227,236,229,235,239,242,229,225,110,128, 50,112, 240,225,242,229,238,235,239,242,229,225,110,128, 50, 16,227,233, 242,227,236,229,235,239,242,229,225,110,128, 50, 98,235,239,242, 229,225,110,128, 49, 55,240,225,242,229,238,235,239,242,229,225, 110,128, 50, 2,236,228,101,133, 2,220,191,228,191,239,192, 0, 192, 12,192, 40,226,229,236,239,247,227,237, 98,128, 3, 48, 99, 2,191,245,191,250,237, 98,128, 3, 3,239,237, 98,128, 3, 3, 228,239,245,226,236,229,227,237, 98,128, 3, 96,111, 2,192, 18, 192, 28,240,229,242,225,244,239,114,128, 34, 60,246,229,242,236, 225,249,227,237, 98,128, 3, 52,246,229,242,244,233,227,225,236, 227,237, 98,128, 3, 62,237,229,243,227,233,242,227,236,101,128, 34,151,112, 2,192, 72,192,102,229,232, 97, 2,192, 80,192, 89, 232,229,226,242,229,119,128, 5,150,236,229,230,244,232,229,226, 242,229,119,128, 5,150,240,233,231,245,242,237,245,235,232,105, 128, 10,112,244,236,239,227,249,242,233,236,236,233,227,227,237, 98,128, 4,131,247,238,225,242,237,229,238,233,225,110,128, 5, 127,236,233,238,229,226,229,236,239,119,128, 30,111,237,239,238, 239,243,240,225,227,101,128,255, 84,111, 7,192,185,192,196,192, 207,192,232,193, 96,193,108,193,192,225,242,237,229,238,233,225, 110,128, 5,105,232,233,242,225,231,225,238, 97,128, 48,104,235, 225,244,225,235,225,238, 97,129, 48,200,192,220,232,225,236,230, 247,233,228,244,104,128,255,132,110, 3,192,240,193, 82,193, 87, 101, 4,192,250,193, 63,193, 70,193, 76,226,225,114, 4,193, 6, 193, 35,193, 45,193, 54,229,248,244,242, 97, 2,193, 16,193, 26, 232,233,231,232,237,239,100,128, 2,229,236,239,247,237,239,100, 128, 2,233,232,233,231,232,237,239,100,128, 2,230,236,239,247, 237,239,100,128, 2,232,237,233,228,237,239,100,128, 2,231,230, 233,246,101,128, 1,189,243,233,120,128, 1,133,244,247,111,128, 1,168,239,115,128, 3,132,243,241,245,225,242,101,128, 51, 39, 240,225,244,225,235,244,232,225,105,128, 14, 15,242,244,239,233, 243,229,243,232,229,236,236,226,242,225,227,235,229,116, 2,193, 131,193,161,236,229,230,116,130, 48, 20,193,142,193,150,243,237, 225,236,108,128,254, 93,246,229,242,244,233,227,225,108,128,254, 57,242,233,231,232,116,130, 48, 21,193,173,193,181,243,237,225, 236,108,128,254, 94,246,229,242,244,233,227,225,108,128,254, 58, 244,225,239,244,232,225,105,128, 14, 21,240, 97, 2,193,209,193, 221,236,225,244,225,236,232,239,239,107,128, 1,171,242,229,110, 128, 36,175,114, 3,193,235,194, 10,194, 25,225,228,229,237,225, 242,107,129, 33, 34,193,247,115, 2,193,253,194, 3,225,238,115, 128,248,234,229,242,233,102,128,246,219,229,244,242,239,230,236, 229,248,232,239,239,107,128, 2,136,233,225,103, 4,194, 37,194, 42,194, 47,194, 52,228,110,128, 37,188,236,102,128, 37,196,242, 116,128, 37,186,245,112,128, 37,178,115,132, 2,166,194, 69,194, 108,194,214,194,227,225,228,105,130, 5,230,194, 79,194, 99,228, 225,231,229,243,104,129,251, 70,194, 90,232,229,226,242,229,119, 128,251, 70,232,229,226,242,229,119,128, 5,230,101, 2,194,114, 194,125,227,249,242,233,236,236,233, 99,128, 4, 70,242,101,134, 5,181,194,142,194,156,194,161,194,170,194,185,194,201, 49, 2, 194,148,194,152, 50,128, 5,181,101,128, 5,181,178, 98,128, 5, 181,232,229,226,242,229,119,128, 5,181,238,225,242,242,239,247, 232,229,226,242,229,119,128, 5,181,241,245,225,242,244,229,242, 232,229,226,242,229,119,128, 5,181,247,233,228,229,232,229,226, 242,229,119,128, 5,181,232,229,227,249,242,233,236,236,233, 99, 128, 4, 91,245,240,229,242,233,239,114,128,246,243,116, 4,194, 247,195, 41,195,106,195,157, 97, 3,194,255,195, 9,195, 16,226, 229,238,231,225,236,105,128, 9,159,228,229,246, 97,128, 9, 31, 231,117, 2,195, 23,195, 32,234,225,242,225,244,105,128, 10,159, 242,237,245,235,232,105,128, 10, 31,229,104, 4,195, 52,195, 61, 195, 75,195, 91,225,242,225,226,233, 99,128, 6,121,230,233,238, 225,236,225,242,225,226,233, 99,128,251,103,233,238,233,244,233, 225,236,225,242,225,226,233, 99,128,251,104,237,229,228,233,225, 236,225,242,225,226,233, 99,128,251,105,232, 97, 3,195,115,195, 125,195,132,226,229,238,231,225,236,105,128, 9,160,228,229,246, 97,128, 9, 32,231,117, 2,195,139,195,148,234,225,242,225,244, 105,128, 10,160,242,237,245,235,232,105,128, 10, 32,245,242,238, 229,100,128, 2,135,117, 3,195,173,195,184,195,209,232,233,242, 225,231,225,238, 97,128, 48,100,235,225,244,225,235,225,238, 97, 129, 48,196,195,197,232,225,236,230,247,233,228,244,104,128,255, 130,243,237,225,236,108, 2,195,219,195,230,232,233,242,225,231, 225,238, 97,128, 48, 99,235,225,244,225,235,225,238, 97,129, 48, 195,195,243,232,225,236,230,247,233,228,244,104,128,255,111,119, 2,196, 5,196,110,101, 2,196, 11,196, 59,236,246,101, 3,196, 21,196, 30,196, 51,227,233,242,227,236,101,128, 36,107,112, 2, 196, 36,196, 43,225,242,229,110,128, 36,127,229,242,233,239,100, 128, 36,147,242,239,237,225,110,128, 33,123,238,244,121, 3,196, 69,196, 78,196, 89,227,233,242,227,236,101,128, 36,115,232,225, 238,231,250,232,239,117,128, 83, 68,112, 2,196, 95,196,102,225, 242,229,110,128, 36,135,229,242,233,239,100,128, 36,155,111,142, 0, 50,196,142,196,151,196,161,196,191,196,243,197, 12,197, 39, 197, 73,197, 85,197,104,197,115,197,148,197,156,197,180,225,242, 225,226,233, 99,128, 6, 98,226,229,238,231,225,236,105,128, 9, 232,227,233,242,227,236,101,129, 36, 97,196,172,233,238,246,229, 242,243,229,243,225,238,243,243,229,242,233,102,128, 39,139,100, 2,196,197,196,203,229,246, 97,128, 9,104,239,116, 2,196,210, 196,221,229,238,236,229,225,228,229,114,128, 32, 37,236,229,225, 228,229,114,129, 32, 37,196,232,246,229,242,244,233,227,225,108, 128,254, 48,231,117, 2,196,250,197, 3,234,225,242,225,244,105, 128, 10,232,242,237,245,235,232,105,128, 10,104,232, 97, 2,197, 19,197, 30,227,235,225,242,225,226,233, 99,128, 6, 98,238,231, 250,232,239,117,128, 48, 34,105, 2,197, 45,197, 63,228,229,239, 231,242,225,240,232,233,227,240,225,242,229,110,128, 50, 33,238, 230,229,242,233,239,114,128, 32,130,237,239,238,239,243,240,225, 227,101,128,255, 18,238,245,237,229,242,225,244,239,242,226,229, 238,231,225,236,105,128, 9,245,239,236,228,243,244,249,236,101, 128,247, 50,112, 2,197,121,197,128,225,242,229,110,128, 36,117, 229,114, 2,197,135,197,141,233,239,100,128, 36,137,243,233,225, 110,128, 6,242,242,239,237,225,110,128, 33,113,115, 2,197,162, 197,170,244,242,239,235,101,128, 1,187,245,240,229,242,233,239, 114,128, 0,178,244,104, 2,197,187,197,192,225,105,128, 14, 82, 233,242,228,115,128, 33, 84,117,145, 0,117,197,237,197,245,198, 30,198, 87,198,225,199, 6,199,129,199,145,199,196,200, 10,200, 91,200,100,200,219,200,243,201, 95,201,123,201,237,225,227,245, 244,101,128, 0,250, 98, 4,197,255,198, 4,198, 13,198, 23,225, 114,128, 2,137,229,238,231,225,236,105,128, 9,137,239,240,239, 237,239,230,111,128, 49, 40,242,229,246,101,128, 1,109, 99, 3, 198, 38,198, 45,198, 77,225,242,239,110,128, 1,212,233,242, 99, 2,198, 53,198, 58,236,101,128, 36,228,245,237,230,236,229,120, 129, 0,251,198, 69,226,229,236,239,119,128, 30,119,249,242,233, 236,236,233, 99,128, 4, 67,100, 5,198, 99,198,110,198,133,198, 139,198,215,225,244,244,225,228,229,246, 97,128, 9, 81,226,108, 2,198,117,198,125,225,227,245,244,101,128, 1,113,231,242,225, 246,101,128, 2, 21,229,246, 97,128, 9, 9,233,229,242,229,243, 233,115,133, 0,252,198,159,198,167,198,175,198,198,198,206,225, 227,245,244,101,128, 1,216,226,229,236,239,119,128, 30,115, 99, 2,198,181,198,188,225,242,239,110,128, 1,218,249,242,233,236, 236,233, 99,128, 4,241,231,242,225,246,101,128, 1,220,237,225, 227,242,239,110,128, 1,214,239,244,226,229,236,239,119,128, 30, 229,103, 2,198,231,198,238,242,225,246,101,128, 0,249,117, 2, 198,244,198,253,234,225,242,225,244,105,128, 10,137,242,237,245, 235,232,105,128, 10, 9,104, 3,199, 14,199, 24,199,102,233,242, 225,231,225,238, 97,128, 48, 70,111, 2,199, 30,199, 40,239,235, 225,226,239,246,101,128, 30,231,242,110,133, 1,176,199, 55,199, 63,199, 74,199, 82,199, 94,225,227,245,244,101,128, 30,233,228, 239,244,226,229,236,239,119,128, 30,241,231,242,225,246,101,128, 30,235,232,239,239,235,225,226,239,246,101,128, 30,237,244,233, 236,228,101,128, 30,239,245,238,231,225,242,245,237,236,225,245, 116,129, 1,113,199,118,227,249,242,233,236,236,233, 99,128, 4, 243,233,238,246,229,242,244,229,228,226,242,229,246,101,128, 2, 23,107, 3,199,153,199,177,199,188,225,244,225,235,225,238, 97, 129, 48,166,199,165,232,225,236,230,247,233,228,244,104,128,255, 115,227,249,242,233,236,236,233, 99,128, 4,121,239,242,229,225, 110,128, 49, 92,109, 2,199,202,199,255, 97, 2,199,208,199,241, 227,242,239,110,130, 1,107,199,219,199,230,227,249,242,233,236, 236,233, 99,128, 4,239,228,233,229,242,229,243,233,115,128, 30, 123,244,242,225,231,245,242,237,245,235,232,105,128, 10, 65,239, 238,239,243,240,225,227,101,128,255, 85,110, 2,200, 16,200, 71, 228,229,242,243,227,239,242,101,132, 0, 95,200, 35,200, 41,200, 53,200, 64,228,226,108,128, 32, 23,237,239,238,239,243,240,225, 227,101,128,255, 63,246,229,242,244,233,227,225,108,128,254, 51, 247,225,246,121,128,254, 79,105, 2,200, 77,200, 82,239,110,128, 34, 42,246,229,242,243,225,108,128, 34, 0,239,231,239,238,229, 107,128, 1,115,112, 5,200,112,200,119,200,127,200,142,200,193, 225,242,229,110,128, 36,176,226,236,239,227,107,128, 37,128,240, 229,242,228,239,244,232,229,226,242,229,119,128, 5,196,243,233, 236,239,110,131, 3,197,200,156,200,177,200,185,228,233,229,242, 229,243,233,115,129, 3,203,200,169,244,239,238,239,115,128, 3, 176,236,225,244,233,110,128, 2,138,244,239,238,239,115,128, 3, 205,244,225,227,107, 2,200,202,200,213,226,229,236,239,247,227, 237, 98,128, 3, 29,237,239,100,128, 2,212,114, 2,200,225,200, 237,225,231,245,242,237,245,235,232,105,128, 10,115,233,238,103, 128, 1,111,115, 3,200,251,201, 10,201, 55,232,239,242,244,227, 249,242,233,236,236,233, 99,128, 4, 94,237,225,236,108, 2,201, 19,201, 30,232,233,242,225,231,225,238, 97,128, 48, 69,235,225, 244,225,235,225,238, 97,129, 48,165,201, 43,232,225,236,230,247, 233,228,244,104,128,255,105,244,242,225,233,231,232,116, 2,201, 67,201, 78,227,249,242,233,236,236,233, 99,128, 4,175,243,244, 242,239,235,229,227,249,242,233,236,236,233, 99,128, 4,177,244, 233,236,228,101,130, 1,105,201,107,201,115,225,227,245,244,101, 128, 30,121,226,229,236,239,119,128, 30,117,117, 5,201,135,201, 145,201,152,201,177,201,193,226,229,238,231,225,236,105,128, 9, 138,228,229,246, 97,128, 9, 10,231,117, 2,201,159,201,168,234, 225,242,225,244,105,128, 10,138,242,237,245,235,232,105,128, 10, 10,237,225,244,242,225,231,245,242,237,245,235,232,105,128, 10, 66,246,239,247,229,236,243,233,231,110, 3,201,209,201,219,201, 226,226,229,238,231,225,236,105,128, 9,194,228,229,246, 97,128, 9, 66,231,245,234,225,242,225,244,105,128, 10,194,246,239,247, 229,236,243,233,231,110, 3,201,253,202, 7,202, 14,226,229,238, 231,225,236,105,128, 9,193,228,229,246, 97,128, 9, 65,231,245, 234,225,242,225,244,105,128, 10,193,118,139, 0,118,202, 51,202, 199,202,208,202,219,203,148,203,155,203,253,204, 9,204,109,204, 117,204,138, 97, 4,202, 61,202, 68,202, 93,202,104,228,229,246, 97,128, 9, 53,231,117, 2,202, 75,202, 84,234,225,242,225,244, 105,128, 10,181,242,237,245,235,232,105,128, 10, 53,235,225,244, 225,235,225,238, 97,128, 48,247,118,132, 5,213,202,116,202,143, 202,175,202,187,228,225,231,229,243,104,130,251, 53,202,129,202, 134,182, 53,128,251, 53,232,229,226,242,229,119,128,251, 53,104, 2,202,149,202,157,229,226,242,229,119,128, 5,213,239,236,225, 109,129,251, 75,202,166,232,229,226,242,229,119,128,251, 75,246, 225,246,232,229,226,242,229,119,128, 5,240,249,239,228,232,229, 226,242,229,119,128, 5,241,227,233,242,227,236,101,128, 36,229, 228,239,244,226,229,236,239,119,128, 30,127,101, 6,202,233,202, 244,203, 52,203, 63,203, 69,203,136,227,249,242,233,236,236,233, 99,128, 4, 50,104, 4,202,254,203, 7,203, 21,203, 37,225,242, 225,226,233, 99,128, 6,164,230,233,238,225,236,225,242,225,226, 233, 99,128,251,107,233,238,233,244,233,225,236,225,242,225,226, 233, 99,128,251,108,237,229,228,233,225,236,225,242,225,226,233, 99,128,251,109,235,225,244,225,235,225,238, 97,128, 48,249,238, 245,115,128, 38, 64,242,244,233,227,225,108, 2,203, 80,203, 86, 226,225,114,128, 0,124,236,233,238,101, 4,203, 99,203,110,203, 121,203,130,225,226,239,246,229,227,237, 98,128, 3, 13,226,229, 236,239,247,227,237, 98,128, 3, 41,236,239,247,237,239,100,128, 2,204,237,239,100,128, 2,200,247,225,242,237,229,238,233,225, 110,128, 5,126,232,239,239,107,128, 2,139,105, 3,203,163,203, 174,203,213,235,225,244,225,235,225,238, 97,128, 48,248,242,225, 237, 97, 3,203,185,203,195,203,202,226,229,238,231,225,236,105, 128, 9,205,228,229,246, 97,128, 9, 77,231,245,234,225,242,225, 244,105,128, 10,205,243,225,242,231, 97, 3,203,225,203,235,203, 242,226,229,238,231,225,236,105,128, 9,131,228,229,246, 97,128, 9, 3,231,245,234,225,242,225,244,105,128, 10,131,237,239,238, 239,243,240,225,227,101,128,255, 86,111, 3,204, 17,204, 28,204, 98,225,242,237,229,238,233,225,110,128, 5,120,233,227,229,100, 2,204, 37,204, 73,233,244,229,242,225,244,233,239,110, 2,204, 51,204, 62,232,233,242,225,231,225,238, 97,128, 48,158,235,225, 244,225,235,225,238, 97,128, 48,254,237,225,242,235,235,225,238, 97,129, 48,155,204, 86,232,225,236,230,247,233,228,244,104,128, 255,158,235,225,244,225,235,225,238, 97,128, 48,250,240,225,242, 229,110,128, 36,177,116, 2,204,123,204,130,233,236,228,101,128, 30,125,245,242,238,229,100,128, 2,140,117, 2,204,144,204,155, 232,233,242,225,231,225,238, 97,128, 48,148,235,225,244,225,235, 225,238, 97,128, 48,244,119,143, 0,119,204,200,205,177,205,187, 205,210,205,250,206, 61,206, 69,208, 40,208, 81,208, 93,208,168, 208,176,208,183,208,194,208,203, 97, 8,204,218,204,225,204,235, 204,246,205, 28,205, 60,205, 72,205,108,227,245,244,101,128, 30, 131,229,235,239,242,229,225,110,128, 49, 89,232,233,242,225,231, 225,238, 97,128, 48,143,107, 2,204,252,205, 20,225,244,225,235, 225,238, 97,129, 48,239,205, 8,232,225,236,230,247,233,228,244, 104,128,255,156,239,242,229,225,110,128, 49, 88,243,237,225,236, 108, 2,205, 38,205, 49,232,233,242,225,231,225,238, 97,128, 48, 142,235,225,244,225,235,225,238, 97,128, 48,238,244,244,239,243, 241,245,225,242,101,128, 51, 87,118, 2,205, 78,205, 86,229,228, 225,243,104,128, 48, 28,249,245,238,228,229,242,243,227,239,242, 229,246,229,242,244,233,227,225,108,128,254, 52,119, 3,205,116, 205,125,205,139,225,242,225,226,233, 99,128, 6, 72,230,233,238, 225,236,225,242,225,226,233, 99,128,254,238,232,225,237,250,225, 225,226,239,246,101, 2,205,154,205,163,225,242,225,226,233, 99, 128, 6, 36,230,233,238,225,236,225,242,225,226,233, 99,128,254, 134,226,243,241,245,225,242,101,128, 51,221,227,233,242, 99, 2, 205,196,205,201,236,101,128, 36,230,245,237,230,236,229,120,128, 1,117,100, 2,205,216,205,226,233,229,242,229,243,233,115,128, 30,133,239,116, 2,205,233,205,242,225,227,227,229,238,116,128, 30,135,226,229,236,239,119,128, 30,137,101, 4,206, 4,206, 15, 206, 27,206, 51,232,233,242,225,231,225,238, 97,128, 48,145,233, 229,242,243,244,242,225,243,115,128, 33, 24,107, 2,206, 33,206, 43,225,244,225,235,225,238, 97,128, 48,241,239,242,229,225,110, 128, 49, 94,239,235,239,242,229,225,110,128, 49, 93,231,242,225, 246,101,128, 30,129,232,233,244,101, 8,206, 90,206, 99,206,183, 207, 17,207,101,207,146,207,198,207,254,226,245,236,236,229,116, 128, 37,230, 99, 2,206,105,206,125,233,242,227,236,101,129, 37, 203,206,115,233,238,246,229,242,243,101,128, 37,217,239,242,238, 229,242,226,242,225,227,235,229,116, 2,206,142,206,162,236,229, 230,116,129, 48, 14,206,151,246,229,242,244,233,227,225,108,128, 254, 67,242,233,231,232,116,129, 48, 15,206,172,246,229,242,244, 233,227,225,108,128,254, 68,100, 2,206,189,206,230,233,225,237, 239,238,100,129, 37,199,206,200,227,239,238,244,225,233,238,233, 238,231,226,236,225,227,235,243,237,225,236,236,228,233,225,237, 239,238,100,128, 37,200,239,247,238,240,239,233,238,244,233,238, 103, 2,206,246,207, 6,243,237,225,236,236,244,242,233,225,238, 231,236,101,128, 37,191,244,242,233,225,238,231,236,101,128, 37, 189,236,101, 2,207, 24,207, 66,230,244,240,239,233,238,244,233, 238,103, 2,207, 39,207, 55,243,237,225,236,236,244,242,233,225, 238,231,236,101,128, 37,195,244,242,233,225,238,231,236,101,128, 37,193,238,244,233,227,245,236,225,242,226,242,225,227,235,229, 116, 2,207, 86,207, 93,236,229,230,116,128, 48, 22,242,233,231, 232,116,128, 48, 23,242,233,231,232,244,240,239,233,238,244,233, 238,103, 2,207,119,207,135,243,237,225,236,236,244,242,233,225, 238,231,236,101,128, 37,185,244,242,233,225,238,231,236,101,128, 37,183,115, 3,207,154,207,184,207,192,109, 2,207,160,207,172, 225,236,236,243,241,245,225,242,101,128, 37,171,233,236,233,238, 231,230,225,227,101,128, 38, 58,241,245,225,242,101,128, 37,161, 244,225,114,128, 38, 6,116, 2,207,204,207,215,229,236,229,240, 232,239,238,101,128, 38, 15,239,242,244,239,233,243,229,243,232, 229,236,236,226,242,225,227,235,229,116, 2,207,239,207,246,236, 229,230,116,128, 48, 24,242,233,231,232,116,128, 48, 25,245,240, 240,239,233,238,244,233,238,103, 2,208, 13,208, 29,243,237,225, 236,236,244,242,233,225,238,231,236,101,128, 37,181,244,242,233, 225,238,231,236,101,128, 37,179,105, 2,208, 46,208, 57,232,233, 242,225,231,225,238, 97,128, 48,144,107, 2,208, 63,208, 73,225, 244,225,235,225,238, 97,128, 48,240,239,242,229,225,110,128, 49, 95,237,239,238,239,243,240,225,227,101,128,255, 87,111, 4,208, 103,208,114,208,139,208,157,232,233,242,225,231,225,238, 97,128, 48,146,235,225,244,225,235,225,238, 97,129, 48,242,208,127,232, 225,236,230,247,233,228,244,104,128,255,102,110,129, 32,169,208, 145,237,239,238,239,243,240,225,227,101,128,255,230,247,225,229, 238,244,232,225,105,128, 14, 39,240,225,242,229,110,128, 36,178, 242,233,238,103,128, 30,152,243,245,240,229,242,233,239,114,128, 2,183,244,245,242,238,229,100,128, 2,141,249,238,110,128, 1, 191,120,137, 0,120,208,231,208,242,208,253,209, 6,209, 33,209, 46,209, 50,209, 62,209, 70,225,226,239,246,229,227,237, 98,128, 3, 61,226,239,240,239,237,239,230,111,128, 49, 18,227,233,242, 227,236,101,128, 36,231,100, 2,209, 12,209, 22,233,229,242,229, 243,233,115,128, 30,141,239,244,225,227,227,229,238,116,128, 30, 139,229,232,225,242,237,229,238,233,225,110,128, 5,109,105,128, 3,190,237,239,238,239,243,240,225,227,101,128,255, 88,240,225, 242,229,110,128, 36,179,243,245,240,229,242,233,239,114,128, 2, 227,121,143, 0,121,209,115,210, 74,210, 97,210,137,212,103,212, 111,212,128,212,192,212,204,213,201,213,241,213,253,214, 8,214, 29,215, 2, 97, 11,209,139,209,151,209,161,209,168,209,175,209, 185,209,210,209,221,210, 3,210, 16,210, 62,225,228,239,243,241, 245,225,242,101,128, 51, 78,226,229,238,231,225,236,105,128, 9, 175,227,245,244,101,128, 0,253,228,229,246, 97,128, 9, 47,229, 235,239,242,229,225,110,128, 49, 82,231,117, 2,209,192,209,201, 234,225,242,225,244,105,128, 10,175,242,237,245,235,232,105,128, 10, 47,232,233,242,225,231,225,238, 97,128, 48,132,107, 2,209, 227,209,251,225,244,225,235,225,238, 97,129, 48,228,209,239,232, 225,236,230,247,233,228,244,104,128,255,148,239,242,229,225,110, 128, 49, 81,237,225,235,235,225,238,244,232,225,105,128, 14, 78, 243,237,225,236,108, 2,210, 26,210, 37,232,233,242,225,231,225, 238, 97,128, 48,131,235,225,244,225,235,225,238, 97,129, 48,227, 210, 50,232,225,236,230,247,233,228,244,104,128,255,108,244,227, 249,242,233,236,236,233, 99,128, 4, 99,227,233,242, 99, 2,210, 83,210, 88,236,101,128, 36,232,245,237,230,236,229,120,128, 1, 119,100, 2,210,103,210,113,233,229,242,229,243,233,115,128, 0, 255,239,116, 2,210,120,210,129,225,227,227,229,238,116,128, 30, 143,226,229,236,239,119,128, 30,245,101, 7,210,153,211,161,211, 170,211,188,211,220,212, 40,212, 91,104, 8,210,171,210,180,210, 214,210,228,211, 45,211, 61,211,120,211,138,225,242,225,226,233, 99,128, 6, 74,226,225,242,242,229,101, 2,210,191,210,200,225, 242,225,226,233, 99,128, 6,210,230,233,238,225,236,225,242,225, 226,233, 99,128,251,175,230,233,238,225,236,225,242,225,226,233, 99,128,254,242,232,225,237,250,225,225,226,239,246,101, 4,210, 247,211, 0,211, 14,211, 30,225,242,225,226,233, 99,128, 6, 38, 230,233,238,225,236,225,242,225,226,233, 99,128,254,138,233,238, 233,244,233,225,236,225,242,225,226,233, 99,128,254,139,237,229, 228,233,225,236,225,242,225,226,233, 99,128,254,140,233,238,233, 244,233,225,236,225,242,225,226,233, 99,128,254,243,237,101, 2, 211, 68,211, 81,228,233,225,236,225,242,225,226,233, 99,128,254, 244,229,237,105, 2,211, 89,211,104,238,233,244,233,225,236,225, 242,225,226,233, 99,128,252,221,243,239,236,225,244,229,228,225, 242,225,226,233, 99,128,252, 88,238,239,239,238,230,233,238,225, 236,225,242,225,226,233, 99,128,252,148,244,232,242,229,229,228, 239,244,243,226,229,236,239,247,225,242,225,226,233, 99,128, 6, 209,235,239,242,229,225,110,128, 49, 86,110,129, 0,165,211,176, 237,239,238,239,243,240,225,227,101,128,255,229,111, 2,211,194, 211,203,235,239,242,229,225,110,128, 49, 85,242,233,238,232,233, 229,245,232,235,239,242,229,225,110,128, 49,134,114, 3,211,228, 212, 8,212, 20,225,232,226,229,238,249,239,237,111, 2,211,242, 211,251,232,229,226,242,229,119,128, 5,170,236,229,230,244,232, 229,226,242,229,119,128, 5,170,233,227,249,242,233,236,236,233, 99,128, 4, 75,245,228,233,229,242,229,243,233,243,227,249,242, 233,236,236,233, 99,128, 4,249,243,233,229,245,238,103, 3,212, 53,212, 62,212, 78,235,239,242,229,225,110,128, 49,129,240,225, 238,243,233,239,243,235,239,242,229,225,110,128, 49,131,243,233, 239,243,235,239,242,229,225,110,128, 49,130,244,233,246,232,229, 226,242,229,119,128, 5,154,231,242,225,246,101,128, 30,243,232, 239,239,107,129, 1,180,212,120,225,226,239,246,101,128, 30,247, 105, 5,212,140,212,151,212,162,212,171,212,179,225,242,237,229, 238,233,225,110,128, 5,117,227,249,242,233,236,236,233, 99,128, 4, 87,235,239,242,229,225,110,128, 49, 98,238,249,225,238,103, 128, 38, 47,247,238,225,242,237,229,238,233,225,110,128, 5,130, 237,239,238,239,243,240,225,227,101,128,255, 89,111, 7,212,220, 213, 34,213, 45,213, 55,213, 93,213,139,213,148,100,131, 5,217, 212,230,212,250,213, 3,228,225,231,229,243,104,129,251, 57,212, 241,232,229,226,242,229,119,128,251, 57,232,229,226,242,229,119, 128, 5,217,249,239,100, 2,213, 11,213, 20,232,229,226,242,229, 119,128, 5,242,240,225,244,225,232,232,229,226,242,229,119,128, 251, 31,232,233,242,225,231,225,238, 97,128, 48,136,233,235,239, 242,229,225,110,128, 49,137,107, 2,213, 61,213, 85,225,244,225, 235,225,238, 97,129, 48,232,213, 73,232,225,236,230,247,233,228, 244,104,128,255,150,239,242,229,225,110,128, 49, 91,243,237,225, 236,108, 2,213,103,213,114,232,233,242,225,231,225,238, 97,128, 48,135,235,225,244,225,235,225,238, 97,129, 48,231,213,127,232, 225,236,230,247,233,228,244,104,128,255,110,244,231,242,229,229, 107,128, 3,243,121, 2,213,154,213,191, 97, 2,213,160,213,170, 229,235,239,242,229,225,110,128, 49,136,107, 2,213,176,213,184, 239,242,229,225,110,128, 49,135,244,232,225,105,128, 14, 34,233, 238,231,244,232,225,105,128, 14, 13,112, 2,213,207,213,214,225, 242,229,110,128, 36,180,239,231,229,231,242,225,237,237,229,238, 105,129, 3,122,213,230,231,242,229,229,235,227,237, 98,128, 3, 69,114,129, 1,166,213,247,233,238,103,128, 30,153,243,245,240, 229,242,233,239,114,128, 2,184,116, 2,214, 14,214, 21,233,236, 228,101,128, 30,249,245,242,238,229,100,128, 2,142,117, 5,214, 41,214, 52,214, 62,214,100,214,232,232,233,242,225,231,225,238, 97,128, 48,134,233,235,239,242,229,225,110,128, 49,140,107, 2, 214, 68,214, 92,225,244,225,235,225,238, 97,129, 48,230,214, 80, 232,225,236,230,247,233,228,244,104,128,255,149,239,242,229,225, 110,128, 49, 96,115, 3,214,108,214,146,214,187,226,233,103, 2, 214,116,214,127,227,249,242,233,236,236,233, 99,128, 4,107,233, 239,244,233,230,233,229,228,227,249,242,233,236,236,233, 99,128, 4,109,236,233,244,244,236,101, 2,214,157,214,168,227,249,242, 233,236,236,233, 99,128, 4,103,233,239,244,233,230,233,229,228, 227,249,242,233,236,236,233, 99,128, 4,105,237,225,236,108, 2, 214,196,214,207,232,233,242,225,231,225,238, 97,128, 48,133,235, 225,244,225,235,225,238, 97,129, 48,229,214,220,232,225,236,230, 247,233,228,244,104,128,255,109,249,101, 2,214,239,214,248,235, 239,242,229,225,110,128, 49,139,239,235,239,242,229,225,110,128, 49,138,249, 97, 2,215, 9,215, 19,226,229,238,231,225,236,105, 128, 9,223,228,229,246, 97,128, 9, 95,122,142, 0,122,215, 58, 216, 66,216, 77,216,120,216,147,217,182,218, 34,218, 76,218, 88, 218,100,218,128,218,136,218,152,218,161, 97, 10,215, 80,215, 91, 215, 98,215,105,215,116,215,194,215,224,215,235,216, 15,216, 27, 225,242,237,229,238,233,225,110,128, 5,102,227,245,244,101,128, 1,122,228,229,246, 97,128, 9, 91,231,245,242,237,245,235,232, 105,128, 10, 91,104, 4,215,126,215,135,215,149,215,179,225,242, 225,226,233, 99,128, 6, 56,230,233,238,225,236,225,242,225,226, 233, 99,128,254,198,105, 2,215,155,215,170,238,233,244,233,225, 236,225,242,225,226,233, 99,128,254,199,242,225,231,225,238, 97, 128, 48, 86,237,229,228,233,225,236,225,242,225,226,233, 99,128, 254,200,233,110, 2,215,201,215,210,225,242,225,226,233, 99,128, 6, 50,230,233,238,225,236,225,242,225,226,233, 99,128,254,176, 235,225,244,225,235,225,238, 97,128, 48,182,241,229,102, 2,215, 243,216, 1,231,225,228,239,236,232,229,226,242,229,119,128, 5, 149,241,225,244,225,238,232,229,226,242,229,119,128, 5,148,242, 241,225,232,229,226,242,229,119,128, 5,152,249,233,110,130, 5, 214,216, 37,216, 57,228,225,231,229,243,104,129,251, 54,216, 48, 232,229,226,242,229,119,128,251, 54,232,229,226,242,229,119,128, 5,214,226,239,240,239,237,239,230,111,128, 49, 23, 99, 3,216, 85,216, 92,216,114,225,242,239,110,128, 1,126,233,242, 99, 2, 216,100,216,105,236,101,128, 36,233,245,237,230,236,229,120,128, 30,145,245,242,108,128, 2,145,228,239,116,130, 1,124,216,130, 216,139,225,227,227,229,238,116,128, 1,124,226,229,236,239,119, 128, 30,147,101, 6,216,161,216,172,216,215,216,226,216,237,217, 177,227,249,242,233,236,236,233, 99,128, 4, 55,100, 2,216,178, 216,197,229,243,227,229,238,228,229,242,227,249,242,233,236,236, 233, 99,128, 4,153,233,229,242,229,243,233,243,227,249,242,233, 236,236,233, 99,128, 4,223,232,233,242,225,231,225,238, 97,128, 48, 92,235,225,244,225,235,225,238, 97,128, 48,188,242,111,140, 0, 48,217, 10,217, 19,217, 29,217, 36,217, 61,217, 74,217, 85, 217, 97,217,108,217,118,217,129,217,136,225,242,225,226,233, 99, 128, 6, 96,226,229,238,231,225,236,105,128, 9,230,228,229,246, 97,128, 9,102,231,117, 2,217, 43,217, 52,234,225,242,225,244, 105,128, 10,230,242,237,245,235,232,105,128, 10,102,232,225,227, 235,225,242,225,226,233, 99,128, 6, 96,233,238,230,229,242,233, 239,114,128, 32,128,237,239,238,239,243,240,225,227,101,128,255, 16,239,236,228,243,244,249,236,101,128,247, 48,240,229,242,243, 233,225,110,128, 6,240,243,245,240,229,242,233,239,114,128, 32, 112,244,232,225,105,128, 14, 80,247,233,228,244,104, 3,217,148, 217,157,217,169,234,239,233,238,229,114,128,254,255,238,239,238, 234,239,233,238,229,114,128, 32, 12,243,240,225,227,101,128, 32, 11,244, 97,128, 3,182,104, 2,217,188,217,199,226,239,240,239, 237,239,230,111,128, 49, 19,101, 4,217,209,217,220,217,236,217, 247,225,242,237,229,238,233,225,110,128, 5,106,226,242,229,246, 229,227,249,242,233,236,236,233, 99,128, 4,194,227,249,242,233, 236,236,233, 99,128, 4, 54,100, 2,217,253,218, 16,229,243,227, 229,238,228,229,242,227,249,242,233,236,236,233, 99,128, 4,151, 233,229,242,229,243,233,243,227,249,242,233,236,236,233, 99,128, 4,221,105, 3,218, 42,218, 53,218, 64,232,233,242,225,231,225, 238, 97,128, 48, 88,235,225,244,225,235,225,238, 97,128, 48,184, 238,239,242,232,229,226,242,229,119,128, 5,174,236,233,238,229, 226,229,236,239,119,128, 30,149,237,239,238,239,243,240,225,227, 101,128,255, 90,111, 2,218,106,218,117,232,233,242,225,231,225, 238, 97,128, 48, 94,235,225,244,225,235,225,238, 97,128, 48,190, 240,225,242,229,110,128, 36,181,242,229,244,242,239,230,236,229, 248,232,239,239,107,128, 2,144,243,244,242,239,235,101,128, 1, 182,117, 2,218,167,218,178,232,233,242,225,231,225,238, 97,128, 48, 90,235,225,244,225,235,225,238, 97,128, 48,186 } #endif /* DEFINE_PS_TABLES_DATA */ ; #ifdef DEFINE_PS_TABLES /* * This function searches the compressed table efficiently. */ static unsigned long ft_get_adobe_glyph_index( const char* name, const char* limit ) { int c = 0; int count, min, max; const unsigned char* p = ft_adobe_glyph_list; if ( name == 0 || name >= limit ) goto NotFound; c = *name++; count = p[1]; p += 2; min = 0; max = count; while ( min < max ) { int mid = ( min + max ) >> 1; const unsigned char* q = p + mid * 2; int c2; q = ft_adobe_glyph_list + ( ( (int)q[0] << 8 ) | q[1] ); c2 = q[0] & 127; if ( c2 == c ) { p = q; goto Found; } if ( c2 < c ) min = mid + 1; else max = mid; } goto NotFound; Found: for (;;) { /* assert (*p & 127) == c */ if ( name >= limit ) { if ( (p[0] & 128) == 0 && (p[1] & 128) != 0 ) return (unsigned long)( ( (int)p[2] << 8 ) | p[3] ); goto NotFound; } c = *name++; if ( p[0] & 128 ) { p++; if ( c != (p[0] & 127) ) goto NotFound; continue; } p++; count = p[0] & 127; if ( p[0] & 128 ) p += 2; p++; for ( ; count > 0; count--, p += 2 ) { int offset = ( (int)p[0] << 8 ) | p[1]; const unsigned char* q = ft_adobe_glyph_list + offset; if ( c == ( q[0] & 127 ) ) { p = q; goto NextIter; } } goto NotFound; NextIter: ; } NotFound: return 0; } #endif /* DEFINE_PS_TABLES */ #endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/pstables.h
C++
gpl-3.0
268,144
# # FreeType 2 psnames driver configuration rules # # Copyright (C) 1996-2022 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. # psnames driver directory # PSNAMES_DIR := $(SRC_DIR)/psnames # compilation flags for the driver # PSNAMES_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(PSNAMES_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # psnames driver sources (i.e., C files) # PSNAMES_DRV_SRC := $(PSNAMES_DIR)/psmodule.c # psnames driver headers # PSNAMES_DRV_H := $(PSNAMES_DRV_SRC:%.c=%.h) \ $(PSNAMES_DIR)/psnamerr.h \ $(PSNAMES_DIR)/pstables.h # psnames driver object(s) # # PSNAMES_DRV_OBJ_M is used during `multi' builds # PSNAMES_DRV_OBJ_S is used during `single' builds # PSNAMES_DRV_OBJ_M := $(PSNAMES_DRV_SRC:$(PSNAMES_DIR)/%.c=$(OBJ_DIR)/%.$O) PSNAMES_DRV_OBJ_S := $(OBJ_DIR)/psnames.$O # psnames driver source file for single build # PSNAMES_DRV_SRC_S := $(PSNAMES_DIR)/psnames.c # psnames driver - single object # $(PSNAMES_DRV_OBJ_S): $(PSNAMES_DRV_SRC_S) $(PSNAMES_DRV_SRC) \ $(FREETYPE_H) $(PSNAMES_DRV_H) $(PSNAMES_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(PSNAMES_DRV_SRC_S)) # psnames driver - multiple objects # $(OBJ_DIR)/%.$O: $(PSNAMES_DIR)/%.c $(FREETYPE_H) $(PSNAMES_DRV_H) $(PSNAMES_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(PSNAMES_DRV_OBJ_S) DRV_OBJS_M += $(PSNAMES_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/psnames/rules.mk
mk
gpl-3.0
1,900
/**************************************************************************** * * ftmisc.h * * Miscellaneous macros for stand-alone rasterizer (specification * only). * * Copyright (C) 2005-2022 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. * */ /**************************************************** * * This file is *not* portable! You have to adapt * its definitions to your platform. * */ #ifndef FTMISC_H_ #define FTMISC_H_ /* memset */ #include FT_CONFIG_STANDARD_LIBRARY_H #define FT_BEGIN_HEADER #define FT_END_HEADER #define FT_LOCAL_DEF( x ) static x /* from include/freetype/fttypes.h */ typedef unsigned char FT_Byte; typedef signed int FT_Int; typedef unsigned int FT_UInt; typedef signed long FT_Long; typedef unsigned long FT_ULong; typedef signed long FT_F26Dot6; typedef int FT_Error; #define FT_STATIC_BYTE_CAST( type, var ) (type)(FT_Byte)(var) /* from include/freetype/ftsystem.h */ typedef struct FT_MemoryRec_* FT_Memory; typedef void* (*FT_Alloc_Func)( FT_Memory memory, long size ); typedef void (*FT_Free_Func)( FT_Memory memory, void* block ); typedef void* (*FT_Realloc_Func)( FT_Memory memory, long cur_size, long new_size, void* block ); typedef struct FT_MemoryRec_ { void* user; FT_Alloc_Func alloc; FT_Free_Func free; FT_Realloc_Func realloc; } FT_MemoryRec; /* from src/ftcalc.c */ #if ( defined _WIN32 || defined _WIN64 ) typedef __int64 FT_Int64; #else #include "inttypes.h" typedef int64_t FT_Int64; #endif static FT_Long FT_MulDiv( FT_Long a, FT_Long b, FT_Long c ) { FT_Int s; FT_Long d; s = 1; if ( a < 0 ) { a = -a; s = -1; } if ( b < 0 ) { b = -b; s = -s; } if ( c < 0 ) { c = -c; s = -s; } d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c : 0x7FFFFFFFL ); return ( s > 0 ) ? d : -d; } static FT_Long FT_MulDiv_No_Round( FT_Long a, FT_Long b, FT_Long c ) { FT_Int s; FT_Long d; s = 1; if ( a < 0 ) { a = -a; s = -1; } if ( b < 0 ) { b = -b; s = -s; } if ( c < 0 ) { c = -c; s = -s; } d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c : 0x7FFFFFFFL ); return ( s > 0 ) ? d : -d; } #endif /* FTMISC_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/ftmisc.h
C++
gpl-3.0
2,969
/**************************************************************************** * * ftraster.c * * The FreeType glyph rasterizer (body). * * Copyright (C) 1996-2022 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. * */ /************************************************************************** * * This file can be compiled without the rest of the FreeType engine, by * defining the STANDALONE_ macro when compiling it. You also need to * put the files `ftimage.h' and `ftmisc.h' into the $(incdir) * directory. Typically, you should do something like * * - copy `src/raster/ftraster.c' (this file) to your current directory * * - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h' to your * current directory * * - compile `ftraster' with the STANDALONE_ macro defined, as in * * cc -c -DSTANDALONE_ ftraster.c * * The renderer can be initialized with a call to * `ft_standard_raster.raster_new'; a bitmap can be generated * with a call to `ft_standard_raster.raster_render'. * * See the comments and documentation in the file `ftimage.h' for more * details on how the raster works. * */ /************************************************************************** * * This is a rewrite of the FreeType 1.x scan-line converter * */ #ifdef STANDALONE_ /* The size in bytes of the render pool used by the scan-line converter */ /* to do all of its work. */ #define FT_RENDER_POOL_SIZE 16384L #define FT_CONFIG_STANDARD_LIBRARY_H <stdlib.h> #include <string.h> /* for memset */ #include "ftmisc.h" #include "ftimage.h" #else /* !STANDALONE_ */ #include "ftraster.h" #include <freetype/internal/ftcalc.h> /* for FT_MulDiv and FT_MulDiv_No_Round */ #include <freetype/ftoutln.h> /* for FT_Outline_Get_CBox */ #endif /* !STANDALONE_ */ /************************************************************************** * * A simple technical note on how the raster works * ----------------------------------------------- * * Converting an outline into a bitmap is achieved in several steps: * * 1 - Decomposing the outline into successive `profiles'. Each * profile is simply an array of scanline intersections on a given * dimension. A profile's main attributes are * * o its scanline position boundaries, i.e. `Ymin' and `Ymax' * * o an array of intersection coordinates for each scanline * between `Ymin' and `Ymax' * * o a direction, indicating whether it was built going `up' or * `down', as this is very important for filling rules * * o its drop-out mode * * 2 - Sweeping the target map's scanlines in order to compute segment * `spans' which are then filled. Additionally, this pass * performs drop-out control. * * The outline data is parsed during step 1 only. The profiles are * built from the bottom of the render pool, used as a stack. The * following graphics shows the profile list under construction: * * __________________________________________________________ _ _ * | | | | | * | profile | coordinates for | profile | coordinates for |--> * | 1 | profile 1 | 2 | profile 2 |--> * |_________|_________________|_________|_________________|__ _ _ * * ^ ^ * | | * start of render pool top * * The top of the profile stack is kept in the `top' variable. * * As you can see, a profile record is pushed on top of the render * pool, which is then followed by its coordinates/intersections. If * a change of direction is detected in the outline, a new profile is * generated until the end of the outline. * * Note that when all profiles have been generated, the function * Finalize_Profile_Table() is used to record, for each profile, its * bottom-most scanline as well as the scanline above its upmost * boundary. These positions are called `y-turns' because they (sort * of) correspond to local extrema. They are stored in a sorted list * built from the top of the render pool as a downwards stack: * * _ _ _______________________________________ * | | * <--| sorted list of | * <--| extrema scanlines | * _ _ __________________|____________________| * * ^ ^ * | | * maxBuff sizeBuff = end of pool * * This list is later used during the sweep phase in order to * optimize performance (see technical note on the sweep below). * * Of course, the raster detects whether the two stacks collide and * handles the situation properly. * */ /*************************************************************************/ /*************************************************************************/ /** **/ /** CONFIGURATION MACROS **/ /** **/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /** **/ /** OTHER MACROS (do not change) **/ /** **/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT raster #ifdef STANDALONE_ /* Auxiliary macros for token concatenation. */ #define FT_ERR_XCAT( x, y ) x ## y #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) /* This macro is used to indicate that a function parameter is unused. */ /* Its purpose is simply to reduce compiler warnings. Note also that */ /* simply defining it as `(void)x' doesn't avoid warnings with certain */ /* ANSI compilers (e.g. LCC). */ #define FT_UNUSED( x ) (x) = (x) /* Disable the tracing mechanism for simplicity -- developers can */ /* activate it easily by redefining these macros. */ #ifndef FT_ERROR #define FT_ERROR( x ) do { } while ( 0 ) /* nothing */ #endif #ifndef FT_TRACE #define FT_TRACE( x ) do { } while ( 0 ) /* nothing */ #define FT_TRACE1( x ) do { } while ( 0 ) /* nothing */ #define FT_TRACE6( x ) do { } while ( 0 ) /* nothing */ #define FT_TRACE7( x ) do { } while ( 0 ) /* nothing */ #endif #ifndef FT_THROW #define FT_THROW( e ) FT_ERR_CAT( Raster_Err_, e ) #endif #define Raster_Err_Ok 0 #define Raster_Err_Invalid_Outline -1 #define Raster_Err_Cannot_Render_Glyph -2 #define Raster_Err_Invalid_Argument -3 #define Raster_Err_Raster_Overflow -4 #define Raster_Err_Raster_Uninitialized -5 #define Raster_Err_Raster_Negative_Height -6 #define ft_memset memset #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, raster_new_, \ raster_reset_, raster_set_mode_, \ raster_render_, raster_done_ ) \ const FT_Raster_Funcs class_ = \ { \ glyph_format_, \ raster_new_, \ raster_reset_, \ raster_set_mode_, \ raster_render_, \ raster_done_ \ }; #else /* !STANDALONE_ */ #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> /* for FT_TRACE, FT_ERROR, and FT_THROW */ #include "rasterrs.h" #endif /* !STANDALONE_ */ #ifndef FT_MEM_SET #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c ) #endif #ifndef FT_MEM_ZERO #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count ) #endif #ifndef FT_ZERO #define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) ) #endif /* FMulDiv means `Fast MulDiv'; it is used in case where `b' is */ /* typically a small value and the result of a*b is known to fit into */ /* 32 bits. */ #define FMulDiv( a, b, c ) ( (a) * (b) / (c) ) /* On the other hand, SMulDiv means `Slow MulDiv', and is used typically */ /* for clipping computations. It simply uses the FT_MulDiv() function */ /* defined in `ftcalc.h'. */ #define SMulDiv FT_MulDiv #define SMulDiv_No_Round FT_MulDiv_No_Round /* The rasterizer is a very general purpose component; please leave */ /* the following redefinitions there (you never know your target */ /* environment). */ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef NULL #define NULL (void*)0 #endif #ifndef SUCCESS #define SUCCESS 0 #endif #ifndef FAILURE #define FAILURE 1 #endif #define MaxBezier 32 /* The maximum number of stacked Bezier curves. */ /* Setting this constant to more than 32 is a */ /* pure waste of space. */ #define Pixel_Bits 6 /* fractional bits of *input* coordinates */ /*************************************************************************/ /*************************************************************************/ /** **/ /** SIMPLE TYPE DECLARATIONS **/ /** **/ /*************************************************************************/ /*************************************************************************/ typedef int Int; typedef unsigned int UInt; typedef short Short; typedef unsigned short UShort, *PUShort; typedef long Long, *PLong; typedef unsigned long ULong; typedef unsigned char Byte, *PByte; typedef char Bool; typedef union Alignment_ { Long l; void* p; void (*f)(void); } Alignment, *PAlignment; typedef struct TPoint_ { Long x; Long y; } TPoint; /* values for the `flags' bit field */ #define Flow_Up 0x08U #define Overshoot_Top 0x10U #define Overshoot_Bottom 0x20U /* States of each line, arc, and profile */ typedef enum TStates_ { Unknown_State, Ascending_State, Descending_State, Flat_State } TStates; typedef struct TProfile_ TProfile; typedef TProfile* PProfile; struct TProfile_ { FT_F26Dot6 X; /* current coordinate during sweep */ PProfile link; /* link to next profile (various purposes) */ PLong offset; /* start of profile's data in render pool */ UShort flags; /* Bit 0-2: drop-out mode */ /* Bit 3: profile orientation (up/down) */ /* Bit 4: is top profile? */ /* Bit 5: is bottom profile? */ Long height; /* profile's height in scanlines */ Long start; /* profile's starting scanline */ Int countL; /* number of lines to step before this */ /* profile becomes drawable */ PProfile next; /* next profile in same contour, used */ /* during drop-out control */ }; typedef PProfile TProfileList; typedef PProfile* PProfileList; #define AlignProfileSize \ ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( Long ) ) #undef RAS_ARG #undef RAS_ARGS #undef RAS_VAR #undef RAS_VARS #ifdef FT_STATIC_RASTER #define RAS_ARGS /* void */ #define RAS_ARG void #define RAS_VARS /* void */ #define RAS_VAR /* void */ #define FT_UNUSED_RASTER do { } while ( 0 ) #else /* !FT_STATIC_RASTER */ #define RAS_ARGS black_PWorker worker, #define RAS_ARG black_PWorker worker #define RAS_VARS worker, #define RAS_VAR worker #define FT_UNUSED_RASTER FT_UNUSED( worker ) #endif /* !FT_STATIC_RASTER */ typedef struct black_TWorker_ black_TWorker, *black_PWorker; /* prototypes used for sweep function dispatch */ typedef void Function_Sweep_Init( RAS_ARGS Short min, Short max ); typedef void Function_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ); typedef void Function_Sweep_Step( RAS_ARG ); /* NOTE: These operations are only valid on 2's complement processors */ #undef FLOOR #undef CEILING #undef TRUNC #undef SCALED #define FLOOR( x ) ( (x) & -ras.precision ) #define CEILING( x ) ( ( (x) + ras.precision - 1 ) & -ras.precision ) #define TRUNC( x ) ( (Long)(x) >> ras.precision_bits ) #define FRAC( x ) ( (x) & ( ras.precision - 1 ) ) /* scale and shift grid to pixel centers */ #define SCALED( x ) ( (x) * ras.precision_scale - ras.precision_half ) #define IS_BOTTOM_OVERSHOOT( x ) \ (Bool)( CEILING( x ) - x >= ras.precision_half ) #define IS_TOP_OVERSHOOT( x ) \ (Bool)( x - FLOOR( x ) >= ras.precision_half ) /* Smart dropout rounding to find which pixel is closer to span ends. */ /* To mimick Windows, symmetric cases break down indepenently of the */ /* precision. */ #define SMART( p, q ) FLOOR( ( (p) + (q) + ras.precision * 63 / 64 ) >> 1 ) #if FT_RENDER_POOL_SIZE > 2048 #define FT_MAX_BLACK_POOL ( FT_RENDER_POOL_SIZE / sizeof ( Long ) ) #else #define FT_MAX_BLACK_POOL ( 2048 / sizeof ( Long ) ) #endif /* The most used variables are positioned at the top of the structure. */ /* Thus, their offset can be coded with less opcodes, resulting in a */ /* smaller executable. */ struct black_TWorker_ { Int precision_bits; /* precision related variables */ Int precision; Int precision_half; Int precision_scale; Int precision_step; Int precision_jitter; PLong buff; /* The profiles buffer */ PLong sizeBuff; /* Render pool size */ PLong maxBuff; /* Profiles buffer size */ PLong top; /* Current cursor in buffer */ FT_Error error; Int numTurns; /* number of Y-turns in outline */ Byte dropOutControl; /* current drop_out control method */ UShort bWidth; /* target bitmap width */ PByte bOrigin; /* target bitmap bottom-left origin */ PByte bLine; /* target bitmap current line */ Long lastX, lastY; Long minY, maxY; UShort num_Profs; /* current number of profiles */ Bool fresh; /* signals a fresh new profile which */ /* `start' field must be completed */ Bool joint; /* signals that the last arc ended */ /* exactly on a scanline. Allows */ /* removal of doublets */ PProfile cProfile; /* current profile */ PProfile fProfile; /* head of linked list of profiles */ PProfile gProfile; /* contour's first profile in case */ /* of impact */ TStates state; /* rendering state */ FT_Bitmap target; /* description of target bit/pixmap */ FT_Outline outline; /* dispatch variables */ Function_Sweep_Init* Proc_Sweep_Init; Function_Sweep_Span* Proc_Sweep_Span; Function_Sweep_Span* Proc_Sweep_Drop; Function_Sweep_Step* Proc_Sweep_Step; }; typedef struct black_TRaster_ { void* memory; } black_TRaster, *black_PRaster; #ifdef FT_STATIC_RASTER static black_TWorker ras; #else /* !FT_STATIC_RASTER */ #define ras (*worker) #endif /* !FT_STATIC_RASTER */ /*************************************************************************/ /*************************************************************************/ /** **/ /** PROFILES COMPUTATION **/ /** **/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * @Function: * Set_High_Precision * * @Description: * Set precision variables according to param flag. * * @Input: * High :: * Set to True for high precision (typically for ppem < 24), * false otherwise. */ static void Set_High_Precision( RAS_ARGS Int High ) { /* * `precision_step' is used in `Bezier_Up' to decide when to split a * given y-monotonous Bezier arc that crosses a scanline before * approximating it as a straight segment. The default value of 32 (for * low accuracy) corresponds to * * 32 / 64 == 0.5 pixels, * * while for the high accuracy case we have * * 256 / (1 << 12) = 0.0625 pixels. * * `precision_jitter' is an epsilon threshold used in * `Vertical_Sweep_Span' to deal with small imperfections in the Bezier * decomposition (after all, we are working with approximations only); * it avoids switching on additional pixels which would cause artifacts * otherwise. * * The value of `precision_jitter' has been determined heuristically. * */ if ( High ) { ras.precision_bits = 12; ras.precision_step = 256; ras.precision_jitter = 30; } else { ras.precision_bits = 6; ras.precision_step = 32; ras.precision_jitter = 2; } FT_TRACE6(( "Set_High_Precision(%s)\n", High ? "true" : "false" )); ras.precision = 1 << ras.precision_bits; ras.precision_half = ras.precision >> 1; ras.precision_scale = ras.precision >> Pixel_Bits; } /************************************************************************** * * @Function: * New_Profile * * @Description: * Create a new profile in the render pool. * * @Input: * aState :: * The state/orientation of the new profile. * * overshoot :: * Whether the profile's unrounded start position * differs by at least a half pixel. * * @Return: * SUCCESS on success. FAILURE in case of overflow or of incoherent * profile. */ static Bool New_Profile( RAS_ARGS TStates aState, Bool overshoot ) { if ( !ras.fProfile ) { ras.cProfile = (PProfile)ras.top; ras.fProfile = ras.cProfile; ras.top += AlignProfileSize; } if ( ras.top >= ras.maxBuff ) { ras.error = FT_THROW( Raster_Overflow ); return FAILURE; } ras.cProfile->start = 0; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; ras.cProfile->link = (PProfile)0; ras.cProfile->next = (PProfile)0; ras.cProfile->flags = ras.dropOutControl; switch ( aState ) { case Ascending_State: ras.cProfile->flags |= Flow_Up; if ( overshoot ) ras.cProfile->flags |= Overshoot_Bottom; FT_TRACE6(( " new ascending profile = %p\n", (void *)ras.cProfile )); break; case Descending_State: if ( overshoot ) ras.cProfile->flags |= Overshoot_Top; FT_TRACE6(( " new descending profile = %p\n", (void *)ras.cProfile )); break; default: FT_ERROR(( "New_Profile: invalid profile direction\n" )); ras.error = FT_THROW( Invalid_Outline ); return FAILURE; } if ( !ras.gProfile ) ras.gProfile = ras.cProfile; ras.state = aState; ras.fresh = TRUE; ras.joint = FALSE; return SUCCESS; } /************************************************************************** * * @Function: * End_Profile * * @Description: * Finalize the current profile. * * @Input: * overshoot :: * Whether the profile's unrounded end position differs * by at least a half pixel. * * @Return: * SUCCESS on success. FAILURE in case of overflow or incoherency. */ static Bool End_Profile( RAS_ARGS Bool overshoot ) { Long h; h = (Long)( ras.top - ras.cProfile->offset ); if ( h < 0 ) { FT_ERROR(( "End_Profile: negative height encountered\n" )); ras.error = FT_THROW( Raster_Negative_Height ); return FAILURE; } if ( h > 0 ) { PProfile oldProfile; FT_TRACE6(( " ending profile %p, start = %ld, height = %ld\n", (void *)ras.cProfile, ras.cProfile->start, h )); ras.cProfile->height = h; if ( overshoot ) { if ( ras.cProfile->flags & Flow_Up ) ras.cProfile->flags |= Overshoot_Top; else ras.cProfile->flags |= Overshoot_Bottom; } oldProfile = ras.cProfile; ras.cProfile = (PProfile)ras.top; ras.top += AlignProfileSize; ras.cProfile->height = 0; ras.cProfile->offset = ras.top; oldProfile->next = ras.cProfile; ras.num_Profs++; } if ( ras.top >= ras.maxBuff ) { FT_TRACE1(( "overflow in End_Profile\n" )); ras.error = FT_THROW( Raster_Overflow ); return FAILURE; } ras.joint = FALSE; return SUCCESS; } /************************************************************************** * * @Function: * Insert_Y_Turn * * @Description: * Insert a salient into the sorted list placed on top of the render * pool. * * @Input: * New y scanline position. * * @Return: * SUCCESS on success. FAILURE in case of overflow. */ static Bool Insert_Y_Turn( RAS_ARGS Int y ) { PLong y_turns; Int n; n = ras.numTurns - 1; y_turns = ras.sizeBuff - ras.numTurns; /* look for first y value that is <= */ while ( n >= 0 && y < y_turns[n] ) n--; /* if it is <, simply insert it, ignore if == */ if ( n >= 0 && y > y_turns[n] ) do { Int y2 = (Int)y_turns[n]; y_turns[n] = y; y = y2; } while ( --n >= 0 ); if ( n < 0 ) { ras.maxBuff--; if ( ras.maxBuff <= ras.top ) { ras.error = FT_THROW( Raster_Overflow ); return FAILURE; } ras.numTurns++; ras.sizeBuff[-ras.numTurns] = y; } return SUCCESS; } /************************************************************************** * * @Function: * Finalize_Profile_Table * * @Description: * Adjust all links in the profiles list. * * @Return: * SUCCESS on success. FAILURE in case of overflow. */ static Bool Finalize_Profile_Table( RAS_ARG ) { UShort n; PProfile p; n = ras.num_Profs; p = ras.fProfile; if ( n > 1 && p ) { do { Int bottom, top; if ( n > 1 ) p->link = (PProfile)( p->offset + p->height ); else p->link = NULL; if ( p->flags & Flow_Up ) { bottom = (Int)p->start; top = (Int)( p->start + p->height - 1 ); } else { bottom = (Int)( p->start - p->height + 1 ); top = (Int)p->start; p->start = bottom; p->offset += p->height - 1; } if ( Insert_Y_Turn( RAS_VARS bottom ) || Insert_Y_Turn( RAS_VARS top + 1 ) ) return FAILURE; p = p->link; } while ( --n ); } else ras.fProfile = NULL; return SUCCESS; } /************************************************************************** * * @Function: * Split_Conic * * @Description: * Subdivide one conic Bezier into two joint sub-arcs in the Bezier * stack. * * @Input: * None (subdivided Bezier is taken from the top of the stack). * * @Note: * This routine is the `beef' of this component. It is _the_ inner * loop that should be optimized to hell to get the best performance. */ static void Split_Conic( TPoint* base ) { Long a, b; base[4].x = base[2].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; base[3].x = b >> 1; base[2].x = ( a + b ) >> 2; base[1].x = a >> 1; base[4].y = base[2].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; base[3].y = b >> 1; base[2].y = ( a + b ) >> 2; base[1].y = a >> 1; /* hand optimized. gcc doesn't seem to be too good at common */ /* expression substitution and instruction scheduling ;-) */ } /************************************************************************** * * @Function: * Split_Cubic * * @Description: * Subdivide a third-order Bezier arc into two joint sub-arcs in the * Bezier stack. * * @Note: * This routine is the `beef' of the component. It is one of _the_ * inner loops that should be optimized like hell to get the best * performance. */ static void Split_Cubic( TPoint* base ) { Long a, b, c; base[6].x = base[3].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; c = base[2].x + base[3].x; base[5].x = c >> 1; c += b; base[4].x = c >> 2; base[1].x = a >> 1; a += b; base[2].x = a >> 2; base[3].x = ( a + c ) >> 3; base[6].y = base[3].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; c = base[2].y + base[3].y; base[5].y = c >> 1; c += b; base[4].y = c >> 2; base[1].y = a >> 1; a += b; base[2].y = a >> 2; base[3].y = ( a + c ) >> 3; } /************************************************************************** * * @Function: * Line_Up * * @Description: * Compute the x-coordinates of an ascending line segment and store * them in the render pool. * * @Input: * x1 :: * The x-coordinate of the segment's start point. * * y1 :: * The y-coordinate of the segment's start point. * * x2 :: * The x-coordinate of the segment's end point. * * y2 :: * The y-coordinate of the segment's end point. * * miny :: * A lower vertical clipping bound value. * * maxy :: * An upper vertical clipping bound value. * * @Return: * SUCCESS on success, FAILURE on render pool overflow. */ static Bool Line_Up( RAS_ARGS Long x1, Long y1, Long x2, Long y2, Long miny, Long maxy ) { Long Dx, Dy; Int e1, e2, f1, f2, size; /* XXX: is `Short' sufficient? */ Long Ix, Rx, Ax; PLong top; Dx = x2 - x1; Dy = y2 - y1; if ( Dy <= 0 || y2 < miny || y1 > maxy ) return SUCCESS; if ( y1 < miny ) { /* Take care: miny-y1 can be a very large value; we use */ /* a slow MulDiv function to avoid clipping bugs */ x1 += SMulDiv( Dx, miny - y1, Dy ); e1 = (Int)TRUNC( miny ); f1 = 0; } else { e1 = (Int)TRUNC( y1 ); f1 = (Int)FRAC( y1 ); } if ( y2 > maxy ) { /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */ e2 = (Int)TRUNC( maxy ); f2 = 0; } else { e2 = (Int)TRUNC( y2 ); f2 = (Int)FRAC( y2 ); } if ( f1 > 0 ) { if ( e1 == e2 ) return SUCCESS; else { x1 += SMulDiv( Dx, ras.precision - f1, Dy ); e1 += 1; } } else if ( ras.joint ) { ras.top--; ras.joint = FALSE; } ras.joint = (char)( f2 == 0 ); if ( ras.fresh ) { ras.cProfile->start = e1; ras.fresh = FALSE; } size = e2 - e1 + 1; if ( ras.top + size >= ras.maxBuff ) { ras.error = FT_THROW( Raster_Overflow ); return FAILURE; } if ( Dx > 0 ) { Ix = SMulDiv_No_Round( ras.precision, Dx, Dy ); Rx = ( ras.precision * Dx ) % Dy; Dx = 1; } else { Ix = -SMulDiv_No_Round( ras.precision, -Dx, Dy ); Rx = ( ras.precision * -Dx ) % Dy; Dx = -1; } Ax = -Dy; top = ras.top; while ( size > 0 ) { *top++ = x1; x1 += Ix; Ax += Rx; if ( Ax >= 0 ) { Ax -= Dy; x1 += Dx; } size--; } ras.top = top; return SUCCESS; } /************************************************************************** * * @Function: * Line_Down * * @Description: * Compute the x-coordinates of an descending line segment and store * them in the render pool. * * @Input: * x1 :: * The x-coordinate of the segment's start point. * * y1 :: * The y-coordinate of the segment's start point. * * x2 :: * The x-coordinate of the segment's end point. * * y2 :: * The y-coordinate of the segment's end point. * * miny :: * A lower vertical clipping bound value. * * maxy :: * An upper vertical clipping bound value. * * @Return: * SUCCESS on success, FAILURE on render pool overflow. */ static Bool Line_Down( RAS_ARGS Long x1, Long y1, Long x2, Long y2, Long miny, Long maxy ) { Bool result, fresh; fresh = ras.fresh; result = Line_Up( RAS_VARS x1, -y1, x2, -y2, -maxy, -miny ); if ( fresh && !ras.fresh ) ras.cProfile->start = -ras.cProfile->start; return result; } /* A function type describing the functions used to split Bezier arcs */ typedef void (*TSplitter)( TPoint* base ); /************************************************************************** * * @Function: * Bezier_Up * * @Description: * Compute the x-coordinates of an ascending Bezier arc and store * them in the render pool. * * @Input: * degree :: * The degree of the Bezier arc (either 2 or 3). * * splitter :: * The function to split Bezier arcs. * * miny :: * A lower vertical clipping bound value. * * maxy :: * An upper vertical clipping bound value. * * @Return: * SUCCESS on success, FAILURE on render pool overflow. */ static Bool Bezier_Up( RAS_ARGS Int degree, TPoint* arc, TSplitter splitter, Long miny, Long maxy ) { Long y1, y2, e, e2, e0; Short f1; TPoint* start_arc; PLong top; y1 = arc[degree].y; y2 = arc[0].y; top = ras.top; if ( y2 < miny || y1 > maxy ) goto Fin; e2 = FLOOR( y2 ); if ( e2 > maxy ) e2 = maxy; e0 = miny; if ( y1 < miny ) e = miny; else { e = CEILING( y1 ); f1 = (Short)( FRAC( y1 ) ); e0 = e; if ( f1 == 0 ) { if ( ras.joint ) { top--; ras.joint = FALSE; } *top++ = arc[degree].x; e += ras.precision; } } if ( ras.fresh ) { ras.cProfile->start = TRUNC( e0 ); ras.fresh = FALSE; } if ( e2 < e ) goto Fin; if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.maxBuff ) { ras.top = top; ras.error = FT_THROW( Raster_Overflow ); return FAILURE; } start_arc = arc; do { ras.joint = FALSE; y2 = arc[0].y; if ( y2 > e ) { y1 = arc[degree].y; if ( y2 - y1 >= ras.precision_step ) { splitter( arc ); arc += degree; } else { *top++ = arc[degree].x + FMulDiv( arc[0].x - arc[degree].x, e - y1, y2 - y1 ); arc -= degree; e += ras.precision; } } else { if ( y2 == e ) { ras.joint = TRUE; *top++ = arc[0].x; e += ras.precision; } arc -= degree; } } while ( arc >= start_arc && e <= e2 ); Fin: ras.top = top; return SUCCESS; } /************************************************************************** * * @Function: * Bezier_Down * * @Description: * Compute the x-coordinates of an descending Bezier arc and store * them in the render pool. * * @Input: * degree :: * The degree of the Bezier arc (either 2 or 3). * * splitter :: * The function to split Bezier arcs. * * miny :: * A lower vertical clipping bound value. * * maxy :: * An upper vertical clipping bound value. * * @Return: * SUCCESS on success, FAILURE on render pool overflow. */ static Bool Bezier_Down( RAS_ARGS Int degree, TPoint* arc, TSplitter splitter, Long miny, Long maxy ) { Bool result, fresh; arc[0].y = -arc[0].y; arc[1].y = -arc[1].y; arc[2].y = -arc[2].y; if ( degree > 2 ) arc[3].y = -arc[3].y; fresh = ras.fresh; result = Bezier_Up( RAS_VARS degree, arc, splitter, -maxy, -miny ); if ( fresh && !ras.fresh ) ras.cProfile->start = -ras.cProfile->start; arc[0].y = -arc[0].y; return result; } /************************************************************************** * * @Function: * Line_To * * @Description: * Inject a new line segment and adjust the Profiles list. * * @Input: * x :: * The x-coordinate of the segment's end point (its start point * is stored in `lastX'). * * y :: * The y-coordinate of the segment's end point (its start point * is stored in `lastY'). * * @Return: * SUCCESS on success, FAILURE on render pool overflow or incorrect * profile. */ static Bool Line_To( RAS_ARGS Long x, Long y ) { /* First, detect a change of direction */ switch ( ras.state ) { case Unknown_State: if ( y > ras.lastY ) { if ( New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } else { if ( y < ras.lastY ) if ( New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Ascending_State: if ( y < ras.lastY ) { if ( End_Profile( RAS_VARS IS_TOP_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Descending_State, IS_TOP_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; case Descending_State: if ( y > ras.lastY ) { if ( End_Profile( RAS_VARS IS_BOTTOM_OVERSHOOT( ras.lastY ) ) || New_Profile( RAS_VARS Ascending_State, IS_BOTTOM_OVERSHOOT( ras.lastY ) ) ) return FAILURE; } break; default: ; } /* Then compute the lines */ switch ( ras.state ) { case Ascending_State: if ( Line_Up( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; case Descending_State: if ( Line_Down( RAS_VARS ras.lastX, ras.lastY, x, y, ras.minY, ras.maxY ) ) return FAILURE; break; default: ; } ras.lastX = x; ras.lastY = y; return SUCCESS; } /************************************************************************** * * @Function: * Conic_To * * @Description: * Inject a new conic arc and adjust the profile list. * * @Input: * cx :: * The x-coordinate of the arc's new control point. * * cy :: * The y-coordinate of the arc's new control point. * * x :: * The x-coordinate of the arc's end point (its start point is * stored in `lastX'). * * y :: * The y-coordinate of the arc's end point (its start point is * stored in `lastY'). * * @Return: * SUCCESS on success, FAILURE on render pool overflow or incorrect * profile. */ static Bool Conic_To( RAS_ARGS Long cx, Long cy, Long x, Long y ) { Long y1, y2, y3, x3, ymin, ymax; TStates state_bez; TPoint arcs[2 * MaxBezier + 1]; /* The Bezier stack */ TPoint* arc; /* current Bezier arc pointer */ arc = arcs; arc[2].x = ras.lastX; arc[2].y = ras.lastY; arc[1].x = cx; arc[1].y = cy; arc[0].x = x; arc[0].y = y; do { y1 = arc[2].y; y2 = arc[1].y; y3 = arc[0].y; x3 = arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y3 ) { ymin = y1; ymax = y3; } else { ymin = y3; ymax = y1; } if ( y2 < ymin || y2 > ymax ) { /* this arc has no given direction, split it! */ Split_Conic( arc ); arc += 2; } else if ( y1 == y3 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ arc -= 2; } else { /* the arc is y-monotonous, either ascending or descending */ /* detect a change of direction */ state_bez = y1 < y3 ? Ascending_State : Descending_State; if ( ras.state != state_bez ) { Bool o = ( state_bez == Ascending_State ) ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; /* create a new profile */ if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* now call the appropriate routine */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 2, arc, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 2, arc, Split_Conic, ras.minY, ras.maxY ) ) goto Fail; arc -= 2; } } while ( arc >= arcs ); ras.lastX = x3; ras.lastY = y3; return SUCCESS; Fail: return FAILURE; } /************************************************************************** * * @Function: * Cubic_To * * @Description: * Inject a new cubic arc and adjust the profile list. * * @Input: * cx1 :: * The x-coordinate of the arc's first new control point. * * cy1 :: * The y-coordinate of the arc's first new control point. * * cx2 :: * The x-coordinate of the arc's second new control point. * * cy2 :: * The y-coordinate of the arc's second new control point. * * x :: * The x-coordinate of the arc's end point (its start point is * stored in `lastX'). * * y :: * The y-coordinate of the arc's end point (its start point is * stored in `lastY'). * * @Return: * SUCCESS on success, FAILURE on render pool overflow or incorrect * profile. */ static Bool Cubic_To( RAS_ARGS Long cx1, Long cy1, Long cx2, Long cy2, Long x, Long y ) { Long y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2; TStates state_bez; TPoint arcs[3 * MaxBezier + 1]; /* The Bezier stack */ TPoint* arc; /* current Bezier arc pointer */ arc = arcs; arc[3].x = ras.lastX; arc[3].y = ras.lastY; arc[2].x = cx1; arc[2].y = cy1; arc[1].x = cx2; arc[1].y = cy2; arc[0].x = x; arc[0].y = y; do { y1 = arc[3].y; y2 = arc[2].y; y3 = arc[1].y; y4 = arc[0].y; x4 = arc[0].x; /* first, categorize the Bezier arc */ if ( y1 <= y4 ) { ymin1 = y1; ymax1 = y4; } else { ymin1 = y4; ymax1 = y1; } if ( y2 <= y3 ) { ymin2 = y2; ymax2 = y3; } else { ymin2 = y3; ymax2 = y2; } if ( ymin2 < ymin1 || ymax2 > ymax1 ) { /* this arc has no given direction, split it! */ Split_Cubic( arc ); arc += 3; } else if ( y1 == y4 ) { /* this arc is flat, ignore it and pop it from the Bezier stack */ arc -= 3; } else { state_bez = ( y1 <= y4 ) ? Ascending_State : Descending_State; /* detect a change of direction */ if ( ras.state != state_bez ) { Bool o = ( state_bez == Ascending_State ) ? IS_BOTTOM_OVERSHOOT( y1 ) : IS_TOP_OVERSHOOT( y1 ); /* finalize current profile if any */ if ( ras.state != Unknown_State && End_Profile( RAS_VARS o ) ) goto Fail; if ( New_Profile( RAS_VARS state_bez, o ) ) goto Fail; } /* compute intersections */ if ( state_bez == Ascending_State ) { if ( Bezier_Up( RAS_VARS 3, arc, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; } else if ( Bezier_Down( RAS_VARS 3, arc, Split_Cubic, ras.minY, ras.maxY ) ) goto Fail; arc -= 3; } } while ( arc >= arcs ); ras.lastX = x4; ras.lastY = y4; return SUCCESS; Fail: return FAILURE; } #undef SWAP_ #define SWAP_( x, y ) do \ { \ Long swap = x; \ \ \ x = y; \ y = swap; \ } while ( 0 ) /************************************************************************** * * @Function: * Decompose_Curve * * @Description: * Scan the outline arrays in order to emit individual segments and * Beziers by calling Line_To() and Bezier_To(). It handles all * weird cases, like when the first point is off the curve, or when * there are simply no `on' points in the contour! * * @Input: * first :: * The index of the first point in the contour. * * last :: * The index of the last point in the contour. * * flipped :: * If set, flip the direction of the curve. * * @Return: * SUCCESS on success, FAILURE on error. */ static Bool Decompose_Curve( RAS_ARGS UShort first, UShort last, Int flipped ) { FT_Vector v_last; FT_Vector v_control; FT_Vector v_start; FT_Vector* points; FT_Vector* point; FT_Vector* limit; char* tags; UInt tag; /* current point's state */ points = ras.outline.points; limit = points + last; v_start.x = SCALED( points[first].x ); v_start.y = SCALED( points[first].y ); v_last.x = SCALED( points[last].x ); v_last.y = SCALED( points[last].y ); if ( flipped ) { SWAP_( v_start.x, v_start.y ); SWAP_( v_last.x, v_last.y ); } v_control = v_start; point = points + first; tags = ras.outline.tags + first; /* set scan mode if necessary */ if ( tags[0] & FT_CURVE_TAG_HAS_SCANMODE ) ras.dropOutControl = (Byte)tags[0] >> 5; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ if ( tag == FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; /* check first point to determine origin */ if ( tag == FT_CURVE_TAG_CONIC ) { /* first point is conic control. Yes, this happens. */ if ( FT_CURVE_TAG( ras.outline.tags[last] ) == FT_CURVE_TAG_ON ) { /* start at last point if it is on the curve */ v_start = v_last; limit--; } else { /* if both first and last points are conic, */ /* start at their middle and record its position */ /* for closure */ v_start.x = ( v_start.x + v_last.x ) / 2; v_start.y = ( v_start.y + v_last.y ) / 2; /* v_last = v_start; */ } point--; tags--; } ras.lastX = v_start.x; ras.lastY = v_start.y; while ( point < limit ) { point++; tags++; tag = FT_CURVE_TAG( tags[0] ); switch ( tag ) { case FT_CURVE_TAG_ON: /* emit a single line_to */ { Long x, y; x = SCALED( point->x ); y = SCALED( point->y ); if ( flipped ) SWAP_( x, y ); if ( Line_To( RAS_VARS x, y ) ) goto Fail; continue; } case FT_CURVE_TAG_CONIC: /* consume conic arcs */ v_control.x = SCALED( point[0].x ); v_control.y = SCALED( point[0].y ); if ( flipped ) SWAP_( v_control.x, v_control.y ); Do_Conic: if ( point < limit ) { FT_Vector v_middle; Long x, y; point++; tags++; tag = FT_CURVE_TAG( tags[0] ); x = SCALED( point[0].x ); y = SCALED( point[0].y ); if ( flipped ) SWAP_( x, y ); if ( tag == FT_CURVE_TAG_ON ) { if ( Conic_To( RAS_VARS v_control.x, v_control.y, x, y ) ) goto Fail; continue; } if ( tag != FT_CURVE_TAG_CONIC ) goto Invalid_Outline; v_middle.x = ( v_control.x + x ) / 2; v_middle.y = ( v_control.y + y ) / 2; if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_middle.x, v_middle.y ) ) goto Fail; v_control.x = x; v_control.y = y; goto Do_Conic; } if ( Conic_To( RAS_VARS v_control.x, v_control.y, v_start.x, v_start.y ) ) goto Fail; goto Close; default: /* FT_CURVE_TAG_CUBIC */ { Long x1, y1, x2, y2, x3, y3; if ( point + 1 > limit || FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; point += 2; tags += 2; x1 = SCALED( point[-2].x ); y1 = SCALED( point[-2].y ); x2 = SCALED( point[-1].x ); y2 = SCALED( point[-1].y ); if ( flipped ) { SWAP_( x1, y1 ); SWAP_( x2, y2 ); } if ( point <= limit ) { x3 = SCALED( point[0].x ); y3 = SCALED( point[0].y ); if ( flipped ) SWAP_( x3, y3 ); if ( Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ) ) goto Fail; continue; } if ( Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ) ) goto Fail; goto Close; } } } /* close the contour with a line segment */ if ( Line_To( RAS_VARS v_start.x, v_start.y ) ) goto Fail; Close: return SUCCESS; Invalid_Outline: ras.error = FT_THROW( Invalid_Outline ); Fail: return FAILURE; } /************************************************************************** * * @Function: * Convert_Glyph * * @Description: * Convert a glyph into a series of segments and arcs and make a * profiles list with them. * * @Input: * flipped :: * If set, flip the direction of curve. * * @Return: * SUCCESS on success, FAILURE if any error was encountered during * rendering. */ static Bool Convert_Glyph( RAS_ARGS Int flipped ) { Int i; UInt start; ras.fProfile = NULL; ras.joint = FALSE; ras.fresh = FALSE; ras.maxBuff = ras.sizeBuff - AlignProfileSize; ras.numTurns = 0; ras.cProfile = (PProfile)ras.top; ras.cProfile->offset = ras.top; ras.num_Profs = 0; start = 0; for ( i = 0; i < ras.outline.n_contours; i++ ) { PProfile lastProfile; Bool o; ras.state = Unknown_State; ras.gProfile = NULL; if ( Decompose_Curve( RAS_VARS (UShort)start, (UShort)ras.outline.contours[i], flipped ) ) return FAILURE; start = (UShort)ras.outline.contours[i] + 1; /* we must now check whether the extreme arcs join or not */ if ( FRAC( ras.lastY ) == 0 && ras.lastY >= ras.minY && ras.lastY <= ras.maxY ) if ( ras.gProfile && ( ras.gProfile->flags & Flow_Up ) == ( ras.cProfile->flags & Flow_Up ) ) ras.top--; /* Note that ras.gProfile can be nil if the contour was too small */ /* to be drawn. */ lastProfile = ras.cProfile; if ( ras.top != ras.cProfile->offset && ( ras.cProfile->flags & Flow_Up ) ) o = IS_TOP_OVERSHOOT( ras.lastY ); else o = IS_BOTTOM_OVERSHOOT( ras.lastY ); if ( End_Profile( RAS_VARS o ) ) return FAILURE; /* close the `next profile in contour' linked list */ if ( ras.gProfile ) lastProfile->next = ras.gProfile; } if ( Finalize_Profile_Table( RAS_VAR ) ) return FAILURE; return (Bool)( ras.top < ras.maxBuff ? SUCCESS : FAILURE ); } /*************************************************************************/ /*************************************************************************/ /** **/ /** SCAN-LINE SWEEPS AND DRAWING **/ /** **/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * Init_Linked * * Initializes an empty linked list. */ static void Init_Linked( TProfileList* l ) { *l = NULL; } /************************************************************************** * * InsNew * * Inserts a new profile in a linked list. */ static void InsNew( PProfileList list, PProfile profile ) { PProfile *old, current; Long x; old = list; current = *old; x = profile->X; while ( current ) { if ( x < current->X ) break; old = &current->link; current = *old; } profile->link = current; *old = profile; } /************************************************************************** * * DelOld * * Removes an old profile from a linked list. */ static void DelOld( PProfileList list, const PProfile profile ) { PProfile *old, current; old = list; current = *old; while ( current ) { if ( current == profile ) { *old = current->link; return; } old = &current->link; current = *old; } /* we should never get there, unless the profile was not part of */ /* the list. */ } /************************************************************************** * * Sort * * Sorts a trace list. In 95%, the list is already sorted. We need * an algorithm which is fast in this case. Bubble sort is enough * and simple. */ static void Sort( PProfileList list ) { PProfile *old, current, next; /* First, set the new X coordinate of each profile */ current = *list; while ( current ) { current->X = *current->offset; current->offset += ( current->flags & Flow_Up ) ? 1 : -1; current->height--; current = current->link; } /* Then sort them */ old = list; current = *old; if ( !current ) return; next = current->link; while ( next ) { if ( current->X <= next->X ) { old = &current->link; current = *old; if ( !current ) return; } else { *old = next; current->link = next->link; next->link = current; old = list; current = *old; } next = current->link; } } /************************************************************************** * * Vertical Sweep Procedure Set * * These four routines are used during the vertical black/white sweep * phase by the generic Draw_Sweep() function. * */ static void Vertical_Sweep_Init( RAS_ARGS Short min, Short max ) { FT_UNUSED( max ); ras.bLine = ras.bOrigin - min * ras.target.pitch; } static void Vertical_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2; Int dropOutControl = left->flags & 7; FT_UNUSED( y ); FT_UNUSED( left ); FT_UNUSED( right ); /* in high-precision mode, we need 12 digits after the comma to */ /* represent multiples of 1/(1<<12) = 1/4096 */ FT_TRACE7(( " y=%d x=[% .12f;% .12f]", y, x1 / (double)ras.precision, x2 / (double)ras.precision )); /* Drop-out control */ e1 = CEILING( x1 ); e2 = FLOOR( x2 ); /* take care of the special case where both the left */ /* and right contour lie exactly on pixel centers */ if ( dropOutControl != 2 && x2 - x1 - ras.precision <= ras.precision_jitter && e1 != x1 && e2 != x2 ) e2 = e1; e1 = TRUNC( e1 ); e2 = TRUNC( e2 ); if ( e2 >= 0 && e1 < ras.bWidth ) { Byte* target; Int c1, c2; Byte f1, f2; if ( e1 < 0 ) e1 = 0; if ( e2 >= ras.bWidth ) e2 = ras.bWidth - 1; FT_TRACE7(( " -> x=[%ld;%ld]", e1, e2 )); c1 = (Short)( e1 >> 3 ); c2 = (Short)( e2 >> 3 ); f1 = (Byte) ( 0xFF >> ( e1 & 7 ) ); f2 = (Byte) ~( 0x7F >> ( e2 & 7 ) ); target = ras.bLine + c1; c2 -= c1; if ( c2 > 0 ) { target[0] |= f1; /* memset() is slower than the following code on many platforms. */ /* This is due to the fact that, in the vast majority of cases, */ /* the span length in bytes is relatively small. */ while ( --c2 > 0 ) *(++target) = 0xFF; target[1] |= f2; } else *target |= ( f1 & f2 ); } FT_TRACE7(( "\n" )); } static void Vertical_Sweep_Drop( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2, pxl; Short c1, f1; FT_TRACE7(( " y=%d x=[% .12f;% .12f]", y, x1 / (double)ras.precision, x2 / (double)ras.precision )); /* Drop-out control */ /* e2 x2 x1 e1 */ /* */ /* ^ | */ /* | | */ /* +-------------+---------------------+------------+ */ /* | | */ /* | v */ /* */ /* pixel contour contour pixel */ /* center center */ /* drop-out mode scan conversion rules (as defined in OpenType) */ /* --------------------------------------------------------------- */ /* 0 1, 2, 3 */ /* 1 1, 2, 4 */ /* 2 1, 2 */ /* 3 same as mode 2 */ /* 4 1, 2, 5 */ /* 5 1, 2, 6 */ /* 6, 7 same as mode 2 */ e1 = CEILING( x1 ); e2 = FLOOR ( x2 ); pxl = e1; if ( e1 > e2 ) { Int dropOutControl = left->flags & 7; if ( e1 == e2 + ras.precision ) { switch ( dropOutControl ) { case 0: /* simple drop-outs including stubs */ pxl = e2; break; case 4: /* smart drop-outs including stubs */ pxl = SMART( x1, x2 ); break; case 1: /* simple drop-outs excluding stubs */ case 5: /* smart drop-outs excluding stubs */ /* Drop-out Control Rules #4 and #6 */ /* The specification neither provides an exact definition */ /* of a `stub' nor gives exact rules to exclude them. */ /* */ /* Here the constraints we use to recognize a stub. */ /* */ /* upper stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Right is the successor of P_Left in that contour */ /* - y is the top of P_Left and P_Right */ /* */ /* lower stub: */ /* */ /* - P_Left and P_Right are in the same contour */ /* - P_Left is the successor of P_Right in that contour */ /* - y is the bottom of P_Left */ /* */ /* We draw a stub if the following constraints are met. */ /* */ /* - for an upper or lower stub, there is top or bottom */ /* overshoot, respectively */ /* - the covered interval is greater or equal to a half */ /* pixel */ /* upper stub test */ if ( left->next == right && left->height <= 0 && !( left->flags & Overshoot_Top && x2 - x1 >= ras.precision_half ) ) goto Exit; /* lower stub test */ if ( right->next == left && left->start == y && !( left->flags & Overshoot_Bottom && x2 - x1 >= ras.precision_half ) ) goto Exit; if ( dropOutControl == 1 ) pxl = e2; else pxl = SMART( x1, x2 ); break; default: /* modes 2, 3, 6, 7 */ goto Exit; /* no drop-out control */ } /* undocumented but confirmed: If the drop-out would result in a */ /* pixel outside of the bounding box, use the pixel inside of the */ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; else if ( TRUNC( pxl ) >= ras.bWidth ) pxl = e2; /* check that the other pixel isn't set */ e1 = ( pxl == e1 ) ? e2 : e1; e1 = TRUNC( e1 ); c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); if ( e1 >= 0 && e1 < ras.bWidth && ras.bLine[c1] & ( 0x80 >> f1 ) ) goto Exit; } else goto Exit; } e1 = TRUNC( pxl ); if ( e1 >= 0 && e1 < ras.bWidth ) { FT_TRACE7(( " -> x=%ld", e1 )); c1 = (Short)( e1 >> 3 ); f1 = (Short)( e1 & 7 ); ras.bLine[c1] |= (char)( 0x80 >> f1 ); } Exit: FT_TRACE7(( " dropout=%d\n", left->flags & 7 )); } static void Vertical_Sweep_Step( RAS_ARG ) { ras.bLine -= ras.target.pitch; } /************************************************************************ * * Horizontal Sweep Procedure Set * * These four routines are used during the horizontal black/white * sweep phase by the generic Draw_Sweep() function. * */ static void Horizontal_Sweep_Init( RAS_ARGS Short min, Short max ) { /* nothing, really */ FT_UNUSED_RASTER; FT_UNUSED( min ); FT_UNUSED( max ); } static void Horizontal_Sweep_Span( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2; FT_UNUSED( left ); FT_UNUSED( right ); FT_TRACE7(( " x=%d y=[% .12f;% .12f]", y, x1 / (double)ras.precision, x2 / (double)ras.precision )); /* We should not need this procedure but the vertical sweep */ /* mishandles horizontal lines through pixel centers. So we */ /* have to check perfectly aligned span edges here. */ /* */ /* XXX: Can we handle horizontal lines better and drop this? */ e1 = CEILING( x1 ); if ( x1 == e1 ) { e1 = TRUNC( e1 ); if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { Byte f1; PByte bits; bits = ras.bOrigin + ( y >> 3 ) - e1 * ras.target.pitch; f1 = (Byte)( 0x80 >> ( y & 7 ) ); FT_TRACE7(( bits[0] & f1 ? " redundant" : " -> y=%ld edge", e1 )); bits[0] |= f1; } } e2 = FLOOR ( x2 ); if ( x2 == e2 ) { e2 = TRUNC( e2 ); if ( e2 >= 0 && (ULong)e2 < ras.target.rows ) { Byte f1; PByte bits; bits = ras.bOrigin + ( y >> 3 ) - e2 * ras.target.pitch; f1 = (Byte)( 0x80 >> ( y & 7 ) ); FT_TRACE7(( bits[0] & f1 ? " redundant" : " -> y=%ld edge", e2 )); bits[0] |= f1; } } FT_TRACE7(( "\n" )); } static void Horizontal_Sweep_Drop( RAS_ARGS Short y, FT_F26Dot6 x1, FT_F26Dot6 x2, PProfile left, PProfile right ) { Long e1, e2, pxl; PByte bits; Byte f1; FT_TRACE7(( " x=%d y=[% .12f;% .12f]", y, x1 / (double)ras.precision, x2 / (double)ras.precision )); /* During the horizontal sweep, we only take care of drop-outs */ /* e1 + <-- pixel center */ /* | */ /* x1 ---+--> <-- contour */ /* | */ /* | */ /* x2 <--+--- <-- contour */ /* | */ /* | */ /* e2 + <-- pixel center */ e1 = CEILING( x1 ); e2 = FLOOR ( x2 ); pxl = e1; if ( e1 > e2 ) { Int dropOutControl = left->flags & 7; if ( e1 == e2 + ras.precision ) { switch ( dropOutControl ) { case 0: /* simple drop-outs including stubs */ pxl = e2; break; case 4: /* smart drop-outs including stubs */ pxl = SMART( x1, x2 ); break; case 1: /* simple drop-outs excluding stubs */ case 5: /* smart drop-outs excluding stubs */ /* see Vertical_Sweep_Drop for details */ /* rightmost stub test */ if ( left->next == right && left->height <= 0 && !( left->flags & Overshoot_Top && x2 - x1 >= ras.precision_half ) ) goto Exit; /* leftmost stub test */ if ( right->next == left && left->start == y && !( left->flags & Overshoot_Bottom && x2 - x1 >= ras.precision_half ) ) goto Exit; if ( dropOutControl == 1 ) pxl = e2; else pxl = SMART( x1, x2 ); break; default: /* modes 2, 3, 6, 7 */ goto Exit; /* no drop-out control */ } /* undocumented but confirmed: If the drop-out would result in a */ /* pixel outside of the bounding box, use the pixel inside of the */ /* bounding box instead */ if ( pxl < 0 ) pxl = e1; else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) pxl = e2; /* check that the other pixel isn't set */ e1 = ( pxl == e1 ) ? e2 : e1; e1 = TRUNC( e1 ); bits = ras.bOrigin + ( y >> 3 ) - e1 * ras.target.pitch; f1 = (Byte)( 0x80 >> ( y & 7 ) ); if ( e1 >= 0 && (ULong)e1 < ras.target.rows && *bits & f1 ) goto Exit; } else goto Exit; } e1 = TRUNC( pxl ); if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { FT_TRACE7(( " -> y=%ld", e1 )); bits = ras.bOrigin + ( y >> 3 ) - e1 * ras.target.pitch; f1 = (Byte)( 0x80 >> ( y & 7 ) ); bits[0] |= f1; } Exit: FT_TRACE7(( " dropout=%d\n", left->flags & 7 )); } static void Horizontal_Sweep_Step( RAS_ARG ) { /* Nothing, really */ FT_UNUSED_RASTER; } /************************************************************************** * * Generic Sweep Drawing routine * */ static Bool Draw_Sweep( RAS_ARG ) { Short y, y_change, y_height; PProfile P, Q, P_Left, P_Right; Short min_Y, max_Y, top, bottom, dropouts; Long x1, x2, xs, e1, e2; TProfileList waiting; TProfileList draw_left, draw_right; /* initialize empty linked lists */ Init_Linked( &waiting ); Init_Linked( &draw_left ); Init_Linked( &draw_right ); /* first, compute min and max Y */ P = ras.fProfile; max_Y = (Short)TRUNC( ras.minY ); min_Y = (Short)TRUNC( ras.maxY ); while ( P ) { Q = P->link; bottom = (Short)P->start; top = (Short)( P->start + P->height - 1 ); if ( min_Y > bottom ) min_Y = bottom; if ( max_Y < top ) max_Y = top; P->X = 0; InsNew( &waiting, P ); P = Q; } /* check the Y-turns */ if ( ras.numTurns == 0 ) { ras.error = FT_THROW( Invalid_Outline ); return FAILURE; } /* now initialize the sweep */ ras.Proc_Sweep_Init( RAS_VARS min_Y, max_Y ); /* then compute the distance of each profile from min_Y */ P = waiting; while ( P ) { P->countL = P->start - min_Y; P = P->link; } /* let's go */ y = min_Y; y_height = 0; if ( ras.numTurns > 0 && ras.sizeBuff[-ras.numTurns] == min_Y ) ras.numTurns--; while ( ras.numTurns > 0 ) { /* check waiting list for new activations */ P = waiting; while ( P ) { Q = P->link; P->countL -= y_height; if ( P->countL == 0 ) { DelOld( &waiting, P ); if ( P->flags & Flow_Up ) InsNew( &draw_left, P ); else InsNew( &draw_right, P ); } P = Q; } /* sort the drawing lists */ Sort( &draw_left ); Sort( &draw_right ); y_change = (Short)ras.sizeBuff[-ras.numTurns--]; y_height = (Short)( y_change - y ); while ( y < y_change ) { /* let's trace */ dropouts = 0; P_Left = draw_left; P_Right = draw_right; while ( P_Left && P_Right ) { x1 = P_Left ->X; x2 = P_Right->X; if ( x1 > x2 ) { xs = x1; x1 = x2; x2 = xs; } e1 = FLOOR( x1 ); e2 = CEILING( x2 ); if ( x2 - x1 <= ras.precision && e1 != x1 && e2 != x2 ) { if ( e1 > e2 || e2 == e1 + ras.precision ) { Int dropOutControl = P_Left->flags & 7; if ( dropOutControl != 2 ) { /* a drop-out was detected */ P_Left ->X = x1; P_Right->X = x2; /* mark profile for drop-out processing */ P_Left->countL = 1; dropouts++; } goto Skip_To_Next; } } ras.Proc_Sweep_Span( RAS_VARS y, x1, x2, P_Left, P_Right ); Skip_To_Next: P_Left = P_Left->link; P_Right = P_Right->link; } /* handle drop-outs _after_ the span drawing -- */ /* drop-out processing has been moved out of the loop */ /* for performance tuning */ if ( dropouts > 0 ) goto Scan_DropOuts; Next_Line: ras.Proc_Sweep_Step( RAS_VAR ); y++; if ( y < y_change ) { Sort( &draw_left ); Sort( &draw_right ); } } /* now finalize the profiles that need it */ P = draw_left; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_left, P ); P = Q; } P = draw_right; while ( P ) { Q = P->link; if ( P->height == 0 ) DelOld( &draw_right, P ); P = Q; } } /* for gray-scaling, flush the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VAR ); y++; } return SUCCESS; Scan_DropOuts: P_Left = draw_left; P_Right = draw_right; while ( P_Left && P_Right ) { if ( P_Left->countL ) { P_Left->countL = 0; #if 0 dropouts--; /* -- this is useful when debugging only */ #endif ras.Proc_Sweep_Drop( RAS_VARS y, P_Left->X, P_Right->X, P_Left, P_Right ); } P_Left = P_Left->link; P_Right = P_Right->link; } goto Next_Line; } #ifdef STANDALONE_ /************************************************************************** * * The following functions should only compile in stand-alone mode, * i.e., when building this component without the rest of FreeType. * */ /************************************************************************** * * @Function: * FT_Outline_Get_CBox * * @Description: * Return an outline's `control box'. The control box encloses all * the outline's points, including Bézier control points. Though it * coincides with the exact bounding box for most glyphs, it can be * slightly larger in some situations (like when rotating an outline * that contains Bézier outside arcs). * * Computing the control box is very fast, while getting the bounding * box can take much more time as it needs to walk over all segments * and arcs in the outline. To get the latter, you can use the * `ftbbox' component, which is dedicated to this single task. * * @Input: * outline :: * A pointer to the source outline descriptor. * * @Output: * acbox :: * The outline's control box. * * @Note: * See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */ static void FT_Outline_Get_CBox( const FT_Outline* outline, FT_BBox *acbox ) { if ( outline && acbox ) { Long xMin, yMin, xMax, yMax; if ( outline->n_points == 0 ) { xMin = 0; yMin = 0; xMax = 0; yMax = 0; } else { FT_Vector* vec = outline->points; FT_Vector* limit = vec + outline->n_points; xMin = xMax = vec->x; yMin = yMax = vec->y; vec++; for ( ; vec < limit; vec++ ) { Long x, y; x = vec->x; if ( x < xMin ) xMin = x; if ( x > xMax ) xMax = x; y = vec->y; if ( y < yMin ) yMin = y; if ( y > yMax ) yMax = y; } } acbox->xMin = xMin; acbox->xMax = xMax; acbox->yMin = yMin; acbox->yMax = yMax; } } #endif /* STANDALONE_ */ /************************************************************************** * * @Function: * Render_Single_Pass * * @Description: * Perform one sweep with sub-banding. * * @Input: * flipped :: * If set, flip the direction of the outline. * * @Return: * Renderer error code. */ static int Render_Single_Pass( RAS_ARGS Bool flipped, Int y_min, Int y_max ) { Int y_mid; Int band_top = 0; Int band_stack[32]; /* enough to bisect 32-bit int bands */ while ( 1 ) { ras.minY = (Long)y_min * ras.precision; ras.maxY = (Long)y_max * ras.precision; ras.top = ras.buff; ras.error = Raster_Err_Ok; if ( Convert_Glyph( RAS_VARS flipped ) ) { if ( ras.error != Raster_Err_Raster_Overflow ) return ras.error; /* sub-banding */ if ( y_min == y_max ) return ras.error; /* still Raster_Overflow */ y_mid = ( y_min + y_max ) >> 1; band_stack[band_top++] = y_min; y_min = y_mid + 1; } else { if ( ras.fProfile ) if ( Draw_Sweep( RAS_VAR ) ) return ras.error; if ( --band_top < 0 ) break; y_max = y_min - 1; y_min = band_stack[band_top]; } } return Raster_Err_Ok; } /************************************************************************** * * @Function: * Render_Glyph * * @Description: * Render a glyph in a bitmap. Sub-banding if needed. * * @Return: * FreeType error code. 0 means success. */ static FT_Error Render_Glyph( RAS_ARG ) { FT_Error error; Set_High_Precision( RAS_VARS ras.outline.flags & FT_OUTLINE_HIGH_PRECISION ); if ( ras.outline.flags & FT_OUTLINE_IGNORE_DROPOUTS ) ras.dropOutControl = 2; else { if ( ras.outline.flags & FT_OUTLINE_SMART_DROPOUTS ) ras.dropOutControl = 4; else ras.dropOutControl = 0; if ( !( ras.outline.flags & FT_OUTLINE_INCLUDE_STUBS ) ) ras.dropOutControl += 1; } /* Vertical Sweep */ FT_TRACE7(( "Vertical pass (ftraster)\n" )); ras.Proc_Sweep_Init = Vertical_Sweep_Init; ras.Proc_Sweep_Span = Vertical_Sweep_Span; ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; ras.Proc_Sweep_Step = Vertical_Sweep_Step; ras.bWidth = (UShort)ras.target.width; ras.bOrigin = (Byte*)ras.target.buffer; if ( ras.target.pitch > 0 ) ras.bOrigin += (Long)( ras.target.rows - 1 ) * ras.target.pitch; error = Render_Single_Pass( RAS_VARS 0, 0, (Int)ras.target.rows - 1 ); if ( error ) return error; /* Horizontal Sweep */ if ( !( ras.outline.flags & FT_OUTLINE_SINGLE_PASS ) ) { FT_TRACE7(( "Horizontal pass (ftraster)\n" )); ras.Proc_Sweep_Init = Horizontal_Sweep_Init; ras.Proc_Sweep_Span = Horizontal_Sweep_Span; ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop; ras.Proc_Sweep_Step = Horizontal_Sweep_Step; error = Render_Single_Pass( RAS_VARS 1, 0, (Int)ras.target.width - 1 ); if ( error ) return error; } return Raster_Err_Ok; } /**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/ /**** a static object. *****/ #ifdef STANDALONE_ static int ft_black_new( void* memory, FT_Raster *araster ) { static black_TRaster the_raster; FT_UNUSED( memory ); *araster = (FT_Raster)&the_raster; FT_ZERO( &the_raster ); return 0; } static void ft_black_done( FT_Raster raster ) { /* nothing */ FT_UNUSED( raster ); } #else /* !STANDALONE_ */ static int ft_black_new( FT_Memory memory, black_PRaster *araster ) { FT_Error error; black_PRaster raster = NULL; if ( !FT_NEW( raster ) ) raster->memory = memory; *araster = raster; return error; } static void ft_black_done( black_PRaster raster ) { FT_Memory memory = (FT_Memory)raster->memory; FT_FREE( raster ); } #endif /* !STANDALONE_ */ static void ft_black_reset( FT_Raster raster, PByte pool_base, ULong pool_size ) { FT_UNUSED( raster ); FT_UNUSED( pool_base ); FT_UNUSED( pool_size ); } static int ft_black_set_mode( FT_Raster raster, ULong mode, void* args ) { FT_UNUSED( raster ); FT_UNUSED( mode ); FT_UNUSED( args ); return 0; } static int ft_black_render( FT_Raster raster, const FT_Raster_Params* params ) { const FT_Outline* outline = (const FT_Outline*)params->source; const FT_Bitmap* target_map = params->target; #ifndef FT_STATIC_RASTER black_TWorker worker[1]; #endif Long buffer[FT_MAX_BLACK_POOL]; if ( !raster ) return FT_THROW( Raster_Uninitialized ); if ( !outline ) return FT_THROW( Invalid_Outline ); /* return immediately if the outline is empty */ if ( outline->n_points == 0 || outline->n_contours <= 0 ) return Raster_Err_Ok; if ( !outline->contours || !outline->points ) return FT_THROW( Invalid_Outline ); if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 ) return FT_THROW( Invalid_Outline ); /* this version of the raster does not support direct rendering, sorry */ if ( params->flags & FT_RASTER_FLAG_DIRECT || params->flags & FT_RASTER_FLAG_AA ) return FT_THROW( Cannot_Render_Glyph ); if ( !target_map ) return FT_THROW( Invalid_Argument ); /* nothing to do */ if ( !target_map->width || !target_map->rows ) return Raster_Err_Ok; if ( !target_map->buffer ) return FT_THROW( Invalid_Argument ); ras.outline = *outline; ras.target = *target_map; ras.buff = buffer; ras.sizeBuff = (&buffer)[1]; /* Points to right after buffer. */ return Render_Glyph( RAS_VAR ); } FT_DEFINE_RASTER_FUNCS( ft_standard_raster, FT_GLYPH_FORMAT_OUTLINE, (FT_Raster_New_Func) ft_black_new, /* raster_new */ (FT_Raster_Reset_Func) ft_black_reset, /* raster_reset */ (FT_Raster_Set_Mode_Func)ft_black_set_mode, /* raster_set_mode */ (FT_Raster_Render_Func) ft_black_render, /* raster_render */ (FT_Raster_Done_Func) ft_black_done /* raster_done */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/ftraster.c
C++
gpl-3.0
84,452
/**************************************************************************** * * ftraster.h * * The FreeType glyph rasterizer (specification). * * Copyright (C) 1996-2022 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 FTRASTER_H_ #define FTRASTER_H_ #include <ft2build.h> #include FT_CONFIG_CONFIG_H #include <freetype/ftimage.h> #include <freetype/internal/compiler-macros.h> FT_BEGIN_HEADER /************************************************************************** * * Uncomment the following line if you are using ftraster.c as a * standalone module, fully independent of FreeType. */ /* #define STANDALONE_ */ FT_EXPORT_VAR( const FT_Raster_Funcs ) ft_standard_raster; FT_END_HEADER #endif /* FTRASTER_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/ftraster.h
C++
gpl-3.0
1,092
/**************************************************************************** * * ftrend1.c * * The FreeType glyph rasterizer interface (body). * * Copyright (C) 1996-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftobjs.h> #include <freetype/ftoutln.h> #include "ftrend1.h" #include "ftraster.h" #include "rasterrs.h" /* initialize renderer -- init its raster */ static FT_Error ft_raster1_init( FT_Renderer render ) { render->clazz->raster_class->raster_reset( render->raster, NULL, 0 ); return FT_Err_Ok; } /* set render-specific mode */ static FT_Error ft_raster1_set_mode( FT_Renderer render, FT_ULong mode_tag, FT_Pointer data ) { /* we simply pass it to the raster */ return render->clazz->raster_class->raster_set_mode( render->raster, mode_tag, data ); } /* transform a given glyph image */ static FT_Error ft_raster1_transform( FT_Renderer render, FT_GlyphSlot slot, const FT_Matrix* matrix, const FT_Vector* delta ) { FT_Error error = FT_Err_Ok; if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( matrix ) FT_Outline_Transform( &slot->outline, matrix ); if ( delta ) FT_Outline_Translate( &slot->outline, delta->x, delta->y ); Exit: return error; } /* return the glyph's control box */ static void ft_raster1_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox ) { FT_ZERO( cbox ); if ( slot->format == render->glyph_format ) FT_Outline_Get_CBox( &slot->outline, cbox ); } /* convert a slot's glyph image into a bitmap */ static FT_Error ft_raster1_render( FT_Renderer render, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) { FT_Error error = FT_Err_Ok; FT_Outline* outline = &slot->outline; FT_Bitmap* bitmap = &slot->bitmap; FT_Memory memory = render->root.memory; FT_Pos x_shift = 0; FT_Pos y_shift = 0; FT_Raster_Params params; /* check glyph image format */ if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* check rendering mode */ if ( mode != FT_RENDER_MODE_MONO ) { /* raster1 is only capable of producing monochrome bitmaps */ return FT_THROW( Cannot_Render_Glyph ); } /* release old bitmap buffer */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) ) { error = FT_THROW( Raster_Overflow ); goto Exit; } /* allocate new one */ if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) ) goto Exit; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; x_shift = -slot->bitmap_left * 64; y_shift = ( (FT_Int)bitmap->rows - slot->bitmap_top ) * 64; if ( origin ) { x_shift += origin->x; y_shift += origin->y; } /* translate outline to render it into the bitmap */ if ( x_shift || y_shift ) FT_Outline_Translate( outline, x_shift, y_shift ); /* set up parameters */ params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_DEFAULT; /* render outline into the bitmap */ error = render->raster_render( render->raster, &params ); Exit: if ( !error ) /* everything is fine; the glyph is now officially a bitmap */ slot->format = FT_GLYPH_FORMAT_BITMAP; else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } if ( x_shift || y_shift ) FT_Outline_Translate( outline, -x_shift, -y_shift ); return error; } FT_DEFINE_RENDERER( ft_raster1_renderer_class, FT_MODULE_RENDERER, sizeof ( FT_RendererRec ), "raster1", 0x10000L, 0x20000L, NULL, /* module specific interface */ (FT_Module_Constructor)ft_raster1_init, /* module_init */ (FT_Module_Destructor) NULL, /* module_done */ (FT_Module_Requester) NULL, /* get_interface */ FT_GLYPH_FORMAT_OUTLINE, (FT_Renderer_RenderFunc) ft_raster1_render, /* render_glyph */ (FT_Renderer_TransformFunc)ft_raster1_transform, /* transform_glyph */ (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox, /* get_glyph_cbox */ (FT_Renderer_SetModeFunc) ft_raster1_set_mode, /* set_mode */ (FT_Raster_Funcs*)&ft_standard_raster /* raster_class */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/ftrend1.c
C++
gpl-3.0
5,490
/**************************************************************************** * * ftrend1.h * * The FreeType glyph rasterizer interface (specification). * * Copyright (C) 1996-2022 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 FTREND1_H_ #define FTREND1_H_ #include <freetype/ftrender.h> FT_BEGIN_HEADER FT_DECLARE_RENDERER( ft_raster1_renderer_class ) FT_END_HEADER #endif /* FTREND1_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/ftrend1.h
C++
gpl-3.0
755
# # FreeType 2 renderer module definition # # Copyright (C) 1996-2022 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. FTMODULE_H_COMMANDS += RASTER_MODULE define RASTER_MODULE $(OPEN_DRIVER) FT_Renderer_Class, ft_raster1_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)raster $(ECHO_DRIVER_DESC)monochrome bitmap renderer$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/module.mk
mk
gpl-3.0
666
/**************************************************************************** * * raster.c * * FreeType monochrome rasterer module component (body only). * * Copyright (C) 1996-2022 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "ftraster.c" #include "ftrend1.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/raster.c
C++
gpl-3.0
654
/**************************************************************************** * * rasterrs.h * * monochrome renderer error codes (specification only). * * Copyright (C) 2001-2022 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. * */ /************************************************************************** * * This file is used to define the monochrome renderer error enumeration * constants. * */ #ifndef RASTERRS_H_ #define RASTERRS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX Raster_Err_ #define FT_ERR_BASE FT_Mod_Err_Raster #include <freetype/fterrors.h> #endif /* RASTERRS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/rasterrs.h
C++
gpl-3.0
1,005
# # FreeType 2 renderer module build rules # # Copyright (C) 1996-2022 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. # raster driver directory # RASTER_DIR := $(SRC_DIR)/raster # compilation flags for the driver # RASTER_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(RASTER_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # raster driver sources (i.e., C files) # RASTER_DRV_SRC := $(RASTER_DIR)/ftraster.c \ $(RASTER_DIR)/ftrend1.c # raster driver headers # RASTER_DRV_H := $(RASTER_DRV_SRC:%.c=%.h) \ $(RASTER_DIR)/rasterrs.h # raster driver object(s) # # RASTER_DRV_OBJ_M is used during `multi' builds. # RASTER_DRV_OBJ_S is used during `single' builds. # RASTER_DRV_OBJ_M := $(RASTER_DRV_SRC:$(RASTER_DIR)/%.c=$(OBJ_DIR)/%.$O) RASTER_DRV_OBJ_S := $(OBJ_DIR)/raster.$O # raster driver source file for single build # RASTER_DRV_SRC_S := $(RASTER_DIR)/raster.c # raster driver - single object # $(RASTER_DRV_OBJ_S): $(RASTER_DRV_SRC_S) $(RASTER_DRV_SRC) \ $(FREETYPE_H) $(RASTER_DRV_H) $(RASTER_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(RASTER_DRV_SRC_S)) # raster driver - multiple objects # $(OBJ_DIR)/%.$O: $(RASTER_DIR)/%.c $(FREETYPE_H) $(RASTER_DRV_H) $(RASTER_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(RASTER_DRV_OBJ_S) DRV_OBJS_M += $(RASTER_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/raster/rules.mk
mk
gpl-3.0
1,848
/**************************************************************************** * * ftbsdf.c * * Signed Distance Field support for bitmap fonts (body only). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftmemory.h> #include <freetype/fttrigon.h> #include "ftsdf.h" #include "ftsdferrs.h" #include "ftsdfcommon.h" /************************************************************************** * * A brief technical overview of how the BSDF rasterizer works * ----------------------------------------------------------- * * [Notes]: * * SDF stands for Signed Distance Field everywhere. * * * BSDF stands for Bitmap to Signed Distance Field rasterizer. * * * This renderer converts rasterized bitmaps to SDF. There is another * renderer called 'sdf', which generates SDF directly from outlines; * see file `ftsdf.c` for more. * * * The idea of generating SDF from bitmaps is taken from two research * papers, where one is dependent on the other: * * - Per-Erik Danielsson: Euclidean Distance Mapping * http://webstaff.itn.liu.se/~stegu/JFA/Danielsson.pdf * * From this paper we use the eight-point sequential Euclidean * distance mapping (8SED). This is the heart of the process used * in this rasterizer. * * - Stefan Gustavson, Robin Strand: Anti-aliased Euclidean distance transform. * http://weber.itn.liu.se/~stegu/aadist/edtaa_preprint.pdf * * The original 8SED algorithm discards the pixels' alpha values, * which can contain information about the actual outline of the * glyph. This paper takes advantage of those alpha values and * approximates outline pretty accurately. * * * This rasterizer also works for monochrome bitmaps. However, the * result is not as accurate since we don't have any way to * approximate outlines from binary bitmaps. * * ======================================================================== * * Generating SDF from bitmap is done in several steps. * * (1) The only information we have is the bitmap itself. It can * be monochrome or anti-aliased. If it is anti-aliased, pixel values * are nothing but coverage values. These coverage values can be used * to extract information about the outline of the image. For * example, if the pixel's alpha value is 0.5, then we can safely * assume that the outline passes through the center of the pixel. * * (2) Find edge pixels in the bitmap (see `bsdf_is_edge` for more). For * all edge pixels we use the Anti-aliased Euclidean distance * transform algorithm and compute approximate edge distances (see * `compute_edge_distance` and/or the second paper for more). * * (3) Now that we have computed approximate distances for edge pixels we * use the 8SED algorithm to basically sweep the entire bitmap and * compute distances for the rest of the pixels. (Since the algorithm * is pretty convoluted it is only explained briefly in a comment to * function `edt8`. To see the actual algorithm refer to the first * paper.) * * (4) Finally, compute the sign for each pixel. This is done in function * `finalize_sdf`. The basic idea is that if a pixel's original * alpha/coverage value is greater than 0.5 then it is 'inside' (and * 'outside' otherwise). * * Pseudo Code: * * ``` * b = source bitmap; * t = target bitmap; * dm = list of distances; // dimension equal to b * * foreach grid_point (x, y) in b: * { * if (is_edge(x, y)): * dm = approximate_edge_distance(b, x, y); * * // do the 8SED on the distances * edt8(dm); * * // determine the signs * determine_signs(dm): * * // copy SDF data to the target bitmap * copy(dm to t); * } * */ /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT bsdf /************************************************************************** * * useful macros * */ #define ONE 65536 /* 1 in 16.16 */ /************************************************************************** * * structs * */ /************************************************************************** * * @Struct: * BSDF_TRaster * * @Description: * This struct is used in place of @FT_Raster and is stored within the * internal FreeType renderer struct. While rasterizing this is passed * to the @FT_Raster_RenderFunc function, which then can be used however * we want. * * @Fields: * memory :: * Used internally to allocate intermediate memory while raterizing. * */ typedef struct BSDF_TRaster_ { FT_Memory memory; } BSDF_TRaster, *BSDF_PRaster; /************************************************************************** * * @Struct: * ED * * @Description: * Euclidean distance. It gets used for Euclidean distance transforms; * it can also be interpreted as an edge distance. * * @Fields: * dist :: * Vector length of the `prox` parameter. Can be squared or absolute * depending on the `USE_SQUARED_DISTANCES` macro defined in file * `ftsdfcommon.h`. * * prox :: * Vector to the nearest edge. Can also be interpreted as shortest * distance of a point. * * alpha :: * Alpha value of the original bitmap from which we generate SDF. * Needed for computing the gradient and determining the proper sign * of a pixel. * */ typedef struct ED_ { FT_16D16 dist; FT_16D16_Vec prox; FT_Byte alpha; } ED; /************************************************************************** * * @Struct: * BSDF_Worker * * @Description: * A convenience struct that is passed to functions while generating * SDF; most of those functions require the same parameters. * * @Fields: * distance_map :: * A one-dimensional array that gets interpreted as two-dimensional * one. It contains the Euclidean distances of all points of the * bitmap. * * width :: * Width of the above `distance_map`. * * rows :: * Number of rows in the above `distance_map`. * * params :: * Internal parameters and properties required by the rasterizer. See * file `ftsdf.h` for more. * */ typedef struct BSDF_Worker_ { ED* distance_map; FT_Int width; FT_Int rows; SDF_Raster_Params params; } BSDF_Worker; /************************************************************************** * * initializer * */ static const ED zero_ed = { 0, { 0, 0 }, 0 }; /************************************************************************** * * rasterizer functions * */ /************************************************************************** * * @Function: * bsdf_is_edge * * @Description: * Check whether a pixel is an edge pixel, i.e., whether it is * surrounded by a completely black pixel (zero alpha), and the current * pixel is not a completely black pixel. * * @Input: * dm :: * Array of distances. The parameter must point to the current * pixel, i.e., the pixel that is to be checked for being an edge. * * x :: * The x position of the current pixel. * * y :: * The y position of the current pixel. * * w :: * Width of the bitmap. * * r :: * Number of rows in the bitmap. * * @Return: * 1~if the current pixel is an edge pixel, 0~otherwise. * */ #ifdef CHECK_NEIGHBOR #undef CHECK_NEIGHBOR #endif #define CHECK_NEIGHBOR( x_offset, y_offset ) \ do \ { \ if ( x + x_offset >= 0 && x + x_offset < w && \ y + y_offset >= 0 && y + y_offset < r ) \ { \ num_neighbors++; \ \ to_check = dm + y_offset * w + x_offset; \ if ( to_check->alpha == 0 ) \ { \ is_edge = 1; \ goto Done; \ } \ } \ } while ( 0 ) static FT_Bool bsdf_is_edge( ED* dm, /* distance map */ FT_Int x, /* x index of point to check */ FT_Int y, /* y index of point to check */ FT_Int w, /* width */ FT_Int r ) /* rows */ { FT_Bool is_edge = 0; ED* to_check = NULL; FT_Int num_neighbors = 0; if ( dm->alpha == 0 ) goto Done; if ( dm->alpha > 0 && dm->alpha < 255 ) { is_edge = 1; goto Done; } /* up */ CHECK_NEIGHBOR( 0, -1 ); /* down */ CHECK_NEIGHBOR( 0, 1 ); /* left */ CHECK_NEIGHBOR( -1, 0 ); /* right */ CHECK_NEIGHBOR( 1, 0 ); /* up left */ CHECK_NEIGHBOR( -1, -1 ); /* up right */ CHECK_NEIGHBOR( 1, -1 ); /* down left */ CHECK_NEIGHBOR( -1, 1 ); /* down right */ CHECK_NEIGHBOR( 1, 1 ); if ( num_neighbors != 8 ) is_edge = 1; Done: return is_edge; } #undef CHECK_NEIGHBOR /************************************************************************** * * @Function: * compute_edge_distance * * @Description: * Approximate the outline and compute the distance from `current` * to the approximated outline. * * @Input: * current :: * Array of Euclidean distances. `current` must point to the position * for which the distance is to be caculated. We treat this array as * a two-dimensional array mapped to a one-dimensional array. * * x :: * The x coordinate of the `current` parameter in the array. * * y :: * The y coordinate of the `current` parameter in the array. * * w :: * The width of the distances array. * * r :: * Number of rows in the distances array. * * @Return: * A vector pointing to the approximate edge distance. * * @Note: * This is a computationally expensive function. Try to reduce the * number of calls to this function. Moreover, this must only be used * for edge pixel positions. * */ static FT_16D16_Vec compute_edge_distance( ED* current, FT_Int x, FT_Int y, FT_Int w, FT_Int r ) { /* * This function, based on the paper presented by Stefan Gustavson and * Robin Strand, gets used to approximate edge distances from * anti-aliased bitmaps. * * The algorithm is as follows. * * (1) In anti-aliased images, the pixel's alpha value is the coverage * of the pixel by the outline. For example, if the alpha value is * 0.5f we can assume that the outline passes through the center of * the pixel. * * (2) For this reason we can use that alpha value to approximate the real * distance of the pixel to edge pretty accurately. A simple * approximation is `(0.5f - alpha)`, assuming that the outline is * parallel to the x or y~axis. However, in this algorithm we use a * different approximation which is quite accurate even for * non-axis-aligned edges. * * (3) The only remaining piece of information that we cannot * approximate directly from the alpha is the direction of the edge. * This is where we use Sobel's operator to compute the gradient of * the pixel. The gradient give us a pretty good approximation of * the edge direction. We use a 3x3 kernel filter to compute the * gradient. * * (4) After the above two steps we have both the direction and the * distance to the edge which is used to generate the Signed * Distance Field. * * References: * * - Anti-Aliased Euclidean Distance Transform: * http://weber.itn.liu.se/~stegu/aadist/edtaa_preprint.pdf * - Sobel Operator: * https://en.wikipedia.org/wiki/Sobel_operator */ FT_16D16_Vec g = { 0, 0 }; FT_16D16 dist, current_alpha; FT_16D16 a1, temp; FT_16D16 gx, gy; FT_16D16 alphas[9]; /* Since our spread cannot be 0, this condition */ /* can never be true. */ if ( x <= 0 || x >= w - 1 || y <= 0 || y >= r - 1 ) return g; /* initialize the alphas */ alphas[0] = 256 * (FT_16D16)current[-w - 1].alpha; alphas[1] = 256 * (FT_16D16)current[-w ].alpha; alphas[2] = 256 * (FT_16D16)current[-w + 1].alpha; alphas[3] = 256 * (FT_16D16)current[ -1].alpha; alphas[4] = 256 * (FT_16D16)current[ 0].alpha; alphas[5] = 256 * (FT_16D16)current[ 1].alpha; alphas[6] = 256 * (FT_16D16)current[ w - 1].alpha; alphas[7] = 256 * (FT_16D16)current[ w ].alpha; alphas[8] = 256 * (FT_16D16)current[ w + 1].alpha; current_alpha = alphas[4]; /* Compute the gradient using the Sobel operator. */ /* In this case we use the following 3x3 filters: */ /* */ /* For x: | -1 0 -1 | */ /* | -root(2) 0 root(2) | */ /* | -1 0 1 | */ /* */ /* For y: | -1 -root(2) -1 | */ /* | 0 0 0 | */ /* | 1 root(2) 1 | */ /* */ /* [Note]: 92681 is root(2) in 16.16 format. */ g.x = -alphas[0] - FT_MulFix( alphas[3], 92681 ) - alphas[6] + alphas[2] + FT_MulFix( alphas[5], 92681 ) + alphas[8]; g.y = -alphas[0] - FT_MulFix( alphas[1], 92681 ) - alphas[2] + alphas[6] + FT_MulFix( alphas[7], 92681 ) + alphas[8]; FT_Vector_NormLen( &g ); /* The gradient gives us the direction of the */ /* edge for the current pixel. Once we have the */ /* approximate direction of the edge, we can */ /* approximate the edge distance much better. */ if ( g.x == 0 || g.y == 0 ) dist = ONE / 2 - alphas[4]; else { gx = g.x; gy = g.y; gx = FT_ABS( gx ); gy = FT_ABS( gy ); if ( gx < gy ) { temp = gx; gx = gy; gy = temp; } a1 = FT_DivFix( gy, gx ) / 2; if ( current_alpha < a1 ) dist = ( gx + gy ) / 2 - square_root( 2 * FT_MulFix( gx, FT_MulFix( gy, current_alpha ) ) ); else if ( current_alpha < ( ONE - a1 ) ) dist = FT_MulFix( ONE / 2 - current_alpha, gx ); else dist = -( gx + gy ) / 2 + square_root( 2 * FT_MulFix( gx, FT_MulFix( gy, ONE - current_alpha ) ) ); } g.x = FT_MulFix( g.x, dist ); g.y = FT_MulFix( g.y, dist ); return g; } /************************************************************************** * * @Function: * bsdf_approximate_edge * * @Description: * Loops over all the pixels and call `compute_edge_distance` only for * edge pixels. This maked the process a lot faster since * `compute_edge_distance` uses functions such as `FT_Vector_NormLen', * which are quite slow. * * @InOut: * worker :: * Contains the distance map as well as all the relevant parameters * required by the function. * * @Return: * FreeType error, 0 means success. * * @Note: * The function directly manipulates `worker->distance_map`. * */ static FT_Error bsdf_approximate_edge( BSDF_Worker* worker ) { FT_Error error = FT_Err_Ok; FT_Int i, j; FT_Int index; ED* ed; if ( !worker || !worker->distance_map ) { error = FT_THROW( Invalid_Argument ); goto Exit; } ed = worker->distance_map; for ( j = 0; j < worker->rows; j++ ) { for ( i = 0; i < worker->width; i++ ) { index = j * worker->width + i; if ( bsdf_is_edge( worker->distance_map + index, i, j, worker->width, worker->rows ) ) { /* approximate the edge distance for edge pixels */ ed[index].prox = compute_edge_distance( ed + index, i, j, worker->width, worker->rows ); ed[index].dist = VECTOR_LENGTH_16D16( ed[index].prox ); } else { /* for non-edge pixels assign far away distances */ ed[index].dist = 400 * ONE; ed[index].prox.x = 200 * ONE; ed[index].prox.y = 200 * ONE; } } } Exit: return error; } /************************************************************************** * * @Function: * bsdf_init_distance_map * * @Description: * Initialize the distance map according to the '8-point sequential * Euclidean distance mapping' (8SED) algorithm. Basically it copies * the `source` bitmap alpha values to the `distance_map->alpha` * parameter of `worker`. * * @Input: * source :: * Source bitmap to copy the data from. * * @Output: * worker :: * Target distance map to copy the data to. * * @Return: * FreeType error, 0 means success. * */ static FT_Error bsdf_init_distance_map( const FT_Bitmap* source, BSDF_Worker* worker ) { FT_Error error = FT_Err_Ok; FT_Int x_diff, y_diff; FT_Int t_i, t_j, s_i, s_j; FT_Byte* s; ED* t; /* again check the parameters (probably unnecessary) */ if ( !source || !worker ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* Because of the way we convert a bitmap to SDF, */ /* i.e., aligning the source to the center of the */ /* target, the target's width and rows must be */ /* checked before copying. */ if ( worker->width < (FT_Int)source->width || worker->rows < (FT_Int)source->rows ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* check pixel mode */ if ( source->pixel_mode == FT_PIXEL_MODE_NONE ) { FT_ERROR(( "bsdf_copy_source_to_target:" " Invalid pixel mode of source bitmap" )); error = FT_THROW( Invalid_Argument ); goto Exit; } #ifdef FT_DEBUG_LEVEL_TRACE if ( source->pixel_mode == FT_PIXEL_MODE_MONO ) { FT_TRACE0(( "bsdf_copy_source_to_target:" " The `bsdf' renderer can convert monochrome\n" )); FT_TRACE0(( " " " bitmaps to SDF but the results are not perfect\n" )); FT_TRACE0(( " " " because there is no way to approximate actual\n" )); FT_TRACE0(( " " " outlines from monochrome bitmaps. Consider\n" )); FT_TRACE0(( " " " using an anti-aliased bitmap instead.\n" )); } #endif /* Calculate the width and row differences */ /* between target and source. */ x_diff = worker->width - (int)source->width; y_diff = worker->rows - (int)source->rows; x_diff /= 2; y_diff /= 2; t = (ED*)worker->distance_map; s = source->buffer; /* For now we only support pixel mode `FT_PIXEL_MODE_MONO` */ /* and `FT_PIXEL_MODE_GRAY`. More will be added later. */ /* */ /* [NOTE]: We can also use @FT_Bitmap_Convert to convert */ /* bitmap to 8bpp. To avoid extra allocation and */ /* since the target bitmap can be 16bpp we manually */ /* convert the source bitmap to the desired bpp. */ switch ( source->pixel_mode ) { case FT_PIXEL_MODE_MONO: { FT_Int t_width = worker->width; FT_Int t_rows = worker->rows; FT_Int s_width = (int)source->width; FT_Int s_rows = (int)source->rows; for ( t_j = 0; t_j < t_rows; t_j++ ) { for ( t_i = 0; t_i < t_width; t_i++ ) { FT_Int t_index = t_j * t_width + t_i; FT_Int s_index; FT_Int div, mod; FT_Byte pixel, byte; t[t_index] = zero_ed; s_i = t_i - x_diff; s_j = t_j - y_diff; /* Assign 0 to padding similar to */ /* the source bitmap. */ if ( s_i < 0 || s_i >= s_width || s_j < 0 || s_j >= s_rows ) continue; if ( worker->params.flip_y ) s_index = ( s_rows - s_j - 1 ) * source->pitch; else s_index = s_j * source->pitch; div = s_index + s_i / 8; mod = 7 - s_i % 8; pixel = s[div]; byte = (FT_Byte)( 1 << mod ); t[t_index].alpha = pixel & byte ? 255 : 0; } } } break; case FT_PIXEL_MODE_GRAY: { FT_Int t_width = worker->width; FT_Int t_rows = worker->rows; FT_Int s_width = (int)source->width; FT_Int s_rows = (int)source->rows; /* loop over all pixels and assign pixel values from source */ for ( t_j = 0; t_j < t_rows; t_j++ ) { for ( t_i = 0; t_i < t_width; t_i++ ) { FT_Int t_index = t_j * t_width + t_i; FT_Int s_index; t[t_index] = zero_ed; s_i = t_i - x_diff; s_j = t_j - y_diff; /* Assign 0 to padding similar to */ /* the source bitmap. */ if ( s_i < 0 || s_i >= s_width || s_j < 0 || s_j >= s_rows ) continue; if ( worker->params.flip_y ) s_index = ( s_rows - s_j - 1 ) * s_width + s_i; else s_index = s_j * s_width + s_i; /* simply copy the alpha values */ t[t_index].alpha = s[s_index]; } } } break; default: FT_ERROR(( "bsdf_copy_source_to_target:" " unsopported pixel mode of source bitmap\n" )); error = FT_THROW( Unimplemented_Feature ); break; } Exit: return error; } /************************************************************************** * * @Function: * compare_neighbor * * @Description: * Compare neighbor pixel (which is defined by the offset) and update * `current` distance if the new distance is shorter than the original. * * @Input: * x_offset :: * X offset of the neighbor to be checked. The offset is relative to * the `current`. * * y_offset :: * Y offset of the neighbor to be checked. The offset is relative to * the `current`. * * width :: * Width of the `current` array. * * @InOut: * current :: * Pointer into array of distances. This parameter must point to the * position whose neighbor is to be checked. The array is treated as * a two-dimensional array. * */ static void compare_neighbor( ED* current, FT_Int x_offset, FT_Int y_offset, FT_Int width ) { ED* to_check; FT_16D16 dist; FT_16D16_Vec dist_vec; to_check = current + ( y_offset * width ) + x_offset; /* * While checking for the nearest point we first approximate the * distance of `current` by adding the deviation (which is sqrt(2) at * most). Only if the new value is less than the current value we * calculate the actual distances using `FT_Vector_Length`. This last * step can be omitted by using squared distances. */ /* * Approximate the distance. We subtract 1 to avoid precision errors, * which could happen because the two directions can be opposite. */ dist = to_check->dist - ONE; if ( dist < current->dist ) { dist_vec = to_check->prox; dist_vec.x += x_offset * ONE; dist_vec.y += y_offset * ONE; dist = VECTOR_LENGTH_16D16( dist_vec ); if ( dist < current->dist ) { current->dist = dist; current->prox = dist_vec; } } } /************************************************************************** * * @Function: * first_pass * * @Description: * First pass of the 8SED algorithm. Loop over the bitmap from top to * bottom and scan each row left to right, updating the distances in * `worker->distance_map`. * * @InOut: * worker:: * Contains all the relevant parameters. * */ static void first_pass( BSDF_Worker* worker ) { FT_Int i, j; /* iterators */ FT_Int w, r; /* width, rows */ ED* dm; /* distance map */ dm = worker->distance_map; w = worker->width; r = worker->rows; /* Start scanning from top to bottom and sweep each */ /* row back and forth comparing the distances of the */ /* neighborhood. Leave the first row as it has no top */ /* neighbor; it will be covered in the second scan of */ /* the image (from bottom to top). */ for ( j = 1; j < r; j++ ) { FT_Int index; ED* current; /* Forward pass of rows (left -> right). Leave the first */ /* column, which gets covered in the backward pass. */ for ( i = 1; i < w - 1; i++ ) { index = j * w + i; current = dm + index; /* left-up */ compare_neighbor( current, -1, -1, w ); /* up */ compare_neighbor( current, 0, -1, w ); /* up-right */ compare_neighbor( current, 1, -1, w ); /* left */ compare_neighbor( current, -1, 0, w ); } /* Backward pass of rows (right -> left). Leave the last */ /* column, which was already covered in the forward pass. */ for ( i = w - 2; i >= 0; i-- ) { index = j * w + i; current = dm + index; /* right */ compare_neighbor( current, 1, 0, w ); } } } /************************************************************************** * * @Function: * second_pass * * @Description: * Second pass of the 8SED algorithm. Loop over the bitmap from bottom * to top and scan each row left to right, updating the distances in * `worker->distance_map`. * * @InOut: * worker:: * Contains all the relevant parameters. * */ static void second_pass( BSDF_Worker* worker ) { FT_Int i, j; /* iterators */ FT_Int w, r; /* width, rows */ ED* dm; /* distance map */ dm = worker->distance_map; w = worker->width; r = worker->rows; /* Start scanning from bottom to top and sweep each */ /* row back and forth comparing the distances of the */ /* neighborhood. Leave the last row as it has no down */ /* neighbor; it is already covered in the first scan */ /* of the image (from top to bottom). */ for ( j = r - 2; j >= 0; j-- ) { FT_Int index; ED* current; /* Forward pass of rows (left -> right). Leave the first */ /* column, which gets covered in the backward pass. */ for ( i = 1; i < w - 1; i++ ) { index = j * w + i; current = dm + index; /* left-up */ compare_neighbor( current, -1, 1, w ); /* up */ compare_neighbor( current, 0, 1, w ); /* up-right */ compare_neighbor( current, 1, 1, w ); /* left */ compare_neighbor( current, -1, 0, w ); } /* Backward pass of rows (right -> left). Leave the last */ /* column, which was already covered in the forward pass. */ for ( i = w - 2; i >= 0; i-- ) { index = j * w + i; current = dm + index; /* right */ compare_neighbor( current, 1, 0, w ); } } } /************************************************************************** * * @Function: * edt8 * * @Description: * Compute the distance map of the a bitmap. Execute both first and * second pass of the 8SED algorithm. * * @InOut: * worker:: * Contains all the relevant parameters. * * @Return: * FreeType error, 0 means success. * */ static FT_Error edt8( BSDF_Worker* worker ) { FT_Error error = FT_Err_Ok; if ( !worker || !worker->distance_map ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* first scan of the image */ first_pass( worker ); /* second scan of the image */ second_pass( worker ); Exit: return error; } /************************************************************************** * * @Function: * finalize_sdf * * @Description: * Copy the SDF data from `worker->distance_map` to the `target` bitmap. * Also transform the data to output format, (which is 6.10 fixed-point * format at the moment). * * @Input: * worker :: * Contains source distance map and other SDF data. * * @Output: * target :: * Target bitmap to which the SDF data is copied to. * * @Return: * FreeType error, 0 means success. * */ static FT_Error finalize_sdf( BSDF_Worker* worker, const FT_Bitmap* target ) { FT_Error error = FT_Err_Ok; FT_Int w, r; FT_Int i, j; FT_SDFFormat* t_buffer; FT_16D16 sp_sq, spread; if ( !worker || !target ) { error = FT_THROW( Invalid_Argument ); goto Exit; } w = (int)target->width; r = (int)target->rows; t_buffer = (FT_SDFFormat*)target->buffer; if ( w != worker->width || r != worker->rows ) { error = FT_THROW( Invalid_Argument ); goto Exit; } spread = FT_INT_16D16( worker->params.spread ); #if USE_SQUARED_DISTANCES sp_sq = FT_INT_16D16( worker->params.spread * worker->params.spread ); #else sp_sq = FT_INT_16D16( worker->params.spread ); #endif for ( j = 0; j < r; j++ ) { for ( i = 0; i < w; i++ ) { FT_Int index; FT_16D16 dist; FT_SDFFormat final_dist; FT_Char sign; index = j * w + i; dist = worker->distance_map[index].dist; if ( dist < 0 || dist > sp_sq ) dist = sp_sq; #if USE_SQUARED_DISTANCES dist = square_root( dist ); #endif /* We assume that if the pixel is inside a contour */ /* its coverage value must be > 127. */ sign = worker->distance_map[index].alpha < 127 ? -1 : 1; /* flip the sign according to the property */ if ( worker->params.flip_sign ) sign = -sign; /* concatenate from 16.16 to appropriate format */ final_dist = map_fixed_to_sdf( dist * sign, spread ); t_buffer[index] = final_dist; } } Exit: return error; } /************************************************************************** * * interface functions * */ /* called when adding a new module through @FT_Add_Module */ static FT_Error bsdf_raster_new( FT_Memory memory, BSDF_PRaster* araster ) { FT_Error error; BSDF_PRaster raster = NULL; if ( !FT_NEW( raster ) ) raster->memory = memory; *araster = raster; return error; } /* unused */ static void bsdf_raster_reset( FT_Raster raster, unsigned char* pool_base, unsigned long pool_size ) { FT_UNUSED( raster ); FT_UNUSED( pool_base ); FT_UNUSED( pool_size ); } /* unused */ static FT_Error bsdf_raster_set_mode( FT_Raster raster, unsigned long mode, void* args ) { FT_UNUSED( raster ); FT_UNUSED( mode ); FT_UNUSED( args ); return FT_Err_Ok; } /* called while rendering through @FT_Render_Glyph */ static FT_Error bsdf_raster_render( FT_Raster raster, const FT_Raster_Params* params ) { FT_Error error = FT_Err_Ok; FT_Memory memory = NULL; const FT_Bitmap* source = NULL; const FT_Bitmap* target = NULL; BSDF_TRaster* bsdf_raster = (BSDF_TRaster*)raster; BSDF_Worker worker; const SDF_Raster_Params* sdf_params = (const SDF_Raster_Params*)params; worker.distance_map = NULL; /* check for valid parameters */ if ( !raster || !params ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* check whether the flag is set */ if ( sdf_params->root.flags != FT_RASTER_FLAG_SDF ) { error = FT_THROW( Raster_Corrupted ); goto Exit; } source = (const FT_Bitmap*)sdf_params->root.source; target = (const FT_Bitmap*)sdf_params->root.target; /* check source and target bitmap */ if ( !source || !target ) { error = FT_THROW( Invalid_Argument ); goto Exit; } memory = bsdf_raster->memory; if ( !memory ) { FT_TRACE0(( "bsdf_raster_render: Raster not set up properly,\n" )); FT_TRACE0(( " unable to find memory handle.\n" )); error = FT_THROW( Invalid_Handle ); goto Exit; } /* check whether spread is set properly */ if ( sdf_params->spread > MAX_SPREAD || sdf_params->spread < MIN_SPREAD ) { FT_TRACE0(( "bsdf_raster_render:" " The `spread' field of `SDF_Raster_Params'\n" )); FT_TRACE0(( " " " is invalid; the value of this field must be\n" )); FT_TRACE0(( " " " within [%d, %d].\n", MIN_SPREAD, MAX_SPREAD )); FT_TRACE0(( " " " Also, you must pass `SDF_Raster_Params'\n" )); FT_TRACE0(( " " " instead of the default `FT_Raster_Params'\n" )); FT_TRACE0(( " " " while calling this function and set the fields\n" )); FT_TRACE0(( " " " accordingly.\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } /* set up the worker */ /* allocate the distance map */ if ( FT_QALLOC_MULT( worker.distance_map, target->rows, target->width * sizeof ( *worker.distance_map ) ) ) goto Exit; worker.width = (int)target->width; worker.rows = (int)target->rows; worker.params = *sdf_params; FT_CALL( bsdf_init_distance_map( source, &worker ) ); FT_CALL( bsdf_approximate_edge( &worker ) ); FT_CALL( edt8( &worker ) ); FT_CALL( finalize_sdf( &worker, target ) ); FT_TRACE0(( "bsdf_raster_render: Total memory used = %ld\n", worker.width * worker.rows * (long)sizeof ( *worker.distance_map ) )); Exit: if ( worker.distance_map ) FT_FREE( worker.distance_map ); return error; } /* called while deleting `FT_Library` only if the module is added */ static void bsdf_raster_done( FT_Raster raster ) { FT_Memory memory = (FT_Memory)((BSDF_TRaster*)raster)->memory; FT_FREE( raster ); } FT_DEFINE_RASTER_FUNCS( ft_bitmap_sdf_raster, FT_GLYPH_FORMAT_BITMAP, (FT_Raster_New_Func) bsdf_raster_new, /* raster_new */ (FT_Raster_Reset_Func) bsdf_raster_reset, /* raster_reset */ (FT_Raster_Set_Mode_Func)bsdf_raster_set_mode, /* raster_set_mode */ (FT_Raster_Render_Func) bsdf_raster_render, /* raster_render */ (FT_Raster_Done_Func) bsdf_raster_done /* raster_done */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftbsdf.c
C++
gpl-3.0
38,269
/**************************************************************************** * * ftsdf.c * * Signed Distance Field support for outline fonts (body). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/ftoutln.h> #include <freetype/fttrigon.h> #include <freetype/ftbitmap.h> #include "ftsdf.h" #include "ftsdferrs.h" /************************************************************************** * * A brief technical overview of how the SDF rasterizer works * ---------------------------------------------------------- * * [Notes]: * * SDF stands for Signed Distance Field everywhere. * * * This renderer generates SDF directly from outlines. There is * another renderer called 'bsdf', which converts bitmaps to SDF; see * file `ftbsdf.c` for more. * * * The basic idea of generating the SDF is taken from Viktor Chlumsky's * research paper. The paper explains both single and multi-channel * SDF, however, this implementation only generates single-channel SDF. * * Chlumsky, Viktor: Shape Decomposition for Multi-channel Distance * Fields. Master's thesis. Czech Technical University in Prague, * Faculty of InformationTechnology, 2015. * * For more information: https://github.com/Chlumsky/msdfgen * * ======================================================================== * * Generating SDF from outlines is pretty straightforward. * * (1) We have a set of contours that make the outline of a shape/glyph. * Each contour comprises of several edges, with three types of edges. * * * line segments * * conic Bezier curves * * cubic Bezier curves * * (2) Apart from the outlines we also have a two-dimensional grid, namely * the bitmap that is used to represent the final SDF data. * * (3) In order to generate SDF, our task is to find shortest signed * distance from each grid point to the outline. The 'signed * distance' means that if the grid point is filled by any contour * then its sign is positive, otherwise it is negative. The pseudo * code is as follows. * * ``` * foreach grid_point (x, y): * { * int min_dist = INT_MAX; * * foreach contour in outline: * { * foreach edge in contour: * { * // get shortest distance from point (x, y) to the edge * d = get_min_dist(x, y, edge); * * if (d < min_dist) * min_dist = d; * } * * bitmap[x, y] = min_dist; * } * } * ``` * * (4) After running this algorithm the bitmap contains information about * the shortest distance from each point to the outline of the shape. * Of course, while this is the most straightforward way of generating * SDF, we use various optimizations in our implementation. See the * `sdf_generate_*' functions in this file for all details. * * The optimization currently used by default is subdivision; see * function `sdf_generate_subdivision` for more. * * Also, to see how we compute the shortest distance from a point to * each type of edge, check out the `get_min_distance_*' functions. * */ /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sdf /************************************************************************** * * definitions * */ /* * If set to 1, the rasterizer uses Newton-Raphson's method for finding * the shortest distance from a point to a conic curve. * * If set to 0, an analytical method gets used instead, which computes the * roots of a cubic polynomial to find the shortest distance. However, * the analytical method can currently underflow; we thus use Newton's * method by default. */ #ifndef USE_NEWTON_FOR_CONIC #define USE_NEWTON_FOR_CONIC 1 #endif /* * The number of intervals a Bezier curve gets sampled and checked to find * the shortest distance. */ #define MAX_NEWTON_DIVISIONS 4 /* * The number of steps of Newton's iterations in each interval of the * Bezier curve. Basically, we run Newton's approximation * * x -= Q(t) / Q'(t) * * for each division to get the shortest distance. */ #define MAX_NEWTON_STEPS 4 /* * The epsilon distance (in 16.16 fractional units) used for corner * resolving. If the difference of two distances is less than this value * they will be checked for a corner if they are ambiguous. */ #define CORNER_CHECK_EPSILON 32 #if 0 /* * Coarse grid dimension. Will probably be removed in the future because * coarse grid optimization is the slowest algorithm. */ #define CG_DIMEN 8 #endif /************************************************************************** * * macros * */ #define MUL_26D6( a, b ) ( ( ( a ) * ( b ) ) / 64 ) #define VEC_26D6_DOT( p, q ) ( MUL_26D6( p.x, q.x ) + \ MUL_26D6( p.y, q.y ) ) /************************************************************************** * * structures and enums * */ /************************************************************************** * * @Struct: * SDF_TRaster * * @Description: * This struct is used in place of @FT_Raster and is stored within the * internal FreeType renderer struct. While rasterizing it is passed to * the @FT_Raster_RenderFunc function, which then can be used however we * want. * * @Fields: * memory :: * Used internally to allocate intermediate memory while raterizing. * */ typedef struct SDF_TRaster_ { FT_Memory memory; } SDF_TRaster, *SDF_PRaster; /************************************************************************** * * @Enum: * SDF_Edge_Type * * @Description: * Enumeration of all curve types present in fonts. * * @Fields: * SDF_EDGE_UNDEFINED :: * Undefined edge, simply used to initialize and detect errors. * * SDF_EDGE_LINE :: * Line segment with start and end point. * * SDF_EDGE_CONIC :: * A conic/quadratic Bezier curve with start, end, and one control * point. * * SDF_EDGE_CUBIC :: * A cubic Bezier curve with start, end, and two control points. * */ typedef enum SDF_Edge_Type_ { SDF_EDGE_UNDEFINED = 0, SDF_EDGE_LINE = 1, SDF_EDGE_CONIC = 2, SDF_EDGE_CUBIC = 3 } SDF_Edge_Type; /************************************************************************** * * @Enum: * SDF_Contour_Orientation * * @Description: * Enumeration of all orientation values of a contour. We determine the * orientation by calculating the area covered by a contour. Contrary * to values returned by @FT_Outline_Get_Orientation, * `SDF_Contour_Orientation` is independent of the fill rule, which can * be different for different font formats. * * @Fields: * SDF_ORIENTATION_NONE :: * Undefined orientation, used for initialization and error detection. * * SDF_ORIENTATION_CW :: * Clockwise orientation (positive area covered). * * SDF_ORIENTATION_CCW :: * Counter-clockwise orientation (negative area covered). * * @Note: * See @FT_Outline_Get_Orientation for more details. * */ typedef enum SDF_Contour_Orientation_ { SDF_ORIENTATION_NONE = 0, SDF_ORIENTATION_CW = 1, SDF_ORIENTATION_CCW = 2 } SDF_Contour_Orientation; /************************************************************************** * * @Struct: * SDF_Edge * * @Description: * Represent an edge of a contour. * * @Fields: * start_pos :: * Start position of an edge. Valid for all types of edges. * * end_pos :: * Etart position of an edge. Valid for all types of edges. * * control_a :: * A control point of the edge. Valid only for `SDF_EDGE_CONIC` * and `SDF_EDGE_CUBIC`. * * control_b :: * Another control point of the edge. Valid only for * `SDF_EDGE_CONIC`. * * edge_type :: * Type of the edge, see @SDF_Edge_Type for all possible edge types. * * next :: * Used to create a singly linked list, which can be interpreted * as a contour. * */ typedef struct SDF_Edge_ { FT_26D6_Vec start_pos; FT_26D6_Vec end_pos; FT_26D6_Vec control_a; FT_26D6_Vec control_b; SDF_Edge_Type edge_type; struct SDF_Edge_* next; } SDF_Edge; /************************************************************************** * * @Struct: * SDF_Contour * * @Description: * Represent a complete contour, which contains a list of edges. * * @Fields: * last_pos :: * Contains the value of `end_pos' of the last edge in the list of * edges. Useful while decomposing the outline with * @FT_Outline_Decompose. * * edges :: * Linked list of all the edges that make the contour. * * next :: * Used to create a singly linked list, which can be interpreted as a * complete shape or @FT_Outline. * */ typedef struct SDF_Contour_ { FT_26D6_Vec last_pos; SDF_Edge* edges; struct SDF_Contour_* next; } SDF_Contour; /************************************************************************** * * @Struct: * SDF_Shape * * @Description: * Represent a complete shape, which is the decomposition of * @FT_Outline. * * @Fields: * memory :: * Used internally to allocate memory. * * contours :: * Linked list of all the contours that make the shape. * */ typedef struct SDF_Shape_ { FT_Memory memory; SDF_Contour* contours; } SDF_Shape; /************************************************************************** * * @Struct: * SDF_Signed_Distance * * @Description: * Represent signed distance of a point, i.e., the distance of the edge * nearest to the point. * * @Fields: * distance :: * Distance of the point from the nearest edge. Can be squared or * absolute depending on the `USE_SQUARED_DISTANCES` macro defined in * file `ftsdfcommon.h`. * * cross :: * Cross product of the shortest distance vector (i.e., the vector * from the point to the nearest edge) and the direction of the edge * at the nearest point. This is used to resolve ambiguities of * `sign`. * * sign :: * A value used to indicate whether the distance vector is outside or * inside the contour corresponding to the edge. * * @Note: * `sign` may or may not be correct, therefore it must be checked * properly in case there is an ambiguity. * */ typedef struct SDF_Signed_Distance_ { FT_16D16 distance; FT_16D16 cross; FT_Char sign; } SDF_Signed_Distance; /************************************************************************** * * @Struct: * SDF_Params * * @Description: * Yet another internal parameters required by the rasterizer. * * @Fields: * orientation :: * This is not the @SDF_Contour_Orientation value but @FT_Orientation, * which determines whether clockwise-oriented outlines are to be * filled or counter-clockwise-oriented ones. * * flip_sign :: * If set to true, flip the sign. By default the points filled by the * outline are positive. * * flip_y :: * If set to true the output bitmap is upside-down. Can be useful * because OpenGL and DirectX use different coordinate systems for * textures. * * overload_sign :: * In the subdivision and bounding box optimization, the default * outside sign is taken as -1. This parameter can be used to modify * that behaviour. For example, while generating SDF for a single * counter-clockwise contour, the outside sign should be 1. * */ typedef struct SDF_Params_ { FT_Orientation orientation; FT_Bool flip_sign; FT_Bool flip_y; FT_Int overload_sign; } SDF_Params; /************************************************************************** * * constants, initializer, and destructor * */ static const FT_Vector zero_vector = { 0, 0 }; static const SDF_Edge null_edge = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, SDF_EDGE_UNDEFINED, NULL }; static const SDF_Contour null_contour = { { 0, 0 }, NULL, NULL }; static const SDF_Shape null_shape = { NULL, NULL }; static const SDF_Signed_Distance max_sdf = { INT_MAX, 0, 0 }; /* Create a new @SDF_Edge on the heap and assigns the `edge` */ /* pointer to the newly allocated memory. */ static FT_Error sdf_edge_new( FT_Memory memory, SDF_Edge** edge ) { FT_Error error = FT_Err_Ok; SDF_Edge* ptr = NULL; if ( !memory || !edge ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_QNEW( ptr ) ) { *ptr = null_edge; *edge = ptr; } Exit: return error; } /* Free the allocated `edge` variable. */ static void sdf_edge_done( FT_Memory memory, SDF_Edge** edge ) { if ( !memory || !edge || !*edge ) return; FT_FREE( *edge ); } /* Create a new @SDF_Contour on the heap and assign */ /* the `contour` pointer to the newly allocated memory. */ static FT_Error sdf_contour_new( FT_Memory memory, SDF_Contour** contour ) { FT_Error error = FT_Err_Ok; SDF_Contour* ptr = NULL; if ( !memory || !contour ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_QNEW( ptr ) ) { *ptr = null_contour; *contour = ptr; } Exit: return error; } /* Free the allocated `contour` variable. */ /* Also free the list of edges. */ static void sdf_contour_done( FT_Memory memory, SDF_Contour** contour ) { SDF_Edge* edges; SDF_Edge* temp; if ( !memory || !contour || !*contour ) return; edges = (*contour)->edges; /* release all edges */ while ( edges ) { temp = edges; edges = edges->next; sdf_edge_done( memory, &temp ); } FT_FREE( *contour ); } /* Create a new @SDF_Shape on the heap and assign */ /* the `shape` pointer to the newly allocated memory. */ static FT_Error sdf_shape_new( FT_Memory memory, SDF_Shape** shape ) { FT_Error error = FT_Err_Ok; SDF_Shape* ptr = NULL; if ( !memory || !shape ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_QNEW( ptr ) ) { *ptr = null_shape; ptr->memory = memory; *shape = ptr; } Exit: return error; } /* Free the allocated `shape` variable. */ /* Also free the list of contours. */ static void sdf_shape_done( SDF_Shape** shape ) { FT_Memory memory; SDF_Contour* contours; SDF_Contour* temp; if ( !shape || !*shape ) return; memory = (*shape)->memory; contours = (*shape)->contours; if ( !memory ) return; /* release all contours */ while ( contours ) { temp = contours; contours = contours->next; sdf_contour_done( memory, &temp ); } /* release the allocated shape struct */ FT_FREE( *shape ); } /************************************************************************** * * shape decomposition functions * */ /* This function is called when starting a new contour at `to`, */ /* which gets added to the shape's list. */ static FT_Error sdf_move_to( const FT_26D6_Vec* to, void* user ) { SDF_Shape* shape = ( SDF_Shape* )user; SDF_Contour* contour = NULL; FT_Error error = FT_Err_Ok; FT_Memory memory = shape->memory; if ( !to || !user ) { error = FT_THROW( Invalid_Argument ); goto Exit; } FT_CALL( sdf_contour_new( memory, &contour ) ); contour->last_pos = *to; contour->next = shape->contours; shape->contours = contour; Exit: return error; } /* This function is called when there is a line in the */ /* contour. The line starts at the previous edge point and */ /* stops at `to`. */ static FT_Error sdf_line_to( const FT_26D6_Vec* to, void* user ) { SDF_Shape* shape = ( SDF_Shape* )user; SDF_Edge* edge = NULL; SDF_Contour* contour = NULL; FT_Error error = FT_Err_Ok; FT_Memory memory = shape->memory; if ( !to || !user ) { error = FT_THROW( Invalid_Argument ); goto Exit; } contour = shape->contours; if ( contour->last_pos.x == to->x && contour->last_pos.y == to->y ) goto Exit; FT_CALL( sdf_edge_new( memory, &edge ) ); edge->edge_type = SDF_EDGE_LINE; edge->start_pos = contour->last_pos; edge->end_pos = *to; edge->next = contour->edges; contour->edges = edge; contour->last_pos = *to; Exit: return error; } /* This function is called when there is a conic Bezier curve */ /* in the contour. The curve starts at the previous edge point */ /* and stops at `to`, with control point `control_1`. */ static FT_Error sdf_conic_to( const FT_26D6_Vec* control_1, const FT_26D6_Vec* to, void* user ) { SDF_Shape* shape = ( SDF_Shape* )user; SDF_Edge* edge = NULL; SDF_Contour* contour = NULL; FT_Error error = FT_Err_Ok; FT_Memory memory = shape->memory; if ( !control_1 || !to || !user ) { error = FT_THROW( Invalid_Argument ); goto Exit; } contour = shape->contours; /* If the control point coincides with any of the end points */ /* then it is a line and should be treated as one to avoid */ /* unnecessary complexity later in the algorithm. */ if ( ( contour->last_pos.x == control_1->x && contour->last_pos.y == control_1->y ) || ( control_1->x == to->x && control_1->y == to->y ) ) { sdf_line_to( to, user ); goto Exit; } FT_CALL( sdf_edge_new( memory, &edge ) ); edge->edge_type = SDF_EDGE_CONIC; edge->start_pos = contour->last_pos; edge->control_a = *control_1; edge->end_pos = *to; edge->next = contour->edges; contour->edges = edge; contour->last_pos = *to; Exit: return error; } /* This function is called when there is a cubic Bezier curve */ /* in the contour. The curve starts at the previous edge point */ /* and stops at `to`, with two control points `control_1` and */ /* `control_2`. */ static FT_Error sdf_cubic_to( const FT_26D6_Vec* control_1, const FT_26D6_Vec* control_2, const FT_26D6_Vec* to, void* user ) { SDF_Shape* shape = ( SDF_Shape* )user; SDF_Edge* edge = NULL; SDF_Contour* contour = NULL; FT_Error error = FT_Err_Ok; FT_Memory memory = shape->memory; if ( !control_2 || !control_1 || !to || !user ) { error = FT_THROW( Invalid_Argument ); goto Exit; } contour = shape->contours; FT_CALL( sdf_edge_new( memory, &edge ) ); edge->edge_type = SDF_EDGE_CUBIC; edge->start_pos = contour->last_pos; edge->control_a = *control_1; edge->control_b = *control_2; edge->end_pos = *to; edge->next = contour->edges; contour->edges = edge; contour->last_pos = *to; Exit: return error; } /* Construct the structure to hold all four outline */ /* decomposition functions. */ FT_DEFINE_OUTLINE_FUNCS( sdf_decompose_funcs, (FT_Outline_MoveTo_Func) sdf_move_to, /* move_to */ (FT_Outline_LineTo_Func) sdf_line_to, /* line_to */ (FT_Outline_ConicTo_Func)sdf_conic_to, /* conic_to */ (FT_Outline_CubicTo_Func)sdf_cubic_to, /* cubic_to */ 0, /* shift */ 0 /* delta */ ) /* Decompose `outline` and put it into the `shape` structure. */ static FT_Error sdf_outline_decompose( FT_Outline* outline, SDF_Shape* shape ) { FT_Error error = FT_Err_Ok; if ( !outline || !shape ) { error = FT_THROW( Invalid_Argument ); goto Exit; } error = FT_Outline_Decompose( outline, &sdf_decompose_funcs, (void*)shape ); Exit: return error; } /************************************************************************** * * utility functions * */ /* Return the control box of an edge. The control box is a rectangle */ /* in which all the control points can fit tightly. */ static FT_CBox get_control_box( SDF_Edge edge ) { FT_CBox cbox = { 0, 0, 0, 0 }; FT_Bool is_set = 0; switch ( edge.edge_type ) { case SDF_EDGE_CUBIC: cbox.xMin = edge.control_b.x; cbox.xMax = edge.control_b.x; cbox.yMin = edge.control_b.y; cbox.yMax = edge.control_b.y; is_set = 1; /* fall through */ case SDF_EDGE_CONIC: if ( is_set ) { cbox.xMin = edge.control_a.x < cbox.xMin ? edge.control_a.x : cbox.xMin; cbox.xMax = edge.control_a.x > cbox.xMax ? edge.control_a.x : cbox.xMax; cbox.yMin = edge.control_a.y < cbox.yMin ? edge.control_a.y : cbox.yMin; cbox.yMax = edge.control_a.y > cbox.yMax ? edge.control_a.y : cbox.yMax; } else { cbox.xMin = edge.control_a.x; cbox.xMax = edge.control_a.x; cbox.yMin = edge.control_a.y; cbox.yMax = edge.control_a.y; is_set = 1; } /* fall through */ case SDF_EDGE_LINE: if ( is_set ) { cbox.xMin = edge.start_pos.x < cbox.xMin ? edge.start_pos.x : cbox.xMin; cbox.xMax = edge.start_pos.x > cbox.xMax ? edge.start_pos.x : cbox.xMax; cbox.yMin = edge.start_pos.y < cbox.yMin ? edge.start_pos.y : cbox.yMin; cbox.yMax = edge.start_pos.y > cbox.yMax ? edge.start_pos.y : cbox.yMax; } else { cbox.xMin = edge.start_pos.x; cbox.xMax = edge.start_pos.x; cbox.yMin = edge.start_pos.y; cbox.yMax = edge.start_pos.y; } cbox.xMin = edge.end_pos.x < cbox.xMin ? edge.end_pos.x : cbox.xMin; cbox.xMax = edge.end_pos.x > cbox.xMax ? edge.end_pos.x : cbox.xMax; cbox.yMin = edge.end_pos.y < cbox.yMin ? edge.end_pos.y : cbox.yMin; cbox.yMax = edge.end_pos.y > cbox.yMax ? edge.end_pos.y : cbox.yMax; break; default: break; } return cbox; } /* Return orientation of a single contour. */ /* Note that the orientation is independent of the fill rule! */ /* So, for TTF a clockwise-oriented contour has to be filled */ /* and the opposite for OTF fonts. */ static SDF_Contour_Orientation get_contour_orientation ( SDF_Contour* contour ) { SDF_Edge* head = NULL; FT_26D6 area = 0; /* return none if invalid parameters */ if ( !contour || !contour->edges ) return SDF_ORIENTATION_NONE; head = contour->edges; /* Calculate the area of the control box for all edges. */ while ( head ) { switch ( head->edge_type ) { case SDF_EDGE_LINE: area += MUL_26D6( ( head->end_pos.x - head->start_pos.x ), ( head->end_pos.y + head->start_pos.y ) ); break; case SDF_EDGE_CONIC: area += MUL_26D6( head->control_a.x - head->start_pos.x, head->control_a.y + head->start_pos.y ); area += MUL_26D6( head->end_pos.x - head->control_a.x, head->end_pos.y + head->control_a.y ); break; case SDF_EDGE_CUBIC: area += MUL_26D6( head->control_a.x - head->start_pos.x, head->control_a.y + head->start_pos.y ); area += MUL_26D6( head->control_b.x - head->control_a.x, head->control_b.y + head->control_a.y ); area += MUL_26D6( head->end_pos.x - head->control_b.x, head->end_pos.y + head->control_b.y ); break; default: return SDF_ORIENTATION_NONE; } head = head->next; } /* Clockwise contours cover a positive area, and counter-clockwise */ /* contours cover a negative area. */ if ( area > 0 ) return SDF_ORIENTATION_CW; else return SDF_ORIENTATION_CCW; } /* This function is exactly the same as the one */ /* in the smooth renderer. It splits a conic */ /* into two conics exactly half way at t = 0.5. */ static void split_conic( FT_26D6_Vec* base ) { FT_26D6 a, b; base[4].x = base[2].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; base[3].x = b / 2; base[2].x = ( a + b ) / 4; base[1].x = a / 2; base[4].y = base[2].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; base[3].y = b / 2; base[2].y = ( a + b ) / 4; base[1].y = a / 2; } /* This function is exactly the same as the one */ /* in the smooth renderer. It splits a cubic */ /* into two cubics exactly half way at t = 0.5. */ static void split_cubic( FT_26D6_Vec* base ) { FT_26D6 a, b, c; base[6].x = base[3].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; c = base[2].x + base[3].x; base[5].x = c / 2; c += b; base[4].x = c / 4; base[1].x = a / 2; a += b; base[2].x = a / 4; base[3].x = ( a + c ) / 8; base[6].y = base[3].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; c = base[2].y + base[3].y; base[5].y = c / 2; c += b; base[4].y = c / 4; base[1].y = a / 2; a += b; base[2].y = a / 4; base[3].y = ( a + c ) / 8; } /* Split a conic Bezier curve into a number of lines */ /* and add them to `out'. */ /* */ /* This function uses recursion; we thus need */ /* parameter `max_splits' for stopping. */ static FT_Error split_sdf_conic( FT_Memory memory, FT_26D6_Vec* control_points, FT_UInt max_splits, SDF_Edge** out ) { FT_Error error = FT_Err_Ok; FT_26D6_Vec cpos[5]; SDF_Edge* left,* right; if ( !memory || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* split conic outline */ cpos[0] = control_points[0]; cpos[1] = control_points[1]; cpos[2] = control_points[2]; split_conic( cpos ); /* If max number of splits is done */ /* then stop and add the lines to */ /* the list. */ if ( max_splits <= 2 ) goto Append; /* Otherwise keep splitting. */ FT_CALL( split_sdf_conic( memory, &cpos[0], max_splits / 2, out ) ); FT_CALL( split_sdf_conic( memory, &cpos[2], max_splits / 2, out ) ); /* [NOTE]: This is not an efficient way of */ /* splitting the curve. Check the deviation */ /* instead and stop if the deviation is less */ /* than a pixel. */ goto Exit; Append: /* Do allocation and add the lines to the list. */ FT_CALL( sdf_edge_new( memory, &left ) ); FT_CALL( sdf_edge_new( memory, &right ) ); left->start_pos = cpos[0]; left->end_pos = cpos[2]; left->edge_type = SDF_EDGE_LINE; right->start_pos = cpos[2]; right->end_pos = cpos[4]; right->edge_type = SDF_EDGE_LINE; left->next = right; right->next = (*out); *out = left; Exit: return error; } /* Split a cubic Bezier curve into a number of lines */ /* and add them to `out`. */ /* */ /* This function uses recursion; we thus need */ /* parameter `max_splits' for stopping. */ static FT_Error split_sdf_cubic( FT_Memory memory, FT_26D6_Vec* control_points, FT_UInt max_splits, SDF_Edge** out ) { FT_Error error = FT_Err_Ok; FT_26D6_Vec cpos[7]; SDF_Edge* left, *right; const FT_26D6 threshold = ONE_PIXEL / 4; if ( !memory || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* split the cubic */ cpos[0] = control_points[0]; cpos[1] = control_points[1]; cpos[2] = control_points[2]; cpos[3] = control_points[3]; /* If the segment is flat enough we won't get any benefit by */ /* splitting it further, so we can just stop splitting. */ /* */ /* Check the deviation of the Bezier curve and stop if it is */ /* smaller than the pre-defined `threshold` value. */ if ( FT_ABS( 2 * cpos[0].x - 3 * cpos[1].x + cpos[3].x ) < threshold && FT_ABS( 2 * cpos[0].y - 3 * cpos[1].y + cpos[3].y ) < threshold && FT_ABS( cpos[0].x - 3 * cpos[2].x + 2 * cpos[3].x ) < threshold && FT_ABS( cpos[0].y - 3 * cpos[2].y + 2 * cpos[3].y ) < threshold ) { split_cubic( cpos ); goto Append; } split_cubic( cpos ); /* If max number of splits is done */ /* then stop and add the lines to */ /* the list. */ if ( max_splits <= 2 ) goto Append; /* Otherwise keep splitting. */ FT_CALL( split_sdf_cubic( memory, &cpos[0], max_splits / 2, out ) ); FT_CALL( split_sdf_cubic( memory, &cpos[3], max_splits / 2, out ) ); /* [NOTE]: This is not an efficient way of */ /* splitting the curve. Check the deviation */ /* instead and stop if the deviation is less */ /* than a pixel. */ goto Exit; Append: /* Do allocation and add the lines to the list. */ FT_CALL( sdf_edge_new( memory, &left) ); FT_CALL( sdf_edge_new( memory, &right) ); left->start_pos = cpos[0]; left->end_pos = cpos[3]; left->edge_type = SDF_EDGE_LINE; right->start_pos = cpos[3]; right->end_pos = cpos[6]; right->edge_type = SDF_EDGE_LINE; left->next = right; right->next = (*out); *out = left; Exit: return error; } /* Subdivide an entire shape into line segments */ /* such that it doesn't look visually different */ /* from the original curve. */ static FT_Error split_sdf_shape( SDF_Shape* shape ) { FT_Error error = FT_Err_Ok; FT_Memory memory; SDF_Contour* contours; SDF_Contour* new_contours = NULL; if ( !shape || !shape->memory ) { error = FT_THROW( Invalid_Argument ); goto Exit; } contours = shape->contours; memory = shape->memory; /* for each contour */ while ( contours ) { SDF_Edge* edges = contours->edges; SDF_Edge* new_edges = NULL; SDF_Contour* tempc; /* for each edge */ while ( edges ) { SDF_Edge* edge = edges; SDF_Edge* temp; switch ( edge->edge_type ) { case SDF_EDGE_LINE: /* Just create a duplicate edge in case */ /* it is a line. We can use the same edge. */ FT_CALL( sdf_edge_new( memory, &temp ) ); ft_memcpy( temp, edge, sizeof ( *edge ) ); temp->next = new_edges; new_edges = temp; break; case SDF_EDGE_CONIC: /* Subdivide the curve and add it to the list. */ { FT_26D6_Vec ctrls[3]; FT_26D6 dx, dy; FT_UInt num_splits; ctrls[0] = edge->start_pos; ctrls[1] = edge->control_a; ctrls[2] = edge->end_pos; dx = FT_ABS( ctrls[2].x + ctrls[0].x - 2 * ctrls[1].x ); dy = FT_ABS( ctrls[2].y + ctrls[0].y - 2 * ctrls[1].y ); if ( dx < dy ) dx = dy; /* Calculate the number of necessary bisections. Each */ /* bisection causes a four-fold reduction of the deviation, */ /* hence we bisect the Bezier curve until the deviation */ /* becomes less than 1/8th of a pixel. For more details */ /* check file `ftgrays.c`. */ num_splits = 1; while ( dx > ONE_PIXEL / 8 ) { dx >>= 2; num_splits <<= 1; } error = split_sdf_conic( memory, ctrls, num_splits, &new_edges ); } break; case SDF_EDGE_CUBIC: /* Subdivide the curve and add it to the list. */ { FT_26D6_Vec ctrls[4]; ctrls[0] = edge->start_pos; ctrls[1] = edge->control_a; ctrls[2] = edge->control_b; ctrls[3] = edge->end_pos; error = split_sdf_cubic( memory, ctrls, 32, &new_edges ); } break; default: error = FT_THROW( Invalid_Argument ); } if ( error != FT_Err_Ok ) goto Exit; edges = edges->next; } /* add to the contours list */ FT_CALL( sdf_contour_new( memory, &tempc ) ); tempc->next = new_contours; tempc->edges = new_edges; new_contours = tempc; new_edges = NULL; /* deallocate the contour */ tempc = contours; contours = contours->next; sdf_contour_done( memory, &tempc ); } shape->contours = new_contours; Exit: return error; } /************************************************************************** * * for debugging * */ #ifdef FT_DEBUG_LEVEL_TRACE static void sdf_shape_dump( SDF_Shape* shape ) { FT_UInt num_contours = 0; FT_UInt total_edges = 0; FT_UInt total_lines = 0; FT_UInt total_conic = 0; FT_UInt total_cubic = 0; SDF_Contour* contour_list; if ( !shape ) { FT_TRACE5(( "sdf_shape_dump: null shape\n" )); return; } contour_list = shape->contours; FT_TRACE5(( "sdf_shape_dump (values are in 26.6 format):\n" )); while ( contour_list ) { FT_UInt num_edges = 0; SDF_Edge* edge_list; SDF_Contour* contour = contour_list; FT_TRACE5(( " Contour %d\n", num_contours )); edge_list = contour->edges; while ( edge_list ) { SDF_Edge* edge = edge_list; FT_TRACE5(( " %3d: ", num_edges )); switch ( edge->edge_type ) { case SDF_EDGE_LINE: FT_TRACE5(( "Line: (%ld, %ld) -- (%ld, %ld)\n", edge->start_pos.x, edge->start_pos.y, edge->end_pos.x, edge->end_pos.y )); total_lines++; break; case SDF_EDGE_CONIC: FT_TRACE5(( "Conic: (%ld, %ld) .. (%ld, %ld) .. (%ld, %ld)\n", edge->start_pos.x, edge->start_pos.y, edge->control_a.x, edge->control_a.y, edge->end_pos.x, edge->end_pos.y )); total_conic++; break; case SDF_EDGE_CUBIC: FT_TRACE5(( "Cubic: (%ld, %ld) .. (%ld, %ld)" " .. (%ld, %ld) .. (%ld %ld)\n", edge->start_pos.x, edge->start_pos.y, edge->control_a.x, edge->control_a.y, edge->control_b.x, edge->control_b.y, edge->end_pos.x, edge->end_pos.y )); total_cubic++; break; default: break; } num_edges++; total_edges++; edge_list = edge_list->next; } num_contours++; contour_list = contour_list->next; } FT_TRACE5(( "\n" )); FT_TRACE5(( " total number of contours = %d\n", num_contours )); FT_TRACE5(( " total number of edges = %d\n", total_edges )); FT_TRACE5(( " |__lines = %d\n", total_lines )); FT_TRACE5(( " |__conic = %d\n", total_conic )); FT_TRACE5(( " |__cubic = %d\n", total_cubic )); } #endif /* FT_DEBUG_LEVEL_TRACE */ /************************************************************************** * * math functions * */ #if !USE_NEWTON_FOR_CONIC /* [NOTE]: All the functions below down until rasterizer */ /* can be avoided if we decide to subdivide the */ /* curve into lines. */ /* This function uses Newton's iteration to find */ /* the cube root of a fixed-point integer. */ static FT_16D16 cube_root( FT_16D16 val ) { /* [IMPORTANT]: This function is not good as it may */ /* not break, so use a lookup table instead. Or we */ /* can use an algorithm similar to `square_root`. */ FT_Int v, g, c; if ( val == 0 || val == -FT_INT_16D16( 1 ) || val == FT_INT_16D16( 1 ) ) return val; v = val < 0 ? -val : val; g = square_root( v ); c = 0; while ( 1 ) { c = FT_MulFix( FT_MulFix( g, g ), g ) - v; c = FT_DivFix( c, 3 * FT_MulFix( g, g ) ); g -= c; if ( ( c < 0 ? -c : c ) < 30 ) break; } return val < 0 ? -g : g; } /* Calculate the perpendicular by using '1 - base^2'. */ /* Then use arctan to compute the angle. */ static FT_16D16 arc_cos( FT_16D16 val ) { FT_16D16 p; FT_16D16 b = val; FT_16D16 one = FT_INT_16D16( 1 ); if ( b > one ) b = one; if ( b < -one ) b = -one; p = one - FT_MulFix( b, b ); p = square_root( p ); return FT_Atan2( b, p ); } /* Compute roots of a quadratic polynomial, assign them to `out`, */ /* and return number of real roots. */ /* */ /* The procedure can be found at */ /* */ /* https://mathworld.wolfram.com/QuadraticFormula.html */ static FT_UShort solve_quadratic_equation( FT_26D6 a, FT_26D6 b, FT_26D6 c, FT_16D16 out[2] ) { FT_16D16 discriminant = 0; a = FT_26D6_16D16( a ); b = FT_26D6_16D16( b ); c = FT_26D6_16D16( c ); if ( a == 0 ) { if ( b == 0 ) return 0; else { out[0] = FT_DivFix( -c, b ); return 1; } } discriminant = FT_MulFix( b, b ) - 4 * FT_MulFix( a, c ); if ( discriminant < 0 ) return 0; else if ( discriminant == 0 ) { out[0] = FT_DivFix( -b, 2 * a ); return 1; } else { discriminant = square_root( discriminant ); out[0] = FT_DivFix( -b + discriminant, 2 * a ); out[1] = FT_DivFix( -b - discriminant, 2 * a ); return 2; } } /* Compute roots of a cubic polynomial, assign them to `out`, */ /* and return number of real roots. */ /* */ /* The procedure can be found at */ /* */ /* https://mathworld.wolfram.com/CubicFormula.html */ static FT_UShort solve_cubic_equation( FT_26D6 a, FT_26D6 b, FT_26D6 c, FT_26D6 d, FT_16D16 out[3] ) { FT_16D16 q = 0; /* intermediate */ FT_16D16 r = 0; /* intermediate */ FT_16D16 a2 = b; /* x^2 coefficients */ FT_16D16 a1 = c; /* x coefficients */ FT_16D16 a0 = d; /* constant */ FT_16D16 q3 = 0; FT_16D16 r2 = 0; FT_16D16 a23 = 0; FT_16D16 a22 = 0; FT_16D16 a1x2 = 0; /* cutoff value for `a` to be a cubic, otherwise solve quadratic */ if ( a == 0 || FT_ABS( a ) < 16 ) return solve_quadratic_equation( b, c, d, out ); if ( d == 0 ) { out[0] = 0; return solve_quadratic_equation( a, b, c, out + 1 ) + 1; } /* normalize the coefficients; this also makes them 16.16 */ a2 = FT_DivFix( a2, a ); a1 = FT_DivFix( a1, a ); a0 = FT_DivFix( a0, a ); /* compute intermediates */ a1x2 = FT_MulFix( a1, a2 ); a22 = FT_MulFix( a2, a2 ); a23 = FT_MulFix( a22, a2 ); q = ( 3 * a1 - a22 ) / 9; r = ( 9 * a1x2 - 27 * a0 - 2 * a23 ) / 54; /* [BUG]: `q3` and `r2` still cause underflow. */ q3 = FT_MulFix( q, q ); q3 = FT_MulFix( q3, q ); r2 = FT_MulFix( r, r ); if ( q3 < 0 && r2 < -q3 ) { FT_16D16 t = 0; q3 = square_root( -q3 ); t = FT_DivFix( r, q3 ); if ( t > ( 1 << 16 ) ) t = ( 1 << 16 ); if ( t < -( 1 << 16 ) ) t = -( 1 << 16 ); t = arc_cos( t ); a2 /= 3; q = 2 * square_root( -q ); out[0] = FT_MulFix( q, FT_Cos( t / 3 ) ) - a2; out[1] = FT_MulFix( q, FT_Cos( ( t + FT_ANGLE_PI * 2 ) / 3 ) ) - a2; out[2] = FT_MulFix( q, FT_Cos( ( t + FT_ANGLE_PI * 4 ) / 3 ) ) - a2; return 3; } else if ( r2 == -q3 ) { FT_16D16 s = 0; s = cube_root( r ); a2 /= -3; out[0] = a2 + ( 2 * s ); out[1] = a2 - s; return 2; } else { FT_16D16 s = 0; FT_16D16 t = 0; FT_16D16 dis = 0; if ( q3 == 0 ) dis = FT_ABS( r ); else dis = square_root( q3 + r2 ); s = cube_root( r + dis ); t = cube_root( r - dis ); a2 /= -3; out[0] = ( a2 + ( s + t ) ); return 1; } } #endif /* !USE_NEWTON_FOR_CONIC */ /*************************************************************************/ /*************************************************************************/ /** **/ /** RASTERIZER **/ /** **/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * @Function: * resolve_corner * * @Description: * At some places on the grid two edges can give opposite directions; * this happens when the closest point is on one of the endpoint. In * that case we need to check the proper sign. * * This can be visualized by an example: * * ``` * x * * o * ^ \ * / \ * / \ * (a) / \ (b) * / \ * / \ * / v * ``` * * Suppose `x` is the point whose shortest distance from an arbitrary * contour we want to find out. It is clear that `o` is the nearest * point on the contour. Now to determine the sign we do a cross * product of the shortest distance vector and the edge direction, i.e., * * ``` * => sign = cross(x - o, direction(a)) * ``` * * Using the right hand thumb rule we can see that the sign will be * positive. * * If we use `b', however, we have * * ``` * => sign = cross(x - o, direction(b)) * ``` * * In this case the sign will be negative. To determine the correct * sign we thus divide the plane in two halves and check which plane the * point lies in. * * ``` * | * x | * | * o * ^|\ * / | \ * / | \ * (a) / | \ (b) * / | \ * / \ * / v * ``` * * We can see that `x` lies in the plane of `a`, so we take the sign * determined by `a`. This test can be easily done by calculating the * orthogonality and taking the greater one. * * The orthogonality is simply the sinus of the two vectors (i.e., * x - o) and the corresponding direction. We efficiently pre-compute * the orthogonality with the corresponding `get_min_distance_*` * functions. * * @Input: * sdf1 :: * First signed distance (can be any of `a` or `b`). * * sdf1 :: * Second signed distance (can be any of `a` or `b`). * * @Return: * The correct signed distance, which is computed by using the above * algorithm. * * @Note: * The function does not care about the actual distance, it simply * returns the signed distance which has a larger cross product. As a * consequence, this function should not be used if the two distances * are fairly apart. In that case simply use the signed distance with * a shorter absolute distance. * */ static SDF_Signed_Distance resolve_corner( SDF_Signed_Distance sdf1, SDF_Signed_Distance sdf2 ) { return FT_ABS( sdf1.cross ) > FT_ABS( sdf2.cross ) ? sdf1 : sdf2; } /************************************************************************** * * @Function: * get_min_distance_line * * @Description: * Find the shortest distance from the `line` segment to a given `point` * and assign it to `out`. Use it for line segments only. * * @Input: * line :: * The line segment to which the shortest distance is to be computed. * * point :: * Point from which the shortest distance is to be computed. * * @Output: * out :: * Signed distance from `point` to `line`. * * @Return: * FreeType error, 0 means success. * * @Note: * The `line' parameter must have an edge type of `SDF_EDGE_LINE`. * */ static FT_Error get_min_distance_line( SDF_Edge* line, FT_26D6_Vec point, SDF_Signed_Distance* out ) { /* * In order to calculate the shortest distance from a point to * a line segment, we do the following. Let's assume that * * ``` * a = start point of the line segment * b = end point of the line segment * p = point from which shortest distance is to be calculated * ``` * * (1) Write the parametric equation of the line. * * ``` * point_on_line = a + (b - a) * t (t is the factor) * ``` * * (2) Find the projection of point `p` on the line. The projection * will be perpendicular to the line, which allows us to get the * solution by making the dot product zero. * * ``` * (point_on_line - a) . (p - point_on_line) = 0 * * (point_on_line) * (a) x-------o----------------x (b) * |_| * | * | * (p) * ``` * * (3) Simplification of the above equation yields the factor of * `point_on_line`: * * ``` * t = ((p - a) . (b - a)) / |b - a|^2 * ``` * * (4) We clamp factor `t` between [0.0f, 1.0f] because `point_on_line` * can be outside of the line segment: * * ``` * (point_on_line) * (a) x------------------------x (b) -----o--- * |_| * | * | * (p) * ``` * * (5) Finally, the distance we are interested in is * * ``` * |point_on_line - p| * ``` */ FT_Error error = FT_Err_Ok; FT_Vector a; /* start position */ FT_Vector b; /* end position */ FT_Vector p; /* current point */ FT_26D6_Vec line_segment; /* `b` - `a` */ FT_26D6_Vec p_sub_a; /* `p` - `a` */ FT_26D6 sq_line_length; /* squared length of `line_segment` */ FT_16D16 factor; /* factor of the nearest point */ FT_26D6 cross; /* used to determine sign */ FT_16D16_Vec nearest_point; /* `point_on_line` */ FT_16D16_Vec nearest_vector; /* `p` - `nearest_point` */ if ( !line || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( line->edge_type != SDF_EDGE_LINE ) { error = FT_THROW( Invalid_Argument ); goto Exit; } a = line->start_pos; b = line->end_pos; p = point; line_segment.x = b.x - a.x; line_segment.y = b.y - a.y; p_sub_a.x = p.x - a.x; p_sub_a.y = p.y - a.y; sq_line_length = ( line_segment.x * line_segment.x ) / 64 + ( line_segment.y * line_segment.y ) / 64; /* currently factor is 26.6 */ factor = ( p_sub_a.x * line_segment.x ) / 64 + ( p_sub_a.y * line_segment.y ) / 64; /* now factor is 16.16 */ factor = FT_DivFix( factor, sq_line_length ); /* clamp the factor between 0.0 and 1.0 in fixed point */ if ( factor > FT_INT_16D16( 1 ) ) factor = FT_INT_16D16( 1 ); if ( factor < 0 ) factor = 0; nearest_point.x = FT_MulFix( FT_26D6_16D16( line_segment.x ), factor ); nearest_point.y = FT_MulFix( FT_26D6_16D16( line_segment.y ), factor ); nearest_point.x = FT_26D6_16D16( a.x ) + nearest_point.x; nearest_point.y = FT_26D6_16D16( a.y ) + nearest_point.y; nearest_vector.x = nearest_point.x - FT_26D6_16D16( p.x ); nearest_vector.y = nearest_point.y - FT_26D6_16D16( p.y ); cross = FT_MulFix( nearest_vector.x, line_segment.y ) - FT_MulFix( nearest_vector.y, line_segment.x ); /* assign the output */ out->sign = cross < 0 ? 1 : -1; out->distance = VECTOR_LENGTH_16D16( nearest_vector ); /* Instead of finding `cross` for checking corner we */ /* directly set it here. This is more efficient */ /* because if the distance is perpendicular we can */ /* directly set it to 1. */ if ( factor != 0 && factor != FT_INT_16D16( 1 ) ) out->cross = FT_INT_16D16( 1 ); else { /* [OPTIMIZATION]: Pre-compute this direction. */ /* If not perpendicular then compute `cross`. */ FT_Vector_NormLen( &line_segment ); FT_Vector_NormLen( &nearest_vector ); out->cross = FT_MulFix( line_segment.x, nearest_vector.y ) - FT_MulFix( line_segment.y, nearest_vector.x ); } Exit: return error; } /************************************************************************** * * @Function: * get_min_distance_conic * * @Description: * Find the shortest distance from the `conic` Bezier curve to a given * `point` and assign it to `out`. Use it for conic/quadratic curves * only. * * @Input: * conic :: * The conic Bezier curve to which the shortest distance is to be * computed. * * point :: * Point from which the shortest distance is to be computed. * * @Output: * out :: * Signed distance from `point` to `conic`. * * @Return: * FreeType error, 0 means success. * * @Note: * The `conic` parameter must have an edge type of `SDF_EDGE_CONIC`. * */ #if !USE_NEWTON_FOR_CONIC /* * The function uses an analytical method to find the shortest distance * which is faster than the Newton-Raphson method, but has underflows at * the moment. Use Newton's method if you can see artifacts in the SDF. */ static FT_Error get_min_distance_conic( SDF_Edge* conic, FT_26D6_Vec point, SDF_Signed_Distance* out ) { /* * The procedure to find the shortest distance from a point to a * quadratic Bezier curve is similar to the line segment algorithm. The * shortest distance is perpendicular to the Bezier curve; the only * difference from line is that there can be more than one * perpendicular, and we also have to check the endpoints, because the * perpendicular may not be the shortest. * * Let's assume that * ``` * p0 = first endpoint * p1 = control point * p2 = second endpoint * p = point from which shortest distance is to be calculated * ``` * * (1) The equation of a quadratic Bezier curve can be written as * * ``` * B(t) = (1 - t)^2 * p0 + 2(1 - t)t * p1 + t^2 * p2 * ``` * * with `t` a factor in the range [0.0f, 1.0f]. This equation can * be rewritten as * * ``` * B(t) = t^2 * (p0 - 2p1 + p2) + 2t * (p1 - p0) + p0 * ``` * * With * * ``` * A = p0 - 2p1 + p2 * B = p1 - p0 * ``` * * we have * * ``` * B(t) = t^2 * A + 2t * B + p0 * ``` * * (2) The derivative of the last equation above is * * ``` * B'(t) = 2 *(tA + B) * ``` * * (3) To find the shortest distance from `p` to `B(t)` we find the * point on the curve at which the shortest distance vector (i.e., * `B(t) - p`) and the direction (i.e., `B'(t)`) make 90 degrees. * In other words, we make the dot product zero. * * ``` * (B(t) - p) . (B'(t)) = 0 * (t^2 * A + 2t * B + p0 - p) . (2 * (tA + B)) = 0 * ``` * * After simplifying we get a cubic equation * * ``` * at^3 + bt^2 + ct + d = 0 * ``` * * with * * ``` * a = A.A * b = 3A.B * c = 2B.B + A.p0 - A.p * d = p0.B - p.B * ``` * * (4) Now the roots of the equation can be computed using 'Cardano's * Cubic formula'; we clamp the roots in the range [0.0f, 1.0f]. * * [note]: `B` and `B(t)` are different in the above equations. */ FT_Error error = FT_Err_Ok; FT_26D6_Vec aA, bB; /* A, B in the above comment */ FT_26D6_Vec nearest_point; /* point on curve nearest to `point` */ FT_26D6_Vec direction; /* direction of curve at `nearest_point` */ FT_26D6_Vec p0, p1, p2; /* control points of a conic curve */ FT_26D6_Vec p; /* `point` to which shortest distance */ FT_26D6 a, b, c, d; /* cubic coefficients */ FT_16D16 roots[3] = { 0, 0, 0 }; /* real roots of the cubic eq. */ FT_16D16 min_factor; /* factor at `nearest_point` */ FT_16D16 cross; /* to determine the sign */ FT_16D16 min = FT_INT_MAX; /* shortest squared distance */ FT_UShort num_roots; /* number of real roots of cubic */ FT_UShort i; if ( !conic || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( conic->edge_type != SDF_EDGE_CONIC ) { error = FT_THROW( Invalid_Argument ); goto Exit; } p0 = conic->start_pos; p1 = conic->control_a; p2 = conic->end_pos; p = point; /* compute substitution coefficients */ aA.x = p0.x - 2 * p1.x + p2.x; aA.y = p0.y - 2 * p1.y + p2.y; bB.x = p1.x - p0.x; bB.y = p1.y - p0.y; /* compute cubic coefficients */ a = VEC_26D6_DOT( aA, aA ); b = 3 * VEC_26D6_DOT( aA, bB ); c = 2 * VEC_26D6_DOT( bB, bB ) + VEC_26D6_DOT( aA, p0 ) - VEC_26D6_DOT( aA, p ); d = VEC_26D6_DOT( p0, bB ) - VEC_26D6_DOT( p, bB ); /* find the roots */ num_roots = solve_cubic_equation( a, b, c, d, roots ); if ( num_roots == 0 ) { roots[0] = 0; roots[1] = FT_INT_16D16( 1 ); num_roots = 2; } /* [OPTIMIZATION]: Check the roots, clamp them and discard */ /* duplicate roots. */ /* convert these values to 16.16 for further computation */ aA.x = FT_26D6_16D16( aA.x ); aA.y = FT_26D6_16D16( aA.y ); bB.x = FT_26D6_16D16( bB.x ); bB.y = FT_26D6_16D16( bB.y ); p0.x = FT_26D6_16D16( p0.x ); p0.y = FT_26D6_16D16( p0.y ); p.x = FT_26D6_16D16( p.x ); p.y = FT_26D6_16D16( p.y ); for ( i = 0; i < num_roots; i++ ) { FT_16D16 t = roots[i]; FT_16D16 t2 = 0; FT_16D16 dist = 0; FT_16D16_Vec curve_point; FT_16D16_Vec dist_vector; /* * Ideally we should discard the roots which are outside the range * [0.0, 1.0] and check the endpoints of the Bezier curve, but Behdad * Esfahbod proved the following lemma. * * Lemma: * * (1) If the closest point on the curve [0, 1] is to the endpoint at * `t` = 1 and the cubic has no real roots at `t` = 1 then the * cubic must have a real root at some `t` > 1. * * (2) Similarly, if the closest point on the curve [0, 1] is to the * endpoint at `t` = 0 and the cubic has no real roots at `t` = 0 * then the cubic must have a real root at some `t` < 0. * * Now because of this lemma we only need to clamp the roots and that * will take care of the endpoints. * * For more details see * * https://lists.nongnu.org/archive/html/freetype-devel/2020-06/msg00147.html */ if ( t < 0 ) t = 0; if ( t > FT_INT_16D16( 1 ) ) t = FT_INT_16D16( 1 ); t2 = FT_MulFix( t, t ); /* B(t) = t^2 * A + 2t * B + p0 - p */ curve_point.x = FT_MulFix( aA.x, t2 ) + 2 * FT_MulFix( bB.x, t ) + p0.x; curve_point.y = FT_MulFix( aA.y, t2 ) + 2 * FT_MulFix( bB.y, t ) + p0.y; /* `curve_point` - `p` */ dist_vector.x = curve_point.x - p.x; dist_vector.y = curve_point.y - p.y; dist = VECTOR_LENGTH_16D16( dist_vector ); if ( dist < min ) { min = dist; nearest_point = curve_point; min_factor = t; } } /* B'(t) = 2 * (tA + B) */ direction.x = 2 * FT_MulFix( aA.x, min_factor ) + 2 * bB.x; direction.y = 2 * FT_MulFix( aA.y, min_factor ) + 2 * bB.y; /* determine the sign */ cross = FT_MulFix( nearest_point.x - p.x, direction.y ) - FT_MulFix( nearest_point.y - p.y, direction.x ); /* assign the values */ out->distance = min; out->sign = cross < 0 ? 1 : -1; if ( min_factor != 0 && min_factor != FT_INT_16D16( 1 ) ) out->cross = FT_INT_16D16( 1 ); /* the two are perpendicular */ else { /* convert to nearest vector */ nearest_point.x -= FT_26D6_16D16( p.x ); nearest_point.y -= FT_26D6_16D16( p.y ); /* compute `cross` if not perpendicular */ FT_Vector_NormLen( &direction ); FT_Vector_NormLen( &nearest_point ); out->cross = FT_MulFix( direction.x, nearest_point.y ) - FT_MulFix( direction.y, nearest_point.x ); } Exit: return error; } #else /* USE_NEWTON_FOR_CONIC */ /* * The function uses Newton's approximation to find the shortest distance, * which is a bit slower than the analytical method but doesn't cause * underflow. */ static FT_Error get_min_distance_conic( SDF_Edge* conic, FT_26D6_Vec point, SDF_Signed_Distance* out ) { /* * This method uses Newton-Raphson's approximation to find the shortest * distance from a point to a conic curve. It does not involve solving * any cubic equation, that is why there is no risk of underflow. * * Let's assume that * * ``` * p0 = first endpoint * p1 = control point * p3 = second endpoint * p = point from which shortest distance is to be calculated * ``` * * (1) The equation of a quadratic Bezier curve can be written as * * ``` * B(t) = (1 - t)^2 * p0 + 2(1 - t)t * p1 + t^2 * p2 * ``` * * with `t` the factor in the range [0.0f, 1.0f]. The above * equation can be rewritten as * * ``` * B(t) = t^2 * (p0 - 2p1 + p2) + 2t * (p1 - p0) + p0 * ``` * * With * * ``` * A = p0 - 2p1 + p2 * B = 2 * (p1 - p0) * ``` * * we have * * ``` * B(t) = t^2 * A + t * B + p0 * ``` * * (2) The derivative of the above equation is * * ``` * B'(t) = 2t * A + B * ``` * * (3) The second derivative of the above equation is * * ``` * B''(t) = 2A * ``` * * (4) The equation `P(t)` of the distance from point `p` to the curve * can be written as * * ``` * P(t) = t^2 * A + t^2 * B + p0 - p * ``` * * With * * ``` * C = p0 - p * ``` * * we have * * ``` * P(t) = t^2 * A + t * B + C * ``` * * (5) Finally, the equation of the angle between `B(t)` and `P(t)` can * be written as * * ``` * Q(t) = P(t) . B'(t) * ``` * * (6) Our task is to find a value of `t` such that the above equation * `Q(t)` becomes zero, this is, the point-to-curve vector makes * 90~degrees with the curve. We solve this with the Newton-Raphson * method. * * (7) We first assume an arbitary value of factor `t`, which we then * improve. * * ``` * t := Q(t) / Q'(t) * ``` * * Putting the value of `Q(t)` from the above equation gives * * ``` * t := P(t) . B'(t) / derivative(P(t) . B'(t)) * t := P(t) . B'(t) / * (P'(t) . B'(t) + P(t) . B''(t)) * ``` * * Note that `P'(t)` is the same as `B'(t)` because the constant is * gone due to the derivative. * * (8) Finally we get the equation to improve the factor as * * ``` * t := P(t) . B'(t) / * (B'(t) . B'(t) + P(t) . B''(t)) * ``` * * [note]: `B` and `B(t)` are different in the above equations. */ FT_Error error = FT_Err_Ok; FT_26D6_Vec aA, bB, cC; /* A, B, C in the above comment */ FT_26D6_Vec nearest_point; /* point on curve nearest to `point` */ FT_26D6_Vec direction; /* direction of curve at `nearest_point` */ FT_26D6_Vec p0, p1, p2; /* control points of a conic curve */ FT_26D6_Vec p; /* `point` to which shortest distance */ FT_16D16 min_factor = 0; /* factor at `nearest_point' */ FT_16D16 cross; /* to determine the sign */ FT_16D16 min = FT_INT_MAX; /* shortest squared distance */ FT_UShort iterations; FT_UShort steps; if ( !conic || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( conic->edge_type != SDF_EDGE_CONIC ) { error = FT_THROW( Invalid_Argument ); goto Exit; } p0 = conic->start_pos; p1 = conic->control_a; p2 = conic->end_pos; p = point; /* compute substitution coefficients */ aA.x = p0.x - 2 * p1.x + p2.x; aA.y = p0.y - 2 * p1.y + p2.y; bB.x = 2 * ( p1.x - p0.x ); bB.y = 2 * ( p1.y - p0.y ); cC.x = p0.x; cC.y = p0.y; /* do Newton's iterations */ for ( iterations = 0; iterations <= MAX_NEWTON_DIVISIONS; iterations++ ) { FT_16D16 factor = FT_INT_16D16( iterations ) / MAX_NEWTON_DIVISIONS; FT_16D16 factor2; FT_16D16 length; FT_16D16_Vec curve_point; /* point on the curve */ FT_16D16_Vec dist_vector; /* `curve_point` - `p` */ FT_26D6_Vec d1; /* first derivative */ FT_26D6_Vec d2; /* second derivative */ FT_16D16 temp1; FT_16D16 temp2; for ( steps = 0; steps < MAX_NEWTON_STEPS; steps++ ) { factor2 = FT_MulFix( factor, factor ); /* B(t) = t^2 * A + t * B + p0 */ curve_point.x = FT_MulFix( aA.x, factor2 ) + FT_MulFix( bB.x, factor ) + cC.x; curve_point.y = FT_MulFix( aA.y, factor2 ) + FT_MulFix( bB.y, factor ) + cC.y; /* convert to 16.16 */ curve_point.x = FT_26D6_16D16( curve_point.x ); curve_point.y = FT_26D6_16D16( curve_point.y ); /* P(t) in the comment */ dist_vector.x = curve_point.x - FT_26D6_16D16( p.x ); dist_vector.y = curve_point.y - FT_26D6_16D16( p.y ); length = VECTOR_LENGTH_16D16( dist_vector ); if ( length < min ) { min = length; min_factor = factor; nearest_point = curve_point; } /* This is Newton's approximation. */ /* */ /* t := P(t) . B'(t) / */ /* (B'(t) . B'(t) + P(t) . B''(t)) */ /* B'(t) = 2tA + B */ d1.x = FT_MulFix( aA.x, 2 * factor ) + bB.x; d1.y = FT_MulFix( aA.y, 2 * factor ) + bB.y; /* B''(t) = 2A */ d2.x = 2 * aA.x; d2.y = 2 * aA.y; dist_vector.x /= 1024; dist_vector.y /= 1024; /* temp1 = P(t) . B'(t) */ temp1 = VEC_26D6_DOT( dist_vector, d1 ); /* temp2 = B'(t) . B'(t) + P(t) . B''(t) */ temp2 = VEC_26D6_DOT( d1, d1 ) + VEC_26D6_DOT( dist_vector, d2 ); factor -= FT_DivFix( temp1, temp2 ); if ( factor < 0 || factor > FT_INT_16D16( 1 ) ) break; } } /* B'(t) = 2t * A + B */ direction.x = 2 * FT_MulFix( aA.x, min_factor ) + bB.x; direction.y = 2 * FT_MulFix( aA.y, min_factor ) + bB.y; /* determine the sign */ cross = FT_MulFix( nearest_point.x - FT_26D6_16D16( p.x ), direction.y ) - FT_MulFix( nearest_point.y - FT_26D6_16D16( p.y ), direction.x ); /* assign the values */ out->distance = min; out->sign = cross < 0 ? 1 : -1; if ( min_factor != 0 && min_factor != FT_INT_16D16( 1 ) ) out->cross = FT_INT_16D16( 1 ); /* the two are perpendicular */ else { /* convert to nearest vector */ nearest_point.x -= FT_26D6_16D16( p.x ); nearest_point.y -= FT_26D6_16D16( p.y ); /* compute `cross` if not perpendicular */ FT_Vector_NormLen( &direction ); FT_Vector_NormLen( &nearest_point ); out->cross = FT_MulFix( direction.x, nearest_point.y ) - FT_MulFix( direction.y, nearest_point.x ); } Exit: return error; } #endif /* USE_NEWTON_FOR_CONIC */ /************************************************************************** * * @Function: * get_min_distance_cubic * * @Description: * Find the shortest distance from the `cubic` Bezier curve to a given * `point` and assigns it to `out`. Use it for cubic curves only. * * @Input: * cubic :: * The cubic Bezier curve to which the shortest distance is to be * computed. * * point :: * Point from which the shortest distance is to be computed. * * @Output: * out :: * Signed distance from `point` to `cubic`. * * @Return: * FreeType error, 0 means success. * * @Note: * The function uses Newton's approximation to find the shortest * distance. Another way would be to divide the cubic into conic or * subdivide the curve into lines, but that is not implemented. * * The `cubic` parameter must have an edge type of `SDF_EDGE_CUBIC`. * */ static FT_Error get_min_distance_cubic( SDF_Edge* cubic, FT_26D6_Vec point, SDF_Signed_Distance* out ) { /* * The procedure to find the shortest distance from a point to a cubic * Bezier curve is similar to quadratic curve algorithm. The only * difference is that while calculating factor `t`, instead of a cubic * polynomial equation we have to find the roots of a 5th degree * polynomial equation. Solving this would require a significant amount * of time, and still the results may not be accurate. We are thus * going to directly approximate the value of `t` using the Newton-Raphson * method. * * Let's assume that * * ``` * p0 = first endpoint * p1 = first control point * p2 = second control point * p3 = second endpoint * p = point from which shortest distance is to be calculated * ``` * * (1) The equation of a cubic Bezier curve can be written as * * ``` * B(t) = (1 - t)^3 * p0 + 3(1 - t)^2 t * p1 + * 3(1 - t)t^2 * p2 + t^3 * p3 * ``` * * The equation can be expanded and written as * * ``` * B(t) = t^3 * (-p0 + 3p1 - 3p2 + p3) + * 3t^2 * (p0 - 2p1 + p2) + 3t * (-p0 + p1) + p0 * ``` * * With * * ``` * A = -p0 + 3p1 - 3p2 + p3 * B = 3(p0 - 2p1 + p2) * C = 3(-p0 + p1) * ``` * * we have * * ``` * B(t) = t^3 * A + t^2 * B + t * C + p0 * ``` * * (2) The derivative of the above equation is * * ``` * B'(t) = 3t^2 * A + 2t * B + C * ``` * * (3) The second derivative of the above equation is * * ``` * B''(t) = 6t * A + 2B * ``` * * (4) The equation `P(t)` of the distance from point `p` to the curve * can be written as * * ``` * P(t) = t^3 * A + t^2 * B + t * C + p0 - p * ``` * * With * * ``` * D = p0 - p * ``` * * we have * * ``` * P(t) = t^3 * A + t^2 * B + t * C + D * ``` * * (5) Finally the equation of the angle between `B(t)` and `P(t)` can * be written as * * ``` * Q(t) = P(t) . B'(t) * ``` * * (6) Our task is to find a value of `t` such that the above equation * `Q(t)` becomes zero, this is, the point-to-curve vector makes * 90~degree with curve. We solve this with the Newton-Raphson * method. * * (7) We first assume an arbitary value of factor `t`, which we then * improve. * * ``` * t := Q(t) / Q'(t) * ``` * * Putting the value of `Q(t)` from the above equation gives * * ``` * t := P(t) . B'(t) / derivative(P(t) . B'(t)) * t := P(t) . B'(t) / * (P'(t) . B'(t) + P(t) . B''(t)) * ``` * * Note that `P'(t)` is the same as `B'(t)` because the constant is * gone due to the derivative. * * (8) Finally we get the equation to improve the factor as * * ``` * t := P(t) . B'(t) / * (B'(t) . B'( t ) + P(t) . B''(t)) * ``` * * [note]: `B` and `B(t)` are different in the above equations. */ FT_Error error = FT_Err_Ok; FT_26D6_Vec aA, bB, cC, dD; /* A, B, C in the above comment */ FT_16D16_Vec nearest_point; /* point on curve nearest to `point` */ FT_16D16_Vec direction; /* direction of curve at `nearest_point` */ FT_26D6_Vec p0, p1, p2, p3; /* control points of a cubic curve */ FT_26D6_Vec p; /* `point` to which shortest distance */ FT_16D16 min_factor = 0; /* factor at shortest distance */ FT_16D16 min_factor_sq = 0; /* factor at shortest distance */ FT_16D16 cross; /* to determine the sign */ FT_16D16 min = FT_INT_MAX; /* shortest distance */ FT_UShort iterations; FT_UShort steps; if ( !cubic || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( cubic->edge_type != SDF_EDGE_CUBIC ) { error = FT_THROW( Invalid_Argument ); goto Exit; } p0 = cubic->start_pos; p1 = cubic->control_a; p2 = cubic->control_b; p3 = cubic->end_pos; p = point; /* compute substitution coefficients */ aA.x = -p0.x + 3 * ( p1.x - p2.x ) + p3.x; aA.y = -p0.y + 3 * ( p1.y - p2.y ) + p3.y; bB.x = 3 * ( p0.x - 2 * p1.x + p2.x ); bB.y = 3 * ( p0.y - 2 * p1.y + p2.y ); cC.x = 3 * ( p1.x - p0.x ); cC.y = 3 * ( p1.y - p0.y ); dD.x = p0.x; dD.y = p0.y; for ( iterations = 0; iterations <= MAX_NEWTON_DIVISIONS; iterations++ ) { FT_16D16 factor = FT_INT_16D16( iterations ) / MAX_NEWTON_DIVISIONS; FT_16D16 factor2; /* factor^2 */ FT_16D16 factor3; /* factor^3 */ FT_16D16 length; FT_16D16_Vec curve_point; /* point on the curve */ FT_16D16_Vec dist_vector; /* `curve_point' - `p' */ FT_26D6_Vec d1; /* first derivative */ FT_26D6_Vec d2; /* second derivative */ FT_16D16 temp1; FT_16D16 temp2; for ( steps = 0; steps < MAX_NEWTON_STEPS; steps++ ) { factor2 = FT_MulFix( factor, factor ); factor3 = FT_MulFix( factor2, factor ); /* B(t) = t^3 * A + t^2 * B + t * C + D */ curve_point.x = FT_MulFix( aA.x, factor3 ) + FT_MulFix( bB.x, factor2 ) + FT_MulFix( cC.x, factor ) + dD.x; curve_point.y = FT_MulFix( aA.y, factor3 ) + FT_MulFix( bB.y, factor2 ) + FT_MulFix( cC.y, factor ) + dD.y; /* convert to 16.16 */ curve_point.x = FT_26D6_16D16( curve_point.x ); curve_point.y = FT_26D6_16D16( curve_point.y ); /* P(t) in the comment */ dist_vector.x = curve_point.x - FT_26D6_16D16( p.x ); dist_vector.y = curve_point.y - FT_26D6_16D16( p.y ); length = VECTOR_LENGTH_16D16( dist_vector ); if ( length < min ) { min = length; min_factor = factor; min_factor_sq = factor2; nearest_point = curve_point; } /* This the Newton's approximation. */ /* */ /* t := P(t) . B'(t) / */ /* (B'(t) . B'(t) + P(t) . B''(t)) */ /* B'(t) = 3t^2 * A + 2t * B + C */ d1.x = FT_MulFix( aA.x, 3 * factor2 ) + FT_MulFix( bB.x, 2 * factor ) + cC.x; d1.y = FT_MulFix( aA.y, 3 * factor2 ) + FT_MulFix( bB.y, 2 * factor ) + cC.y; /* B''(t) = 6t * A + 2B */ d2.x = FT_MulFix( aA.x, 6 * factor ) + 2 * bB.x; d2.y = FT_MulFix( aA.y, 6 * factor ) + 2 * bB.y; dist_vector.x /= 1024; dist_vector.y /= 1024; /* temp1 = P(t) . B'(t) */ temp1 = VEC_26D6_DOT( dist_vector, d1 ); /* temp2 = B'(t) . B'(t) + P(t) . B''(t) */ temp2 = VEC_26D6_DOT( d1, d1 ) + VEC_26D6_DOT( dist_vector, d2 ); factor -= FT_DivFix( temp1, temp2 ); if ( factor < 0 || factor > FT_INT_16D16( 1 ) ) break; } } /* B'(t) = 3t^2 * A + 2t * B + C */ direction.x = FT_MulFix( aA.x, 3 * min_factor_sq ) + FT_MulFix( bB.x, 2 * min_factor ) + cC.x; direction.y = FT_MulFix( aA.y, 3 * min_factor_sq ) + FT_MulFix( bB.y, 2 * min_factor ) + cC.y; /* determine the sign */ cross = FT_MulFix( nearest_point.x - FT_26D6_16D16( p.x ), direction.y ) - FT_MulFix( nearest_point.y - FT_26D6_16D16( p.y ), direction.x ); /* assign the values */ out->distance = min; out->sign = cross < 0 ? 1 : -1; if ( min_factor != 0 && min_factor != FT_INT_16D16( 1 ) ) out->cross = FT_INT_16D16( 1 ); /* the two are perpendicular */ else { /* convert to nearest vector */ nearest_point.x -= FT_26D6_16D16( p.x ); nearest_point.y -= FT_26D6_16D16( p.y ); /* compute `cross` if not perpendicular */ FT_Vector_NormLen( &direction ); FT_Vector_NormLen( &nearest_point ); out->cross = FT_MulFix( direction.x, nearest_point.y ) - FT_MulFix( direction.y, nearest_point.x ); } Exit: return error; } /************************************************************************** * * @Function: * sdf_edge_get_min_distance * * @Description: * Find shortest distance from `point` to any type of `edge`. It checks * the edge type and then calls the relevant `get_min_distance_*` * function. * * @Input: * edge :: * An edge to which the shortest distance is to be computed. * * point :: * Point from which the shortest distance is to be computed. * * @Output: * out :: * Signed distance from `point` to `edge`. * * @Return: * FreeType error, 0 means success. * */ static FT_Error sdf_edge_get_min_distance( SDF_Edge* edge, FT_26D6_Vec point, SDF_Signed_Distance* out ) { FT_Error error = FT_Err_Ok; if ( !edge || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* edge-specific distance calculation */ switch ( edge->edge_type ) { case SDF_EDGE_LINE: get_min_distance_line( edge, point, out ); break; case SDF_EDGE_CONIC: get_min_distance_conic( edge, point, out ); break; case SDF_EDGE_CUBIC: get_min_distance_cubic( edge, point, out ); break; default: error = FT_THROW( Invalid_Argument ); } Exit: return error; } /* `sdf_generate' is not used at the moment */ #if 0 #error "DO NOT USE THIS!" #error "The function still outputs 16-bit data, which might cause memory" #error "corruption. If required I will add this later." /************************************************************************** * * @Function: * sdf_contour_get_min_distance * * @Description: * Iterate over all edges that make up the contour, find the shortest * distance from a point to this contour, and assigns result to `out`. * * @Input: * contour :: * A contour to which the shortest distance is to be computed. * * point :: * Point from which the shortest distance is to be computed. * * @Output: * out :: * Signed distance from the `point' to the `contour'. * * @Return: * FreeType error, 0 means success. * * @Note: * The function does not return a signed distance for each edge which * makes up the contour, it simply returns the shortest of all the * edges. * */ static FT_Error sdf_contour_get_min_distance( SDF_Contour* contour, FT_26D6_Vec point, SDF_Signed_Distance* out ) { FT_Error error = FT_Err_Ok; SDF_Signed_Distance min_dist = max_sdf; SDF_Edge* edge_list; if ( !contour || !out ) { error = FT_THROW( Invalid_Argument ); goto Exit; } edge_list = contour->edges; /* iterate over all the edges manually */ while ( edge_list ) { SDF_Signed_Distance current_dist = max_sdf; FT_16D16 diff; FT_CALL( sdf_edge_get_min_distance( edge_list, point, &current_dist ) ); if ( current_dist.distance >= 0 ) { diff = current_dist.distance - min_dist.distance; if ( FT_ABS(diff ) < CORNER_CHECK_EPSILON ) min_dist = resolve_corner( min_dist, current_dist ); else if ( diff < 0 ) min_dist = current_dist; } else FT_TRACE0(( "sdf_contour_get_min_distance: Overflow.\n" )); edge_list = edge_list->next; } *out = min_dist; Exit: return error; } /************************************************************************** * * @Function: * sdf_generate * * @Description: * This is the main function that is responsible for generating signed * distance fields. The function does not align or compute the size of * `bitmap`; therefore the calling application must set up `bitmap` * properly and transform the `shape' appropriately in advance. * * Currently we check all pixels against all contours and all edges. * * @Input: * internal_params :: * Internal parameters and properties required by the rasterizer. See * @SDF_Params for more. * * shape :: * A complete shape which is used to generate SDF. * * spread :: * Maximum distances to be allowed in the output bitmap. * * @Output: * bitmap :: * The output bitmap which will contain the SDF information. * * @Return: * FreeType error, 0 means success. * */ static FT_Error sdf_generate( const SDF_Params internal_params, const SDF_Shape* shape, FT_UInt spread, const FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_UInt width = 0; FT_UInt rows = 0; FT_UInt x = 0; /* used to loop in x direction, i.e., width */ FT_UInt y = 0; /* used to loop in y direction, i.e., rows */ FT_UInt sp_sq = 0; /* `spread` [* `spread`] as a 16.16 fixed value */ FT_Short* buffer; if ( !shape || !bitmap ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( spread < MIN_SPREAD || spread > MAX_SPREAD ) { error = FT_THROW( Invalid_Argument ); goto Exit; } width = bitmap->width; rows = bitmap->rows; buffer = (FT_Short*)bitmap->buffer; if ( USE_SQUARED_DISTANCES ) sp_sq = FT_INT_16D16( spread * spread ); else sp_sq = FT_INT_16D16( spread ); if ( width == 0 || rows == 0 ) { FT_TRACE0(( "sdf_generate:" " Cannot render glyph with width/height == 0\n" )); FT_TRACE0(( " " " (width, height provided [%d, %d])\n", width, rows )); error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } /* loop over all rows */ for ( y = 0; y < rows; y++ ) { /* loop over all pixels of a row */ for ( x = 0; x < width; x++ ) { /* `grid_point` is the current pixel position; */ /* our task is to find the shortest distance */ /* from this point to the entire shape. */ FT_26D6_Vec grid_point = zero_vector; SDF_Signed_Distance min_dist = max_sdf; SDF_Contour* contour_list; FT_UInt index; FT_Short value; grid_point.x = FT_INT_26D6( x ); grid_point.y = FT_INT_26D6( y ); /* This `grid_point' is at the corner, but we */ /* use the center of the pixel. */ grid_point.x += FT_INT_26D6( 1 ) / 2; grid_point.y += FT_INT_26D6( 1 ) / 2; contour_list = shape->contours; /* iterate over all contours manually */ while ( contour_list ) { SDF_Signed_Distance current_dist = max_sdf; FT_CALL( sdf_contour_get_min_distance( contour_list, grid_point, &current_dist ) ); if ( current_dist.distance < min_dist.distance ) min_dist = current_dist; contour_list = contour_list->next; } /* [OPTIMIZATION]: if (min_dist > sp_sq) then simply clamp */ /* the value to spread to avoid square_root */ /* clamp the values to spread */ if ( min_dist.distance > sp_sq ) min_dist.distance = sp_sq; /* square_root the values and fit in a 6.10 fixed point */ if ( USE_SQUARED_DISTANCES ) min_dist.distance = square_root( min_dist.distance ); if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) min_dist.sign = -min_dist.sign; if ( internal_params.flip_sign ) min_dist.sign = -min_dist.sign; min_dist.distance /= 64; /* convert from 16.16 to 22.10 */ value = min_dist.distance & 0x0000FFFF; /* truncate to 6.10 */ value *= min_dist.sign; if ( internal_params.flip_y ) index = y * width + x; else index = ( rows - y - 1 ) * width + x; buffer[index] = value; } } Exit: return error; } #endif /* 0 */ /************************************************************************** * * @Function: * sdf_generate_bounding_box * * @Description: * This function does basically the same thing as `sdf_generate` above * but more efficiently. * * Instead of checking all pixels against all edges, we loop over all * edges and only check pixels around the control box of the edge; the * control box is increased by the spread in all directions. Anything * outside of the control box that exceeds `spread` doesn't need to be * computed. * * Lastly, to determine the sign of unchecked pixels, we do a single * pass of all rows starting with a '+' sign and flipping when we come * across a '-' sign and continue. This also eliminates the possibility * of overflow because we only check the proximity of the curve. * Therefore we can use squared distanced safely. * * @Input: * internal_params :: * Internal parameters and properties required by the rasterizer. * See @SDF_Params for more. * * shape :: * A complete shape which is used to generate SDF. * * spread :: * Maximum distances to be allowed in the output bitmap. * * @Output: * bitmap :: * The output bitmap which will contain the SDF information. * * @Return: * FreeType error, 0 means success. * */ static FT_Error sdf_generate_bounding_box( const SDF_Params internal_params, const SDF_Shape* shape, FT_UInt spread, const FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Memory memory = NULL; FT_Int width, rows, i, j; FT_Int sp_sq; /* max value to check */ SDF_Contour* contours; /* list of all contours */ FT_SDFFormat* buffer; /* the bitmap buffer */ /* This buffer has the same size in indices as the */ /* bitmap buffer. When we check a pixel position for */ /* a shortest distance we keep it in this buffer. */ /* This way we can find out which pixel is set, */ /* and also determine the signs properly. */ SDF_Signed_Distance* dists = NULL; const FT_16D16 fixed_spread = FT_INT_16D16( spread ); if ( !shape || !bitmap ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( spread < MIN_SPREAD || spread > MAX_SPREAD ) { error = FT_THROW( Invalid_Argument ); goto Exit; } memory = shape->memory; if ( !memory ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( FT_ALLOC( dists, bitmap->width * bitmap->rows * sizeof ( *dists ) ) ) goto Exit; contours = shape->contours; width = (FT_Int)bitmap->width; rows = (FT_Int)bitmap->rows; buffer = (FT_SDFFormat*)bitmap->buffer; if ( USE_SQUARED_DISTANCES ) sp_sq = FT_INT_16D16( (FT_Int)( spread * spread ) ); else sp_sq = fixed_spread; if ( width == 0 || rows == 0 ) { FT_TRACE0(( "sdf_generate:" " Cannot render glyph with width/height == 0\n" )); FT_TRACE0(( " " " (width, height provided [%d, %d])", width, rows )); error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } /* loop over all contours */ while ( contours ) { SDF_Edge* edges = contours->edges; /* loop over all edges */ while ( edges ) { FT_CBox cbox; FT_Int x, y; /* get the control box and increase it by `spread' */ cbox = get_control_box( *edges ); cbox.xMin = ( cbox.xMin - 63 ) / 64 - ( FT_Pos )spread; cbox.xMax = ( cbox.xMax + 63 ) / 64 + ( FT_Pos )spread; cbox.yMin = ( cbox.yMin - 63 ) / 64 - ( FT_Pos )spread; cbox.yMax = ( cbox.yMax + 63 ) / 64 + ( FT_Pos )spread; /* now loop over the pixels in the control box. */ for ( y = cbox.yMin; y < cbox.yMax; y++ ) { for ( x = cbox.xMin; x < cbox.xMax; x++ ) { FT_26D6_Vec grid_point = zero_vector; SDF_Signed_Distance dist = max_sdf; FT_UInt index = 0; FT_16D16 diff = 0; if ( x < 0 || x >= width ) continue; if ( y < 0 || y >= rows ) continue; grid_point.x = FT_INT_26D6( x ); grid_point.y = FT_INT_26D6( y ); /* This `grid_point` is at the corner, but we */ /* use the center of the pixel. */ grid_point.x += FT_INT_26D6( 1 ) / 2; grid_point.y += FT_INT_26D6( 1 ) / 2; FT_CALL( sdf_edge_get_min_distance( edges, grid_point, &dist ) ); if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) dist.sign = -dist.sign; /* ignore if the distance is greater than spread; */ /* otherwise it creates artifacts due to the wrong sign */ if ( dist.distance > sp_sq ) continue; /* take the square root of the distance if required */ if ( USE_SQUARED_DISTANCES ) dist.distance = square_root( dist.distance ); if ( internal_params.flip_y ) index = (FT_UInt)( y * width + x ); else index = (FT_UInt)( ( rows - y - 1 ) * width + x ); /* check whether the pixel is set or not */ if ( dists[index].sign == 0 ) dists[index] = dist; else { diff = FT_ABS( dists[index].distance - dist.distance ); if ( diff <= CORNER_CHECK_EPSILON ) dists[index] = resolve_corner( dists[index], dist ); else if ( dists[index].distance > dist.distance ) dists[index] = dist; } } } edges = edges->next; } contours = contours->next; } /* final pass */ for ( j = 0; j < rows; j++ ) { /* We assume the starting pixel of each row is outside. */ FT_Char current_sign = -1; FT_UInt index; if ( internal_params.overload_sign != 0 ) current_sign = internal_params.overload_sign < 0 ? -1 : 1; for ( i = 0; i < width; i++ ) { index = (FT_UInt)( j * width + i ); /* if the pixel is not set */ /* its shortest distance is more than `spread` */ if ( dists[index].sign == 0 ) dists[index].distance = fixed_spread; else current_sign = dists[index].sign; /* clamp the values */ if ( dists[index].distance > fixed_spread ) dists[index].distance = fixed_spread; /* flip sign if required */ dists[index].distance *= internal_params.flip_sign ? -current_sign : current_sign; /* concatenate to appropriate format */ buffer[index] = map_fixed_to_sdf( dists[index].distance, fixed_spread ); } } Exit: FT_FREE( dists ); return error; } /************************************************************************** * * @Function: * sdf_generate_subdivision * * @Description: * Subdivide the shape into a number of straight lines, then use the * above `sdf_generate_bounding_box` function to generate the SDF. * * Note: After calling this function `shape` no longer has the original * edges, it only contains lines. * * @Input: * internal_params :: * Internal parameters and properties required by the rasterizer. * See @SDF_Params for more. * * shape :: * A complete shape which is used to generate SDF. * * spread :: * Maximum distances to be allowed inthe output bitmap. * * @Output: * bitmap :: * The output bitmap which will contain the SDF information. * * @Return: * FreeType error, 0 means success. * */ static FT_Error sdf_generate_subdivision( const SDF_Params internal_params, SDF_Shape* shape, FT_UInt spread, const FT_Bitmap* bitmap ) { /* * Thanks to Alexei for providing the idea of this optimization. * * We take advantage of two facts. * * (1) Computing the shortest distance from a point to a line segment is * very fast. * (2) We don't have to compute the shortest distance for the entire * two-dimensional grid. * * Both ideas lead to the following optimization. * * (1) Split the outlines into a number of line segments. * * (2) For each line segment, only process its neighborhood. * * (3) Compute the closest distance to the line only for neighborhood * grid points. * * This greatly reduces the number of grid points to check. */ FT_Error error = FT_Err_Ok; FT_CALL( split_sdf_shape( shape ) ); FT_CALL( sdf_generate_bounding_box( internal_params, shape, spread, bitmap ) ); Exit: return error; } /************************************************************************** * * @Function: * sdf_generate_with_overlaps * * @Description: * This function can be used to generate SDF for glyphs with overlapping * contours. The function generates SDF for contours separately on * separate bitmaps (to generate SDF it uses * `sdf_generate_subdivision`). At the end it simply combines all the * SDF into the output bitmap; this fixes all the signs and removes * overlaps. * * @Input: * internal_params :: * Internal parameters and properties required by the rasterizer. See * @SDF_Params for more. * * shape :: * A complete shape which is used to generate SDF. * * spread :: * Maximum distances to be allowed in the output bitmap. * * @Output: * bitmap :: * The output bitmap which will contain the SDF information. * * @Return: * FreeType error, 0 means success. * * @Note: * The function cannot generate a proper SDF for glyphs with * self-intersecting contours because we cannot separate them into two * separate bitmaps. In case of self-intersecting contours it is * necessary to remove the overlaps before generating the SDF. * */ static FT_Error sdf_generate_with_overlaps( SDF_Params internal_params, SDF_Shape* shape, FT_UInt spread, const FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Int num_contours; /* total number of contours */ FT_Int i, j; /* iterators */ FT_Int width, rows; /* width and rows of the bitmap */ FT_Bitmap* bitmaps; /* separate bitmaps for contours */ SDF_Contour* contour; /* temporary variable to iterate */ SDF_Contour* temp_contour; /* temporary contour */ SDF_Contour* head; /* head of the contour list */ SDF_Shape temp_shape; /* temporary shape */ FT_Memory memory; /* to allocate memory */ FT_SDFFormat* t; /* target bitmap buffer */ FT_Bool flip_sign; /* flip sign? */ /* orientation of all the separate contours */ SDF_Contour_Orientation* orientations; bitmaps = NULL; orientations = NULL; head = NULL; if ( !shape || !bitmap || !shape->memory ) return FT_THROW( Invalid_Argument ); /* Disable `flip_sign` to avoid extra complication */ /* during the combination phase. */ flip_sign = internal_params.flip_sign; internal_params.flip_sign = 0; contour = shape->contours; memory = shape->memory; temp_shape.memory = memory; width = (FT_Int)bitmap->width; rows = (FT_Int)bitmap->rows; num_contours = 0; /* find the number of contours in the shape */ while ( contour ) { num_contours++; contour = contour->next; } /* allocate the bitmaps to generate SDF for separate contours */ if ( FT_ALLOC( bitmaps, (FT_UInt)num_contours * sizeof ( *bitmaps ) ) ) goto Exit; /* allocate array to hold orientation for all contours */ if ( FT_ALLOC( orientations, (FT_UInt)num_contours * sizeof ( *orientations ) ) ) goto Exit; contour = shape->contours; /* Iterate over all contours and generate SDF separately. */ for ( i = 0; i < num_contours; i++ ) { /* initialize the corresponding bitmap */ FT_Bitmap_Init( &bitmaps[i] ); bitmaps[i].width = bitmap->width; bitmaps[i].rows = bitmap->rows; bitmaps[i].pitch = bitmap->pitch; bitmaps[i].num_grays = bitmap->num_grays; bitmaps[i].pixel_mode = bitmap->pixel_mode; /* allocate memory for the buffer */ if ( FT_ALLOC( bitmaps[i].buffer, bitmap->rows * (FT_UInt)bitmap->pitch ) ) goto Exit; /* determine the orientation */ orientations[i] = get_contour_orientation( contour ); /* The `overload_sign` property is specific to */ /* `sdf_generate_bounding_box`. This basically */ /* overloads the default sign of the outside */ /* pixels, which is necessary for */ /* counter-clockwise contours. */ if ( orientations[i] == SDF_ORIENTATION_CCW && internal_params.orientation == FT_ORIENTATION_FILL_RIGHT ) internal_params.overload_sign = 1; else if ( orientations[i] == SDF_ORIENTATION_CW && internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) internal_params.overload_sign = 1; else internal_params.overload_sign = 0; /* Make `contour->next` NULL so that there is */ /* one contour in the list. Also hold the next */ /* contour in a temporary variable so as to */ /* restore the original value. */ temp_contour = contour->next; contour->next = NULL; /* Use `temp_shape` to hold the new contour. */ /* Now, `temp_shape` has only one contour. */ temp_shape.contours = contour; /* finally generate the SDF */ FT_CALL( sdf_generate_subdivision( internal_params, &temp_shape, spread, &bitmaps[i] ) ); /* Restore the original `next` variable. */ contour->next = temp_contour; /* Since `split_sdf_shape` deallocated the original */ /* contours list we need to assign the new value to */ /* the shape's contour. */ temp_shape.contours->next = head; head = temp_shape.contours; /* Simply flip the orientation in case of post-script fonts */ /* so as to avoid modificatons in the combining phase. */ if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) { if ( orientations[i] == SDF_ORIENTATION_CW ) orientations[i] = SDF_ORIENTATION_CCW; else if ( orientations[i] == SDF_ORIENTATION_CCW ) orientations[i] = SDF_ORIENTATION_CW; } contour = contour->next; } /* assign the new contour list to `shape->contours` */ shape->contours = head; /* cast the output bitmap buffer */ t = (FT_SDFFormat*)bitmap->buffer; /* Iterate over all pixels and combine all separate */ /* contours. These are the rules for combining: */ /* */ /* (1) For all clockwise contours, compute the largest */ /* value. Name this as `val_c`. */ /* (2) For all counter-clockwise contours, compute the */ /* smallest value. Name this as `val_ac`. */ /* (3) Now, finally use the smaller value of `val_c' */ /* and `val_ac'. */ for ( j = 0; j < rows; j++ ) { for ( i = 0; i < width; i++ ) { FT_Int id = j * width + i; /* index of current pixel */ FT_Int c; /* contour iterator */ FT_SDFFormat val_c = 0; /* max clockwise value */ FT_SDFFormat val_ac = UCHAR_MAX; /* min counter-clockwise val */ /* iterate through all the contours */ for ( c = 0; c < num_contours; c++ ) { /* current contour value */ FT_SDFFormat temp = ( (FT_SDFFormat*)bitmaps[c].buffer )[id]; if ( orientations[c] == SDF_ORIENTATION_CW ) val_c = FT_MAX( val_c, temp ); /* clockwise */ else val_ac = FT_MIN( val_ac, temp ); /* counter-clockwise */ } /* Finally find the smaller of the two and assign to output. */ /* Also apply `flip_sign` if set. */ t[id] = FT_MIN( val_c, val_ac ); if ( flip_sign ) t[id] = invert_sign( t[id] ); } } Exit: /* deallocate orientations array */ if ( orientations ) FT_FREE( orientations ); /* deallocate temporary bitmaps */ if ( bitmaps ) { if ( num_contours == 0 ) error = FT_THROW( Raster_Corrupted ); else { for ( i = 0; i < num_contours; i++ ) FT_FREE( bitmaps[i].buffer ); FT_FREE( bitmaps ); } } /* restore the `flip_sign` property */ internal_params.flip_sign = flip_sign; return error; } /************************************************************************** * * interface functions * */ static FT_Error sdf_raster_new( FT_Memory memory, SDF_PRaster* araster ) { FT_Error error; SDF_PRaster raster = NULL; if ( !FT_NEW( raster ) ) raster->memory = memory; *araster = raster; return error; } static void sdf_raster_reset( FT_Raster raster, unsigned char* pool_base, unsigned long pool_size ) { FT_UNUSED( raster ); FT_UNUSED( pool_base ); FT_UNUSED( pool_size ); } static FT_Error sdf_raster_set_mode( FT_Raster raster, unsigned long mode, void* args ) { FT_UNUSED( raster ); FT_UNUSED( mode ); FT_UNUSED( args ); return FT_Err_Ok; } static FT_Error sdf_raster_render( FT_Raster raster, const FT_Raster_Params* params ) { FT_Error error = FT_Err_Ok; SDF_TRaster* sdf_raster = (SDF_TRaster*)raster; FT_Outline* outline = NULL; const SDF_Raster_Params* sdf_params = (const SDF_Raster_Params*)params; FT_Memory memory = NULL; SDF_Shape* shape = NULL; SDF_Params internal_params; /* check for valid arguments */ if ( !sdf_raster || !sdf_params ) { error = FT_THROW( Invalid_Argument ); goto Exit; } outline = (FT_Outline*)sdf_params->root.source; /* check whether outline is valid */ if ( !outline ) { error = FT_THROW( Invalid_Outline ); goto Exit; } /* if the outline is empty, return */ if ( outline->n_points <= 0 || outline->n_contours <= 0 ) goto Exit; /* check whether the outline has valid fields */ if ( !outline->contours || !outline->points ) { error = FT_THROW( Invalid_Outline ); goto Exit; } /* check whether spread is set properly */ if ( sdf_params->spread > MAX_SPREAD || sdf_params->spread < MIN_SPREAD ) { FT_TRACE0(( "sdf_raster_render:" " The `spread' field of `SDF_Raster_Params' is invalid,\n" )); FT_TRACE0(( " " " the value of this field must be within [%d, %d].\n", MIN_SPREAD, MAX_SPREAD )); FT_TRACE0(( " " " Also, you must pass `SDF_Raster_Params' instead of\n" )); FT_TRACE0(( " " " the default `FT_Raster_Params' while calling\n" )); FT_TRACE0(( " " " this function and set the fields properly.\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } memory = sdf_raster->memory; if ( !memory ) { FT_TRACE0(( "sdf_raster_render:" " Raster not setup properly,\n" )); FT_TRACE0(( " " " unable to find memory handle.\n" )); error = FT_THROW( Invalid_Handle ); goto Exit; } /* set up the parameters */ internal_params.orientation = FT_Outline_Get_Orientation( outline ); internal_params.flip_sign = sdf_params->flip_sign; internal_params.flip_y = sdf_params->flip_y; internal_params.overload_sign = 0; FT_CALL( sdf_shape_new( memory, &shape ) ); FT_CALL( sdf_outline_decompose( outline, shape ) ); if ( sdf_params->overlaps ) FT_CALL( sdf_generate_with_overlaps( internal_params, shape, sdf_params->spread, sdf_params->root.target ) ); else FT_CALL( sdf_generate_subdivision( internal_params, shape, sdf_params->spread, sdf_params->root.target ) ); if ( shape ) sdf_shape_done( &shape ); Exit: return error; } static void sdf_raster_done( FT_Raster raster ) { FT_Memory memory = (FT_Memory)((SDF_TRaster*)raster)->memory; FT_FREE( raster ); } FT_DEFINE_RASTER_FUNCS( ft_sdf_raster, FT_GLYPH_FORMAT_OUTLINE, (FT_Raster_New_Func) sdf_raster_new, /* raster_new */ (FT_Raster_Reset_Func) sdf_raster_reset, /* raster_reset */ (FT_Raster_Set_Mode_Func)sdf_raster_set_mode, /* raster_set_mode */ (FT_Raster_Render_Func) sdf_raster_render, /* raster_render */ (FT_Raster_Done_Func) sdf_raster_done /* raster_done */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdf.c
C++
gpl-3.0
111,825
/**************************************************************************** * * ftsdf.h * * Signed Distance Field support (specification). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 FTSDF_H_ #define FTSDF_H_ #include <ft2build.h> #include FT_CONFIG_CONFIG_H #include <freetype/ftimage.h> /* common properties and function */ #include "ftsdfcommon.h" FT_BEGIN_HEADER /************************************************************************** * * @struct: * SDF_Raster_Params * * @description: * This struct must be passed to the raster render function * @FT_Raster_RenderFunc instead of @FT_Raster_Params because the * rasterizer requires some additional information to render properly. * * @fields: * root :: * The native raster parameters structure. * * spread :: * This is an essential parameter/property required by the renderer. * `spread` defines the maximum unsigned value that is present in the * final SDF output. For the default value check file * `ftsdfcommon.h`. * * flip_sign :: * By default positive values indicate positions inside of contours, * i.e., filled by a contour. If this property is true then that * output will be the opposite of the default, i.e., negative values * indicate positions inside of contours. * * flip_y :: * Setting this parameter to true maked the output image flipped * along the y-axis. * * overlaps :: * Set this to true to generate SDF for glyphs having overlapping * contours. The overlapping support is limited to glyphs that do not * have self-intersecting contours. Also, removing overlaps require a * considerable amount of extra memory; additionally, it will not work * if generating SDF from bitmap. * * @note: * All properties are valid for both the 'sdf' and 'bsdf' renderers; the * exception is `overlaps`, which gets ignored by the 'bsdf' renderer. * */ typedef struct SDF_Raster_Params_ { FT_Raster_Params root; FT_UInt spread; FT_Bool flip_sign; FT_Bool flip_y; FT_Bool overlaps; } SDF_Raster_Params; /* rasterizer to convert outline to SDF */ FT_EXPORT_VAR( const FT_Raster_Funcs ) ft_sdf_raster; /* rasterizer to convert bitmap to SDF */ FT_EXPORT_VAR( const FT_Raster_Funcs ) ft_bitmap_sdf_raster; FT_END_HEADER #endif /* FTSDF_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdf.h
C++
gpl-3.0
2,914
/**************************************************************************** * * ftsdfcommon.c * * Auxiliary data for Signed Distance Field support (body). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 "ftsdf.h" #include "ftsdfcommon.h" /************************************************************************** * * common functions * */ /* * Original algorithm: * * https://github.com/chmike/fpsqrt * * Use this to compute the square root of a 16.16 fixed point number. */ FT_LOCAL_DEF( FT_16D16 ) square_root( FT_16D16 val ) { FT_ULong t, q, b, r; r = (FT_ULong)val; b = 0x40000000L; q = 0; while ( b > 0x40L ) { t = q + b; if ( r >= t ) { r -= t; q = t + b; } r <<= 1; b >>= 1; } q >>= 8; return (FT_16D16)q; } /************************************************************************** * * format and sign manipulating functions * */ /* * Convert 16.16 fixed point values to the desired output format. * In this case we reduce 16.16 fixed point values to normalized * 8-bit values. * * The `max_value` in the parameter is the maximum value in the * distance field map and is equal to the spread. We normalize * the distances using this value instead of computing the maximum * value for the entire bitmap. * * You can use this function to map the 16.16 signed values to any * format required. Do note that the output buffer is 8-bit, so only * use an 8-bit format for `FT_SDFFormat`, or increase the buffer size in * `ftsdfrend.c`. */ FT_LOCAL_DEF( FT_SDFFormat ) map_fixed_to_sdf( FT_16D16 dist, FT_16D16 max_value ) { FT_SDFFormat out; FT_16D16 udist; /* normalize the distance values */ dist = FT_DivFix( dist, max_value ); udist = dist < 0 ? -dist : dist; /* Reduce the distance values to 8 bits. */ /* */ /* Since +1/-1 in 16.16 takes the 16th bit, we right-shift */ /* the number by 9 to make it fit into the 7-bit range. */ /* */ /* One bit is reserved for the sign. */ udist >>= 9; /* Since `char` can only store a maximum positive value */ /* of 127 we need to make sure it does not wrap around and */ /* give a negative value. */ if ( dist > 0 && udist > 127 ) udist = 127; if ( dist < 0 && udist > 128 ) udist = 128; /* Output the data; negative values are from [0, 127] and positive */ /* from [128, 255]. One important thing is that negative values */ /* are inverted here, that means [0, 128] maps to [-128, 0] linearly. */ /* More on that in `freetype.h` near the documentation of */ /* `FT_RENDER_MODE_SDF`. */ out = dist < 0 ? 128 - (FT_SDFFormat)udist : (FT_SDFFormat)udist + 128; return out; } /* * Invert the signed distance packed into the corresponding format. * So if the values are negative they will become positive in the * chosen format. * * [Note]: This function should only be used after converting the * 16.16 signed distance values to `FT_SDFFormat`. If that * conversion has not been done, then simply invert the sign * and use the above function to pack the values. */ FT_LOCAL_DEF( FT_SDFFormat ) invert_sign( FT_SDFFormat dist ) { return 255 - dist; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdfcommon.c
C++
gpl-3.0
4,108
/**************************************************************************** * * ftsdfcommon.h * * Auxiliary data for Signed Distance Field support (specification). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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. * */ /**************************************************** * * This file contains common functions and properties * for both the 'sdf' and 'bsdf' renderers. * */ #ifndef FTSDFCOMMON_H_ #define FTSDFCOMMON_H_ #include <ft2build.h> #include FT_CONFIG_CONFIG_H #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER /************************************************************************** * * default values (cannot be set individually for each renderer) * */ /* default spread value */ #define DEFAULT_SPREAD 8 /* minimum spread supported by the renderer */ #define MIN_SPREAD 2 /* maximum spread supported by the renderer */ #define MAX_SPREAD 32 /* pixel size in 26.6 */ #define ONE_PIXEL ( 1 << 6 ) /************************************************************************** * * common definitions (cannot be set individually for each renderer) * */ /* If this macro is set to 1 the rasterizer uses squared distances for */ /* computation. It can greatly improve the performance but there is a */ /* chance of overflow and artifacts. You can safely use it up to a */ /* pixel size of 128. */ #ifndef USE_SQUARED_DISTANCES #define USE_SQUARED_DISTANCES 0 #endif /************************************************************************** * * common macros * */ /* convert int to 26.6 fixed-point */ #define FT_INT_26D6( x ) ( x * 64 ) /* convert int to 16.16 fixed-point */ #define FT_INT_16D16( x ) ( x * 65536 ) /* convert 26.6 to 16.16 fixed-point */ #define FT_26D6_16D16( x ) ( x * 1024 ) /* Convenience macro to call a function; it */ /* jumps to label `Exit` if an error occurs. */ #define FT_CALL( x ) do \ { \ error = ( x ); \ if ( error != FT_Err_Ok ) \ goto Exit; \ } while ( 0 ) /* * The macro `VECTOR_LENGTH_16D16` computes either squared distances or * actual distances, depending on the value of `USE_SQUARED_DISTANCES`. * * By using squared distances the performance can be greatly improved but * there is a risk of overflow. */ #if USE_SQUARED_DISTANCES #define VECTOR_LENGTH_16D16( v ) ( FT_MulFix( v.x, v.x ) + \ FT_MulFix( v.y, v.y ) ) #else #define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v ) #endif /************************************************************************** * * common typedefs * */ typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed-point components */ typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed-point components */ typedef FT_Fixed FT_16D16; /* 16.16 fixed-point representation */ typedef FT_Fixed FT_26D6; /* 26.6 fixed-point representation */ typedef FT_Byte FT_SDFFormat; /* format to represent SDF data */ typedef FT_BBox FT_CBox; /* control box of a curve */ FT_LOCAL( FT_16D16 ) square_root( FT_16D16 val ); FT_LOCAL( FT_SDFFormat ) map_fixed_to_sdf( FT_16D16 dist, FT_16D16 max_value ); FT_LOCAL( FT_SDFFormat ) invert_sign( FT_SDFFormat dist ); FT_END_HEADER #endif /* FTSDFCOMMON_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdfcommon.h
C++
gpl-3.0
4,007
/**************************************************************************** * * ftsdferrs.h * * Signed Distance Field error codes (specification only). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 FTSDFERRS_H_ #define FTSDFERRS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX Sdf_Err_ #define FT_ERR_BASE FT_Mod_Err_Sdf #include <freetype/fterrors.h> #endif /* FTSDFERRS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdferrs.h
C++
gpl-3.0
848
/**************************************************************************** * * ftsdfrend.c * * Signed Distance Field renderer interface (body). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/services/svprop.h> #include <freetype/ftoutln.h> #include <freetype/ftbitmap.h> #include "ftsdfrend.h" #include "ftsdf.h" #include "ftsdferrs.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sdf /************************************************************************** * * macros and default property values * */ #define SDF_RENDERER( rend ) ( (SDF_Renderer)rend ) /************************************************************************** * * for setting properties * */ /* property setter function */ static FT_Error sdf_property_set( FT_Module module, const char* property_name, const void* value, FT_Bool value_is_string ) { FT_Error error = FT_Err_Ok; SDF_Renderer render = SDF_RENDERER( FT_RENDERER( module ) ); FT_UNUSED( value_is_string ); if ( ft_strcmp( property_name, "spread" ) == 0 ) { FT_Int val = *(const FT_Int*)value; if ( val > MAX_SPREAD || val < MIN_SPREAD ) { FT_TRACE0(( "[sdf] sdf_property_set:" " the `spread' property can have a value\n" )); FT_TRACE0(( " " " within range [%d, %d] (value provided: %d)\n", MIN_SPREAD, MAX_SPREAD, val )); error = FT_THROW( Invalid_Argument ); goto Exit; } render->spread = (FT_UInt)val; FT_TRACE7(( "[sdf] sdf_property_set:" " updated property `spread' to %d\n", val )); } else if ( ft_strcmp( property_name, "flip_sign" ) == 0 ) { FT_Int val = *(const FT_Int*)value; render->flip_sign = val ? 1 : 0; FT_TRACE7(( "[sdf] sdf_property_set:" " updated property `flip_sign' to %d\n", val )); } else if ( ft_strcmp( property_name, "flip_y" ) == 0 ) { FT_Int val = *(const FT_Int*)value; render->flip_y = val ? 1 : 0; FT_TRACE7(( "[sdf] sdf_property_set:" " updated property `flip_y' to %d\n", val )); } else if ( ft_strcmp( property_name, "overlaps" ) == 0 ) { FT_Bool val = *(const FT_Bool*)value; render->overlaps = val; FT_TRACE7(( "[sdf] sdf_property_set:" " updated property `overlaps' to %d\n", val )); } else { FT_TRACE0(( "[sdf] sdf_property_set:" " missing property `%s'\n", property_name )); error = FT_THROW( Missing_Property ); } Exit: return error; } /* property getter function */ static FT_Error sdf_property_get( FT_Module module, const char* property_name, void* value ) { FT_Error error = FT_Err_Ok; SDF_Renderer render = SDF_RENDERER( FT_RENDERER( module ) ); if ( ft_strcmp( property_name, "spread" ) == 0 ) { FT_UInt* val = (FT_UInt*)value; *val = render->spread; } else if ( ft_strcmp( property_name, "flip_sign" ) == 0 ) { FT_Int* val = (FT_Int*)value; *val = render->flip_sign; } else if ( ft_strcmp( property_name, "flip_y" ) == 0 ) { FT_Int* val = (FT_Int*)value; *val = render->flip_y; } else if ( ft_strcmp( property_name, "overlaps" ) == 0 ) { FT_Int* val = (FT_Int*)value; *val = render->overlaps; } else { FT_TRACE0(( "[sdf] sdf_property_get:" " missing property `%s'\n", property_name )); error = FT_THROW( Missing_Property ); } return error; } FT_DEFINE_SERVICE_PROPERTIESREC( sdf_service_properties, (FT_Properties_SetFunc)sdf_property_set, /* set_property */ (FT_Properties_GetFunc)sdf_property_get ) /* get_property */ FT_DEFINE_SERVICEDESCREC1( sdf_services, FT_SERVICE_ID_PROPERTIES, &sdf_service_properties ) static FT_Module_Interface ft_sdf_requester( FT_Renderer render, const char* module_interface ) { FT_UNUSED( render ); return ft_service_list_lookup( sdf_services, module_interface ); } /*************************************************************************/ /*************************************************************************/ /** **/ /** OUTLINE TO SDF CONVERTER **/ /** **/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * interface functions * */ static FT_Error ft_sdf_init( FT_Renderer render ) { SDF_Renderer sdf_render = SDF_RENDERER( render ); sdf_render->spread = DEFAULT_SPREAD; sdf_render->flip_sign = 0; sdf_render->flip_y = 0; sdf_render->overlaps = 0; return FT_Err_Ok; } static void ft_sdf_done( FT_Renderer render ) { FT_UNUSED( render ); } /* generate signed distance field from a glyph's slot image */ static FT_Error ft_sdf_render( FT_Renderer module, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) { FT_Error error = FT_Err_Ok; FT_Outline* outline = &slot->outline; FT_Bitmap* bitmap = &slot->bitmap; FT_Memory memory = NULL; FT_Renderer render = NULL; FT_Pos x_shift = 0; FT_Pos y_shift = 0; FT_Pos x_pad = 0; FT_Pos y_pad = 0; SDF_Raster_Params params; SDF_Renderer sdf_module = SDF_RENDERER( module ); render = &sdf_module->root; memory = render->root.memory; /* check whether slot format is correct before rendering */ if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Glyph_Format ); goto Exit; } /* check whether render mode is correct */ if ( mode != FT_RENDER_MODE_SDF ) { error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } /* deallocate the previously allocated bitmap */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } /* preset the bitmap using the glyph's outline; */ /* the sdf bitmap is similar to an anti-aliased bitmap */ /* with a slightly bigger size and different pixel mode */ if ( ft_glyphslot_preset_bitmap( slot, FT_RENDER_MODE_NORMAL, origin ) ) { error = FT_THROW( Raster_Overflow ); goto Exit; } /* the rows and pitch must be valid after presetting the */ /* bitmap using outline */ if ( !bitmap->rows || !bitmap->pitch ) { FT_ERROR(( "ft_sdf_render: failed to preset bitmap\n" )); error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } /* the padding will simply be equal to the `spread' */ x_pad = sdf_module->spread; y_pad = sdf_module->spread; /* apply the padding; will be in all the directions */ bitmap->rows += y_pad * 2; bitmap->width += x_pad * 2; /* ignore the pitch, pixel mode and set custom */ bitmap->pixel_mode = FT_PIXEL_MODE_GRAY; bitmap->pitch = (int)( bitmap->width ); bitmap->num_grays = 255; /* allocate new buffer */ if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) ) goto Exit; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; slot->bitmap_top += y_pad; slot->bitmap_left -= x_pad; x_shift = 64 * -slot->bitmap_left; y_shift = 64 * -slot->bitmap_top; y_shift += 64 * (FT_Int)bitmap->rows; if ( origin ) { x_shift += origin->x; y_shift += origin->y; } /* translate outline to render it into the bitmap */ if ( x_shift || y_shift ) FT_Outline_Translate( outline, x_shift, y_shift ); /* set up parameters */ params.root.target = bitmap; params.root.source = outline; params.root.flags = FT_RASTER_FLAG_SDF; params.spread = sdf_module->spread; params.flip_sign = sdf_module->flip_sign; params.flip_y = sdf_module->flip_y; params.overlaps = sdf_module->overlaps; /* render the outline */ error = render->raster_render( render->raster, (const FT_Raster_Params*)&params ); /* transform the outline back to the original state */ if ( x_shift || y_shift ) FT_Outline_Translate( outline, -x_shift, -y_shift ); Exit: if ( !error ) { /* the glyph is successfully rendered to a bitmap */ slot->format = FT_GLYPH_FORMAT_BITMAP; } else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } return error; } /* transform the glyph using matrix and/or delta */ static FT_Error ft_sdf_transform( FT_Renderer render, FT_GlyphSlot slot, const FT_Matrix* matrix, const FT_Vector* delta ) { FT_Error error = FT_Err_Ok; if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( matrix ) FT_Outline_Transform( &slot->outline, matrix ); if ( delta ) FT_Outline_Translate( &slot->outline, delta->x, delta->y ); Exit: return error; } /* return the control box of a glyph's outline */ static void ft_sdf_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox ) { FT_ZERO( cbox ); if ( slot->format == render->glyph_format ) FT_Outline_Get_CBox( &slot->outline, cbox ); } /* set render specific modes or attributes */ static FT_Error ft_sdf_set_mode( FT_Renderer render, FT_ULong mode_tag, FT_Pointer data ) { /* pass it to the rasterizer */ return render->clazz->raster_class->raster_set_mode( render->raster, mode_tag, data ); } FT_DEFINE_RENDERER( ft_sdf_renderer_class, FT_MODULE_RENDERER, sizeof ( SDF_Renderer_Module ), "sdf", 0x10000L, 0x20000L, NULL, (FT_Module_Constructor)ft_sdf_init, (FT_Module_Destructor) ft_sdf_done, (FT_Module_Requester) ft_sdf_requester, FT_GLYPH_FORMAT_OUTLINE, (FT_Renderer_RenderFunc) ft_sdf_render, /* render_glyph */ (FT_Renderer_TransformFunc)ft_sdf_transform, /* transform_glyph */ (FT_Renderer_GetCBoxFunc) ft_sdf_get_cbox, /* get_glyph_cbox */ (FT_Renderer_SetModeFunc) ft_sdf_set_mode, /* set_mode */ (FT_Raster_Funcs*)&ft_sdf_raster /* raster_class */ ) /*************************************************************************/ /*************************************************************************/ /** **/ /** BITMAP TO SDF CONVERTER **/ /** **/ /*************************************************************************/ /*************************************************************************/ /* generate signed distance field from glyph's bitmap */ static FT_Error ft_bsdf_render( FT_Renderer module, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) { FT_Error error = FT_Err_Ok; FT_Memory memory = NULL; FT_Bitmap* bitmap = &slot->bitmap; FT_Renderer render = NULL; FT_Bitmap target; FT_Pos x_pad = 0; FT_Pos y_pad = 0; SDF_Raster_Params params; SDF_Renderer sdf_module = SDF_RENDERER( module ); /* initialize the bitmap in case any error occurs */ FT_Bitmap_Init( &target ); render = &sdf_module->root; memory = render->root.memory; /* check whether slot format is correct before rendering */ if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Glyph_Format ); goto Exit; } /* check whether render mode is correct */ if ( mode != FT_RENDER_MODE_SDF ) { error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } if ( origin ) { FT_ERROR(( "ft_bsdf_render: can't translate the bitmap\n" )); error = FT_THROW( Unimplemented_Feature ); goto Exit; } /* Do not generate SDF if the bitmap is not owned by the */ /* glyph: it might be that the source buffer is already freed. */ if ( !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) { FT_ERROR(( "ft_bsdf_render: can't generate SDF from" " unowned source bitmap\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !bitmap->rows || !bitmap->pitch ) { FT_ERROR(( "ft_bsdf_render: invalid bitmap size\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } FT_Bitmap_New( &target ); /* padding will simply be equal to `spread` */ x_pad = sdf_module->spread; y_pad = sdf_module->spread; /* apply padding, which extends to all directions */ target.rows = bitmap->rows + y_pad * 2; target.width = bitmap->width + x_pad * 2; /* set up the target bitmap */ target.pixel_mode = FT_PIXEL_MODE_GRAY; target.pitch = (int)( target.width ); target.num_grays = 255; if ( FT_ALLOC_MULT( target.buffer, target.rows, target.pitch ) ) goto Exit; /* set up parameters */ params.root.target = &target; params.root.source = bitmap; params.root.flags = FT_RASTER_FLAG_SDF; params.spread = sdf_module->spread; params.flip_sign = sdf_module->flip_sign; params.flip_y = sdf_module->flip_y; error = render->raster_render( render->raster, (const FT_Raster_Params*)&params ); Exit: if ( !error ) { /* the glyph is successfully converted to a SDF */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } slot->bitmap = target; slot->bitmap_top += y_pad; slot->bitmap_left -= x_pad; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; } else if ( target.buffer ) FT_FREE( target.buffer ); return error; } FT_DEFINE_RENDERER( ft_bitmap_sdf_renderer_class, FT_MODULE_RENDERER, sizeof ( SDF_Renderer_Module ), "bsdf", 0x10000L, 0x20000L, NULL, (FT_Module_Constructor)ft_sdf_init, (FT_Module_Destructor) ft_sdf_done, (FT_Module_Requester) ft_sdf_requester, FT_GLYPH_FORMAT_BITMAP, (FT_Renderer_RenderFunc) ft_bsdf_render, /* render_glyph */ (FT_Renderer_TransformFunc)ft_sdf_transform, /* transform_glyph */ (FT_Renderer_GetCBoxFunc) ft_sdf_get_cbox, /* get_glyph_cbox */ (FT_Renderer_SetModeFunc) ft_sdf_set_mode, /* set_mode */ (FT_Raster_Funcs*)&ft_bitmap_sdf_raster /* raster_class */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdfrend.c
C++
gpl-3.0
16,559
/**************************************************************************** * * ftsdfrend.h * * Signed Distance Field renderer interface (specification). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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 FTSDFREND_H_ #define FTSDFREND_H_ #include <freetype/ftrender.h> #include <freetype/ftmodapi.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER /************************************************************************** * * @struct: * SDF_Renderer_Module * * @description: * This struct extends the native renderer struct `FT_RendererRec`. It * is basically used to store various parameters required by the * renderer and some additional parameters that can be used to tweak the * output of the renderer. * * @fields: * root :: * The native rendere struct. * * spread :: * This is an essential parameter/property required by the renderer. * `spread` defines the maximum unsigned value that is present in the * final SDF output. For the default value check file * `ftsdfcommon.h`. * * flip_sign :: * By default positive values indicate positions inside of contours, * i.e., filled by a contour. If this property is true then that * output will be the opposite of the default, i.e., negative values * indicate positions inside of contours. * * flip_y :: * Setting this parameter to true makes the output image flipped * along the y-axis. * * overlaps :: * Set this to true to generate SDF for glyphs having overlapping * contours. The overlapping support is limited to glyphs that do not * have self-intersecting contours. Also, removing overlaps require a * considerable amount of extra memory; additionally, it will not work * if generating SDF from bitmap. * * @note: * All properties except `overlaps` are valid for both the 'sdf' and * 'bsdf' renderers. * */ typedef struct SDF_Renderer_Module_ { FT_RendererRec root; FT_UInt spread; FT_Bool flip_sign; FT_Bool flip_y; FT_Bool overlaps; } SDF_Renderer_Module, *SDF_Renderer; /************************************************************************** * * @renderer: * ft_sdf_renderer_class * * @description: * Renderer to convert @FT_Outline to signed distance fields. * */ FT_DECLARE_RENDERER( ft_sdf_renderer_class ) /************************************************************************** * * @renderer: * ft_bitmap_sdf_renderer_class * * @description: * This is not exactly a renderer; it is just a converter that * transforms bitmaps to signed distance fields. * * @note: * This is not a separate module, it is part of the 'sdf' module. * */ FT_DECLARE_RENDERER( ft_bitmap_sdf_renderer_class ) FT_END_HEADER #endif /* FTSDFREND_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/ftsdfrend.h
C++
gpl-3.0
3,386
# # FreeType 2 Signed Distance Field module definition # # Copyright (C) 2020-2022 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. FTMODULE_H_COMMANDS += SDF_RENDERER FTMODULE_H_COMMANDS += BSDF_RENDERER define SDF_RENDERER $(OPEN_DRIVER) FT_Renderer_Class, ft_sdf_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)sdf $(ECHO_DRIVER_DESC)signed distance field renderer$(ECHO_DRIVER_DONE) endef define BSDF_RENDERER $(OPEN_DRIVER) FT_Renderer_Class, ft_bitmap_sdf_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)bsdf $(ECHO_DRIVER_DESC)bitmap to signed distance field converter$(ECHO_DRIVER_DONE) endef #EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/module.mk
mk
gpl-3.0
924
# # FreeType 2 Signed Distance Field driver configuration rules # # Copyright (C) 2020-2022 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. # sdf driver directory # SDF_DIR := $(SRC_DIR)/sdf # compilation flags for the driver # SDF_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(SDF_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # sdf driver sources (i.e., C files) # SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \ $(SDF_DIR)/ftsdf.c \ $(SDF_DIR)/ftbsdf.c \ $(SDF_DIR)/ftsdfcommon.c # sdf driver headers # SDF_DRV_H := $(SDF_DIR)/ftsdfrend.h \ $(SDF_DIR)/ftsdf.h \ $(SDF_DIR)/ftsdferrs.h \ $(SDF_DIR)/ftsdfcommon.h # sdf driver object(s) # # SDF_DRV_OBJ_M is used during `multi' builds. # SDF_DRV_OBJ_S is used during `single' builds. # SDF_DRV_OBJ_M := $(SDF_DRV_SRC:$(SDF_DIR)/%.c=$(OBJ_DIR)/%.$O) SDF_DRV_OBJ_S := $(OBJ_DIR)/sdf.$O # sdf driver source file for single build # SDF_DRV_SRC_S := $(SDF_DIR)/sdf.c # sdf driver - single object # $(SDF_DRV_OBJ_S): $(SDF_DRV_SRC_S) $(SDF_DRV_SRC) \ $(FREETYPE_H) $(SDF_DRV_H) $(SDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(SDF_DRV_SRC_S)) # sdf driver - multiple objects # $(OBJ_DIR)/%.$O: $(SDF_DIR)/%.c $(FREETYPE_H) $(SDF_DRV_H) $(SDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver list # DRV_OBJS_S += $(SDF_DRV_OBJ_S) DRV_OBJS_M += $(SDF_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/rules.mk
mk
gpl-3.0
1,901
/**************************************************************************** * * sdf.c * * FreeType Signed Distance Field renderer module component (body only). * * Copyright (C) 2020-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "ftsdfrend.c" #include "ftsdfcommon.c" #include "ftbsdf.c" #include "ftsdf.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sdf/sdf.c
C++
gpl-3.0
735
# # FreeType 2 SFNT module definition # # Copyright (C) 1996-2022 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. FTMODULE_H_COMMANDS += SFNT_MODULE define SFNT_MODULE $(OPEN_DRIVER) FT_Module_Class, sfnt_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)sfnt $(ECHO_DRIVER_DESC)helper module for TrueType & OpenType formats$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/module.mk
mk
gpl-3.0
667
/**************************************************************************** * * pngshim.c * * PNG Bitmap glyph support. * * Copyright (C) 2013-2022 by * Google, Inc. * Written by Stuart Gill and Behdad Esfahbod. * * 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include FT_CONFIG_STANDARD_LIBRARY_H #if defined( TT_CONFIG_OPTION_EMBEDDED_BITMAPS ) && \ defined( FT_CONFIG_OPTION_USE_PNG ) /* We always include <setjmp.h>, so make libpng shut up! */ #define PNG_SKIP_SETJMP_CHECK 1 #include <png.h> #include "pngshim.h" #include "sferrors.h" /* This code is freely based on cairo-png.c. There's so many ways */ /* to call libpng, and the way cairo does it is defacto standard. */ static unsigned int multiply_alpha( unsigned int alpha, unsigned int color ) { unsigned int temp = alpha * color + 0x80; return ( temp + ( temp >> 8 ) ) >> 8; } /* Premultiplies data and converts RGBA bytes => BGRA. */ static void premultiply_data( png_structp png, png_row_infop row_info, png_bytep data ) { unsigned int i = 0, limit; /* The `vector_size' attribute was introduced in gcc 3.1, which */ /* predates clang; the `__BYTE_ORDER__' preprocessor symbol was */ /* introduced in gcc 4.6 and clang 3.2, respectively. */ /* `__builtin_shuffle' for gcc was introduced in gcc 4.7.0. */ /* */ /* Intel compilers do not currently support __builtin_shuffle; */ /* The Intel check must be first. */ #if !defined( __INTEL_COMPILER ) && \ ( ( defined( __GNUC__ ) && \ ( ( __GNUC__ >= 5 ) || \ ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 7 ) ) ) ) || \ ( defined( __clang__ ) && \ ( ( __clang_major__ >= 4 ) || \ ( ( __clang_major__ == 3 ) && ( __clang_minor__ >= 2 ) ) ) ) ) && \ defined( __OPTIMIZE__ ) && \ defined( __SSE__ ) && \ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #ifdef __clang__ /* the clang documentation doesn't cover the two-argument case of */ /* `__builtin_shufflevector'; however, it is is implemented since */ /* version 2.8 */ #define vector_shuffle __builtin_shufflevector #else #define vector_shuffle __builtin_shuffle #endif typedef unsigned short v82 __attribute__(( vector_size( 16 ) )); if ( row_info->rowbytes > 15 ) { /* process blocks of 16 bytes in one rush, which gives a nice speed-up */ limit = row_info->rowbytes - 16 + 1; for ( ; i < limit; i += 16 ) { unsigned char* base = &data[i]; v82 s, s0, s1, a; /* clang <= 3.9 can't apply scalar values to vectors */ /* (or rather, it needs a different syntax) */ v82 n0x80 = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }; v82 n0xFF = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; v82 n8 = { 8, 8, 8, 8, 8, 8, 8, 8 }; v82 ma = { 1, 1, 3, 3, 5, 5, 7, 7 }; v82 o1 = { 0, 0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF }; v82 m0 = { 1, 0, 3, 2, 5, 4, 7, 6 }; ft_memcpy( &s, base, 16 ); /* RGBA RGBA RGBA RGBA */ s0 = s & n0xFF; /* R B R B R B R B */ s1 = s >> n8; /* G A G A G A G A */ a = vector_shuffle( s1, ma ); /* A A A A A A A A */ s1 |= o1; /* G 1 G 1 G 1 G 1 */ s0 = vector_shuffle( s0, m0 ); /* B R B R B R B R */ s0 *= a; s1 *= a; s0 += n0x80; s1 += n0x80; s0 = ( s0 + ( s0 >> n8 ) ) >> n8; s1 = ( s1 + ( s1 >> n8 ) ) >> n8; s = s0 | ( s1 << n8 ); ft_memcpy( base, &s, 16 ); } } #endif /* use `vector_size' */ FT_UNUSED( png ); limit = row_info->rowbytes; for ( ; i < limit; i += 4 ) { unsigned char* base = &data[i]; unsigned int alpha = base[3]; if ( alpha == 0 ) base[0] = base[1] = base[2] = base[3] = 0; else { unsigned int red = base[0]; unsigned int green = base[1]; unsigned int blue = base[2]; if ( alpha != 0xFF ) { red = multiply_alpha( alpha, red ); green = multiply_alpha( alpha, green ); blue = multiply_alpha( alpha, blue ); } base[0] = (unsigned char)blue; base[1] = (unsigned char)green; base[2] = (unsigned char)red; base[3] = (unsigned char)alpha; } } } /* Converts RGBx bytes to BGRA. */ static void convert_bytes_to_data( png_structp png, png_row_infop row_info, png_bytep data ) { unsigned int i; FT_UNUSED( png ); for ( i = 0; i < row_info->rowbytes; i += 4 ) { unsigned char* base = &data[i]; unsigned int red = base[0]; unsigned int green = base[1]; unsigned int blue = base[2]; base[0] = (unsigned char)blue; base[1] = (unsigned char)green; base[2] = (unsigned char)red; base[3] = 0xFF; } } /* Use error callback to avoid png writing to stderr. */ static void error_callback( png_structp png, png_const_charp error_msg ) { FT_Error* error = (FT_Error*)png_get_error_ptr( png ); FT_UNUSED( error_msg ); *error = FT_THROW( Out_Of_Memory ); #ifdef PNG_SETJMP_SUPPORTED ft_longjmp( png_jmpbuf( png ), 1 ); #endif /* if we get here, then we have no choice but to abort ... */ } /* Use warning callback to avoid png writing to stderr. */ static void warning_callback( png_structp png, png_const_charp error_msg ) { FT_UNUSED( png ); FT_UNUSED( error_msg ); /* Just ignore warnings. */ } static void read_data_from_FT_Stream( png_structp png, png_bytep data, png_size_t length ) { FT_Error error; png_voidp p = png_get_io_ptr( png ); FT_Stream stream = (FT_Stream)p; if ( FT_FRAME_ENTER( length ) ) { FT_Error* e = (FT_Error*)png_get_error_ptr( png ); *e = FT_THROW( Invalid_Stream_Read ); png_error( png, NULL ); return; } ft_memcpy( data, stream->cursor, length ); FT_FRAME_EXIT(); } FT_LOCAL_DEF( FT_Error ) Load_SBit_Png( FT_GlyphSlot slot, FT_Int x_offset, FT_Int y_offset, FT_Int pix_bits, TT_SBit_Metrics metrics, FT_Memory memory, FT_Byte* data, FT_UInt png_len, FT_Bool populate_map_and_metrics, FT_Bool metrics_only ) { FT_Bitmap *map = &slot->bitmap; FT_Error error = FT_Err_Ok; FT_StreamRec stream; png_structp png; png_infop info; png_uint_32 imgWidth, imgHeight; int bitdepth, color_type, interlace; FT_Int i; /* `rows` gets modified within a 'setjmp' scope; */ /* we thus need the `volatile` keyword. */ png_byte* *volatile rows = NULL; if ( x_offset < 0 || y_offset < 0 ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !populate_map_and_metrics && ( (FT_UInt)x_offset + metrics->width > map->width || (FT_UInt)y_offset + metrics->height > map->rows || pix_bits != 32 || map->pixel_mode != FT_PIXEL_MODE_BGRA ) ) { error = FT_THROW( Invalid_Argument ); goto Exit; } FT_Stream_OpenMemory( &stream, data, png_len ); png = png_create_read_struct( PNG_LIBPNG_VER_STRING, &error, error_callback, warning_callback ); if ( !png ) { error = FT_THROW( Out_Of_Memory ); goto Exit; } info = png_create_info_struct( png ); if ( !info ) { error = FT_THROW( Out_Of_Memory ); png_destroy_read_struct( &png, NULL, NULL ); goto Exit; } if ( ft_setjmp( png_jmpbuf( png ) ) ) { error = FT_THROW( Invalid_File_Format ); goto DestroyExit; } png_set_read_fn( png, &stream, read_data_from_FT_Stream ); png_read_info( png, info ); png_get_IHDR( png, info, &imgWidth, &imgHeight, &bitdepth, &color_type, &interlace, NULL, NULL ); if ( error || ( !populate_map_and_metrics && ( (FT_Int)imgWidth != metrics->width || (FT_Int)imgHeight != metrics->height ) ) ) goto DestroyExit; if ( populate_map_and_metrics ) { /* reject too large bitmaps similarly to the rasterizer */ if ( imgHeight > 0x7FFF || imgWidth > 0x7FFF ) { error = FT_THROW( Array_Too_Large ); goto DestroyExit; } metrics->width = (FT_UShort)imgWidth; metrics->height = (FT_UShort)imgHeight; map->width = metrics->width; map->rows = metrics->height; map->pixel_mode = FT_PIXEL_MODE_BGRA; map->pitch = (int)( map->width * 4 ); map->num_grays = 256; } /* convert palette/gray image to rgb */ if ( color_type == PNG_COLOR_TYPE_PALETTE ) png_set_palette_to_rgb( png ); /* expand gray bit depth if needed */ if ( color_type == PNG_COLOR_TYPE_GRAY ) { #if PNG_LIBPNG_VER >= 10209 png_set_expand_gray_1_2_4_to_8( png ); #else png_set_gray_1_2_4_to_8( png ); #endif } /* transform transparency to alpha */ if ( png_get_valid(png, info, PNG_INFO_tRNS ) ) png_set_tRNS_to_alpha( png ); if ( bitdepth == 16 ) png_set_strip_16( png ); if ( bitdepth < 8 ) png_set_packing( png ); /* convert grayscale to RGB */ if ( color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) png_set_gray_to_rgb( png ); if ( interlace != PNG_INTERLACE_NONE ) png_set_interlace_handling( png ); png_set_filler( png, 0xFF, PNG_FILLER_AFTER ); /* recheck header after setting EXPAND options */ png_read_update_info(png, info ); png_get_IHDR( png, info, &imgWidth, &imgHeight, &bitdepth, &color_type, &interlace, NULL, NULL ); if ( bitdepth != 8 || !( color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA ) ) { error = FT_THROW( Invalid_File_Format ); goto DestroyExit; } if ( metrics_only ) goto DestroyExit; switch ( color_type ) { default: /* Shouldn't happen, but fall through. */ case PNG_COLOR_TYPE_RGB_ALPHA: png_set_read_user_transform_fn( png, premultiply_data ); break; case PNG_COLOR_TYPE_RGB: /* Humm, this smells. Carry on though. */ png_set_read_user_transform_fn( png, convert_bytes_to_data ); break; } if ( populate_map_and_metrics ) { /* this doesn't overflow: 0x7FFF * 0x7FFF * 4 < 2^32 */ FT_ULong size = map->rows * (FT_ULong)map->pitch; error = ft_glyphslot_alloc_bitmap( slot, size ); if ( error ) goto DestroyExit; } if ( FT_QNEW_ARRAY( rows, imgHeight ) ) { error = FT_THROW( Out_Of_Memory ); goto DestroyExit; } for ( i = 0; i < (FT_Int)imgHeight; i++ ) rows[i] = map->buffer + ( y_offset + i ) * map->pitch + x_offset * 4; png_read_image( png, rows ); png_read_end( png, info ); DestroyExit: /* even if reading fails with longjmp, rows must be freed */ FT_FREE( rows ); png_destroy_read_struct( &png, &info, NULL ); FT_Stream_Close( &stream ); Exit: return error; } #else /* !(TT_CONFIG_OPTION_EMBEDDED_BITMAPS && FT_CONFIG_OPTION_USE_PNG) */ /* ANSI C doesn't like empty source files */ typedef int _pngshim_dummy; #endif /* !(TT_CONFIG_OPTION_EMBEDDED_BITMAPS && FT_CONFIG_OPTION_USE_PNG) */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/pngshim.c
C++
gpl-3.0
13,180
/**************************************************************************** * * pngshim.h * * PNG Bitmap glyph support. * * Copyright (C) 2013-2022 by * Google, Inc. * Written by Stuart Gill and Behdad Esfahbod. * * 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 PNGSHIM_H_ #define PNGSHIM_H_ #include "ttload.h" FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_USE_PNG FT_LOCAL( FT_Error ) Load_SBit_Png( FT_GlyphSlot slot, FT_Int x_offset, FT_Int y_offset, FT_Int pix_bits, TT_SBit_Metrics metrics, FT_Memory memory, FT_Byte* data, FT_UInt png_len, FT_Bool populate_map_and_metrics, FT_Bool metrics_only ); #endif FT_END_HEADER #endif /* PNGSHIM_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/pngshim.h
C++
gpl-3.0
1,184
# # FreeType 2 SFNT driver configuration rules # # Copyright (C) 1996-2022 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. # SFNT driver directory # SFNT_DIR := $(SRC_DIR)/sfnt # compilation flags for the driver # SFNT_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(SFNT_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # SFNT driver sources (i.e., C files) # SFNT_DRV_SRC := $(SFNT_DIR)/pngshim.c \ $(SFNT_DIR)/sfdriver.c \ $(SFNT_DIR)/sfobjs.c \ $(SFNT_DIR)/sfwoff.c \ $(SFNT_DIR)/sfwoff2.c \ $(SFNT_DIR)/ttbdf.c \ $(SFNT_DIR)/ttcmap.c \ $(SFNT_DIR)/ttcolr.c \ $(SFNT_DIR)/ttsvg.c \ $(SFNT_DIR)/ttcpal.c \ $(SFNT_DIR)/ttkern.c \ $(SFNT_DIR)/ttload.c \ $(SFNT_DIR)/ttmtx.c \ $(SFNT_DIR)/ttpost.c \ $(SFNT_DIR)/ttsbit.c \ $(SFNT_DIR)/woff2tags.c # SFNT driver headers # SFNT_DRV_H := $(SFNT_DRV_SRC:%c=%h) \ $(SFNT_DIR)/sferrors.h # SFNT driver object(s) # # SFNT_DRV_OBJ_M is used during `multi' builds. # SFNT_DRV_OBJ_S is used during `single' builds. # SFNT_DRV_OBJ_M := $(SFNT_DRV_SRC:$(SFNT_DIR)/%.c=$(OBJ_DIR)/%.$O) SFNT_DRV_OBJ_S := $(OBJ_DIR)/sfnt.$O # SFNT driver source file for single build # SFNT_DRV_SRC_S := $(SFNT_DIR)/sfnt.c # SFNT driver - single object # $(SFNT_DRV_OBJ_S): $(SFNT_DRV_SRC_S) $(SFNT_DRV_SRC) \ $(FREETYPE_H) $(SFNT_DRV_H) $(SFNT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(SFNT_DRV_SRC_S)) # SFNT driver - multiple objects # $(OBJ_DIR)/%.$O: $(SFNT_DIR)/%.c $(FREETYPE_H) $(SFNT_DRV_H) $(SFNT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(SFNT_DRV_OBJ_S) DRV_OBJS_M += $(SFNT_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/rules.mk
mk
gpl-3.0
2,350
/**************************************************************************** * * sfdriver.c * * High-level SFNT driver interface (body). * * Copyright (C) 1996-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/sfnt.h> #include <freetype/internal/ftobjs.h> #include <freetype/ttnameid.h> #include "sfdriver.h" #include "ttload.h" #include "sfobjs.h" #include "sferrors.h" #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS #include "ttsbit.h" #endif #ifdef TT_CONFIG_OPTION_COLOR_LAYERS #include "ttcolr.h" #include "ttcpal.h" #endif #ifdef FT_CONFIG_OPTION_SVG #include "ttsvg.h" #endif #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #include "ttpost.h" #endif #ifdef TT_CONFIG_OPTION_BDF #include "ttbdf.h" #include <freetype/internal/services/svbdf.h> #endif #include "ttcmap.h" #include "ttkern.h" #include "ttmtx.h" #include <freetype/internal/services/svgldict.h> #include <freetype/internal/services/svpostnm.h> #include <freetype/internal/services/svsfnt.h> #include <freetype/internal/services/svttcmap.h> #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/ftmm.h> #include <freetype/internal/services/svmm.h> #endif /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sfdriver /* * SFNT TABLE SERVICE * */ static void* get_sfnt_table( TT_Face face, FT_Sfnt_Tag tag ) { void* table; switch ( tag ) { case FT_SFNT_HEAD: table = &face->header; break; case FT_SFNT_HHEA: table = &face->horizontal; break; case FT_SFNT_VHEA: table = face->vertical_info ? &face->vertical : NULL; break; case FT_SFNT_OS2: table = ( face->os2.version == 0xFFFFU ) ? NULL : &face->os2; break; case FT_SFNT_POST: table = &face->postscript; break; case FT_SFNT_MAXP: table = &face->max_profile; break; case FT_SFNT_PCLT: table = face->pclt.Version ? &face->pclt : NULL; break; default: table = NULL; } return table; } static FT_Error sfnt_table_info( TT_Face face, FT_UInt idx, FT_ULong *tag, FT_ULong *offset, FT_ULong *length ) { if ( !offset || !length ) return FT_THROW( Invalid_Argument ); if ( !tag ) *length = face->num_tables; else { if ( idx >= face->num_tables ) return FT_THROW( Table_Missing ); *tag = face->dir_tables[idx].Tag; *offset = face->dir_tables[idx].Offset; *length = face->dir_tables[idx].Length; } return FT_Err_Ok; } FT_DEFINE_SERVICE_SFNT_TABLEREC( sfnt_service_sfnt_table, (FT_SFNT_TableLoadFunc)tt_face_load_any, /* load_table */ (FT_SFNT_TableGetFunc) get_sfnt_table, /* get_table */ (FT_SFNT_TableInfoFunc)sfnt_table_info /* table_info */ ) #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES /* * GLYPH DICT SERVICE * */ static FT_Error sfnt_get_glyph_name( FT_Face face, FT_UInt glyph_index, FT_Pointer buffer, FT_UInt buffer_max ) { FT_String* gname; FT_Error error; error = tt_face_get_ps_name( (TT_Face)face, glyph_index, &gname ); if ( !error ) FT_STRCPYN( buffer, gname, buffer_max ); return error; } static FT_UInt sfnt_get_name_index( FT_Face face, const FT_String* glyph_name ) { TT_Face ttface = (TT_Face)face; FT_UInt i, max_gid = FT_UINT_MAX; if ( face->num_glyphs < 0 ) return 0; else if ( (FT_ULong)face->num_glyphs < FT_UINT_MAX ) max_gid = (FT_UInt)face->num_glyphs; else FT_TRACE0(( "Ignore glyph names for invalid GID 0x%08x - 0x%08lx\n", FT_UINT_MAX, face->num_glyphs )); for ( i = 0; i < max_gid; i++ ) { FT_String* gname; FT_Error error = tt_face_get_ps_name( ttface, i, &gname ); if ( error ) continue; if ( !ft_strcmp( glyph_name, gname ) ) return i; } return 0; } FT_DEFINE_SERVICE_GLYPHDICTREC( sfnt_service_glyph_dict, (FT_GlyphDict_GetNameFunc) sfnt_get_glyph_name, /* get_name */ (FT_GlyphDict_NameIndexFunc)sfnt_get_name_index /* name_index */ ) #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ /* * POSTSCRIPT NAME SERVICE * */ /* an array representing allowed ASCII characters in a PS string */ static const unsigned char sfnt_ps_map[16] = { /* 4 0 C 8 */ 0x00, 0x00, /* 0x00: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */ 0x00, 0x00, /* 0x10: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */ 0xDE, 0x7C, /* 0x20: 1 1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 */ 0xFF, 0xAF, /* 0x30: 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 */ 0xFF, 0xFF, /* 0x40: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 */ 0xFF, 0xD7, /* 0x50: 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 */ 0xFF, 0xFF, /* 0x60: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 */ 0xFF, 0x57 /* 0x70: 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 */ }; static int sfnt_is_postscript( int c ) { unsigned int cc; if ( c < 0 || c >= 0x80 ) return 0; cc = (unsigned int)c; return sfnt_ps_map[cc >> 3] & ( 1 << ( cc & 0x07 ) ); } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* Only ASCII letters and digits are taken for a variation font */ /* instance's PostScript name. */ /* */ /* `ft_isalnum' is a macro, but we need a function here, thus */ /* this definition. */ static int sfnt_is_alphanumeric( int c ) { return ft_isalnum( c ); } /* the implementation of MurmurHash3 is taken and adapted from */ /* https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp */ #define ROTL32( x, r ) ( x << r ) | ( x >> ( 32 - r ) ) static FT_UInt32 fmix32( FT_UInt32 h ) { h ^= h >> 16; h *= 0x85ebca6b; h ^= h >> 13; h *= 0xc2b2ae35; h ^= h >> 16; return h; } static void murmur_hash_3_128( const void* key, const unsigned int len, FT_UInt32 seed, void* out ) { const FT_Byte* data = (const FT_Byte*)key; const int nblocks = (int)len / 16; FT_UInt32 h1 = seed; FT_UInt32 h2 = seed; FT_UInt32 h3 = seed; FT_UInt32 h4 = seed; const FT_UInt32 c1 = 0x239b961b; const FT_UInt32 c2 = 0xab0e9789; const FT_UInt32 c3 = 0x38b34ae5; const FT_UInt32 c4 = 0xa1e38b93; const FT_UInt32* blocks = (const FT_UInt32*)( data + nblocks * 16 ); int i; for( i = -nblocks; i; i++ ) { FT_UInt32 k1 = blocks[i * 4 + 0]; FT_UInt32 k2 = blocks[i * 4 + 1]; FT_UInt32 k3 = blocks[i * 4 + 2]; FT_UInt32 k4 = blocks[i * 4 + 3]; k1 *= c1; k1 = ROTL32( k1, 15 ); k1 *= c2; h1 ^= k1; h1 = ROTL32( h1, 19 ); h1 += h2; h1 = h1 * 5 + 0x561ccd1b; k2 *= c2; k2 = ROTL32( k2, 16 ); k2 *= c3; h2 ^= k2; h2 = ROTL32( h2, 17 ); h2 += h3; h2 = h2 * 5 + 0x0bcaa747; k3 *= c3; k3 = ROTL32( k3, 17 ); k3 *= c4; h3 ^= k3; h3 = ROTL32( h3, 15 ); h3 += h4; h3 = h3 * 5 + 0x96cd1c35; k4 *= c4; k4 = ROTL32( k4, 18 ); k4 *= c1; h4 ^= k4; h4 = ROTL32( h4, 13 ); h4 += h1; h4 = h4 * 5 + 0x32ac3b17; } { const FT_Byte* tail = (const FT_Byte*)( data + nblocks * 16 ); FT_UInt32 k1 = 0; FT_UInt32 k2 = 0; FT_UInt32 k3 = 0; FT_UInt32 k4 = 0; switch ( len & 15 ) { case 15: k4 ^= (FT_UInt32)tail[14] << 16; /* fall through */ case 14: k4 ^= (FT_UInt32)tail[13] << 8; /* fall through */ case 13: k4 ^= (FT_UInt32)tail[12]; k4 *= c4; k4 = ROTL32( k4, 18 ); k4 *= c1; h4 ^= k4; /* fall through */ case 12: k3 ^= (FT_UInt32)tail[11] << 24; /* fall through */ case 11: k3 ^= (FT_UInt32)tail[10] << 16; /* fall through */ case 10: k3 ^= (FT_UInt32)tail[9] << 8; /* fall through */ case 9: k3 ^= (FT_UInt32)tail[8]; k3 *= c3; k3 = ROTL32( k3, 17 ); k3 *= c4; h3 ^= k3; /* fall through */ case 8: k2 ^= (FT_UInt32)tail[7] << 24; /* fall through */ case 7: k2 ^= (FT_UInt32)tail[6] << 16; /* fall through */ case 6: k2 ^= (FT_UInt32)tail[5] << 8; /* fall through */ case 5: k2 ^= (FT_UInt32)tail[4]; k2 *= c2; k2 = ROTL32( k2, 16 ); k2 *= c3; h2 ^= k2; /* fall through */ case 4: k1 ^= (FT_UInt32)tail[3] << 24; /* fall through */ case 3: k1 ^= (FT_UInt32)tail[2] << 16; /* fall through */ case 2: k1 ^= (FT_UInt32)tail[1] << 8; /* fall through */ case 1: k1 ^= (FT_UInt32)tail[0]; k1 *= c1; k1 = ROTL32( k1, 15 ); k1 *= c2; h1 ^= k1; } } h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len; h1 += h2; h1 += h3; h1 += h4; h2 += h1; h3 += h1; h4 += h1; h1 = fmix32( h1 ); h2 = fmix32( h2 ); h3 = fmix32( h3 ); h4 = fmix32( h4 ); h1 += h2; h1 += h3; h1 += h4; h2 += h1; h3 += h1; h4 += h1; ((FT_UInt32*)out)[0] = h1; ((FT_UInt32*)out)[1] = h2; ((FT_UInt32*)out)[2] = h3; ((FT_UInt32*)out)[3] = h4; } #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ typedef int (*char_type_func)( int c ); /* Handling of PID/EID 3/0 and 3/1 is the same. */ #define IS_WIN( n ) ( (n)->platformID == 3 && \ ( (n)->encodingID == 1 || (n)->encodingID == 0 ) ) #define IS_APPLE( n ) ( (n)->platformID == 1 && \ (n)->encodingID == 0 ) static char* get_win_string( FT_Memory memory, FT_Stream stream, TT_Name entry, char_type_func char_type, FT_Bool report_invalid_characters ) { FT_Error error; char* result = NULL; FT_String* r; FT_Char* p; FT_UInt len; if ( FT_QALLOC( result, entry->stringLength / 2 + 1 ) ) return NULL; if ( FT_STREAM_SEEK( entry->stringOffset ) || FT_FRAME_ENTER( entry->stringLength ) ) goto get_win_string_error; r = (FT_String*)result; p = (FT_Char*)stream->cursor; for ( len = entry->stringLength / 2; len > 0; len--, p += 2 ) { if ( p[0] == 0 && char_type( p[1] ) ) *r++ = p[1]; else { if ( report_invalid_characters ) FT_TRACE0(( "get_win_string:" " Character 0x%X invalid in PS name string\n", ((unsigned)p[0])*256 + (unsigned)p[1] )); break; } } if ( !len ) *r = '\0'; FT_FRAME_EXIT(); if ( !len ) return result; get_win_string_error: FT_FREE( result ); entry->stringLength = 0; entry->stringOffset = 0; FT_FREE( entry->string ); return NULL; } static char* get_apple_string( FT_Memory memory, FT_Stream stream, TT_Name entry, char_type_func char_type, FT_Bool report_invalid_characters ) { FT_Error error; char* result = NULL; FT_String* r; FT_Char* p; FT_UInt len; if ( FT_QALLOC( result, entry->stringLength + 1 ) ) return NULL; if ( FT_STREAM_SEEK( entry->stringOffset ) || FT_FRAME_ENTER( entry->stringLength ) ) goto get_apple_string_error; r = (FT_String*)result; p = (FT_Char*)stream->cursor; for ( len = entry->stringLength; len > 0; len--, p++ ) { if ( char_type( *p ) ) *r++ = *p; else { if ( report_invalid_characters ) FT_TRACE0(( "get_apple_string:" " Character `%c' (0x%X) invalid in PS name string\n", *p, *p )); break; } } if ( !len ) *r = '\0'; FT_FRAME_EXIT(); if ( !len ) return result; get_apple_string_error: FT_FREE( result ); entry->stringOffset = 0; entry->stringLength = 0; FT_FREE( entry->string ); return NULL; } static FT_Bool sfnt_get_name_id( TT_Face face, FT_UShort id, FT_Int *win, FT_Int *apple ) { FT_Int n; *win = -1; *apple = -1; for ( n = 0; n < face->num_names; n++ ) { TT_Name name = face->name_table.names + n; if ( name->nameID == id && name->stringLength > 0 ) { if ( IS_WIN( name ) && ( name->languageID == 0x409 || *win == -1 ) ) *win = n; if ( IS_APPLE( name ) && ( name->languageID == 0 || *apple == -1 ) ) *apple = n; } } return ( *win >= 0 ) || ( *apple >= 0 ); } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* The maximum length of an axis value descriptor. We need 65536 different values for the decimal fraction; this fits nicely into five decimal places. Consequently, it consists of . the minus sign if the number is negative, . up to five characters for the digits before the decimal point, . the decimal point if there is a fractional part, and . up to five characters for the digits after the decimal point. We also need one byte for the leading `_' character and up to four bytes for the axis tag. */ #define MAX_VALUE_DESCRIPTOR_LEN ( 1 + 5 + 1 + 5 + 1 + 4 ) /* the maximum length of PostScript font names */ #define MAX_PS_NAME_LEN 127 /* * Find the shortest decimal representation of a 16.16 fixed point * number. The function fills `buf' with the result, returning a pointer * to the position after the representation's last byte. */ static char* fixed2float( FT_Int fixed, char* buf ) { char* p; char* q; char tmp[5]; FT_Int int_part; FT_Int frac_part; FT_Int i; p = buf; if ( fixed == 0 ) { *p++ = '0'; return p; } if ( fixed < 0 ) { *p++ = '-'; fixed = NEG_INT( fixed ); } int_part = ( fixed >> 16 ) & 0xFFFF; frac_part = fixed & 0xFFFF; /* get digits of integer part (in reverse order) */ q = tmp; while ( int_part > 0 ) { *q++ = '0' + int_part % 10; int_part /= 10; } /* copy digits in correct order to buffer */ while ( q > tmp ) *p++ = *--q; if ( !frac_part ) return p; /* save position of point */ q = p; *p++ = '.'; /* apply rounding */ frac_part = frac_part * 10 + 5; /* get digits of fractional part */ for ( i = 0; i < 5; i++ ) { *p++ = '0' + (char)( frac_part / 0x10000L ); frac_part %= 0x10000L; if ( !frac_part ) break; frac_part *= 10; } /* If the remainder stored in `frac_part' (after the last FOR loop) is smaller than 34480*10, the resulting decimal value minus 0.00001 is an equivalent representation of `fixed'. The above FOR loop always finds the larger of the two values; I verified this by iterating over all possible fixed point numbers. If the remainder is 17232*10, both values are equally good, and we take the next even number (following IEEE 754's `round to nearest, ties to even' rounding rule). If the remainder is smaller than 17232*10, the lower of the two numbers is nearer to the exact result (values 17232 and 34480 were also found by testing all possible fixed point values). We use this to find a shorter decimal representation. If not ending with digit zero, we take the representation with less error. */ p--; if ( p - q == 5 ) /* five digits? */ { /* take the representation that has zero as the last digit */ if ( frac_part < 34480 * 10 && *p == '1' ) *p = '0'; /* otherwise use the one with less error */ else if ( frac_part == 17232 * 10 && *p & 1 ) *p -= 1; else if ( frac_part < 17232 * 10 && *p != '0' ) *p -= 1; } /* remove trailing zeros */ while ( *p == '0' ) *p-- = '\0'; return p + 1; } static const char hexdigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; static const char* sfnt_get_var_ps_name( TT_Face face ) { FT_Error error; FT_Memory memory = face->root.memory; FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; FT_UInt num_coords; FT_Fixed* coords; FT_MM_Var* mm_var; FT_Int found, win, apple; FT_UInt i, j; char* result = NULL; char* p; if ( !face->var_postscript_prefix ) { FT_UInt len; /* check whether we have a Variations PostScript Name Prefix */ found = sfnt_get_name_id( face, TT_NAME_ID_VARIATIONS_PREFIX, &win, &apple ); if ( !found ) { /* otherwise use the typographic family name */ found = sfnt_get_name_id( face, TT_NAME_ID_TYPOGRAPHIC_FAMILY, &win, &apple ); } if ( !found ) { /* as a last resort we try the family name; note that this is */ /* not in the Adobe TechNote, but GX fonts (which predate the */ /* TechNote) benefit from this behaviour */ found = sfnt_get_name_id( face, TT_NAME_ID_FONT_FAMILY, &win, &apple ); } if ( !found ) { FT_TRACE0(( "sfnt_get_var_ps_name:" " Can't construct PS name prefix for font instances\n" )); return NULL; } /* prefer Windows entries over Apple */ if ( win != -1 ) result = get_win_string( face->root.memory, face->name_table.stream, face->name_table.names + win, sfnt_is_alphanumeric, 0 ); if ( !result && apple != -1 ) result = get_apple_string( face->root.memory, face->name_table.stream, face->name_table.names + apple, sfnt_is_alphanumeric, 0 ); if ( !result ) { FT_TRACE0(( "sfnt_get_var_ps_name:" " No valid PS name prefix for font instances found\n" )); return NULL; } len = ft_strlen( result ); /* sanitize if necessary; we reserve space for 36 bytes (a 128bit */ /* checksum as a hex number, preceded by `-' and followed by three */ /* ASCII dots, to be used if the constructed PS name would be too */ /* long); this is also sufficient for a single instance */ if ( len > MAX_PS_NAME_LEN - ( 1 + 32 + 3 ) ) { len = MAX_PS_NAME_LEN - ( 1 + 32 + 3 ); result[len] = '\0'; FT_TRACE0(( "sfnt_get_var_ps_name:" " Shortening variation PS name prefix\n" )); FT_TRACE0(( " " " to %d characters\n", len )); } face->var_postscript_prefix = result; face->var_postscript_prefix_len = len; } mm->get_var_blend( FT_FACE( face ), &num_coords, &coords, NULL, &mm_var ); if ( FT_IS_NAMED_INSTANCE( FT_FACE( face ) ) && !FT_IS_VARIATION( FT_FACE( face ) ) ) { SFNT_Service sfnt = (SFNT_Service)face->sfnt; FT_Long instance = ( ( face->root.face_index & 0x7FFF0000L ) >> 16 ) - 1; FT_UInt psid = mm_var->namedstyle[instance].psid; char* ps_name = NULL; /* try first to load the name string with index `postScriptNameID' */ if ( psid == 6 || ( psid > 255 && psid < 32768 ) ) (void)sfnt->get_name( face, (FT_UShort)psid, &ps_name ); if ( ps_name ) { result = ps_name; p = result + ft_strlen( result ) + 1; goto check_length; } else { /* otherwise construct a name using `subfamilyNameID' */ FT_UInt strid = mm_var->namedstyle[instance].strid; char* subfamily_name; char* s; (void)sfnt->get_name( face, (FT_UShort)strid, &subfamily_name ); if ( !subfamily_name ) { FT_TRACE1(( "sfnt_get_var_ps_name:" " can't construct named instance PS name;\n" )); FT_TRACE1(( " " " trying to construct normal instance PS name\n" )); goto construct_instance_name; } /* after the prefix we have character `-' followed by the */ /* subfamily name (using only characters a-z, A-Z, and 0-9) */ if ( FT_QALLOC( result, face->var_postscript_prefix_len + 1 + ft_strlen( subfamily_name ) + 1 ) ) return NULL; ft_strcpy( result, face->var_postscript_prefix ); p = result + face->var_postscript_prefix_len; *p++ = '-'; s = subfamily_name; while ( *s ) { if ( ft_isalnum( *s ) ) *p++ = *s; s++; } *p++ = '\0'; FT_FREE( subfamily_name ); } } else { FT_Var_Axis* axis; construct_instance_name: axis = mm_var->axis; if ( FT_QALLOC( result, face->var_postscript_prefix_len + num_coords * MAX_VALUE_DESCRIPTOR_LEN + 1 ) ) return NULL; p = result; ft_strcpy( p, face->var_postscript_prefix ); p += face->var_postscript_prefix_len; for ( i = 0; i < num_coords; i++, coords++, axis++ ) { char t; /* omit axis value descriptor if it is identical */ /* to the default axis value */ if ( *coords == axis->def ) continue; *p++ = '_'; p = fixed2float( *coords, p ); t = (char)( axis->tag >> 24 ); if ( t != ' ' && ft_isalnum( t ) ) *p++ = t; t = (char)( axis->tag >> 16 ); if ( t != ' ' && ft_isalnum( t ) ) *p++ = t; t = (char)( axis->tag >> 8 ); if ( t != ' ' && ft_isalnum( t ) ) *p++ = t; t = (char)axis->tag; if ( t != ' ' && ft_isalnum( t ) ) *p++ = t; } *p++ = '\0'; } check_length: if ( p - result > MAX_PS_NAME_LEN ) { /* the PS name is too long; replace the part after the prefix with */ /* a checksum; we use MurmurHash 3 with a hash length of 128 bit */ FT_UInt32 seed = 123456789; FT_UInt32 hash[4]; FT_UInt32* h; murmur_hash_3_128( result, p - result, seed, hash ); p = result + face->var_postscript_prefix_len; *p++ = '-'; /* we convert the hash value to hex digits from back to front */ p += 32 + 3; h = hash + 3; *p-- = '\0'; *p-- = '.'; *p-- = '.'; *p-- = '.'; for ( i = 0; i < 4; i++, h-- ) { FT_UInt32 v = *h; for ( j = 0; j < 8; j++ ) { *p-- = hexdigits[v & 0xF]; v >>= 4; } } } return result; } #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ static const char* sfnt_get_ps_name( TT_Face face ) { FT_Int found, win, apple; const char* result = NULL; if ( face->postscript_name ) return face->postscript_name; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT if ( face->blend && ( FT_IS_NAMED_INSTANCE( FT_FACE( face ) ) || FT_IS_VARIATION( FT_FACE( face ) ) ) ) { face->postscript_name = sfnt_get_var_ps_name( face ); return face->postscript_name; } #endif /* scan the name table to see whether we have a Postscript name here, */ /* either in Macintosh or Windows platform encodings */ found = sfnt_get_name_id( face, TT_NAME_ID_PS_NAME, &win, &apple ); if ( !found ) return NULL; /* prefer Windows entries over Apple */ if ( win != -1 ) result = get_win_string( face->root.memory, face->name_table.stream, face->name_table.names + win, sfnt_is_postscript, 1 ); if ( !result && apple != -1 ) result = get_apple_string( face->root.memory, face->name_table.stream, face->name_table.names + apple, sfnt_is_postscript, 1 ); face->postscript_name = result; return result; } FT_DEFINE_SERVICE_PSFONTNAMEREC( sfnt_service_ps_name, (FT_PsName_GetFunc)sfnt_get_ps_name /* get_ps_font_name */ ) /* * TT CMAP INFO */ FT_DEFINE_SERVICE_TTCMAPSREC( tt_service_get_cmap_info, (TT_CMap_Info_GetFunc)tt_get_cmap_info /* get_cmap_info */ ) #ifdef TT_CONFIG_OPTION_BDF static FT_Error sfnt_get_charset_id( TT_Face face, const char* *acharset_encoding, const char* *acharset_registry ) { BDF_PropertyRec encoding, registry; FT_Error error; /* XXX: I don't know whether this is correct, since * tt_face_find_bdf_prop only returns something correct if we have * previously selected a size that is listed in the BDF table. * Should we change the BDF table format to include single offsets * for `CHARSET_REGISTRY' and `CHARSET_ENCODING'? */ error = tt_face_find_bdf_prop( face, "CHARSET_REGISTRY", &registry ); if ( !error ) { error = tt_face_find_bdf_prop( face, "CHARSET_ENCODING", &encoding ); if ( !error ) { if ( registry.type == BDF_PROPERTY_TYPE_ATOM && encoding.type == BDF_PROPERTY_TYPE_ATOM ) { *acharset_encoding = encoding.u.atom; *acharset_registry = registry.u.atom; } else error = FT_THROW( Invalid_Argument ); } } return error; } FT_DEFINE_SERVICE_BDFRec( sfnt_service_bdf, (FT_BDF_GetCharsetIdFunc)sfnt_get_charset_id, /* get_charset_id */ (FT_BDF_GetPropertyFunc) tt_face_find_bdf_prop /* get_property */ ) #endif /* TT_CONFIG_OPTION_BDF */ /* * SERVICE LIST */ #if defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES && defined TT_CONFIG_OPTION_BDF FT_DEFINE_SERVICEDESCREC5( sfnt_services, FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict, FT_SERVICE_ID_BDF, &sfnt_service_bdf, FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) #elif defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES FT_DEFINE_SERVICEDESCREC4( sfnt_services, FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict, FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) #elif defined TT_CONFIG_OPTION_BDF FT_DEFINE_SERVICEDESCREC4( sfnt_services, FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, FT_SERVICE_ID_BDF, &sfnt_service_bdf, FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) #else FT_DEFINE_SERVICEDESCREC3( sfnt_services, FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name, FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info ) #endif FT_CALLBACK_DEF( FT_Module_Interface ) sfnt_get_interface( FT_Module module, const char* module_interface ) { FT_UNUSED( module ); return ft_service_list_lookup( sfnt_services, module_interface ); } #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS #define PUT_EMBEDDED_BITMAPS( a ) a #else #define PUT_EMBEDDED_BITMAPS( a ) NULL #endif #ifdef TT_CONFIG_OPTION_COLOR_LAYERS #define PUT_COLOR_LAYERS( a ) a #else #define PUT_COLOR_LAYERS( a ) NULL #endif #ifdef FT_CONFIG_OPTION_SVG #define PUT_SVG_SUPPORT( a ) a #else #define PUT_SVG_SUPPORT( a ) NULL #endif #define PUT_COLOR_LAYERS_V1( a ) PUT_COLOR_LAYERS( a ) #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #define PUT_PS_NAMES( a ) a #else #define PUT_PS_NAMES( a ) NULL #endif FT_DEFINE_SFNT_INTERFACE( sfnt_interface, tt_face_goto_table, /* TT_Loader_GotoTableFunc goto_table */ sfnt_init_face, /* TT_Init_Face_Func init_face */ sfnt_load_face, /* TT_Load_Face_Func load_face */ sfnt_done_face, /* TT_Done_Face_Func done_face */ sfnt_get_interface, /* FT_Module_Requester get_interface */ tt_face_load_any, /* TT_Load_Any_Func load_any */ tt_face_load_head, /* TT_Load_Table_Func load_head */ tt_face_load_hhea, /* TT_Load_Metrics_Func load_hhea */ tt_face_load_cmap, /* TT_Load_Table_Func load_cmap */ tt_face_load_maxp, /* TT_Load_Table_Func load_maxp */ tt_face_load_os2, /* TT_Load_Table_Func load_os2 */ tt_face_load_post, /* TT_Load_Table_Func load_post */ tt_face_load_name, /* TT_Load_Table_Func load_name */ tt_face_free_name, /* TT_Free_Table_Func free_name */ tt_face_load_kern, /* TT_Load_Table_Func load_kern */ tt_face_load_gasp, /* TT_Load_Table_Func load_gasp */ tt_face_load_pclt, /* TT_Load_Table_Func load_init */ /* see `ttload.h' */ PUT_EMBEDDED_BITMAPS( tt_face_load_bhed ), /* TT_Load_Table_Func load_bhed */ PUT_EMBEDDED_BITMAPS( tt_face_load_sbit_image ), /* TT_Load_SBit_Image_Func load_sbit_image */ /* see `ttpost.h' */ PUT_PS_NAMES( tt_face_get_ps_name ), /* TT_Get_PS_Name_Func get_psname */ PUT_PS_NAMES( tt_face_free_ps_names ), /* TT_Free_Table_Func free_psnames */ /* since version 2.1.8 */ tt_face_get_kerning, /* TT_Face_GetKerningFunc get_kerning */ /* since version 2.2 */ tt_face_load_font_dir, /* TT_Load_Table_Func load_font_dir */ tt_face_load_hmtx, /* TT_Load_Metrics_Func load_hmtx */ /* see `ttsbit.h' and `sfnt.h' */ PUT_EMBEDDED_BITMAPS( tt_face_load_sbit ), /* TT_Load_Table_Func load_eblc */ PUT_EMBEDDED_BITMAPS( tt_face_free_sbit ), /* TT_Free_Table_Func free_eblc */ PUT_EMBEDDED_BITMAPS( tt_face_set_sbit_strike ), /* TT_Set_SBit_Strike_Func set_sbit_strike */ PUT_EMBEDDED_BITMAPS( tt_face_load_strike_metrics ), /* TT_Load_Strike_Metrics_Func load_strike_metrics */ PUT_COLOR_LAYERS( tt_face_load_cpal ), /* TT_Load_Table_Func load_cpal */ PUT_COLOR_LAYERS( tt_face_load_colr ), /* TT_Load_Table_Func load_colr */ PUT_COLOR_LAYERS( tt_face_free_cpal ), /* TT_Free_Table_Func free_cpal */ PUT_COLOR_LAYERS( tt_face_free_colr ), /* TT_Free_Table_Func free_colr */ PUT_COLOR_LAYERS( tt_face_palette_set ), /* TT_Set_Palette_Func set_palette */ PUT_COLOR_LAYERS( tt_face_get_colr_layer ), /* TT_Get_Colr_Layer_Func get_colr_layer */ PUT_COLOR_LAYERS_V1( tt_face_get_colr_glyph_paint ), /* TT_Get_Color_Glyph_Paint_Func get_colr_glyph_paint */ PUT_COLOR_LAYERS_V1( tt_face_get_color_glyph_clipbox ), /* TT_Get_Color_Glyph_ClipBox_Func get_clipbox */ PUT_COLOR_LAYERS_V1( tt_face_get_paint_layers ), /* TT_Get_Paint_Layers_Func get_paint_layers */ PUT_COLOR_LAYERS_V1( tt_face_get_colorline_stops ), /* TT_Get_Paint get_paint */ PUT_COLOR_LAYERS_V1( tt_face_get_paint ), /* TT_Get_Colorline_Stops_Func get_colorline_stops */ PUT_COLOR_LAYERS( tt_face_colr_blend_layer ), /* TT_Blend_Colr_Func colr_blend */ tt_face_get_metrics, /* TT_Get_Metrics_Func get_metrics */ tt_face_get_name, /* TT_Get_Name_Func get_name */ sfnt_get_name_id, /* TT_Get_Name_ID_Func get_name_id */ PUT_SVG_SUPPORT( tt_face_load_svg ), /* TT_Load_Table_Func load_svg */ PUT_SVG_SUPPORT( tt_face_free_svg ), /* TT_Free_Table_Func free_svg */ PUT_SVG_SUPPORT( tt_face_load_svg_doc ) /* TT_Load_Svg_Doc_Func load_svg_doc */ ) FT_DEFINE_MODULE( sfnt_module_class, 0, /* not a font driver or renderer */ sizeof ( FT_ModuleRec ), "sfnt", /* driver name */ 0x10000L, /* driver version 1.0 */ 0x20000L, /* driver requires FreeType 2.0 or higher */ (const void*)&sfnt_interface, /* module specific interface */ (FT_Module_Constructor)NULL, /* module_init */ (FT_Module_Destructor) NULL, /* module_done */ (FT_Module_Requester) sfnt_get_interface /* get_interface */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfdriver.c
C++
gpl-3.0
35,903
/**************************************************************************** * * sfdriver.h * * High-level SFNT driver interface (specification). * * Copyright (C) 1996-2022 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 SFDRIVER_H_ #define SFDRIVER_H_ #include <freetype/ftmodapi.h> FT_BEGIN_HEADER FT_DECLARE_MODULE( sfnt_module_class ) FT_END_HEADER #endif /* SFDRIVER_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfdriver.h
C++
gpl-3.0
740
/**************************************************************************** * * sferrors.h * * SFNT error codes (specification only). * * Copyright (C) 2001-2022 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. * */ /************************************************************************** * * This file is used to define the SFNT error enumeration constants. * */ #ifndef SFERRORS_H_ #define SFERRORS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX SFNT_Err_ #define FT_ERR_BASE FT_Mod_Err_SFNT #include <freetype/fterrors.h> #endif /* SFERRORS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sferrors.h
C++
gpl-3.0
966
/**************************************************************************** * * sfnt.c * * Single object library component. * * Copyright (C) 1996-2022 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "pngshim.c" #include "sfdriver.c" #include "sfobjs.c" #include "sfwoff.c" #include "sfwoff2.c" #include "ttbdf.c" #include "ttcmap.c" #include "ttcolr.c" #include "ttcpal.c" #include "ttsvg.c" #include "ttkern.c" #include "ttload.c" #include "ttmtx.c" #include "ttpost.c" #include "ttsbit.c" #include "woff2tags.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfnt.c
C++
gpl-3.0
908
/**************************************************************************** * * sfobjs.c * * SFNT object management (base). * * Copyright (C) 1996-2022 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 "sfobjs.h" #include "ttload.h" #include "ttcmap.h" #include "ttkern.h" #include "sfwoff.h" #include "sfwoff2.h" #include <freetype/internal/sfnt.h> #include <freetype/internal/ftdebug.h> #include <freetype/ttnameid.h> #include <freetype/tttags.h> #include <freetype/internal/services/svpscmap.h> #include <freetype/ftsnames.h> #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/internal/services/svmm.h> #include <freetype/internal/services/svmetric.h> #endif #include "sferrors.h" #ifdef TT_CONFIG_OPTION_BDF #include "ttbdf.h" #endif /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sfobjs /* convert a UTF-16 name entry to ASCII */ static FT_String* tt_name_ascii_from_utf16( TT_Name entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength / 2; if ( FT_QNEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = FT_NEXT_USHORT( read ); if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; } /* convert an Apple Roman or symbol name entry to ASCII */ static FT_String* tt_name_ascii_from_other( TT_Name entry, FT_Memory memory ) { FT_String* string = NULL; FT_UInt len, code, n; FT_Byte* read = (FT_Byte*)entry->string; FT_Error error; len = (FT_UInt)entry->stringLength; if ( FT_QNEW_ARRAY( string, len + 1 ) ) return NULL; for ( n = 0; n < len; n++ ) { code = *read++; if ( code == 0 ) break; if ( code < 32 || code > 127 ) code = '?'; string[n] = (char)code; } string[n] = 0; return string; } typedef FT_String* (*TT_Name_ConvertFunc)( TT_Name entry, FT_Memory memory ); /* documentation is in sfnt.h */ FT_LOCAL_DEF( FT_Error ) tt_face_get_name( TT_Face face, FT_UShort nameid, FT_String** name ) { FT_Memory memory = face->root.memory; FT_Error error = FT_Err_Ok; FT_String* result = NULL; FT_UShort n; TT_Name rec; FT_Int found_apple = -1; FT_Int found_apple_roman = -1; FT_Int found_apple_english = -1; FT_Int found_win = -1; FT_Int found_unicode = -1; FT_Bool is_english = 0; TT_Name_ConvertFunc convert; FT_ASSERT( name ); rec = face->name_table.names; for ( n = 0; n < face->num_names; n++, rec++ ) { /* According to the OpenType 1.3 specification, only Microsoft or */ /* Apple platform IDs might be used in the `name' table. The */ /* `Unicode' platform is reserved for the `cmap' table, and the */ /* `ISO' one is deprecated. */ /* */ /* However, the Apple TrueType specification doesn't say the same */ /* thing and goes to suggest that all Unicode `name' table entries */ /* should be coded in UTF-16 (in big-endian format I suppose). */ /* */ if ( rec->nameID == nameid && rec->stringLength > 0 ) { switch ( rec->platformID ) { case TT_PLATFORM_APPLE_UNICODE: case TT_PLATFORM_ISO: /* there is `languageID' to check there. We should use this */ /* field only as a last solution when nothing else is */ /* available. */ /* */ found_unicode = n; break; case TT_PLATFORM_MACINTOSH: /* This is a bit special because some fonts will use either */ /* an English language id, or a Roman encoding id, to indicate */ /* the English version of its font name. */ /* */ if ( rec->languageID == TT_MAC_LANGID_ENGLISH ) found_apple_english = n; else if ( rec->encodingID == TT_MAC_ID_ROMAN ) found_apple_roman = n; break; case TT_PLATFORM_MICROSOFT: /* we only take a non-English name when there is nothing */ /* else available in the font */ /* */ if ( found_win == -1 || ( rec->languageID & 0x3FF ) == 0x009 ) { switch ( rec->encodingID ) { case TT_MS_ID_SYMBOL_CS: case TT_MS_ID_UNICODE_CS: case TT_MS_ID_UCS_4: is_english = FT_BOOL( ( rec->languageID & 0x3FF ) == 0x009 ); found_win = n; break; default: ; } } break; default: ; } } } found_apple = found_apple_roman; if ( found_apple_english >= 0 ) found_apple = found_apple_english; /* some fonts contain invalid Unicode or Macintosh formatted entries; */ /* we will thus favor names encoded in Windows formats if available */ /* (provided it is an English name) */ /* */ convert = NULL; if ( found_win >= 0 && !( found_apple >= 0 && !is_english ) ) { rec = face->name_table.names + found_win; switch ( rec->encodingID ) { /* all Unicode strings are encoded using UTF-16BE */ case TT_MS_ID_UNICODE_CS: case TT_MS_ID_SYMBOL_CS: convert = tt_name_ascii_from_utf16; break; case TT_MS_ID_UCS_4: /* Apparently, if this value is found in a name table entry, it is */ /* documented as `full Unicode repertoire'. Experience with the */ /* MsGothic font shipped with Windows Vista shows that this really */ /* means UTF-16 encoded names (UCS-4 values are only used within */ /* charmaps). */ convert = tt_name_ascii_from_utf16; break; default: ; } } else if ( found_apple >= 0 ) { rec = face->name_table.names + found_apple; convert = tt_name_ascii_from_other; } else if ( found_unicode >= 0 ) { rec = face->name_table.names + found_unicode; convert = tt_name_ascii_from_utf16; } if ( rec && convert ) { if ( !rec->string ) { FT_Stream stream = face->name_table.stream; if ( FT_QNEW_ARRAY ( rec->string, rec->stringLength ) || FT_STREAM_SEEK( rec->stringOffset ) || FT_STREAM_READ( rec->string, rec->stringLength ) ) { FT_FREE( rec->string ); rec->stringLength = 0; result = NULL; goto Exit; } } result = convert( rec, memory ); } Exit: *name = result; return error; } static FT_Encoding sfnt_find_encoding( int platform_id, int encoding_id ) { typedef struct TEncoding_ { int platform_id; int encoding_id; FT_Encoding encoding; } TEncoding; static const TEncoding tt_encodings[] = { { TT_PLATFORM_ISO, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_APPLE_UNICODE, -1, FT_ENCODING_UNICODE }, { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, FT_ENCODING_SJIS }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_PRC, FT_ENCODING_PRC }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, FT_ENCODING_BIG5 }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, FT_ENCODING_WANSUNG }, { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, FT_ENCODING_JOHAB } }; const TEncoding *cur, *limit; cur = tt_encodings; limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] ); for ( ; cur < limit; cur++ ) { if ( cur->platform_id == platform_id ) { if ( cur->encoding_id == encoding_id || cur->encoding_id == -1 ) return cur->encoding; } } return FT_ENCODING_NONE; } /* Fill in face->ttc_header. If the font is not a TTC, it is */ /* synthesized into a TTC with one offset table. */ static FT_Error sfnt_open_font( FT_Stream stream, TT_Face face, FT_Int* face_instance_index, FT_Long* woff2_num_faces ) { FT_Memory memory = stream->memory; FT_Error error; FT_ULong tag, offset; static const FT_Frame_Field ttc_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TTC_HeaderRec FT_FRAME_START( 8 ), FT_FRAME_LONG( version ), FT_FRAME_LONG( count ), /* this is ULong in the specs */ FT_FRAME_END }; #ifndef FT_CONFIG_OPTION_USE_BROTLI FT_UNUSED( face_instance_index ); FT_UNUSED( woff2_num_faces ); #endif face->ttc_header.tag = 0; face->ttc_header.version = 0; face->ttc_header.count = 0; #if defined( FT_CONFIG_OPTION_USE_ZLIB ) || \ defined( FT_CONFIG_OPTION_USE_BROTLI ) retry: #endif offset = FT_STREAM_POS(); if ( FT_READ_ULONG( tag ) ) return error; #ifdef FT_CONFIG_OPTION_USE_ZLIB if ( tag == TTAG_wOFF ) { FT_TRACE2(( "sfnt_open_font: file is a WOFF; synthesizing SFNT\n" )); if ( FT_STREAM_SEEK( offset ) ) return error; error = woff_open_font( stream, face ); if ( error ) return error; /* Swap out stream and retry! */ stream = face->root.stream; goto retry; } #endif #ifdef FT_CONFIG_OPTION_USE_BROTLI if ( tag == TTAG_wOF2 ) { FT_TRACE2(( "sfnt_open_font: file is a WOFF2; synthesizing SFNT\n" )); if ( FT_STREAM_SEEK( offset ) ) return error; error = woff2_open_font( stream, face, face_instance_index, woff2_num_faces ); if ( error ) return error; /* Swap out stream and retry! */ stream = face->root.stream; goto retry; } #endif if ( tag != 0x00010000UL && tag != TTAG_ttcf && tag != TTAG_OTTO && tag != TTAG_true && tag != TTAG_typ1 && tag != TTAG_0xA5kbd && tag != TTAG_0xA5lst && tag != 0x00020000UL ) { FT_TRACE2(( " not a font using the SFNT container format\n" )); return FT_THROW( Unknown_File_Format ); } face->ttc_header.tag = TTAG_ttcf; if ( tag == TTAG_ttcf ) { FT_Int n; FT_TRACE3(( "sfnt_open_font: file is a collection\n" )); if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) ) return error; FT_TRACE3(( " with %ld subfonts\n", face->ttc_header.count )); if ( face->ttc_header.count == 0 ) return FT_THROW( Invalid_Table ); /* a rough size estimate: let's conservatively assume that there */ /* is just a single table info in each subfont header (12 + 16*1 = */ /* 28 bytes), thus we have (at least) `12 + 4*count' bytes for the */ /* size of the TTC header plus `28*count' bytes for all subfont */ /* headers */ if ( (FT_ULong)face->ttc_header.count > stream->size / ( 28 + 4 ) ) return FT_THROW( Array_Too_Large ); /* now read the offsets of each font in the file */ if ( FT_QNEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) ) return error; if ( FT_FRAME_ENTER( face->ttc_header.count * 4L ) ) return error; for ( n = 0; n < face->ttc_header.count; n++ ) face->ttc_header.offsets[n] = FT_GET_ULONG(); FT_FRAME_EXIT(); } else { FT_TRACE3(( "sfnt_open_font: synthesize TTC\n" )); face->ttc_header.version = 1 << 16; face->ttc_header.count = 1; if ( FT_QNEW( face->ttc_header.offsets ) ) return error; face->ttc_header.offsets[0] = offset; } return error; } FT_LOCAL_DEF( FT_Error ) sfnt_init_face( FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error; FT_Library library = face->root.driver->root.library; SFNT_Service sfnt; FT_Int face_index; FT_Long woff2_num_faces = 0; /* for now, parameters are unused */ FT_UNUSED( num_params ); FT_UNUSED( params ); sfnt = (SFNT_Service)face->sfnt; if ( !sfnt ) { sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) { FT_ERROR(( "sfnt_init_face: cannot access `sfnt' module\n" )); return FT_THROW( Missing_Module ); } face->sfnt = sfnt; face->goto_table = sfnt->goto_table; } FT_FACE_FIND_GLOBAL_SERVICE( face, face->psnames, POSTSCRIPT_CMAPS ); #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT if ( !face->mm ) { /* we want the MM interface from the `truetype' module only */ FT_Module tt_module = FT_Get_Module( library, "truetype" ); face->mm = ft_module_get_service( tt_module, FT_SERVICE_ID_MULTI_MASTERS, 0 ); } if ( !face->var ) { /* we want the metrics variations interface */ /* from the `truetype' module only */ FT_Module tt_module = FT_Get_Module( library, "truetype" ); face->var = ft_module_get_service( tt_module, FT_SERVICE_ID_METRICS_VARIATIONS, 0 ); } #endif FT_TRACE2(( "SFNT driver\n" )); error = sfnt_open_font( stream, face, &face_instance_index, &woff2_num_faces ); if ( error ) return error; /* Stream may have changed in sfnt_open_font. */ stream = face->root.stream; FT_TRACE2(( "sfnt_init_face: %p (index %d)\n", (void *)face, face_instance_index )); face_index = FT_ABS( face_instance_index ) & 0xFFFF; /* value -(N+1) requests information on index N */ if ( face_instance_index < 0 && face_index > 0 ) face_index--; if ( face_index >= face->ttc_header.count ) { if ( face_instance_index >= 0 ) return FT_THROW( Invalid_Argument ); else face_index = 0; } if ( FT_STREAM_SEEK( face->ttc_header.offsets[face_index] ) ) return error; /* check whether we have a valid TrueType file */ error = sfnt->load_font_dir( face, stream ); if ( error ) return error; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT { FT_Memory memory = face->root.memory; FT_ULong fvar_len; FT_ULong version; FT_ULong offset; FT_UShort num_axes; FT_UShort axis_size; FT_UShort num_instances; FT_UShort instance_size; FT_Int instance_index; FT_Byte* default_values = NULL; FT_Byte* instance_values = NULL; instance_index = FT_ABS( face_instance_index ) >> 16; /* test whether current face is a GX font with named instances */ if ( face->goto_table( face, TTAG_fvar, stream, &fvar_len ) || fvar_len < 20 || FT_READ_ULONG( version ) || FT_READ_USHORT( offset ) || FT_STREAM_SKIP( 2 ) /* reserved */ || FT_READ_USHORT( num_axes ) || FT_READ_USHORT( axis_size ) || FT_READ_USHORT( num_instances ) || FT_READ_USHORT( instance_size ) ) { version = 0; offset = 0; num_axes = 0; axis_size = 0; num_instances = 0; instance_size = 0; } /* check that the data is bound by the table length */ if ( version != 0x00010000UL || axis_size != 20 || num_axes == 0 || /* `num_axes' limit implied by 16-bit `instance_size' */ num_axes > 0x3FFE || !( instance_size == 4 + 4 * num_axes || instance_size == 6 + 4 * num_axes ) || /* `num_instances' limit implied by limited range of name IDs */ num_instances > 0x7EFF || offset + axis_size * num_axes + instance_size * num_instances > fvar_len ) num_instances = 0; else face->variation_support |= TT_FACE_FLAG_VAR_FVAR; /* * As documented in the OpenType specification, an entry for the * default instance may be omitted in the named instance table. In * particular this means that even if there is no named instance * table in the font we actually do have a named instance, namely the * default instance. * * For consistency, we always want the default instance in our list * of named instances. If it is missing, we try to synthesize it * later on. Here, we have to adjust `num_instances' accordingly. */ if ( ( face->variation_support & TT_FACE_FLAG_VAR_FVAR ) && !( FT_QALLOC( default_values, num_axes * 4 ) || FT_QALLOC( instance_values, num_axes * 4 ) ) ) { /* the current stream position is 16 bytes after the table start */ FT_ULong array_start = FT_STREAM_POS() - 16 + offset; FT_ULong default_value_offset, instance_offset; FT_Byte* p; FT_UInt i; default_value_offset = array_start + 8; p = default_values; for ( i = 0; i < num_axes; i++ ) { (void)FT_STREAM_READ_AT( default_value_offset, p, 4 ); default_value_offset += axis_size; p += 4; } instance_offset = array_start + axis_size * num_axes + 4; for ( i = 0; i < num_instances; i++ ) { (void)FT_STREAM_READ_AT( instance_offset, instance_values, num_axes * 4 ); if ( !ft_memcmp( default_values, instance_values, num_axes * 4 ) ) break; instance_offset += instance_size; } if ( i == num_instances ) { /* no default instance in named instance table; */ /* we thus have to synthesize it */ num_instances++; } } FT_FREE( default_values ); FT_FREE( instance_values ); /* we don't support Multiple Master CFFs yet; */ /* note that `glyf' or `CFF2' have precedence */ if ( face->goto_table( face, TTAG_glyf, stream, 0 ) && face->goto_table( face, TTAG_CFF2, stream, 0 ) && !face->goto_table( face, TTAG_CFF, stream, 0 ) ) num_instances = 0; /* instance indices in `face_instance_index' start with index 1, */ /* thus `>' and not `>=' */ if ( instance_index > num_instances ) { if ( face_instance_index >= 0 ) return FT_THROW( Invalid_Argument ); else num_instances = 0; } face->root.style_flags = (FT_Long)num_instances << 16; } #endif face->root.num_faces = face->ttc_header.count; face->root.face_index = face_instance_index; /* `num_faces' for a WOFF2 needs to be handled separately. */ if ( woff2_num_faces ) face->root.num_faces = woff2_num_faces; return error; } #define LOAD_( x ) \ do \ { \ FT_TRACE2(( "`" #x "' " )); \ FT_TRACE3(( "-->\n" )); \ \ error = sfnt->load_ ## x( face, stream ); \ \ FT_TRACE2(( "%s\n", ( !error ) \ ? "loaded" \ : FT_ERR_EQ( error, Table_Missing ) \ ? "missing" \ : "failed to load" )); \ FT_TRACE3(( "\n" )); \ } while ( 0 ) #define LOADM_( x, vertical ) \ do \ { \ FT_TRACE2(( "`%s" #x "' ", \ vertical ? "vertical " : "" )); \ FT_TRACE3(( "-->\n" )); \ \ error = sfnt->load_ ## x( face, stream, vertical ); \ \ FT_TRACE2(( "%s\n", ( !error ) \ ? "loaded" \ : FT_ERR_EQ( error, Table_Missing ) \ ? "missing" \ : "failed to load" )); \ FT_TRACE3(( "\n" )); \ } while ( 0 ) #define GET_NAME( id, field ) \ do \ { \ error = tt_face_get_name( face, TT_NAME_ID_ ## id, field ); \ if ( error ) \ goto Exit; \ } while ( 0 ) FT_LOCAL_DEF( FT_Error ) sfnt_load_face( FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error; #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES FT_Error psnames_error; #endif FT_Bool has_outline; FT_Bool is_apple_sbit; FT_Bool has_CBLC; FT_Bool has_CBDT; FT_Bool has_EBLC; FT_Bool has_bloc; FT_Bool has_sbix; FT_Bool ignore_typographic_family = FALSE; FT_Bool ignore_typographic_subfamily = FALSE; FT_Bool ignore_sbix = FALSE; SFNT_Service sfnt = (SFNT_Service)face->sfnt; FT_UNUSED( face_instance_index ); /* Check parameters */ { FT_Int i; for ( i = 0; i < num_params; i++ ) { if ( params[i].tag == FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY ) ignore_typographic_family = TRUE; else if ( params[i].tag == FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY ) ignore_typographic_subfamily = TRUE; else if ( params[i].tag == FT_PARAM_TAG_IGNORE_SBIX ) ignore_sbix = TRUE; } } /* Load tables */ /* We now support two SFNT-based bitmapped font formats. They */ /* are recognized easily as they do not include a `glyf' */ /* table. */ /* */ /* The first format comes from Apple, and uses a table named */ /* `bhed' instead of `head' to store the font header (using */ /* the same format). It also doesn't include horizontal and */ /* vertical metrics tables (i.e. `hhea' and `vhea' tables are */ /* missing). */ /* */ /* The other format comes from Microsoft, and is used with */ /* WinCE/PocketPC. It looks like a standard TTF, except that */ /* it doesn't contain outlines. */ /* */ FT_TRACE2(( "sfnt_load_face: %p\n", (void *)face )); FT_TRACE2(( "\n" )); /* do we have outlines in there? */ #ifdef FT_CONFIG_OPTION_INCREMENTAL has_outline = FT_BOOL( face->root.internal->incremental_interface || tt_face_lookup_table( face, TTAG_glyf ) || tt_face_lookup_table( face, TTAG_CFF ) || tt_face_lookup_table( face, TTAG_CFF2 ) ); #else has_outline = FT_BOOL( tt_face_lookup_table( face, TTAG_glyf ) || tt_face_lookup_table( face, TTAG_CFF ) || tt_face_lookup_table( face, TTAG_CFF2 ) ); #endif /* check which sbit formats are present */ has_CBLC = !face->goto_table( face, TTAG_CBLC, stream, 0 ); has_CBDT = !face->goto_table( face, TTAG_CBDT, stream, 0 ); has_EBLC = !face->goto_table( face, TTAG_EBLC, stream, 0 ); has_bloc = !face->goto_table( face, TTAG_bloc, stream, 0 ); has_sbix = !face->goto_table( face, TTAG_sbix, stream, 0 ); is_apple_sbit = FALSE; if ( ignore_sbix ) has_sbix = FALSE; /* if this font doesn't contain outlines, we try to load */ /* a `bhed' table */ if ( !has_outline && sfnt->load_bhed ) { LOAD_( bhed ); is_apple_sbit = FT_BOOL( !error ); } /* load the font header (`head' table) if this isn't an Apple */ /* sbit font file */ if ( !is_apple_sbit || has_sbix ) { LOAD_( head ); if ( error ) goto Exit; } /* Ignore outlines for CBLC/CBDT fonts. */ if ( has_CBLC || has_CBDT ) has_outline = FALSE; /* OpenType 1.8.2 introduced limits to this value; */ /* however, they make sense for older SFNT fonts also */ if ( face->header.Units_Per_EM < 16 || face->header.Units_Per_EM > 16384 ) { error = FT_THROW( Invalid_Table ); goto Exit; } /* the following tables are often not present in embedded TrueType */ /* fonts within PDF documents, so don't check for them. */ LOAD_( maxp ); LOAD_( cmap ); /* the following tables are optional in PCL fonts -- */ /* don't check for errors */ LOAD_( name ); LOAD_( post ); #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES psnames_error = error; #endif /* do not load the metrics headers and tables if this is an Apple */ /* sbit font file */ if ( !is_apple_sbit ) { /* load the `hhea' and `hmtx' tables */ LOADM_( hhea, 0 ); if ( !error ) { LOADM_( hmtx, 0 ); if ( FT_ERR_EQ( error, Table_Missing ) ) { error = FT_THROW( Hmtx_Table_Missing ); #ifdef FT_CONFIG_OPTION_INCREMENTAL /* If this is an incrementally loaded font and there are */ /* overriding metrics, tolerate a missing `hmtx' table. */ if ( face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs-> get_glyph_metrics ) { face->horizontal.number_Of_HMetrics = 0; error = FT_Err_Ok; } #endif } } else if ( FT_ERR_EQ( error, Table_Missing ) ) { /* No `hhea' table necessary for SFNT Mac fonts. */ if ( face->format_tag == TTAG_true ) { FT_TRACE2(( "This is an SFNT Mac font.\n" )); has_outline = 0; error = FT_Err_Ok; } else { error = FT_THROW( Horiz_Header_Missing ); #ifdef FT_CONFIG_OPTION_INCREMENTAL /* If this is an incrementally loaded font and there are */ /* overriding metrics, tolerate a missing `hhea' table. */ if ( face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs-> get_glyph_metrics ) { face->horizontal.number_Of_HMetrics = 0; error = FT_Err_Ok; } #endif } } if ( error ) goto Exit; /* try to load the `vhea' and `vmtx' tables */ LOADM_( hhea, 1 ); if ( !error ) { LOADM_( hmtx, 1 ); if ( !error ) face->vertical_info = 1; } if ( error && FT_ERR_NEQ( error, Table_Missing ) ) goto Exit; LOAD_( os2 ); if ( error ) { /* we treat the table as missing if there are any errors */ face->os2.version = 0xFFFFU; } } /* the optional tables */ /* embedded bitmap support */ /* TODO: Replace this clumsy check for all possible sbit tables */ /* with something better (for example, by passing a parameter */ /* to suppress 'sbix' loading). */ if ( sfnt->load_eblc && ( has_CBLC || has_EBLC || has_bloc || has_sbix ) ) LOAD_( eblc ); /* colored glyph support */ if ( sfnt->load_cpal ) { LOAD_( cpal ); LOAD_( colr ); } /* OpenType-SVG glyph support */ if ( sfnt->load_svg ) LOAD_( svg ); /* consider the pclt, kerning, and gasp tables as optional */ LOAD_( pclt ); LOAD_( gasp ); LOAD_( kern ); face->root.num_glyphs = face->max_profile.numGlyphs; /* Bit 8 of the `fsSelection' field in the `OS/2' table denotes */ /* a WWS-only font face. `WWS' stands for `weight', width', and */ /* `slope', a term used by Microsoft's Windows Presentation */ /* Foundation (WPF). This flag has been introduced in version */ /* 1.5 of the OpenType specification (May 2008). */ face->root.family_name = NULL; face->root.style_name = NULL; if ( face->os2.version != 0xFFFFU && face->os2.fsSelection & 256 ) { if ( !ignore_typographic_family ) GET_NAME( TYPOGRAPHIC_FAMILY, &face->root.family_name ); if ( !face->root.family_name ) GET_NAME( FONT_FAMILY, &face->root.family_name ); if ( !ignore_typographic_subfamily ) GET_NAME( TYPOGRAPHIC_SUBFAMILY, &face->root.style_name ); if ( !face->root.style_name ) GET_NAME( FONT_SUBFAMILY, &face->root.style_name ); } else { GET_NAME( WWS_FAMILY, &face->root.family_name ); if ( !face->root.family_name && !ignore_typographic_family ) GET_NAME( TYPOGRAPHIC_FAMILY, &face->root.family_name ); if ( !face->root.family_name ) GET_NAME( FONT_FAMILY, &face->root.family_name ); GET_NAME( WWS_SUBFAMILY, &face->root.style_name ); if ( !face->root.style_name && !ignore_typographic_subfamily ) GET_NAME( TYPOGRAPHIC_SUBFAMILY, &face->root.style_name ); if ( !face->root.style_name ) GET_NAME( FONT_SUBFAMILY, &face->root.style_name ); } /* now set up root fields */ { FT_Face root = &face->root; FT_Long flags = root->face_flags; /********************************************************************** * * Compute face flags. */ if ( face->sbit_table_type == TT_SBIT_TABLE_TYPE_CBLC || face->sbit_table_type == TT_SBIT_TABLE_TYPE_SBIX || face->colr ) flags |= FT_FACE_FLAG_COLOR; /* color glyphs */ if ( has_outline == TRUE ) { /* by default (and for backward compatibility) we handle */ /* fonts with an 'sbix' table as bitmap-only */ if ( has_sbix ) flags |= FT_FACE_FLAG_SBIX; /* with 'sbix' bitmaps */ else flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */ } /* The sfnt driver only supports bitmap fonts natively, thus we */ /* don't set FT_FACE_FLAG_HINTER. */ flags |= FT_FACE_FLAG_SFNT | /* SFNT file format */ FT_FACE_FLAG_HORIZONTAL; /* horizontal data */ #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES if ( !psnames_error && face->postscript.FormatType != 0x00030000L ) flags |= FT_FACE_FLAG_GLYPH_NAMES; #endif /* fixed width font? */ if ( face->postscript.isFixedPitch ) flags |= FT_FACE_FLAG_FIXED_WIDTH; /* vertical information? */ if ( face->vertical_info ) flags |= FT_FACE_FLAG_VERTICAL; /* kerning available ? */ if ( TT_FACE_HAS_KERNING( face ) ) flags |= FT_FACE_FLAG_KERNING; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* Don't bother to load the tables unless somebody asks for them. */ /* No need to do work which will (probably) not be used. */ if ( face->variation_support & TT_FACE_FLAG_VAR_FVAR ) { if ( tt_face_lookup_table( face, TTAG_glyf ) != 0 && tt_face_lookup_table( face, TTAG_gvar ) != 0 ) flags |= FT_FACE_FLAG_MULTIPLE_MASTERS; if ( tt_face_lookup_table( face, TTAG_CFF2 ) != 0 ) flags |= FT_FACE_FLAG_MULTIPLE_MASTERS; } #endif root->face_flags = flags; /********************************************************************** * * Compute style flags. */ flags = 0; if ( has_outline == TRUE && face->os2.version != 0xFFFFU ) { /* We have an OS/2 table; use the `fsSelection' field. Bit 9 */ /* indicates an oblique font face. This flag has been */ /* introduced in version 1.5 of the OpenType specification. */ if ( face->os2.fsSelection & 512 ) /* bit 9 */ flags |= FT_STYLE_FLAG_ITALIC; else if ( face->os2.fsSelection & 1 ) /* bit 0 */ flags |= FT_STYLE_FLAG_ITALIC; if ( face->os2.fsSelection & 32 ) /* bit 5 */ flags |= FT_STYLE_FLAG_BOLD; } else { /* this is an old Mac font, use the header field */ if ( face->header.Mac_Style & 1 ) flags |= FT_STYLE_FLAG_BOLD; if ( face->header.Mac_Style & 2 ) flags |= FT_STYLE_FLAG_ITALIC; } root->style_flags |= flags; /********************************************************************** * * Polish the charmaps. * * Try to set the charmap encoding according to the platform & * encoding ID of each charmap. Emulate Unicode charmap if one * is missing. */ tt_face_build_cmaps( face ); /* ignore errors */ /* set the encoding fields */ { FT_Int m; #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES FT_Bool has_unicode = FALSE; #endif for ( m = 0; m < root->num_charmaps; m++ ) { FT_CharMap charmap = root->charmaps[m]; charmap->encoding = sfnt_find_encoding( charmap->platform_id, charmap->encoding_id ); #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES if ( charmap->encoding == FT_ENCODING_UNICODE || charmap->encoding == FT_ENCODING_MS_SYMBOL ) /* PUA */ has_unicode = TRUE; } /* synthesize Unicode charmap if one is missing */ if ( !has_unicode && root->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) { FT_CharMapRec cmaprec; cmaprec.face = root; cmaprec.platform_id = TT_PLATFORM_MICROSOFT; cmaprec.encoding_id = TT_MS_ID_UNICODE_CS; cmaprec.encoding = FT_ENCODING_UNICODE; error = FT_CMap_New( (FT_CMap_Class)&tt_cmap_unicode_class_rec, NULL, &cmaprec, NULL ); if ( error && FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) && FT_ERR_NEQ( error, Unimplemented_Feature ) ) goto Exit; error = FT_Err_Ok; #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ } } #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS /* * Now allocate the root array of FT_Bitmap_Size records and * populate them. Unfortunately, it isn't possible to indicate bit * depths in the FT_Bitmap_Size record. This is a design error. */ { FT_UInt count; count = face->sbit_num_strikes; if ( count > 0 ) { FT_Memory memory = face->root.stream->memory; FT_UShort em_size = face->header.Units_Per_EM; FT_Short avgwidth = face->os2.xAvgCharWidth; FT_Size_Metrics metrics; FT_UInt* sbit_strike_map = NULL; FT_UInt strike_idx, bsize_idx; if ( em_size == 0 || face->os2.version == 0xFFFFU ) { avgwidth = 1; em_size = 1; } /* to avoid invalid strike data in the `available_sizes' field */ /* of `FT_Face', we map `available_sizes' indices to strike */ /* indices */ if ( FT_NEW_ARRAY( root->available_sizes, count ) || FT_QNEW_ARRAY( sbit_strike_map, count ) ) goto Exit; bsize_idx = 0; for ( strike_idx = 0; strike_idx < count; strike_idx++ ) { FT_Bitmap_Size* bsize = root->available_sizes + bsize_idx; error = sfnt->load_strike_metrics( face, strike_idx, &metrics ); if ( error ) continue; bsize->height = (FT_Short)( metrics.height >> 6 ); bsize->width = (FT_Short)( ( avgwidth * metrics.x_ppem + em_size / 2 ) / em_size ); bsize->x_ppem = metrics.x_ppem << 6; bsize->y_ppem = metrics.y_ppem << 6; /* assume 72dpi */ bsize->size = metrics.y_ppem << 6; /* only use strikes with valid PPEM values */ if ( bsize->x_ppem && bsize->y_ppem ) sbit_strike_map[bsize_idx++] = strike_idx; } /* reduce array size to the actually used elements */ FT_MEM_QRENEW_ARRAY( sbit_strike_map, count, bsize_idx ); /* from now on, all strike indices are mapped */ /* using `sbit_strike_map' */ if ( bsize_idx ) { face->sbit_strike_map = sbit_strike_map; root->face_flags |= FT_FACE_FLAG_FIXED_SIZES; root->num_fixed_sizes = (FT_Int)bsize_idx; } } } #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /* a font with no bitmaps and no outlines is scalable; */ /* it has only empty glyphs then */ if ( !FT_HAS_FIXED_SIZES( root ) && !FT_IS_SCALABLE( root ) ) root->face_flags |= FT_FACE_FLAG_SCALABLE; /********************************************************************** * * Set up metrics. */ if ( FT_IS_SCALABLE( root ) || FT_HAS_SBIX( root ) ) { /* XXX What about if outline header is missing */ /* (e.g. sfnt wrapped bitmap)? */ root->bbox.xMin = face->header.xMin; root->bbox.yMin = face->header.yMin; root->bbox.xMax = face->header.xMax; root->bbox.yMax = face->header.yMax; root->units_per_EM = face->header.Units_Per_EM; /* * Computing the ascender/descender/height is tricky. * * The OpenType specification v1.8.3 says: * * [OS/2's] sTypoAscender, sTypoDescender and sTypoLineGap fields * are intended to allow applications to lay out documents in a * typographically-correct and portable fashion. * * This is somewhat at odds with the decades of backwards * compatibility, operating systems and applications doing whatever * they want, not to mention broken fonts. * * Not all fonts have an OS/2 table; in this case, we take the values * in the horizontal header, although there is nothing stopping the * values from being unreliable. Even with a OS/2 table, certain fonts * set the sTypoAscender, sTypoDescender and sTypoLineGap fields to 0 * and instead correctly set usWinAscent and usWinDescent. * * As an example, Arial Narrow is shipped as four files ARIALN.TTF, * ARIALNI.TTF, ARIALNB.TTF and ARIALNBI.TTF. Strangely, all fonts have * the same values in their sTypo* fields, except ARIALNB.ttf which * sets them to 0. All of them have different usWinAscent/Descent * values. The OS/2 table therefore cannot be trusted for computing the * text height reliably. * * As a compromise, do the following: * * 1. If the OS/2 table exists and the fsSelection bit 7 is set * (USE_TYPO_METRICS), trust the font and use the sTypo* metrics. * 2. Otherwise, use the `hhea' table's metrics. * 3. If they are zero and the OS/2 table exists, * 1. use the OS/2 table's sTypo* metrics if they are non-zero. * 2. Otherwise, use the OS/2 table's usWin* metrics. */ if ( face->os2.version != 0xFFFFU && face->os2.fsSelection & 128 ) { root->ascender = face->os2.sTypoAscender; root->descender = face->os2.sTypoDescender; root->height = root->ascender - root->descender + face->os2.sTypoLineGap; } else { root->ascender = face->horizontal.Ascender; root->descender = face->horizontal.Descender; root->height = root->ascender - root->descender + face->horizontal.Line_Gap; if ( !( root->ascender || root->descender ) ) { if ( face->os2.version != 0xFFFFU ) { if ( face->os2.sTypoAscender || face->os2.sTypoDescender ) { root->ascender = face->os2.sTypoAscender; root->descender = face->os2.sTypoDescender; root->height = root->ascender - root->descender + face->os2.sTypoLineGap; } else { root->ascender = (FT_Short)face->os2.usWinAscent; root->descender = -(FT_Short)face->os2.usWinDescent; root->height = root->ascender - root->descender; } } } } root->max_advance_width = (FT_Short)face->horizontal.advance_Width_Max; root->max_advance_height = (FT_Short)( face->vertical_info ? face->vertical.advance_Height_Max : root->height ); /* See https://www.microsoft.com/typography/otspec/post.htm -- */ /* Adjust underline position from top edge to centre of */ /* stroke to convert TrueType meaning to FreeType meaning. */ root->underline_position = face->postscript.underlinePosition - face->postscript.underlineThickness / 2; root->underline_thickness = face->postscript.underlineThickness; } } Exit: FT_TRACE2(( "sfnt_load_face: done\n" )); return error; } #undef LOAD_ #undef LOADM_ #undef GET_NAME FT_LOCAL_DEF( void ) sfnt_done_face( TT_Face face ) { FT_Memory memory; SFNT_Service sfnt; if ( !face ) return; memory = face->root.memory; sfnt = (SFNT_Service)face->sfnt; if ( sfnt ) { /* destroy the postscript names table if it is loaded */ if ( sfnt->free_psnames ) sfnt->free_psnames( face ); /* destroy the embedded bitmaps table if it is loaded */ if ( sfnt->free_eblc ) sfnt->free_eblc( face ); /* destroy color table data if it is loaded */ if ( sfnt->free_cpal ) { sfnt->free_cpal( face ); sfnt->free_colr( face ); } #ifdef FT_CONFIG_OPTION_SVG /* free SVG data */ if ( sfnt->free_svg ) sfnt->free_svg( face ); #endif } #ifdef TT_CONFIG_OPTION_BDF /* freeing the embedded BDF properties */ tt_face_free_bdf_props( face ); #endif /* freeing the kerning table */ tt_face_done_kern( face ); /* freeing the collection table */ FT_FREE( face->ttc_header.offsets ); face->ttc_header.count = 0; /* freeing table directory */ FT_FREE( face->dir_tables ); face->num_tables = 0; { FT_Stream stream = FT_FACE_STREAM( face ); /* simply release the 'cmap' table frame */ FT_FRAME_RELEASE( face->cmap_table ); face->cmap_size = 0; } face->horz_metrics_size = 0; face->vert_metrics_size = 0; /* freeing vertical metrics, if any */ if ( face->vertical_info ) { FT_FREE( face->vertical.long_metrics ); FT_FREE( face->vertical.short_metrics ); face->vertical_info = 0; } /* freeing the gasp table */ FT_FREE( face->gasp.gaspRanges ); face->gasp.numRanges = 0; /* freeing the name table */ if ( sfnt ) sfnt->free_name( face ); /* freeing family and style name */ FT_FREE( face->root.family_name ); FT_FREE( face->root.style_name ); /* freeing sbit size table */ FT_FREE( face->root.available_sizes ); FT_FREE( face->sbit_strike_map ); face->root.num_fixed_sizes = 0; FT_FREE( face->postscript_name ); #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_FREE( face->var_postscript_prefix ); #endif /* freeing glyph color palette data */ FT_FREE( face->palette_data.palette_name_ids ); FT_FREE( face->palette_data.palette_flags ); FT_FREE( face->palette_data.palette_entry_name_ids ); FT_FREE( face->palette ); face->sfnt = NULL; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfobjs.c
C++
gpl-3.0
48,557
/**************************************************************************** * * sfobjs.h * * SFNT object management (specification). * * Copyright (C) 1996-2022 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 SFOBJS_H_ #define SFOBJS_H_ #include <freetype/internal/sfnt.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) sfnt_init_face( FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter* params ); FT_LOCAL( FT_Error ) sfnt_load_face( FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter* params ); FT_LOCAL( void ) sfnt_done_face( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_get_name( TT_Face face, FT_UShort nameid, FT_String** name ); FT_END_HEADER #endif /* SFOBJS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfobjs.h
C++
gpl-3.0
1,417
/**************************************************************************** * * sfwoff.c * * WOFF format management (base). * * Copyright (C) 1996-2022 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 "sfwoff.h" #include <freetype/tttags.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/ftgzip.h> #ifdef FT_CONFIG_OPTION_USE_ZLIB /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sfwoff #define WRITE_USHORT( p, v ) \ do \ { \ *(p)++ = (FT_Byte)( (v) >> 8 ); \ *(p)++ = (FT_Byte)( (v) >> 0 ); \ \ } while ( 0 ) #define WRITE_ULONG( p, v ) \ do \ { \ *(p)++ = (FT_Byte)( (v) >> 24 ); \ *(p)++ = (FT_Byte)( (v) >> 16 ); \ *(p)++ = (FT_Byte)( (v) >> 8 ); \ *(p)++ = (FT_Byte)( (v) >> 0 ); \ \ } while ( 0 ) static void sfnt_stream_close( FT_Stream stream ) { FT_Memory memory = stream->memory; FT_FREE( stream->base ); stream->size = 0; stream->close = NULL; } FT_COMPARE_DEF( int ) compare_offsets( const void* a, const void* b ) { WOFF_Table table1 = *(WOFF_Table*)a; WOFF_Table table2 = *(WOFF_Table*)b; FT_ULong offset1 = table1->Offset; FT_ULong offset2 = table2->Offset; if ( offset1 > offset2 ) return 1; else if ( offset1 < offset2 ) return -1; else return 0; } /* Replace `face->root.stream' with a stream containing the extracted */ /* SFNT of a WOFF font. */ FT_LOCAL_DEF( FT_Error ) woff_open_font( FT_Stream stream, TT_Face face ) { FT_Memory memory = stream->memory; FT_Error error = FT_Err_Ok; WOFF_HeaderRec woff; WOFF_Table tables = NULL; WOFF_Table* indices = NULL; FT_ULong woff_offset; FT_Byte* sfnt = NULL; FT_Stream sfnt_stream = NULL; FT_Byte* sfnt_header; FT_ULong sfnt_offset; FT_Int nn; FT_Tag old_tag = 0; static const FT_Frame_Field woff_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE WOFF_HeaderRec FT_FRAME_START( 44 ), FT_FRAME_ULONG ( signature ), FT_FRAME_ULONG ( flavor ), FT_FRAME_ULONG ( length ), FT_FRAME_USHORT( num_tables ), FT_FRAME_USHORT( reserved ), FT_FRAME_ULONG ( totalSfntSize ), FT_FRAME_USHORT( majorVersion ), FT_FRAME_USHORT( minorVersion ), FT_FRAME_ULONG ( metaOffset ), FT_FRAME_ULONG ( metaLength ), FT_FRAME_ULONG ( metaOrigLength ), FT_FRAME_ULONG ( privOffset ), FT_FRAME_ULONG ( privLength ), FT_FRAME_END }; FT_ASSERT( stream == face->root.stream ); FT_ASSERT( FT_STREAM_POS() == 0 ); if ( FT_STREAM_READ_FIELDS( woff_header_fields, &woff ) ) return error; /* Make sure we don't recurse back here or hit TTC code. */ if ( woff.flavor == TTAG_wOFF || woff.flavor == TTAG_ttcf ) return FT_THROW( Invalid_Table ); /* Miscellaneous checks. */ if ( woff.length != stream->size || woff.num_tables == 0 || 44 + woff.num_tables * 20UL >= woff.length || 12 + woff.num_tables * 16UL >= woff.totalSfntSize || ( woff.totalSfntSize & 3 ) != 0 || ( woff.metaOffset == 0 && ( woff.metaLength != 0 || woff.metaOrigLength != 0 ) ) || ( woff.metaLength != 0 && woff.metaOrigLength == 0 ) || ( woff.privOffset == 0 && woff.privLength != 0 ) ) { FT_ERROR(( "woff_font_open: invalid WOFF header\n" )); return FT_THROW( Invalid_Table ); } /* Don't trust `totalSfntSize' before thorough checks. */ if ( FT_QALLOC( sfnt, 12 + woff.num_tables * 16UL ) || FT_NEW( sfnt_stream ) ) goto Exit; sfnt_header = sfnt; /* Write sfnt header. */ { FT_UInt searchRange, entrySelector, rangeShift, x; x = woff.num_tables; entrySelector = 0; while ( x ) { x >>= 1; entrySelector += 1; } entrySelector--; searchRange = ( 1 << entrySelector ) * 16; rangeShift = woff.num_tables * 16 - searchRange; WRITE_ULONG ( sfnt_header, woff.flavor ); WRITE_USHORT( sfnt_header, woff.num_tables ); WRITE_USHORT( sfnt_header, searchRange ); WRITE_USHORT( sfnt_header, entrySelector ); WRITE_USHORT( sfnt_header, rangeShift ); } /* While the entries in the sfnt header must be sorted by the */ /* tag value, the tables themselves are not. We thus have to */ /* sort them by offset and check that they don't overlap. */ if ( FT_NEW_ARRAY( tables, woff.num_tables ) || FT_NEW_ARRAY( indices, woff.num_tables ) ) goto Exit; FT_TRACE2(( "\n" )); FT_TRACE2(( " tag offset compLen origLen checksum\n" )); FT_TRACE2(( " -------------------------------------------\n" )); if ( FT_FRAME_ENTER( 20L * woff.num_tables ) ) goto Exit; for ( nn = 0; nn < woff.num_tables; nn++ ) { WOFF_Table table = tables + nn; table->Tag = FT_GET_TAG4(); table->Offset = FT_GET_ULONG(); table->CompLength = FT_GET_ULONG(); table->OrigLength = FT_GET_ULONG(); table->CheckSum = FT_GET_ULONG(); FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx %08lx\n", (FT_Char)( table->Tag >> 24 ), (FT_Char)( table->Tag >> 16 ), (FT_Char)( table->Tag >> 8 ), (FT_Char)( table->Tag ), table->Offset, table->CompLength, table->OrigLength, table->CheckSum )); if ( table->Tag <= old_tag ) { FT_FRAME_EXIT(); FT_ERROR(( "woff_font_open: table tags are not sorted\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } old_tag = table->Tag; indices[nn] = table; } FT_FRAME_EXIT(); /* Sort by offset. */ ft_qsort( indices, woff.num_tables, sizeof ( WOFF_Table ), compare_offsets ); /* Check offsets and lengths. */ woff_offset = 44 + woff.num_tables * 20L; sfnt_offset = 12 + woff.num_tables * 16L; for ( nn = 0; nn < woff.num_tables; nn++ ) { WOFF_Table table = indices[nn]; if ( table->Offset != woff_offset || table->CompLength > woff.length || table->Offset > woff.length - table->CompLength || table->OrigLength > woff.totalSfntSize || sfnt_offset > woff.totalSfntSize - table->OrigLength || table->CompLength > table->OrigLength ) { FT_ERROR(( "woff_font_open: invalid table offsets\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } table->OrigOffset = sfnt_offset; /* The offsets must be multiples of 4. */ woff_offset += ( table->CompLength + 3 ) & ~3U; sfnt_offset += ( table->OrigLength + 3 ) & ~3U; } /* * Final checks! * * We don't decode and check the metadata block. * We don't check table checksums either. * But other than those, I think we implement all * `MUST' checks from the spec. */ if ( woff.metaOffset ) { if ( woff.metaOffset != woff_offset || woff.metaOffset + woff.metaLength > woff.length ) { FT_ERROR(( "woff_font_open:" " invalid `metadata' offset or length\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } /* We have padding only ... */ woff_offset += woff.metaLength; } if ( woff.privOffset ) { /* ... if it isn't the last block. */ woff_offset = ( woff_offset + 3 ) & ~3U; if ( woff.privOffset != woff_offset || woff.privOffset + woff.privLength > woff.length ) { FT_ERROR(( "woff_font_open: invalid `private' offset or length\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } /* No padding for the last block. */ woff_offset += woff.privLength; } if ( sfnt_offset != woff.totalSfntSize || woff_offset != woff.length ) { FT_ERROR(( "woff_font_open: invalid `sfnt' table structure\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } /* Now use `totalSfntSize'. */ if ( FT_REALLOC( sfnt, 12 + woff.num_tables * 16UL, woff.totalSfntSize ) ) goto Exit; sfnt_header = sfnt + 12; /* Write the tables. */ for ( nn = 0; nn < woff.num_tables; nn++ ) { WOFF_Table table = tables + nn; /* Write SFNT table entry. */ WRITE_ULONG( sfnt_header, table->Tag ); WRITE_ULONG( sfnt_header, table->CheckSum ); WRITE_ULONG( sfnt_header, table->OrigOffset ); WRITE_ULONG( sfnt_header, table->OrigLength ); /* Write table data. */ if ( FT_STREAM_SEEK( table->Offset ) || FT_FRAME_ENTER( table->CompLength ) ) goto Exit; if ( table->CompLength == table->OrigLength ) { /* Uncompressed data; just copy. */ ft_memcpy( sfnt + table->OrigOffset, stream->cursor, table->OrigLength ); } else { /* Uncompress with zlib. */ FT_ULong output_len = table->OrigLength; error = FT_Gzip_Uncompress( memory, sfnt + table->OrigOffset, &output_len, stream->cursor, table->CompLength ); if ( error ) goto Exit1; if ( output_len != table->OrigLength ) { FT_ERROR(( "woff_font_open: compressed table length mismatch\n" )); error = FT_THROW( Invalid_Table ); goto Exit1; } } FT_FRAME_EXIT(); /* We don't check whether the padding bytes in the WOFF file are */ /* actually '\0'. For the output, however, we do set them properly. */ sfnt_offset = table->OrigOffset + table->OrigLength; while ( sfnt_offset & 3 ) { sfnt[sfnt_offset] = '\0'; sfnt_offset++; } } /* Ok! Finally ready. Swap out stream and return. */ FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize ); sfnt_stream->memory = stream->memory; sfnt_stream->close = sfnt_stream_close; FT_Stream_Free( face->root.stream, ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 ); face->root.stream = sfnt_stream; face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; Exit: FT_FREE( tables ); FT_FREE( indices ); if ( error ) { FT_FREE( sfnt ); FT_Stream_Close( sfnt_stream ); FT_FREE( sfnt_stream ); } return error; Exit1: FT_FRAME_EXIT(); goto Exit; } #undef WRITE_USHORT #undef WRITE_ULONG #else /* !FT_CONFIG_OPTION_USE_ZLIB */ /* ANSI C doesn't like empty source files */ typedef int _sfwoff_dummy; #endif /* !FT_CONFIG_OPTION_USE_ZLIB */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfwoff.c
C++
gpl-3.0
12,465
/**************************************************************************** * * sfwoff.h * * WOFFF format management (specification). * * Copyright (C) 1996-2022 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 SFWOFF_H_ #define SFWOFF_H_ #include <freetype/internal/sfnt.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_USE_ZLIB FT_LOCAL( FT_Error ) woff_open_font( FT_Stream stream, TT_Face face ); #endif FT_END_HEADER #endif /* SFWOFF_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfwoff.h
C++
gpl-3.0
865
/**************************************************************************** * * sfwoff2.c * * WOFF2 format management (base). * * Copyright (C) 2019-2022 by * Nikhil Ramakrishnan, 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 "sfwoff2.h" #include "woff2tags.h" #include <freetype/tttags.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #ifdef FT_CONFIG_OPTION_USE_BROTLI #include <brotli/decode.h> /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT sfwoff2 #define READ_255USHORT( var ) FT_SET_ERROR( Read255UShort( stream, &var ) ) #define READ_BASE128( var ) FT_SET_ERROR( ReadBase128( stream, &var ) ) /* `var' should be FT_ULong */ #define ROUND4( var ) ( ( var + 3 ) & ~3UL ) #define WRITE_USHORT( p, v ) \ do \ { \ *(p)++ = (FT_Byte)( (v) >> 8 ); \ *(p)++ = (FT_Byte)( (v) >> 0 ); \ \ } while ( 0 ) #define WRITE_ULONG( p, v ) \ do \ { \ *(p)++ = (FT_Byte)( (v) >> 24 ); \ *(p)++ = (FT_Byte)( (v) >> 16 ); \ *(p)++ = (FT_Byte)( (v) >> 8 ); \ *(p)++ = (FT_Byte)( (v) >> 0 ); \ \ } while ( 0 ) #define WRITE_SHORT( p, v ) \ do \ { \ *(p)++ = (FT_Byte)( (v) >> 8 ); \ *(p)++ = (FT_Byte)( (v) >> 0 ); \ \ } while ( 0 ) #define WRITE_SFNT_BUF( buf, s ) \ write_buf( &sfnt, sfnt_size, &dest_offset, buf, s, memory ) #define WRITE_SFNT_BUF_AT( offset, buf, s ) \ write_buf( &sfnt, sfnt_size, &offset, buf, s, memory ) #define N_CONTOUR_STREAM 0 #define N_POINTS_STREAM 1 #define FLAG_STREAM 2 #define GLYPH_STREAM 3 #define COMPOSITE_STREAM 4 #define BBOX_STREAM 5 #define INSTRUCTION_STREAM 6 #define HAVE_OVERLAP_SIMPLE_BITMAP 0x1 static void stream_close( FT_Stream stream ) { FT_Memory memory = stream->memory; FT_FREE( stream->base ); stream->size = 0; stream->close = NULL; } FT_COMPARE_DEF( int ) compare_tags( const void* a, const void* b ) { WOFF2_Table table1 = *(WOFF2_Table*)a; WOFF2_Table table2 = *(WOFF2_Table*)b; FT_Tag tag1 = table1->Tag; FT_Tag tag2 = table2->Tag; if ( tag1 > tag2 ) return 1; else if ( tag1 < tag2 ) return -1; else return 0; } static FT_Error Read255UShort( FT_Stream stream, FT_UShort* value ) { const FT_Byte oneMoreByteCode1 = 255; const FT_Byte oneMoreByteCode2 = 254; const FT_Byte wordCode = 253; const FT_UShort lowestUCode = 253; FT_Error error = FT_Err_Ok; FT_Byte code; FT_Byte result_byte = 0; FT_UShort result_short = 0; if ( FT_READ_BYTE( code ) ) return error; if ( code == wordCode ) { /* Read next two bytes and store `FT_UShort' value. */ if ( FT_READ_USHORT( result_short ) ) return error; *value = result_short; return FT_Err_Ok; } else if ( code == oneMoreByteCode1 ) { if ( FT_READ_BYTE( result_byte ) ) return error; *value = result_byte + lowestUCode; return FT_Err_Ok; } else if ( code == oneMoreByteCode2 ) { if ( FT_READ_BYTE( result_byte ) ) return error; *value = result_byte + lowestUCode * 2; return FT_Err_Ok; } else { *value = code; return FT_Err_Ok; } } static FT_Error ReadBase128( FT_Stream stream, FT_ULong* value ) { FT_ULong result = 0; FT_Int i; FT_Byte code; FT_Error error = FT_Err_Ok; for ( i = 0; i < 5; ++i ) { code = 0; if ( FT_READ_BYTE( code ) ) return error; /* Leading zeros are invalid. */ if ( i == 0 && code == 0x80 ) return FT_THROW( Invalid_Table ); /* If any of top seven bits are set then we're about to overflow. */ if ( result & 0xfe000000 ) return FT_THROW( Invalid_Table ); result = ( result << 7 ) | ( code & 0x7f ); /* Spin until most significant bit of data byte is false. */ if ( ( code & 0x80 ) == 0 ) { *value = result; return FT_Err_Ok; } } /* Make sure not to exceed the size bound. */ return FT_THROW( Invalid_Table ); } /* Extend memory of `dst_bytes' buffer and copy data from `src'. */ static FT_Error write_buf( FT_Byte** dst_bytes, FT_ULong* dst_size, FT_ULong* offset, FT_Byte* src, FT_ULong size, FT_Memory memory ) { FT_Error error = FT_Err_Ok; /* We are reallocating memory for `dst', so its pointer may change. */ FT_Byte* dst = *dst_bytes; /* Check whether we are within limits. */ if ( ( *offset + size ) > WOFF2_DEFAULT_MAX_SIZE ) return FT_THROW( Array_Too_Large ); /* Reallocate `dst'. */ if ( ( *offset + size ) > *dst_size ) { FT_TRACE6(( "Reallocating %lu to %lu.\n", *dst_size, (*offset + size) )); if ( FT_REALLOC( dst, (FT_ULong)( *dst_size ), (FT_ULong)( *offset + size ) ) ) goto Exit; *dst_size = *offset + size; } /* Copy data. */ ft_memcpy( dst + *offset, src, size ); *offset += size; /* Set pointer of `dst' to its correct value. */ *dst_bytes = dst; Exit: return error; } /* Pad buffer to closest multiple of 4. */ static FT_Error pad4( FT_Byte** sfnt_bytes, FT_ULong* sfnt_size, FT_ULong* out_offset, FT_Memory memory ) { FT_Byte* sfnt = *sfnt_bytes; FT_ULong dest_offset = *out_offset; FT_Byte zeroes[] = { 0, 0, 0 }; FT_ULong pad_bytes; if ( dest_offset + 3 < dest_offset ) return FT_THROW( Invalid_Table ); pad_bytes = ROUND4( dest_offset ) - dest_offset; if ( pad_bytes > 0 ) { if ( WRITE_SFNT_BUF( &zeroes[0], pad_bytes ) ) return FT_THROW( Invalid_Table ); } *sfnt_bytes = sfnt; *out_offset = dest_offset; return FT_Err_Ok; } /* Calculate table checksum of `buf'. */ static FT_ULong compute_ULong_sum( FT_Byte* buf, FT_ULong size ) { FT_ULong checksum = 0; FT_ULong aligned_size = size & ~3UL; FT_ULong i; FT_ULong v; for ( i = 0; i < aligned_size; i += 4 ) checksum += ( (FT_ULong)buf[i ] << 24 ) | ( (FT_ULong)buf[i + 1] << 16 ) | ( (FT_ULong)buf[i + 2] << 8 ) | ( (FT_ULong)buf[i + 3] << 0 ); /* If size is not aligned to 4, treat as if it is padded with 0s. */ if ( size != aligned_size ) { v = 0; for ( i = aligned_size ; i < size; ++i ) v |= (FT_ULong)buf[i] << ( 24 - 8 * ( i & 3 ) ); checksum += v; } return checksum; } static FT_Error woff2_decompress( FT_Byte* dst, FT_ULong dst_size, const FT_Byte* src, FT_ULong src_size ) { /* this cast is only of importance on 32bit systems; */ /* we don't validate it */ FT_Offset uncompressed_size = (FT_Offset)dst_size; BrotliDecoderResult result; result = BrotliDecoderDecompress( src_size, src, &uncompressed_size, dst ); if ( result != BROTLI_DECODER_RESULT_SUCCESS || uncompressed_size != dst_size ) { FT_ERROR(( "woff2_decompress: Stream length mismatch.\n" )); return FT_THROW( Invalid_Table ); } FT_TRACE2(( "woff2_decompress: Brotli stream decompressed.\n" )); return FT_Err_Ok; } static WOFF2_Table find_table( WOFF2_Table* tables, FT_UShort num_tables, FT_Tag tag ) { FT_Int i; for ( i = 0; i < num_tables; i++ ) { if ( tables[i]->Tag == tag ) return tables[i]; } return NULL; } /* Read `numberOfHMetrics' field from `hhea' table. */ static FT_Error read_num_hmetrics( FT_Stream stream, FT_UShort* num_hmetrics ) { FT_Error error = FT_Err_Ok; FT_UShort num_metrics; if ( FT_STREAM_SKIP( 34 ) ) return FT_THROW( Invalid_Table ); if ( FT_READ_USHORT( num_metrics ) ) return FT_THROW( Invalid_Table ); *num_hmetrics = num_metrics; return error; } /* An auxiliary function for overflow-safe addition. */ static FT_Int with_sign( FT_Byte flag, FT_Int base_val ) { /* Precondition: 0 <= base_val < 65536 (to avoid overflow). */ return ( flag & 1 ) ? base_val : -base_val; } /* An auxiliary function for overflow-safe addition. */ static FT_Int safe_int_addition( FT_Int a, FT_Int b, FT_Int* result ) { if ( ( ( a > 0 ) && ( b > FT_INT_MAX - a ) ) || ( ( a < 0 ) && ( b < FT_INT_MIN - a ) ) ) return FT_THROW( Invalid_Table ); *result = a + b; return FT_Err_Ok; } /* * Decode variable-length (flag, xCoordinate, yCoordinate) triplet for a * simple glyph. See * * https://www.w3.org/TR/WOFF2/#triplet_decoding */ static FT_Error triplet_decode( const FT_Byte* flags_in, const FT_Byte* in, FT_ULong in_size, FT_ULong n_points, WOFF2_Point result, FT_ULong* in_bytes_used ) { FT_Int x = 0; FT_Int y = 0; FT_Int dx; FT_Int dy; FT_Int b0, b1, b2; FT_ULong triplet_index = 0; FT_ULong data_bytes; FT_UInt i; if ( n_points > in_size ) return FT_THROW( Invalid_Table ); for ( i = 0; i < n_points; ++i ) { FT_Byte flag = flags_in[i]; FT_Bool on_curve = !( flag >> 7 ); flag &= 0x7f; if ( flag < 84 ) data_bytes = 1; else if ( flag < 120 ) data_bytes = 2; else if ( flag < 124 ) data_bytes = 3; else data_bytes = 4; /* Overflow checks */ if ( triplet_index + data_bytes > in_size || triplet_index + data_bytes < triplet_index ) return FT_THROW( Invalid_Table ); if ( flag < 10 ) { dx = 0; dy = with_sign( flag, ( ( flag & 14 ) << 7 ) + in[triplet_index] ); } else if ( flag < 20 ) { dx = with_sign( flag, ( ( ( flag - 10 ) & 14 ) << 7 ) + in[triplet_index] ); dy = 0; } else if ( flag < 84 ) { b0 = flag - 20; b1 = in[triplet_index]; dx = with_sign( flag, 1 + ( b0 & 0x30 ) + ( b1 >> 4 ) ); dy = with_sign( flag >> 1, 1 + ( ( b0 & 0x0c ) << 2 ) + ( b1 & 0x0f ) ); } else if ( flag < 120 ) { b0 = flag - 84; dx = with_sign( flag, 1 + ( ( b0 / 12 ) << 8 ) + in[triplet_index] ); dy = with_sign( flag >> 1, 1 + ( ( ( b0 % 12 ) >> 2 ) << 8 ) + in[triplet_index + 1] ); } else if ( flag < 124 ) { b2 = in[triplet_index + 1]; dx = with_sign( flag, ( in[triplet_index] << 4 ) + ( b2 >> 4 ) ); dy = with_sign( flag >> 1, ( ( b2 & 0x0f ) << 8 ) + in[triplet_index + 2] ); } else { dx = with_sign( flag, ( in[triplet_index] << 8 ) + in[triplet_index + 1] ); dy = with_sign( flag >> 1, ( in[triplet_index + 2] << 8 ) + in[triplet_index + 3] ); } triplet_index += data_bytes; if ( safe_int_addition( x, dx, &x ) ) return FT_THROW( Invalid_Table ); if ( safe_int_addition( y, dy, &y ) ) return FT_THROW( Invalid_Table ); result[i].x = x; result[i].y = y; result[i].on_curve = on_curve; } *in_bytes_used = triplet_index; return FT_Err_Ok; } /* Store decoded points in glyph buffer. */ static FT_Error store_points( FT_ULong n_points, const WOFF2_Point points, FT_UShort n_contours, FT_UShort instruction_len, FT_Bool have_overlap, FT_Byte* dst, FT_ULong dst_size, FT_ULong* glyph_size ) { FT_UInt flag_offset = 10 + ( 2 * n_contours ) + 2 + instruction_len; FT_Byte last_flag = 0xFFU; FT_Byte repeat_count = 0; FT_Int last_x = 0; FT_Int last_y = 0; FT_UInt x_bytes = 0; FT_UInt y_bytes = 0; FT_UInt xy_bytes; FT_UInt i; FT_UInt x_offset; FT_UInt y_offset; FT_Byte* pointer; for ( i = 0; i < n_points; ++i ) { const WOFF2_PointRec point = points[i]; FT_Byte flag = point.on_curve ? GLYF_ON_CURVE : 0; FT_Int dx = point.x - last_x; FT_Int dy = point.y - last_y; if ( i == 0 && have_overlap ) flag |= GLYF_OVERLAP_SIMPLE; if ( dx == 0 ) flag |= GLYF_THIS_X_IS_SAME; else if ( dx > -256 && dx < 256 ) { flag |= GLYF_X_SHORT | ( dx > 0 ? GLYF_THIS_X_IS_SAME : 0 ); x_bytes += 1; } else x_bytes += 2; if ( dy == 0 ) flag |= GLYF_THIS_Y_IS_SAME; else if ( dy > -256 && dy < 256 ) { flag |= GLYF_Y_SHORT | ( dy > 0 ? GLYF_THIS_Y_IS_SAME : 0 ); y_bytes += 1; } else y_bytes += 2; if ( flag == last_flag && repeat_count != 255 ) { dst[flag_offset - 1] |= GLYF_REPEAT; repeat_count++; } else { if ( repeat_count != 0 ) { if ( flag_offset >= dst_size ) return FT_THROW( Invalid_Table ); dst[flag_offset++] = repeat_count; } if ( flag_offset >= dst_size ) return FT_THROW( Invalid_Table ); dst[flag_offset++] = flag; repeat_count = 0; } last_x = point.x; last_y = point.y; last_flag = flag; } if ( repeat_count != 0 ) { if ( flag_offset >= dst_size ) return FT_THROW( Invalid_Table ); dst[flag_offset++] = repeat_count; } xy_bytes = x_bytes + y_bytes; if ( xy_bytes < x_bytes || flag_offset + xy_bytes < flag_offset || flag_offset + xy_bytes > dst_size ) return FT_THROW( Invalid_Table ); x_offset = flag_offset; y_offset = flag_offset + x_bytes; last_x = 0; last_y = 0; for ( i = 0; i < n_points; ++i ) { FT_Int dx = points[i].x - last_x; FT_Int dy = points[i].y - last_y; if ( dx == 0 ) ; else if ( dx > -256 && dx < 256 ) dst[x_offset++] = (FT_Byte)FT_ABS( dx ); else { pointer = dst + x_offset; WRITE_SHORT( pointer, dx ); x_offset += 2; } last_x += dx; if ( dy == 0 ) ; else if ( dy > -256 && dy < 256 ) dst[y_offset++] = (FT_Byte)FT_ABS( dy ); else { pointer = dst + y_offset; WRITE_SHORT( pointer, dy ); y_offset += 2; } last_y += dy; } *glyph_size = y_offset; return FT_Err_Ok; } static void compute_bbox( FT_ULong n_points, const WOFF2_Point points, FT_Byte* dst, FT_UShort* src_x_min ) { FT_Int x_min = 0; FT_Int y_min = 0; FT_Int x_max = 0; FT_Int y_max = 0; FT_UInt i; FT_ULong offset; FT_Byte* pointer; if ( n_points > 0 ) { x_min = points[0].x; y_min = points[0].y; x_max = points[0].x; y_max = points[0].y; } for ( i = 1; i < n_points; ++i ) { FT_Int x = points[i].x; FT_Int y = points[i].y; x_min = FT_MIN( x, x_min ); y_min = FT_MIN( y, y_min ); x_max = FT_MAX( x, x_max ); y_max = FT_MAX( y, y_max ); } /* Write values to `glyf' record. */ offset = 2; pointer = dst + offset; WRITE_SHORT( pointer, x_min ); WRITE_SHORT( pointer, y_min ); WRITE_SHORT( pointer, x_max ); WRITE_SHORT( pointer, y_max ); *src_x_min = (FT_UShort)x_min; } static FT_Error compositeGlyph_size( FT_Stream stream, FT_ULong offset, FT_ULong* size, FT_Bool* have_instructions ) { FT_Error error = FT_Err_Ok; FT_ULong start_offset = offset; FT_Bool we_have_inst = FALSE; FT_UShort flags = FLAG_MORE_COMPONENTS; if ( FT_STREAM_SEEK( start_offset ) ) goto Exit; while ( flags & FLAG_MORE_COMPONENTS ) { FT_ULong arg_size; if ( FT_READ_USHORT( flags ) ) goto Exit; we_have_inst |= ( flags & FLAG_WE_HAVE_INSTRUCTIONS ) != 0; /* glyph index */ arg_size = 2; if ( flags & FLAG_ARG_1_AND_2_ARE_WORDS ) arg_size += 4; else arg_size += 2; if ( flags & FLAG_WE_HAVE_A_SCALE ) arg_size += 2; else if ( flags & FLAG_WE_HAVE_AN_X_AND_Y_SCALE ) arg_size += 4; else if ( flags & FLAG_WE_HAVE_A_TWO_BY_TWO ) arg_size += 8; if ( FT_STREAM_SKIP( arg_size ) ) goto Exit; } *size = FT_STREAM_POS() - start_offset; *have_instructions = we_have_inst; Exit: return error; } /* Store loca values (provided by `reconstruct_glyf') to output stream. */ static FT_Error store_loca( FT_ULong* loca_values, FT_ULong loca_values_size, FT_UShort index_format, FT_ULong* checksum, FT_Byte** sfnt_bytes, FT_ULong* sfnt_size, FT_ULong* out_offset, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_Byte* sfnt = *sfnt_bytes; FT_ULong dest_offset = *out_offset; FT_Byte* loca_buf = NULL; FT_Byte* dst = NULL; FT_UInt i = 0; FT_ULong loca_buf_size; const FT_ULong offset_size = index_format ? 4 : 2; if ( ( loca_values_size << 2 ) >> 2 != loca_values_size ) goto Fail; loca_buf_size = loca_values_size * offset_size; if ( FT_QNEW_ARRAY( loca_buf, loca_buf_size ) ) goto Fail; dst = loca_buf; for ( i = 0; i < loca_values_size; i++ ) { FT_ULong value = loca_values[i]; if ( index_format ) WRITE_ULONG( dst, value ); else WRITE_USHORT( dst, ( value >> 1 ) ); } *checksum = compute_ULong_sum( loca_buf, loca_buf_size ); /* Write `loca' table to sfnt buffer. */ if ( WRITE_SFNT_BUF( loca_buf, loca_buf_size ) ) goto Fail; /* Set pointer `sfnt_bytes' to its correct value. */ *sfnt_bytes = sfnt; *out_offset = dest_offset; FT_FREE( loca_buf ); return error; Fail: if ( !error ) error = FT_THROW( Invalid_Table ); FT_FREE( loca_buf ); return error; } static FT_Error reconstruct_glyf( FT_Stream stream, FT_ULong* glyf_checksum, FT_ULong* loca_checksum, FT_Byte** sfnt_bytes, FT_ULong* sfnt_size, FT_ULong* out_offset, WOFF2_Info info, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_Byte* sfnt = *sfnt_bytes; /* current position in stream */ const FT_ULong pos = FT_STREAM_POS(); FT_UInt num_substreams = 7; FT_UShort option_flags; FT_UShort num_glyphs; FT_UShort index_format; FT_ULong expected_loca_length; FT_UInt offset; FT_UInt i; FT_ULong points_size; FT_ULong glyph_buf_size; FT_ULong bbox_bitmap_offset; FT_ULong bbox_bitmap_length; FT_ULong overlap_bitmap_offset = 0; FT_ULong overlap_bitmap_length = 0; const FT_ULong glyf_start = *out_offset; FT_ULong dest_offset = *out_offset; WOFF2_Substream substreams = NULL; FT_ULong* loca_values = NULL; FT_UShort* n_points_arr = NULL; FT_Byte* glyph_buf = NULL; WOFF2_Point points = NULL; if ( FT_NEW_ARRAY( substreams, num_substreams ) ) goto Fail; if ( FT_STREAM_SKIP( 2 ) ) goto Fail; if ( FT_READ_USHORT( option_flags ) ) goto Fail; if ( FT_READ_USHORT( num_glyphs ) ) goto Fail; if ( FT_READ_USHORT( index_format ) ) goto Fail; FT_TRACE4(( "option_flags = %u; num_glyphs = %u; index_format = %u\n", option_flags, num_glyphs, index_format )); info->num_glyphs = num_glyphs; /* Calculate expected length of loca and compare. */ /* See https://www.w3.org/TR/WOFF2/#conform-mustRejectLoca */ /* index_format = 0 => Short version `loca'. */ /* index_format = 1 => Long version `loca'. */ expected_loca_length = ( index_format ? 4 : 2 ) * ( (FT_ULong)num_glyphs + 1 ); if ( info->loca_table->dst_length != expected_loca_length ) goto Fail; offset = 2 + 2 + 2 + 2 + ( num_substreams * 4 ); if ( offset > info->glyf_table->TransformLength ) goto Fail; for ( i = 0; i < num_substreams; ++i ) { FT_ULong substream_size; if ( FT_READ_ULONG( substream_size ) ) goto Fail; if ( substream_size > info->glyf_table->TransformLength - offset ) goto Fail; substreams[i].start = pos + offset; substreams[i].offset = pos + offset; substreams[i].size = substream_size; FT_TRACE5(( " Substream %d: offset = %lu; size = %lu;\n", i, substreams[i].offset, substreams[i].size )); offset += substream_size; } if ( option_flags & HAVE_OVERLAP_SIMPLE_BITMAP ) { /* Size of overlapBitmap = floor((numGlyphs + 7) / 8) */ overlap_bitmap_length = ( num_glyphs + 7U ) >> 3; if ( overlap_bitmap_length > info->glyf_table->TransformLength - offset ) goto Fail; overlap_bitmap_offset = pos + offset; FT_TRACE5(( " Overlap bitmap: offset = %lu; size = %lu;\n", overlap_bitmap_offset, overlap_bitmap_length )); offset += overlap_bitmap_length; } if ( FT_NEW_ARRAY( loca_values, num_glyphs + 1 ) ) goto Fail; points_size = 0; bbox_bitmap_offset = substreams[BBOX_STREAM].offset; /* Size of bboxBitmap = 4 * floor((numGlyphs + 31) / 32) */ bbox_bitmap_length = ( ( num_glyphs + 31U ) >> 5 ) << 2; /* bboxStreamSize is the combined size of bboxBitmap and bboxStream. */ substreams[BBOX_STREAM].offset += bbox_bitmap_length; glyph_buf_size = WOFF2_DEFAULT_GLYPH_BUF; if ( FT_NEW_ARRAY( glyph_buf, glyph_buf_size ) ) goto Fail; if ( FT_NEW_ARRAY( info->x_mins, num_glyphs ) ) goto Fail; for ( i = 0; i < num_glyphs; ++i ) { FT_ULong glyph_size = 0; FT_UShort n_contours = 0; FT_Bool have_bbox = FALSE; FT_Byte bbox_bitmap; FT_ULong bbox_offset; FT_UShort x_min = 0; /* Set `have_bbox'. */ bbox_offset = bbox_bitmap_offset + ( i >> 3 ); if ( FT_STREAM_SEEK( bbox_offset ) || FT_READ_BYTE( bbox_bitmap ) ) goto Fail; if ( bbox_bitmap & ( 0x80 >> ( i & 7 ) ) ) have_bbox = TRUE; /* Read value from `nContourStream'. */ if ( FT_STREAM_SEEK( substreams[N_CONTOUR_STREAM].offset ) || FT_READ_USHORT( n_contours ) ) goto Fail; substreams[N_CONTOUR_STREAM].offset += 2; if ( n_contours == 0xffff ) { /* composite glyph */ FT_Bool have_instructions = FALSE; FT_UShort instruction_size = 0; FT_ULong composite_size; FT_ULong size_needed; FT_Byte* pointer = NULL; /* Composite glyphs must have explicit bbox. */ if ( !have_bbox ) goto Fail; if ( compositeGlyph_size( stream, substreams[COMPOSITE_STREAM].offset, &composite_size, &have_instructions) ) goto Fail; if ( have_instructions ) { if ( FT_STREAM_SEEK( substreams[GLYPH_STREAM].offset ) || READ_255USHORT( instruction_size ) ) goto Fail; substreams[GLYPH_STREAM].offset = FT_STREAM_POS(); } size_needed = 12 + composite_size + instruction_size; if ( glyph_buf_size < size_needed ) { if ( FT_RENEW_ARRAY( glyph_buf, glyph_buf_size, size_needed ) ) goto Fail; glyph_buf_size = size_needed; } pointer = glyph_buf + glyph_size; WRITE_USHORT( pointer, n_contours ); glyph_size += 2; /* Read x_min for current glyph. */ if ( FT_STREAM_SEEK( substreams[BBOX_STREAM].offset ) || FT_READ_USHORT( x_min ) ) goto Fail; /* No increment here because we read again. */ if ( FT_STREAM_SEEK( substreams[BBOX_STREAM].offset ) || FT_STREAM_READ( glyph_buf + glyph_size, 8 ) ) goto Fail; substreams[BBOX_STREAM].offset += 8; glyph_size += 8; if ( FT_STREAM_SEEK( substreams[COMPOSITE_STREAM].offset ) || FT_STREAM_READ( glyph_buf + glyph_size, composite_size ) ) goto Fail; substreams[COMPOSITE_STREAM].offset += composite_size; glyph_size += composite_size; if ( have_instructions ) { pointer = glyph_buf + glyph_size; WRITE_USHORT( pointer, instruction_size ); glyph_size += 2; if ( FT_STREAM_SEEK( substreams[INSTRUCTION_STREAM].offset ) || FT_STREAM_READ( glyph_buf + glyph_size, instruction_size ) ) goto Fail; substreams[INSTRUCTION_STREAM].offset += instruction_size; glyph_size += instruction_size; } } else if ( n_contours > 0 ) { /* simple glyph */ FT_ULong total_n_points = 0; FT_UShort n_points_contour; FT_UInt j; FT_ULong flag_size; FT_ULong triplet_size; FT_ULong triplet_bytes_used; FT_Bool have_overlap = FALSE; FT_Byte overlap_bitmap; FT_ULong overlap_offset; FT_Byte* flags_buf = NULL; FT_Byte* triplet_buf = NULL; FT_UShort instruction_size; FT_ULong size_needed; FT_Int end_point; FT_UInt contour_ix; FT_Byte* pointer = NULL; /* Set `have_overlap`. */ if ( overlap_bitmap_offset ) { overlap_offset = overlap_bitmap_offset + ( i >> 3 ); if ( FT_STREAM_SEEK( overlap_offset ) || FT_READ_BYTE( overlap_bitmap ) ) goto Fail; if ( overlap_bitmap & ( 0x80 >> ( i & 7 ) ) ) have_overlap = TRUE; } if ( FT_NEW_ARRAY( n_points_arr, n_contours ) ) goto Fail; if ( FT_STREAM_SEEK( substreams[N_POINTS_STREAM].offset ) ) goto Fail; for ( j = 0; j < n_contours; ++j ) { if ( READ_255USHORT( n_points_contour ) ) goto Fail; n_points_arr[j] = n_points_contour; /* Prevent negative/overflow. */ if ( total_n_points + n_points_contour < total_n_points ) goto Fail; total_n_points += n_points_contour; } substreams[N_POINTS_STREAM].offset = FT_STREAM_POS(); flag_size = total_n_points; if ( flag_size > substreams[FLAG_STREAM].size ) goto Fail; flags_buf = stream->base + substreams[FLAG_STREAM].offset; triplet_buf = stream->base + substreams[GLYPH_STREAM].offset; if ( substreams[GLYPH_STREAM].size < ( substreams[GLYPH_STREAM].offset - substreams[GLYPH_STREAM].start ) ) goto Fail; triplet_size = substreams[GLYPH_STREAM].size - ( substreams[GLYPH_STREAM].offset - substreams[GLYPH_STREAM].start ); triplet_bytes_used = 0; /* Create array to store point information. */ points_size = total_n_points; if ( FT_NEW_ARRAY( points, points_size ) ) goto Fail; if ( triplet_decode( flags_buf, triplet_buf, triplet_size, total_n_points, points, &triplet_bytes_used ) ) goto Fail; substreams[FLAG_STREAM].offset += flag_size; substreams[GLYPH_STREAM].offset += triplet_bytes_used; if ( FT_STREAM_SEEK( substreams[GLYPH_STREAM].offset ) || READ_255USHORT( instruction_size ) ) goto Fail; substreams[GLYPH_STREAM].offset = FT_STREAM_POS(); if ( total_n_points >= ( 1 << 27 ) ) goto Fail; size_needed = 12 + ( 2 * n_contours ) + ( 5 * total_n_points ) + instruction_size; if ( glyph_buf_size < size_needed ) { if ( FT_RENEW_ARRAY( glyph_buf, glyph_buf_size, size_needed ) ) goto Fail; glyph_buf_size = size_needed; } pointer = glyph_buf + glyph_size; WRITE_USHORT( pointer, n_contours ); glyph_size += 2; if ( have_bbox ) { /* Read x_min for current glyph. */ if ( FT_STREAM_SEEK( substreams[BBOX_STREAM].offset ) || FT_READ_USHORT( x_min ) ) goto Fail; /* No increment here because we read again. */ if ( FT_STREAM_SEEK( substreams[BBOX_STREAM].offset ) || FT_STREAM_READ( glyph_buf + glyph_size, 8 ) ) goto Fail; substreams[BBOX_STREAM].offset += 8; } else compute_bbox( total_n_points, points, glyph_buf, &x_min ); glyph_size = CONTOUR_OFFSET_END_POINT; pointer = glyph_buf + glyph_size; end_point = -1; for ( contour_ix = 0; contour_ix < n_contours; ++contour_ix ) { end_point += n_points_arr[contour_ix]; if ( end_point >= 65536 ) goto Fail; WRITE_SHORT( pointer, end_point ); glyph_size += 2; } WRITE_USHORT( pointer, instruction_size ); glyph_size += 2; if ( FT_STREAM_SEEK( substreams[INSTRUCTION_STREAM].offset ) || FT_STREAM_READ( glyph_buf + glyph_size, instruction_size ) ) goto Fail; substreams[INSTRUCTION_STREAM].offset += instruction_size; glyph_size += instruction_size; if ( store_points( total_n_points, points, n_contours, instruction_size, have_overlap, glyph_buf, glyph_buf_size, &glyph_size ) ) goto Fail; FT_FREE( points ); FT_FREE( n_points_arr ); } else { /* Empty glyph. */ /* Must not have a bbox. */ if ( have_bbox ) { FT_ERROR(( "Empty glyph has a bbox.\n" )); goto Fail; } } loca_values[i] = dest_offset - glyf_start; if ( WRITE_SFNT_BUF( glyph_buf, glyph_size ) ) goto Fail; if ( pad4( &sfnt, sfnt_size, &dest_offset, memory ) ) goto Fail; *glyf_checksum += compute_ULong_sum( glyph_buf, glyph_size ); /* Store x_mins, may be required to reconstruct `hmtx'. */ if ( n_contours > 0 ) info->x_mins[i] = (FT_Short)x_min; } info->glyf_table->dst_length = dest_offset - info->glyf_table->dst_offset; info->loca_table->dst_offset = dest_offset; /* `loca[n]' will be equal to the length of the `glyf' table. */ loca_values[num_glyphs] = info->glyf_table->dst_length; if ( store_loca( loca_values, num_glyphs + 1, index_format, loca_checksum, &sfnt, sfnt_size, &dest_offset, memory ) ) goto Fail; info->loca_table->dst_length = dest_offset - info->loca_table->dst_offset; FT_TRACE4(( " loca table info:\n" )); FT_TRACE4(( " dst_offset = %lu\n", info->loca_table->dst_offset )); FT_TRACE4(( " dst_length = %lu\n", info->loca_table->dst_length )); FT_TRACE4(( " checksum = %09lx\n", *loca_checksum )); /* Set pointer `sfnt_bytes' to its correct value. */ *sfnt_bytes = sfnt; *out_offset = dest_offset; FT_FREE( substreams ); FT_FREE( loca_values ); FT_FREE( n_points_arr ); FT_FREE( glyph_buf ); FT_FREE( points ); return error; Fail: if ( !error ) error = FT_THROW( Invalid_Table ); /* Set pointer `sfnt_bytes' to its correct value. */ *sfnt_bytes = sfnt; FT_FREE( substreams ); FT_FREE( loca_values ); FT_FREE( n_points_arr ); FT_FREE( glyph_buf ); FT_FREE( points ); return error; } /* Get `x_mins' for untransformed `glyf' table. */ static FT_Error get_x_mins( FT_Stream stream, WOFF2_Table* tables, FT_UShort num_tables, WOFF2_Info info, FT_Memory memory ) { FT_UShort num_glyphs; FT_UShort index_format; FT_ULong glyf_offset; FT_UShort glyf_offset_short; FT_ULong loca_offset; FT_Int i; FT_Error error = FT_Err_Ok; FT_ULong offset_size; /* At this point of time those tables might not have been read yet. */ const WOFF2_Table maxp_table = find_table( tables, num_tables, TTAG_maxp ); const WOFF2_Table head_table = find_table( tables, num_tables, TTAG_head ); if ( !maxp_table ) { FT_ERROR(( "`maxp' table is missing.\n" )); return FT_THROW( Invalid_Table ); } if ( !head_table ) { FT_ERROR(( "`head' table is missing.\n" )); return FT_THROW( Invalid_Table ); } if ( !info->loca_table ) { FT_ERROR(( "`loca' table is missing.\n" )); return FT_THROW( Invalid_Table ); } /* Read `numGlyphs' field from `maxp' table. */ if ( FT_STREAM_SEEK( maxp_table->src_offset ) || FT_STREAM_SKIP( 8 ) ) return error; if ( FT_READ_USHORT( num_glyphs ) ) return error; info->num_glyphs = num_glyphs; /* Read `indexToLocFormat' field from `head' table. */ if ( FT_STREAM_SEEK( head_table->src_offset ) || FT_STREAM_SKIP( 50 ) ) return error; if ( FT_READ_USHORT( index_format ) ) return error; offset_size = index_format ? 4 : 2; /* Create `x_mins' array. */ if ( FT_NEW_ARRAY( info->x_mins, num_glyphs ) ) return error; loca_offset = info->loca_table->src_offset; for ( i = 0; i < num_glyphs; ++i ) { if ( FT_STREAM_SEEK( loca_offset ) ) return error; loca_offset += offset_size; if ( index_format ) { if ( FT_READ_ULONG( glyf_offset ) ) return error; } else { if ( FT_READ_USHORT( glyf_offset_short ) ) return error; glyf_offset = (FT_ULong)( glyf_offset_short ); glyf_offset = glyf_offset << 1; } glyf_offset += info->glyf_table->src_offset; if ( FT_STREAM_SEEK( glyf_offset ) || FT_STREAM_SKIP( 2 ) ) return error; if ( FT_READ_SHORT( info->x_mins[i] ) ) return error; } return error; } static FT_Error reconstruct_hmtx( FT_Stream stream, FT_UShort num_glyphs, FT_UShort num_hmetrics, FT_Short* x_mins, FT_ULong* checksum, FT_Byte** sfnt_bytes, FT_ULong* sfnt_size, FT_ULong* out_offset, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_Byte* sfnt = *sfnt_bytes; FT_ULong dest_offset = *out_offset; FT_Byte hmtx_flags; FT_Bool has_proportional_lsbs, has_monospace_lsbs; FT_ULong hmtx_table_size; FT_Int i; FT_UShort* advance_widths = NULL; FT_Short* lsbs = NULL; FT_Byte* hmtx_table = NULL; FT_Byte* dst = NULL; if ( FT_READ_BYTE( hmtx_flags ) ) goto Fail; has_proportional_lsbs = ( hmtx_flags & 1 ) == 0; has_monospace_lsbs = ( hmtx_flags & 2 ) == 0; /* Bits 2-7 are reserved and MUST be zero. */ if ( ( hmtx_flags & 0xFC ) != 0 ) goto Fail; /* Are you REALLY transformed? */ if ( has_proportional_lsbs && has_monospace_lsbs ) goto Fail; /* Cannot have a transformed `hmtx' without `glyf'. */ if ( ( num_hmetrics > num_glyphs ) || ( num_hmetrics < 1 ) ) goto Fail; /* Must have at least one entry. */ if ( num_hmetrics < 1 ) goto Fail; if ( FT_NEW_ARRAY( advance_widths, num_hmetrics ) || FT_NEW_ARRAY( lsbs, num_glyphs ) ) goto Fail; /* Read `advanceWidth' stream. Always present. */ for ( i = 0; i < num_hmetrics; i++ ) { FT_UShort advance_width; if ( FT_READ_USHORT( advance_width ) ) goto Fail; advance_widths[i] = advance_width; } /* lsb values for proportional glyphs. */ for ( i = 0; i < num_hmetrics; i++ ) { FT_Short lsb; if ( has_proportional_lsbs ) { if ( FT_READ_SHORT( lsb ) ) goto Fail; } else lsb = x_mins[i]; lsbs[i] = lsb; } /* lsb values for monospaced glyphs. */ for ( i = num_hmetrics; i < num_glyphs; i++ ) { FT_Short lsb; if ( has_monospace_lsbs ) { if ( FT_READ_SHORT( lsb ) ) goto Fail; } else lsb = x_mins[i]; lsbs[i] = lsb; } /* Build the hmtx table. */ hmtx_table_size = 2 * num_hmetrics + 2 * num_glyphs; if ( FT_NEW_ARRAY( hmtx_table, hmtx_table_size ) ) goto Fail; dst = hmtx_table; FT_TRACE6(( "hmtx values: \n" )); for ( i = 0; i < num_glyphs; i++ ) { if ( i < num_hmetrics ) { WRITE_SHORT( dst, advance_widths[i] ); FT_TRACE6(( "%d ", advance_widths[i] )); } WRITE_SHORT( dst, lsbs[i] ); FT_TRACE6(( "%d ", lsbs[i] )); } FT_TRACE6(( "\n" )); *checksum = compute_ULong_sum( hmtx_table, hmtx_table_size ); /* Write `hmtx' table to sfnt buffer. */ if ( WRITE_SFNT_BUF( hmtx_table, hmtx_table_size ) ) goto Fail; /* Set pointer `sfnt_bytes' to its correct value. */ *sfnt_bytes = sfnt; *out_offset = dest_offset; FT_FREE( advance_widths ); FT_FREE( lsbs ); FT_FREE( hmtx_table ); return error; Fail: FT_FREE( advance_widths ); FT_FREE( lsbs ); FT_FREE( hmtx_table ); if ( !error ) error = FT_THROW( Invalid_Table ); return error; } static FT_Error reconstruct_font( FT_Byte* transformed_buf, FT_ULong transformed_buf_size, WOFF2_Table* indices, WOFF2_Header woff2, WOFF2_Info info, FT_Byte** sfnt_bytes, FT_ULong* sfnt_size, FT_Memory memory ) { /* Memory management of `transformed_buf' is handled by the caller. */ FT_Error error = FT_Err_Ok; FT_Stream stream = NULL; FT_Byte* buf_cursor = NULL; FT_Byte* table_entry = NULL; /* We are reallocating memory for `sfnt', so its pointer may change. */ FT_Byte* sfnt = *sfnt_bytes; FT_UShort num_tables = woff2->num_tables; FT_ULong dest_offset = 12 + num_tables * 16UL; FT_ULong checksum = 0; FT_ULong loca_checksum = 0; FT_Int nn = 0; FT_UShort num_hmetrics = 0; FT_ULong font_checksum = info->header_checksum; FT_Bool is_glyf_xform = FALSE; FT_ULong table_entry_offset = 12; /* A few table checks before reconstruction. */ /* `glyf' must be present with `loca'. */ info->glyf_table = find_table( indices, num_tables, TTAG_glyf ); info->loca_table = find_table( indices, num_tables, TTAG_loca ); if ( ( info->glyf_table == NULL ) ^ ( info->loca_table == NULL ) ) { FT_ERROR(( "One of `glyf'/`loca' tables missing.\n" )); return FT_THROW( Invalid_Table ); } /* Both `glyf' and `loca' must have same transformation. */ if ( info->glyf_table != NULL ) { if ( ( info->glyf_table->flags & WOFF2_FLAGS_TRANSFORM ) != ( info->loca_table->flags & WOFF2_FLAGS_TRANSFORM ) ) { FT_ERROR(( "Transformation mismatch" " between `glyf' and `loca' table." )); return FT_THROW( Invalid_Table ); } } /* Create buffer for table entries. */ if ( FT_NEW_ARRAY( table_entry, 16 ) ) goto Fail; /* Create a stream for the uncompressed buffer. */ if ( FT_NEW( stream ) ) goto Fail; FT_Stream_OpenMemory( stream, transformed_buf, transformed_buf_size ); FT_ASSERT( FT_STREAM_POS() == 0 ); /* Reconstruct/copy tables to output stream. */ for ( nn = 0; nn < num_tables; nn++ ) { WOFF2_TableRec table = *( indices[nn] ); FT_TRACE3(( "Seeking to %ld with table size %ld.\n", table.src_offset, table.src_length )); FT_TRACE3(( "Table tag: %c%c%c%c.\n", (FT_Char)( table.Tag >> 24 ), (FT_Char)( table.Tag >> 16 ), (FT_Char)( table.Tag >> 8 ), (FT_Char)( table.Tag ) )); if ( FT_STREAM_SEEK( table.src_offset ) ) goto Fail; if ( table.src_offset + table.src_length > transformed_buf_size ) goto Fail; /* Get stream size for fields of `hmtx' table. */ if ( table.Tag == TTAG_hhea ) { if ( read_num_hmetrics( stream, &num_hmetrics ) ) goto Fail; } info->num_hmetrics = num_hmetrics; checksum = 0; if ( ( table.flags & WOFF2_FLAGS_TRANSFORM ) != WOFF2_FLAGS_TRANSFORM ) { /* Check whether `head' is at least 12 bytes. */ if ( table.Tag == TTAG_head ) { if ( table.src_length < 12 ) goto Fail; buf_cursor = transformed_buf + table.src_offset + 8; /* Set checkSumAdjustment = 0 */ WRITE_ULONG( buf_cursor, 0 ); } table.dst_offset = dest_offset; checksum = compute_ULong_sum( transformed_buf + table.src_offset, table.src_length ); FT_TRACE4(( "Checksum = %09lx.\n", checksum )); if ( WRITE_SFNT_BUF( transformed_buf + table.src_offset, table.src_length ) ) goto Fail; } else { FT_TRACE3(( "This table is transformed.\n" )); if ( table.Tag == TTAG_glyf ) { is_glyf_xform = TRUE; table.dst_offset = dest_offset; if ( reconstruct_glyf( stream, &checksum, &loca_checksum, &sfnt, sfnt_size, &dest_offset, info, memory ) ) goto Fail; FT_TRACE4(( "Checksum = %09lx.\n", checksum )); } else if ( table.Tag == TTAG_loca ) checksum = loca_checksum; else if ( table.Tag == TTAG_hmtx ) { /* If glyf is not transformed and hmtx is, handle separately. */ if ( !is_glyf_xform ) { if ( get_x_mins( stream, indices, num_tables, info, memory ) ) goto Fail; } table.dst_offset = dest_offset; if ( reconstruct_hmtx( stream, info->num_glyphs, info->num_hmetrics, info->x_mins, &checksum, &sfnt, sfnt_size, &dest_offset, memory ) ) goto Fail; } else { /* Unknown transform. */ FT_ERROR(( "Unknown table transform.\n" )); goto Fail; } } font_checksum += checksum; buf_cursor = &table_entry[0]; WRITE_ULONG( buf_cursor, table.Tag ); WRITE_ULONG( buf_cursor, checksum ); WRITE_ULONG( buf_cursor, table.dst_offset ); WRITE_ULONG( buf_cursor, table.dst_length ); WRITE_SFNT_BUF_AT( table_entry_offset, table_entry, 16 ); /* Update checksum. */ font_checksum += compute_ULong_sum( table_entry, 16 ); if ( pad4( &sfnt, sfnt_size, &dest_offset, memory ) ) goto Fail; /* Sanity check. */ if ( (FT_ULong)( table.dst_offset + table.dst_length ) > dest_offset ) { FT_ERROR(( "Table was partially written.\n" )); goto Fail; } } /* Update `head' checkSumAdjustment. */ info->head_table = find_table( indices, num_tables, TTAG_head ); if ( !info->head_table ) { FT_ERROR(( "`head' table is missing.\n" )); goto Fail; } if ( info->head_table->dst_length < 12 ) goto Fail; buf_cursor = sfnt + info->head_table->dst_offset + 8; font_checksum = 0xB1B0AFBA - font_checksum; WRITE_ULONG( buf_cursor, font_checksum ); FT_TRACE2(( "Final checksum = %09lx.\n", font_checksum )); woff2->actual_sfnt_size = dest_offset; /* Set pointer of sfnt stream to its correct value. */ *sfnt_bytes = sfnt; FT_FREE( table_entry ); FT_Stream_Close( stream ); FT_FREE( stream ); return error; Fail: if ( !error ) error = FT_THROW( Invalid_Table ); /* Set pointer of sfnt stream to its correct value. */ *sfnt_bytes = sfnt; FT_FREE( table_entry ); FT_Stream_Close( stream ); FT_FREE( stream ); return error; } /* Replace `face->root.stream' with a stream containing the extracted */ /* SFNT of a WOFF2 font. */ FT_LOCAL_DEF( FT_Error ) woff2_open_font( FT_Stream stream, TT_Face face, FT_Int* face_instance_index, FT_Long* num_faces ) { FT_Memory memory = stream->memory; FT_Error error = FT_Err_Ok; FT_Int face_index; WOFF2_HeaderRec woff2; WOFF2_InfoRec info = { 0, 0, 0, NULL, NULL, NULL, NULL }; WOFF2_Table tables = NULL; WOFF2_Table* indices = NULL; WOFF2_Table* temp_indices = NULL; WOFF2_Table last_table; FT_Int nn; FT_ULong j; FT_ULong flags; FT_UShort xform_version; FT_ULong src_offset = 0; FT_UInt glyf_index; FT_UInt loca_index; FT_UInt32 file_offset; FT_Byte* sfnt = NULL; FT_Stream sfnt_stream = NULL; FT_Byte* sfnt_header; FT_ULong sfnt_size; FT_Byte* uncompressed_buf = NULL; static const FT_Frame_Field woff2_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE WOFF2_HeaderRec FT_FRAME_START( 48 ), FT_FRAME_ULONG ( signature ), FT_FRAME_ULONG ( flavor ), FT_FRAME_ULONG ( length ), FT_FRAME_USHORT ( num_tables ), FT_FRAME_SKIP_BYTES( 2 ), FT_FRAME_ULONG ( totalSfntSize ), FT_FRAME_ULONG ( totalCompressedSize ), FT_FRAME_SKIP_BYTES( 2 * 2 ), FT_FRAME_ULONG ( metaOffset ), FT_FRAME_ULONG ( metaLength ), FT_FRAME_ULONG ( metaOrigLength ), FT_FRAME_ULONG ( privOffset ), FT_FRAME_ULONG ( privLength ), FT_FRAME_END }; FT_ASSERT( stream == face->root.stream ); FT_ASSERT( FT_STREAM_POS() == 0 ); face_index = FT_ABS( *face_instance_index ) & 0xFFFF; /* Read WOFF2 Header. */ if ( FT_STREAM_READ_FIELDS( woff2_header_fields, &woff2 ) ) return error; FT_TRACE4(( "signature -> 0x%lX\n", woff2.signature )); FT_TRACE2(( "flavor -> 0x%08lx\n", woff2.flavor )); FT_TRACE4(( "length -> %lu\n", woff2.length )); FT_TRACE2(( "num_tables -> %hu\n", woff2.num_tables )); FT_TRACE4(( "totalSfntSize -> %lu\n", woff2.totalSfntSize )); FT_TRACE4(( "metaOffset -> %lu\n", woff2.metaOffset )); FT_TRACE4(( "metaLength -> %lu\n", woff2.metaLength )); FT_TRACE4(( "privOffset -> %lu\n", woff2.privOffset )); FT_TRACE4(( "privLength -> %lu\n", woff2.privLength )); /* Make sure we don't recurse back here. */ if ( woff2.flavor == TTAG_wOF2 ) return FT_THROW( Invalid_Table ); /* Miscellaneous checks. */ if ( woff2.length != stream->size || woff2.num_tables == 0 || 48 + woff2.num_tables * 20UL >= woff2.length || ( woff2.metaOffset == 0 && ( woff2.metaLength != 0 || woff2.metaOrigLength != 0 ) ) || ( woff2.metaLength != 0 && woff2.metaOrigLength == 0 ) || ( woff2.metaOffset >= woff2.length ) || ( woff2.length - woff2.metaOffset < woff2.metaLength ) || ( woff2.privOffset == 0 && woff2.privLength != 0 ) || ( woff2.privOffset >= woff2.length ) || ( woff2.length - woff2.privOffset < woff2.privLength ) ) { FT_ERROR(( "woff2_open_font: invalid WOFF2 header\n" )); return FT_THROW( Invalid_Table ); } FT_TRACE2(( "woff2_open_font: WOFF2 Header is valid.\n" )); woff2.ttc_fonts = NULL; /* Read table directory. */ if ( FT_NEW_ARRAY( tables, woff2.num_tables ) || FT_NEW_ARRAY( indices, woff2.num_tables ) ) goto Exit; FT_TRACE2(( "\n" )); FT_TRACE2(( " tag flags transform origLen transformLen offset\n" )); FT_TRACE2(( " -----------------------------------------------------------\n" )); /* " XXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX" */ for ( nn = 0; nn < woff2.num_tables; nn++ ) { WOFF2_Table table = tables + nn; if ( FT_READ_BYTE( table->FlagByte ) ) goto Exit; if ( ( table->FlagByte & 0x3f ) == 0x3f ) { if ( FT_READ_ULONG( table->Tag ) ) goto Exit; } else { table->Tag = woff2_known_tags( table->FlagByte & 0x3f ); if ( !table->Tag ) { FT_ERROR(( "woff2_open_font: Unknown table tag." )); error = FT_THROW( Invalid_Table ); goto Exit; } } flags = 0; xform_version = ( table->FlagByte >> 6 ) & 0x03; /* 0 means xform for glyph/loca, non-0 for others. */ if ( table->Tag == TTAG_glyf || table->Tag == TTAG_loca ) { if ( xform_version == 0 ) flags |= WOFF2_FLAGS_TRANSFORM; } else if ( xform_version != 0 ) flags |= WOFF2_FLAGS_TRANSFORM; flags |= xform_version; if ( READ_BASE128( table->dst_length ) ) goto Exit; table->TransformLength = table->dst_length; if ( ( flags & WOFF2_FLAGS_TRANSFORM ) != 0 ) { if ( READ_BASE128( table->TransformLength ) ) goto Exit; if ( table->Tag == TTAG_loca && table->TransformLength ) { FT_ERROR(( "woff2_open_font: Invalid loca `transformLength'.\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } } if ( src_offset + table->TransformLength < src_offset ) { FT_ERROR(( "woff2_open_font: invalid WOFF2 table directory.\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } table->src_offset = src_offset; table->src_length = table->TransformLength; src_offset += table->TransformLength; table->flags = flags; FT_TRACE2(( " %c%c%c%c %08d %08d %08ld %08ld %08ld\n", (FT_Char)( table->Tag >> 24 ), (FT_Char)( table->Tag >> 16 ), (FT_Char)( table->Tag >> 8 ), (FT_Char)( table->Tag ), table->FlagByte & 0x3f, ( table->FlagByte >> 6 ) & 0x03, table->dst_length, table->TransformLength, table->src_offset )); indices[nn] = table; } /* End of last table is uncompressed size. */ last_table = indices[woff2.num_tables - 1]; woff2.uncompressed_size = last_table->src_offset + last_table->src_length; if ( woff2.uncompressed_size < last_table->src_offset ) { error = FT_THROW( Invalid_Table ); goto Exit; } FT_TRACE2(( "Table directory parsed.\n" )); /* Check for and read collection directory. */ woff2.num_fonts = 1; woff2.header_version = 0; if ( woff2.flavor == TTAG_ttcf ) { FT_TRACE2(( "Font is a TTC, reading collection directory.\n" )); if ( FT_READ_ULONG( woff2.header_version ) ) goto Exit; if ( woff2.header_version != 0x00010000 && woff2.header_version != 0x00020000 ) { error = FT_THROW( Invalid_Table ); goto Exit; } if ( READ_255USHORT( woff2.num_fonts ) ) goto Exit; if ( !woff2.num_fonts ) { error = FT_THROW( Invalid_Table ); goto Exit; } FT_TRACE4(( "Number of fonts in TTC: %d\n", woff2.num_fonts )); if ( FT_NEW_ARRAY( woff2.ttc_fonts, woff2.num_fonts ) ) goto Exit; for ( nn = 0; nn < woff2.num_fonts; nn++ ) { WOFF2_TtcFont ttc_font = woff2.ttc_fonts + nn; if ( READ_255USHORT( ttc_font->num_tables ) ) goto Exit; if ( FT_READ_ULONG( ttc_font->flavor ) ) goto Exit; if ( FT_NEW_ARRAY( ttc_font->table_indices, ttc_font->num_tables ) ) goto Exit; FT_TRACE5(( "Number of tables in font %d: %d\n", nn, ttc_font->num_tables )); #ifdef FT_DEBUG_LEVEL_TRACE if ( ttc_font->num_tables ) FT_TRACE6(( " Indices: " )); #endif glyf_index = 0; loca_index = 0; for ( j = 0; j < ttc_font->num_tables; j++ ) { FT_UShort table_index; WOFF2_Table table; if ( READ_255USHORT( table_index ) ) goto Exit; FT_TRACE6(( "%hu ", table_index )); if ( table_index >= woff2.num_tables ) { FT_ERROR(( "woff2_open_font: invalid table index\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } ttc_font->table_indices[j] = table_index; table = indices[table_index]; if ( table->Tag == TTAG_loca ) loca_index = table_index; if ( table->Tag == TTAG_glyf ) glyf_index = table_index; } #ifdef FT_DEBUG_LEVEL_TRACE if ( ttc_font->num_tables ) FT_TRACE6(( "\n" )); #endif /* glyf and loca must be consecutive */ if ( glyf_index > 0 || loca_index > 0 ) { if ( glyf_index > loca_index || loca_index - glyf_index != 1 ) { error = FT_THROW( Invalid_Table ); goto Exit; } } } /* Collection directory reading complete. */ FT_TRACE2(( "WOFF2 collection directory is valid.\n" )); } else woff2.ttc_fonts = NULL; woff2.compressed_offset = FT_STREAM_POS(); file_offset = ROUND4( woff2.compressed_offset + woff2.totalCompressedSize ); /* Some more checks before we start reading the tables. */ if ( file_offset > woff2.length ) { error = FT_THROW( Invalid_Table ); goto Exit; } if ( woff2.metaOffset ) { if ( file_offset != woff2.metaOffset ) { error = FT_THROW( Invalid_Table ); goto Exit; } file_offset = ROUND4(woff2.metaOffset + woff2.metaLength); } if ( woff2.privOffset ) { if ( file_offset != woff2.privOffset ) { error = FT_THROW( Invalid_Table ); goto Exit; } file_offset = ROUND4(woff2.privOffset + woff2.privLength); } if ( file_offset != ( ROUND4( woff2.length ) ) ) { error = FT_THROW( Invalid_Table ); goto Exit; } /* Validate requested face index. */ *num_faces = woff2.num_fonts; /* value -(N+1) requests information on index N */ if ( *face_instance_index < 0 && face_index > 0 ) face_index--; if ( face_index >= woff2.num_fonts ) { if ( *face_instance_index >= 0 ) { error = FT_THROW( Invalid_Argument ); goto Exit; } else face_index = 0; } /* Only retain tables of the requested face in a TTC. */ if ( woff2.header_version ) { WOFF2_TtcFont ttc_font = woff2.ttc_fonts + face_index; /* Create a temporary array. */ if ( FT_QNEW_ARRAY( temp_indices, ttc_font->num_tables ) ) goto Exit; FT_TRACE4(( "Storing tables for TTC face index %d.\n", face_index )); for ( nn = 0; nn < ttc_font->num_tables; nn++ ) temp_indices[nn] = indices[ttc_font->table_indices[nn]]; /* Resize array to required size. */ if ( FT_QRENEW_ARRAY( indices, woff2.num_tables, ttc_font->num_tables ) ) goto Exit; for ( nn = 0; nn < ttc_font->num_tables; nn++ ) indices[nn] = temp_indices[nn]; FT_FREE( temp_indices ); /* Change header values. */ woff2.flavor = ttc_font->flavor; woff2.num_tables = ttc_font->num_tables; } /* We need to allocate this much at the minimum. */ sfnt_size = 12 + woff2.num_tables * 16UL; /* This is what we normally expect. */ /* Initially trust `totalSfntSize' and change later as required. */ if ( woff2.totalSfntSize > sfnt_size ) { /* However, adjust the value to something reasonable. */ /* Factor 64 is heuristic. */ if ( ( woff2.totalSfntSize >> 6 ) > woff2.length ) sfnt_size = woff2.length << 6; else sfnt_size = woff2.totalSfntSize; /* Value 1<<26 = 67108864 is heuristic. */ if (sfnt_size >= (1 << 26)) sfnt_size = 1 << 26; #ifdef FT_DEBUG_LEVEL_TRACE if ( sfnt_size != woff2.totalSfntSize ) FT_TRACE4(( "adjusting estimate of uncompressed font size" " to %lu bytes\n", sfnt_size )); #endif } /* Write sfnt header. */ if ( FT_QALLOC( sfnt, sfnt_size ) || FT_NEW( sfnt_stream ) ) goto Exit; sfnt_header = sfnt; WRITE_ULONG( sfnt_header, woff2.flavor ); if ( woff2.num_tables ) { FT_UInt searchRange, entrySelector, rangeShift, x; x = woff2.num_tables; entrySelector = 0; while ( x ) { x >>= 1; entrySelector += 1; } entrySelector--; searchRange = ( 1 << entrySelector ) * 16; rangeShift = ( woff2.num_tables * 16 ) - searchRange; WRITE_USHORT( sfnt_header, woff2.num_tables ); WRITE_USHORT( sfnt_header, searchRange ); WRITE_USHORT( sfnt_header, entrySelector ); WRITE_USHORT( sfnt_header, rangeShift ); } info.header_checksum = compute_ULong_sum( sfnt, 12 ); /* Sort tables by tag. */ ft_qsort( indices, woff2.num_tables, sizeof ( WOFF2_Table ), compare_tags ); /* reject fonts that have multiple tables with the same tag */ for ( nn = 1; nn < woff2.num_tables; nn++ ) { FT_Tag tag = indices[nn]->Tag; if ( tag == indices[nn - 1]->Tag ) { FT_ERROR(( "woff2_open_font:" " multiple tables with tag `%c%c%c%c'.\n", (FT_Char)( tag >> 24 ), (FT_Char)( tag >> 16 ), (FT_Char)( tag >> 8 ), (FT_Char)( tag ) )); error = FT_THROW( Invalid_Table ); goto Exit; } } if ( woff2.uncompressed_size < 1 ) { error = FT_THROW( Invalid_Table ); goto Exit; } if ( woff2.uncompressed_size > sfnt_size ) { FT_ERROR(( "woff2_open_font: SFNT table lengths are too large.\n" )); error = FT_THROW( Invalid_Table ); goto Exit; } /* Allocate memory for uncompressed table data. */ if ( FT_QALLOC( uncompressed_buf, woff2.uncompressed_size ) || FT_FRAME_ENTER( woff2.totalCompressedSize ) ) goto Exit; /* Uncompress the stream. */ error = woff2_decompress( uncompressed_buf, woff2.uncompressed_size, stream->cursor, woff2.totalCompressedSize ); FT_FRAME_EXIT(); if ( error ) goto Exit; error = reconstruct_font( uncompressed_buf, woff2.uncompressed_size, indices, &woff2, &info, &sfnt, &sfnt_size, memory ); if ( error ) goto Exit; /* Resize `sfnt' to actual size of sfnt stream. */ if ( woff2.actual_sfnt_size < sfnt_size ) { FT_TRACE5(( "Trimming sfnt stream from %lu to %lu.\n", sfnt_size, woff2.actual_sfnt_size )); if ( FT_REALLOC( sfnt, (FT_ULong)( sfnt_size ), (FT_ULong)( woff2.actual_sfnt_size ) ) ) goto Exit; } /* `reconstruct_font' has done all the work. */ /* Swap out stream and return. */ FT_Stream_OpenMemory( sfnt_stream, sfnt, woff2.actual_sfnt_size ); sfnt_stream->memory = stream->memory; sfnt_stream->close = stream_close; FT_Stream_Free( face->root.stream, ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 ); face->root.stream = sfnt_stream; face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; /* Set face_index to 0 or -1. */ if ( *face_instance_index >= 0 ) *face_instance_index = 0; else *face_instance_index = -1; FT_TRACE2(( "woff2_open_font: SFNT synthesized.\n" )); Exit: FT_FREE( tables ); FT_FREE( indices ); FT_FREE( uncompressed_buf ); FT_FREE( info.x_mins ); if ( woff2.ttc_fonts ) { WOFF2_TtcFont ttc_font = woff2.ttc_fonts; for ( nn = 0; nn < woff2.num_fonts; nn++ ) { FT_FREE( ttc_font->table_indices ); ttc_font++; } FT_FREE( woff2.ttc_fonts ); } if ( error ) { FT_FREE( sfnt ); if ( sfnt_stream ) { FT_Stream_Close( sfnt_stream ); FT_FREE( sfnt_stream ); } } return error; } #undef READ_255USHORT #undef READ_BASE128 #undef ROUND4 #undef WRITE_USHORT #undef WRITE_ULONG #undef WRITE_SHORT #undef WRITE_SFNT_BUF #undef WRITE_SFNT_BUF_AT #undef N_CONTOUR_STREAM #undef N_POINTS_STREAM #undef FLAG_STREAM #undef GLYPH_STREAM #undef COMPOSITE_STREAM #undef BBOX_STREAM #undef INSTRUCTION_STREAM #else /* !FT_CONFIG_OPTION_USE_BROTLI */ /* ANSI C doesn't like empty source files */ typedef int _sfwoff2_dummy; #endif /* !FT_CONFIG_OPTION_USE_BROTLI */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfwoff2.c
C++
gpl-3.0
66,393
/**************************************************************************** * * sfwoff2.h * * WOFFF2 format management (specification). * * Copyright (C) 2019-2022 by * Nikhil Ramakrishnan, 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 SFWOFF2_H_ #define SFWOFF2_H_ #include <freetype/internal/sfnt.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_USE_BROTLI /* Leave the first byte open to store `flag_byte'. */ #define WOFF2_FLAGS_TRANSFORM 1 << 8 #define WOFF2_SFNT_HEADER_SIZE 12 #define WOFF2_SFNT_ENTRY_SIZE 16 /* Suggested maximum size for output. */ #define WOFF2_DEFAULT_MAX_SIZE 30 * 1024 * 1024 /* 98% of Google Fonts have no glyph above 5k bytes. */ #define WOFF2_DEFAULT_GLYPH_BUF 5120 /* Composite glyph flags. */ /* See `CompositeGlyph.java' in `sfntly' for full definitions. */ #define FLAG_ARG_1_AND_2_ARE_WORDS 1 << 0 #define FLAG_WE_HAVE_A_SCALE 1 << 3 #define FLAG_MORE_COMPONENTS 1 << 5 #define FLAG_WE_HAVE_AN_X_AND_Y_SCALE 1 << 6 #define FLAG_WE_HAVE_A_TWO_BY_TWO 1 << 7 #define FLAG_WE_HAVE_INSTRUCTIONS 1 << 8 /* Simple glyph flags */ #define GLYF_ON_CURVE 1 << 0 #define GLYF_X_SHORT 1 << 1 #define GLYF_Y_SHORT 1 << 2 #define GLYF_REPEAT 1 << 3 #define GLYF_THIS_X_IS_SAME 1 << 4 #define GLYF_THIS_Y_IS_SAME 1 << 5 #define GLYF_OVERLAP_SIMPLE 1 << 6 /* Other constants */ #define CONTOUR_OFFSET_END_POINT 10 FT_LOCAL( FT_Error ) woff2_open_font( FT_Stream stream, TT_Face face, FT_Int* face_index, FT_Long* num_faces ); #endif /* FT_CONFIG_OPTION_USE_BROTLI */ FT_END_HEADER #endif /* SFWOFF2_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/sfwoff2.h
C++
gpl-3.0
2,124
/**************************************************************************** * * ttbdf.c * * TrueType and OpenType embedded BDF properties (body). * * Copyright (C) 2005-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include "ttbdf.h" #include "sferrors.h" #ifdef TT_CONFIG_OPTION_BDF /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttbdf FT_LOCAL_DEF( void ) tt_face_free_bdf_props( TT_Face face ) { TT_BDF bdf = &face->bdf; if ( bdf->loaded ) { FT_Stream stream = FT_FACE( face )->stream; if ( bdf->table ) FT_FRAME_RELEASE( bdf->table ); bdf->table_end = NULL; bdf->strings = NULL; bdf->strings_size = 0; } } static FT_Error tt_face_load_bdf_props( TT_Face face, FT_Stream stream ) { TT_BDF bdf = &face->bdf; FT_ULong length; FT_Error error; FT_ZERO( bdf ); error = tt_face_goto_table( face, TTAG_BDF, stream, &length ); if ( error || length < 8 || FT_FRAME_EXTRACT( length, bdf->table ) ) { error = FT_THROW( Invalid_Table ); goto Exit; } bdf->table_end = bdf->table + length; { FT_Byte* p = bdf->table; FT_UInt version = FT_NEXT_USHORT( p ); FT_UInt num_strikes = FT_NEXT_USHORT( p ); FT_ULong strings = FT_NEXT_ULONG ( p ); FT_UInt count; FT_Byte* strike; if ( version != 0x0001 || strings < 8 || ( strings - 8 ) / 4 < num_strikes || strings + 1 > length ) { goto BadTable; } bdf->num_strikes = num_strikes; bdf->strings = bdf->table + strings; bdf->strings_size = length - strings; count = bdf->num_strikes; p = bdf->table + 8; strike = p + count * 4; for ( ; count > 0; count-- ) { FT_UInt num_items = FT_PEEK_USHORT( p + 2 ); /* * We don't need to check the value sets themselves, since this * is done later. */ strike += 10 * num_items; p += 4; } if ( strike > bdf->strings ) goto BadTable; } bdf->loaded = 1; Exit: return error; BadTable: FT_FRAME_RELEASE( bdf->table ); FT_ZERO( bdf ); error = FT_THROW( Invalid_Table ); goto Exit; } FT_LOCAL_DEF( FT_Error ) tt_face_find_bdf_prop( TT_Face face, const char* property_name, BDF_PropertyRec *aprop ) { TT_BDF bdf = &face->bdf; FT_Size size = FT_FACE( face )->size; FT_Error error = FT_Err_Ok; FT_Byte* p; FT_UInt count; FT_Byte* strike; FT_Offset property_len; aprop->type = BDF_PROPERTY_TYPE_NONE; if ( bdf->loaded == 0 ) { error = tt_face_load_bdf_props( face, FT_FACE( face )->stream ); if ( error ) goto Exit; } count = bdf->num_strikes; p = bdf->table + 8; strike = p + 4 * count; error = FT_ERR( Invalid_Argument ); if ( !size || !property_name ) goto Exit; property_len = ft_strlen( property_name ); if ( property_len == 0 ) goto Exit; for ( ; count > 0; count-- ) { FT_UInt _ppem = FT_NEXT_USHORT( p ); FT_UInt _count = FT_NEXT_USHORT( p ); if ( _ppem == size->metrics.y_ppem ) { count = _count; goto FoundStrike; } strike += 10 * _count; } goto Exit; FoundStrike: p = strike; for ( ; count > 0; count-- ) { FT_UInt type = FT_PEEK_USHORT( p + 4 ); if ( ( type & 0x10 ) != 0 ) { FT_UInt32 name_offset = FT_PEEK_ULONG( p ); FT_UInt32 value = FT_PEEK_ULONG( p + 6 ); /* be a bit paranoid for invalid entries here */ if ( name_offset < bdf->strings_size && property_len < bdf->strings_size - name_offset && ft_strncmp( property_name, (const char*)bdf->strings + name_offset, bdf->strings_size - name_offset ) == 0 ) { switch ( type & 0x0F ) { case 0x00: /* string */ case 0x01: /* atoms */ /* check that the content is really 0-terminated */ if ( value < bdf->strings_size && ft_memchr( bdf->strings + value, 0, bdf->strings_size ) ) { aprop->type = BDF_PROPERTY_TYPE_ATOM; aprop->u.atom = (const char*)bdf->strings + value; error = FT_Err_Ok; goto Exit; } break; case 0x02: aprop->type = BDF_PROPERTY_TYPE_INTEGER; aprop->u.integer = (FT_Int32)value; error = FT_Err_Ok; goto Exit; case 0x03: aprop->type = BDF_PROPERTY_TYPE_CARDINAL; aprop->u.cardinal = value; error = FT_Err_Ok; goto Exit; default: ; } } } p += 10; } Exit: return error; } #else /* !TT_CONFIG_OPTION_BDF */ /* ANSI C doesn't like empty source files */ typedef int _tt_bdf_dummy; #endif /* !TT_CONFIG_OPTION_BDF */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttbdf.c
C++
gpl-3.0
6,180
/**************************************************************************** * * ttbdf.h * * TrueType and OpenType embedded BDF properties (specification). * * Copyright (C) 2005-2022 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 TTBDF_H_ #define TTBDF_H_ #include "ttload.h" #include <freetype/ftbdf.h> FT_BEGIN_HEADER #ifdef TT_CONFIG_OPTION_BDF FT_LOCAL( void ) tt_face_free_bdf_props( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_find_bdf_prop( TT_Face face, const char* property_name, BDF_PropertyRec *aprop ); #endif /* TT_CONFIG_OPTION_BDF */ FT_END_HEADER #endif /* TTBDF_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttbdf.h
C++
gpl-3.0
1,029
/**************************************************************************** * * ttcmap.c * * TrueType character mapping table (cmap) support (body). * * Copyright (C) 2002-2022 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 <freetype/internal/ftdebug.h> #include "sferrors.h" /* must come before `ftvalid.h' */ #include <freetype/internal/ftvalid.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/services/svpscmap.h> #include "ttload.h" #include "ttcmap.h" #include "ttpost.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttcmap #define TT_PEEK_SHORT FT_PEEK_SHORT #define TT_PEEK_USHORT FT_PEEK_USHORT #define TT_PEEK_UINT24 FT_PEEK_UOFF3 #define TT_PEEK_LONG FT_PEEK_LONG #define TT_PEEK_ULONG FT_PEEK_ULONG #define TT_NEXT_SHORT FT_NEXT_SHORT #define TT_NEXT_USHORT FT_NEXT_USHORT #define TT_NEXT_UINT24 FT_NEXT_UOFF3 #define TT_NEXT_LONG FT_NEXT_LONG #define TT_NEXT_ULONG FT_NEXT_ULONG /* Too large glyph index return values are caught in `FT_Get_Char_Index' */ /* and `FT_Get_Next_Char' (the latter calls the internal `next' function */ /* again in this case). To mark character code return values as invalid */ /* it is sufficient to set the corresponding glyph index return value to */ /* zero. */ FT_CALLBACK_DEF( FT_Error ) tt_cmap_init( TT_CMap cmap, FT_Byte* table ) { cmap->data = table; return FT_Err_Ok; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 0 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 0 * length 2 USHORT table length in bytes * language 4 USHORT Mac language code * glyph_ids 6 BYTE[256] array of glyph indices * 262 */ #ifdef TT_CONFIG_CMAP_FORMAT_0 FT_CALLBACK_DEF( FT_Error ) tt_cmap0_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 262 ) FT_INVALID_TOO_SHORT; /* check glyph indices whenever necessary */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt n, idx; p = table + 6; for ( n = 0; n < 256; n++ ) { idx = *p++; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap0_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_Byte* table = cmap->data; return char_code < 256 ? table[6 + char_code] : 0; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap0_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_Byte* table = cmap->data; FT_UInt32 charcode = *pchar_code; FT_UInt32 result = 0; FT_UInt gindex = 0; table += 6; /* go to glyph IDs */ while ( ++charcode < 256 ) { gindex = table[charcode]; if ( gindex != 0 ) { result = charcode; break; } } *pchar_code = result; return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap0_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 0; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap0_class_rec, sizeof ( TT_CMapRec ), (FT_CMap_InitFunc) tt_cmap_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap0_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap0_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 0, (TT_CMap_ValidateFunc)tt_cmap0_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap0_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_0 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 2 *****/ /***** *****/ /***** This is used for certain CJK encodings that encode text in a *****/ /***** mixed 8/16 bits encoding along the following lines. *****/ /***** *****/ /***** * Certain byte values correspond to an 8-bit character code *****/ /***** (typically in the range 0..127 for ASCII compatibility). *****/ /***** *****/ /***** * Certain byte values signal the first byte of a 2-byte *****/ /***** character code (but these values are also valid as the *****/ /***** second byte of a 2-byte character). *****/ /***** *****/ /***** The following charmap lookup and iteration functions all *****/ /***** assume that the value `charcode' fulfills the following. *****/ /***** *****/ /***** - For one-byte characters, `charcode' is simply the *****/ /***** character code. *****/ /***** *****/ /***** - For two-byte characters, `charcode' is the 2-byte *****/ /***** character code in big endian format. More precisely: *****/ /***** *****/ /***** (charcode >> 8) is the first byte value *****/ /***** (charcode & 0xFF) is the second byte value *****/ /***** *****/ /***** Note that not all values of `charcode' are valid according *****/ /***** to these rules, and the function moderately checks the *****/ /***** arguments. *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 2 * length 2 USHORT table length in bytes * language 4 USHORT Mac language code * keys 6 USHORT[256] sub-header keys * subs 518 SUBHEAD[NSUBS] sub-headers array * glyph_ids 518+NSUB*8 USHORT[] glyph ID array * * The `keys' table is used to map charcode high bytes to sub-headers. * The value of `NSUBS' is the number of sub-headers defined in the * table and is computed by finding the maximum of the `keys' table. * * Note that for any `n', `keys[n]' is a byte offset within the `subs' * table, i.e., it is the corresponding sub-header index multiplied * by 8. * * Each sub-header has the following format. * * NAME OFFSET TYPE DESCRIPTION * * first 0 USHORT first valid low-byte * count 2 USHORT number of valid low-bytes * delta 4 SHORT see below * offset 6 USHORT see below * * A sub-header defines, for each high byte, the range of valid * low bytes within the charmap. Note that the range defined by `first' * and `count' must be completely included in the interval [0..255] * according to the specification. * * If a character code is contained within a given sub-header, then * mapping it to a glyph index is done as follows. * * - The value of `offset' is read. This is a _byte_ distance from the * location of the `offset' field itself into a slice of the * `glyph_ids' table. Let's call it `slice' (it is a USHORT[], too). * * - The value `slice[char.lo - first]' is read. If it is 0, there is * no glyph for the charcode. Otherwise, the value of `delta' is * added to it (modulo 65536) to form a new glyph index. * * It is up to the validation routine to check that all offsets fall * within the glyph IDs table (and not within the `subs' table itself or * outside of the CMap). */ #ifdef TT_CONFIG_CMAP_FORMAT_2 FT_CALLBACK_DEF( FT_Error ) tt_cmap2_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_UInt n, max_subs; FT_Byte* keys; /* keys table */ FT_Byte* subs; /* sub-headers */ FT_Byte* glyph_ids; /* glyph ID array */ if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 6 + 512 ) FT_INVALID_TOO_SHORT; keys = table + 6; /* parse keys to compute sub-headers count */ p = keys; max_subs = 0; for ( n = 0; n < 256; n++ ) { FT_UInt idx = TT_NEXT_USHORT( p ); /* value must be multiple of 8 */ if ( valid->level >= FT_VALIDATE_PARANOID && ( idx & 7 ) != 0 ) FT_INVALID_DATA; idx >>= 3; if ( idx > max_subs ) max_subs = idx; } FT_ASSERT( p == table + 518 ); subs = p; glyph_ids = subs + ( max_subs + 1 ) * 8; if ( glyph_ids > valid->limit ) FT_INVALID_TOO_SHORT; /* parse sub-headers */ for ( n = 0; n <= max_subs; n++ ) { FT_UInt first_code, code_count, offset; FT_Int delta; first_code = TT_NEXT_USHORT( p ); code_count = TT_NEXT_USHORT( p ); delta = TT_NEXT_SHORT( p ); offset = TT_NEXT_USHORT( p ); /* many Dynalab fonts have empty sub-headers */ if ( code_count == 0 ) continue; /* check range within 0..255 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { if ( first_code >= 256 || code_count > 256 - first_code ) FT_INVALID_DATA; } /* check offset */ if ( offset != 0 ) { FT_Byte* ids; ids = p - 2 + offset; if ( ids < glyph_ids || ids + code_count * 2 > table + length ) FT_INVALID_OFFSET; /* check glyph IDs */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_Byte* limit = p + code_count * 2; FT_UInt idx; for ( ; p < limit; ) { idx = TT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } } return FT_Err_Ok; } /* return sub header corresponding to a given character code */ /* NULL on invalid charcode */ static FT_Byte* tt_cmap2_get_subheader( FT_Byte* table, FT_UInt32 char_code ) { FT_Byte* result = NULL; if ( char_code < 0x10000UL ) { FT_UInt char_lo = (FT_UInt)( char_code & 0xFF ); FT_UInt char_hi = (FT_UInt)( char_code >> 8 ); FT_Byte* p = table + 6; /* keys table */ FT_Byte* subs = table + 518; /* subheaders table */ FT_Byte* sub; if ( char_hi == 0 ) { /* an 8-bit character code -- we use subHeader 0 in this case */ /* to test whether the character code is in the charmap */ /* */ sub = subs; /* jump to first sub-header */ /* check that the sub-header for this byte is 0, which */ /* indicates that it is really a valid one-byte value; */ /* otherwise, return 0 */ /* */ p += char_lo * 2; if ( TT_PEEK_USHORT( p ) != 0 ) goto Exit; } else { /* a 16-bit character code */ /* jump to key entry */ p += char_hi * 2; /* jump to sub-header */ sub = subs + ( FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 8 ) ); /* check that the high byte isn't a valid one-byte value */ if ( sub == subs ) goto Exit; } result = sub; } Exit: return result; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap2_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_Byte* table = cmap->data; FT_UInt result = 0; FT_Byte* subheader; subheader = tt_cmap2_get_subheader( table, char_code ); if ( subheader ) { FT_Byte* p = subheader; FT_UInt idx = (FT_UInt)(char_code & 0xFF); FT_UInt start, count; FT_Int delta; FT_UInt offset; start = TT_NEXT_USHORT( p ); count = TT_NEXT_USHORT( p ); delta = TT_NEXT_SHORT ( p ); offset = TT_PEEK_USHORT( p ); idx -= start; if ( idx < count && offset != 0 ) { p += offset + 2 * idx; idx = TT_PEEK_USHORT( p ); if ( idx != 0 ) result = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU; } } return result; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap2_char_next( TT_CMap cmap, FT_UInt32 *pcharcode ) { FT_Byte* table = cmap->data; FT_UInt gindex = 0; FT_UInt32 result = 0; FT_UInt32 charcode = *pcharcode + 1; FT_Byte* subheader; while ( charcode < 0x10000UL ) { subheader = tt_cmap2_get_subheader( table, charcode ); if ( subheader ) { FT_Byte* p = subheader; FT_UInt start = TT_NEXT_USHORT( p ); FT_UInt count = TT_NEXT_USHORT( p ); FT_Int delta = TT_NEXT_SHORT ( p ); FT_UInt offset = TT_PEEK_USHORT( p ); FT_UInt char_lo = (FT_UInt)( charcode & 0xFF ); FT_UInt pos, idx; if ( char_lo >= start + count && charcode <= 0xFF ) { /* this happens only for a malformed cmap */ charcode = 0x100; continue; } if ( offset == 0 ) { if ( charcode == 0x100 ) goto Exit; /* this happens only for a malformed cmap */ goto Next_SubHeader; } if ( char_lo < start ) { char_lo = start; pos = 0; } else pos = (FT_UInt)( char_lo - start ); p += offset + pos * 2; charcode = FT_PAD_FLOOR( charcode, 256 ) + char_lo; for ( ; pos < count; pos++, charcode++ ) { idx = TT_NEXT_USHORT( p ); if ( idx != 0 ) { gindex = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU; if ( gindex != 0 ) { result = charcode; goto Exit; } } } /* if unsuccessful, avoid `charcode' leaving */ /* the current 256-character block */ if ( count ) charcode--; } /* If `charcode' is <= 0xFF, retry with `charcode + 1'. */ /* Otherwise jump to the next 256-character block and retry. */ Next_SubHeader: if ( charcode <= 0xFF ) charcode++; else charcode = FT_PAD_FLOOR( charcode, 0x100 ) + 0x100; } Exit: *pcharcode = result; return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap2_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 2; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap2_class_rec, sizeof ( TT_CMapRec ), (FT_CMap_InitFunc) tt_cmap_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap2_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap2_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 2, (TT_CMap_ValidateFunc)tt_cmap2_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap2_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_2 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 4 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 4 * length 2 USHORT table length * in bytes * language 4 USHORT Mac language code * * segCountX2 6 USHORT 2*NUM_SEGS * searchRange 8 USHORT 2*(1 << LOG_SEGS) * entrySelector 10 USHORT LOG_SEGS * rangeShift 12 USHORT segCountX2 - * searchRange * * endCount 14 USHORT[NUM_SEGS] end charcode for * each segment; last * is 0xFFFF * * pad 14+NUM_SEGS*2 USHORT padding * * startCount 16+NUM_SEGS*2 USHORT[NUM_SEGS] first charcode for * each segment * * idDelta 16+NUM_SEGS*4 SHORT[NUM_SEGS] delta for each * segment * idOffset 16+NUM_SEGS*6 SHORT[NUM_SEGS] range offset for * each segment; can be * zero * * glyphIds 16+NUM_SEGS*8 USHORT[] array of glyph ID * ranges * * Character codes are modelled by a series of ordered (increasing) * intervals called segments. Each segment has start and end codes, * provided by the `startCount' and `endCount' arrays. Segments must * not overlap, and the last segment should always contain the value * 0xFFFF for `endCount'. * * The fields `searchRange', `entrySelector' and `rangeShift' are better * ignored (they are traces of over-engineering in the TrueType * specification). * * Each segment also has a signed `delta', as well as an optional offset * within the `glyphIds' table. * * If a segment's idOffset is 0, the glyph index corresponding to any * charcode within the segment is obtained by adding the value of * `idDelta' directly to the charcode, modulo 65536. * * Otherwise, a glyph index is taken from the glyph IDs sub-array for * the segment, and the value of `idDelta' is added to it. * * * Finally, note that a lot of fonts contain an invalid last segment, * where `start' and `end' are correctly set to 0xFFFF but both `delta' * and `offset' are incorrect (e.g., `opens___.ttf' which comes with * OpenOffice.org). We need special code to deal with them correctly. */ #ifdef TT_CONFIG_CMAP_FORMAT_4 typedef struct TT_CMap4Rec_ { TT_CMapRec cmap; FT_UInt32 cur_charcode; /* current charcode */ FT_UInt cur_gindex; /* current glyph index */ FT_UInt num_ranges; FT_UInt cur_range; FT_UInt cur_start; FT_UInt cur_end; FT_Int cur_delta; FT_Byte* cur_values; } TT_CMap4Rec, *TT_CMap4; FT_CALLBACK_DEF( FT_Error ) tt_cmap4_init( TT_CMap4 cmap, FT_Byte* table ) { FT_Byte* p; cmap->cmap.data = table; p = table + 6; cmap->num_ranges = FT_PEEK_USHORT( p ) >> 1; cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; return FT_Err_Ok; } static FT_Int tt_cmap4_set_range( TT_CMap4 cmap, FT_UInt range_index ) { FT_Byte* table = cmap->cmap.data; FT_Byte* p; FT_UInt num_ranges = cmap->num_ranges; while ( range_index < num_ranges ) { FT_UInt offset; p = table + 14 + range_index * 2; cmap->cur_end = FT_PEEK_USHORT( p ); p += 2 + num_ranges * 2; cmap->cur_start = FT_PEEK_USHORT( p ); p += num_ranges * 2; cmap->cur_delta = FT_PEEK_SHORT( p ); p += num_ranges * 2; offset = FT_PEEK_USHORT( p ); /* some fonts have an incorrect last segment; */ /* we have to catch it */ if ( range_index >= num_ranges - 1 && cmap->cur_start == 0xFFFFU && cmap->cur_end == 0xFFFFU ) { TT_Face face = (TT_Face)cmap->cmap.cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; if ( offset && p + offset + 2 > limit ) { cmap->cur_delta = 1; offset = 0; } } if ( offset != 0xFFFFU ) { cmap->cur_values = offset ? p + offset : NULL; cmap->cur_range = range_index; return 0; } /* we skip empty segments */ range_index++; } return -1; } /* search the index of the charcode next to cmap->cur_charcode; */ /* caller should call tt_cmap4_set_range with proper range */ /* before calling this function */ /* */ static void tt_cmap4_next( TT_CMap4 cmap ) { TT_Face face = (TT_Face)cmap->cmap.cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; FT_UInt charcode; if ( cmap->cur_charcode >= 0xFFFFUL ) goto Fail; charcode = (FT_UInt)cmap->cur_charcode + 1; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; for (;;) { FT_Byte* values = cmap->cur_values; FT_UInt end = cmap->cur_end; FT_Int delta = cmap->cur_delta; if ( charcode <= end ) { if ( values ) { FT_Byte* p = values + 2 * ( charcode - cmap->cur_start ); /* if p > limit, the whole segment is invalid */ if ( p > limit ) goto Next_Segment; do { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex ) { gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU; if ( gindex ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } } while ( ++charcode <= end ); } else { do { FT_UInt gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU; if ( gindex >= (FT_UInt)face->root.num_glyphs ) { /* we have an invalid glyph index; if there is an overflow, */ /* we can adjust `charcode', otherwise the whole segment is */ /* invalid */ gindex = 0; if ( (FT_Int)charcode + delta < 0 && (FT_Int)end + delta >= 0 ) charcode = (FT_UInt)( -delta ); else if ( (FT_Int)charcode + delta < 0x10000L && (FT_Int)end + delta >= 0x10000L ) charcode = (FT_UInt)( 0x10000L - delta ); else goto Next_Segment; } if ( gindex ) { cmap->cur_charcode = charcode; cmap->cur_gindex = gindex; return; } } while ( ++charcode <= end ); } } Next_Segment: /* we need to find another range */ if ( tt_cmap4_set_range( cmap, cmap->cur_range + 1 ) < 0 ) break; if ( charcode < cmap->cur_start ) charcode = cmap->cur_start; } Fail: cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL; cmap->cur_gindex = 0; } FT_CALLBACK_DEF( FT_Error ) tt_cmap4_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length; FT_Byte *ends, *starts, *offsets, *deltas, *glyph_ids; FT_UInt num_segs; FT_Error error = FT_Err_Ok; if ( table + 2 + 2 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; /* skip format */ length = TT_NEXT_USHORT( p ); /* in certain fonts, the `length' field is invalid and goes */ /* out of bound. We try to correct this here... */ if ( table + length > valid->limit ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_TOO_SHORT; length = (FT_UInt)( valid->limit - table ); } /* it also happens that the `length' field is too small; */ /* this is easy to correct */ if ( length < (FT_UInt)( valid->limit - table ) ) { if ( valid->level >= FT_VALIDATE_PARANOID ) FT_INVALID_DATA; length = (FT_UInt)( valid->limit - table ); } if ( length < 16 ) FT_INVALID_TOO_SHORT; p = table + 6; num_segs = TT_NEXT_USHORT( p ); /* read segCountX2 */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check that we have an even value here */ if ( num_segs & 1 ) FT_INVALID_DATA; } num_segs /= 2; if ( length < 16 + num_segs * 2 * 4 ) FT_INVALID_TOO_SHORT; /* check the search parameters - even though we never use them */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID ) { /* check the values of `searchRange', `entrySelector', `rangeShift' */ FT_UInt search_range = TT_NEXT_USHORT( p ); FT_UInt entry_selector = TT_NEXT_USHORT( p ); FT_UInt range_shift = TT_NEXT_USHORT( p ); if ( ( search_range | range_shift ) & 1 ) /* must be even values */ FT_INVALID_DATA; search_range /= 2; range_shift /= 2; /* `search range' is the greatest power of 2 that is <= num_segs */ if ( search_range > num_segs || search_range * 2 < num_segs || search_range + range_shift != num_segs || search_range != ( 1U << entry_selector ) ) FT_INVALID_DATA; } ends = table + 14; starts = table + 16 + num_segs * 2; deltas = starts + num_segs * 2; offsets = deltas + num_segs * 2; glyph_ids = offsets + num_segs * 2; /* check last segment; its end count value must be 0xFFFF */ if ( valid->level >= FT_VALIDATE_PARANOID ) { p = ends + ( num_segs - 1 ) * 2; if ( TT_PEEK_USHORT( p ) != 0xFFFFU ) FT_INVALID_DATA; } { FT_UInt start, end, offset, n; FT_UInt last_start = 0, last_end = 0; FT_Int delta; FT_Byte* p_start = starts; FT_Byte* p_end = ends; FT_Byte* p_delta = deltas; FT_Byte* p_offset = offsets; for ( n = 0; n < num_segs; n++ ) { p = p_offset; start = TT_NEXT_USHORT( p_start ); end = TT_NEXT_USHORT( p_end ); delta = TT_NEXT_SHORT( p_delta ); offset = TT_NEXT_USHORT( p_offset ); if ( start > end ) FT_INVALID_DATA; /* this test should be performed at default validation level; */ /* unfortunately, some popular Asian fonts have overlapping */ /* ranges in their charmaps */ /* */ if ( start <= last_end && n > 0 ) { if ( valid->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; else { /* allow overlapping segments, provided their start points */ /* and end points, respectively, are in ascending order */ /* */ if ( last_start > start || last_end > end ) error |= TT_CMAP_FLAG_UNSORTED; else error |= TT_CMAP_FLAG_OVERLAPPING; } } if ( offset && offset != 0xFFFFU ) { p += offset; /* start of glyph ID array */ /* check that we point within the glyph IDs table only */ if ( valid->level >= FT_VALIDATE_TIGHT ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > table + length ) FT_INVALID_DATA; } /* Some fonts handle the last segment incorrectly. In */ /* theory, 0xFFFF might point to an ordinary glyph -- */ /* a cmap 4 is versatile and could be used for any */ /* encoding, not only Unicode. However, reality shows */ /* that far too many fonts are sloppy and incorrectly */ /* set all fields but `start' and `end' for the last */ /* segment if it contains only a single character. */ /* */ /* We thus omit the test here, delaying it to the */ /* routines that actually access the cmap. */ else if ( n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) { if ( p < glyph_ids || p + ( end - start + 1 ) * 2 > valid->limit ) FT_INVALID_DATA; } /* check glyph indices within the segment range */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt i, idx; for ( i = start; i < end; i++ ) { idx = FT_NEXT_USHORT( p ); if ( idx != 0 ) { idx = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU; if ( idx >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } else if ( offset == 0xFFFFU ) { /* some fonts (erroneously?) use a range offset of 0xFFFF */ /* to mean missing glyph in cmap table */ /* */ if ( valid->level >= FT_VALIDATE_PARANOID || n != num_segs - 1 || !( start == 0xFFFFU && end == 0xFFFFU ) ) FT_INVALID_DATA; } last_start = start; last_end = end; } } return error; } static FT_UInt tt_cmap4_char_map_linear( TT_CMap cmap, FT_UInt32* pcharcode, FT_Bool next ) { TT_Face face = (TT_Face)cmap->cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; FT_UInt num_segs2, start, end, offset; FT_Int delta; FT_UInt i, num_segs; FT_UInt32 charcode = *pcharcode; FT_UInt gindex = 0; FT_Byte* p; FT_Byte* q; p = cmap->data + 6; num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 ); num_segs = num_segs2 >> 1; if ( !num_segs ) return 0; if ( next ) charcode++; if ( charcode > 0xFFFFU ) return 0; /* linear search */ p = cmap->data + 14; /* ends table */ q = cmap->data + 16 + num_segs2; /* starts table */ for ( i = 0; i < num_segs; i++ ) { end = TT_NEXT_USHORT( p ); start = TT_NEXT_USHORT( q ); if ( charcode < start ) { if ( next ) charcode = start; else break; } Again: if ( charcode <= end ) { FT_Byte* r; r = q - 2 + num_segs2; delta = TT_PEEK_SHORT( r ); r += num_segs2; offset = TT_PEEK_USHORT( r ); /* some fonts have an incorrect last segment; */ /* we have to catch it */ if ( i >= num_segs - 1 && start == 0xFFFFU && end == 0xFFFFU ) { if ( offset && r + offset + 2 > limit ) { delta = 1; offset = 0; } } if ( offset == 0xFFFFU ) continue; if ( offset ) { r += offset + ( charcode - start ) * 2; /* if r > limit, the whole segment is invalid */ if ( next && r > limit ) continue; gindex = TT_PEEK_USHORT( r ); if ( gindex ) { gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU; if ( gindex >= (FT_UInt)face->root.num_glyphs ) gindex = 0; } } else { gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU; if ( next && gindex >= (FT_UInt)face->root.num_glyphs ) { /* we have an invalid glyph index; if there is an overflow, */ /* we can adjust `charcode', otherwise the whole segment is */ /* invalid */ gindex = 0; if ( (FT_Int)charcode + delta < 0 && (FT_Int)end + delta >= 0 ) charcode = (FT_UInt)( -delta ); else if ( (FT_Int)charcode + delta < 0x10000L && (FT_Int)end + delta >= 0x10000L ) charcode = (FT_UInt)( 0x10000L - delta ); else continue; } } if ( next && !gindex ) { if ( charcode >= 0xFFFFU ) break; charcode++; goto Again; } break; } } if ( next ) *pcharcode = charcode; return gindex; } static FT_UInt tt_cmap4_char_map_binary( TT_CMap cmap, FT_UInt32* pcharcode, FT_Bool next ) { TT_Face face = (TT_Face)cmap->cmap.charmap.face; FT_Byte* limit = face->cmap_table + face->cmap_size; FT_UInt num_segs2, start, end, offset; FT_Int delta; FT_UInt max, min, mid, num_segs; FT_UInt charcode = (FT_UInt)*pcharcode; FT_UInt gindex = 0; FT_Byte* p; p = cmap->data + 6; num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 ); if ( !num_segs2 ) return 0; num_segs = num_segs2 >> 1; /* make compiler happy */ mid = num_segs; end = 0xFFFFU; if ( next ) charcode++; min = 0; max = num_segs; /* binary search */ while ( min < max ) { mid = ( min + max ) >> 1; p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); if ( charcode < start ) max = mid; else if ( charcode > end ) min = mid + 1; else { p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); /* some fonts have an incorrect last segment; */ /* we have to catch it */ if ( mid >= num_segs - 1 && start == 0xFFFFU && end == 0xFFFFU ) { if ( offset && p + offset + 2 > limit ) { delta = 1; offset = 0; } } /* search the first segment containing `charcode' */ if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPING ) { FT_UInt i; /* call the current segment `max' */ max = mid; if ( offset == 0xFFFFU ) mid = max + 1; /* search in segments before the current segment */ for ( i = max; i > 0; i-- ) { FT_UInt prev_end; FT_Byte* old_p; old_p = p; p = cmap->data + 14 + ( i - 1 ) * 2; prev_end = TT_PEEK_USHORT( p ); if ( charcode > prev_end ) { p = old_p; break; } end = prev_end; p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i - 1; } /* no luck */ if ( mid == max + 1 ) { if ( i != max ) { p = cmap->data + 14 + max * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } mid = max; /* search in segments after the current segment */ for ( i = max + 1; i < num_segs; i++ ) { FT_UInt next_end, next_start; p = cmap->data + 14 + i * 2; next_end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; next_start = TT_PEEK_USHORT( p ); if ( charcode < next_start ) break; end = next_end; start = next_start; p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); if ( offset != 0xFFFFU ) mid = i; } i--; /* still no luck */ if ( mid == max ) { mid = i; break; } } /* end, start, delta, and offset are for the i'th segment */ if ( mid != i ) { p = cmap->data + 14 + mid * 2; end = TT_PEEK_USHORT( p ); p += 2 + num_segs2; start = TT_PEEK_USHORT( p ); p += num_segs2; delta = TT_PEEK_SHORT( p ); p += num_segs2; offset = TT_PEEK_USHORT( p ); } } else { if ( offset == 0xFFFFU ) break; } if ( offset ) { p += offset + ( charcode - start ) * 2; /* if p > limit, the whole segment is invalid */ if ( next && p > limit ) break; gindex = TT_PEEK_USHORT( p ); if ( gindex ) { gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU; if ( gindex >= (FT_UInt)face->root.num_glyphs ) gindex = 0; } } else { gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU; if ( next && gindex >= (FT_UInt)face->root.num_glyphs ) { /* we have an invalid glyph index; if there is an overflow, */ /* we can adjust `charcode', otherwise the whole segment is */ /* invalid */ gindex = 0; if ( (FT_Int)charcode + delta < 0 && (FT_Int)end + delta >= 0 ) charcode = (FT_UInt)( -delta ); else if ( (FT_Int)charcode + delta < 0x10000L && (FT_Int)end + delta >= 0x10000L ) charcode = (FT_UInt)( 0x10000L - delta ); } } break; } } if ( next ) { TT_CMap4 cmap4 = (TT_CMap4)cmap; /* if `charcode' is not in any segment, then `mid' is */ /* the segment nearest to `charcode' */ if ( charcode > end ) { mid++; if ( mid == num_segs ) return 0; } if ( tt_cmap4_set_range( cmap4, mid ) ) { if ( gindex ) *pcharcode = charcode; } else { cmap4->cur_charcode = charcode; if ( gindex ) cmap4->cur_gindex = gindex; else { cmap4->cur_charcode = charcode; tt_cmap4_next( cmap4 ); gindex = cmap4->cur_gindex; } if ( gindex ) *pcharcode = cmap4->cur_charcode; } } return gindex; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap4_char_index( TT_CMap cmap, FT_UInt32 char_code ) { if ( char_code >= 0x10000UL ) return 0; if ( cmap->flags & TT_CMAP_FLAG_UNSORTED ) return tt_cmap4_char_map_linear( cmap, &char_code, 0 ); else return tt_cmap4_char_map_binary( cmap, &char_code, 0 ); } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap4_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_UInt gindex; if ( *pchar_code >= 0xFFFFU ) return 0; if ( cmap->flags & TT_CMAP_FLAG_UNSORTED ) gindex = tt_cmap4_char_map_linear( cmap, pchar_code, 1 ); else { TT_CMap4 cmap4 = (TT_CMap4)cmap; /* no need to search */ if ( *pchar_code == cmap4->cur_charcode ) { tt_cmap4_next( cmap4 ); gindex = cmap4->cur_gindex; if ( gindex ) *pchar_code = cmap4->cur_charcode; } else gindex = tt_cmap4_char_map_binary( cmap, pchar_code, 1 ); } return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap4_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 4; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap4_class_rec, sizeof ( TT_CMap4Rec ), (FT_CMap_InitFunc) tt_cmap4_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap4_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap4_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 4, (TT_CMap_ValidateFunc)tt_cmap4_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap4_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_4 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 6 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 6 * length 2 USHORT table length in bytes * language 4 USHORT Mac language code * * first 6 USHORT first segment code * count 8 USHORT segment size in chars * glyphIds 10 USHORT[count] glyph IDs * * A very simplified segment mapping. */ #ifdef TT_CONFIG_CMAP_FORMAT_6 FT_CALLBACK_DEF( FT_Error ) tt_cmap6_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_UInt length, count; if ( table + 10 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; length = TT_NEXT_USHORT( p ); p = table + 8; /* skip language and start index */ count = TT_NEXT_USHORT( p ); if ( table + length > valid->limit || length < 10 + count * 2 ) FT_INVALID_TOO_SHORT; /* check glyph indices */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt gindex; for ( ; count > 0; count-- ) { gindex = TT_NEXT_USHORT( p ); if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap6_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_Byte* table = cmap->data; FT_UInt result = 0; FT_Byte* p = table + 6; FT_UInt start = TT_NEXT_USHORT( p ); FT_UInt count = TT_NEXT_USHORT( p ); FT_UInt idx = (FT_UInt)( char_code - start ); if ( idx < count ) { p += 2 * idx; result = TT_PEEK_USHORT( p ); } return result; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap6_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_Byte* table = cmap->data; FT_UInt32 result = 0; FT_UInt32 char_code = *pchar_code + 1; FT_UInt gindex = 0; FT_Byte* p = table + 6; FT_UInt start = TT_NEXT_USHORT( p ); FT_UInt count = TT_NEXT_USHORT( p ); FT_UInt idx; if ( char_code >= 0x10000UL ) return 0; if ( char_code < start ) char_code = start; idx = (FT_UInt)( char_code - start ); p += 2 * idx; for ( ; idx < count; idx++ ) { gindex = TT_NEXT_USHORT( p ); if ( gindex != 0 ) { result = char_code; break; } if ( char_code >= 0xFFFFU ) return 0; char_code++; } *pchar_code = result; return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap6_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 4; cmap_info->format = 6; cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap6_class_rec, sizeof ( TT_CMapRec ), (FT_CMap_InitFunc) tt_cmap_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap6_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap6_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 6, (TT_CMap_ValidateFunc)tt_cmap6_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap6_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_6 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 8 *****/ /***** *****/ /***** It is hard to completely understand what the OpenType spec *****/ /***** says about this format, but here is my conclusion. *****/ /***** *****/ /***** The purpose of this format is to easily map UTF-16 text to *****/ /***** glyph indices. Basically, the `char_code' must be in one of *****/ /***** the following formats. *****/ /***** *****/ /***** - A 16-bit value that isn't part of the Unicode Surrogates *****/ /***** Area (i.e. U+D800-U+DFFF). *****/ /***** *****/ /***** - A 32-bit value, made of two surrogate values, i.e.. if *****/ /***** `char_code = (char_hi << 16) | char_lo', then both *****/ /***** `char_hi' and `char_lo' must be in the Surrogates Area. *****/ /***** Area. *****/ /***** *****/ /***** The `is32' table embedded in the charmap indicates whether a *****/ /***** given 16-bit value is in the surrogates area or not. *****/ /***** *****/ /***** So, for any given `char_code', we can assert the following. *****/ /***** *****/ /***** If `char_hi == 0' then we must have `is32[char_lo] == 0'. *****/ /***** *****/ /***** If `char_hi != 0' then we must have both *****/ /***** `is32[char_hi] != 0' and `is32[char_lo] != 0'. *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 8 * reserved 2 USHORT reserved * length 4 ULONG length in bytes * language 8 ULONG Mac language code * is32 12 BYTE[8192] 32-bitness bitmap * count 8204 ULONG number of groups * * This header is followed by `count' groups of the following format: * * start 0 ULONG first charcode * end 4 ULONG last charcode * startId 8 ULONG start glyph ID for the group */ #ifdef TT_CONFIG_CMAP_FORMAT_8 FT_CALLBACK_DEF( FT_Error ) tt_cmap8_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p = table + 4; FT_Byte* is32; FT_UInt32 length; FT_UInt32 num_groups; if ( table + 16 + 8192 > valid->limit ) FT_INVALID_TOO_SHORT; length = TT_NEXT_ULONG( p ); if ( length > (FT_UInt32)( valid->limit - table ) || length < 8192 + 16 ) FT_INVALID_TOO_SHORT; is32 = table + 12; p = is32 + 8192; /* skip `is32' array */ num_groups = TT_NEXT_ULONG( p ); /* p + num_groups * 12 > valid->limit ? */ if ( num_groups > (FT_UInt32)( valid->limit - p ) / 12 ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ { FT_UInt32 n, start, end, start_id, count, last = 0; for ( n = 0; n < num_groups; n++ ) { FT_UInt hi, lo; start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); start_id = TT_NEXT_ULONG( p ); if ( start > end ) FT_INVALID_DATA; if ( n > 0 && start <= last ) FT_INVALID_DATA; if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt32 d = end - start; /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ if ( d > TT_VALID_GLYPH_COUNT( valid ) || start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; count = (FT_UInt32)( end - start + 1 ); if ( start & ~0xFFFFU ) { /* start_hi != 0; check that is32[i] is 1 for each i in */ /* the `hi' and `lo' of the range [start..end] */ for ( ; count > 0; count--, start++ ) { hi = (FT_UInt)( start >> 16 ); lo = (FT_UInt)( start & 0xFFFFU ); if ( (is32[hi >> 3] & ( 0x80 >> ( hi & 7 ) ) ) == 0 ) FT_INVALID_DATA; if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) == 0 ) FT_INVALID_DATA; } } else { /* start_hi == 0; check that is32[i] is 0 for each i in */ /* the range [start..end] */ /* end_hi cannot be != 0! */ if ( end & ~0xFFFFU ) FT_INVALID_DATA; for ( ; count > 0; count--, start++ ) { lo = (FT_UInt)( start & 0xFFFFU ); if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) != 0 ) FT_INVALID_DATA; } } } last = end; } } return FT_Err_Ok; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap8_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_Byte* table = cmap->data; FT_UInt result = 0; FT_Byte* p = table + 8204; FT_UInt32 num_groups = TT_NEXT_ULONG( p ); FT_UInt32 start, end, start_id; for ( ; num_groups > 0; num_groups-- ) { start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); start_id = TT_NEXT_ULONG( p ); if ( char_code < start ) break; if ( char_code <= end ) { if ( start_id > 0xFFFFFFFFUL - ( char_code - start ) ) return 0; result = (FT_UInt)( start_id + ( char_code - start ) ); break; } } return result; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap8_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_Face face = cmap->cmap.charmap.face; FT_UInt32 result = 0; FT_UInt32 char_code; FT_UInt gindex = 0; FT_Byte* table = cmap->data; FT_Byte* p = table + 8204; FT_UInt32 num_groups = TT_NEXT_ULONG( p ); FT_UInt32 start, end, start_id; if ( *pchar_code >= 0xFFFFFFFFUL ) return 0; char_code = *pchar_code + 1; p = table + 8208; for ( ; num_groups > 0; num_groups-- ) { start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); start_id = TT_NEXT_ULONG( p ); if ( char_code < start ) char_code = start; Again: if ( char_code <= end ) { /* ignore invalid group */ if ( start_id > 0xFFFFFFFFUL - ( char_code - start ) ) continue; gindex = (FT_UInt)( start_id + ( char_code - start ) ); /* does first element of group point to `.notdef' glyph? */ if ( gindex == 0 ) { if ( char_code >= 0xFFFFFFFFUL ) break; char_code++; goto Again; } /* if `gindex' is invalid, the remaining values */ /* in this group are invalid, too */ if ( gindex >= (FT_UInt)face->num_glyphs ) { gindex = 0; continue; } result = char_code; break; } } *pchar_code = result; return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap8_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 8; cmap_info->format = 8; cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap8_class_rec, sizeof ( TT_CMapRec ), (FT_CMap_InitFunc) tt_cmap_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap8_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap8_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 8, (TT_CMap_ValidateFunc)tt_cmap8_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap8_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_8 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 10 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 10 * reserved 2 USHORT reserved * length 4 ULONG length in bytes * language 8 ULONG Mac language code * * start 12 ULONG first char in range * count 16 ULONG number of chars in range * glyphIds 20 USHORT[count] glyph indices covered */ #ifdef TT_CONFIG_CMAP_FORMAT_10 FT_CALLBACK_DEF( FT_Error ) tt_cmap10_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p = table + 4; FT_ULong length, count; if ( table + 20 > valid->limit ) FT_INVALID_TOO_SHORT; length = TT_NEXT_ULONG( p ); p = table + 16; count = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || /* length < 20 + count * 2 ? */ length < 20 || ( length - 20 ) / 2 < count ) FT_INVALID_TOO_SHORT; /* check glyph indices */ if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt gindex; for ( ; count > 0; count-- ) { gindex = TT_NEXT_USHORT( p ); if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } return FT_Err_Ok; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap10_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_Byte* table = cmap->data; FT_UInt result = 0; FT_Byte* p = table + 12; FT_UInt32 start = TT_NEXT_ULONG( p ); FT_UInt32 count = TT_NEXT_ULONG( p ); FT_UInt32 idx; if ( char_code < start ) return 0; idx = char_code - start; if ( idx < count ) { p += 2 * idx; result = TT_PEEK_USHORT( p ); } return result; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap10_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_Byte* table = cmap->data; FT_UInt32 char_code; FT_UInt gindex = 0; FT_Byte* p = table + 12; FT_UInt32 start = TT_NEXT_ULONG( p ); FT_UInt32 count = TT_NEXT_ULONG( p ); FT_UInt32 idx; if ( *pchar_code >= 0xFFFFFFFFUL ) return 0; char_code = *pchar_code + 1; if ( char_code < start ) char_code = start; idx = char_code - start; p += 2 * idx; for ( ; idx < count; idx++ ) { gindex = TT_NEXT_USHORT( p ); if ( gindex != 0 ) break; if ( char_code >= 0xFFFFFFFFUL ) return 0; char_code++; } *pchar_code = char_code; return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap10_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 8; cmap_info->format = 10; cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap10_class_rec, sizeof ( TT_CMapRec ), (FT_CMap_InitFunc) tt_cmap_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap10_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap10_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 10, (TT_CMap_ValidateFunc)tt_cmap10_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap10_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_10 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 12 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 12 * reserved 2 USHORT reserved * length 4 ULONG length in bytes * language 8 ULONG Mac language code * count 12 ULONG number of groups * 16 * * This header is followed by `count' groups of the following format: * * start 0 ULONG first charcode * end 4 ULONG last charcode * startId 8 ULONG start glyph ID for the group */ #ifdef TT_CONFIG_CMAP_FORMAT_12 typedef struct TT_CMap12Rec_ { TT_CMapRec cmap; FT_Bool valid; FT_ULong cur_charcode; FT_UInt cur_gindex; FT_ULong cur_group; FT_ULong num_groups; } TT_CMap12Rec, *TT_CMap12; FT_CALLBACK_DEF( FT_Error ) tt_cmap12_init( TT_CMap12 cmap, FT_Byte* table ) { cmap->cmap.data = table; table += 12; cmap->num_groups = FT_PEEK_ULONG( table ); cmap->valid = 0; return FT_Err_Ok; } FT_CALLBACK_DEF( FT_Error ) tt_cmap12_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_ULong length; FT_ULong num_groups; if ( table + 16 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 4; length = TT_NEXT_ULONG( p ); p = table + 12; num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || /* length < 16 + 12 * num_groups ? */ length < 16 || ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ { FT_ULong n, start, end, start_id, last = 0; for ( n = 0; n < num_groups; n++ ) { start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); start_id = TT_NEXT_ULONG( p ); if ( start > end ) FT_INVALID_DATA; if ( n > 0 && start <= last ) FT_INVALID_DATA; if ( valid->level >= FT_VALIDATE_TIGHT ) { FT_UInt32 d = end - start; /* start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) ? */ if ( d > TT_VALID_GLYPH_COUNT( valid ) || start_id >= TT_VALID_GLYPH_COUNT( valid ) - d ) FT_INVALID_GLYPH_ID; } last = end; } } return FT_Err_Ok; } /* search the index of the charcode next to cmap->cur_charcode */ /* cmap->cur_group should be set up properly by caller */ /* */ static void tt_cmap12_next( TT_CMap12 cmap ) { FT_Face face = cmap->cmap.cmap.charmap.face; FT_Byte* p; FT_ULong start, end, start_id, char_code; FT_ULong n; FT_UInt gindex; if ( cmap->cur_charcode >= 0xFFFFFFFFUL ) goto Fail; char_code = cmap->cur_charcode + 1; for ( n = cmap->cur_group; n < cmap->num_groups; n++ ) { p = cmap->cmap.data + 16 + 12 * n; start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); start_id = TT_PEEK_ULONG( p ); if ( char_code < start ) char_code = start; Again: if ( char_code <= end ) { /* ignore invalid group */ if ( start_id > 0xFFFFFFFFUL - ( char_code - start ) ) continue; gindex = (FT_UInt)( start_id + ( char_code - start ) ); /* does first element of group point to `.notdef' glyph? */ if ( gindex == 0 ) { if ( char_code >= 0xFFFFFFFFUL ) goto Fail; char_code++; goto Again; } /* if `gindex' is invalid, the remaining values */ /* in this group are invalid, too */ if ( gindex >= (FT_UInt)face->num_glyphs ) continue; cmap->cur_charcode = char_code; cmap->cur_gindex = gindex; cmap->cur_group = n; return; } } Fail: cmap->valid = 0; } static FT_UInt tt_cmap12_char_map_binary( TT_CMap cmap, FT_UInt32* pchar_code, FT_Bool next ) { FT_UInt gindex = 0; FT_Byte* p = cmap->data + 12; FT_UInt32 num_groups = TT_PEEK_ULONG( p ); FT_UInt32 char_code = *pchar_code; FT_UInt32 start, end, start_id; FT_UInt32 max, min, mid; if ( !num_groups ) return 0; /* make compiler happy */ mid = num_groups; end = 0xFFFFFFFFUL; if ( next ) { if ( char_code >= 0xFFFFFFFFUL ) return 0; char_code++; } min = 0; max = num_groups; /* binary search */ while ( min < max ) { mid = ( min + max ) >> 1; p = cmap->data + 16 + 12 * mid; start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); if ( char_code < start ) max = mid; else if ( char_code > end ) min = mid + 1; else { start_id = TT_PEEK_ULONG( p ); /* reject invalid glyph index */ if ( start_id > 0xFFFFFFFFUL - ( char_code - start ) ) gindex = 0; else gindex = (FT_UInt)( start_id + ( char_code - start ) ); break; } } if ( next ) { FT_Face face = cmap->cmap.charmap.face; TT_CMap12 cmap12 = (TT_CMap12)cmap; /* if `char_code' is not in any group, then `mid' is */ /* the group nearest to `char_code' */ if ( char_code > end ) { mid++; if ( mid == num_groups ) return 0; } cmap12->valid = 1; cmap12->cur_charcode = char_code; cmap12->cur_group = mid; if ( gindex >= (FT_UInt)face->num_glyphs ) gindex = 0; if ( !gindex ) { tt_cmap12_next( cmap12 ); if ( cmap12->valid ) gindex = cmap12->cur_gindex; } else cmap12->cur_gindex = gindex; *pchar_code = cmap12->cur_charcode; } return gindex; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap12_char_index( TT_CMap cmap, FT_UInt32 char_code ) { return tt_cmap12_char_map_binary( cmap, &char_code, 0 ); } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap12_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { TT_CMap12 cmap12 = (TT_CMap12)cmap; FT_UInt gindex; /* no need to search */ if ( cmap12->valid && cmap12->cur_charcode == *pchar_code ) { tt_cmap12_next( cmap12 ); if ( cmap12->valid ) { gindex = cmap12->cur_gindex; *pchar_code = (FT_UInt32)cmap12->cur_charcode; } else gindex = 0; } else gindex = tt_cmap12_char_map_binary( cmap, pchar_code, 1 ); return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap12_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 8; cmap_info->format = 12; cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap12_class_rec, sizeof ( TT_CMap12Rec ), (FT_CMap_InitFunc) tt_cmap12_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap12_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap12_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 12, (TT_CMap_ValidateFunc)tt_cmap12_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap12_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_12 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 13 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 13 * reserved 2 USHORT reserved * length 4 ULONG length in bytes * language 8 ULONG Mac language code * count 12 ULONG number of groups * 16 * * This header is followed by `count' groups of the following format: * * start 0 ULONG first charcode * end 4 ULONG last charcode * glyphId 8 ULONG glyph ID for the whole group */ #ifdef TT_CONFIG_CMAP_FORMAT_13 typedef struct TT_CMap13Rec_ { TT_CMapRec cmap; FT_Bool valid; FT_ULong cur_charcode; FT_UInt cur_gindex; FT_ULong cur_group; FT_ULong num_groups; } TT_CMap13Rec, *TT_CMap13; FT_CALLBACK_DEF( FT_Error ) tt_cmap13_init( TT_CMap13 cmap, FT_Byte* table ) { cmap->cmap.data = table; table += 12; cmap->num_groups = FT_PEEK_ULONG( table ); cmap->valid = 0; return FT_Err_Ok; } FT_CALLBACK_DEF( FT_Error ) tt_cmap13_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_ULong length; FT_ULong num_groups; if ( table + 16 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 4; length = TT_NEXT_ULONG( p ); p = table + 12; num_groups = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || /* length < 16 + 12 * num_groups ? */ length < 16 || ( length - 16 ) / 12 < num_groups ) FT_INVALID_TOO_SHORT; /* check groups, they must be in increasing order */ { FT_ULong n, start, end, glyph_id, last = 0; for ( n = 0; n < num_groups; n++ ) { start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); glyph_id = TT_NEXT_ULONG( p ); if ( start > end ) FT_INVALID_DATA; if ( n > 0 && start <= last ) FT_INVALID_DATA; if ( valid->level >= FT_VALIDATE_TIGHT ) { if ( glyph_id >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } last = end; } } return FT_Err_Ok; } /* search the index of the charcode next to cmap->cur_charcode */ /* cmap->cur_group should be set up properly by caller */ /* */ static void tt_cmap13_next( TT_CMap13 cmap ) { FT_Face face = cmap->cmap.cmap.charmap.face; FT_Byte* p; FT_ULong start, end, glyph_id, char_code; FT_ULong n; FT_UInt gindex; if ( cmap->cur_charcode >= 0xFFFFFFFFUL ) goto Fail; char_code = cmap->cur_charcode + 1; for ( n = cmap->cur_group; n < cmap->num_groups; n++ ) { p = cmap->cmap.data + 16 + 12 * n; start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); glyph_id = TT_PEEK_ULONG( p ); if ( char_code < start ) char_code = start; if ( char_code <= end ) { gindex = (FT_UInt)glyph_id; if ( gindex && gindex < (FT_UInt)face->num_glyphs ) { cmap->cur_charcode = char_code; cmap->cur_gindex = gindex; cmap->cur_group = n; return; } } } Fail: cmap->valid = 0; } static FT_UInt tt_cmap13_char_map_binary( TT_CMap cmap, FT_UInt32* pchar_code, FT_Bool next ) { FT_UInt gindex = 0; FT_Byte* p = cmap->data + 12; FT_UInt32 num_groups = TT_PEEK_ULONG( p ); FT_UInt32 char_code = *pchar_code; FT_UInt32 start, end; FT_UInt32 max, min, mid; if ( !num_groups ) return 0; /* make compiler happy */ mid = num_groups; end = 0xFFFFFFFFUL; if ( next ) { if ( char_code >= 0xFFFFFFFFUL ) return 0; char_code++; } min = 0; max = num_groups; /* binary search */ while ( min < max ) { mid = ( min + max ) >> 1; p = cmap->data + 16 + 12 * mid; start = TT_NEXT_ULONG( p ); end = TT_NEXT_ULONG( p ); if ( char_code < start ) max = mid; else if ( char_code > end ) min = mid + 1; else { gindex = (FT_UInt)TT_PEEK_ULONG( p ); break; } } if ( next ) { FT_Face face = cmap->cmap.charmap.face; TT_CMap13 cmap13 = (TT_CMap13)cmap; /* if `char_code' is not in any group, then `mid' is */ /* the group nearest to `char_code' */ if ( char_code > end ) { mid++; if ( mid == num_groups ) return 0; } cmap13->valid = 1; cmap13->cur_charcode = char_code; cmap13->cur_group = mid; if ( gindex >= (FT_UInt)face->num_glyphs ) gindex = 0; if ( !gindex ) { tt_cmap13_next( cmap13 ); if ( cmap13->valid ) gindex = cmap13->cur_gindex; } else cmap13->cur_gindex = gindex; *pchar_code = cmap13->cur_charcode; } return gindex; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap13_char_index( TT_CMap cmap, FT_UInt32 char_code ) { return tt_cmap13_char_map_binary( cmap, &char_code, 0 ); } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap13_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { TT_CMap13 cmap13 = (TT_CMap13)cmap; FT_UInt gindex; /* no need to search */ if ( cmap13->valid && cmap13->cur_charcode == *pchar_code ) { tt_cmap13_next( cmap13 ); if ( cmap13->valid ) { gindex = cmap13->cur_gindex; *pchar_code = cmap13->cur_charcode; } else gindex = 0; } else gindex = tt_cmap13_char_map_binary( cmap, pchar_code, 1 ); return gindex; } FT_CALLBACK_DEF( FT_Error ) tt_cmap13_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_Byte* p = cmap->data + 8; cmap_info->format = 13; cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p ); return FT_Err_Ok; } FT_DEFINE_TT_CMAP( tt_cmap13_class_rec, sizeof ( TT_CMap13Rec ), (FT_CMap_InitFunc) tt_cmap13_init, /* init */ (FT_CMap_DoneFunc) NULL, /* done */ (FT_CMap_CharIndexFunc)tt_cmap13_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap13_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ 13, (TT_CMap_ValidateFunc)tt_cmap13_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap13_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_13 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FORMAT 14 *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * TABLE OVERVIEW * -------------- * * NAME OFFSET TYPE DESCRIPTION * * format 0 USHORT must be 14 * length 2 ULONG table length in bytes * numSelector 6 ULONG number of variation sel. records * * Followed by numSelector records, each of which looks like * * varSelector 0 UINT24 Unicode codepoint of sel. * defaultOff 3 ULONG offset to a default UVS table * describing any variants to be found in * the normal Unicode subtable. * nonDefOff 7 ULONG offset to a non-default UVS table * describing any variants not in the * standard cmap, with GIDs here * (either offset may be 0 NULL) * * Selectors are sorted by code point. * * A default Unicode Variation Selector (UVS) subtable is just a list of * ranges of code points which are to be found in the standard cmap. No * glyph IDs (GIDs) here. * * numRanges 0 ULONG number of ranges following * * A range looks like * * uniStart 0 UINT24 code point of the first character in * this range * additionalCnt 3 UBYTE count of additional characters in this * range (zero means a range of a single * character) * * Ranges are sorted by `uniStart'. * * A non-default Unicode Variation Selector (UVS) subtable is a list of * mappings from codepoint to GID. * * numMappings 0 ULONG number of mappings * * A range looks like * * uniStart 0 UINT24 code point of the first character in * this range * GID 3 USHORT and its GID * * Ranges are sorted by `uniStart'. */ #ifdef TT_CONFIG_CMAP_FORMAT_14 typedef struct TT_CMap14Rec_ { TT_CMapRec cmap; FT_ULong num_selectors; /* This array is used to store the results of various * cmap 14 query functions. The data is overwritten * on each call to these functions. */ FT_UInt32 max_results; FT_UInt32* results; FT_Memory memory; } TT_CMap14Rec, *TT_CMap14; FT_CALLBACK_DEF( void ) tt_cmap14_done( TT_CMap14 cmap ) { FT_Memory memory = cmap->memory; cmap->max_results = 0; if ( memory && cmap->results ) FT_FREE( cmap->results ); } static FT_Error tt_cmap14_ensure( TT_CMap14 cmap, FT_UInt32 num_results, FT_Memory memory ) { FT_UInt32 old_max = cmap->max_results; FT_Error error = FT_Err_Ok; if ( num_results > cmap->max_results ) { cmap->memory = memory; if ( FT_QRENEW_ARRAY( cmap->results, old_max, num_results ) ) return error; cmap->max_results = num_results; } return error; } FT_CALLBACK_DEF( FT_Error ) tt_cmap14_init( TT_CMap14 cmap, FT_Byte* table ) { cmap->cmap.data = table; table += 6; cmap->num_selectors = FT_PEEK_ULONG( table ); cmap->max_results = 0; cmap->results = NULL; return FT_Err_Ok; } FT_CALLBACK_DEF( FT_Error ) tt_cmap14_validate( FT_Byte* table, FT_Validator valid ) { FT_Byte* p; FT_ULong length; FT_ULong num_selectors; if ( table + 2 + 4 + 4 > valid->limit ) FT_INVALID_TOO_SHORT; p = table + 2; length = TT_NEXT_ULONG( p ); num_selectors = TT_NEXT_ULONG( p ); if ( length > (FT_ULong)( valid->limit - table ) || /* length < 10 + 11 * num_selectors ? */ length < 10 || ( length - 10 ) / 11 < num_selectors ) FT_INVALID_TOO_SHORT; /* check selectors, they must be in increasing order */ { /* we start lastVarSel at 1 because a variant selector value of 0 * isn't valid. */ FT_ULong n, lastVarSel = 1; for ( n = 0; n < num_selectors; n++ ) { FT_ULong varSel = TT_NEXT_UINT24( p ); FT_ULong defOff = TT_NEXT_ULONG( p ); FT_ULong nondefOff = TT_NEXT_ULONG( p ); if ( defOff >= length || nondefOff >= length ) FT_INVALID_TOO_SHORT; if ( varSel < lastVarSel ) FT_INVALID_DATA; lastVarSel = varSel + 1; /* check the default table (these glyphs should be reached */ /* through the normal Unicode cmap, no GIDs, just check order) */ if ( defOff != 0 ) { FT_Byte* defp = table + defOff; FT_ULong numRanges; FT_ULong i; FT_ULong lastBase = 0; if ( defp + 4 > valid->limit ) FT_INVALID_TOO_SHORT; numRanges = TT_NEXT_ULONG( defp ); /* defp + numRanges * 4 > valid->limit ? */ if ( numRanges > (FT_ULong)( valid->limit - defp ) / 4 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numRanges; i++ ) { FT_ULong base = TT_NEXT_UINT24( defp ); FT_ULong cnt = FT_NEXT_BYTE( defp ); if ( base + cnt >= 0x110000UL ) /* end of Unicode */ FT_INVALID_DATA; if ( base < lastBase ) FT_INVALID_DATA; lastBase = base + cnt + 1U; } } /* and the non-default table (these glyphs are specified here) */ if ( nondefOff != 0 ) { FT_Byte* ndp = table + nondefOff; FT_ULong numMappings; FT_ULong i, lastUni = 0; if ( ndp + 4 > valid->limit ) FT_INVALID_TOO_SHORT; numMappings = TT_NEXT_ULONG( ndp ); /* numMappings * 5 > (FT_ULong)( valid->limit - ndp ) ? */ if ( numMappings > ( (FT_ULong)( valid->limit - ndp ) ) / 5 ) FT_INVALID_TOO_SHORT; for ( i = 0; i < numMappings; i++ ) { FT_ULong uni = TT_NEXT_UINT24( ndp ); FT_ULong gid = TT_NEXT_USHORT( ndp ); if ( uni >= 0x110000UL ) /* end of Unicode */ FT_INVALID_DATA; if ( uni < lastUni ) FT_INVALID_DATA; lastUni = uni + 1U; if ( valid->level >= FT_VALIDATE_TIGHT && gid >= TT_VALID_GLYPH_COUNT( valid ) ) FT_INVALID_GLYPH_ID; } } } } return FT_Err_Ok; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap14_char_index( TT_CMap cmap, FT_UInt32 char_code ) { FT_UNUSED( cmap ); FT_UNUSED( char_code ); /* This can't happen */ return 0; } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap14_char_next( TT_CMap cmap, FT_UInt32 *pchar_code ) { FT_UNUSED( cmap ); /* This can't happen */ *pchar_code = 0; return 0; } FT_CALLBACK_DEF( FT_Error ) tt_cmap14_get_info( TT_CMap cmap, TT_CMapInfo *cmap_info ) { FT_UNUSED( cmap ); cmap_info->format = 14; /* subtable 14 does not define a language field */ cmap_info->language = 0xFFFFFFFFUL; return FT_Err_Ok; } static FT_UInt tt_cmap14_char_map_def_binary( FT_Byte *base, FT_UInt32 char_code ) { FT_UInt32 numRanges = TT_PEEK_ULONG( base ); FT_UInt32 max, min; min = 0; max = numRanges; base += 4; /* binary search */ while ( min < max ) { FT_UInt32 mid = ( min + max ) >> 1; FT_Byte* p = base + 4 * mid; FT_ULong start = TT_NEXT_UINT24( p ); FT_UInt cnt = FT_NEXT_BYTE( p ); if ( char_code < start ) max = mid; else if ( char_code > start + cnt ) min = mid + 1; else return TRUE; } return FALSE; } static FT_UInt tt_cmap14_char_map_nondef_binary( FT_Byte *base, FT_UInt32 char_code ) { FT_UInt32 numMappings = TT_PEEK_ULONG( base ); FT_UInt32 max, min; min = 0; max = numMappings; base += 4; /* binary search */ while ( min < max ) { FT_UInt32 mid = ( min + max ) >> 1; FT_Byte* p = base + 5 * mid; FT_UInt32 uni = (FT_UInt32)TT_NEXT_UINT24( p ); if ( char_code < uni ) max = mid; else if ( char_code > uni ) min = mid + 1; else return TT_PEEK_USHORT( p ); } return 0; } static FT_Byte* tt_cmap14_find_variant( FT_Byte *base, FT_UInt32 variantCode ) { FT_UInt32 numVar = TT_PEEK_ULONG( base ); FT_UInt32 max, min; min = 0; max = numVar; base += 4; /* binary search */ while ( min < max ) { FT_UInt32 mid = ( min + max ) >> 1; FT_Byte* p = base + 11 * mid; FT_ULong varSel = TT_NEXT_UINT24( p ); if ( variantCode < varSel ) max = mid; else if ( variantCode > varSel ) min = mid + 1; else return p; } return NULL; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap14_char_var_index( TT_CMap cmap, TT_CMap ucmap, FT_UInt32 charcode, FT_UInt32 variantSelector ) { FT_Byte* p = tt_cmap14_find_variant( cmap->data + 6, variantSelector ); FT_ULong defOff; FT_ULong nondefOff; if ( !p ) return 0; defOff = TT_NEXT_ULONG( p ); nondefOff = TT_PEEK_ULONG( p ); if ( defOff != 0 && tt_cmap14_char_map_def_binary( cmap->data + defOff, charcode ) ) { /* This is the default variant of this charcode. GID not stored */ /* here; stored in the normal Unicode charmap instead. */ return ucmap->cmap.clazz->char_index( &ucmap->cmap, charcode ); } if ( nondefOff != 0 ) return tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff, charcode ); return 0; } FT_CALLBACK_DEF( FT_Int ) tt_cmap14_char_var_isdefault( TT_CMap cmap, FT_UInt32 charcode, FT_UInt32 variantSelector ) { FT_Byte* p = tt_cmap14_find_variant( cmap->data + 6, variantSelector ); FT_ULong defOff; FT_ULong nondefOff; if ( !p ) return -1; defOff = TT_NEXT_ULONG( p ); nondefOff = TT_NEXT_ULONG( p ); if ( defOff != 0 && tt_cmap14_char_map_def_binary( cmap->data + defOff, charcode ) ) return 1; if ( nondefOff != 0 && tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff, charcode ) != 0 ) return 0; return -1; } FT_CALLBACK_DEF( FT_UInt32* ) tt_cmap14_variants( TT_CMap cmap, FT_Memory memory ) { TT_CMap14 cmap14 = (TT_CMap14)cmap; FT_UInt32 count = cmap14->num_selectors; FT_Byte* p = cmap->data + 10; FT_UInt32* result; FT_UInt32 i; if ( tt_cmap14_ensure( cmap14, ( count + 1 ), memory ) ) return NULL; result = cmap14->results; for ( i = 0; i < count; i++ ) { result[i] = (FT_UInt32)TT_NEXT_UINT24( p ); p += 8; } result[i] = 0; return result; } FT_CALLBACK_DEF( FT_UInt32 * ) tt_cmap14_char_variants( TT_CMap cmap, FT_Memory memory, FT_UInt32 charCode ) { TT_CMap14 cmap14 = (TT_CMap14) cmap; FT_UInt32 count = cmap14->num_selectors; FT_Byte* p = cmap->data + 10; FT_UInt32* q; if ( tt_cmap14_ensure( cmap14, ( count + 1 ), memory ) ) return NULL; for ( q = cmap14->results; count > 0; count-- ) { FT_UInt32 varSel = TT_NEXT_UINT24( p ); FT_ULong defOff = TT_NEXT_ULONG( p ); FT_ULong nondefOff = TT_NEXT_ULONG( p ); if ( ( defOff != 0 && tt_cmap14_char_map_def_binary( cmap->data + defOff, charCode ) ) || ( nondefOff != 0 && tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff, charCode ) != 0 ) ) { q[0] = varSel; q++; } } q[0] = 0; return cmap14->results; } static FT_UInt tt_cmap14_def_char_count( FT_Byte *p ) { FT_UInt32 numRanges = (FT_UInt32)TT_NEXT_ULONG( p ); FT_UInt tot = 0; p += 3; /* point to the first `cnt' field */ for ( ; numRanges > 0; numRanges-- ) { tot += 1 + p[0]; p += 4; } return tot; } static FT_UInt32* tt_cmap14_get_def_chars( TT_CMap cmap, FT_Byte* p, FT_Memory memory ) { TT_CMap14 cmap14 = (TT_CMap14) cmap; FT_UInt32 numRanges; FT_UInt cnt; FT_UInt32* q; cnt = tt_cmap14_def_char_count( p ); numRanges = (FT_UInt32)TT_NEXT_ULONG( p ); if ( tt_cmap14_ensure( cmap14, ( cnt + 1 ), memory ) ) return NULL; for ( q = cmap14->results; numRanges > 0; numRanges-- ) { FT_UInt32 uni = (FT_UInt32)TT_NEXT_UINT24( p ); cnt = FT_NEXT_BYTE( p ) + 1; do { q[0] = uni; uni += 1; q += 1; } while ( --cnt != 0 ); } q[0] = 0; return cmap14->results; } static FT_UInt32* tt_cmap14_get_nondef_chars( TT_CMap cmap, FT_Byte *p, FT_Memory memory ) { TT_CMap14 cmap14 = (TT_CMap14) cmap; FT_UInt32 numMappings; FT_UInt i; FT_UInt32 *ret; numMappings = (FT_UInt32)TT_NEXT_ULONG( p ); if ( tt_cmap14_ensure( cmap14, ( numMappings + 1 ), memory ) ) return NULL; ret = cmap14->results; for ( i = 0; i < numMappings; i++ ) { ret[i] = (FT_UInt32)TT_NEXT_UINT24( p ); p += 2; } ret[i] = 0; return ret; } FT_CALLBACK_DEF( FT_UInt32 * ) tt_cmap14_variant_chars( TT_CMap cmap, FT_Memory memory, FT_UInt32 variantSelector ) { FT_Byte *p = tt_cmap14_find_variant( cmap->data + 6, variantSelector ); FT_Int i; FT_ULong defOff; FT_ULong nondefOff; if ( !p ) return NULL; defOff = TT_NEXT_ULONG( p ); nondefOff = TT_NEXT_ULONG( p ); if ( defOff == 0 && nondefOff == 0 ) return NULL; if ( defOff == 0 ) return tt_cmap14_get_nondef_chars( cmap, cmap->data + nondefOff, memory ); else if ( nondefOff == 0 ) return tt_cmap14_get_def_chars( cmap, cmap->data + defOff, memory ); else { /* Both a default and a non-default glyph set? That's probably not */ /* good font design, but the spec allows for it... */ TT_CMap14 cmap14 = (TT_CMap14) cmap; FT_UInt32 numRanges; FT_UInt32 numMappings; FT_UInt32 duni; FT_UInt32 dcnt; FT_UInt32 nuni; FT_Byte* dp; FT_UInt di, ni, k; FT_UInt32 *ret; p = cmap->data + nondefOff; dp = cmap->data + defOff; numMappings = (FT_UInt32)TT_NEXT_ULONG( p ); dcnt = tt_cmap14_def_char_count( dp ); numRanges = (FT_UInt32)TT_NEXT_ULONG( dp ); if ( numMappings == 0 ) return tt_cmap14_get_def_chars( cmap, cmap->data + defOff, memory ); if ( dcnt == 0 ) return tt_cmap14_get_nondef_chars( cmap, cmap->data + nondefOff, memory ); if ( tt_cmap14_ensure( cmap14, ( dcnt + numMappings + 1 ), memory ) ) return NULL; ret = cmap14->results; duni = (FT_UInt32)TT_NEXT_UINT24( dp ); dcnt = FT_NEXT_BYTE( dp ); di = 1; nuni = (FT_UInt32)TT_NEXT_UINT24( p ); p += 2; ni = 1; i = 0; for (;;) { if ( nuni > duni + dcnt ) { for ( k = 0; k <= dcnt; k++ ) ret[i++] = duni + k; di++; if ( di > numRanges ) break; duni = (FT_UInt32)TT_NEXT_UINT24( dp ); dcnt = FT_NEXT_BYTE( dp ); } else { if ( nuni < duni ) ret[i++] = nuni; /* If it is within the default range then ignore it -- */ /* that should not have happened */ ni++; if ( ni > numMappings ) break; nuni = (FT_UInt32)TT_NEXT_UINT24( p ); p += 2; } } if ( ni <= numMappings ) { /* If we get here then we have run out of all default ranges. */ /* We have read one non-default mapping which we haven't stored */ /* and there may be others that need to be read. */ ret[i++] = nuni; while ( ni < numMappings ) { ret[i++] = (FT_UInt32)TT_NEXT_UINT24( p ); p += 2; ni++; } } else if ( di <= numRanges ) { /* If we get here then we have run out of all non-default */ /* mappings. We have read one default range which we haven't */ /* stored and there may be others that need to be read. */ for ( k = 0; k <= dcnt; k++ ) ret[i++] = duni + k; while ( di < numRanges ) { duni = (FT_UInt32)TT_NEXT_UINT24( dp ); dcnt = FT_NEXT_BYTE( dp ); for ( k = 0; k <= dcnt; k++ ) ret[i++] = duni + k; di++; } } ret[i] = 0; return ret; } } FT_DEFINE_TT_CMAP( tt_cmap14_class_rec, sizeof ( TT_CMap14Rec ), (FT_CMap_InitFunc) tt_cmap14_init, /* init */ (FT_CMap_DoneFunc) tt_cmap14_done, /* done */ (FT_CMap_CharIndexFunc)tt_cmap14_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap14_char_next, /* char_next */ /* Format 14 extension functions */ (FT_CMap_CharVarIndexFunc) tt_cmap14_char_var_index, (FT_CMap_CharVarIsDefaultFunc)tt_cmap14_char_var_isdefault, (FT_CMap_VariantListFunc) tt_cmap14_variants, (FT_CMap_CharVariantListFunc) tt_cmap14_char_variants, (FT_CMap_VariantCharListFunc) tt_cmap14_variant_chars, 14, (TT_CMap_ValidateFunc)tt_cmap14_validate, /* validate */ (TT_CMap_Info_GetFunc)tt_cmap14_get_info /* get_cmap_info */ ) #endif /* TT_CONFIG_CMAP_FORMAT_14 */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** SYNTHETIC UNICODE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* This charmap is generated using postscript glyph names. */ #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES FT_CALLBACK_DEF( const char * ) tt_get_glyph_name( TT_Face face, FT_UInt idx ) { FT_String* PSname = NULL; tt_face_get_ps_name( face, idx, &PSname ); return PSname; } FT_CALLBACK_DEF( FT_Error ) tt_cmap_unicode_init( PS_Unicodes unicodes, FT_Pointer pointer ) { TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes ); FT_Memory memory = FT_FACE_MEMORY( face ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; FT_UNUSED( pointer ); if ( !psnames->unicodes_init ) return FT_THROW( Unimplemented_Feature ); return psnames->unicodes_init( memory, unicodes, face->root.num_glyphs, (PS_GetGlyphNameFunc)&tt_get_glyph_name, (PS_FreeGlyphNameFunc)NULL, (FT_Pointer)face ); } FT_CALLBACK_DEF( void ) tt_cmap_unicode_done( PS_Unicodes unicodes ) { FT_Face face = FT_CMAP_FACE( unicodes ); FT_Memory memory = FT_FACE_MEMORY( face ); FT_FREE( unicodes->maps ); unicodes->num_maps = 0; } FT_CALLBACK_DEF( FT_UInt ) tt_cmap_unicode_char_index( PS_Unicodes unicodes, FT_UInt32 char_code ) { TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; return psnames->unicodes_char_index( unicodes, char_code ); } FT_CALLBACK_DEF( FT_UInt32 ) tt_cmap_unicode_char_next( PS_Unicodes unicodes, FT_UInt32 *pchar_code ) { TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes ); FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)face->psnames; return psnames->unicodes_char_next( unicodes, pchar_code ); } FT_DEFINE_TT_CMAP( tt_cmap_unicode_class_rec, sizeof ( PS_UnicodesRec ), (FT_CMap_InitFunc) tt_cmap_unicode_init, /* init */ (FT_CMap_DoneFunc) tt_cmap_unicode_done, /* done */ (FT_CMap_CharIndexFunc)tt_cmap_unicode_char_index, /* char_index */ (FT_CMap_CharNextFunc) tt_cmap_unicode_char_next, /* char_next */ (FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */ (FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */ (FT_CMap_VariantListFunc) NULL, /* variant_list */ (FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */ (FT_CMap_VariantCharListFunc) NULL, /* variantchar_list */ ~0U, (TT_CMap_ValidateFunc)NULL, /* validate */ (TT_CMap_Info_GetFunc)NULL /* get_cmap_info */ ) #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ static const TT_CMap_Class tt_cmap_classes[] = { #undef TTCMAPCITEM #define TTCMAPCITEM( a ) &a, #include "ttcmapc.h" NULL, }; /* parse the `cmap' table and build the corresponding TT_CMap objects */ /* in the current face */ /* */ FT_LOCAL_DEF( FT_Error ) tt_face_build_cmaps( TT_Face face ) { FT_Byte* const table = face->cmap_table; FT_Byte* limit; FT_UInt volatile num_cmaps; FT_Byte* volatile p = table; FT_Library library = FT_FACE_LIBRARY( face ); FT_UNUSED( library ); if ( !p || face->cmap_size < 4 ) return FT_THROW( Invalid_Table ); /* Version 1.8.3 of the OpenType specification contains the following */ /* (https://docs.microsoft.com/en-us/typography/opentype/spec/cmap): */ /* */ /* The 'cmap' table version number remains at 0x0000 for fonts that */ /* make use of the newer subtable formats. */ /* */ /* This essentially means that a version format test is useless. */ /* ignore format */ p += 2; num_cmaps = TT_NEXT_USHORT( p ); FT_TRACE4(( "tt_face_build_cmaps: %d cmaps\n", num_cmaps )); limit = table + face->cmap_size; for ( ; num_cmaps > 0 && p + 8 <= limit; num_cmaps-- ) { FT_CharMapRec charmap; FT_UInt32 offset; charmap.platform_id = TT_NEXT_USHORT( p ); charmap.encoding_id = TT_NEXT_USHORT( p ); charmap.face = FT_FACE( face ); charmap.encoding = FT_ENCODING_NONE; /* will be filled later */ offset = TT_NEXT_ULONG( p ); if ( offset && offset <= face->cmap_size - 2 ) { FT_Byte* volatile cmap = table + offset; volatile FT_UInt format = TT_PEEK_USHORT( cmap ); const TT_CMap_Class* volatile pclazz = tt_cmap_classes; TT_CMap_Class volatile clazz; for ( ; *pclazz; pclazz++ ) { clazz = *pclazz; if ( clazz->format == format ) { volatile TT_ValidatorRec valid; volatile FT_Error error = FT_Err_Ok; ft_validator_init( FT_VALIDATOR( &valid ), cmap, limit, FT_VALIDATE_DEFAULT ); valid.num_glyphs = (FT_UInt)face->max_profile.numGlyphs; if ( ft_setjmp( FT_VALIDATOR( &valid )->jump_buffer) == 0 ) { /* validate this cmap sub-table */ error = clazz->validate( cmap, FT_VALIDATOR( &valid ) ); } if ( !valid.validator.error ) { FT_CMap ttcmap; /* It might make sense to store the single variation */ /* selector cmap somewhere special. But it would have to be */ /* in the public FT_FaceRec, and we can't change that. */ if ( !FT_CMap_New( (FT_CMap_Class)clazz, cmap, &charmap, &ttcmap ) ) { /* it is simpler to directly set `flags' than adding */ /* a parameter to FT_CMap_New */ ((TT_CMap)ttcmap)->flags = (FT_Int)error; } } else { FT_TRACE0(( "tt_face_build_cmaps:" " broken cmap sub-table ignored\n" )); } break; } } if ( !*pclazz ) { FT_TRACE0(( "tt_face_build_cmaps:" " unsupported cmap sub-table ignored\n" )); } } } return FT_Err_Ok; } FT_LOCAL( FT_Error ) tt_get_cmap_info( FT_CharMap charmap, TT_CMapInfo *cmap_info ) { FT_CMap cmap = (FT_CMap)charmap; TT_CMap_Class clazz = (TT_CMap_Class)cmap->clazz; if ( clazz->get_cmap_info ) return clazz->get_cmap_info( charmap, cmap_info ); else return FT_THROW( Invalid_CharMap_Format ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcmap.c
C++
gpl-3.0
109,699
/**************************************************************************** * * ttcmap.h * * TrueType character mapping table (cmap) support (specification). * * Copyright (C) 2002-2022 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 TTCMAP_H_ #define TTCMAP_H_ #include <freetype/internal/tttypes.h> #include <freetype/internal/ftvalid.h> #include <freetype/internal/services/svttcmap.h> FT_BEGIN_HEADER #define TT_CMAP_FLAG_UNSORTED 1 #define TT_CMAP_FLAG_OVERLAPPING 2 typedef struct TT_CMapRec_ { FT_CMapRec cmap; FT_Byte* data; /* pointer to in-memory cmap table */ FT_Int flags; /* for format 4 only */ } TT_CMapRec, *TT_CMap; typedef const struct TT_CMap_ClassRec_* TT_CMap_Class; typedef FT_Error (*TT_CMap_ValidateFunc)( FT_Byte* data, FT_Validator valid ); typedef struct TT_CMap_ClassRec_ { FT_CMap_ClassRec clazz; FT_UInt format; TT_CMap_ValidateFunc validate; TT_CMap_Info_GetFunc get_cmap_info; } TT_CMap_ClassRec; #define FT_DEFINE_TT_CMAP( class_, \ size_, \ init_, \ done_, \ char_index_, \ char_next_, \ char_var_index_, \ char_var_default_, \ variant_list_, \ charvariant_list_, \ variantchar_list_, \ format_, \ validate_, \ get_cmap_info_ ) \ FT_CALLBACK_TABLE_DEF \ const TT_CMap_ClassRec class_ = \ { \ { size_, \ init_, \ done_, \ char_index_, \ char_next_, \ char_var_index_, \ char_var_default_, \ variant_list_, \ charvariant_list_, \ variantchar_list_ \ }, \ \ format_, \ validate_, \ get_cmap_info_ \ }; #undef TTCMAPCITEM #define TTCMAPCITEM( a ) FT_CALLBACK_TABLE const TT_CMap_ClassRec a; #include "ttcmapc.h" typedef struct TT_ValidatorRec_ { FT_ValidatorRec validator; FT_UInt num_glyphs; } TT_ValidatorRec, *TT_Validator; #define TT_VALIDATOR( x ) ( (TT_Validator)( x ) ) #define TT_VALID_GLYPH_COUNT( x ) TT_VALIDATOR( x )->num_glyphs FT_CALLBACK_TABLE const TT_CMap_ClassRec tt_cmap_unicode_class_rec; FT_LOCAL( FT_Error ) tt_face_build_cmaps( TT_Face face ); /* used in tt-cmaps service */ FT_LOCAL( FT_Error ) tt_get_cmap_info( FT_CharMap charmap, TT_CMapInfo *cmap_info ); FT_END_HEADER #endif /* TTCMAP_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcmap.h
C++
gpl-3.0
3,727
/**************************************************************************** * * ttcmapc.h * * TT CMAP classes definitions (specification only). * * Copyright (C) 2009-2022 by * Oran Agra and Mickey Gabel. * * 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. * */ #ifdef TT_CONFIG_CMAP_FORMAT_0 TTCMAPCITEM( tt_cmap0_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_2 TTCMAPCITEM( tt_cmap2_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_4 TTCMAPCITEM( tt_cmap4_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_6 TTCMAPCITEM( tt_cmap6_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_8 TTCMAPCITEM( tt_cmap8_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_10 TTCMAPCITEM( tt_cmap10_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_12 TTCMAPCITEM( tt_cmap12_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_13 TTCMAPCITEM( tt_cmap13_class_rec ) #endif #ifdef TT_CONFIG_CMAP_FORMAT_14 TTCMAPCITEM( tt_cmap14_class_rec ) #endif /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcmapc.h
C++
gpl-3.0
1,227
/**************************************************************************** * * ttcolr.c * * TrueType and OpenType colored glyph layer support (body). * * Copyright (C) 2018-2022 by * David Turner, Robert Wilhelm, Dominik Röttsches, and Werner Lemberg. * * Originally written by Shao Yu Zhang <shaozhang@fb.com>. * * 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. * */ /************************************************************************** * * `COLR' table specification: * * https://www.microsoft.com/typography/otspec/colr.htm * */ #include <freetype/internal/ftcalc.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include <freetype/ftcolor.h> #include <freetype/config/integer-types.h> #ifdef TT_CONFIG_OPTION_COLOR_LAYERS #include "ttcolr.h" /* NOTE: These are the table sizes calculated through the specs. */ #define BASE_GLYPH_SIZE 6U #define BASE_GLYPH_PAINT_RECORD_SIZE 6U #define LAYER_V1_LIST_PAINT_OFFSET_SIZE 4U #define LAYER_V1_LIST_NUM_LAYERS_SIZE 4U #define COLOR_STOP_SIZE 6U #define LAYER_SIZE 4U #define COLR_HEADER_SIZE 14U typedef enum FT_PaintFormat_Internal_ { FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER = 18, FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM = 20, FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER = 22, FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER = 26, FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER = 30 } FT_PaintFormat_Internal; typedef struct BaseGlyphRecord_ { FT_UShort gid; FT_UShort first_layer_index; FT_UShort num_layers; } BaseGlyphRecord; typedef struct BaseGlyphV1Record_ { FT_UShort gid; /* Offset from start of BaseGlyphV1List, i.e., from base_glyphs_v1. */ FT_ULong paint_offset; } BaseGlyphV1Record; typedef struct Colr_ { FT_UShort version; FT_UShort num_base_glyphs; FT_UShort num_layers; FT_Byte* base_glyphs; FT_Byte* layers; FT_ULong num_base_glyphs_v1; /* Points at beginning of BaseGlyphV1List. */ FT_Byte* base_glyphs_v1; FT_ULong num_layers_v1; FT_Byte* layers_v1; FT_Byte* clip_list; /* * Paint tables start at the minimum of the end of the LayerList and the * end of the BaseGlyphList. Record this location in a field here for * safety checks when accessing paint tables. */ FT_Byte* paints_start_v1; /* The memory that backs up the `COLR' table. */ void* table; FT_ULong table_size; } Colr; /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttcolr FT_LOCAL_DEF( FT_Error ) tt_face_load_colr( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = face->root.memory; FT_Byte* table = NULL; FT_Byte* p = NULL; /* Needed for reading array lengths in referenced tables. */ FT_Byte* p1 = NULL; Colr* colr = NULL; FT_ULong base_glyph_offset, layer_offset; FT_ULong base_glyphs_offset_v1, num_base_glyphs_v1; FT_ULong layer_offset_v1, num_layers_v1, clip_list_offset; FT_ULong table_size; /* `COLR' always needs `CPAL' */ if ( !face->cpal ) return FT_THROW( Invalid_File_Format ); error = face->goto_table( face, TTAG_COLR, stream, &table_size ); if ( error ) goto NoColr; if ( table_size < COLR_HEADER_SIZE ) goto InvalidTable; if ( FT_FRAME_EXTRACT( table_size, table ) ) goto NoColr; p = table; if ( FT_NEW( colr ) ) goto NoColr; colr->version = FT_NEXT_USHORT( p ); if ( colr->version != 0 && colr->version != 1 ) goto InvalidTable; colr->num_base_glyphs = FT_NEXT_USHORT( p ); base_glyph_offset = FT_NEXT_ULONG( p ); if ( base_glyph_offset >= table_size ) goto InvalidTable; if ( colr->num_base_glyphs * BASE_GLYPH_SIZE > table_size - base_glyph_offset ) goto InvalidTable; layer_offset = FT_NEXT_ULONG( p ); colr->num_layers = FT_NEXT_USHORT( p ); if ( layer_offset >= table_size ) goto InvalidTable; if ( colr->num_layers * LAYER_SIZE > table_size - layer_offset ) goto InvalidTable; if ( colr->version == 1 ) { base_glyphs_offset_v1 = FT_NEXT_ULONG( p ); if ( base_glyphs_offset_v1 >= table_size ) goto InvalidTable; p1 = (FT_Byte*)( table + base_glyphs_offset_v1 ); num_base_glyphs_v1 = FT_PEEK_ULONG( p1 ); if ( num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE > table_size - base_glyphs_offset_v1 ) goto InvalidTable; colr->num_base_glyphs_v1 = num_base_glyphs_v1; colr->base_glyphs_v1 = p1; layer_offset_v1 = FT_NEXT_ULONG( p ); if ( layer_offset_v1 >= table_size ) goto InvalidTable; if ( layer_offset_v1 ) { p1 = (FT_Byte*)( table + layer_offset_v1 ); num_layers_v1 = FT_PEEK_ULONG( p1 ); if ( num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE > table_size - layer_offset_v1 ) goto InvalidTable; colr->num_layers_v1 = num_layers_v1; colr->layers_v1 = p1; colr->paints_start_v1 = FT_MIN( colr->base_glyphs_v1 + colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE, colr->layers_v1 + colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ); } else { colr->num_layers_v1 = 0; colr->layers_v1 = 0; colr->paints_start_v1 = colr->base_glyphs_v1 + colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE; } clip_list_offset = FT_NEXT_ULONG( p ); if ( clip_list_offset >= table_size ) goto InvalidTable; if ( clip_list_offset ) colr->clip_list = (FT_Byte*)( table + clip_list_offset ); else colr->clip_list = 0; } colr->base_glyphs = (FT_Byte*)( table + base_glyph_offset ); colr->layers = (FT_Byte*)( table + layer_offset ); colr->table = table; colr->table_size = table_size; face->colr = colr; return FT_Err_Ok; InvalidTable: error = FT_THROW( Invalid_Table ); NoColr: FT_FRAME_RELEASE( table ); FT_FREE( colr ); return error; } FT_LOCAL_DEF( void ) tt_face_free_colr( TT_Face face ) { FT_Stream stream = face->root.stream; FT_Memory memory = face->root.memory; Colr* colr = (Colr*)face->colr; if ( colr ) { FT_FRAME_RELEASE( colr->table ); FT_FREE( colr ); } } static FT_Bool find_base_glyph_record( FT_Byte* base_glyph_begin, FT_UInt num_base_glyph, FT_UInt glyph_id, BaseGlyphRecord* record ) { FT_UInt min = 0; FT_UInt max = num_base_glyph; while ( min < max ) { FT_UInt mid = min + ( max - min ) / 2; FT_Byte* p = base_glyph_begin + mid * BASE_GLYPH_SIZE; FT_UShort gid = FT_NEXT_USHORT( p ); if ( gid < glyph_id ) min = mid + 1; else if (gid > glyph_id ) max = mid; else { record->gid = gid; record->first_layer_index = FT_NEXT_USHORT( p ); record->num_layers = FT_NEXT_USHORT( p ); return 1; } } return 0; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_colr_layer( TT_Face face, FT_UInt base_glyph, FT_UInt *aglyph_index, FT_UInt *acolor_index, FT_LayerIterator* iterator ) { Colr* colr = (Colr*)face->colr; BaseGlyphRecord glyph_record; if ( !colr ) return 0; if ( !iterator->p ) { FT_ULong offset; /* first call to function */ iterator->layer = 0; if ( !find_base_glyph_record( colr->base_glyphs, colr->num_base_glyphs, base_glyph, &glyph_record ) ) return 0; if ( glyph_record.num_layers ) iterator->num_layers = glyph_record.num_layers; else return 0; offset = LAYER_SIZE * glyph_record.first_layer_index; if ( offset + LAYER_SIZE * glyph_record.num_layers > colr->table_size ) return 0; iterator->p = colr->layers + offset; } if ( iterator->layer >= iterator->num_layers ) return 0; *aglyph_index = FT_NEXT_USHORT( iterator->p ); *acolor_index = FT_NEXT_USHORT( iterator->p ); if ( *aglyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) || ( *acolor_index != 0xFFFF && *acolor_index >= face->palette_data.num_palette_entries ) ) return 0; iterator->layer++; return 1; } static FT_Bool read_color_line( FT_Byte* color_line_p, FT_ColorLine *colorline ) { FT_Byte* p = color_line_p; FT_PaintExtend paint_extend; paint_extend = (FT_PaintExtend)FT_NEXT_BYTE( p ); if ( paint_extend > FT_COLR_PAINT_EXTEND_REFLECT ) return 0; colorline->extend = paint_extend; colorline->color_stop_iterator.num_color_stops = FT_NEXT_USHORT( p ); colorline->color_stop_iterator.p = p; colorline->color_stop_iterator.current_color_stop = 0; return 1; } /* * Read a paint offset for `FT_Paint*` objects that have them and check * whether it is within reasonable limits within the font and the COLR * table. * * Return 1 on success, 0 on failure. */ static FT_Bool get_child_table_pointer ( Colr* colr, FT_Byte* paint_base, FT_Byte** p, FT_Byte** child_table_pointer ) { FT_UInt32 paint_offset; FT_Byte* child_table_p; if ( !child_table_pointer ) return 0; paint_offset = FT_NEXT_UOFF3( *p ); if ( !paint_offset ) return 0; child_table_p = (FT_Byte*)( paint_base + paint_offset ); if ( child_table_p < colr->paints_start_v1 || child_table_p >= ( (FT_Byte*)colr->table + colr->table_size ) ) return 0; *child_table_pointer = child_table_p; return 1; } static FT_Bool read_paint( Colr* colr, FT_Byte* p, FT_COLR_Paint* apaint ) { FT_Byte* paint_base = p; FT_Byte* child_table_p = NULL; if ( !p || !colr || !colr->table ) return 0; if ( p < colr->paints_start_v1 || p >= ( (FT_Byte*)colr->table + colr->table_size ) ) return 0; apaint->format = (FT_PaintFormat)FT_NEXT_BYTE( p ); if ( apaint->format >= FT_COLR_PAINT_FORMAT_MAX ) return 0; if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_LAYERS ) { /* Initialize layer iterator/ */ FT_Byte num_layers; FT_UInt32 first_layer_index; num_layers = FT_NEXT_BYTE( p ); if ( num_layers > colr->num_layers_v1 ) return 0; first_layer_index = FT_NEXT_ULONG( p ); if ( first_layer_index + num_layers > colr->num_layers_v1 ) return 0; apaint->u.colr_layers.layer_iterator.num_layers = num_layers; apaint->u.colr_layers.layer_iterator.layer = 0; /* TODO: Check whether pointer is outside colr? */ apaint->u.colr_layers.layer_iterator.p = colr->layers_v1 + LAYER_V1_LIST_NUM_LAYERS_SIZE + LAYER_V1_LIST_PAINT_OFFSET_SIZE * first_layer_index; return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID ) { apaint->u.solid.color.palette_index = FT_NEXT_USHORT( p ); apaint->u.solid.color.alpha = FT_NEXT_SHORT( p ); return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_GLYPH ) { apaint->u.colr_glyph.glyphID = FT_NEXT_USHORT( p ); return 1; } /* * Grouped below here are all paint formats that have an offset to a * child paint table as the first entry (for example, a color line or a * child paint table). Retrieve that and determine whether that paint * offset is valid first. */ if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) ) return 0; if ( apaint->format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT ) { if ( !read_color_line( child_table_p, &apaint->u.linear_gradient.colorline ) ) return 0; /* * In order to support variations expose these as FT_Fixed 16.16 values so * that we can support fractional values after interpolation. */ apaint->u.linear_gradient.p0.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.linear_gradient.p0.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.linear_gradient.p1.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.linear_gradient.p1.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.linear_gradient.p2.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.linear_gradient.p2.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT ) { FT_Pos tmp; if ( !read_color_line( child_table_p, &apaint->u.radial_gradient.colorline ) ) return 0; /* In the OpenType specification, `r0` and `r1` are defined as */ /* `UFWORD`. Since FreeType doesn't have a corresponding 16.16 */ /* format we convert to `FWORD` and replace negative values with */ /* (32bit) `FT_INT_MAX`. */ apaint->u.radial_gradient.c0.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.radial_gradient.c0.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); tmp = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.radial_gradient.r0 = tmp < 0 ? FT_INT_MAX : tmp; apaint->u.radial_gradient.c1.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.radial_gradient.c1.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); tmp = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.radial_gradient.r1 = tmp < 0 ? FT_INT_MAX : tmp; return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT ) { if ( !read_color_line( child_table_p, &apaint->u.sweep_gradient.colorline ) ) return 0; apaint->u.sweep_gradient.center.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.sweep_gradient.center.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.sweep_gradient.start_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.sweep_gradient.end_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); return 1; } if ( apaint->format == FT_COLR_PAINTFORMAT_GLYPH ) { apaint->u.glyph.paint.p = child_table_p; apaint->u.glyph.paint.insert_root_transform = 0; apaint->u.glyph.glyphID = FT_NEXT_USHORT( p ); return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSFORM ) { apaint->u.transform.paint.p = child_table_p; apaint->u.transform.paint.insert_root_transform = 0; if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) ) return 0; p = child_table_p; /* * The following matrix coefficients are encoded as * OpenType 16.16 fixed-point values. */ apaint->u.transform.affine.xx = FT_NEXT_LONG( p ); apaint->u.transform.affine.yx = FT_NEXT_LONG( p ); apaint->u.transform.affine.xy = FT_NEXT_LONG( p ); apaint->u.transform.affine.yy = FT_NEXT_LONG( p ); apaint->u.transform.affine.dx = FT_NEXT_LONG( p ); apaint->u.transform.affine.dy = FT_NEXT_LONG( p ); return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSLATE ) { apaint->u.translate.paint.p = child_table_p; apaint->u.translate.paint.insert_root_transform = 0; apaint->u.translate.dx = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.translate.dy = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_SCALE || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER ) { apaint->u.scale.paint.p = child_table_p; apaint->u.scale.paint.insert_root_transform = 0; /* All scale paints get at least one scale value. */ apaint->u.scale.scale_x = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); /* Non-uniform ones read an extra y value. */ if ( apaint->format == FT_COLR_PAINTFORMAT_SCALE || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER ) apaint->u.scale.scale_y = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); else apaint->u.scale.scale_y = apaint->u.scale.scale_x; /* Scale paints that have a center read center coordinates, */ /* otherwise the center is (0,0). */ if ( (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER ) { apaint->u.scale.center_x = INT_TO_FIXED( FT_NEXT_SHORT ( p ) ); apaint->u.scale.center_y = INT_TO_FIXED( FT_NEXT_SHORT ( p ) ); } else { apaint->u.scale.center_x = 0; apaint->u.scale.center_y = 0; } /* FT 'COLR' v1 API output format always returns fully defined */ /* structs; we thus set the format to the public API value. */ apaint->format = FT_COLR_PAINTFORMAT_SCALE; return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_ROTATE || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER ) { apaint->u.rotate.paint.p = child_table_p; apaint->u.rotate.paint.insert_root_transform = 0; apaint->u.rotate.angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); if ( (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER ) { apaint->u.rotate.center_x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.rotate.center_y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); } else { apaint->u.rotate.center_x = 0; apaint->u.rotate.center_y = 0; } apaint->format = FT_COLR_PAINTFORMAT_ROTATE; return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_SKEW || (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER ) { apaint->u.skew.paint.p = child_table_p; apaint->u.skew.paint.insert_root_transform = 0; apaint->u.skew.x_skew_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.skew.y_skew_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) ); if ( (FT_PaintFormat_Internal)apaint->format == FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER ) { apaint->u.skew.center_x = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); apaint->u.skew.center_y = INT_TO_FIXED( FT_NEXT_SHORT( p ) ); } else { apaint->u.skew.center_x = 0; apaint->u.skew.center_y = 0; } apaint->format = FT_COLR_PAINTFORMAT_SKEW; return 1; } else if ( apaint->format == FT_COLR_PAINTFORMAT_COMPOSITE ) { FT_UInt composite_mode; apaint->u.composite.source_paint.p = child_table_p; apaint->u.composite.source_paint.insert_root_transform = 0; composite_mode = FT_NEXT_BYTE( p ); if ( composite_mode >= FT_COLR_COMPOSITE_MAX ) return 0; apaint->u.composite.composite_mode = (FT_Composite_Mode)composite_mode; if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) ) return 0; apaint->u.composite.backdrop_paint.p = child_table_p; apaint->u.composite.backdrop_paint.insert_root_transform = 0; return 1; } return 0; } static FT_Bool find_base_glyph_v1_record( FT_Byte * base_glyph_begin, FT_UInt num_base_glyph, FT_UInt glyph_id, BaseGlyphV1Record *record ) { FT_UInt min = 0; FT_UInt max = num_base_glyph; while ( min < max ) { FT_UInt mid = min + ( max - min ) / 2; /* * `base_glyph_begin` is the beginning of `BaseGlyphV1List`; * skip `numBaseGlyphV1Records` by adding 4 to start binary search * in the array of `BaseGlyphV1Record`. */ FT_Byte *p = base_glyph_begin + 4 + mid * BASE_GLYPH_PAINT_RECORD_SIZE; FT_UShort gid = FT_NEXT_USHORT( p ); if ( gid < glyph_id ) min = mid + 1; else if (gid > glyph_id ) max = mid; else { record->gid = gid; record->paint_offset = FT_NEXT_ULONG ( p ); return 1; } } return 0; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_colr_glyph_paint( TT_Face face, FT_UInt base_glyph, FT_Color_Root_Transform root_transform, FT_OpaquePaint* opaque_paint ) { Colr* colr = (Colr*)face->colr; BaseGlyphV1Record base_glyph_v1_record; FT_Byte* p; if ( !colr || !colr->table ) return 0; if ( colr->version < 1 || !colr->num_base_glyphs_v1 || !colr->base_glyphs_v1 ) return 0; if ( opaque_paint->p ) return 0; if ( !find_base_glyph_v1_record( colr->base_glyphs_v1, colr->num_base_glyphs_v1, base_glyph, &base_glyph_v1_record ) ) return 0; if ( !base_glyph_v1_record.paint_offset || base_glyph_v1_record.paint_offset > colr->table_size ) return 0; p = (FT_Byte*)( colr->base_glyphs_v1 + base_glyph_v1_record.paint_offset ); if ( p >= ( (FT_Byte*)colr->table + colr->table_size ) ) return 0; opaque_paint->p = p; if ( root_transform == FT_COLOR_INCLUDE_ROOT_TRANSFORM ) opaque_paint->insert_root_transform = 1; else opaque_paint->insert_root_transform = 0; return 1; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_color_glyph_clipbox( TT_Face face, FT_UInt base_glyph, FT_ClipBox* clip_box ) { Colr* colr; FT_Byte *p, *p1, *clip_base, *limit; FT_Byte clip_list_format; FT_ULong num_clip_boxes, i; FT_UShort gid_start, gid_end; FT_UInt32 clip_box_offset; FT_Byte format; const FT_Byte num_corners = 4; FT_Vector corners[4]; FT_Byte j; FT_BBox font_clip_box; colr = (Colr*)face->colr; if ( !colr ) return 0; if ( !colr->clip_list ) return 0; p = colr->clip_list; /* Limit points to the first byte after the end of the color table. */ /* Thus, in subsequent limit checks below we need to check whether the */ /* read pointer is strictly greater than a position offset by certain */ /* field sizes to the left of that position. */ limit = (FT_Byte*)colr->table + colr->table_size; /* Check whether we can extract one `uint8` and one `uint32`. */ if ( p > limit - ( 1 + 4 ) ) return 0; clip_base = p; clip_list_format = FT_NEXT_BYTE ( p ); /* Format byte used here to be able to upgrade ClipList for >16bit */ /* glyph ids; for now we can expect it to be 0. */ if ( !( clip_list_format == 1 ) ) return 0; num_clip_boxes = FT_NEXT_ULONG( p ); /* Check whether we can extract two `uint16` and one `Offset24`, */ /* `num_clip_boxes` times. */ if ( colr->table_size / ( 2 + 2 + 3 ) < num_clip_boxes || p > limit - ( 2 + 2 + 3 ) * num_clip_boxes ) return 0; for ( i = 0; i < num_clip_boxes; ++i ) { gid_start = FT_NEXT_USHORT( p ); gid_end = FT_NEXT_USHORT( p ); clip_box_offset = FT_NEXT_UOFF3( p ); if ( base_glyph >= gid_start && base_glyph <= gid_end ) { p1 = (FT_Byte*)( clip_base + clip_box_offset ); /* Check whether we can extract one `uint8`. */ if ( p1 > limit - 1 ) return 0; format = FT_NEXT_BYTE( p1 ); if ( format > 1 ) return 0; /* Check whether we can extract four `FWORD`. */ if ( p1 > limit - ( 2 + 2 + 2 + 2 ) ) return 0; /* `face->root.size->metrics.x_scale` and `y_scale` are factors */ /* that scale a font unit value in integers to a 26.6 fixed value */ /* according to the requested size, see for example */ /* `ft_recompute_scaled_metrics`. */ font_clip_box.xMin = FT_MulFix( FT_NEXT_SHORT( p1 ), face->root.size->metrics.x_scale ); font_clip_box.yMin = FT_MulFix( FT_NEXT_SHORT( p1 ), face->root.size->metrics.x_scale ); font_clip_box.xMax = FT_MulFix( FT_NEXT_SHORT( p1 ), face->root.size->metrics.x_scale ); font_clip_box.yMax = FT_MulFix( FT_NEXT_SHORT( p1 ), face->root.size->metrics.x_scale ); /* Make 4 corner points (xMin, yMin), (xMax, yMax) and transform */ /* them. If we we would only transform two corner points and */ /* span a rectangle based on those, the rectangle may become too */ /* small to cover the glyph. */ corners[0].x = font_clip_box.xMin; corners[1].x = font_clip_box.xMin; corners[2].x = font_clip_box.xMax; corners[3].x = font_clip_box.xMax; corners[0].y = font_clip_box.yMin; corners[1].y = font_clip_box.yMax; corners[2].y = font_clip_box.yMax; corners[3].y = font_clip_box.yMin; for ( j = 0; j < num_corners; ++j ) { if ( face->root.internal->transform_flags & 1 ) FT_Vector_Transform( &corners[j], &face->root.internal->transform_matrix ); if ( face->root.internal->transform_flags & 2 ) { corners[j].x += face->root.internal->transform_delta.x; corners[j].y += face->root.internal->transform_delta.y; } } clip_box->bottom_left = corners[0]; clip_box->top_left = corners[1]; clip_box->top_right = corners[2]; clip_box->bottom_right = corners[3]; return 1; } } return 0; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_paint_layers( TT_Face face, FT_LayerIterator* iterator, FT_OpaquePaint* opaque_paint ) { FT_Byte* p = NULL; FT_Byte* p_first_layer = NULL; FT_Byte* p_paint = NULL; FT_UInt32 paint_offset; Colr* colr; if ( iterator->layer == iterator->num_layers ) return 0; colr = (Colr*)face->colr; if ( !colr ) return 0; /* * We have an iterator pointing at a paint offset as part of the * `paintOffset` array in `LayerV1List`. */ p = iterator->p; /* * First ensure that p is within COLRv1. */ if ( p < colr->layers_v1 || p >= ( (FT_Byte*)colr->table + colr->table_size ) ) return 0; /* * Do a cursor sanity check of the iterator. Counting backwards from * where it stands, we need to end up at a position after the beginning * of the `LayerV1List` table and not after the end of the * `LayerV1List`. */ p_first_layer = p - iterator->layer * LAYER_V1_LIST_PAINT_OFFSET_SIZE - LAYER_V1_LIST_NUM_LAYERS_SIZE; if ( p_first_layer < (FT_Byte*)colr->layers_v1 ) return 0; if ( p_first_layer >= (FT_Byte*)( colr->layers_v1 + LAYER_V1_LIST_NUM_LAYERS_SIZE + colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ) ) return 0; paint_offset = FT_NEXT_ULONG( p ); opaque_paint->insert_root_transform = 0; p_paint = (FT_Byte*)( colr->layers_v1 + paint_offset ); if ( p_paint < colr->paints_start_v1 || p_paint >= ( (FT_Byte*)colr->table + colr->table_size ) ) return 0; opaque_paint->p = p_paint; iterator->p = p; iterator->layer++; return 1; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_colorline_stops( TT_Face face, FT_ColorStop* color_stop, FT_ColorStopIterator *iterator ) { Colr* colr = (Colr*)face->colr; FT_Byte* p; if ( !colr || !colr->table ) return 0; if ( iterator->current_color_stop >= iterator->num_color_stops ) return 0; if ( iterator->p + ( ( iterator->num_color_stops - iterator->current_color_stop ) * COLOR_STOP_SIZE ) > ( (FT_Byte *)colr->table + colr->table_size ) ) return 0; /* Iterator points at first `ColorStop` of `ColorLine`. */ p = iterator->p; color_stop->stop_offset = FT_NEXT_SHORT( p ); color_stop->color.palette_index = FT_NEXT_USHORT( p ); color_stop->color.alpha = FT_NEXT_SHORT( p ); iterator->p = p; iterator->current_color_stop++; return 1; } FT_LOCAL_DEF( FT_Bool ) tt_face_get_paint( TT_Face face, FT_OpaquePaint opaque_paint, FT_COLR_Paint* paint ) { Colr* colr = (Colr*)face->colr; FT_OpaquePaint next_paint; FT_Matrix ft_root_scale; if ( !colr || !colr->base_glyphs_v1 || !colr->table ) return 0; if ( opaque_paint.insert_root_transform ) { /* 'COLR' v1 glyph information is returned in unscaled coordinates, * i.e., `FT_Size` is not applied or multiplied into the values. When * client applications draw color glyphs, they can request to include * a top-level transform, which includes the active `x_scale` and * `y_scale` information for scaling the glyph, as well the additional * transform and translate configured through `FT_Set_Transform`. * This allows client applications to apply this top-level transform * to the graphics context first and only once, then have gradient and * contour scaling applied correctly when performing the additional * drawing operations for subsequenct paints. Prepare this initial * transform here. */ paint->format = FT_COLR_PAINTFORMAT_TRANSFORM; next_paint.p = opaque_paint.p; next_paint.insert_root_transform = 0; paint->u.transform.paint = next_paint; /* `x_scale` and `y_scale` are in 26.6 format, representing the scale * factor to get from font units to requested size. However, expected * return values are in 16.16, so we shift accordingly with rounding. */ ft_root_scale.xx = ( face->root.size->metrics.x_scale + 32 ) >> 6; ft_root_scale.xy = 0; ft_root_scale.yx = 0; ft_root_scale.yy = ( face->root.size->metrics.y_scale + 32 ) >> 6; if ( face->root.internal->transform_flags & 1 ) FT_Matrix_Multiply( &face->root.internal->transform_matrix, &ft_root_scale ); paint->u.transform.affine.xx = ft_root_scale.xx; paint->u.transform.affine.xy = ft_root_scale.xy; paint->u.transform.affine.yx = ft_root_scale.yx; paint->u.transform.affine.yy = ft_root_scale.yy; /* The translation is specified in 26.6 format and, according to the * documentation of `FT_Set_Translate`, is performed on the character * size given in the last call to `FT_Set_Char_Size`. The * 'PaintTransform' paint table's `FT_Affine23` format expects * values in 16.16 format, thus we need to shift by 10 bits. */ if ( face->root.internal->transform_flags & 2 ) { paint->u.transform.affine.dx = face->root.internal->transform_delta.x * ( 1 << 10 ); paint->u.transform.affine.dy = face->root.internal->transform_delta.y * ( 1 << 10 ); } else { paint->u.transform.affine.dx = 0; paint->u.transform.affine.dy = 0; } return 1; } return read_paint( colr, opaque_paint.p, paint ); } FT_LOCAL_DEF( FT_Error ) tt_face_colr_blend_layer( TT_Face face, FT_UInt color_index, FT_GlyphSlot dstSlot, FT_GlyphSlot srcSlot ) { FT_Error error; FT_UInt x, y; FT_Byte b, g, r, alpha; FT_ULong size; FT_Byte* src; FT_Byte* dst; if ( !dstSlot->bitmap.buffer ) { /* Initialize destination of color bitmap */ /* with the size of first component. */ dstSlot->bitmap_left = srcSlot->bitmap_left; dstSlot->bitmap_top = srcSlot->bitmap_top; dstSlot->bitmap.width = srcSlot->bitmap.width; dstSlot->bitmap.rows = srcSlot->bitmap.rows; dstSlot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA; dstSlot->bitmap.pitch = (int)dstSlot->bitmap.width * 4; dstSlot->bitmap.num_grays = 256; size = dstSlot->bitmap.rows * (unsigned int)dstSlot->bitmap.pitch; error = ft_glyphslot_alloc_bitmap( dstSlot, size ); if ( error ) return error; FT_MEM_ZERO( dstSlot->bitmap.buffer, size ); } else { /* Resize destination if needed such that new component fits. */ FT_Int x_min, x_max, y_min, y_max; x_min = FT_MIN( dstSlot->bitmap_left, srcSlot->bitmap_left ); x_max = FT_MAX( dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width, srcSlot->bitmap_left + (FT_Int)srcSlot->bitmap.width ); y_min = FT_MIN( dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows, srcSlot->bitmap_top - (FT_Int)srcSlot->bitmap.rows ); y_max = FT_MAX( dstSlot->bitmap_top, srcSlot->bitmap_top ); if ( x_min != dstSlot->bitmap_left || x_max != dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width || y_min != dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows || y_max != dstSlot->bitmap_top ) { FT_Memory memory = face->root.memory; FT_UInt width = (FT_UInt)( x_max - x_min ); FT_UInt rows = (FT_UInt)( y_max - y_min ); FT_UInt pitch = width * 4; FT_Byte* buf = NULL; FT_Byte* p; FT_Byte* q; size = rows * pitch; if ( FT_ALLOC( buf, size ) ) return error; p = dstSlot->bitmap.buffer; q = buf + (int)pitch * ( y_max - dstSlot->bitmap_top ) + 4 * ( dstSlot->bitmap_left - x_min ); for ( y = 0; y < dstSlot->bitmap.rows; y++ ) { FT_MEM_COPY( q, p, dstSlot->bitmap.width * 4 ); p += dstSlot->bitmap.pitch; q += pitch; } ft_glyphslot_set_bitmap( dstSlot, buf ); dstSlot->bitmap_top = y_max; dstSlot->bitmap_left = x_min; dstSlot->bitmap.width = width; dstSlot->bitmap.rows = rows; dstSlot->bitmap.pitch = (int)pitch; dstSlot->internal->flags |= FT_GLYPH_OWN_BITMAP; dstSlot->format = FT_GLYPH_FORMAT_BITMAP; } } if ( color_index == 0xFFFF ) { if ( face->have_foreground_color ) { b = face->foreground_color.blue; g = face->foreground_color.green; r = face->foreground_color.red; alpha = face->foreground_color.alpha; } else { if ( face->palette_data.palette_flags && ( face->palette_data.palette_flags[face->palette_index] & FT_PALETTE_FOR_DARK_BACKGROUND ) ) { /* white opaque */ b = 0xFF; g = 0xFF; r = 0xFF; alpha = 0xFF; } else { /* black opaque */ b = 0x00; g = 0x00; r = 0x00; alpha = 0xFF; } } } else { b = face->palette[color_index].blue; g = face->palette[color_index].green; r = face->palette[color_index].red; alpha = face->palette[color_index].alpha; } /* XXX Convert if srcSlot.bitmap is not grey? */ src = srcSlot->bitmap.buffer; dst = dstSlot->bitmap.buffer + dstSlot->bitmap.pitch * ( dstSlot->bitmap_top - srcSlot->bitmap_top ) + 4 * ( srcSlot->bitmap_left - dstSlot->bitmap_left ); for ( y = 0; y < srcSlot->bitmap.rows; y++ ) { for ( x = 0; x < srcSlot->bitmap.width; x++ ) { int aa = src[x]; int fa = alpha * aa / 255; int fb = b * fa / 255; int fg = g * fa / 255; int fr = r * fa / 255; int ba2 = 255 - fa; int bb = dst[4 * x + 0]; int bg = dst[4 * x + 1]; int br = dst[4 * x + 2]; int ba = dst[4 * x + 3]; dst[4 * x + 0] = (FT_Byte)( bb * ba2 / 255 + fb ); dst[4 * x + 1] = (FT_Byte)( bg * ba2 / 255 + fg ); dst[4 * x + 2] = (FT_Byte)( br * ba2 / 255 + fr ); dst[4 * x + 3] = (FT_Byte)( ba * ba2 / 255 + fa ); } src += srcSlot->bitmap.pitch; dst += dstSlot->bitmap.pitch; } return FT_Err_Ok; } #else /* !TT_CONFIG_OPTION_COLOR_LAYERS */ /* ANSI C doesn't like empty source files */ typedef int _tt_colr_dummy; #endif /* !TT_CONFIG_OPTION_COLOR_LAYERS */ /* EOF */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcolr.c
C++
gpl-3.0
40,007
/**************************************************************************** * * ttcolr.h * * TrueType and OpenType colored glyph layer support (specification). * * Copyright (C) 2018-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Originally written by Shao Yu Zhang <shaozhang@fb.com>. * * 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 __TTCOLR_H__ #define __TTCOLR_H__ #include "ttload.h" FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_colr( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_free_colr( TT_Face face ); FT_LOCAL( FT_Bool ) tt_face_get_colr_layer( TT_Face face, FT_UInt base_glyph, FT_UInt *aglyph_index, FT_UInt *acolor_index, FT_LayerIterator* iterator ); FT_LOCAL( FT_Bool ) tt_face_get_colr_glyph_paint( TT_Face face, FT_UInt base_glyph, FT_Color_Root_Transform root_transform, FT_OpaquePaint* paint ); FT_LOCAL( FT_Bool ) tt_face_get_color_glyph_clipbox( TT_Face face, FT_UInt base_glyph, FT_ClipBox* clip_box ); FT_LOCAL( FT_Bool ) tt_face_get_paint_layers( TT_Face face, FT_LayerIterator* iterator, FT_OpaquePaint* paint ); FT_LOCAL( FT_Bool ) tt_face_get_colorline_stops( TT_Face face, FT_ColorStop* color_stop, FT_ColorStopIterator* iterator ); FT_LOCAL( FT_Bool ) tt_face_get_paint( TT_Face face, FT_OpaquePaint opaque_paint, FT_COLR_Paint* paint ); FT_LOCAL( FT_Error ) tt_face_colr_blend_layer( TT_Face face, FT_UInt color_index, FT_GlyphSlot dstSlot, FT_GlyphSlot srcSlot ); FT_END_HEADER #endif /* __TTCOLR_H__ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcolr.h
C++
gpl-3.0
2,526
/**************************************************************************** * * ttcpal.c * * TrueType and OpenType color palette support (body). * * Copyright (C) 2018-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Originally written by Shao Yu Zhang <shaozhang@fb.com>. * * 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. * */ /************************************************************************** * * `CPAL' table specification: * * https://www.microsoft.com/typography/otspec/cpal.htm * */ #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include <freetype/ftcolor.h> #ifdef TT_CONFIG_OPTION_COLOR_LAYERS #include "ttcpal.h" /* NOTE: These are the table sizes calculated through the specs. */ #define CPAL_V0_HEADER_BASE_SIZE 12U #define COLOR_SIZE 4U /* all data from `CPAL' not covered in FT_Palette_Data */ typedef struct Cpal_ { FT_UShort version; /* Table version number (0 or 1 supported). */ FT_UShort num_colors; /* Total number of color records, */ /* combined for all palettes. */ FT_Byte* colors; /* RGBA array of colors */ FT_Byte* color_indices; /* Index of each palette's first color record */ /* in the combined color record array. */ /* The memory which backs up the `CPAL' table. */ void* table; FT_ULong table_size; } Cpal; /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttcpal FT_LOCAL_DEF( FT_Error ) tt_face_load_cpal( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = face->root.memory; FT_Byte* table = NULL; FT_Byte* p = NULL; Cpal* cpal = NULL; FT_ULong colors_offset; FT_ULong table_size; error = face->goto_table( face, TTAG_CPAL, stream, &table_size ); if ( error ) goto NoCpal; if ( table_size < CPAL_V0_HEADER_BASE_SIZE ) goto InvalidTable; if ( FT_FRAME_EXTRACT( table_size, table ) ) goto NoCpal; p = table; if ( FT_NEW( cpal ) ) goto NoCpal; cpal->version = FT_NEXT_USHORT( p ); if ( cpal->version > 1 ) goto InvalidTable; face->palette_data.num_palette_entries = FT_NEXT_USHORT( p ); face->palette_data.num_palettes = FT_NEXT_USHORT( p ); cpal->num_colors = FT_NEXT_USHORT( p ); colors_offset = FT_NEXT_ULONG( p ); if ( CPAL_V0_HEADER_BASE_SIZE + face->palette_data.num_palettes * 2U > table_size ) goto InvalidTable; if ( colors_offset >= table_size ) goto InvalidTable; if ( cpal->num_colors * COLOR_SIZE > table_size - colors_offset ) goto InvalidTable; if ( face->palette_data.num_palette_entries > cpal->num_colors ) goto InvalidTable; cpal->color_indices = p; cpal->colors = (FT_Byte*)( table + colors_offset ); if ( cpal->version == 1 ) { FT_ULong type_offset, label_offset, entry_label_offset; FT_UShort* array = NULL; FT_UShort* limit; FT_UShort* q; if ( CPAL_V0_HEADER_BASE_SIZE + face->palette_data.num_palettes * 2U + 3U * 4 > table_size ) goto InvalidTable; p += face->palette_data.num_palettes * 2U; type_offset = FT_NEXT_ULONG( p ); label_offset = FT_NEXT_ULONG( p ); entry_label_offset = FT_NEXT_ULONG( p ); if ( type_offset ) { if ( type_offset >= table_size ) goto InvalidTable; if ( face->palette_data.num_palettes * 2U > table_size - type_offset ) goto InvalidTable; if ( FT_QNEW_ARRAY( array, face->palette_data.num_palettes ) ) goto NoCpal; p = table + type_offset; q = array; limit = q + face->palette_data.num_palettes; while ( q < limit ) *q++ = FT_NEXT_USHORT( p ); face->palette_data.palette_flags = array; } if ( label_offset ) { if ( label_offset >= table_size ) goto InvalidTable; if ( face->palette_data.num_palettes * 2U > table_size - label_offset ) goto InvalidTable; if ( FT_QNEW_ARRAY( array, face->palette_data.num_palettes ) ) goto NoCpal; p = table + label_offset; q = array; limit = q + face->palette_data.num_palettes; while ( q < limit ) *q++ = FT_NEXT_USHORT( p ); face->palette_data.palette_name_ids = array; } if ( entry_label_offset ) { if ( entry_label_offset >= table_size ) goto InvalidTable; if ( face->palette_data.num_palette_entries * 2U > table_size - entry_label_offset ) goto InvalidTable; if ( FT_QNEW_ARRAY( array, face->palette_data.num_palette_entries ) ) goto NoCpal; p = table + entry_label_offset; q = array; limit = q + face->palette_data.num_palette_entries; while ( q < limit ) *q++ = FT_NEXT_USHORT( p ); face->palette_data.palette_entry_name_ids = array; } } cpal->table = table; cpal->table_size = table_size; face->cpal = cpal; /* set up default palette */ if ( FT_NEW_ARRAY( face->palette, face->palette_data.num_palette_entries ) ) goto NoCpal; if ( tt_face_palette_set( face, 0 ) ) goto InvalidTable; return FT_Err_Ok; InvalidTable: error = FT_THROW( Invalid_Table ); NoCpal: FT_FRAME_RELEASE( table ); FT_FREE( cpal ); face->cpal = NULL; /* arrays in `face->palette_data' and `face->palette' */ /* are freed in `sfnt_done_face' */ return error; } FT_LOCAL_DEF( void ) tt_face_free_cpal( TT_Face face ) { FT_Stream stream = face->root.stream; FT_Memory memory = face->root.memory; Cpal* cpal = (Cpal*)face->cpal; if ( cpal ) { FT_FRAME_RELEASE( cpal->table ); FT_FREE( cpal ); } } FT_LOCAL_DEF( FT_Error ) tt_face_palette_set( TT_Face face, FT_UInt palette_index ) { Cpal* cpal = (Cpal*)face->cpal; FT_Byte* offset; FT_Byte* p; FT_Color* q; FT_Color* limit; FT_UShort color_index; if ( !cpal || palette_index >= face->palette_data.num_palettes ) return FT_THROW( Invalid_Argument ); offset = cpal->color_indices + 2 * palette_index; color_index = FT_PEEK_USHORT( offset ); if ( color_index + face->palette_data.num_palette_entries > cpal->num_colors ) return FT_THROW( Invalid_Table ); p = cpal->colors + COLOR_SIZE * color_index; q = face->palette; limit = q + face->palette_data.num_palette_entries; while ( q < limit ) { q->blue = FT_NEXT_BYTE( p ); q->green = FT_NEXT_BYTE( p ); q->red = FT_NEXT_BYTE( p ); q->alpha = FT_NEXT_BYTE( p ); q++; } return FT_Err_Ok; } #else /* !TT_CONFIG_OPTION_COLOR_LAYERS */ /* ANSI C doesn't like empty source files */ typedef int _tt_cpal_dummy; #endif /* !TT_CONFIG_OPTION_COLOR_LAYERS */ /* EOF */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcpal.c
C++
gpl-3.0
7,964
/**************************************************************************** * * ttcpal.h * * TrueType and OpenType color palette support (specification). * * Copyright (C) 2018-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Originally written by Shao Yu Zhang <shaozhang@fb.com>. * * 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 __TTCPAL_H__ #define __TTCPAL_H__ #include "ttload.h" FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_cpal( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_free_cpal( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_palette_set( TT_Face face, FT_UInt palette_index ); FT_END_HEADER #endif /* __TTCPAL_H__ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttcpal.h
C++
gpl-3.0
1,036
/**************************************************************************** * * ttkern.c * * Load the basic TrueType kerning table. This doesn't handle * kerning data within the GPOS table at the moment. * * Copyright (C) 1996-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include "ttkern.h" #include "sferrors.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttkern #undef TT_KERN_INDEX #define TT_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)(g1) << 16 ) | (g2) ) FT_LOCAL_DEF( FT_Error ) tt_face_load_kern( TT_Face face, FT_Stream stream ) { FT_Error error; FT_ULong table_size; FT_Byte* p; FT_Byte* p_limit; FT_UInt nn, num_tables; FT_UInt32 avail = 0, ordered = 0; /* the kern table is optional; exit silently if it is missing */ error = face->goto_table( face, TTAG_kern, stream, &table_size ); if ( error ) goto Exit; if ( table_size < 4 ) /* the case of a malformed table */ { FT_ERROR(( "tt_face_load_kern:" " kerning table is too small - ignored\n" )); error = FT_THROW( Table_Missing ); goto Exit; } if ( FT_FRAME_EXTRACT( table_size, face->kern_table ) ) { FT_ERROR(( "tt_face_load_kern:" " could not extract kerning table\n" )); goto Exit; } face->kern_table_size = table_size; p = face->kern_table; p_limit = p + table_size; p += 2; /* skip version */ num_tables = FT_NEXT_USHORT( p ); if ( num_tables > 32 ) /* we only support up to 32 sub-tables */ num_tables = 32; for ( nn = 0; nn < num_tables; nn++ ) { FT_UInt num_pairs, length, coverage, format; FT_Byte* p_next; FT_UInt32 mask = (FT_UInt32)1UL << nn; if ( p + 6 > p_limit ) break; p_next = p; p += 2; /* skip version */ length = FT_NEXT_USHORT( p ); coverage = FT_NEXT_USHORT( p ); if ( length <= 6 + 8 ) break; p_next += length; if ( p_next > p_limit ) /* handle broken table */ p_next = p_limit; format = coverage >> 8; /* we currently only support format 0 kerning tables */ if ( format != 0 ) goto NextTable; /* only use horizontal kerning tables */ if ( ( coverage & 3U ) != 0x0001 || p + 8 > p_next ) goto NextTable; num_pairs = FT_NEXT_USHORT( p ); p += 6; if ( ( p_next - p ) < 6 * (int)num_pairs ) /* handle broken count */ num_pairs = (FT_UInt)( ( p_next - p ) / 6 ); avail |= mask; /* * Now check whether the pairs in this table are ordered. * We then can use binary search. */ if ( num_pairs > 0 ) { FT_ULong count; FT_ULong old_pair; old_pair = FT_NEXT_ULONG( p ); p += 2; for ( count = num_pairs - 1; count > 0; count-- ) { FT_UInt32 cur_pair; cur_pair = FT_NEXT_ULONG( p ); if ( cur_pair < old_pair ) break; p += 2; old_pair = cur_pair; } if ( count == 0 ) ordered |= mask; } NextTable: p = p_next; } face->num_kern_tables = nn; face->kern_avail_bits = avail; face->kern_order_bits = ordered; Exit: return error; } FT_LOCAL_DEF( void ) tt_face_done_kern( TT_Face face ) { FT_Stream stream = face->root.stream; FT_FRAME_RELEASE( face->kern_table ); face->kern_table_size = 0; face->num_kern_tables = 0; face->kern_avail_bits = 0; face->kern_order_bits = 0; } FT_LOCAL_DEF( FT_Int ) tt_face_get_kerning( TT_Face face, FT_UInt left_glyph, FT_UInt right_glyph ) { FT_Int result = 0; FT_UInt count, mask; FT_Byte* p; FT_Byte* p_limit; if ( !face->kern_table ) return result; p = face->kern_table; p_limit = p + face->kern_table_size; p += 4; mask = 0x0001; for ( count = face->num_kern_tables; count > 0 && p + 6 <= p_limit; count--, mask <<= 1 ) { FT_Byte* base = p; FT_Byte* next; FT_UInt version = FT_NEXT_USHORT( p ); FT_UInt length = FT_NEXT_USHORT( p ); FT_UInt coverage = FT_NEXT_USHORT( p ); FT_UInt num_pairs; FT_Int value = 0; FT_UNUSED( version ); next = base + length; if ( next > p_limit ) /* handle broken table */ next = p_limit; if ( ( face->kern_avail_bits & mask ) == 0 ) goto NextTable; FT_ASSERT( p + 8 <= next ); /* tested in tt_face_load_kern */ num_pairs = FT_NEXT_USHORT( p ); p += 6; if ( ( next - p ) < 6 * (int)num_pairs ) /* handle broken count */ num_pairs = (FT_UInt)( ( next - p ) / 6 ); switch ( coverage >> 8 ) { case 0: { FT_ULong key0 = TT_KERN_INDEX( left_glyph, right_glyph ); if ( face->kern_order_bits & mask ) /* binary search */ { FT_UInt min = 0; FT_UInt max = num_pairs; while ( min < max ) { FT_UInt mid = ( min + max ) >> 1; FT_Byte* q = p + 6 * mid; FT_ULong key; key = FT_NEXT_ULONG( q ); if ( key == key0 ) { value = FT_PEEK_SHORT( q ); goto Found; } if ( key < key0 ) min = mid + 1; else max = mid; } } else /* linear search */ { FT_UInt count2; for ( count2 = num_pairs; count2 > 0; count2-- ) { FT_ULong key = FT_NEXT_ULONG( p ); if ( key == key0 ) { value = FT_PEEK_SHORT( p ); goto Found; } p += 2; } } } break; /* * We don't support format 2 because we haven't seen a single font * using it in real life... */ default: ; } goto NextTable; Found: if ( coverage & 8 ) /* override or add */ result = value; else result += value; NextTable: p = next; } return result; } #undef TT_KERN_INDEX /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttkern.c
C++
gpl-3.0
7,232
/**************************************************************************** * * ttkern.h * * Load the basic TrueType kerning table. This doesn't handle * kerning data within the GPOS table at the moment. * * Copyright (C) 1996-2022 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 TTKERN_H_ #define TTKERN_H_ #include <freetype/internal/ftstream.h> #include <freetype/internal/tttypes.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_kern( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_done_kern( TT_Face face ); FT_LOCAL( FT_Int ) tt_face_get_kerning( TT_Face face, FT_UInt left_glyph, FT_UInt right_glyph ); #define TT_FACE_HAS_KERNING( face ) ( (face)->kern_avail_bits != 0 ) FT_END_HEADER #endif /* TTKERN_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttkern.h
C++
gpl-3.0
1,199
/**************************************************************************** * * ttload.c * * Load the basic TrueType tables, i.e., tables that can be either in * TTF or OTF fonts (body). * * Copyright (C) 1996-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include "ttload.h" #include "sferrors.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttload /************************************************************************** * * @Function: * tt_face_lookup_table * * @Description: * Looks for a TrueType table by name. * * @Input: * face :: * A face object handle. * * tag :: * The searched tag. * * @Return: * A pointer to the table directory entry. 0 if not found. */ FT_LOCAL_DEF( TT_Table ) tt_face_lookup_table( TT_Face face, FT_ULong tag ) { TT_Table entry; TT_Table limit; #ifdef FT_DEBUG_LEVEL_TRACE FT_Bool zero_length = FALSE; #endif FT_TRACE4(( "tt_face_lookup_table: %p, `%c%c%c%c' -- ", (void *)face, (FT_Char)( tag >> 24 ), (FT_Char)( tag >> 16 ), (FT_Char)( tag >> 8 ), (FT_Char)( tag ) )); entry = face->dir_tables; limit = entry + face->num_tables; for ( ; entry < limit; entry++ ) { /* For compatibility with Windows, we consider */ /* zero-length tables the same as missing tables. */ if ( entry->Tag == tag ) { if ( entry->Length != 0 ) { FT_TRACE4(( "found table.\n" )); return entry; } #ifdef FT_DEBUG_LEVEL_TRACE zero_length = TRUE; #endif } } #ifdef FT_DEBUG_LEVEL_TRACE if ( zero_length ) FT_TRACE4(( "ignoring empty table\n" )); else FT_TRACE4(( "could not find table\n" )); #endif return NULL; } /************************************************************************** * * @Function: * tt_face_goto_table * * @Description: * Looks for a TrueType table by name, then seek a stream to it. * * @Input: * face :: * A face object handle. * * tag :: * The searched tag. * * stream :: * The stream to seek when the table is found. * * @Output: * length :: * The length of the table if found, undefined otherwise. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_goto_table( TT_Face face, FT_ULong tag, FT_Stream stream, FT_ULong* length ) { TT_Table table; FT_Error error; table = tt_face_lookup_table( face, tag ); if ( table ) { if ( length ) *length = table->Length; if ( FT_STREAM_SEEK( table->Offset ) ) goto Exit; } else error = FT_THROW( Table_Missing ); Exit: return error; } /* Here, we */ /* */ /* - check that `num_tables' is valid (and adjust it if necessary); */ /* also return the number of valid table entries */ /* */ /* - look for a `head' table, check its size, and parse it to check */ /* whether its `magic' field is correctly set */ /* */ /* - errors (except errors returned by stream handling) */ /* */ /* SFNT_Err_Unknown_File_Format: */ /* no table is defined in directory, it is not sfnt-wrapped */ /* data */ /* SFNT_Err_Table_Missing: */ /* table directory is valid, but essential tables */ /* (head/bhed/SING) are missing */ /* */ static FT_Error check_table_dir( SFNT_Header sfnt, FT_Stream stream, FT_UShort* valid ) { FT_Error error; FT_UShort nn, valid_entries = 0; FT_UInt has_head = 0, has_sing = 0, has_meta = 0; FT_ULong offset = sfnt->offset + 12; static const FT_Frame_Field table_dir_entry_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_TableRec FT_FRAME_START( 16 ), FT_FRAME_ULONG( Tag ), FT_FRAME_ULONG( CheckSum ), FT_FRAME_ULONG( Offset ), FT_FRAME_ULONG( Length ), FT_FRAME_END }; if ( FT_STREAM_SEEK( offset ) ) goto Exit; for ( nn = 0; nn < sfnt->num_tables; nn++ ) { TT_TableRec table; if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields, &table ) ) { FT_TRACE2(( "check_table_dir:" " can read only %d table%s in font (instead of %d)\n", nn, nn == 1 ? "" : "s", sfnt->num_tables )); sfnt->num_tables = nn; break; } /* we ignore invalid tables */ if ( table.Offset > stream->size ) { FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn )); continue; } else if ( table.Length > stream->size - table.Offset ) { /* Some tables have such a simple structure that clipping its */ /* contents is harmless. This also makes FreeType less sensitive */ /* to invalid table lengths (which programs like Acroread seem to */ /* ignore in general). */ if ( table.Tag == TTAG_hmtx || table.Tag == TTAG_vmtx ) valid_entries++; else { FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn )); continue; } } else valid_entries++; if ( table.Tag == TTAG_head || table.Tag == TTAG_bhed ) { FT_UInt32 magic; #ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS if ( table.Tag == TTAG_head ) #endif has_head = 1; /* * The table length should be 0x36, but certain font tools make it * 0x38, so we will just check that it is greater. * * Note that according to the specification, the table must be * padded to 32-bit lengths, but this doesn't apply to the value of * its `Length' field! * */ if ( table.Length < 0x36 ) { FT_TRACE2(( "check_table_dir:" " `head' or `bhed' table too small\n" )); error = FT_THROW( Table_Missing ); goto Exit; } if ( FT_STREAM_SEEK( table.Offset + 12 ) || FT_READ_ULONG( magic ) ) goto Exit; if ( magic != 0x5F0F3CF5UL ) FT_TRACE2(( "check_table_dir:" " invalid magic number in `head' or `bhed' table\n")); if ( FT_STREAM_SEEK( offset + ( nn + 1 ) * 16 ) ) goto Exit; } else if ( table.Tag == TTAG_SING ) has_sing = 1; else if ( table.Tag == TTAG_META ) has_meta = 1; } *valid = valid_entries; if ( !valid_entries ) { FT_TRACE2(( "check_table_dir: no valid tables found\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } /* if `sing' and `meta' tables are present, there is no `head' table */ if ( has_head || ( has_sing && has_meta ) ) { error = FT_Err_Ok; goto Exit; } else { FT_TRACE2(( "check_table_dir:" )); #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_TRACE2(( " neither `head', `bhed', nor `sing' table found\n" )); #else FT_TRACE2(( " neither `head' nor `sing' table found\n" )); #endif error = FT_THROW( Table_Missing ); } Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_font_dir * * @Description: * Loads the header of a SFNT font file. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * @Output: * sfnt :: * The SFNT header. * * @Return: * FreeType error code. 0 means success. * * @Note: * The stream cursor must be at the beginning of the font directory. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_font_dir( TT_Face face, FT_Stream stream ) { SFNT_HeaderRec sfnt; FT_Error error; FT_Memory memory = stream->memory; FT_UShort nn, valid_entries = 0; static const FT_Frame_Field offset_table_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE SFNT_HeaderRec FT_FRAME_START( 8 ), FT_FRAME_USHORT( num_tables ), FT_FRAME_USHORT( search_range ), FT_FRAME_USHORT( entry_selector ), FT_FRAME_USHORT( range_shift ), FT_FRAME_END }; FT_TRACE2(( "tt_face_load_font_dir: %p\n", (void *)face )); /* read the offset table */ sfnt.offset = FT_STREAM_POS(); if ( FT_READ_ULONG( sfnt.format_tag ) || FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) ) goto Exit; /* many fonts don't have these fields set correctly */ #if 0 if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 ) || sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 ) return FT_THROW( Unknown_File_Format ); #endif /* load the table directory */ FT_TRACE2(( "-- Number of tables: %10u\n", sfnt.num_tables )); FT_TRACE2(( "-- Format version: 0x%08lx\n", sfnt.format_tag )); if ( sfnt.format_tag != TTAG_OTTO ) { /* check first */ error = check_table_dir( &sfnt, stream, &valid_entries ); if ( error ) { FT_TRACE2(( "tt_face_load_font_dir:" " invalid table directory for TrueType\n" )); goto Exit; } } else { valid_entries = sfnt.num_tables; if ( !valid_entries ) { FT_TRACE2(( "tt_face_load_font_dir: no valid tables found\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } } face->num_tables = valid_entries; face->format_tag = sfnt.format_tag; if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) ) goto Exit; if ( FT_STREAM_SEEK( sfnt.offset + 12 ) || FT_FRAME_ENTER( sfnt.num_tables * 16L ) ) goto Exit; FT_TRACE2(( "\n" )); FT_TRACE2(( " tag offset length checksum\n" )); FT_TRACE2(( " ----------------------------------\n" )); valid_entries = 0; for ( nn = 0; nn < sfnt.num_tables; nn++ ) { TT_TableRec entry; FT_UShort i; FT_Bool duplicate; entry.Tag = FT_GET_TAG4(); entry.CheckSum = FT_GET_ULONG(); entry.Offset = FT_GET_ULONG(); entry.Length = FT_GET_ULONG(); /* ignore invalid tables that can't be sanitized */ if ( entry.Offset > stream->size ) continue; else if ( entry.Length > stream->size - entry.Offset ) { if ( entry.Tag == TTAG_hmtx || entry.Tag == TTAG_vmtx ) { #ifdef FT_DEBUG_LEVEL_TRACE FT_ULong old_length = entry.Length; #endif /* make metrics table length a multiple of 4 */ entry.Length = ( stream->size - entry.Offset ) & ~3U; FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx" " (sanitized; original length %08lx)", (FT_Char)( entry.Tag >> 24 ), (FT_Char)( entry.Tag >> 16 ), (FT_Char)( entry.Tag >> 8 ), (FT_Char)( entry.Tag ), entry.Offset, entry.Length, entry.CheckSum, old_length )); } else continue; } #ifdef FT_DEBUG_LEVEL_TRACE else FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx", (FT_Char)( entry.Tag >> 24 ), (FT_Char)( entry.Tag >> 16 ), (FT_Char)( entry.Tag >> 8 ), (FT_Char)( entry.Tag ), entry.Offset, entry.Length, entry.CheckSum )); #endif /* ignore duplicate tables – the first one wins */ duplicate = 0; for ( i = 0; i < valid_entries; i++ ) { if ( face->dir_tables[i].Tag == entry.Tag ) { duplicate = 1; break; } } if ( duplicate ) { FT_TRACE2(( " (duplicate, ignored)\n" )); continue; } else { FT_TRACE2(( "\n" )); /* we finally have a valid entry */ face->dir_tables[valid_entries++] = entry; } } /* final adjustment to number of tables */ face->num_tables = valid_entries; FT_FRAME_EXIT(); FT_TRACE2(( "table directory loaded\n" )); FT_TRACE2(( "\n" )); Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_any * * @Description: * Loads any font table into client memory. * * @Input: * face :: * The face object to look for. * * tag :: * The tag of table to load. Use the value 0 if you want * to access the whole font file, else set this parameter * to a valid TrueType table tag that you can forge with * the MAKE_TT_TAG macro. * * offset :: * The starting offset in the table (or the file if * tag == 0). * * length :: * The address of the decision variable: * * If length == NULL: * Loads the whole table. Returns an error if * `offset' == 0! * * If *length == 0: * Exits immediately; returning the length of the given * table or of the font file, depending on the value of * `tag'. * * If *length != 0: * Loads the next `length' bytes of table or font, * starting at offset `offset' (in table or font too). * * @Output: * buffer :: * The address of target buffer. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_any( TT_Face face, FT_ULong tag, FT_Long offset, FT_Byte* buffer, FT_ULong* length ) { FT_Error error; FT_Stream stream; TT_Table table; FT_ULong size; if ( tag != 0 ) { /* look for tag in font directory */ table = tt_face_lookup_table( face, tag ); if ( !table ) { error = FT_THROW( Table_Missing ); goto Exit; } offset += table->Offset; size = table->Length; } else /* tag == 0 -- the user wants to access the font file directly */ size = face->root.stream->size; if ( length && *length == 0 ) { *length = size; return FT_Err_Ok; } if ( length ) size = *length; stream = face->root.stream; /* the `if' is syntactic sugar for picky compilers */ if ( FT_STREAM_READ_AT( offset, buffer, size ) ) goto Exit; Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_generic_header * * @Description: * Loads the TrueType table `head' or `bhed'. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * @Return: * FreeType error code. 0 means success. */ static FT_Error tt_face_load_generic_header( TT_Face face, FT_Stream stream, FT_ULong tag ) { FT_Error error; TT_Header* header; static const FT_Frame_Field header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_Header FT_FRAME_START( 54 ), FT_FRAME_ULONG ( Table_Version ), FT_FRAME_ULONG ( Font_Revision ), FT_FRAME_LONG ( CheckSum_Adjust ), FT_FRAME_LONG ( Magic_Number ), FT_FRAME_USHORT( Flags ), FT_FRAME_USHORT( Units_Per_EM ), FT_FRAME_ULONG ( Created[0] ), FT_FRAME_ULONG ( Created[1] ), FT_FRAME_ULONG ( Modified[0] ), FT_FRAME_ULONG ( Modified[1] ), FT_FRAME_SHORT ( xMin ), FT_FRAME_SHORT ( yMin ), FT_FRAME_SHORT ( xMax ), FT_FRAME_SHORT ( yMax ), FT_FRAME_USHORT( Mac_Style ), FT_FRAME_USHORT( Lowest_Rec_PPEM ), FT_FRAME_SHORT ( Font_Direction ), FT_FRAME_SHORT ( Index_To_Loc_Format ), FT_FRAME_SHORT ( Glyph_Data_Format ), FT_FRAME_END }; error = face->goto_table( face, tag, stream, 0 ); if ( error ) goto Exit; header = &face->header; if ( FT_STREAM_READ_FIELDS( header_fields, header ) ) goto Exit; FT_TRACE3(( "Units per EM: %4u\n", header->Units_Per_EM )); FT_TRACE3(( "IndexToLoc: %4d\n", header->Index_To_Loc_Format )); Exit: return error; } FT_LOCAL_DEF( FT_Error ) tt_face_load_head( TT_Face face, FT_Stream stream ) { return tt_face_load_generic_header( face, stream, TTAG_head ); } #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_LOCAL_DEF( FT_Error ) tt_face_load_bhed( TT_Face face, FT_Stream stream ) { return tt_face_load_generic_header( face, stream, TTAG_bhed ); } #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /************************************************************************** * * @Function: * tt_face_load_maxp * * @Description: * Loads the maximum profile into a face object. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_maxp( TT_Face face, FT_Stream stream ) { FT_Error error; TT_MaxProfile* maxProfile = &face->max_profile; static const FT_Frame_Field maxp_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_MaxProfile FT_FRAME_START( 6 ), FT_FRAME_LONG ( version ), FT_FRAME_USHORT( numGlyphs ), FT_FRAME_END }; static const FT_Frame_Field maxp_fields_extra[] = { FT_FRAME_START( 26 ), FT_FRAME_USHORT( maxPoints ), FT_FRAME_USHORT( maxContours ), FT_FRAME_USHORT( maxCompositePoints ), FT_FRAME_USHORT( maxCompositeContours ), FT_FRAME_USHORT( maxZones ), FT_FRAME_USHORT( maxTwilightPoints ), FT_FRAME_USHORT( maxStorage ), FT_FRAME_USHORT( maxFunctionDefs ), FT_FRAME_USHORT( maxInstructionDefs ), FT_FRAME_USHORT( maxStackElements ), FT_FRAME_USHORT( maxSizeOfInstructions ), FT_FRAME_USHORT( maxComponentElements ), FT_FRAME_USHORT( maxComponentDepth ), FT_FRAME_END }; error = face->goto_table( face, TTAG_maxp, stream, 0 ); if ( error ) goto Exit; if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) ) goto Exit; maxProfile->maxPoints = 0; maxProfile->maxContours = 0; maxProfile->maxCompositePoints = 0; maxProfile->maxCompositeContours = 0; maxProfile->maxZones = 0; maxProfile->maxTwilightPoints = 0; maxProfile->maxStorage = 0; maxProfile->maxFunctionDefs = 0; maxProfile->maxInstructionDefs = 0; maxProfile->maxStackElements = 0; maxProfile->maxSizeOfInstructions = 0; maxProfile->maxComponentElements = 0; maxProfile->maxComponentDepth = 0; if ( maxProfile->version >= 0x10000L ) { if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) ) goto Exit; /* XXX: an adjustment that is necessary to load certain */ /* broken fonts like `Keystrokes MT' :-( */ /* */ /* We allocate 64 function entries by default when */ /* the maxFunctionDefs value is smaller. */ if ( maxProfile->maxFunctionDefs < 64 ) maxProfile->maxFunctionDefs = 64; /* we add 4 phantom points later */ if ( maxProfile->maxTwilightPoints > ( 0xFFFFU - 4 ) ) { FT_TRACE0(( "tt_face_load_maxp:" " too much twilight points in `maxp' table;\n" )); FT_TRACE0(( " " " some glyphs might be rendered incorrectly\n" )); maxProfile->maxTwilightPoints = 0xFFFFU - 4; } } FT_TRACE3(( "numGlyphs: %u\n", maxProfile->numGlyphs )); Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_name * * @Description: * Loads the name records. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_name( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_pos, table_len; FT_ULong storage_start, storage_limit; TT_NameTable table; TT_Name names = NULL; TT_LangTag langTags = NULL; static const FT_Frame_Field name_table_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_NameTableRec FT_FRAME_START( 6 ), FT_FRAME_USHORT( format ), FT_FRAME_USHORT( numNameRecords ), FT_FRAME_USHORT( storageOffset ), FT_FRAME_END }; static const FT_Frame_Field name_record_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_NameRec /* no FT_FRAME_START */ FT_FRAME_USHORT( platformID ), FT_FRAME_USHORT( encodingID ), FT_FRAME_USHORT( languageID ), FT_FRAME_USHORT( nameID ), FT_FRAME_USHORT( stringLength ), FT_FRAME_USHORT( stringOffset ), FT_FRAME_END }; static const FT_Frame_Field langTag_record_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_LangTagRec /* no FT_FRAME_START */ FT_FRAME_USHORT( stringLength ), FT_FRAME_USHORT( stringOffset ), FT_FRAME_END }; table = &face->name_table; table->stream = stream; error = face->goto_table( face, TTAG_name, stream, &table_len ); if ( error ) goto Exit; table_pos = FT_STREAM_POS(); if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) ) goto Exit; /* Some popular Asian fonts have an invalid `storageOffset' value (it */ /* should be at least `6 + 12*numNameRecords'). However, the string */ /* offsets, computed as `storageOffset + entry->stringOffset', are */ /* valid pointers within the name table... */ /* */ /* We thus can't check `storageOffset' right now. */ /* */ storage_start = table_pos + 6 + 12 * table->numNameRecords; storage_limit = table_pos + table_len; if ( storage_start > storage_limit ) { FT_ERROR(( "tt_face_load_name: invalid `name' table\n" )); error = FT_THROW( Name_Table_Missing ); goto Exit; } /* `name' format 1 contains additional language tag records, */ /* which we load first */ if ( table->format == 1 ) { if ( FT_STREAM_SEEK( storage_start ) || FT_READ_USHORT( table->numLangTagRecords ) ) goto Exit; storage_start += 2 + 4 * table->numLangTagRecords; /* allocate language tag records array */ if ( FT_QNEW_ARRAY( langTags, table->numLangTagRecords ) || FT_FRAME_ENTER( table->numLangTagRecords * 4 ) ) goto Exit; /* load language tags */ { TT_LangTag entry = langTags; TT_LangTag limit = FT_OFFSET( entry, table->numLangTagRecords ); for ( ; entry < limit; entry++ ) { (void)FT_STREAM_READ_FIELDS( langTag_record_fields, entry ); /* check that the langTag string is within the table */ entry->stringOffset += table_pos + table->storageOffset; if ( entry->stringOffset < storage_start || entry->stringOffset + entry->stringLength > storage_limit ) { /* invalid entry; ignore it */ entry->stringLength = 0; } /* mark the string as not yet loaded */ entry->string = NULL; } table->langTags = langTags; langTags = NULL; } FT_FRAME_EXIT(); (void)FT_STREAM_SEEK( table_pos + 6 ); } /* allocate name records array */ if ( FT_QNEW_ARRAY( names, table->numNameRecords ) || FT_FRAME_ENTER( table->numNameRecords * 12 ) ) goto Exit; /* load name records */ { TT_Name entry = names; FT_UInt count = table->numNameRecords; FT_UInt valid = 0; for ( ; count > 0; count-- ) { if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) ) continue; /* check that the name is not empty */ if ( entry->stringLength == 0 ) continue; /* check that the name string is within the table */ entry->stringOffset += table_pos + table->storageOffset; if ( entry->stringOffset < storage_start || entry->stringOffset + entry->stringLength > storage_limit ) { /* invalid entry; ignore it */ continue; } /* assure that we have a valid language tag ID, and */ /* that the corresponding langTag entry is valid, too */ if ( table->format == 1 && entry->languageID >= 0x8000U ) { if ( entry->languageID - 0x8000U >= table->numLangTagRecords || !table->langTags[entry->languageID - 0x8000U].stringLength ) { /* invalid entry; ignore it */ continue; } } /* mark the string as not yet converted */ entry->string = NULL; valid++; entry++; } /* reduce array size to the actually used elements */ FT_MEM_QRENEW_ARRAY( names, table->numNameRecords, valid ); table->names = names; names = NULL; table->numNameRecords = valid; } FT_FRAME_EXIT(); /* everything went well, update face->num_names */ face->num_names = (FT_UShort)table->numNameRecords; Exit: FT_FREE( names ); FT_FREE( langTags ); return error; } /************************************************************************** * * @Function: * tt_face_free_name * * @Description: * Frees the name records. * * @Input: * face :: * A handle to the target face object. */ FT_LOCAL_DEF( void ) tt_face_free_name( TT_Face face ) { FT_Memory memory = face->root.driver->root.memory; TT_NameTable table = &face->name_table; if ( table->names ) { TT_Name entry = table->names; TT_Name limit = entry + table->numNameRecords; for ( ; entry < limit; entry++ ) FT_FREE( entry->string ); FT_FREE( table->names ); } if ( table->langTags ) { TT_LangTag entry = table->langTags; TT_LangTag limit = entry + table->numLangTagRecords; for ( ; entry < limit; entry++ ) FT_FREE( entry->string ); FT_FREE( table->langTags ); } table->numNameRecords = 0; table->numLangTagRecords = 0; table->format = 0; table->storageOffset = 0; } /************************************************************************** * * @Function: * tt_face_load_cmap * * @Description: * Loads the cmap directory in a face object. The cmaps themselves * are loaded on demand in the `ttcmap.c' module. * * @Input: * face :: * A handle to the target face object. * * stream :: * A handle to the input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_cmap( TT_Face face, FT_Stream stream ) { FT_Error error; error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size ); if ( error ) goto Exit; if ( FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) ) face->cmap_size = 0; Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_os2 * * @Description: * Loads the OS2 table. * * @Input: * face :: * A handle to the target face object. * * stream :: * A handle to the input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_os2( TT_Face face, FT_Stream stream ) { FT_Error error; TT_OS2* os2; static const FT_Frame_Field os2_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_OS2 FT_FRAME_START( 78 ), FT_FRAME_USHORT( version ), FT_FRAME_SHORT ( xAvgCharWidth ), FT_FRAME_USHORT( usWeightClass ), FT_FRAME_USHORT( usWidthClass ), FT_FRAME_SHORT ( fsType ), FT_FRAME_SHORT ( ySubscriptXSize ), FT_FRAME_SHORT ( ySubscriptYSize ), FT_FRAME_SHORT ( ySubscriptXOffset ), FT_FRAME_SHORT ( ySubscriptYOffset ), FT_FRAME_SHORT ( ySuperscriptXSize ), FT_FRAME_SHORT ( ySuperscriptYSize ), FT_FRAME_SHORT ( ySuperscriptXOffset ), FT_FRAME_SHORT ( ySuperscriptYOffset ), FT_FRAME_SHORT ( yStrikeoutSize ), FT_FRAME_SHORT ( yStrikeoutPosition ), FT_FRAME_SHORT ( sFamilyClass ), FT_FRAME_BYTE ( panose[0] ), FT_FRAME_BYTE ( panose[1] ), FT_FRAME_BYTE ( panose[2] ), FT_FRAME_BYTE ( panose[3] ), FT_FRAME_BYTE ( panose[4] ), FT_FRAME_BYTE ( panose[5] ), FT_FRAME_BYTE ( panose[6] ), FT_FRAME_BYTE ( panose[7] ), FT_FRAME_BYTE ( panose[8] ), FT_FRAME_BYTE ( panose[9] ), FT_FRAME_ULONG ( ulUnicodeRange1 ), FT_FRAME_ULONG ( ulUnicodeRange2 ), FT_FRAME_ULONG ( ulUnicodeRange3 ), FT_FRAME_ULONG ( ulUnicodeRange4 ), FT_FRAME_BYTE ( achVendID[0] ), FT_FRAME_BYTE ( achVendID[1] ), FT_FRAME_BYTE ( achVendID[2] ), FT_FRAME_BYTE ( achVendID[3] ), FT_FRAME_USHORT( fsSelection ), FT_FRAME_USHORT( usFirstCharIndex ), FT_FRAME_USHORT( usLastCharIndex ), FT_FRAME_SHORT ( sTypoAscender ), FT_FRAME_SHORT ( sTypoDescender ), FT_FRAME_SHORT ( sTypoLineGap ), FT_FRAME_USHORT( usWinAscent ), FT_FRAME_USHORT( usWinDescent ), FT_FRAME_END }; /* `OS/2' version 1 and newer */ static const FT_Frame_Field os2_fields_extra1[] = { FT_FRAME_START( 8 ), FT_FRAME_ULONG( ulCodePageRange1 ), FT_FRAME_ULONG( ulCodePageRange2 ), FT_FRAME_END }; /* `OS/2' version 2 and newer */ static const FT_Frame_Field os2_fields_extra2[] = { FT_FRAME_START( 10 ), FT_FRAME_SHORT ( sxHeight ), FT_FRAME_SHORT ( sCapHeight ), FT_FRAME_USHORT( usDefaultChar ), FT_FRAME_USHORT( usBreakChar ), FT_FRAME_USHORT( usMaxContext ), FT_FRAME_END }; /* `OS/2' version 5 and newer */ static const FT_Frame_Field os2_fields_extra5[] = { FT_FRAME_START( 4 ), FT_FRAME_USHORT( usLowerOpticalPointSize ), FT_FRAME_USHORT( usUpperOpticalPointSize ), FT_FRAME_END }; /* We now support old Mac fonts where the OS/2 table doesn't */ /* exist. Simply put, we set the `version' field to 0xFFFF */ /* and test this value each time we need to access the table. */ error = face->goto_table( face, TTAG_OS2, stream, 0 ); if ( error ) goto Exit; os2 = &face->os2; if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) ) goto Exit; os2->ulCodePageRange1 = 0; os2->ulCodePageRange2 = 0; os2->sxHeight = 0; os2->sCapHeight = 0; os2->usDefaultChar = 0; os2->usBreakChar = 0; os2->usMaxContext = 0; os2->usLowerOpticalPointSize = 0; os2->usUpperOpticalPointSize = 0xFFFF; if ( os2->version >= 0x0001 ) { /* only version 1 tables */ if ( FT_STREAM_READ_FIELDS( os2_fields_extra1, os2 ) ) goto Exit; if ( os2->version >= 0x0002 ) { /* only version 2 tables */ if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) ) goto Exit; if ( os2->version >= 0x0005 ) { /* only version 5 tables */ if ( FT_STREAM_READ_FIELDS( os2_fields_extra5, os2 ) ) goto Exit; } } } FT_TRACE3(( "sTypoAscender: %4d\n", os2->sTypoAscender )); FT_TRACE3(( "sTypoDescender: %4d\n", os2->sTypoDescender )); FT_TRACE3(( "usWinAscent: %4u\n", os2->usWinAscent )); FT_TRACE3(( "usWinDescent: %4u\n", os2->usWinDescent )); FT_TRACE3(( "fsSelection: 0x%2x\n", os2->fsSelection )); Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_postscript * * @Description: * Loads the Postscript table. * * @Input: * face :: * A handle to the target face object. * * stream :: * A handle to the input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_post( TT_Face face, FT_Stream stream ) { FT_Error error; TT_Postscript* post = &face->postscript; static const FT_Frame_Field post_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_Postscript FT_FRAME_START( 32 ), FT_FRAME_LONG ( FormatType ), FT_FRAME_LONG ( italicAngle ), FT_FRAME_SHORT( underlinePosition ), FT_FRAME_SHORT( underlineThickness ), FT_FRAME_ULONG( isFixedPitch ), FT_FRAME_ULONG( minMemType42 ), FT_FRAME_ULONG( maxMemType42 ), FT_FRAME_ULONG( minMemType1 ), FT_FRAME_ULONG( maxMemType1 ), FT_FRAME_END }; error = face->goto_table( face, TTAG_post, stream, 0 ); if ( error ) return error; if ( FT_STREAM_READ_FIELDS( post_fields, post ) ) return error; if ( post->FormatType != 0x00030000L && post->FormatType != 0x00025000L && post->FormatType != 0x00020000L && post->FormatType != 0x00010000L ) return FT_THROW( Invalid_Post_Table_Format ); /* we don't load the glyph names, we do that in another */ /* module (ttpost). */ FT_TRACE3(( "FormatType: 0x%lx\n", post->FormatType )); FT_TRACE3(( "isFixedPitch: %s\n", post->isFixedPitch ? " yes" : " no" )); return FT_Err_Ok; } /************************************************************************** * * @Function: * tt_face_load_pclt * * @Description: * Loads the PCL 5 Table. * * @Input: * face :: * A handle to the target face object. * * stream :: * A handle to the input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_pclt( TT_Face face, FT_Stream stream ) { static const FT_Frame_Field pclt_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_PCLT FT_FRAME_START( 54 ), FT_FRAME_ULONG ( Version ), FT_FRAME_ULONG ( FontNumber ), FT_FRAME_USHORT( Pitch ), FT_FRAME_USHORT( xHeight ), FT_FRAME_USHORT( Style ), FT_FRAME_USHORT( TypeFamily ), FT_FRAME_USHORT( CapHeight ), FT_FRAME_USHORT( SymbolSet ), FT_FRAME_BYTES ( TypeFace, 16 ), FT_FRAME_BYTES ( CharacterComplement, 8 ), FT_FRAME_BYTES ( FileName, 6 ), FT_FRAME_CHAR ( StrokeWeight ), FT_FRAME_CHAR ( WidthType ), FT_FRAME_BYTE ( SerifStyle ), FT_FRAME_BYTE ( Reserved ), FT_FRAME_END }; FT_Error error; TT_PCLT* pclt = &face->pclt; /* optional table */ error = face->goto_table( face, TTAG_PCLT, stream, 0 ); if ( error ) goto Exit; if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) ) goto Exit; Exit: return error; } /************************************************************************** * * @Function: * tt_face_load_gasp * * @Description: * Loads the `gasp' table into a face object. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_gasp( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_UShort j, num_ranges; TT_GaspRange gasp_ranges = NULL; /* the gasp table is optional */ error = face->goto_table( face, TTAG_gasp, stream, 0 ); if ( error ) goto Exit; if ( FT_FRAME_ENTER( 4L ) ) goto Exit; face->gasp.version = FT_GET_USHORT(); num_ranges = FT_GET_USHORT(); FT_FRAME_EXIT(); /* only support versions 0 and 1 of the table */ if ( face->gasp.version >= 2 ) { face->gasp.numRanges = 0; error = FT_THROW( Invalid_Table ); goto Exit; } FT_TRACE3(( "numRanges: %hu\n", num_ranges )); if ( FT_QNEW_ARRAY( gasp_ranges, num_ranges ) || FT_FRAME_ENTER( num_ranges * 4L ) ) goto Exit; for ( j = 0; j < num_ranges; j++ ) { gasp_ranges[j].maxPPEM = FT_GET_USHORT(); gasp_ranges[j].gaspFlag = FT_GET_USHORT(); FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n", j, gasp_ranges[j].maxPPEM, gasp_ranges[j].gaspFlag )); } face->gasp.gaspRanges = gasp_ranges; gasp_ranges = NULL; face->gasp.numRanges = num_ranges; FT_FRAME_EXIT(); Exit: FT_FREE( gasp_ranges ); return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttload.c
C++
gpl-3.0
40,454
/**************************************************************************** * * ttload.h * * Load the basic TrueType tables, i.e., tables that can be either in * TTF or OTF fonts (specification). * * Copyright (C) 1996-2022 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 TTLOAD_H_ #define TTLOAD_H_ #include <freetype/internal/ftstream.h> #include <freetype/internal/tttypes.h> FT_BEGIN_HEADER FT_LOCAL( TT_Table ) tt_face_lookup_table( TT_Face face, FT_ULong tag ); FT_LOCAL( FT_Error ) tt_face_goto_table( TT_Face face, FT_ULong tag, FT_Stream stream, FT_ULong* length ); FT_LOCAL( FT_Error ) tt_face_load_font_dir( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_any( TT_Face face, FT_ULong tag, FT_Long offset, FT_Byte* buffer, FT_ULong* length ); FT_LOCAL( FT_Error ) tt_face_load_head( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_cmap( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_maxp( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_name( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_os2( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_post( TT_Face face, FT_Stream stream ); FT_LOCAL( FT_Error ) tt_face_load_pclt( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_free_name( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_load_gasp( TT_Face face, FT_Stream stream ); #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_LOCAL( FT_Error ) tt_face_load_bhed( TT_Face face, FT_Stream stream ); #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ FT_END_HEADER #endif /* TTLOAD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttload.h
C++
gpl-3.0
2,507
/**************************************************************************** * * ttmtx.c * * Load the metrics tables common to TTF and OTF fonts (body). * * Copyright (C) 2006-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/internal/services/svmetric.h> #endif #include "ttmtx.h" #include "sferrors.h" /* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */ /* be identical except for the names of their fields, */ /* which are different. */ /* */ /* This ensures that `tt_face_load_hmtx' is able to read */ /* both the horizontal and vertical headers. */ /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttmtx /************************************************************************** * * @Function: * tt_face_load_hmtx * * @Description: * Load the `hmtx' or `vmtx' table into a face object. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * vertical :: * A boolean flag. If set, load `vmtx'. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_hmtx( TT_Face face, FT_Stream stream, FT_Bool vertical ) { FT_Error error; FT_ULong tag, table_size; FT_ULong* ptable_offset; FT_ULong* ptable_size; if ( vertical ) { tag = TTAG_vmtx; ptable_offset = &face->vert_metrics_offset; ptable_size = &face->vert_metrics_size; } else { tag = TTAG_hmtx; ptable_offset = &face->horz_metrics_offset; ptable_size = &face->horz_metrics_size; } error = face->goto_table( face, tag, stream, &table_size ); if ( error ) goto Fail; *ptable_size = table_size; *ptable_offset = FT_STREAM_POS(); Fail: return error; } /************************************************************************** * * @Function: * tt_face_load_hhea * * @Description: * Load the `hhea' or 'vhea' table into a face object. * * @Input: * face :: * A handle to the target face object. * * stream :: * The input stream. * * vertical :: * A boolean flag. If set, load `vhea'. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_load_hhea( TT_Face face, FT_Stream stream, FT_Bool vertical ) { FT_Error error; TT_HoriHeader* header; static const FT_Frame_Field metrics_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_HoriHeader FT_FRAME_START( 36 ), FT_FRAME_ULONG ( Version ), FT_FRAME_SHORT ( Ascender ), FT_FRAME_SHORT ( Descender ), FT_FRAME_SHORT ( Line_Gap ), FT_FRAME_USHORT( advance_Width_Max ), FT_FRAME_SHORT ( min_Left_Side_Bearing ), FT_FRAME_SHORT ( min_Right_Side_Bearing ), FT_FRAME_SHORT ( xMax_Extent ), FT_FRAME_SHORT ( caret_Slope_Rise ), FT_FRAME_SHORT ( caret_Slope_Run ), FT_FRAME_SHORT ( caret_Offset ), FT_FRAME_SHORT ( Reserved[0] ), FT_FRAME_SHORT ( Reserved[1] ), FT_FRAME_SHORT ( Reserved[2] ), FT_FRAME_SHORT ( Reserved[3] ), FT_FRAME_SHORT ( metric_Data_Format ), FT_FRAME_USHORT( number_Of_HMetrics ), FT_FRAME_END }; if ( vertical ) { void *v = &face->vertical; error = face->goto_table( face, TTAG_vhea, stream, 0 ); if ( error ) goto Fail; header = (TT_HoriHeader*)v; } else { error = face->goto_table( face, TTAG_hhea, stream, 0 ); if ( error ) goto Fail; header = &face->horizontal; } if ( FT_STREAM_READ_FIELDS( metrics_header_fields, header ) ) goto Fail; FT_TRACE3(( "Ascender: %5d\n", header->Ascender )); FT_TRACE3(( "Descender: %5d\n", header->Descender )); FT_TRACE3(( "number_Of_Metrics: %5u\n", header->number_Of_HMetrics )); header->long_metrics = NULL; header->short_metrics = NULL; Fail: return error; } /************************************************************************** * * @Function: * tt_face_get_metrics * * @Description: * Return the horizontal or vertical metrics in font units for a * given glyph. The values are the left side bearing (top side * bearing for vertical metrics) and advance width (advance height * for vertical metrics). * * @Input: * face :: * A pointer to the TrueType face structure. * * vertical :: * If set to TRUE, get vertical metrics. * * gindex :: * The glyph index. * * @Output: * abearing :: * The bearing, either left side or top side. * * aadvance :: * The advance width or advance height, depending on * the `vertical' flag. */ FT_LOCAL_DEF( void ) tt_face_get_metrics( TT_Face face, FT_Bool vertical, FT_UInt gindex, FT_Short *abearing, FT_UShort *aadvance ) { FT_Error error; FT_Stream stream = face->root.stream; TT_HoriHeader* header; FT_ULong table_pos, table_size, table_end; FT_UShort k; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_Service_MetricsVariations var = (FT_Service_MetricsVariations)face->var; #endif if ( vertical ) { void* v = &face->vertical; header = (TT_HoriHeader*)v; table_pos = face->vert_metrics_offset; table_size = face->vert_metrics_size; } else { header = &face->horizontal; table_pos = face->horz_metrics_offset; table_size = face->horz_metrics_size; } table_end = table_pos + table_size; k = header->number_Of_HMetrics; if ( k > 0 ) { if ( gindex < (FT_UInt)k ) { table_pos += 4 * gindex; if ( table_pos + 4 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) || FT_READ_SHORT( *abearing ) ) goto NoData; } else { table_pos += 4 * ( k - 1 ); if ( table_pos + 2 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) ) goto NoData; table_pos += 4 + 2 * ( gindex - k ); if ( table_pos + 2 > table_end ) *abearing = 0; else { if ( FT_STREAM_SEEK( table_pos ) ) *abearing = 0; else (void)FT_READ_SHORT( *abearing ); } } } else { NoData: *abearing = 0; *aadvance = 0; } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT if ( var ) { FT_Face f = FT_FACE( face ); FT_Int a = (FT_Int)*aadvance; FT_Int b = (FT_Int)*abearing; if ( vertical ) { if ( var->vadvance_adjust ) var->vadvance_adjust( f, gindex, &a ); if ( var->tsb_adjust ) var->tsb_adjust( f, gindex, &b ); } else { if ( var->hadvance_adjust ) var->hadvance_adjust( f, gindex, &a ); if ( var->lsb_adjust ) var->lsb_adjust( f, gindex, &b ); } *aadvance = (FT_UShort)a; *abearing = (FT_Short)b; } #endif } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttmtx.c
C++
gpl-3.0
8,534
/**************************************************************************** * * ttmtx.h * * Load the metrics tables common to TTF and OTF fonts (specification). * * Copyright (C) 2006-2022 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 TTMTX_H_ #define TTMTX_H_ #include <freetype/internal/ftstream.h> #include <freetype/internal/tttypes.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_hhea( TT_Face face, FT_Stream stream, FT_Bool vertical ); FT_LOCAL( FT_Error ) tt_face_load_hmtx( TT_Face face, FT_Stream stream, FT_Bool vertical ); FT_LOCAL( void ) tt_face_get_metrics( TT_Face face, FT_Bool vertical, FT_UInt gindex, FT_Short* abearing, FT_UShort* aadvance ); FT_END_HEADER #endif /* TTMTX_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttmtx.h
C++
gpl-3.0
1,289
/**************************************************************************** * * ttpost.c * * PostScript name table processing for TrueType and OpenType fonts * (body). * * Copyright (C) 1996-2022 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. * */ /************************************************************************** * * The post table is not completely loaded by the core engine. This * file loads the missing PS glyph names and implements an API to access * them. * */ #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #include "ttpost.h" #include "sferrors.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttpost /* If this configuration macro is defined, we rely on the `psnames' */ /* module to grab the glyph names. */ #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES #include <freetype/internal/services/svpscmap.h> #define MAC_NAME( x ) (FT_String*)psnames->macintosh_name( (FT_UInt)(x) ) #else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ /* Otherwise, we ignore the `psnames' module, and provide our own */ /* table of Mac names. Thus, it is possible to build a version of */ /* FreeType without the Type 1 driver & psnames module. */ #define MAC_NAME( x ) (FT_String*)tt_post_default_names[x] /* the 258 default Mac PS glyph names; see file `tools/glnames.py' */ static const FT_String* const tt_post_default_names[258] = { /* 0 */ ".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", /* 10 */ "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", /* 20 */ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", /* 30 */ "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", /* 40 */ "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", /* 50 */ "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", /* 60 */ "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", /* 70 */ "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", /* 80 */ "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", /* 90 */ "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring", /* 100 */ "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", /* 110 */ "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", /* 120 */ "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", /* 130 */ "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", /* 140 */ "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", /* 150 */ "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", /* 160 */ "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", /* 170 */ "guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", /* 180 */ "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", /* 190 */ "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", /* 200 */ "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", /* 210 */ "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", /* 220 */ "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron", /* 230 */ "Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn", "thorn", "minus", /* 240 */ "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve", /* 250 */ "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat", }; #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ static FT_Error load_format_20( TT_Face face, FT_Stream stream, FT_ULong post_len ) { FT_Memory memory = stream->memory; FT_Error error; FT_Int num_glyphs; FT_UShort num_names; FT_UShort* glyph_indices = NULL; FT_Char** name_strings = NULL; FT_Byte* strings = NULL; if ( FT_READ_USHORT( num_glyphs ) ) goto Exit; /* UNDOCUMENTED! The number of glyphs in this table can be smaller */ /* than the value in the maxp table (cf. cyberbit.ttf). */ /* There already exist fonts which have more than 32768 glyph names */ /* in this table, so the test for this threshold has been dropped. */ if ( num_glyphs > face->max_profile.numGlyphs || (FT_ULong)num_glyphs * 2UL > post_len - 2 ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* load the indices */ { FT_Int n; if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) || FT_FRAME_ENTER( num_glyphs * 2L ) ) goto Fail; for ( n = 0; n < num_glyphs; n++ ) glyph_indices[n] = FT_GET_USHORT(); FT_FRAME_EXIT(); } /* compute number of names stored in table */ { FT_Int n; num_names = 0; for ( n = 0; n < num_glyphs; n++ ) { FT_Int idx; idx = glyph_indices[n]; if ( idx >= 258 ) { idx -= 257; if ( idx > num_names ) num_names = (FT_UShort)idx; } } } /* now load the name strings */ if ( num_names ) { FT_UShort n; FT_ULong p; post_len -= (FT_ULong)num_glyphs * 2UL + 2; if ( FT_QALLOC( strings, post_len + 1 ) || FT_STREAM_READ( strings, post_len ) || FT_QNEW_ARRAY( name_strings, num_names ) ) goto Fail; /* convert from Pascal- to C-strings and set pointers */ for ( p = 0, n = 0; p < post_len && n < num_names; n++ ) { FT_UInt len = strings[p]; if ( len > 63U ) { error = FT_THROW( Invalid_File_Format ); goto Fail; } strings[p] = 0; name_strings[n] = (FT_Char*)strings + p + 1; p += len + 1; } strings[post_len] = 0; /* deal with missing or insufficient string data */ if ( n < num_names ) { if ( post_len == 0 ) { /* fake empty string */ if ( FT_QREALLOC( strings, 1, 2 ) ) goto Fail; post_len = 1; strings[post_len] = 0; } FT_ERROR(( "load_format_20:" " all entries in post table are already parsed," " using NULL names for gid %d - %d\n", n, num_names - 1 )); for ( ; n < num_names; n++ ) name_strings[n] = (FT_Char*)strings + post_len; } } /* all right, set table fields and exit successfully */ { TT_Post_20 table = &face->postscript_names.names.format_20; table->num_glyphs = (FT_UShort)num_glyphs; table->num_names = (FT_UShort)num_names; table->glyph_indices = glyph_indices; table->glyph_names = name_strings; } return FT_Err_Ok; Fail: FT_FREE( name_strings ); FT_FREE( strings ); FT_FREE( glyph_indices ); Exit: return error; } static FT_Error load_format_25( TT_Face face, FT_Stream stream, FT_ULong post_len ) { FT_Memory memory = stream->memory; FT_Error error; FT_Int num_glyphs; FT_Char* offset_table = NULL; FT_UNUSED( post_len ); if ( FT_READ_USHORT( num_glyphs ) ) goto Exit; /* check the number of glyphs */ if ( num_glyphs > face->max_profile.numGlyphs || num_glyphs > 258 || num_glyphs < 1 ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( FT_QNEW_ARRAY( offset_table, num_glyphs ) || FT_STREAM_READ( offset_table, num_glyphs ) ) goto Fail; /* now check the offset table */ { FT_Int n; for ( n = 0; n < num_glyphs; n++ ) { FT_Long idx = (FT_Long)n + offset_table[n]; if ( idx < 0 || idx > num_glyphs ) { error = FT_THROW( Invalid_File_Format ); goto Fail; } } } /* OK, set table fields and exit successfully */ { TT_Post_25 table = &face->postscript_names.names.format_25; table->num_glyphs = (FT_UShort)num_glyphs; table->offsets = offset_table; } return FT_Err_Ok; Fail: FT_FREE( offset_table ); Exit: return error; } static FT_Error load_post_names( TT_Face face ) { FT_Stream stream; FT_Error error; FT_Fixed format; FT_ULong post_len; /* get a stream for the face's resource */ stream = face->root.stream; /* seek to the beginning of the PS names table */ error = face->goto_table( face, TTAG_post, stream, &post_len ); if ( error ) goto Exit; format = face->postscript.FormatType; /* go to beginning of subtable */ if ( FT_STREAM_SKIP( 32 ) ) goto Exit; /* now read postscript table */ if ( format == 0x00020000L && post_len >= 34 ) error = load_format_20( face, stream, post_len - 32 ); else if ( format == 0x00025000L && post_len >= 34 ) error = load_format_25( face, stream, post_len - 32 ); else error = FT_THROW( Invalid_File_Format ); face->postscript_names.loaded = 1; Exit: return error; } FT_LOCAL_DEF( void ) tt_face_free_ps_names( TT_Face face ) { FT_Memory memory = face->root.memory; TT_Post_Names names = &face->postscript_names; FT_Fixed format; if ( names->loaded ) { format = face->postscript.FormatType; if ( format == 0x00020000L ) { TT_Post_20 table = &names->names.format_20; FT_FREE( table->glyph_indices ); table->num_glyphs = 0; if ( table->num_names ) { table->glyph_names[0]--; FT_FREE( table->glyph_names[0] ); FT_FREE( table->glyph_names ); table->num_names = 0; } } else if ( format == 0x00025000L ) { TT_Post_25 table = &names->names.format_25; FT_FREE( table->offsets ); table->num_glyphs = 0; } } names->loaded = 0; } /************************************************************************** * * @Function: * tt_face_get_ps_name * * @Description: * Get the PostScript glyph name of a glyph. * * @Input: * face :: * A handle to the parent face. * * idx :: * The glyph index. * * @InOut: * PSname :: * The address of a string pointer. Undefined in case of * error, otherwise it is a pointer to the glyph name. * * You must not modify the returned string! * * @Output: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) tt_face_get_ps_name( TT_Face face, FT_UInt idx, FT_String** PSname ) { FT_Error error; TT_Post_Names names; FT_Fixed format; #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES FT_Service_PsCMaps psnames; #endif if ( !face ) return FT_THROW( Invalid_Face_Handle ); if ( idx >= (FT_UInt)face->max_profile.numGlyphs ) return FT_THROW( Invalid_Glyph_Index ); #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES psnames = (FT_Service_PsCMaps)face->psnames; if ( !psnames ) return FT_THROW( Unimplemented_Feature ); #endif names = &face->postscript_names; /* `.notdef' by default */ *PSname = MAC_NAME( 0 ); format = face->postscript.FormatType; if ( format == 0x00010000L ) { if ( idx < 258 ) /* paranoid checking */ *PSname = MAC_NAME( idx ); } else if ( format == 0x00020000L ) { TT_Post_20 table = &names->names.format_20; if ( !names->loaded ) { error = load_post_names( face ); if ( error ) goto End; } if ( idx < (FT_UInt)table->num_glyphs ) { FT_UShort name_index = table->glyph_indices[idx]; if ( name_index < 258 ) *PSname = MAC_NAME( name_index ); else *PSname = (FT_String*)table->glyph_names[name_index - 258]; } } else if ( format == 0x00025000L ) { TT_Post_25 table = &names->names.format_25; if ( !names->loaded ) { error = load_post_names( face ); if ( error ) goto End; } if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */ *PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] ); } /* nothing to do for format == 0x00030000L */ End: return FT_Err_Ok; } #else /* !TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ /* ANSI C doesn't like empty source files */ typedef int _tt_post_dummy; #endif /* !TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttpost.c
C++
gpl-3.0
14,704
/**************************************************************************** * * ttpost.h * * PostScript name table processing for TrueType and OpenType fonts * (specification). * * Copyright (C) 1996-2022 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 TTPOST_H_ #define TTPOST_H_ #include <ft2build.h> #include FT_CONFIG_CONFIG_H #include <freetype/internal/tttypes.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_get_ps_name( TT_Face face, FT_UInt idx, FT_String** PSname ); FT_LOCAL( void ) tt_face_free_ps_names( TT_Face face ); FT_END_HEADER #endif /* TTPOST_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttpost.h
C++
gpl-3.0
1,002
/**************************************************************************** * * ttsbit.c * * TrueType and OpenType embedded bitmap support (body). * * Copyright (C) 2005-2022 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Copyright 2013 by Google, Inc. * Google Author(s): Behdad Esfahbod. * * 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/tttags.h> #include <freetype/ftbitmap.h> #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS #include "ttsbit.h" #include "sferrors.h" #include "ttmtx.h" #include "pngshim.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttsbit FT_LOCAL_DEF( FT_Error ) tt_face_load_sbit( TT_Face face, FT_Stream stream ) { FT_Error error; FT_ULong table_size; FT_ULong table_start; face->sbit_table = NULL; face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; error = face->goto_table( face, TTAG_CBLC, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_CBLC; else { error = face->goto_table( face, TTAG_EBLC, stream, &table_size ); if ( error ) error = face->goto_table( face, TTAG_bloc, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_EBLC; } if ( error ) { error = face->goto_table( face, TTAG_sbix, stream, &table_size ); if ( !error ) face->sbit_table_type = TT_SBIT_TABLE_TYPE_SBIX; } if ( error ) goto Exit; if ( table_size < 8 ) { FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } table_start = FT_STREAM_POS(); switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* p; FT_Fixed version; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) ) goto Exit; face->sbit_table_size = table_size; p = face->sbit_table; version = FT_NEXT_LONG( p ); num_strikes = FT_NEXT_ULONG( p ); /* there's at least one font (FZShuSong-Z01, version 3) */ /* that uses the wrong byte order for the `version' field */ if ( ( (FT_ULong)version & 0xFFFF0000UL ) != 0x00020000UL && ( (FT_ULong)version & 0x0000FFFFUL ) != 0x00000200UL && ( (FT_ULong)version & 0xFFFF0000UL ) != 0x00030000UL && ( (FT_ULong)version & 0x0000FFFFUL ) != 0x00000300UL ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } if ( num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 48UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 48 ); face->sbit_num_strikes = count; } break; case TT_SBIT_TABLE_TYPE_SBIX: { FT_UShort version; FT_UShort flags; FT_ULong num_strikes; FT_UInt count; if ( FT_FRAME_ENTER( 8 ) ) goto Exit; version = FT_GET_USHORT(); flags = FT_GET_USHORT(); num_strikes = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( version < 1 ) { error = FT_THROW( Unknown_File_Format ); goto Exit; } /* Bit 0 must always be `1'. */ /* Bit 1 controls the overlay of bitmaps with outlines. */ /* All other bits should be zero. */ if ( !( flags == 1 || flags == 3 ) || num_strikes >= 0x10000UL ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( flags == 3 ) face->root.face_flags |= FT_FACE_FLAG_SBIX_OVERLAY; /* * Count the number of strikes available in the table. We are a bit * paranoid there and don't trust the data. */ count = (FT_UInt)num_strikes; if ( 8 + 4UL * count > table_size ) count = (FT_UInt)( ( table_size - 8 ) / 4 ); if ( FT_STREAM_SEEK( FT_STREAM_POS() - 8 ) ) goto Exit; face->sbit_table_size = 8 + count * 4; if ( FT_FRAME_EXTRACT( face->sbit_table_size, face->sbit_table ) ) goto Exit; face->sbit_num_strikes = count; } break; default: /* we ignore unknown table formats */ error = FT_THROW( Unknown_File_Format ); break; } if ( !error ) FT_TRACE3(( "tt_face_load_sbit_strikes: found %u strikes\n", face->sbit_num_strikes )); face->ebdt_start = 0; face->ebdt_size = 0; if ( face->sbit_table_type == TT_SBIT_TABLE_TYPE_SBIX ) { /* the `sbix' table is self-contained; */ /* it has no associated data table */ face->ebdt_start = table_start; face->ebdt_size = table_size; } else if ( face->sbit_table_type != TT_SBIT_TABLE_TYPE_NONE ) { FT_ULong ebdt_size; error = face->goto_table( face, TTAG_CBDT, stream, &ebdt_size ); if ( error ) error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size ); if ( error ) error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size ); if ( !error ) { face->ebdt_start = FT_STREAM_POS(); face->ebdt_size = ebdt_size; } } if ( !face->ebdt_size ) { FT_TRACE2(( "tt_face_load_sbit_strikes:" " no embedded bitmap data table found;\n" )); FT_TRACE2(( " " " resetting number of strikes to zero\n" )); face->sbit_num_strikes = 0; } return FT_Err_Ok; Exit: if ( error ) { if ( face->sbit_table ) FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; } return error; } FT_LOCAL_DEF( void ) tt_face_free_sbit( TT_Face face ) { FT_Stream stream = face->root.stream; FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE; face->sbit_num_strikes = 0; } FT_LOCAL_DEF( FT_Error ) tt_face_set_sbit_strike( TT_Face face, FT_Size_Request req, FT_ULong* astrike_index ) { return FT_Match_Size( (FT_Face)face, req, 0, astrike_index ); } FT_LOCAL_DEF( FT_Error ) tt_face_load_strike_metrics( TT_Face face, FT_ULong strike_index, FT_Size_Metrics* metrics ) { /* we have to test for the existence of `sbit_strike_map' */ /* because the function gets also used at the very beginning */ /* to construct `sbit_strike_map' itself */ if ( face->sbit_strike_map ) { if ( strike_index >= (FT_ULong)face->root.num_fixed_sizes ) return FT_THROW( Invalid_Argument ); /* map to real index */ strike_index = face->sbit_strike_map[strike_index]; } else { if ( strike_index >= (FT_ULong)face->sbit_num_strikes ) return FT_THROW( Invalid_Argument ); } switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { FT_Byte* strike; FT_Char max_before_bl; FT_Char min_after_bl; strike = face->sbit_table + 8 + strike_index * 48; metrics->x_ppem = (FT_UShort)strike[44]; metrics->y_ppem = (FT_UShort)strike[45]; metrics->ascender = (FT_Char)strike[16] * 64; /* hori.ascender */ metrics->descender = (FT_Char)strike[17] * 64; /* hori.descender */ /* Due to fuzzy wording in the EBLC documentation, we find both */ /* positive and negative values for `descender'. Additionally, */ /* many fonts have both `ascender' and `descender' set to zero */ /* (which is definitely wrong). MS Windows simply ignores all */ /* those values... For these reasons we apply some heuristics */ /* to get a reasonable, non-zero value for the height. */ max_before_bl = (FT_Char)strike[24]; min_after_bl = (FT_Char)strike[25]; if ( metrics->descender > 0 ) { /* compare sign of descender with `min_after_bl' */ if ( min_after_bl < 0 ) metrics->descender = -metrics->descender; } else if ( metrics->descender == 0 ) { if ( metrics->ascender == 0 ) { FT_TRACE2(( "tt_face_load_strike_metrics:" " sanitizing invalid ascender and descender\n" )); FT_TRACE2(( " " " values for strike %ld (%dppem, %dppem)\n", strike_index, metrics->x_ppem, metrics->y_ppem )); /* sanitize buggy ascender and descender values */ if ( max_before_bl || min_after_bl ) { metrics->ascender = max_before_bl * 64; metrics->descender = min_after_bl * 64; } else { metrics->ascender = metrics->y_ppem * 64; metrics->descender = 0; } } } #if 0 else ; /* if we have a negative descender, simply use it */ #endif metrics->height = metrics->ascender - metrics->descender; if ( metrics->height == 0 ) { FT_TRACE2(( "tt_face_load_strike_metrics:" " sanitizing invalid height value\n" )); FT_TRACE2(( " " " for strike (%d, %d)\n", metrics->x_ppem, metrics->y_ppem )); metrics->height = metrics->y_ppem * 64; metrics->descender = metrics->ascender - metrics->height; } /* Is this correct? */ metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */ strike[18] + /* max_width */ (FT_Char)strike[23] /* min_advance_SB */ ) * 64; /* set the scale values (in 16.16 units) so advances */ /* from the hmtx and vmtx table are scaled correctly */ metrics->x_scale = FT_MulDiv( metrics->x_ppem, 64 * 0x10000, face->header.Units_Per_EM ); metrics->y_scale = FT_MulDiv( metrics->y_ppem, 64 * 0x10000, face->header.Units_Per_EM ); return FT_Err_Ok; } case TT_SBIT_TABLE_TYPE_SBIX: { FT_Stream stream = face->root.stream; FT_UInt offset; FT_UShort upem, ppem, resolution; TT_HoriHeader *hori; FT_Pos ppem_; /* to reduce casts */ FT_Error error; FT_Byte* p; p = face->sbit_table + 8 + 4 * strike_index; offset = FT_NEXT_ULONG( p ); if ( offset + 4 > face->ebdt_size ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( face->ebdt_start + offset ) || FT_FRAME_ENTER( 4 ) ) return error; ppem = FT_GET_USHORT(); resolution = FT_GET_USHORT(); FT_UNUSED( resolution ); /* What to do with this? */ FT_FRAME_EXIT(); upem = face->header.Units_Per_EM; hori = &face->horizontal; metrics->x_ppem = ppem; metrics->y_ppem = ppem; ppem_ = (FT_Pos)ppem; metrics->ascender = FT_MulDiv( hori->Ascender, ppem_ * 64, upem ); metrics->descender = FT_MulDiv( hori->Descender, ppem_ * 64, upem ); metrics->height = FT_MulDiv( hori->Ascender - hori->Descender + hori->Line_Gap, ppem_ * 64, upem ); metrics->max_advance = FT_MulDiv( hori->advance_Width_Max, ppem_ * 64, upem ); /* set the scale values (in 16.16 units) so advances */ /* from the hmtx and vmtx table are scaled correctly */ metrics->x_scale = FT_MulDiv( metrics->x_ppem, 64 * 0x10000, face->header.Units_Per_EM ); metrics->y_scale = FT_MulDiv( metrics->y_ppem, 64 * 0x10000, face->header.Units_Per_EM ); return error; } default: return FT_THROW( Unknown_File_Format ); } } typedef struct TT_SBitDecoderRec_ { TT_Face face; FT_Stream stream; FT_Bitmap* bitmap; TT_SBit_Metrics metrics; FT_Bool metrics_loaded; FT_Bool bitmap_allocated; FT_Byte bit_depth; FT_ULong ebdt_start; FT_ULong ebdt_size; FT_ULong strike_index_array; FT_ULong strike_index_count; FT_Byte* eblc_base; FT_Byte* eblc_limit; } TT_SBitDecoderRec, *TT_SBitDecoder; static FT_Error tt_sbit_decoder_init( TT_SBitDecoder decoder, TT_Face face, FT_ULong strike_index, TT_SBit_MetricsRec* metrics ) { FT_Error error = FT_ERR( Table_Missing ); FT_Stream stream = face->root.stream; strike_index = face->sbit_strike_map[strike_index]; if ( !face->ebdt_size ) goto Exit; if ( FT_STREAM_SEEK( face->ebdt_start ) ) goto Exit; decoder->face = face; decoder->stream = stream; decoder->bitmap = &face->root.glyph->bitmap; decoder->metrics = metrics; decoder->metrics_loaded = 0; decoder->bitmap_allocated = 0; decoder->ebdt_start = face->ebdt_start; decoder->ebdt_size = face->ebdt_size; decoder->eblc_base = face->sbit_table; decoder->eblc_limit = face->sbit_table + face->sbit_table_size; /* now find the strike corresponding to the index */ { FT_Byte* p; if ( 8 + 48 * strike_index + 3 * 4 + 34 + 1 > face->sbit_table_size ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } p = decoder->eblc_base + 8 + 48 * strike_index; decoder->strike_index_array = FT_NEXT_ULONG( p ); p += 4; decoder->strike_index_count = FT_NEXT_ULONG( p ); p += 34; decoder->bit_depth = *p; /* decoder->strike_index_array + */ /* 8 * decoder->strike_index_count > face->sbit_table_size ? */ if ( decoder->strike_index_array > face->sbit_table_size || decoder->strike_index_count > ( face->sbit_table_size - decoder->strike_index_array ) / 8 ) error = FT_THROW( Invalid_File_Format ); } Exit: return error; } static void tt_sbit_decoder_done( TT_SBitDecoder decoder ) { FT_UNUSED( decoder ); } static FT_Error tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder, FT_Bool metrics_only ) { FT_Error error = FT_Err_Ok; FT_UInt width, height; FT_Bitmap* map = decoder->bitmap; FT_ULong size; if ( !decoder->metrics_loaded ) { error = FT_THROW( Invalid_Argument ); goto Exit; } width = decoder->metrics->width; height = decoder->metrics->height; map->width = width; map->rows = height; switch ( decoder->bit_depth ) { case 1: map->pixel_mode = FT_PIXEL_MODE_MONO; map->pitch = (int)( ( map->width + 7 ) >> 3 ); map->num_grays = 2; break; case 2: map->pixel_mode = FT_PIXEL_MODE_GRAY2; map->pitch = (int)( ( map->width + 3 ) >> 2 ); map->num_grays = 4; break; case 4: map->pixel_mode = FT_PIXEL_MODE_GRAY4; map->pitch = (int)( ( map->width + 1 ) >> 1 ); map->num_grays = 16; break; case 8: map->pixel_mode = FT_PIXEL_MODE_GRAY; map->pitch = (int)( map->width ); map->num_grays = 256; break; case 32: map->pixel_mode = FT_PIXEL_MODE_BGRA; map->pitch = (int)( map->width * 4 ); map->num_grays = 256; break; default: error = FT_THROW( Invalid_File_Format ); goto Exit; } size = map->rows * (FT_ULong)map->pitch; /* check that there is no empty image */ if ( size == 0 ) goto Exit; /* exit successfully! */ if ( metrics_only ) goto Exit; /* only metrics are requested */ error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size ); if ( error ) goto Exit; decoder->bitmap_allocated = 1; Exit: return error; } static FT_Error tt_sbit_decoder_load_metrics( TT_SBitDecoder decoder, FT_Byte* *pp, FT_Byte* limit, FT_Bool big ) { FT_Byte* p = *pp; TT_SBit_Metrics metrics = decoder->metrics; if ( p + 5 > limit ) goto Fail; metrics->height = p[0]; metrics->width = p[1]; metrics->horiBearingX = (FT_Char)p[2]; metrics->horiBearingY = (FT_Char)p[3]; metrics->horiAdvance = p[4]; p += 5; if ( big ) { if ( p + 3 > limit ) goto Fail; metrics->vertBearingX = (FT_Char)p[0]; metrics->vertBearingY = (FT_Char)p[1]; metrics->vertAdvance = p[2]; p += 3; } else { /* avoid uninitialized data in case there is no vertical info -- */ metrics->vertBearingX = 0; metrics->vertBearingY = 0; metrics->vertAdvance = 0; } decoder->metrics_loaded = 1; *pp = p; return FT_Err_Ok; Fail: FT_TRACE1(( "tt_sbit_decoder_load_metrics: broken table\n" )); return FT_THROW( Invalid_Argument ); } /* forward declaration */ static FT_Error tt_sbit_decoder_load_image( TT_SBitDecoder decoder, FT_UInt glyph_index, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count, FT_Bool metrics_only ); typedef FT_Error (*TT_SBitDecoder_LoadFunc)( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* plimit, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count ); static FT_Error tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count ) { FT_Error error = FT_Err_Ok; FT_Byte* line; FT_Int pitch, width, height, line_bits, h; FT_UInt bit_height, bit_width; FT_Bitmap* bitmap; FT_UNUSED( recurse_count ); /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; pitch = bitmap->pitch; line = bitmap->buffer; if ( !line ) goto Exit; width = decoder->metrics->width; height = decoder->metrics->height; line_bits = width * decoder->bit_depth; if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width || y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height ) { FT_TRACE1(( "tt_sbit_decoder_load_byte_aligned:" " invalid bitmap dimensions\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( p + ( ( line_bits + 7 ) >> 3 ) * height > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_byte_aligned: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* now do the blit */ line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; if ( x_pos == 0 ) /* the easy one */ { for ( h = height; h > 0; h--, line += pitch ) { FT_Byte* pwrite = line; FT_Int w; for ( w = line_bits; w >= 8; w -= 8 ) { pwrite[0] = (FT_Byte)( pwrite[0] | *p++ ); pwrite += 1; } if ( w > 0 ) pwrite[0] = (FT_Byte)( pwrite[0] | ( *p++ & ( 0xFF00U >> w ) ) ); } } else /* x_pos > 0 */ { for ( h = height; h > 0; h--, line += pitch ) { FT_Byte* pwrite = line; FT_Int w; FT_UInt wval = 0; for ( w = line_bits; w >= 8; w -= 8 ) { wval = (FT_UInt)( wval | *p++ ); pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); pwrite += 1; wval <<= 8; } if ( w > 0 ) wval = (FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) ); /* all bits read and there are `x_pos + w' bits to be written */ pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); if ( x_pos + w > 8 ) { pwrite++; wval <<= 8; pwrite[0] = (FT_Byte)( pwrite[0] | ( wval >> x_pos ) ); } } } Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_byte_aligned: loaded\n" )); return error; } /* * Load a bit-aligned bitmap (with pointer `p') into a line-aligned bitmap * (with pointer `pwrite'). In the example below, the width is 3 pixel, * and `x_pos' is 1 pixel. * * p p+1 * | | | * | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |... * | | | * +-------+ +-------+ +-------+ ... * . . . * . . . * v . . * +-------+ . . * | | . * | 7 6 5 4 3 2 1 0 | . * | | . * pwrite . . * . . * v . * +-------+ . * | | * | 7 6 5 4 3 2 1 0 | * | | * pwrite+1 . * . * v * +-------+ * | | * | 7 6 5 4 3 2 1 0 | * | | * pwrite+2 * */ static FT_Error tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count ) { FT_Error error = FT_Err_Ok; FT_Byte* line; FT_Int pitch, width, height, line_bits, h, nbits; FT_UInt bit_height, bit_width; FT_Bitmap* bitmap; FT_UShort rval; FT_UNUSED( recurse_count ); /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; pitch = bitmap->pitch; line = bitmap->buffer; width = decoder->metrics->width; height = decoder->metrics->height; line_bits = width * decoder->bit_depth; if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width || y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned:" " invalid bitmap dimensions\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( p + ( ( line_bits * height + 7 ) >> 3 ) > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( !line_bits || !height ) { /* nothing to do */ goto Exit; } /* now do the blit */ /* adjust `line' to point to the first byte of the bitmap */ line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; /* the higher byte of `rval' is used as a buffer */ rval = 0; nbits = 0; for ( h = height; h > 0; h--, line += pitch ) { FT_Byte* pwrite = line; FT_Int w = line_bits; /* handle initial byte (in target bitmap) specially if necessary */ if ( x_pos ) { w = ( line_bits < 8 - x_pos ) ? line_bits : 8 - x_pos; if ( h == height ) { rval = *p++; nbits = x_pos; } else if ( nbits < w ) { if ( p < limit ) rval |= *p++; nbits += 8 - w; } else { rval >>= 8; nbits -= w; } *pwrite++ |= ( ( rval >> nbits ) & 0xFF ) & ( ~( 0xFFU << w ) << ( 8 - w - x_pos ) ); rval <<= 8; w = line_bits - w; } /* handle medial bytes */ for ( ; w >= 8; w -= 8 ) { rval |= *p++; *pwrite++ |= ( rval >> nbits ) & 0xFF; rval <<= 8; } /* handle final byte if necessary */ if ( w > 0 ) { if ( nbits < w ) { if ( p < limit ) rval |= *p++; *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits += 8 - w; rval <<= 8; } else { *pwrite |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w ); nbits -= w; } } } Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_bit_aligned: loaded\n" )); return error; } static FT_Error tt_sbit_decoder_load_compound( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count ) { FT_Error error = FT_Err_Ok; FT_UInt num_components, nn; FT_Char horiBearingX = (FT_Char)decoder->metrics->horiBearingX; FT_Char horiBearingY = (FT_Char)decoder->metrics->horiBearingY; FT_Byte horiAdvance = (FT_Byte)decoder->metrics->horiAdvance; FT_Char vertBearingX = (FT_Char)decoder->metrics->vertBearingX; FT_Char vertBearingY = (FT_Char)decoder->metrics->vertBearingY; FT_Byte vertAdvance = (FT_Byte)decoder->metrics->vertAdvance; if ( p + 2 > limit ) goto Fail; num_components = FT_NEXT_USHORT( p ); if ( p + 4 * num_components > limit ) { FT_TRACE1(( "tt_sbit_decoder_load_compound: broken table\n" )); goto Fail; } FT_TRACE3(( "tt_sbit_decoder_load_compound: loading %d component%s\n", num_components, num_components == 1 ? "" : "s" )); for ( nn = 0; nn < num_components; nn++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); FT_Char dx = FT_NEXT_CHAR( p ); FT_Char dy = FT_NEXT_CHAR( p ); /* NB: a recursive call */ error = tt_sbit_decoder_load_image( decoder, gindex, x_pos + dx, y_pos + dy, recurse_count + 1, /* request full bitmap image */ FALSE ); if ( error ) break; } FT_TRACE3(( "tt_sbit_decoder_load_compound: done\n" )); decoder->metrics->horiBearingX = horiBearingX; decoder->metrics->horiBearingY = horiBearingY; decoder->metrics->horiAdvance = horiAdvance; decoder->metrics->vertBearingX = vertBearingX; decoder->metrics->vertBearingY = vertBearingY; decoder->metrics->vertAdvance = vertAdvance; decoder->metrics->width = (FT_Byte)decoder->bitmap->width; decoder->metrics->height = (FT_Byte)decoder->bitmap->rows; Exit: return error; Fail: error = FT_THROW( Invalid_File_Format ); goto Exit; } #ifdef FT_CONFIG_OPTION_USE_PNG static FT_Error tt_sbit_decoder_load_png( TT_SBitDecoder decoder, FT_Byte* p, FT_Byte* limit, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count ) { FT_Error error = FT_Err_Ok; FT_ULong png_len; FT_UNUSED( recurse_count ); if ( limit - p < 4 ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } png_len = FT_NEXT_ULONG( p ); if ( (FT_ULong)( limit - p ) < png_len ) { FT_TRACE1(( "tt_sbit_decoder_load_png: broken bitmap\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } error = Load_SBit_Png( decoder->face->root.glyph, x_pos, y_pos, decoder->bit_depth, decoder->metrics, decoder->stream->memory, p, png_len, FALSE, FALSE ); Exit: if ( !error ) FT_TRACE3(( "tt_sbit_decoder_load_png: loaded\n" )); return error; } #endif /* FT_CONFIG_OPTION_USE_PNG */ static FT_Error tt_sbit_decoder_load_bitmap( TT_SBitDecoder decoder, FT_UInt glyph_format, FT_ULong glyph_start, FT_ULong glyph_size, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count, FT_Bool metrics_only ) { FT_Error error; FT_Stream stream = decoder->stream; FT_Byte* p; FT_Byte* p_limit; FT_Byte* data; /* seek into the EBDT table now */ if ( !glyph_size || glyph_start + glyph_size > decoder->ebdt_size ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( FT_STREAM_SEEK( decoder->ebdt_start + glyph_start ) || FT_FRAME_EXTRACT( glyph_size, data ) ) goto Exit; p = data; p_limit = p + glyph_size; /* read the data, depending on the glyph format */ switch ( glyph_format ) { case 1: case 2: case 8: case 17: error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 0 ); break; case 6: case 7: case 9: case 18: error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ); break; default: error = FT_Err_Ok; } if ( error ) goto Fail; { TT_SBitDecoder_LoadFunc loader; switch ( glyph_format ) { case 1: case 6: loader = tt_sbit_decoder_load_byte_aligned; break; case 2: case 7: { /* Don't trust `glyph_format'. For example, Apple's main Korean */ /* system font, `AppleMyungJo.ttf' (version 7.0d2e6), uses glyph */ /* format 7, but the data is format 6. We check whether we have */ /* an excessive number of bytes in the image: If it is equal to */ /* the value for a byte-aligned glyph, use the other loading */ /* routine. */ /* */ /* Note that for some (width,height) combinations, where the */ /* width is not a multiple of 8, the sizes for bit- and */ /* byte-aligned data are equal, for example (7,7) or (15,6). We */ /* then prefer what `glyph_format' specifies. */ FT_UInt width = decoder->metrics->width; FT_UInt height = decoder->metrics->height; FT_UInt bit_size = ( width * height + 7 ) >> 3; FT_UInt byte_size = height * ( ( width + 7 ) >> 3 ); if ( bit_size < byte_size && byte_size == (FT_UInt)( p_limit - p ) ) loader = tt_sbit_decoder_load_byte_aligned; else loader = tt_sbit_decoder_load_bit_aligned; } break; case 5: loader = tt_sbit_decoder_load_bit_aligned; break; case 8: if ( p + 1 > p_limit ) goto Fail; p += 1; /* skip padding */ /* fall-through */ case 9: loader = tt_sbit_decoder_load_compound; break; case 17: /* small metrics, PNG image data */ case 18: /* big metrics, PNG image data */ case 19: /* metrics in EBLC, PNG image data */ #ifdef FT_CONFIG_OPTION_USE_PNG loader = tt_sbit_decoder_load_png; break; #else error = FT_THROW( Unimplemented_Feature ); goto Fail; #endif /* FT_CONFIG_OPTION_USE_PNG */ default: error = FT_THROW( Invalid_Table ); goto Fail; } if ( !decoder->bitmap_allocated ) { error = tt_sbit_decoder_alloc_bitmap( decoder, metrics_only ); if ( error ) goto Fail; } if ( metrics_only ) goto Fail; /* this is not an error */ error = loader( decoder, p, p_limit, x_pos, y_pos, recurse_count ); } Fail: FT_FRAME_RELEASE( data ); Exit: return error; } static FT_Error tt_sbit_decoder_load_image( TT_SBitDecoder decoder, FT_UInt glyph_index, FT_Int x_pos, FT_Int y_pos, FT_UInt recurse_count, FT_Bool metrics_only ) { FT_Byte* p = decoder->eblc_base + decoder->strike_index_array; FT_Byte* p_limit = decoder->eblc_limit; FT_ULong num_ranges = decoder->strike_index_count; FT_UInt start, end, index_format, image_format; FT_ULong image_start = 0, image_end = 0, image_offset; /* arbitrary recursion limit */ if ( recurse_count > 100 ) { FT_TRACE4(( "tt_sbit_decoder_load_image:" " recursion depth exceeded\n" )); goto Failure; } /* First, we find the correct strike range that applies to this */ /* glyph index. */ for ( ; num_ranges > 0; num_ranges-- ) { start = FT_NEXT_USHORT( p ); end = FT_NEXT_USHORT( p ); if ( glyph_index >= start && glyph_index <= end ) goto FoundRange; p += 4; /* ignore index offset */ } goto NoBitmap; FoundRange: image_offset = FT_NEXT_ULONG( p ); /* overflow check */ p = decoder->eblc_base + decoder->strike_index_array; if ( image_offset > (FT_ULong)( p_limit - p ) ) goto Failure; p += image_offset; if ( p + 8 > p_limit ) goto NoBitmap; /* now find the glyph's location and extend within the ebdt table */ index_format = FT_NEXT_USHORT( p ); image_format = FT_NEXT_USHORT( p ); image_offset = FT_NEXT_ULONG ( p ); switch ( index_format ) { case 1: /* 4-byte offsets relative to `image_offset' */ p += 4 * ( glyph_index - start ); if ( p + 8 > p_limit ) goto NoBitmap; image_start = FT_NEXT_ULONG( p ); image_end = FT_NEXT_ULONG( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 2: /* big metrics, constant image size */ { FT_ULong image_size; if ( p + 12 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; image_start = image_size * ( glyph_index - start ); image_end = image_start + image_size; } break; case 3: /* 2-byte offsets relative to 'image_offset' */ p += 2 * ( glyph_index - start ); if ( p + 4 > p_limit ) goto NoBitmap; image_start = FT_NEXT_USHORT( p ); image_end = FT_NEXT_USHORT( p ); if ( image_start == image_end ) /* missing glyph */ goto NoBitmap; break; case 4: /* sparse glyph array with (glyph,offset) pairs */ { FT_ULong mm, num_glyphs; if ( p + 4 > p_limit ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + ( num_glyphs + 1 ) * 4 */ if ( p + 4 > p_limit || num_glyphs > (FT_ULong)( ( ( p_limit - p ) >> 2 ) - 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) { image_start = FT_NEXT_USHORT( p ); p += 2; image_end = FT_PEEK_USHORT( p ); break; } p += 2; } if ( mm >= num_glyphs ) goto NoBitmap; } break; case 5: /* constant metrics with sparse glyph codes */ case 19: { FT_ULong image_size, mm, num_glyphs; if ( p + 16 > p_limit ) goto NoBitmap; image_size = FT_NEXT_ULONG( p ); if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) goto NoBitmap; num_glyphs = FT_NEXT_ULONG( p ); /* overflow check for p + 2 * num_glyphs */ if ( num_glyphs > (FT_ULong)( ( p_limit - p ) >> 1 ) ) goto NoBitmap; for ( mm = 0; mm < num_glyphs; mm++ ) { FT_UInt gindex = FT_NEXT_USHORT( p ); if ( gindex == glyph_index ) break; } if ( mm >= num_glyphs ) goto NoBitmap; image_start = image_size * mm; image_end = image_start + image_size; } break; default: goto NoBitmap; } if ( image_start > image_end ) goto NoBitmap; image_end -= image_start; image_start = image_offset + image_start; FT_TRACE3(( "tt_sbit_decoder_load_image:" " found sbit (format %d) for glyph index %d\n", image_format, glyph_index )); return tt_sbit_decoder_load_bitmap( decoder, image_format, image_start, image_end, x_pos, y_pos, recurse_count, metrics_only ); Failure: return FT_THROW( Invalid_Table ); NoBitmap: if ( recurse_count ) { FT_TRACE4(( "tt_sbit_decoder_load_image:" " missing subglyph sbit with glyph index %d\n", glyph_index )); return FT_THROW( Invalid_Composite ); } FT_TRACE4(( "tt_sbit_decoder_load_image:" " no sbit found for glyph index %d\n", glyph_index )); return FT_THROW( Missing_Bitmap ); } static FT_Error tt_face_load_sbix_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics, FT_Bool metrics_only ) { FT_UInt strike_offset, glyph_start, glyph_end; FT_Int originOffsetX, originOffsetY; FT_Tag graphicType; FT_Int recurse_depth = 0; FT_Error error; FT_Byte* p; FT_UNUSED( map ); #ifndef FT_CONFIG_OPTION_USE_PNG FT_UNUSED( metrics_only ); #endif strike_index = face->sbit_strike_map[strike_index]; metrics->width = 0; metrics->height = 0; p = face->sbit_table + 8 + 4 * strike_index; strike_offset = FT_NEXT_ULONG( p ); retry: if ( glyph_index > (FT_UInt)face->root.num_glyphs ) return FT_THROW( Invalid_Argument ); if ( strike_offset >= face->ebdt_size || face->ebdt_size - strike_offset < 4 + glyph_index * 4 + 8 ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( face->ebdt_start + strike_offset + 4 + glyph_index * 4 ) || FT_FRAME_ENTER( 8 ) ) return error; glyph_start = FT_GET_ULONG(); glyph_end = FT_GET_ULONG(); FT_FRAME_EXIT(); if ( glyph_start == glyph_end ) return FT_THROW( Missing_Bitmap ); if ( glyph_start > glyph_end || glyph_end - glyph_start < 8 || face->ebdt_size - strike_offset < glyph_end ) return FT_THROW( Invalid_File_Format ); if ( FT_STREAM_SEEK( face->ebdt_start + strike_offset + glyph_start ) || FT_FRAME_ENTER( glyph_end - glyph_start ) ) return error; originOffsetX = FT_GET_SHORT(); originOffsetY = FT_GET_SHORT(); graphicType = FT_GET_TAG4(); switch ( graphicType ) { case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): if ( recurse_depth < 4 ) { glyph_index = FT_GET_USHORT(); FT_FRAME_EXIT(); recurse_depth++; goto retry; } error = FT_THROW( Invalid_File_Format ); break; case FT_MAKE_TAG( 'p', 'n', 'g', ' ' ): #ifdef FT_CONFIG_OPTION_USE_PNG error = Load_SBit_Png( face->root.glyph, 0, 0, 32, metrics, stream->memory, stream->cursor, glyph_end - glyph_start - 8, TRUE, metrics_only ); #else error = FT_THROW( Unimplemented_Feature ); #endif break; case FT_MAKE_TAG( 'j', 'p', 'g', ' ' ): case FT_MAKE_TAG( 't', 'i', 'f', 'f' ): case FT_MAKE_TAG( 'r', 'g', 'b', 'l' ): /* used on iOS 7.1 */ error = FT_THROW( Unknown_File_Format ); break; default: error = FT_THROW( Unimplemented_Feature ); break; } FT_FRAME_EXIT(); if ( !error ) { FT_Short abearing; /* not used here */ FT_UShort aadvance; tt_face_get_metrics( face, FALSE, glyph_index, &abearing, &aadvance ); metrics->horiBearingX = (FT_Short)originOffsetX; metrics->vertBearingX = (FT_Short)originOffsetX; metrics->horiBearingY = (FT_Short)( originOffsetY + metrics->height ); metrics->vertBearingY = (FT_Short)originOffsetY; metrics->horiAdvance = (FT_UShort)( aadvance * face->root.size->metrics.x_ppem / face->header.Units_Per_EM ); if ( face->vertical_info ) tt_face_get_metrics( face, TRUE, glyph_index, &abearing, &aadvance ); else if ( face->os2.version != 0xFFFFU ) aadvance = (FT_UShort)FT_ABS( face->os2.sTypoAscender - face->os2.sTypoDescender ); else aadvance = (FT_UShort)FT_ABS( face->horizontal.Ascender - face->horizontal.Descender ); metrics->vertAdvance = (FT_UShort)( aadvance * face->root.size->metrics.x_ppem / face->header.Units_Per_EM ); } return error; } FT_LOCAL( FT_Error ) tt_face_load_sbit_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_UInt load_flags, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ) { FT_Error error = FT_Err_Ok; switch ( (FT_UInt)face->sbit_table_type ) { case TT_SBIT_TABLE_TYPE_EBLC: case TT_SBIT_TABLE_TYPE_CBLC: { TT_SBitDecoderRec decoder[1]; error = tt_sbit_decoder_init( decoder, face, strike_index, metrics ); if ( !error ) { error = tt_sbit_decoder_load_image( decoder, glyph_index, 0, 0, 0, ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) != 0 ); tt_sbit_decoder_done( decoder ); } } break; case TT_SBIT_TABLE_TYPE_SBIX: error = tt_face_load_sbix_image( face, strike_index, glyph_index, stream, map, metrics, ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) != 0 ); break; default: error = FT_THROW( Unknown_File_Format ); break; } /* Flatten color bitmaps if color was not requested. */ if ( !error && !( load_flags & FT_LOAD_COLOR ) && !( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) && map->pixel_mode == FT_PIXEL_MODE_BGRA ) { FT_Bitmap new_map; FT_Library library = face->root.glyph->library; FT_Bitmap_Init( &new_map ); /* Convert to 8bit grayscale. */ error = FT_Bitmap_Convert( library, map, &new_map, 1 ); if ( error ) FT_Bitmap_Done( library, &new_map ); else { map->pixel_mode = new_map.pixel_mode; map->pitch = new_map.pitch; map->num_grays = new_map.num_grays; ft_glyphslot_set_bitmap( face->root.glyph, new_map.buffer ); face->root.glyph->internal->flags |= FT_GLYPH_OWN_BITMAP; } } return error; } #else /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /* ANSI C doesn't like empty source files */ typedef int _tt_sbit_dummy; #endif /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttsbit.c
C++
gpl-3.0
48,780
/**************************************************************************** * * ttsbit.h * * TrueType and OpenType embedded bitmap support (specification). * * Copyright (C) 1996-2022 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 TTSBIT_H_ #define TTSBIT_H_ #include "ttload.h" FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_sbit( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_free_sbit( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_set_sbit_strike( TT_Face face, FT_Size_Request req, FT_ULong* astrike_index ); FT_LOCAL( FT_Error ) tt_face_load_strike_metrics( TT_Face face, FT_ULong strike_index, FT_Size_Metrics* metrics ); FT_LOCAL( FT_Error ) tt_face_load_sbit_image( TT_Face face, FT_ULong strike_index, FT_UInt glyph_index, FT_UInt load_flags, FT_Stream stream, FT_Bitmap *map, TT_SBit_MetricsRec *metrics ); FT_END_HEADER #endif /* TTSBIT_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttsbit.h
C++
gpl-3.0
1,672
/**************************************************************************** * * ttsvg.c * * OpenType SVG Color (specification). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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. * */ /************************************************************************** * * 'SVG' table specification: * * https://docs.microsoft.com/en-us/typography/opentype/spec/svg * */ #include <ft2build.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/tttags.h> #include <freetype/ftgzip.h> #include <freetype/otsvg.h> #ifdef FT_CONFIG_OPTION_SVG #include "ttsvg.h" /* NOTE: These table sizes are given by the specification. */ #define SVG_TABLE_HEADER_SIZE (10U) #define SVG_DOCUMENT_RECORD_SIZE (12U) #define SVG_DOCUMENT_LIST_MINIMUM_SIZE (2U + SVG_DOCUMENT_RECORD_SIZE) #define SVG_MINIMUM_SIZE (SVG_TABLE_HEADER_SIZE + \ SVG_DOCUMENT_LIST_MINIMUM_SIZE) typedef struct Svg_ { FT_UShort version; /* table version (starting at 0) */ FT_UShort num_entries; /* number of SVG document records */ FT_Byte* svg_doc_list; /* pointer to the start of SVG Document List */ void* table; /* memory that backs up SVG */ FT_ULong table_size; } Svg; /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, usued to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT ttsvg FT_LOCAL_DEF( FT_Error ) tt_face_load_svg( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = face->root.memory; FT_ULong table_size; FT_Byte* table = NULL; FT_Byte* p = NULL; Svg* svg = NULL; FT_ULong offsetToSVGDocumentList; error = face->goto_table( face, TTAG_SVG, stream, &table_size ); if ( error ) goto NoSVG; if ( table_size < SVG_MINIMUM_SIZE ) goto InvalidTable; if ( FT_FRAME_EXTRACT( table_size, table ) ) goto NoSVG; /* Allocate memory for the SVG object */ if ( FT_NEW( svg ) ) goto NoSVG; p = table; svg->version = FT_NEXT_USHORT( p ); offsetToSVGDocumentList = FT_NEXT_ULONG( p ); if ( offsetToSVGDocumentList < SVG_TABLE_HEADER_SIZE || offsetToSVGDocumentList > table_size - SVG_DOCUMENT_LIST_MINIMUM_SIZE ) goto InvalidTable; svg->svg_doc_list = (FT_Byte*)( table + offsetToSVGDocumentList ); p = svg->svg_doc_list; svg->num_entries = FT_NEXT_USHORT( p ); FT_TRACE3(( "version: %d\n", svg->version )); FT_TRACE3(( "number of entries: %d\n", svg->num_entries )); if ( offsetToSVGDocumentList + svg->num_entries * SVG_DOCUMENT_RECORD_SIZE > table_size ) goto InvalidTable; svg->table = table; svg->table_size = table_size; face->svg = svg; face->root.face_flags |= FT_FACE_FLAG_SVG; return FT_Err_Ok; InvalidTable: error = FT_THROW( Invalid_Table ); NoSVG: FT_FRAME_RELEASE( table ); FT_FREE( svg ); face->svg = NULL; return error; } FT_LOCAL_DEF( void ) tt_face_free_svg( TT_Face face ) { FT_Memory memory = face->root.memory; FT_Stream stream = face->root.stream; Svg* svg = (Svg*)face->svg; if ( svg ) { FT_FRAME_RELEASE( svg->table ); FT_FREE( svg ); } } typedef struct Svg_doc_ { FT_UShort start_glyph_id; FT_UShort end_glyph_id; FT_ULong offset; FT_ULong length; } Svg_doc; static Svg_doc extract_svg_doc( FT_Byte* stream ) { Svg_doc doc; doc.start_glyph_id = FT_NEXT_USHORT( stream ); doc.end_glyph_id = FT_NEXT_USHORT( stream ); doc.offset = FT_NEXT_ULONG( stream ); doc.length = FT_NEXT_ULONG( stream ); return doc; } static FT_Int compare_svg_doc( Svg_doc doc, FT_UInt glyph_index ) { if ( glyph_index < doc.start_glyph_id ) return -1; else if ( glyph_index > doc.end_glyph_id ) return 1; else return 0; } static FT_Error find_doc( FT_Byte* stream, FT_UShort num_entries, FT_UInt glyph_index, FT_ULong *doc_offset, FT_ULong *doc_length, FT_UShort *start_glyph, FT_UShort *end_glyph ) { FT_Error error; Svg_doc start_doc; Svg_doc mid_doc; Svg_doc end_doc; FT_Bool found = FALSE; FT_UInt i = 0; FT_UInt start_index = 0; FT_UInt end_index = num_entries - 1; FT_Int comp_res; /* search algorithm */ if ( num_entries == 0 ) { error = FT_THROW( Invalid_Table ); return error; } start_doc = extract_svg_doc( stream + start_index * 12 ); end_doc = extract_svg_doc( stream + end_index * 12 ); if ( ( compare_svg_doc( start_doc, glyph_index ) == -1 ) || ( compare_svg_doc( end_doc, glyph_index ) == 1 ) ) { error = FT_THROW( Invalid_Glyph_Index ); return error; } while ( start_index <= end_index ) { i = ( start_index + end_index ) / 2; mid_doc = extract_svg_doc( stream + i * 12 ); comp_res = compare_svg_doc( mid_doc, glyph_index ); if ( comp_res == 1 ) { start_index = i + 1; start_doc = extract_svg_doc( stream + start_index * 4 ); } else if ( comp_res == -1 ) { end_index = i - 1; end_doc = extract_svg_doc( stream + end_index * 4 ); } else { found = TRUE; break; } } /* search algorithm end */ if ( found != TRUE ) { FT_TRACE5(( "SVG glyph not found\n" )); error = FT_THROW( Invalid_Glyph_Index ); } else { *doc_offset = mid_doc.offset; *doc_length = mid_doc.length; *start_glyph = mid_doc.start_glyph_id; *end_glyph = mid_doc.end_glyph_id; error = FT_Err_Ok; } return error; } FT_LOCAL_DEF( FT_Error ) tt_face_load_svg_doc( FT_GlyphSlot glyph, FT_UInt glyph_index ) { FT_Byte* doc_list; /* pointer to the SVG doc list */ FT_UShort num_entries; /* total number of entries in doc list */ FT_ULong doc_offset; FT_ULong doc_length; FT_UShort start_glyph_id; FT_UShort end_glyph_id; FT_Error error = FT_Err_Ok; TT_Face face = (TT_Face)glyph->face; FT_Memory memory = face->root.memory; Svg* svg = (Svg*)face->svg; FT_SVG_Document svg_document = (FT_SVG_Document)glyph->other; FT_ASSERT( !( svg == NULL ) ); doc_list = svg->svg_doc_list; num_entries = FT_NEXT_USHORT( doc_list ); error = find_doc( doc_list, num_entries, glyph_index, &doc_offset, &doc_length, &start_glyph_id, &end_glyph_id ); if ( error != FT_Err_Ok ) goto Exit; doc_list = svg->svg_doc_list; /* reset, so we can use it again */ doc_list = (FT_Byte*)( doc_list + doc_offset ); if ( ( doc_list[0] == 0x1F ) && ( doc_list[1] == 0x8B ) && ( doc_list[2] == 0x08 ) ) { #ifdef FT_CONFIG_OPTION_USE_ZLIB FT_ULong uncomp_size; FT_Byte* uncomp_buffer = NULL; /* * Get the size of the original document. This helps in allotting the * buffer to accommodate the uncompressed version. The last 4 bytes * of the compressed document are equal to the original size modulo * 2^32. Since the size of SVG documents is less than 2^32 bytes we * can use this accurately. The four bytes are stored in * little-endian format. */ FT_TRACE4(( "SVG document is GZIP compressed\n" )); uncomp_size = (FT_ULong)doc_list[doc_length - 1] << 24 | (FT_ULong)doc_list[doc_length - 2] << 16 | (FT_ULong)doc_list[doc_length - 3] << 8 | (FT_ULong)doc_list[doc_length - 4]; if ( FT_QALLOC( uncomp_buffer, uncomp_size ) ) goto Exit; error = FT_Gzip_Uncompress( memory, uncomp_buffer, &uncomp_size, doc_list, doc_length ); if ( error ) { FT_FREE( uncomp_buffer ); error = FT_THROW( Invalid_Table ); goto Exit; } glyph->internal->flags |= FT_GLYPH_OWN_GZIP_SVG; doc_list = uncomp_buffer; doc_length = uncomp_size; #else /* !FT_CONFIG_OPTION_USE_ZLIB */ error = FT_THROW( Unimplemented_Feature ); goto Exit; #endif /* !FT_CONFIG_OPTION_USE_ZLIB */ } svg_document->svg_document = doc_list; svg_document->svg_document_length = doc_length; svg_document->metrics = glyph->face->size->metrics; svg_document->units_per_EM = glyph->face->units_per_EM; svg_document->start_glyph_id = start_glyph_id; svg_document->end_glyph_id = end_glyph_id; svg_document->transform.xx = 0x10000; svg_document->transform.xy = 0; svg_document->transform.yx = 0; svg_document->transform.yy = 0x10000; svg_document->delta.x = 0; svg_document->delta.y = 0; FT_TRACE5(( "start_glyph_id: %d\n", start_glyph_id )); FT_TRACE5(( "end_glyph_id: %d\n", end_glyph_id )); FT_TRACE5(( "svg_document:\n" )); FT_TRACE5(( " %.*s\n", (FT_UInt)doc_length, doc_list )); glyph->other = svg_document; Exit: return error; } #else /* !FT_CONFIG_OPTION_SVG */ /* ANSI C doesn't like empty source files */ typedef int _tt_svg_dummy; #endif /* !FT_CONFIG_OPTION_SVG */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttsvg.c
C++
gpl-3.0
10,489
/**************************************************************************** * * ttsvg.h * * OpenType SVG Color (specification). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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 TTSVG_H_ #define TTSVG_H_ #include <freetype/internal/ftstream.h> #include <freetype/internal/tttypes.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) tt_face_load_svg( TT_Face face, FT_Stream stream ); FT_LOCAL( void ) tt_face_free_svg( TT_Face face ); FT_LOCAL( FT_Error ) tt_face_load_svg_doc( FT_GlyphSlot glyph, FT_UInt glyph_index ); FT_END_HEADER #endif /* TTSVG_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/ttsvg.h
C++
gpl-3.0
1,009
/**************************************************************************** * * woff2tags.c * * WOFF2 Font table tags (base). * * Copyright (C) 2019-2022 by * Nikhil Ramakrishnan, 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 <freetype/tttags.h> #ifdef FT_CONFIG_OPTION_USE_BROTLI #include "woff2tags.h" /* * Return tag from index in the order given in WOFF2 specification. * * See * * https://www.w3.org/TR/WOFF2/#table_dir_format * * for details. */ FT_LOCAL_DEF( FT_Tag ) woff2_known_tags( FT_Byte index ) { static const FT_Tag known_tags[63] = { FT_MAKE_TAG('c', 'm', 'a', 'p'), /* 0 */ FT_MAKE_TAG('h', 'e', 'a', 'd'), /* 1 */ FT_MAKE_TAG('h', 'h', 'e', 'a'), /* 2 */ FT_MAKE_TAG('h', 'm', 't', 'x'), /* 3 */ FT_MAKE_TAG('m', 'a', 'x', 'p'), /* 4 */ FT_MAKE_TAG('n', 'a', 'm', 'e'), /* 5 */ FT_MAKE_TAG('O', 'S', '/', '2'), /* 6 */ FT_MAKE_TAG('p', 'o', 's', 't'), /* 7 */ FT_MAKE_TAG('c', 'v', 't', ' '), /* 8 */ FT_MAKE_TAG('f', 'p', 'g', 'm'), /* 9 */ FT_MAKE_TAG('g', 'l', 'y', 'f'), /* 10 */ FT_MAKE_TAG('l', 'o', 'c', 'a'), /* 11 */ FT_MAKE_TAG('p', 'r', 'e', 'p'), /* 12 */ FT_MAKE_TAG('C', 'F', 'F', ' '), /* 13 */ FT_MAKE_TAG('V', 'O', 'R', 'G'), /* 14 */ FT_MAKE_TAG('E', 'B', 'D', 'T'), /* 15 */ FT_MAKE_TAG('E', 'B', 'L', 'C'), /* 16 */ FT_MAKE_TAG('g', 'a', 's', 'p'), /* 17 */ FT_MAKE_TAG('h', 'd', 'm', 'x'), /* 18 */ FT_MAKE_TAG('k', 'e', 'r', 'n'), /* 19 */ FT_MAKE_TAG('L', 'T', 'S', 'H'), /* 20 */ FT_MAKE_TAG('P', 'C', 'L', 'T'), /* 21 */ FT_MAKE_TAG('V', 'D', 'M', 'X'), /* 22 */ FT_MAKE_TAG('v', 'h', 'e', 'a'), /* 23 */ FT_MAKE_TAG('v', 'm', 't', 'x'), /* 24 */ FT_MAKE_TAG('B', 'A', 'S', 'E'), /* 25 */ FT_MAKE_TAG('G', 'D', 'E', 'F'), /* 26 */ FT_MAKE_TAG('G', 'P', 'O', 'S'), /* 27 */ FT_MAKE_TAG('G', 'S', 'U', 'B'), /* 28 */ FT_MAKE_TAG('E', 'B', 'S', 'C'), /* 29 */ FT_MAKE_TAG('J', 'S', 'T', 'F'), /* 30 */ FT_MAKE_TAG('M', 'A', 'T', 'H'), /* 31 */ FT_MAKE_TAG('C', 'B', 'D', 'T'), /* 32 */ FT_MAKE_TAG('C', 'B', 'L', 'C'), /* 33 */ FT_MAKE_TAG('C', 'O', 'L', 'R'), /* 34 */ FT_MAKE_TAG('C', 'P', 'A', 'L'), /* 35 */ FT_MAKE_TAG('S', 'V', 'G', ' '), /* 36 */ FT_MAKE_TAG('s', 'b', 'i', 'x'), /* 37 */ FT_MAKE_TAG('a', 'c', 'n', 't'), /* 38 */ FT_MAKE_TAG('a', 'v', 'a', 'r'), /* 39 */ FT_MAKE_TAG('b', 'd', 'a', 't'), /* 40 */ FT_MAKE_TAG('b', 'l', 'o', 'c'), /* 41 */ FT_MAKE_TAG('b', 's', 'l', 'n'), /* 42 */ FT_MAKE_TAG('c', 'v', 'a', 'r'), /* 43 */ FT_MAKE_TAG('f', 'd', 's', 'c'), /* 44 */ FT_MAKE_TAG('f', 'e', 'a', 't'), /* 45 */ FT_MAKE_TAG('f', 'm', 't', 'x'), /* 46 */ FT_MAKE_TAG('f', 'v', 'a', 'r'), /* 47 */ FT_MAKE_TAG('g', 'v', 'a', 'r'), /* 48 */ FT_MAKE_TAG('h', 's', 't', 'y'), /* 49 */ FT_MAKE_TAG('j', 'u', 's', 't'), /* 50 */ FT_MAKE_TAG('l', 'c', 'a', 'r'), /* 51 */ FT_MAKE_TAG('m', 'o', 'r', 't'), /* 52 */ FT_MAKE_TAG('m', 'o', 'r', 'x'), /* 53 */ FT_MAKE_TAG('o', 'p', 'b', 'd'), /* 54 */ FT_MAKE_TAG('p', 'r', 'o', 'p'), /* 55 */ FT_MAKE_TAG('t', 'r', 'a', 'k'), /* 56 */ FT_MAKE_TAG('Z', 'a', 'p', 'f'), /* 57 */ FT_MAKE_TAG('S', 'i', 'l', 'f'), /* 58 */ FT_MAKE_TAG('G', 'l', 'a', 't'), /* 59 */ FT_MAKE_TAG('G', 'l', 'o', 'c'), /* 60 */ FT_MAKE_TAG('F', 'e', 'a', 't'), /* 61 */ FT_MAKE_TAG('S', 'i', 'l', 'l'), /* 62 */ }; if ( index > 62 ) return 0; return known_tags[index]; } #else /* !FT_CONFIG_OPTION_USE_BROTLI */ /* ANSI C doesn't like empty source files */ typedef int _woff2tags_dummy; #endif /* !FT_CONFIG_OPTION_USE_BROTLI */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/woff2tags.c
C++
gpl-3.0
4,350
/**************************************************************************** * * woff2tags.h * * WOFF2 Font table tags (specification). * * Copyright (C) 2019-2022 by * Nikhil Ramakrishnan, 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 WOFF2TAGS_H #define WOFF2TAGS_H #include <freetype/internal/ftobjs.h> #include <freetype/internal/compiler-macros.h> FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_USE_BROTLI FT_LOCAL( FT_Tag ) woff2_known_tags( FT_Byte index ); #endif FT_END_HEADER #endif /* WOFF2TAGS_H */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/sfnt/woff2tags.h
C++
gpl-3.0
867
/**************************************************************************** * * ftgrays.c * * A new `perfect' anti-aliasing renderer (body). * * Copyright (C) 2000-2022 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. * */ /************************************************************************** * * This file can be compiled without the rest of the FreeType engine, by * defining the STANDALONE_ macro when compiling it. You also need to * put the files `ftgrays.h' and `ftimage.h' into the current * compilation directory. Typically, you could do something like * * - copy `src/smooth/ftgrays.c' (this file) to your current directory * * - copy `include/freetype/ftimage.h' and `src/smooth/ftgrays.h' to the * same directory * * - compile `ftgrays' with the STANDALONE_ macro defined, as in * * cc -c -DSTANDALONE_ ftgrays.c * * The renderer can be initialized with a call to * `ft_gray_raster.raster_new'; an anti-aliased bitmap can be generated * with a call to `ft_gray_raster.raster_render'. * * See the comments and documentation in the file `ftimage.h' for more * details on how the raster works. * */ /************************************************************************** * * This is a new anti-aliasing scan-converter for FreeType 2. The * algorithm used here is _very_ different from the one in the standard * `ftraster' module. Actually, `ftgrays' computes the _exact_ * coverage of the outline on each pixel cell by straight segments. * * It is based on ideas that I initially found in Raph Levien's * excellent LibArt graphics library (see https://www.levien.com/libart * for more information, though the web pages do not tell anything * about the renderer; you'll have to dive into the source code to * understand how it works). * * Note, however, that this is a _very_ different implementation * compared to Raph's. Coverage information is stored in a very * different way, and I don't use sorted vector paths. Also, it doesn't * use floating point values. * * Bézier segments are flattened by splitting them until their deviation * from straight line becomes much smaller than a pixel. Therefore, the * pixel coverage by a Bézier curve is calculated approximately. To * estimate the deviation, we use the distance from the control point * to the conic chord centre or the cubic chord trisection. These * distances vanish fast after each split. In the conic case, they vanish * predictably and the number of necessary splits can be calculated. * * This renderer has the following advantages: * * - It doesn't need an intermediate bitmap. Instead, one can supply a * callback function that will be called by the renderer to draw gray * spans on any target surface. You can thus do direct composition on * any kind of bitmap, provided that you give the renderer the right * callback. * * - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on * each pixel cell by straight segments. * * - It performs a single pass on the outline (the `standard' FT2 * renderer makes two passes). * * - It can easily be modified to render to _any_ number of gray levels * cheaply. * * - For small (< 80) pixel sizes, it is faster than the standard * renderer. * */ /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT smooth #ifdef STANDALONE_ /* The size in bytes of the render pool used by the scan-line converter */ /* to do all of its work. */ #define FT_RENDER_POOL_SIZE 16384L /* Auxiliary macros for token concatenation. */ #define FT_ERR_XCAT( x, y ) x ## y #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) #define FT_BEGIN_STMNT do { #define FT_END_STMNT } while ( 0 ) #define FT_MIN( a, b ) ( (a) < (b) ? (a) : (b) ) #define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) ) #define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) ) /* * Approximate sqrt(x*x+y*y) using the `alpha max plus beta min' * algorithm. We use alpha = 1, beta = 3/8, giving us results with a * largest error less than 7% compared to the exact value. */ #define FT_HYPOT( x, y ) \ ( x = FT_ABS( x ), \ y = FT_ABS( y ), \ x > y ? x + ( 3 * y >> 3 ) \ : y + ( 3 * x >> 3 ) ) /* define this to dump debugging information */ /* #define FT_DEBUG_LEVEL_TRACE */ #ifdef FT_DEBUG_LEVEL_TRACE #include <stdio.h> #include <stdarg.h> #endif #include <stddef.h> #include <string.h> #include <setjmp.h> #include <limits.h> #define FT_CHAR_BIT CHAR_BIT #define FT_UINT_MAX UINT_MAX #define FT_INT_MAX INT_MAX #define FT_ULONG_MAX ULONG_MAX #define ADD_INT( a, b ) \ (int)( (unsigned int)(a) + (unsigned int)(b) ) #define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var) #define ft_memset memset #define ft_setjmp setjmp #define ft_longjmp longjmp #define ft_jmp_buf jmp_buf typedef ptrdiff_t FT_PtrDist; #define Smooth_Err_Ok 0 #define Smooth_Err_Invalid_Outline -1 #define Smooth_Err_Cannot_Render_Glyph -2 #define Smooth_Err_Invalid_Argument -3 #define Smooth_Err_Raster_Overflow -4 #define FT_BEGIN_HEADER #define FT_END_HEADER #include "ftimage.h" #include "ftgrays.h" /* This macro is used to indicate that a function parameter is unused. */ /* Its purpose is simply to reduce compiler warnings. Note also that */ /* simply defining it as `(void)x' doesn't avoid warnings with certain */ /* ANSI compilers (e.g. LCC). */ #define FT_UNUSED( x ) (x) = (x) /* we only use level 5 & 7 tracing messages; cf. ftdebug.h */ #ifdef FT_DEBUG_LEVEL_TRACE void FT_Message( const char* fmt, ... ) { va_list ap; va_start( ap, fmt ); vfprintf( stderr, fmt, ap ); va_end( ap ); } /* empty function useful for setting a breakpoint to catch errors */ int FT_Throw( int error, int line, const char* file ) { FT_UNUSED( error ); FT_UNUSED( line ); FT_UNUSED( file ); return 0; } /* we don't handle tracing levels in stand-alone mode; */ #ifndef FT_TRACE5 #define FT_TRACE5( varformat ) FT_Message varformat #endif #ifndef FT_TRACE7 #define FT_TRACE7( varformat ) FT_Message varformat #endif #ifndef FT_ERROR #define FT_ERROR( varformat ) FT_Message varformat #endif #define FT_THROW( e ) \ ( FT_Throw( FT_ERR_CAT( Smooth_Err_, e ), \ __LINE__, \ __FILE__ ) | \ FT_ERR_CAT( Smooth_Err_, e ) ) #else /* !FT_DEBUG_LEVEL_TRACE */ #define FT_TRACE5( x ) do { } while ( 0 ) /* nothing */ #define FT_TRACE7( x ) do { } while ( 0 ) /* nothing */ #define FT_ERROR( x ) do { } while ( 0 ) /* nothing */ #define FT_THROW( e ) FT_ERR_CAT( Smooth_Err_, e ) #endif /* !FT_DEBUG_LEVEL_TRACE */ #define FT_Trace_Enable() do { } while ( 0 ) /* nothing */ #define FT_Trace_Disable() do { } while ( 0 ) /* nothing */ #define FT_DEFINE_OUTLINE_FUNCS( class_, \ move_to_, line_to_, \ conic_to_, cubic_to_, \ shift_, delta_ ) \ static const FT_Outline_Funcs class_ = \ { \ move_to_, \ line_to_, \ conic_to_, \ cubic_to_, \ shift_, \ delta_ \ }; #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, \ raster_new_, raster_reset_, \ raster_set_mode_, raster_render_, \ raster_done_ ) \ const FT_Raster_Funcs class_ = \ { \ glyph_format_, \ raster_new_, \ raster_reset_, \ raster_set_mode_, \ raster_render_, \ raster_done_ \ }; #else /* !STANDALONE_ */ #include <ft2build.h> #include FT_CONFIG_CONFIG_H #include "ftgrays.h" #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftcalc.h> #include <freetype/ftoutln.h> #include "ftsmerrs.h" #endif /* !STANDALONE_ */ #ifndef FT_MEM_SET #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c ) #endif #ifndef FT_MEM_ZERO #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count ) #endif #ifndef FT_ZERO #define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) ) #endif /* as usual, for the speed hungry :-) */ #undef RAS_ARG #undef RAS_ARG_ #undef RAS_VAR #undef RAS_VAR_ #ifndef FT_STATIC_RASTER #define RAS_ARG gray_PWorker worker #define RAS_ARG_ gray_PWorker worker, #define RAS_VAR worker #define RAS_VAR_ worker, #else /* FT_STATIC_RASTER */ #define RAS_ARG void #define RAS_ARG_ /* empty */ #define RAS_VAR /* empty */ #define RAS_VAR_ /* empty */ #endif /* FT_STATIC_RASTER */ /* must be at least 6 bits! */ #define PIXEL_BITS 8 #define ONE_PIXEL ( 1 << PIXEL_BITS ) #undef TRUNC #define TRUNC( x ) (TCoord)( (x) >> PIXEL_BITS ) #undef FRACT #define FRACT( x ) (TCoord)( (x) & ( ONE_PIXEL - 1 ) ) #if PIXEL_BITS >= 6 #define UPSCALE( x ) ( (x) * ( ONE_PIXEL >> 6 ) ) #define DOWNSCALE( x ) ( (x) >> ( PIXEL_BITS - 6 ) ) #else #define UPSCALE( x ) ( (x) >> ( 6 - PIXEL_BITS ) ) #define DOWNSCALE( x ) ( (x) * ( 64 >> PIXEL_BITS ) ) #endif /* Compute `dividend / divisor' and return both its quotient and */ /* remainder, cast to a specific type. This macro also ensures that */ /* the remainder is always positive. We use the remainder to keep */ /* track of accumulating errors and compensate for them. */ #define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \ FT_BEGIN_STMNT \ (quotient) = (type)( (dividend) / (divisor) ); \ (remainder) = (type)( (dividend) % (divisor) ); \ if ( (remainder) < 0 ) \ { \ (quotient)--; \ (remainder) += (type)(divisor); \ } \ FT_END_STMNT #if defined( __GNUC__ ) && __GNUC__ < 7 && defined( __arm__ ) /* Work around a bug specific to GCC which make the compiler fail to */ /* optimize a division and modulo operation on the same parameters */ /* into a single call to `__aeabi_idivmod'. See */ /* */ /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */ #undef FT_DIV_MOD #define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \ FT_BEGIN_STMNT \ (quotient) = (type)( (dividend) / (divisor) ); \ (remainder) = (type)( (dividend) - (quotient) * (divisor) ); \ if ( (remainder) < 0 ) \ { \ (quotient)--; \ (remainder) += (type)(divisor); \ } \ FT_END_STMNT #endif /* __arm__ */ /* Calculating coverages for a slanted line requires a division each */ /* time the line crosses from cell to cell. These macros speed up */ /* the repetitive divisions by replacing them with multiplications */ /* and right shifts so that at most two divisions are performed for */ /* each slanted line. Nevertheless, these divisions are noticeable */ /* in the overall performance because flattened curves produce a */ /* very large number of slanted lines. */ /* */ /* The division results here are always within ONE_PIXEL. Therefore */ /* the shift magnitude should be at least PIXEL_BITS wider than the */ /* divisors to provide sufficient accuracy of the multiply-shift. */ /* It should not exceed (64 - PIXEL_BITS) to prevent overflowing and */ /* leave enough room for 64-bit unsigned multiplication however. */ #define FT_UDIVPREP( c, b ) \ FT_Int64 b ## _r = c ? (FT_Int64)0xFFFFFFFF / ( b ) : 0 #define FT_UDIV( a, b ) \ (TCoord)( ( (FT_UInt64)( a ) * (FT_UInt64)( b ## _r ) ) >> 32 ) /* Scale area and apply fill rule to calculate the coverage byte. */ /* The top fill bit is used for the non-zero rule. The eighth */ /* fill bit is used for the even-odd rule. The higher coverage */ /* bytes are either clamped for the non-zero-rule or discarded */ /* later for the even-odd rule. */ #define FT_FILL_RULE( coverage, area, fill ) \ FT_BEGIN_STMNT \ coverage = (int)( area >> ( PIXEL_BITS * 2 + 1 - 8 ) ); \ if ( coverage & fill ) \ coverage = ~coverage; \ if ( coverage > 255 && fill & INT_MIN ) \ coverage = 255; \ FT_END_STMNT /* It is faster to write small spans byte-by-byte than calling */ /* `memset'. This is mainly due to the cost of the function call. */ #define FT_GRAY_SET( d, s, count ) \ FT_BEGIN_STMNT \ unsigned char* q = d; \ switch ( count ) \ { \ case 7: *q++ = (unsigned char)s; /* fall through */ \ case 6: *q++ = (unsigned char)s; /* fall through */ \ case 5: *q++ = (unsigned char)s; /* fall through */ \ case 4: *q++ = (unsigned char)s; /* fall through */ \ case 3: *q++ = (unsigned char)s; /* fall through */ \ case 2: *q++ = (unsigned char)s; /* fall through */ \ case 1: *q = (unsigned char)s; /* fall through */ \ case 0: break; \ default: FT_MEM_SET( d, s, count ); \ } \ FT_END_STMNT /************************************************************************** * * TYPE DEFINITIONS */ /* don't change the following types to FT_Int or FT_Pos, since we might */ /* need to define them to "float" or "double" when experimenting with */ /* new algorithms */ typedef long TPos; /* subpixel coordinate */ typedef int TCoord; /* integer scanline/pixel coordinate */ typedef int TArea; /* cell areas, coordinate products */ typedef struct TCell_* PCell; typedef struct TCell_ { TCoord x; /* same with gray_TWorker.ex */ TCoord cover; /* same with gray_TWorker.cover */ TArea area; PCell next; } TCell; typedef struct TPixmap_ { unsigned char* origin; /* pixmap origin at the bottom-left */ int pitch; /* pitch to go down one row */ } TPixmap; /* maximum number of gray cells in the buffer */ #if FT_RENDER_POOL_SIZE > 2048 #define FT_MAX_GRAY_POOL ( FT_RENDER_POOL_SIZE / sizeof ( TCell ) ) #else #define FT_MAX_GRAY_POOL ( 2048 / sizeof ( TCell ) ) #endif /* FT_Span buffer size for direct rendering only */ #define FT_MAX_GRAY_SPANS 16 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */ /* We disable the warning `structure was padded due to */ /* __declspec(align())' in order to compile cleanly with */ /* the maximum level of warnings. */ #pragma warning( push ) #pragma warning( disable : 4324 ) #endif /* _MSC_VER */ typedef struct gray_TWorker_ { ft_jmp_buf jump_buffer; TCoord min_ex, max_ex; /* min and max integer pixel coordinates */ TCoord min_ey, max_ey; TCoord count_ey; /* same as (max_ey - min_ey) */ PCell cell; /* current cell */ PCell cell_free; /* call allocation next free slot */ PCell cell_null; /* last cell, used as dumpster and limit */ PCell* ycells; /* array of cell linked-lists; one per */ /* vertical coordinate in the current band */ TPos x, y; /* last point position */ FT_Outline outline; /* input outline */ TPixmap target; /* target pixmap */ FT_Raster_Span_Func render_span; void* render_span_data; } gray_TWorker, *gray_PWorker; #if defined( _MSC_VER ) #pragma warning( pop ) #endif #ifndef FT_STATIC_RASTER #define ras (*worker) #else static gray_TWorker ras; #endif /* The |x| value of the null cell. Must be the largest possible */ /* integer value stored in a `TCell.x` field. */ #define CELL_MAX_X_VALUE INT_MAX #define FT_INTEGRATE( ras, a, b ) \ ras.cell->cover = ADD_INT( ras.cell->cover, a ), \ ras.cell->area = ADD_INT( ras.cell->area, (a) * (TArea)(b) ) typedef struct gray_TRaster_ { void* memory; } gray_TRaster, *gray_PRaster; #ifdef FT_DEBUG_LEVEL_TRACE /* to be called while in the debugger -- */ /* this function causes a compiler warning since it is unused otherwise */ static void gray_dump_cells( RAS_ARG ) { int y; for ( y = ras.min_ey; y < ras.max_ey; y++ ) { PCell cell = ras.ycells[y - ras.min_ey]; printf( "%3d:", y ); for ( ; cell != ras.cell_null; cell = cell->next ) printf( " (%3d, c:%4d, a:%6d)", cell->x, cell->cover, cell->area ); printf( "\n" ); } } #endif /* FT_DEBUG_LEVEL_TRACE */ /************************************************************************** * * Set the current cell to a new position. */ static void gray_set_cell( RAS_ARG_ TCoord ex, TCoord ey ) { /* Move the cell pointer to a new position in the linked list. We use */ /* a dumpster null cell for everything outside of the clipping region */ /* during the render phase. This means that: */ /* */ /* . the new vertical position must be within min_ey..max_ey-1. */ /* . the new horizontal position must be strictly less than max_ex */ /* */ /* Note that if a cell is to the left of the clipping region, it is */ /* actually set to the (min_ex-1) horizontal position. */ TCoord ey_index = ey - ras.min_ey; if ( ey_index < 0 || ey_index >= ras.count_ey || ex >= ras.max_ex ) ras.cell = ras.cell_null; else { PCell* pcell = ras.ycells + ey_index; PCell cell; ex = FT_MAX( ex, ras.min_ex - 1 ); while ( 1 ) { cell = *pcell; if ( cell->x > ex ) break; if ( cell->x == ex ) goto Found; pcell = &cell->next; } /* insert new cell */ cell = ras.cell_free++; if ( cell >= ras.cell_null ) ft_longjmp( ras.jump_buffer, 1 ); cell->x = ex; cell->area = 0; cell->cover = 0; cell->next = *pcell; *pcell = cell; Found: ras.cell = cell; } } #ifndef FT_INT64 /************************************************************************** * * Render a scanline as one or more cells. */ static void gray_render_scanline( RAS_ARG_ TCoord ey, TPos x1, TCoord y1, TPos x2, TCoord y2 ) { TCoord ex1, ex2, fx1, fx2, first, dy, delta, mod; TPos p, dx; int incr; ex1 = TRUNC( x1 ); ex2 = TRUNC( x2 ); /* trivial case. Happens often */ if ( y1 == y2 ) { gray_set_cell( RAS_VAR_ ex2, ey ); return; } fx1 = FRACT( x1 ); fx2 = FRACT( x2 ); /* everything is located in a single cell. That is easy! */ /* */ if ( ex1 == ex2 ) goto End; /* ok, we'll have to render a run of adjacent cells on the same */ /* scanline... */ /* */ dx = x2 - x1; dy = y2 - y1; if ( dx > 0 ) { p = ( ONE_PIXEL - fx1 ) * dy; first = ONE_PIXEL; incr = 1; } else { p = fx1 * dy; first = 0; incr = -1; dx = -dx; } /* the fractional part of y-delta is mod/dx. It is essential to */ /* keep track of its accumulation for accurate rendering. */ /* XXX: y-delta and x-delta below should be related. */ FT_DIV_MOD( TCoord, p, dx, delta, mod ); FT_INTEGRATE( ras, delta, fx1 + first ); y1 += delta; ex1 += incr; gray_set_cell( RAS_VAR_ ex1, ey ); if ( ex1 != ex2 ) { TCoord lift, rem; p = ONE_PIXEL * dy; FT_DIV_MOD( TCoord, p, dx, lift, rem ); do { delta = lift; mod += rem; if ( mod >= (TCoord)dx ) { mod -= (TCoord)dx; delta++; } FT_INTEGRATE( ras, delta, ONE_PIXEL ); y1 += delta; ex1 += incr; gray_set_cell( RAS_VAR_ ex1, ey ); } while ( ex1 != ex2 ); } fx1 = ONE_PIXEL - first; End: FT_INTEGRATE( ras, y2 - y1, fx1 + fx2 ); } /************************************************************************** * * Render a given line as a series of scanlines. */ static void gray_render_line( RAS_ARG_ TPos to_x, TPos to_y ) { TCoord ey1, ey2, fy1, fy2, first, delta, mod; TPos p, dx, dy, x, x2; int incr; ey1 = TRUNC( ras.y ); ey2 = TRUNC( to_y ); /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */ /* perform vertical clipping */ if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) || ( ey1 < ras.min_ey && ey2 < ras.min_ey ) ) goto End; fy1 = FRACT( ras.y ); fy2 = FRACT( to_y ); /* everything is on a single scanline */ if ( ey1 == ey2 ) { gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 ); goto End; } dx = to_x - ras.x; dy = to_y - ras.y; /* vertical line - avoid calling gray_render_scanline */ if ( dx == 0 ) { TCoord ex = TRUNC( ras.x ); TCoord two_fx = FRACT( ras.x ) << 1; if ( dy > 0) { first = ONE_PIXEL; incr = 1; } else { first = 0; incr = -1; } delta = first - fy1; FT_INTEGRATE( ras, delta, two_fx); ey1 += incr; gray_set_cell( RAS_VAR_ ex, ey1 ); delta = first + first - ONE_PIXEL; while ( ey1 != ey2 ) { FT_INTEGRATE( ras, delta, two_fx); ey1 += incr; gray_set_cell( RAS_VAR_ ex, ey1 ); } delta = fy2 - ONE_PIXEL + first; FT_INTEGRATE( ras, delta, two_fx); goto End; } /* ok, we have to render several scanlines */ if ( dy > 0) { p = ( ONE_PIXEL - fy1 ) * dx; first = ONE_PIXEL; incr = 1; } else { p = fy1 * dx; first = 0; incr = -1; dy = -dy; } /* the fractional part of x-delta is mod/dy. It is essential to */ /* keep track of its accumulation for accurate rendering. */ FT_DIV_MOD( TCoord, p, dy, delta, mod ); x = ras.x + delta; gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first ); ey1 += incr; gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 ); if ( ey1 != ey2 ) { TCoord lift, rem; p = ONE_PIXEL * dx; FT_DIV_MOD( TCoord, p, dy, lift, rem ); do { delta = lift; mod += rem; if ( mod >= (TCoord)dy ) { mod -= (TCoord)dy; delta++; } x2 = x + delta; gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, x2, first ); x = x2; ey1 += incr; gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 ); } while ( ey1 != ey2 ); } gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, to_x, fy2 ); End: ras.x = to_x; ras.y = to_y; } #else /************************************************************************** * * Render a straight line across multiple cells in any direction. */ static void gray_render_line( RAS_ARG_ TPos to_x, TPos to_y ) { TPos dx, dy; TCoord fx1, fy1, fx2, fy2; TCoord ex1, ey1, ex2, ey2; ey1 = TRUNC( ras.y ); ey2 = TRUNC( to_y ); /* perform vertical clipping */ if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) || ( ey1 < ras.min_ey && ey2 < ras.min_ey ) ) goto End; ex1 = TRUNC( ras.x ); ex2 = TRUNC( to_x ); fx1 = FRACT( ras.x ); fy1 = FRACT( ras.y ); dx = to_x - ras.x; dy = to_y - ras.y; if ( ex1 == ex2 && ey1 == ey2 ) /* inside one cell */ ; else if ( dy == 0 ) /* ex1 != ex2 */ /* any horizontal line */ { gray_set_cell( RAS_VAR_ ex2, ey2 ); goto End; } else if ( dx == 0 ) { if ( dy > 0 ) /* vertical line up */ do { fy2 = ONE_PIXEL; FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 ); fy1 = 0; ey1++; gray_set_cell( RAS_VAR_ ex1, ey1 ); } while ( ey1 != ey2 ); else /* vertical line down */ do { fy2 = 0; FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 ); fy1 = ONE_PIXEL; ey1--; gray_set_cell( RAS_VAR_ ex1, ey1 ); } while ( ey1 != ey2 ); } else /* any other line */ { FT_Int64 prod = dx * (FT_Int64)fy1 - dy * (FT_Int64)fx1; FT_UDIVPREP( ex1 != ex2, dx ); FT_UDIVPREP( ey1 != ey2, dy ); /* The fundamental value `prod' determines which side and the */ /* exact coordinate where the line exits current cell. It is */ /* also easily updated when moving from one cell to the next. */ do { if ( prod - dx * ONE_PIXEL > 0 && prod <= 0 ) /* left */ { fx2 = 0; fy2 = FT_UDIV( -prod, -dx ); prod -= dy * ONE_PIXEL; FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 ); fx1 = ONE_PIXEL; fy1 = fy2; ex1--; } else if ( prod - dx * ONE_PIXEL + dy * ONE_PIXEL > 0 && prod - dx * ONE_PIXEL <= 0 ) /* up */ { prod -= dx * ONE_PIXEL; fx2 = FT_UDIV( -prod, dy ); fy2 = ONE_PIXEL; FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 ); fx1 = fx2; fy1 = 0; ey1++; } else if ( prod + dy * ONE_PIXEL >= 0 && prod - dx * ONE_PIXEL + dy * ONE_PIXEL <= 0 ) /* right */ { prod += dy * ONE_PIXEL; fx2 = ONE_PIXEL; fy2 = FT_UDIV( prod, dx ); FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 ); fx1 = 0; fy1 = fy2; ex1++; } else /* ( prod > 0 && prod + dy * ONE_PIXEL < 0 ) down */ { fx2 = FT_UDIV( prod, -dy ); fy2 = 0; prod += dx * ONE_PIXEL; FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 ); fx1 = fx2; fy1 = ONE_PIXEL; ey1--; } gray_set_cell( RAS_VAR_ ex1, ey1 ); } while ( ex1 != ex2 || ey1 != ey2 ); } fx2 = FRACT( to_x ); fy2 = FRACT( to_y ); FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 ); End: ras.x = to_x; ras.y = to_y; } #endif /* * Benchmarking shows that using DDA to flatten the quadratic Bézier arcs * is slightly faster in the following cases: * * - When the host CPU is 64-bit. * - When SSE2 SIMD registers and instructions are available (even on * x86). * * For other cases, using binary splits is actually slightly faster. */ #if defined( __SSE2__ ) || \ defined( __x86_64__ ) || \ defined( _M_AMD64 ) || \ ( defined( _M_IX86_FP ) && _M_IX86_FP >= 2 ) # define FT_SSE2 1 #else # define FT_SSE2 0 #endif #if FT_SSE2 || \ defined( __aarch64__ ) || \ defined( _M_ARM64 ) # define BEZIER_USE_DDA 1 #else # define BEZIER_USE_DDA 0 #endif /* * For now, the code that depends on `BEZIER_USE_DDA` requires `FT_Int64` * to be defined. If `FT_INT64` is not defined, meaning there is no * 64-bit type available, disable it to avoid compilation errors. See for * example https://gitlab.freedesktop.org/freetype/freetype/-/issues/1071. */ #if !defined( FT_INT64 ) # undef BEZIER_USE_DDA # define BEZIER_USE_DDA 0 #endif #if BEZIER_USE_DDA #if FT_SSE2 # include <emmintrin.h> #endif #define LEFT_SHIFT( a, b ) (FT_Int64)( (FT_UInt64)(a) << (b) ) static void gray_render_conic( RAS_ARG_ const FT_Vector* control, const FT_Vector* to ) { FT_Vector p0, p1, p2; TPos ax, ay, bx, by, dx, dy; int shift; FT_Int64 rx, ry; FT_Int64 qx, qy; FT_Int64 px, py; FT_UInt count; p0.x = ras.x; p0.y = ras.y; p1.x = UPSCALE( control->x ); p1.y = UPSCALE( control->y ); p2.x = UPSCALE( to->x ); p2.y = UPSCALE( to->y ); /* short-cut the arc that crosses the current band */ if ( ( TRUNC( p0.y ) >= ras.max_ey && TRUNC( p1.y ) >= ras.max_ey && TRUNC( p2.y ) >= ras.max_ey ) || ( TRUNC( p0.y ) < ras.min_ey && TRUNC( p1.y ) < ras.min_ey && TRUNC( p2.y ) < ras.min_ey ) ) { ras.x = p2.x; ras.y = p2.y; return; } bx = p1.x - p0.x; by = p1.y - p0.y; ax = p2.x - p1.x - bx; /* p0.x + p2.x - 2 * p1.x */ ay = p2.y - p1.y - by; /* p0.y + p2.y - 2 * p1.y */ dx = FT_ABS( ax ); dy = FT_ABS( ay ); if ( dx < dy ) dx = dy; if ( dx <= ONE_PIXEL / 4 ) { gray_render_line( RAS_VAR_ p2.x, p2.y ); return; } /* We can calculate the number of necessary bisections because */ /* each bisection predictably reduces deviation exactly 4-fold. */ /* Even 32-bit deviation would vanish after 16 bisections. */ shift = 0; do { dx >>= 2; shift += 1; } while ( dx > ONE_PIXEL / 4 ); /* * The (P0,P1,P2) arc equation, for t in [0,1] range: * * P(t) = P0*(1-t)^2 + P1*2*t*(1-t) + P2*t^2 * * P(t) = P0 + 2*(P1-P0)*t + (P0+P2-2*P1)*t^2 * = P0 + 2*B*t + A*t^2 * * for A = P0 + P2 - 2*P1 * and B = P1 - P0 * * Let's consider the difference when advancing by a small * parameter h: * * Q(h,t) = P(t+h) - P(t) = 2*B*h + A*h^2 + 2*A*h*t * * And then its own difference: * * R(h,t) = Q(h,t+h) - Q(h,t) = 2*A*h*h = R (constant) * * Since R is always a constant, it is possible to compute * successive positions with: * * P = P0 * Q = Q(h,0) = 2*B*h + A*h*h * R = 2*A*h*h * * loop: * P += Q * Q += R * EMIT(P) * * To ensure accurate results, perform computations on 64-bit * values, after scaling them by 2^32. * * h = 1 / 2^N * * R << 32 = 2 * A << (32 - N - N) * = A << (33 - 2*N) * * Q << 32 = (2 * B << (32 - N)) + (A << (32 - N - N)) * = (B << (33 - N)) + (A << (32 - 2*N)) */ #if FT_SSE2 /* Experience shows that for small shift values, */ /* SSE2 is actually slower. */ if ( shift > 2 ) { union { struct { FT_Int64 ax, ay, bx, by; } i; struct { __m128i a, b; } vec; } u; union { struct { FT_Int32 px_lo, px_hi, py_lo, py_hi; } i; __m128i vec; } v; __m128i a, b; __m128i r, q, q2; __m128i p; u.i.ax = ax; u.i.ay = ay; u.i.bx = bx; u.i.by = by; a = _mm_load_si128( &u.vec.a ); b = _mm_load_si128( &u.vec.b ); r = _mm_slli_epi64( a, 33 - 2 * shift ); q = _mm_slli_epi64( b, 33 - shift ); q2 = _mm_slli_epi64( a, 32 - 2 * shift ); q = _mm_add_epi64( q2, q ); v.i.px_lo = 0; v.i.px_hi = p0.x; v.i.py_lo = 0; v.i.py_hi = p0.y; p = _mm_load_si128( &v.vec ); for ( count = 1U << shift; count > 0; count-- ) { p = _mm_add_epi64( p, q ); q = _mm_add_epi64( q, r ); _mm_store_si128( &v.vec, p ); gray_render_line( RAS_VAR_ v.i.px_hi, v.i.py_hi ); } return; } #endif /* FT_SSE2 */ rx = LEFT_SHIFT( ax, 33 - 2 * shift ); ry = LEFT_SHIFT( ay, 33 - 2 * shift ); qx = LEFT_SHIFT( bx, 33 - shift ) + LEFT_SHIFT( ax, 32 - 2 * shift ); qy = LEFT_SHIFT( by, 33 - shift ) + LEFT_SHIFT( ay, 32 - 2 * shift ); px = LEFT_SHIFT( p0.x, 32 ); py = LEFT_SHIFT( p0.y, 32 ); for ( count = 1U << shift; count > 0; count-- ) { px += qx; py += qy; qx += rx; qy += ry; gray_render_line( RAS_VAR_ (FT_Pos)( px >> 32 ), (FT_Pos)( py >> 32 ) ); } } #else /* !BEZIER_USE_DDA */ /* * Note that multiple attempts to speed up the function below * with SSE2 intrinsics, using various data layouts, have turned * out to be slower than the non-SIMD code below. */ static void gray_split_conic( FT_Vector* base ) { TPos a, b; base[4].x = base[2].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; base[3].x = b >> 1; base[2].x = ( a + b ) >> 2; base[1].x = a >> 1; base[4].y = base[2].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; base[3].y = b >> 1; base[2].y = ( a + b ) >> 2; base[1].y = a >> 1; } static void gray_render_conic( RAS_ARG_ const FT_Vector* control, const FT_Vector* to ) { FT_Vector bez_stack[16 * 2 + 1]; /* enough to accommodate bisections */ FT_Vector* arc = bez_stack; TPos dx, dy; int draw; arc[0].x = UPSCALE( to->x ); arc[0].y = UPSCALE( to->y ); arc[1].x = UPSCALE( control->x ); arc[1].y = UPSCALE( control->y ); arc[2].x = ras.x; arc[2].y = ras.y; /* short-cut the arc that crosses the current band */ if ( ( TRUNC( arc[0].y ) >= ras.max_ey && TRUNC( arc[1].y ) >= ras.max_ey && TRUNC( arc[2].y ) >= ras.max_ey ) || ( TRUNC( arc[0].y ) < ras.min_ey && TRUNC( arc[1].y ) < ras.min_ey && TRUNC( arc[2].y ) < ras.min_ey ) ) { ras.x = arc[0].x; ras.y = arc[0].y; return; } dx = FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x ); dy = FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y ); if ( dx < dy ) dx = dy; /* We can calculate the number of necessary bisections because */ /* each bisection predictably reduces deviation exactly 4-fold. */ /* Even 32-bit deviation would vanish after 16 bisections. */ draw = 1; while ( dx > ONE_PIXEL / 4 ) { dx >>= 2; draw <<= 1; } /* We use decrement counter to count the total number of segments */ /* to draw starting from 2^level. Before each draw we split as */ /* many times as there are trailing zeros in the counter. */ do { int split = draw & ( -draw ); /* isolate the rightmost 1-bit */ while ( ( split >>= 1 ) ) { gray_split_conic( arc ); arc += 2; } gray_render_line( RAS_VAR_ arc[0].x, arc[0].y ); arc -= 2; } while ( --draw ); } #endif /* !BEZIER_USE_DDA */ /* * For cubic Bézier, binary splits are still faster than DDA * because the splits are adaptive to how quickly each sub-arc * approaches their chord trisection points. * * It might be useful to experiment with SSE2 to speed up * `gray_split_cubic`, though. */ static void gray_split_cubic( FT_Vector* base ) { TPos a, b, c; base[6].x = base[3].x; a = base[0].x + base[1].x; b = base[1].x + base[2].x; c = base[2].x + base[3].x; base[5].x = c >> 1; c += b; base[4].x = c >> 2; base[1].x = a >> 1; a += b; base[2].x = a >> 2; base[3].x = ( a + c ) >> 3; base[6].y = base[3].y; a = base[0].y + base[1].y; b = base[1].y + base[2].y; c = base[2].y + base[3].y; base[5].y = c >> 1; c += b; base[4].y = c >> 2; base[1].y = a >> 1; a += b; base[2].y = a >> 2; base[3].y = ( a + c ) >> 3; } static void gray_render_cubic( RAS_ARG_ const FT_Vector* control1, const FT_Vector* control2, const FT_Vector* to ) { FT_Vector bez_stack[16 * 3 + 1]; /* enough to accommodate bisections */ FT_Vector* arc = bez_stack; arc[0].x = UPSCALE( to->x ); arc[0].y = UPSCALE( to->y ); arc[1].x = UPSCALE( control2->x ); arc[1].y = UPSCALE( control2->y ); arc[2].x = UPSCALE( control1->x ); arc[2].y = UPSCALE( control1->y ); arc[3].x = ras.x; arc[3].y = ras.y; /* short-cut the arc that crosses the current band */ if ( ( TRUNC( arc[0].y ) >= ras.max_ey && TRUNC( arc[1].y ) >= ras.max_ey && TRUNC( arc[2].y ) >= ras.max_ey && TRUNC( arc[3].y ) >= ras.max_ey ) || ( TRUNC( arc[0].y ) < ras.min_ey && TRUNC( arc[1].y ) < ras.min_ey && TRUNC( arc[2].y ) < ras.min_ey && TRUNC( arc[3].y ) < ras.min_ey ) ) { ras.x = arc[0].x; ras.y = arc[0].y; return; } for (;;) { /* with each split, control points quickly converge towards */ /* chord trisection points and the vanishing distances below */ /* indicate when the segment is flat enough to draw */ if ( FT_ABS( 2 * arc[0].x - 3 * arc[1].x + arc[3].x ) > ONE_PIXEL / 2 || FT_ABS( 2 * arc[0].y - 3 * arc[1].y + arc[3].y ) > ONE_PIXEL / 2 || FT_ABS( arc[0].x - 3 * arc[2].x + 2 * arc[3].x ) > ONE_PIXEL / 2 || FT_ABS( arc[0].y - 3 * arc[2].y + 2 * arc[3].y ) > ONE_PIXEL / 2 ) goto Split; gray_render_line( RAS_VAR_ arc[0].x, arc[0].y ); if ( arc == bez_stack ) return; arc -= 3; continue; Split: gray_split_cubic( arc ); arc += 3; } } static int gray_move_to( const FT_Vector* to, gray_PWorker worker ) { TPos x, y; /* start to a new position */ x = UPSCALE( to->x ); y = UPSCALE( to->y ); gray_set_cell( RAS_VAR_ TRUNC( x ), TRUNC( y ) ); ras.x = x; ras.y = y; return 0; } static int gray_line_to( const FT_Vector* to, gray_PWorker worker ) { gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) ); return 0; } static int gray_conic_to( const FT_Vector* control, const FT_Vector* to, gray_PWorker worker ) { gray_render_conic( RAS_VAR_ control, to ); return 0; } static int gray_cubic_to( const FT_Vector* control1, const FT_Vector* control2, const FT_Vector* to, gray_PWorker worker ) { gray_render_cubic( RAS_VAR_ control1, control2, to ); return 0; } static void gray_sweep( RAS_ARG ) { int fill = ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL ) ? 0x100 : INT_MIN; int coverage; int y; for ( y = ras.min_ey; y < ras.max_ey; y++ ) { PCell cell = ras.ycells[y - ras.min_ey]; TCoord x = ras.min_ex; TArea cover = 0; unsigned char* line = ras.target.origin - ras.target.pitch * y; for ( ; cell != ras.cell_null; cell = cell->next ) { TArea area; if ( cover != 0 && cell->x > x ) { FT_FILL_RULE( coverage, cover, fill ); FT_GRAY_SET( line + x, coverage, cell->x - x ); } cover += (TArea)cell->cover * ( ONE_PIXEL * 2 ); area = cover - cell->area; if ( area != 0 && cell->x >= ras.min_ex ) { FT_FILL_RULE( coverage, area, fill ); line[cell->x] = (unsigned char)coverage; } x = cell->x + 1; } if ( cover != 0 ) /* only if cropped */ { FT_FILL_RULE( coverage, cover, fill ); FT_GRAY_SET( line + x, coverage, ras.max_ex - x ); } } } static void gray_sweep_direct( RAS_ARG ) { int fill = ( ras.outline.flags & FT_OUTLINE_EVEN_ODD_FILL ) ? 0x100 : INT_MIN; int coverage; int y; FT_Span span[FT_MAX_GRAY_SPANS]; int n = 0; for ( y = ras.min_ey; y < ras.max_ey; y++ ) { PCell cell = ras.ycells[y - ras.min_ey]; TCoord x = ras.min_ex; TArea cover = 0; for ( ; cell != ras.cell_null; cell = cell->next ) { TArea area; if ( cover != 0 && cell->x > x ) { FT_FILL_RULE( coverage, cover, fill ); span[n].coverage = (unsigned char)coverage; span[n].x = (short)x; span[n].len = (unsigned short)( cell->x - x ); if ( ++n == FT_MAX_GRAY_SPANS ) { /* flush the span buffer and reset the count */ ras.render_span( y, n, span, ras.render_span_data ); n = 0; } } cover += (TArea)cell->cover * ( ONE_PIXEL * 2 ); area = cover - cell->area; if ( area != 0 && cell->x >= ras.min_ex ) { FT_FILL_RULE( coverage, area, fill ); span[n].coverage = (unsigned char)coverage; span[n].x = (short)cell->x; span[n].len = 1; if ( ++n == FT_MAX_GRAY_SPANS ) { /* flush the span buffer and reset the count */ ras.render_span( y, n, span, ras.render_span_data ); n = 0; } } x = cell->x + 1; } if ( cover != 0 ) /* only if cropped */ { FT_FILL_RULE( coverage, cover, fill ); span[n].coverage = (unsigned char)coverage; span[n].x = (short)x; span[n].len = (unsigned short)( ras.max_ex - x ); ++n; } if ( n ) { /* flush the span buffer and reset the count */ ras.render_span( y, n, span, ras.render_span_data ); n = 0; } } } #ifdef STANDALONE_ /************************************************************************** * * The following functions should only compile in stand-alone mode, * i.e., when building this component without the rest of FreeType. * */ /************************************************************************** * * @Function: * FT_Outline_Decompose * * @Description: * Walk over an outline's structure to decompose it into individual * segments and Bézier arcs. This function is also able to emit * `move to' and `close to' operations to indicate the start and end * of new contours in the outline. * * @Input: * outline :: * A pointer to the source target. * * func_interface :: * A table of `emitters', i.e., function pointers * called during decomposition to indicate path * operations. * * @InOut: * user :: * A typeless pointer which is passed to each * emitter during the decomposition. It can be * used to store the state during the * decomposition. * * @Return: * Error code. 0 means success. */ static int FT_Outline_Decompose( const FT_Outline* outline, const FT_Outline_Funcs* func_interface, void* user ) { #undef SCALED #define SCALED( x ) ( (x) * ( 1L << shift ) - delta ) FT_Vector v_last; FT_Vector v_control; FT_Vector v_start; FT_Vector* point; FT_Vector* limit; char* tags; int error; int n; /* index of contour in outline */ int first; /* index of first point in contour */ char tag; /* current point's state */ int shift; TPos delta; if ( !outline ) return FT_THROW( Invalid_Outline ); if ( !func_interface ) return FT_THROW( Invalid_Argument ); shift = func_interface->shift; delta = func_interface->delta; first = 0; for ( n = 0; n < outline->n_contours; n++ ) { int last; /* index of last point in contour */ FT_TRACE5(( "FT_Outline_Decompose: Outline %d\n", n )); last = outline->contours[n]; if ( last < 0 ) goto Invalid_Outline; limit = outline->points + last; v_start = outline->points[first]; v_start.x = SCALED( v_start.x ); v_start.y = SCALED( v_start.y ); v_last = outline->points[last]; v_last.x = SCALED( v_last.x ); v_last.y = SCALED( v_last.y ); v_control = v_start; point = outline->points + first; tags = outline->tags + first; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ if ( tag == FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; /* check first point to determine origin */ if ( tag == FT_CURVE_TAG_CONIC ) { /* first point is conic control. Yes, this happens. */ if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON ) { /* start at last point if it is on the curve */ v_start = v_last; limit--; } else { /* if both first and last points are conic, */ /* start at their middle and record its position */ /* for closure */ v_start.x = ( v_start.x + v_last.x ) / 2; v_start.y = ( v_start.y + v_last.y ) / 2; v_last = v_start; } point--; tags--; } FT_TRACE5(( " move to (%.2f, %.2f)\n", v_start.x / 64.0, v_start.y / 64.0 )); error = func_interface->move_to( &v_start, user ); if ( error ) goto Exit; while ( point < limit ) { point++; tags++; tag = FT_CURVE_TAG( tags[0] ); switch ( tag ) { case FT_CURVE_TAG_ON: /* emit a single line_to */ { FT_Vector vec; vec.x = SCALED( point->x ); vec.y = SCALED( point->y ); FT_TRACE5(( " line to (%.2f, %.2f)\n", vec.x / 64.0, vec.y / 64.0 )); error = func_interface->line_to( &vec, user ); if ( error ) goto Exit; continue; } case FT_CURVE_TAG_CONIC: /* consume conic arcs */ v_control.x = SCALED( point->x ); v_control.y = SCALED( point->y ); Do_Conic: if ( point < limit ) { FT_Vector vec; FT_Vector v_middle; point++; tags++; tag = FT_CURVE_TAG( tags[0] ); vec.x = SCALED( point->x ); vec.y = SCALED( point->y ); if ( tag == FT_CURVE_TAG_ON ) { FT_TRACE5(( " conic to (%.2f, %.2f)" " with control (%.2f, %.2f)\n", vec.x / 64.0, vec.y / 64.0, v_control.x / 64.0, v_control.y / 64.0 )); error = func_interface->conic_to( &v_control, &vec, user ); if ( error ) goto Exit; continue; } if ( tag != FT_CURVE_TAG_CONIC ) goto Invalid_Outline; v_middle.x = ( v_control.x + vec.x ) / 2; v_middle.y = ( v_control.y + vec.y ) / 2; FT_TRACE5(( " conic to (%.2f, %.2f)" " with control (%.2f, %.2f)\n", v_middle.x / 64.0, v_middle.y / 64.0, v_control.x / 64.0, v_control.y / 64.0 )); error = func_interface->conic_to( &v_control, &v_middle, user ); if ( error ) goto Exit; v_control = vec; goto Do_Conic; } FT_TRACE5(( " conic to (%.2f, %.2f)" " with control (%.2f, %.2f)\n", v_start.x / 64.0, v_start.y / 64.0, v_control.x / 64.0, v_control.y / 64.0 )); error = func_interface->conic_to( &v_control, &v_start, user ); goto Close; default: /* FT_CURVE_TAG_CUBIC */ { FT_Vector vec1, vec2; if ( point + 1 > limit || FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC ) goto Invalid_Outline; point += 2; tags += 2; vec1.x = SCALED( point[-2].x ); vec1.y = SCALED( point[-2].y ); vec2.x = SCALED( point[-1].x ); vec2.y = SCALED( point[-1].y ); if ( point <= limit ) { FT_Vector vec; vec.x = SCALED( point->x ); vec.y = SCALED( point->y ); FT_TRACE5(( " cubic to (%.2f, %.2f)" " with controls (%.2f, %.2f) and (%.2f, %.2f)\n", vec.x / 64.0, vec.y / 64.0, vec1.x / 64.0, vec1.y / 64.0, vec2.x / 64.0, vec2.y / 64.0 )); error = func_interface->cubic_to( &vec1, &vec2, &vec, user ); if ( error ) goto Exit; continue; } FT_TRACE5(( " cubic to (%.2f, %.2f)" " with controls (%.2f, %.2f) and (%.2f, %.2f)\n", v_start.x / 64.0, v_start.y / 64.0, vec1.x / 64.0, vec1.y / 64.0, vec2.x / 64.0, vec2.y / 64.0 )); error = func_interface->cubic_to( &vec1, &vec2, &v_start, user ); goto Close; } } } /* close the contour with a line segment */ FT_TRACE5(( " line to (%.2f, %.2f)\n", v_start.x / 64.0, v_start.y / 64.0 )); error = func_interface->line_to( &v_start, user ); Close: if ( error ) goto Exit; first = last + 1; } FT_TRACE5(( "FT_Outline_Decompose: Done\n", n )); return Smooth_Err_Ok; Exit: FT_TRACE5(( "FT_Outline_Decompose: Error 0x%x\n", error )); return error; Invalid_Outline: return FT_THROW( Invalid_Outline ); } #endif /* STANDALONE_ */ FT_DEFINE_OUTLINE_FUNCS( func_interface, (FT_Outline_MoveTo_Func) gray_move_to, /* move_to */ (FT_Outline_LineTo_Func) gray_line_to, /* line_to */ (FT_Outline_ConicTo_Func)gray_conic_to, /* conic_to */ (FT_Outline_CubicTo_Func)gray_cubic_to, /* cubic_to */ 0, /* shift */ 0 /* delta */ ) static int gray_convert_glyph_inner( RAS_ARG, int continued ) { int error; if ( ft_setjmp( ras.jump_buffer ) == 0 ) { if ( continued ) FT_Trace_Disable(); error = FT_Outline_Decompose( &ras.outline, &func_interface, &ras ); if ( continued ) FT_Trace_Enable(); FT_TRACE7(( "band [%d..%d]: %ld cell%s remaining/\n", ras.min_ey, ras.max_ey, ras.cell_null - ras.cell_free, ras.cell_null - ras.cell_free == 1 ? "" : "s" )); } else { error = FT_THROW( Raster_Overflow ); FT_TRACE7(( "band [%d..%d]: to be bisected\n", ras.min_ey, ras.max_ey )); } return error; } static int gray_convert_glyph( RAS_ARG ) { const TCoord yMin = ras.min_ey; const TCoord yMax = ras.max_ey; TCell buffer[FT_MAX_GRAY_POOL]; size_t height = (size_t)( yMax - yMin ); size_t n = FT_MAX_GRAY_POOL / 8; TCoord y; TCoord bands[32]; /* enough to accommodate bisections */ TCoord* band; int continued = 0; /* Initialize the null cell at the end of the poll. */ ras.cell_null = buffer + FT_MAX_GRAY_POOL - 1; ras.cell_null->x = CELL_MAX_X_VALUE; ras.cell_null->area = 0; ras.cell_null->cover = 0; ras.cell_null->next = NULL; /* set up vertical bands */ ras.ycells = (PCell*)buffer; if ( height > n ) { /* two divisions rounded up */ n = ( height + n - 1 ) / n; height = ( height + n - 1 ) / n; } for ( y = yMin; y < yMax; ) { ras.min_ey = y; y += height; ras.max_ey = FT_MIN( y, yMax ); band = bands; band[1] = ras.min_ey; band[0] = ras.max_ey; do { TCoord width = band[0] - band[1]; TCoord w; int error; for ( w = 0; w < width; ++w ) ras.ycells[w] = ras.cell_null; /* memory management: skip ycells */ n = ( (size_t)width * sizeof ( PCell ) + sizeof ( TCell ) - 1 ) / sizeof ( TCell ); ras.cell_free = buffer + n; ras.cell = ras.cell_null; ras.min_ey = band[1]; ras.max_ey = band[0]; ras.count_ey = width; error = gray_convert_glyph_inner( RAS_VAR, continued ); continued = 1; if ( !error ) { if ( ras.render_span ) /* for FT_RASTER_FLAG_DIRECT only */ gray_sweep_direct( RAS_VAR ); else gray_sweep( RAS_VAR ); band--; continue; } else if ( error != Smooth_Err_Raster_Overflow ) return error; /* render pool overflow; we will reduce the render band by half */ width >>= 1; /* this should never happen even with tiny rendering pool */ if ( width == 0 ) { FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" )); return FT_THROW( Raster_Overflow ); } band++; band[1] = band[0]; band[0] += width; } while ( band >= bands ); } return Smooth_Err_Ok; } static int gray_raster_render( FT_Raster raster, const FT_Raster_Params* params ) { const FT_Outline* outline = (const FT_Outline*)params->source; const FT_Bitmap* target_map = params->target; #ifndef FT_STATIC_RASTER gray_TWorker worker[1]; #endif if ( !raster ) return FT_THROW( Invalid_Argument ); /* this version does not support monochrome rendering */ if ( !( params->flags & FT_RASTER_FLAG_AA ) ) return FT_THROW( Cannot_Render_Glyph ); if ( !outline ) return FT_THROW( Invalid_Outline ); /* return immediately if the outline is empty */ if ( outline->n_points == 0 || outline->n_contours <= 0 ) return Smooth_Err_Ok; if ( !outline->contours || !outline->points ) return FT_THROW( Invalid_Outline ); if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 ) return FT_THROW( Invalid_Outline ); ras.outline = *outline; if ( params->flags & FT_RASTER_FLAG_DIRECT ) { if ( !params->gray_spans ) return Smooth_Err_Ok; ras.render_span = (FT_Raster_Span_Func)params->gray_spans; ras.render_span_data = params->user; ras.min_ex = params->clip_box.xMin; ras.min_ey = params->clip_box.yMin; ras.max_ex = params->clip_box.xMax; ras.max_ey = params->clip_box.yMax; } else { /* if direct mode is not set, we must have a target bitmap */ if ( !target_map ) return FT_THROW( Invalid_Argument ); /* nothing to do */ if ( !target_map->width || !target_map->rows ) return Smooth_Err_Ok; if ( !target_map->buffer ) return FT_THROW( Invalid_Argument ); if ( target_map->pitch < 0 ) ras.target.origin = target_map->buffer; else ras.target.origin = target_map->buffer + ( target_map->rows - 1 ) * (unsigned int)target_map->pitch; ras.target.pitch = target_map->pitch; ras.render_span = (FT_Raster_Span_Func)NULL; ras.render_span_data = NULL; ras.min_ex = 0; ras.min_ey = 0; ras.max_ex = (FT_Pos)target_map->width; ras.max_ey = (FT_Pos)target_map->rows; } /* exit if nothing to do */ if ( ras.max_ex <= ras.min_ex || ras.max_ey <= ras.min_ey ) return Smooth_Err_Ok; return gray_convert_glyph( RAS_VAR ); } /**** RASTER OBJECT CREATION: In stand-alone mode, we simply use *****/ /**** a static object. *****/ #ifdef STANDALONE_ static int gray_raster_new( void* memory, FT_Raster* araster ) { static gray_TRaster the_raster; FT_UNUSED( memory ); *araster = (FT_Raster)&the_raster; FT_ZERO( &the_raster ); return 0; } static void gray_raster_done( FT_Raster raster ) { /* nothing */ FT_UNUSED( raster ); } #else /* !STANDALONE_ */ static int gray_raster_new( FT_Memory memory, gray_PRaster* araster ) { FT_Error error; gray_PRaster raster = NULL; if ( !FT_NEW( raster ) ) raster->memory = memory; *araster = raster; return error; } static void gray_raster_done( FT_Raster raster ) { FT_Memory memory = (FT_Memory)((gray_PRaster)raster)->memory; FT_FREE( raster ); } #endif /* !STANDALONE_ */ static void gray_raster_reset( FT_Raster raster, unsigned char* pool_base, unsigned long pool_size ) { FT_UNUSED( raster ); FT_UNUSED( pool_base ); FT_UNUSED( pool_size ); } static int gray_raster_set_mode( FT_Raster raster, unsigned long mode, void* args ) { FT_UNUSED( raster ); FT_UNUSED( mode ); FT_UNUSED( args ); return 0; /* nothing to do */ } FT_DEFINE_RASTER_FUNCS( ft_grays_raster, FT_GLYPH_FORMAT_OUTLINE, (FT_Raster_New_Func) gray_raster_new, /* raster_new */ (FT_Raster_Reset_Func) gray_raster_reset, /* raster_reset */ (FT_Raster_Set_Mode_Func)gray_raster_set_mode, /* raster_set_mode */ (FT_Raster_Render_Func) gray_raster_render, /* raster_render */ (FT_Raster_Done_Func) gray_raster_done /* raster_done */ ) /* END */ /* Local Variables: */ /* coding: utf-8 */ /* End: */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/ftgrays.c
C++
gpl-3.0
62,168
/**************************************************************************** * * ftgrays.h * * FreeType smooth renderer declaration * * Copyright (C) 1996-2022 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 FTGRAYS_H_ #define FTGRAYS_H_ #ifdef __cplusplus extern "C" { #endif #ifdef STANDALONE_ #include "ftimage.h" #else #include <ft2build.h> #include <freetype/ftimage.h> #endif /************************************************************************** * * To make ftgrays.h independent from configuration files we check * whether FT_EXPORT_VAR has been defined already. * * On some systems and compilers (Win32 mostly), an extra keyword is * necessary to compile the library as a DLL. */ #ifndef FT_EXPORT_VAR #define FT_EXPORT_VAR( x ) extern x #endif FT_EXPORT_VAR( const FT_Raster_Funcs ) ft_grays_raster; #ifdef __cplusplus } #endif #endif /* FTGRAYS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/ftgrays.h
C++
gpl-3.0
1,260
/**************************************************************************** * * ftsmerrs.h * * smooth renderer error codes (specification only). * * Copyright (C) 2001-2022 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. * */ /************************************************************************** * * This file is used to define the smooth renderer error enumeration * constants. * */ #ifndef FTSMERRS_H_ #define FTSMERRS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX Smooth_Err_ #define FT_ERR_BASE FT_Mod_Err_Smooth #include <freetype/fterrors.h> #endif /* FTSMERRS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/ftsmerrs.h
C++
gpl-3.0
997
/**************************************************************************** * * ftsmooth.c * * Anti-aliasing renderer interface (body). * * Copyright (C) 2000-2022 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftobjs.h> #include <freetype/ftoutln.h> #include "ftsmooth.h" #include "ftgrays.h" #include "ftsmerrs.h" /* sets render-specific mode */ static FT_Error ft_smooth_set_mode( FT_Renderer render, FT_ULong mode_tag, FT_Pointer data ) { /* we simply pass it to the raster */ return render->clazz->raster_class->raster_set_mode( render->raster, mode_tag, data ); } /* transform a given glyph image */ static FT_Error ft_smooth_transform( FT_Renderer render, FT_GlyphSlot slot, const FT_Matrix* matrix, const FT_Vector* delta ) { FT_Error error = FT_Err_Ok; if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( matrix ) FT_Outline_Transform( &slot->outline, matrix ); if ( delta ) FT_Outline_Translate( &slot->outline, delta->x, delta->y ); Exit: return error; } /* return the glyph's control box */ static void ft_smooth_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox ) { FT_ZERO( cbox ); if ( slot->format == render->glyph_format ) FT_Outline_Get_CBox( &slot->outline, cbox ); } typedef struct TOrigin_ { unsigned char* origin; /* pixmap origin at the bottom-left */ int pitch; /* pitch to go down one row */ } TOrigin; #ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING /* initialize renderer -- init its raster */ static FT_Error ft_smooth_init( FT_Renderer render ) { FT_Vector* sub = render->root.library->lcd_geometry; /* set up default subpixel geometry for striped RGB panels. */ sub[0].x = -21; sub[0].y = 0; sub[1].x = 0; sub[1].y = 0; sub[2].x = 21; sub[2].y = 0; render->clazz->raster_class->raster_reset( render->raster, NULL, 0 ); return 0; } /* This function writes every third byte in direct rendering mode */ static void ft_smooth_lcd_spans( int y, int count, const FT_Span* spans, TOrigin* target ) { unsigned char* dst_line = target->origin - y * target->pitch; unsigned char* dst; unsigned short w; for ( ; count--; spans++ ) for ( dst = dst_line + spans->x * 3, w = spans->len; w--; dst += 3 ) *dst = spans->coverage; } static FT_Error ft_smooth_raster_lcd( FT_Renderer render, FT_Outline* outline, FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Vector* sub = render->root.library->lcd_geometry; FT_Pos x, y; FT_Raster_Params params; TOrigin target; /* Render 3 separate coverage bitmaps, shifting the outline. */ /* Set up direct rendering to record them on each third byte. */ params.source = outline; params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT; params.gray_spans = (FT_SpanFunc)ft_smooth_lcd_spans; params.user = &target; params.clip_box.xMin = 0; params.clip_box.yMin = 0; params.clip_box.xMax = bitmap->width; params.clip_box.yMax = bitmap->rows; if ( bitmap->pitch < 0 ) target.origin = bitmap->buffer; else target.origin = bitmap->buffer + ( bitmap->rows - 1 ) * (unsigned int)bitmap->pitch; target.pitch = bitmap->pitch; FT_Outline_Translate( outline, -sub[0].x, -sub[0].y ); error = render->raster_render( render->raster, &params ); x = sub[0].x; y = sub[0].y; if ( error ) goto Exit; target.origin++; FT_Outline_Translate( outline, sub[0].x - sub[1].x, sub[0].y - sub[1].y ); error = render->raster_render( render->raster, &params ); x = sub[1].x; y = sub[1].y; if ( error ) goto Exit; target.origin++; FT_Outline_Translate( outline, sub[1].x - sub[2].x, sub[1].y - sub[2].y ); error = render->raster_render( render->raster, &params ); x = sub[2].x; y = sub[2].y; Exit: FT_Outline_Translate( outline, x, y ); return error; } static FT_Error ft_smooth_raster_lcdv( FT_Renderer render, FT_Outline* outline, FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; int pitch = bitmap->pitch; FT_Vector* sub = render->root.library->lcd_geometry; FT_Pos x, y; FT_Raster_Params params; params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_AA; /* Render 3 separate coverage bitmaps, shifting the outline. */ /* Notice that the subpixel geometry vectors are rotated. */ /* Triple the pitch to render on each third row. */ bitmap->pitch *= 3; bitmap->rows /= 3; FT_Outline_Translate( outline, -sub[0].y, sub[0].x ); error = render->raster_render( render->raster, &params ); x = sub[0].y; y = -sub[0].x; if ( error ) goto Exit; bitmap->buffer += pitch; FT_Outline_Translate( outline, sub[0].y - sub[1].y, sub[1].x - sub[0].x ); error = render->raster_render( render->raster, &params ); x = sub[1].y; y = -sub[1].x; bitmap->buffer -= pitch; if ( error ) goto Exit; bitmap->buffer += 2 * pitch; FT_Outline_Translate( outline, sub[1].y - sub[2].y, sub[2].x - sub[1].x ); error = render->raster_render( render->raster, &params ); x = sub[2].y; y = -sub[2].x; bitmap->buffer -= 2 * pitch; Exit: FT_Outline_Translate( outline, x, y ); bitmap->pitch /= 3; bitmap->rows *= 3; return error; } #else /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ /* initialize renderer -- init its raster */ static FT_Error ft_smooth_init( FT_Renderer render ) { /* set up default LCD filtering */ FT_Library_SetLcdFilter( render->root.library, FT_LCD_FILTER_DEFAULT ); render->clazz->raster_class->raster_reset( render->raster, NULL, 0 ); return 0; } static FT_Error ft_smooth_raster_lcd( FT_Renderer render, FT_Outline* outline, FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Vector* points = outline->points; FT_Vector* points_end = FT_OFFSET( points, outline->n_points ); FT_Vector* vec; FT_Raster_Params params; params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_AA; /* implode outline */ for ( vec = points; vec < points_end; vec++ ) vec->x *= 3; /* render outline into the bitmap */ error = render->raster_render( render->raster, &params ); /* deflate outline */ for ( vec = points; vec < points_end; vec++ ) vec->x /= 3; return error; } static FT_Error ft_smooth_raster_lcdv( FT_Renderer render, FT_Outline* outline, FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Vector* points = outline->points; FT_Vector* points_end = FT_OFFSET( points, outline->n_points ); FT_Vector* vec; FT_Raster_Params params; params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_AA; /* implode outline */ for ( vec = points; vec < points_end; vec++ ) vec->y *= 3; /* render outline into the bitmap */ error = render->raster_render( render->raster, &params ); /* deflate outline */ for ( vec = points; vec < points_end; vec++ ) vec->y /= 3; return error; } #endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ /* Oversampling scale to be used in rendering overlaps */ #define SCALE ( 1 << 2 ) /* This function averages inflated spans in direct rendering mode */ static void ft_smooth_overlap_spans( int y, int count, const FT_Span* spans, TOrigin* target ) { unsigned char* dst = target->origin - ( y / SCALE ) * target->pitch; unsigned short x; unsigned int cover, sum; /* When accumulating the oversampled spans we need to assure that */ /* fully covered pixels are equal to 255 and do not overflow. */ /* It is important that the SCALE is a power of 2, each subpixel */ /* cover can also reach a power of 2 after rounding, and the total */ /* is clamped to 255 when it adds up to 256. */ for ( ; count--; spans++ ) { cover = ( spans->coverage + SCALE * SCALE / 2 ) / ( SCALE * SCALE ); for ( x = 0; x < spans->len; x++ ) { sum = dst[( spans->x + x ) / SCALE] + cover; dst[( spans->x + x ) / SCALE] = (unsigned char)( sum - ( sum >> 8 ) ); } } } static FT_Error ft_smooth_raster_overlap( FT_Renderer render, FT_Outline* outline, FT_Bitmap* bitmap ) { FT_Error error = FT_Err_Ok; FT_Vector* points = outline->points; FT_Vector* points_end = FT_OFFSET( points, outline->n_points ); FT_Vector* vec; FT_Raster_Params params; TOrigin target; /* Reject outlines that are too wide for 16-bit FT_Span. */ /* Other limits are applied upstream with the same error code. */ if ( bitmap->width * SCALE > 0x7FFF ) return FT_THROW( Raster_Overflow ); /* Set up direct rendering to average oversampled spans. */ params.source = outline; params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT; params.gray_spans = (FT_SpanFunc)ft_smooth_overlap_spans; params.user = &target; params.clip_box.xMin = 0; params.clip_box.yMin = 0; params.clip_box.xMax = bitmap->width * SCALE; params.clip_box.yMax = bitmap->rows * SCALE; if ( bitmap->pitch < 0 ) target.origin = bitmap->buffer; else target.origin = bitmap->buffer + ( bitmap->rows - 1 ) * (unsigned int)bitmap->pitch; target.pitch = bitmap->pitch; /* inflate outline */ for ( vec = points; vec < points_end; vec++ ) { vec->x *= SCALE; vec->y *= SCALE; } /* render outline into the bitmap */ error = render->raster_render( render->raster, &params ); /* deflate outline */ for ( vec = points; vec < points_end; vec++ ) { vec->x /= SCALE; vec->y /= SCALE; } return error; } #undef SCALE static FT_Error ft_smooth_render( FT_Renderer render, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) { FT_Error error = FT_Err_Ok; FT_Outline* outline = &slot->outline; FT_Bitmap* bitmap = &slot->bitmap; FT_Memory memory = render->root.memory; FT_Pos x_shift = 0; FT_Pos y_shift = 0; /* check glyph image format */ if ( slot->format != render->glyph_format ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* check mode */ if ( mode != FT_RENDER_MODE_NORMAL && mode != FT_RENDER_MODE_LIGHT && mode != FT_RENDER_MODE_LCD && mode != FT_RENDER_MODE_LCD_V ) { error = FT_THROW( Cannot_Render_Glyph ); goto Exit; } /* release old bitmap buffer */ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) ) { error = FT_THROW( Raster_Overflow ); goto Exit; } if ( !bitmap->rows || !bitmap->pitch ) goto Exit; /* allocate new one */ if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) ) goto Exit; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; x_shift = 64 * -slot->bitmap_left; y_shift = 64 * -slot->bitmap_top; if ( bitmap->pixel_mode == FT_PIXEL_MODE_LCD_V ) y_shift += 64 * (FT_Int)bitmap->rows / 3; else y_shift += 64 * (FT_Int)bitmap->rows; if ( origin ) { x_shift += origin->x; y_shift += origin->y; } /* translate outline to render it into the bitmap */ if ( x_shift || y_shift ) FT_Outline_Translate( outline, x_shift, y_shift ); if ( mode == FT_RENDER_MODE_NORMAL || mode == FT_RENDER_MODE_LIGHT ) { if ( outline->flags & FT_OUTLINE_OVERLAP ) error = ft_smooth_raster_overlap( render, outline, bitmap ); else { FT_Raster_Params params; params.target = bitmap; params.source = outline; params.flags = FT_RASTER_FLAG_AA; error = render->raster_render( render->raster, &params ); } } else { if ( mode == FT_RENDER_MODE_LCD ) error = ft_smooth_raster_lcd ( render, outline, bitmap ); else if ( mode == FT_RENDER_MODE_LCD_V ) error = ft_smooth_raster_lcdv( render, outline, bitmap ); #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING /* finally apply filtering */ { FT_Byte* lcd_weights; FT_Bitmap_LcdFilterFunc lcd_filter_func; /* Per-face LCD filtering takes priority if set up. */ if ( slot->face && slot->face->internal->lcd_filter_func ) { lcd_weights = slot->face->internal->lcd_weights; lcd_filter_func = slot->face->internal->lcd_filter_func; } else { lcd_weights = slot->library->lcd_weights; lcd_filter_func = slot->library->lcd_filter_func; } if ( lcd_filter_func ) lcd_filter_func( bitmap, lcd_weights ); } #endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ } Exit: if ( !error ) { /* everything is fine; the glyph is now officially a bitmap */ slot->format = FT_GLYPH_FORMAT_BITMAP; } else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { FT_FREE( bitmap->buffer ); slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } if ( x_shift || y_shift ) FT_Outline_Translate( outline, -x_shift, -y_shift ); return error; } FT_DEFINE_RENDERER( ft_smooth_renderer_class, FT_MODULE_RENDERER, sizeof ( FT_RendererRec ), "smooth", 0x10000L, 0x20000L, NULL, /* module specific interface */ (FT_Module_Constructor)ft_smooth_init, /* module_init */ (FT_Module_Destructor) NULL, /* module_done */ (FT_Module_Requester) NULL, /* get_interface */ FT_GLYPH_FORMAT_OUTLINE, (FT_Renderer_RenderFunc) ft_smooth_render, /* render_glyph */ (FT_Renderer_TransformFunc)ft_smooth_transform, /* transform_glyph */ (FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox, /* get_glyph_cbox */ (FT_Renderer_SetModeFunc) ft_smooth_set_mode, /* set_mode */ (FT_Raster_Funcs*)&ft_grays_raster /* raster_class */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/ftsmooth.c
C++
gpl-3.0
16,336
/**************************************************************************** * * ftsmooth.h * * Anti-aliasing renderer interface (specification). * * Copyright (C) 1996-2022 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 FTSMOOTH_H_ #define FTSMOOTH_H_ #include <freetype/ftrender.h> FT_BEGIN_HEADER FT_DECLARE_RENDERER( ft_smooth_renderer_class ) FT_END_HEADER #endif /* FTSMOOTH_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/ftsmooth.h
C++
gpl-3.0
751
# # FreeType 2 smooth renderer module definition # # Copyright (C) 1996-2022 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. FTMODULE_H_COMMANDS += SMOOTH_RENDERER define SMOOTH_RENDERER $(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/module.mk
mk
gpl-3.0
678
# # FreeType 2 smooth renderer module build rules # # Copyright (C) 1996-2022 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. # smooth driver directory # SMOOTH_DIR := $(SRC_DIR)/smooth # compilation flags for the driver # SMOOTH_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(SMOOTH_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # smooth driver sources (i.e., C files) # SMOOTH_DRV_SRC := $(SMOOTH_DIR)/ftgrays.c \ $(SMOOTH_DIR)/ftsmooth.c # smooth driver headers # SMOOTH_DRV_H := $(SMOOTH_DRV_SRC:%c=%h) \ $(SMOOTH_DIR)/ftsmerrs.h # smooth driver object(s) # # SMOOTH_DRV_OBJ_M is used during `multi' builds. # SMOOTH_DRV_OBJ_S is used during `single' builds. # SMOOTH_DRV_OBJ_M := $(SMOOTH_DRV_SRC:$(SMOOTH_DIR)/%.c=$(OBJ_DIR)/%.$O) SMOOTH_DRV_OBJ_S := $(OBJ_DIR)/smooth.$O # smooth driver source file for single build # SMOOTH_DRV_SRC_S := $(SMOOTH_DIR)/smooth.c # smooth driver - single object # $(SMOOTH_DRV_OBJ_S): $(SMOOTH_DRV_SRC_S) $(SMOOTH_DRV_SRC) \ $(FREETYPE_H) $(SMOOTH_DRV_H) $(SMOOTH_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(SMOOTH_DRV_SRC_S)) # smooth driver - multiple objects # $(OBJ_DIR)/%.$O: $(SMOOTH_DIR)/%.c $(FREETYPE_H) $(SMOOTH_DRV_H) $(SMOOTH_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(SMOOTH_DRV_OBJ_S) DRV_OBJS_M += $(SMOOTH_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/rules.mk
mk
gpl-3.0
1,856
/**************************************************************************** * * smooth.c * * FreeType anti-aliasing rasterer module component (body only). * * Copyright (C) 1996-2022 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "ftgrays.c" #include "ftsmooth.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/smooth/smooth.c
C++
gpl-3.0
657
/**************************************************************************** * * ftsvg.c * * The FreeType SVG renderer interface (body). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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 <freetype/internal/ftdebug.h> #include <freetype/internal/ftserv.h> #include <freetype/internal/services/svprop.h> #include <freetype/otsvg.h> #include <freetype/internal/svginterface.h> #include <freetype/ftbbox.h> #include "ftsvg.h" #include "svgtypes.h" /************************************************************************** * * The macro FT_COMPONENT is used in trace mode. It is an implicit * parameter of the FT_TRACE() and FT_ERROR() macros, usued to print/log * messages during execution. */ #undef FT_COMPONENT #define FT_COMPONENT otsvg #ifdef FT_CONFIG_OPTION_SVG /* ft_svg_init */ static FT_Error ft_svg_init( SVG_Renderer svg_module ) { FT_Error error = FT_Err_Ok; svg_module->loaded = FALSE; svg_module->hooks_set = FALSE; return error; } static void ft_svg_done( SVG_Renderer svg_module ) { if ( svg_module->loaded == TRUE && svg_module->hooks_set == TRUE ) svg_module->hooks.free_svg( &svg_module->state ); svg_module->loaded = FALSE; } static FT_Error ft_svg_preset_slot( FT_Module module, FT_GlyphSlot slot, FT_Bool cache ) { SVG_Renderer svg_renderer = (SVG_Renderer)module; SVG_RendererHooks hooks = svg_renderer->hooks; if ( svg_renderer->hooks_set == FALSE ) { FT_TRACE1(( "Hooks are NOT set. Can't render OT-SVG glyphs\n" )); return FT_THROW( Missing_SVG_Hooks ); } if ( svg_renderer->loaded == FALSE ) { FT_TRACE3(( "ft_svg_preset_slot: first presetting call," " calling init hook\n" )); hooks.init_svg( &svg_renderer->state ); svg_renderer->loaded = TRUE; } return hooks.preset_slot( slot, cache, &svg_renderer->state ); } static FT_Error ft_svg_render( FT_Renderer renderer, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) { SVG_Renderer svg_renderer = (SVG_Renderer)renderer; FT_Library library = renderer->root.library; FT_Memory memory = library->memory; FT_Error error; FT_ULong size_image_buffer; SVG_RendererHooks hooks = svg_renderer->hooks; FT_UNUSED( mode ); FT_UNUSED( origin ); if ( mode != FT_RENDER_MODE_NORMAL ) return FT_THROW( Bad_Argument ); if ( svg_renderer->hooks_set == FALSE ) { FT_TRACE1(( "Hooks are NOT set. Can't render OT-SVG glyphs\n" )); return FT_THROW( Missing_SVG_Hooks ); } if ( svg_renderer->loaded == FALSE ) { FT_TRACE3(( "ft_svg_render: first rendering, calling init hook\n" )); error = hooks.init_svg( &svg_renderer->state ); svg_renderer->loaded = TRUE; } ft_svg_preset_slot( (FT_Module)renderer, slot, TRUE ); size_image_buffer = (FT_ULong)slot->bitmap.pitch * slot->bitmap.rows; /* No `FT_QALLOC` here since we need a clean, empty canvas */ /* to start with. */ if ( FT_ALLOC( slot->bitmap.buffer, size_image_buffer ) ) return error; error = hooks.render_svg( slot, &svg_renderer->state ); if ( error ) FT_FREE( slot->bitmap.buffer ); else slot->internal->flags |= FT_GLYPH_OWN_BITMAP; return error; } static const SVG_Interface svg_interface = { (Preset_Bitmap_Func)ft_svg_preset_slot }; static FT_Error ft_svg_property_set( FT_Module module, const char* property_name, const void* value, FT_Bool value_is_string ) { FT_Error error = FT_Err_Ok; SVG_Renderer renderer = (SVG_Renderer)module; if ( !ft_strcmp( property_name, "svg-hooks" ) ) { SVG_RendererHooks* hooks; if ( value_is_string == TRUE ) { error = FT_THROW( Invalid_Argument ); goto Exit; } hooks = (SVG_RendererHooks*)value; if ( !hooks->init_svg || !hooks->free_svg || !hooks->render_svg || !hooks->preset_slot ) { FT_TRACE0(( "ft_svg_property_set:" " SVG rendering hooks not set because\n" )); FT_TRACE0(( " " " at least one function pointer is NULL\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } renderer->hooks = *hooks; renderer->hooks_set = TRUE; } else error = FT_THROW( Missing_Property ); Exit: return error; } static FT_Error ft_svg_property_get( FT_Module module, const char* property_name, const void* value ) { FT_Error error = FT_Err_Ok; SVG_Renderer renderer = (SVG_Renderer)module; if ( !ft_strcmp( property_name, "svg-hooks" ) ) { SVG_RendererHooks* hooks = (SVG_RendererHooks*)value; *hooks = renderer->hooks; } else error = FT_THROW( Missing_Property ); return error; } FT_DEFINE_SERVICE_PROPERTIESREC( ft_svg_service_properties, (FT_Properties_SetFunc)ft_svg_property_set, /* set_property */ (FT_Properties_GetFunc)ft_svg_property_get /* get_property */ ) FT_DEFINE_SERVICEDESCREC1( ft_svg_services, FT_SERVICE_ID_PROPERTIES, &ft_svg_service_properties ) FT_CALLBACK_DEF( FT_Module_Interface ) ft_svg_get_interface( FT_Module module, const char* ft_svg_interface ) { FT_Module_Interface result; FT_UNUSED( module ); result = ft_service_list_lookup( ft_svg_services, ft_svg_interface ); if ( result ) return result; return 0; } static FT_Error ft_svg_transform( FT_Renderer renderer, FT_GlyphSlot slot, const FT_Matrix* _matrix, const FT_Vector* _delta ) { FT_SVG_Document doc = (FT_SVG_Document)slot->other; FT_Matrix* matrix = (FT_Matrix*)_matrix; FT_Vector* delta = (FT_Vector*)_delta; FT_Matrix tmp_matrix; FT_Vector tmp_delta; FT_Matrix a, b; FT_Pos x, y; FT_UNUSED( renderer ); if ( !matrix ) { tmp_matrix.xx = 0x10000; tmp_matrix.xy = 0; tmp_matrix.yx = 0; tmp_matrix.yy = 0x10000; matrix = &tmp_matrix; } if ( !delta ) { tmp_delta.x = 0; tmp_delta.y = 0; delta = &tmp_delta; } a = doc->transform; b = *matrix; FT_Matrix_Multiply( &b, &a ); x = ADD_LONG( ADD_LONG( FT_MulFix( matrix->xx, doc->delta.x ), FT_MulFix( matrix->xy, doc->delta.y ) ), delta->x ); y = ADD_LONG( ADD_LONG( FT_MulFix( matrix->yx, doc->delta.x ), FT_MulFix( matrix->yy, doc->delta.y ) ), delta->y ); doc->delta.x = x; doc->delta.y = y; doc->transform = a; return FT_Err_Ok; } #endif /* FT_CONFIG_OPTION_SVG */ #ifdef FT_CONFIG_OPTION_SVG #define PUT_SVG_MODULE( a ) a #define SVG_GLYPH_FORMAT FT_GLYPH_FORMAT_SVG #else #define PUT_SVG_MODULE( a ) NULL #define SVG_GLYPH_FORMAT FT_GLYPH_FORMAT_NONE #endif FT_DEFINE_RENDERER( ft_svg_renderer_class, FT_MODULE_RENDERER, sizeof ( SVG_RendererRec ), "ot-svg", 0x10000L, 0x20000L, (const void*)PUT_SVG_MODULE( &svg_interface ), /* module specific interface */ (FT_Module_Constructor)PUT_SVG_MODULE( ft_svg_init ), /* module_init */ (FT_Module_Destructor)PUT_SVG_MODULE( ft_svg_done ), /* module_done */ PUT_SVG_MODULE( ft_svg_get_interface ), /* get_interface */ SVG_GLYPH_FORMAT, (FT_Renderer_RenderFunc) PUT_SVG_MODULE( ft_svg_render ), /* render_glyph */ (FT_Renderer_TransformFunc)PUT_SVG_MODULE( ft_svg_transform ), /* transform_glyph */ NULL, /* get_glyph_cbox */ NULL, /* set_mode */ NULL /* raster_class */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/ftsvg.c
C++
gpl-3.0
8,833
/**************************************************************************** * * ftsvg.h * * The FreeType SVG renderer interface (specification). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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 FTSVG_H_ #define FTSVG_H_ #include <ft2build.h> #include <freetype/ftrender.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER FT_DECLARE_RENDERER( ft_svg_renderer_class ) FT_END_HEADER #endif /* FTSVG_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/ftsvg.h
C++
gpl-3.0
805
# # FreeType 2 SVG renderer module definition # # Copyright (C) 2022 by # David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. # # 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. FTMODULE_H_COMMANDS += SVG_MODULE define SVG_MODULE $(OPEN_DRIVER) FT_Renderer_Class, ft_svg_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)ot-svg $(ECHO_DRIVER_DESC)OT-SVG glyph renderer module$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/module.mk
mk
gpl-3.0
672
# # FreeType 2 SVG renderer module build rules # # Copyright (C) 2022 by # David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. # # 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. # SVG renderer driver directory # SVG_DIR := $(SRC_DIR)/svg # compilation flags for the driver # SVG_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(SVG_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # SVG renderer sources (i.e., C files) # SVG_DRV_SRC := $(SVG_DIR)/ftsvg.c # SVG renderer headers # SVG_DRV_H := $(SVG_DIR)/ftsvg.h \ $(SVG_DIR)/svgtypes.h # SVG renderer object(s) # # SVG_DRV_OBJ_M is used during `multi' builds. # SVG_DRV_OBJ_S is used during `single' builds. # SVG_DRV_OBJ_M := $(SVG_DRV_SRC:$(SVG_DIR)/%.c=$(OBJ_DIR)/%.$O) SVG_DRV_OBJ_S := $(OBJ_DIR)/svg.$O # SVG renderer source file for single build # SVG_DRV_SRC_S := $(SVG_DIR)/svg.c # SVG renderer - single object # $(SVG_DRV_OBJ_S): $(SVG_DRV_SRC_S) $(SVG_DRV_SRC) \ $(FREETYPE_H) $(SVG_DRV_H) $(SVG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(SVG_DRV_SRC_S)) # SVG renderer - multiple objects # $(OBJ_DIR)/%.$O: $(SVG_DIR)/%.c $(FREETYPE_H) $(SVG_DRV_H) $(SVG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(SVG_DRV_OBJ_S) DRV_OBJS_M += $(SVG_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/rules.mk
mk
gpl-3.0
1,702
/**************************************************************************** * * svg.c * * FreeType SVG renderer module component (body only). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "svgtypes.h" #include "ftsvg.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/svg.c
C++
gpl-3.0
651
/**************************************************************************** * * svgtypes.h * * The FreeType SVG renderer internal types (specification). * * Copyright (C) 2022 by * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti. * * 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 SVGTYPES_H_ #define SVGTYPES_H_ #include <ft2build.h> #include <freetype/internal/ftobjs.h> #include <freetype/ftrender.h> #include <freetype/otsvg.h> typedef struct SVG_RendererRec_ { FT_RendererRec root; /* this inherits FT_RendererRec */ FT_Bool loaded; FT_Bool hooks_set; SVG_RendererHooks hooks; /* this holds hooks for SVG rendering */ FT_Pointer state; /* a place for hooks to store state, if needed */ } SVG_RendererRec; typedef struct SVG_RendererRec_* SVG_Renderer; #endif /* SVGTYPES_H_ */ /* EOF */
whupdup/frame
real/third_party/freetype-2.12.0/src/svg/svgtypes.h
C++
gpl-3.0
1,190
#! /usr/bin/perl -w # -*- Perl -*- # # afblue.pl # # Process a blue zone character data file. # # Copyright (C) 2013-2022 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. use strict; use warnings; use English '-no_match_vars'; use open ':std', ':encoding(UTF-8)'; my $prog = $PROGRAM_NAME; $prog =~ s| .* / ||x; # Remove path. die "usage: $prog datafile < infile > outfile\n" if $#ARGV != 0; my $datafile = $ARGV[0]; my %diversions; # The extracted and massaged data from `datafile'. my @else_stack; # Booleans to track else-clauses. my @name_stack; # Stack of integers used for names of aux. variables. my $curr_enum; # Name of the current enumeration. my $curr_array; # Name of the current array. my $curr_max; # Name of the current maximum value. my $curr_enum_element; # Name of the current enumeration element. my $curr_offset; # The offset relative to current aux. variable. my $curr_elem_size; # The number of non-space characters in the current string or # the number of elements in the current block. my $have_sections = 0; # Boolean; set if start of a section has been seen. my $have_strings; # Boolean; set if current section contains strings. my $have_blocks; # Boolean; set if current section contains blocks. my $have_enum_element; # Boolean; set if we have an enumeration element. my $in_string; # Boolean; set if a string has been parsed. my $num_sections = 0; # Number of sections seen so far. my $last_aux; # Name of last auxiliary variable. # Regular expressions. # [<ws>] <enum_name> <ws> <array_name> <ws> <max_name> [<ws>] ':' [<ws>] '\n' my $section_re = qr/ ^ \s* (\S+) \s+ (\S+) \s+ (\S+) \s* : \s* $ /x; # [<ws>] <enum_element_name> [<ws>] '\n' my $enum_element_re = qr/ ^ \s* ( [A-Za-z0-9_]+ ) \s* $ /x; # '#' <preprocessor directive> '\n' my $preprocessor_re = qr/ ^ \# /x; # [<ws>] '/' '/' <comment> '\n' my $comment_re = qr| ^ \s* // |x; # empty line my $whitespace_only_re = qr/ ^ \s* $ /x; # [<ws>] '"' <string> '"' [<ws>] '\n' (<string> doesn't contain newlines) my $string_re = qr/ ^ \s* " ( (?> (?: (?> [^"\\]+ ) | \\. )* ) ) " \s* $ /x; # [<ws>] '{' <block> '}' [<ws>] '\n' (<block> can contain newlines) my $block_start_re = qr/ ^ \s* \{ /x; # We need the capturing group for `split' to make it return the separator # tokens (i.e., the opening and closing brace) also. my $brace_re = qr/ ( [{}] ) /x; sub Warn { my $message = shift; warn "$datafile:$INPUT_LINE_NUMBER: warning: $message\n"; } sub Die { my $message = shift; die "$datafile:$INPUT_LINE_NUMBER: error: $message\n"; } my $warned_before = 0; sub warn_before { Warn("data before first section gets ignored") unless $warned_before; $warned_before = 1; } sub strip_newline { chomp; s/ \x0D $ //x; } sub end_curr_string { # Append final null byte to string. if ($have_strings) { push @{$diversions{$curr_array}}, " '\\0',\n" if $in_string; $curr_offset++; $in_string = 0; } } sub update_max_elem_size { if ($curr_elem_size) { my $max = pop @{$diversions{$curr_max}}; $max = $curr_elem_size if $curr_elem_size > $max; push @{$diversions{$curr_max}}, $max; } } sub convert_non_ascii_char { # A UTF-8 character outside of the printable ASCII range, with possibly a # leading backslash character. my $s = shift; # Here we count characters, not bytes. $curr_elem_size += length $s; utf8::encode($s); $s = uc unpack 'H*', $s; $curr_offset += $s =~ s/\G(..)/'\\x$1', /sg; return $s; } sub convert_ascii_chars { # A series of ASCII characters in the printable range. my $s = shift; # We reduce multiple space characters to a single one. $s =~ s/ +/ /g; # Count all non-space characters. Note that `()' applies a list context # to the capture that is used to count the elements. $curr_elem_size += () = $s =~ /[^ ]/g; $curr_offset += $s =~ s/\G(.)/'$1', /g; return $s; } sub convert_literal { my $s = shift; my $orig = $s; # ASCII printables and space my $safe_re = '\x20-\x7E'; # ASCII printables and space, no backslash my $safe_no_backslash_re = '\x20-\x5B\x5D-\x7E'; $s =~ s{ (?: \\? ( [^$safe_re] ) | ( (?: [$safe_no_backslash_re] | \\ [$safe_re] )+ ) ) } { defined($1) ? convert_non_ascii_char($1) : convert_ascii_chars($2) }egx; # We assume that `$orig' doesn't contain `*/' return $s . " /* $orig */"; } sub aux_name { return "af_blue_" . $num_sections. "_" . join('_', @name_stack); } sub aux_name_next { $name_stack[$#name_stack]++; my $name = aux_name(); $name_stack[$#name_stack]--; return $name; } sub enum_val_string { # Build string that holds code to save the current offset in an # enumeration element. my $aux = shift; my $add = ($last_aux eq "af_blue_" . $num_sections . "_0" ) ? "" : "$last_aux + "; return " $aux = $add$curr_offset,\n"; } # Process data file. open(DATA, $datafile) || die "$prog: can't open \`$datafile': $OS_ERROR\n"; while (<DATA>) { strip_newline(); next if /$comment_re/; next if /$whitespace_only_re/; if (/$section_re/) { Warn("previous section is empty") if ($have_sections && !$have_strings && !$have_blocks); end_curr_string(); update_max_elem_size(); # Save captured groups from `section_re'. $curr_enum = $1; $curr_array = $2; $curr_max = $3; $curr_enum_element = ""; $curr_offset = 0; Warn("overwriting already defined enumeration \`$curr_enum'") if exists($diversions{$curr_enum}); Warn("overwriting already defined array \`$curr_array'") if exists($diversions{$curr_array}); Warn("overwriting already defined maximum value \`$curr_max'") if exists($diversions{$curr_max}); $diversions{$curr_enum} = []; $diversions{$curr_array} = []; $diversions{$curr_max} = []; push @{$diversions{$curr_max}}, 0; @name_stack = (); push @name_stack, 0; $have_sections = 1; $have_strings = 0; $have_blocks = 0; $have_enum_element = 0; $in_string = 0; $num_sections++; $curr_elem_size = 0; $last_aux = aux_name(); next; } if (/$preprocessor_re/) { if ($have_sections) { # Having preprocessor conditionals complicates the computation of # correct offset values. We have to introduce auxiliary enumeration # elements with the name `af_blue_<s>_<n1>_<n2>_...' that store # offsets to be used in conditional clauses. `<s>' is the number of # sections seen so far, `<n1>' is the number of `#if' and `#endif' # conditionals seen so far in the topmost level, `<n2>' the number of # `#if' and `#endif' conditionals seen so far one level deeper, etc. # As a consequence, uneven values are used within a clause, and even # values after a clause, since the C standard doesn't allow the # redefinition of an enumeration value. For example, the name # `af_blue_5_1_6' is used to construct enumeration values in the fifth # section after the third (second-level) if-clause within the first # (top-level) if-clause. After the first top-level clause has # finished, `af_blue_5_2' is used. The current offset is then # relative to the value stored in the current auxiliary element. if (/ ^ \# \s* if /x) { push @else_stack, 0; $name_stack[$#name_stack]++; push @{$diversions{$curr_enum}}, enum_val_string(aux_name()); $last_aux = aux_name(); push @name_stack, 0; $curr_offset = 0; } elsif (/ ^ \# \s* elif /x) { Die("unbalanced #elif") unless @else_stack; pop @name_stack; push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next()); $last_aux = aux_name(); push @name_stack, 0; $curr_offset = 0; } elsif (/ ^ \# \s* else /x) { my $prev_else = pop @else_stack; Die("unbalanced #else") unless defined($prev_else); Die("#else already seen") if $prev_else; push @else_stack, 1; pop @name_stack; push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next()); $last_aux = aux_name(); push @name_stack, 0; $curr_offset = 0; } elsif (/ ^ (\# \s*) endif /x) { my $prev_else = pop @else_stack; Die("unbalanced #endif") unless defined($prev_else); pop @name_stack; # If there is no else-clause for an if-clause, we add one. This is # necessary to have correct offsets. if (!$prev_else) { # Use amount of whitespace from `endif'. push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next()) . $1 . "else\n"; $last_aux = aux_name(); $curr_offset = 0; } $name_stack[$#name_stack]++; push @{$diversions{$curr_enum}}, enum_val_string(aux_name()); $last_aux = aux_name(); $curr_offset = 0; } # Handle (probably continued) preprocessor lines. CONTINUED_LOOP: { do { strip_newline(); push @{$diversions{$curr_enum}}, $ARG . "\n"; push @{$diversions{$curr_array}}, $ARG . "\n"; last CONTINUED_LOOP unless / \\ $ /x; } while (<DATA>); } } else { warn_before(); } next; } if (/$enum_element_re/) { end_curr_string(); update_max_elem_size(); $curr_enum_element = $1; $have_enum_element = 1; $curr_elem_size = 0; next; } if (/$string_re/) { if ($have_sections) { Die("strings and blocks can't be mixed in a section") if $have_blocks; # Save captured group from `string_re'. my $string = $1; if ($have_enum_element) { push @{$diversions{$curr_enum}}, enum_val_string($curr_enum_element); $have_enum_element = 0; } $string = convert_literal($string); push @{$diversions{$curr_array}}, " $string\n"; $have_strings = 1; $in_string = 1; } else { warn_before(); } next; } if (/$block_start_re/) { if ($have_sections) { Die("strings and blocks can't be mixed in a section") if $have_strings; my $depth = 0; my $block = ""; my $block_end = 0; # Count braces while getting the block. BRACE_LOOP: { do { strip_newline(); foreach my $substring (split(/$brace_re/)) { if ($block_end) { Die("invalid data after last matching closing brace") if $substring !~ /$whitespace_only_re/; } $block .= $substring; if ($substring eq '{') { $depth++; } elsif ($substring eq '}') { $depth--; $block_end = 1 if $depth == 0; } } # If we are here, we have run out of substrings, so get next line # or exit. last BRACE_LOOP if $block_end; $block .= "\n"; } while (<DATA>); } if ($have_enum_element) { push @{$diversions{$curr_enum}}, enum_val_string($curr_enum_element); $have_enum_element = 0; } push @{$diversions{$curr_array}}, $block . ",\n"; $curr_offset++; $curr_elem_size++; $have_blocks = 1; } else { warn_before(); } next; } # Garbage. We weren't able to parse the data. Die("syntax error"); } # Finalize data. end_curr_string(); update_max_elem_size(); # Filter stdin to stdout, replacing `@...@' templates. sub emit_diversion { my $diversion_name = shift; return (exists($diversions{$1})) ? "@{$diversions{$1}}" : "@" . $diversion_name . "@"; } $LIST_SEPARATOR = ''; my $s1 = "This file has been generated by the Perl script \`$prog',"; my $s1len = length $s1; my $s2 = "using data from file \`$datafile'."; my $s2len = length $s2; my $slen = ($s1len > $s2len) ? $s1len : $s2len; print "/* " . $s1 . " " x ($slen - $s1len) . " */\n" . "/* " . $s2 . " " x ($slen - $s2len) . " */\n" . "\n"; while (<STDIN>) { s/ @ ( [A-Za-z0-9_]+? ) @ / emit_diversion($1) /egx; print; } # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/afblue.pl
Perl
gpl-3.0
13,048
/* * This little program is used to parse the FreeType headers and * find the declaration of all public APIs. This is easy, because * they all look like the following: * * FT_EXPORT( return_type ) * function_name( function arguments ); * * You must pass the list of header files as arguments. Wildcards are * accepted if you are using GCC for compilation (and probably by * other compilers too). * * Author: FreeType team, 2005-2019 * * This code is explicitly placed into the public domain. * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define PROGRAM_NAME "apinames" #define PROGRAM_VERSION "0.4" #define LINEBUFF_SIZE 1024 typedef enum OutputFormat_ { OUTPUT_LIST = 0, /* output the list of names, one per line */ OUTPUT_WINDOWS_DEF, /* output a Windows .DEF file for Visual C++ or Mingw */ OUTPUT_BORLAND_DEF, /* output a Windows .DEF file for Borland C++ */ OUTPUT_WATCOM_LBC, /* output a Watcom Linker Command File */ OUTPUT_VMS_OPT, /* output an OpenVMS Linker Option File */ OUTPUT_NETWARE_IMP, /* output a NetWare ImportFile */ OUTPUT_GNU_VERMAP /* output a version map for GNU or Solaris linker */ } OutputFormat; static void panic( const char* message ) { fprintf( stderr, "PANIC: %s\n", message ); exit(2); } typedef struct NameRec_ { char* name; unsigned int hash; } NameRec, *Name; static Name the_names; static int num_names; static int max_names; static void names_add( const char* name, const char* end ) { unsigned int h; int nn, len; Name nm; if ( end <= name ) return; /* compute hash value */ len = (int)( end - name ); h = 0; for ( nn = 0; nn < len; nn++ ) h = h * 33 + name[nn]; /* check for an pre-existing name */ for ( nn = 0; nn < num_names; nn++ ) { nm = the_names + nn; if ( (int)nm->hash == h && memcmp( name, nm->name, len ) == 0 && nm->name[len] == 0 ) return; } /* add new name */ if ( num_names >= max_names ) { max_names += ( max_names >> 1 ) + 4; the_names = (NameRec*)realloc( the_names, sizeof ( the_names[0] ) * max_names ); if ( !the_names ) panic( "not enough memory" ); } nm = &the_names[num_names++]; nm->hash = h; nm->name = (char*)malloc( len + 1 ); if ( !nm->name ) panic( "not enough memory" ); memcpy( nm->name, name, len ); nm->name[len] = 0; } static int name_compare( const void* name1, const void* name2 ) { Name n1 = (Name)name1; Name n2 = (Name)name2; return strcmp( n1->name, n2->name ); } static void names_sort( void ) { qsort( the_names, (size_t)num_names, sizeof ( the_names[0] ), name_compare ); } static void names_dump( FILE* out, OutputFormat format, const char* dll_name ) { int nn; switch ( format ) { case OUTPUT_WINDOWS_DEF: if ( dll_name ) fprintf( out, "LIBRARY %s\n", dll_name ); fprintf( out, "DESCRIPTION FreeType 2 DLL\n" ); fprintf( out, "EXPORTS\n" ); for ( nn = 0; nn < num_names; nn++ ) fprintf( out, " %s\n", the_names[nn].name ); break; case OUTPUT_BORLAND_DEF: if ( dll_name ) fprintf( out, "LIBRARY %s\n", dll_name ); fprintf( out, "DESCRIPTION FreeType 2 DLL\n" ); fprintf( out, "EXPORTS\n" ); for ( nn = 0; nn < num_names; nn++ ) fprintf( out, " _%s\n", the_names[nn].name ); break; case OUTPUT_WATCOM_LBC: { const char* dot; if ( !dll_name ) { fprintf( stderr, "you must provide a DLL name with the -d option!\n" ); exit( 4 ); } /* we must omit the `.dll' suffix from the library name */ dot = strchr( dll_name, '.' ); if ( dot ) { char temp[512]; int len = dot - dll_name; if ( len > (int)( sizeof ( temp ) - 1 ) ) len = sizeof ( temp ) - 1; memcpy( temp, dll_name, len ); temp[len] = 0; dll_name = (const char*)temp; } for ( nn = 0; nn < num_names; nn++ ) fprintf( out, "++_%s.%s.%s\n", the_names[nn].name, dll_name, the_names[nn].name ); } break; case OUTPUT_VMS_OPT: fprintf( out, "GSMATCH=LEQUAL,2,0\n" "CASE_SENSITIVE=YES\n" "SYMBOL_VECTOR=(-\n" ); for ( nn = 0; nn < num_names - 1; nn++ ) fprintf( out, " %s=PROCEDURE,-\n", the_names[nn].name ); fprintf( out, " %s=PROCEDURE)\n", the_names[num_names - 1].name ); break; case OUTPUT_NETWARE_IMP: if ( dll_name ) fprintf( out, " (%s)\n", dll_name ); for ( nn = 0; nn < num_names - 1; nn++ ) fprintf( out, " %s,\n", the_names[nn].name ); fprintf( out, " %s\n", the_names[num_names - 1].name ); break; case OUTPUT_GNU_VERMAP: fprintf( out, "{\n\tglobal:\n" ); for ( nn = 0; nn < num_names; nn++ ) fprintf( out, "\t\t%s;\n", the_names[nn].name ); fprintf( out, "\tlocal:\n\t\t*;\n};\n" ); break; default: /* LIST */ for ( nn = 0; nn < num_names; nn++ ) fprintf( out, "%s\n", the_names[nn].name ); break; } } /* states of the line parser */ typedef enum State_ { STATE_START = 0, /* waiting for FT_EXPORT keyword and return type */ STATE_TYPE /* type was read, waiting for function name */ } State; static int read_header_file( FILE* file, int verbose ) { static char buff[LINEBUFF_SIZE + 1]; State state = STATE_START; while ( !feof( file ) ) { char* p; if ( !fgets( buff, LINEBUFF_SIZE, file ) ) break; p = buff; /* skip leading whitespace */ while ( *p && ( *p == ' ' || *p == '\\' ) ) p++; /* skip empty lines */ if ( *p == '\n' || *p == '\r' ) continue; switch ( state ) { case STATE_START: if ( memcmp( p, "FT_EXPORT(", 10 ) != 0 ) break; p += 10; for (;;) { if ( *p == 0 || *p == '\n' || *p == '\r' ) goto NextLine; if ( *p == ')' ) { p++; break; } p++; } state = STATE_TYPE; /* * Sometimes, the name is just after `FT_EXPORT(...)', so skip * whitespace and fall-through if we find an alphanumeric character. */ while ( *p == ' ' || *p == '\t' ) p++; if ( !isalpha( *p ) ) break; /* fall-through */ case STATE_TYPE: { char* name = p; while ( isalnum( *p ) || *p == '_' ) p++; if ( p > name ) { if ( verbose ) fprintf( stderr, ">>> %.*s\n", (int)( p - name ), name ); names_add( name, p ); } state = STATE_START; } break; default: ; } NextLine: ; } /* end of while loop */ return 0; } static void usage( void ) { static const char* const format = "%s %s: extract FreeType API names from header files\n" "\n" "This program extracts the list of public FreeType API functions.\n" "It receives a list of header files as an argument and\n" "generates a sorted list of unique identifiers in various formats.\n" "\n" "usage: %s header1 [options] [header2 ...]\n" "\n" "options: - parse the contents of stdin, ignore arguments\n" " -v verbose mode, output sent to standard error\n" " -oFILE write output to FILE instead of standard output\n" " -dNAME indicate DLL file name, 'freetype.dll' by default\n" " -w output .DEF file for Visual C++ and Mingw\n" " -wB output .DEF file for Borland C++\n" " -wW output Watcom Linker Response File\n" " -wV output OpenVMS Linker Options File\n" " -wN output NetWare Import File\n" " -wL output version map for GNU or Solaris linker\n" "\n"; fprintf( stderr, format, PROGRAM_NAME, PROGRAM_VERSION, PROGRAM_NAME ); exit( 1 ); } int main( int argc, const char* const* argv ) { int from_stdin = 0; int verbose = 0; OutputFormat format = OUTPUT_LIST; /* the default */ FILE* out = stdout; const char* library_name = NULL; if ( argc < 2 ) usage(); /* `-' used as a single argument means read source file from stdin */ while ( argc > 1 && argv[1][0] == '-' ) { const char* arg = argv[1]; switch ( arg[1] ) { case 'v': verbose = 1; break; case 'o': if ( arg[2] == 0 ) { if ( argc < 2 ) usage(); arg = argv[2]; argv++; argc--; } else arg += 2; out = fopen( arg, "wt" ); if ( !out ) { fprintf( stderr, "could not open '%s' for writing\n", arg ); exit( 3 ); } break; case 'd': if ( arg[2] == 0 ) { if ( argc < 2 ) usage(); arg = argv[2]; argv++; argc--; } else arg += 2; library_name = arg; break; case 'w': format = OUTPUT_WINDOWS_DEF; switch ( arg[2] ) { case 'B': format = OUTPUT_BORLAND_DEF; break; case 'W': format = OUTPUT_WATCOM_LBC; break; case 'V': format = OUTPUT_VMS_OPT; break; case 'N': format = OUTPUT_NETWARE_IMP; break; case 'L': format = OUTPUT_GNU_VERMAP; break; case 0: break; default: usage(); } break; case 0: from_stdin = 1; break; default: usage(); } argc--; argv++; } /* end of while loop */ if ( from_stdin ) read_header_file( stdin, verbose ); else { for ( --argc, argv++; argc > 0; argc--, argv++ ) { FILE* file = fopen( argv[0], "rb" ); if ( !file ) fprintf( stderr, "unable to open '%s'\n", argv[0] ); else { if ( verbose ) fprintf( stderr, "opening '%s'\n", argv[0] ); read_header_file( file, verbose ); fclose( file ); } } } if ( num_names == 0 ) panic( "could not find exported functions\n" ); names_sort(); names_dump( out, format, library_name ); if ( out != stdout ) fclose( out ); return 0; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/apinames.c
C++
gpl-3.0
10,796
#!/usr/bin/env python # # Check trace components in FreeType 2 source. # Author: suzuki toshiya, 2009, 2013, 2020 # # This code is explicitly into the public domain. import sys import os import re SRC_FILE_LIST = [] USED_COMPONENT = {} KNOWN_COMPONENT = {} SRC_FILE_DIRS = [ "src" ] TRACE_DEF_FILES = [ "include/freetype/internal/fttrace.h" ] # -------------------------------------------------------------- # Parse command line options # for i in range( 1, len( sys.argv ) ): if sys.argv[i].startswith( "--help" ): print "Usage: %s [option]" % sys.argv[0] print "Search used-but-defined and defined-but-not-used trace_XXX macros" print "" print " --help:" print " Show this help" print "" print " --src-dirs=dir1:dir2:..." print " Specify the directories of C source files to be checked" print " Default is %s" % ":".join( SRC_FILE_DIRS ) print "" print " --def-files=file1:file2:..." print " Specify the header files including FT_TRACE_DEF()" print " Default is %s" % ":".join( TRACE_DEF_FILES ) print "" exit(0) if sys.argv[i].startswith( "--src-dirs=" ): SRC_FILE_DIRS = sys.argv[i].replace( "--src-dirs=", "", 1 ).split( ":" ) elif sys.argv[i].startswith( "--def-files=" ): TRACE_DEF_FILES = sys.argv[i].replace( "--def-files=", "", 1 ).split( ":" ) # -------------------------------------------------------------- # Scan C source and header files using trace macros. # c_pathname_pat = re.compile( '^.*\.[ch]$', re.IGNORECASE ) trace_use_pat = re.compile( '^[ \t]*#define[ \t]+FT_COMPONENT[ \t]+' ) for d in SRC_FILE_DIRS: for ( p, dlst, flst ) in os.walk( d ): for f in flst: if c_pathname_pat.match( f ) != None: src_pathname = os.path.join( p, f ) line_num = 0 for src_line in open( src_pathname, 'r' ): line_num = line_num + 1 src_line = src_line.strip() if trace_use_pat.match( src_line ) != None: component_name = trace_use_pat.sub( '', src_line ) if component_name in USED_COMPONENT: USED_COMPONENT[component_name].append( "%s:%d" % ( src_pathname, line_num ) ) else: USED_COMPONENT[component_name] = [ "%s:%d" % ( src_pathname, line_num ) ] # -------------------------------------------------------------- # Scan header file(s) defining trace macros. # trace_def_pat_opn = re.compile( '^.*FT_TRACE_DEF[ \t]*\([ \t]*' ) trace_def_pat_cls = re.compile( '[ \t\)].*$' ) for f in TRACE_DEF_FILES: line_num = 0 for hdr_line in open( f, 'r' ): line_num = line_num + 1 hdr_line = hdr_line.strip() if trace_def_pat_opn.match( hdr_line ) != None: component_name = trace_def_pat_opn.sub( '', hdr_line ) component_name = trace_def_pat_cls.sub( '', component_name ) if component_name in KNOWN_COMPONENT: print "trace component %s is defined twice, see %s and fttrace.h:%d" % \ ( component_name, KNOWN_COMPONENT[component_name], line_num ) else: KNOWN_COMPONENT[component_name] = "%s:%d" % \ ( os.path.basename( f ), line_num ) # -------------------------------------------------------------- # Compare the used and defined trace macros. # print "# Trace component used in the implementations but not defined in fttrace.h." cmpnt = USED_COMPONENT.keys() cmpnt.sort() for c in cmpnt: if c not in KNOWN_COMPONENT: print "Trace component %s (used in %s) is not defined." % ( c, ", ".join( USED_COMPONENT[c] ) ) print "# Trace component is defined but not used in the implementations." cmpnt = KNOWN_COMPONENT.keys() cmpnt.sort() for c in cmpnt: if c not in USED_COMPONENT: if c != "any": print "Trace component %s (defined in %s) is not used." % ( c, KNOWN_COMPONENT[c] )
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/chktrcmp.py
Python
gpl-3.0
3,832
# compute arctangent table for CORDIC computations in fttrigon.c import sys, math #units = 64*65536.0 # don't change !! units = 180 * 2**16 scale = units/math.pi shrink = 1.0 comma = "" print "" print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units" for n in range(1,32): x = 0.5**n # tangent value angle = math.atan(x) # arctangent angle2 = round(angle*scale) # arctangent in FT_Angle units if angle2 <= 0: break sys.stdout.write( comma + repr( int(angle2) ) ) comma = ", " shrink /= math.sqrt( 1 + x*x ) print print "shrink factor = " + repr( shrink ) print "shrink factor 2 = " + repr( int( shrink * (2**32) ) ) print "expansion factor = " + repr( 1/shrink ) print ""
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/cordic.py
Python
gpl-3.0
784
# TOP_DIR and OBJ_DIR should be set by the user to the right directories, # if necessary. TOP_DIR ?= ../../.. OBJ_DIR ?= $(TOP_DIR)/objs # The setup below is for gcc on a Unix-like platform, # where FreeType has been set up to create a static library # (which is the default). VPATH = $(OBJ_DIR) \ $(OBJ_DIR)/.libs SRC_DIR = $(TOP_DIR)/src/tools/ftrandom CC = gcc WFLAGS = -Wmissing-prototypes \ -Wunused \ -Wimplicit \ -Wreturn-type \ -Wparentheses \ -pedantic \ -Wformat \ -Wchar-subscripts \ -Wsequence-point CFLAGS = $(WFLAGS) \ -g INCLUDES = -I $(TOP_DIR)/include LDFLAGS = LIBS = -lm \ -lz \ -lpng \ -lbz2 \ -lharfbuzz all: $(OBJ_DIR)/ftrandom $(OBJ_DIR)/ftrandom.o: $(SRC_DIR)/ftrandom.c $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< $(OBJ_DIR)/ftrandom: $(OBJ_DIR)/ftrandom.o libfreetype.a $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/ftrandom/Makefile
Makefile
gpl-3.0
961
ftrandom ======== This program expects a set of directories containing good fonts, and a set of extensions of fonts to be tested. It will randomly pick a font, copy it, introduce an error and then test it. The FreeType tests are quite basic; for each erroneous font ftrandom . forks off a new tester, . initializes the library, . opens each font in the file, . loads each glyph, . optionally reviews the contours of the glyph, . optionally rasterizes the glyph, and . closes the face. If a tester takes longer than 20 seconds, ftrandom saves the erroneous font and continues. If the tester exits normally or with an error, then the superstructure removes the test font and continues. Command line options -------------------- --all Test every font in the directory(ies) no matter what its extension. --check-outlines Call `FT_Outline_Decompose' on each glyph. --dir <dir> Append <dir> to the list of directories to search for good fonts. No recursive search. --error-count <cnt> Introduce <cnt> single-byte errors into the erroneous fonts (default: 1). --error-fraction <frac> Multiply the file size of the font by <frac> and introduce that many errors into the erroneous font file. <frac> should be in the range [0;1] (default: 0.0). --ext <ext> Add <ext> to the set of font types tested. --help Print out this list of options. --nohints Specify FT_LOAD_NO_HINTING when loading glyphs. --rasterize Call `FT_Render_Glyph' as well as loading it. --result <dir> This is the directory in which test files are placed. --test <file> Run a single test on a pre-generated testcase. This is done in the current process so it can be debugged more easily. The default font extensions tested by ftrandom are .ttf .otf .ttc .cid .pfb .pfa .bdf .pcf .pfr .fon .otb .cff The default font directory is controlled by the macro `GOOD_FONTS_DIR' in the source code (and can be thus specified during compilation); its default value is /usr/local/share/fonts The default result directory is `results' (in the current directory). Compilation ----------- Two possible solutions. . Run ftrandom within a debugging tool like `valgrind' to catch various memory issues. . Compile FreeType with sanitizer flags as provided by gcc or clang, for example, then link it with ftrandom.
whupdup/frame
real/third_party/freetype-2.12.0/src/tools/ftrandom/README
none
gpl-3.0
2,688