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
/* * Copyright 2000 Computing Research Labs, New Mexico State University * Copyright 2001-2004, 2011 Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef BDF_H_ #define BDF_H_ /* * Based on bdf.h,v 1.16 2000/03/16 20:08:51 mleisher */ #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/fthash.h> FT_BEGIN_HEADER /* Imported from bdfP.h */ #define _bdf_glyph_modified( map, e ) \ ( (map)[(e) >> 5] & ( 1UL << ( (e) & 31 ) ) ) #define _bdf_set_glyph_modified( map, e ) \ ( (map)[(e) >> 5] |= ( 1UL << ( (e) & 31 ) ) ) #define _bdf_clear_glyph_modified( map, e ) \ ( (map)[(e) >> 5] &= ~( 1UL << ( (e) & 31 ) ) ) /* end of bdfP.h */ /************************************************************************** * * BDF font options macros and types. * */ #define BDF_CORRECT_METRICS 0x01 /* Correct invalid metrics when loading. */ #define BDF_KEEP_COMMENTS 0x02 /* Preserve the font comments. */ #define BDF_KEEP_UNENCODED 0x04 /* Keep the unencoded glyphs. */ #define BDF_PROPORTIONAL 0x08 /* Font has proportional spacing. */ #define BDF_MONOWIDTH 0x10 /* Font has mono width. */ #define BDF_CHARCELL 0x20 /* Font has charcell spacing. */ #define BDF_ALL_SPACING ( BDF_PROPORTIONAL | \ BDF_MONOWIDTH | \ BDF_CHARCELL ) #define BDF_DEFAULT_LOAD_OPTIONS ( BDF_CORRECT_METRICS | \ BDF_KEEP_COMMENTS | \ BDF_KEEP_UNENCODED | \ BDF_PROPORTIONAL ) typedef struct bdf_options_t_ { int correct_metrics; int keep_unencoded; int keep_comments; int font_spacing; } bdf_options_t; /* Callback function type for unknown configuration options. */ typedef int (*bdf_options_callback_t)( bdf_options_t* opts, char** params, unsigned long nparams, void* client_data ); /************************************************************************** * * BDF font property macros and types. * */ #define BDF_ATOM 1 #define BDF_INTEGER 2 #define BDF_CARDINAL 3 /* This structure represents a particular property of a font. */ /* There are a set of defaults and each font has their own. */ typedef struct bdf_property_t_ { const char* name; /* Name of the property. */ int format; /* Format of the property. */ int builtin; /* A builtin property. */ union { char* atom; long l; unsigned long ul; } value; /* Value of the property. */ } bdf_property_t; /************************************************************************** * * BDF font metric and glyph types. * */ typedef struct bdf_bbx_t_ { unsigned short width; unsigned short height; short x_offset; short y_offset; short ascent; short descent; } bdf_bbx_t; typedef struct bdf_glyph_t_ { char* name; /* Glyph name. */ unsigned long encoding; /* Glyph encoding. */ unsigned short swidth; /* Scalable width. */ unsigned short dwidth; /* Device width. */ bdf_bbx_t bbx; /* Glyph bounding box. */ unsigned char* bitmap; /* Glyph bitmap. */ unsigned long bpr; /* Number of bytes used per row. */ unsigned short bytes; /* Number of bytes used for the bitmap. */ } bdf_glyph_t; typedef struct bdf_font_t_ { char* name; /* Name of the font. */ bdf_bbx_t bbx; /* Font bounding box. */ unsigned long point_size; /* Point size of the font. */ unsigned long resolution_x; /* Font horizontal resolution. */ unsigned long resolution_y; /* Font vertical resolution. */ int spacing; /* Font spacing value. */ unsigned short monowidth; /* Logical width for monowidth font. */ unsigned long default_char; /* Encoding of the default glyph. */ long font_ascent; /* Font ascent. */ long font_descent; /* Font descent. */ unsigned long glyphs_size; /* Glyph structures allocated. */ unsigned long glyphs_used; /* Glyph structures used. */ bdf_glyph_t* glyphs; /* Glyphs themselves. */ unsigned long unencoded_size; /* Unencoded glyph struct. allocated. */ unsigned long unencoded_used; /* Unencoded glyph struct. used. */ bdf_glyph_t* unencoded; /* Unencoded glyphs themselves. */ unsigned long props_size; /* Font properties allocated. */ unsigned long props_used; /* Font properties used. */ bdf_property_t* props; /* Font properties themselves. */ char* comments; /* Font comments. */ unsigned long comments_len; /* Length of comment string. */ void* internal; /* Internal data for the font. */ unsigned short bpp; /* Bits per pixel. */ FT_Memory memory; bdf_property_t* user_props; unsigned long nuser_props; FT_HashRec proptbl; } bdf_font_t; /************************************************************************** * * Types for load/save callbacks. * */ /* Error codes. */ #define BDF_MISSING_START -1 #define BDF_MISSING_FONTNAME -2 #define BDF_MISSING_SIZE -3 #define BDF_MISSING_CHARS -4 #define BDF_MISSING_STARTCHAR -5 #define BDF_MISSING_ENCODING -6 #define BDF_MISSING_BBX -7 #define BDF_OUT_OF_MEMORY -20 #define BDF_INVALID_LINE -100 /************************************************************************** * * BDF font API. * */ FT_LOCAL( FT_Error ) bdf_load_font( FT_Stream stream, FT_Memory memory, bdf_options_t* opts, bdf_font_t* *font ); FT_LOCAL( void ) bdf_free_font( bdf_font_t* font ); FT_LOCAL( bdf_property_t * ) bdf_get_property( char* name, bdf_font_t* font ); FT_LOCAL( bdf_property_t * ) bdf_get_font_property( bdf_font_t* font, const char* name ); FT_END_HEADER #endif /* BDF_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/bdf.h
C++
gpl-3.0
8,233
/* bdfdrivr.c FreeType font driver for bdf files Copyright (C) 2001-2008, 2011, 2013, 2014 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/ftobjs.h> #include <freetype/ftbdf.h> #include <freetype/ttnameid.h> #include <freetype/internal/services/svbdf.h> #include <freetype/internal/services/svfntfmt.h> #include "bdf.h" #include "bdfdrivr.h" #include "bdferror.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 bdfdriver typedef struct BDF_CMapRec_ { FT_CMapRec cmap; FT_ULong num_encodings; /* ftobjs.h: FT_CMap->clazz->size */ BDF_encoding_el* encodings; } BDF_CMapRec, *BDF_CMap; FT_CALLBACK_DEF( FT_Error ) bdf_cmap_init( FT_CMap bdfcmap, FT_Pointer init_data ) { BDF_CMap cmap = (BDF_CMap)bdfcmap; BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap ); FT_UNUSED( init_data ); cmap->num_encodings = face->bdffont->glyphs_used; cmap->encodings = face->en_table; return FT_Err_Ok; } FT_CALLBACK_DEF( void ) bdf_cmap_done( FT_CMap bdfcmap ) { BDF_CMap cmap = (BDF_CMap)bdfcmap; cmap->encodings = NULL; cmap->num_encodings = 0; } FT_CALLBACK_DEF( FT_UInt ) bdf_cmap_char_index( FT_CMap bdfcmap, FT_UInt32 charcode ) { BDF_CMap cmap = (BDF_CMap)bdfcmap; BDF_encoding_el* encodings = cmap->encodings; FT_ULong min, max, mid; /* num_encodings */ FT_UShort result = 0; /* encodings->glyph */ min = 0; max = cmap->num_encodings; mid = ( min + max ) >> 1; while ( min < max ) { FT_ULong code; if ( mid >= max || mid < min ) mid = ( min + max ) >> 1; code = encodings[mid].enc; if ( charcode == code ) { /* increase glyph index by 1 -- */ /* we reserve slot 0 for the undefined glyph */ result = encodings[mid].glyph + 1; break; } if ( charcode < code ) max = mid; else min = mid + 1; /* prediction in a continuous block */ mid += charcode - code; } return result; } FT_CALLBACK_DEF( FT_UInt ) bdf_cmap_char_next( FT_CMap bdfcmap, FT_UInt32 *acharcode ) { BDF_CMap cmap = (BDF_CMap)bdfcmap; BDF_encoding_el* encodings = cmap->encodings; FT_ULong min, max, mid; /* num_encodings */ FT_UShort result = 0; /* encodings->glyph */ FT_ULong charcode = *acharcode + 1; min = 0; max = cmap->num_encodings; mid = ( min + max ) >> 1; while ( min < max ) { FT_ULong code; /* same as BDF_encoding_el.enc */ if ( mid >= max || mid < min ) mid = ( min + max ) >> 1; code = encodings[mid].enc; if ( charcode == code ) { /* increase glyph index by 1 -- */ /* we reserve slot 0 for the undefined glyph */ result = encodings[mid].glyph + 1; goto Exit; } if ( charcode < code ) max = mid; else min = mid + 1; /* prediction in a continuous block */ mid += charcode - code; } charcode = 0; if ( min < cmap->num_encodings ) { charcode = encodings[min].enc; result = encodings[min].glyph + 1; } Exit: if ( charcode > 0xFFFFFFFFUL ) { FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%lx > 32bit API", charcode )); *acharcode = 0; /* XXX: result should be changed to indicate an overflow error */ } else *acharcode = (FT_UInt32)charcode; return result; } static const FT_CMap_ClassRec bdf_cmap_class = { sizeof ( BDF_CMapRec ), bdf_cmap_init, bdf_cmap_done, bdf_cmap_char_index, bdf_cmap_char_next, NULL, NULL, NULL, NULL, NULL }; static FT_Error bdf_interpret_style( BDF_Face bdf ) { FT_Error error = FT_Err_Ok; FT_Face face = FT_FACE( bdf ); FT_Memory memory = face->memory; bdf_font_t* font = bdf->bdffont; bdf_property_t* prop; const char* strings[4] = { NULL, NULL, NULL, NULL }; size_t lengths[4], nn, len; face->style_flags = 0; prop = bdf_get_font_property( font, "SLANT" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' || *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) { face->style_flags |= FT_STYLE_FLAG_ITALIC; strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) ? "Oblique" : "Italic"; } prop = bdf_get_font_property( font, "WEIGHT_NAME" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) ) { face->style_flags |= FT_STYLE_FLAG_BOLD; strings[1] = "Bold"; } prop = bdf_get_font_property( font, "SETWIDTH_NAME" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[3] = (const char *)(prop->value.atom); prop = bdf_get_font_property( font, "ADD_STYLE_NAME" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[0] = (const char *)(prop->value.atom); for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; if ( strings[nn] ) { lengths[nn] = ft_strlen( strings[nn] ); len += lengths[nn] + 1; } } if ( len == 0 ) { strings[0] = "Regular"; lengths[0] = ft_strlen( strings[0] ); len = lengths[0] + 1; } { char* s; if ( FT_QALLOC( face->style_name, len ) ) return error; s = face->style_name; for ( nn = 0; nn < 4; nn++ ) { const char* src = strings[nn]; len = lengths[nn]; if ( !src ) continue; /* separate elements with a space */ if ( s != face->style_name ) *s++ = ' '; ft_memcpy( s, src, len ); /* need to convert spaces to dashes for */ /* add_style_name and setwidth_name */ if ( nn == 0 || nn == 3 ) { size_t mm; for ( mm = 0; mm < len; mm++ ) if ( s[mm] == ' ' ) s[mm] = '-'; } s += len; } *s = 0; } return error; } FT_CALLBACK_DEF( void ) BDF_Face_Done( FT_Face bdfface ) /* BDF_Face */ { BDF_Face face = (BDF_Face)bdfface; FT_Memory memory; if ( !face ) return; memory = FT_FACE_MEMORY( face ); bdf_free_font( face->bdffont ); FT_FREE( face->en_table ); FT_FREE( face->charset_encoding ); FT_FREE( face->charset_registry ); FT_FREE( bdfface->family_name ); FT_FREE( bdfface->style_name ); FT_FREE( bdfface->available_sizes ); FT_FREE( face->bdffont ); } FT_CALLBACK_DEF( FT_Error ) BDF_Face_Init( FT_Stream stream, FT_Face bdfface, /* BDF_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error = FT_Err_Ok; BDF_Face face = (BDF_Face)bdfface; FT_Memory memory = FT_FACE_MEMORY( face ); bdf_font_t* font = NULL; bdf_options_t options; FT_UNUSED( num_params ); FT_UNUSED( params ); FT_TRACE2(( "BDF driver\n" )); if ( FT_STREAM_SEEK( 0 ) ) goto Exit; options.correct_metrics = 1; /* FZ XXX: options semantics */ options.keep_unencoded = 1; options.keep_comments = 0; options.font_spacing = BDF_PROPORTIONAL; error = bdf_load_font( stream, memory, &options, &font ); if ( FT_ERR_EQ( error, Missing_Startfont_Field ) ) { FT_TRACE2(( " not a BDF file\n" )); goto Fail; } else if ( error ) goto Exit; /* we have a bdf font: let's construct the face object */ face->bdffont = font; /* BDF cannot have multiple faces in a single font file. * XXX: non-zero face_index is already invalid argument, but * Type1, Type42 driver has a convention to return * an invalid argument error when the font could be * opened by the specified driver. */ if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) { FT_ERROR(( "BDF_Face_Init: invalid face index\n" )); BDF_Face_Done( bdfface ); return FT_THROW( Invalid_Argument ); } { bdf_property_t* prop = NULL; FT_TRACE4(( " number of glyphs: allocated %ld (used %ld)\n", font->glyphs_size, font->glyphs_used )); FT_TRACE4(( " number of unencoded glyphs: allocated %ld (used %ld)\n", font->unencoded_size, font->unencoded_used )); bdfface->num_faces = 1; bdfface->face_index = 0; bdfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES | FT_FACE_FLAG_HORIZONTAL; prop = bdf_get_font_property( font, "SPACING" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && ( *(prop->value.atom) == 'M' || *(prop->value.atom) == 'm' || *(prop->value.atom) == 'C' || *(prop->value.atom) == 'c' ) ) bdfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL */ /* FZ XXX: I need a font to implement this */ prop = bdf_get_font_property( font, "FAMILY_NAME" ); if ( prop && prop->value.atom ) { if ( FT_STRDUP( bdfface->family_name, prop->value.atom ) ) goto Exit; } else bdfface->family_name = NULL; if ( FT_SET_ERROR( bdf_interpret_style( face ) ) ) goto Exit; /* the number of glyphs (with one slot for the undefined glyph */ /* at position 0 and all unencoded glyphs) */ bdfface->num_glyphs = (FT_Long)( font->glyphs_size + 1 ); bdfface->num_fixed_sizes = 1; if ( FT_NEW( bdfface->available_sizes ) ) goto Exit; { FT_Bitmap_Size* bsize = bdfface->available_sizes; FT_Short resolution_x = 0, resolution_y = 0; long value; /* sanity checks */ if ( font->font_ascent > 0x7FFF || font->font_ascent < -0x7FFF ) { font->font_ascent = font->font_ascent < 0 ? -0x7FFF : 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping font ascent to value %ld\n", font->font_ascent )); } if ( font->font_descent > 0x7FFF || font->font_descent < -0x7FFF ) { font->font_descent = font->font_descent < 0 ? -0x7FFF : 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping font descent to value %ld\n", font->font_descent )); } bsize->height = (FT_Short)( font->font_ascent + font->font_descent ); prop = bdf_get_font_property( font, "AVERAGE_WIDTH" ); if ( prop ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( prop->value.l < 0 ) FT_TRACE0(( "BDF_Face_Init: negative average width\n" )); #endif if ( prop->value.l > 0x7FFFL * 10 - 5 || prop->value.l < -( 0x7FFFL * 10 - 5 ) ) { bsize->width = 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping average width to value %d\n", bsize->width )); } else bsize->width = FT_ABS( (FT_Short)( ( prop->value.l + 5 ) / 10 ) ); } else { /* this is a heuristical value */ bsize->width = ( bsize->height * 2 + 1 ) / 3; } prop = bdf_get_font_property( font, "POINT_SIZE" ); if ( prop ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( prop->value.l < 0 ) FT_TRACE0(( "BDF_Face_Init: negative point size\n" )); #endif /* convert from 722.7 decipoints to 72 points per inch */ if ( prop->value.l > 0x504C2L || /* 0x7FFF * 72270/7200 */ prop->value.l < -0x504C2L ) { bsize->size = 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping point size to value %ld\n", bsize->size )); } else bsize->size = FT_MulDiv( FT_ABS( prop->value.l ), 64 * 7200, 72270L ); } else if ( font->point_size ) { if ( font->point_size > 0x7FFF ) { bsize->size = 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping point size to value %ld\n", bsize->size )); } else bsize->size = (FT_Pos)font->point_size << 6; } else { /* this is a heuristical value */ bsize->size = bsize->width * 64; } prop = bdf_get_font_property( font, "PIXEL_SIZE" ); if ( prop ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( prop->value.l < 0 ) FT_TRACE0(( "BDF_Face_Init: negative pixel size\n" )); #endif if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF ) { bsize->y_ppem = 0x7FFF << 6; FT_TRACE0(( "BDF_Face_Init: clamping pixel size to value %ld\n", bsize->y_ppem )); } else bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6; } prop = bdf_get_font_property( font, "RESOLUTION_X" ); if ( prop ) value = prop->value.l; else value = (long)font->resolution_x; if ( value ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( value < 0 ) FT_TRACE0(( "BDF_Face_Init: negative X resolution\n" )); #endif if ( value > 0x7FFF || value < -0x7FFF ) { resolution_x = 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping X resolution to value %d\n", resolution_x )); } else resolution_x = FT_ABS( (FT_Short)value ); } prop = bdf_get_font_property( font, "RESOLUTION_Y" ); if ( prop ) value = prop->value.l; else value = (long)font->resolution_y; if ( value ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( value < 0 ) FT_TRACE0(( "BDF_Face_Init: negative Y resolution\n" )); #endif if ( value > 0x7FFF || value < -0x7FFF ) { resolution_y = 0x7FFF; FT_TRACE0(( "BDF_Face_Init: clamping Y resolution to value %d\n", resolution_y )); } else resolution_y = FT_ABS( (FT_Short)value ); } if ( bsize->y_ppem == 0 ) { bsize->y_ppem = bsize->size; if ( resolution_y ) bsize->y_ppem = FT_MulDiv( bsize->y_ppem, resolution_y, 72 ); } if ( resolution_x && resolution_y ) bsize->x_ppem = FT_MulDiv( bsize->y_ppem, resolution_x, resolution_y ); else bsize->x_ppem = bsize->y_ppem; } /* encoding table */ { bdf_glyph_t* cur = font->glyphs; unsigned long n; if ( FT_QNEW_ARRAY( face->en_table, font->glyphs_size ) ) goto Exit; face->default_glyph = 0; for ( n = 0; n < font->glyphs_size; n++ ) { (face->en_table[n]).enc = cur[n].encoding; FT_TRACE4(( " idx %ld, val 0x%lX\n", n, cur[n].encoding )); (face->en_table[n]).glyph = (FT_UShort)n; if ( cur[n].encoding == font->default_char ) { if ( n < FT_UINT_MAX ) face->default_glyph = (FT_UInt)n; else FT_TRACE1(( "BDF_Face_Init:" " idx %ld is too large for this system\n", n )); } } } /* charmaps */ { bdf_property_t *charset_registry, *charset_encoding; FT_Bool unicode_charmap = 0; charset_registry = bdf_get_font_property( font, "CHARSET_REGISTRY" ); charset_encoding = bdf_get_font_property( font, "CHARSET_ENCODING" ); if ( charset_registry && charset_encoding ) { if ( charset_registry->format == BDF_ATOM && charset_encoding->format == BDF_ATOM && charset_registry->value.atom && charset_encoding->value.atom ) { const char* s; if ( FT_STRDUP( face->charset_encoding, charset_encoding->value.atom ) || FT_STRDUP( face->charset_registry, charset_registry->value.atom ) ) goto Exit; /* Uh, oh, compare first letters manually to avoid dependency */ /* on locales. */ s = face->charset_registry; if ( ( s[0] == 'i' || s[0] == 'I' ) && ( s[1] == 's' || s[1] == 'S' ) && ( s[2] == 'o' || s[2] == 'O' ) ) { s += 3; if ( !ft_strcmp( s, "10646" ) || ( !ft_strcmp( s, "8859" ) && !ft_strcmp( face->charset_encoding, "1" ) ) ) unicode_charmap = 1; /* another name for ASCII */ else if ( !ft_strcmp( s, "646.1991" ) && !ft_strcmp( face->charset_encoding, "IRV" ) ) unicode_charmap = 1; } { FT_CharMapRec charmap; charmap.face = FT_FACE( face ); charmap.encoding = FT_ENCODING_NONE; /* initial platform/encoding should indicate unset status? */ charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; charmap.encoding_id = TT_APPLE_ID_DEFAULT; if ( unicode_charmap ) { charmap.encoding = FT_ENCODING_UNICODE; charmap.platform_id = TT_PLATFORM_MICROSOFT; charmap.encoding_id = TT_MS_ID_UNICODE_CS; } error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); } goto Exit; } } /* otherwise assume Adobe standard encoding */ { FT_CharMapRec charmap; charmap.face = FT_FACE( face ); charmap.encoding = FT_ENCODING_ADOBE_STANDARD; charmap.platform_id = TT_PLATFORM_ADOBE; charmap.encoding_id = TT_ADOBE_ID_STANDARD; error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); /* Select default charmap */ if ( bdfface->num_charmaps ) bdfface->charmap = bdfface->charmaps[0]; } } } Exit: return error; Fail: BDF_Face_Done( bdfface ); return FT_THROW( Unknown_File_Format ); } FT_CALLBACK_DEF( FT_Error ) BDF_Size_Select( FT_Size size, FT_ULong strike_index ) { bdf_font_t* bdffont = ( (BDF_Face)size->face )->bdffont; FT_Select_Metrics( size->face, strike_index ); size->metrics.ascender = bdffont->font_ascent * 64; size->metrics.descender = -bdffont->font_descent * 64; size->metrics.max_advance = bdffont->bbx.width * 64; return FT_Err_Ok; } FT_CALLBACK_DEF( FT_Error ) BDF_Size_Request( FT_Size size, FT_Size_Request req ) { FT_Face face = size->face; FT_Bitmap_Size* bsize = face->available_sizes; bdf_font_t* bdffont = ( (BDF_Face)face )->bdffont; FT_Error error = FT_ERR( Invalid_Pixel_Size ); FT_Long height; height = FT_REQUEST_HEIGHT( req ); height = ( height + 32 ) >> 6; switch ( req->type ) { case FT_SIZE_REQUEST_TYPE_NOMINAL: if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) error = FT_Err_Ok; break; case FT_SIZE_REQUEST_TYPE_REAL_DIM: if ( height == ( bdffont->font_ascent + bdffont->font_descent ) ) error = FT_Err_Ok; break; default: error = FT_THROW( Unimplemented_Feature ); break; } if ( error ) return error; else return BDF_Size_Select( size, 0 ); } FT_CALLBACK_DEF( FT_Error ) BDF_Glyph_Load( FT_GlyphSlot slot, FT_Size size, FT_UInt glyph_index, FT_Int32 load_flags ) { BDF_Face bdf = (BDF_Face)FT_SIZE_FACE( size ); FT_Face face = FT_FACE( bdf ); FT_Error error = FT_Err_Ok; FT_Bitmap* bitmap = &slot->bitmap; bdf_glyph_t glyph; int bpp = bdf->bdffont->bpp; FT_UNUSED( load_flags ); if ( !face ) { error = FT_THROW( Invalid_Face_Handle ); goto Exit; } if ( glyph_index >= (FT_UInt)face->num_glyphs ) { error = FT_THROW( Invalid_Argument ); goto Exit; } FT_TRACE1(( "BDF_Glyph_Load: glyph index %d\n", glyph_index )); /* index 0 is the undefined glyph */ if ( glyph_index == 0 ) glyph_index = bdf->default_glyph; else glyph_index--; /* slot, bitmap => freetype, glyph => bdflib */ glyph = bdf->bdffont->glyphs[glyph_index]; bitmap->rows = glyph.bbx.height; bitmap->width = glyph.bbx.width; if ( glyph.bpr > FT_INT_MAX ) FT_TRACE1(( "BDF_Glyph_Load: too large pitch %ld is truncated\n", glyph.bpr )); bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */ /* note: we don't allocate a new array to hold the bitmap; */ /* we can simply point to it */ ft_glyphslot_set_bitmap( slot, glyph.bitmap ); switch ( bpp ) { case 1: bitmap->pixel_mode = FT_PIXEL_MODE_MONO; break; case 2: bitmap->pixel_mode = FT_PIXEL_MODE_GRAY2; break; case 4: bitmap->pixel_mode = FT_PIXEL_MODE_GRAY4; break; case 8: bitmap->pixel_mode = FT_PIXEL_MODE_GRAY; bitmap->num_grays = 256; break; } slot->format = FT_GLYPH_FORMAT_BITMAP; slot->bitmap_left = glyph.bbx.x_offset; slot->bitmap_top = glyph.bbx.ascent; slot->metrics.horiAdvance = (FT_Pos)( glyph.dwidth * 64 ); slot->metrics.horiBearingX = (FT_Pos)( glyph.bbx.x_offset * 64 ); slot->metrics.horiBearingY = (FT_Pos)( glyph.bbx.ascent * 64 ); slot->metrics.width = (FT_Pos)( bitmap->width * 64 ); slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); /* * XXX DWIDTH1 and VVECTOR should be parsed and * used here, provided such fonts do exist. */ ft_synthesize_vertical_metrics( &slot->metrics, bdf->bdffont->bbx.height * 64 ); Exit: return error; } /* * * BDF SERVICE * */ static FT_Error bdf_get_bdf_property( BDF_Face face, const char* prop_name, BDF_PropertyRec *aproperty ) { bdf_property_t* prop; FT_ASSERT( face && face->bdffont ); prop = bdf_get_font_property( face->bdffont, prop_name ); if ( prop ) { switch ( prop->format ) { case BDF_ATOM: aproperty->type = BDF_PROPERTY_TYPE_ATOM; aproperty->u.atom = prop->value.atom; break; case BDF_INTEGER: if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) ) { FT_TRACE1(( "bdf_get_bdf_property:" " too large integer 0x%lx is truncated\n", prop->value.l )); } aproperty->type = BDF_PROPERTY_TYPE_INTEGER; aproperty->u.integer = (FT_Int32)prop->value.l; break; case BDF_CARDINAL: if ( prop->value.ul > 0xFFFFFFFFUL ) { FT_TRACE1(( "bdf_get_bdf_property:" " too large cardinal 0x%lx is truncated\n", prop->value.ul )); } aproperty->type = BDF_PROPERTY_TYPE_CARDINAL; aproperty->u.cardinal = (FT_UInt32)prop->value.ul; break; default: goto Fail; } return 0; } Fail: return FT_THROW( Invalid_Argument ); } static FT_Error bdf_get_charset_id( BDF_Face face, const char* *acharset_encoding, const char* *acharset_registry ) { *acharset_encoding = face->charset_encoding; *acharset_registry = face->charset_registry; return 0; } static const FT_Service_BDFRec bdf_service_bdf = { (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id, /* get_charset_id */ (FT_BDF_GetPropertyFunc) bdf_get_bdf_property /* get_property */ }; /* * * SERVICES LIST * */ static const FT_ServiceDescRec bdf_services[] = { { FT_SERVICE_ID_BDF, &bdf_service_bdf }, { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_BDF }, { NULL, NULL } }; FT_CALLBACK_DEF( FT_Module_Interface ) bdf_driver_requester( FT_Module module, const char* name ) { FT_UNUSED( module ); return ft_service_list_lookup( bdf_services, name ); } FT_CALLBACK_TABLE_DEF const FT_Driver_ClassRec bdf_driver_class = { { FT_MODULE_FONT_DRIVER | FT_MODULE_DRIVER_NO_OUTLINES, sizeof ( FT_DriverRec ), "bdf", 0x10000L, 0x20000L, NULL, /* module-specific interface */ NULL, /* FT_Module_Constructor module_init */ NULL, /* FT_Module_Destructor module_done */ bdf_driver_requester /* FT_Module_Requester get_interface */ }, sizeof ( BDF_FaceRec ), sizeof ( FT_SizeRec ), sizeof ( FT_GlyphSlotRec ), BDF_Face_Init, /* FT_Face_InitFunc init_face */ BDF_Face_Done, /* FT_Face_DoneFunc done_face */ NULL, /* FT_Size_InitFunc init_size */ NULL, /* FT_Size_DoneFunc done_size */ NULL, /* FT_Slot_InitFunc init_slot */ NULL, /* FT_Slot_DoneFunc done_slot */ BDF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ NULL, /* FT_Face_GetKerningFunc get_kerning */ NULL, /* FT_Face_AttachFunc attach_file */ NULL, /* FT_Face_GetAdvancesFunc get_advances */ BDF_Size_Request, /* FT_Size_RequestFunc request_size */ BDF_Size_Select /* FT_Size_SelectFunc select_size */ }; /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/bdfdrivr.c
C++
gpl-3.0
29,066
/* bdfdrivr.h FreeType font driver for bdf fonts Copyright (C) 2001, 2002, 2003, 2004 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef BDFDRIVR_H_ #define BDFDRIVR_H_ #include <freetype/internal/ftdrv.h> #include "bdf.h" FT_BEGIN_HEADER typedef struct BDF_encoding_el_ { FT_ULong enc; FT_UShort glyph; } BDF_encoding_el; typedef struct BDF_FaceRec_ { FT_FaceRec root; char* charset_encoding; char* charset_registry; bdf_font_t* bdffont; BDF_encoding_el* en_table; FT_UInt default_glyph; } BDF_FaceRec, *BDF_Face; FT_EXPORT_VAR( const FT_Driver_ClassRec ) bdf_driver_class; FT_END_HEADER #endif /* BDFDRIVR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/bdfdrivr.h
C++
gpl-3.0
1,772
/* * Copyright 2001, 2002, 2012 Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /************************************************************************** * * This file is used to define the BDF error enumeration constants. * */ #ifndef BDFERROR_H_ #define BDFERROR_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX BDF_Err_ #define FT_ERR_BASE FT_Mod_Err_BDF #include <freetype/fterrors.h> #endif /* BDFERROR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/bdferror.h
C++
gpl-3.0
1,584
/* * Copyright 2000 Computing Research Labs, New Mexico State University * Copyright 2001-2014 * Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /************************************************************************** * * This file is based on bdf.c,v 1.22 2000/03/16 20:08:50 * * taken from Mark Leisher's xmbdfed package * */ #include <freetype/freetype.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/ftobjs.h> #include "bdf.h" #include "bdferror.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 bdflib /************************************************************************** * * Default BDF font options. * */ static const bdf_options_t _bdf_opts = { 1, /* Correct metrics. */ 1, /* Preserve unencoded glyphs. */ 0, /* Preserve comments. */ BDF_PROPORTIONAL /* Default spacing. */ }; /************************************************************************** * * Builtin BDF font properties. * */ /* List of most properties that might appear in a font. Doesn't include */ /* the RAW_* and AXIS_* properties in X11R6 polymorphic fonts. */ static const bdf_property_t _bdf_properties[] = { { "ADD_STYLE_NAME", BDF_ATOM, 1, { 0 } }, { "AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } }, { "AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "CAP_HEIGHT", BDF_INTEGER, 1, { 0 } }, { "CHARSET_COLLECTIONS", BDF_ATOM, 1, { 0 } }, { "CHARSET_ENCODING", BDF_ATOM, 1, { 0 } }, { "CHARSET_REGISTRY", BDF_ATOM, 1, { 0 } }, { "COMMENT", BDF_ATOM, 1, { 0 } }, { "COPYRIGHT", BDF_ATOM, 1, { 0 } }, { "DEFAULT_CHAR", BDF_CARDINAL, 1, { 0 } }, { "DESTINATION", BDF_CARDINAL, 1, { 0 } }, { "DEVICE_FONT_NAME", BDF_ATOM, 1, { 0 } }, { "END_SPACE", BDF_INTEGER, 1, { 0 } }, { "FACE_NAME", BDF_ATOM, 1, { 0 } }, { "FAMILY_NAME", BDF_ATOM, 1, { 0 } }, { "FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "FONT", BDF_ATOM, 1, { 0 } }, { "FONTNAME_REGISTRY", BDF_ATOM, 1, { 0 } }, { "FONT_ASCENT", BDF_INTEGER, 1, { 0 } }, { "FONT_DESCENT", BDF_INTEGER, 1, { 0 } }, { "FOUNDRY", BDF_ATOM, 1, { 0 } }, { "FULL_NAME", BDF_ATOM, 1, { 0 } }, { "ITALIC_ANGLE", BDF_INTEGER, 1, { 0 } }, { "MAX_SPACE", BDF_INTEGER, 1, { 0 } }, { "MIN_SPACE", BDF_INTEGER, 1, { 0 } }, { "NORM_SPACE", BDF_INTEGER, 1, { 0 } }, { "NOTICE", BDF_ATOM, 1, { 0 } }, { "PIXEL_SIZE", BDF_INTEGER, 1, { 0 } }, { "POINT_SIZE", BDF_INTEGER, 1, { 0 } }, { "QUAD_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_ASCENT", BDF_INTEGER, 1, { 0 } }, { "RAW_AVERAGE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_AVG_CAPITAL_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_AVG_LOWERCASE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_CAP_HEIGHT", BDF_INTEGER, 1, { 0 } }, { "RAW_DESCENT", BDF_INTEGER, 1, { 0 } }, { "RAW_END_SPACE", BDF_INTEGER, 1, { 0 } }, { "RAW_FIGURE_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_MAX_SPACE", BDF_INTEGER, 1, { 0 } }, { "RAW_MIN_SPACE", BDF_INTEGER, 1, { 0 } }, { "RAW_NORM_SPACE", BDF_INTEGER, 1, { 0 } }, { "RAW_PIXEL_SIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_POINT_SIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_PIXELSIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_POINTSIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_QUAD_WIDTH", BDF_INTEGER, 1, { 0 } }, { "RAW_SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } }, { "RAW_STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } }, { "RAW_SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } }, { "RAW_SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, { "RAW_SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, { "RAW_SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } }, { "RAW_SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, { "RAW_UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } }, { "RAW_UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } }, { "RAW_X_HEIGHT", BDF_INTEGER, 1, { 0 } }, { "RELATIVE_SETWIDTH", BDF_CARDINAL, 1, { 0 } }, { "RELATIVE_WEIGHT", BDF_CARDINAL, 1, { 0 } }, { "RESOLUTION", BDF_INTEGER, 1, { 0 } }, { "RESOLUTION_X", BDF_CARDINAL, 1, { 0 } }, { "RESOLUTION_Y", BDF_CARDINAL, 1, { 0 } }, { "SETWIDTH_NAME", BDF_ATOM, 1, { 0 } }, { "SLANT", BDF_ATOM, 1, { 0 } }, { "SMALL_CAP_SIZE", BDF_INTEGER, 1, { 0 } }, { "SPACING", BDF_ATOM, 1, { 0 } }, { "STRIKEOUT_ASCENT", BDF_INTEGER, 1, { 0 } }, { "STRIKEOUT_DESCENT", BDF_INTEGER, 1, { 0 } }, { "SUBSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, { "SUBSCRIPT_X", BDF_INTEGER, 1, { 0 } }, { "SUBSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, { "SUPERSCRIPT_SIZE", BDF_INTEGER, 1, { 0 } }, { "SUPERSCRIPT_X", BDF_INTEGER, 1, { 0 } }, { "SUPERSCRIPT_Y", BDF_INTEGER, 1, { 0 } }, { "UNDERLINE_POSITION", BDF_INTEGER, 1, { 0 } }, { "UNDERLINE_THICKNESS", BDF_INTEGER, 1, { 0 } }, { "WEIGHT", BDF_CARDINAL, 1, { 0 } }, { "WEIGHT_NAME", BDF_ATOM, 1, { 0 } }, { "X_HEIGHT", BDF_INTEGER, 1, { 0 } }, { "_MULE_BASELINE_OFFSET", BDF_INTEGER, 1, { 0 } }, { "_MULE_RELATIVE_COMPOSE", BDF_INTEGER, 1, { 0 } }, }; static const unsigned long _num_bdf_properties = sizeof ( _bdf_properties ) / sizeof ( _bdf_properties[0] ); /* An auxiliary macro to parse properties, to be used in conditionals. */ /* It behaves like `strncmp' but also tests the following character */ /* whether it is a whitespace or null. */ /* `property' is a constant string of length `n' to compare with. */ #define _bdf_strncmp( name, property, n ) \ ( ft_strncmp( name, property, n ) || \ !( name[n] == ' ' || \ name[n] == '\0' || \ name[n] == '\n' || \ name[n] == '\r' || \ name[n] == '\t' ) ) /* Auto correction messages. */ #define ACMSG1 "FONT_ASCENT property missing. " \ "Added `FONT_ASCENT %hd'.\n" #define ACMSG2 "FONT_DESCENT property missing. " \ "Added `FONT_DESCENT %hd'.\n" #define ACMSG3 "Font width != actual width. Old: %d New: %d.\n" #define ACMSG4 "Font left bearing != actual left bearing. " \ "Old: %hd New: %hd.\n" #define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n" #define ACMSG6 "Font descent != actual descent. Old: %d New: %d.\n" #define ACMSG7 "Font height != actual height. Old: %d New: %d.\n" #define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n" #define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n" #define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n" #define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n" #define ACMSG13 "Glyph %lu extra rows removed.\n" #define ACMSG14 "Glyph %lu extra columns removed.\n" #define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n" #define ACMSG16 "Glyph %lu missing columns padded with zero bits.\n" #define ACMSG17 "Adjusting number of glyphs to %ld.\n" /* Error messages. */ #define ERRMSG1 "[line %ld] Missing `%s' line.\n" #define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n" #define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n" #define ERRMSG4 "[line %ld] BBX too big.\n" #define ERRMSG5 "[line %ld] `%s' value too big.\n" #define ERRMSG6 "[line %ld] Input line too long.\n" #define ERRMSG7 "[line %ld] Font name too long.\n" #define ERRMSG8 "[line %ld] Invalid `%s' value.\n" #define ERRMSG9 "[line %ld] Invalid keyword.\n" /* Debug messages. */ #define DBGMSG1 " [%6ld] %s" /* no \n */ #define DBGMSG2 " (0x%lX)\n" /************************************************************************** * * Utility types and functions. * */ /* Function type for parsing lines of a BDF font. */ typedef FT_Error (*_bdf_line_func_t)( char* line, unsigned long linelen, unsigned long lineno, void* call_data, void* client_data ); /* List structure for splitting lines into fields. */ typedef struct _bdf_list_t_ { char** field; unsigned long size; unsigned long used; FT_Memory memory; } _bdf_list_t; /* Structure used while loading BDF fonts. */ typedef struct _bdf_parse_t_ { unsigned long flags; unsigned long cnt; unsigned long row; short minlb; short maxlb; short maxrb; short maxas; short maxds; short rbearing; char* glyph_name; long glyph_enc; bdf_font_t* font; bdf_options_t* opts; _bdf_list_t list; FT_Memory memory; unsigned long size; /* the stream size */ } _bdf_parse_t; #define setsbit( m, cc ) \ ( m[(FT_Byte)(cc) >> 3] |= (FT_Byte)( 1 << ( (cc) & 7 ) ) ) #define sbitset( m, cc ) \ ( m[(FT_Byte)(cc) >> 3] & ( 1 << ( (cc) & 7 ) ) ) static void _bdf_list_init( _bdf_list_t* list, FT_Memory memory ) { FT_ZERO( list ); list->memory = memory; } static void _bdf_list_done( _bdf_list_t* list ) { FT_Memory memory = list->memory; if ( memory ) { FT_FREE( list->field ); FT_ZERO( list ); } } static FT_Error _bdf_list_ensure( _bdf_list_t* list, unsigned long num_items ) /* same as _bdf_list_t.used */ { FT_Error error = FT_Err_Ok; if ( num_items > list->size ) { unsigned long oldsize = list->size; /* same as _bdf_list_t.size */ unsigned long newsize = oldsize + ( oldsize >> 1 ) + 5; unsigned long bigsize = (unsigned long)( FT_INT_MAX / sizeof ( char* ) ); FT_Memory memory = list->memory; if ( oldsize == bigsize ) { error = FT_THROW( Out_Of_Memory ); goto Exit; } else if ( newsize < oldsize || newsize > bigsize ) newsize = bigsize; if ( FT_QRENEW_ARRAY( list->field, oldsize, newsize ) ) goto Exit; list->size = newsize; } Exit: return error; } static void _bdf_list_shift( _bdf_list_t* list, unsigned long n ) { unsigned long i, u; if ( list == NULL || list->used == 0 || n == 0 ) return; if ( n >= list->used ) { list->used = 0; return; } for ( u = n, i = 0; u < list->used; i++, u++ ) list->field[i] = list->field[u]; list->used -= n; } /* An empty string for empty fields. */ static const char empty[] = ""; /* XXX eliminate this */ static char * _bdf_list_join( _bdf_list_t* list, int c, unsigned long *alen ) { unsigned long i, j; char* dp; *alen = 0; if ( list == NULL || list->used == 0 ) return 0; dp = list->field[0]; for ( i = j = 0; i < list->used; i++ ) { char* fp = list->field[i]; while ( *fp ) dp[j++] = *fp++; if ( i + 1 < list->used ) dp[j++] = (char)c; } if ( dp != empty ) dp[j] = 0; *alen = j; return dp; } /* The code below ensures that we have at least 4 + 1 `field' */ /* elements in `list' (which are possibly NULL) so that we */ /* don't have to check the number of fields in most cases. */ static FT_Error _bdf_list_split( _bdf_list_t* list, const char* separators, char* line, unsigned long linelen ) { unsigned long final_empty; int mult; const char *sp, *end; char *ep; char seps[32]; FT_Error error = FT_Err_Ok; /* Initialize the list. */ list->used = 0; if ( list->size ) { list->field[0] = (char*)empty; list->field[1] = (char*)empty; list->field[2] = (char*)empty; list->field[3] = (char*)empty; list->field[4] = (char*)empty; } /* If the line is empty, then simply return. */ if ( linelen == 0 || line[0] == 0 ) goto Exit; /* In the original code, if the `separators' parameter is NULL or */ /* empty, the list is split into individual bytes. We don't need */ /* this, so an error is signaled. */ if ( separators == NULL || *separators == 0 ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* Prepare the separator bitmap. */ FT_MEM_ZERO( seps, 32 ); /* If the very last character of the separator string is a plus, then */ /* set the `mult' flag to indicate that multiple separators should be */ /* collapsed into one. */ for ( mult = 0, sp = separators; sp && *sp; sp++ ) { if ( *sp == '+' && *( sp + 1 ) == 0 ) mult = 1; else setsbit( seps, *sp ); } /* Break the line up into fields. */ for ( final_empty = 0, sp = ep = line, end = sp + linelen; sp < end && *sp; ) { /* Collect everything that is not a separator. */ for ( ; *ep && !sbitset( seps, *ep ); ep++ ) ; /* Resize the list if necessary. */ if ( list->used == list->size ) { error = _bdf_list_ensure( list, list->used + 1 ); if ( error ) goto Exit; } /* Assign the field appropriately. */ list->field[list->used++] = ( ep > sp ) ? (char*)sp : (char*)empty; sp = ep; if ( mult ) { /* If multiple separators should be collapsed, do it now by */ /* setting all the separator characters to 0. */ for ( ; *ep && sbitset( seps, *ep ); ep++ ) *ep = 0; } else if ( *ep != 0 ) /* Don't collapse multiple separators by making them 0, so just */ /* make the one encountered 0. */ *ep++ = 0; final_empty = ( ep > sp && *ep == 0 ); sp = ep; } /* Finally, NULL-terminate the list. */ if ( list->used + final_empty >= list->size ) { error = _bdf_list_ensure( list, list->used + final_empty + 1 ); if ( error ) goto Exit; } if ( final_empty ) list->field[list->used++] = (char*)empty; list->field[list->used] = NULL; Exit: return error; } #define NO_SKIP 256 /* this value cannot be stored in a 'char' */ static FT_Error _bdf_readstream( FT_Stream stream, _bdf_line_func_t callback, void* client_data, unsigned long *lno ) { _bdf_line_func_t cb; unsigned long lineno, buf_size; int refill, hold, to_skip; ptrdiff_t bytes, start, end, cursor, avail; char* buf = NULL; FT_Memory memory = stream->memory; FT_Error error = FT_Err_Ok; if ( callback == NULL ) { error = FT_THROW( Invalid_Argument ); goto Exit; } /* initial size and allocation of the input buffer */ buf_size = 1024; if ( FT_QALLOC( buf, buf_size ) ) goto Exit; cb = callback; lineno = 1; buf[0] = 0; start = 0; avail = 0; cursor = 0; refill = 1; to_skip = NO_SKIP; bytes = 0; /* make compiler happy */ for (;;) { if ( refill ) { bytes = (ptrdiff_t)FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor, buf_size - (unsigned long)cursor ); avail = cursor + bytes; cursor = 0; refill = 0; } end = start; /* should we skip an optional character like \n or \r? */ if ( start < avail && buf[start] == to_skip ) { start += 1; to_skip = NO_SKIP; continue; } /* try to find the end of the line */ while ( end < avail && buf[end] != '\n' && buf[end] != '\r' ) end++; /* if we hit the end of the buffer, try shifting its content */ /* or even resizing it */ if ( end >= avail ) { if ( bytes == 0 ) { /* last line in file doesn't end in \r or \n; */ /* ignore it then exit */ if ( lineno == 1 ) error = FT_THROW( Missing_Startfont_Field ); break; } if ( start == 0 ) { /* this line is definitely too long; try resizing the input */ /* buffer a bit to handle it. */ FT_ULong new_size; if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */ { if ( lineno == 1 ) error = FT_THROW( Missing_Startfont_Field ); else { FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno )); error = FT_THROW( Invalid_Argument ); } goto Exit; } new_size = buf_size * 2; if ( FT_QREALLOC( buf, buf_size, new_size ) ) goto Exit; cursor = avail; buf_size = new_size; } else { bytes = avail - start; FT_MEM_MOVE( buf, buf + start, bytes ); cursor = bytes; start = 0; } refill = 1; continue; } /* Temporarily NUL-terminate the line. */ hold = buf[end]; buf[end] = 0; /* XXX: Use encoding independent value for 0x1A */ if ( buf[start] != '#' && buf[start] != 0x1A && end > start ) { error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, (void*)&cb, client_data ); /* Redo if we have encountered CHARS without properties. */ if ( error == -1 ) error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, (void*)&cb, client_data ); if ( error ) break; } lineno += 1; buf[end] = (char)hold; start = end + 1; if ( hold == '\n' ) to_skip = '\r'; else if ( hold == '\r' ) to_skip = '\n'; else to_skip = NO_SKIP; } *lno = lineno; Exit: FT_FREE( buf ); return error; } /* XXX: make this work with EBCDIC also */ static const unsigned char a2i[128] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char ddigits[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; static const unsigned char hdigits[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; /* Routine to convert a decimal ASCII string to an unsigned long integer. */ static unsigned long _bdf_atoul( const char* s ) { unsigned long v; if ( s == NULL || *s == 0 ) return 0; for ( v = 0; sbitset( ddigits, *s ); s++ ) { if ( v < ( FT_ULONG_MAX - 9 ) / 10 ) v = v * 10 + a2i[(int)*s]; else { v = FT_ULONG_MAX; break; } } return v; } /* Routine to convert a decimal ASCII string to a signed long integer. */ static long _bdf_atol( const char* s ) { long v, neg; if ( s == NULL || *s == 0 ) return 0; /* Check for a minus sign. */ neg = 0; if ( *s == '-' ) { s++; neg = 1; } for ( v = 0; sbitset( ddigits, *s ); s++ ) { if ( v < ( FT_LONG_MAX - 9 ) / 10 ) v = v * 10 + a2i[(int)*s]; else { v = FT_LONG_MAX; break; } } return ( !neg ) ? v : -v; } /* Routine to convert a decimal ASCII string to an unsigned short integer. */ static unsigned short _bdf_atous( const char* s ) { unsigned short v; if ( s == NULL || *s == 0 ) return 0; for ( v = 0; sbitset( ddigits, *s ); s++ ) { if ( v < ( FT_USHORT_MAX - 9 ) / 10 ) v = (unsigned short)( v * 10 + a2i[(int)*s] ); else { v = FT_USHORT_MAX; break; } } return v; } /* Routine to convert a decimal ASCII string to a signed short integer. */ static short _bdf_atos( const char* s ) { short v, neg; if ( s == NULL || *s == 0 ) return 0; /* Check for a minus. */ neg = 0; if ( *s == '-' ) { s++; neg = 1; } for ( v = 0; sbitset( ddigits, *s ); s++ ) { if ( v < ( SHRT_MAX - 9 ) / 10 ) v = (short)( v * 10 + a2i[(int)*s] ); else { v = SHRT_MAX; break; } } return (short)( ( !neg ) ? v : -v ); } /* Routine to compare two glyphs by encoding so they can be sorted. */ FT_COMPARE_DEF( int ) by_encoding( const void* a, const void* b ) { bdf_glyph_t *c1, *c2; c1 = (bdf_glyph_t *)a; c2 = (bdf_glyph_t *)b; if ( c1->encoding < c2->encoding ) return -1; if ( c1->encoding > c2->encoding ) return 1; return 0; } static FT_Error bdf_create_property( const char* name, int format, bdf_font_t* font ) { size_t n; bdf_property_t* p; FT_Memory memory = font->memory; FT_Error error = FT_Err_Ok; /* First check whether the property has */ /* already been added or not. If it has, then */ /* simply ignore it. */ if ( ft_hash_str_lookup( name, &(font->proptbl) ) ) goto Exit; if ( FT_QRENEW_ARRAY( font->user_props, font->nuser_props, font->nuser_props + 1 ) ) goto Exit; p = font->user_props + font->nuser_props; n = ft_strlen( name ) + 1; if ( n > FT_LONG_MAX ) return FT_THROW( Invalid_Argument ); if ( FT_QALLOC( p->name, n ) ) goto Exit; FT_MEM_COPY( (char *)p->name, name, n ); p->format = format; p->builtin = 0; p->value.atom = NULL; /* nothing is ever stored here */ n = _num_bdf_properties + font->nuser_props; error = ft_hash_str_insert( p->name, n, &(font->proptbl), memory ); if ( error ) goto Exit; font->nuser_props++; Exit: return error; } FT_LOCAL_DEF( bdf_property_t* ) bdf_get_property( char* name, bdf_font_t* font ) { size_t* propid; if ( name == NULL || *name == 0 ) return 0; if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL ) return 0; if ( *propid >= _num_bdf_properties ) return font->user_props + ( *propid - _num_bdf_properties ); return (bdf_property_t*)_bdf_properties + *propid; } /************************************************************************** * * BDF font file parsing flags and functions. * */ /* Parse flags. */ #define BDF_START_ 0x0001U #define BDF_FONT_NAME_ 0x0002U #define BDF_SIZE_ 0x0004U #define BDF_FONT_BBX_ 0x0008U #define BDF_PROPS_ 0x0010U #define BDF_GLYPHS_ 0x0020U #define BDF_GLYPH_ 0x0040U #define BDF_ENCODING_ 0x0080U #define BDF_SWIDTH_ 0x0100U #define BDF_DWIDTH_ 0x0200U #define BDF_BBX_ 0x0400U #define BDF_BITMAP_ 0x0800U #define BDF_SWIDTH_ADJ_ 0x1000U #define BDF_GLYPH_BITS_ ( BDF_GLYPH_ | \ BDF_ENCODING_ | \ BDF_SWIDTH_ | \ BDF_DWIDTH_ | \ BDF_BBX_ | \ BDF_BITMAP_ ) #define BDF_GLYPH_WIDTH_CHECK_ 0x40000000UL #define BDF_GLYPH_HEIGHT_CHECK_ 0x80000000UL static FT_Error _bdf_add_comment( bdf_font_t* font, char* comment, unsigned long len ) { char* cp; FT_Memory memory = font->memory; FT_Error error = FT_Err_Ok; if ( FT_QRENEW_ARRAY( font->comments, font->comments_len, font->comments_len + len + 1 ) ) goto Exit; cp = font->comments + font->comments_len; FT_MEM_COPY( cp, comment, len ); cp[len] = '\0'; font->comments_len += len + 1; Exit: return error; } /* Set the spacing from the font name if it exists, or set it to the */ /* default specified in the options. */ static FT_Error _bdf_set_default_spacing( bdf_font_t* font, bdf_options_t* opts, unsigned long lineno ) { size_t len; char name[256]; _bdf_list_t list; FT_Memory memory; FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); /* only used in debug mode */ if ( font == NULL || font->name == NULL || font->name[0] == 0 ) { error = FT_THROW( Invalid_Argument ); goto Exit; } memory = font->memory; _bdf_list_init( &list, memory ); font->spacing = opts->font_spacing; len = ft_strlen( font->name ) + 1; /* Limit ourselves to 256 characters in the font name. */ if ( len >= 256 ) { FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno )); error = FT_THROW( Invalid_Argument ); goto Exit; } FT_MEM_COPY( name, font->name, len ); error = _bdf_list_split( &list, "-", name, (unsigned long)len ); if ( error ) goto Fail; if ( list.used == 15 ) { switch ( list.field[11][0] ) { case 'C': case 'c': font->spacing = BDF_CHARCELL; break; case 'M': case 'm': font->spacing = BDF_MONOWIDTH; break; case 'P': case 'p': font->spacing = BDF_PROPORTIONAL; break; } } Fail: _bdf_list_done( &list ); Exit: return error; } /* Determine whether the property is an atom or not. If it is, then */ /* clean it up so the double quotes are removed if they exist. */ static int _bdf_is_atom( char* line, unsigned long linelen, char** name, char** value, bdf_font_t* font ) { int hold; char *sp, *ep; bdf_property_t* p; *name = sp = ep = line; while ( *ep && *ep != ' ' && *ep != '\t' ) ep++; hold = -1; if ( *ep ) { hold = *ep; *ep = 0; } p = bdf_get_property( sp, font ); /* Restore the character that was saved before any return can happen. */ if ( hold != -1 ) *ep = (char)hold; /* If the property exists and is not an atom, just return here. */ if ( p && p->format != BDF_ATOM ) return 0; /* The property is an atom. Trim all leading and trailing whitespace */ /* and double quotes for the atom value. */ sp = ep; ep = line + linelen; /* Trim the leading whitespace if it exists. */ if ( *sp ) *sp++ = 0; while ( *sp && ( *sp == ' ' || *sp == '\t' ) ) sp++; /* Trim the leading double quote if it exists. */ if ( *sp == '"' ) sp++; *value = sp; /* Trim the trailing whitespace if it exists. */ while ( ep > sp && ( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) ) *--ep = 0; /* Trim the trailing double quote if it exists. */ if ( ep > sp && *( ep - 1 ) == '"' ) *--ep = 0; return 1; } static FT_Error _bdf_add_property( bdf_font_t* font, const char* name, char* value, unsigned long lineno ) { size_t* propid; bdf_property_t *prop, *fp; FT_Memory memory = font->memory; FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); /* only used in debug mode */ /* First, check whether the property already exists in the font. */ if ( ( propid = ft_hash_str_lookup( name, (FT_Hash)font->internal ) ) != NULL ) { /* The property already exists in the font, so simply replace */ /* the value of the property with the current value. */ fp = font->props + *propid; switch ( fp->format ) { case BDF_ATOM: /* Delete the current atom if it exists. */ FT_FREE( fp->value.atom ); if ( value && value[0] != 0 ) { if ( FT_STRDUP( fp->value.atom, value ) ) goto Exit; } break; case BDF_INTEGER: fp->value.l = _bdf_atol( value ); break; case BDF_CARDINAL: fp->value.ul = _bdf_atoul( value ); break; default: ; } goto Exit; } /* See whether this property type exists yet or not. */ /* If not, create it. */ propid = ft_hash_str_lookup( name, &(font->proptbl) ); if ( !propid ) { error = bdf_create_property( name, BDF_ATOM, font ); if ( error ) goto Exit; propid = ft_hash_str_lookup( name, &(font->proptbl) ); } /* Allocate another property if this is overflowing. */ if ( font->props_used == font->props_size ) { if ( FT_QRENEW_ARRAY( font->props, font->props_size, font->props_size + 1 ) ) goto Exit; font->props_size++; } if ( *propid >= _num_bdf_properties ) prop = font->user_props + ( *propid - _num_bdf_properties ); else prop = (bdf_property_t*)_bdf_properties + *propid; fp = font->props + font->props_used; fp->name = prop->name; fp->format = prop->format; fp->builtin = prop->builtin; switch ( prop->format ) { case BDF_ATOM: fp->value.atom = NULL; if ( value && value[0] ) { if ( FT_STRDUP( fp->value.atom, value ) ) goto Exit; } break; case BDF_INTEGER: fp->value.l = _bdf_atol( value ); break; case BDF_CARDINAL: fp->value.ul = _bdf_atoul( value ); break; } /* If the property happens to be a comment, then it doesn't need */ /* to be added to the internal hash table. */ if ( _bdf_strncmp( name, "COMMENT", 7 ) != 0 ) { /* Add the property to the font property table. */ error = ft_hash_str_insert( fp->name, font->props_used, (FT_Hash)font->internal, memory ); if ( error ) goto Exit; } font->props_used++; /* Some special cases need to be handled here. The DEFAULT_CHAR */ /* property needs to be located if it exists in the property list, the */ /* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */ /* present, and the SPACING property should override the default */ /* spacing. */ if ( _bdf_strncmp( name, "DEFAULT_CHAR", 12 ) == 0 ) font->default_char = fp->value.ul; else if ( _bdf_strncmp( name, "FONT_ASCENT", 11 ) == 0 ) font->font_ascent = fp->value.l; else if ( _bdf_strncmp( name, "FONT_DESCENT", 12 ) == 0 ) font->font_descent = fp->value.l; else if ( _bdf_strncmp( name, "SPACING", 7 ) == 0 ) { if ( !fp->value.atom ) { FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( fp->value.atom[0] == 'p' || fp->value.atom[0] == 'P' ) font->spacing = BDF_PROPORTIONAL; else if ( fp->value.atom[0] == 'm' || fp->value.atom[0] == 'M' ) font->spacing = BDF_MONOWIDTH; else if ( fp->value.atom[0] == 'c' || fp->value.atom[0] == 'C' ) font->spacing = BDF_CHARCELL; } Exit: return error; } static const unsigned char nibble_mask[8] = { 0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; static FT_Error _bdf_parse_end( char* line, unsigned long linelen, unsigned long lineno, void* call_data, void* client_data ) { /* a no-op; we ignore everything after `ENDFONT' */ FT_UNUSED( line ); FT_UNUSED( linelen ); FT_UNUSED( lineno ); FT_UNUSED( call_data ); FT_UNUSED( client_data ); return FT_Err_Ok; } /* Actually parse the glyph info and bitmaps. */ static FT_Error _bdf_parse_glyphs( char* line, unsigned long linelen, unsigned long lineno, void* call_data, void* client_data ) { int c, mask_index; char* s; unsigned char* bp; unsigned long i, slen, nibbles; _bdf_line_func_t* next; _bdf_parse_t* p; bdf_glyph_t* glyph; bdf_font_t* font; FT_Memory memory; FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); /* only used in debug mode */ next = (_bdf_line_func_t *)call_data; p = (_bdf_parse_t *) client_data; font = p->font; memory = font->memory; /* Check for a comment. */ if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { if ( p->opts->keep_comments ) { linelen -= 7; s = line + 7; if ( *s != 0 ) { s++; linelen--; } error = _bdf_add_comment( p->font, s, linelen ); } goto Exit; } /* The very first thing expected is the number of glyphs. */ if ( !( p->flags & BDF_GLYPHS_ ) ) { if ( _bdf_strncmp( line, "CHARS", 5 ) != 0 ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" )); error = FT_THROW( Missing_Chars_Field ); goto Exit; } error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1] ); /* We need at least 20 bytes per glyph. */ if ( p->cnt > p->size / 20 ) { p->cnt = font->glyphs_size = p->size / 20; FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG17, p->cnt )); } /* Make sure the number of glyphs is non-zero. */ if ( p->cnt == 0 ) font->glyphs_size = 64; /* Limit ourselves to 1,114,112 glyphs in the font (this is the */ /* number of code points available in Unicode). */ if ( p->cnt >= 0x110000UL ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "CHARS" )); error = FT_THROW( Invalid_Argument ); goto Exit; } if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) ) goto Exit; p->flags |= BDF_GLYPHS_; goto Exit; } /* Check for the ENDFONT field. */ if ( _bdf_strncmp( line, "ENDFONT", 7 ) == 0 ) { if ( p->flags & BDF_GLYPH_BITS_ ) { /* Missing ENDCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); error = FT_THROW( Corrupted_Font_Glyphs ); goto Exit; } /* Sort the glyphs by encoding. */ ft_qsort( (char *)font->glyphs, font->glyphs_used, sizeof ( bdf_glyph_t ), by_encoding ); p->flags &= ~BDF_START_; *next = _bdf_parse_end; goto Exit; } /* Check for the ENDCHAR field. */ if ( _bdf_strncmp( line, "ENDCHAR", 7 ) == 0 ) { p->glyph_enc = 0; p->flags &= ~BDF_GLYPH_BITS_; goto Exit; } /* Check whether a glyph is being scanned but should be */ /* ignored because it is an unencoded glyph. */ if ( ( p->flags & BDF_GLYPH_ ) && p->glyph_enc == -1 && p->opts->keep_unencoded == 0 ) goto Exit; /* Check for the STARTCHAR field. */ if ( _bdf_strncmp( line, "STARTCHAR", 9 ) == 0 ) { if ( p->flags & BDF_GLYPH_BITS_ ) { /* Missing ENDCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); error = FT_THROW( Missing_Startchar_Field ); goto Exit; } /* Set the character name in the parse info first until the */ /* encoding can be checked for an unencoded character. */ FT_FREE( p->glyph_name ); error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; _bdf_list_shift( &p->list, 1 ); s = _bdf_list_join( &p->list, ' ', &slen ); if ( !s ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG8, lineno, "STARTCHAR" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( FT_QALLOC( p->glyph_name, slen + 1 ) ) goto Exit; FT_MEM_COPY( p->glyph_name, s, slen + 1 ); p->flags |= BDF_GLYPH_; FT_TRACE4(( DBGMSG1, lineno, s )); goto Exit; } /* Check for the ENCODING field. */ if ( _bdf_strncmp( line, "ENCODING", 8 ) == 0 ) { if ( !( p->flags & BDF_GLYPH_ ) ) { /* Missing STARTCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "STARTCHAR" )); error = FT_THROW( Missing_Startchar_Field ); goto Exit; } error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; p->glyph_enc = _bdf_atol( p->list.field[1] ); /* Normalize negative encoding values. The specification only */ /* allows -1, but we can be more generous here. */ if ( p->glyph_enc < -1 ) p->glyph_enc = -1; /* Check for alternative encoding format. */ if ( p->glyph_enc == -1 && p->list.used > 2 ) p->glyph_enc = _bdf_atol( p->list.field[2] ); if ( p->glyph_enc < -1 || p->glyph_enc >= 0x110000L ) p->glyph_enc = -1; FT_TRACE4(( DBGMSG2, p->glyph_enc )); if ( p->glyph_enc >= 0 ) { /* Make sure there are enough glyphs allocated in case the */ /* number of characters happen to be wrong. */ if ( font->glyphs_used == font->glyphs_size ) { if ( FT_RENEW_ARRAY( font->glyphs, font->glyphs_size, font->glyphs_size + 64 ) ) goto Exit; font->glyphs_size += 64; } glyph = font->glyphs + font->glyphs_used++; glyph->name = p->glyph_name; glyph->encoding = (unsigned long)p->glyph_enc; /* Reset the initial glyph info. */ p->glyph_name = NULL; } else { /* Unencoded glyph. Check whether it should */ /* be added or not. */ if ( p->opts->keep_unencoded ) { /* Allocate the next unencoded glyph. */ if ( font->unencoded_used == font->unencoded_size ) { if ( FT_RENEW_ARRAY( font->unencoded , font->unencoded_size, font->unencoded_size + 4 ) ) goto Exit; font->unencoded_size += 4; } glyph = font->unencoded + font->unencoded_used; glyph->name = p->glyph_name; glyph->encoding = font->unencoded_used++; /* Reset the initial glyph info. */ p->glyph_name = NULL; } else { /* Free up the glyph name if the unencoded shouldn't be */ /* kept. */ FT_FREE( p->glyph_name ); } } /* Clear the flags that might be added when width and height are */ /* checked for consistency. */ p->flags &= ~( BDF_GLYPH_WIDTH_CHECK_ | BDF_GLYPH_HEIGHT_CHECK_ ); p->flags |= BDF_ENCODING_; goto Exit; } if ( !( p->flags & BDF_ENCODING_ ) ) goto Missing_Encoding; /* Point at the glyph being constructed. */ if ( p->glyph_enc == -1 ) glyph = font->unencoded + ( font->unencoded_used - 1 ); else glyph = font->glyphs + ( font->glyphs_used - 1 ); /* Check whether a bitmap is being constructed. */ if ( p->flags & BDF_BITMAP_ ) { /* If there are more rows than are specified in the glyph metrics, */ /* ignore the remaining lines. */ if ( p->row >= (unsigned long)glyph->bbx.height ) { if ( !( p->flags & BDF_GLYPH_HEIGHT_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG13, glyph->encoding )); p->flags |= BDF_GLYPH_HEIGHT_CHECK_; } goto Exit; } /* Only collect the number of nibbles indicated by the glyph */ /* metrics. If there are more columns, they are simply ignored. */ nibbles = glyph->bpr << 1; bp = glyph->bitmap + p->row * glyph->bpr; for ( i = 0; i < nibbles; i++ ) { c = line[i]; if ( !sbitset( hdigits, c ) ) break; *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] ); if ( i + 1 < nibbles && ( i & 1 ) ) *++bp = 0; } /* If any line has not enough columns, */ /* indicate they have been padded with zero bits. */ if ( i < nibbles && !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG16, glyph->encoding )); p->flags |= BDF_GLYPH_WIDTH_CHECK_; } /* Remove possible garbage at the right. */ mask_index = ( glyph->bbx.width * p->font->bpp ) & 7; if ( glyph->bbx.width ) *bp &= nibble_mask[mask_index]; /* If any line has extra columns, indicate they have been removed. */ if ( i == nibbles && sbitset( hdigits, line[nibbles] ) && !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding )); p->flags |= BDF_GLYPH_WIDTH_CHECK_; } p->row++; goto Exit; } /* Expect the SWIDTH (scalable width) field next. */ if ( _bdf_strncmp( line, "SWIDTH", 6 ) == 0 ) { error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; glyph->swidth = _bdf_atous( p->list.field[1] ); p->flags |= BDF_SWIDTH_; goto Exit; } /* Expect the DWIDTH (device width) field next. */ if ( _bdf_strncmp( line, "DWIDTH", 6 ) == 0 ) { error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; glyph->dwidth = _bdf_atous( p->list.field[1] ); if ( !( p->flags & BDF_SWIDTH_ ) ) { /* Missing SWIDTH field. Emit an auto correction message and set */ /* the scalable width from the device width. */ FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG9, lineno )); glyph->swidth = (unsigned short)FT_MulDiv( glyph->dwidth, 72000L, (FT_Long)( font->point_size * font->resolution_x ) ); } p->flags |= BDF_DWIDTH_; goto Exit; } /* Expect the BBX field next. */ if ( _bdf_strncmp( line, "BBX", 3 ) == 0 ) { error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; glyph->bbx.width = _bdf_atous( p->list.field[1] ); glyph->bbx.height = _bdf_atous( p->list.field[2] ); glyph->bbx.x_offset = _bdf_atos( p->list.field[3] ); glyph->bbx.y_offset = _bdf_atos( p->list.field[4] ); /* Generate the ascent and descent of the character. */ glyph->bbx.ascent = (short)( glyph->bbx.height + glyph->bbx.y_offset ); glyph->bbx.descent = (short)( -glyph->bbx.y_offset ); /* Determine the overall font bounding box as the characters are */ /* loaded so corrections can be done later if indicated. */ p->maxas = (short)FT_MAX( glyph->bbx.ascent, p->maxas ); p->maxds = (short)FT_MAX( glyph->bbx.descent, p->maxds ); p->rbearing = (short)( glyph->bbx.width + glyph->bbx.x_offset ); p->maxrb = (short)FT_MAX( p->rbearing, p->maxrb ); p->minlb = (short)FT_MIN( glyph->bbx.x_offset, p->minlb ); p->maxlb = (short)FT_MAX( glyph->bbx.x_offset, p->maxlb ); if ( !( p->flags & BDF_DWIDTH_ ) ) { /* Missing DWIDTH field. Emit an auto correction message and set */ /* the device width to the glyph width. */ FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG10, lineno )); glyph->dwidth = glyph->bbx.width; } /* If the BDF_CORRECT_METRICS flag is set, then adjust the SWIDTH */ /* value if necessary. */ if ( p->opts->correct_metrics ) { /* Determine the point size of the glyph. */ unsigned short sw = (unsigned short)FT_MulDiv( glyph->dwidth, 72000L, (FT_Long)( font->point_size * font->resolution_x ) ); if ( sw != glyph->swidth ) { glyph->swidth = sw; p->flags |= BDF_SWIDTH_ADJ_; } } p->flags |= BDF_BBX_; goto Exit; } /* And finally, gather up the bitmap. */ if ( _bdf_strncmp( line, "BITMAP", 6 ) == 0 ) { unsigned long bitmap_size; if ( !( p->flags & BDF_BBX_ ) ) { /* Missing BBX field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "BBX" )); error = FT_THROW( Missing_Bbx_Field ); goto Exit; } /* Allocate enough space for the bitmap. */ glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3; bitmap_size = glyph->bpr * glyph->bbx.height; if ( glyph->bpr > 0xFFFFU || bitmap_size > 0xFFFFU ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG4, lineno )); error = FT_THROW( Bbx_Too_Big ); goto Exit; } else glyph->bytes = (unsigned short)bitmap_size; if ( FT_ALLOC( glyph->bitmap, glyph->bytes ) ) goto Exit; p->row = 0; p->flags |= BDF_BITMAP_; goto Exit; } FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG9, lineno )); error = FT_THROW( Invalid_File_Format ); goto Exit; Missing_Encoding: /* Missing ENCODING field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENCODING" )); error = FT_THROW( Missing_Encoding_Field ); Exit: if ( error && ( p->flags & BDF_GLYPH_ ) ) FT_FREE( p->glyph_name ); return error; } /* Load the font properties. */ static FT_Error _bdf_parse_properties( char* line, unsigned long linelen, unsigned long lineno, void* call_data, void* client_data ) { unsigned long vlen; _bdf_line_func_t* next; _bdf_parse_t* p; char* name; char* value; char nbuf[128]; FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); next = (_bdf_line_func_t *)call_data; p = (_bdf_parse_t *) client_data; /* Check for the end of the properties. */ if ( _bdf_strncmp( line, "ENDPROPERTIES", 13 ) == 0 ) { /* If the FONT_ASCENT or FONT_DESCENT properties have not been */ /* encountered yet, then make sure they are added as properties and */ /* make sure they are set from the font bounding box info. */ /* */ /* This is *always* done regardless of the options, because X11 */ /* requires these two fields to compile fonts. */ if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 ) { p->font->font_ascent = p->font->bbx.ascent; ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); error = _bdf_add_property( p->font, "FONT_ASCENT", nbuf, lineno ); if ( error ) goto Exit; FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent )); } if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 ) { p->font->font_descent = p->font->bbx.descent; ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); error = _bdf_add_property( p->font, "FONT_DESCENT", nbuf, lineno ); if ( error ) goto Exit; FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent )); } p->flags &= ~BDF_PROPS_; *next = _bdf_parse_glyphs; goto Exit; } /* Ignore the _XFREE86_GLYPH_RANGES properties. */ if ( _bdf_strncmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 ) goto Exit; /* Handle COMMENT fields and properties in a special way to preserve */ /* the spacing. */ if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { name = value = line; value += 7; if ( *value ) *value++ = 0; error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) ) { error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } else { error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; name = p->list.field[0]; _bdf_list_shift( &p->list, 1 ); value = _bdf_list_join( &p->list, ' ', &vlen ); error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } Exit: return error; } /* Load the font header. */ static FT_Error _bdf_parse_start( char* line, unsigned long linelen, unsigned long lineno, void* call_data, void* client_data ) { unsigned long slen; _bdf_line_func_t* next; _bdf_parse_t* p; bdf_font_t* font; char *s; FT_Memory memory = NULL; FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); /* only used in debug mode */ next = (_bdf_line_func_t *)call_data; p = (_bdf_parse_t *) client_data; if ( p->font ) memory = p->font->memory; /* Check for a comment. This is done to handle those fonts that have */ /* comments before the STARTFONT line for some reason. */ if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { if ( p->opts->keep_comments && p->font ) { linelen -= 7; s = line + 7; if ( *s != 0 ) { s++; linelen--; } error = _bdf_add_comment( p->font, s, linelen ); } goto Exit; } if ( !( p->flags & BDF_START_ ) ) { memory = p->memory; if ( _bdf_strncmp( line, "STARTFONT", 9 ) != 0 ) { /* we don't emit an error message since this code gets */ /* explicitly caught one level higher */ error = FT_THROW( Missing_Startfont_Field ); goto Exit; } p->flags = BDF_START_; font = p->font = NULL; if ( FT_NEW( font ) ) goto Exit; p->font = font; font->memory = p->memory; { /* setup */ size_t i; bdf_property_t* prop; error = ft_hash_str_init( &(font->proptbl), memory ); if ( error ) goto Exit; for ( i = 0, prop = (bdf_property_t*)_bdf_properties; i < _num_bdf_properties; i++, prop++ ) { error = ft_hash_str_insert( prop->name, i, &(font->proptbl), memory ); if ( error ) goto Exit; } } if ( FT_QALLOC( p->font->internal, sizeof ( FT_HashRec ) ) ) goto Exit; error = ft_hash_str_init( (FT_Hash)p->font->internal, memory ); if ( error ) goto Exit; p->font->spacing = p->opts->font_spacing; p->font->default_char = ~0UL; goto Exit; } /* Check for the start of the properties. */ if ( _bdf_strncmp( line, "STARTPROPERTIES", 15 ) == 0 ) { if ( !( p->flags & BDF_FONT_BBX_ ) ) { /* Missing the FONTBOUNDINGBOX field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); error = FT_THROW( Missing_Fontboundingbox_Field ); goto Exit; } error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; /* at this point, `p->font' can't be NULL */ p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1] ); /* We need at least 4 bytes per property. */ if ( p->cnt > p->size / 4 ) { p->font->props_size = 0; FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "STARTPROPERTIES" )); error = FT_THROW( Invalid_Argument ); goto Exit; } if ( FT_NEW_ARRAY( p->font->props, p->cnt ) ) { p->font->props_size = 0; goto Exit; } p->flags |= BDF_PROPS_; *next = _bdf_parse_properties; goto Exit; } /* Check for the FONTBOUNDINGBOX field. */ if ( _bdf_strncmp( line, "FONTBOUNDINGBOX", 15 ) == 0 ) { if ( !( p->flags & BDF_SIZE_ ) ) { /* Missing the SIZE field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" )); error = FT_THROW( Missing_Size_Field ); goto Exit; } error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; p->font->bbx.width = _bdf_atous( p->list.field[1] ); p->font->bbx.height = _bdf_atous( p->list.field[2] ); p->font->bbx.x_offset = _bdf_atos( p->list.field[3] ); p->font->bbx.y_offset = _bdf_atos( p->list.field[4] ); p->font->bbx.ascent = (short)( p->font->bbx.height + p->font->bbx.y_offset ); p->font->bbx.descent = (short)( -p->font->bbx.y_offset ); p->flags |= BDF_FONT_BBX_; goto Exit; } /* The next thing to check for is the FONT field. */ if ( _bdf_strncmp( line, "FONT", 4 ) == 0 ) { error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; _bdf_list_shift( &p->list, 1 ); s = _bdf_list_join( &p->list, ' ', &slen ); if ( !s ) { FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */ FT_FREE( p->font->name ); if ( FT_QALLOC( p->font->name, slen + 1 ) ) goto Exit; FT_MEM_COPY( p->font->name, s, slen + 1 ); /* If the font name is an XLFD name, set the spacing to the one in */ /* the font name. If there is no spacing fall back on the default. */ error = _bdf_set_default_spacing( p->font, p->opts, lineno ); if ( error ) goto Exit; p->flags |= BDF_FONT_NAME_; goto Exit; } /* Check for the SIZE field. */ if ( _bdf_strncmp( line, "SIZE", 4 ) == 0 ) { if ( !( p->flags & BDF_FONT_NAME_ ) ) { /* Missing the FONT field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" )); error = FT_THROW( Missing_Font_Field ); goto Exit; } error = _bdf_list_split( &p->list, " +", line, linelen ); if ( error ) goto Exit; p->font->point_size = _bdf_atoul( p->list.field[1] ); p->font->resolution_x = _bdf_atoul( p->list.field[2] ); p->font->resolution_y = _bdf_atoul( p->list.field[3] ); /* Check for the bits per pixel field. */ if ( p->list.used == 5 ) { unsigned short bpp; bpp = _bdf_atous( p->list.field[4] ); /* Only values 1, 2, 4, 8 are allowed for greymap fonts. */ if ( bpp > 4 ) p->font->bpp = 8; else if ( bpp > 2 ) p->font->bpp = 4; else if ( bpp > 1 ) p->font->bpp = 2; else p->font->bpp = 1; if ( p->font->bpp != bpp ) FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp )); } else p->font->bpp = 1; p->flags |= BDF_SIZE_; goto Exit; } /* Check for the CHARS field -- font properties are optional */ if ( _bdf_strncmp( line, "CHARS", 5 ) == 0 ) { char nbuf[128]; if ( !( p->flags & BDF_FONT_BBX_ ) ) { /* Missing the FONTBOUNDINGBOX field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); error = FT_THROW( Missing_Fontboundingbox_Field ); goto Exit; } /* Add the two standard X11 properties which are required */ /* for compiling fonts. */ p->font->font_ascent = p->font->bbx.ascent; ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); error = _bdf_add_property( p->font, "FONT_ASCENT", nbuf, lineno ); if ( error ) goto Exit; FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent )); p->font->font_descent = p->font->bbx.descent; ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); error = _bdf_add_property( p->font, "FONT_DESCENT", nbuf, lineno ); if ( error ) goto Exit; FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent )); *next = _bdf_parse_glyphs; /* A special return value. */ error = -1; goto Exit; } FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno )); error = FT_THROW( Invalid_File_Format ); Exit: return error; } /************************************************************************** * * API. * */ FT_LOCAL_DEF( FT_Error ) bdf_load_font( FT_Stream stream, FT_Memory memory, bdf_options_t* opts, bdf_font_t* *font ) { unsigned long lineno = 0; /* make compiler happy */ _bdf_parse_t *p = NULL; FT_Error error = FT_Err_Ok; if ( FT_NEW( p ) ) goto Exit; p->opts = (bdf_options_t*)( opts ? opts : &_bdf_opts ); p->minlb = 32767; p->size = stream->size; p->memory = memory; /* only during font creation */ _bdf_list_init( &p->list, memory ); error = _bdf_readstream( stream, _bdf_parse_start, (void *)p, &lineno ); if ( error ) goto Fail; if ( p->font ) { /* If the font is not proportional, set the font's monowidth */ /* field to the width of the font bounding box. */ if ( p->font->spacing != BDF_PROPORTIONAL ) p->font->monowidth = p->font->bbx.width; /* If the number of glyphs loaded is not that of the original count, */ /* indicate the difference. */ if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used ) { FT_TRACE2(( "bdf_load_font: " ACMSG15, p->cnt, p->font->glyphs_used + p->font->unencoded_used )); } /* Once the font has been loaded, adjust the overall font metrics if */ /* necessary. */ if ( p->opts->correct_metrics != 0 && ( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) ) { if ( p->maxrb - p->minlb != p->font->bbx.width ) { FT_TRACE2(( "bdf_load_font: " ACMSG3, p->font->bbx.width, p->maxrb - p->minlb )); p->font->bbx.width = (unsigned short)( p->maxrb - p->minlb ); } if ( p->font->bbx.x_offset != p->minlb ) { FT_TRACE2(( "bdf_load_font: " ACMSG4, p->font->bbx.x_offset, p->minlb )); p->font->bbx.x_offset = p->minlb; } if ( p->font->bbx.ascent != p->maxas ) { FT_TRACE2(( "bdf_load_font: " ACMSG5, p->font->bbx.ascent, p->maxas )); p->font->bbx.ascent = p->maxas; } if ( p->font->bbx.descent != p->maxds ) { FT_TRACE2(( "bdf_load_font: " ACMSG6, p->font->bbx.descent, p->maxds )); p->font->bbx.descent = p->maxds; p->font->bbx.y_offset = (short)( -p->maxds ); } if ( p->maxas + p->maxds != p->font->bbx.height ) { FT_TRACE2(( "bdf_load_font: " ACMSG7, p->font->bbx.height, p->maxas + p->maxds )); p->font->bbx.height = (unsigned short)( p->maxas + p->maxds ); } if ( p->flags & BDF_SWIDTH_ADJ_ ) FT_TRACE2(( "bdf_load_font: " ACMSG8 )); } } if ( p->flags & BDF_START_ ) { /* The ENDFONT field was never reached or did not exist. */ if ( !( p->flags & BDF_GLYPHS_ ) ) { /* Error happened while parsing header. */ FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno )); error = FT_THROW( Corrupted_Font_Header ); goto Fail; } else { /* Error happened when parsing glyphs. */ FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno )); error = FT_THROW( Corrupted_Font_Glyphs ); goto Fail; } } if ( !p->font && !error ) error = FT_THROW( Invalid_File_Format ); *font = p->font; Exit: if ( p ) { _bdf_list_done( &p->list ); FT_FREE( p->glyph_name ); FT_FREE( p ); } return error; Fail: bdf_free_font( p->font ); FT_FREE( p->font ); goto Exit; } FT_LOCAL_DEF( void ) bdf_free_font( bdf_font_t* font ) { bdf_property_t* prop; unsigned long i; bdf_glyph_t* glyphs; FT_Memory memory; if ( font == NULL ) return; memory = font->memory; FT_FREE( font->name ); /* Free up the internal hash table of property names. */ if ( font->internal ) { ft_hash_str_free( (FT_Hash)font->internal, memory ); FT_FREE( font->internal ); } /* Free up the comment info. */ FT_FREE( font->comments ); /* Free up the properties. */ for ( i = 0; i < font->props_size; i++ ) { if ( font->props[i].format == BDF_ATOM ) FT_FREE( font->props[i].value.atom ); } FT_FREE( font->props ); /* Free up the character info. */ for ( i = 0, glyphs = font->glyphs; i < font->glyphs_used; i++, glyphs++ ) { FT_FREE( glyphs->name ); FT_FREE( glyphs->bitmap ); } for ( i = 0, glyphs = font->unencoded; i < font->unencoded_used; i++, glyphs++ ) { FT_FREE( glyphs->name ); FT_FREE( glyphs->bitmap ); } FT_FREE( font->glyphs ); FT_FREE( font->unencoded ); /* bdf_cleanup */ ft_hash_str_free( &(font->proptbl), memory ); /* Free up the user defined properties. */ for ( prop = font->user_props, i = 0; i < font->nuser_props; i++, prop++ ) FT_FREE( prop->name ); FT_FREE( font->user_props ); /* FREE( font ); */ /* XXX Fixme */ } FT_LOCAL_DEF( bdf_property_t * ) bdf_get_font_property( bdf_font_t* font, const char* name ) { size_t* propid; if ( font == NULL || font->props_size == 0 || name == NULL || *name == 0 ) return 0; propid = ft_hash_str_lookup( name, (FT_Hash)font->internal ); return propid ? ( font->props + *propid ) : 0; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/bdflib.c
C++
gpl-3.0
68,360
# # FreeType 2 BDF module definition # # Copyright 2001, 2002, 2006 by # Francesco Zappa Nardelli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. FTMODULE_H_COMMANDS += BDF_DRIVER define BDF_DRIVER $(OPEN_DRIVER) FT_Driver_ClassRec, bdf_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)bdf $(ECHO_DRIVER_DESC)bdf bitmap fonts$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/module.mk
mk
gpl-3.0
1,372
# # FreeType 2 bdf driver configuration rules # # Copyright (C) 2001, 2002, 2003, 2008 by # Francesco Zappa Nardelli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # bdf driver directory # BDF_DIR := $(SRC_DIR)/bdf BDF_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(BDF_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # bdf driver sources (i.e., C files) # BDF_DRV_SRC := $(BDF_DIR)/bdflib.c \ $(BDF_DIR)/bdfdrivr.c # bdf driver headers # BDF_DRV_H := $(BDF_DIR)/bdf.h \ $(BDF_DIR)/bdfdrivr.h \ $(BDF_DIR)/bdferror.h # bdf driver object(s) # # BDF_DRV_OBJ_M is used during `multi' builds # BDF_DRV_OBJ_S is used during `single' builds # BDF_DRV_OBJ_M := $(BDF_DRV_SRC:$(BDF_DIR)/%.c=$(OBJ_DIR)/%.$O) BDF_DRV_OBJ_S := $(OBJ_DIR)/bdf.$O # bdf driver source file for single build # BDF_DRV_SRC_S := $(BDF_DIR)/bdf.c # bdf driver - single object # $(BDF_DRV_OBJ_S): $(BDF_DRV_SRC_S) $(BDF_DRV_SRC) $(FREETYPE_H) $(BDF_DRV_H) $(BDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(BDF_DRV_SRC_S)) # bdf driver - multiple objects # $(OBJ_DIR)/%.$O: $(BDF_DIR)/%.c $(FREETYPE_H) $(BDF_DRV_H) $(BDF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(BDF_DRV_OBJ_S) DRV_OBJS_M += $(BDF_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/bdf/rules.mk
mk
gpl-3.0
2,432
/**************************************************************************** * * ftbzip2.c * * FreeType support for .bz2 compressed files. * * This optional component relies on libbz2. It should mainly be used to * parse compressed PCF fonts, as found with many X11 server * distributions. * * Copyright (C) 2010-2022 by * Joel Klinghed. * * based on `src/gzip/ftgzip.c' * * 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/ftmemory.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/ftdebug.h> #include <freetype/ftbzip2.h> #include FT_CONFIG_STANDARD_LIBRARY_H #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX Bzip2_Err_ #define FT_ERR_BASE FT_Mod_Err_Bzip2 #include <freetype/fterrors.h> #ifdef FT_CONFIG_OPTION_USE_BZIP2 #define BZ_NO_STDIO /* Do not need FILE */ #include <bzlib.h> /***************************************************************************/ /***************************************************************************/ /***** *****/ /***** B Z I P 2 M E M O R Y M A N A G E M E N T *****/ /***** *****/ /***************************************************************************/ /***************************************************************************/ /* it is better to use FreeType memory routines instead of raw 'malloc/free' */ typedef void *(* alloc_func)(void*, int, int); typedef void (* free_func)(void*, void*); static void* ft_bzip2_alloc( FT_Memory memory, int items, int size ) { FT_ULong sz = (FT_ULong)size * (FT_ULong)items; FT_Error error; FT_Pointer p = NULL; FT_MEM_QALLOC( p, sz ); return p; } static void ft_bzip2_free( FT_Memory memory, void* address ) { FT_MEM_FREE( address ); } /***************************************************************************/ /***************************************************************************/ /***** *****/ /***** B Z I P 2 F I L E D E S C R I P T O R *****/ /***** *****/ /***************************************************************************/ /***************************************************************************/ #define FT_BZIP2_BUFFER_SIZE 4096 typedef struct FT_BZip2FileRec_ { FT_Stream source; /* parent/source stream */ FT_Stream stream; /* embedding stream */ FT_Memory memory; /* memory allocator */ bz_stream bzstream; /* bzlib input stream */ FT_Byte input[FT_BZIP2_BUFFER_SIZE]; /* input read buffer */ FT_Byte buffer[FT_BZIP2_BUFFER_SIZE]; /* output buffer */ FT_ULong pos; /* position in output */ FT_Byte* cursor; FT_Byte* limit; FT_Bool reset; /* reset before next read */ } FT_BZip2FileRec, *FT_BZip2File; /* check and skip .bz2 header - we don't support `transparent' compression */ static FT_Error ft_bzip2_check_header( FT_Stream stream ) { FT_Error error = FT_Err_Ok; FT_Byte head[4]; if ( FT_STREAM_SEEK( 0 ) || FT_STREAM_READ( head, 4 ) ) goto Exit; /* head[0] && head[1] are the magic numbers; */ /* head[2] is the version, and head[3] the blocksize */ if ( head[0] != 0x42 || head[1] != 0x5A || head[2] != 0x68 ) /* only support bzip2 (huffman) */ { error = FT_THROW( Invalid_File_Format ); goto Exit; } Exit: return error; } static FT_Error ft_bzip2_file_init( FT_BZip2File zip, FT_Stream stream, FT_Stream source ) { bz_stream* bzstream = &zip->bzstream; FT_Error error = FT_Err_Ok; zip->stream = stream; zip->source = source; zip->memory = stream->memory; zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE; zip->cursor = zip->limit; zip->pos = 0; zip->reset = 0; /* check .bz2 header */ { stream = source; error = ft_bzip2_check_header( stream ); if ( error ) goto Exit; if ( FT_STREAM_SEEK( 0 ) ) goto Exit; } /* initialize bzlib */ bzstream->bzalloc = (alloc_func)ft_bzip2_alloc; bzstream->bzfree = (free_func) ft_bzip2_free; bzstream->opaque = zip->memory; bzstream->avail_in = 0; bzstream->next_in = (char*)zip->buffer; if ( BZ2_bzDecompressInit( bzstream, 0, 0 ) != BZ_OK || !bzstream->next_in ) error = FT_THROW( Invalid_File_Format ); Exit: return error; } static void ft_bzip2_file_done( FT_BZip2File zip ) { bz_stream* bzstream = &zip->bzstream; BZ2_bzDecompressEnd( bzstream ); /* clear the rest */ bzstream->bzalloc = NULL; bzstream->bzfree = NULL; bzstream->opaque = NULL; bzstream->next_in = NULL; bzstream->next_out = NULL; bzstream->avail_in = 0; bzstream->avail_out = 0; zip->memory = NULL; zip->source = NULL; zip->stream = NULL; } static FT_Error ft_bzip2_file_reset( FT_BZip2File zip ) { FT_Stream stream = zip->source; FT_Error error; if ( !FT_STREAM_SEEK( 0 ) ) { bz_stream* bzstream = &zip->bzstream; BZ2_bzDecompressEnd( bzstream ); bzstream->avail_in = 0; bzstream->next_in = (char*)zip->input; bzstream->avail_out = 0; bzstream->next_out = (char*)zip->buffer; zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE; zip->cursor = zip->limit; zip->pos = 0; zip->reset = 0; BZ2_bzDecompressInit( bzstream, 0, 0 ); } return error; } static FT_Error ft_bzip2_file_fill_input( FT_BZip2File zip ) { bz_stream* bzstream = &zip->bzstream; FT_Stream stream = zip->source; FT_ULong size; if ( stream->read ) { size = stream->read( stream, stream->pos, zip->input, FT_BZIP2_BUFFER_SIZE ); if ( size == 0 ) { zip->limit = zip->cursor; return FT_THROW( Invalid_Stream_Operation ); } } else { size = stream->size - stream->pos; if ( size > FT_BZIP2_BUFFER_SIZE ) size = FT_BZIP2_BUFFER_SIZE; if ( size == 0 ) { zip->limit = zip->cursor; return FT_THROW( Invalid_Stream_Operation ); } FT_MEM_COPY( zip->input, stream->base + stream->pos, size ); } stream->pos += size; bzstream->next_in = (char*)zip->input; bzstream->avail_in = size; return FT_Err_Ok; } static FT_Error ft_bzip2_file_fill_output( FT_BZip2File zip ) { bz_stream* bzstream = &zip->bzstream; FT_Error error = FT_Err_Ok; zip->cursor = zip->buffer; bzstream->next_out = (char*)zip->cursor; bzstream->avail_out = FT_BZIP2_BUFFER_SIZE; while ( bzstream->avail_out > 0 ) { int err; if ( bzstream->avail_in == 0 ) { error = ft_bzip2_file_fill_input( zip ); if ( error ) break; } err = BZ2_bzDecompress( bzstream ); if ( err != BZ_OK ) { zip->reset = 1; if ( err == BZ_STREAM_END ) { zip->limit = (FT_Byte*)bzstream->next_out; if ( zip->limit == zip->cursor ) error = FT_THROW( Invalid_Stream_Operation ); break; } else { zip->limit = zip->cursor; error = FT_THROW( Invalid_Stream_Operation ); break; } } } return error; } /* fill output buffer; `count' must be <= FT_BZIP2_BUFFER_SIZE */ static FT_Error ft_bzip2_file_skip_output( FT_BZip2File zip, FT_ULong count ) { FT_Error error = FT_Err_Ok; for (;;) { FT_ULong delta = (FT_ULong)( zip->limit - zip->cursor ); if ( delta >= count ) delta = count; zip->cursor += delta; zip->pos += delta; count -= delta; if ( count == 0 ) break; error = ft_bzip2_file_fill_output( zip ); if ( error ) break; } return error; } static FT_ULong ft_bzip2_file_io( FT_BZip2File zip, FT_ULong pos, FT_Byte* buffer, FT_ULong count ) { FT_ULong result = 0; FT_Error error; /* Reset inflate stream if seeking backwards or bzip reported an error. */ /* Yes, that is not too efficient, but it saves memory :-) */ if ( pos < zip->pos || zip->reset ) { error = ft_bzip2_file_reset( zip ); if ( error ) goto Exit; } /* skip unwanted bytes */ if ( pos > zip->pos ) { error = ft_bzip2_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) ); if ( error ) goto Exit; } if ( count == 0 ) goto Exit; /* now read the data */ for (;;) { FT_ULong delta; delta = (FT_ULong)( zip->limit - zip->cursor ); if ( delta >= count ) delta = count; FT_MEM_COPY( buffer, zip->cursor, delta ); buffer += delta; result += delta; zip->cursor += delta; zip->pos += delta; count -= delta; if ( count == 0 ) break; error = ft_bzip2_file_fill_output( zip ); if ( error ) break; } Exit: return result; } /***************************************************************************/ /***************************************************************************/ /***** *****/ /***** B Z E M B E D D I N G S T R E A M *****/ /***** *****/ /***************************************************************************/ /***************************************************************************/ static void ft_bzip2_stream_close( FT_Stream stream ) { FT_BZip2File zip = (FT_BZip2File)stream->descriptor.pointer; FT_Memory memory = stream->memory; if ( zip ) { /* finalize bzip file descriptor */ ft_bzip2_file_done( zip ); FT_FREE( zip ); stream->descriptor.pointer = NULL; } } static unsigned long ft_bzip2_stream_io( FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count ) { FT_BZip2File zip = (FT_BZip2File)stream->descriptor.pointer; return ft_bzip2_file_io( zip, offset, buffer, count ); } FT_EXPORT_DEF( FT_Error ) FT_Stream_OpenBzip2( FT_Stream stream, FT_Stream source ) { FT_Error error; FT_Memory memory; FT_BZip2File zip = NULL; if ( !stream || !source ) { error = FT_THROW( Invalid_Stream_Handle ); goto Exit; } memory = source->memory; /* * check the header right now; this prevents allocating unnecessary * objects when we don't need them */ error = ft_bzip2_check_header( source ); if ( error ) goto Exit; FT_ZERO( stream ); stream->memory = memory; if ( !FT_QNEW( zip ) ) { error = ft_bzip2_file_init( zip, stream, source ); if ( error ) { FT_FREE( zip ); goto Exit; } stream->descriptor.pointer = zip; } stream->size = 0x7FFFFFFFL; /* don't know the real size! */ stream->pos = 0; stream->base = NULL; stream->read = ft_bzip2_stream_io; stream->close = ft_bzip2_stream_close; Exit: return error; } #else /* !FT_CONFIG_OPTION_USE_BZIP2 */ FT_EXPORT_DEF( FT_Error ) FT_Stream_OpenBzip2( FT_Stream stream, FT_Stream source ) { FT_UNUSED( stream ); FT_UNUSED( source ); return FT_THROW( Unimplemented_Feature ); } #endif /* !FT_CONFIG_OPTION_USE_BZIP2 */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/bzip2/ftbzip2.c
C++
gpl-3.0
12,781
# # FreeType 2 BZIP2 support configuration rules # # Copyright (C) 2010-2022 by # Joel Klinghed. # # based on `src/lzw/rules.mk' # # 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. # BZIP2 driver directory # BZIP2_DIR := $(SRC_DIR)/bzip2 # compilation flags for the driver # BZIP2_COMPILE := $(CC) $(ANSIFLAGS) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # BZIP2 support sources (i.e., C files) # BZIP2_DRV_SRC := $(BZIP2_DIR)/ftbzip2.c # BZIP2 driver object(s) # # BZIP2_DRV_OBJ_M is used during `multi' builds # BZIP2_DRV_OBJ_S is used during `single' builds # BZIP2_DRV_OBJ_M := $(OBJ_DIR)/ftbzip2.$O BZIP2_DRV_OBJ_S := $(OBJ_DIR)/ftbzip2.$O # BZIP2 support source file for single build # BZIP2_DRV_SRC_S := $(BZIP2_DIR)/ftbzip2.c # BZIP2 support - single object # $(BZIP2_DRV_OBJ_S): $(BZIP2_DRV_SRC_S) $(BZIP2_DRV_SRC) $(FREETYPE_H) $(BZIP2_DRV_H) $(BZIP2_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(BZIP2_DRV_SRC_S)) # BZIP2 support - multiple objects # $(OBJ_DIR)/%.$O: $(BZIP2_DIR)/%.c $(FREETYPE_H) $(BZIP2_DRV_H) $(BZIP2_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(BZIP2_DRV_OBJ_S) DRV_OBJS_M += $(BZIP2_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/bzip2/rules.mk
mk
gpl-3.0
1,492
/**************************************************************************** * * ftcache.c * * The FreeType Caching sub-system (body only). * * 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. * */ #define FT_MAKE_OPTION_SINGLE_OBJECT #include "ftcbasic.c" #include "ftccache.c" #include "ftccmap.c" #include "ftcglyph.c" #include "ftcimage.c" #include "ftcmanag.c" #include "ftcmru.c" #include "ftcsbits.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcache.c
C++
gpl-3.0
771
/**************************************************************************** * * ftcbasic.c * * The FreeType basic cache interface (body). * * 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. * */ #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/ftcache.h> #include "ftcglyph.h" #include "ftcimage.h" #include "ftcsbits.h" #include "ftccback.h" #include "ftcerror.h" #undef FT_COMPONENT #define FT_COMPONENT cache /* * Basic Families * */ typedef struct FTC_BasicAttrRec_ { FTC_ScalerRec scaler; FT_UInt load_flags; } FTC_BasicAttrRec, *FTC_BasicAttrs; #define FTC_BASIC_ATTR_COMPARE( a, b ) \ FT_BOOL( FTC_SCALER_COMPARE( &(a)->scaler, &(b)->scaler ) && \ (a)->load_flags == (b)->load_flags ) #define FTC_BASIC_ATTR_HASH( a ) \ ( FTC_SCALER_HASH( &(a)->scaler ) + 31 * (a)->load_flags ) typedef struct FTC_BasicQueryRec_ { FTC_GQueryRec gquery; FTC_BasicAttrRec attrs; } FTC_BasicQueryRec, *FTC_BasicQuery; typedef struct FTC_BasicFamilyRec_ { FTC_FamilyRec family; FTC_BasicAttrRec attrs; } FTC_BasicFamilyRec, *FTC_BasicFamily; FT_CALLBACK_DEF( FT_Bool ) ftc_basic_family_compare( FTC_MruNode ftcfamily, FT_Pointer ftcquery ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FTC_BasicQuery query = (FTC_BasicQuery)ftcquery; return FTC_BASIC_ATTR_COMPARE( &family->attrs, &query->attrs ); } FT_CALLBACK_DEF( FT_Error ) ftc_basic_family_init( FTC_MruNode ftcfamily, FT_Pointer ftcquery, FT_Pointer ftccache ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FTC_BasicQuery query = (FTC_BasicQuery)ftcquery; FTC_Cache cache = (FTC_Cache)ftccache; FTC_Family_Init( FTC_FAMILY( family ), cache ); family->attrs = query->attrs; return 0; } FT_CALLBACK_DEF( FT_UInt ) ftc_basic_family_get_count( FTC_Family ftcfamily, FTC_Manager manager ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FT_Error error; FT_Face face; FT_UInt result = 0; error = FTC_Manager_LookupFace( manager, family->attrs.scaler.face_id, &face ); if ( error || !face ) return result; #ifdef FT_DEBUG_LEVEL_TRACE if ( (FT_ULong)face->num_glyphs > FT_UINT_MAX || 0 > face->num_glyphs ) { FT_TRACE1(( "ftc_basic_family_get_count:" " the number of glyphs in this face is %ld,\n", face->num_glyphs )); FT_TRACE1(( " " " which is too much and thus truncated\n" )); } #endif if ( !error ) result = (FT_UInt)face->num_glyphs; return result; } FT_CALLBACK_DEF( FT_Error ) ftc_basic_family_load_bitmap( FTC_Family ftcfamily, FT_UInt gindex, FTC_Manager manager, FT_Face *aface ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FT_Error error; FT_Size size; error = FTC_Manager_LookupSize( manager, &family->attrs.scaler, &size ); if ( !error ) { FT_Face face = size->face; error = FT_Load_Glyph( face, gindex, (FT_Int)family->attrs.load_flags | FT_LOAD_RENDER ); if ( !error ) *aface = face; } return error; } FT_CALLBACK_DEF( FT_Error ) ftc_basic_family_load_glyph( FTC_Family ftcfamily, FT_UInt gindex, FTC_Cache cache, FT_Glyph *aglyph ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FT_Error error; FTC_Scaler scaler = &family->attrs.scaler; FT_Face face; FT_Size size; /* we will now load the glyph image */ error = FTC_Manager_LookupSize( cache->manager, scaler, &size ); if ( !error ) { face = size->face; error = FT_Load_Glyph( face, gindex, (FT_Int)family->attrs.load_flags ); if ( !error ) { if ( face->glyph->format == FT_GLYPH_FORMAT_BITMAP || face->glyph->format == FT_GLYPH_FORMAT_OUTLINE || face->glyph->format == FT_GLYPH_FORMAT_SVG ) { /* ok, copy it */ FT_Glyph glyph; error = FT_Get_Glyph( face->glyph, &glyph ); if ( !error ) { *aglyph = glyph; goto Exit; } } else error = FT_THROW( Invalid_Argument ); } } Exit: return error; } FT_CALLBACK_DEF( FT_Bool ) ftc_basic_gnode_compare_faceid( FTC_Node ftcgnode, FT_Pointer ftcface_id, FTC_Cache cache, FT_Bool* list_changed ) { FTC_GNode gnode = (FTC_GNode)ftcgnode; FTC_FaceID face_id = (FTC_FaceID)ftcface_id; FTC_BasicFamily family = (FTC_BasicFamily)gnode->family; FT_Bool result; if ( list_changed ) *list_changed = FALSE; result = FT_BOOL( family->attrs.scaler.face_id == face_id ); if ( result ) { /* we must call this function to avoid this node from appearing * in later lookups with the same face_id! */ FTC_GNode_UnselectFamily( gnode, cache ); } return result; } /* * * basic image cache * */ static const FTC_IFamilyClassRec ftc_basic_image_family_class = { { sizeof ( FTC_BasicFamilyRec ), ftc_basic_family_compare, /* FTC_MruNode_CompareFunc node_compare */ ftc_basic_family_init, /* FTC_MruNode_InitFunc node_init */ NULL, /* FTC_MruNode_ResetFunc node_reset */ NULL /* FTC_MruNode_DoneFunc node_done */ }, ftc_basic_family_load_glyph /* FTC_IFamily_LoadGlyphFunc family_load_glyph */ }; static const FTC_GCacheClassRec ftc_basic_image_cache_class = { { ftc_inode_new, /* FTC_Node_NewFunc node_new */ ftc_inode_weight, /* FTC_Node_WeightFunc node_weight */ ftc_gnode_compare, /* FTC_Node_CompareFunc node_compare */ ftc_basic_gnode_compare_faceid, /* FTC_Node_CompareFunc node_remove_faceid */ ftc_inode_free, /* FTC_Node_FreeFunc node_free */ sizeof ( FTC_GCacheRec ), ftc_gcache_init, /* FTC_Cache_InitFunc cache_init */ ftc_gcache_done /* FTC_Cache_DoneFunc cache_done */ }, (FTC_MruListClass)&ftc_basic_image_family_class }; /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_ImageCache_New( FTC_Manager manager, FTC_ImageCache *acache ) { return FTC_GCache_New( manager, &ftc_basic_image_cache_class, (FTC_GCache*)acache ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_ImageCache_Lookup( FTC_ImageCache cache, FTC_ImageType type, FT_UInt gindex, FT_Glyph *aglyph, FTC_Node *anode ) { FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Error error; FT_Offset hash; /* some argument checks are delayed to `FTC_Cache_Lookup' */ if ( !aglyph ) { error = FT_THROW( Invalid_Argument ); goto Exit; } *aglyph = NULL; if ( anode ) *anode = NULL; /* * Internal `FTC_BasicAttr->load_flags' is of type `FT_UInt', * but public `FT_ImageType->flags' is of type `FT_Int32'. * * On 16bit systems, higher bits of type->flags cannot be handled. */ #if 0xFFFFFFFFUL > FT_UINT_MAX if ( (type->flags & (FT_ULong)FT_UINT_MAX) ) FT_TRACE1(( "FTC_ImageCache_Lookup:" " higher bits in load_flags 0x%x are dropped\n", (FT_ULong)type->flags & ~((FT_ULong)FT_UINT_MAX) )); #endif query.attrs.scaler.face_id = type->face_id; query.attrs.scaler.width = type->width; query.attrs.scaler.height = type->height; query.attrs.load_flags = (FT_UInt)type->flags; query.attrs.scaler.pixel = 1; query.attrs.scaler.x_res = 0; /* make compilers happy */ query.attrs.scaler.y_res = 0; hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + gindex; #if 1 /* inlining is about 50% faster! */ FTC_GCACHE_LOOKUP_CMP( cache, ftc_basic_family_compare, FTC_GNode_Compare, hash, gindex, &query, node, error ); #else error = FTC_GCache_Lookup( FTC_GCACHE( cache ), hash, gindex, FTC_GQUERY( &query ), &node ); #endif if ( !error ) { *aglyph = FTC_INODE( node )->glyph; if ( anode ) { *anode = node; node->ref_count++; } } Exit: return error; } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_ImageCache_LookupScaler( FTC_ImageCache cache, FTC_Scaler scaler, FT_ULong load_flags, FT_UInt gindex, FT_Glyph *aglyph, FTC_Node *anode ) { FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Error error; FT_Offset hash; /* some argument checks are delayed to `FTC_Cache_Lookup' */ if ( !aglyph || !scaler ) { error = FT_THROW( Invalid_Argument ); goto Exit; } *aglyph = NULL; if ( anode ) *anode = NULL; /* * Internal `FTC_BasicAttr->load_flags' is of type `FT_UInt', * but public `FT_Face->face_flags' is of type `FT_Long'. * * On long > int systems, higher bits of load_flags cannot be handled. */ #if FT_ULONG_MAX > FT_UINT_MAX if ( load_flags > FT_UINT_MAX ) FT_TRACE1(( "FTC_ImageCache_LookupScaler:" " higher bits in load_flags 0x%lx are dropped\n", load_flags & ~((FT_ULong)FT_UINT_MAX) )); #endif query.attrs.scaler = scaler[0]; query.attrs.load_flags = (FT_UInt)load_flags; hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + gindex; FTC_GCACHE_LOOKUP_CMP( cache, ftc_basic_family_compare, FTC_GNode_Compare, hash, gindex, &query, node, error ); if ( !error ) { *aglyph = FTC_INODE( node )->glyph; if ( anode ) { *anode = node; node->ref_count++; } } Exit: return error; } /* * * basic small bitmap cache * */ static const FTC_SFamilyClassRec ftc_basic_sbit_family_class = { { sizeof ( FTC_BasicFamilyRec ), ftc_basic_family_compare, /* FTC_MruNode_CompareFunc node_compare */ ftc_basic_family_init, /* FTC_MruNode_InitFunc node_init */ NULL, /* FTC_MruNode_ResetFunc node_reset */ NULL /* FTC_MruNode_DoneFunc node_done */ }, ftc_basic_family_get_count, ftc_basic_family_load_bitmap }; static const FTC_GCacheClassRec ftc_basic_sbit_cache_class = { { ftc_snode_new, /* FTC_Node_NewFunc node_new */ ftc_snode_weight, /* FTC_Node_WeightFunc node_weight */ ftc_snode_compare, /* FTC_Node_CompareFunc node_compare */ ftc_basic_gnode_compare_faceid, /* FTC_Node_CompareFunc node_remove_faceid */ ftc_snode_free, /* FTC_Node_FreeFunc node_free */ sizeof ( FTC_GCacheRec ), ftc_gcache_init, /* FTC_Cache_InitFunc cache_init */ ftc_gcache_done /* FTC_Cache_DoneFunc cache_done */ }, (FTC_MruListClass)&ftc_basic_sbit_family_class }; /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_SBitCache_New( FTC_Manager manager, FTC_SBitCache *acache ) { return FTC_GCache_New( manager, &ftc_basic_sbit_cache_class, (FTC_GCache*)acache ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_SBitCache_Lookup( FTC_SBitCache cache, FTC_ImageType type, FT_UInt gindex, FTC_SBit *ansbit, FTC_Node *anode ) { FT_Error error; FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Offset hash; if ( anode ) *anode = NULL; /* other argument checks delayed to `FTC_Cache_Lookup' */ if ( !ansbit ) return FT_THROW( Invalid_Argument ); *ansbit = NULL; /* * Internal `FTC_BasicAttr->load_flags' is of type `FT_UInt', * but public `FT_ImageType->flags' is of type `FT_Int32'. * * On 16bit systems, higher bits of type->flags cannot be handled. */ #if 0xFFFFFFFFUL > FT_UINT_MAX if ( (type->flags & (FT_ULong)FT_UINT_MAX) ) FT_TRACE1(( "FTC_ImageCache_Lookup:" " higher bits in load_flags 0x%x are dropped\n", (FT_ULong)type->flags & ~((FT_ULong)FT_UINT_MAX) )); #endif query.attrs.scaler.face_id = type->face_id; query.attrs.scaler.width = type->width; query.attrs.scaler.height = type->height; query.attrs.load_flags = (FT_UInt)type->flags; query.attrs.scaler.pixel = 1; query.attrs.scaler.x_res = 0; /* make compilers happy */ query.attrs.scaler.y_res = 0; /* beware, the hash must be the same for all glyph ranges! */ hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + gindex / FTC_SBIT_ITEMS_PER_NODE; #if 1 /* inlining is about 50% faster! */ FTC_GCACHE_LOOKUP_CMP( cache, ftc_basic_family_compare, FTC_SNode_Compare, hash, gindex, &query, node, error ); #else error = FTC_GCache_Lookup( FTC_GCACHE( cache ), hash, gindex, FTC_GQUERY( &query ), &node ); #endif if ( error ) goto Exit; *ansbit = FTC_SNODE( node )->sbits + ( gindex - FTC_GNODE( node )->gindex ); if ( anode ) { *anode = node; node->ref_count++; } Exit: return error; } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_SBitCache_LookupScaler( FTC_SBitCache cache, FTC_Scaler scaler, FT_ULong load_flags, FT_UInt gindex, FTC_SBit *ansbit, FTC_Node *anode ) { FT_Error error; FTC_BasicQueryRec query; FTC_Node node = 0; /* make compiler happy */ FT_Offset hash; if ( anode ) *anode = NULL; /* other argument checks delayed to `FTC_Cache_Lookup' */ if ( !ansbit || !scaler ) return FT_THROW( Invalid_Argument ); *ansbit = NULL; /* * Internal `FTC_BasicAttr->load_flags' is of type `FT_UInt', * but public `FT_Face->face_flags' is of type `FT_Long'. * * On long > int systems, higher bits of load_flags cannot be handled. */ #if FT_ULONG_MAX > FT_UINT_MAX if ( load_flags > FT_UINT_MAX ) FT_TRACE1(( "FTC_ImageCache_LookupScaler:" " higher bits in load_flags 0x%lx are dropped\n", load_flags & ~((FT_ULong)FT_UINT_MAX) )); #endif query.attrs.scaler = scaler[0]; query.attrs.load_flags = (FT_UInt)load_flags; /* beware, the hash must be the same for all glyph ranges! */ hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + gindex / FTC_SBIT_ITEMS_PER_NODE; FTC_GCACHE_LOOKUP_CMP( cache, ftc_basic_family_compare, FTC_SNode_Compare, hash, gindex, &query, node, error ); if ( error ) goto Exit; *ansbit = FTC_SNODE( node )->sbits + ( gindex - FTC_GNODE( node )->gindex ); if ( anode ) { *anode = node; node->ref_count++; } Exit: return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcbasic.c
C++
gpl-3.0
18,051
/**************************************************************************** * * ftccache.c * * The FreeType internal cache 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 "ftcmanag.h" #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include "ftccback.h" #include "ftcerror.h" #undef FT_COMPONENT #define FT_COMPONENT cache #define FTC_HASH_MAX_LOAD 2 #define FTC_HASH_MIN_LOAD 1 #define FTC_HASH_SUB_LOAD ( FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD ) /* this one _must_ be a power of 2! */ #define FTC_HASH_INITIAL_SIZE 8 /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE NODE DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* add a new node to the head of the manager's circular MRU list */ static void ftc_node_mru_link( FTC_Node node, FTC_Manager manager ) { void *nl = &manager->nodes_list; FTC_MruNode_Prepend( (FTC_MruNode*)nl, (FTC_MruNode)node ); manager->num_nodes++; } /* remove a node from the manager's MRU list */ static void ftc_node_mru_unlink( FTC_Node node, FTC_Manager manager ) { void *nl = &manager->nodes_list; FTC_MruNode_Remove( (FTC_MruNode*)nl, (FTC_MruNode)node ); manager->num_nodes--; } #ifndef FTC_INLINE /* move a node to the head of the manager's MRU list */ static void ftc_node_mru_up( FTC_Node node, FTC_Manager manager ) { FTC_MruNode_Up( (FTC_MruNode*)&manager->nodes_list, (FTC_MruNode)node ); } /* get a top bucket for specified hash from cache, * body for FTC_NODE_TOP_FOR_HASH( cache, hash ) */ FT_LOCAL_DEF( FTC_Node* ) ftc_get_top_node_for_hash( FTC_Cache cache, FT_Offset hash ) { FT_Offset idx; idx = hash & cache->mask; if ( idx < cache->p ) idx = hash & ( 2 * cache->mask + 1 ); return cache->buckets + idx; } #endif /* !FTC_INLINE */ /* Note that this function cannot fail. If we cannot re-size the * buckets array appropriately, we simply degrade the hash table's * performance! */ static void ftc_cache_resize( FTC_Cache cache ) { for (;;) { FTC_Node node, *pnode; FT_UFast p = cache->p; FT_UFast mask = cache->mask; FT_UFast count = mask + p + 1; /* number of buckets */ /* do we need to expand the buckets array? */ if ( cache->slack < 0 ) { FTC_Node new_list = NULL; /* try to expand the buckets array _before_ splitting * the bucket lists */ if ( p >= mask ) { FT_Memory memory = cache->memory; FT_Error error; /* if we can't expand the array, leave immediately */ if ( FT_RENEW_ARRAY( cache->buckets, ( mask + 1 ) * 2, ( mask + 1 ) * 4 ) ) break; } /* split a single bucket */ pnode = cache->buckets + p; for (;;) { node = *pnode; if ( !node ) break; if ( node->hash & ( mask + 1 ) ) { *pnode = node->link; node->link = new_list; new_list = node; } else pnode = &node->link; } cache->buckets[p + mask + 1] = new_list; cache->slack += FTC_HASH_MAX_LOAD; if ( p >= mask ) { cache->mask = 2 * mask + 1; cache->p = 0; } else cache->p = p + 1; } /* do we need to shrink the buckets array? */ else if ( cache->slack > (FT_Long)count * FTC_HASH_SUB_LOAD ) { FT_UFast old_index = p + mask; FTC_Node* pold; if ( old_index + 1 <= FTC_HASH_INITIAL_SIZE ) break; if ( p == 0 ) { FT_Memory memory = cache->memory; FT_Error error; /* if we can't shrink the array, leave immediately */ if ( FT_QRENEW_ARRAY( cache->buckets, ( mask + 1 ) * 2, mask + 1 ) ) break; cache->mask >>= 1; p = cache->mask; } else p--; pnode = cache->buckets + p; while ( *pnode ) pnode = &(*pnode)->link; pold = cache->buckets + old_index; *pnode = *pold; *pold = NULL; cache->slack -= FTC_HASH_MAX_LOAD; cache->p = p; } /* otherwise, the hash table is balanced */ else break; } } /* remove a node from its cache's hash table */ static void ftc_node_hash_unlink( FTC_Node node0, FTC_Cache cache ) { FTC_Node *pnode = FTC_NODE_TOP_FOR_HASH( cache, node0->hash ); for (;;) { FTC_Node node = *pnode; if ( !node ) { FT_TRACE0(( "ftc_node_hash_unlink: unknown node\n" )); return; } if ( node == node0 ) break; pnode = &(*pnode)->link; } *pnode = node0->link; node0->link = NULL; cache->slack++; ftc_cache_resize( cache ); } /* add a node to the `top' of its cache's hash table */ static void ftc_node_hash_link( FTC_Node node, FTC_Cache cache ) { FTC_Node *pnode = FTC_NODE_TOP_FOR_HASH( cache, node->hash ); node->link = *pnode; *pnode = node; cache->slack--; ftc_cache_resize( cache ); } /* remove a node from the cache manager */ FT_LOCAL_DEF( void ) ftc_node_destroy( FTC_Node node, FTC_Manager manager ) { FTC_Cache cache; #ifdef FT_DEBUG_ERROR /* find node's cache */ if ( node->cache_index >= manager->num_caches ) { FT_TRACE0(( "ftc_node_destroy: invalid node handle\n" )); return; } #endif cache = manager->caches[node->cache_index]; #ifdef FT_DEBUG_ERROR if ( !cache ) { FT_TRACE0(( "ftc_node_destroy: invalid node handle\n" )); return; } #endif manager->cur_weight -= cache->clazz.node_weight( node, cache ); /* remove node from mru list */ ftc_node_mru_unlink( node, manager ); /* remove node from cache's hash table */ ftc_node_hash_unlink( node, cache ); /* now finalize it */ cache->clazz.node_free( node, cache ); #if 0 /* check, just in case of general corruption :-) */ if ( manager->num_nodes == 0 ) FT_TRACE0(( "ftc_node_destroy: invalid cache node count (%d)\n", manager->num_nodes )); #endif } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** ABSTRACT CACHE CLASS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( FT_Error ) FTC_Cache_Init( FTC_Cache cache ) { return ftc_cache_init( cache ); } FT_LOCAL_DEF( FT_Error ) ftc_cache_init( FTC_Cache cache ) { FT_Memory memory = cache->memory; FT_Error error; cache->p = 0; cache->mask = FTC_HASH_INITIAL_SIZE - 1; cache->slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD; FT_MEM_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 ); return error; } static void FTC_Cache_Clear( FTC_Cache cache ) { if ( cache && cache->buckets ) { FTC_Manager manager = cache->manager; FT_UFast i; FT_UFast count; count = cache->p + cache->mask + 1; for ( i = 0; i < count; i++ ) { FTC_Node node = cache->buckets[i], next; while ( node ) { next = node->link; node->link = NULL; /* remove node from mru list */ ftc_node_mru_unlink( node, manager ); /* now finalize it */ manager->cur_weight -= cache->clazz.node_weight( node, cache ); cache->clazz.node_free( node, cache ); node = next; } cache->buckets[i] = NULL; } ftc_cache_resize( cache ); } } FT_LOCAL_DEF( void ) ftc_cache_done( FTC_Cache cache ) { if ( cache->memory ) { FT_Memory memory = cache->memory; FTC_Cache_Clear( cache ); FT_FREE( cache->buckets ); cache->mask = 0; cache->p = 0; cache->slack = 0; cache->memory = NULL; } } FT_LOCAL_DEF( void ) FTC_Cache_Done( FTC_Cache cache ) { ftc_cache_done( cache ); } static void ftc_cache_add( FTC_Cache cache, FT_Offset hash, FTC_Node node ) { node->hash = hash; node->cache_index = (FT_UShort)cache->index; node->ref_count = 0; ftc_node_hash_link( node, cache ); ftc_node_mru_link( node, cache->manager ); { FTC_Manager manager = cache->manager; manager->cur_weight += cache->clazz.node_weight( node, cache ); if ( manager->cur_weight >= manager->max_weight ) { node->ref_count++; FTC_Manager_Compress( manager ); node->ref_count--; } } } FT_LOCAL_DEF( FT_Error ) FTC_Cache_NewNode( FTC_Cache cache, FT_Offset hash, FT_Pointer query, FTC_Node *anode ) { FT_Error error; FTC_Node node; /* * We use the FTC_CACHE_TRYLOOP macros to support out-of-memory * errors (OOM) correctly, i.e., by flushing the cache progressively * in order to make more room. */ FTC_CACHE_TRYLOOP( cache ) { error = cache->clazz.node_new( &node, query, cache ); } FTC_CACHE_TRYLOOP_END( NULL ) if ( error ) node = NULL; else { /* don't assume that the cache has the same number of buckets, since * our allocation request might have triggered global cache flushing */ ftc_cache_add( cache, hash, node ); } *anode = node; return error; } #ifndef FTC_INLINE FT_LOCAL_DEF( FT_Error ) FTC_Cache_Lookup( FTC_Cache cache, FT_Offset hash, FT_Pointer query, FTC_Node *anode ) { FTC_Node* bucket; FTC_Node* pnode; FTC_Node node; FT_Error error = FT_Err_Ok; FT_Bool list_changed = FALSE; FTC_Node_CompareFunc compare = cache->clazz.node_compare; if ( !cache || !anode ) return FT_THROW( Invalid_Argument ); /* Go to the `top' node of the list sharing same masked hash */ bucket = pnode = FTC_NODE_TOP_FOR_HASH( cache, hash ); /* Lookup a node with exactly same hash and queried properties. */ /* NOTE: _nodcomp() may change the linked list to reduce memory. */ for (;;) { node = *pnode; if ( !node ) goto NewNode; if ( node->hash == hash && compare( node, query, cache, &list_changed ) ) break; pnode = &node->link; } if ( list_changed ) { /* Update bucket by modified linked list */ bucket = pnode = FTC_NODE_TOP_FOR_HASH( cache, hash ); /* Update pnode by modified linked list */ while ( *pnode != node ) { if ( !*pnode ) { FT_ERROR(( "FTC_Cache_Lookup: oops!!! node missing\n" )); goto NewNode; } else pnode = &(*pnode)->link; } } /* Reorder the list to move the found node to the `top' */ if ( node != *bucket ) { *pnode = node->link; node->link = *bucket; *bucket = node; } /* move to head of MRU list */ { FTC_Manager manager = cache->manager; if ( node != manager->nodes_list ) ftc_node_mru_up( node, manager ); } *anode = node; return error; NewNode: return FTC_Cache_NewNode( cache, hash, query, anode ); } #endif /* !FTC_INLINE */ FT_LOCAL_DEF( void ) FTC_Cache_RemoveFaceID( FTC_Cache cache, FTC_FaceID face_id ) { FT_UFast i, count; FTC_Manager manager = cache->manager; FTC_Node frees = NULL; count = cache->p + cache->mask + 1; for ( i = 0; i < count; i++ ) { FTC_Node* pnode = cache->buckets + i; for (;;) { FTC_Node node = *pnode; FT_Bool list_changed = FALSE; if ( !node ) break; if ( cache->clazz.node_remove_faceid( node, face_id, cache, &list_changed ) ) { *pnode = node->link; node->link = frees; frees = node; } else pnode = &node->link; } } /* remove all nodes in the free list */ while ( frees ) { FTC_Node node; node = frees; frees = node->link; manager->cur_weight -= cache->clazz.node_weight( node, cache ); ftc_node_mru_unlink( node, manager ); cache->clazz.node_free( node, cache ); cache->slack++; } ftc_cache_resize( cache ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftccache.c
C++
gpl-3.0
14,320
/**************************************************************************** * * ftccache.h * * FreeType internal cache interface (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 FTCCACHE_H_ #define FTCCACHE_H_ #include <freetype/internal/compiler-macros.h> #include "ftcmru.h" FT_BEGIN_HEADER #define FTC_FACE_ID_HASH( i ) \ ( ( (FT_Offset)(i) >> 3 ) ^ ( (FT_Offset)(i) << 7 ) ) /* handle to cache object */ typedef struct FTC_CacheRec_* FTC_Cache; /* handle to cache class */ typedef const struct FTC_CacheClassRec_* FTC_CacheClass; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE NODE DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * Each cache controls one or more cache nodes. Each node is part of * the global_lru list of the manager. Its `data' field however is used * as a reference count for now. * * A node can be anything, depending on the type of information held by * the cache. It can be an individual glyph image, a set of bitmaps * glyphs for a given size, some metrics, etc. * */ /* structure size should be 20 bytes on 32-bits machines */ typedef struct FTC_NodeRec_ { FTC_MruNodeRec mru; /* circular mru list pointer */ FTC_Node link; /* used for hashing */ FT_Offset hash; /* used for hashing too */ FT_UShort cache_index; /* index of cache the node belongs to */ FT_Short ref_count; /* reference count for this node */ } FTC_NodeRec; #define FTC_NODE( x ) ( (FTC_Node)(x) ) #define FTC_NODE_P( x ) ( (FTC_Node*)(x) ) #define FTC_NODE_NEXT( x ) FTC_NODE( (x)->mru.next ) #define FTC_NODE_PREV( x ) FTC_NODE( (x)->mru.prev ) #ifdef FTC_INLINE #define FTC_NODE_TOP_FOR_HASH( cache, hash ) \ ( ( cache )->buckets + \ ( ( ( ( hash ) & ( cache )->mask ) < ( cache )->p ) \ ? ( ( hash ) & ( ( cache )->mask * 2 + 1 ) ) \ : ( ( hash ) & ( cache )->mask ) ) ) #else FT_LOCAL( FTC_Node* ) ftc_get_top_node_for_hash( FTC_Cache cache, FT_Offset hash ); #define FTC_NODE_TOP_FOR_HASH( cache, hash ) \ ftc_get_top_node_for_hash( ( cache ), ( hash ) ) #endif /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* initialize a new cache node */ typedef FT_Error (*FTC_Node_NewFunc)( FTC_Node *pnode, FT_Pointer query, FTC_Cache cache ); typedef FT_Offset (*FTC_Node_WeightFunc)( FTC_Node node, FTC_Cache cache ); /* compare a node to a given key pair */ typedef FT_Bool (*FTC_Node_CompareFunc)( FTC_Node node, FT_Pointer key, FTC_Cache cache, FT_Bool* list_changed ); typedef void (*FTC_Node_FreeFunc)( FTC_Node node, FTC_Cache cache ); typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache ); typedef void (*FTC_Cache_DoneFunc)( FTC_Cache cache ); typedef struct FTC_CacheClassRec_ { FTC_Node_NewFunc node_new; FTC_Node_WeightFunc node_weight; FTC_Node_CompareFunc node_compare; FTC_Node_CompareFunc node_remove_faceid; FTC_Node_FreeFunc node_free; FT_Offset cache_size; FTC_Cache_InitFunc cache_init; FTC_Cache_DoneFunc cache_done; } FTC_CacheClassRec; /* each cache really implements a dynamic hash table to manage its nodes */ typedef struct FTC_CacheRec_ { FT_UFast p; FT_UFast mask; FT_Long slack; FTC_Node* buckets; FTC_CacheClassRec clazz; /* local copy, for speed */ FTC_Manager manager; FT_Memory memory; FT_UInt index; /* in manager's table */ FTC_CacheClass org_class; /* original class pointer */ } FTC_CacheRec; #define FTC_CACHE( x ) ( (FTC_Cache)(x) ) #define FTC_CACHE_P( x ) ( (FTC_Cache*)(x) ) /* default cache initialize */ FT_LOCAL( FT_Error ) FTC_Cache_Init( FTC_Cache cache ); /* default cache finalizer */ FT_LOCAL( void ) FTC_Cache_Done( FTC_Cache cache ); /* Call this function to look up the cache. If no corresponding * node is found, a new one is automatically created. This function * is capable of flushing the cache adequately to make room for the * new cache object. */ #ifndef FTC_INLINE FT_LOCAL( FT_Error ) FTC_Cache_Lookup( FTC_Cache cache, FT_Offset hash, FT_Pointer query, FTC_Node *anode ); #endif FT_LOCAL( FT_Error ) FTC_Cache_NewNode( FTC_Cache cache, FT_Offset hash, FT_Pointer query, FTC_Node *anode ); /* Remove all nodes that relate to a given face_id. This is useful * when un-installing fonts. Note that if a cache node relates to * the face_id but is locked (i.e., has `ref_count > 0'), the node * will _not_ be destroyed, but its internal face_id reference will * be modified. * * The final result will be that the node will never come back * in further lookup requests, and will be flushed on demand from * the cache normally when its reference count reaches 0. */ FT_LOCAL( void ) FTC_Cache_RemoveFaceID( FTC_Cache cache, FTC_FaceID face_id ); #ifdef FTC_INLINE #define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \ FT_BEGIN_STMNT \ FTC_Node *_bucket, *_pnode, _node; \ FTC_Cache _cache = FTC_CACHE(cache); \ FT_Offset _hash = (FT_Offset)(hash); \ FTC_Node_CompareFunc _nodcomp = (FTC_Node_CompareFunc)(nodecmp); \ FT_Bool _list_changed = FALSE; \ \ \ error = FT_Err_Ok; \ node = NULL; \ \ /* Go to the `top' node of the list sharing same masked hash */ \ _bucket = _pnode = FTC_NODE_TOP_FOR_HASH( _cache, _hash ); \ \ /* Look up a node with identical hash and queried properties. */ \ /* NOTE: _nodcomp() may change the linked list to reduce memory. */ \ for (;;) \ { \ _node = *_pnode; \ if ( !_node ) \ goto NewNode_; \ \ if ( _node->hash == _hash && \ _nodcomp( _node, query, _cache, &_list_changed ) ) \ break; \ \ _pnode = &_node->link; \ } \ \ if ( _list_changed ) \ { \ /* Update _bucket by possibly modified linked list */ \ _bucket = _pnode = FTC_NODE_TOP_FOR_HASH( _cache, _hash ); \ \ /* Update _pnode by possibly modified linked list */ \ while ( *_pnode != _node ) \ { \ if ( !*_pnode ) \ { \ FT_ERROR(( "FTC_CACHE_LOOKUP_CMP: oops!!! node missing\n" )); \ goto NewNode_; \ } \ else \ _pnode = &(*_pnode)->link; \ } \ } \ \ /* Reorder the list to move the found node to the `top' */ \ if ( _node != *_bucket ) \ { \ *_pnode = _node->link; \ _node->link = *_bucket; \ *_bucket = _node; \ } \ \ /* Update MRU list */ \ { \ FTC_Manager _manager = _cache->manager; \ void* _nl = &_manager->nodes_list; \ \ \ if ( _node != _manager->nodes_list ) \ FTC_MruNode_Up( (FTC_MruNode*)_nl, \ (FTC_MruNode)_node ); \ } \ goto Ok_; \ \ NewNode_: \ error = FTC_Cache_NewNode( _cache, _hash, query, &_node ); \ \ Ok_: \ node = _node; \ FT_END_STMNT #else /* !FTC_INLINE */ #define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \ FT_BEGIN_STMNT \ error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, \ (FTC_Node*)&(node) ); \ FT_END_STMNT #endif /* !FTC_INLINE */ /* * This macro, together with FTC_CACHE_TRYLOOP_END, defines a retry * loop to flush the cache repeatedly in case of memory overflows. * * It is used when creating a new cache node, or within a lookup * that needs to allocate data (e.g. the sbit cache lookup). * * Example: * * { * FTC_CACHE_TRYLOOP( cache ) * error = load_data( ... ); * FTC_CACHE_TRYLOOP_END() * } * */ #define FTC_CACHE_TRYLOOP( cache ) \ { \ FTC_Manager _try_manager = FTC_CACHE( cache )->manager; \ FT_UInt _try_count = 4; \ \ \ for (;;) \ { \ FT_UInt _try_done; #define FTC_CACHE_TRYLOOP_END( list_changed ) \ if ( !error || FT_ERR_NEQ( error, Out_Of_Memory ) ) \ break; \ \ _try_done = FTC_Manager_FlushN( _try_manager, _try_count ); \ if ( _try_done > 0 && list_changed != NULL ) \ *(FT_Bool*)( list_changed ) = TRUE; \ \ if ( _try_done == 0 ) \ break; \ \ if ( _try_done == _try_count ) \ { \ _try_count *= 2; \ if ( _try_count < _try_done || \ _try_count > _try_manager->num_nodes ) \ _try_count = _try_manager->num_nodes; \ } \ } \ } /* */ FT_END_HEADER #endif /* FTCCACHE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftccache.h
C++
gpl-3.0
15,225
/**************************************************************************** * * ftccback.h * * Callback functions of the caching sub-system (specification only). * * Copyright (C) 2004-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 FTCCBACK_H_ #define FTCCBACK_H_ #include <freetype/ftcache.h> #include "ftcmru.h" #include "ftcimage.h" #include "ftcmanag.h" #include "ftcglyph.h" #include "ftcsbits.h" FT_BEGIN_HEADER FT_LOCAL( void ) ftc_inode_free( FTC_Node inode, FTC_Cache cache ); FT_LOCAL( FT_Error ) ftc_inode_new( FTC_Node *pinode, FT_Pointer gquery, FTC_Cache cache ); FT_LOCAL( FT_Offset ) ftc_inode_weight( FTC_Node inode, FTC_Cache cache ); FT_LOCAL( void ) ftc_snode_free( FTC_Node snode, FTC_Cache cache ); FT_LOCAL( FT_Error ) ftc_snode_new( FTC_Node *psnode, FT_Pointer gquery, FTC_Cache cache ); FT_LOCAL( FT_Offset ) ftc_snode_weight( FTC_Node snode, FTC_Cache cache ); FT_LOCAL( FT_Bool ) ftc_snode_compare( FTC_Node snode, FT_Pointer gquery, FTC_Cache cache, FT_Bool* list_changed ); FT_LOCAL( FT_Bool ) ftc_gnode_compare( FTC_Node gnode, FT_Pointer gquery, FTC_Cache cache, FT_Bool* list_changed ); FT_LOCAL( FT_Error ) ftc_gcache_init( FTC_Cache cache ); FT_LOCAL( void ) ftc_gcache_done( FTC_Cache cache ); FT_LOCAL( FT_Error ) ftc_cache_init( FTC_Cache cache ); FT_LOCAL( void ) ftc_cache_done( FTC_Cache cache ); FT_LOCAL( void ) ftc_node_destroy( FTC_Node node, FTC_Manager manager ); FT_END_HEADER #endif /* FTCCBACK_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftccback.h
C++
gpl-3.0
2,220
/**************************************************************************** * * ftccmap.c * * FreeType CharMap cache (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/freetype.h> #include <freetype/ftcache.h> #include "ftcmanag.h" #include <freetype/internal/ftmemory.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include "ftccback.h" #include "ftcerror.h" #undef FT_COMPONENT #define FT_COMPONENT cache /************************************************************************** * * Each FTC_CMapNode contains a simple array to map a range of character * codes to equivalent glyph indices. * * For now, the implementation is very basic: Each node maps a range of * 128 consecutive character codes to their corresponding glyph indices. * * We could do more complex things, but I don't think it is really very * useful. * */ /* number of glyph indices / character code per node */ #define FTC_CMAP_INDICES_MAX 128 /* compute a query/node hash */ #define FTC_CMAP_HASH( faceid, index, charcode ) \ ( FTC_FACE_ID_HASH( faceid ) + 211 * (index) + \ ( (charcode) / FTC_CMAP_INDICES_MAX ) ) /* the charmap query */ typedef struct FTC_CMapQueryRec_ { FTC_FaceID face_id; FT_UInt cmap_index; FT_UInt32 char_code; } FTC_CMapQueryRec, *FTC_CMapQuery; #define FTC_CMAP_QUERY( x ) ((FTC_CMapQuery)(x)) /* the cmap cache node */ typedef struct FTC_CMapNodeRec_ { FTC_NodeRec node; FTC_FaceID face_id; FT_UInt cmap_index; FT_UInt32 first; /* first character in node */ FT_UInt16 indices[FTC_CMAP_INDICES_MAX]; /* array of glyph indices */ } FTC_CMapNodeRec, *FTC_CMapNode; #define FTC_CMAP_NODE( x ) ( (FTC_CMapNode)( x ) ) /* if (indices[n] == FTC_CMAP_UNKNOWN), we assume that the corresponding */ /* glyph indices haven't been queried through FT_Get_Glyph_Index() yet */ #define FTC_CMAP_UNKNOWN (FT_UInt16)~0 /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CHARMAP NODES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_CALLBACK_DEF( void ) ftc_cmap_node_free( FTC_Node ftcnode, FTC_Cache cache ) { FTC_CMapNode node = (FTC_CMapNode)ftcnode; FT_Memory memory = cache->memory; FT_FREE( node ); } /* initialize a new cmap node */ FT_CALLBACK_DEF( FT_Error ) ftc_cmap_node_new( FTC_Node *ftcanode, FT_Pointer ftcquery, FTC_Cache cache ) { FTC_CMapNode *anode = (FTC_CMapNode*)ftcanode; FTC_CMapQuery query = (FTC_CMapQuery)ftcquery; FT_Error error; FT_Memory memory = cache->memory; FTC_CMapNode node = NULL; FT_UInt nn; if ( !FT_QNEW( node ) ) { node->face_id = query->face_id; node->cmap_index = query->cmap_index; node->first = (query->char_code / FTC_CMAP_INDICES_MAX) * FTC_CMAP_INDICES_MAX; for ( nn = 0; nn < FTC_CMAP_INDICES_MAX; nn++ ) node->indices[nn] = FTC_CMAP_UNKNOWN; } *anode = node; return error; } /* compute the weight of a given cmap node */ FT_CALLBACK_DEF( FT_Offset ) ftc_cmap_node_weight( FTC_Node cnode, FTC_Cache cache ) { FT_UNUSED( cnode ); FT_UNUSED( cache ); return sizeof ( *cnode ); } /* compare a cmap node to a given query */ FT_CALLBACK_DEF( FT_Bool ) ftc_cmap_node_compare( FTC_Node ftcnode, FT_Pointer ftcquery, FTC_Cache cache, FT_Bool* list_changed ) { FTC_CMapNode node = (FTC_CMapNode)ftcnode; FTC_CMapQuery query = (FTC_CMapQuery)ftcquery; FT_UNUSED( cache ); if ( list_changed ) *list_changed = FALSE; if ( node->face_id == query->face_id && node->cmap_index == query->cmap_index ) { FT_UInt32 offset = (FT_UInt32)( query->char_code - node->first ); return FT_BOOL( offset < FTC_CMAP_INDICES_MAX ); } return 0; } FT_CALLBACK_DEF( FT_Bool ) ftc_cmap_node_remove_faceid( FTC_Node ftcnode, FT_Pointer ftcface_id, FTC_Cache cache, FT_Bool* list_changed ) { FTC_CMapNode node = (FTC_CMapNode)ftcnode; FTC_FaceID face_id = (FTC_FaceID)ftcface_id; FT_UNUSED( cache ); if ( list_changed ) *list_changed = FALSE; return FT_BOOL( node->face_id == face_id ); } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** GLYPH IMAGE CACHE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static const FTC_CacheClassRec ftc_cmap_cache_class = { ftc_cmap_node_new, /* FTC_Node_NewFunc node_new */ ftc_cmap_node_weight, /* FTC_Node_WeightFunc node_weight */ ftc_cmap_node_compare, /* FTC_Node_CompareFunc node_compare */ ftc_cmap_node_remove_faceid, /* FTC_Node_CompareFunc node_remove_faceid */ ftc_cmap_node_free, /* FTC_Node_FreeFunc node_free */ sizeof ( FTC_CacheRec ), ftc_cache_init, /* FTC_Cache_InitFunc cache_init */ ftc_cache_done, /* FTC_Cache_DoneFunc cache_done */ }; /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_CMapCache_New( FTC_Manager manager, FTC_CMapCache *acache ) { return FTC_Manager_RegisterCache( manager, &ftc_cmap_cache_class, FTC_CACHE_P( acache ) ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_UInt ) FTC_CMapCache_Lookup( FTC_CMapCache cmap_cache, FTC_FaceID face_id, FT_Int cmap_index, FT_UInt32 char_code ) { FTC_Cache cache = FTC_CACHE( cmap_cache ); FTC_CMapQueryRec query; FTC_Node node; FT_Error error; FT_UInt gindex = 0; FT_Offset hash; FT_Int no_cmap_change = 0; if ( cmap_index < 0 ) { /* Treat a negative cmap index as a special value, meaning that you */ /* don't want to change the FT_Face's character map through this */ /* call. This can be useful if the face requester callback already */ /* sets the face's charmap to the appropriate value. */ no_cmap_change = 1; cmap_index = 0; } if ( !cache ) { FT_TRACE0(( "FTC_CMapCache_Lookup: bad arguments, returning 0\n" )); return 0; } query.face_id = face_id; query.cmap_index = (FT_UInt)cmap_index; query.char_code = char_code; hash = FTC_CMAP_HASH( face_id, (FT_UInt)cmap_index, char_code ); #if 1 FTC_CACHE_LOOKUP_CMP( cache, ftc_cmap_node_compare, hash, &query, node, error ); #else error = FTC_Cache_Lookup( cache, hash, &query, &node ); #endif if ( error ) goto Exit; FT_ASSERT( char_code - FTC_CMAP_NODE( node )->first < FTC_CMAP_INDICES_MAX ); /* something rotten can happen with rogue clients */ if ( char_code - FTC_CMAP_NODE( node )->first >= FTC_CMAP_INDICES_MAX ) return 0; /* XXX: should return appropriate error */ gindex = FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first]; if ( gindex == FTC_CMAP_UNKNOWN ) { FT_Face face; gindex = 0; error = FTC_Manager_LookupFace( cache->manager, FTC_CMAP_NODE( node )->face_id, &face ); if ( error ) goto Exit; if ( (FT_UInt)cmap_index < (FT_UInt)face->num_charmaps ) { FT_CharMap old, cmap = NULL; old = face->charmap; cmap = face->charmaps[cmap_index]; if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, cmap ); gindex = FT_Get_Char_Index( face, char_code ); if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, old ); } FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first] = (FT_UShort)gindex; } Exit: return gindex; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftccmap.c
C++
gpl-3.0
9,791
/**************************************************************************** * * ftcerror.h * * Caching sub-system 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 caching sub-system error enumeration * constants. * */ #ifndef FTCERROR_H_ #define FTCERROR_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX FTC_Err_ #define FT_ERR_BASE FT_Mod_Err_Cache #include <freetype/fterrors.h> #endif /* FTCERROR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcerror.h
C++
gpl-3.0
999
/**************************************************************************** * * ftcglyph.c * * FreeType Glyph Image (FT_Glyph) cache (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/ftobjs.h> #include <freetype/ftcache.h> #include "ftcglyph.h" #include <freetype/fterrors.h> #include "ftccback.h" #include "ftcerror.h" /* create a new chunk node, setting its cache index and ref count */ FT_LOCAL_DEF( void ) FTC_GNode_Init( FTC_GNode gnode, FT_UInt gindex, FTC_Family family ) { gnode->family = family; gnode->gindex = gindex; family->num_nodes++; } FT_LOCAL_DEF( void ) FTC_GNode_UnselectFamily( FTC_GNode gnode, FTC_Cache cache ) { FTC_Family family = gnode->family; gnode->family = NULL; if ( family && --family->num_nodes == 0 ) FTC_FAMILY_FREE( family, cache ); } FT_LOCAL_DEF( void ) FTC_GNode_Done( FTC_GNode gnode, FTC_Cache cache ) { /* finalize the node */ gnode->gindex = 0; FTC_GNode_UnselectFamily( gnode, cache ); } FT_LOCAL_DEF( FT_Bool ) ftc_gnode_compare( FTC_Node ftcgnode, FT_Pointer ftcgquery, FTC_Cache cache, FT_Bool* list_changed ) { FTC_GNode gnode = (FTC_GNode)ftcgnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; FT_UNUSED( cache ); if ( list_changed ) *list_changed = FALSE; return FT_BOOL( gnode->family == gquery->family && gnode->gindex == gquery->gindex ); } #ifdef FTC_INLINE FT_LOCAL_DEF( FT_Bool ) FTC_GNode_Compare( FTC_GNode gnode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed ) { return ftc_gnode_compare( FTC_NODE( gnode ), gquery, cache, list_changed ); } #endif /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CHUNK SETS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) FTC_Family_Init( FTC_Family family, FTC_Cache cache ) { FTC_GCacheClass clazz = FTC_CACHE_GCACHE_CLASS( cache ); family->clazz = clazz->family_class; family->num_nodes = 0; family->cache = cache; } FT_LOCAL_DEF( FT_Error ) ftc_gcache_init( FTC_Cache ftccache ) { FTC_GCache cache = (FTC_GCache)ftccache; FT_Error error; error = FTC_Cache_Init( FTC_CACHE( cache ) ); if ( !error ) { FTC_GCacheClass clazz = (FTC_GCacheClass)FTC_CACHE( cache )->org_class; FTC_MruList_Init( &cache->families, clazz->family_class, 0, /* no maximum here! */ cache, FTC_CACHE( cache )->memory ); } return error; } #if 0 FT_LOCAL_DEF( FT_Error ) FTC_GCache_Init( FTC_GCache cache ) { return ftc_gcache_init( FTC_CACHE( cache ) ); } #endif /* 0 */ FT_LOCAL_DEF( void ) ftc_gcache_done( FTC_Cache ftccache ) { FTC_GCache cache = (FTC_GCache)ftccache; FTC_Cache_Done( (FTC_Cache)cache ); FTC_MruList_Done( &cache->families ); } #if 0 FT_LOCAL_DEF( void ) FTC_GCache_Done( FTC_GCache cache ) { ftc_gcache_done( FTC_CACHE( cache ) ); } #endif /* 0 */ FT_LOCAL_DEF( FT_Error ) FTC_GCache_New( FTC_Manager manager, FTC_GCacheClass clazz, FTC_GCache *acache ) { return FTC_Manager_RegisterCache( manager, (FTC_CacheClass)clazz, (FTC_Cache*)acache ); } #ifndef FTC_INLINE FT_LOCAL_DEF( FT_Error ) FTC_GCache_Lookup( FTC_GCache cache, FT_Offset hash, FT_UInt gindex, FTC_GQuery query, FTC_Node *anode ) { FT_Error error; query->gindex = gindex; FTC_MRULIST_LOOKUP( &cache->families, query, query->family, error ); if ( !error ) { FTC_Family family = query->family; /* prevent the family from being destroyed too early when an */ /* out-of-memory condition occurs during glyph node initialization. */ family->num_nodes++; error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, anode ); if ( --family->num_nodes == 0 ) FTC_FAMILY_FREE( family, cache ); } return error; } #endif /* !FTC_INLINE */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcglyph.c
C++
gpl-3.0
5,357
/**************************************************************************** * * ftcglyph.h * * FreeType abstract glyph cache (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. * */ /* * * FTC_GCache is an _abstract_ cache object optimized to store glyph * data. It works as follows: * * - It manages FTC_GNode objects. Each one of them can hold one or more * glyph `items'. Item types are not specified in the FTC_GCache but * in classes that extend it. * * - Glyph attributes, like face ID, character size, render mode, etc., * can be grouped into abstract `glyph families'. This avoids storing * the attributes within the FTC_GCache, since it is likely that many * FTC_GNodes will belong to the same family in typical uses. * * - Each FTC_GNode is thus an FTC_Node with two additional fields: * * * gindex: A glyph index, or the first index in a glyph range. * * family: A pointer to a glyph `family'. * * - Family types are not fully specific in the FTC_Family type, but * by classes that extend it. * * Note that both FTC_ImageCache and FTC_SBitCache extend FTC_GCache. * They share an FTC_Family sub-class called FTC_BasicFamily which is * used to store the following data: face ID, pixel/point sizes, load * flags. For more details see the file `src/cache/ftcbasic.c'. * * Client applications can extend FTC_GNode with their own FTC_GNode * and FTC_Family sub-classes to implement more complex caches (e.g., * handling automatic synthesis, like obliquing & emboldening, colored * glyphs, etc.). * * See also the FTC_ICache & FTC_SCache classes in `ftcimage.h' and * `ftcsbits.h', which both extend FTC_GCache with additional * optimizations. * * A typical FTC_GCache implementation must provide at least the * following: * * - FTC_GNode sub-class, e.g. MyNode, with relevant methods: * my_node_new (must call FTC_GNode_Init) * my_node_free (must call FTC_GNode_Done) * my_node_compare (must call FTC_GNode_Compare) * my_node_remove_faceid (must call ftc_gnode_unselect in case * of match) * * - FTC_Family sub-class, e.g. MyFamily, with relevant methods: * my_family_compare * my_family_init * my_family_reset (optional) * my_family_done * * - FTC_GQuery sub-class, e.g. MyQuery, to hold cache-specific query * data. * * - Constant structures for a FTC_GNodeClass. * * - MyCacheNew() can be implemented easily as a call to the convenience * function FTC_GCache_New. * * - MyCacheLookup with a call to FTC_GCache_Lookup. This function will * automatically: * * - Search for the corresponding family in the cache, or create * a new one if necessary. Put it in FTC_GQUERY(myquery).family * * - Call FTC_Cache_Lookup. * * If it returns NULL, you should create a new node, then call * ftc_cache_add as usual. */ /************************************************************************** * * Important: The functions defined in this file are only used to * implement an abstract glyph cache class. You need to * provide additional logic to implement a complete cache. * */ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********* *********/ /********* WARNING, THIS IS BETA CODE. *********/ /********* *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ #ifndef FTCGLYPH_H_ #define FTCGLYPH_H_ #include "ftcmanag.h" FT_BEGIN_HEADER /* * We can group glyphs into `families'. Each family correspond to a * given face ID, character size, transform, etc. * * Families are implemented as MRU list nodes. They are * reference-counted. */ typedef struct FTC_FamilyRec_ { FTC_MruNodeRec mrunode; FT_UInt num_nodes; /* current number of nodes in this family */ FTC_Cache cache; FTC_MruListClass clazz; } FTC_FamilyRec, *FTC_Family; #define FTC_FAMILY(x) ( (FTC_Family)(x) ) #define FTC_FAMILY_P(x) ( (FTC_Family*)(x) ) typedef struct FTC_GNodeRec_ { FTC_NodeRec node; FTC_Family family; FT_UInt gindex; } FTC_GNodeRec, *FTC_GNode; #define FTC_GNODE( x ) ( (FTC_GNode)(x) ) #define FTC_GNODE_P( x ) ( (FTC_GNode*)(x) ) typedef struct FTC_GQueryRec_ { FT_UInt gindex; FTC_Family family; } FTC_GQueryRec, *FTC_GQuery; #define FTC_GQUERY( x ) ( (FTC_GQuery)(x) ) /************************************************************************** * * These functions are exported so that they can be called from * user-provided cache classes; otherwise, they are really part of the * cache sub-system internals. */ /* must be called by derived FTC_Node_InitFunc routines */ FT_LOCAL( void ) FTC_GNode_Init( FTC_GNode node, FT_UInt gindex, /* glyph index for node */ FTC_Family family ); #ifdef FTC_INLINE /* returns TRUE iff the query's glyph index correspond to the node; */ /* this assumes that the `family' and `hash' fields of the query are */ /* already correctly set */ FT_LOCAL( FT_Bool ) FTC_GNode_Compare( FTC_GNode gnode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed ); #endif /* call this function to clear a node's family -- this is necessary */ /* to implement the `node_remove_faceid' cache method correctly */ FT_LOCAL( void ) FTC_GNode_UnselectFamily( FTC_GNode gnode, FTC_Cache cache ); /* must be called by derived FTC_Node_DoneFunc routines */ FT_LOCAL( void ) FTC_GNode_Done( FTC_GNode node, FTC_Cache cache ); FT_LOCAL( void ) FTC_Family_Init( FTC_Family family, FTC_Cache cache ); typedef struct FTC_GCacheRec_ { FTC_CacheRec cache; FTC_MruListRec families; } FTC_GCacheRec, *FTC_GCache; #define FTC_GCACHE( x ) ((FTC_GCache)(x)) #if 0 /* can be used as @FTC_Cache_InitFunc */ FT_LOCAL( FT_Error ) FTC_GCache_Init( FTC_GCache cache ); #endif #if 0 /* can be used as @FTC_Cache_DoneFunc */ FT_LOCAL( void ) FTC_GCache_Done( FTC_GCache cache ); #endif /* the glyph cache class adds fields for the family implementation */ typedef struct FTC_GCacheClassRec_ { FTC_CacheClassRec clazz; FTC_MruListClass family_class; } FTC_GCacheClassRec; typedef const FTC_GCacheClassRec* FTC_GCacheClass; #define FTC_GCACHE_CLASS( x ) ((FTC_GCacheClass)(x)) #define FTC_CACHE_GCACHE_CLASS( x ) \ FTC_GCACHE_CLASS( FTC_CACHE(x)->org_class ) #define FTC_CACHE_FAMILY_CLASS( x ) \ ( (FTC_MruListClass)FTC_CACHE_GCACHE_CLASS( x )->family_class ) /* convenience function; use it instead of FTC_Manager_Register_Cache */ FT_LOCAL( FT_Error ) FTC_GCache_New( FTC_Manager manager, FTC_GCacheClass clazz, FTC_GCache *acache ); #ifndef FTC_INLINE FT_LOCAL( FT_Error ) FTC_GCache_Lookup( FTC_GCache cache, FT_Offset hash, FT_UInt gindex, FTC_GQuery query, FTC_Node *anode ); #endif /* */ #define FTC_FAMILY_FREE( family, cache ) \ FTC_MruList_Remove( &FTC_GCACHE((cache))->families, \ (FTC_MruNode)(family) ) #ifdef FTC_INLINE #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash, \ gindex, query, node, error ) \ FT_BEGIN_STMNT \ FTC_GCache _gcache = FTC_GCACHE( cache ); \ FTC_GQuery _gquery = (FTC_GQuery)( query ); \ FTC_MruNode_CompareFunc _fcompare = (FTC_MruNode_CompareFunc)(famcmp); \ FTC_MruNode _mrunode; \ \ \ _gquery->gindex = (gindex); \ \ FTC_MRULIST_LOOKUP_CMP( &_gcache->families, _gquery, _fcompare, \ _mrunode, error ); \ _gquery->family = FTC_FAMILY( _mrunode ); \ if ( !error ) \ { \ FTC_Family _gqfamily = _gquery->family; \ \ \ _gqfamily->num_nodes++; \ \ FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ); \ \ if ( --_gqfamily->num_nodes == 0 ) \ FTC_FAMILY_FREE( _gqfamily, _gcache ); \ } \ FT_END_STMNT /* */ #else /* !FTC_INLINE */ #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash, \ gindex, query, node, error ) \ FT_BEGIN_STMNT \ \ error = FTC_GCache_Lookup( FTC_GCACHE( cache ), hash, gindex, \ FTC_GQUERY( query ), &node ); \ \ FT_END_STMNT #endif /* !FTC_INLINE */ FT_END_HEADER #endif /* FTCGLYPH_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcglyph.h
C++
gpl-3.0
11,552
/**************************************************************************** * * ftcimage.c * * FreeType Image cache (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/ftcache.h> #include "ftcimage.h" #include <freetype/internal/ftmemory.h> #include <freetype/internal/ftobjs.h> #include "ftccback.h" #include "ftcerror.h" /* finalize a given glyph image node */ FT_LOCAL_DEF( void ) ftc_inode_free( FTC_Node ftcinode, FTC_Cache cache ) { FTC_INode inode = (FTC_INode)ftcinode; FT_Memory memory = cache->memory; if ( inode->glyph ) { FT_Done_Glyph( inode->glyph ); inode->glyph = NULL; } FTC_GNode_Done( FTC_GNODE( inode ), cache ); FT_FREE( inode ); } FT_LOCAL_DEF( void ) FTC_INode_Free( FTC_INode inode, FTC_Cache cache ) { ftc_inode_free( FTC_NODE( inode ), cache ); } /* initialize a new glyph image node */ FT_LOCAL_DEF( FT_Error ) FTC_INode_New( FTC_INode *pinode, FTC_GQuery gquery, FTC_Cache cache ) { FT_Memory memory = cache->memory; FT_Error error; FTC_INode inode = NULL; if ( !FT_QNEW( inode ) ) { FTC_GNode gnode = FTC_GNODE( inode ); FTC_Family family = gquery->family; FT_UInt gindex = gquery->gindex; FTC_IFamilyClass clazz = FTC_CACHE_IFAMILY_CLASS( cache ); /* initialize its inner fields */ FTC_GNode_Init( gnode, gindex, family ); inode->glyph = NULL; /* we will now load the glyph image */ error = clazz->family_load_glyph( family, gindex, cache, &inode->glyph ); if ( error ) { FTC_INode_Free( inode, cache ); inode = NULL; } } *pinode = inode; return error; } FT_LOCAL_DEF( FT_Error ) ftc_inode_new( FTC_Node *ftcpinode, FT_Pointer ftcgquery, FTC_Cache cache ) { FTC_INode *pinode = (FTC_INode*)ftcpinode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; return FTC_INode_New( pinode, gquery, cache ); } FT_LOCAL_DEF( FT_Offset ) ftc_inode_weight( FTC_Node ftcinode, FTC_Cache ftccache ) { FTC_INode inode = (FTC_INode)ftcinode; FT_Offset size = 0; FT_Glyph glyph = inode->glyph; FT_UNUSED( ftccache ); switch ( glyph->format ) { case FT_GLYPH_FORMAT_BITMAP: { FT_BitmapGlyph bitg; bitg = (FT_BitmapGlyph)glyph; size = bitg->bitmap.rows * (FT_Offset)FT_ABS( bitg->bitmap.pitch ) + sizeof ( *bitg ); } break; case FT_GLYPH_FORMAT_OUTLINE: { FT_OutlineGlyph outg; outg = (FT_OutlineGlyph)glyph; size = (FT_Offset)outg->outline.n_points * ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) + (FT_Offset)outg->outline.n_contours * sizeof ( FT_Short ) + sizeof ( *outg ); } break; default: ; } size += sizeof ( *inode ); return size; } #if 0 FT_LOCAL_DEF( FT_Offset ) FTC_INode_Weight( FTC_INode inode ) { return ftc_inode_weight( FTC_NODE( inode ), NULL ); } #endif /* 0 */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcimage.c
C++
gpl-3.0
3,677
/**************************************************************************** * * ftcimage.h * * FreeType Generic Image cache (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. * */ /* * FTC_ICache is an _abstract_ cache used to store a single FT_Glyph * image per cache node. * * FTC_ICache extends FTC_GCache. For an implementation example, * see FTC_ImageCache in `src/cache/ftbasic.c'. */ /************************************************************************** * * Each image cache really manages FT_Glyph objects. * */ #ifndef FTCIMAGE_H_ #define FTCIMAGE_H_ #include <freetype/ftcache.h> #include "ftcglyph.h" FT_BEGIN_HEADER /* the FT_Glyph image node type - we store only 1 glyph per node */ typedef struct FTC_INodeRec_ { FTC_GNodeRec gnode; FT_Glyph glyph; } FTC_INodeRec, *FTC_INode; #define FTC_INODE( x ) ( (FTC_INode)( x ) ) #define FTC_INODE_GINDEX( x ) FTC_GNODE(x)->gindex #define FTC_INODE_FAMILY( x ) FTC_GNODE(x)->family typedef FT_Error (*FTC_IFamily_LoadGlyphFunc)( FTC_Family family, FT_UInt gindex, FTC_Cache cache, FT_Glyph *aglyph ); typedef struct FTC_IFamilyClassRec_ { FTC_MruListClassRec clazz; FTC_IFamily_LoadGlyphFunc family_load_glyph; } FTC_IFamilyClassRec; typedef const FTC_IFamilyClassRec* FTC_IFamilyClass; #define FTC_IFAMILY_CLASS( x ) ((FTC_IFamilyClass)(x)) #define FTC_CACHE_IFAMILY_CLASS( x ) \ FTC_IFAMILY_CLASS( FTC_CACHE_GCACHE_CLASS(x)->family_class ) /* can be used as a @FTC_Node_FreeFunc */ FT_LOCAL( void ) FTC_INode_Free( FTC_INode inode, FTC_Cache cache ); /* Can be used as @FTC_Node_NewFunc. `gquery.index' and `gquery.family' * must be set correctly. This function will call the `family_load_glyph' * method to load the FT_Glyph into the cache node. */ FT_LOCAL( FT_Error ) FTC_INode_New( FTC_INode *pinode, FTC_GQuery gquery, FTC_Cache cache ); #if 0 /* can be used as @FTC_Node_WeightFunc */ FT_LOCAL( FT_ULong ) FTC_INode_Weight( FTC_INode inode ); #endif /* */ FT_END_HEADER #endif /* FTCIMAGE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcimage.h
C++
gpl-3.0
2,669
/**************************************************************************** * * ftcmanag.c * * FreeType Cache Manager (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/ftcache.h> #include "ftcmanag.h" #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/ftsizes.h> #include "ftccback.h" #include "ftcerror.h" #undef FT_COMPONENT #define FT_COMPONENT cache static FT_Error ftc_scaler_lookup_size( FTC_Manager manager, FTC_Scaler scaler, FT_Size *asize ) { FT_Face face; FT_Size size = NULL; FT_Error error; error = FTC_Manager_LookupFace( manager, scaler->face_id, &face ); if ( error ) goto Exit; error = FT_New_Size( face, &size ); if ( error ) goto Exit; FT_Activate_Size( size ); if ( scaler->pixel ) error = FT_Set_Pixel_Sizes( face, scaler->width, scaler->height ); else error = FT_Set_Char_Size( face, (FT_F26Dot6)scaler->width, (FT_F26Dot6)scaler->height, scaler->x_res, scaler->y_res ); if ( error ) { FT_Done_Size( size ); size = NULL; } Exit: *asize = size; return error; } typedef struct FTC_SizeNodeRec_ { FTC_MruNodeRec node; FT_Size size; FTC_ScalerRec scaler; } FTC_SizeNodeRec, *FTC_SizeNode; #define FTC_SIZE_NODE( x ) ( (FTC_SizeNode)( x ) ) FT_CALLBACK_DEF( void ) ftc_size_node_done( FTC_MruNode ftcnode, FT_Pointer data ) { FTC_SizeNode node = (FTC_SizeNode)ftcnode; FT_Size size = node->size; FT_UNUSED( data ); if ( size ) FT_Done_Size( size ); } FT_CALLBACK_DEF( FT_Bool ) ftc_size_node_compare( FTC_MruNode ftcnode, FT_Pointer ftcscaler ) { FTC_SizeNode node = (FTC_SizeNode)ftcnode; FTC_Scaler scaler = (FTC_Scaler)ftcscaler; FTC_Scaler scaler0 = &node->scaler; if ( FTC_SCALER_COMPARE( scaler0, scaler ) ) { FT_Activate_Size( node->size ); return 1; } return 0; } FT_CALLBACK_DEF( FT_Error ) ftc_size_node_init( FTC_MruNode ftcnode, FT_Pointer ftcscaler, FT_Pointer ftcmanager ) { FTC_SizeNode node = (FTC_SizeNode)ftcnode; FTC_Scaler scaler = (FTC_Scaler)ftcscaler; FTC_Manager manager = (FTC_Manager)ftcmanager; node->scaler = scaler[0]; return ftc_scaler_lookup_size( manager, scaler, &node->size ); } FT_CALLBACK_DEF( FT_Error ) ftc_size_node_reset( FTC_MruNode ftcnode, FT_Pointer ftcscaler, FT_Pointer ftcmanager ) { FTC_SizeNode node = (FTC_SizeNode)ftcnode; FTC_Scaler scaler = (FTC_Scaler)ftcscaler; FTC_Manager manager = (FTC_Manager)ftcmanager; FT_Done_Size( node->size ); node->scaler = scaler[0]; return ftc_scaler_lookup_size( manager, scaler, &node->size ); } static const FTC_MruListClassRec ftc_size_list_class = { sizeof ( FTC_SizeNodeRec ), ftc_size_node_compare, /* FTC_MruNode_CompareFunc node_compare */ ftc_size_node_init, /* FTC_MruNode_InitFunc node_init */ ftc_size_node_reset, /* FTC_MruNode_ResetFunc node_reset */ ftc_size_node_done /* FTC_MruNode_DoneFunc node_done */ }; /* helper function used by ftc_face_node_done */ static FT_Bool ftc_size_node_compare_faceid( FTC_MruNode ftcnode, FT_Pointer ftcface_id ) { FTC_SizeNode node = (FTC_SizeNode)ftcnode; FTC_FaceID face_id = (FTC_FaceID)ftcface_id; return FT_BOOL( node->scaler.face_id == face_id ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_Manager_LookupSize( FTC_Manager manager, FTC_Scaler scaler, FT_Size *asize ) { FT_Error error; FTC_MruNode mrunode; if ( !asize || !scaler ) return FT_THROW( Invalid_Argument ); *asize = NULL; if ( !manager ) return FT_THROW( Invalid_Cache_Handle ); #ifdef FTC_INLINE FTC_MRULIST_LOOKUP_CMP( &manager->sizes, scaler, ftc_size_node_compare, mrunode, error ); #else error = FTC_MruList_Lookup( &manager->sizes, scaler, &mrunode ); #endif if ( !error ) *asize = FTC_SIZE_NODE( mrunode )->size; return error; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FACE MRU IMPLEMENTATION *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct FTC_FaceNodeRec_ { FTC_MruNodeRec node; FTC_FaceID face_id; FT_Face face; } FTC_FaceNodeRec, *FTC_FaceNode; #define FTC_FACE_NODE( x ) ( ( FTC_FaceNode )( x ) ) FT_CALLBACK_DEF( FT_Error ) ftc_face_node_init( FTC_MruNode ftcnode, FT_Pointer ftcface_id, FT_Pointer ftcmanager ) { FTC_FaceNode node = (FTC_FaceNode)ftcnode; FTC_FaceID face_id = (FTC_FaceID)ftcface_id; FTC_Manager manager = (FTC_Manager)ftcmanager; FT_Error error; node->face_id = face_id; error = manager->request_face( face_id, manager->library, manager->request_data, &node->face ); if ( !error ) { /* destroy initial size object; it will be re-created later */ if ( node->face->size ) FT_Done_Size( node->face->size ); } return error; } FT_CALLBACK_DEF( void ) ftc_face_node_done( FTC_MruNode ftcnode, FT_Pointer ftcmanager ) { FTC_FaceNode node = (FTC_FaceNode)ftcnode; FTC_Manager manager = (FTC_Manager)ftcmanager; /* we must begin by removing all scalers for the target face */ /* from the manager's list */ FTC_MruList_RemoveSelection( &manager->sizes, ftc_size_node_compare_faceid, node->face_id ); /* all right, we can discard the face now */ FT_Done_Face( node->face ); node->face = NULL; node->face_id = NULL; } FT_CALLBACK_DEF( FT_Bool ) ftc_face_node_compare( FTC_MruNode ftcnode, FT_Pointer ftcface_id ) { FTC_FaceNode node = (FTC_FaceNode)ftcnode; FTC_FaceID face_id = (FTC_FaceID)ftcface_id; return FT_BOOL( node->face_id == face_id ); } static const FTC_MruListClassRec ftc_face_list_class = { sizeof ( FTC_FaceNodeRec), ftc_face_node_compare, /* FTC_MruNode_CompareFunc node_compare */ ftc_face_node_init, /* FTC_MruNode_InitFunc node_init */ NULL, /* FTC_MruNode_ResetFunc node_reset */ ftc_face_node_done /* FTC_MruNode_DoneFunc node_done */ }; /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_Manager_LookupFace( FTC_Manager manager, FTC_FaceID face_id, FT_Face *aface ) { FT_Error error; FTC_MruNode mrunode; if ( !aface ) return FT_THROW( Invalid_Argument ); *aface = NULL; if ( !manager ) return FT_THROW( Invalid_Cache_Handle ); /* we break encapsulation for the sake of speed */ #ifdef FTC_INLINE FTC_MRULIST_LOOKUP_CMP( &manager->faces, face_id, ftc_face_node_compare, mrunode, error ); #else error = FTC_MruList_Lookup( &manager->faces, face_id, &mrunode ); #endif if ( !error ) *aface = FTC_FACE_NODE( mrunode )->face; return error; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE MANAGER ROUTINES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* documentation is in ftcache.h */ FT_EXPORT_DEF( FT_Error ) FTC_Manager_New( FT_Library library, FT_UInt max_faces, FT_UInt max_sizes, FT_ULong max_bytes, FTC_Face_Requester requester, FT_Pointer req_data, FTC_Manager *amanager ) { FT_Error error; FT_Memory memory; FTC_Manager manager = NULL; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !amanager || !requester ) return FT_THROW( Invalid_Argument ); memory = library->memory; if ( FT_QNEW( manager ) ) goto Exit; if ( max_faces == 0 ) max_faces = FTC_MAX_FACES_DEFAULT; if ( max_sizes == 0 ) max_sizes = FTC_MAX_SIZES_DEFAULT; if ( max_bytes == 0 ) max_bytes = FTC_MAX_BYTES_DEFAULT; manager->library = library; manager->memory = memory; manager->max_weight = max_bytes; manager->request_face = requester; manager->request_data = req_data; FTC_MruList_Init( &manager->faces, &ftc_face_list_class, max_faces, manager, memory ); FTC_MruList_Init( &manager->sizes, &ftc_size_list_class, max_sizes, manager, memory ); manager->nodes_list = NULL; manager->num_nodes = 0; manager->num_caches = 0; *amanager = manager; Exit: return error; } /* documentation is in ftcache.h */ FT_EXPORT_DEF( void ) FTC_Manager_Done( FTC_Manager manager ) { FT_Memory memory; FT_UInt idx; if ( !manager || !manager->library ) return; memory = manager->memory; /* now discard all caches */ for (idx = manager->num_caches; idx-- > 0; ) { FTC_Cache cache = manager->caches[idx]; if ( cache ) { cache->clazz.cache_done( cache ); FT_FREE( cache ); manager->caches[idx] = NULL; } } manager->num_caches = 0; /* discard faces and sizes */ FTC_MruList_Done( &manager->sizes ); FTC_MruList_Done( &manager->faces ); manager->library = NULL; manager->memory = NULL; FT_FREE( manager ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( void ) FTC_Manager_Reset( FTC_Manager manager ) { if ( !manager ) return; FTC_MruList_Reset( &manager->sizes ); FTC_MruList_Reset( &manager->faces ); FTC_Manager_FlushN( manager, manager->num_nodes ); } #ifdef FT_DEBUG_ERROR static void FTC_Manager_Check( FTC_Manager manager ) { FTC_Node node, first; first = manager->nodes_list; /* check node weights */ if ( first ) { FT_Offset weight = 0; node = first; do { FTC_Cache cache = manager->caches[node->cache_index]; if ( (FT_UInt)node->cache_index >= manager->num_caches ) FT_TRACE0(( "FTC_Manager_Check: invalid node (cache index = %ld\n", node->cache_index )); else weight += cache->clazz.node_weight( node, cache ); node = FTC_NODE_NEXT( node ); } while ( node != first ); if ( weight != manager->cur_weight ) FT_TRACE0(( "FTC_Manager_Check: invalid weight %ld instead of %ld\n", manager->cur_weight, weight )); } /* check circular list */ if ( first ) { FT_UFast count = 0; node = first; do { count++; node = FTC_NODE_NEXT( node ); } while ( node != first ); if ( count != manager->num_nodes ) FT_TRACE0(( "FTC_Manager_Check:" " invalid cache node count %d instead of %d\n", manager->num_nodes, count )); } } #endif /* FT_DEBUG_ERROR */ /* `Compress' the manager's data, i.e., get rid of old cache nodes */ /* that are not referenced anymore in order to limit the total */ /* memory used by the cache. */ /* documentation is in ftcmanag.h */ FT_LOCAL_DEF( void ) FTC_Manager_Compress( FTC_Manager manager ) { FTC_Node node, first; if ( !manager ) return; first = manager->nodes_list; #ifdef FT_DEBUG_ERROR FTC_Manager_Check( manager ); FT_TRACE0(( "compressing, weight = %ld, max = %ld, nodes = %d\n", manager->cur_weight, manager->max_weight, manager->num_nodes )); #endif if ( manager->cur_weight < manager->max_weight || !first ) return; /* go to last node -- it's a circular list */ node = FTC_NODE_PREV( first ); do { FTC_Node prev; prev = ( node == first ) ? NULL : FTC_NODE_PREV( node ); if ( node->ref_count <= 0 ) ftc_node_destroy( node, manager ); node = prev; } while ( node && manager->cur_weight > manager->max_weight ); } /* documentation is in ftcmanag.h */ FT_LOCAL_DEF( FT_Error ) FTC_Manager_RegisterCache( FTC_Manager manager, FTC_CacheClass clazz, FTC_Cache *acache ) { FT_Error error = FT_ERR( Invalid_Argument ); FTC_Cache cache = NULL; if ( manager && clazz && acache ) { FT_Memory memory = manager->memory; if ( manager->num_caches >= FTC_MAX_CACHES ) { error = FT_THROW( Too_Many_Caches ); FT_ERROR(( "FTC_Manager_RegisterCache:" " too many registered caches\n" )); goto Exit; } if ( !FT_QALLOC( cache, clazz->cache_size ) ) { cache->manager = manager; cache->memory = memory; cache->clazz = clazz[0]; cache->org_class = clazz; /* THIS IS VERY IMPORTANT! IT WILL WRETCH THE MANAGER */ /* IF IT IS NOT SET CORRECTLY */ cache->index = manager->num_caches; error = clazz->cache_init( cache ); if ( error ) { clazz->cache_done( cache ); FT_FREE( cache ); goto Exit; } manager->caches[manager->num_caches++] = cache; } } Exit: if ( acache ) *acache = cache; return error; } FT_LOCAL_DEF( FT_UInt ) FTC_Manager_FlushN( FTC_Manager manager, FT_UInt count ) { FTC_Node first = manager->nodes_list; FTC_Node node; FT_UInt result; /* try to remove `count' nodes from the list */ if ( !first ) /* empty list! */ return 0; /* go to last node - it's a circular list */ node = FTC_NODE_PREV(first); for ( result = 0; result < count; ) { FTC_Node prev = FTC_NODE_PREV( node ); /* don't touch locked nodes */ if ( node->ref_count <= 0 ) { ftc_node_destroy( node, manager ); result++; } if ( node == first ) break; node = prev; } return result; } /* documentation is in ftcache.h */ FT_EXPORT_DEF( void ) FTC_Manager_RemoveFaceID( FTC_Manager manager, FTC_FaceID face_id ) { FT_UInt nn; if ( !manager ) return; /* this will remove all FTC_SizeNode that correspond to * the face_id as well */ FTC_MruList_RemoveSelection( &manager->faces, ftc_face_node_compare, face_id ); for ( nn = 0; nn < manager->num_caches; nn++ ) FTC_Cache_RemoveFaceID( manager->caches[nn], face_id ); } /* documentation is in ftcache.h */ FT_EXPORT_DEF( void ) FTC_Node_Unref( FTC_Node node, FTC_Manager manager ) { if ( node && manager && (FT_UInt)node->cache_index < manager->num_caches ) node->ref_count--; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcmanag.c
C++
gpl-3.0
17,344
/**************************************************************************** * * ftcmanag.h * * FreeType Cache Manager (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. * */ /************************************************************************** * * A cache manager is in charge of the following: * * - Maintain a mapping between generic FTC_FaceIDs and live FT_Face * objects. The mapping itself is performed through a user-provided * callback. However, the manager maintains a small cache of FT_Face * and FT_Size objects in order to speed up things considerably. * * - Manage one or more cache objects. Each cache is in charge of * holding a varying number of `cache nodes'. Each cache node * represents a minimal amount of individually accessible cached * data. For example, a cache node can be an FT_Glyph image * containing a vector outline, or some glyph metrics, or anything * else. * * Each cache node has a certain size in bytes that is added to the * total amount of `cache memory' within the manager. * * All cache nodes are located in a global LRU list, where the oldest * node is at the tail of the list. * * Each node belongs to a single cache, and includes a reference * count to avoid destroying it (due to caching). * */ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********* *********/ /********* WARNING, THIS IS BETA CODE. *********/ /********* *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ #ifndef FTCMANAG_H_ #define FTCMANAG_H_ #include <freetype/ftcache.h> #include "ftcmru.h" #include "ftccache.h" FT_BEGIN_HEADER /************************************************************************** * * @Section: * cache_subsystem * */ #define FTC_MAX_FACES_DEFAULT 2 #define FTC_MAX_SIZES_DEFAULT 4 #define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */ /* maximum number of caches registered in a single manager */ #define FTC_MAX_CACHES 16 typedef struct FTC_ManagerRec_ { FT_Library library; FT_Memory memory; FTC_Node nodes_list; FT_Offset max_weight; FT_Offset cur_weight; FT_UInt num_nodes; FTC_Cache caches[FTC_MAX_CACHES]; FT_UInt num_caches; FTC_MruListRec faces; FTC_MruListRec sizes; FT_Pointer request_data; FTC_Face_Requester request_face; } FTC_ManagerRec; /************************************************************************** * * @Function: * FTC_Manager_Compress * * @Description: * This function is used to check the state of the cache manager if * its `num_bytes' field is greater than its `max_bytes' field. It * will flush as many old cache nodes as possible (ignoring cache * nodes with a non-zero reference count). * * @InOut: * manager :: * A handle to the cache manager. * * @Note: * Client applications should not call this function directly. It is * normally invoked by specific cache implementations. * * The reason this function is exported is to allow client-specific * cache classes. */ FT_LOCAL( void ) FTC_Manager_Compress( FTC_Manager manager ); /* try to flush `count' old nodes from the cache; return the number * of really flushed nodes */ FT_LOCAL( FT_UInt ) FTC_Manager_FlushN( FTC_Manager manager, FT_UInt count ); /* this must be used internally for the moment */ FT_LOCAL( FT_Error ) FTC_Manager_RegisterCache( FTC_Manager manager, FTC_CacheClass clazz, FTC_Cache *acache ); /* */ #define FTC_SCALER_COMPARE( a, b ) \ ( (a)->face_id == (b)->face_id && \ (a)->width == (b)->width && \ (a)->height == (b)->height && \ ((a)->pixel != 0) == ((b)->pixel != 0) && \ ( (a)->pixel || \ ( (a)->x_res == (b)->x_res && \ (a)->y_res == (b)->y_res ) ) ) #define FTC_SCALER_HASH( q ) \ ( FTC_FACE_ID_HASH( (q)->face_id ) + \ (q)->width + (q)->height*7 + \ ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) ) /* */ FT_END_HEADER #endif /* FTCMANAG_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcmanag.h
C++
gpl-3.0
5,734
/**************************************************************************** * * ftcmru.c * * FreeType MRU support (body). * * 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. * */ #include <freetype/ftcache.h> #include "ftcmru.h" #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include "ftcerror.h" FT_LOCAL_DEF( void ) FTC_MruNode_Prepend( FTC_MruNode *plist, FTC_MruNode node ) { FTC_MruNode first = *plist; if ( first ) { FTC_MruNode last = first->prev; #ifdef FT_DEBUG_ERROR { FTC_MruNode cnode = first; do { if ( cnode == node ) { fprintf( stderr, "FTC_MruNode_Prepend: invalid action\n" ); exit( 2 ); } cnode = cnode->next; } while ( cnode != first ); } #endif first->prev = node; last->next = node; node->next = first; node->prev = last; } else { node->next = node; node->prev = node; } *plist = node; } FT_LOCAL_DEF( void ) FTC_MruNode_Up( FTC_MruNode *plist, FTC_MruNode node ) { FTC_MruNode first = *plist; FT_ASSERT( first ); if ( first != node ) { FTC_MruNode prev, next, last; #ifdef FT_DEBUG_ERROR { FTC_MruNode cnode = first; do { if ( cnode == node ) goto Ok; cnode = cnode->next; } while ( cnode != first ); fprintf( stderr, "FTC_MruNode_Up: invalid action\n" ); exit( 2 ); Ok: } #endif prev = node->prev; next = node->next; prev->next = next; next->prev = prev; last = first->prev; last->next = node; first->prev = node; node->next = first; node->prev = last; *plist = node; } } FT_LOCAL_DEF( void ) FTC_MruNode_Remove( FTC_MruNode *plist, FTC_MruNode node ) { FTC_MruNode first = *plist; FTC_MruNode prev, next; FT_ASSERT( first ); #ifdef FT_DEBUG_ERROR { FTC_MruNode cnode = first; do { if ( cnode == node ) goto Ok; cnode = cnode->next; } while ( cnode != first ); fprintf( stderr, "FTC_MruNode_Remove: invalid action\n" ); exit( 2 ); Ok: } #endif prev = node->prev; next = node->next; prev->next = next; next->prev = prev; if ( node == next ) { FT_ASSERT( first == node ); FT_ASSERT( prev == node ); *plist = NULL; } else if ( node == first ) *plist = next; } FT_LOCAL_DEF( void ) FTC_MruList_Init( FTC_MruList list, FTC_MruListClass clazz, FT_UInt max_nodes, FT_Pointer data, FT_Memory memory ) { list->num_nodes = 0; list->max_nodes = max_nodes; list->nodes = NULL; list->clazz = *clazz; list->data = data; list->memory = memory; } FT_LOCAL_DEF( void ) FTC_MruList_Reset( FTC_MruList list ) { while ( list->nodes ) FTC_MruList_Remove( list, list->nodes ); FT_ASSERT( list->num_nodes == 0 ); } FT_LOCAL_DEF( void ) FTC_MruList_Done( FTC_MruList list ) { FTC_MruList_Reset( list ); } #ifndef FTC_INLINE FT_LOCAL_DEF( FTC_MruNode ) FTC_MruList_Find( FTC_MruList list, FT_Pointer key ) { FTC_MruNode_CompareFunc compare = list->clazz.node_compare; FTC_MruNode first, node; first = list->nodes; node = NULL; if ( first ) { node = first; do { if ( compare( node, key ) ) { if ( node != first ) FTC_MruNode_Up( &list->nodes, node ); return node; } node = node->next; } while ( node != first); } return NULL; } #endif FT_LOCAL_DEF( FT_Error ) FTC_MruList_New( FTC_MruList list, FT_Pointer key, FTC_MruNode *anode ) { FT_Error error; FTC_MruNode node = NULL; FT_Memory memory = list->memory; if ( list->num_nodes >= list->max_nodes && list->max_nodes > 0 ) { node = list->nodes->prev; FT_ASSERT( node ); if ( list->clazz.node_reset ) { FTC_MruNode_Up( &list->nodes, node ); error = list->clazz.node_reset( node, key, list->data ); if ( !error ) goto Exit; } FTC_MruNode_Remove( &list->nodes, node ); list->num_nodes--; if ( list->clazz.node_done ) list->clazz.node_done( node, list->data ); } /* zero new node in case of node_init failure */ else if ( FT_ALLOC( node, list->clazz.node_size ) ) goto Exit; error = list->clazz.node_init( node, key, list->data ); if ( error ) goto Fail; FTC_MruNode_Prepend( &list->nodes, node ); list->num_nodes++; Exit: *anode = node; return error; Fail: if ( list->clazz.node_done ) list->clazz.node_done( node, list->data ); FT_FREE( node ); goto Exit; } #ifndef FTC_INLINE FT_LOCAL_DEF( FT_Error ) FTC_MruList_Lookup( FTC_MruList list, FT_Pointer key, FTC_MruNode *anode ) { FTC_MruNode node; node = FTC_MruList_Find( list, key ); if ( !node ) return FTC_MruList_New( list, key, anode ); *anode = node; return 0; } #endif /* FTC_INLINE */ FT_LOCAL_DEF( void ) FTC_MruList_Remove( FTC_MruList list, FTC_MruNode node ) { FTC_MruNode_Remove( &list->nodes, node ); list->num_nodes--; { FT_Memory memory = list->memory; if ( list->clazz.node_done ) list->clazz.node_done( node, list->data ); FT_FREE( node ); } } FT_LOCAL_DEF( void ) FTC_MruList_RemoveSelection( FTC_MruList list, FTC_MruNode_CompareFunc selection, FT_Pointer key ) { FTC_MruNode first, node, next; first = list->nodes; while ( first && ( !selection || selection( first, key ) ) ) { FTC_MruList_Remove( list, first ); first = list->nodes; } if ( first ) { node = first->next; while ( node != first ) { next = node->next; if ( selection( node, key ) ) FTC_MruList_Remove( list, node ); node = next; } } } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcmru.c
C++
gpl-3.0
7,002
/**************************************************************************** * * ftcmru.h * * Simple MRU list-cache (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. * */ /************************************************************************** * * An MRU is a list that cannot hold more than a certain number of * elements (`max_elements'). All elements in the list are sorted in * least-recently-used order, i.e., the `oldest' element is at the tail * of the list. * * When doing a lookup (either through `Lookup()' or `Lookup_Node()'), * the list is searched for an element with the corresponding key. If * it is found, the element is moved to the head of the list and is * returned. * * If no corresponding element is found, the lookup routine will try to * obtain a new element with the relevant key. If the list is already * full, the oldest element from the list is discarded and replaced by a * new one; a new element is added to the list otherwise. * * Note that it is possible to pre-allocate the element list nodes. * This is handy if `max_elements' is sufficiently small, as it saves * allocations/releases during the lookup process. * */ #ifndef FTCMRU_H_ #define FTCMRU_H_ #include <freetype/freetype.h> #include <freetype/internal/compiler-macros.h> #ifdef FREETYPE_H #error "freetype.h of FreeType 1 has been loaded!" #error "Please fix the directory search order for header files" #error "so that freetype.h of FreeType 2 is found first." #endif #define xxFT_DEBUG_ERROR #define FTC_INLINE FT_BEGIN_HEADER typedef struct FTC_MruNodeRec_* FTC_MruNode; typedef struct FTC_MruNodeRec_ { FTC_MruNode next; FTC_MruNode prev; } FTC_MruNodeRec; FT_LOCAL( void ) FTC_MruNode_Prepend( FTC_MruNode *plist, FTC_MruNode node ); FT_LOCAL( void ) FTC_MruNode_Up( FTC_MruNode *plist, FTC_MruNode node ); FT_LOCAL( void ) FTC_MruNode_Remove( FTC_MruNode *plist, FTC_MruNode node ); typedef struct FTC_MruListRec_* FTC_MruList; typedef struct FTC_MruListClassRec_ const * FTC_MruListClass; typedef FT_Bool (*FTC_MruNode_CompareFunc)( FTC_MruNode node, FT_Pointer key ); typedef FT_Error (*FTC_MruNode_InitFunc)( FTC_MruNode node, FT_Pointer key, FT_Pointer data ); typedef FT_Error (*FTC_MruNode_ResetFunc)( FTC_MruNode node, FT_Pointer key, FT_Pointer data ); typedef void (*FTC_MruNode_DoneFunc)( FTC_MruNode node, FT_Pointer data ); typedef struct FTC_MruListClassRec_ { FT_Offset node_size; FTC_MruNode_CompareFunc node_compare; FTC_MruNode_InitFunc node_init; FTC_MruNode_ResetFunc node_reset; FTC_MruNode_DoneFunc node_done; } FTC_MruListClassRec; typedef struct FTC_MruListRec_ { FT_UInt num_nodes; FT_UInt max_nodes; FTC_MruNode nodes; FT_Pointer data; FTC_MruListClassRec clazz; FT_Memory memory; } FTC_MruListRec; FT_LOCAL( void ) FTC_MruList_Init( FTC_MruList list, FTC_MruListClass clazz, FT_UInt max_nodes, FT_Pointer data, FT_Memory memory ); FT_LOCAL( void ) FTC_MruList_Reset( FTC_MruList list ); FT_LOCAL( void ) FTC_MruList_Done( FTC_MruList list ); FT_LOCAL( FT_Error ) FTC_MruList_New( FTC_MruList list, FT_Pointer key, FTC_MruNode *anode ); FT_LOCAL( void ) FTC_MruList_Remove( FTC_MruList list, FTC_MruNode node ); FT_LOCAL( void ) FTC_MruList_RemoveSelection( FTC_MruList list, FTC_MruNode_CompareFunc selection, FT_Pointer key ); #ifdef FTC_INLINE #define FTC_MRULIST_LOOKUP_CMP( list, key, compare, node, error ) \ FT_BEGIN_STMNT \ FTC_MruNode* _pfirst = &(list)->nodes; \ FTC_MruNode_CompareFunc _compare = (FTC_MruNode_CompareFunc)(compare); \ FTC_MruNode _first, _node; \ \ \ error = FT_Err_Ok; \ _first = *(_pfirst); \ _node = NULL; \ \ if ( _first ) \ { \ _node = _first; \ do \ { \ if ( _compare( _node, (key) ) ) \ { \ if ( _node != _first ) \ FTC_MruNode_Up( _pfirst, _node ); \ \ node = _node; \ goto MruOk_; \ } \ _node = _node->next; \ \ } while ( _node != _first); \ } \ \ error = FTC_MruList_New( (list), (key), (FTC_MruNode*)(void*)&(node) ); \ MruOk_: \ ; \ FT_END_STMNT #define FTC_MRULIST_LOOKUP( list, key, node, error ) \ FTC_MRULIST_LOOKUP_CMP( list, key, (list)->clazz.node_compare, node, error ) #else /* !FTC_INLINE */ FT_LOCAL( FTC_MruNode ) FTC_MruList_Find( FTC_MruList list, FT_Pointer key ); FT_LOCAL( FT_Error ) FTC_MruList_Lookup( FTC_MruList list, FT_Pointer key, FTC_MruNode *pnode ); #define FTC_MRULIST_LOOKUP( list, key, node, error ) \ error = FTC_MruList_Lookup( (list), (key), (FTC_MruNode*)&(node) ) #endif /* !FTC_INLINE */ #define FTC_MRULIST_LOOP( list, node ) \ FT_BEGIN_STMNT \ FTC_MruNode _first = (list)->nodes; \ \ \ if ( _first ) \ { \ FTC_MruNode _node = _first; \ \ \ do \ { \ *(FTC_MruNode*)&(node) = _node; #define FTC_MRULIST_LOOP_END() \ _node = _node->next; \ \ } while ( _node != _first ); \ } \ FT_END_STMNT /* */ FT_END_HEADER #endif /* FTCMRU_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcmru.h
C++
gpl-3.0
8,525
/**************************************************************************** * * ftcsbits.c * * FreeType sbits manager (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/ftcache.h> #include "ftcsbits.h" #include <freetype/internal/ftobjs.h> #include <freetype/internal/ftdebug.h> #include <freetype/fterrors.h> #include "ftccback.h" #include "ftcerror.h" #undef FT_COMPONENT #define FT_COMPONENT cache /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** SBIT CACHE NODES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static FT_Error ftc_sbit_copy_bitmap( FTC_SBit sbit, FT_Bitmap* bitmap, FT_Memory memory ) { FT_Error error; FT_Int pitch = bitmap->pitch; FT_ULong size; if ( pitch < 0 ) pitch = -pitch; size = (FT_ULong)pitch * bitmap->rows; if ( !FT_QALLOC( sbit->buffer, size ) ) FT_MEM_COPY( sbit->buffer, bitmap->buffer, size ); return error; } FT_LOCAL_DEF( void ) ftc_snode_free( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_SBit sbit = snode->sbits; FT_UInt count = snode->count; FT_Memory memory = cache->memory; for ( ; count > 0; sbit++, count-- ) FT_FREE( sbit->buffer ); FTC_GNode_Done( FTC_GNODE( snode ), cache ); FT_FREE( snode ); } FT_LOCAL_DEF( void ) FTC_SNode_Free( FTC_SNode snode, FTC_Cache cache ) { ftc_snode_free( FTC_NODE( snode ), cache ); } /* * This function tries to load a small bitmap within a given FTC_SNode. * Note that it returns a non-zero error code _only_ in the case of * out-of-memory condition. For all other errors (e.g., corresponding * to a bad font file), this function will mark the sbit as `unavailable' * and return a value of 0. * * You should also read the comment within the @ftc_snode_compare * function below to see how out-of-memory is handled during a lookup. */ static FT_Error ftc_snode_load( FTC_SNode snode, FTC_Manager manager, FT_UInt gindex, FT_ULong *asize ) { FT_Error error; FTC_GNode gnode = FTC_GNODE( snode ); FTC_Family family = gnode->family; FT_Face face; FTC_SBit sbit; FTC_SFamilyClass clazz; if ( gindex - gnode->gindex >= snode->count ) { FT_ERROR(( "ftc_snode_load: invalid glyph index" )); return FT_THROW( Invalid_Argument ); } sbit = snode->sbits + ( gindex - gnode->gindex ); clazz = (FTC_SFamilyClass)family->clazz; error = clazz->family_load_glyph( family, gindex, manager, &face ); if ( error ) goto BadGlyph; { FT_Int temp; FT_GlyphSlot slot = face->glyph; FT_Bitmap* bitmap = &slot->bitmap; FT_Pos xadvance, yadvance; /* FT_GlyphSlot->advance.{x|y} */ if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) { FT_TRACE0(( "ftc_snode_load:" " glyph loaded didn't return a bitmap\n" )); goto BadGlyph; } /* Check whether our values fit into 8/16-bit containers! */ /* If this is not the case, our bitmap is too large */ /* and we will leave it as `missing' with sbit.buffer = 0 */ #define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d ) #define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d ) #define CHECK_SHRT( d ) ( temp = (FT_Short)d, (FT_Int)temp == (FT_Int) d ) /* horizontal advance in pixels */ xadvance = ( slot->advance.x + 32 ) >> 6; yadvance = ( slot->advance.y + 32 ) >> 6; if ( !CHECK_BYTE( bitmap->rows ) || !CHECK_BYTE( bitmap->width ) || !CHECK_SHRT( bitmap->pitch ) || !CHECK_CHAR( slot->bitmap_left ) || !CHECK_CHAR( slot->bitmap_top ) || !CHECK_CHAR( xadvance ) || !CHECK_CHAR( yadvance ) ) { FT_TRACE2(( "ftc_snode_load:" " glyph too large for small bitmap cache\n")); goto BadGlyph; } sbit->width = (FT_Byte)bitmap->width; sbit->height = (FT_Byte)bitmap->rows; sbit->pitch = (FT_Short)bitmap->pitch; sbit->left = (FT_Char)slot->bitmap_left; sbit->top = (FT_Char)slot->bitmap_top; sbit->xadvance = (FT_Char)xadvance; sbit->yadvance = (FT_Char)yadvance; sbit->format = (FT_Byte)bitmap->pixel_mode; sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1); if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) { /* take the bitmap ownership */ sbit->buffer = bitmap->buffer; slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } else { /* copy the bitmap into a new buffer -- ignore error */ error = ftc_sbit_copy_bitmap( sbit, bitmap, manager->memory ); } /* now, compute size */ if ( asize ) *asize = (FT_ULong)FT_ABS( sbit->pitch ) * sbit->height; } /* glyph loading successful */ /* ignore the errors that might have occurred -- */ /* we mark unloaded glyphs with `sbit.buffer == 0' */ /* and `width == 255', `height == 0' */ /* */ if ( error && FT_ERR_NEQ( error, Out_Of_Memory ) ) { BadGlyph: sbit->width = 255; sbit->height = 0; sbit->buffer = NULL; error = FT_Err_Ok; if ( asize ) *asize = 0; } return error; } FT_LOCAL_DEF( FT_Error ) FTC_SNode_New( FTC_SNode *psnode, FTC_GQuery gquery, FTC_Cache cache ) { FT_Memory memory = cache->memory; FT_Error error; FTC_SNode snode = NULL; FT_UInt gindex = gquery->gindex; FTC_Family family = gquery->family; FTC_SFamilyClass clazz = FTC_CACHE_SFAMILY_CLASS( cache ); FT_UInt total; FT_UInt node_count; total = clazz->family_get_count( family, cache->manager ); if ( total == 0 || gindex >= total ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( !FT_QNEW( snode ) ) { FT_UInt count, start; start = gindex - ( gindex % FTC_SBIT_ITEMS_PER_NODE ); count = total - start; if ( count > FTC_SBIT_ITEMS_PER_NODE ) count = FTC_SBIT_ITEMS_PER_NODE; FTC_GNode_Init( FTC_GNODE( snode ), start, family ); snode->count = count; for ( node_count = 0; node_count < count; node_count++ ) { snode->sbits[node_count].width = 255; snode->sbits[node_count].height = 0; snode->sbits[node_count].buffer = NULL; } error = ftc_snode_load( snode, cache->manager, gindex, NULL ); if ( error ) { FTC_SNode_Free( snode, cache ); snode = NULL; } } Exit: *psnode = snode; return error; } FT_LOCAL_DEF( FT_Error ) ftc_snode_new( FTC_Node *ftcpsnode, FT_Pointer ftcgquery, FTC_Cache cache ) { FTC_SNode *psnode = (FTC_SNode*)ftcpsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; return FTC_SNode_New( psnode, gquery, cache ); } FT_LOCAL_DEF( FT_Offset ) ftc_snode_weight( FTC_Node ftcsnode, FTC_Cache cache ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FT_UInt count = snode->count; FTC_SBit sbit = snode->sbits; FT_Int pitch; FT_Offset size; FT_UNUSED( cache ); FT_ASSERT( snode->count <= FTC_SBIT_ITEMS_PER_NODE ); /* the node itself */ size = sizeof ( *snode ); for ( ; count > 0; count--, sbit++ ) { if ( sbit->buffer ) { pitch = sbit->pitch; if ( pitch < 0 ) pitch = -pitch; /* add the size of a given glyph image */ size += (FT_Offset)pitch * sbit->height; } } return size; } #if 0 FT_LOCAL_DEF( FT_Offset ) FTC_SNode_Weight( FTC_SNode snode ) { return ftc_snode_weight( FTC_NODE( snode ), NULL ); } #endif /* 0 */ FT_LOCAL_DEF( FT_Bool ) ftc_snode_compare( FTC_Node ftcsnode, FT_Pointer ftcgquery, FTC_Cache cache, FT_Bool* list_changed ) { FTC_SNode snode = (FTC_SNode)ftcsnode; FTC_GQuery gquery = (FTC_GQuery)ftcgquery; FTC_GNode gnode = FTC_GNODE( snode ); FT_UInt gindex = gquery->gindex; FT_Bool result; if (list_changed) *list_changed = FALSE; result = FT_BOOL( gnode->family == gquery->family && gindex - gnode->gindex < snode->count ); if ( result ) { /* check if we need to load the glyph bitmap now */ FTC_SBit sbit = snode->sbits + ( gindex - gnode->gindex ); /* * The following code illustrates what to do when you want to * perform operations that may fail within a lookup function. * * Here, we want to load a small bitmap on-demand; we thus * need to call the `ftc_snode_load' function which may return * a non-zero error code only when we are out of memory (OOM). * * The correct thing to do is to use @FTC_CACHE_TRYLOOP and * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop * that is capable of flushing the cache incrementally when * an OOM errors occur. * * However, we need to `lock' the node before this operation to * prevent it from being flushed within the loop. * * When we exit the loop, we unlock the node, then check the `error' * variable. If it is non-zero, this means that the cache was * completely flushed and that no usable memory was found to load * the bitmap. * * We then prefer to return a value of 0 (i.e., NO MATCH). This * ensures that the caller will try to allocate a new node. * This operation consequently _fail_ and the lookup function * returns the appropriate OOM error code. * * Note that `buffer == NULL && width == 255' is a hack used to * tag `unavailable' bitmaps in the array. We should never try * to load these. * */ if ( !sbit->buffer && sbit->width == 255 ) { FT_ULong size; FT_Error error; ftcsnode->ref_count++; /* lock node to prevent flushing */ /* in retry loop */ FTC_CACHE_TRYLOOP( cache ) { error = ftc_snode_load( snode, cache->manager, gindex, &size ); } FTC_CACHE_TRYLOOP_END( list_changed ) ftcsnode->ref_count--; /* unlock the node */ if ( error ) result = 0; else cache->manager->cur_weight += size; } } return result; } #ifdef FTC_INLINE FT_LOCAL_DEF( FT_Bool ) FTC_SNode_Compare( FTC_SNode snode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed ) { return ftc_snode_compare( FTC_NODE( snode ), gquery, cache, list_changed ); } #endif /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcsbits.c
C++
gpl-3.0
12,296
/**************************************************************************** * * ftcsbits.h * * A small-bitmap cache (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 FTCSBITS_H_ #define FTCSBITS_H_ #include <freetype/ftcache.h> #include "ftcglyph.h" FT_BEGIN_HEADER #define FTC_SBIT_ITEMS_PER_NODE 16 typedef struct FTC_SNodeRec_ { FTC_GNodeRec gnode; FT_UInt count; FTC_SBitRec sbits[FTC_SBIT_ITEMS_PER_NODE]; } FTC_SNodeRec, *FTC_SNode; #define FTC_SNODE( x ) ( (FTC_SNode)( x ) ) #define FTC_SNODE_GINDEX( x ) FTC_GNODE( x )->gindex #define FTC_SNODE_FAMILY( x ) FTC_GNODE( x )->family typedef FT_UInt (*FTC_SFamily_GetCountFunc)( FTC_Family family, FTC_Manager manager ); typedef FT_Error (*FTC_SFamily_LoadGlyphFunc)( FTC_Family family, FT_UInt gindex, FTC_Manager manager, FT_Face *aface ); typedef struct FTC_SFamilyClassRec_ { FTC_MruListClassRec clazz; FTC_SFamily_GetCountFunc family_get_count; FTC_SFamily_LoadGlyphFunc family_load_glyph; } FTC_SFamilyClassRec; typedef const FTC_SFamilyClassRec* FTC_SFamilyClass; #define FTC_SFAMILY_CLASS( x ) ((FTC_SFamilyClass)(x)) #define FTC_CACHE_SFAMILY_CLASS( x ) \ FTC_SFAMILY_CLASS( FTC_CACHE_GCACHE_CLASS( x )->family_class ) FT_LOCAL( void ) FTC_SNode_Free( FTC_SNode snode, FTC_Cache cache ); FT_LOCAL( FT_Error ) FTC_SNode_New( FTC_SNode *psnode, FTC_GQuery gquery, FTC_Cache cache ); #if 0 FT_LOCAL( FT_ULong ) FTC_SNode_Weight( FTC_SNode inode ); #endif #ifdef FTC_INLINE FT_LOCAL( FT_Bool ) FTC_SNode_Compare( FTC_SNode snode, FTC_GQuery gquery, FTC_Cache cache, FT_Bool* list_changed); #endif /* */ FT_END_HEADER #endif /* FTCSBITS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/ftcsbits.h
C++
gpl-3.0
2,409
# # FreeType 2 Cache configuration rules # # 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. # Cache driver directory # CACHE_DIR := $(SRC_DIR)/cache # compilation flags for the driver # CACHE_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(CACHE_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # Cache driver sources (i.e., C files) # CACHE_DRV_SRC := $(CACHE_DIR)/ftcbasic.c \ $(CACHE_DIR)/ftccache.c \ $(CACHE_DIR)/ftccmap.c \ $(CACHE_DIR)/ftcglyph.c \ $(CACHE_DIR)/ftcimage.c \ $(CACHE_DIR)/ftcmanag.c \ $(CACHE_DIR)/ftcmru.c \ $(CACHE_DIR)/ftcsbits.c # Cache driver headers # CACHE_DRV_H := $(CACHE_DIR)/ftccache.h \ $(CACHE_DIR)/ftccback.h \ $(CACHE_DIR)/ftcerror.h \ $(CACHE_DIR)/ftcglyph.h \ $(CACHE_DIR)/ftcimage.h \ $(CACHE_DIR)/ftcmanag.h \ $(CACHE_DIR)/ftcmru.h \ $(CACHE_DIR)/ftcsbits.h # Cache driver object(s) # # CACHE_DRV_OBJ_M is used during `multi' builds. # CACHE_DRV_OBJ_S is used during `single' builds. # CACHE_DRV_OBJ_M := $(CACHE_DRV_SRC:$(CACHE_DIR)/%.c=$(OBJ_DIR)/%.$O) CACHE_DRV_OBJ_S := $(OBJ_DIR)/ftcache.$O # Cache driver source file for single build # CACHE_DRV_SRC_S := $(CACHE_DIR)/ftcache.c # Cache driver - single object # $(CACHE_DRV_OBJ_S): $(CACHE_DRV_SRC_S) $(CACHE_DRV_SRC) \ $(FREETYPE_H) $(CACHE_DRV_H) $(CACHE_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(CACHE_DRV_SRC_S)) # Cache driver - multiple objects # $(OBJ_DIR)/%.$O: $(CACHE_DIR)/%.c $(FREETYPE_H) $(CACHE_DRV_H) $(CACHE_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(CACHE_DRV_OBJ_S) DRV_OBJS_M += $(CACHE_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/cache/rules.mk
mk
gpl-3.0
2,308
/**************************************************************************** * * cff.c * * FreeType OpenType driver 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 "cffcmap.c" #include "cffdrivr.c" #include "cffgload.c" #include "cffparse.c" #include "cffload.c" #include "cffobjs.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cff.c
C++
gpl-3.0
725
/**************************************************************************** * * cffcmap.c * * CFF 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 "cffcmap.h" #include "cffload.h" #include "cfferrs.h" /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_CALLBACK_DEF( FT_Error ) cff_cmap_encoding_init( CFF_CMapStd cmap, FT_Pointer pointer ) { TT_Face face = (TT_Face)FT_CMAP_FACE( cmap ); CFF_Font cff = (CFF_Font)face->extra.data; CFF_Encoding encoding = &cff->encoding; FT_UNUSED( pointer ); cmap->gids = encoding->codes; return 0; } FT_CALLBACK_DEF( void ) cff_cmap_encoding_done( CFF_CMapStd cmap ) { cmap->gids = NULL; } FT_CALLBACK_DEF( FT_UInt ) cff_cmap_encoding_char_index( CFF_CMapStd cmap, FT_UInt32 char_code ) { FT_UInt result = 0; if ( char_code < 256 ) result = cmap->gids[char_code]; return result; } FT_CALLBACK_DEF( FT_UInt32 ) cff_cmap_encoding_char_next( CFF_CMapStd cmap, FT_UInt32 *pchar_code ) { FT_UInt result = 0; FT_UInt32 char_code = *pchar_code; *pchar_code = 0; if ( char_code < 255 ) { FT_UInt code = (FT_UInt)(char_code + 1); for (;;) { if ( code >= 256 ) break; result = cmap->gids[code]; if ( result != 0 ) { *pchar_code = code; break; } code++; } } return result; } FT_DEFINE_CMAP_CLASS( cff_cmap_encoding_class_rec, sizeof ( CFF_CMapStdRec ), (FT_CMap_InitFunc) cff_cmap_encoding_init, /* init */ (FT_CMap_DoneFunc) cff_cmap_encoding_done, /* done */ (FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index, /* char_index */ (FT_CMap_CharNextFunc) cff_cmap_encoding_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 */ ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_CALLBACK_DEF( const char* ) cff_sid_to_glyph_name( TT_Face face, FT_UInt idx ) { CFF_Font cff = (CFF_Font)face->extra.data; CFF_Charset charset = &cff->charset; FT_UInt sid = charset->sids[idx]; return cff_index_get_sid_string( cff, sid ); } FT_CALLBACK_DEF( FT_Error ) cff_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 ); CFF_Font cff = (CFF_Font)face->extra.data; CFF_Charset charset = &cff->charset; FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; FT_UNUSED( pointer ); /* can't build Unicode map for CID-keyed font */ /* because we don't know glyph names. */ if ( !charset->sids ) return FT_THROW( No_Unicode_Glyph_Name ); if ( !psnames->unicodes_init ) return FT_THROW( Unimplemented_Feature ); return psnames->unicodes_init( memory, unicodes, cff->num_glyphs, (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name, (PS_FreeGlyphNameFunc)NULL, (FT_Pointer)face ); } FT_CALLBACK_DEF( void ) cff_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 ) cff_cmap_unicode_char_index( PS_Unicodes unicodes, FT_UInt32 char_code ) { TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes ); CFF_Font cff = (CFF_Font)face->extra.data; FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; return psnames->unicodes_char_index( unicodes, char_code ); } FT_CALLBACK_DEF( FT_UInt32 ) cff_cmap_unicode_char_next( PS_Unicodes unicodes, FT_UInt32 *pchar_code ) { TT_Face face = (TT_Face)FT_CMAP_FACE( unicodes ); CFF_Font cff = (CFF_Font)face->extra.data; FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; return psnames->unicodes_char_next( unicodes, pchar_code ); } FT_DEFINE_CMAP_CLASS( cff_cmap_unicode_class_rec, sizeof ( PS_UnicodesRec ), (FT_CMap_InitFunc) cff_cmap_unicode_init, /* init */ (FT_CMap_DoneFunc) cff_cmap_unicode_done, /* done */ (FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index, /* char_index */ (FT_CMap_CharNextFunc) cff_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/cff/cffcmap.c
C++
gpl-3.0
6,971
/**************************************************************************** * * cffcmap.h * * CFF 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 CFFCMAP_H_ #define CFFCMAP_H_ #include <freetype/internal/cffotypes.h> FT_BEGIN_HEADER /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* standard (and expert) encoding cmaps */ typedef struct CFF_CMapStdRec_* CFF_CMapStd; typedef struct CFF_CMapStdRec_ { FT_CMapRec cmap; FT_UShort* gids; /* up to 256 elements */ } CFF_CMapStdRec; FT_DECLARE_CMAP_CLASS( cff_cmap_encoding_class_rec ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* unicode (synthetic) cmaps */ FT_DECLARE_CMAP_CLASS( cff_cmap_unicode_class_rec ) FT_END_HEADER #endif /* CFFCMAP_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffcmap.h
C++
gpl-3.0
2,181
/**************************************************************************** * * cffdrivr.c * * OpenType font driver 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/freetype.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/sfnt.h> #include <freetype/internal/psaux.h> #include <freetype/internal/ftpsprop.h> #include <freetype/internal/services/svcid.h> #include <freetype/internal/services/svpsinfo.h> #include <freetype/internal/services/svpostnm.h> #include <freetype/internal/services/svttcmap.h> #include <freetype/internal/services/svcfftl.h> #include "cffdrivr.h" #include "cffgload.h" #include "cffload.h" #include "cffcmap.h" #include "cffparse.h" #include "cffobjs.h" #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/internal/services/svmm.h> #include <freetype/internal/services/svmetric.h> #endif #include "cfferrs.h" #include <freetype/internal/services/svfntfmt.h> #include <freetype/internal/services/svgldict.h> #include <freetype/internal/services/svprop.h> #include <freetype/ftdriver.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 cffdriver /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /**** ****/ /**** ****/ /**** F A C E S ****/ /**** ****/ /**** ****/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * @Function: * cff_get_kerning * * @Description: * A driver method used to return the kerning vector between two * glyphs of the same face. * * @Input: * face :: * A handle to the source face object. * * left_glyph :: * The index of the left glyph in the kern pair. * * right_glyph :: * The index of the right glyph in the kern pair. * * @Output: * kerning :: * The kerning vector. This is in font units for * scalable formats, and in pixels for fixed-sizes * formats. * * @Return: * FreeType error code. 0 means success. * * @Note: * Only horizontal layouts (left-to-right & right-to-left) are * supported by this function. Other layouts, or more sophisticated * kernings, are out of scope of this method (the basic driver * interface is meant to be simple). * * They can be implemented by format-specific interfaces. */ FT_CALLBACK_DEF( FT_Error ) cff_get_kerning( FT_Face ttface, /* TT_Face */ FT_UInt left_glyph, FT_UInt right_glyph, FT_Vector* kerning ) { TT_Face face = (TT_Face)ttface; SFNT_Service sfnt = (SFNT_Service)face->sfnt; kerning->x = 0; kerning->y = 0; if ( sfnt ) kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph ); return FT_Err_Ok; } /************************************************************************** * * @Function: * cff_glyph_load * * @Description: * A driver method used to load a glyph within a given glyph slot. * * @Input: * slot :: * A handle to the target slot object where the glyph * will be loaded. * * size :: * A handle to the source face size at which the glyph * must be scaled, loaded, etc. * * glyph_index :: * The index of the glyph in the font file. * * load_flags :: * A flag indicating what to load for this glyph. The * FT_LOAD_??? constants can be used to control the * glyph loading process (e.g., whether the outline * should be scaled, whether to load bitmaps or not, * whether to hint the outline, etc). * * @Return: * FreeType error code. 0 means success. */ FT_CALLBACK_DEF( FT_Error ) cff_glyph_load( FT_GlyphSlot cffslot, /* CFF_GlyphSlot */ FT_Size cffsize, /* CFF_Size */ FT_UInt glyph_index, FT_Int32 load_flags ) { FT_Error error; CFF_GlyphSlot slot = (CFF_GlyphSlot)cffslot; CFF_Size size = (CFF_Size)cffsize; if ( !slot ) return FT_THROW( Invalid_Slot_Handle ); FT_TRACE1(( "cff_glyph_load: glyph index %d\n", glyph_index )); /* check whether we want a scaled outline or bitmap */ if ( !size ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; /* reset the size object if necessary */ if ( load_flags & FT_LOAD_NO_SCALE ) size = NULL; if ( size ) { /* these two objects must have the same parent */ if ( cffsize->face != cffslot->face ) return FT_THROW( Invalid_Face_Handle ); } /* now load the glyph outline if necessary */ error = cff_slot_load( slot, size, glyph_index, load_flags ); /* force drop-out mode to 2 - irrelevant now */ /* slot->outline.dropout_mode = 2; */ return error; } FT_CALLBACK_DEF( FT_Error ) cff_get_advances( FT_Face face, FT_UInt start, FT_UInt count, FT_Int32 flags, FT_Fixed* advances ) { FT_UInt nn; FT_Error error = FT_Err_Ok; FT_GlyphSlot slot = face->glyph; if ( FT_IS_SFNT( face ) ) { /* OpenType 1.7 mandates that the data from `hmtx' table be used; */ /* it is no longer necessary that those values are identical to */ /* the values in the `CFF' table */ TT_Face ttface = (TT_Face)face; FT_Short dummy; if ( flags & FT_LOAD_VERTICAL_LAYOUT ) { #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* no fast retrieval for blended MM fonts without VVAR table */ if ( ( FT_IS_NAMED_INSTANCE( face ) || FT_IS_VARIATION( face ) ) && !( ttface->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) ) return FT_THROW( Unimplemented_Feature ); #endif /* check whether we have data from the `vmtx' table at all; */ /* otherwise we extract the info from the CFF glyphstrings */ /* (instead of synthesizing a global value using the `OS/2' */ /* table) */ if ( !ttface->vertical_info ) goto Missing_Table; for ( nn = 0; nn < count; nn++ ) { FT_UShort ah; ( (SFNT_Service)ttface->sfnt )->get_metrics( ttface, 1, start + nn, &dummy, &ah ); FT_TRACE5(( " idx %d: advance height %d font unit%s\n", start + nn, ah, ah == 1 ? "" : "s" )); advances[nn] = ah; } } else { #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* no fast retrieval for blended MM fonts without HVAR table */ if ( ( FT_IS_NAMED_INSTANCE( face ) || FT_IS_VARIATION( face ) ) && !( ttface->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) ) return FT_THROW( Unimplemented_Feature ); #endif /* check whether we have data from the `hmtx' table at all */ if ( !ttface->horizontal.number_Of_HMetrics ) goto Missing_Table; for ( nn = 0; nn < count; nn++ ) { FT_UShort aw; ( (SFNT_Service)ttface->sfnt )->get_metrics( ttface, 0, start + nn, &dummy, &aw ); FT_TRACE5(( " idx %d: advance width %d font unit%s\n", start + nn, aw, aw == 1 ? "" : "s" )); advances[nn] = aw; } } return error; } Missing_Table: flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY; for ( nn = 0; nn < count; nn++ ) { error = cff_glyph_load( slot, face->size, start + nn, flags ); if ( error ) break; advances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) ? slot->linearVertAdvance : slot->linearHoriAdvance; } return error; } /* * GLYPH DICT SERVICE * */ static FT_Error cff_get_glyph_name( CFF_Face face, FT_UInt glyph_index, FT_Pointer buffer, FT_UInt buffer_max ) { CFF_Font font = (CFF_Font)face->extra.data; FT_String* gname; FT_UShort sid; FT_Error error; /* CFF2 table does not have glyph names; */ /* we need to use `post' table method */ if ( font->version_major == 2 ) { FT_Library library = FT_FACE_LIBRARY( face ); FT_Module sfnt_module = FT_Get_Module( library, "sfnt" ); FT_Service_GlyphDict service = (FT_Service_GlyphDict)ft_module_get_service( sfnt_module, FT_SERVICE_ID_GLYPH_DICT, 0 ); if ( service && service->get_name ) return service->get_name( FT_FACE( face ), glyph_index, buffer, buffer_max ); else { FT_ERROR(( "cff_get_glyph_name:" " cannot get glyph name from a CFF2 font\n" )); FT_ERROR(( " " " without the `psnames' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } } if ( !font->psnames ) { FT_ERROR(( "cff_get_glyph_name:" " cannot get glyph name from CFF & CEF fonts\n" )); FT_ERROR(( " " " without the `psnames' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } /* first, locate the sid in the charset table */ sid = font->charset.sids[glyph_index]; /* now, lookup the name itself */ gname = cff_index_get_sid_string( font, sid ); if ( gname ) FT_STRCPYN( buffer, gname, buffer_max ); error = FT_Err_Ok; Exit: return error; } static FT_UInt cff_get_name_index( CFF_Face face, const FT_String* glyph_name ) { CFF_Font cff; CFF_Charset charset; FT_Service_PsCMaps psnames; FT_String* name; FT_UShort sid; FT_UInt i; cff = (CFF_FontRec *)face->extra.data; charset = &cff->charset; /* CFF2 table does not have glyph names; */ /* we need to use `post' table method */ if ( cff->version_major == 2 ) { FT_Library library = FT_FACE_LIBRARY( face ); FT_Module sfnt_module = FT_Get_Module( library, "sfnt" ); FT_Service_GlyphDict service = (FT_Service_GlyphDict)ft_module_get_service( sfnt_module, FT_SERVICE_ID_GLYPH_DICT, 0 ); if ( service && service->name_index ) return service->name_index( FT_FACE( face ), glyph_name ); else { FT_ERROR(( "cff_get_name_index:" " cannot get glyph index from a CFF2 font\n" )); FT_ERROR(( " " " without the `psnames' module\n" )); return 0; } } FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); if ( !psnames ) return 0; for ( i = 0; i < cff->num_glyphs; i++ ) { sid = charset->sids[i]; if ( sid > 390 ) name = cff_index_get_string( cff, sid - 391 ); else name = (FT_String *)psnames->adobe_std_strings( sid ); if ( !name ) continue; if ( !ft_strcmp( glyph_name, name ) ) return i; } return 0; } FT_DEFINE_SERVICE_GLYPHDICTREC( cff_service_glyph_dict, (FT_GlyphDict_GetNameFunc) cff_get_glyph_name, /* get_name */ (FT_GlyphDict_NameIndexFunc)cff_get_name_index /* name_index */ ) /* * POSTSCRIPT INFO SERVICE * */ static FT_Int cff_ps_has_glyph_names( FT_Face face ) { return ( face->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) > 0; } static FT_Error cff_ps_get_font_info( CFF_Face face, PS_FontInfoRec* afont_info ) { CFF_Font cff = (CFF_Font)face->extra.data; FT_Error error = FT_Err_Ok; if ( cff && !cff->font_info ) { CFF_FontRecDict dict = &cff->top_font.font_dict; FT_Memory memory = face->root.memory; PS_FontInfoRec* font_info = NULL; if ( FT_QNEW( font_info ) ) goto Fail; font_info->version = cff_index_get_sid_string( cff, dict->version ); font_info->notice = cff_index_get_sid_string( cff, dict->notice ); font_info->full_name = cff_index_get_sid_string( cff, dict->full_name ); font_info->family_name = cff_index_get_sid_string( cff, dict->family_name ); font_info->weight = cff_index_get_sid_string( cff, dict->weight ); font_info->italic_angle = dict->italic_angle; font_info->is_fixed_pitch = dict->is_fixed_pitch; font_info->underline_position = (FT_Short)dict->underline_position; font_info->underline_thickness = (FT_UShort)dict->underline_thickness; cff->font_info = font_info; } if ( cff ) *afont_info = *cff->font_info; Fail: return error; } static FT_Error cff_ps_get_font_extra( CFF_Face face, PS_FontExtraRec* afont_extra ) { CFF_Font cff = (CFF_Font)face->extra.data; FT_Error error = FT_Err_Ok; if ( cff && !cff->font_extra ) { CFF_FontRecDict dict = &cff->top_font.font_dict; FT_Memory memory = face->root.memory; PS_FontExtraRec* font_extra = NULL; FT_String* embedded_postscript; if ( FT_QNEW( font_extra ) ) goto Fail; font_extra->fs_type = 0U; embedded_postscript = cff_index_get_sid_string( cff, dict->embedded_postscript ); if ( embedded_postscript ) { FT_String* start_fstype; FT_String* start_def; /* Identify the XYZ integer in `/FSType XYZ def' substring. */ if ( ( start_fstype = ft_strstr( embedded_postscript, "/FSType" ) ) != NULL && ( start_def = ft_strstr( start_fstype + sizeof ( "/FSType" ) - 1, "def" ) ) != NULL ) { FT_String* s; for ( s = start_fstype + sizeof ( "/FSType" ) - 1; s != start_def; s++ ) { if ( *s >= '0' && *s <= '9' ) { if ( font_extra->fs_type >= ( FT_USHORT_MAX - 9 ) / 10 ) { /* Overflow - ignore the FSType value. */ font_extra->fs_type = 0U; break; } font_extra->fs_type *= 10; font_extra->fs_type += (FT_UShort)( *s - '0' ); } else if ( *s != ' ' && *s != '\n' && *s != '\r' ) { /* Non-whitespace character between `/FSType' and next `def' */ /* - ignore the FSType value. */ font_extra->fs_type = 0U; break; } } } } cff->font_extra = font_extra; } if ( cff ) *afont_extra = *cff->font_extra; Fail: return error; } FT_DEFINE_SERVICE_PSINFOREC( cff_service_ps_info, (PS_GetFontInfoFunc) cff_ps_get_font_info, /* ps_get_font_info */ (PS_GetFontExtraFunc) cff_ps_get_font_extra, /* ps_get_font_extra */ (PS_HasGlyphNamesFunc) cff_ps_has_glyph_names, /* ps_has_glyph_names */ /* unsupported with CFF fonts */ (PS_GetFontPrivateFunc)NULL, /* ps_get_font_private */ /* not implemented */ (PS_GetFontValueFunc) NULL /* ps_get_font_value */ ) /* * POSTSCRIPT NAME SERVICE * */ static const char* cff_get_ps_name( CFF_Face face ) { CFF_Font cff = (CFF_Font)face->extra.data; SFNT_Service sfnt = (SFNT_Service)face->sfnt; /* following the OpenType specification 1.7, we return the name stored */ /* in the `name' table for a CFF wrapped into an SFNT container */ if ( FT_IS_SFNT( FT_FACE( face ) ) && sfnt ) { FT_Library library = FT_FACE_LIBRARY( face ); FT_Module sfnt_module = FT_Get_Module( library, "sfnt" ); FT_Service_PsFontName service = (FT_Service_PsFontName)ft_module_get_service( sfnt_module, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, 0 ); if ( service && service->get_ps_font_name ) return service->get_ps_font_name( FT_FACE( face ) ); } return (const char*)cff->font_name; } FT_DEFINE_SERVICE_PSFONTNAMEREC( cff_service_ps_name, (FT_PsName_GetFunc)cff_get_ps_name /* get_ps_font_name */ ) /* * TT CMAP INFO * * If the charmap is a synthetic Unicode encoding cmap or * a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO * service defined in SFNT module. * * Otherwise call the service function in the sfnt module. * */ static FT_Error cff_get_cmap_info( FT_CharMap charmap, TT_CMapInfo *cmap_info ) { FT_CMap cmap = FT_CMAP( charmap ); FT_Error error = FT_Err_Ok; FT_Face face = FT_CMAP_FACE( cmap ); FT_Library library = FT_FACE_LIBRARY( face ); if ( cmap->clazz != &cff_cmap_encoding_class_rec && cmap->clazz != &cff_cmap_unicode_class_rec ) { FT_Module sfnt = FT_Get_Module( library, "sfnt" ); FT_Service_TTCMaps service = (FT_Service_TTCMaps)ft_module_get_service( sfnt, FT_SERVICE_ID_TT_CMAP, 0 ); if ( service && service->get_cmap_info ) error = service->get_cmap_info( charmap, cmap_info ); } else error = FT_THROW( Invalid_CharMap_Format ); return error; } FT_DEFINE_SERVICE_TTCMAPSREC( cff_service_get_cmap_info, (TT_CMap_Info_GetFunc)cff_get_cmap_info /* get_cmap_info */ ) /* * CID INFO SERVICE * */ static FT_Error cff_get_ros( CFF_Face face, const char* *registry, const char* *ordering, FT_Int *supplement ) { FT_Error error = FT_Err_Ok; CFF_Font cff = (CFF_Font)face->extra.data; if ( cff ) { CFF_FontRecDict dict = &cff->top_font.font_dict; if ( dict->cid_registry == 0xFFFFU ) { error = FT_THROW( Invalid_Argument ); goto Fail; } if ( registry ) { if ( !cff->registry ) cff->registry = cff_index_get_sid_string( cff, dict->cid_registry ); *registry = cff->registry; } if ( ordering ) { if ( !cff->ordering ) cff->ordering = cff_index_get_sid_string( cff, dict->cid_ordering ); *ordering = cff->ordering; } /* * XXX: According to Adobe TechNote #5176, the supplement in CFF * can be a real number. We truncate it to fit public API * since freetype-2.3.6. */ if ( supplement ) { if ( dict->cid_supplement < FT_INT_MIN || dict->cid_supplement > FT_INT_MAX ) FT_TRACE1(( "cff_get_ros: too large supplement %ld is truncated\n", dict->cid_supplement )); *supplement = (FT_Int)dict->cid_supplement; } } Fail: return error; } static FT_Error cff_get_is_cid( CFF_Face face, FT_Bool *is_cid ) { FT_Error error = FT_Err_Ok; CFF_Font cff = (CFF_Font)face->extra.data; *is_cid = 0; if ( cff ) { CFF_FontRecDict dict = &cff->top_font.font_dict; if ( dict->cid_registry != 0xFFFFU ) *is_cid = 1; } return error; } static FT_Error cff_get_cid_from_glyph_index( CFF_Face face, FT_UInt glyph_index, FT_UInt *cid ) { FT_Error error = FT_Err_Ok; CFF_Font cff; cff = (CFF_Font)face->extra.data; if ( cff ) { FT_UInt c; CFF_FontRecDict dict = &cff->top_font.font_dict; if ( dict->cid_registry == 0xFFFFU ) { error = FT_THROW( Invalid_Argument ); goto Fail; } if ( glyph_index >= cff->num_glyphs ) { error = FT_THROW( Invalid_Argument ); goto Fail; } c = cff->charset.sids[glyph_index]; if ( cid ) *cid = c; } Fail: return error; } FT_DEFINE_SERVICE_CIDREC( cff_service_cid_info, (FT_CID_GetRegistryOrderingSupplementFunc) cff_get_ros, /* get_ros */ (FT_CID_GetIsInternallyCIDKeyedFunc) cff_get_is_cid, /* get_is_cid */ (FT_CID_GetCIDFromGlyphIndexFunc) cff_get_cid_from_glyph_index /* get_cid_from_glyph_index */ ) /* * PROPERTY SERVICE * */ FT_DEFINE_SERVICE_PROPERTIESREC( cff_service_properties, (FT_Properties_SetFunc)ps_property_set, /* set_property */ (FT_Properties_GetFunc)ps_property_get ) /* get_property */ #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* * MULTIPLE MASTER SERVICE * */ static FT_Error cff_set_mm_blend( CFF_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->set_mm_blend( FT_FACE( face ), num_coords, coords ); } static FT_Error cff_get_mm_blend( CFF_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->get_mm_blend( FT_FACE( face ), num_coords, coords ); } static FT_Error cff_set_mm_weightvector( CFF_Face face, FT_UInt len, FT_Fixed* weightvector ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->set_mm_weightvector( FT_FACE( face ), len, weightvector ); } static FT_Error cff_get_mm_weightvector( CFF_Face face, FT_UInt* len, FT_Fixed* weightvector ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->get_mm_weightvector( FT_FACE( face ), len, weightvector ); } static FT_Error cff_get_mm_var( CFF_Face face, FT_MM_Var* *master ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->get_mm_var( FT_FACE( face ), master ); } static FT_Error cff_set_var_design( CFF_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->set_var_design( FT_FACE( face ), num_coords, coords ); } static FT_Error cff_get_var_design( CFF_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->get_var_design( FT_FACE( face ), num_coords, coords ); } static FT_Error cff_set_instance( CFF_Face face, FT_UInt instance_index ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->set_instance( FT_FACE( face ), instance_index ); } FT_DEFINE_SERVICE_MULTIMASTERSREC( cff_service_multi_masters, (FT_Get_MM_Func) NULL, /* get_mm */ (FT_Set_MM_Design_Func) NULL, /* set_mm_design */ (FT_Set_MM_Blend_Func) cff_set_mm_blend, /* set_mm_blend */ (FT_Get_MM_Blend_Func) cff_get_mm_blend, /* get_mm_blend */ (FT_Get_MM_Var_Func) cff_get_mm_var, /* get_mm_var */ (FT_Set_Var_Design_Func) cff_set_var_design, /* set_var_design */ (FT_Get_Var_Design_Func) cff_get_var_design, /* get_var_design */ (FT_Set_Instance_Func) cff_set_instance, /* set_instance */ (FT_Set_MM_WeightVector_Func)cff_set_mm_weightvector, /* set_mm_weightvector */ (FT_Get_MM_WeightVector_Func)cff_get_mm_weightvector, /* get_mm_weightvector */ (FT_Get_Var_Blend_Func) cff_get_var_blend, /* get_var_blend */ (FT_Done_Blend_Func) cff_done_blend /* done_blend */ ) /* * METRICS VARIATIONS SERVICE * */ static FT_Error cff_hadvance_adjust( CFF_Face face, FT_UInt gindex, FT_Int *avalue ) { FT_Service_MetricsVariations var = (FT_Service_MetricsVariations)face->var; return var->hadvance_adjust( FT_FACE( face ), gindex, avalue ); } static void cff_metrics_adjust( CFF_Face face ) { FT_Service_MetricsVariations var = (FT_Service_MetricsVariations)face->var; var->metrics_adjust( FT_FACE( face ) ); } FT_DEFINE_SERVICE_METRICSVARIATIONSREC( cff_service_metrics_variations, (FT_HAdvance_Adjust_Func)cff_hadvance_adjust, /* hadvance_adjust */ (FT_LSB_Adjust_Func) NULL, /* lsb_adjust */ (FT_RSB_Adjust_Func) NULL, /* rsb_adjust */ (FT_VAdvance_Adjust_Func)NULL, /* vadvance_adjust */ (FT_TSB_Adjust_Func) NULL, /* tsb_adjust */ (FT_BSB_Adjust_Func) NULL, /* bsb_adjust */ (FT_VOrg_Adjust_Func) NULL, /* vorg_adjust */ (FT_Metrics_Adjust_Func) cff_metrics_adjust /* metrics_adjust */ ) #endif /* * CFFLOAD SERVICE * */ FT_DEFINE_SERVICE_CFFLOADREC( cff_service_cff_load, (FT_Get_Standard_Encoding_Func)cff_get_standard_encoding, (FT_Load_Private_Dict_Func) cff_load_private_dict, (FT_FD_Select_Get_Func) cff_fd_select_get, (FT_Blend_Check_Vector_Func) cff_blend_check_vector, (FT_Blend_Build_Vector_Func) cff_blend_build_vector ) /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /**** ****/ /**** ****/ /**** D R I V E R I N T E R F A C E ****/ /**** ****/ /**** ****/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ #if !defined FT_CONFIG_OPTION_NO_GLYPH_NAMES && \ defined TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_DEFINE_SERVICEDESCREC10( cff_services, FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CFF, FT_SERVICE_ID_MULTI_MASTERS, &cff_service_multi_masters, FT_SERVICE_ID_METRICS_VARIATIONS, &cff_service_metrics_variations, FT_SERVICE_ID_POSTSCRIPT_INFO, &cff_service_ps_info, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cff_service_ps_name, FT_SERVICE_ID_GLYPH_DICT, &cff_service_glyph_dict, FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info, FT_SERVICE_ID_CID, &cff_service_cid_info, FT_SERVICE_ID_PROPERTIES, &cff_service_properties, FT_SERVICE_ID_CFF_LOAD, &cff_service_cff_load ) #elif !defined FT_CONFIG_OPTION_NO_GLYPH_NAMES FT_DEFINE_SERVICEDESCREC8( cff_services, FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CFF, FT_SERVICE_ID_POSTSCRIPT_INFO, &cff_service_ps_info, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cff_service_ps_name, FT_SERVICE_ID_GLYPH_DICT, &cff_service_glyph_dict, FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info, FT_SERVICE_ID_CID, &cff_service_cid_info, FT_SERVICE_ID_PROPERTIES, &cff_service_properties, FT_SERVICE_ID_CFF_LOAD, &cff_service_cff_load ) #elif defined TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_DEFINE_SERVICEDESCREC9( cff_services, FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CFF, FT_SERVICE_ID_MULTI_MASTERS, &cff_service_multi_masters, FT_SERVICE_ID_METRICS_VARIATIONS, &cff_service_metrics_var, FT_SERVICE_ID_POSTSCRIPT_INFO, &cff_service_ps_info, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cff_service_ps_name, FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info, FT_SERVICE_ID_CID, &cff_service_cid_info, FT_SERVICE_ID_PROPERTIES, &cff_service_properties, FT_SERVICE_ID_CFF_LOAD, &cff_service_cff_load ) #else FT_DEFINE_SERVICEDESCREC7( cff_services, FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CFF, FT_SERVICE_ID_POSTSCRIPT_INFO, &cff_service_ps_info, FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cff_service_ps_name, FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info, FT_SERVICE_ID_CID, &cff_service_cid_info, FT_SERVICE_ID_PROPERTIES, &cff_service_properties, FT_SERVICE_ID_CFF_LOAD, &cff_service_cff_load ) #endif FT_CALLBACK_DEF( FT_Module_Interface ) cff_get_interface( FT_Module driver, /* CFF_Driver */ const char* module_interface ) { FT_Library library; FT_Module sfnt; FT_Module_Interface result; result = ft_service_list_lookup( cff_services, module_interface ); if ( result ) return result; /* `driver' is not yet evaluated */ if ( !driver ) return NULL; library = driver->library; if ( !library ) return NULL; /* we pass our request to the `sfnt' module */ sfnt = FT_Get_Module( library, "sfnt" ); return sfnt ? sfnt->clazz->get_interface( sfnt, module_interface ) : 0; } /* The FT_DriverInterface structure is defined in ftdriver.h. */ #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS #define CFF_SIZE_SELECT cff_size_select #else #define CFF_SIZE_SELECT 0 #endif FT_DEFINE_DRIVER( cff_driver_class, FT_MODULE_FONT_DRIVER | FT_MODULE_DRIVER_SCALABLE | FT_MODULE_DRIVER_HAS_HINTER | FT_MODULE_DRIVER_HINTS_LIGHTLY, sizeof ( PS_DriverRec ), "cff", 0x10000L, 0x20000L, NULL, /* module-specific interface */ cff_driver_init, /* FT_Module_Constructor module_init */ cff_driver_done, /* FT_Module_Destructor module_done */ cff_get_interface, /* FT_Module_Requester get_interface */ sizeof ( TT_FaceRec ), sizeof ( CFF_SizeRec ), sizeof ( CFF_GlyphSlotRec ), cff_face_init, /* FT_Face_InitFunc init_face */ cff_face_done, /* FT_Face_DoneFunc done_face */ cff_size_init, /* FT_Size_InitFunc init_size */ cff_size_done, /* FT_Size_DoneFunc done_size */ cff_slot_init, /* FT_Slot_InitFunc init_slot */ cff_slot_done, /* FT_Slot_DoneFunc done_slot */ cff_glyph_load, /* FT_Slot_LoadFunc load_glyph */ cff_get_kerning, /* FT_Face_GetKerningFunc get_kerning */ NULL, /* FT_Face_AttachFunc attach_file */ cff_get_advances, /* FT_Face_GetAdvancesFunc get_advances */ cff_size_request, /* FT_Size_RequestFunc request_size */ CFF_SIZE_SELECT /* FT_Size_SelectFunc select_size */ ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffdrivr.c
C++
gpl-3.0
34,862
/**************************************************************************** * * cffdrivr.h * * High-level OpenType 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 CFFDRIVER_H_ #define CFFDRIVER_H_ #include <freetype/internal/ftdrv.h> FT_BEGIN_HEADER FT_DECLARE_DRIVER( cff_driver_class ) FT_END_HEADER #endif /* CFFDRIVER_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffdrivr.h
C++
gpl-3.0
752
/**************************************************************************** * * cfferrs.h * * CFF 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 CFF error enumeration constants. * */ #ifndef CFFERRS_H_ #define CFFERRS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX CFF_Err_ #define FT_ERR_BASE FT_Mod_Err_CFF #include <freetype/fterrors.h> #endif /* CFFERRS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cfferrs.h
C++
gpl-3.0
959
/**************************************************************************** * * cffgload.c * * OpenType Glyph Loader (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/internal/sfnt.h> #include <freetype/internal/ftcalc.h> #include <freetype/internal/psaux.h> #include <freetype/ftoutln.h> #include <freetype/ftdriver.h> #include "cffload.h" #include "cffgload.h" #include "cfferrs.h" #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #define IS_DEFAULT_INSTANCE( _face ) \ ( !( FT_IS_NAMED_INSTANCE( _face ) || \ FT_IS_VARIATION( _face ) ) ) #else #define IS_DEFAULT_INSTANCE( _face ) 1 #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 cffgload FT_LOCAL_DEF( FT_Error ) cff_get_glyph_data( TT_Face face, FT_UInt glyph_index, FT_Byte** pointer, FT_ULong* length ) { #ifdef FT_CONFIG_OPTION_INCREMENTAL /* For incremental fonts get the character data using the */ /* callback function. */ if ( face->root.internal->incremental_interface ) { FT_Data data; FT_Error error = face->root.internal->incremental_interface->funcs->get_glyph_data( face->root.internal->incremental_interface->object, glyph_index, &data ); *pointer = (FT_Byte*)data.pointer; *length = data.length; return error; } else #endif /* FT_CONFIG_OPTION_INCREMENTAL */ { CFF_Font cff = (CFF_Font)(face->extra.data); return cff_index_access_element( &cff->charstrings_index, glyph_index, pointer, length ); } } FT_LOCAL_DEF( void ) cff_free_glyph_data( TT_Face face, FT_Byte** pointer, FT_ULong length ) { #ifndef FT_CONFIG_OPTION_INCREMENTAL FT_UNUSED( length ); #endif #ifdef FT_CONFIG_OPTION_INCREMENTAL /* For incremental fonts get the character data using the */ /* callback function. */ if ( face->root.internal->incremental_interface ) { FT_Data data; data.pointer = *pointer; data.length = (FT_UInt)length; face->root.internal->incremental_interface->funcs->free_glyph_data( face->root.internal->incremental_interface->object, &data ); } else #endif /* FT_CONFIG_OPTION_INCREMENTAL */ { CFF_Font cff = (CFF_Font)(face->extra.data); cff_index_forget_element( &cff->charstrings_index, pointer ); } } /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********** *********/ /********** *********/ /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ /********** *********/ /********** The following code is in charge of computing *********/ /********** the maximum advance width of the font. It *********/ /********** quickly processes each glyph charstring to *********/ /********** extract the value from either a `sbw' or `seac' *********/ /********** operator. *********/ /********** *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ #if 0 /* unused until we support pure CFF fonts */ FT_LOCAL_DEF( FT_Error ) cff_compute_max_advance( TT_Face face, FT_Int* max_advance ) { FT_Error error = FT_Err_Ok; CFF_Decoder decoder; FT_Int glyph_index; CFF_Font cff = (CFF_Font)face->other; PSAux_Service psaux = (PSAux_Service)face->psaux; const CFF_Decoder_Funcs decoder_funcs = psaux->cff_decoder_funcs; *max_advance = 0; /* Initialize load decoder */ decoder_funcs->init( &decoder, face, 0, 0, 0, 0, 0, 0 ); decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; /* For each glyph, parse the glyph charstring and extract */ /* the advance width. */ for ( glyph_index = 0; glyph_index < face->root.num_glyphs; glyph_index++ ) { FT_Byte* charstring; FT_ULong charstring_len; /* now get load the unscaled outline */ error = cff_get_glyph_data( face, glyph_index, &charstring, &charstring_len ); if ( !error ) { error = decoder_funcs->prepare( &decoder, size, glyph_index ); if ( !error ) error = decoder_funcs->parse_charstrings_old( &decoder, charstring, charstring_len, 0 ); cff_free_glyph_data( face, &charstring, &charstring_len ); } /* ignore the error if one has occurred -- skip to next glyph */ error = FT_Err_Ok; } *max_advance = decoder.builder.advance.x; return FT_Err_Ok; } #endif /* 0 */ FT_LOCAL_DEF( FT_Error ) cff_slot_load( CFF_GlyphSlot glyph, CFF_Size size, FT_UInt glyph_index, FT_Int32 load_flags ) { FT_Error error; CFF_Decoder decoder; PS_Decoder psdecoder; TT_Face face = (TT_Face)glyph->root.face; FT_Bool hinting, scaled, force_scaling; CFF_Font cff = (CFF_Font)face->extra.data; PSAux_Service psaux = (PSAux_Service)face->psaux; const CFF_Decoder_Funcs decoder_funcs = psaux->cff_decoder_funcs; FT_Matrix font_matrix; FT_Vector font_offset; force_scaling = FALSE; /* in a CID-keyed font, consider `glyph_index' as a CID and map */ /* it immediately to the real glyph_index -- if it isn't a */ /* subsetted font, glyph_indices and CIDs are identical, though */ if ( cff->top_font.font_dict.cid_registry != 0xFFFFU && cff->charset.cids ) { /* don't handle CID 0 (.notdef) which is directly mapped to GID 0 */ if ( glyph_index != 0 ) { glyph_index = cff_charset_cid_to_gindex( &cff->charset, glyph_index ); if ( glyph_index == 0 ) return FT_THROW( Invalid_Argument ); } } else if ( glyph_index >= cff->num_glyphs ) return FT_THROW( Invalid_Argument ); if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; glyph->x_scale = 0x10000L; glyph->y_scale = 0x10000L; if ( size ) { glyph->x_scale = size->root.metrics.x_scale; glyph->y_scale = size->root.metrics.y_scale; } #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS /* try to load embedded bitmap if any */ /* */ /* XXX: The convention should be emphasized in */ /* the documents because it can be confusing. */ if ( size ) { CFF_Face cff_face = (CFF_Face)size->root.face; SFNT_Service sfnt = (SFNT_Service)cff_face->sfnt; FT_Stream stream = cff_face->root.stream; if ( size->strike_index != 0xFFFFFFFFUL && ( load_flags & FT_LOAD_NO_BITMAP ) == 0 && IS_DEFAULT_INSTANCE( size->root.face ) ) { TT_SBit_MetricsRec metrics; error = sfnt->load_sbit_image( face, size->strike_index, glyph_index, (FT_UInt)load_flags, stream, &glyph->root.bitmap, &metrics ); if ( !error ) { FT_Bool has_vertical_info; FT_UShort advance; FT_Short dummy; glyph->root.outline.n_points = 0; glyph->root.outline.n_contours = 0; glyph->root.metrics.width = (FT_Pos)metrics.width * 64; glyph->root.metrics.height = (FT_Pos)metrics.height * 64; glyph->root.metrics.horiBearingX = (FT_Pos)metrics.horiBearingX * 64; glyph->root.metrics.horiBearingY = (FT_Pos)metrics.horiBearingY * 64; glyph->root.metrics.horiAdvance = (FT_Pos)metrics.horiAdvance * 64; glyph->root.metrics.vertBearingX = (FT_Pos)metrics.vertBearingX * 64; glyph->root.metrics.vertBearingY = (FT_Pos)metrics.vertBearingY * 64; glyph->root.metrics.vertAdvance = (FT_Pos)metrics.vertAdvance * 64; glyph->root.format = FT_GLYPH_FORMAT_BITMAP; if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) { glyph->root.bitmap_left = metrics.vertBearingX; glyph->root.bitmap_top = metrics.vertBearingY; } else { glyph->root.bitmap_left = metrics.horiBearingX; glyph->root.bitmap_top = metrics.horiBearingY; } /* compute linear advance widths */ (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 0, glyph_index, &dummy, &advance ); glyph->root.linearHoriAdvance = advance; has_vertical_info = FT_BOOL( face->vertical_info && face->vertical.number_Of_VMetrics > 0 ); /* get the vertical metrics from the vmtx table if we have one */ if ( has_vertical_info ) { (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1, glyph_index, &dummy, &advance ); glyph->root.linearVertAdvance = advance; } else { /* make up vertical ones */ if ( face->os2.version != 0xFFFFU ) glyph->root.linearVertAdvance = (FT_Pos) ( face->os2.sTypoAscender - face->os2.sTypoDescender ); else glyph->root.linearVertAdvance = (FT_Pos) ( face->horizontal.Ascender - face->horizontal.Descender ); } return error; } } } #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /* return immediately if we only want the embedded bitmaps */ if ( load_flags & FT_LOAD_SBITS_ONLY ) return FT_THROW( Invalid_Argument ); #ifdef FT_CONFIG_OPTION_SVG /* check for OT-SVG */ if ( ( load_flags & FT_LOAD_COLOR ) && ( (TT_Face)glyph->root.face )->svg ) { /* * We load the SVG document and try to grab the advances from the * table. For the bearings we rely on the presetting hook to do that. */ FT_Short dummy; FT_UShort advanceX; FT_UShort advanceY; SFNT_Service sfnt; if ( size->root.metrics.x_ppem < 1 || size->root.metrics.y_ppem < 1 ) { error = FT_THROW( Invalid_Size_Handle ); return error; } FT_TRACE3(( "Trying to load SVG glyph\n" )); sfnt = (SFNT_Service)((TT_Face)glyph->root.face)->sfnt; error = sfnt->load_svg_doc( (FT_GlyphSlot)glyph, glyph_index ); if ( !error ) { FT_TRACE3(( "Successfully loaded SVG glyph\n" )); glyph->root.format = FT_GLYPH_FORMAT_SVG; /* * If horizontal or vertical advances are not present in the table, * this is a problem with the font since the standard requires them. * However, we are graceful and calculate the values by ourselves * for the vertical case. */ sfnt->get_metrics( face, FALSE, glyph_index, &dummy, &advanceX ); sfnt->get_metrics( face, TRUE, glyph_index, &dummy, &advanceY ); advanceX = (FT_UShort)FT_MulDiv( advanceX, glyph->root.face->size->metrics.x_ppem, glyph->root.face->units_per_EM ); advanceY = (FT_UShort)FT_MulDiv( advanceY, glyph->root.face->size->metrics.y_ppem, glyph->root.face->units_per_EM ); glyph->root.metrics.horiAdvance = advanceX << 6; glyph->root.metrics.vertAdvance = advanceY << 6; return error; } FT_TRACE3(( "Failed to load SVG glyph\n" )); } #endif /* FT_CONFIG_OPTION_SVG */ /* if we have a CID subfont, use its matrix (which has already */ /* been multiplied with the root matrix) */ /* this scaling is only relevant if the PS hinter isn't active */ if ( cff->num_subfonts ) { FT_Long top_upm, sub_upm; FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, glyph_index ); if ( fd_index >= cff->num_subfonts ) fd_index = (FT_Byte)( cff->num_subfonts - 1 ); top_upm = (FT_Long)cff->top_font.font_dict.units_per_em; sub_upm = (FT_Long)cff->subfonts[fd_index]->font_dict.units_per_em; font_matrix = cff->subfonts[fd_index]->font_dict.font_matrix; font_offset = cff->subfonts[fd_index]->font_dict.font_offset; if ( top_upm != sub_upm ) { glyph->x_scale = FT_MulDiv( glyph->x_scale, top_upm, sub_upm ); glyph->y_scale = FT_MulDiv( glyph->y_scale, top_upm, sub_upm ); force_scaling = TRUE; } } else { font_matrix = cff->top_font.font_dict.font_matrix; font_offset = cff->top_font.font_dict.font_offset; } glyph->root.outline.n_points = 0; glyph->root.outline.n_contours = 0; /* top-level code ensures that FT_LOAD_NO_HINTING is set */ /* if FT_LOAD_NO_SCALE is active */ hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_HINTING ) == 0 ); scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ); glyph->hint = hinting; glyph->scaled = scaled; glyph->root.format = FT_GLYPH_FORMAT_OUTLINE; /* by default */ { #ifdef CFF_CONFIG_OPTION_OLD_ENGINE PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face ); #endif FT_Byte* charstring; FT_ULong charstring_len; decoder_funcs->init( &decoder, face, size, glyph, hinting, FT_LOAD_TARGET_MODE( load_flags ), cff_get_glyph_data, cff_free_glyph_data ); /* this is for pure CFFs */ if ( load_flags & FT_LOAD_ADVANCE_ONLY ) decoder.width_only = TRUE; decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE ); /* now load the unscaled outline */ error = cff_get_glyph_data( face, glyph_index, &charstring, &charstring_len ); if ( error ) goto Glyph_Build_Finished; error = decoder_funcs->prepare( &decoder, size, glyph_index ); if ( error ) goto Glyph_Build_Finished; #ifdef CFF_CONFIG_OPTION_OLD_ENGINE /* choose which CFF renderer to use */ if ( driver->hinting_engine == FT_HINTING_FREETYPE ) error = decoder_funcs->parse_charstrings_old( &decoder, charstring, charstring_len, 0 ); else #endif { psaux->ps_decoder_init( &psdecoder, &decoder, FALSE ); error = decoder_funcs->parse_charstrings( &psdecoder, charstring, charstring_len ); /* Adobe's engine uses 16.16 numbers everywhere; */ /* as a consequence, glyphs larger than 2000ppem get rejected */ if ( FT_ERR_EQ( error, Glyph_Too_Big ) ) { /* this time, we retry unhinted and scale up the glyph later on */ /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */ /* 0x400 for both `x_scale' and `y_scale' in this case) */ hinting = FALSE; force_scaling = TRUE; glyph->hint = hinting; error = decoder_funcs->parse_charstrings( &psdecoder, charstring, charstring_len ); } } cff_free_glyph_data( face, &charstring, charstring_len ); if ( error ) goto Glyph_Build_Finished; #ifdef FT_CONFIG_OPTION_INCREMENTAL /* Control data and length may not be available for incremental */ /* fonts. */ if ( face->root.internal->incremental_interface ) { glyph->root.control_data = NULL; glyph->root.control_len = 0; } else #endif /* FT_CONFIG_OPTION_INCREMENTAL */ /* We set control_data and control_len if charstrings is loaded. */ /* See how charstring loads at cff_index_access_element() in */ /* cffload.c. */ { CFF_Index csindex = &cff->charstrings_index; if ( csindex->offsets ) { glyph->root.control_data = csindex->bytes + csindex->offsets[glyph_index] - 1; glyph->root.control_len = (FT_Long)charstring_len; } } Glyph_Build_Finished: /* save new glyph tables, if no error */ if ( !error ) decoder.builder.funcs.done( &decoder.builder ); /* XXX: anything to do for broken glyph entry? */ } #ifdef FT_CONFIG_OPTION_INCREMENTAL /* Incremental fonts can optionally override the metrics. */ if ( !error && face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs->get_glyph_metrics ) { FT_Incremental_MetricsRec metrics; metrics.bearing_x = decoder.builder.left_bearing.x; metrics.bearing_y = 0; metrics.advance = decoder.builder.advance.x; metrics.advance_v = decoder.builder.advance.y; error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( face->root.internal->incremental_interface->object, glyph_index, FALSE, &metrics ); decoder.builder.left_bearing.x = metrics.bearing_x; decoder.builder.advance.x = metrics.advance; decoder.builder.advance.y = metrics.advance_v; } #endif /* FT_CONFIG_OPTION_INCREMENTAL */ if ( !error ) { /* Now, set the metrics -- this is rather simple, as */ /* the left side bearing is the xMin, and the top side */ /* bearing the yMax. */ /* For composite glyphs, return only left side bearing and */ /* advance width. */ if ( load_flags & FT_LOAD_NO_RECURSE ) { FT_Slot_Internal internal = glyph->root.internal; glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x; glyph->root.metrics.horiAdvance = decoder.glyph_width; internal->glyph_matrix = font_matrix; internal->glyph_delta = font_offset; internal->glyph_transformed = 1; } else { FT_BBox cbox; FT_Glyph_Metrics* metrics = &glyph->root.metrics; FT_Bool has_vertical_info; if ( face->horizontal.number_Of_HMetrics ) { FT_Short horiBearingX = 0; FT_UShort horiAdvance = 0; ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, glyph_index, &horiBearingX, &horiAdvance ); metrics->horiAdvance = horiAdvance; metrics->horiBearingX = horiBearingX; glyph->root.linearHoriAdvance = horiAdvance; } else { /* copy the _unscaled_ advance width */ metrics->horiAdvance = decoder.glyph_width; glyph->root.linearHoriAdvance = decoder.glyph_width; } glyph->root.internal->glyph_transformed = 0; has_vertical_info = FT_BOOL( face->vertical_info && face->vertical.number_Of_VMetrics > 0 ); /* get the vertical metrics from the vmtx table if we have one */ if ( has_vertical_info ) { FT_Short vertBearingY = 0; FT_UShort vertAdvance = 0; ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, glyph_index, &vertBearingY, &vertAdvance ); metrics->vertBearingY = vertBearingY; metrics->vertAdvance = vertAdvance; } else { /* make up vertical ones */ if ( face->os2.version != 0xFFFFU ) metrics->vertAdvance = (FT_Pos)( face->os2.sTypoAscender - face->os2.sTypoDescender ); else metrics->vertAdvance = (FT_Pos)( face->horizontal.Ascender - face->horizontal.Descender ); } glyph->root.linearVertAdvance = metrics->vertAdvance; glyph->root.format = FT_GLYPH_FORMAT_OUTLINE; glyph->root.outline.flags = 0; if ( size && size->root.metrics.y_ppem < 24 ) glyph->root.outline.flags |= FT_OUTLINE_HIGH_PRECISION; glyph->root.outline.flags |= FT_OUTLINE_REVERSE_FILL; /* apply the font matrix, if any */ if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L || font_matrix.xy != 0 || font_matrix.yx != 0 ) { FT_Outline_Transform( &glyph->root.outline, &font_matrix ); metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, font_matrix.xx ); metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, font_matrix.yy ); } if ( font_offset.x || font_offset.y ) { FT_Outline_Translate( &glyph->root.outline, font_offset.x, font_offset.y ); metrics->horiAdvance += font_offset.x; metrics->vertAdvance += font_offset.y; } if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || force_scaling ) { /* scale the outline and the metrics */ FT_Int n; FT_Outline* cur = &glyph->root.outline; FT_Vector* vec = cur->points; FT_Fixed x_scale = glyph->x_scale; FT_Fixed y_scale = glyph->y_scale; /* First of all, scale the points */ if ( !hinting || !decoder.builder.hints_funcs ) for ( n = cur->n_points; n > 0; n--, vec++ ) { vec->x = FT_MulFix( vec->x, x_scale ); vec->y = FT_MulFix( vec->y, y_scale ); } /* Then scale the metrics */ metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale ); metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale ); } /* compute the other metrics */ FT_Outline_Get_CBox( &glyph->root.outline, &cbox ); metrics->width = cbox.xMax - cbox.xMin; metrics->height = cbox.yMax - cbox.yMin; metrics->horiBearingX = cbox.xMin; metrics->horiBearingY = cbox.yMax; if ( has_vertical_info ) { metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2; metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, glyph->y_scale ); } else { if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) ft_synthesize_vertical_metrics( metrics, metrics->vertAdvance ); } } } return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffgload.c
C++
gpl-3.0
26,382
/**************************************************************************** * * cffgload.h * * OpenType Glyph Loader (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 CFFGLOAD_H_ #define CFFGLOAD_H_ #include <freetype/freetype.h> #include <freetype/internal/cffotypes.h> FT_BEGIN_HEADER FT_LOCAL( FT_Error ) cff_get_glyph_data( TT_Face face, FT_UInt glyph_index, FT_Byte** pointer, FT_ULong* length ); FT_LOCAL( void ) cff_free_glyph_data( TT_Face face, FT_Byte** pointer, FT_ULong length ); #if 0 /* unused until we support pure CFF fonts */ /* Compute the maximum advance width of a font through quick parsing */ FT_LOCAL( FT_Error ) cff_compute_max_advance( TT_Face face, FT_Int* max_advance ); #endif /* 0 */ FT_LOCAL( FT_Error ) cff_slot_load( CFF_GlyphSlot glyph, CFF_Size size, FT_UInt glyph_index, FT_Int32 load_flags ); FT_END_HEADER #endif /* CFFGLOAD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffgload.h
C++
gpl-3.0
1,523
/**************************************************************************** * * cffload.c * * OpenType and CFF data/program tables loader (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/ftstream.h> #include <freetype/tttags.h> #include <freetype/t1tables.h> #include <freetype/internal/psaux.h> #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/ftmm.h> #include <freetype/internal/services/svmm.h> #endif #include "cffload.h" #include "cffparse.h" #include "cfferrs.h" #define FT_FIXED_ONE ( (FT_Fixed)0x10000 ) #if 1 static const FT_UShort cff_isoadobe_charset[229] = { 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, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228 }; static const FT_UShort cff_expert_charset[166] = { 0, 1, 229, 230, 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, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 109, 110, 267, 268, 269, 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, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 158, 155, 163, 319, 320, 321, 322, 323, 324, 325, 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 }; static const FT_UShort cff_expertsubset_charset[87] = { 0, 1, 231, 232, 235, 236, 237, 238, 13, 14, 15, 99, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 27, 28, 249, 250, 251, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 109, 110, 267, 268, 269, 270, 272, 300, 301, 302, 305, 314, 315, 158, 155, 163, 320, 321, 322, 323, 324, 325, 326, 150, 164, 169, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346 }; static const FT_UShort cff_standard_encoding[256] = { 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 }; static const FT_UShort cff_expert_encoding[256] = { 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, 312, 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 /* 1 */ FT_LOCAL_DEF( FT_UShort ) cff_get_standard_encoding( FT_UInt charcode ) { return (FT_UShort)( charcode < 256 ? cff_standard_encoding[charcode] : 0 ); } /************************************************************************** * * 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 cffload /* read an offset from the index's stream current position */ static FT_ULong cff_index_read_offset( CFF_Index idx, FT_Error *errorp ) { FT_Error error; FT_Stream stream = idx->stream; FT_Byte tmp[4]; FT_ULong result = 0; if ( !FT_STREAM_READ( tmp, idx->off_size ) ) { FT_Int nn; for ( nn = 0; nn < idx->off_size; nn++ ) result = ( result << 8 ) | tmp[nn]; } *errorp = error; return result; } static FT_Error cff_index_init( CFF_Index idx, FT_Stream stream, FT_Bool load, FT_Bool cff2 ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt count; FT_ZERO( idx ); idx->stream = stream; idx->start = FT_STREAM_POS(); if ( cff2 ) { if ( FT_READ_ULONG( count ) ) goto Exit; idx->hdr_size = 5; } else { if ( FT_READ_USHORT( count ) ) goto Exit; idx->hdr_size = 3; } if ( count > 0 ) { FT_Byte offsize; FT_ULong size; /* there is at least one element; read the offset size, */ /* then access the offset table to compute the index's total size */ if ( FT_READ_BYTE( offsize ) ) goto Exit; if ( offsize < 1 || offsize > 4 ) { error = FT_THROW( Invalid_Table ); goto Exit; } idx->count = count; idx->off_size = offsize; size = (FT_ULong)( count + 1 ) * offsize; idx->data_offset = idx->start + idx->hdr_size + size; if ( FT_STREAM_SKIP( size - offsize ) ) goto Exit; size = cff_index_read_offset( idx, &error ); if ( error ) goto Exit; if ( size == 0 ) { error = FT_THROW( Invalid_Table ); goto Exit; } idx->data_size = --size; if ( load ) { /* load the data */ if ( FT_FRAME_EXTRACT( size, idx->bytes ) ) goto Exit; } else { /* skip the data */ if ( FT_STREAM_SKIP( size ) ) goto Exit; } } Exit: if ( error ) FT_FREE( idx->offsets ); return error; } static void cff_index_done( CFF_Index idx ) { if ( idx->stream ) { FT_Stream stream = idx->stream; FT_Memory memory = stream->memory; if ( idx->bytes ) FT_FRAME_RELEASE( idx->bytes ); FT_FREE( idx->offsets ); FT_ZERO( idx ); } } static FT_Error cff_index_load_offsets( CFF_Index idx ) { FT_Error error = FT_Err_Ok; FT_Stream stream = idx->stream; FT_Memory memory = stream->memory; if ( idx->count > 0 && !idx->offsets ) { FT_Byte offsize = idx->off_size; FT_ULong data_size; FT_Byte* p; FT_Byte* p_end; FT_ULong* poff; data_size = (FT_ULong)( idx->count + 1 ) * offsize; if ( FT_QNEW_ARRAY( idx->offsets, idx->count + 1 ) || FT_STREAM_SEEK( idx->start + idx->hdr_size ) || FT_FRAME_ENTER( data_size ) ) goto Exit; poff = idx->offsets; p = (FT_Byte*)stream->cursor; p_end = p + data_size; switch ( offsize ) { case 1: for ( ; p < p_end; p++, poff++ ) poff[0] = p[0]; break; case 2: for ( ; p < p_end; p += 2, poff++ ) poff[0] = FT_PEEK_USHORT( p ); break; case 3: for ( ; p < p_end; p += 3, poff++ ) poff[0] = FT_PEEK_UOFF3( p ); break; default: for ( ; p < p_end; p += 4, poff++ ) poff[0] = FT_PEEK_ULONG( p ); } FT_FRAME_EXIT(); } Exit: if ( error ) FT_FREE( idx->offsets ); return error; } /* Allocate a table containing pointers to an index's elements. */ /* The `pool' argument makes this function convert the index */ /* entries to C-style strings (this is, null-terminated). */ static FT_Error cff_index_get_pointers( CFF_Index idx, FT_Byte*** table, FT_Byte** pool, FT_ULong* pool_size ) { FT_Error error = FT_Err_Ok; FT_Memory memory = idx->stream->memory; FT_Byte** tbl = NULL; FT_Byte* new_bytes = NULL; FT_ULong new_size; *table = NULL; if ( !idx->offsets ) { error = cff_index_load_offsets( idx ); if ( error ) goto Exit; } new_size = idx->data_size + idx->count; if ( idx->count > 0 && !FT_QNEW_ARRAY( tbl, idx->count + 1 ) && ( !pool || !FT_ALLOC( new_bytes, new_size ) ) ) { FT_ULong n, cur_offset; FT_ULong extra = 0; FT_Byte* org_bytes = idx->bytes; /* at this point, `idx->offsets' can't be NULL */ cur_offset = idx->offsets[0] - 1; /* sanity check */ if ( cur_offset != 0 ) { FT_TRACE0(( "cff_index_get_pointers:" " invalid first offset value %ld set to zero\n", cur_offset )); cur_offset = 0; } if ( !pool ) tbl[0] = org_bytes + cur_offset; else tbl[0] = new_bytes + cur_offset; for ( n = 1; n <= idx->count; n++ ) { FT_ULong next_offset = idx->offsets[n] - 1; /* two sanity checks for invalid offset tables */ if ( next_offset < cur_offset ) next_offset = cur_offset; else if ( next_offset > idx->data_size ) next_offset = idx->data_size; if ( !pool ) tbl[n] = org_bytes + next_offset; else { tbl[n] = new_bytes + next_offset + extra; if ( next_offset != cur_offset ) { FT_MEM_COPY( tbl[n - 1], org_bytes + cur_offset, tbl[n] - tbl[n - 1] ); tbl[n][0] = '\0'; tbl[n] += 1; extra++; } } cur_offset = next_offset; } *table = tbl; if ( pool ) *pool = new_bytes; if ( pool_size ) *pool_size = new_size; } Exit: if ( error && new_bytes ) FT_FREE( new_bytes ); if ( error && tbl ) FT_FREE( tbl ); return error; } FT_LOCAL_DEF( FT_Error ) cff_index_access_element( CFF_Index idx, FT_UInt element, FT_Byte** pbytes, FT_ULong* pbyte_len ) { FT_Error error = FT_Err_Ok; if ( idx && idx->count > element ) { /* compute start and end offsets */ FT_Stream stream = idx->stream; FT_ULong off1, off2 = 0; /* load offsets from file or the offset table */ if ( !idx->offsets ) { FT_ULong pos = element * idx->off_size; if ( FT_STREAM_SEEK( idx->start + idx->hdr_size + pos ) ) goto Exit; off1 = cff_index_read_offset( idx, &error ); if ( error ) goto Exit; if ( off1 != 0 ) { do { element++; off2 = cff_index_read_offset( idx, &error ); } while ( off2 == 0 && element < idx->count ); } } else /* use offsets table */ { off1 = idx->offsets[element]; if ( off1 ) { do { element++; off2 = idx->offsets[element]; } while ( off2 == 0 && element < idx->count ); } } /* XXX: should check off2 does not exceed the end of this entry; */ /* at present, only truncate off2 at the end of this stream */ if ( off2 > stream->size + 1 || idx->data_offset > stream->size - off2 + 1 ) { FT_ERROR(( "cff_index_access_element:" " offset to next entry (%ld)" " exceeds the end of stream (%ld)\n", off2, stream->size - idx->data_offset + 1 )); off2 = stream->size - idx->data_offset + 1; } /* access element */ if ( off1 && off2 > off1 ) { *pbyte_len = off2 - off1; if ( idx->bytes ) { /* this index was completely loaded in memory, that's easy */ *pbytes = idx->bytes + off1 - 1; } else { /* this index is still on disk/file, access it through a frame */ if ( FT_STREAM_SEEK( idx->data_offset + off1 - 1 ) || FT_FRAME_EXTRACT( off2 - off1, *pbytes ) ) goto Exit; } } else { /* empty index element */ *pbytes = 0; *pbyte_len = 0; } } else error = FT_THROW( Invalid_Argument ); Exit: return error; } FT_LOCAL_DEF( void ) cff_index_forget_element( CFF_Index idx, FT_Byte** pbytes ) { if ( idx->bytes == 0 ) { FT_Stream stream = idx->stream; FT_FRAME_RELEASE( *pbytes ); } } /* get an entry from Name INDEX */ FT_LOCAL_DEF( FT_String* ) cff_index_get_name( CFF_Font font, FT_UInt element ) { CFF_Index idx = &font->name_index; FT_Memory memory; FT_Byte* bytes; FT_ULong byte_len; FT_Error error; FT_String* name = NULL; if ( !idx->stream ) /* CFF2 does not include a name index */ goto Exit; memory = idx->stream->memory; error = cff_index_access_element( idx, element, &bytes, &byte_len ); if ( error ) goto Exit; if ( !FT_QALLOC( name, byte_len + 1 ) ) { FT_MEM_COPY( name, bytes, byte_len ); name[byte_len] = 0; } cff_index_forget_element( idx, &bytes ); Exit: return name; } /* get an entry from String INDEX */ FT_LOCAL_DEF( FT_String* ) cff_index_get_string( CFF_Font font, FT_UInt element ) { return ( element < font->num_strings ) ? (FT_String*)font->strings[element] : NULL; } FT_LOCAL_DEF( FT_String* ) cff_index_get_sid_string( CFF_Font font, FT_UInt sid ) { /* value 0xFFFFU indicates a missing dictionary entry */ if ( sid == 0xFFFFU ) return NULL; /* if it is not a standard string, return it */ if ( sid > 390 ) return cff_index_get_string( font, sid - 391 ); /* CID-keyed CFF fonts don't have glyph names */ if ( !font->psnames ) return NULL; /* this is a standard string */ return (FT_String *)font->psnames->adobe_std_strings( sid ); } /*************************************************************************/ /*************************************************************************/ /*** ***/ /*** FD Select table support ***/ /*** ***/ /*************************************************************************/ /*************************************************************************/ static void CFF_Done_FD_Select( CFF_FDSelect fdselect, FT_Stream stream ) { if ( fdselect->data ) FT_FRAME_RELEASE( fdselect->data ); fdselect->data_size = 0; fdselect->format = 0; fdselect->range_count = 0; } static FT_Error CFF_Load_FD_Select( CFF_FDSelect fdselect, FT_UInt num_glyphs, FT_Stream stream, FT_ULong offset ) { FT_Error error; FT_Byte format; FT_UInt num_ranges; /* read format */ if ( FT_STREAM_SEEK( offset ) || FT_READ_BYTE( format ) ) goto Exit; fdselect->format = format; fdselect->cache_count = 0; /* clear cache */ switch ( format ) { case 0: /* format 0, that's simple */ fdselect->data_size = num_glyphs; goto Load_Data; case 3: /* format 3, a tad more complex */ if ( FT_READ_USHORT( num_ranges ) ) goto Exit; if ( !num_ranges ) { FT_TRACE0(( "CFF_Load_FD_Select: empty FDSelect array\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } fdselect->data_size = num_ranges * 3 + 2; Load_Data: if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) ) goto Exit; break; default: /* hmm... that's wrong */ error = FT_THROW( Invalid_File_Format ); } Exit: return error; } FT_LOCAL_DEF( FT_Byte ) cff_fd_select_get( CFF_FDSelect fdselect, FT_UInt glyph_index ) { FT_Byte fd = 0; /* if there is no FDSelect, return zero */ /* Note: CFF2 with just one Font Dict has no FDSelect */ if ( !fdselect->data ) goto Exit; switch ( fdselect->format ) { case 0: fd = fdselect->data[glyph_index]; break; case 3: /* first, compare to the cache */ if ( glyph_index - fdselect->cache_first < fdselect->cache_count ) { fd = fdselect->cache_fd; break; } /* then, look up the ranges array */ { FT_Byte* p = fdselect->data; FT_Byte* p_limit = p + fdselect->data_size; FT_Byte fd2; FT_UInt first, limit; first = FT_NEXT_USHORT( p ); do { if ( glyph_index < first ) break; fd2 = *p++; limit = FT_NEXT_USHORT( p ); if ( glyph_index < limit ) { fd = fd2; /* update cache */ fdselect->cache_first = first; fdselect->cache_count = limit - first; fdselect->cache_fd = fd2; break; } first = limit; } while ( p < p_limit ); } break; default: ; } Exit: return fd; } /*************************************************************************/ /*************************************************************************/ /*** ***/ /*** CFF font support ***/ /*** ***/ /*************************************************************************/ /*************************************************************************/ static FT_Error cff_charset_compute_cids( CFF_Charset charset, FT_UInt num_glyphs, FT_Memory memory ) { FT_Error error = FT_Err_Ok; FT_UInt i; FT_UShort max_cid = 0; if ( charset->max_cid > 0 ) goto Exit; for ( i = 0; i < num_glyphs; i++ ) { if ( charset->sids[i] > max_cid ) max_cid = charset->sids[i]; } if ( FT_NEW_ARRAY( charset->cids, (FT_ULong)max_cid + 1 ) ) goto Exit; /* When multiple GIDs map to the same CID, we choose the lowest */ /* GID. This is not described in any spec, but it matches the */ /* behaviour of recent Acroread versions. The loop stops when */ /* the unsigned index wraps around after reaching zero. */ for ( i = num_glyphs - 1; i < num_glyphs; i-- ) charset->cids[charset->sids[i]] = (FT_UShort)i; charset->max_cid = max_cid; charset->num_glyphs = num_glyphs; Exit: return error; } FT_LOCAL_DEF( FT_UInt ) cff_charset_cid_to_gindex( CFF_Charset charset, FT_UInt cid ) { FT_UInt result = 0; if ( cid <= charset->max_cid ) result = charset->cids[cid]; return result; } static void cff_charset_free_cids( CFF_Charset charset, FT_Memory memory ) { FT_FREE( charset->cids ); charset->max_cid = 0; } static void cff_charset_done( CFF_Charset charset, FT_Stream stream ) { FT_Memory memory = stream->memory; cff_charset_free_cids( charset, memory ); FT_FREE( charset->sids ); charset->format = 0; charset->offset = 0; } static FT_Error cff_charset_load( CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset, FT_Bool invert ) { FT_Memory memory = stream->memory; FT_Error error = FT_Err_Ok; FT_UShort glyph_sid; /* If the offset is greater than 2, we have to parse the charset */ /* table. */ if ( offset > 2 ) { FT_UInt j; charset->offset = base_offset + offset; /* Get the format of the table. */ if ( FT_STREAM_SEEK( charset->offset ) || FT_READ_BYTE( charset->format ) ) goto Exit; /* Allocate memory for sids. */ if ( FT_QNEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* assign the .notdef glyph */ charset->sids[0] = 0; switch ( charset->format ) { case 0: if ( num_glyphs > 0 ) { if ( FT_FRAME_ENTER( ( num_glyphs - 1 ) * 2 ) ) goto Exit; for ( j = 1; j < num_glyphs; j++ ) charset->sids[j] = FT_GET_USHORT(); FT_FRAME_EXIT(); } break; case 1: case 2: { FT_UInt nleft; FT_UInt i; j = 1; while ( j < num_glyphs ) { /* Read the first glyph sid of the range. */ if ( FT_READ_USHORT( glyph_sid ) ) goto Exit; /* Read the number of glyphs in the range. */ if ( charset->format == 2 ) { if ( FT_READ_USHORT( nleft ) ) goto Exit; } else { if ( FT_READ_BYTE( nleft ) ) goto Exit; } /* try to rescue some of the SIDs if `nleft' is too large */ if ( glyph_sid > 0xFFFFL - nleft ) { FT_ERROR(( "cff_charset_load: invalid SID range trimmed" " nleft=%d -> %ld\n", nleft, 0xFFFFL - glyph_sid )); nleft = ( FT_UInt )( 0xFFFFL - glyph_sid ); } /* Fill in the range of sids -- `nleft + 1' glyphs. */ for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ ) charset->sids[j] = glyph_sid; } } break; default: FT_ERROR(( "cff_charset_load: invalid table format\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } else { /* Parse default tables corresponding to offset == 0, 1, or 2. */ /* CFF specification intimates the following: */ /* */ /* In order to use a predefined charset, the following must be */ /* true: The charset constructed for the glyphs in the font's */ /* charstrings dictionary must match the predefined charset in */ /* the first num_glyphs. */ charset->offset = offset; /* record charset type */ switch ( (FT_UInt)offset ) { case 0: if ( num_glyphs > 229 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" )); FT_ERROR(( "predefined charset (Adobe ISO-Latin)\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Allocate memory for sids. */ if ( FT_QNEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs ); break; case 1: if ( num_glyphs > 166 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" )); FT_ERROR(( "predefined charset (Adobe Expert)\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Allocate memory for sids. */ if ( FT_QNEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs ); break; case 2: if ( num_glyphs > 87 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" )); FT_ERROR(( "predefined charset (Adobe Expert Subset)\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Allocate memory for sids. */ if ( FT_QNEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs ); break; default: error = FT_THROW( Invalid_File_Format ); goto Exit; } } /* we have to invert the `sids' array for subsetted CID-keyed fonts */ if ( invert ) error = cff_charset_compute_cids( charset, num_glyphs, memory ); Exit: /* Clean up if there was an error. */ if ( error ) { FT_FREE( charset->sids ); FT_FREE( charset->cids ); charset->format = 0; charset->offset = 0; } return error; } static void cff_vstore_done( CFF_VStoreRec* vstore, FT_Memory memory ) { FT_UInt i; /* free regionList and axisLists */ if ( vstore->varRegionList ) { for ( i = 0; i < vstore->regionCount; i++ ) FT_FREE( vstore->varRegionList[i].axisList ); } FT_FREE( vstore->varRegionList ); /* free varData and indices */ if ( vstore->varData ) { for ( i = 0; i < vstore->dataCount; i++ ) FT_FREE( vstore->varData[i].regionIndices ); } FT_FREE( vstore->varData ); } /* convert 2.14 to Fixed */ #define FT_fdot14ToFixed( x ) ( (FT_Fixed)( (FT_ULong)(x) << 2 ) ) static FT_Error cff_vstore_load( CFF_VStoreRec* vstore, FT_Stream stream, FT_ULong base_offset, FT_ULong offset ) { FT_Memory memory = stream->memory; FT_Error error = FT_ERR( Invalid_File_Format ); FT_ULong* dataOffsetArray = NULL; FT_UInt i, j; /* no offset means no vstore to parse */ if ( offset ) { FT_UInt vsOffset; FT_UInt format; FT_UInt dataCount; FT_UInt regionCount; FT_ULong regionListOffset; /* we need to parse the table to determine its size; */ /* skip table length */ if ( FT_STREAM_SEEK( base_offset + offset ) || FT_STREAM_SKIP( 2 ) ) goto Exit; /* actual variation store begins after the length */ vsOffset = FT_STREAM_POS(); /* check the header */ if ( FT_READ_USHORT( format ) ) goto Exit; if ( format != 1 ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* read top level fields */ if ( FT_READ_ULONG( regionListOffset ) || FT_READ_USHORT( dataCount ) ) goto Exit; /* make temporary copy of item variation data offsets; */ /* we'll parse region list first, then come back */ if ( FT_QNEW_ARRAY( dataOffsetArray, dataCount ) ) goto Exit; for ( i = 0; i < dataCount; i++ ) { if ( FT_READ_ULONG( dataOffsetArray[i] ) ) goto Exit; } /* parse regionList and axisLists */ if ( FT_STREAM_SEEK( vsOffset + regionListOffset ) || FT_READ_USHORT( vstore->axisCount ) || FT_READ_USHORT( regionCount ) ) goto Exit; vstore->regionCount = 0; if ( FT_QNEW_ARRAY( vstore->varRegionList, regionCount ) ) goto Exit; for ( i = 0; i < regionCount; i++ ) { CFF_VarRegion* region = &vstore->varRegionList[i]; if ( FT_QNEW_ARRAY( region->axisList, vstore->axisCount ) ) goto Exit; /* keep track of how many axisList to deallocate on error */ vstore->regionCount++; for ( j = 0; j < vstore->axisCount; j++ ) { CFF_AxisCoords* axis = &region->axisList[j]; FT_Int16 start14, peak14, end14; if ( FT_READ_SHORT( start14 ) || FT_READ_SHORT( peak14 ) || FT_READ_SHORT( end14 ) ) goto Exit; axis->startCoord = FT_fdot14ToFixed( start14 ); axis->peakCoord = FT_fdot14ToFixed( peak14 ); axis->endCoord = FT_fdot14ToFixed( end14 ); } } /* use dataOffsetArray now to parse varData items */ vstore->dataCount = 0; if ( FT_QNEW_ARRAY( vstore->varData, dataCount ) ) goto Exit; for ( i = 0; i < dataCount; i++ ) { CFF_VarData* data = &vstore->varData[i]; if ( FT_STREAM_SEEK( vsOffset + dataOffsetArray[i] ) ) goto Exit; /* ignore `itemCount' and `shortDeltaCount' */ /* because CFF2 has no delta sets */ if ( FT_STREAM_SKIP( 4 ) ) goto Exit; /* Note: just record values; consistency is checked later */ /* by cff_blend_build_vector when it consumes `vstore' */ if ( FT_READ_USHORT( data->regionIdxCount ) ) goto Exit; if ( FT_QNEW_ARRAY( data->regionIndices, data->regionIdxCount ) ) goto Exit; /* keep track of how many regionIndices to deallocate on error */ vstore->dataCount++; for ( j = 0; j < data->regionIdxCount; j++ ) { if ( FT_READ_USHORT( data->regionIndices[j] ) ) goto Exit; } } } error = FT_Err_Ok; Exit: FT_FREE( dataOffsetArray ); if ( error ) cff_vstore_done( vstore, memory ); return error; } /* Clear blend stack (after blend values are consumed). */ /* */ /* TODO: Should do this in cff_run_parse, but subFont */ /* ref is not available there. */ /* */ /* Allocation is not changed when stack is cleared. */ FT_LOCAL_DEF( void ) cff_blend_clear( CFF_SubFont subFont ) { subFont->blend_top = subFont->blend_stack; subFont->blend_used = 0; } /* Blend numOperands on the stack, */ /* store results into the first numBlends values, */ /* then pop remaining arguments. */ /* */ /* This is comparable to `cf2_doBlend' but */ /* the cffparse stack is different and can't be written. */ /* Blended values are written to a different buffer, */ /* using reserved operator 255. */ /* */ /* Blend calculation is done in 16.16 fixed point. */ FT_LOCAL_DEF( FT_Error ) cff_blend_doBlend( CFF_SubFont subFont, CFF_Parser parser, FT_UInt numBlends ) { FT_UInt delta; FT_UInt base; FT_UInt i, j; FT_UInt size; CFF_Blend blend = &subFont->blend; FT_Memory memory = subFont->blend.font->memory; /* for FT_REALLOC */ FT_Error error = FT_Err_Ok; /* for FT_REALLOC */ /* compute expected number of operands for this blend */ FT_UInt numOperands = (FT_UInt)( numBlends * blend->lenBV ); FT_UInt count = (FT_UInt)( parser->top - 1 - parser->stack ); if ( numOperands > count ) { FT_TRACE4(( " cff_blend_doBlend: Stack underflow %d argument%s\n", count, count == 1 ? "" : "s" )); error = FT_THROW( Stack_Underflow ); goto Exit; } /* check whether we have room for `numBlends' values at `blend_top' */ size = 5 * numBlends; /* add 5 bytes per entry */ if ( subFont->blend_used + size > subFont->blend_alloc ) { FT_Byte* blend_stack_old = subFont->blend_stack; FT_Byte* blend_top_old = subFont->blend_top; /* increase or allocate `blend_stack' and reset `blend_top'; */ /* prepare to append `numBlends' values to the buffer */ if ( FT_QREALLOC( subFont->blend_stack, subFont->blend_alloc, subFont->blend_alloc + size ) ) goto Exit; subFont->blend_top = subFont->blend_stack + subFont->blend_used; subFont->blend_alloc += size; /* iterate over the parser stack and adjust pointers */ /* if the reallocated buffer has a different address */ if ( blend_stack_old && subFont->blend_stack != blend_stack_old ) { FT_PtrDist offset = subFont->blend_stack - blend_stack_old; FT_Byte** p; for ( p = parser->stack; p < parser->top; p++ ) { if ( *p >= blend_stack_old && *p < blend_top_old ) *p += offset; } } } subFont->blend_used += size; base = count - numOperands; /* index of first blend arg */ delta = base + numBlends; /* index of first delta arg */ for ( i = 0; i < numBlends; i++ ) { const FT_Int32* weight = &blend->BV[1]; FT_UInt32 sum; /* convert inputs to 16.16 fixed point */ sum = cff_parse_num( parser, &parser->stack[i + base] ) * 0x10000; for ( j = 1; j < blend->lenBV; j++ ) sum += cff_parse_num( parser, &parser->stack[delta++] ) * *weight++; /* point parser stack to new value on blend_stack */ parser->stack[i + base] = subFont->blend_top; /* Push blended result as Type 2 5-byte fixed point number. This */ /* will not conflict with actual DICTs because 255 is a reserved */ /* opcode in both CFF and CFF2 DICTs. See `cff_parse_num' for */ /* decode of this, which rounds to an integer. */ *subFont->blend_top++ = 255; *subFont->blend_top++ = (FT_Byte)( sum >> 24 ); *subFont->blend_top++ = (FT_Byte)( sum >> 16 ); *subFont->blend_top++ = (FT_Byte)( sum >> 8 ); *subFont->blend_top++ = (FT_Byte)sum; } /* leave only numBlends results on parser stack */ parser->top = &parser->stack[base + numBlends]; Exit: return error; } /* Compute a blend vector from variation store index and normalized */ /* vector based on pseudo-code in OpenType Font Variations Overview. */ /* */ /* Note: lenNDV == 0 produces a default blend vector, (1,0,0,...). */ FT_LOCAL_DEF( FT_Error ) cff_blend_build_vector( CFF_Blend blend, FT_UInt vsindex, FT_UInt lenNDV, FT_Fixed* NDV ) { FT_Error error = FT_Err_Ok; /* for FT_REALLOC */ FT_Memory memory = blend->font->memory; /* for FT_REALLOC */ FT_UInt len; CFF_VStore vs; CFF_VarData* varData; FT_UInt master; /* protect against malformed fonts */ if ( !( lenNDV == 0 || NDV ) ) { FT_TRACE4(( " cff_blend_build_vector:" " Malformed Normalize Design Vector data\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } blend->builtBV = FALSE; vs = &blend->font->vstore; /* VStore and fvar must be consistent */ if ( lenNDV != 0 && lenNDV != vs->axisCount ) { FT_TRACE4(( " cff_blend_build_vector: Axis count mismatch\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( vsindex >= vs->dataCount ) { FT_TRACE4(( " cff_blend_build_vector: vsindex out of range\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* select the item variation data structure */ varData = &vs->varData[vsindex]; /* prepare buffer for the blend vector */ len = varData->regionIdxCount + 1; /* add 1 for default component */ if ( FT_QRENEW_ARRAY( blend->BV, blend->lenBV, len ) ) goto Exit; blend->lenBV = len; /* outer loop steps through master designs to be blended */ for ( master = 0; master < len; master++ ) { FT_UInt j; FT_UInt idx; CFF_VarRegion* varRegion; /* default factor is always one */ if ( master == 0 ) { blend->BV[master] = FT_FIXED_ONE; FT_TRACE4(( " build blend vector len %d\n", len )); FT_TRACE4(( " [ %f ", blend->BV[master] / 65536.0 )); continue; } /* VStore array does not include default master, so subtract one */ idx = varData->regionIndices[master - 1]; varRegion = &vs->varRegionList[idx]; if ( idx >= vs->regionCount ) { FT_TRACE4(( " cff_blend_build_vector:" " region index out of range\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Note: `lenNDV' could be zero. */ /* In that case, build default blend vector (1,0,0...). */ if ( !lenNDV ) { blend->BV[master] = 0; continue; } /* In the normal case, initialize each component to 1 */ /* before inner loop. */ blend->BV[master] = FT_FIXED_ONE; /* default */ /* inner loop steps through axes in this region */ for ( j = 0; j < lenNDV; j++ ) { CFF_AxisCoords* axis = &varRegion->axisList[j]; FT_Fixed axisScalar; /* compute the scalar contribution of this axis; */ /* ignore invalid ranges */ if ( axis->startCoord > axis->peakCoord || axis->peakCoord > axis->endCoord ) axisScalar = FT_FIXED_ONE; else if ( axis->startCoord < 0 && axis->endCoord > 0 && axis->peakCoord != 0 ) axisScalar = FT_FIXED_ONE; /* peak of 0 means ignore this axis */ else if ( axis->peakCoord == 0 ) axisScalar = FT_FIXED_ONE; /* ignore this region if coords are out of range */ else if ( NDV[j] < axis->startCoord || NDV[j] > axis->endCoord ) axisScalar = 0; /* calculate a proportional factor */ else { if ( NDV[j] == axis->peakCoord ) axisScalar = FT_FIXED_ONE; else if ( NDV[j] < axis->peakCoord ) axisScalar = FT_DivFix( NDV[j] - axis->startCoord, axis->peakCoord - axis->startCoord ); else axisScalar = FT_DivFix( axis->endCoord - NDV[j], axis->endCoord - axis->peakCoord ); } /* take product of all the axis scalars */ blend->BV[master] = FT_MulFix( blend->BV[master], axisScalar ); } FT_TRACE4(( ", %f ", blend->BV[master] / 65536.0 )); } FT_TRACE4(( "]\n" )); /* record the parameters used to build the blend vector */ blend->lastVsindex = vsindex; if ( lenNDV != 0 ) { /* user has set a normalized vector */ if ( FT_QRENEW_ARRAY( blend->lastNDV, blend->lenNDV, lenNDV ) ) goto Exit; FT_MEM_COPY( blend->lastNDV, NDV, lenNDV * sizeof ( *NDV ) ); } blend->lenNDV = lenNDV; blend->builtBV = TRUE; Exit: return error; } /* `lenNDV' is zero for default vector; */ /* return TRUE if blend vector needs to be built. */ FT_LOCAL_DEF( FT_Bool ) cff_blend_check_vector( CFF_Blend blend, FT_UInt vsindex, FT_UInt lenNDV, FT_Fixed* NDV ) { if ( !blend->builtBV || blend->lastVsindex != vsindex || blend->lenNDV != lenNDV || ( lenNDV && ft_memcmp( NDV, blend->lastNDV, lenNDV * sizeof ( *NDV ) ) != 0 ) ) { /* need to build blend vector */ return TRUE; } return FALSE; } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_LOCAL_DEF( FT_Error ) cff_get_var_blend( CFF_Face face, FT_UInt *num_coords, FT_Fixed* *coords, FT_Fixed* *normalizedcoords, FT_MM_Var* *mm_var ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; return mm->get_var_blend( FT_FACE( face ), num_coords, coords, normalizedcoords, mm_var ); } FT_LOCAL_DEF( void ) cff_done_blend( CFF_Face face ) { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; if (mm) mm->done_blend( FT_FACE( face ) ); } #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ static void cff_encoding_done( CFF_Encoding encoding ) { encoding->format = 0; encoding->offset = 0; encoding->count = 0; } static FT_Error cff_encoding_load( CFF_Encoding encoding, CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset ) { FT_Error error = FT_Err_Ok; FT_UInt count; FT_UInt j; FT_UShort glyph_sid; FT_UInt glyph_code; /* Check for charset->sids. If we do not have this, we fail. */ if ( !charset->sids ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Zero out the code to gid/sid mappings. */ for ( j = 0; j < 256; j++ ) { encoding->sids [j] = 0; encoding->codes[j] = 0; } /* Note: The encoding table in a CFF font is indexed by glyph index; */ /* the first encoded glyph index is 1. Hence, we read the character */ /* code (`glyph_code') at index j and make the assignment: */ /* */ /* encoding->codes[glyph_code] = j + 1 */ /* */ /* We also make the assignment: */ /* */ /* encoding->sids[glyph_code] = charset->sids[j + 1] */ /* */ /* This gives us both a code to GID and a code to SID mapping. */ if ( offset > 1 ) { encoding->offset = base_offset + offset; /* we need to parse the table to determine its size */ if ( FT_STREAM_SEEK( encoding->offset ) || FT_READ_BYTE( encoding->format ) || FT_READ_BYTE( count ) ) goto Exit; switch ( encoding->format & 0x7F ) { case 0: { FT_Byte* p; /* By convention, GID 0 is always ".notdef" and is never */ /* coded in the font. Hence, the number of codes found */ /* in the table is `count+1'. */ /* */ encoding->count = count + 1; if ( FT_FRAME_ENTER( count ) ) goto Exit; p = (FT_Byte*)stream->cursor; for ( j = 1; j <= count; j++ ) { glyph_code = *p++; /* Make sure j is not too big. */ if ( j < num_glyphs ) { /* Assign code to GID mapping. */ encoding->codes[glyph_code] = (FT_UShort)j; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = charset->sids[j]; } } FT_FRAME_EXIT(); } break; case 1: { FT_UInt nleft; FT_UInt i = 1; FT_UInt k; encoding->count = 0; /* Parse the Format1 ranges. */ for ( j = 0; j < count; j++, i += nleft ) { /* Read the first glyph code of the range. */ if ( FT_READ_BYTE( glyph_code ) ) goto Exit; /* Read the number of codes in the range. */ if ( FT_READ_BYTE( nleft ) ) goto Exit; /* Increment nleft, so we read `nleft + 1' codes/sids. */ nleft++; /* compute max number of character codes */ if ( (FT_UInt)nleft > encoding->count ) encoding->count = nleft; /* Fill in the range of codes/sids. */ for ( k = i; k < nleft + i; k++, glyph_code++ ) { /* Make sure k is not too big. */ if ( k < num_glyphs && glyph_code < 256 ) { /* Assign code to GID mapping. */ encoding->codes[glyph_code] = (FT_UShort)k; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = charset->sids[k]; } } } /* simple check; one never knows what can be found in a font */ if ( encoding->count > 256 ) encoding->count = 256; } break; default: FT_ERROR(( "cff_encoding_load: invalid table format\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* Parse supplemental encodings, if any. */ if ( encoding->format & 0x80 ) { FT_UInt gindex; /* count supplements */ if ( FT_READ_BYTE( count ) ) goto Exit; for ( j = 0; j < count; j++ ) { /* Read supplemental glyph code. */ if ( FT_READ_BYTE( glyph_code ) ) goto Exit; /* Read the SID associated with this glyph code. */ if ( FT_READ_USHORT( glyph_sid ) ) goto Exit; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = glyph_sid; /* First, look up GID which has been assigned to */ /* SID glyph_sid. */ for ( gindex = 0; gindex < num_glyphs; gindex++ ) { if ( charset->sids[gindex] == glyph_sid ) { encoding->codes[glyph_code] = (FT_UShort)gindex; break; } } } } } else { /* We take into account the fact a CFF font can use a predefined */ /* encoding without containing all of the glyphs encoded by this */ /* encoding (see the note at the end of section 12 in the CFF */ /* specification). */ switch ( (FT_UInt)offset ) { case 0: /* First, copy the code to SID mapping. */ FT_ARRAY_COPY( encoding->sids, cff_standard_encoding, 256 ); goto Populate; case 1: /* First, copy the code to SID mapping. */ FT_ARRAY_COPY( encoding->sids, cff_expert_encoding, 256 ); Populate: /* Construct code to GID mapping from code to SID mapping */ /* and charset. */ encoding->offset = offset; /* used in cff_face_init */ encoding->count = 0; error = cff_charset_compute_cids( charset, num_glyphs, stream->memory ); if ( error ) goto Exit; for ( j = 0; j < 256; j++ ) { FT_UInt sid = encoding->sids[j]; FT_UInt gid = 0; if ( sid ) gid = cff_charset_cid_to_gindex( charset, sid ); if ( gid != 0 ) { encoding->codes[j] = (FT_UShort)gid; encoding->count = j + 1; } else { encoding->codes[j] = 0; encoding->sids [j] = 0; } } break; default: FT_ERROR(( "cff_encoding_load: invalid table format\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } Exit: /* Clean up if there was an error. */ return error; } /* Parse private dictionary; first call is always from `cff_face_init', */ /* so NDV has not been set for CFF2 variation. */ /* */ /* `cff_slot_load' must call this function each time NDV changes. */ FT_LOCAL_DEF( FT_Error ) cff_load_private_dict( CFF_Font font, CFF_SubFont subfont, FT_UInt lenNDV, FT_Fixed* NDV ) { FT_Error error = FT_Err_Ok; CFF_ParserRec parser; CFF_FontRecDict top = &subfont->font_dict; CFF_Private priv = &subfont->private_dict; FT_Stream stream = font->stream; FT_UInt stackSize; /* store handle needed to access memory, vstore for blend; */ /* we need this for clean-up even if there is no private DICT */ subfont->blend.font = font; subfont->blend.usedBV = FALSE; /* clear state */ if ( !top->private_offset || !top->private_size ) goto Exit2; /* no private DICT, do nothing */ /* set defaults */ FT_ZERO( priv ); priv->blue_shift = 7; priv->blue_fuzz = 1; priv->lenIV = -1; priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); /* provide inputs for blend calculations */ priv->subfont = subfont; subfont->lenNDV = lenNDV; subfont->NDV = NDV; /* add 1 for the operator */ stackSize = font->cff2 ? font->top_font.font_dict.maxstack + 1 : CFF_MAX_STACK_DEPTH + 1; if ( cff_parser_init( &parser, font->cff2 ? CFF2_CODE_PRIVATE : CFF_CODE_PRIVATE, priv, font->library, stackSize, top->num_designs, top->num_axes ) ) goto Exit; if ( FT_STREAM_SEEK( font->base_offset + top->private_offset ) || FT_FRAME_ENTER( top->private_size ) ) goto Exit; FT_TRACE4(( " private dictionary:\n" )); error = cff_parser_run( &parser, (FT_Byte*)stream->cursor, (FT_Byte*)stream->limit ); FT_FRAME_EXIT(); if ( error ) goto Exit; /* ensure that `num_blue_values' is even */ priv->num_blue_values &= ~1; /* sanitize `initialRandomSeed' to be a positive value, if necessary; */ /* this is not mandated by the specification but by our implementation */ if ( priv->initial_random_seed < 0 ) priv->initial_random_seed = -priv->initial_random_seed; else if ( priv->initial_random_seed == 0 ) priv->initial_random_seed = 987654321; /* some sanitizing to avoid overflows later on; */ /* the upper limits are ad-hoc values */ if ( priv->blue_shift > 1000 || priv->blue_shift < 0 ) { FT_TRACE2(( "cff_load_private_dict:" " setting unlikely BlueShift value %ld to default (7)\n", priv->blue_shift )); priv->blue_shift = 7; } if ( priv->blue_fuzz > 1000 || priv->blue_fuzz < 0 ) { FT_TRACE2(( "cff_load_private_dict:" " setting unlikely BlueFuzz value %ld to default (1)\n", priv->blue_fuzz )); priv->blue_fuzz = 1; } Exit: /* clean up */ cff_blend_clear( subfont ); /* clear blend stack */ cff_parser_done( &parser ); /* free parser stack */ Exit2: /* no clean up (parser not initialized) */ return error; } /* There are 3 ways to call this function, distinguished by code. */ /* */ /* . CFF_CODE_TOPDICT for either a CFF Top DICT or a CFF Font DICT */ /* . CFF2_CODE_TOPDICT for CFF2 Top DICT */ /* . CFF2_CODE_FONTDICT for CFF2 Font DICT */ static FT_Error cff_subfont_load( CFF_SubFont subfont, CFF_Index idx, FT_UInt font_index, FT_Stream stream, FT_ULong base_offset, FT_UInt code, CFF_Font font, CFF_Face face ) { FT_Error error; CFF_ParserRec parser; FT_Byte* dict = NULL; FT_ULong dict_len; CFF_FontRecDict top = &subfont->font_dict; CFF_Private priv = &subfont->private_dict; PSAux_Service psaux = (PSAux_Service)face->psaux; FT_Bool cff2 = FT_BOOL( code == CFF2_CODE_TOPDICT || code == CFF2_CODE_FONTDICT ); FT_UInt stackSize = cff2 ? CFF2_DEFAULT_STACK : CFF_MAX_STACK_DEPTH; /* Note: We use default stack size for CFF2 Font DICT because */ /* Top and Font DICTs are not allowed to have blend operators. */ error = cff_parser_init( &parser, code, &subfont->font_dict, font->library, stackSize, 0, 0 ); if ( error ) goto Exit; /* set defaults */ FT_ZERO( top ); top->underline_position = -( 100L << 16 ); top->underline_thickness = 50L << 16; top->charstring_type = 2; top->font_matrix.xx = 0x10000L; top->font_matrix.yy = 0x10000L; top->cid_count = 8720; /* we use the implementation specific SID value 0xFFFF to indicate */ /* missing entries */ top->version = 0xFFFFU; top->notice = 0xFFFFU; top->copyright = 0xFFFFU; top->full_name = 0xFFFFU; top->family_name = 0xFFFFU; top->weight = 0xFFFFU; top->embedded_postscript = 0xFFFFU; top->cid_registry = 0xFFFFU; top->cid_ordering = 0xFFFFU; top->cid_font_name = 0xFFFFU; /* set default stack size */ top->maxstack = cff2 ? CFF2_DEFAULT_STACK : 48; if ( idx->count ) /* count is nonzero for a real index */ error = cff_index_access_element( idx, font_index, &dict, &dict_len ); else { /* CFF2 has a fake top dict index; */ /* simulate `cff_index_access_element' */ /* Note: macros implicitly use `stream' and set `error' */ if ( FT_STREAM_SEEK( idx->data_offset ) || FT_FRAME_EXTRACT( idx->data_size, dict ) ) goto Exit; dict_len = idx->data_size; } if ( !error ) { FT_TRACE4(( " top dictionary:\n" )); error = cff_parser_run( &parser, dict, FT_OFFSET( dict, dict_len ) ); } /* clean up regardless of error */ if ( idx->count ) cff_index_forget_element( idx, &dict ); else FT_FRAME_RELEASE( dict ); if ( error ) goto Exit; /* if it is a CID font, we stop there */ if ( top->cid_registry != 0xFFFFU ) goto Exit; /* Parse the private dictionary, if any. */ /* */ /* CFF2 does not have a private dictionary in the Top DICT */ /* but may have one in a Font DICT. We need to parse */ /* the latter here in order to load any local subrs. */ error = cff_load_private_dict( font, subfont, 0, 0 ); if ( error ) goto Exit; if ( !cff2 ) { /* * Initialize the random number generator. * * - If we have a face-specific seed, use it. * If non-zero, update it to a positive value. * * - Otherwise, use the seed from the CFF driver. * If non-zero, update it to a positive value. * * - If the random value is zero, use the seed given by the subfont's * `initialRandomSeed' value. * */ if ( face->root.internal->random_seed == -1 ) { PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face ); subfont->random = (FT_UInt32)driver->random_seed; if ( driver->random_seed ) { do { driver->random_seed = (FT_Int32)psaux->cff_random( (FT_UInt32)driver->random_seed ); } while ( driver->random_seed < 0 ); } } else { subfont->random = (FT_UInt32)face->root.internal->random_seed; if ( face->root.internal->random_seed ) { do { face->root.internal->random_seed = (FT_Int32)psaux->cff_random( (FT_UInt32)face->root.internal->random_seed ); } while ( face->root.internal->random_seed < 0 ); } } if ( !subfont->random ) subfont->random = (FT_UInt32)priv->initial_random_seed; } /* read the local subrs, if any */ if ( priv->local_subrs_offset ) { if ( FT_STREAM_SEEK( base_offset + top->private_offset + priv->local_subrs_offset ) ) goto Exit; error = cff_index_init( &subfont->local_subrs_index, stream, 1, cff2 ); if ( error ) goto Exit; error = cff_index_get_pointers( &subfont->local_subrs_index, &subfont->local_subrs, NULL, NULL ); if ( error ) goto Exit; } Exit: cff_parser_done( &parser ); /* free parser stack */ return error; } static void cff_subfont_done( FT_Memory memory, CFF_SubFont subfont ) { if ( subfont ) { cff_index_done( &subfont->local_subrs_index ); FT_FREE( subfont->local_subrs ); FT_FREE( subfont->blend.lastNDV ); FT_FREE( subfont->blend.BV ); FT_FREE( subfont->blend_stack ); } } FT_LOCAL_DEF( FT_Error ) cff_font_load( FT_Library library, FT_Stream stream, FT_Int face_index, CFF_Font font, CFF_Face face, FT_Bool pure_cff, FT_Bool cff2 ) { static const FT_Frame_Field cff_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE CFF_FontRec FT_FRAME_START( 3 ), FT_FRAME_BYTE( version_major ), FT_FRAME_BYTE( version_minor ), FT_FRAME_BYTE( header_size ), FT_FRAME_END }; FT_Error error; FT_Memory memory = stream->memory; FT_ULong base_offset; CFF_FontRecDict dict; CFF_IndexRec string_index; FT_UInt subfont_index; FT_ZERO( font ); FT_ZERO( &string_index ); dict = &font->top_font.font_dict; base_offset = FT_STREAM_POS(); font->library = library; font->stream = stream; font->memory = memory; font->cff2 = cff2; font->base_offset = base_offset; /* read CFF font header */ if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) goto Exit; if ( cff2 ) { if ( font->version_major != 2 || font->header_size < 5 ) { FT_TRACE2(( " not a CFF2 font header\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } if ( FT_READ_USHORT( font->top_dict_length ) ) goto Exit; } else { FT_Byte absolute_offset; if ( FT_READ_BYTE( absolute_offset ) ) goto Exit; if ( font->version_major != 1 || font->header_size < 4 || absolute_offset > 4 ) { FT_TRACE2(( " not a CFF font header\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } } /* skip the rest of the header */ if ( FT_STREAM_SEEK( base_offset + font->header_size ) ) { /* For pure CFFs we have read only four bytes so far. Contrary to */ /* other formats like SFNT those bytes doesn't define a signature; */ /* it is thus possible that the font isn't a CFF at all. */ if ( pure_cff ) { FT_TRACE2(( " not a CFF file\n" )); error = FT_THROW( Unknown_File_Format ); } goto Exit; } if ( cff2 ) { /* For CFF2, the top dict data immediately follow the header */ /* and the length is stored in the header `offSize' field; */ /* there is no index for it. */ /* */ /* Use the `font_dict_index' to save the current position */ /* and length of data, but leave count at zero as an indicator. */ FT_ZERO( &font->font_dict_index ); font->font_dict_index.data_offset = FT_STREAM_POS(); font->font_dict_index.data_size = font->top_dict_length; /* skip the top dict data for now, we will parse it later */ if ( FT_STREAM_SKIP( font->top_dict_length ) ) goto Exit; /* next, read the global subrs index */ if ( FT_SET_ERROR( cff_index_init( &font->global_subrs_index, stream, 1, cff2 ) ) ) goto Exit; } else { /* for CFF, read the name, top dict, string and global subrs index */ if ( FT_SET_ERROR( cff_index_init( &font->name_index, stream, 0, cff2 ) ) ) { if ( pure_cff ) { FT_TRACE2(( " not a CFF file\n" )); error = FT_THROW( Unknown_File_Format ); } goto Exit; } /* if we have an empty font name, */ /* it must be the only font in the CFF */ if ( font->name_index.count > 1 && font->name_index.data_size < font->name_index.count ) { /* for pure CFFs, we still haven't checked enough bytes */ /* to be sure that it is a CFF at all */ error = pure_cff ? FT_THROW( Unknown_File_Format ) : FT_THROW( Invalid_File_Format ); goto Exit; } if ( FT_SET_ERROR( cff_index_init( &font->font_dict_index, stream, 0, cff2 ) ) || FT_SET_ERROR( cff_index_init( &string_index, stream, 1, cff2 ) ) || FT_SET_ERROR( cff_index_init( &font->global_subrs_index, stream, 1, cff2 ) ) || FT_SET_ERROR( cff_index_get_pointers( &string_index, &font->strings, &font->string_pool, &font->string_pool_size ) ) ) goto Exit; /* there must be a Top DICT index entry for each name index entry */ if ( font->name_index.count > font->font_dict_index.count ) { FT_ERROR(( "cff_font_load:" " not enough entries in Top DICT index\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } font->num_strings = string_index.count; if ( pure_cff ) { /* well, we don't really forget the `disabled' fonts... */ subfont_index = (FT_UInt)( face_index & 0xFFFF ); if ( face_index > 0 && subfont_index >= font->name_index.count ) { FT_ERROR(( "cff_font_load:" " invalid subfont index for pure CFF font (%d)\n", subfont_index )); error = FT_THROW( Invalid_Argument ); goto Exit; } font->num_faces = font->name_index.count; } else { subfont_index = 0; if ( font->name_index.count > 1 ) { FT_ERROR(( "cff_font_load:" " invalid CFF font with multiple subfonts\n" )); FT_ERROR(( " " " in SFNT wrapper\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } /* in case of a font format check, simply exit now */ if ( face_index < 0 ) goto Exit; /* now, parse the top-level font dictionary */ FT_TRACE4(( "parsing top-level\n" )); error = cff_subfont_load( &font->top_font, &font->font_dict_index, subfont_index, stream, base_offset, cff2 ? CFF2_CODE_TOPDICT : CFF_CODE_TOPDICT, font, face ); if ( error ) goto Exit; if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) goto Exit; error = cff_index_init( &font->charstrings_index, stream, 0, cff2 ); if ( error ) goto Exit; /* now, check for a CID or CFF2 font */ if ( dict->cid_registry != 0xFFFFU || cff2 ) { CFF_IndexRec fd_index; CFF_SubFont sub = NULL; FT_UInt idx; /* for CFF2, read the Variation Store if available; */ /* this must follow the Top DICT parse and precede any Private DICT */ error = cff_vstore_load( &font->vstore, stream, base_offset, dict->vstore_offset ); if ( error ) goto Exit; /* this is a CID-keyed font, we must now allocate a table of */ /* sub-fonts, then load each of them separately */ if ( FT_STREAM_SEEK( base_offset + dict->cid_fd_array_offset ) ) goto Exit; error = cff_index_init( &fd_index, stream, 0, cff2 ); if ( error ) goto Exit; /* Font Dicts are not limited to 256 for CFF2. */ /* TODO: support this for CFF2 */ if ( fd_index.count > CFF_MAX_CID_FONTS ) { FT_TRACE0(( "cff_font_load: FD array too large in CID font\n" )); goto Fail_CID; } /* allocate & read each font dict independently */ font->num_subfonts = fd_index.count; if ( FT_NEW_ARRAY( sub, fd_index.count ) ) goto Fail_CID; /* set up pointer table */ for ( idx = 0; idx < fd_index.count; idx++ ) font->subfonts[idx] = sub + idx; /* now load each subfont independently */ for ( idx = 0; idx < fd_index.count; idx++ ) { sub = font->subfonts[idx]; FT_TRACE4(( "parsing subfont %u\n", idx )); error = cff_subfont_load( sub, &fd_index, idx, stream, base_offset, cff2 ? CFF2_CODE_FONTDICT : CFF_CODE_TOPDICT, font, face ); if ( error ) goto Fail_CID; } /* now load the FD Select array; */ /* CFF2 omits FDSelect if there is only one FD */ if ( !cff2 || fd_index.count > 1 ) error = CFF_Load_FD_Select( &font->fd_select, font->charstrings_index.count, stream, base_offset + dict->cid_fd_select_offset ); Fail_CID: cff_index_done( &fd_index ); if ( error ) goto Exit; } else font->num_subfonts = 0; /* read the charstrings index now */ if ( dict->charstrings_offset == 0 ) { FT_ERROR(( "cff_font_load: no charstrings offset\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } font->num_glyphs = font->charstrings_index.count; error = cff_index_get_pointers( &font->global_subrs_index, &font->global_subrs, NULL, NULL ); if ( error ) goto Exit; /* read the Charset and Encoding tables if available */ if ( !cff2 && font->num_glyphs > 0 ) { FT_Bool invert = FT_BOOL( dict->cid_registry != 0xFFFFU && pure_cff ); error = cff_charset_load( &font->charset, font->num_glyphs, stream, base_offset, dict->charset_offset, invert ); if ( error ) goto Exit; /* CID-keyed CFFs don't have an encoding */ if ( dict->cid_registry == 0xFFFFU ) { error = cff_encoding_load( &font->encoding, &font->charset, font->num_glyphs, stream, base_offset, dict->encoding_offset ); if ( error ) goto Exit; } } /* get the font name (/CIDFontName for CID-keyed fonts, */ /* /FontName otherwise) */ font->font_name = cff_index_get_name( font, subfont_index ); Exit: cff_index_done( &string_index ); return error; } FT_LOCAL_DEF( void ) cff_font_done( CFF_Font font ) { FT_Memory memory = font->memory; FT_UInt idx; cff_index_done( &font->global_subrs_index ); cff_index_done( &font->font_dict_index ); cff_index_done( &font->name_index ); cff_index_done( &font->charstrings_index ); /* release font dictionaries, but only if working with */ /* a CID keyed CFF font or a CFF2 font */ if ( font->num_subfonts > 0 ) { for ( idx = 0; idx < font->num_subfonts; idx++ ) cff_subfont_done( memory, font->subfonts[idx] ); /* the subfonts array has been allocated as a single block */ FT_FREE( font->subfonts[0] ); } cff_encoding_done( &font->encoding ); cff_charset_done( &font->charset, font->stream ); cff_vstore_done( &font->vstore, memory ); cff_subfont_done( memory, &font->top_font ); CFF_Done_FD_Select( &font->fd_select, font->stream ); FT_FREE( font->font_info ); FT_FREE( font->font_name ); FT_FREE( font->global_subrs ); FT_FREE( font->strings ); FT_FREE( font->string_pool ); if ( font->cf2_instance.finalizer ) { font->cf2_instance.finalizer( font->cf2_instance.data ); FT_FREE( font->cf2_instance.data ); } FT_FREE( font->font_extra ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffload.c
C++
gpl-3.0
75,289
/**************************************************************************** * * cffload.h * * OpenType & CFF data/program tables loader (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 CFFLOAD_H_ #define CFFLOAD_H_ #include <freetype/internal/cfftypes.h> #include "cffparse.h" #include <freetype/internal/cffotypes.h> /* for CFF_Face */ FT_BEGIN_HEADER FT_LOCAL( FT_UShort ) cff_get_standard_encoding( FT_UInt charcode ); FT_LOCAL( FT_String* ) cff_index_get_string( CFF_Font font, FT_UInt element ); FT_LOCAL( FT_String* ) cff_index_get_sid_string( CFF_Font font, FT_UInt sid ); FT_LOCAL( FT_Error ) cff_index_access_element( CFF_Index idx, FT_UInt element, FT_Byte** pbytes, FT_ULong* pbyte_len ); FT_LOCAL( void ) cff_index_forget_element( CFF_Index idx, FT_Byte** pbytes ); FT_LOCAL( FT_String* ) cff_index_get_name( CFF_Font font, FT_UInt element ); FT_LOCAL( FT_UInt ) cff_charset_cid_to_gindex( CFF_Charset charset, FT_UInt cid ); FT_LOCAL( FT_Error ) cff_font_load( FT_Library library, FT_Stream stream, FT_Int face_index, CFF_Font font, CFF_Face face, FT_Bool pure_cff, FT_Bool cff2 ); FT_LOCAL( void ) cff_font_done( CFF_Font font ); FT_LOCAL( FT_Error ) cff_load_private_dict( CFF_Font font, CFF_SubFont subfont, FT_UInt lenNDV, FT_Fixed* NDV ); FT_LOCAL( FT_Byte ) cff_fd_select_get( CFF_FDSelect fdselect, FT_UInt glyph_index ); FT_LOCAL( FT_Bool ) cff_blend_check_vector( CFF_Blend blend, FT_UInt vsindex, FT_UInt lenNDV, FT_Fixed* NDV ); FT_LOCAL( FT_Error ) cff_blend_build_vector( CFF_Blend blend, FT_UInt vsindex, FT_UInt lenNDV, FT_Fixed* NDV ); FT_LOCAL( void ) cff_blend_clear( CFF_SubFont subFont ); FT_LOCAL( FT_Error ) cff_blend_doBlend( CFF_SubFont subfont, CFF_Parser parser, FT_UInt numBlends ); #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_LOCAL( FT_Error ) cff_get_var_blend( CFF_Face face, FT_UInt *num_coords, FT_Fixed* *coords, FT_Fixed* *normalizedcoords, FT_MM_Var* *mm_var ); FT_LOCAL( void ) cff_done_blend( CFF_Face face ); #endif FT_END_HEADER #endif /* CFFLOAD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffload.h
C++
gpl-3.0
3,299
/**************************************************************************** * * cffobjs.c * * OpenType objects manager (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/ftcalc.h> #include <freetype/internal/ftstream.h> #include <freetype/fterrors.h> #include <freetype/ttnameid.h> #include <freetype/tttags.h> #include <freetype/internal/sfnt.h> #include <freetype/ftdriver.h> #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #include <freetype/ftmm.h> #include <freetype/internal/services/svmm.h> #include <freetype/internal/services/svmetric.h> #endif #include <freetype/internal/cffotypes.h> #include "cffobjs.h" #include "cffload.h" #include "cffcmap.h" #include "cfferrs.h" #include <freetype/internal/psaux.h> #include <freetype/internal/services/svcfftl.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 cffobjs /************************************************************************** * * SIZE FUNCTIONS * */ static PSH_Globals_Funcs cff_size_get_globals_funcs( CFF_Size size ) { CFF_Face face = (CFF_Face)size->root.face; CFF_Font font = (CFF_Font)face->extra.data; PSHinter_Service pshinter = font->pshinter; FT_Module module; module = FT_Get_Module( size->root.face->driver->root.library, "pshinter" ); return ( module && pshinter && pshinter->get_globals_funcs ) ? pshinter->get_globals_funcs( module ) : 0; } FT_LOCAL_DEF( void ) cff_size_done( FT_Size cffsize ) /* CFF_Size */ { FT_Memory memory = cffsize->face->memory; CFF_Size size = (CFF_Size)cffsize; CFF_Face face = (CFF_Face)size->root.face; CFF_Font font = (CFF_Font)face->extra.data; CFF_Internal internal = (CFF_Internal)cffsize->internal->module_data; if ( internal ) { PSH_Globals_Funcs funcs; funcs = cff_size_get_globals_funcs( size ); if ( funcs ) { FT_UInt i; funcs->destroy( internal->topfont ); for ( i = font->num_subfonts; i > 0; i-- ) funcs->destroy( internal->subfonts[i - 1] ); } FT_FREE( internal ); } } /* CFF and Type 1 private dictionaries have slightly different */ /* structures; we need to synthesize a Type 1 dictionary on the fly */ static void cff_make_private_dict( CFF_SubFont subfont, PS_Private priv ) { CFF_Private cpriv = &subfont->private_dict; FT_UInt n, count; FT_ZERO( priv ); count = priv->num_blue_values = cpriv->num_blue_values; for ( n = 0; n < count; n++ ) priv->blue_values[n] = (FT_Short)cpriv->blue_values[n]; count = priv->num_other_blues = cpriv->num_other_blues; for ( n = 0; n < count; n++ ) priv->other_blues[n] = (FT_Short)cpriv->other_blues[n]; count = priv->num_family_blues = cpriv->num_family_blues; for ( n = 0; n < count; n++ ) priv->family_blues[n] = (FT_Short)cpriv->family_blues[n]; count = priv->num_family_other_blues = cpriv->num_family_other_blues; for ( n = 0; n < count; n++ ) priv->family_other_blues[n] = (FT_Short)cpriv->family_other_blues[n]; priv->blue_scale = cpriv->blue_scale; priv->blue_shift = (FT_Int)cpriv->blue_shift; priv->blue_fuzz = (FT_Int)cpriv->blue_fuzz; priv->standard_width[0] = (FT_UShort)cpriv->standard_width; priv->standard_height[0] = (FT_UShort)cpriv->standard_height; count = priv->num_snap_widths = cpriv->num_snap_widths; for ( n = 0; n < count; n++ ) priv->snap_widths[n] = (FT_Short)cpriv->snap_widths[n]; count = priv->num_snap_heights = cpriv->num_snap_heights; for ( n = 0; n < count; n++ ) priv->snap_heights[n] = (FT_Short)cpriv->snap_heights[n]; priv->force_bold = cpriv->force_bold; priv->language_group = cpriv->language_group; priv->lenIV = cpriv->lenIV; } FT_LOCAL_DEF( FT_Error ) cff_size_init( FT_Size cffsize ) /* CFF_Size */ { CFF_Size size = (CFF_Size)cffsize; FT_Error error = FT_Err_Ok; PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size ); FT_Memory memory = cffsize->face->memory; CFF_Internal internal = NULL; CFF_Face face = (CFF_Face)cffsize->face; CFF_Font font = (CFF_Font)face->extra.data; PS_PrivateRec priv; FT_UInt i; if ( !funcs ) goto Exit; if ( FT_NEW( internal ) ) goto Exit; cff_make_private_dict( &font->top_font, &priv ); error = funcs->create( cffsize->face->memory, &priv, &internal->topfont ); if ( error ) goto Exit; for ( i = font->num_subfonts; i > 0; i-- ) { CFF_SubFont sub = font->subfonts[i - 1]; cff_make_private_dict( sub, &priv ); error = funcs->create( cffsize->face->memory, &priv, &internal->subfonts[i - 1] ); if ( error ) goto Exit; } cffsize->internal->module_data = internal; size->strike_index = 0xFFFFFFFFUL; Exit: if ( error ) { if ( internal ) { for ( i = font->num_subfonts; i > 0; i-- ) FT_FREE( internal->subfonts[i - 1] ); FT_FREE( internal->topfont ); } FT_FREE( internal ); } return error; } #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_LOCAL_DEF( FT_Error ) cff_size_select( FT_Size size, FT_ULong strike_index ) { CFF_Size cffsize = (CFF_Size)size; PSH_Globals_Funcs funcs; cffsize->strike_index = strike_index; FT_Select_Metrics( size->face, strike_index ); funcs = cff_size_get_globals_funcs( cffsize ); if ( funcs ) { CFF_Face face = (CFF_Face)size->face; CFF_Font font = (CFF_Font)face->extra.data; CFF_Internal internal = (CFF_Internal)size->internal->module_data; FT_Long top_upm = (FT_Long)font->top_font.font_dict.units_per_em; FT_UInt i; funcs->set_scale( internal->topfont, size->metrics.x_scale, size->metrics.y_scale, 0, 0 ); for ( i = font->num_subfonts; i > 0; i-- ) { CFF_SubFont sub = font->subfonts[i - 1]; FT_Long sub_upm = (FT_Long)sub->font_dict.units_per_em; FT_Pos x_scale, y_scale; if ( top_upm != sub_upm ) { x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm ); y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm ); } else { x_scale = size->metrics.x_scale; y_scale = size->metrics.y_scale; } funcs->set_scale( internal->subfonts[i - 1], x_scale, y_scale, 0, 0 ); } } return FT_Err_Ok; } #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ FT_LOCAL_DEF( FT_Error ) cff_size_request( FT_Size size, FT_Size_Request req ) { FT_Error error; CFF_Size cffsize = (CFF_Size)size; PSH_Globals_Funcs funcs; #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS if ( FT_HAS_FIXED_SIZES( size->face ) ) { CFF_Face cffface = (CFF_Face)size->face; SFNT_Service sfnt = (SFNT_Service)cffface->sfnt; FT_ULong strike_index; if ( sfnt->set_sbit_strike( cffface, req, &strike_index ) ) cffsize->strike_index = 0xFFFFFFFFUL; else return cff_size_select( size, strike_index ); } #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ error = FT_Request_Metrics( size->face, req ); if ( error ) goto Exit; funcs = cff_size_get_globals_funcs( cffsize ); if ( funcs ) { CFF_Face cffface = (CFF_Face)size->face; CFF_Font font = (CFF_Font)cffface->extra.data; CFF_Internal internal = (CFF_Internal)size->internal->module_data; FT_Long top_upm = (FT_Long)font->top_font.font_dict.units_per_em; FT_UInt i; funcs->set_scale( internal->topfont, size->metrics.x_scale, size->metrics.y_scale, 0, 0 ); for ( i = font->num_subfonts; i > 0; i-- ) { CFF_SubFont sub = font->subfonts[i - 1]; FT_Long sub_upm = (FT_Long)sub->font_dict.units_per_em; FT_Pos x_scale, y_scale; if ( top_upm != sub_upm ) { x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm ); y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm ); } else { x_scale = size->metrics.x_scale; y_scale = size->metrics.y_scale; } funcs->set_scale( internal->subfonts[i - 1], x_scale, y_scale, 0, 0 ); } } Exit: return error; } /************************************************************************** * * SLOT FUNCTIONS * */ FT_LOCAL_DEF( void ) cff_slot_done( FT_GlyphSlot slot ) { if ( slot->internal ) slot->internal->glyph_hints = NULL; } FT_LOCAL_DEF( FT_Error ) cff_slot_init( FT_GlyphSlot slot ) { CFF_Face face = (CFF_Face)slot->face; CFF_Font font = (CFF_Font)face->extra.data; PSHinter_Service pshinter = font->pshinter; if ( pshinter ) { FT_Module module; module = FT_Get_Module( slot->face->driver->root.library, "pshinter" ); if ( module ) { T2_Hints_Funcs funcs; funcs = pshinter->get_t2_funcs( module ); slot->internal->glyph_hints = (void*)funcs; } } return FT_Err_Ok; } /************************************************************************** * * FACE FUNCTIONS * */ static FT_String* cff_strcpy( FT_Memory memory, const FT_String* source ) { FT_Error error; FT_String* result; FT_MEM_STRDUP( result, source ); return result; } /* Strip all subset prefixes of the form `ABCDEF+'. Usually, there */ /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold' */ /* have been seen in the wild. */ static void remove_subset_prefix( FT_String* name ) { FT_Int32 idx = 0; FT_Int32 length = (FT_Int32)ft_strlen( name ) + 1; FT_Bool continue_search = 1; while ( continue_search ) { if ( length >= 7 && name[6] == '+' ) { for ( idx = 0; idx < 6; idx++ ) { /* ASCII uppercase letters */ if ( !( 'A' <= name[idx] && name[idx] <= 'Z' ) ) continue_search = 0; } if ( continue_search ) { for ( idx = 7; idx < length; idx++ ) name[idx - 7] = name[idx]; length -= 7; } } else continue_search = 0; } } /* Remove the style part from the family name (if present). */ static void remove_style( FT_String* family_name, const FT_String* style_name ) { FT_Int32 family_name_length, style_name_length; family_name_length = (FT_Int32)ft_strlen( family_name ); style_name_length = (FT_Int32)ft_strlen( style_name ); if ( family_name_length > style_name_length ) { FT_Int idx; for ( idx = 1; idx <= style_name_length; idx++ ) { if ( family_name[family_name_length - idx] != style_name[style_name_length - idx] ) break; } if ( idx > style_name_length ) { /* family_name ends with style_name; remove it */ idx = family_name_length - style_name_length - 1; /* also remove special characters */ /* between real family name and style */ while ( idx > 0 && ( family_name[idx] == '-' || family_name[idx] == ' ' || family_name[idx] == '_' || family_name[idx] == '+' ) ) idx--; if ( idx > 0 ) family_name[idx + 1] = '\0'; } } } FT_LOCAL_DEF( FT_Error ) cff_face_init( FT_Stream stream, FT_Face cffface, /* CFF_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { CFF_Face face = (CFF_Face)cffface; FT_Error error; SFNT_Service sfnt; FT_Service_PsCMaps psnames; PSHinter_Service pshinter; PSAux_Service psaux; FT_Service_CFFLoad cffload; FT_Bool pure_cff = 1; FT_Bool cff2 = 0; FT_Bool sfnt_format = 0; FT_Library library = cffface->driver->root.library; sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) { FT_ERROR(( "cff_face_init: cannot access `sfnt' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); pshinter = (PSHinter_Service)FT_Get_Module_Interface( library, "pshinter" ); psaux = (PSAux_Service)FT_Get_Module_Interface( library, "psaux" ); if ( !psaux ) { FT_ERROR(( "cff_face_init: cannot access `psaux' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } face->psaux = psaux; FT_FACE_FIND_GLOBAL_SERVICE( face, cffload, CFF_LOAD ); FT_TRACE2(( "CFF driver\n" )); /* create input stream from resource */ if ( FT_STREAM_SEEK( 0 ) ) goto Exit; /* check whether we have a valid OpenType file */ FT_TRACE2(( " " )); error = sfnt->init_face( stream, face, face_index, num_params, params ); if ( !error ) { if ( face->format_tag != TTAG_OTTO ) /* `OTTO'; OpenType/CFF font */ { FT_TRACE2(( " not an OpenType/CFF font\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } /* if we are performing a simple font format check, exit immediately */ if ( face_index < 0 ) return FT_Err_Ok; sfnt_format = 1; /* now, the font can be either an OpenType/CFF font, or an SVG CEF */ /* font; in the latter case it doesn't have a `head' table */ error = face->goto_table( face, TTAG_head, stream, 0 ); if ( !error ) { pure_cff = 0; /* load font directory */ error = sfnt->load_face( stream, face, face_index, num_params, params ); if ( error ) goto Exit; } else { /* load the `cmap' table explicitly */ error = sfnt->load_cmap( face, stream ); if ( error ) goto Exit; } /* now load the CFF part of the file; */ /* give priority to CFF2 */ error = face->goto_table( face, TTAG_CFF2, stream, 0 ); if ( !error ) { cff2 = 1; face->is_cff2 = cff2; } if ( FT_ERR_EQ( error, Table_Missing ) ) error = face->goto_table( face, TTAG_CFF, stream, 0 ); if ( error ) goto Exit; } else { /* rewind to start of file; we are going to load a pure-CFF font */ if ( FT_STREAM_SEEK( 0 ) ) goto Exit; error = FT_Err_Ok; } /* now load and parse the CFF table in the file */ { CFF_Font cff = NULL; CFF_FontRecDict dict; FT_Memory memory = cffface->memory; FT_Int32 flags; FT_UInt i; if ( FT_NEW( cff ) ) goto Exit; face->extra.data = cff; error = cff_font_load( library, stream, face_index, cff, face, pure_cff, cff2 ); if ( error ) goto Exit; /* if we are performing a simple font format check, exit immediately */ /* (this is here for pure CFF) */ if ( face_index < 0 ) { cffface->num_faces = (FT_Long)cff->num_faces; return FT_Err_Ok; } cff->pshinter = pshinter; cff->psnames = psnames; cff->cffload = cffload; cffface->face_index = face_index & 0xFFFF; /* Complement the root flags with some interesting information. */ /* Note that this is only necessary for pure CFF and CEF fonts; */ /* SFNT based fonts use the `name' table instead. */ cffface->num_glyphs = (FT_Long)cff->num_glyphs; dict = &cff->top_font.font_dict; /* we need the `psnames' module for CFF and CEF formats */ /* which aren't CID-keyed */ if ( dict->cid_registry == 0xFFFFU && !psnames ) { FT_ERROR(( "cff_face_init:" " cannot open CFF & CEF fonts\n" )); FT_ERROR(( " " " without the `psnames' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } #ifdef FT_DEBUG_LEVEL_TRACE { FT_UInt idx; FT_String* s; FT_TRACE4(( "SIDs\n" )); /* dump string index, including default strings for convenience */ for ( idx = 0; idx <= 390; idx++ ) { s = cff_index_get_sid_string( cff, idx ); if ( s ) FT_TRACE4(( " %5d %s\n", idx, s )); } /* In Multiple Master CFFs, two SIDs hold the Normalize Design */ /* Vector (NDV) and Convert Design Vector (CDV) charstrings, */ /* which may contain null bytes in the middle of the data, too. */ /* We thus access `cff->strings' directly. */ for ( idx = 1; idx < cff->num_strings; idx++ ) { FT_Byte* s1 = cff->strings[idx - 1]; FT_Byte* s2 = cff->strings[idx]; FT_PtrDist s1len = s2 - s1 - 1; /* without the final null byte */ FT_PtrDist l; FT_TRACE4(( " %5d ", idx + 390 )); for ( l = 0; l < s1len; l++ ) FT_TRACE4(( "%c", s1[l] )); FT_TRACE4(( "\n" )); } /* print last element */ if ( cff->num_strings ) { FT_Byte* s1 = cff->strings[cff->num_strings - 1]; FT_Byte* s2 = cff->string_pool + cff->string_pool_size; FT_PtrDist s1len = s2 - s1 - 1; FT_PtrDist l; FT_TRACE4(( " %5d ", cff->num_strings + 390 )); for ( l = 0; l < s1len; l++ ) FT_TRACE4(( "%c", s1[l] )); FT_TRACE4(( "\n" )); } } #endif /* FT_DEBUG_LEVEL_TRACE */ #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT { FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm; FT_Service_MetricsVariations var = (FT_Service_MetricsVariations)face->var; FT_UInt instance_index = (FT_UInt)face_index >> 16; if ( FT_HAS_MULTIPLE_MASTERS( cffface ) && mm && instance_index > 0 ) { error = mm->set_instance( cffface, instance_index ); if ( error ) goto Exit; if ( var ) var->metrics_adjust( cffface ); } } #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ if ( !dict->has_font_matrix ) dict->units_per_em = pure_cff ? 1000 : face->root.units_per_EM; /* Normalize the font matrix so that `matrix->yy' is 1; if */ /* it is zero, we use `matrix->yx' instead. The scaling is */ /* done with `units_per_em' then (at this point, it already */ /* contains the scaling factor, but without normalization */ /* of the matrix). */ /* */ /* Note that the offsets must be expressed in integer font */ /* units. */ { FT_Matrix* matrix = &dict->font_matrix; FT_Vector* offset = &dict->font_offset; FT_ULong* upm = &dict->units_per_em; FT_Fixed temp; temp = matrix->yy ? FT_ABS( matrix->yy ) : FT_ABS( matrix->yx ); if ( temp != 0x10000L ) { *upm = (FT_ULong)FT_DivFix( (FT_Long)*upm, temp ); matrix->xx = FT_DivFix( matrix->xx, temp ); matrix->yx = FT_DivFix( matrix->yx, temp ); matrix->xy = FT_DivFix( matrix->xy, temp ); matrix->yy = FT_DivFix( matrix->yy, temp ); offset->x = FT_DivFix( offset->x, temp ); offset->y = FT_DivFix( offset->y, temp ); } offset->x >>= 16; offset->y >>= 16; } for ( i = cff->num_subfonts; i > 0; i-- ) { CFF_FontRecDict sub = &cff->subfonts[i - 1]->font_dict; CFF_FontRecDict top = &cff->top_font.font_dict; FT_Matrix* matrix; FT_Vector* offset; FT_ULong* upm; FT_Fixed temp; if ( sub->has_font_matrix ) { FT_Long scaling; /* if we have a top-level matrix, */ /* concatenate the subfont matrix */ if ( top->has_font_matrix ) { if ( top->units_per_em > 1 && sub->units_per_em > 1 ) scaling = (FT_Long)FT_MIN( top->units_per_em, sub->units_per_em ); else scaling = 1; FT_Matrix_Multiply_Scaled( &top->font_matrix, &sub->font_matrix, scaling ); FT_Vector_Transform_Scaled( &sub->font_offset, &top->font_matrix, scaling ); sub->units_per_em = (FT_ULong) FT_MulDiv( (FT_Long)sub->units_per_em, (FT_Long)top->units_per_em, scaling ); } } else { sub->font_matrix = top->font_matrix; sub->font_offset = top->font_offset; sub->units_per_em = top->units_per_em; } matrix = &sub->font_matrix; offset = &sub->font_offset; upm = &sub->units_per_em; temp = matrix->yy ? FT_ABS( matrix->yy ) : FT_ABS( matrix->yx ); if ( temp != 0x10000L ) { *upm = (FT_ULong)FT_DivFix( (FT_Long)*upm, temp ); matrix->xx = FT_DivFix( matrix->xx, temp ); matrix->yx = FT_DivFix( matrix->yx, temp ); matrix->xy = FT_DivFix( matrix->xy, temp ); matrix->yy = FT_DivFix( matrix->yy, temp ); offset->x = FT_DivFix( offset->x, temp ); offset->y = FT_DivFix( offset->y, temp ); } offset->x >>= 16; offset->y >>= 16; } if ( pure_cff ) { char* style_name = NULL; /* set up num_faces */ cffface->num_faces = (FT_Long)cff->num_faces; /* compute number of glyphs */ if ( dict->cid_registry != 0xFFFFU ) cffface->num_glyphs = (FT_Long)( cff->charset.max_cid + 1 ); else cffface->num_glyphs = (FT_Long)cff->charstrings_index.count; /* set global bbox, as well as EM size */ cffface->bbox.xMin = dict->font_bbox.xMin >> 16; cffface->bbox.yMin = dict->font_bbox.yMin >> 16; /* no `U' suffix here to 0xFFFF! */ cffface->bbox.xMax = ( dict->font_bbox.xMax + 0xFFFF ) >> 16; cffface->bbox.yMax = ( dict->font_bbox.yMax + 0xFFFF ) >> 16; cffface->units_per_EM = (FT_UShort)( dict->units_per_em ); cffface->ascender = (FT_Short)( cffface->bbox.yMax ); cffface->descender = (FT_Short)( cffface->bbox.yMin ); cffface->height = (FT_Short)( ( cffface->units_per_EM * 12 ) / 10 ); if ( cffface->height < cffface->ascender - cffface->descender ) cffface->height = (FT_Short)( cffface->ascender - cffface->descender ); cffface->underline_position = (FT_Short)( dict->underline_position >> 16 ); cffface->underline_thickness = (FT_Short)( dict->underline_thickness >> 16 ); /* retrieve font family & style name */ if ( dict->family_name ) { char* family_name; family_name = cff_index_get_sid_string( cff, dict->family_name ); if ( family_name ) cffface->family_name = cff_strcpy( memory, family_name ); } if ( !cffface->family_name ) { cffface->family_name = cff_index_get_name( cff, (FT_UInt)( face_index & 0xFFFF ) ); if ( cffface->family_name ) remove_subset_prefix( cffface->family_name ); } if ( cffface->family_name ) { char* full = cff_index_get_sid_string( cff, dict->full_name ); char* fullp = full; char* family = cffface->family_name; /* We try to extract the style name from the full name. */ /* We need to ignore spaces and dashes during the search. */ if ( full && family ) { while ( *fullp ) { /* skip common characters at the start of both strings */ if ( *fullp == *family ) { family++; fullp++; continue; } /* ignore spaces and dashes in full name during comparison */ if ( *fullp == ' ' || *fullp == '-' ) { fullp++; continue; } /* ignore spaces and dashes in family name during comparison */ if ( *family == ' ' || *family == '-' ) { family++; continue; } if ( !*family && *fullp ) { /* The full name begins with the same characters as the */ /* family name, with spaces and dashes removed. In this */ /* case, the remaining string in `fullp' will be used as */ /* the style name. */ style_name = cff_strcpy( memory, fullp ); /* remove the style part from the family name (if present) */ if ( style_name ) remove_style( cffface->family_name, style_name ); } break; } } } else { char *cid_font_name = cff_index_get_sid_string( cff, dict->cid_font_name ); /* do we have a `/FontName' for a CID-keyed font? */ if ( cid_font_name ) cffface->family_name = cff_strcpy( memory, cid_font_name ); } if ( style_name ) cffface->style_name = style_name; else /* assume "Regular" style if we don't know better */ cffface->style_name = cff_strcpy( memory, "Regular" ); /******************************************************************** * * Compute face flags. */ flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */ FT_FACE_FLAG_HORIZONTAL | /* horizontal data */ FT_FACE_FLAG_HINTER; /* has native hinter */ if ( sfnt_format ) flags |= FT_FACE_FLAG_SFNT; /* fixed width font? */ if ( dict->is_fixed_pitch ) flags |= FT_FACE_FLAG_FIXED_WIDTH; /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */ #if 0 /* kerning available? */ if ( face->kern_pairs ) flags |= FT_FACE_FLAG_KERNING; #endif cffface->face_flags |= flags; /******************************************************************** * * Compute style flags. */ flags = 0; if ( dict->italic_angle ) flags |= FT_STYLE_FLAG_ITALIC; { char *weight = cff_index_get_sid_string( cff, dict->weight ); if ( weight ) if ( !ft_strcmp( weight, "Bold" ) || !ft_strcmp( weight, "Black" ) ) flags |= FT_STYLE_FLAG_BOLD; } /* double check */ if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name ) if ( !ft_strncmp( cffface->style_name, "Bold", 4 ) || !ft_strncmp( cffface->style_name, "Black", 5 ) ) flags |= FT_STYLE_FLAG_BOLD; cffface->style_flags = flags; } #ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES /* CID-keyed CFF or CFF2 fonts don't have glyph names -- the SFNT */ /* loader has unset this flag because of the 3.0 `post' table. */ if ( dict->cid_registry == 0xFFFFU && !cff2 ) cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES; #endif if ( dict->cid_registry != 0xFFFFU && pure_cff ) cffface->face_flags |= FT_FACE_FLAG_CID_KEYED; /******************************************************************** * * Compute char maps. */ /* Try to synthesize a Unicode charmap if there is none available */ /* already. If an OpenType font contains a Unicode "cmap", we */ /* will use it, whatever be in the CFF part of the file. */ { FT_CharMapRec cmaprec; FT_CharMap cmap; FT_Int nn; CFF_Encoding encoding = &cff->encoding; for ( nn = 0; nn < cffface->num_charmaps; nn++ ) { cmap = cffface->charmaps[nn]; /* Windows Unicode? */ if ( cmap->platform_id == TT_PLATFORM_MICROSOFT && cmap->encoding_id == TT_MS_ID_UNICODE_CS ) goto Skip_Unicode; /* Apple Unicode platform id? */ if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE ) goto Skip_Unicode; /* Apple Unicode */ } /* since CID-keyed fonts don't contain glyph names, we can't */ /* construct a cmap */ if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU ) goto Exit; /* we didn't find a Unicode charmap -- synthesize one */ cmaprec.face = cffface; cmaprec.platform_id = TT_PLATFORM_MICROSOFT; cmaprec.encoding_id = TT_MS_ID_UNICODE_CS; cmaprec.encoding = FT_ENCODING_UNICODE; nn = cffface->num_charmaps; error = FT_CMap_New( &cff_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; /* if no Unicode charmap was previously selected, select this one */ if ( !cffface->charmap && nn != cffface->num_charmaps ) cffface->charmap = cffface->charmaps[nn]; Skip_Unicode: if ( encoding->count > 0 ) { FT_CMap_Class clazz; cmaprec.face = cffface; cmaprec.platform_id = TT_PLATFORM_ADOBE; /* Adobe platform id */ if ( encoding->offset == 0 ) { cmaprec.encoding_id = TT_ADOBE_ID_STANDARD; cmaprec.encoding = FT_ENCODING_ADOBE_STANDARD; clazz = &cff_cmap_encoding_class_rec; } else if ( encoding->offset == 1 ) { cmaprec.encoding_id = TT_ADOBE_ID_EXPERT; cmaprec.encoding = FT_ENCODING_ADOBE_EXPERT; clazz = &cff_cmap_encoding_class_rec; } else { cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM; cmaprec.encoding = FT_ENCODING_ADOBE_CUSTOM; clazz = &cff_cmap_encoding_class_rec; } error = FT_CMap_New( clazz, NULL, &cmaprec, NULL ); } } } Exit: return error; } FT_LOCAL_DEF( void ) cff_face_done( FT_Face cffface ) /* CFF_Face */ { CFF_Face face = (CFF_Face)cffface; FT_Memory memory; SFNT_Service sfnt; if ( !face ) return; memory = cffface->memory; sfnt = (SFNT_Service)face->sfnt; if ( sfnt ) sfnt->done_face( face ); { CFF_Font cff = (CFF_Font)face->extra.data; if ( cff ) { cff_font_done( cff ); FT_FREE( face->extra.data ); } } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT cff_done_blend( face ); face->blend = NULL; #endif } FT_LOCAL_DEF( FT_Error ) cff_driver_init( FT_Module module ) /* CFF_Driver */ { PS_Driver driver = (PS_Driver)module; FT_UInt32 seed; /* set default property values, cf. `ftcffdrv.h' */ driver->hinting_engine = FT_HINTING_ADOBE; driver->no_stem_darkening = TRUE; driver->darken_params[0] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1; driver->darken_params[1] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1; driver->darken_params[2] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2; driver->darken_params[3] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2; driver->darken_params[4] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3; driver->darken_params[5] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3; driver->darken_params[6] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4; driver->darken_params[7] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4; /* compute random seed from some memory addresses */ seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^ (FT_Offset)(char*)&module ^ (FT_Offset)(char*)module->memory ); seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 ); driver->random_seed = (FT_Int32)seed; if ( driver->random_seed < 0 ) driver->random_seed = -driver->random_seed; else if ( driver->random_seed == 0 ) driver->random_seed = 123456789; return FT_Err_Ok; } FT_LOCAL_DEF( void ) cff_driver_done( FT_Module module ) /* CFF_Driver */ { FT_UNUSED( module ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffobjs.c
C++
gpl-3.0
35,915
/**************************************************************************** * * cffobjs.h * * OpenType objects manager (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 CFFOBJS_H_ #define CFFOBJS_H_ FT_BEGIN_HEADER FT_LOCAL( FT_Error ) cff_size_init( FT_Size size ); /* CFF_Size */ FT_LOCAL( void ) cff_size_done( FT_Size size ); /* CFF_Size */ FT_LOCAL( FT_Error ) cff_size_request( FT_Size size, FT_Size_Request req ); #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_LOCAL( FT_Error ) cff_size_select( FT_Size size, FT_ULong strike_index ); #endif FT_LOCAL( void ) cff_slot_done( FT_GlyphSlot slot ); FT_LOCAL( FT_Error ) cff_slot_init( FT_GlyphSlot slot ); /************************************************************************** * * Face functions */ FT_LOCAL( FT_Error ) cff_face_init( FT_Stream stream, FT_Face face, /* CFF_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ); FT_LOCAL( void ) cff_face_done( FT_Face face ); /* CFF_Face */ /************************************************************************** * * Driver functions */ FT_LOCAL( FT_Error ) cff_driver_init( FT_Module module ); /* PS_Driver */ FT_LOCAL( void ) cff_driver_done( FT_Module module ); /* PS_Driver */ FT_END_HEADER #endif /* CFFOBJS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffobjs.h
C++
gpl-3.0
1,940
/**************************************************************************** * * cffparse.c * * CFF token stream parser (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 "cffparse.h" #include <freetype/internal/ftstream.h> #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftcalc.h> #include <freetype/internal/psaux.h> #include <freetype/ftlist.h> #include "cfferrs.h" #include "cffload.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 cffparse FT_LOCAL_DEF( FT_Error ) cff_parser_init( CFF_Parser parser, FT_UInt code, void* object, FT_Library library, FT_UInt stackSize, FT_UShort num_designs, FT_UShort num_axes ) { FT_Memory memory = library->memory; /* for FT_NEW_ARRAY */ FT_Error error; /* for FT_NEW_ARRAY */ FT_ZERO( parser ); #if 0 parser->top = parser->stack; #endif parser->object_code = code; parser->object = object; parser->library = library; parser->num_designs = num_designs; parser->num_axes = num_axes; /* allocate the stack buffer */ if ( FT_QNEW_ARRAY( parser->stack, stackSize ) ) { FT_FREE( parser->stack ); goto Exit; } parser->stackSize = stackSize; parser->top = parser->stack; /* empty stack */ Exit: return error; } #ifdef CFF_CONFIG_OPTION_OLD_ENGINE static void finalize_t2_strings( FT_Memory memory, void* data, void* user ) { CFF_T2_String t2 = (CFF_T2_String)data; FT_UNUSED( user ); memory->free( memory, t2->start ); memory->free( memory, data ); } #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ FT_LOCAL_DEF( void ) cff_parser_done( CFF_Parser parser ) { FT_Memory memory = parser->library->memory; /* for FT_FREE */ FT_FREE( parser->stack ); #ifdef CFF_CONFIG_OPTION_OLD_ENGINE FT_List_Finalize( &parser->t2_strings, finalize_t2_strings, memory, NULL ); #endif } /* Assuming `first >= last'. */ static FT_Error cff_parser_within_limits( CFF_Parser parser, FT_Byte* first, FT_Byte* last ) { #ifndef CFF_CONFIG_OPTION_OLD_ENGINE /* Fast path for regular FreeType builds with the "new" engine; */ /* `first >= parser->start' can be assumed. */ FT_UNUSED( first ); return last < parser->limit ? FT_Err_Ok : FT_THROW( Invalid_Argument ); #else /* CFF_CONFIG_OPTION_OLD_ENGINE */ FT_ListNode node; if ( first >= parser->start && last < parser->limit ) return FT_Err_Ok; node = parser->t2_strings.head; while ( node ) { CFF_T2_String t2 = (CFF_T2_String)node->data; if ( first >= t2->start && last < t2->limit ) return FT_Err_Ok; node = node->next; } return FT_THROW( Invalid_Argument ); #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ } /* read an integer */ static FT_Long cff_parse_integer( CFF_Parser parser, FT_Byte* start ) { FT_Byte* p = start; FT_Int v = *p++; FT_Long val = 0; if ( v == 28 ) { if ( cff_parser_within_limits( parser, p, p + 1 ) ) goto Bad; val = (FT_Short)( ( (FT_UShort)p[0] << 8 ) | p[1] ); } else if ( v == 29 ) { if ( cff_parser_within_limits( parser, p, p + 3 ) ) goto Bad; val = (FT_Long)( ( (FT_ULong)p[0] << 24 ) | ( (FT_ULong)p[1] << 16 ) | ( (FT_ULong)p[2] << 8 ) | (FT_ULong)p[3] ); } else if ( v < 247 ) { val = v - 139; } else if ( v < 251 ) { if ( cff_parser_within_limits( parser, p, p ) ) goto Bad; val = ( v - 247 ) * 256 + p[0] + 108; } else { if ( cff_parser_within_limits( parser, p, p ) ) goto Bad; val = -( v - 251 ) * 256 - p[0] - 108; } Exit: return val; Bad: val = 0; FT_TRACE4(( "!!!END OF DATA:!!!" )); goto Exit; } static const FT_Long power_tens[] = { 1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L }; /* maximum values allowed for multiplying */ /* with the corresponding `power_tens' element */ static const FT_Long power_ten_limits[] = { FT_LONG_MAX / 1L, FT_LONG_MAX / 10L, FT_LONG_MAX / 100L, FT_LONG_MAX / 1000L, FT_LONG_MAX / 10000L, FT_LONG_MAX / 100000L, FT_LONG_MAX / 1000000L, FT_LONG_MAX / 10000000L, FT_LONG_MAX / 100000000L, FT_LONG_MAX / 1000000000L, }; /* read a real */ static FT_Fixed cff_parse_real( CFF_Parser parser, FT_Byte* start, FT_Long power_ten, FT_Long* scaling ) { FT_Byte* p = start; FT_Int nib; FT_UInt phase; FT_Long result, number, exponent; FT_Int sign = 0, exponent_sign = 0, have_overflow = 0; FT_Long exponent_add, integer_length, fraction_length; if ( scaling ) *scaling = 0; result = 0; number = 0; exponent = 0; exponent_add = 0; integer_length = 0; fraction_length = 0; /* First of all, read the integer part. */ phase = 4; for (;;) { /* If we entered this iteration with phase == 4, we need to */ /* read a new byte. This also skips past the initial 0x1E. */ if ( phase ) { p++; /* Make sure we don't read past the end. */ if ( cff_parser_within_limits( parser, p, p ) ) goto Bad; } /* Get the nibble. */ nib = (FT_Int)( p[0] >> phase ) & 0xF; phase = 4 - phase; if ( nib == 0xE ) sign = 1; else if ( nib > 9 ) break; else { /* Increase exponent if we can't add the digit. */ if ( number >= 0xCCCCCCCL ) exponent_add++; /* Skip leading zeros. */ else if ( nib || number ) { integer_length++; number = number * 10 + nib; } } } /* Read fraction part, if any. */ if ( nib == 0xA ) for (;;) { /* If we entered this iteration with phase == 4, we need */ /* to read a new byte. */ if ( phase ) { p++; /* Make sure we don't read past the end. */ if ( cff_parser_within_limits( parser, p, p ) ) goto Bad; } /* Get the nibble. */ nib = ( p[0] >> phase ) & 0xF; phase = 4 - phase; if ( nib >= 10 ) break; /* Skip leading zeros if possible. */ if ( !nib && !number ) exponent_add--; /* Only add digit if we don't overflow. */ else if ( number < 0xCCCCCCCL && fraction_length < 9 ) { fraction_length++; number = number * 10 + nib; } } /* Read exponent, if any. */ if ( nib == 12 ) { exponent_sign = 1; nib = 11; } if ( nib == 11 ) { for (;;) { /* If we entered this iteration with phase == 4, */ /* we need to read a new byte. */ if ( phase ) { p++; /* Make sure we don't read past the end. */ if ( cff_parser_within_limits( parser, p, p ) ) goto Bad; } /* Get the nibble. */ nib = ( p[0] >> phase ) & 0xF; phase = 4 - phase; if ( nib >= 10 ) break; /* Arbitrarily limit exponent. */ if ( exponent > 1000 ) have_overflow = 1; else exponent = exponent * 10 + nib; } if ( exponent_sign ) exponent = -exponent; } if ( !number ) goto Exit; if ( have_overflow ) { if ( exponent_sign ) goto Underflow; else goto Overflow; } /* We don't check `power_ten' and `exponent_add'. */ exponent += power_ten + exponent_add; if ( scaling ) { /* Only use `fraction_length'. */ fraction_length += integer_length; exponent += integer_length; if ( fraction_length <= 5 ) { if ( number > 0x7FFFL ) { result = FT_DivFix( number, 10 ); *scaling = exponent - fraction_length + 1; } else { if ( exponent > 0 ) { FT_Long new_fraction_length, shift; /* Make `scaling' as small as possible. */ new_fraction_length = FT_MIN( exponent, 5 ); shift = new_fraction_length - fraction_length; if ( shift > 0 ) { exponent -= new_fraction_length; number *= power_tens[shift]; if ( number > 0x7FFFL ) { number /= 10; exponent += 1; } } else exponent -= fraction_length; } else exponent -= fraction_length; result = (FT_Long)( (FT_ULong)number << 16 ); *scaling = exponent; } } else { if ( ( number / power_tens[fraction_length - 5] ) > 0x7FFFL ) { result = FT_DivFix( number, power_tens[fraction_length - 4] ); *scaling = exponent - 4; } else { result = FT_DivFix( number, power_tens[fraction_length - 5] ); *scaling = exponent - 5; } } } else { integer_length += exponent; fraction_length -= exponent; if ( integer_length > 5 ) goto Overflow; if ( integer_length < -5 ) goto Underflow; /* Remove non-significant digits. */ if ( integer_length < 0 ) { number /= power_tens[-integer_length]; fraction_length += integer_length; } /* this can only happen if exponent was non-zero */ if ( fraction_length == 10 ) { number /= 10; fraction_length -= 1; } /* Convert into 16.16 format. */ if ( fraction_length > 0 ) { if ( ( number / power_tens[fraction_length] ) > 0x7FFFL ) goto Exit; result = FT_DivFix( number, power_tens[fraction_length] ); } else { number *= power_tens[-fraction_length]; if ( number > 0x7FFFL ) goto Overflow; result = (FT_Long)( (FT_ULong)number << 16 ); } } Exit: if ( sign ) result = -result; return result; Overflow: result = 0x7FFFFFFFL; FT_TRACE4(( "!!!OVERFLOW:!!!" )); goto Exit; Underflow: result = 0; FT_TRACE4(( "!!!UNDERFLOW:!!!" )); goto Exit; Bad: result = 0; FT_TRACE4(( "!!!END OF DATA:!!!" )); goto Exit; } /* read a number, either integer or real */ FT_LOCAL_DEF( FT_Long ) cff_parse_num( CFF_Parser parser, FT_Byte** d ) { if ( **d == 30 ) { /* binary-coded decimal is truncated to integer */ return cff_parse_real( parser, *d, 0, NULL ) >> 16; } else if ( **d == 255 ) { /* 16.16 fixed point is used internally for CFF2 blend results. */ /* Since these are trusted values, a limit check is not needed. */ /* After the 255, 4 bytes give the number. */ /* The blend value is converted to integer, with rounding; */ /* due to the right-shift we don't need the lowest byte. */ #if 0 return (FT_Short)( ( ( ( (FT_UInt32)*( d[0] + 1 ) << 24 ) | ( (FT_UInt32)*( d[0] + 2 ) << 16 ) | ( (FT_UInt32)*( d[0] + 3 ) << 8 ) | (FT_UInt32)*( d[0] + 4 ) ) + 0x8000U ) >> 16 ); #else return (FT_Short)( ( ( ( (FT_UInt32)*( d[0] + 1 ) << 16 ) | ( (FT_UInt32)*( d[0] + 2 ) << 8 ) | (FT_UInt32)*( d[0] + 3 ) ) + 0x80U ) >> 8 ); #endif } else return cff_parse_integer( parser, *d ); } /* read a floating point number, either integer or real */ static FT_Fixed do_fixed( CFF_Parser parser, FT_Byte** d, FT_Long scaling ) { if ( **d == 30 ) return cff_parse_real( parser, *d, scaling, NULL ); else { FT_Long val = cff_parse_integer( parser, *d ); if ( scaling ) { if ( FT_ABS( val ) > power_ten_limits[scaling] ) { val = val > 0 ? 0x7FFFFFFFL : -0x7FFFFFFFL; goto Overflow; } val *= power_tens[scaling]; } if ( val > 0x7FFF ) { val = 0x7FFFFFFFL; goto Overflow; } else if ( val < -0x7FFF ) { val = -0x7FFFFFFFL; goto Overflow; } return (FT_Long)( (FT_ULong)val << 16 ); Overflow: FT_TRACE4(( "!!!OVERFLOW:!!!" )); return val; } } /* read a floating point number, either integer or real */ static FT_Fixed cff_parse_fixed( CFF_Parser parser, FT_Byte** d ) { return do_fixed( parser, d, 0 ); } /* read a floating point number, either integer or real, */ /* but return `10^scaling' times the number read in */ static FT_Fixed cff_parse_fixed_scaled( CFF_Parser parser, FT_Byte** d, FT_Long scaling ) { return do_fixed( parser, d, scaling ); } /* read a floating point number, either integer or real, */ /* and return it as precise as possible -- `scaling' returns */ /* the scaling factor (as a power of 10) */ static FT_Fixed cff_parse_fixed_dynamic( CFF_Parser parser, FT_Byte** d, FT_Long* scaling ) { FT_ASSERT( scaling ); if ( **d == 30 ) return cff_parse_real( parser, *d, 0, scaling ); else { FT_Long number; FT_Int integer_length; number = cff_parse_integer( parser, d[0] ); if ( number > 0x7FFFL ) { for ( integer_length = 5; integer_length < 10; integer_length++ ) if ( number < power_tens[integer_length] ) break; if ( ( number / power_tens[integer_length - 5] ) > 0x7FFFL ) { *scaling = integer_length - 4; return FT_DivFix( number, power_tens[integer_length - 4] ); } else { *scaling = integer_length - 5; return FT_DivFix( number, power_tens[integer_length - 5] ); } } else { *scaling = 0; return (FT_Long)( (FT_ULong)number << 16 ); } } } static FT_Error cff_parse_font_matrix( CFF_Parser parser ) { CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_Matrix* matrix = &dict->font_matrix; FT_Vector* offset = &dict->font_offset; FT_ULong* upm = &dict->units_per_em; FT_Byte** data = parser->stack; if ( parser->top >= parser->stack + 6 ) { FT_Fixed values[6]; FT_Long scalings[6]; FT_Long min_scaling, max_scaling; int i; dict->has_font_matrix = TRUE; /* We expect a well-formed font matrix, this is, the matrix elements */ /* `xx' and `yy' are of approximately the same magnitude. To avoid */ /* loss of precision, we use the magnitude of the largest matrix */ /* element to scale all other elements. The scaling factor is then */ /* contained in the `units_per_em' value. */ max_scaling = FT_LONG_MIN; min_scaling = FT_LONG_MAX; for ( i = 0; i < 6; i++ ) { values[i] = cff_parse_fixed_dynamic( parser, data++, &scalings[i] ); if ( values[i] ) { if ( scalings[i] > max_scaling ) max_scaling = scalings[i]; if ( scalings[i] < min_scaling ) min_scaling = scalings[i]; } } if ( max_scaling < -9 || max_scaling > 0 || ( max_scaling - min_scaling ) < 0 || ( max_scaling - min_scaling ) > 9 ) { FT_TRACE1(( "cff_parse_font_matrix:" " strange scaling values (minimum %ld, maximum %ld),\n", min_scaling, max_scaling )); FT_TRACE1(( " " " using default matrix\n" )); goto Unlikely; } for ( i = 0; i < 6; i++ ) { FT_Fixed value = values[i]; FT_Long divisor, half_divisor; if ( !value ) continue; divisor = power_tens[max_scaling - scalings[i]]; half_divisor = divisor >> 1; if ( value < 0 ) { if ( FT_LONG_MIN + half_divisor < value ) values[i] = ( value - half_divisor ) / divisor; else values[i] = FT_LONG_MIN / divisor; } else { if ( FT_LONG_MAX - half_divisor > value ) values[i] = ( value + half_divisor ) / divisor; else values[i] = FT_LONG_MAX / divisor; } } matrix->xx = values[0]; matrix->yx = values[1]; matrix->xy = values[2]; matrix->yy = values[3]; offset->x = values[4]; offset->y = values[5]; *upm = (FT_ULong)power_tens[-max_scaling]; FT_TRACE4(( " [%f %f %f %f %f %f]\n", (double)matrix->xx / *upm / 65536, (double)matrix->xy / *upm / 65536, (double)matrix->yx / *upm / 65536, (double)matrix->yy / *upm / 65536, (double)offset->x / *upm / 65536, (double)offset->y / *upm / 65536 )); if ( !FT_Matrix_Check( matrix ) ) { FT_TRACE1(( "cff_parse_font_matrix:" " degenerate values, using default matrix\n" )); goto Unlikely; } return FT_Err_Ok; } else return FT_THROW( Stack_Underflow ); Unlikely: /* Return default matrix in case of unlikely values. */ matrix->xx = 0x10000L; matrix->yx = 0; matrix->xy = 0; matrix->yy = 0x10000L; offset->x = 0; offset->y = 0; *upm = 1; return FT_Err_Ok; } static FT_Error cff_parse_font_bbox( CFF_Parser parser ) { CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_BBox* bbox = &dict->font_bbox; FT_Byte** data = parser->stack; FT_Error error; error = FT_ERR( Stack_Underflow ); if ( parser->top >= parser->stack + 4 ) { bbox->xMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) ); bbox->yMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) ); bbox->xMax = FT_RoundFix( cff_parse_fixed( parser, data++ ) ); bbox->yMax = FT_RoundFix( cff_parse_fixed( parser, data ) ); error = FT_Err_Ok; FT_TRACE4(( " [%ld %ld %ld %ld]\n", bbox->xMin / 65536, bbox->yMin / 65536, bbox->xMax / 65536, bbox->yMax / 65536 )); } return error; } static FT_Error cff_parse_private_dict( CFF_Parser parser ) { CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_Byte** data = parser->stack; FT_Error error; error = FT_ERR( Stack_Underflow ); if ( parser->top >= parser->stack + 2 ) { FT_Long tmp; tmp = cff_parse_num( parser, data++ ); if ( tmp < 0 ) { FT_ERROR(( "cff_parse_private_dict: Invalid dictionary size\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } dict->private_size = (FT_ULong)tmp; tmp = cff_parse_num( parser, data ); if ( tmp < 0 ) { FT_ERROR(( "cff_parse_private_dict: Invalid dictionary offset\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } dict->private_offset = (FT_ULong)tmp; FT_TRACE4(( " %lu %lu\n", dict->private_size, dict->private_offset )); error = FT_Err_Ok; } Fail: return error; } /* The `MultipleMaster' operator comes before any */ /* top DICT operators that contain T2 charstrings. */ static FT_Error cff_parse_multiple_master( CFF_Parser parser ) { CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_Error error; #ifdef FT_DEBUG_LEVEL_TRACE /* beautify tracing message */ if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] < 4 ) FT_TRACE1(( "Multiple Master CFFs not supported yet," " handling first master design only\n" )); else FT_TRACE1(( " (not supported yet," " handling first master design only)\n" )); #endif error = FT_ERR( Stack_Underflow ); /* currently, we handle only the first argument */ if ( parser->top >= parser->stack + 5 ) { FT_Long num_designs = cff_parse_num( parser, parser->stack ); if ( num_designs > 16 || num_designs < 2 ) { FT_ERROR(( "cff_parse_multiple_master:" " Invalid number of designs\n" )); error = FT_THROW( Invalid_File_Format ); } else { dict->num_designs = (FT_UShort)num_designs; dict->num_axes = (FT_UShort)( parser->top - parser->stack - 4 ); parser->num_designs = dict->num_designs; parser->num_axes = dict->num_axes; error = FT_Err_Ok; } } return error; } static FT_Error cff_parse_cid_ros( CFF_Parser parser ) { CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_Byte** data = parser->stack; FT_Error error; error = FT_ERR( Stack_Underflow ); if ( parser->top >= parser->stack + 3 ) { dict->cid_registry = (FT_UInt)cff_parse_num( parser, data++ ); dict->cid_ordering = (FT_UInt)cff_parse_num( parser, data++ ); if ( **data == 30 ) FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" )); dict->cid_supplement = cff_parse_num( parser, data ); if ( dict->cid_supplement < 0 ) FT_TRACE1(( "cff_parse_cid_ros: negative supplement %ld is found\n", dict->cid_supplement )); error = FT_Err_Ok; FT_TRACE4(( " %d %d %ld\n", dict->cid_registry, dict->cid_ordering, dict->cid_supplement )); } return error; } static FT_Error cff_parse_vsindex( CFF_Parser parser ) { /* vsindex operator can only be used in a Private DICT */ CFF_Private priv = (CFF_Private)parser->object; FT_Byte** data = parser->stack; CFF_Blend blend; FT_Error error; if ( !priv || !priv->subfont ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } blend = &priv->subfont->blend; if ( blend->usedBV ) { FT_ERROR(( " cff_parse_vsindex: vsindex not allowed after blend\n" )); error = FT_THROW( Syntax_Error ); goto Exit; } priv->vsindex = (FT_UInt)cff_parse_num( parser, data++ ); FT_TRACE4(( " %d\n", priv->vsindex )); error = FT_Err_Ok; Exit: return error; } static FT_Error cff_parse_blend( CFF_Parser parser ) { /* blend operator can only be used in a Private DICT */ CFF_Private priv = (CFF_Private)parser->object; CFF_SubFont subFont; CFF_Blend blend; FT_UInt numBlends; FT_Error error; if ( !priv || !priv->subfont ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } subFont = priv->subfont; blend = &subFont->blend; if ( cff_blend_check_vector( blend, priv->vsindex, subFont->lenNDV, subFont->NDV ) ) { error = cff_blend_build_vector( blend, priv->vsindex, subFont->lenNDV, subFont->NDV ); if ( error ) goto Exit; } numBlends = (FT_UInt)cff_parse_num( parser, parser->top - 1 ); if ( numBlends > parser->stackSize ) { FT_ERROR(( "cff_parse_blend: Invalid number of blends\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } FT_TRACE4(( " %d value%s blended\n", numBlends, numBlends == 1 ? "" : "s" )); error = cff_blend_doBlend( subFont, parser, numBlends ); blend->usedBV = TRUE; Exit: return error; } /* maxstack operator increases parser and operand stacks for CFF2 */ static FT_Error cff_parse_maxstack( CFF_Parser parser ) { /* maxstack operator can only be used in a Top DICT */ CFF_FontRecDict dict = (CFF_FontRecDict)parser->object; FT_Byte** data = parser->stack; FT_Error error = FT_Err_Ok; if ( !dict ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } dict->maxstack = (FT_UInt)cff_parse_num( parser, data++ ); if ( dict->maxstack > CFF2_MAX_STACK ) dict->maxstack = CFF2_MAX_STACK; if ( dict->maxstack < CFF2_DEFAULT_STACK ) dict->maxstack = CFF2_DEFAULT_STACK; FT_TRACE4(( " %d\n", dict->maxstack )); Exit: return error; } #define CFF_FIELD_NUM( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_num ) #define CFF_FIELD_FIXED( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_fixed ) #define CFF_FIELD_FIXED_1000( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_fixed_thousand ) #define CFF_FIELD_STRING( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_string ) #define CFF_FIELD_BOOL( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_bool ) #undef CFF_FIELD #undef CFF_FIELD_DELTA #ifndef FT_DEBUG_LEVEL_TRACE #define CFF_FIELD_CALLBACK( code, name, id ) \ { \ cff_kind_callback, \ code | CFFCODE, \ 0, 0, \ cff_parse_ ## name, \ 0, 0 \ }, #define CFF_FIELD_BLEND( code, id ) \ { \ cff_kind_blend, \ code | CFFCODE, \ 0, 0, \ cff_parse_blend, \ 0, 0 \ }, #define CFF_FIELD( code, name, id, kind ) \ { \ kind, \ code | CFFCODE, \ FT_FIELD_OFFSET( name ), \ FT_FIELD_SIZE( name ), \ 0, 0, 0 \ }, #define CFF_FIELD_DELTA( code, name, max, id ) \ { \ cff_kind_delta, \ code | CFFCODE, \ FT_FIELD_OFFSET( name ), \ FT_FIELD_SIZE_DELTA( name ), \ 0, \ max, \ FT_FIELD_OFFSET( num_ ## name ) \ }, static const CFF_Field_Handler cff_field_handlers[] = { #include "cfftoken.h" { 0, 0, 0, 0, 0, 0, 0 } }; #else /* FT_DEBUG_LEVEL_TRACE */ #define CFF_FIELD_CALLBACK( code, name, id ) \ { \ cff_kind_callback, \ code | CFFCODE, \ 0, 0, \ cff_parse_ ## name, \ 0, 0, \ id \ }, #define CFF_FIELD_BLEND( code, id ) \ { \ cff_kind_blend, \ code | CFFCODE, \ 0, 0, \ cff_parse_blend, \ 0, 0, \ id \ }, #define CFF_FIELD( code, name, id, kind ) \ { \ kind, \ code | CFFCODE, \ FT_FIELD_OFFSET( name ), \ FT_FIELD_SIZE( name ), \ 0, 0, 0, \ id \ }, #define CFF_FIELD_DELTA( code, name, max, id ) \ { \ cff_kind_delta, \ code | CFFCODE, \ FT_FIELD_OFFSET( name ), \ FT_FIELD_SIZE_DELTA( name ), \ 0, \ max, \ FT_FIELD_OFFSET( num_ ## name ), \ id \ }, static const CFF_Field_Handler cff_field_handlers[] = { #include "cfftoken.h" { 0, 0, 0, 0, 0, 0, 0, 0 } }; #endif /* FT_DEBUG_LEVEL_TRACE */ FT_LOCAL_DEF( FT_Error ) cff_parser_run( CFF_Parser parser, FT_Byte* start, FT_Byte* limit ) { FT_Byte* p = start; FT_Error error = FT_Err_Ok; #ifdef CFF_CONFIG_OPTION_OLD_ENGINE PSAux_Service psaux; FT_Library library = parser->library; FT_Memory memory = library->memory; #endif parser->top = parser->stack; parser->start = start; parser->limit = limit; parser->cursor = start; while ( p < limit ) { FT_UInt v = *p; /* Opcode 31 is legacy MM T2 operator, not a number. */ /* Opcode 255 is reserved and should not appear in fonts; */ /* it is used internally for CFF2 blends. */ if ( v >= 27 && v != 31 && v != 255 ) { /* it's a number; we will push its position on the stack */ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize ) goto Stack_Overflow; *parser->top++ = p; /* now, skip it */ if ( v == 30 ) { /* skip real number */ p++; for (;;) { /* An unterminated floating point number at the */ /* end of a dictionary is invalid but harmless. */ if ( p >= limit ) goto Exit; v = p[0] >> 4; if ( v == 15 ) break; v = p[0] & 0xF; if ( v == 15 ) break; p++; } } else if ( v == 28 ) p += 2; else if ( v == 29 ) p += 4; else if ( v > 246 ) p += 1; } #ifdef CFF_CONFIG_OPTION_OLD_ENGINE else if ( v == 31 ) { /* a Type 2 charstring */ CFF_Decoder decoder; CFF_FontRec cff_rec; FT_Byte* charstring_base; FT_ULong charstring_len; FT_Fixed* stack; FT_ListNode node; CFF_T2_String t2; FT_Fixed t2_size; FT_Byte* q; charstring_base = ++p; /* search `endchar' operator */ for (;;) { if ( p >= limit ) goto Exit; if ( *p == 14 ) break; p++; } charstring_len = (FT_ULong)( p - charstring_base ) + 1; /* construct CFF_Decoder object */ FT_ZERO( &decoder ); FT_ZERO( &cff_rec ); cff_rec.top_font.font_dict.num_designs = parser->num_designs; cff_rec.top_font.font_dict.num_axes = parser->num_axes; decoder.cff = &cff_rec; psaux = (PSAux_Service)FT_Get_Module_Interface( library, "psaux" ); if ( !psaux ) { FT_ERROR(( "cff_parser_run: cannot access `psaux' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } error = psaux->cff_decoder_funcs->parse_charstrings_old( &decoder, charstring_base, charstring_len, 1 ); if ( error ) goto Exit; /* Now copy the stack data in the temporary decoder object, */ /* converting it back to charstring number representations */ /* (this is ugly, I know). */ node = (FT_ListNode)memory->alloc( memory, sizeof ( FT_ListNodeRec ) ); if ( !node ) goto Out_Of_Memory_Error; FT_List_Add( &parser->t2_strings, node ); t2 = (CFF_T2_String)memory->alloc( memory, sizeof ( CFF_T2_StringRec ) ); if ( !t2 ) goto Out_Of_Memory_Error; node->data = t2; /* `5' is the conservative upper bound of required bytes per stack */ /* element. */ t2_size = 5 * ( decoder.top - decoder.stack ); q = (FT_Byte*)memory->alloc( memory, t2_size ); if ( !q ) goto Out_Of_Memory_Error; t2->start = q; t2->limit = q + t2_size; stack = decoder.stack; while ( stack < decoder.top ) { FT_ULong num; FT_Bool neg; if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize ) goto Stack_Overflow; *parser->top++ = q; if ( *stack < 0 ) { num = (FT_ULong)NEG_LONG( *stack ); neg = 1; } else { num = (FT_ULong)*stack; neg = 0; } if ( num & 0xFFFFU ) { if ( neg ) num = (FT_ULong)-num; *q++ = 255; *q++ = ( num & 0xFF000000U ) >> 24; *q++ = ( num & 0x00FF0000U ) >> 16; *q++ = ( num & 0x0000FF00U ) >> 8; *q++ = num & 0x000000FFU; } else { num >>= 16; if ( neg ) { if ( num <= 107 ) *q++ = (FT_Byte)( 139 - num ); else if ( num <= 1131 ) { *q++ = (FT_Byte)( ( ( num - 108 ) >> 8 ) + 251 ); *q++ = (FT_Byte)( ( num - 108 ) & 0xFF ); } else { num = (FT_ULong)-num; *q++ = 28; *q++ = (FT_Byte)( num >> 8 ); *q++ = (FT_Byte)( num & 0xFF ); } } else { if ( num <= 107 ) *q++ = (FT_Byte)( num + 139 ); else if ( num <= 1131 ) { *q++ = (FT_Byte)( ( ( num - 108 ) >> 8 ) + 247 ); *q++ = (FT_Byte)( ( num - 108 ) & 0xFF ); } else { *q++ = 28; *q++ = (FT_Byte)( num >> 8 ); *q++ = (FT_Byte)( num & 0xFF ); } } } stack++; } } #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ else { /* This is not a number, hence it's an operator. Compute its code */ /* and look for it in our current list. */ FT_UInt code; FT_UInt num_args; const CFF_Field_Handler* field; if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize ) goto Stack_Overflow; num_args = (FT_UInt)( parser->top - parser->stack ); *parser->top = p; code = v; if ( v == 12 ) { /* two byte operator */ p++; if ( p >= limit ) goto Syntax_Error; code = 0x100 | p[0]; } code = code | parser->object_code; for ( field = cff_field_handlers; field->kind; field++ ) { if ( field->code == (FT_Int)code ) { /* we found our field's handler; read it */ FT_Long val; FT_Byte* q = (FT_Byte*)parser->object + field->offset; #ifdef FT_DEBUG_LEVEL_TRACE FT_TRACE4(( " %s", field->id )); #endif /* check that we have enough arguments -- except for */ /* delta encoded arrays, which can be empty */ if ( field->kind != cff_kind_delta && num_args < 1 ) goto Stack_Underflow; switch ( field->kind ) { case cff_kind_bool: case cff_kind_string: case cff_kind_num: val = cff_parse_num( parser, parser->stack ); goto Store_Number; case cff_kind_fixed: val = cff_parse_fixed( parser, parser->stack ); goto Store_Number; case cff_kind_fixed_thousand: val = cff_parse_fixed_scaled( parser, parser->stack, 3 ); Store_Number: switch ( field->size ) { case (8 / FT_CHAR_BIT): *(FT_Byte*)q = (FT_Byte)val; break; case (16 / FT_CHAR_BIT): *(FT_Short*)q = (FT_Short)val; break; case (32 / FT_CHAR_BIT): *(FT_Int32*)q = (FT_Int)val; break; default: /* for 64-bit systems */ *(FT_Long*)q = val; } #ifdef FT_DEBUG_LEVEL_TRACE switch ( field->kind ) { case cff_kind_bool: FT_TRACE4(( " %s\n", val ? "true" : "false" )); break; case cff_kind_string: FT_TRACE4(( " %ld (SID)\n", val )); break; case cff_kind_num: FT_TRACE4(( " %ld\n", val )); break; case cff_kind_fixed: FT_TRACE4(( " %f\n", (double)val / 65536 )); break; case cff_kind_fixed_thousand: FT_TRACE4(( " %f\n", (double)val / 65536 / 1000 )); break; default: ; /* never reached */ } #endif break; case cff_kind_delta: { FT_Byte* qcount = (FT_Byte*)parser->object + field->count_offset; FT_Byte** data = parser->stack; if ( num_args > field->array_max ) num_args = field->array_max; FT_TRACE4(( " [" )); /* store count */ *qcount = (FT_Byte)num_args; val = 0; while ( num_args > 0 ) { val = ADD_LONG( val, cff_parse_num( parser, data++ ) ); switch ( field->size ) { case (8 / FT_CHAR_BIT): *(FT_Byte*)q = (FT_Byte)val; break; case (16 / FT_CHAR_BIT): *(FT_Short*)q = (FT_Short)val; break; case (32 / FT_CHAR_BIT): *(FT_Int32*)q = (FT_Int)val; break; default: /* for 64-bit systems */ *(FT_Long*)q = val; } FT_TRACE4(( " %ld", val )); q += field->size; num_args--; } FT_TRACE4(( "]\n" )); } break; default: /* callback or blend */ error = field->reader( parser ); if ( error ) goto Exit; } goto Found; } } /* this is an unknown operator, or it is unsupported; */ /* we will ignore it for now. */ Found: /* clear stack */ /* TODO: could clear blend stack here, */ /* but we don't have access to subFont */ if ( field->kind != cff_kind_blend ) parser->top = parser->stack; } p++; } /* while ( p < limit ) */ Exit: return error; #ifdef CFF_CONFIG_OPTION_OLD_ENGINE Out_Of_Memory_Error: error = FT_THROW( Out_Of_Memory ); goto Exit; #endif Stack_Overflow: error = FT_THROW( Invalid_Argument ); goto Exit; Stack_Underflow: error = FT_THROW( Invalid_Argument ); goto Exit; Syntax_Error: error = FT_THROW( Invalid_Argument ); goto Exit; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffparse.c
C++
gpl-3.0
42,033
/**************************************************************************** * * cffparse.h * * CFF token stream parser (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 CFFPARSE_H_ #define CFFPARSE_H_ #include <freetype/internal/cfftypes.h> #include <freetype/internal/ftobjs.h> FT_BEGIN_HEADER /* CFF uses constant parser stack size; */ /* CFF2 can increase from default 193 */ #define CFF_MAX_STACK_DEPTH 96 /* * There are plans to remove the `maxstack' operator in a forthcoming * revision of the CFF2 specification, increasing the (then static) stack * size to 513. By making the default stack size equal to the maximum * stack size, the operator is essentially disabled, which has the * desired effect in FreeType. */ #define CFF2_MAX_STACK 513 #define CFF2_DEFAULT_STACK 513 #define CFF_CODE_TOPDICT 0x1000 #define CFF_CODE_PRIVATE 0x2000 #define CFF2_CODE_TOPDICT 0x3000 #define CFF2_CODE_FONTDICT 0x4000 #define CFF2_CODE_PRIVATE 0x5000 typedef struct CFF_ParserRec_ { FT_Library library; FT_Byte* start; FT_Byte* limit; FT_Byte* cursor; FT_Byte** stack; FT_Byte** top; FT_UInt stackSize; /* allocated size */ #ifdef CFF_CONFIG_OPTION_OLD_ENGINE FT_ListRec t2_strings; #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ FT_UInt object_code; void* object; FT_UShort num_designs; /* a copy of `CFF_FontRecDict->num_designs' */ FT_UShort num_axes; /* a copy of `CFF_FontRecDict->num_axes' */ } CFF_ParserRec, *CFF_Parser; FT_LOCAL( FT_Long ) cff_parse_num( CFF_Parser parser, FT_Byte** d ); FT_LOCAL( FT_Error ) cff_parser_init( CFF_Parser parser, FT_UInt code, void* object, FT_Library library, FT_UInt stackSize, FT_UShort num_designs, FT_UShort num_axes ); FT_LOCAL( void ) cff_parser_done( CFF_Parser parser ); FT_LOCAL( FT_Error ) cff_parser_run( CFF_Parser parser, FT_Byte* start, FT_Byte* limit ); enum { cff_kind_none = 0, cff_kind_num, cff_kind_fixed, cff_kind_fixed_thousand, cff_kind_string, cff_kind_bool, cff_kind_delta, cff_kind_callback, cff_kind_blend, cff_kind_max /* do not remove */ }; /* now generate handlers for the most simple fields */ typedef FT_Error (*CFF_Field_Reader)( CFF_Parser parser ); typedef struct CFF_Field_Handler_ { int kind; int code; FT_UInt offset; FT_Byte size; CFF_Field_Reader reader; FT_UInt array_max; FT_UInt count_offset; #ifdef FT_DEBUG_LEVEL_TRACE const char* id; #endif } CFF_Field_Handler; FT_END_HEADER #ifdef CFF_CONFIG_OPTION_OLD_ENGINE typedef struct CFF_T2_String_ { FT_Byte* start; FT_Byte* limit; } CFF_T2_StringRec, *CFF_T2_String; #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */ #endif /* CFFPARSE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cffparse.h
C++
gpl-3.0
3,523
/**************************************************************************** * * cfftoken.h * * CFF token definitions (specification 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. * */ #undef FT_STRUCTURE #define FT_STRUCTURE CFF_FontRecDictRec #undef CFFCODE #define CFFCODE CFF_CODE_TOPDICT CFF_FIELD_STRING ( 0, version, "Version" ) CFF_FIELD_STRING ( 1, notice, "Notice" ) CFF_FIELD_STRING ( 0x100, copyright, "Copyright" ) CFF_FIELD_STRING ( 2, full_name, "FullName" ) CFF_FIELD_STRING ( 3, family_name, "FamilyName" ) CFF_FIELD_STRING ( 4, weight, "Weight" ) CFF_FIELD_BOOL ( 0x101, is_fixed_pitch, "isFixedPitch" ) CFF_FIELD_FIXED ( 0x102, italic_angle, "ItalicAngle" ) CFF_FIELD_FIXED ( 0x103, underline_position, "UnderlinePosition" ) CFF_FIELD_FIXED ( 0x104, underline_thickness, "UnderlineThickness" ) CFF_FIELD_NUM ( 0x105, paint_type, "PaintType" ) CFF_FIELD_NUM ( 0x106, charstring_type, "CharstringType" ) CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" ) CFF_FIELD_NUM ( 13, unique_id, "UniqueID" ) CFF_FIELD_CALLBACK( 5, font_bbox, "FontBBox" ) CFF_FIELD_NUM ( 0x108, stroke_width, "StrokeWidth" ) #if 0 CFF_FIELD_DELTA ( 14, xuid, 16, "XUID" ) #endif CFF_FIELD_NUM ( 15, charset_offset, "charset" ) CFF_FIELD_NUM ( 16, encoding_offset, "Encoding" ) CFF_FIELD_NUM ( 17, charstrings_offset, "CharStrings" ) CFF_FIELD_CALLBACK( 18, private_dict, "Private" ) CFF_FIELD_NUM ( 0x114, synthetic_base, "SyntheticBase" ) CFF_FIELD_STRING ( 0x115, embedded_postscript, "PostScript" ) #if 0 CFF_FIELD_STRING ( 0x116, base_font_name, "BaseFontName" ) CFF_FIELD_DELTA ( 0x117, base_font_blend, 16, "BaseFontBlend" ) #endif /* the next two operators were removed from the Type2 specification */ /* in version 16-March-2000 */ CFF_FIELD_CALLBACK( 0x118, multiple_master, "MultipleMaster" ) #if 0 CFF_FIELD_CALLBACK( 0x11A, blend_axis_types, "BlendAxisTypes" ) #endif CFF_FIELD_CALLBACK( 0x11E, cid_ros, "ROS" ) CFF_FIELD_NUM ( 0x11F, cid_font_version, "CIDFontVersion" ) CFF_FIELD_NUM ( 0x120, cid_font_revision, "CIDFontRevision" ) CFF_FIELD_NUM ( 0x121, cid_font_type, "CIDFontType" ) CFF_FIELD_NUM ( 0x122, cid_count, "CIDCount" ) CFF_FIELD_NUM ( 0x123, cid_uid_base, "UIDBase" ) CFF_FIELD_NUM ( 0x124, cid_fd_array_offset, "FDArray" ) CFF_FIELD_NUM ( 0x125, cid_fd_select_offset, "FDSelect" ) CFF_FIELD_STRING ( 0x126, cid_font_name, "FontName" ) #if 0 CFF_FIELD_NUM ( 0x127, chameleon, "Chameleon" ) #endif #undef FT_STRUCTURE #define FT_STRUCTURE CFF_PrivateRec #undef CFFCODE #define CFFCODE CFF_CODE_PRIVATE CFF_FIELD_DELTA ( 6, blue_values, 14, "BlueValues" ) CFF_FIELD_DELTA ( 7, other_blues, 10, "OtherBlues" ) CFF_FIELD_DELTA ( 8, family_blues, 14, "FamilyBlues" ) CFF_FIELD_DELTA ( 9, family_other_blues, 10, "FamilyOtherBlues" ) CFF_FIELD_FIXED_1000( 0x109, blue_scale, "BlueScale" ) CFF_FIELD_NUM ( 0x10A, blue_shift, "BlueShift" ) CFF_FIELD_NUM ( 0x10B, blue_fuzz, "BlueFuzz" ) CFF_FIELD_NUM ( 10, standard_width, "StdHW" ) CFF_FIELD_NUM ( 11, standard_height, "StdVW" ) CFF_FIELD_DELTA ( 0x10C, snap_widths, 13, "StemSnapH" ) CFF_FIELD_DELTA ( 0x10D, snap_heights, 13, "StemSnapV" ) CFF_FIELD_BOOL ( 0x10E, force_bold, "ForceBold" ) CFF_FIELD_FIXED ( 0x10F, force_bold_threshold, "ForceBoldThreshold" ) CFF_FIELD_NUM ( 0x110, lenIV, "lenIV" ) CFF_FIELD_NUM ( 0x111, language_group, "LanguageGroup" ) CFF_FIELD_FIXED ( 0x112, expansion_factor, "ExpansionFactor" ) CFF_FIELD_NUM ( 0x113, initial_random_seed, "initialRandomSeed" ) CFF_FIELD_NUM ( 19, local_subrs_offset, "Subrs" ) CFF_FIELD_NUM ( 20, default_width, "defaultWidthX" ) CFF_FIELD_NUM ( 21, nominal_width, "nominalWidthX" ) #undef FT_STRUCTURE #define FT_STRUCTURE CFF_FontRecDictRec #undef CFFCODE #define CFFCODE CFF2_CODE_TOPDICT CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" ) CFF_FIELD_NUM ( 17, charstrings_offset, "CharStrings" ) CFF_FIELD_NUM ( 0x124, cid_fd_array_offset, "FDArray" ) CFF_FIELD_NUM ( 0x125, cid_fd_select_offset, "FDSelect" ) CFF_FIELD_NUM ( 24, vstore_offset, "vstore" ) CFF_FIELD_CALLBACK( 25, maxstack, "maxstack" ) #undef FT_STRUCTURE #define FT_STRUCTURE CFF_FontRecDictRec #undef CFFCODE #define CFFCODE CFF2_CODE_FONTDICT CFF_FIELD_CALLBACK( 18, private_dict, "Private" ) CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" ) #undef FT_STRUCTURE #define FT_STRUCTURE CFF_PrivateRec #undef CFFCODE #define CFFCODE CFF2_CODE_PRIVATE CFF_FIELD_DELTA ( 6, blue_values, 14, "BlueValues" ) CFF_FIELD_DELTA ( 7, other_blues, 10, "OtherBlues" ) CFF_FIELD_DELTA ( 8, family_blues, 14, "FamilyBlues" ) CFF_FIELD_DELTA ( 9, family_other_blues, 10, "FamilyOtherBlues" ) CFF_FIELD_FIXED_1000( 0x109, blue_scale, "BlueScale" ) CFF_FIELD_NUM ( 0x10A, blue_shift, "BlueShift" ) CFF_FIELD_NUM ( 0x10B, blue_fuzz, "BlueFuzz" ) CFF_FIELD_NUM ( 10, standard_width, "StdHW" ) CFF_FIELD_NUM ( 11, standard_height, "StdVW" ) CFF_FIELD_DELTA ( 0x10C, snap_widths, 13, "StemSnapH" ) CFF_FIELD_DELTA ( 0x10D, snap_heights, 13, "StemSnapV" ) CFF_FIELD_NUM ( 0x111, language_group, "LanguageGroup" ) CFF_FIELD_FIXED ( 0x112, expansion_factor, "ExpansionFactor" ) CFF_FIELD_CALLBACK ( 22, vsindex, "vsindex" ) CFF_FIELD_BLEND ( 23, "blend" ) CFF_FIELD_NUM ( 19, local_subrs_offset, "Subrs" ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/cfftoken.h
C++
gpl-3.0
6,772
# # FreeType 2 CFF 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 += CFF_DRIVER define CFF_DRIVER $(OPEN_DRIVER) FT_Driver_ClassRec, cff_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)cff $(ECHO_DRIVER_DESC)OpenType fonts with extension *.otf$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/module.mk
mk
gpl-3.0
656
# # FreeType 2 OpenType/CFF 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. # OpenType driver directory # CFF_DIR := $(SRC_DIR)/cff CFF_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(CFF_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # CFF driver sources (i.e., C files) # CFF_DRV_SRC := $(CFF_DIR)/cffcmap.c \ $(CFF_DIR)/cffdrivr.c \ $(CFF_DIR)/cffgload.c \ $(CFF_DIR)/cffload.c \ $(CFF_DIR)/cffobjs.c \ $(CFF_DIR)/cffparse.c # CFF driver headers # CFF_DRV_H := $(CFF_DRV_SRC:%.c=%.h) \ $(CFF_DIR)/cfferrs.h \ $(CFF_DIR)/cfftoken.h # CFF driver object(s) # # CFF_DRV_OBJ_M is used during `multi' builds # CFF_DRV_OBJ_S is used during `single' builds # CFF_DRV_OBJ_M := $(CFF_DRV_SRC:$(CFF_DIR)/%.c=$(OBJ_DIR)/%.$O) CFF_DRV_OBJ_S := $(OBJ_DIR)/cff.$O # CFF driver source file for single build # CFF_DRV_SRC_S := $(CFF_DIR)/cff.c # CFF driver - single object # $(CFF_DRV_OBJ_S): $(CFF_DRV_SRC_S) $(CFF_DRV_SRC) $(FREETYPE_H) $(CFF_DRV_H) $(CFF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(CFF_DRV_SRC_S)) # CFF driver - multiple objects # $(OBJ_DIR)/%.$O: $(CFF_DIR)/%.c $(FREETYPE_H) $(CFF_DRV_H) $(CFF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(CFF_DRV_OBJ_S) DRV_OBJS_M += $(CFF_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/cff/rules.mk
mk
gpl-3.0
1,864
/**************************************************************************** * * ciderrs.h * * CID 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 CID error enumeration constants. * */ #ifndef CIDERRS_H_ #define CIDERRS_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX CID_Err_ #define FT_ERR_BASE FT_Mod_Err_CID #include <freetype/fterrors.h> #endif /* CIDERRS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/ciderrs.h
C++
gpl-3.0
958
/**************************************************************************** * * cidgload.c * * CID-keyed Type1 Glyph Loader (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 "cidload.h" #include "cidgload.h" #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftstream.h> #include <freetype/ftoutln.h> #include <freetype/internal/ftcalc.h> #include <freetype/internal/psaux.h> #include <freetype/internal/cfftypes.h> #include <freetype/ftdriver.h> #include "ciderrs.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 cidgload FT_CALLBACK_DEF( FT_Error ) cid_load_glyph( T1_Decoder decoder, FT_UInt glyph_index ) { CID_Face face = (CID_Face)decoder->builder.face; CID_FaceInfo cid = &face->cid; FT_Byte* p; FT_ULong fd_select; FT_Stream stream = face->cid_stream; FT_Error error = FT_Err_Ok; FT_Byte* charstring = NULL; FT_Memory memory = face->root.memory; FT_ULong glyph_length = 0; PSAux_Service psaux = (PSAux_Service)face->psaux; FT_Bool force_scaling = FALSE; #ifdef FT_CONFIG_OPTION_INCREMENTAL FT_Incremental_InterfaceRec *inc = face->root.internal->incremental_interface; #endif FT_TRACE1(( "cid_load_glyph: glyph index %u\n", glyph_index )); #ifdef FT_CONFIG_OPTION_INCREMENTAL /* For incremental fonts get the character data using */ /* the callback function. */ if ( inc ) { FT_Data glyph_data; error = inc->funcs->get_glyph_data( inc->object, glyph_index, &glyph_data ); if ( error || glyph_data.length < cid->fd_bytes ) goto Exit; p = (FT_Byte*)glyph_data.pointer; fd_select = cid_get_offset( &p, cid->fd_bytes ); glyph_length = glyph_data.length - cid->fd_bytes; if ( !FT_QALLOC( charstring, glyph_length ) ) FT_MEM_COPY( charstring, glyph_data.pointer + cid->fd_bytes, glyph_length ); inc->funcs->free_glyph_data( inc->object, &glyph_data ); if ( error ) goto Exit; } else #endif /* FT_CONFIG_OPTION_INCREMENTAL */ /* For ordinary fonts read the CID font dictionary index */ /* and charstring offset from the CIDMap. */ { FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes; FT_ULong off1, off2; if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + glyph_index * entry_len ) || FT_FRAME_ENTER( 2 * entry_len ) ) goto Exit; p = (FT_Byte*)stream->cursor; fd_select = cid_get_offset( &p, cid->fd_bytes ); off1 = cid_get_offset( &p, cid->gd_bytes ); p += cid->fd_bytes; off2 = cid_get_offset( &p, cid->gd_bytes ); FT_FRAME_EXIT(); if ( fd_select >= cid->num_dicts || off2 > stream->size || off1 > off2 ) { FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" )); error = FT_THROW( Invalid_Offset ); goto Exit; } glyph_length = off2 - off1; if ( glyph_length == 0 || FT_QALLOC( charstring, glyph_length ) || FT_STREAM_READ_AT( cid->data_offset + off1, charstring, glyph_length ) ) goto Exit; } /* Now set up the subrs array and parse the charstrings. */ { CID_FaceDict dict; CID_Subrs cid_subrs = face->subrs + fd_select; FT_UInt cs_offset; /* Set up subrs */ decoder->num_subrs = cid_subrs->num_subrs; decoder->subrs = cid_subrs->code; decoder->subrs_len = 0; decoder->subrs_hash = NULL; /* Set up font matrix */ dict = cid->font_dicts + fd_select; decoder->font_matrix = dict->font_matrix; decoder->font_offset = dict->font_offset; decoder->lenIV = dict->private_dict.lenIV; /* Decode the charstring. */ /* Adjustment for seed bytes. */ cs_offset = decoder->lenIV >= 0 ? (FT_UInt)decoder->lenIV : 0; if ( cs_offset > glyph_length ) { FT_TRACE0(( "cid_load_glyph: invalid glyph stream offsets\n" )); error = FT_THROW( Invalid_Offset ); goto Exit; } /* Decrypt only if lenIV >= 0. */ if ( decoder->lenIV >= 0 ) psaux->t1_decrypt( charstring, glyph_length, 4330 ); /* choose which renderer to use */ #ifdef T1_CONFIG_OPTION_OLD_ENGINE if ( ( (PS_Driver)FT_FACE_DRIVER( face ) )->hinting_engine == FT_HINTING_FREETYPE || decoder->builder.metrics_only ) error = psaux->t1_decoder_funcs->parse_charstrings_old( decoder, charstring + cs_offset, glyph_length - cs_offset ); #else if ( decoder->builder.metrics_only ) error = psaux->t1_decoder_funcs->parse_metrics( decoder, charstring + cs_offset, glyph_length - cs_offset ); #endif else { PS_Decoder psdecoder; CFF_SubFontRec subfont; psaux->ps_decoder_init( &psdecoder, decoder, TRUE ); psaux->t1_make_subfont( FT_FACE( face ), &dict->private_dict, &subfont ); psdecoder.current_subfont = &subfont; error = psaux->t1_decoder_funcs->parse_charstrings( &psdecoder, charstring + cs_offset, glyph_length - cs_offset ); /* Adobe's engine uses 16.16 numbers everywhere; */ /* as a consequence, glyphs larger than 2000ppem get rejected */ if ( FT_ERR_EQ( error, Glyph_Too_Big ) ) { /* this time, we retry unhinted and scale up the glyph later on */ /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */ /* 0x400 for both `x_scale' and `y_scale' in this case) */ ((CID_GlyphSlot)decoder->builder.glyph)->hint = FALSE; force_scaling = TRUE; error = psaux->t1_decoder_funcs->parse_charstrings( &psdecoder, charstring + cs_offset, glyph_length - cs_offset ); } } } #ifdef FT_CONFIG_OPTION_INCREMENTAL /* Incremental fonts can optionally override the metrics. */ if ( !error && inc && inc->funcs->get_glyph_metrics ) { FT_Incremental_MetricsRec metrics; metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x ); metrics.bearing_y = 0; metrics.advance = FIXED_TO_INT( decoder->builder.advance.x ); metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y ); error = inc->funcs->get_glyph_metrics( inc->object, glyph_index, FALSE, &metrics ); decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x ); decoder->builder.advance.x = INT_TO_FIXED( metrics.advance ); decoder->builder.advance.y = INT_TO_FIXED( metrics.advance_v ); } #endif /* FT_CONFIG_OPTION_INCREMENTAL */ Exit: FT_FREE( charstring ); ((CID_GlyphSlot)decoder->builder.glyph)->scaled = force_scaling; return error; } #if 0 /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********** *********/ /********** *********/ /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ /********** *********/ /********** The following code is in charge of computing *********/ /********** the maximum advance width of the font. It *********/ /********** quickly processes each glyph charstring to *********/ /********** extract the value from either a `sbw' or `seac' *********/ /********** operator. *********/ /********** *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( FT_Error ) cid_face_compute_max_advance( CID_Face face, FT_Int* max_advance ) { FT_Error error; T1_DecoderRec decoder; FT_Int glyph_index; PSAux_Service psaux = (PSAux_Service)face->psaux; *max_advance = 0; /* Initialize load decoder */ error = psaux->t1_decoder_funcs->init( &decoder, (FT_Face)face, 0, /* size */ 0, /* glyph slot */ 0, /* glyph names! XXX */ 0, /* blend == 0 */ 0, /* hinting == 0 */ cid_load_glyph ); if ( error ) return error; /* TODO: initialize decoder.len_buildchar and decoder.buildchar */ /* if we ever support CID-keyed multiple master fonts */ decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; /* for each glyph, parse the glyph charstring and extract */ /* the advance width */ for ( glyph_index = 0; glyph_index < face->root.num_glyphs; glyph_index++ ) { /* now get load the unscaled outline */ error = cid_load_glyph( &decoder, glyph_index ); /* ignore the error if one occurred - skip to next glyph */ } *max_advance = FIXED_TO_INT( decoder.builder.advance.x ); psaux->t1_decoder_funcs->done( &decoder ); return FT_Err_Ok; } #endif /* 0 */ FT_LOCAL_DEF( FT_Error ) cid_slot_load_glyph( FT_GlyphSlot cidglyph, /* CID_GlyphSlot */ FT_Size cidsize, /* CID_Size */ FT_UInt glyph_index, FT_Int32 load_flags ) { CID_GlyphSlot glyph = (CID_GlyphSlot)cidglyph; FT_Error error; T1_DecoderRec decoder; CID_Face face = (CID_Face)cidglyph->face; FT_Bool hinting; FT_Bool scaled; PSAux_Service psaux = (PSAux_Service)face->psaux; FT_Matrix font_matrix; FT_Vector font_offset; FT_Bool must_finish_decoder = FALSE; if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) { error = FT_THROW( Invalid_Argument ); goto Exit; } if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; glyph->x_scale = cidsize->metrics.x_scale; glyph->y_scale = cidsize->metrics.y_scale; cidglyph->outline.n_points = 0; cidglyph->outline.n_contours = 0; hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 && ( load_flags & FT_LOAD_NO_HINTING ) == 0 ); scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ); glyph->hint = hinting; glyph->scaled = scaled; cidglyph->format = FT_GLYPH_FORMAT_OUTLINE; error = psaux->t1_decoder_funcs->init( &decoder, cidglyph->face, cidsize, cidglyph, 0, /* glyph names -- XXX */ 0, /* blend == 0 */ hinting, FT_LOAD_TARGET_MODE( load_flags ), cid_load_glyph ); if ( error ) goto Exit; /* TODO: initialize decoder.len_buildchar and decoder.buildchar */ /* if we ever support CID-keyed multiple master fonts */ must_finish_decoder = TRUE; /* set up the decoder */ decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE ); error = cid_load_glyph( &decoder, glyph_index ); if ( error ) goto Exit; /* copy flags back for forced scaling */ hinting = glyph->hint; scaled = glyph->scaled; font_matrix = decoder.font_matrix; font_offset = decoder.font_offset; /* save new glyph tables */ psaux->t1_decoder_funcs->done( &decoder ); must_finish_decoder = FALSE; /* now set the metrics -- this is rather simple, as */ /* the left side bearing is the xMin, and the top side */ /* bearing the yMax */ cidglyph->outline.flags &= FT_OUTLINE_OWNER; cidglyph->outline.flags |= FT_OUTLINE_REVERSE_FILL; /* for composite glyphs, return only left side bearing and */ /* advance width */ if ( load_flags & FT_LOAD_NO_RECURSE ) { FT_Slot_Internal internal = cidglyph->internal; cidglyph->metrics.horiBearingX = FIXED_TO_INT( decoder.builder.left_bearing.x ); cidglyph->metrics.horiAdvance = FIXED_TO_INT( decoder.builder.advance.x ); internal->glyph_matrix = font_matrix; internal->glyph_delta = font_offset; internal->glyph_transformed = 1; } else { FT_BBox cbox; FT_Glyph_Metrics* metrics = &cidglyph->metrics; /* copy the _unscaled_ advance width */ metrics->horiAdvance = FIXED_TO_INT( decoder.builder.advance.x ); cidglyph->linearHoriAdvance = FIXED_TO_INT( decoder.builder.advance.x ); cidglyph->internal->glyph_transformed = 0; /* make up vertical ones */ metrics->vertAdvance = ( face->cid.font_bbox.yMax - face->cid.font_bbox.yMin ) >> 16; cidglyph->linearVertAdvance = metrics->vertAdvance; cidglyph->format = FT_GLYPH_FORMAT_OUTLINE; if ( cidsize->metrics.y_ppem < 24 ) cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; /* apply the font matrix, if any */ if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L || font_matrix.xy != 0 || font_matrix.yx != 0 ) { FT_Outline_Transform( &cidglyph->outline, &font_matrix ); metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, font_matrix.xx ); metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, font_matrix.yy ); } if ( font_offset.x || font_offset.y ) { FT_Outline_Translate( &cidglyph->outline, font_offset.x, font_offset.y ); metrics->horiAdvance += font_offset.x; metrics->vertAdvance += font_offset.y; } if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || scaled ) { /* scale the outline and the metrics */ FT_Int n; FT_Outline* cur = decoder.builder.base; FT_Vector* vec = cur->points; FT_Fixed x_scale = glyph->x_scale; FT_Fixed y_scale = glyph->y_scale; /* First of all, scale the points */ if ( !hinting || !decoder.builder.hints_funcs ) for ( n = cur->n_points; n > 0; n--, vec++ ) { vec->x = FT_MulFix( vec->x, x_scale ); vec->y = FT_MulFix( vec->y, y_scale ); } /* Then scale the metrics */ metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale ); metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale ); } /* compute the other metrics */ FT_Outline_Get_CBox( &cidglyph->outline, &cbox ); metrics->width = cbox.xMax - cbox.xMin; metrics->height = cbox.yMax - cbox.yMin; metrics->horiBearingX = cbox.xMin; metrics->horiBearingY = cbox.yMax; if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) { /* make up vertical ones */ ft_synthesize_vertical_metrics( metrics, metrics->vertAdvance ); } } Exit: if ( must_finish_decoder ) psaux->t1_decoder_funcs->done( &decoder ); return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidgload.c
C++
gpl-3.0
17,610
/**************************************************************************** * * cidgload.h * * OpenType Glyph Loader (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 CIDGLOAD_H_ #define CIDGLOAD_H_ #include "cidobjs.h" FT_BEGIN_HEADER #if 0 /* Compute the maximum advance width of a font through quick parsing */ FT_LOCAL( FT_Error ) cid_face_compute_max_advance( CID_Face face, FT_Int* max_advance ); #endif /* 0 */ FT_LOCAL( FT_Error ) cid_slot_load_glyph( FT_GlyphSlot glyph, /* CID_Glyph_Slot */ FT_Size size, /* CID_Size */ FT_UInt glyph_index, FT_Int32 load_flags ); FT_END_HEADER #endif /* CIDGLOAD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidgload.h
C++
gpl-3.0
1,176
/**************************************************************************** * * cidload.c * * CID-keyed Type1 font loader (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 <ft2build.h> #include <freetype/internal/ftdebug.h> #include FT_CONFIG_CONFIG_H #include <freetype/ftmm.h> #include <freetype/internal/t1types.h> #include <freetype/internal/psaux.h> #include "cidload.h" #include "ciderrs.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 cidload /* read a single offset */ FT_LOCAL_DEF( FT_ULong ) cid_get_offset( FT_Byte* *start, FT_UInt offsize ) { FT_ULong result; FT_Byte* p = *start; for ( result = 0; offsize > 0; offsize-- ) { result <<= 8; result |= *p++; } *start = p; return result; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** TYPE 1 SYMBOL PARSING *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static FT_Error cid_load_keyword( CID_Face face, CID_Loader* loader, const T1_Field keyword ) { FT_Error error; CID_Parser* parser = &loader->parser; FT_Byte* object; void* dummy_object; CID_FaceInfo cid = &face->cid; /* if the keyword has a dedicated callback, call it */ if ( keyword->type == T1_FIELD_TYPE_CALLBACK ) { FT_TRACE4(( " %s", keyword->ident )); keyword->reader( (FT_Face)face, parser ); error = parser->root.error; goto Exit; } /* we must now compute the address of our target object */ switch ( keyword->location ) { case T1_FIELD_LOCATION_CID_INFO: object = (FT_Byte*)cid; break; case T1_FIELD_LOCATION_FONT_INFO: object = (FT_Byte*)&cid->font_info; break; case T1_FIELD_LOCATION_FONT_EXTRA: object = (FT_Byte*)&face->font_extra; break; case T1_FIELD_LOCATION_BBOX: object = (FT_Byte*)&cid->font_bbox; break; default: { CID_FaceDict dict; if ( parser->num_dict >= cid->num_dicts ) { FT_ERROR(( "cid_load_keyword: invalid use of `%s'\n", keyword->ident )); error = FT_THROW( Syntax_Error ); goto Exit; } dict = cid->font_dicts + parser->num_dict; switch ( keyword->location ) { case T1_FIELD_LOCATION_PRIVATE: object = (FT_Byte*)&dict->private_dict; break; default: object = (FT_Byte*)dict; } } } FT_TRACE4(( " %s", keyword->ident )); dummy_object = object; /* now, load the keyword data in the object's field(s) */ if ( keyword->type == T1_FIELD_TYPE_INTEGER_ARRAY || keyword->type == T1_FIELD_TYPE_FIXED_ARRAY ) error = cid_parser_load_field_table( &loader->parser, keyword, &dummy_object ); else error = cid_parser_load_field( &loader->parser, keyword, &dummy_object ); FT_TRACE4(( "\n" )); Exit: return error; } FT_CALLBACK_DEF( void ) cid_parse_font_matrix( CID_Face face, CID_Parser* parser ) { CID_FaceDict dict; FT_Face root = (FT_Face)&face->root; FT_Fixed temp[6]; FT_Fixed temp_scale; if ( parser->num_dict < face->cid.num_dicts ) { FT_Matrix* matrix; FT_Vector* offset; FT_Int result; dict = face->cid.font_dicts + parser->num_dict; matrix = &dict->font_matrix; offset = &dict->font_offset; /* input is scaled by 1000 to accommodate default FontMatrix */ result = cid_parser_to_fixed_array( parser, 6, temp, 3 ); if ( result < 6 ) { FT_ERROR(( "cid_parse_font_matrix: not enough matrix elements\n" )); goto Exit; } FT_TRACE4(( " [%f %f %f %f %f %f]\n", (double)temp[0] / 65536 / 1000, (double)temp[1] / 65536 / 1000, (double)temp[2] / 65536 / 1000, (double)temp[3] / 65536 / 1000, (double)temp[4] / 65536 / 1000, (double)temp[5] / 65536 / 1000 )); temp_scale = FT_ABS( temp[3] ); if ( temp_scale == 0 ) { FT_ERROR(( "cid_parse_font_matrix: invalid font matrix\n" )); goto Exit; } /* atypical case */ if ( temp_scale != 0x10000L ) { /* set units per EM based on FontMatrix values */ root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale ); temp[0] = FT_DivFix( temp[0], temp_scale ); temp[1] = FT_DivFix( temp[1], temp_scale ); temp[2] = FT_DivFix( temp[2], temp_scale ); temp[4] = FT_DivFix( temp[4], temp_scale ); temp[5] = FT_DivFix( temp[5], temp_scale ); temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L; } matrix->xx = temp[0]; matrix->yx = temp[1]; matrix->xy = temp[2]; matrix->yy = temp[3]; if ( !FT_Matrix_Check( matrix ) ) { FT_ERROR(( "t1_parse_font_matrix: invalid font matrix\n" )); parser->root.error = FT_THROW( Invalid_File_Format ); goto Exit; } /* note that the font offsets are expressed in integer font units */ offset->x = temp[4] >> 16; offset->y = temp[5] >> 16; } Exit: return; } FT_CALLBACK_DEF( void ) parse_fd_array( CID_Face face, CID_Parser* parser ) { CID_FaceInfo cid = &face->cid; FT_Memory memory = face->root.memory; FT_Stream stream = parser->stream; FT_Error error = FT_Err_Ok; FT_Long num_dicts, max_dicts; num_dicts = cid_parser_to_int( parser ); if ( num_dicts < 0 || num_dicts > FT_INT_MAX ) { FT_ERROR(( "parse_fd_array: invalid number of dictionaries\n" )); goto Exit; } FT_TRACE4(( " %ld\n", num_dicts )); /* * A single entry in the FDArray must (at least) contain the following * structure elements. * * %ADOBeginFontDict 18 * X dict begin 13 * /FontMatrix [X X X X] 22 * /Private X dict begin 22 * end 4 * end 4 * %ADOEndFontDict 16 * * This needs 18+13+22+22+4+4+16=99 bytes or more. Normally, you also * need a `dup X' at the very beginning and a `put' at the end, so a * rough guess using 100 bytes as the minimum is justified. */ max_dicts = (FT_Long)( stream->size / 100 ); if ( num_dicts > max_dicts ) { FT_TRACE0(( "parse_fd_array: adjusting FDArray size" " (from %ld to %ld)\n", num_dicts, max_dicts )); num_dicts = max_dicts; } if ( !cid->font_dicts ) { FT_UInt n; if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) ) goto Exit; cid->num_dicts = num_dicts; /* set some default values (the same as for Type 1 fonts) */ for ( n = 0; n < cid->num_dicts; n++ ) { CID_FaceDict dict = cid->font_dicts + n; dict->private_dict.blue_shift = 7; dict->private_dict.blue_fuzz = 1; dict->private_dict.lenIV = 4; dict->private_dict.expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); dict->private_dict.blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); } } Exit: return; } /* By mistake, `expansion_factor' appears both in PS_PrivateRec */ /* and CID_FaceDictRec (both are public header files and can't */ /* changed). We simply copy the value. */ FT_CALLBACK_DEF( void ) parse_expansion_factor( CID_Face face, CID_Parser* parser ) { CID_FaceDict dict; if ( parser->num_dict < face->cid.num_dicts ) { dict = face->cid.font_dicts + parser->num_dict; dict->expansion_factor = cid_parser_to_fixed( parser, 0 ); dict->private_dict.expansion_factor = dict->expansion_factor; FT_TRACE4(( "%ld\n", dict->expansion_factor )); } return; } /* By mistake, `CID_FaceDictRec' doesn't contain a field for the */ /* `FontName' keyword. FreeType doesn't need it, but it is nice */ /* to catch it for producing better trace output. */ FT_CALLBACK_DEF( void ) parse_font_name( CID_Face face, CID_Parser* parser ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( parser->num_dict < face->cid.num_dicts ) { T1_TokenRec token; FT_UInt len; cid_parser_to_token( parser, &token ); len = (FT_UInt)( token.limit - token.start ); if ( len ) FT_TRACE4(( " %.*s\n", len, token.start )); else FT_TRACE4(( " <no value>\n" )); } #else FT_UNUSED( face ); FT_UNUSED( parser ); #endif return; } static const T1_FieldRec cid_field_records[] = { #include "cidtoken.h" T1_FIELD_CALLBACK( "FDArray", parse_fd_array, 0 ) T1_FIELD_CALLBACK( "FontMatrix", cid_parse_font_matrix, 0 ) T1_FIELD_CALLBACK( "ExpansionFactor", parse_expansion_factor, 0 ) T1_FIELD_CALLBACK( "FontName", parse_font_name, 0 ) { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 } }; static FT_Error cid_parse_dict( CID_Face face, CID_Loader* loader, FT_Byte* base, FT_ULong size ) { CID_Parser* parser = &loader->parser; parser->root.cursor = base; parser->root.limit = base + size; parser->root.error = FT_Err_Ok; { FT_Byte* cur = base; FT_Byte* limit = cur + size; for (;;) { FT_Byte* newlimit; parser->root.cursor = cur; cid_parser_skip_spaces( parser ); if ( parser->root.cursor >= limit ) newlimit = limit - 1 - 17; else newlimit = parser->root.cursor - 17; /* look for `%ADOBeginFontDict' */ for ( ; cur < newlimit; cur++ ) { if ( *cur == '%' && ft_strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 ) { /* if /FDArray was found, then cid->num_dicts is > 0, and */ /* we can start increasing parser->num_dict */ if ( face->cid.num_dicts > 0 ) { parser->num_dict++; #ifdef FT_DEBUG_LEVEL_TRACE FT_TRACE4(( " FontDict %u", parser->num_dict )); if ( parser->num_dict > face->cid.num_dicts ) FT_TRACE4(( " (ignored)" )); FT_TRACE4(( "\n" )); #endif } } } cur = parser->root.cursor; /* no error can occur in cid_parser_skip_spaces */ if ( cur >= limit ) break; cid_parser_skip_PS_token( parser ); if ( parser->root.cursor >= limit || parser->root.error ) break; /* look for immediates */ if ( *cur == '/' && cur + 2 < limit ) { FT_UInt len; cur++; len = (FT_UInt)( parser->root.cursor - cur ); if ( len > 0 && len < 22 ) { /* now compare the immediate name to the keyword table */ T1_Field keyword = (T1_Field)cid_field_records; for (;;) { FT_Byte* name; name = (FT_Byte*)keyword->ident; if ( !name ) break; if ( cur[0] == name[0] && len == ft_strlen( (const char*)name ) ) { FT_UInt n; for ( n = 1; n < len; n++ ) if ( cur[n] != name[n] ) break; if ( n >= len ) { /* we found it - run the parsing callback */ parser->root.error = cid_load_keyword( face, loader, keyword ); if ( parser->root.error ) return parser->root.error; break; } } keyword++; } } } cur = parser->root.cursor; } if ( !face->cid.num_dicts ) { FT_ERROR(( "cid_parse_dict: No font dictionary found\n" )); return FT_THROW( Invalid_File_Format ); } } return parser->root.error; } /* read the subrmap and the subrs of each font dict */ static FT_Error cid_read_subrs( CID_Face face ) { CID_FaceInfo cid = &face->cid; FT_Memory memory = face->root.memory; FT_Stream stream = face->cid_stream; FT_Error error; FT_UInt n; CID_Subrs subr; FT_UInt max_offsets = 0; FT_ULong* offsets = NULL; PSAux_Service psaux = (PSAux_Service)face->psaux; if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) ) goto Exit; subr = face->subrs; for ( n = 0; n < cid->num_dicts; n++, subr++ ) { CID_FaceDict dict = cid->font_dicts + n; FT_Int lenIV = dict->private_dict.lenIV; FT_UInt count, num_subrs = dict->num_subrs; FT_ULong data_len; FT_Byte* p; if ( !num_subrs ) continue; /* reallocate offsets array if needed */ if ( num_subrs + 1 > max_offsets ) { FT_UInt new_max = FT_PAD_CEIL( num_subrs + 1, 4 ); if ( new_max <= max_offsets ) { error = FT_THROW( Syntax_Error ); goto Fail; } if ( FT_QRENEW_ARRAY( offsets, max_offsets, new_max ) ) goto Fail; max_offsets = new_max; } /* read the subrmap's offsets */ if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) || FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) ) goto Fail; p = (FT_Byte*)stream->cursor; for ( count = 0; count <= num_subrs; count++ ) offsets[count] = cid_get_offset( &p, dict->sd_bytes ); FT_FRAME_EXIT(); /* offsets must be ordered */ for ( count = 1; count <= num_subrs; count++ ) if ( offsets[count - 1] > offsets[count] ) { FT_ERROR(( "cid_read_subrs: offsets are not ordered\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } if ( offsets[num_subrs] > stream->size - cid->data_offset ) { FT_ERROR(( "cid_read_subrs: too large `subrs' offsets\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } /* now, compute the size of subrs charstrings, */ /* allocate, and read them */ data_len = offsets[num_subrs] - offsets[0]; if ( FT_QNEW_ARRAY( subr->code, num_subrs + 1 ) || FT_QALLOC( subr->code[0], data_len ) ) goto Fail; if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) || FT_STREAM_READ( subr->code[0], data_len ) ) goto Fail; /* set up pointers */ for ( count = 1; count <= num_subrs; count++ ) { FT_ULong len; len = offsets[count] - offsets[count - 1]; subr->code[count] = subr->code[count - 1] + len; } /* decrypt subroutines, but only if lenIV >= 0 */ if ( lenIV >= 0 ) { for ( count = 0; count < num_subrs; count++ ) { FT_ULong len; len = offsets[count + 1] - offsets[count]; psaux->t1_decrypt( subr->code[count], len, 4330 ); } } subr->num_subrs = (FT_Int)num_subrs; } Exit: FT_FREE( offsets ); return error; Fail: if ( face->subrs ) { for ( n = 0; n < cid->num_dicts; n++ ) { if ( face->subrs[n].code ) FT_FREE( face->subrs[n].code[0] ); FT_FREE( face->subrs[n].code ); } FT_FREE( face->subrs ); } goto Exit; } static void cid_init_loader( CID_Loader* loader, CID_Face face ) { FT_UNUSED( face ); FT_ZERO( loader ); } static void cid_done_loader( CID_Loader* loader ) { CID_Parser* parser = &loader->parser; /* finalize parser */ cid_parser_done( parser ); } static FT_Error cid_hex_to_binary( FT_Byte* data, FT_ULong data_len, FT_ULong offset, CID_Face face, FT_ULong* data_written ) { FT_Stream stream = face->root.stream; FT_Error error; FT_Byte buffer[256]; FT_Byte *p, *plimit; FT_Byte *d = data, *dlimit; FT_Byte val; FT_Bool upper_nibble, done; if ( FT_STREAM_SEEK( offset ) ) goto Exit; dlimit = d + data_len; p = buffer; plimit = p; upper_nibble = 1; done = 0; while ( d < dlimit ) { if ( p >= plimit ) { FT_ULong oldpos = FT_STREAM_POS(); FT_ULong size = stream->size - oldpos; if ( size == 0 ) { error = FT_THROW( Syntax_Error ); goto Exit; } if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) ) goto Exit; p = buffer; plimit = p + FT_STREAM_POS() - oldpos; } if ( ft_isdigit( *p ) ) val = (FT_Byte)( *p - '0' ); else if ( *p >= 'a' && *p <= 'f' ) val = (FT_Byte)( *p - 'a' + 10 ); else if ( *p >= 'A' && *p <= 'F' ) val = (FT_Byte)( *p - 'A' + 10 ); else if ( *p == ' ' || *p == '\t' || *p == '\r' || *p == '\n' || *p == '\f' || *p == '\0' ) { p++; continue; } else if ( *p == '>' ) { val = 0; done = 1; } else { error = FT_THROW( Syntax_Error ); goto Exit; } if ( upper_nibble ) *d = (FT_Byte)( val << 4 ); else { *d = (FT_Byte)( *d + val ); d++; } upper_nibble = (FT_Byte)( 1 - upper_nibble ); if ( done ) break; p++; } error = FT_Err_Ok; Exit: *data_written = (FT_ULong)( d - data ); return error; } FT_LOCAL_DEF( FT_Error ) cid_face_open( CID_Face face, FT_Int face_index ) { CID_Loader loader; CID_Parser* parser; FT_Memory memory = face->root.memory; FT_Error error; FT_UInt n; CID_FaceInfo cid = &face->cid; FT_ULong binary_length; cid_init_loader( &loader, face ); parser = &loader.parser; error = cid_parser_new( parser, face->root.stream, face->root.memory, (PSAux_Service)face->psaux ); if ( error ) goto Exit; error = cid_parse_dict( face, &loader, parser->postscript, parser->postscript_len ); if ( error ) goto Exit; if ( face_index < 0 ) goto Exit; if ( FT_NEW( face->cid_stream ) ) goto Exit; if ( parser->binary_length ) { if ( parser->binary_length > face->root.stream->size - parser->data_offset ) { FT_TRACE0(( "cid_face_open: adjusting length of binary data\n" )); FT_TRACE0(( " (from %lu to %lu bytes)\n", parser->binary_length, face->root.stream->size - parser->data_offset )); parser->binary_length = face->root.stream->size - parser->data_offset; } /* we must convert the data section from hexadecimal to binary */ if ( FT_QALLOC( face->binary_data, parser->binary_length ) || FT_SET_ERROR( cid_hex_to_binary( face->binary_data, parser->binary_length, parser->data_offset, face, &binary_length ) ) ) goto Exit; FT_Stream_OpenMemory( face->cid_stream, face->binary_data, binary_length ); cid->data_offset = 0; } else { *face->cid_stream = *face->root.stream; cid->data_offset = loader.parser.data_offset; } /* sanity tests */ if ( cid->gd_bytes == 0 ) { FT_ERROR(( "cid_face_open:" " Invalid `GDBytes' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* allow at most 32bit offsets */ if ( cid->fd_bytes > 4 || cid->gd_bytes > 4 ) { FT_ERROR(( "cid_face_open:" " Values of `FDBytes' or `GDBytes' larger than 4\n" )); FT_ERROR(( " " " are not supported\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } binary_length = face->cid_stream->size - cid->data_offset; if ( cid->cidmap_offset > binary_length ) { FT_ERROR(( "cid_face_open: Invalid `CIDMapOffset' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* the initial pre-check prevents the multiplication overflow */ if ( cid->cid_count > FT_ULONG_MAX / 8 || cid->cid_count * ( cid->fd_bytes + cid->gd_bytes ) > binary_length - cid->cidmap_offset ) { FT_ERROR(( "cid_face_open: Invalid `CIDCount' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } for ( n = 0; n < cid->num_dicts; n++ ) { CID_FaceDict dict = cid->font_dicts + n; /* the upper limits are ad-hoc values */ if ( dict->private_dict.blue_shift > 1000 || dict->private_dict.blue_shift < 0 ) { FT_TRACE2(( "cid_face_open:" " setting unlikely BlueShift value %d to default (7)\n", dict->private_dict.blue_shift )); dict->private_dict.blue_shift = 7; } if ( dict->private_dict.blue_fuzz > 1000 || dict->private_dict.blue_fuzz < 0 ) { FT_TRACE2(( "cid_face_open:" " setting unlikely BlueFuzz value %d to default (1)\n", dict->private_dict.blue_fuzz )); dict->private_dict.blue_fuzz = 1; } if ( dict->num_subrs && dict->sd_bytes == 0 ) { FT_ERROR(( "cid_face_open: Invalid `SDBytes' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( dict->sd_bytes > 4 ) { FT_ERROR(( "cid_face_open:" " Values of `SDBytes' larger than 4" " are not supported\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( dict->subrmap_offset > binary_length ) { FT_ERROR(( "cid_face_open: Invalid `SubrMapOffset' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } /* the initial pre-check prevents the multiplication overflow */ if ( dict->num_subrs > FT_UINT_MAX / 4 || dict->num_subrs * dict->sd_bytes > binary_length - dict->subrmap_offset ) { FT_ERROR(( "cid_face_open: Invalid `SubrCount' value\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } /* we can now safely proceed */ error = cid_read_subrs( face ); Exit: cid_done_loader( &loader ); return error; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidload.c
C++
gpl-3.0
25,040
/**************************************************************************** * * cidload.h * * CID-keyed Type1 font loader (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 CIDLOAD_H_ #define CIDLOAD_H_ #include <freetype/internal/ftstream.h> #include "cidparse.h" FT_BEGIN_HEADER typedef struct CID_Loader_ { CID_Parser parser; /* parser used to read the stream */ FT_Int num_chars; /* number of characters in encoding */ } CID_Loader; FT_LOCAL( FT_ULong ) cid_get_offset( FT_Byte** start, FT_UInt offsize ); FT_LOCAL( FT_Error ) cid_face_open( CID_Face face, FT_Int face_index ); FT_END_HEADER #endif /* CIDLOAD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidload.h
C++
gpl-3.0
1,115
/**************************************************************************** * * cidobjs.c * * CID objects manager (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 "cidgload.h" #include "cidload.h" #include <freetype/internal/services/svpscmap.h> #include <freetype/internal/psaux.h> #include <freetype/internal/pshints.h> #include <freetype/ftdriver.h> #include "ciderrs.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 cidobjs /************************************************************************** * * SLOT FUNCTIONS * */ FT_LOCAL_DEF( void ) cid_slot_done( FT_GlyphSlot slot ) { if ( slot->internal ) slot->internal->glyph_hints = NULL; } FT_LOCAL_DEF( FT_Error ) cid_slot_init( FT_GlyphSlot slot ) { CID_Face face; PSHinter_Service pshinter; face = (CID_Face)slot->face; pshinter = (PSHinter_Service)face->pshinter; if ( pshinter ) { FT_Module module; module = FT_Get_Module( slot->face->driver->root.library, "pshinter" ); if ( module ) { T1_Hints_Funcs funcs; funcs = pshinter->get_t1_funcs( module ); slot->internal->glyph_hints = (void*)funcs; } } return 0; } /************************************************************************** * * SIZE FUNCTIONS * */ static PSH_Globals_Funcs cid_size_get_globals_funcs( CID_Size size ) { CID_Face face = (CID_Face)size->root.face; PSHinter_Service pshinter = (PSHinter_Service)face->pshinter; FT_Module module; module = FT_Get_Module( size->root.face->driver->root.library, "pshinter" ); return ( module && pshinter && pshinter->get_globals_funcs ) ? pshinter->get_globals_funcs( module ) : 0; } FT_LOCAL_DEF( void ) cid_size_done( FT_Size cidsize ) /* CID_Size */ { CID_Size size = (CID_Size)cidsize; if ( cidsize->internal->module_data ) { PSH_Globals_Funcs funcs; funcs = cid_size_get_globals_funcs( size ); if ( funcs ) funcs->destroy( (PSH_Globals)cidsize->internal->module_data ); cidsize->internal->module_data = NULL; } } FT_LOCAL_DEF( FT_Error ) cid_size_init( FT_Size cidsize ) /* CID_Size */ { CID_Size size = (CID_Size)cidsize; FT_Error error = FT_Err_Ok; PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size ); if ( funcs ) { PSH_Globals globals; CID_Face face = (CID_Face)cidsize->face; CID_FaceDict dict = face->cid.font_dicts + face->root.face_index; PS_Private priv = &dict->private_dict; error = funcs->create( cidsize->face->memory, priv, &globals ); if ( !error ) cidsize->internal->module_data = globals; } return error; } FT_LOCAL( FT_Error ) cid_size_request( FT_Size size, FT_Size_Request req ) { FT_Error error; PSH_Globals_Funcs funcs; error = FT_Request_Metrics( size->face, req ); if ( error ) goto Exit; funcs = cid_size_get_globals_funcs( (CID_Size)size ); if ( funcs ) funcs->set_scale( (PSH_Globals)size->internal->module_data, size->metrics.x_scale, size->metrics.y_scale, 0, 0 ); Exit: return error; } /************************************************************************** * * FACE FUNCTIONS * */ /************************************************************************** * * @Function: * cid_face_done * * @Description: * Finalizes a given face object. * * @Input: * face :: * A pointer to the face object to destroy. */ FT_LOCAL_DEF( void ) cid_face_done( FT_Face cidface ) /* CID_Face */ { CID_Face face = (CID_Face)cidface; FT_Memory memory; CID_FaceInfo cid; PS_FontInfo info; if ( !face ) return; cid = &face->cid; info = &cid->font_info; memory = cidface->memory; /* release subrs */ if ( face->subrs ) { FT_UInt n; for ( n = 0; n < cid->num_dicts; n++ ) { CID_Subrs subr = face->subrs + n; if ( subr->code ) { FT_FREE( subr->code[0] ); FT_FREE( subr->code ); } } FT_FREE( face->subrs ); } /* release FontInfo strings */ FT_FREE( info->version ); FT_FREE( info->notice ); FT_FREE( info->full_name ); FT_FREE( info->family_name ); FT_FREE( info->weight ); /* release font dictionaries */ FT_FREE( cid->font_dicts ); cid->num_dicts = 0; /* release other strings */ FT_FREE( cid->cid_font_name ); FT_FREE( cid->registry ); FT_FREE( cid->ordering ); cidface->family_name = NULL; cidface->style_name = NULL; FT_FREE( face->binary_data ); FT_FREE( face->cid_stream ); } /************************************************************************** * * @Function: * cid_face_init * * @Description: * Initializes a given CID face object. * * @Input: * stream :: * The source font stream. * * face_index :: * The index of the font face in the resource. * * num_params :: * Number of additional generic parameters. Ignored. * * params :: * Additional generic parameters. Ignored. * * @InOut: * face :: * The newly built face object. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) cid_face_init( FT_Stream stream, FT_Face cidface, /* CID_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { CID_Face face = (CID_Face)cidface; FT_Error error; PSAux_Service psaux; PSHinter_Service pshinter; FT_UNUSED( num_params ); FT_UNUSED( params ); FT_UNUSED( stream ); cidface->num_faces = 1; psaux = (PSAux_Service)face->psaux; if ( !psaux ) { psaux = (PSAux_Service)FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); if ( !psaux ) { FT_ERROR(( "cid_face_init: cannot access `psaux' module\n" )); error = FT_THROW( Missing_Module ); goto Exit; } face->psaux = psaux; } pshinter = (PSHinter_Service)face->pshinter; if ( !pshinter ) { pshinter = (PSHinter_Service)FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "pshinter" ); face->pshinter = pshinter; } FT_TRACE2(( "CID driver\n" )); /* open the tokenizer; this will also check the font format */ if ( FT_STREAM_SEEK( 0 ) ) goto Exit; error = cid_face_open( face, face_index ); if ( error ) goto Exit; /* if we just wanted to check the format, leave successfully now */ if ( face_index < 0 ) goto Exit; /* check the face index */ /* XXX: handle CID fonts with more than a single face */ if ( ( face_index & 0xFFFF ) != 0 ) { FT_ERROR(( "cid_face_init: invalid face index\n" )); error = FT_THROW( Invalid_Argument ); goto Exit; } /* now load the font program into the face object */ /* initialize the face object fields */ /* set up root face fields */ { CID_FaceInfo cid = &face->cid; PS_FontInfo info = &cid->font_info; cidface->num_glyphs = (FT_Long)cid->cid_count; cidface->num_charmaps = 0; cidface->face_index = face_index & 0xFFFF; cidface->face_flags |= FT_FACE_FLAG_SCALABLE | /* scalable outlines */ FT_FACE_FLAG_HORIZONTAL | /* horizontal data */ FT_FACE_FLAG_HINTER; /* has native hinter */ if ( info->is_fixed_pitch ) cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; /* XXX: TODO: add kerning with .afm support */ /* get style name -- be careful, some broken fonts only */ /* have a /FontName dictionary entry! */ cidface->family_name = info->family_name; /* assume "Regular" style if we don't know better */ cidface->style_name = (char *)"Regular"; if ( cidface->family_name ) { char* full = info->full_name; char* family = cidface->family_name; if ( full ) { while ( *full ) { if ( *full == *family ) { family++; full++; } else { if ( *full == ' ' || *full == '-' ) full++; else if ( *family == ' ' || *family == '-' ) family++; else { if ( !*family ) cidface->style_name = full; break; } } } } } else { /* do we have a `/FontName'? */ if ( cid->cid_font_name ) cidface->family_name = cid->cid_font_name; } /* compute style flags */ cidface->style_flags = 0; if ( info->italic_angle ) cidface->style_flags |= FT_STYLE_FLAG_ITALIC; if ( info->weight ) { if ( !ft_strcmp( info->weight, "Bold" ) || !ft_strcmp( info->weight, "Black" ) ) cidface->style_flags |= FT_STYLE_FLAG_BOLD; } /* no embedded bitmap support */ cidface->num_fixed_sizes = 0; cidface->available_sizes = NULL; cidface->bbox.xMin = cid->font_bbox.xMin >> 16; cidface->bbox.yMin = cid->font_bbox.yMin >> 16; /* no `U' suffix here to 0xFFFF! */ cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16; cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16; if ( !cidface->units_per_EM ) cidface->units_per_EM = 1000; cidface->ascender = (FT_Short)( cidface->bbox.yMax ); cidface->descender = (FT_Short)( cidface->bbox.yMin ); cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 ); if ( cidface->height < cidface->ascender - cidface->descender ) cidface->height = (FT_Short)( cidface->ascender - cidface->descender ); cidface->underline_position = (FT_Short)info->underline_position; cidface->underline_thickness = (FT_Short)info->underline_thickness; } Exit: return error; } /************************************************************************** * * @Function: * cid_driver_init * * @Description: * Initializes a given CID driver object. * * @Input: * driver :: * A handle to the target driver object. * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) cid_driver_init( FT_Module module ) { PS_Driver driver = (PS_Driver)module; FT_UInt32 seed; /* set default property values, cf. `ftt1drv.h' */ driver->hinting_engine = FT_HINTING_ADOBE; driver->no_stem_darkening = TRUE; driver->darken_params[0] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1; driver->darken_params[1] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1; driver->darken_params[2] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2; driver->darken_params[3] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2; driver->darken_params[4] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3; driver->darken_params[5] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3; driver->darken_params[6] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4; driver->darken_params[7] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4; /* compute random seed from some memory addresses */ seed = (FT_UInt32)( (FT_Offset)(char*)&seed ^ (FT_Offset)(char*)&module ^ (FT_Offset)(char*)module->memory ); seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 ); driver->random_seed = (FT_Int32)seed; if ( driver->random_seed < 0 ) driver->random_seed = -driver->random_seed; else if ( driver->random_seed == 0 ) driver->random_seed = 123456789; return FT_Err_Ok; } /************************************************************************** * * @Function: * cid_driver_done * * @Description: * Finalizes a given CID driver. * * @Input: * driver :: * A handle to the target CID driver. */ FT_LOCAL_DEF( void ) cid_driver_done( FT_Module driver ) { FT_UNUSED( driver ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidobjs.c
C++
gpl-3.0
13,613
/**************************************************************************** * * cidobjs.h * * CID objects manager (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 CIDOBJS_H_ #define CIDOBJS_H_ #include <ft2build.h> #include <freetype/internal/ftobjs.h> #include FT_CONFIG_CONFIG_H #include <freetype/internal/t1types.h> FT_BEGIN_HEADER /* The following structures must be defined by the hinter */ typedef struct CID_Size_Hints_ CID_Size_Hints; typedef struct CID_Glyph_Hints_ CID_Glyph_Hints; /************************************************************************** * * @Type: * CID_Driver * * @Description: * A handle to a Type 1 driver object. */ typedef struct CID_DriverRec_* CID_Driver; /************************************************************************** * * @Type: * CID_Size * * @Description: * A handle to a Type 1 size object. */ typedef struct CID_SizeRec_* CID_Size; /************************************************************************** * * @Type: * CID_GlyphSlot * * @Description: * A handle to a Type 1 glyph slot object. */ typedef struct CID_GlyphSlotRec_* CID_GlyphSlot; /************************************************************************** * * @Type: * CID_CharMap * * @Description: * A handle to a Type 1 character mapping object. * * @Note: * The Type 1 format doesn't use a charmap but an encoding table. * The driver is responsible for making up charmap objects * corresponding to these tables. */ typedef struct CID_CharMapRec_* CID_CharMap; /************************************************************************** * * HERE BEGINS THE TYPE 1 SPECIFIC STUFF * */ typedef struct CID_SizeRec_ { FT_SizeRec root; FT_Bool valid; } CID_SizeRec; typedef struct CID_GlyphSlotRec_ { FT_GlyphSlotRec root; FT_Bool hint; FT_Bool scaled; FT_Fixed x_scale; FT_Fixed y_scale; } CID_GlyphSlotRec; FT_LOCAL( void ) cid_slot_done( FT_GlyphSlot slot ); FT_LOCAL( FT_Error ) cid_slot_init( FT_GlyphSlot slot ); FT_LOCAL( void ) cid_size_done( FT_Size size ); /* CID_Size */ FT_LOCAL( FT_Error ) cid_size_init( FT_Size size ); /* CID_Size */ FT_LOCAL( FT_Error ) cid_size_request( FT_Size size, /* CID_Size */ FT_Size_Request req ); FT_LOCAL( FT_Error ) cid_face_init( FT_Stream stream, FT_Face face, /* CID_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ); FT_LOCAL( void ) cid_face_done( FT_Face face ); /* CID_Face */ FT_LOCAL( FT_Error ) cid_driver_init( FT_Module driver ); FT_LOCAL( void ) cid_driver_done( FT_Module driver ); FT_END_HEADER #endif /* CIDOBJS_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidobjs.h
C++
gpl-3.0
3,412
/**************************************************************************** * * cidparse.c * * CID-keyed Type1 parser (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/ftstream.h> #include "cidparse.h" #include "ciderrs.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 cidparse /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** INPUT STREAM PARSER *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ #define STARTDATA "StartData" #define STARTDATA_LEN ( sizeof ( STARTDATA ) - 1 ) #define SFNTS "/sfnts" #define SFNTS_LEN ( sizeof ( SFNTS ) - 1 ) FT_LOCAL_DEF( FT_Error ) cid_parser_new( CID_Parser* parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ) { FT_Error error; FT_ULong base_offset, offset, ps_len; FT_Byte *cur, *limit; FT_Byte *arg1, *arg2; FT_ZERO( parser ); psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; base_offset = FT_STREAM_POS(); /* first of all, check the font format in the header */ if ( FT_FRAME_ENTER( 31 ) ) { FT_TRACE2(( " not a CID-keyed font\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } if ( ft_strncmp( (char *)stream->cursor, "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) ) { FT_TRACE2(( " not a CID-keyed font\n" )); error = FT_THROW( Unknown_File_Format ); } FT_FRAME_EXIT(); if ( error ) goto Exit; Again: /* now, read the rest of the file until we find */ /* `StartData' or `/sfnts' */ { /* * The algorithm is as follows (omitting the case with less than 256 * bytes to fill for simplicity). * * 1. Fill the buffer with 256 + STARTDATA_LEN bytes. * * 2. Search for the STARTDATA and SFNTS strings at positions * buffer[0], buffer[1], ..., * buffer[255 + STARTDATA_LEN - SFNTS_LEN]. * * 3. Move the last STARTDATA_LEN bytes to buffer[0]. * * 4. Fill the buffer with 256 bytes, starting at STARTDATA_LEN. * * 5. Repeat with step 2. * */ FT_Byte buffer[256 + STARTDATA_LEN + 1]; /* values for the first loop */ FT_ULong read_len = 256 + STARTDATA_LEN; FT_ULong read_offset = 0; FT_Byte* p = buffer; for ( offset = FT_STREAM_POS(); ; offset += 256 ) { FT_ULong stream_len; stream_len = stream->size - FT_STREAM_POS(); read_len = FT_MIN( read_len, stream_len ); if ( FT_STREAM_READ( p, read_len ) ) goto Exit; /* ensure that we do not compare with data beyond the buffer */ p[read_len] = '\0'; limit = p + read_len - SFNTS_LEN; for ( p = buffer; p < limit; p++ ) { if ( p[0] == 'S' && ft_strncmp( (char*)p, STARTDATA, STARTDATA_LEN ) == 0 ) { /* save offset of binary data after `StartData' */ offset += (FT_ULong)( p - buffer ) + STARTDATA_LEN + 1; goto Found; } else if ( p[1] == 's' && ft_strncmp( (char*)p, SFNTS, SFNTS_LEN ) == 0 ) { offset += (FT_ULong)( p - buffer ) + SFNTS_LEN + 1; goto Found; } } if ( read_offset + read_len < STARTDATA_LEN ) { FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } FT_MEM_MOVE( buffer, buffer + read_offset + read_len - STARTDATA_LEN, STARTDATA_LEN ); /* values for the next loop */ read_len = 256; read_offset = STARTDATA_LEN; p = buffer + read_offset; } } Found: /* We have found the start of the binary data or the `/sfnts' token. */ /* Now rewind and extract the frame corresponding to this PostScript */ /* section. */ ps_len = offset - base_offset; if ( FT_STREAM_SEEK( base_offset ) || FT_FRAME_EXTRACT( ps_len, parser->postscript ) ) goto Exit; parser->data_offset = offset; parser->postscript_len = ps_len; parser->root.base = parser->postscript; parser->root.cursor = parser->postscript; parser->root.limit = parser->root.cursor + ps_len; parser->num_dict = FT_UINT_MAX; /* Finally, we check whether `StartData' or `/sfnts' was real -- */ /* it could be in a comment or string. We also get the arguments */ /* of `StartData' to find out whether the data is represented in */ /* binary or hex format. */ arg1 = parser->root.cursor; cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); arg2 = parser->root.cursor; cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); limit = parser->root.limit; cur = parser->root.cursor; while ( cur <= limit - SFNTS_LEN ) { if ( parser->root.error ) { error = parser->root.error; goto Exit; } if ( cur[0] == 'S' && cur <= limit - STARTDATA_LEN && ft_strncmp( (char*)cur, STARTDATA, STARTDATA_LEN ) == 0 ) { if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 ) { FT_Long tmp = ft_strtol( (const char *)arg2, NULL, 10 ); if ( tmp < 0 ) { FT_ERROR(( "cid_parser_new: invalid length of hex data\n" )); error = FT_THROW( Invalid_File_Format ); } else parser->binary_length = (FT_ULong)tmp; } goto Exit; } else if ( cur[1] == 's' && ft_strncmp( (char*)cur, SFNTS, SFNTS_LEN ) == 0 ) { FT_TRACE2(( "cid_parser_new: cannot handle Type 11 fonts\n" )); error = FT_THROW( Unknown_File_Format ); goto Exit; } cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); arg1 = arg2; arg2 = cur; cur = parser->root.cursor; } /* we haven't found the correct `StartData'; go back and continue */ /* searching */ FT_FRAME_RELEASE( parser->postscript ); if ( !FT_STREAM_SEEK( offset ) ) goto Again; Exit: return error; } #undef STARTDATA #undef STARTDATA_LEN #undef SFNTS #undef SFNTS_LEN FT_LOCAL_DEF( void ) cid_parser_done( CID_Parser* parser ) { /* always free the private dictionary */ if ( parser->postscript ) { FT_Stream stream = parser->stream; FT_FRAME_RELEASE( parser->postscript ); } parser->root.funcs.done( &parser->root ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidparse.c
C++
gpl-3.0
8,487
/**************************************************************************** * * cidparse.h * * CID-keyed Type1 parser (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 CIDPARSE_H_ #define CIDPARSE_H_ #include <freetype/internal/t1types.h> #include <freetype/internal/ftstream.h> #include <freetype/internal/psaux.h> FT_BEGIN_HEADER /************************************************************************** * * @Struct: * CID_Parser * * @Description: * A CID_Parser is an object used to parse a Type 1 fonts very * quickly. * * @Fields: * root :: * The root PS_ParserRec fields. * * stream :: * The current input stream. * * postscript :: * A pointer to the data to be parsed. * * postscript_len :: * The length of the data to be parsed. * * data_offset :: * The start position of the binary data (i.e., the * end of the data to be parsed. * * binary_length :: * The length of the data after the `StartData' * command if the data format is hexadecimal. * * cid :: * A structure which holds the information about * the current font. * * num_dict :: * The number of font dictionaries. */ typedef struct CID_Parser_ { PS_ParserRec root; FT_Stream stream; FT_Byte* postscript; FT_ULong postscript_len; FT_ULong data_offset; FT_ULong binary_length; CID_FaceInfo cid; FT_UInt num_dict; } CID_Parser; FT_LOCAL( FT_Error ) cid_parser_new( CID_Parser* parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ); FT_LOCAL( void ) cid_parser_done( CID_Parser* parser ); /************************************************************************** * * PARSING ROUTINES * */ #define cid_parser_skip_spaces( p ) \ (p)->root.funcs.skip_spaces( &(p)->root ) #define cid_parser_skip_PS_token( p ) \ (p)->root.funcs.skip_PS_token( &(p)->root ) #define cid_parser_to_int( p ) (p)->root.funcs.to_int( &(p)->root ) #define cid_parser_to_fixed( p, t ) (p)->root.funcs.to_fixed( &(p)->root, t ) #define cid_parser_to_coord_array( p, m, c ) \ (p)->root.funcs.to_coord_array( &(p)->root, m, c ) #define cid_parser_to_fixed_array( p, m, f, t ) \ (p)->root.funcs.to_fixed_array( &(p)->root, m, f, t ) #define cid_parser_to_token( p, t ) \ (p)->root.funcs.to_token( &(p)->root, t ) #define cid_parser_to_token_array( p, t, m, c ) \ (p)->root.funcs.to_token_array( &(p)->root, t, m, c ) #define cid_parser_load_field( p, f, o ) \ (p)->root.funcs.load_field( &(p)->root, f, o, 0, 0 ) #define cid_parser_load_field_table( p, f, o ) \ (p)->root.funcs.load_field_table( &(p)->root, f, o, 0, 0 ) FT_END_HEADER #endif /* CIDPARSE_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidparse.h
C++
gpl-3.0
3,518
/**************************************************************************** * * cidriver.c * * CID 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 "cidriver.h" #include "cidgload.h" #include <freetype/internal/ftdebug.h> #include <freetype/internal/ftpsprop.h> #include "ciderrs.h" #include <freetype/internal/services/svpostnm.h> #include <freetype/internal/services/svfntfmt.h> #include <freetype/internal/services/svpsinfo.h> #include <freetype/internal/services/svcid.h> #include <freetype/internal/services/svprop.h> #include <freetype/ftdriver.h> #include <freetype/internal/psaux.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 ciddriver /* * POSTSCRIPT NAME SERVICE * */ static const char* cid_get_postscript_name( CID_Face face ) { const char* result = face->cid.cid_font_name; if ( result && result[0] == '/' ) result++; return result; } static const FT_Service_PsFontNameRec cid_service_ps_name = { (FT_PsName_GetFunc)cid_get_postscript_name /* get_ps_font_name */ }; /* * POSTSCRIPT INFO SERVICE * */ static FT_Error cid_ps_get_font_info( FT_Face face, PS_FontInfoRec* afont_info ) { *afont_info = ((CID_Face)face)->cid.font_info; return FT_Err_Ok; } static FT_Error cid_ps_get_font_extra( FT_Face face, PS_FontExtraRec* afont_extra ) { *afont_extra = ((CID_Face)face)->font_extra; return FT_Err_Ok; } static const FT_Service_PsInfoRec cid_service_ps_info = { (PS_GetFontInfoFunc) cid_ps_get_font_info, /* ps_get_font_info */ (PS_GetFontExtraFunc) cid_ps_get_font_extra, /* ps_get_font_extra */ /* unsupported with CID fonts */ (PS_HasGlyphNamesFunc) NULL, /* ps_has_glyph_names */ /* unsupported */ (PS_GetFontPrivateFunc)NULL, /* ps_get_font_private */ /* not implemented */ (PS_GetFontValueFunc) NULL /* ps_get_font_value */ }; /* * CID INFO SERVICE * */ static FT_Error cid_get_ros( CID_Face face, const char* *registry, const char* *ordering, FT_Int *supplement ) { CID_FaceInfo cid = &face->cid; if ( registry ) *registry = cid->registry; if ( ordering ) *ordering = cid->ordering; if ( supplement ) *supplement = cid->supplement; return FT_Err_Ok; } static FT_Error cid_get_is_cid( CID_Face face, FT_Bool *is_cid ) { FT_Error error = FT_Err_Ok; FT_UNUSED( face ); if ( is_cid ) *is_cid = 1; /* cid driver is only used for CID keyed fonts */ return error; } static FT_Error cid_get_cid_from_glyph_index( CID_Face face, FT_UInt glyph_index, FT_UInt *cid ) { FT_Error error = FT_Err_Ok; FT_UNUSED( face ); if ( cid ) *cid = glyph_index; /* identity mapping */ return error; } static const FT_Service_CIDRec cid_service_cid_info = { (FT_CID_GetRegistryOrderingSupplementFunc) cid_get_ros, /* get_ros */ (FT_CID_GetIsInternallyCIDKeyedFunc) cid_get_is_cid, /* get_is_cid */ (FT_CID_GetCIDFromGlyphIndexFunc) cid_get_cid_from_glyph_index /* get_cid_from_glyph_index */ }; /* * PROPERTY SERVICE * */ FT_DEFINE_SERVICE_PROPERTIESREC( cid_service_properties, (FT_Properties_SetFunc)ps_property_set, /* set_property */ (FT_Properties_GetFunc)ps_property_get ) /* get_property */ /* * SERVICE LIST * */ static const FT_ServiceDescRec cid_services[] = { { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_CID }, { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cid_service_ps_name }, { FT_SERVICE_ID_POSTSCRIPT_INFO, &cid_service_ps_info }, { FT_SERVICE_ID_CID, &cid_service_cid_info }, { FT_SERVICE_ID_PROPERTIES, &cid_service_properties }, { NULL, NULL } }; FT_CALLBACK_DEF( FT_Module_Interface ) cid_get_interface( FT_Module module, const char* cid_interface ) { FT_UNUSED( module ); return ft_service_list_lookup( cid_services, cid_interface ); } FT_CALLBACK_TABLE_DEF const FT_Driver_ClassRec t1cid_driver_class = { { FT_MODULE_FONT_DRIVER | FT_MODULE_DRIVER_SCALABLE | FT_MODULE_DRIVER_HAS_HINTER, sizeof ( PS_DriverRec ), "t1cid", /* module name */ 0x10000L, /* version 1.0 of driver */ 0x20000L, /* requires FreeType 2.0 */ NULL, /* module-specific interface */ cid_driver_init, /* FT_Module_Constructor module_init */ cid_driver_done, /* FT_Module_Destructor module_done */ cid_get_interface /* FT_Module_Requester get_interface */ }, sizeof ( CID_FaceRec ), sizeof ( CID_SizeRec ), sizeof ( CID_GlyphSlotRec ), cid_face_init, /* FT_Face_InitFunc init_face */ cid_face_done, /* FT_Face_DoneFunc done_face */ cid_size_init, /* FT_Size_InitFunc init_size */ cid_size_done, /* FT_Size_DoneFunc done_size */ cid_slot_init, /* FT_Slot_InitFunc init_slot */ cid_slot_done, /* FT_Slot_DoneFunc done_slot */ cid_slot_load_glyph, /* FT_Slot_LoadFunc load_glyph */ NULL, /* FT_Face_GetKerningFunc get_kerning */ NULL, /* FT_Face_AttachFunc attach_file */ NULL, /* FT_Face_GetAdvancesFunc get_advances */ cid_size_request, /* FT_Size_RequestFunc request_size */ NULL /* FT_Size_SelectFunc select_size */ }; /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidriver.c
C++
gpl-3.0
6,691
/**************************************************************************** * * cidriver.h * * High-level CID 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 CIDRIVER_H_ #define CIDRIVER_H_ #include <freetype/internal/ftdrv.h> FT_BEGIN_HEADER FT_CALLBACK_TABLE const FT_Driver_ClassRec t1cid_driver_class; FT_END_HEADER #endif /* CIDRIVER_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidriver.h
C++
gpl-3.0
772
/**************************************************************************** * * cidtoken.h * * CID token definitions (specification 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. * */ #undef FT_STRUCTURE #define FT_STRUCTURE CID_FaceInfoRec #undef T1CODE #define T1CODE T1_FIELD_LOCATION_CID_INFO T1_FIELD_KEY ( "CIDFontName", cid_font_name, 0 ) T1_FIELD_FIXED ( "CIDFontVersion", cid_version, 0 ) T1_FIELD_NUM ( "CIDFontType", cid_font_type, 0 ) T1_FIELD_STRING ( "Registry", registry, 0 ) T1_FIELD_STRING ( "Ordering", ordering, 0 ) T1_FIELD_NUM ( "Supplement", supplement, 0 ) T1_FIELD_NUM ( "UIDBase", uid_base, 0 ) T1_FIELD_NUM_TABLE( "XUID", xuid, 16, 0 ) T1_FIELD_NUM ( "CIDMapOffset", cidmap_offset, 0 ) T1_FIELD_NUM ( "FDBytes", fd_bytes, 0 ) T1_FIELD_NUM ( "GDBytes", gd_bytes, 0 ) T1_FIELD_NUM ( "CIDCount", cid_count, 0 ) #undef FT_STRUCTURE #define FT_STRUCTURE PS_FontInfoRec #undef T1CODE #define T1CODE T1_FIELD_LOCATION_FONT_INFO T1_FIELD_STRING( "version", version, 0 ) T1_FIELD_STRING( "Notice", notice, 0 ) T1_FIELD_STRING( "FullName", full_name, 0 ) T1_FIELD_STRING( "FamilyName", family_name, 0 ) T1_FIELD_STRING( "Weight", weight, 0 ) T1_FIELD_NUM ( "ItalicAngle", italic_angle, 0 ) T1_FIELD_BOOL ( "isFixedPitch", is_fixed_pitch, 0 ) T1_FIELD_NUM ( "UnderlinePosition", underline_position, 0 ) T1_FIELD_NUM ( "UnderlineThickness", underline_thickness, 0 ) #undef FT_STRUCTURE #define FT_STRUCTURE PS_FontExtraRec #undef T1CODE #define T1CODE T1_FIELD_LOCATION_FONT_EXTRA T1_FIELD_NUM ( "FSType", fs_type, 0 ) #undef FT_STRUCTURE #define FT_STRUCTURE CID_FaceDictRec #undef T1CODE #define T1CODE T1_FIELD_LOCATION_FONT_DICT T1_FIELD_NUM ( "PaintType", paint_type, 0 ) T1_FIELD_NUM ( "FontType", font_type, 0 ) T1_FIELD_NUM ( "SubrMapOffset", subrmap_offset, 0 ) T1_FIELD_NUM ( "SDBytes", sd_bytes, 0 ) T1_FIELD_NUM ( "SubrCount", num_subrs, 0 ) T1_FIELD_NUM ( "lenBuildCharArray", len_buildchar, 0 ) T1_FIELD_FIXED( "ForceBoldThreshold", forcebold_threshold, 0 ) T1_FIELD_FIXED( "StrokeWidth", stroke_width, 0 ) #undef FT_STRUCTURE #define FT_STRUCTURE PS_PrivateRec #undef T1CODE #define T1CODE T1_FIELD_LOCATION_PRIVATE T1_FIELD_NUM ( "UniqueID", unique_id, 0 ) T1_FIELD_NUM ( "lenIV", lenIV, 0 ) T1_FIELD_NUM ( "LanguageGroup", language_group, 0 ) T1_FIELD_NUM ( "password", password, 0 ) T1_FIELD_FIXED_1000( "BlueScale", blue_scale, 0 ) T1_FIELD_NUM ( "BlueShift", blue_shift, 0 ) T1_FIELD_NUM ( "BlueFuzz", blue_fuzz, 0 ) T1_FIELD_NUM_TABLE ( "BlueValues", blue_values, 14, 0 ) T1_FIELD_NUM_TABLE ( "OtherBlues", other_blues, 10, 0 ) T1_FIELD_NUM_TABLE ( "FamilyBlues", family_blues, 14, 0 ) T1_FIELD_NUM_TABLE ( "FamilyOtherBlues", family_other_blues, 10, 0 ) T1_FIELD_NUM_TABLE2( "StdHW", standard_width, 1, 0 ) T1_FIELD_NUM_TABLE2( "StdVW", standard_height, 1, 0 ) T1_FIELD_NUM_TABLE2( "MinFeature", min_feature, 2, 0 ) T1_FIELD_NUM_TABLE ( "StemSnapH", snap_widths, 12, 0 ) T1_FIELD_NUM_TABLE ( "StemSnapV", snap_heights, 12, 0 ) T1_FIELD_BOOL ( "ForceBold", force_bold, 0 ) #undef FT_STRUCTURE #define FT_STRUCTURE FT_BBox #undef T1CODE #define T1CODE T1_FIELD_LOCATION_BBOX T1_FIELD_BBOX( "FontBBox", xMin, 0 ) /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/cidtoken.h
C++
gpl-3.0
4,387
# # FreeType 2 CID 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 += TYPE1CID_DRIVER define TYPE1CID_DRIVER $(OPEN_DRIVER) FT_Driver_ClassRec, t1cid_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)cid $(ECHO_DRIVER_DESC)Postscript CID-keyed fonts, no known extension$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/module.mk
mk
gpl-3.0
679
# # FreeType 2 CID 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. # CID driver directory # CID_DIR := $(SRC_DIR)/cid CID_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(CID_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # CID driver sources (i.e., C files) # CID_DRV_SRC := $(CID_DIR)/cidparse.c \ $(CID_DIR)/cidload.c \ $(CID_DIR)/cidriver.c \ $(CID_DIR)/cidgload.c \ $(CID_DIR)/cidobjs.c # CID driver headers # CID_DRV_H := $(CID_DRV_SRC:%.c=%.h) \ $(CID_DIR)/cidtoken.h \ $(CID_DIR)/ciderrs.h # CID driver object(s) # # CID_DRV_OBJ_M is used during `multi' builds # CID_DRV_OBJ_S is used during `single' builds # CID_DRV_OBJ_M := $(CID_DRV_SRC:$(CID_DIR)/%.c=$(OBJ_DIR)/%.$O) CID_DRV_OBJ_S := $(OBJ_DIR)/type1cid.$O # CID driver source file for single build # CID_DRV_SRC_S := $(CID_DIR)/type1cid.c # CID driver - single object # $(CID_DRV_OBJ_S): $(CID_DRV_SRC_S) $(CID_DRV_SRC) $(FREETYPE_H) $(CID_DRV_H) $(CID_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(CID_DRV_SRC_S)) # CID driver - multiple objects # $(OBJ_DIR)/%.$O: $(CID_DIR)/%.c $(FREETYPE_H) $(CID_DRV_H) $(CID_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(CID_DRV_OBJ_S) DRV_OBJS_M += $(CID_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/rules.mk
mk
gpl-3.0
1,818
/**************************************************************************** * * type1cid.c * * FreeType OpenType driver 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 "cidgload.c" #include "cidload.c" #include "cidobjs.c" #include "cidparse.c" #include "cidriver.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/cid/type1cid.c
C++
gpl-3.0
710
// Copyright (c) 2019 nyorain // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt #define _XOPEN_SOURCE 600 #define _POSIX_C_SOURCE 200809L #define _WIN32_WINNT 0x0600 // Needed on windows so that we can use sprintf without warning. #define _CRT_SECURE_NO_WARNINGS #include <dlg/output.h> #include <dlg/dlg.h> #include <wchar.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <string.h> const char* const dlg_reset_sequence = "\033[0m"; const struct dlg_style dlg_default_output_styles[] = { {dlg_text_style_italic, dlg_color_green, dlg_color_none}, {dlg_text_style_dim, dlg_color_gray, dlg_color_none}, {dlg_text_style_none, dlg_color_cyan, dlg_color_none}, {dlg_text_style_none, dlg_color_yellow, dlg_color_none}, {dlg_text_style_none, dlg_color_red, dlg_color_none}, {dlg_text_style_bold, dlg_color_red, dlg_color_none} }; static void* xalloc(size_t size) { void* ret = calloc(size, 1); if(!ret) fprintf(stderr, "dlg: calloc returned NULL, probably crashing (size: %zu)\n", size); return ret; } static void* xrealloc(void* ptr, size_t size) { void* ret = realloc(ptr, size); if(!ret) fprintf(stderr, "dlg: realloc returned NULL, probably crashing (size: %zu)\n", size); return ret; } struct dlg_tag_func_pair { const char* tag; const char* func; }; struct dlg_data { const char** tags; // vec struct dlg_tag_func_pair* pairs; // vec char* buffer; size_t buffer_size; }; static dlg_handler g_handler = dlg_default_output; static void* g_data = NULL; static void dlg_free_data(void* data); static struct dlg_data* dlg_create_data(void); // platform-specific #if defined(__unix__) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__) #define DLG_OS_UNIX #include <unistd.h> #include <pthread.h> #include <sys/time.h> static pthread_key_t dlg_data_key; static void dlg_main_cleanup(void) { void* data = pthread_getspecific(dlg_data_key); if(data) { dlg_free_data(data); pthread_setspecific(dlg_data_key, NULL); } } static void init_data_key(void) { pthread_key_create(&dlg_data_key, dlg_free_data); atexit(dlg_main_cleanup); } static struct dlg_data* dlg_data(void) { static pthread_once_t key_once = PTHREAD_ONCE_INIT; pthread_once(&key_once, init_data_key); void* data = pthread_getspecific(dlg_data_key); if(!data) { data = dlg_create_data(); pthread_setspecific(dlg_data_key, data); } return (struct dlg_data*) data; } static void lock_file(FILE* file) { flockfile(file); } static void unlock_file(FILE* file) { funlockfile(file); } bool dlg_is_tty(FILE* stream) { return isatty(fileno(stream)); } static unsigned get_msecs(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_usec; } // platform switch -- end unix #elif defined(WIN32) || defined(_WIN32) || defined(_WIN64) #define DLG_OS_WIN #define WIN32_LEAN_AND_MEAN #define DEFINE_CONSOLEV2_PROPERTIES #include <windows.h> #include <io.h> // thanks for nothing, microsoft #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #endif // the max buffer size we will convert on the stack #define DLG_MAX_STACK_BUF_SIZE 1024 static void WINAPI dlg_fls_destructor(void* data) { dlg_free_data(data); } // TODO: error handling static BOOL CALLBACK dlg_init_fls(PINIT_ONCE io, void* param, void** lpContext) { (void) io; (void) param; **((DWORD**) lpContext) = FlsAlloc(dlg_fls_destructor); return true; } static struct dlg_data* dlg_data(void) { static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; static DWORD fls = 0; void* flsp = (void*) &fls; InitOnceExecuteOnce(&init_once, dlg_init_fls, NULL, &flsp); void* data = FlsGetValue(fls); if(!data) { data = dlg_create_data(); FlsSetValue(fls, data); } return (struct dlg_data*) data; } static void lock_file(FILE* file) { _lock_file(file); } static void unlock_file(FILE* file) { _unlock_file(file); } bool dlg_is_tty(FILE* stream) { return _isatty(_fileno(stream)); } #ifdef DLG_WIN_CONSOLE static bool init_ansi_console(void) { HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE err = GetStdHandle(STD_ERROR_HANDLE); if(out == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE) return false; DWORD outMode, errMode; if(!GetConsoleMode(out, &outMode) || !GetConsoleMode(err, &errMode)) return false; outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; errMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; if(!SetConsoleMode(out, outMode) || !SetConsoleMode(out, errMode)) return false; return true; } static bool win_write_heap(void* handle, int needed, const char* format, va_list args) { char* buf1 = xalloc(3 * needed + 3 + (needed % 2)); wchar_t* buf2 = (wchar_t*) (buf1 + needed + 1 + (needed % 2)); vsnprintf(buf1, needed + 1, format, args); needed = MultiByteToWideChar(CP_UTF8, 0, buf1, needed, buf2, needed + 1); bool ret = (needed != 0 && WriteConsoleW(handle, buf2, needed, NULL, NULL) != 0); free(buf1); return ret; } static bool win_write_stack(void* handle, int needed, const char* format, va_list args) { char buf1[DLG_MAX_STACK_BUF_SIZE]; wchar_t buf2[DLG_MAX_STACK_BUF_SIZE]; vsnprintf(buf1, needed + 1, format, args); needed = MultiByteToWideChar(CP_UTF8, 0, buf1, needed, buf2, needed + 1); return (needed != 0 && WriteConsoleW(handle, buf2, needed, NULL, NULL) != 0); } #endif // DLG_WIN_CONSOLE static unsigned get_msecs() { SYSTEMTIME st; GetSystemTime(&st); return st.wMilliseconds; } #else // platform switch -- end windows #error Cannot determine platform (needed for color and utf-8 and stuff) #endif // general void dlg_escape_sequence(struct dlg_style style, char buf[12]) { int nums[3]; unsigned int count = 0; if(style.fg != dlg_color_none) { nums[count++] = style.fg + 30; } if(style.bg != dlg_color_none) { nums[count++] = style.fg + 40; } if(style.style != dlg_text_style_none) { nums[count++] = style.style; } switch(count) { case 1: snprintf(buf, 12, "\033[%dm", nums[0]); break; case 2: snprintf(buf, 12, "\033[%d;%dm", nums[0], nums[1]); break; case 3: snprintf(buf, 12, "\033[%d;%d;%dm", nums[0], nums[1], nums[2]); break; default: buf[0] = '\0'; break; } } int dlg_vfprintf(FILE* stream, const char* format, va_list args) { #if defined(DLG_OS_WIN) && defined(DLG_WIN_CONSOLE) void* handle = NULL; if(stream == stdout) { handle = GetStdHandle(STD_OUTPUT_HANDLE); } else if(stream == stderr) { handle = GetStdHandle(STD_ERROR_HANDLE); } if(handle) { va_list args_copy; va_copy(args_copy, args); int needed = vsnprintf(NULL, 0, format, args_copy); va_end(args_copy); if(needed < 0) { return needed; } // We don't allocate too much on the stack // but we also don't want to call alloc every logging call // or use another cached buffer if(needed >= DLG_MAX_STACK_BUF_SIZE) { if(win_write_heap(handle, needed, format, args)) { return needed; } } else { if(win_write_stack(handle, needed, format, args)) { return needed; } } } #endif return vfprintf(stream, format, args); } int dlg_fprintf(FILE* stream, const char* format, ...) { va_list args; va_start(args, format); int ret = dlg_vfprintf(stream, format, args); va_end(args); return ret; } int dlg_styled_fprintf(FILE* stream, struct dlg_style style, const char* format, ...) { char buf[12]; dlg_escape_sequence(style, buf); fprintf(stream, "%s", buf); va_list args; va_start(args, format); int ret = dlg_vfprintf(stream, format, args); va_end(args); fprintf(stream, "%s", dlg_reset_sequence); return ret; } void dlg_generic_output(dlg_generic_output_handler output, void* data, unsigned int features, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6]) { // We never print any dynamic content below so we can be sure at compile // time that a buffer of size 64 is large enough. char format_buf[64]; char* format = format_buf; if(features & dlg_output_style) { format += sprintf(format, "%%s"); } if(features & (dlg_output_time | dlg_output_file_line | dlg_output_tags | dlg_output_func)) { format += sprintf(format, "["); } bool first_meta = true; if(features & dlg_output_time) { format += sprintf(format, "%%h"); first_meta = false; } if(features & dlg_output_time_msecs) { if(!first_meta) { format += sprintf(format, ":"); } format += sprintf(format, "%%m"); first_meta = false; } if(features & dlg_output_file_line) { if(!first_meta) { format += sprintf(format, " "); } format += sprintf(format, "%%o"); first_meta = false; } if(features & dlg_output_func) { if(!first_meta) { format += sprintf(format, " "); } format += sprintf(format, "%%f"); first_meta = false; } if(features & dlg_output_tags) { if(!first_meta) { format += sprintf(format, " "); } format += sprintf(format, "{%%t}"); first_meta = false; } if(features & (dlg_output_time | dlg_output_file_line | dlg_output_tags | dlg_output_func)) { format += sprintf(format, "] "); } format += sprintf(format, "%%c"); if(features & dlg_output_newline) { format += sprintf(format, "\n"); } *format = '\0'; dlg_generic_outputf(output, data, format_buf, origin, string, styles); } void dlg_generic_outputf(dlg_generic_output_handler output, void* data, const char* format_string, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6]) { bool reset_style = false; for(const char* it = format_string; *it; it++) { if(*it != '%') { output(data, "%c", *it); continue; } char next = *(it + 1); // must be valid since *it is not '\0' if(next == 'h') { time_t t = time(NULL); struct tm tm_info; #ifdef DLG_OS_WIN if(localtime_s(&tm_info, &t)) { #else if(!localtime_r(&t, &tm_info)) { #endif output(data, "<DATE ERROR>"); } else { char timebuf[32]; strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm_info); output(data, "%s", timebuf); } it++; } else if(next == 'm') { output(data, "%06d", get_msecs()); it++; } else if(next == 't') { bool first_tag = true; for(const char** tags = origin->tags; *tags; ++tags) { if(!first_tag) { output(data, ", "); } output(data, "%s", *tags); first_tag = false; } ++it; } else if(next == 'f') { output(data, "%s", origin->func); ++it; } else if(next == 'o') { output(data, "%s:%u", origin->file, origin->line); ++it; } else if(next == 's') { char buf[12]; dlg_escape_sequence(styles[origin->level], buf); output(data, "%s", buf); reset_style = true; ++it; } else if(next == 'r') { output(data, "%s", dlg_reset_sequence); reset_style = false; ++it; } else if(next == 'c') { if(origin->expr && string) { output(data, "assertion '%s' failed: '%s'", origin->expr, string); } else if(origin->expr) { output(data, "assertion '%s' failed", origin->expr); } else if(string) { output(data, "%s", string); } ++it; } else if(next == '%') { output(data, "%s", "%"); ++it; } else { // in this case it's a '%' without known format specifier following output(data, "%s", "%"); } } if(reset_style) { output(data, "%s", dlg_reset_sequence); } } struct buf { char* buf; size_t* size; }; static void print_size(void* size, const char* format, ...) { va_list args; va_start(args, format); int ret = vsnprintf(NULL, 0, format, args); va_end(args); if(ret > 0) { *((size_t*) size) += ret; } } static void print_buf(void* dbuf, const char* format, ...) { struct buf* buf = (struct buf*) dbuf; va_list args; va_start(args, format); int printed = vsnprintf(buf->buf, *buf->size, format, args); va_end(args); if(printed > 0) { *buf->size -= printed; buf->buf += printed; } } void dlg_generic_output_buf(char* buf, size_t* size, unsigned int features, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6]) { if(buf) { struct buf mbuf; mbuf.buf = buf; mbuf.size = size; dlg_generic_output(print_buf, &mbuf, features, origin, string, styles); } else { *size = 0; dlg_generic_output(print_size, size, features, origin, string, styles); } } void dlg_generic_outputf_buf(char* buf, size_t* size, const char* format_string, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6]) { if(buf) { struct buf mbuf; mbuf.buf = buf; mbuf.size = size; dlg_generic_outputf(print_buf, &mbuf, format_string, origin, string, styles); } else { *size = 0; dlg_generic_outputf(print_size, size, format_string, origin, string, styles); } } static void print_stream(void* stream, const char* format, ...) { va_list args; va_start(args, format); dlg_vfprintf((FILE*) stream, format, args); va_end(args); } void dlg_generic_output_stream(FILE* stream, unsigned int features, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6]) { stream = stream ? stream : stdout; if(features & dlg_output_threadsafe) { lock_file(stream); } dlg_generic_output(print_stream, stream, features, origin, string, styles); if(features & dlg_output_threadsafe) { unlock_file(stream); } } void dlg_generic_outputf_stream(FILE* stream, const char* format_string, const struct dlg_origin* origin, const char* string, const struct dlg_style styles[6], bool lock_stream) { stream = stream ? stream : stdout; if(lock_stream) { lock_file(stream); } dlg_generic_outputf(print_stream, stream, format_string, origin, string, styles); if(lock_stream) { unlock_file(stream); } } void dlg_default_output(const struct dlg_origin* origin, const char* string, void* data) { FILE* stream = data ? (FILE*) data : stdout; unsigned int features = dlg_output_file_line | dlg_output_newline | dlg_output_threadsafe; #ifdef DLG_DEFAULT_OUTPUT_ALWAYS_COLOR dlg_win_init_ansi(); features |= dlg_output_style; #else if(dlg_is_tty(stream) && dlg_win_init_ansi()) { features |= dlg_output_style; } #endif dlg_generic_output_stream(stream, features, origin, string, dlg_default_output_styles); fflush(stream); } bool dlg_win_init_ansi(void) { #if defined(DLG_OS_WIN) && defined(DLG_WIN_CONSOLE) // TODO: use init once static volatile LONG status = 0; LONG res = InterlockedCompareExchange(&status, 1, 0); if(res == 0) { // not initialized InterlockedExchange(&status, 3 + init_ansi_console()); } while(status == 1); // currently initialized in another thread, spinlock return (status == 4); #else return true; #endif } // small dynamic vec/array implementation // Since the macros vec_init and vec_add[c]/vec_push might // change the pointers value it must not be referenced somewhere else. #define vec__raw(vec) (((unsigned int*) vec) - 2) static void* vec_do_create(unsigned int typesize, unsigned int cap, unsigned int size) { unsigned long a = (size > cap) ? size : cap; void* ptr = xalloc(2 * sizeof(unsigned int) + a * typesize); unsigned int* begin = (unsigned int*) ptr; begin[0] = size * typesize; begin[1] = a * typesize; return begin + 2; } // NOTE: can be more efficient if we are allowed to reorder vector static void vec_do_erase(void* vec, unsigned int pos, unsigned int size) { unsigned int* begin = vec__raw(vec); begin[0] -= size; char* buf = (char*) vec; memcpy(buf + pos, buf + pos + size, size); } static void* vec_do_add(void** vec, unsigned int size) { unsigned int* begin = vec__raw(*vec); unsigned int needed = begin[0] + size; if(needed >= begin[1]) { void* ptr = xrealloc(begin, sizeof(unsigned int) * 2 + needed * 2); begin = (unsigned int*) ptr; begin[1] = needed * 2; (*vec) = begin + 2; } void* ptr = ((char*) (*vec)) + begin[0]; begin[0] += size; return ptr; } #define vec_create(type, size) (type*) vec_do_create(sizeof(type), size * 2, size) #define vec_create_reserve(type, size, capacity) (type*) vec_do_create(sizeof(type), capcity, size) #define vec_init(array, size) array = vec_do_create(sizeof(*array), size * 2, size) #define vec_init_reserve(array, size, capacity) *((void**) &array) = vec_do_create(sizeof(*array), capacity, size) #define vec_free(vec) (free((vec) ? vec__raw(vec) : NULL), vec = NULL) #define vec_erase_range(vec, pos, count) vec_do_erase(vec, pos * sizeof(*vec), count * sizeof(*vec)) #define vec_erase(vec, pos) vec_do_erase(vec, pos * sizeof(*vec), sizeof(*vec)) #define vec_size(vec) (vec__raw(vec)[0] / sizeof(*vec)) #define vec_capacity(vec) (vec_raw(vec)[1] / sizeof(*vec)) #define vec_add(vec) vec_do_add((void**) &vec, sizeof(*vec)) #define vec_addc(vec, count) (vec_do_add((void**) &vec, sizeof(*vec) * count)) #define vec_push(vec, value) (vec_do_add((void**) &vec, sizeof(*vec)), vec_last(vec) = (value)) #define vec_pop(vec) (vec__raw(vec)[0] -= sizeof(*vec)) #define vec_popc(vec, count) (vec__raw(vec)[0] -= sizeof(*vec) * count) #define vec_clear(vec) (vec__raw(vec)[0] = 0) #define vec_last(vec) (vec[vec_size(vec) - 1]) static struct dlg_data* dlg_create_data(void) { struct dlg_data* data = (struct dlg_data*) xalloc(sizeof(struct dlg_data)); vec_init_reserve(data->tags, 0, 20); vec_init_reserve(data->pairs, 0, 20); data->buffer_size = 100; data->buffer = (char*) xalloc(data->buffer_size); return data; } static void dlg_free_data(void* ddata) { struct dlg_data* data = (struct dlg_data*) ddata; if(data) { vec_free(data->pairs); vec_free(data->tags); free(data->buffer); free(data); } } void dlg_add_tag(const char* tag, const char* func) { struct dlg_data* data = dlg_data(); struct dlg_tag_func_pair* pair = (struct dlg_tag_func_pair*) vec_add(data->pairs); pair->tag = tag; pair->func = func; } bool dlg_remove_tag(const char* tag, const char* func) { struct dlg_data* data = dlg_data(); for(unsigned int i = 0; i < vec_size(data->pairs); ++i) { if(data->pairs[i].func == func && data->pairs[i].tag == tag) { vec_erase(data->pairs, i); return true; } } return false; } char** dlg_thread_buffer(size_t** size) { struct dlg_data* data = dlg_data(); if(size) { *size = &data->buffer_size; } return &data->buffer; } void dlg_set_handler(dlg_handler handler, void* data) { g_handler = handler; g_data = data; } dlg_handler dlg_get_handler(void** data) { *data = g_data; return g_handler; } const char* dlg__printf_format(const char* str, ...) { va_list vlist; va_start(vlist, str); va_list vlistcopy; va_copy(vlistcopy, vlist); int needed = vsnprintf(NULL, 0, str, vlist); if(needed < 0) { printf("dlg__printf_format: invalid format given\n"); va_end(vlist); va_end(vlistcopy); return NULL; } va_end(vlist); size_t* buf_size; char** buf = dlg_thread_buffer(&buf_size); if(*buf_size <= (unsigned int) needed) { *buf_size = (needed + 1) * 2; *buf = (char*) xrealloc(*buf, *buf_size); } vsnprintf(*buf, *buf_size, str, vlistcopy); va_end(vlistcopy); return *buf; } void dlg__do_log(enum dlg_level lvl, const char* const* tags, const char* file, int line, const char* func, const char* string, const char* expr) { struct dlg_data* data = dlg_data(); unsigned int tag_count = 0; // push default tags while(tags[tag_count]) { vec_push(data->tags, tags[tag_count++]); } // push current global tags for(size_t i = 0; i < vec_size(data->pairs); ++i) { const struct dlg_tag_func_pair pair = data->pairs[i]; if(pair.func == NULL || !strcmp(pair.func, func)) { vec_push(data->tags, pair.tag); } } // push call-specific tags, skip first terminating NULL ++tag_count; while(tags[tag_count]) { vec_push(data->tags, tags[tag_count++]); } vec_push(data->tags, NULL); // terminating NULL struct dlg_origin origin; origin.level = lvl; origin.file = file; origin.line = line; origin.func = func; origin.expr = expr; origin.tags = data->tags; g_handler(&origin, string, g_data); vec_clear(data->tags); } #ifdef _MSC_VER // shitty msvc compatbility // meson gives us sane paths (separated by '/') while on MSVC, // __FILE__ contains a '\\' separator. static bool path_same(char a, char b) { return (a == b) || (a == '/' && b == '\\') || (a == '\\' && b == '/'); } #else static inline bool path_same(char a, char b) { return a == b; } #endif const char* dlg__strip_root_path(const char* file, const char* base) { if(!file) { return NULL; } const char* saved = file; if(*file == '.') { // relative path detected while(*(++file) == '.' || *file == '/' || *file == '\\'); if(*file == '\0') { // weird case: purely relative path without file return saved; } return file; } // strip base from file if it is given if(base) { char fn = *file; char bn = *base; while(bn != '\0' && path_same(fn, bn)) { fn = *(++file); bn = *(++base); } if(fn == '\0' || bn != '\0') { // weird case: base isn't prefix of file return saved; } } return file; }
whupdup/frame
real/third_party/freetype-2.12.0/src/dlg/dlg.c
C++
gpl-3.0
21,039
/**************************************************************************** * * dlgwrap.c * * Wrapper file for the 'dlg' library (body only) * * 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. * */ #include <ft2build.h> #include FT_CONFIG_OPTIONS_H #ifdef FT_DEBUG_LOGGING #define DLG_STATIC #include "dlg.c" #else /* ANSI C doesn't like empty source files */ typedef int _dlg_dummy; #endif /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/dlg/dlgwrap.c
C++
gpl-3.0
762
# # FreeType 2 dlg logging library 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. # dlg logging library directory # DLG_DIR := $(SRC_DIR)/dlg # compilation flags for the library # DLG_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(DLG_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # dlg logging library sources (i.e., C files) # DLG_SRC := $(DLG_DIR)/dlgwrap.c # dlg logging library headers # DLG_H := $(TOP_DIR)/include/dlg/dlg.h \ $(TOP_DIR)/include/dlg/output.h # dlg logging library object(s) # # DLG_OBJ_M is used during `multi' builds # DLG_OBJ_S is used during `single' builds # DLG_OBJ_M := $(DLG_SRC:$(DLG_DIR)/%.c=$(OBJ_DIR)/%.$O) DLG_OBJ_S := $(OBJ_DIR)/dlg.$O # dlg logging library source file for single build # DLG_SRC_S := $(DLG_DIR)/dlgwrap.c # dlg logging library - single object # $(DLG_OBJ_S): $(DLG_SRC_S) $(DLG_SRC) $(FREETYPE_H) $(DLG_H) $(DLG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(DLG_SRC_S)) # dlg logging library - multiple objects # $(OBJ_DIR)/%.$O: $(DLG_DIR)/%.c $(FREETYPE_H) $(DLG_H) $(DLG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main object lists # DLG_OBJS_S += $(DLG_OBJ_S) DLG_OBJS_M += $(DLG_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/dlg/rules.mk
mk
gpl-3.0
1,670
gxvalid: TrueType GX validator ============================== 1. What is this --------------- `gxvalid' is a module to validate TrueType GX tables: a collection of additional tables in TrueType font which are used by `QuickDraw GX Text', Apple Advanced Typography (AAT). In addition, gxvalid can validates `kern' tables which have been extended for AAT. Like the otvalid module, gxvalid uses FreeType 2's validator framework (ftvalid). You can link gxvalid with your program; before running your own layout engine, gxvalid validates a font file. As the result, you can remove error-checking code from the layout engine. It is also possible to use gxvalid as a stand-alone font validator; the `ftvalid' test program included in the ft2demo bundle calls gxvalid internally. A stand-alone font validator may be useful for font developers. This documents documents the following issues. - supported TrueType GX tables - fundamental validation limitations - permissive error handling of broken GX tables - `kern' table issue. 2. Supported tables ------------------- The following GX tables are currently supported. bsln feat just kern(*) lcar mort morx opbd prop trak The following GX tables are currently unsupported. cvar fdsc fmtx fvar gvar Zapf The following GX tables won't be supported. acnt(**) hsty(***) The following undocumented tables in TrueType fonts designed for Apple platform aren't handled either. addg CVTM TPNM umif *) The `kern' validator handles both the classic and the new kern formats; the former is supported on both Microsoft and Apple platforms, while the latter is supported on Apple platforms. **) `acnt' tables are not supported by currently available Apple font tools. ***) There is one more Apple extension, `hsty', but it is for Newton-OS, not GX (Newton-OS is a platform by Apple, but it can use sfnt- housed bitmap fonts only). Therefore, it should be excluded from `Apple platform' in the context of TrueType. gxvalid ignores it as Apple font tools do so. We have checked 183 fonts bundled with MacOS 9.1, MacOS 9.2, MacOS 10.0, MacOS X 10.1, MSIE for MacOS, and AppleWorks 6.0. In addition, we have checked 67 Dynalab fonts (designed for MacOS) and 189 Ricoh fonts (designed for Windows and MacOS dual platforms). The number of fonts including TrueType GX tables are as follows. bsln: 76 feat: 191 just: 84 kern: 59 lcar: 4 mort: 326 morx: 19 opbd: 4 prop: 114 trak: 16 Dynalab and Ricoh fonts don't have GX tables except of `feat' and `mort'. 3. Fundamental validation limitations ------------------------------------- TrueType GX provides layout information to libraries for font rasterizers and text layout. gxvalid can check whether the layout data in a font is conformant to the TrueType GX format specified by Apple. But gxvalid cannot check a how QuickDraw GX/AAT renderer uses the stored information. 3-1. Validation of State Machine activity ----------------------------------------- QuickDraw GX/AAT uses a `State Machine' to provide `stateful' layout features, and TrueType GX stores the state transition diagram of this `State Machine' in a `StateTable' data structure. While the State Machine receives a series of glyph IDs, the State Machine starts with `start of text' state, walks around various states and generates various layout information to the renderer, and finally reaches the `end of text' state. gxvalid can check essential errors like: - possibility of state transitions to undefined states - existence of glyph IDs that the State Machine doesn't know how to handle - the State Machine cannot compute the layout information from given diagram These errors can be checked within finite steps, and without the State Machine itself, because these are `expression' errors of state transition diagram. There is no limitation about how long the State Machine walks around, so validation of the algorithm in the state transition diagram requires infinite steps, even if we had a State Machine in gxvalid. Therefore, the following errors and problems cannot be checked. - existence of states which the State Machine never transits to - the possibility that the State Machine never reaches `end of text' - the possibility of stack underflow/overflow in the State Machine (in ligature and contextual glyph substitutions, the State Machine can store 16 glyphs onto its stack) In addition, gxvalid doesn't check `temporary glyph IDs' used in the chained State Machines (in `mort' and `morx' tables). If a layout feature is implemented by a single State Machine, a glyph ID converted by the State Machine is passed to the glyph renderer, thus it should not point to an undefined glyph ID. But if a layout feature is implemented by chained State Machines, a component State Machine (if it is not the final one) is permitted to generate undefined glyph IDs for temporary use, because it is handled by next component State Machine and not by the glyph renderer. To validate such temporary glyph IDs, gxvalid must stack all undefined glyph IDs which can occur in the output of the previous State Machine and search them in the `ClassTable' structure of the current State Machine. It is too complex to list all possible glyph IDs from the StateTable, especially from a ligature substitution table. 3-2. Validation of relationship between multiple layout features ---------------------------------------------------------------- gxvalid does not validate the relationship between multiple layout features at all. If multiple layout features are defined in TrueType GX tables, possible interactions, overrides, and conflicts between layout features are implicitly given in the font too. For example, there are several predefined spacing control features: - Text Spacing (Proportional/Monospace/Half-width/Normal) - Number Spacing (Monospaced-numbers/Proportional-numbers) - Kana Spacing (Full-width/Proportional) - Ideographic Spacing (Full-width/Proportional) - CJK Roman Spacing (Half-width/Proportional/Default-roman /Full-width-roman/Proportional) If all layout features are independently managed, we can activate inconsistent typographic rules like `Text Spacing=Monospace' and `Ideographic Spacing=Proportional' at the same time. The combinations of layout features is managed by a 32bit integer (one bit each for selector setting), so we can define relationships between up to 32 features, theoretically. But if one feature setting affects another feature setting, we need typographic priority rules to validate the relationship. Unfortunately, the TrueType GX format specification does not give such information even for predefined features. 4. Permissive error handling of broken GX tables ------------------------------------------------ When Apple's font rendering system finds an inconsistency, like a specification violation or an unspecified value in a TrueType GX table, it does not always return error. In most cases, the rendering engine silently ignores such wrong values or even whole tables. In fact, MacOS is shipped with fonts including broken GX/AAT tables, but no harmful effects due to `officially broken' fonts are observed by end-users. gxvalid is designed to continue the validation process as long as possible. When gxvalid find wrong values, gxvalid warns it at least, and takes a fallback procedure if possible. The fallback procedure depends on the debug level. We used the following three tools to investigate Apple's error handling. - FontValidator (for MacOS 8.5 - 9.2) resource fork font - ftxvalidator (for MacOS X 10.1 -) dfont or naked-sfnt - ftxdumperfuser (for MacOS X 10.1 -) dfont or naked-sfnt However, all tests were done on a PowerPC based Macintosh; at present, we have not checked those tools on a m68k-based Macintosh. In total, we checked 183 fonts bundled to MacOS 9.1, MacOS 9.2, MacOS 10.0, MacOS X 10.1, MSIE for MacOS, and AppleWorks 6.0. These fonts are distributed officially, but many broken GX/AAT tables were found by Apple's font tools. In the following, we list typical violation of the GX specification, in fonts officially distributed with those Apple systems. 4-1. broken BinSrchHeader (19/183) ---------------------------------- `BinSrchHeader' is a header of a data array for m68k platforms to access memory efficiently. Although there are only two independent parameters for real (`unitSize' and `nUnits'), BinSrchHeader has three additional parameters which can be calculated from `unitSize' and `nUnits', for fast setup. Apple font tools ignore them silently, so gxvalid warns if it finds and inconsistency, and always continues validation. The additional parameters are ignored regardless of the consistency. 19 fonts include such inconsistencies; all breaks are in the BinSrchHeader structure of the `kern' table. 4-2. too-short LookupTable (5/183) ---------------------------------- LookupTable format 0 is a simple array to get a value from a given GID (glyph ID); the index of this array is a GID too. Therefore, the length of the array is expected to be same as the maximum GID value defined in the `maxp' table, but there are some fonts whose LookupTable format 0 is too short to cover all GIDs. FontValidator ignores this error silently, ftxvalidator and ftxdumperfuser both warn and continue. Similar problems are found in format 3 subtables of `kern'. gxvalid warns always and abort if the validation level is set to FT_VALIDATE_PARANOID. 5 fonts include too-short kern format 0 subtables. 1 font includes too-short kern format 3 subtable. 4-3. broken LookupTable format 2 (1/183) ---------------------------------------- LookupTable format 2, subformat 4 covers the GID space by a collection of segments which are specified by `firstGlyph' and `lastGlyph'. Some fonts store `firstGlyph' and `lastGlyph' in reverse order, so the segment specification is broken. Apple font tools ignore this error silently; a broken segment is ignored as if it did not exist. gxvalid warns and normalize the segment at FT_VALIDATE_DEFAULT, or ignore the segment at FT_VALIDATE_TIGHT, or abort at FT_VALIDATE_PARANOID. 1 font includes broken LookupTable format 2, in the `just' table. *) It seems that all fonts manufactured by ITC for AppleWorks have this error. 4-4. bad bracketing in glyph property (14/183) ---------------------------------------------- GX/AAT defines a `bracketing' property of the glyphs in the `prop' table, to control layout features of strings enclosed inside and outside of brackets. Some fonts give inappropriate bracket properties to glyphs. Apple font tools warn about this error; gxvalid warns too and aborts at FT_VALIDATE_PARANOID. 14 fonts include wrong bracket properties. 4-5. invalid feature number (117/183) ------------------------------------- The GX/AAT extension can include 255 different layout features, but popular layout features are predefined (see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html). Some fonts include feature numbers which are incompatible with the predefined feature registry. In our survey, there are 140 fonts including `feat' table. a) 67 fonts use a feature number which should not be used. b) 117 fonts set the wrong feature range (nSetting). This is mostly found in the `mort' and `morx' tables. Apple font tools give no warning, although they cannot recognize what the feature is. At FT_VALIDATE_DEFAULT, gxvalid warns but continues in both cases (a, b). At FT_VALIDATE_TIGHT, gxvalid warns and aborts for (a), but continues for (b). At FT_VALIDATE_PARANOID, gxvalid warns and aborts in both cases (a, b). 4-6. invalid prop version (10/183) ---------------------------------- As most TrueType GX tables, the `prop' table must start with a 32bit version identifier: 0x00010000, 0x00020000 or 0x00030000. But some fonts store nonsense binary data instead. When Apple font tools find them, they abort the processing immediately, and the data which follows is unhandled. gxvalid does the same. 10 fonts include broken `prop' version. All of these fonts are classic TrueType fonts for the Japanese script, manufactured by Apple. 4-7. unknown resource name (2/183) ------------------------------------ NOTE: THIS IS NOT A TRUETYPE GX ERROR. If a TrueType font is stored in the resource fork or in dfont format, the data must be tagged as `sfnt' in the resource fork index to invoke TrueType font handler for the data. But the TrueType font data in `Keyboard.dfont' is tagged as `kbd', and that in `LastResort.dfont' is tagged as `lst'. Apple font tools can detect that the data is in TrueType format and successfully validate them. Maybe this is possible because they are known to be dfont. The current implementation of the resource fork driver of FreeType cannot do that, thus gxvalid cannot validate them. 2 fonts use an unknown tag for the TrueType font resource. 5. `kern' table issues ---------------------- In common terminology of TrueType, `kern' is classified as a basic and platform-independent table. But there are Apple extensions of `kern', and there is an extension which requires a GX state machine for contextual kerning. Therefore, gxvalid includes a special validator for `kern' tables. Unfortunately, there is no exact algorithm to check Apple's extension, so gxvalid includes a heuristic algorithm to find the proper validation routines for all possible data formats, including the data format for Microsoft. By calling classic_kern_validate() instead of gxv_validate(), you can specify the `kern' format explicitly. However, current FreeType2 uses Microsoft `kern' format only, others are ignored (and should be handled in a library one level higher than FreeType). 5-1. History ------------ The original 16bit version of `kern' was designed by Apple in the pre-GX era, and it was also approved by Microsoft. Afterwards, Apple designed a new 32bit version of the `kern' table. According to the documentation, the difference between the 16bit and 32bit version is only the size of variables in the `kern' header. In the following, we call the original 16bit version as `classic', and 32bit version as `new'. 5-2. Versions and dialects which should be differentiated --------------------------------------------------------- The `kern' table consists of a table header and several subtables. The version number which identifies a `classic' or a `new' version is explicitly written in the table header, but there are undocumented differences between Microsoft's and Apple's formats. It is called a `dialect' in the following. There are three cases which should be handled: the new Apple-dialect, the classic Apple-dialect, and the classic Microsoft-dialect. An analysis of the formats and the auto detection algorithm of gxvalid is described in the following. 5-2-1. Version detection: classic and new kern ---------------------------------------------- According to Apple TrueType specification, there are only two differences between the classic and the new: - The `kern' table header starts with the version number. The classic version starts with 0x0000 (16bit), the new version starts with 0x00010000 (32bit). - In the `kern' table header, the number of subtables follows the version number. In the classic version, it is stored as a 16bit value. In the new version, it is stored as a 32bit value. From Apple font tool's output (DumpKERN is also tested in addition to the three Apple font tools in above), there is another undocumented difference. In the new version, the subtable header includes a 16bit variable named `tupleIndex' which does not exist in the classic version. The new version can store all subtable formats (0, 1, 2, and 3), but the Apple TrueType specification does not mention the subtable formats available in the classic version. 5-2-2. Available subtable formats in classic version ---------------------------------------------------- Although the Apple TrueType specification recommends to use the classic version in the case if the font is designed for both the Apple and Microsoft platforms, it does not document the available subtable formats in the classic version. According to the Microsoft TrueType specification, the subtable format assured for Windows and OS/2 support is only subtable format 0. The Microsoft TrueType specification also describes subtable format 2, but does not mention which platforms support it. Subtable formats 1, 3, and higher are documented as reserved for future use. Therefore, the classic version can store subtable formats 0 and 2, at least. `ttfdump.exe', a font tool provided by Microsoft, ignores the subtable format written in the subtable header, and parses the table as if all subtables are in format 0. `kern' subtable format 1 uses a StateTable, so it cannot be utilized without a GX State Machine. Therefore, it is reasonable to assume that format 1 (and 3) were introduced after Apple had introduced GX and moved to the new 32bit version. 5-2-3. Apple and Microsoft dialects ----------------------------------- The `kern' subtable has a 16bit `coverage' field to describe kerning attributes, but bit interpretations by Apple and Microsoft are different: For example, Apple uses bits 0-7 to identify the subtable, while Microsoft uses bits 8-15. In addition, due to the output of DumpKERN and FontValidator, Apple's bit interpretations of coverage in classic and new version are incompatible also. In summary, there are three dialects: classic Apple dialect, classic Microsoft dialect, and new Apple dialect. The classic Microsoft dialect and the new Apple dialect are documented by each vendors' TrueType font specification, but the documentation for classic Apple dialect is not available. For example, in the new Apple dialect, bit 15 is documented as `set to 1 if the kerning is vertical'. On the other hand, in classic Microsoft dialect, bit 1 is documented as `set to 1 if the kerning is horizontal'. From the outputs of DumpKERN and FontValidator, classic Apple dialect recognizes 15 as `set to 1 when the kerning is horizontal'. From the results of similar experiments, classic Apple dialect seems to be the Endian reverse of the classic Microsoft dialect. As a conclusion it must be noted that no font tool can identify classic Apple dialect or classic Microsoft dialect automatically. 5-2-4. gxvalid auto dialect detection algorithm ----------------------------------------------- The first 16 bits of the `kern' table are enough to identify the version: - if the first 16 bits are 0x0000, the `kern' table is in classic Apple dialect or classic Microsoft dialect - if the first 16 bits are 0x0001, and next 16 bits are 0x0000, the kern table is in new Apple dialect. If the `kern' table is a classic one, the 16bit `coverage' field is checked next. Firstly, the coverage bits are decoded for the classic Apple dialect using the following bit masks (this is based on DumpKERN output): 0x8000: 1=horizontal, 0=vertical 0x4000: not used 0x2000: 1=cross-stream, 0=normal 0x1FF0: reserved 0x000F: subtable format If any of reserved bits are set or the subtable bits is interpreted as format 1 or 3, we take it as `impossible in classic Apple dialect' and retry, using the classic Microsoft dialect. The most popular coverage in new Apple-dialect: 0x8000, The most popular coverage in classic Apple-dialect: 0x0000, The most popular coverage in classic Microsoft dialect: 0x0001. 5-3. Tested fonts ----------------- We checked 59 fonts bundled with MacOS and 38 fonts bundled with Windows, where all font include a `kern' table. - fonts bundled with MacOS * new Apple dialect format 0: 18 format 2: 1 format 3: 1 * classic Apple dialect format 0: 14 * classic Microsoft dialect format 0: 15 - fonts bundled with Windows * classic Microsoft dialect format 0: 38 It looks strange that classic Microsoft-dialect fonts are bundled to MacOS: they come from MSIE for MacOS, except of MarkerFelt.dfont. ACKNOWLEDGEMENT --------------- Some parts of gxvalid are derived from both the `gxlayout' module and the `otvalid' module. Development of gxlayout was supported by the Information-technology Promotion Agency(IPA), Japan. The detailed analysis of undefined glyph ID utilization in `mort' and `morx' tables is provided by George Williams. ------------------------------------------------------------------------ Copyright (C) 2004-2022 by suzuki toshiya, Masatake YAMATO, Red hat K.K., 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. --- end of README ---
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/README
none
gpl-3.0
23,347
/**************************************************************************** * * gxvalid.c * * FreeType validator for TrueTypeGX/AAT tables (body only). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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 "gxvbsln.c" #include "gxvcommn.c" #include "gxvfeat.c" #include "gxvjust.c" #include "gxvkern.c" #include "gxvlcar.c" #include "gxvmod.c" #include "gxvmort.c" #include "gxvmort0.c" #include "gxvmort1.c" #include "gxvmort2.c" #include "gxvmort4.c" #include "gxvmort5.c" #include "gxvmorx.c" #include "gxvmorx0.c" #include "gxvmorx1.c" #include "gxvmorx2.c" #include "gxvmorx4.c" #include "gxvmorx5.c" #include "gxvopbd.c" #include "gxvprop.c" #include "gxvtrak.c" /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvalid.c
C++
gpl-3.0
1,133
/**************************************************************************** * * gxvalid.h * * TrueTypeGX/AAT table validation (specification only). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #ifndef GXVALID_H_ #define GXVALID_H_ #include <freetype/freetype.h> #include "gxverror.h" /* must come before `ftvalid.h' */ #include <freetype/internal/ftvalid.h> #include <freetype/internal/ftstream.h> FT_BEGIN_HEADER FT_LOCAL( void ) gxv_feat_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_bsln_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_trak_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_just_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_mort_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_morx_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_kern_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_kern_validate_classic( FT_Bytes table, FT_Face face, FT_Int dialect_flags, FT_Validator valid ); FT_LOCAL( void ) gxv_opbd_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_prop_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_LOCAL( void ) gxv_lcar_validate( FT_Bytes table, FT_Face face, FT_Validator valid ); FT_END_HEADER #endif /* GXVALID_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvalid.h
C++
gpl-3.0
2,869
/**************************************************************************** * * gxvbsln.c * * TrueTypeGX/AAT bsln table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.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 gxvbsln /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define GXV_BSLN_VALUE_COUNT 32 #define GXV_BSLN_VALUE_EMPTY 0xFFFFU typedef struct GXV_bsln_DataRec_ { FT_Bytes ctlPoints_p; FT_UShort defaultBaseline; } GXV_bsln_DataRec, *GXV_bsln_Data; #define GXV_BSLN_DATA( field ) GXV_TABLE_DATA( bsln, field ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_bsln_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UShort v = value_p->u; FT_UShort* ctlPoints; FT_UNUSED( glyph ); GXV_NAME_ENTER( "lookup value" ); if ( v >= GXV_BSLN_VALUE_COUNT ) FT_INVALID_DATA; ctlPoints = (FT_UShort*)GXV_BSLN_DATA( ctlPoints_p ); if ( ctlPoints && ctlPoints[v] == GXV_BSLN_VALUE_EMPTY ) FT_INVALID_DATA; GXV_EXIT; } /* +===============+ --------+ | lookup header | | +===============+ | | BinSrchHeader | | +===============+ | | lastGlyph[0] | | +---------------+ | | firstGlyph[0] | | head of lookup table +---------------+ | + | offset[0] | -> | offset [byte] +===============+ | + | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] +---------------+ | | firstGlyph[1] | | +---------------+ | | offset[1] | | +===============+ | | ... | | 16bit value array | +===============+ | | value | <-------+ ... */ static GXV_LookupValueDesc gxv_bsln_LookupFmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; /* XXX: check range ? */ offset = (FT_UShort)( base_value_p->u + ( relative_gindex * sizeof ( FT_UShort ) ) ); p = gxvalid->lookuptbl_head + offset; limit = lookuptbl_limit; GXV_LIMIT_CHECK( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } static void gxv_bsln_parts_fmt0_validate( FT_Bytes tables, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = tables; GXV_NAME_ENTER( "parts format 0" ); /* deltas */ GXV_LIMIT_CHECK( 2 * GXV_BSLN_VALUE_COUNT ); gxvalid->table_data = NULL; /* No ctlPoints here. */ GXV_EXIT; } static void gxv_bsln_parts_fmt1_validate( FT_Bytes tables, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = tables; GXV_NAME_ENTER( "parts format 1" ); /* deltas */ gxv_bsln_parts_fmt0_validate( p, limit, gxvalid ); /* mappingData */ gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_bsln_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit; gxv_LookupTable_validate( p + 2 * GXV_BSLN_VALUE_COUNT, limit, gxvalid ); GXV_EXIT; } static void gxv_bsln_parts_fmt2_validate( FT_Bytes tables, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = tables; FT_UShort stdGlyph; FT_UShort ctlPoint; FT_Int i; FT_UShort defaultBaseline = GXV_BSLN_DATA( defaultBaseline ); GXV_NAME_ENTER( "parts format 2" ); GXV_LIMIT_CHECK( 2 + ( 2 * GXV_BSLN_VALUE_COUNT ) ); /* stdGlyph */ stdGlyph = FT_NEXT_USHORT( p ); GXV_TRACE(( " (stdGlyph = %u)\n", stdGlyph )); gxv_glyphid_validate( stdGlyph, gxvalid ); /* Record the position of ctlPoints */ GXV_BSLN_DATA( ctlPoints_p ) = p; /* ctlPoints */ for ( i = 0; i < GXV_BSLN_VALUE_COUNT; i++ ) { ctlPoint = FT_NEXT_USHORT( p ); if ( ctlPoint == GXV_BSLN_VALUE_EMPTY ) { if ( i == defaultBaseline ) FT_INVALID_DATA; } else gxv_ctlPoint_validate( stdGlyph, ctlPoint, gxvalid ); } GXV_EXIT; } static void gxv_bsln_parts_fmt3_validate( FT_Bytes tables, FT_Bytes limit, GXV_Validator gxvalid) { FT_Bytes p = tables; GXV_NAME_ENTER( "parts format 3" ); /* stdGlyph + ctlPoints */ gxv_bsln_parts_fmt2_validate( p, limit, gxvalid ); /* mappingData */ gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_bsln_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit; gxv_LookupTable_validate( p + ( 2 + 2 * GXV_BSLN_VALUE_COUNT ), limit, gxvalid ); GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** bsln TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_bsln_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_bsln_DataRec bslnrec; GXV_bsln_Data bsln = &bslnrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_ULong version; FT_UShort format; FT_UShort defaultBaseline; GXV_Validate_Func fmt_funcs_table [] = { gxv_bsln_parts_fmt0_validate, gxv_bsln_parts_fmt1_validate, gxv_bsln_parts_fmt2_validate, gxv_bsln_parts_fmt3_validate, }; gxvalid->root = ftvalid; gxvalid->table_data = bsln; gxvalid->face = face; FT_TRACE3(( "validating `bsln' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 2 + 2 ); version = FT_NEXT_ULONG( p ); format = FT_NEXT_USHORT( p ); defaultBaseline = FT_NEXT_USHORT( p ); /* only version 1.0 is defined (1996) */ if ( version != 0x00010000UL ) FT_INVALID_FORMAT; /* only format 1, 2, 3 are defined (1996) */ GXV_TRACE(( " (format = %d)\n", format )); if ( format > 3 ) FT_INVALID_FORMAT; if ( defaultBaseline > 31 ) FT_INVALID_FORMAT; bsln->defaultBaseline = defaultBaseline; fmt_funcs_table[format]( p, limit, gxvalid ); FT_TRACE4(( "\n" )); } /* arch-tag: ebe81143-fdaa-4c68-a4d1-b57227daa3bc (do not change this comment) */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvbsln.c
C++
gpl-3.0
9,637
/**************************************************************************** * * gxvcommn.c * * TrueTypeGX/AAT common tables validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvcommn.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 gxvcommon /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** 16bit offset sorter *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_COMPARE_DEF( int ) gxv_compare_ushort_offset( const void* a, const void* b ) { return *(FT_UShort*)a - *(FT_UShort*)b; } FT_LOCAL_DEF( void ) gxv_set_length_by_ushort_offset( FT_UShort* offset, FT_UShort** length, FT_UShort* buff, FT_UInt nmemb, FT_UShort limit, GXV_Validator gxvalid ) { FT_UInt i; for ( i = 0; i < nmemb; i++ ) *(length[i]) = 0; for ( i = 0; i < nmemb; i++ ) buff[i] = offset[i]; buff[nmemb] = limit; ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_UShort ), gxv_compare_ushort_offset ); if ( buff[nmemb] > limit ) FT_INVALID_OFFSET; for ( i = 0; i < nmemb; i++ ) { FT_UInt j; for ( j = 0; j < nmemb; j++ ) if ( buff[j] == offset[i] ) break; if ( j == nmemb ) FT_INVALID_OFFSET; *(length[i]) = (FT_UShort)( buff[j + 1] - buff[j] ); if ( 0 != offset[i] && 0 == *(length[i]) ) FT_INVALID_OFFSET; } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** 32bit offset sorter *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_COMPARE_DEF( int ) gxv_compare_ulong_offset( const void* a, const void* b ) { FT_ULong a_ = *(FT_ULong*)a; FT_ULong b_ = *(FT_ULong*)b; if ( a_ < b_ ) return -1; else if ( a_ > b_ ) return 1; else return 0; } FT_LOCAL_DEF( void ) gxv_set_length_by_ulong_offset( FT_ULong* offset, FT_ULong** length, FT_ULong* buff, FT_UInt nmemb, FT_ULong limit, GXV_Validator gxvalid) { FT_UInt i; for ( i = 0; i < nmemb; i++ ) *(length[i]) = 0; for ( i = 0; i < nmemb; i++ ) buff[i] = offset[i]; buff[nmemb] = limit; ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_ULong ), gxv_compare_ulong_offset ); if ( buff[nmemb] > limit ) FT_INVALID_OFFSET; for ( i = 0; i < nmemb; i++ ) { FT_UInt j; for ( j = 0; j < nmemb; j++ ) if ( buff[j] == offset[i] ) break; if ( j == nmemb ) FT_INVALID_OFFSET; *(length[i]) = buff[j + 1] - buff[j]; if ( 0 != offset[i] && 0 == *(length[i]) ) FT_INVALID_OFFSET; } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** scan value array and get min & max *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_array_getlimits_byte( FT_Bytes table, FT_Bytes limit, FT_Byte* min, FT_Byte* max, GXV_Validator gxvalid ) { FT_Bytes p = table; *min = 0xFF; *max = 0x00; while ( p < limit ) { FT_Byte val; GXV_LIMIT_CHECK( 1 ); val = FT_NEXT_BYTE( p ); *min = (FT_Byte)FT_MIN( *min, val ); *max = (FT_Byte)FT_MAX( *max, val ); } gxvalid->subtable_length = (FT_ULong)( p - table ); } FT_LOCAL_DEF( void ) gxv_array_getlimits_ushort( FT_Bytes table, FT_Bytes limit, FT_UShort* min, FT_UShort* max, GXV_Validator gxvalid ) { FT_Bytes p = table; *min = 0xFFFFU; *max = 0x0000; while ( p < limit ) { FT_UShort val; GXV_LIMIT_CHECK( 2 ); val = FT_NEXT_USHORT( p ); *min = (FT_Byte)FT_MIN( *min, val ); *max = (FT_Byte)FT_MAX( *max, val ); } gxvalid->subtable_length = (FT_ULong)( p - table ); } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** BINSEARCHHEADER *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_BinSrchHeader_ { FT_UShort unitSize; FT_UShort nUnits; FT_UShort searchRange; FT_UShort entrySelector; FT_UShort rangeShift; } GXV_BinSrchHeader; static void gxv_BinSrchHeader_check_consistency( GXV_BinSrchHeader* binSrchHeader, GXV_Validator gxvalid ) { FT_UShort searchRange; FT_UShort entrySelector; FT_UShort rangeShift; if ( binSrchHeader->unitSize == 0 ) FT_INVALID_DATA; if ( binSrchHeader->nUnits == 0 ) { if ( binSrchHeader->searchRange == 0 && binSrchHeader->entrySelector == 0 && binSrchHeader->rangeShift == 0 ) return; else FT_INVALID_DATA; } for ( searchRange = 1, entrySelector = 1; ( searchRange * 2 ) <= binSrchHeader->nUnits && searchRange < 0x8000U; searchRange *= 2, entrySelector++ ) ; entrySelector--; searchRange = (FT_UShort)( searchRange * binSrchHeader->unitSize ); rangeShift = (FT_UShort)( binSrchHeader->nUnits * binSrchHeader->unitSize - searchRange ); if ( searchRange != binSrchHeader->searchRange || entrySelector != binSrchHeader->entrySelector || rangeShift != binSrchHeader->rangeShift ) { GXV_TRACE(( "Inconsistency found in BinSrchHeader\n" )); GXV_TRACE(( "originally: unitSize=%d, nUnits=%d, " "searchRange=%d, entrySelector=%d, " "rangeShift=%d\n", binSrchHeader->unitSize, binSrchHeader->nUnits, binSrchHeader->searchRange, binSrchHeader->entrySelector, binSrchHeader->rangeShift )); GXV_TRACE(( "calculated: unitSize=%d, nUnits=%d, " "searchRange=%d, entrySelector=%d, " "rangeShift=%d\n", binSrchHeader->unitSize, binSrchHeader->nUnits, searchRange, entrySelector, rangeShift )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } } /* * parser & validator of BinSrchHeader * which is used in LookupTable format 2, 4, 6. * * Essential parameters (unitSize, nUnits) are returned by * given pointer, others (searchRange, entrySelector, rangeShift) * can be calculated by essential parameters, so they are just * validated and discarded. * * However, wrong values in searchRange, entrySelector, rangeShift * won't cause fatal errors, because these parameters might be * only used in old m68k font driver in MacOS. * -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp> */ FT_LOCAL_DEF( void ) gxv_BinSrchHeader_validate( FT_Bytes table, FT_Bytes limit, FT_UShort* unitSize_p, FT_UShort* nUnits_p, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_BinSrchHeader binSrchHeader; GXV_NAME_ENTER( "BinSrchHeader validate" ); if ( *unitSize_p == 0 ) { GXV_LIMIT_CHECK( 2 ); binSrchHeader.unitSize = FT_NEXT_USHORT( p ); } else binSrchHeader.unitSize = *unitSize_p; if ( *nUnits_p == 0 ) { GXV_LIMIT_CHECK( 2 ); binSrchHeader.nUnits = FT_NEXT_USHORT( p ); } else binSrchHeader.nUnits = *nUnits_p; GXV_LIMIT_CHECK( 2 + 2 + 2 ); binSrchHeader.searchRange = FT_NEXT_USHORT( p ); binSrchHeader.entrySelector = FT_NEXT_USHORT( p ); binSrchHeader.rangeShift = FT_NEXT_USHORT( p ); GXV_TRACE(( "nUnits %d\n", binSrchHeader.nUnits )); gxv_BinSrchHeader_check_consistency( &binSrchHeader, gxvalid ); if ( *unitSize_p == 0 ) *unitSize_p = binSrchHeader.unitSize; if ( *nUnits_p == 0 ) *nUnits_p = binSrchHeader.nUnits; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** LOOKUP TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define GXV_LOOKUP_VALUE_LOAD( P, SIGNSPEC ) \ ( P += 2, gxv_lookup_value_load( P - 2, SIGNSPEC ) ) static GXV_LookupValueDesc gxv_lookup_value_load( FT_Bytes p, GXV_LookupValue_SignSpec signspec ) { GXV_LookupValueDesc v; if ( signspec == GXV_LOOKUPVALUE_UNSIGNED ) v.u = FT_NEXT_USHORT( p ); else v.s = FT_NEXT_SHORT( p ); return v; } #define GXV_UNITSIZE_VALIDATE( FORMAT, UNITSIZE, NUNITS, CORRECTSIZE ) \ FT_BEGIN_STMNT \ if ( UNITSIZE != CORRECTSIZE ) \ { \ FT_ERROR(( "unitSize=%d differs from" \ " expected unitSize=%d" \ " in LookupTable %s\n", \ UNITSIZE, CORRECTSIZE, FORMAT )); \ if ( UNITSIZE != 0 && NUNITS != 0 ) \ { \ FT_ERROR(( " cannot validate anymore\n" )); \ FT_INVALID_FORMAT; \ } \ else \ FT_ERROR(( " forcibly continues\n" )); \ } \ FT_END_STMNT /* ================= Simple Array Format 0 Lookup Table ================ */ static void gxv_LookupTable_fmt0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort i; GXV_LookupValueDesc value; GXV_NAME_ENTER( "LookupTable format 0" ); GXV_LIMIT_CHECK( 2 * gxvalid->face->num_glyphs ); for ( i = 0; i < gxvalid->face->num_glyphs; i++ ) { GXV_LIMIT_CHECK( 2 ); if ( p + 2 >= limit ) /* some fonts have too-short fmt0 array */ { GXV_TRACE(( "too short, glyphs %d - %ld are missing\n", i, gxvalid->face->num_glyphs )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); break; } value = GXV_LOOKUP_VALUE_LOAD( p, gxvalid->lookupval_sign ); gxvalid->lookupval_func( i, &value, gxvalid ); } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /* ================= Segment Single Format 2 Lookup Table ============== */ /* * Apple spec says: * * To guarantee that a binary search terminates, you must include one or * more special `end of search table' values at the end of the data to * be searched. The number of termination values that need to be * included is table-specific. The value that indicates binary search * termination is 0xFFFF. * * The problem is that nUnits does not include this end-marker. It's * quite difficult to discriminate whether the following 0xFFFF comes from * the end-marker or some next data. * * -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp> */ static void gxv_LookupTable_fmt2_skip_endmarkers( FT_Bytes table, FT_UShort unitSize, GXV_Validator gxvalid ) { FT_Bytes p = table; while ( ( p + 4 ) < gxvalid->root->limit ) { if ( p[0] != 0xFF || p[1] != 0xFF || /* lastGlyph */ p[2] != 0xFF || p[3] != 0xFF ) /* firstGlyph */ break; p += unitSize; } gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_LookupTable_fmt2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort gid; FT_UShort unitSize; FT_UShort nUnits; FT_UShort unit; FT_UShort lastGlyph; FT_UShort firstGlyph; GXV_LookupValueDesc value; GXV_NAME_ENTER( "LookupTable format 2" ); unitSize = nUnits = 0; gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, gxvalid ); p += gxvalid->subtable_length; GXV_UNITSIZE_VALIDATE( "format2", unitSize, nUnits, 6 ); for ( unit = 0, gid = 0; unit < nUnits; unit++ ) { GXV_LIMIT_CHECK( 2 + 2 + 2 ); lastGlyph = FT_NEXT_USHORT( p ); firstGlyph = FT_NEXT_USHORT( p ); value = GXV_LOOKUP_VALUE_LOAD( p, gxvalid->lookupval_sign ); gxv_glyphid_validate( firstGlyph, gxvalid ); gxv_glyphid_validate( lastGlyph, gxvalid ); if ( lastGlyph < gid ) { GXV_TRACE(( "reverse ordered segment specification:" " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n", unit, lastGlyph, unit - 1 , gid )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } if ( lastGlyph < firstGlyph ) { GXV_TRACE(( "reverse ordered range specification at unit %d:" " lastGlyph %d < firstGlyph %d ", unit, lastGlyph, firstGlyph )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); if ( gxvalid->root->level == FT_VALIDATE_TIGHT ) continue; /* ftxvalidator silently skips such an entry */ FT_TRACE4(( "continuing with exchanged values\n" )); gid = firstGlyph; firstGlyph = lastGlyph; lastGlyph = gid; } for ( gid = firstGlyph; gid <= lastGlyph; gid++ ) gxvalid->lookupval_func( gid, &value, gxvalid ); } gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, gxvalid ); p += gxvalid->subtable_length; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /* ================= Segment Array Format 4 Lookup Table =============== */ static void gxv_LookupTable_fmt4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort unit; FT_UShort gid; FT_UShort unitSize; FT_UShort nUnits; FT_UShort lastGlyph; FT_UShort firstGlyph; GXV_LookupValueDesc base_value; GXV_LookupValueDesc value; GXV_NAME_ENTER( "LookupTable format 4" ); unitSize = nUnits = 0; gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, gxvalid ); p += gxvalid->subtable_length; GXV_UNITSIZE_VALIDATE( "format4", unitSize, nUnits, 6 ); for ( unit = 0, gid = 0; unit < nUnits; unit++ ) { GXV_LIMIT_CHECK( 2 + 2 ); lastGlyph = FT_NEXT_USHORT( p ); firstGlyph = FT_NEXT_USHORT( p ); gxv_glyphid_validate( firstGlyph, gxvalid ); gxv_glyphid_validate( lastGlyph, gxvalid ); if ( lastGlyph < gid ) { GXV_TRACE(( "reverse ordered segment specification:" " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n", unit, lastGlyph, unit - 1 , gid )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } if ( lastGlyph < firstGlyph ) { GXV_TRACE(( "reverse ordered range specification at unit %d:" " lastGlyph %d < firstGlyph %d ", unit, lastGlyph, firstGlyph )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); if ( gxvalid->root->level == FT_VALIDATE_TIGHT ) continue; /* ftxvalidator silently skips such an entry */ FT_TRACE4(( "continuing with exchanged values\n" )); gid = firstGlyph; firstGlyph = lastGlyph; lastGlyph = gid; } GXV_LIMIT_CHECK( 2 ); base_value = GXV_LOOKUP_VALUE_LOAD( p, GXV_LOOKUPVALUE_UNSIGNED ); for ( gid = firstGlyph; gid <= lastGlyph; gid++ ) { value = gxvalid->lookupfmt4_trans( (FT_UShort)( gid - firstGlyph ), &base_value, limit, gxvalid ); gxvalid->lookupval_func( gid, &value, gxvalid ); } } gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, gxvalid ); p += gxvalid->subtable_length; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /* ================= Segment Table Format 6 Lookup Table =============== */ static void gxv_LookupTable_fmt6_skip_endmarkers( FT_Bytes table, FT_UShort unitSize, GXV_Validator gxvalid ) { FT_Bytes p = table; while ( p < gxvalid->root->limit ) { if ( p[0] != 0xFF || p[1] != 0xFF ) break; p += unitSize; } gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_LookupTable_fmt6_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort unit; FT_UShort prev_glyph; FT_UShort unitSize; FT_UShort nUnits; FT_UShort glyph; GXV_LookupValueDesc value; GXV_NAME_ENTER( "LookupTable format 6" ); unitSize = nUnits = 0; gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, gxvalid ); p += gxvalid->subtable_length; GXV_UNITSIZE_VALIDATE( "format6", unitSize, nUnits, 4 ); for ( unit = 0, prev_glyph = 0; unit < nUnits; unit++ ) { GXV_LIMIT_CHECK( 2 + 2 ); glyph = FT_NEXT_USHORT( p ); value = GXV_LOOKUP_VALUE_LOAD( p, gxvalid->lookupval_sign ); if ( gxv_glyphid_validate( glyph, gxvalid ) ) GXV_TRACE(( " endmarker found within defined range" " (entry %d < nUnits=%d)\n", unit, nUnits )); if ( prev_glyph > glyph ) { GXV_TRACE(( "current gid 0x%04x < previous gid 0x%04x\n", glyph, prev_glyph )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } prev_glyph = glyph; gxvalid->lookupval_func( glyph, &value, gxvalid ); } gxv_LookupTable_fmt6_skip_endmarkers( p, unitSize, gxvalid ); p += gxvalid->subtable_length; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /* ================= Trimmed Array Format 8 Lookup Table =============== */ static void gxv_LookupTable_fmt8_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort i; GXV_LookupValueDesc value; FT_UShort firstGlyph; FT_UShort glyphCount; GXV_NAME_ENTER( "LookupTable format 8" ); /* firstGlyph + glyphCount */ GXV_LIMIT_CHECK( 2 + 2 ); firstGlyph = FT_NEXT_USHORT( p ); glyphCount = FT_NEXT_USHORT( p ); gxv_glyphid_validate( firstGlyph, gxvalid ); gxv_glyphid_validate( (FT_UShort)( firstGlyph + glyphCount ), gxvalid ); /* valueArray */ for ( i = 0; i < glyphCount; i++ ) { GXV_LIMIT_CHECK( 2 ); value = GXV_LOOKUP_VALUE_LOAD( p, gxvalid->lookupval_sign ); gxvalid->lookupval_func( (FT_UShort)( firstGlyph + i ), &value, gxvalid ); } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_LookupTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort format; GXV_Validate_Func fmt_funcs_table[] = { gxv_LookupTable_fmt0_validate, /* 0 */ NULL, /* 1 */ gxv_LookupTable_fmt2_validate, /* 2 */ NULL, /* 3 */ gxv_LookupTable_fmt4_validate, /* 4 */ NULL, /* 5 */ gxv_LookupTable_fmt6_validate, /* 6 */ NULL, /* 7 */ gxv_LookupTable_fmt8_validate, /* 8 */ }; GXV_Validate_Func func; GXV_NAME_ENTER( "LookupTable" ); /* lookuptbl_head may be used in fmt4 transit function. */ gxvalid->lookuptbl_head = table; /* format */ GXV_LIMIT_CHECK( 2 ); format = FT_NEXT_USHORT( p ); GXV_TRACE(( " (format %d)\n", format )); if ( format > 8 ) FT_INVALID_FORMAT; func = fmt_funcs_table[format]; if ( !func ) FT_INVALID_FORMAT; func( p, limit, gxvalid ); p += gxvalid->subtable_length; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Glyph ID *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( FT_Int ) gxv_glyphid_validate( FT_UShort gid, GXV_Validator gxvalid ) { FT_Face face; if ( gid == 0xFFFFU ) { GXV_EXIT; return 1; } face = gxvalid->face; if ( face->num_glyphs < gid ) { GXV_TRACE(( " gxv_glyphid_check() gid overflow: num_glyphs %ld < %d\n", face->num_glyphs, gid )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } return 0; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CONTROL POINT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_ctlPoint_validate( FT_UShort gid, FT_UShort ctl_point, GXV_Validator gxvalid ) { FT_Face face; FT_Error error; FT_GlyphSlot glyph; FT_Outline outline; FT_UShort n_points; face = gxvalid->face; error = FT_Load_Glyph( face, gid, FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM ); if ( error ) FT_INVALID_GLYPH_ID; glyph = face->glyph; outline = glyph->outline; n_points = (FT_UShort)outline.n_points; if ( !( ctl_point < n_points ) ) FT_INVALID_DATA; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** SFNT NAME *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_sfntName_validate( FT_UShort name_index, FT_UShort min_index, FT_UShort max_index, GXV_Validator gxvalid ) { FT_SfntName name; FT_UInt i; FT_UInt nnames; GXV_NAME_ENTER( "sfntName" ); if ( name_index < min_index || max_index < name_index ) FT_INVALID_FORMAT; nnames = FT_Get_Sfnt_Name_Count( gxvalid->face ); for ( i = 0; i < nnames; i++ ) { if ( FT_Get_Sfnt_Name( gxvalid->face, i, &name ) != FT_Err_Ok ) continue; if ( name.name_id == name_index ) goto Out; } GXV_TRACE(( " nameIndex = %d (UNTITLED)\n", name_index )); FT_INVALID_DATA; goto Exit; /* make compiler happy */ Out: FT_TRACE1(( " nameIndex = %d (", name_index )); GXV_TRACE_HEXDUMP_SFNTNAME( name ); FT_TRACE1(( ")\n" )); Exit: GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** STATE TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* -------------------------- Class Table --------------------------- */ /* * highestClass specifies how many classes are defined in this * Class Subtable. Apple spec does not mention whether undefined * holes in the class (e.g.: 0-3 are predefined, 4 is unused, 5 is used) * are permitted. At present, holes in a defined class are not checked. * -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp> */ static void gxv_ClassTable_validate( FT_Bytes table, FT_UShort* length_p, FT_UShort stateSize, FT_Byte* maxClassID_p, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes limit = table + *length_p; FT_UShort firstGlyph; FT_UShort nGlyphs; GXV_NAME_ENTER( "ClassTable" ); *maxClassID_p = 3; /* Classes 0, 2, and 3 are predefined */ GXV_LIMIT_CHECK( 2 + 2 ); firstGlyph = FT_NEXT_USHORT( p ); nGlyphs = FT_NEXT_USHORT( p ); GXV_TRACE(( " (firstGlyph = %d, nGlyphs = %d)\n", firstGlyph, nGlyphs )); if ( !nGlyphs ) goto Out; gxv_glyphid_validate( (FT_UShort)( firstGlyph + nGlyphs ), gxvalid ); { FT_Byte nGlyphInClass[256]; FT_Byte classID; FT_UShort i; FT_MEM_ZERO( nGlyphInClass, 256 ); for ( i = 0; i < nGlyphs; i++ ) { GXV_LIMIT_CHECK( 1 ); classID = FT_NEXT_BYTE( p ); switch ( classID ) { /* following classes should not appear in class array */ case 0: /* end of text */ case 2: /* out of bounds */ case 3: /* end of line */ FT_INVALID_DATA; break; case 1: /* out of bounds */ default: /* user-defined: 4 - ( stateSize - 1 ) */ if ( classID >= stateSize ) FT_INVALID_DATA; /* assign glyph to undefined state */ nGlyphInClass[classID]++; break; } } *length_p = (FT_UShort)( p - table ); /* scan max ClassID in use */ for ( i = 0; i < stateSize; i++ ) if ( ( 3 < i ) && ( nGlyphInClass[i] > 0 ) ) *maxClassID_p = (FT_Byte)i; /* XXX: Check Range? */ } Out: GXV_TRACE(( "Declared stateSize=0x%02x, Used maxClassID=0x%02x\n", stateSize, *maxClassID_p )); GXV_EXIT; } /* --------------------------- State Array ----------------------------- */ static void gxv_StateArray_validate( FT_Bytes table, FT_UShort* length_p, FT_Byte maxClassID, FT_UShort stateSize, FT_Byte* maxState_p, FT_Byte* maxEntry_p, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes limit = table + *length_p; FT_Byte clazz; FT_Byte entry; FT_UNUSED( stateSize ); /* for the non-debugging case */ GXV_NAME_ENTER( "StateArray" ); GXV_TRACE(( "parse %d bytes by stateSize=%d maxClassID=%d\n", (int)(*length_p), stateSize, (int)(maxClassID) )); /* * 2 states are predefined and must be described in StateArray: * state 0 (start of text), 1 (start of line) */ GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 ); *maxState_p = 0; *maxEntry_p = 0; /* read if enough to read another state */ while ( p + ( 1 + maxClassID ) <= limit ) { (*maxState_p)++; for ( clazz = 0; clazz <= maxClassID; clazz++ ) { entry = FT_NEXT_BYTE( p ); *maxEntry_p = (FT_Byte)FT_MAX( *maxEntry_p, entry ); } } GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n", *maxState_p, *maxEntry_p )); *length_p = (FT_UShort)( p - table ); GXV_EXIT; } /* --------------------------- Entry Table ----------------------------- */ static void gxv_EntryTable_validate( FT_Bytes table, FT_UShort* length_p, FT_Byte maxEntry, FT_UShort stateArray, FT_UShort stateArray_length, FT_Byte maxClassID, FT_Bytes statetable_table, FT_Bytes statetable_limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes limit = table + *length_p; FT_Byte entry; FT_Byte state; FT_Int entrySize = 2 + 2 + GXV_GLYPHOFFSET_SIZE( statetable ); GXV_XStateTable_GlyphOffsetDesc glyphOffset; GXV_NAME_ENTER( "EntryTable" ); GXV_TRACE(( "maxEntry=%d entrySize=%d\n", maxEntry, entrySize )); if ( ( maxEntry + 1 ) * entrySize > *length_p ) { GXV_SET_ERR_IF_PARANOID( FT_INVALID_TOO_SHORT ); /* ftxvalidator and FontValidator both warn and continue */ maxEntry = (FT_Byte)( *length_p / entrySize - 1 ); GXV_TRACE(( "too large maxEntry, shrinking to %d fit EntryTable length\n", maxEntry )); } for ( entry = 0; entry <= maxEntry; entry++ ) { FT_UShort newState; FT_UShort flags; GXV_LIMIT_CHECK( 2 + 2 ); newState = FT_NEXT_USHORT( p ); flags = FT_NEXT_USHORT( p ); if ( newState < stateArray || stateArray + stateArray_length < newState ) { GXV_TRACE(( " newState offset 0x%04x is out of stateArray\n", newState )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); continue; } if ( 0 != ( ( newState - stateArray ) % ( 1 + maxClassID ) ) ) { GXV_TRACE(( " newState offset 0x%04x is not aligned to %d-classes\n", newState, 1 + maxClassID )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); continue; } state = (FT_Byte)( ( newState - stateArray ) / ( 1 + maxClassID ) ); switch ( GXV_GLYPHOFFSET_FMT( statetable ) ) { case GXV_GLYPHOFFSET_NONE: glyphOffset.uc = 0; /* make compiler happy */ break; case GXV_GLYPHOFFSET_UCHAR: glyphOffset.uc = FT_NEXT_BYTE( p ); break; case GXV_GLYPHOFFSET_CHAR: glyphOffset.c = FT_NEXT_CHAR( p ); break; case GXV_GLYPHOFFSET_USHORT: glyphOffset.u = FT_NEXT_USHORT( p ); break; case GXV_GLYPHOFFSET_SHORT: glyphOffset.s = FT_NEXT_SHORT( p ); break; case GXV_GLYPHOFFSET_ULONG: glyphOffset.ul = FT_NEXT_ULONG( p ); break; case GXV_GLYPHOFFSET_LONG: glyphOffset.l = FT_NEXT_LONG( p ); break; } if ( gxvalid->statetable.entry_validate_func ) gxvalid->statetable.entry_validate_func( state, flags, &glyphOffset, statetable_table, statetable_limit, gxvalid ); } *length_p = (FT_UShort)( p - table ); GXV_EXIT; } /* =========================== State Table ============================= */ FT_LOCAL_DEF( void ) gxv_StateTable_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ) { FT_UShort o[3]; FT_UShort* l[3]; FT_UShort buff[4]; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; gxv_set_length_by_ushort_offset( o, l, buff, 3, table_size, gxvalid ); } FT_LOCAL_DEF( void ) gxv_StateTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_UShort stateSize; FT_UShort classTable; /* offset to Class(Sub)Table */ FT_UShort stateArray; /* offset to StateArray */ FT_UShort entryTable; /* offset to EntryTable */ FT_UShort classTable_length; FT_UShort stateArray_length; FT_UShort entryTable_length; FT_Byte maxClassID; FT_Byte maxState; FT_Byte maxEntry; GXV_StateTable_Subtable_Setup_Func setup_func; FT_Bytes p = table; GXV_NAME_ENTER( "StateTable" ); GXV_TRACE(( "StateTable header\n" )); GXV_LIMIT_CHECK( 2 + 2 + 2 + 2 ); stateSize = FT_NEXT_USHORT( p ); classTable = FT_NEXT_USHORT( p ); stateArray = FT_NEXT_USHORT( p ); entryTable = FT_NEXT_USHORT( p ); GXV_TRACE(( "stateSize=0x%04x\n", stateSize )); GXV_TRACE(( "offset to classTable=0x%04x\n", classTable )); GXV_TRACE(( "offset to stateArray=0x%04x\n", stateArray )); GXV_TRACE(( "offset to entryTable=0x%04x\n", entryTable )); if ( stateSize > 0xFF ) FT_INVALID_DATA; if ( gxvalid->statetable.optdata_load_func ) gxvalid->statetable.optdata_load_func( p, limit, gxvalid ); if ( gxvalid->statetable.subtable_setup_func ) setup_func = gxvalid->statetable.subtable_setup_func; else setup_func = gxv_StateTable_subtable_setup; setup_func( (FT_UShort)( limit - table ), classTable, stateArray, entryTable, &classTable_length, &stateArray_length, &entryTable_length, gxvalid ); GXV_TRACE(( "StateTable Subtables\n" )); if ( classTable != 0 ) gxv_ClassTable_validate( table + classTable, &classTable_length, stateSize, &maxClassID, gxvalid ); else maxClassID = (FT_Byte)( stateSize - 1 ); if ( stateArray != 0 ) gxv_StateArray_validate( table + stateArray, &stateArray_length, maxClassID, stateSize, &maxState, &maxEntry, gxvalid ); else { #if 0 maxState = 1; /* 0:start of text, 1:start of line are predefined */ #endif maxEntry = 0; } if ( maxEntry > 0 && entryTable == 0 ) FT_INVALID_OFFSET; if ( entryTable != 0 ) gxv_EntryTable_validate( table + entryTable, &entryTable_length, maxEntry, stateArray, stateArray_length, maxClassID, table, limit, gxvalid ); GXV_EXIT; } /* ================= eXtended State Table (for morx) =================== */ FT_LOCAL_DEF( void ) gxv_XStateTable_subtable_setup( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ) { FT_ULong o[3]; FT_ULong* l[3]; FT_ULong buff[4]; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; gxv_set_length_by_ulong_offset( o, l, buff, 3, table_size, gxvalid ); } static void gxv_XClassTable_lookupval_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UNUSED( glyph ); if ( value_p->u >= gxvalid->xstatetable.nClasses ) FT_INVALID_DATA; if ( value_p->u > gxvalid->xstatetable.maxClassID ) gxvalid->xstatetable.maxClassID = value_p->u; } /* +===============+ --------+ | lookup header | | +===============+ | | BinSrchHeader | | +===============+ | | lastGlyph[0] | | +---------------+ | | firstGlyph[0] | | head of lookup table +---------------+ | + | offset[0] | -> | offset [byte] +===============+ | + | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] +---------------+ | | firstGlyph[1] | | +---------------+ | | offset[1] | | +===============+ | | .... | | 16bit value array | +===============+ | | value | <-------+ .... */ static GXV_LookupValueDesc gxv_XClassTable_lookupfmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; /* XXX: check range? */ offset = (FT_UShort)( base_value_p->u + relative_gindex * sizeof ( FT_UShort ) ); p = gxvalid->lookuptbl_head + offset; limit = lookuptbl_limit; GXV_LIMIT_CHECK ( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } static void gxv_XStateArray_validate( FT_Bytes table, FT_ULong* length_p, FT_UShort maxClassID, FT_ULong stateSize, FT_UShort* maxState_p, FT_UShort* maxEntry_p, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes limit = table + *length_p; FT_UShort clazz; FT_UShort entry; FT_UNUSED( stateSize ); /* for the non-debugging case */ GXV_NAME_ENTER( "XStateArray" ); GXV_TRACE(( "parse % 3d bytes by stateSize=% 3d maxClassID=% 3d\n", (int)(*length_p), (int)stateSize, (int)(maxClassID) )); /* * 2 states are predefined and must be described: * state 0 (start of text), 1 (start of line) */ GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 * 2 ); *maxState_p = 0; *maxEntry_p = 0; /* read if enough to read another state */ while ( p + ( ( 1 + maxClassID ) * 2 ) <= limit ) { (*maxState_p)++; for ( clazz = 0; clazz <= maxClassID; clazz++ ) { entry = FT_NEXT_USHORT( p ); *maxEntry_p = (FT_UShort)FT_MAX( *maxEntry_p, entry ); } } GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n", *maxState_p, *maxEntry_p )); *length_p = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_XEntryTable_validate( FT_Bytes table, FT_ULong* length_p, FT_UShort maxEntry, FT_ULong stateArray_length, FT_UShort maxClassID, FT_Bytes xstatetable_table, FT_Bytes xstatetable_limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes limit = table + *length_p; FT_UShort entry; FT_UShort state; FT_Int entrySize = 2 + 2 + GXV_GLYPHOFFSET_SIZE( xstatetable ); GXV_NAME_ENTER( "XEntryTable" ); GXV_TRACE(( "maxEntry=%d entrySize=%d\n", maxEntry, entrySize )); if ( ( p + ( maxEntry + 1 ) * entrySize ) > limit ) FT_INVALID_TOO_SHORT; for (entry = 0; entry <= maxEntry; entry++ ) { FT_UShort newState_idx; FT_UShort flags; GXV_XStateTable_GlyphOffsetDesc glyphOffset; GXV_LIMIT_CHECK( 2 + 2 ); newState_idx = FT_NEXT_USHORT( p ); flags = FT_NEXT_USHORT( p ); if ( stateArray_length < (FT_ULong)( newState_idx * 2 ) ) { GXV_TRACE(( " newState index 0x%04x points out of stateArray\n", newState_idx )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } state = (FT_UShort)( newState_idx / ( 1 + maxClassID ) ); if ( 0 != ( newState_idx % ( 1 + maxClassID ) ) ) { FT_TRACE4(( "-> new state = %d (supposed)\n", state )); FT_TRACE4(( "but newState index 0x%04x" " is not aligned to %d-classes\n", newState_idx, 1 + maxClassID )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } switch ( GXV_GLYPHOFFSET_FMT( xstatetable ) ) { case GXV_GLYPHOFFSET_NONE: glyphOffset.uc = 0; /* make compiler happy */ break; case GXV_GLYPHOFFSET_UCHAR: glyphOffset.uc = FT_NEXT_BYTE( p ); break; case GXV_GLYPHOFFSET_CHAR: glyphOffset.c = FT_NEXT_CHAR( p ); break; case GXV_GLYPHOFFSET_USHORT: glyphOffset.u = FT_NEXT_USHORT( p ); break; case GXV_GLYPHOFFSET_SHORT: glyphOffset.s = FT_NEXT_SHORT( p ); break; case GXV_GLYPHOFFSET_ULONG: glyphOffset.ul = FT_NEXT_ULONG( p ); break; case GXV_GLYPHOFFSET_LONG: glyphOffset.l = FT_NEXT_LONG( p ); break; default: GXV_SET_ERR_IF_PARANOID( FT_INVALID_FORMAT ); goto Exit; } if ( gxvalid->xstatetable.entry_validate_func ) gxvalid->xstatetable.entry_validate_func( state, flags, &glyphOffset, xstatetable_table, xstatetable_limit, gxvalid ); } Exit: *length_p = (FT_ULong)( p - table ); GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_XStateTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { /* StateHeader members */ FT_ULong classTable; /* offset to Class(Sub)Table */ FT_ULong stateArray; /* offset to StateArray */ FT_ULong entryTable; /* offset to EntryTable */ FT_ULong classTable_length; FT_ULong stateArray_length; FT_ULong entryTable_length; FT_UShort maxState; FT_UShort maxEntry; GXV_XStateTable_Subtable_Setup_Func setup_func; FT_Bytes p = table; GXV_NAME_ENTER( "XStateTable" ); GXV_TRACE(( "XStateTable header\n" )); GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 ); gxvalid->xstatetable.nClasses = FT_NEXT_ULONG( p ); classTable = FT_NEXT_ULONG( p ); stateArray = FT_NEXT_ULONG( p ); entryTable = FT_NEXT_ULONG( p ); GXV_TRACE(( "nClasses =0x%08lx\n", gxvalid->xstatetable.nClasses )); GXV_TRACE(( "offset to classTable=0x%08lx\n", classTable )); GXV_TRACE(( "offset to stateArray=0x%08lx\n", stateArray )); GXV_TRACE(( "offset to entryTable=0x%08lx\n", entryTable )); if ( gxvalid->xstatetable.nClasses > 0xFFFFU ) FT_INVALID_DATA; GXV_TRACE(( "StateTable Subtables\n" )); if ( gxvalid->xstatetable.optdata_load_func ) gxvalid->xstatetable.optdata_load_func( p, limit, gxvalid ); if ( gxvalid->xstatetable.subtable_setup_func ) setup_func = gxvalid->xstatetable.subtable_setup_func; else setup_func = gxv_XStateTable_subtable_setup; setup_func( (FT_ULong)( limit - table ), classTable, stateArray, entryTable, &classTable_length, &stateArray_length, &entryTable_length, gxvalid ); if ( classTable != 0 ) { gxvalid->xstatetable.maxClassID = 0; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_XClassTable_lookupval_validate; gxvalid->lookupfmt4_trans = gxv_XClassTable_lookupfmt4_transit; gxv_LookupTable_validate( table + classTable, table + classTable + classTable_length, gxvalid ); #if 0 if ( gxvalid->subtable_length < classTable_length ) classTable_length = gxvalid->subtable_length; #endif } else { /* XXX: check range? */ gxvalid->xstatetable.maxClassID = (FT_UShort)( gxvalid->xstatetable.nClasses - 1 ); } if ( stateArray != 0 ) gxv_XStateArray_validate( table + stateArray, &stateArray_length, gxvalid->xstatetable.maxClassID, gxvalid->xstatetable.nClasses, &maxState, &maxEntry, gxvalid ); else { #if 0 maxState = 1; /* 0:start of text, 1:start of line are predefined */ #endif maxEntry = 0; } if ( maxEntry > 0 && entryTable == 0 ) FT_INVALID_OFFSET; if ( entryTable != 0 ) gxv_XEntryTable_validate( table + entryTable, &entryTable_length, maxEntry, stateArray_length, gxvalid->xstatetable.maxClassID, table, limit, gxvalid ); GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Table overlapping *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static int gxv_compare_ranges( FT_Bytes table1_start, FT_ULong table1_length, FT_Bytes table2_start, FT_ULong table2_length ) { if ( table1_start == table2_start ) { if ( ( table1_length == 0 || table2_length == 0 ) ) goto Out; } else if ( table1_start < table2_start ) { if ( ( table1_start + table1_length ) <= table2_start ) goto Out; } else if ( table1_start > table2_start ) { if ( ( table1_start >= table2_start + table2_length ) ) goto Out; } return 1; Out: return 0; } FT_LOCAL_DEF( void ) gxv_odtect_add_range( FT_Bytes start, FT_ULong length, const FT_String* name, GXV_odtect_Range odtect ) { odtect->range[odtect->nRanges].start = start; odtect->range[odtect->nRanges].length = length; odtect->range[odtect->nRanges].name = (FT_String*)name; odtect->nRanges++; } FT_LOCAL_DEF( void ) gxv_odtect_validate( GXV_odtect_Range odtect, GXV_Validator gxvalid ) { FT_UInt i, j; GXV_NAME_ENTER( "check overlap among multi ranges" ); for ( i = 0; i < odtect->nRanges; i++ ) for ( j = 0; j < i; j++ ) if ( 0 != gxv_compare_ranges( odtect->range[i].start, odtect->range[i].length, odtect->range[j].start, odtect->range[j].length ) ) { #ifdef FT_DEBUG_LEVEL_TRACE if ( odtect->range[i].name || odtect->range[j].name ) GXV_TRACE(( "found overlap between range %d and range %d\n", i, j )); else GXV_TRACE(( "found overlap between `%s' and `%s\'\n", odtect->range[i].name, odtect->range[j].name )); #endif FT_INVALID_OFFSET; } GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvcommn.c
C++
gpl-3.0
54,281
/**************************************************************************** * * gxvcommn.h * * TrueTypeGX/AAT common tables validation (specification). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ /* * keywords in variable naming * --------------------------- * table: Of type FT_Bytes, pointing to the start of this table/subtable. * limit: Of type FT_Bytes, pointing to the end of this table/subtable, * including padding for alignment. * offset: Of type FT_UInt, the number of octets from the start to target. * length: Of type FT_UInt, the number of octets from the start to the * end in this table/subtable, including padding for alignment. * * _MIN, _MAX: Should be added to the tail of macros, as INT_MIN, etc. */ #ifndef GXVCOMMN_H_ #define GXVCOMMN_H_ #include "gxvalid.h" #include <freetype/internal/ftdebug.h> #include <freetype/ftsnames.h> FT_BEGIN_HEADER /* some variables are not evaluated or only used in trace */ #ifdef FT_DEBUG_LEVEL_TRACE #define GXV_LOAD_TRACE_VARS #else #undef GXV_LOAD_TRACE_VARS #endif #undef GXV_LOAD_UNUSED_VARS /* debug purpose */ #define IS_PARANOID_VALIDATION \ ( gxvalid->root->level >= FT_VALIDATE_PARANOID ) #define GXV_SET_ERR_IF_PARANOID( err ) \ do { if ( IS_PARANOID_VALIDATION ) ( err ); } while ( 0 ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** VALIDATION *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_ValidatorRec_* GXV_Validator; #define DUMMY_LIMIT 0 typedef void (*GXV_Validate_Func)( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); /* ====================== LookupTable Validator ======================== */ typedef union GXV_LookupValueDesc_ { FT_UShort u; FT_Short s; } GXV_LookupValueDesc; typedef const GXV_LookupValueDesc* GXV_LookupValueCPtr; typedef enum GXV_LookupValue_SignSpec_ { GXV_LOOKUPVALUE_UNSIGNED = 0, GXV_LOOKUPVALUE_SIGNED } GXV_LookupValue_SignSpec; typedef void (*GXV_Lookup_Value_Validate_Func)( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ); typedef GXV_LookupValueDesc (*GXV_Lookup_Fmt4_Transit_Func)( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ); /* ====================== StateTable Validator ========================= */ typedef enum GXV_GlyphOffset_Format_ { GXV_GLYPHOFFSET_NONE = -1, GXV_GLYPHOFFSET_UCHAR = 2, GXV_GLYPHOFFSET_CHAR, GXV_GLYPHOFFSET_USHORT = 4, GXV_GLYPHOFFSET_SHORT, GXV_GLYPHOFFSET_ULONG = 8, GXV_GLYPHOFFSET_LONG } GXV_GlyphOffset_Format; #define GXV_GLYPHOFFSET_FMT( table ) \ ( gxvalid->table.entry_glyphoffset_fmt ) #define GXV_GLYPHOFFSET_SIZE( table ) \ ( gxvalid->table.entry_glyphoffset_fmt / 2 ) /* ----------------------- 16bit StateTable ---------------------------- */ typedef union GXV_StateTable_GlyphOffsetDesc_ { FT_Byte uc; FT_UShort u; /* same as GXV_LookupValueDesc */ FT_ULong ul; FT_Char c; FT_Short s; /* same as GXV_LookupValueDesc */ FT_Long l; } GXV_StateTable_GlyphOffsetDesc; typedef const GXV_StateTable_GlyphOffsetDesc* GXV_StateTable_GlyphOffsetCPtr; typedef void (*GXV_StateTable_Subtable_Setup_Func)( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ); typedef void (*GXV_StateTable_Entry_Validate_Func)( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes statetable_table, FT_Bytes statetable_limit, GXV_Validator gxvalid ); typedef void (*GXV_StateTable_OptData_Load_Func)( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); typedef struct GXV_StateTable_ValidatorRec_ { GXV_GlyphOffset_Format entry_glyphoffset_fmt; void* optdata; GXV_StateTable_Subtable_Setup_Func subtable_setup_func; GXV_StateTable_Entry_Validate_Func entry_validate_func; GXV_StateTable_OptData_Load_Func optdata_load_func; } GXV_StateTable_ValidatorRec, *GXV_StateTable_ValidatorRecData; /* ---------------------- 32bit XStateTable ---------------------------- */ typedef GXV_StateTable_GlyphOffsetDesc GXV_XStateTable_GlyphOffsetDesc; typedef const GXV_XStateTable_GlyphOffsetDesc* GXV_XStateTable_GlyphOffsetCPtr; typedef void (*GXV_XStateTable_Subtable_Setup_Func)( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ); typedef void (*GXV_XStateTable_Entry_Validate_Func)( FT_UShort state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes xstatetable_table, FT_Bytes xstatetable_limit, GXV_Validator gxvalid ); typedef GXV_StateTable_OptData_Load_Func GXV_XStateTable_OptData_Load_Func; typedef struct GXV_XStateTable_ValidatorRec_ { int entry_glyphoffset_fmt; void* optdata; GXV_XStateTable_Subtable_Setup_Func subtable_setup_func; GXV_XStateTable_Entry_Validate_Func entry_validate_func; GXV_XStateTable_OptData_Load_Func optdata_load_func; FT_ULong nClasses; FT_UShort maxClassID; } GXV_XStateTable_ValidatorRec, *GXV_XStateTable_ValidatorRecData; /* ===================================================================== */ typedef struct GXV_ValidatorRec_ { FT_Validator root; FT_Face face; void* table_data; FT_ULong subtable_length; GXV_LookupValue_SignSpec lookupval_sign; GXV_Lookup_Value_Validate_Func lookupval_func; GXV_Lookup_Fmt4_Transit_Func lookupfmt4_trans; FT_Bytes lookuptbl_head; FT_UShort min_gid; FT_UShort max_gid; GXV_StateTable_ValidatorRec statetable; GXV_XStateTable_ValidatorRec xstatetable; #ifdef FT_DEBUG_LEVEL_TRACE FT_UInt debug_indent; const FT_String* debug_function_name[3]; #endif } GXV_ValidatorRec; #define GXV_TABLE_DATA( tag, field ) \ ( ( (GXV_ ## tag ## _Data)gxvalid->table_data )->field ) #undef FT_INVALID_ #define FT_INVALID_( _error ) \ ft_validator_error( gxvalid->root, FT_THROW( _error ) ) #define GXV_LIMIT_CHECK( _count ) \ FT_BEGIN_STMNT \ if ( p + _count > ( limit? limit : gxvalid->root->limit ) ) \ FT_INVALID_TOO_SHORT; \ FT_END_STMNT #ifdef FT_DEBUG_LEVEL_TRACE #define GXV_INIT gxvalid->debug_indent = 0 #define GXV_NAME_ENTER( name ) \ FT_BEGIN_STMNT \ gxvalid->debug_indent += 2; \ FT_TRACE4(( "%*.s", gxvalid->debug_indent, "" )); \ FT_TRACE4(( "%s table\n", name )); \ FT_END_STMNT #define GXV_EXIT gxvalid->debug_indent -= 2 #define GXV_TRACE( s ) \ FT_BEGIN_STMNT \ FT_TRACE4(( "%*.s", gxvalid->debug_indent, "" )); \ FT_TRACE4( s ); \ FT_END_STMNT #else /* !FT_DEBUG_LEVEL_TRACE */ #define GXV_INIT do { } while ( 0 ) #define GXV_NAME_ENTER( name ) do { } while ( 0 ) #define GXV_EXIT do { } while ( 0 ) #define GXV_TRACE( s ) do { } while ( 0 ) #endif /* !FT_DEBUG_LEVEL_TRACE */ /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** 32bit alignment checking *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \ FT_BEGIN_STMNT \ { \ if ( (a) & 3 ) \ FT_INVALID_OFFSET; \ } \ FT_END_STMNT /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Dumping Binary Data *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define GXV_TRACE_HEXDUMP( p, len ) \ FT_BEGIN_STMNT \ { \ FT_Bytes b; \ \ \ for ( b = p; b < (FT_Bytes)p + len; b++ ) \ FT_TRACE1(("\\x%02x", *b)); \ } \ FT_END_STMNT #define GXV_TRACE_HEXDUMP_C( p, len ) \ FT_BEGIN_STMNT \ { \ FT_Bytes b; \ \ \ for ( b = p; b < (FT_Bytes)p + len; b++ ) \ if ( 0x40 < *b && *b < 0x7E ) \ FT_TRACE1(("%c", *b)); \ else \ FT_TRACE1(("\\x%02x", *b)); \ } \ FT_END_STMNT #define GXV_TRACE_HEXDUMP_SFNTNAME( n ) \ GXV_TRACE_HEXDUMP( n.string, n.string_len ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** LOOKUP TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( void ) gxv_BinSrchHeader_validate( FT_Bytes p, FT_Bytes limit, FT_UShort* unitSize_p, FT_UShort* nUnits_p, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_LookupTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Glyph ID *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( FT_Int ) gxv_glyphid_validate( FT_UShort gid, GXV_Validator gxvalid ); /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CONTROL POINT *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( void ) gxv_ctlPoint_validate( FT_UShort gid, FT_UShort ctl_point, GXV_Validator gxvalid ); /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** SFNT NAME *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( void ) gxv_sfntName_validate( FT_UShort name_index, FT_UShort min_index, FT_UShort max_index, GXV_Validator gxvalid ); /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** STATE TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( void ) gxv_StateTable_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_XStateTable_subtable_setup( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_StateTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_XStateTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY MACROS AND FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL( void ) gxv_array_getlimits_byte( FT_Bytes table, FT_Bytes limit, FT_Byte* min, FT_Byte* max, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_array_getlimits_ushort( FT_Bytes table, FT_Bytes limit, FT_UShort* min, FT_UShort* max, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_set_length_by_ushort_offset( FT_UShort* offset, FT_UShort** length, FT_UShort* buff, FT_UInt nmemb, FT_UShort limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_set_length_by_ulong_offset( FT_ULong* offset, FT_ULong** length, FT_ULong* buff, FT_UInt nmemb, FT_ULong limit, GXV_Validator gxvalid); #define GXV_SUBTABLE_OFFSET_CHECK( _offset ) \ FT_BEGIN_STMNT \ if ( (_offset) > gxvalid->subtable_length ) \ FT_INVALID_OFFSET; \ FT_END_STMNT #define GXV_SUBTABLE_LIMIT_CHECK( _count ) \ FT_BEGIN_STMNT \ if ( ( p + (_count) - gxvalid->subtable_start ) > \ gxvalid->subtable_length ) \ FT_INVALID_TOO_SHORT; \ FT_END_STMNT #define GXV_USHORT_TO_SHORT( _us ) \ ( ( 0x8000U < ( _us ) ) ? ( ( _us ) - 0x8000U ) : ( _us ) ) #define GXV_STATETABLE_HEADER_SIZE ( 2 + 2 + 2 + 2 ) #define GXV_STATEHEADER_SIZE GXV_STATETABLE_HEADER_SIZE #define GXV_XSTATETABLE_HEADER_SIZE ( 4 + 4 + 4 + 4 ) #define GXV_XSTATEHEADER_SIZE GXV_XSTATETABLE_HEADER_SIZE /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Table overlapping *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_odtect_DataRec_ { FT_Bytes start; FT_ULong length; FT_String* name; } GXV_odtect_DataRec, *GXV_odtect_Data; typedef struct GXV_odtect_RangeRec_ { FT_UInt nRanges; GXV_odtect_Data range; } GXV_odtect_RangeRec, *GXV_odtect_Range; FT_LOCAL( void ) gxv_odtect_add_range( FT_Bytes start, FT_ULong length, const FT_String* name, GXV_odtect_Range odtect ); FT_LOCAL( void ) gxv_odtect_validate( GXV_odtect_Range odtect, GXV_Validator gxvalid ); #define GXV_ODTECT( n, odtect ) \ GXV_odtect_DataRec odtect ## _range[n]; \ GXV_odtect_RangeRec odtect ## _rec = { 0, NULL }; \ GXV_odtect_Range odtect = NULL #define GXV_ODTECT_INIT( odtect ) \ FT_BEGIN_STMNT \ odtect ## _rec.nRanges = 0; \ odtect ## _rec.range = odtect ## _range; \ odtect = & odtect ## _rec; \ FT_END_STMNT /* */ FT_END_HEADER #endif /* GXVCOMMN_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvcommn.h
C++
gpl-3.0
22,980
/**************************************************************************** * * gxverror.h * * TrueTypeGX/AAT validation module error codes (specification only). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ /************************************************************************** * * This file is used to define the OpenType validation module error * enumeration constants. * */ #ifndef GXVERROR_H_ #define GXVERROR_H_ #include <freetype/ftmoderr.h> #undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX GXV_Err_ #define FT_ERR_BASE FT_Mod_Err_GXvalid #include <freetype/fterrors.h> #endif /* GXVERROR_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxverror.h
C++
gpl-3.0
1,333
/**************************************************************************** * * gxvfeat.c * * TrueTypeGX/AAT feat table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.h" #include "gxvfeat.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 gxvfeat /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_feat_DataRec_ { FT_UInt reserved_size; FT_UShort feature; FT_UShort setting; } GXV_feat_DataRec, *GXV_feat_Data; #define GXV_FEAT_DATA( field ) GXV_TABLE_DATA( feat, field ) typedef enum GXV_FeatureFlagsMask_ { GXV_FEAT_MASK_EXCLUSIVE_SETTINGS = 0x8000U, GXV_FEAT_MASK_DYNAMIC_DEFAULT = 0x4000, GXV_FEAT_MASK_UNUSED = 0x3F00, GXV_FEAT_MASK_DEFAULT_SETTING = 0x00FF } GXV_FeatureFlagsMask; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_feat_registry_validate( FT_UShort feature, FT_UShort nSettings, FT_Bool exclusive, GXV_Validator gxvalid ) { GXV_NAME_ENTER( "feature in registry" ); GXV_TRACE(( " (feature = %u)\n", feature )); if ( feature >= gxv_feat_registry_length ) { GXV_TRACE(( "feature number %d is out of range %lu\n", feature, gxv_feat_registry_length )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); goto Exit; } if ( gxv_feat_registry[feature].existence == 0 ) { GXV_TRACE(( "feature number %d is in defined range but doesn't exist\n", feature )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); goto Exit; } if ( gxv_feat_registry[feature].apple_reserved ) { /* Don't use here. Apple is reserved. */ GXV_TRACE(( "feature number %d is reserved by Apple\n", feature )); if ( gxvalid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } if ( nSettings != gxv_feat_registry[feature].nSettings ) { GXV_TRACE(( "feature %d: nSettings %d != defined nSettings %d\n", feature, nSettings, gxv_feat_registry[feature].nSettings )); if ( gxvalid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } if ( exclusive != gxv_feat_registry[feature].exclusive ) { GXV_TRACE(( "exclusive flag %d differs from predefined value\n", exclusive )); if ( gxvalid->root->level >= FT_VALIDATE_TIGHT ) FT_INVALID_DATA; } Exit: GXV_EXIT; } static void gxv_feat_name_index_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Short nameIndex; GXV_NAME_ENTER( "nameIndex" ); GXV_LIMIT_CHECK( 2 ); nameIndex = FT_NEXT_SHORT ( p ); GXV_TRACE(( " (nameIndex = %d)\n", nameIndex )); gxv_sfntName_validate( (FT_UShort)nameIndex, 255, 32768U, gxvalid ); GXV_EXIT; } static void gxv_feat_setting_validate( FT_Bytes table, FT_Bytes limit, FT_Bool exclusive, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort setting; GXV_NAME_ENTER( "setting" ); GXV_LIMIT_CHECK( 2 ); setting = FT_NEXT_USHORT( p ); /* If we have exclusive setting, the setting should be odd. */ if ( exclusive && ( setting & 1 ) == 0 ) FT_INVALID_DATA; gxv_feat_name_index_validate( p, limit, gxvalid ); GXV_FEAT_DATA( setting ) = setting; GXV_EXIT; } static void gxv_feat_name_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UInt reserved_size = GXV_FEAT_DATA( reserved_size ); FT_UShort feature; FT_UShort nSettings; FT_ULong settingTable; FT_UShort featureFlags; FT_Bool exclusive; FT_Int last_setting; FT_UInt i; GXV_NAME_ENTER( "name" ); /* feature + nSettings + settingTable + featureFlags */ GXV_LIMIT_CHECK( 2 + 2 + 4 + 2 ); feature = FT_NEXT_USHORT( p ); GXV_FEAT_DATA( feature ) = feature; nSettings = FT_NEXT_USHORT( p ); settingTable = FT_NEXT_ULONG ( p ); featureFlags = FT_NEXT_USHORT( p ); if ( settingTable < reserved_size ) FT_INVALID_OFFSET; if ( ( featureFlags & GXV_FEAT_MASK_UNUSED ) == 0 ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); exclusive = FT_BOOL( featureFlags & GXV_FEAT_MASK_EXCLUSIVE_SETTINGS ); if ( exclusive ) { FT_Byte dynamic_default; if ( featureFlags & GXV_FEAT_MASK_DYNAMIC_DEFAULT ) dynamic_default = (FT_Byte)( featureFlags & GXV_FEAT_MASK_DEFAULT_SETTING ); else dynamic_default = 0; /* If exclusive, check whether default setting is in the range. */ if ( !( dynamic_default < nSettings ) ) FT_INVALID_FORMAT; } gxv_feat_registry_validate( feature, nSettings, exclusive, gxvalid ); gxv_feat_name_index_validate( p, limit, gxvalid ); p = gxvalid->root->base + settingTable; for ( last_setting = -1, i = 0; i < nSettings; i++ ) { gxv_feat_setting_validate( p, limit, exclusive, gxvalid ); if ( (FT_Int)GXV_FEAT_DATA( setting ) <= last_setting ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_FORMAT ); last_setting = (FT_Int)GXV_FEAT_DATA( setting ); /* setting + nameIndex */ p += ( 2 + 2 ); } GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** feat TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_feat_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_feat_DataRec featrec; GXV_feat_Data feat = &featrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_UInt featureNameCount; FT_UInt i; FT_Int last_feature; gxvalid->root = ftvalid; gxvalid->table_data = feat; gxvalid->face = face; FT_TRACE3(( "validating `feat' table\n" )); GXV_INIT; feat->reserved_size = 0; /* version + featureNameCount + none_0 + none_1 */ GXV_LIMIT_CHECK( 4 + 2 + 2 + 4 ); feat->reserved_size += 4 + 2 + 2 + 4; if ( FT_NEXT_ULONG( p ) != 0x00010000UL ) /* Version */ FT_INVALID_FORMAT; featureNameCount = FT_NEXT_USHORT( p ); GXV_TRACE(( " (featureNameCount = %d)\n", featureNameCount )); if ( !( IS_PARANOID_VALIDATION ) ) p += 6; /* skip (none) and (none) */ else { if ( FT_NEXT_USHORT( p ) != 0 ) FT_INVALID_DATA; if ( FT_NEXT_ULONG( p ) != 0 ) FT_INVALID_DATA; } feat->reserved_size += featureNameCount * ( 2 + 2 + 4 + 2 + 2 ); for ( last_feature = -1, i = 0; i < featureNameCount; i++ ) { gxv_feat_name_validate( p, limit, gxvalid ); if ( (FT_Int)GXV_FEAT_DATA( feature ) <= last_feature ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_FORMAT ); last_feature = GXV_FEAT_DATA( feature ); p += 2 + 2 + 4 + 2 + 2; } FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvfeat.c
C++
gpl-3.0
9,949
/**************************************************************************** * * gxvfeat.h * * TrueTypeGX/AAT feat table validation (specification). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #ifndef GXVFEAT_H_ #define GXVFEAT_H_ #include "gxvalid.h" #include "gxvcommn.h" /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Registry predefined by Apple *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* TODO: More compact format */ typedef struct GXV_Feature_RegistryRec_ { FT_Bool existence; FT_Bool apple_reserved; FT_Bool exclusive; FT_Byte nSettings; } GX_Feature_RegistryRec; #define gxv_feat_registry_length \ ( sizeof ( gxv_feat_registry ) / \ sizeof ( GX_Feature_RegistryRec ) ) static GX_Feature_RegistryRec gxv_feat_registry[] = { /* Generated from gxvfgen.c */ {1, 0, 0, 1}, /* All Typographic Features */ {1, 0, 0, 8}, /* Ligatures */ {1, 0, 1, 3}, /* Cursive Connection */ {1, 0, 1, 6}, /* Letter Case */ {1, 0, 0, 1}, /* Vertical Substitution */ {1, 0, 0, 1}, /* Linguistic Rearrangement */ {1, 0, 1, 2}, /* Number Spacing */ {1, 1, 0, 0}, /* Apple Reserved 1 */ {1, 0, 0, 5}, /* Smart Swashes */ {1, 0, 1, 3}, /* Diacritics */ {1, 0, 1, 4}, /* Vertical Position */ {1, 0, 1, 3}, /* Fractions */ {1, 1, 0, 0}, /* Apple Reserved 2 */ {1, 0, 0, 1}, /* Overlapping Characters */ {1, 0, 0, 6}, /* Typographic Extras */ {1, 0, 0, 5}, /* Mathematical Extras */ {1, 0, 1, 7}, /* Ornament Sets */ {1, 0, 1, 1}, /* Character Alternatives */ {1, 0, 1, 5}, /* Design Complexity */ {1, 0, 1, 6}, /* Style Options */ {1, 0, 1, 11}, /* Character Shape */ {1, 0, 1, 2}, /* Number Case */ {1, 0, 1, 4}, /* Text Spacing */ {1, 0, 1, 10}, /* Transliteration */ {1, 0, 1, 9}, /* Annotation */ {1, 0, 1, 2}, /* Kana Spacing */ {1, 0, 1, 2}, /* Ideographic Spacing */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {0, 0, 0, 0}, /* __EMPTY__ */ {1, 0, 1, 4}, /* Text Spacing */ {1, 0, 1, 2}, /* Kana Spacing */ {1, 0, 1, 2}, /* Ideographic Spacing */ {1, 0, 1, 4}, /* CJK Roman Spacing */ }; #endif /* GXVFEAT_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvfeat.h
C++
gpl-3.0
6,054
/**************************************************************************** * * gxfgen.c * * Generate feature registry data for gxv `feat' validator. * This program is derived from gxfeatreg.c in gxlayout. * * Copyright (C) 2004-2022 by * Masatake YAMATO and Redhat K.K. * * This file 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. * */ /**************************************************************************** * * gxfeatreg.c * * Database of font features pre-defined by Apple Computer, Inc. * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html * (body). * * Copyright 2003 by * Masatake YAMATO and Redhat K.K. * * This file 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. * */ /**************************************************************************** * * Development of gxfeatreg.c is supported by * Information-technology Promotion Agency, Japan. * */ /**************************************************************************** * * This file is compiled as a stand-alone executable. * This file is never compiled into `libfreetype2'. * The output of this file is used in `gxvfeat.c'. * ----------------------------------------------------------------------- * Compile: gcc `pkg-config --cflags freetype2` gxvfgen.c -o gxvfgen * Run: ./gxvfgen > tmp.c * */ /******************************************************************** * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ /* * If you add a new setting to a feature, check the number of settings * in the feature. If the number is greater than the value defined as * FEATREG_MAX_SETTING, update the value. */ #define FEATREG_MAX_SETTING 12 /******************************************************************** * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ #include <stdio.h> #include <string.h> /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define APPLE_RESERVED "Apple Reserved" #define APPLE_RESERVED_LENGTH 14 typedef struct GX_Feature_RegistryRec_ { const char* feat_name; char exclusive; char* setting_name[FEATREG_MAX_SETTING]; } GX_Feature_RegistryRec; #define EMPTYFEAT {0, 0, {NULL}} static GX_Feature_RegistryRec featreg_table[] = { { /* 0 */ "All Typographic Features", 0, { "All Type Features", NULL } }, { /* 1 */ "Ligatures", 0, { "Required Ligatures", "Common Ligatures", "Rare Ligatures", "Logos", "Rebus Pictures", "Diphthong Ligatures", "Squared Ligatures", "Squared Ligatures, Abbreviated", NULL } }, { /* 2 */ "Cursive Connection", 1, { "Unconnected", "Partially Connected", "Cursive", NULL } }, { /* 3 */ "Letter Case", 1, { "Upper & Lower Case", "All Caps", "All Lower Case", "Small Caps", "Initial Caps", "Initial Caps & Small Caps", NULL } }, { /* 4 */ "Vertical Substitution", 0, { /* "Substitute Vertical Forms", */ "Turns on the feature", NULL } }, { /* 5 */ "Linguistic Rearrangement", 0, { /* "Linguistic Rearrangement", */ "Turns on the feature", NULL } }, { /* 6 */ "Number Spacing", 1, { "Monospaced Numbers", "Proportional Numbers", NULL } }, { /* 7 */ APPLE_RESERVED " 1", 0, {NULL} }, { /* 8 */ "Smart Swashes", 0, { "Word Initial Swashes", "Word Final Swashes", "Line Initial Swashes", "Line Final Swashes", "Non-Final Swashes", NULL } }, { /* 9 */ "Diacritics", 1, { "Show Diacritics", "Hide Diacritics", "Decompose Diacritics", NULL } }, { /* 10 */ "Vertical Position", 1, { /* "Normal Position", */ "No Vertical Position", "Superiors", "Inferiors", "Ordinals", NULL } }, { /* 11 */ "Fractions", 1, { "No Fractions", "Vertical Fractions", "Diagonal Fractions", NULL } }, { /* 12 */ APPLE_RESERVED " 2", 0, {NULL} }, { /* 13 */ "Overlapping Characters", 0, { /* "Prevent Overlap", */ "Turns on the feature", NULL } }, { /* 14 */ "Typographic Extras", 0, { "Hyphens to Em Dash", "Hyphens to En Dash", "Unslashed Zero", "Form Interrobang", "Smart Quotes", "Periods to Ellipsis", NULL } }, { /* 15 */ "Mathematical Extras", 0, { "Hyphens to Minus", "Asterisk to Multiply", "Slash to Divide", "Inequality Ligatures", "Exponents", NULL } }, { /* 16 */ "Ornament Sets", 1, { "No Ornaments", "Dingbats", "Pi Characters", "Fleurons", "Decorative Borders", "International Symbols", "Math Symbols", NULL } }, { /* 17 */ "Character Alternatives", 1, { "No Alternates", /* TODO */ NULL } }, { /* 18 */ "Design Complexity", 1, { "Design Level 1", "Design Level 2", "Design Level 3", "Design Level 4", "Design Level 5", /* TODO */ NULL } }, { /* 19 */ "Style Options", 1, { "No Style Options", "Display Text", "Engraved Text", "Illuminated Caps", "Tilling Caps", "Tall Caps", NULL } }, { /* 20 */ "Character Shape", 1, { "Traditional Characters", "Simplified Characters", "JIS 1978 Characters", "JIS 1983 Characters", "JIS 1990 Characters", "Traditional Characters, Alternative Set 1", "Traditional Characters, Alternative Set 2", "Traditional Characters, Alternative Set 3", "Traditional Characters, Alternative Set 4", "Traditional Characters, Alternative Set 5", "Expert Characters", NULL /* count => 12 */ } }, { /* 21 */ "Number Case", 1, { "Lower Case Numbers", "Upper Case Numbers", NULL } }, { /* 22 */ "Text Spacing", 1, { "Proportional", "Monospaced", "Half-width", "Normal", NULL } }, /* Here after Newer */ { /* 23 */ "Transliteration", 1, { "No Transliteration", "Hanja To Hangul", "Hiragana to Katakana", "Katakana to Hiragana", "Kana to Romanization", "Romanization to Hiragana", "Romanization to Katakana", "Hanja to Hangul, Alternative Set 1", "Hanja to Hangul, Alternative Set 2", "Hanja to Hangul, Alternative Set 3", NULL } }, { /* 24 */ "Annotation", 1, { "No Annotation", "Box Annotation", "Rounded Box Annotation", "Circle Annotation", "Inverted Circle Annotation", "Parenthesis Annotation", "Period Annotation", "Roman Numeral Annotation", "Diamond Annotation", NULL } }, { /* 25 */ "Kana Spacing", 1, { "Full Width", "Proportional", NULL } }, { /* 26 */ "Ideographic Spacing", 1, { "Full Width", "Proportional", NULL } }, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 27-30 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 31-35 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 36-40 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 40-45 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 46-50 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 51-55 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 56-60 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 61-65 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 66-70 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 71-75 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 76-80 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 81-85 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 86-90 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 91-95 */ EMPTYFEAT, EMPTYFEAT, EMPTYFEAT, /* 96-98 */ EMPTYFEAT, /* 99 */ { /* 100 => 22 */ "Text Spacing", 1, { "Proportional", "Monospaced", "Half-width", "Normal", NULL } }, { /* 101 => 25 */ "Kana Spacing", 1, { "Full Width", "Proportional", NULL } }, { /* 102 => 26 */ "Ideographic Spacing", 1, { "Full Width", "Proportional", NULL } }, { /* 103 */ "CJK Roman Spacing", 1, { "Half-width", "Proportional", "Default Roman", "Full-width Roman", NULL } }, { /* 104 => 1 */ "All Typographic Features", 0, { "All Type Features", NULL } } }; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Generator *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ int main( void ) { int i; printf( " {\n" ); printf( " /* Generated from %s */\n", __FILE__ ); for ( i = 0; i < sizeof ( featreg_table ) / sizeof ( GX_Feature_RegistryRec ); i++ ) { const char* feat_name; int nSettings; feat_name = featreg_table[i].feat_name; for ( nSettings = 0; featreg_table[i].setting_name[nSettings]; nSettings++) ; /* Do nothing */ printf( " {%1d, %1d, %1d, %2d}, /* %s */\n", feat_name ? 1 : 0, ( feat_name && ( ft_strncmp( feat_name, APPLE_RESERVED, APPLE_RESERVED_LENGTH ) == 0 ) ) ? 1 : 0, featreg_table[i].exclusive ? 1 : 0, nSettings, feat_name ? feat_name : "__EMPTY__" ); } printf( " };\n" ); return 0; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvfgen.c
C++
gpl-3.0
13,317
/**************************************************************************** * * gxvjust.c * * TrueTypeGX/AAT just table validation (body). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.h" #include <freetype/ftsnames.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 gxvjust /* * referred `just' table format specification: * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6just.html * last updated 2000. * ---------------------------------------------- * [JUST HEADER]: GXV_JUST_HEADER_SIZE * version (fixed: 32bit) = 0x00010000 * format (uint16: 16bit) = 0 is only defined (2000) * horizOffset (uint16: 16bit) * vertOffset (uint16: 16bit) * ---------------------------------------------- */ typedef struct GXV_just_DataRec_ { FT_UShort wdc_offset_max; FT_UShort wdc_offset_min; FT_UShort pc_offset_max; FT_UShort pc_offset_min; } GXV_just_DataRec, *GXV_just_Data; #define GXV_JUST_DATA( a ) GXV_TABLE_DATA( just, a ) /* GX just table does not define their subset of GID */ static void gxv_just_check_max_gid( FT_UShort gid, const FT_String* msg_tag, GXV_Validator gxvalid ) { FT_UNUSED( msg_tag ); if ( gid < gxvalid->face->num_glyphs ) return; GXV_TRACE(( "just table includes too large %s" " GID=%d > %ld (in maxp)\n", msg_tag, gid, gxvalid->face->num_glyphs )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } static void gxv_just_wdp_entry_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_ULong justClass; #ifdef GXV_LOAD_UNUSED_VARS FT_Fixed beforeGrowLimit; FT_Fixed beforeShrinkGrowLimit; FT_Fixed afterGrowLimit; FT_Fixed afterShrinkGrowLimit; FT_UShort growFlags; FT_UShort shrinkFlags; #endif GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 + 4 + 2 + 2 ); justClass = FT_NEXT_ULONG( p ); #ifndef GXV_LOAD_UNUSED_VARS p += 4 + 4 + 4 + 4 + 2 + 2; #else beforeGrowLimit = FT_NEXT_ULONG( p ); beforeShrinkGrowLimit = FT_NEXT_ULONG( p ); afterGrowLimit = FT_NEXT_ULONG( p ); afterShrinkGrowLimit = FT_NEXT_ULONG( p ); growFlags = FT_NEXT_USHORT( p ); shrinkFlags = FT_NEXT_USHORT( p ); #endif /* According to Apple spec, only 7bits in justClass is used */ if ( ( justClass & 0xFFFFFF80UL ) != 0 ) { GXV_TRACE(( "just table includes non-zero value" " in unused justClass higher bits" " of WidthDeltaPair" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_just_wdc_entry_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_ULong count, i; GXV_LIMIT_CHECK( 4 ); count = FT_NEXT_ULONG( p ); for ( i = 0; i < count; i++ ) { GXV_TRACE(( "validating wdc pair %lu/%lu\n", i + 1, count )); gxv_just_wdp_entry_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; } gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_just_widthDeltaClusters_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Bytes wdc_end = table + GXV_JUST_DATA( wdc_offset_max ); FT_UInt i; GXV_NAME_ENTER( "just justDeltaClusters" ); if ( limit <= wdc_end ) FT_INVALID_OFFSET; for ( i = 0; p <= wdc_end; i++ ) { gxv_just_wdc_entry_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_just_actSubrecord_type0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Fixed lowerLimit; FT_Fixed upperLimit; #ifdef GXV_LOAD_UNUSED_VARS FT_UShort order; #endif FT_UShort decomposedCount; FT_UInt i; GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 ); lowerLimit = FT_NEXT_LONG( p ); upperLimit = FT_NEXT_LONG( p ); #ifdef GXV_LOAD_UNUSED_VARS order = FT_NEXT_USHORT( p ); #else p += 2; #endif decomposedCount = FT_NEXT_USHORT( p ); if ( lowerLimit >= upperLimit ) { GXV_TRACE(( "just table includes invalid range spec:" " lowerLimit(%ld) > upperLimit(%ld)\n", lowerLimit, upperLimit )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } for ( i = 0; i < decomposedCount; i++ ) { FT_UShort glyphs; GXV_LIMIT_CHECK( 2 ); glyphs = FT_NEXT_USHORT( p ); gxv_just_check_max_gid( glyphs, "type0:glyphs", gxvalid ); } gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_just_actSubrecord_type1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort addGlyph; GXV_LIMIT_CHECK( 2 ); addGlyph = FT_NEXT_USHORT( p ); gxv_just_check_max_gid( addGlyph, "type1:addGlyph", gxvalid ); gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_just_actSubrecord_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; #ifdef GXV_LOAD_UNUSED_VARS FT_Fixed substThreshhold; /* Apple misspelled "Threshhold" */ #endif FT_UShort addGlyph; FT_UShort substGlyph; GXV_LIMIT_CHECK( 4 + 2 + 2 ); #ifdef GXV_LOAD_UNUSED_VARS substThreshhold = FT_NEXT_ULONG( p ); #else p += 4; #endif addGlyph = FT_NEXT_USHORT( p ); substGlyph = FT_NEXT_USHORT( p ); if ( addGlyph != 0xFFFF ) gxv_just_check_max_gid( addGlyph, "type2:addGlyph", gxvalid ); gxv_just_check_max_gid( substGlyph, "type2:substGlyph", gxvalid ); gxvalid->subtable_length = (FT_ULong)( p - table ); } static void gxv_just_actSubrecord_type4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_ULong variantsAxis; FT_Fixed minimumLimit; FT_Fixed noStretchValue; FT_Fixed maximumLimit; GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 ); variantsAxis = FT_NEXT_ULONG( p ); minimumLimit = FT_NEXT_LONG( p ); noStretchValue = FT_NEXT_LONG( p ); maximumLimit = FT_NEXT_LONG( p ); gxvalid->subtable_length = (FT_ULong)( p - table ); if ( variantsAxis != 0x64756374L ) /* 'duct' */ GXV_TRACE(( "variantsAxis 0x%08lx is non default value", variantsAxis )); if ( minimumLimit > noStretchValue ) GXV_TRACE(( "type4:minimumLimit 0x%08lx > noStretchValue 0x%08lx\n", minimumLimit, noStretchValue )); else if ( noStretchValue > maximumLimit ) GXV_TRACE(( "type4:noStretchValue 0x%08lx > maximumLimit 0x%08lx\n", noStretchValue, maximumLimit )); else if ( !IS_PARANOID_VALIDATION ) return; FT_INVALID_DATA; } static void gxv_just_actSubrecord_type5_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort flags; FT_UShort glyph; GXV_LIMIT_CHECK( 2 + 2 ); flags = FT_NEXT_USHORT( p ); glyph = FT_NEXT_USHORT( p ); if ( flags ) GXV_TRACE(( "type5: nonzero value 0x%04x in unused flags\n", flags )); gxv_just_check_max_gid( glyph, "type5:glyph", gxvalid ); gxvalid->subtable_length = (FT_ULong)( p - table ); } /* parse single actSubrecord */ static void gxv_just_actSubrecord_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort actionClass; FT_UShort actionType; FT_ULong actionLength; GXV_NAME_ENTER( "just actSubrecord" ); GXV_LIMIT_CHECK( 2 + 2 + 4 ); actionClass = FT_NEXT_USHORT( p ); actionType = FT_NEXT_USHORT( p ); actionLength = FT_NEXT_ULONG( p ); /* actionClass is related with justClass using 7bit only */ if ( ( actionClass & 0xFF80 ) != 0 ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); if ( actionType == 0 ) gxv_just_actSubrecord_type0_validate( p, limit, gxvalid ); else if ( actionType == 1 ) gxv_just_actSubrecord_type1_validate( p, limit, gxvalid ); else if ( actionType == 2 ) gxv_just_actSubrecord_type2_validate( p, limit, gxvalid ); else if ( actionType == 3 ) ; /* Stretch glyph action: no actionData */ else if ( actionType == 4 ) gxv_just_actSubrecord_type4_validate( p, limit, gxvalid ); else if ( actionType == 5 ) gxv_just_actSubrecord_type5_validate( p, limit, gxvalid ); else FT_INVALID_DATA; gxvalid->subtable_length = actionLength; GXV_EXIT; } static void gxv_just_pcActionRecord_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_ULong actionCount; FT_ULong i; GXV_LIMIT_CHECK( 4 ); actionCount = FT_NEXT_ULONG( p ); GXV_TRACE(( "actionCount = %lu\n", actionCount )); for ( i = 0; i < actionCount; i++ ) { gxv_just_actSubrecord_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_just_pcTable_LookupValue_entry_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UNUSED( glyph ); if ( value_p->u > GXV_JUST_DATA( pc_offset_max ) ) GXV_JUST_DATA( pc_offset_max ) = value_p->u; if ( value_p->u < GXV_JUST_DATA( pc_offset_max ) ) GXV_JUST_DATA( pc_offset_min ) = value_p->u; } static void gxv_just_pcLookupTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_NAME_ENTER( "just pcLookupTable" ); GXV_JUST_DATA( pc_offset_max ) = 0x0000; GXV_JUST_DATA( pc_offset_min ) = 0xFFFFU; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_just_pcTable_LookupValue_entry_validate; gxv_LookupTable_validate( p, limit, gxvalid ); /* subtable_length is set by gxv_LookupTable_validate() */ GXV_EXIT; } static void gxv_just_postcompTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_NAME_ENTER( "just postcompTable" ); gxv_just_pcLookupTable_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; gxv_just_pcActionRecord_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_just_classTable_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS /* TODO: validate markClass & currentClass */ FT_UShort setMark; FT_UShort dontAdvance; FT_UShort markClass; FT_UShort currentClass; #endif FT_UNUSED( state ); FT_UNUSED( glyphOffset_p ); FT_UNUSED( table ); FT_UNUSED( limit ); FT_UNUSED( gxvalid ); #ifndef GXV_LOAD_UNUSED_VARS FT_UNUSED( flags ); #else setMark = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); markClass = (FT_UShort)( ( flags >> 7 ) & 0x7F ); currentClass = (FT_UShort)( flags & 0x7F ); #endif } static void gxv_just_justClassTable_validate ( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort length; FT_UShort coverage; FT_ULong subFeatureFlags; GXV_NAME_ENTER( "just justClassTable" ); GXV_LIMIT_CHECK( 2 + 2 + 4 ); length = FT_NEXT_USHORT( p ); coverage = FT_NEXT_USHORT( p ); subFeatureFlags = FT_NEXT_ULONG( p ); GXV_TRACE(( " justClassTable: coverage = 0x%04x ", coverage )); if ( ( coverage & 0x4000 ) == 0 ) GXV_TRACE(( "ascending\n" )); else GXV_TRACE(( "descending\n" )); if ( subFeatureFlags ) GXV_TRACE(( " justClassTable: nonzero value (0x%08lx)" " in unused subFeatureFlags\n", subFeatureFlags )); gxvalid->statetable.optdata = NULL; gxvalid->statetable.optdata_load_func = NULL; gxvalid->statetable.subtable_setup_func = NULL; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; gxvalid->statetable.entry_validate_func = gxv_just_classTable_entry_validate; gxv_StateTable_validate( p, table + length, gxvalid ); /* subtable_length is set by gxv_LookupTable_validate() */ GXV_EXIT; } static void gxv_just_wdcTable_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UNUSED( glyph ); if ( value_p->u > GXV_JUST_DATA( wdc_offset_max ) ) GXV_JUST_DATA( wdc_offset_max ) = value_p->u; if ( value_p->u < GXV_JUST_DATA( wdc_offset_min ) ) GXV_JUST_DATA( wdc_offset_min ) = value_p->u; } static void gxv_just_justData_lookuptable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_JUST_DATA( wdc_offset_max ) = 0x0000; GXV_JUST_DATA( wdc_offset_min ) = 0xFFFFU; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_just_wdcTable_LookupValue_validate; gxv_LookupTable_validate( p, limit, gxvalid ); /* subtable_length is set by gxv_LookupTable_validate() */ GXV_EXIT; } /* * gxv_just_justData_validate() parses and validates horizData, vertData. */ static void gxv_just_justData_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { /* * following 3 offsets are measured from the start of `just' * (which table points to), not justData */ FT_UShort justClassTableOffset; FT_UShort wdcTableOffset; FT_UShort pcTableOffset; FT_Bytes p = table; GXV_ODTECT( 4, odtect ); GXV_NAME_ENTER( "just justData" ); GXV_ODTECT_INIT( odtect ); GXV_LIMIT_CHECK( 2 + 2 + 2 ); justClassTableOffset = FT_NEXT_USHORT( p ); wdcTableOffset = FT_NEXT_USHORT( p ); pcTableOffset = FT_NEXT_USHORT( p ); GXV_TRACE(( " (justClassTableOffset = 0x%04x)\n", justClassTableOffset )); GXV_TRACE(( " (wdcTableOffset = 0x%04x)\n", wdcTableOffset )); GXV_TRACE(( " (pcTableOffset = 0x%04x)\n", pcTableOffset )); gxv_just_justData_lookuptable_validate( p, limit, gxvalid ); gxv_odtect_add_range( p, gxvalid->subtable_length, "just_LookupTable", odtect ); if ( wdcTableOffset ) { gxv_just_widthDeltaClusters_validate( gxvalid->root->base + wdcTableOffset, limit, gxvalid ); gxv_odtect_add_range( gxvalid->root->base + wdcTableOffset, gxvalid->subtable_length, "just_wdcTable", odtect ); } if ( pcTableOffset ) { gxv_just_postcompTable_validate( gxvalid->root->base + pcTableOffset, limit, gxvalid ); gxv_odtect_add_range( gxvalid->root->base + pcTableOffset, gxvalid->subtable_length, "just_pcTable", odtect ); } if ( justClassTableOffset ) { gxv_just_justClassTable_validate( gxvalid->root->base + justClassTableOffset, limit, gxvalid ); gxv_odtect_add_range( gxvalid->root->base + justClassTableOffset, gxvalid->subtable_length, "just_justClassTable", odtect ); } gxv_odtect_validate( odtect, gxvalid ); GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_just_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { FT_Bytes p = table; FT_Bytes limit = 0; GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_just_DataRec justrec; GXV_just_Data just = &justrec; FT_ULong version; FT_UShort format; FT_UShort horizOffset; FT_UShort vertOffset; GXV_ODTECT( 3, odtect ); GXV_ODTECT_INIT( odtect ); gxvalid->root = ftvalid; gxvalid->table_data = just; gxvalid->face = face; FT_TRACE3(( "validating `just' table\n" )); GXV_INIT; limit = gxvalid->root->limit; GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 ); version = FT_NEXT_ULONG( p ); format = FT_NEXT_USHORT( p ); horizOffset = FT_NEXT_USHORT( p ); vertOffset = FT_NEXT_USHORT( p ); gxv_odtect_add_range( table, (FT_ULong)( p - table ), "just header", odtect ); /* Version 1.0 (always:2000) */ GXV_TRACE(( " (version = 0x%08lx)\n", version )); if ( version != 0x00010000UL ) FT_INVALID_FORMAT; /* format 0 (always:2000) */ GXV_TRACE(( " (format = 0x%04x)\n", format )); if ( format != 0x0000 ) FT_INVALID_FORMAT; GXV_TRACE(( " (horizOffset = %d)\n", horizOffset )); GXV_TRACE(( " (vertOffset = %d)\n", vertOffset )); /* validate justData */ if ( 0 < horizOffset ) { gxv_just_justData_validate( table + horizOffset, limit, gxvalid ); gxv_odtect_add_range( table + horizOffset, gxvalid->subtable_length, "horizJustData", odtect ); } if ( 0 < vertOffset ) { gxv_just_justData_validate( table + vertOffset, limit, gxvalid ); gxv_odtect_add_range( table + vertOffset, gxvalid->subtable_length, "vertJustData", odtect ); } gxv_odtect_validate( odtect, gxvalid ); FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvjust.c
C++
gpl-3.0
20,615
/**************************************************************************** * * gxvkern.c * * TrueTypeGX/AAT kern table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.h" #include <freetype/ftsnames.h> #include <freetype/internal/services/svgxval.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 gxvkern /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef enum GXV_kern_Version_ { KERN_VERSION_CLASSIC = 0x0000, KERN_VERSION_NEW = 0x0001 } GXV_kern_Version; typedef enum GXV_kern_Dialect_ { KERN_DIALECT_UNKNOWN = 0, KERN_DIALECT_MS = FT_VALIDATE_MS, KERN_DIALECT_APPLE = FT_VALIDATE_APPLE, KERN_DIALECT_ANY = FT_VALIDATE_CKERN } GXV_kern_Dialect; typedef struct GXV_kern_DataRec_ { GXV_kern_Version version; void *subtable_data; GXV_kern_Dialect dialect_request; } GXV_kern_DataRec, *GXV_kern_Data; #define GXV_KERN_DATA( field ) GXV_TABLE_DATA( kern, field ) #define KERN_IS_CLASSIC( gxvalid ) \ ( KERN_VERSION_CLASSIC == GXV_KERN_DATA( version ) ) #define KERN_IS_NEW( gxvalid ) \ ( KERN_VERSION_NEW == GXV_KERN_DATA( version ) ) #define KERN_DIALECT( gxvalid ) \ GXV_KERN_DATA( dialect_request ) #define KERN_ALLOWS_MS( gxvalid ) \ ( KERN_DIALECT( gxvalid ) & KERN_DIALECT_MS ) #define KERN_ALLOWS_APPLE( gxvalid ) \ ( KERN_DIALECT( gxvalid ) & KERN_DIALECT_APPLE ) #define GXV_KERN_HEADER_SIZE ( KERN_IS_NEW( gxvalid ) ? 8 : 4 ) #define GXV_KERN_SUBTABLE_HEADER_SIZE ( KERN_IS_NEW( gxvalid ) ? 8 : 6 ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** SUBTABLE VALIDATORS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* ============================= format 0 ============================== */ static void gxv_kern_subtable_fmt0_pairs_validate( FT_Bytes table, FT_Bytes limit, FT_UShort nPairs, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort i; FT_UShort last_gid_left = 0; FT_UShort last_gid_right = 0; FT_UNUSED( limit ); GXV_NAME_ENTER( "kern format 0 pairs" ); for ( i = 0; i < nPairs; i++ ) { FT_UShort gid_left; FT_UShort gid_right; #ifdef GXV_LOAD_UNUSED_VARS FT_Short kernValue; #endif /* left */ gid_left = FT_NEXT_USHORT( p ); gxv_glyphid_validate( gid_left, gxvalid ); /* right */ gid_right = FT_NEXT_USHORT( p ); gxv_glyphid_validate( gid_right, gxvalid ); /* Pairs of left and right GIDs must be unique and sorted. */ GXV_TRACE(( "left gid = %u, right gid = %u\n", gid_left, gid_right )); if ( gid_left == last_gid_left ) { if ( last_gid_right < gid_right ) last_gid_right = gid_right; else FT_INVALID_DATA; } else if ( last_gid_left < gid_left ) { last_gid_left = gid_left; last_gid_right = gid_right; } else FT_INVALID_DATA; /* skip the kern value */ #ifdef GXV_LOAD_UNUSED_VARS kernValue = FT_NEXT_SHORT( p ); #else p += 2; #endif } GXV_EXIT; } static void gxv_kern_subtable_fmt0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table + GXV_KERN_SUBTABLE_HEADER_SIZE; FT_UShort nPairs; FT_UShort unitSize; GXV_NAME_ENTER( "kern subtable format 0" ); unitSize = 2 + 2 + 2; nPairs = 0; /* nPairs, searchRange, entrySelector, rangeShift */ GXV_LIMIT_CHECK( 2 + 2 + 2 + 2 ); gxv_BinSrchHeader_validate( p, limit, &unitSize, &nPairs, gxvalid ); p += 2 + 2 + 2 + 2; gxv_kern_subtable_fmt0_pairs_validate( p, limit, nPairs, gxvalid ); GXV_EXIT; } /* ============================= format 1 ============================== */ typedef struct GXV_kern_fmt1_StateOptRec_ { FT_UShort valueTable; FT_UShort valueTable_length; } GXV_kern_fmt1_StateOptRec, *GXV_kern_fmt1_StateOptRecData; static void gxv_kern_subtable_fmt1_valueTable_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_kern_fmt1_StateOptRecData optdata = (GXV_kern_fmt1_StateOptRecData)gxvalid->statetable.optdata; GXV_LIMIT_CHECK( 2 ); optdata->valueTable = FT_NEXT_USHORT( p ); } /* * passed tables_size covers whole StateTable, including kern fmt1 header */ static void gxv_kern_subtable_fmt1_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ) { FT_UShort o[4]; FT_UShort *l[4]; FT_UShort buff[5]; GXV_kern_fmt1_StateOptRecData optdata = (GXV_kern_fmt1_StateOptRecData)gxvalid->statetable.optdata; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->valueTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &(optdata->valueTable_length); gxv_set_length_by_ushort_offset( o, l, buff, 4, table_size, gxvalid ); } /* * passed table & limit are of whole StateTable, not including subtables */ static void gxv_kern_subtable_fmt1_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_UShort push; FT_UShort dontAdvance; #endif FT_UShort valueOffset; #ifdef GXV_LOAD_UNUSED_VARS FT_UShort kernAction; FT_UShort kernValue; #endif FT_UNUSED( state ); FT_UNUSED( glyphOffset_p ); #ifdef GXV_LOAD_UNUSED_VARS push = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); #endif valueOffset = (FT_UShort)( flags & 0x3FFF ); { GXV_kern_fmt1_StateOptRecData vt_rec = (GXV_kern_fmt1_StateOptRecData)gxvalid->statetable.optdata; FT_Bytes p; if ( valueOffset < vt_rec->valueTable ) FT_INVALID_OFFSET; p = table + valueOffset; limit = table + vt_rec->valueTable + vt_rec->valueTable_length; GXV_LIMIT_CHECK( 2 + 2 ); #ifdef GXV_LOAD_UNUSED_VARS kernAction = FT_NEXT_USHORT( p ); kernValue = FT_NEXT_USHORT( p ); #endif } } static void gxv_kern_subtable_fmt1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_kern_fmt1_StateOptRec vt_rec; GXV_NAME_ENTER( "kern subtable format 1" ); gxvalid->statetable.optdata = &vt_rec; gxvalid->statetable.optdata_load_func = gxv_kern_subtable_fmt1_valueTable_load; gxvalid->statetable.subtable_setup_func = gxv_kern_subtable_fmt1_subtable_setup; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; gxvalid->statetable.entry_validate_func = gxv_kern_subtable_fmt1_entry_validate; gxv_StateTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* ================ Data for Class-Based Subtables 2, 3 ================ */ typedef enum GXV_kern_ClassSpec_ { GXV_KERN_CLS_L = 0, GXV_KERN_CLS_R } GXV_kern_ClassSpec; /* ============================= format 2 ============================== */ /* ---------------------- format 2 specific data ----------------------- */ typedef struct GXV_kern_subtable_fmt2_DataRec_ { FT_UShort rowWidth; FT_UShort array; FT_UShort offset_min[2]; FT_UShort offset_max[2]; const FT_String* class_tag[2]; GXV_odtect_Range odtect; } GXV_kern_subtable_fmt2_DataRec, *GXV_kern_subtable_fmt2_Data; #define GXV_KERN_FMT2_DATA( field ) \ ( ( (GXV_kern_subtable_fmt2_DataRec *) \ ( GXV_KERN_DATA( subtable_data ) ) )->field ) /* -------------------------- utility functions ----------------------- */ static void gxv_kern_subtable_fmt2_clstbl_validate( FT_Bytes table, FT_Bytes limit, GXV_kern_ClassSpec spec, GXV_Validator gxvalid ) { const FT_String* tag = GXV_KERN_FMT2_DATA( class_tag[spec] ); GXV_odtect_Range odtect = GXV_KERN_FMT2_DATA( odtect ); FT_Bytes p = table; FT_UShort firstGlyph; FT_UShort nGlyphs; GXV_NAME_ENTER( "kern format 2 classTable" ); GXV_LIMIT_CHECK( 2 + 2 ); firstGlyph = FT_NEXT_USHORT( p ); nGlyphs = FT_NEXT_USHORT( p ); GXV_TRACE(( " %s firstGlyph=%d, nGlyphs=%d\n", tag, firstGlyph, nGlyphs )); gxv_glyphid_validate( firstGlyph, gxvalid ); gxv_glyphid_validate( (FT_UShort)( firstGlyph + nGlyphs - 1 ), gxvalid ); gxv_array_getlimits_ushort( p, p + ( 2 * nGlyphs ), &( GXV_KERN_FMT2_DATA( offset_min[spec] ) ), &( GXV_KERN_FMT2_DATA( offset_max[spec] ) ), gxvalid ); gxv_odtect_add_range( table, 2 * nGlyphs, tag, odtect ); GXV_EXIT; } static void gxv_kern_subtable_fmt2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { GXV_ODTECT( 3, odtect ); GXV_kern_subtable_fmt2_DataRec fmt2_rec = { 0, 0, { 0, 0 }, { 0, 0 }, { "leftClass", "rightClass" }, NULL }; FT_Bytes p = table + GXV_KERN_SUBTABLE_HEADER_SIZE; FT_UShort leftOffsetTable; FT_UShort rightOffsetTable; GXV_NAME_ENTER( "kern subtable format 2" ); GXV_ODTECT_INIT( odtect ); fmt2_rec.odtect = odtect; GXV_KERN_DATA( subtable_data ) = &fmt2_rec; GXV_LIMIT_CHECK( 2 + 2 + 2 + 2 ); GXV_KERN_FMT2_DATA( rowWidth ) = FT_NEXT_USHORT( p ); leftOffsetTable = FT_NEXT_USHORT( p ); rightOffsetTable = FT_NEXT_USHORT( p ); GXV_KERN_FMT2_DATA( array ) = FT_NEXT_USHORT( p ); GXV_TRACE(( "rowWidth = %d\n", GXV_KERN_FMT2_DATA( rowWidth ) )); GXV_LIMIT_CHECK( leftOffsetTable ); GXV_LIMIT_CHECK( rightOffsetTable ); GXV_LIMIT_CHECK( GXV_KERN_FMT2_DATA( array ) ); gxv_kern_subtable_fmt2_clstbl_validate( table + leftOffsetTable, limit, GXV_KERN_CLS_L, gxvalid ); gxv_kern_subtable_fmt2_clstbl_validate( table + rightOffsetTable, limit, GXV_KERN_CLS_R, gxvalid ); if ( GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_L] ) + GXV_KERN_FMT2_DATA( offset_min[GXV_KERN_CLS_R] ) < GXV_KERN_FMT2_DATA( array ) ) FT_INVALID_OFFSET; gxv_odtect_add_range( table + GXV_KERN_FMT2_DATA( array ), GXV_KERN_FMT2_DATA( offset_max[GXV_KERN_CLS_L] ) + GXV_KERN_FMT2_DATA( offset_max[GXV_KERN_CLS_R] ) - GXV_KERN_FMT2_DATA( array ), "array", odtect ); gxv_odtect_validate( odtect, gxvalid ); GXV_EXIT; } /* ============================= format 3 ============================== */ static void gxv_kern_subtable_fmt3_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table + GXV_KERN_SUBTABLE_HEADER_SIZE; FT_UShort glyphCount; FT_Byte kernValueCount; FT_Byte leftClassCount; FT_Byte rightClassCount; FT_Byte flags; GXV_NAME_ENTER( "kern subtable format 3" ); GXV_LIMIT_CHECK( 2 + 1 + 1 + 1 + 1 ); glyphCount = FT_NEXT_USHORT( p ); kernValueCount = FT_NEXT_BYTE( p ); leftClassCount = FT_NEXT_BYTE( p ); rightClassCount = FT_NEXT_BYTE( p ); flags = FT_NEXT_BYTE( p ); if ( gxvalid->face->num_glyphs != glyphCount ) { GXV_TRACE(( "maxGID=%ld, but glyphCount=%d\n", gxvalid->face->num_glyphs, glyphCount )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } if ( flags != 0 ) GXV_TRACE(( "kern subtable fmt3 has nonzero value" " (%d) in unused flag\n", flags )); /* * just skip kernValue[kernValueCount] */ GXV_LIMIT_CHECK( 2 * kernValueCount ); p += 2 * kernValueCount; /* * check leftClass[gid] < leftClassCount */ { FT_Byte min, max; GXV_LIMIT_CHECK( glyphCount ); gxv_array_getlimits_byte( p, p + glyphCount, &min, &max, gxvalid ); p += gxvalid->subtable_length; if ( leftClassCount < max ) FT_INVALID_DATA; } /* * check rightClass[gid] < rightClassCount */ { FT_Byte min, max; GXV_LIMIT_CHECK( glyphCount ); gxv_array_getlimits_byte( p, p + glyphCount, &min, &max, gxvalid ); p += gxvalid->subtable_length; if ( rightClassCount < max ) FT_INVALID_DATA; } /* * check kernIndex[i, j] < kernValueCount */ { FT_UShort i, j; for ( i = 0; i < leftClassCount; i++ ) { for ( j = 0; j < rightClassCount; j++ ) { GXV_LIMIT_CHECK( 1 ); if ( kernValueCount < FT_NEXT_BYTE( p ) ) FT_INVALID_OFFSET; } } } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static FT_Bool gxv_kern_coverage_new_apple_validate( FT_UShort coverage, FT_UShort* format, GXV_Validator gxvalid ) { /* new Apple-dialect */ #ifdef GXV_LOAD_TRACE_VARS FT_Bool kernVertical; FT_Bool kernCrossStream; FT_Bool kernVariation; #endif FT_UNUSED( gxvalid ); /* reserved bits = 0 */ if ( coverage & 0x1FFC ) return FALSE; #ifdef GXV_LOAD_TRACE_VARS kernVertical = FT_BOOL( ( coverage >> 15 ) & 1 ); kernCrossStream = FT_BOOL( ( coverage >> 14 ) & 1 ); kernVariation = FT_BOOL( ( coverage >> 13 ) & 1 ); #endif *format = (FT_UShort)( coverage & 0x0003 ); GXV_TRACE(( "new Apple-dialect: " "horizontal=%d, cross-stream=%d, variation=%d, format=%d\n", !kernVertical, kernCrossStream, kernVariation, *format )); GXV_TRACE(( "kerning values in Apple format subtable are ignored\n" )); return TRUE; } static FT_Bool gxv_kern_coverage_classic_apple_validate( FT_UShort coverage, FT_UShort* format, GXV_Validator gxvalid ) { /* classic Apple-dialect */ #ifdef GXV_LOAD_TRACE_VARS FT_Bool horizontal; FT_Bool cross_stream; #endif /* check expected flags, but don't check if MS-dialect is impossible */ if ( !( coverage & 0xFD00 ) && KERN_ALLOWS_MS( gxvalid ) ) return FALSE; /* reserved bits = 0 */ if ( coverage & 0x02FC ) return FALSE; #ifdef GXV_LOAD_TRACE_VARS horizontal = FT_BOOL( ( coverage >> 15 ) & 1 ); cross_stream = FT_BOOL( ( coverage >> 13 ) & 1 ); #endif *format = (FT_UShort)( coverage & 0x0003 ); GXV_TRACE(( "classic Apple-dialect: " "horizontal=%d, cross-stream=%d, format=%d\n", horizontal, cross_stream, *format )); /* format 1 requires GX State Machine, too new for classic */ if ( *format == 1 ) return FALSE; GXV_TRACE(( "kerning values in Apple format subtable are ignored\n" )); return TRUE; } static FT_Bool gxv_kern_coverage_classic_microsoft_validate( FT_UShort coverage, FT_UShort* format, GXV_Validator gxvalid ) { /* classic Microsoft-dialect */ #ifdef GXV_LOAD_TRACE_VARS FT_Bool horizontal; FT_Bool minimum; FT_Bool cross_stream; FT_Bool override; #endif FT_UNUSED( gxvalid ); /* reserved bits = 0 */ if ( coverage & 0xFDF0 ) return FALSE; #ifdef GXV_LOAD_TRACE_VARS horizontal = FT_BOOL( coverage & 1 ); minimum = FT_BOOL( ( coverage >> 1 ) & 1 ); cross_stream = FT_BOOL( ( coverage >> 2 ) & 1 ); override = FT_BOOL( ( coverage >> 3 ) & 1 ); #endif *format = (FT_UShort)( ( coverage >> 8 ) & 0x0003 ); GXV_TRACE(( "classic Microsoft-dialect: " "horizontal=%d, minimum=%d, cross-stream=%d, " "override=%d, format=%d\n", horizontal, minimum, cross_stream, override, *format )); if ( *format == 2 ) GXV_TRACE(( "kerning values in Microsoft format 2 subtable are ignored\n" )); return TRUE; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** MAIN *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static GXV_kern_Dialect gxv_kern_coverage_validate( FT_UShort coverage, FT_UShort* format, GXV_Validator gxvalid ) { GXV_kern_Dialect result = KERN_DIALECT_UNKNOWN; GXV_NAME_ENTER( "validating coverage" ); GXV_TRACE(( "interpret coverage 0x%04x by Apple style\n", coverage )); if ( KERN_IS_NEW( gxvalid ) ) { if ( gxv_kern_coverage_new_apple_validate( coverage, format, gxvalid ) ) { result = KERN_DIALECT_APPLE; goto Exit; } } if ( KERN_IS_CLASSIC( gxvalid ) && KERN_ALLOWS_APPLE( gxvalid ) ) { if ( gxv_kern_coverage_classic_apple_validate( coverage, format, gxvalid ) ) { result = KERN_DIALECT_APPLE; goto Exit; } } if ( KERN_IS_CLASSIC( gxvalid ) && KERN_ALLOWS_MS( gxvalid ) ) { if ( gxv_kern_coverage_classic_microsoft_validate( coverage, format, gxvalid ) ) { result = KERN_DIALECT_MS; goto Exit; } } GXV_TRACE(( "cannot interpret coverage, broken kern subtable\n" )); Exit: GXV_EXIT; return result; } static void gxv_kern_subtable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; #ifdef GXV_LOAD_TRACE_VARS FT_UShort version = 0; /* MS only: subtable version, unused */ #endif FT_ULong length; /* MS: 16bit, Apple: 32bit */ FT_UShort coverage; #ifdef GXV_LOAD_TRACE_VARS FT_UShort tupleIndex = 0; /* Apple only */ #endif FT_UShort u16[2]; FT_UShort format = 255; /* subtable format */ GXV_NAME_ENTER( "kern subtable" ); GXV_LIMIT_CHECK( 2 + 2 + 2 ); u16[0] = FT_NEXT_USHORT( p ); /* Apple: length_hi MS: version */ u16[1] = FT_NEXT_USHORT( p ); /* Apple: length_lo MS: length */ coverage = FT_NEXT_USHORT( p ); switch ( gxv_kern_coverage_validate( coverage, &format, gxvalid ) ) { case KERN_DIALECT_MS: #ifdef GXV_LOAD_TRACE_VARS version = u16[0]; #endif length = u16[1]; #ifdef GXV_LOAD_TRACE_VARS tupleIndex = 0; #endif GXV_TRACE(( "Subtable version = %d\n", version )); GXV_TRACE(( "Subtable length = %lu\n", length )); break; case KERN_DIALECT_APPLE: #ifdef GXV_LOAD_TRACE_VARS version = 0; #endif length = ( (FT_ULong)u16[0] << 16 ) + u16[1]; #ifdef GXV_LOAD_TRACE_VARS tupleIndex = 0; #endif GXV_TRACE(( "Subtable length = %lu\n", length )); if ( KERN_IS_NEW( gxvalid ) ) { GXV_LIMIT_CHECK( 2 ); #ifdef GXV_LOAD_TRACE_VARS tupleIndex = FT_NEXT_USHORT( p ); #else p += 2; #endif GXV_TRACE(( "Subtable tupleIndex = %d\n", tupleIndex )); } break; default: length = u16[1]; GXV_TRACE(( "cannot detect subtable dialect, " "just skip %lu byte\n", length )); goto Exit; } /* formats 1, 2, 3 require the position of the start of this subtable */ if ( format == 0 ) gxv_kern_subtable_fmt0_validate( table, table + length, gxvalid ); else if ( format == 1 ) gxv_kern_subtable_fmt1_validate( table, table + length, gxvalid ); else if ( format == 2 ) gxv_kern_subtable_fmt2_validate( table, table + length, gxvalid ); else if ( format == 3 ) gxv_kern_subtable_fmt3_validate( table, table + length, gxvalid ); else FT_INVALID_DATA; Exit: gxvalid->subtable_length = length; GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** kern TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_kern_validate_generic( FT_Bytes table, FT_Face face, FT_Bool classic_only, GXV_kern_Dialect dialect_request, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_kern_DataRec kernrec; GXV_kern_Data kern = &kernrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_ULong nTables = 0; FT_UInt i; gxvalid->root = ftvalid; gxvalid->table_data = kern; gxvalid->face = face; FT_TRACE3(( "validating `kern' table\n" )); GXV_INIT; KERN_DIALECT( gxvalid ) = dialect_request; GXV_LIMIT_CHECK( 2 ); GXV_KERN_DATA( version ) = (GXV_kern_Version)FT_NEXT_USHORT( p ); GXV_TRACE(( "version 0x%04x (higher 16bit)\n", GXV_KERN_DATA( version ) )); if ( 0x0001 < GXV_KERN_DATA( version ) ) FT_INVALID_FORMAT; else if ( KERN_IS_CLASSIC( gxvalid ) ) { GXV_LIMIT_CHECK( 2 ); nTables = FT_NEXT_USHORT( p ); } else if ( KERN_IS_NEW( gxvalid ) ) { if ( classic_only ) FT_INVALID_FORMAT; if ( 0x0000 != FT_NEXT_USHORT( p ) ) FT_INVALID_FORMAT; GXV_LIMIT_CHECK( 4 ); nTables = FT_NEXT_ULONG( p ); } for ( i = 0; i < nTables; i++ ) { GXV_TRACE(( "validating subtable %d/%lu\n", i, nTables )); /* p should be 32bit-aligned? */ gxv_kern_subtable_validate( p, 0, gxvalid ); p += gxvalid->subtable_length; } FT_TRACE4(( "\n" )); } FT_LOCAL_DEF( void ) gxv_kern_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { gxv_kern_validate_generic( table, face, 0, KERN_DIALECT_ANY, ftvalid ); } FT_LOCAL_DEF( void ) gxv_kern_validate_classic( FT_Bytes table, FT_Face face, FT_Int dialect_flags, FT_Validator ftvalid ) { GXV_kern_Dialect dialect_request; dialect_request = (GXV_kern_Dialect)dialect_flags; gxv_kern_validate_generic( table, face, 1, dialect_request, ftvalid ); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvkern.c
C++
gpl-3.0
27,203
/**************************************************************************** * * gxvlcar.c * * TrueTypeGX/AAT lcar table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.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 gxvlcar /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_lcar_DataRec_ { FT_UShort format; } GXV_lcar_DataRec, *GXV_lcar_Data; #define GXV_LCAR_DATA( FIELD ) GXV_TABLE_DATA( lcar, FIELD ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_lcar_partial_validate( FT_Short partial, FT_UShort glyph, GXV_Validator gxvalid ) { GXV_NAME_ENTER( "partial" ); if ( GXV_LCAR_DATA( format ) != 1 ) goto Exit; gxv_ctlPoint_validate( glyph, (FT_UShort)partial, gxvalid ); Exit: GXV_EXIT; } static void gxv_lcar_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_Bytes p = gxvalid->root->base + value_p->u; FT_Bytes limit = gxvalid->root->limit; FT_UShort count; FT_Short partial; FT_UShort i; GXV_NAME_ENTER( "element in lookupTable" ); GXV_LIMIT_CHECK( 2 ); count = FT_NEXT_USHORT( p ); GXV_LIMIT_CHECK( 2 * count ); for ( i = 0; i < count; i++ ) { partial = FT_NEXT_SHORT( p ); gxv_lcar_partial_validate( partial, glyph, gxvalid ); } GXV_EXIT; } /* +------ lcar --------------------+ | | | +===============+ | | | lookup header | | | +===============+ | | | BinSrchHeader | | | +===============+ | | | lastGlyph[0] | | | +---------------+ | | | firstGlyph[0] | | head of lcar sfnt table | +---------------+ | + | | offset[0] | -> | offset [byte] | +===============+ | + | | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] | +---------------+ | | | firstGlyph[1] | | | +---------------+ | | | offset[1] | | | +===============+ | | | | .... | | | | 16bit value array | | +===============+ | +------| value | <-------+ | .... | | | | | +----> lcar values...handled by lcar callback function */ static GXV_LookupValueDesc gxv_lcar_LookupFmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; FT_UNUSED( lookuptbl_limit ); /* XXX: check range? */ offset = (FT_UShort)( base_value_p->u + relative_gindex * sizeof ( FT_UShort ) ); p = gxvalid->root->base + offset; limit = gxvalid->root->limit; GXV_LIMIT_CHECK ( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** lcar TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_lcar_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { FT_Bytes p = table; FT_Bytes limit = 0; GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_lcar_DataRec lcarrec; GXV_lcar_Data lcar = &lcarrec; FT_Fixed version; gxvalid->root = ftvalid; gxvalid->table_data = lcar; gxvalid->face = face; FT_TRACE3(( "validating `lcar' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 2 ); version = FT_NEXT_LONG( p ); GXV_LCAR_DATA( format ) = FT_NEXT_USHORT( p ); if ( version != 0x00010000UL) FT_INVALID_FORMAT; if ( GXV_LCAR_DATA( format ) > 1 ) FT_INVALID_FORMAT; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_lcar_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_lcar_LookupFmt4_transit; gxv_LookupTable_validate( p, limit, gxvalid ); FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvlcar.c
C++
gpl-3.0
7,139
/**************************************************************************** * * gxvmod.c * * FreeType's TrueTypeGX/AAT validation module implementation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include <freetype/tttables.h> #include <freetype/tttags.h> #include <freetype/ftgxval.h> #include <freetype/internal/ftobjs.h> #include <freetype/internal/services/svgxval.h> #include "gxvmod.h" #include "gxvalid.h" #include "gxvcommn.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 gxvmodule static FT_Error gxv_load_table( FT_Face face, FT_Tag tag, FT_Byte* volatile* table, FT_ULong* table_len ) { FT_Error error; FT_Memory memory = FT_FACE_MEMORY( face ); error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len ); if ( FT_ERR_EQ( error, Table_Missing ) ) return FT_Err_Ok; if ( error ) goto Exit; if ( FT_QALLOC( *table, *table_len ) ) goto Exit; error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len ); Exit: return error; } #define GXV_TABLE_DECL( _sfnt ) \ FT_Byte* volatile _sfnt = NULL; \ FT_ULong len_ ## _sfnt = 0 #define GXV_TABLE_LOAD( _sfnt ) \ FT_BEGIN_STMNT \ if ( ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) && \ ( gx_flags & FT_VALIDATE_ ## _sfnt ) ) \ { \ error = gxv_load_table( face, TTAG_ ## _sfnt, \ &_sfnt, &len_ ## _sfnt ); \ if ( error ) \ goto Exit; \ } \ FT_END_STMNT #define GXV_TABLE_VALIDATE( _sfnt ) \ FT_BEGIN_STMNT \ if ( _sfnt ) \ { \ ft_validator_init( &valid, _sfnt, _sfnt + len_ ## _sfnt, \ FT_VALIDATE_DEFAULT ); \ if ( ft_setjmp( valid.jump_buffer ) == 0 ) \ gxv_ ## _sfnt ## _validate( _sfnt, face, &valid ); \ error = valid.error; \ if ( error ) \ goto Exit; \ } \ FT_END_STMNT #define GXV_TABLE_SET( _sfnt ) \ if ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) \ tables[FT_VALIDATE_ ## _sfnt ## _INDEX] = (FT_Bytes)_sfnt static FT_Error gxv_validate( FT_Face face, FT_UInt gx_flags, FT_Bytes tables[FT_VALIDATE_GX_LENGTH], FT_UInt table_count ) { FT_Memory volatile memory = FT_FACE_MEMORY( face ); FT_Error error = FT_Err_Ok; FT_ValidatorRec volatile valid; FT_UInt i; GXV_TABLE_DECL( feat ); GXV_TABLE_DECL( bsln ); GXV_TABLE_DECL( trak ); GXV_TABLE_DECL( just ); GXV_TABLE_DECL( mort ); GXV_TABLE_DECL( morx ); GXV_TABLE_DECL( kern ); GXV_TABLE_DECL( opbd ); GXV_TABLE_DECL( prop ); GXV_TABLE_DECL( lcar ); for ( i = 0; i < table_count; i++ ) tables[i] = 0; /* load tables */ GXV_TABLE_LOAD( feat ); GXV_TABLE_LOAD( bsln ); GXV_TABLE_LOAD( trak ); GXV_TABLE_LOAD( just ); GXV_TABLE_LOAD( mort ); GXV_TABLE_LOAD( morx ); GXV_TABLE_LOAD( kern ); GXV_TABLE_LOAD( opbd ); GXV_TABLE_LOAD( prop ); GXV_TABLE_LOAD( lcar ); /* validate tables */ GXV_TABLE_VALIDATE( feat ); GXV_TABLE_VALIDATE( bsln ); GXV_TABLE_VALIDATE( trak ); GXV_TABLE_VALIDATE( just ); GXV_TABLE_VALIDATE( mort ); GXV_TABLE_VALIDATE( morx ); GXV_TABLE_VALIDATE( kern ); GXV_TABLE_VALIDATE( opbd ); GXV_TABLE_VALIDATE( prop ); GXV_TABLE_VALIDATE( lcar ); /* Set results */ GXV_TABLE_SET( feat ); GXV_TABLE_SET( mort ); GXV_TABLE_SET( morx ); GXV_TABLE_SET( bsln ); GXV_TABLE_SET( just ); GXV_TABLE_SET( kern ); GXV_TABLE_SET( opbd ); GXV_TABLE_SET( trak ); GXV_TABLE_SET( prop ); GXV_TABLE_SET( lcar ); Exit: if ( error ) { FT_FREE( feat ); FT_FREE( bsln ); FT_FREE( trak ); FT_FREE( just ); FT_FREE( mort ); FT_FREE( morx ); FT_FREE( kern ); FT_FREE( opbd ); FT_FREE( prop ); FT_FREE( lcar ); } return error; } static FT_Error classic_kern_validate( FT_Face face, FT_UInt ckern_flags, FT_Bytes* ckern_table ) { FT_Memory volatile memory = FT_FACE_MEMORY( face ); FT_Byte* volatile ckern = NULL; FT_ULong len_ckern = 0; /* without volatile on `error' GCC 4.1.1. emits: */ /* warning: variable 'error' might be clobbered by 'longjmp' or 'vfork' */ /* this warning seems spurious but --- */ FT_Error volatile error; FT_ValidatorRec volatile valid; *ckern_table = NULL; error = gxv_load_table( face, TTAG_kern, &ckern, &len_ckern ); if ( error ) goto Exit; if ( ckern ) { ft_validator_init( &valid, ckern, ckern + len_ckern, FT_VALIDATE_DEFAULT ); if ( ft_setjmp( valid.jump_buffer ) == 0 ) gxv_kern_validate_classic( ckern, face, ckern_flags & FT_VALIDATE_CKERN, &valid ); error = valid.error; if ( error ) goto Exit; } *ckern_table = ckern; Exit: if ( error ) FT_FREE( ckern ); return error; } static const FT_Service_GXvalidateRec gxvalid_interface = { gxv_validate /* validate */ }; static const FT_Service_CKERNvalidateRec ckernvalid_interface = { classic_kern_validate /* validate */ }; static const FT_ServiceDescRec gxvalid_services[] = { { FT_SERVICE_ID_GX_VALIDATE, &gxvalid_interface }, { FT_SERVICE_ID_CLASSICKERN_VALIDATE, &ckernvalid_interface }, { NULL, NULL } }; static FT_Pointer gxvalid_get_service( FT_Module module, const char* service_id ) { FT_UNUSED( module ); return ft_service_list_lookup( gxvalid_services, service_id ); } FT_CALLBACK_TABLE_DEF const FT_Module_Class gxv_module_class = { 0, sizeof ( FT_ModuleRec ), "gxvalid", 0x10000L, 0x20000L, NULL, /* module-specific interface */ (FT_Module_Constructor)NULL, /* module_init */ (FT_Module_Destructor) NULL, /* module_done */ (FT_Module_Requester) gxvalid_get_service /* get_interface */ }; /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmod.c
C++
gpl-3.0
8,348
/**************************************************************************** * * gxvmod.h * * FreeType's TrueTypeGX/AAT validation module implementation * (specification). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #ifndef GXVMOD_H_ #define GXVMOD_H_ #include <freetype/ftmodapi.h> FT_BEGIN_HEADER FT_EXPORT_VAR( const FT_Module_Class ) gxv_module_class; FT_END_HEADER #endif /* GXVMOD_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmod.h
C++
gpl-3.0
1,093
/**************************************************************************** * * gxvmort.c * * TrueTypeGX/AAT mort table validation (body). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.h" #include "gxvfeat.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 gxvmort static void gxv_mort_feature_validate( GXV_mort_feature f, GXV_Validator gxvalid ) { if ( f->featureType >= gxv_feat_registry_length ) { GXV_TRACE(( "featureType %d is out of registered range, " "setting %d is unchecked\n", f->featureType, f->featureSetting )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } else if ( !gxv_feat_registry[f->featureType].existence ) { GXV_TRACE(( "featureType %d is within registered area " "but undefined, setting %d is unchecked\n", f->featureType, f->featureSetting )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } else { FT_Byte nSettings_max; /* nSettings in gxvfeat.c is halved for exclusive on/off settings */ nSettings_max = gxv_feat_registry[f->featureType].nSettings; if ( gxv_feat_registry[f->featureType].exclusive ) nSettings_max = (FT_Byte)( 2 * nSettings_max ); GXV_TRACE(( "featureType %d is registered", f->featureType )); GXV_TRACE(( "setting %d", f->featureSetting )); if ( f->featureSetting > nSettings_max ) { GXV_TRACE(( "out of defined range %d", nSettings_max )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } GXV_TRACE(( "\n" )); } /* TODO: enableFlags must be unique value in specified chain? */ } /* * nFeatureFlags is typed to FT_ULong to accept that in * mort (typed FT_UShort) and morx (typed FT_ULong). */ FT_LOCAL_DEF( void ) gxv_mort_featurearray_validate( FT_Bytes table, FT_Bytes limit, FT_ULong nFeatureFlags, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_ULong i; GXV_mort_featureRec f = GXV_MORT_FEATURE_OFF; GXV_NAME_ENTER( "mort feature list" ); for ( i = 0; i < nFeatureFlags; i++ ) { GXV_LIMIT_CHECK( 2 + 2 + 4 + 4 ); f.featureType = FT_NEXT_USHORT( p ); f.featureSetting = FT_NEXT_USHORT( p ); f.enableFlags = FT_NEXT_ULONG( p ); f.disableFlags = FT_NEXT_ULONG( p ); gxv_mort_feature_validate( &f, gxvalid ); } if ( !IS_GXV_MORT_FEATURE_OFF( f ) ) FT_INVALID_DATA; gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_mort_coverage_validate( FT_UShort coverage, GXV_Validator gxvalid ) { FT_UNUSED( gxvalid ); FT_UNUSED( coverage ); #ifdef FT_DEBUG_LEVEL_TRACE if ( coverage & 0x8000U ) GXV_TRACE(( " this subtable is for vertical text only\n" )); else GXV_TRACE(( " this subtable is for horizontal text only\n" )); if ( coverage & 0x4000 ) GXV_TRACE(( " this subtable is applied to glyph array " "in descending order\n" )); else GXV_TRACE(( " this subtable is applied to glyph array " "in ascending order\n" )); if ( coverage & 0x2000 ) GXV_TRACE(( " this subtable is forcibly applied to " "vertical/horizontal text\n" )); if ( coverage & 0x1FF8 ) GXV_TRACE(( " coverage has non-zero bits in reserved area\n" )); #endif } static void gxv_mort_subtables_validate( FT_Bytes table, FT_Bytes limit, FT_UShort nSubtables, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_Validate_Func fmt_funcs_table[] = { gxv_mort_subtable_type0_validate, /* 0 */ gxv_mort_subtable_type1_validate, /* 1 */ gxv_mort_subtable_type2_validate, /* 2 */ NULL, /* 3 */ gxv_mort_subtable_type4_validate, /* 4 */ gxv_mort_subtable_type5_validate, /* 5 */ }; FT_UShort i; GXV_NAME_ENTER( "subtables in a chain" ); for ( i = 0; i < nSubtables; i++ ) { GXV_Validate_Func func; FT_UShort length; FT_UShort coverage; #ifdef GXV_LOAD_UNUSED_VARS FT_ULong subFeatureFlags; #endif FT_UInt type; FT_UInt rest; GXV_LIMIT_CHECK( 2 + 2 + 4 ); length = FT_NEXT_USHORT( p ); coverage = FT_NEXT_USHORT( p ); #ifdef GXV_LOAD_UNUSED_VARS subFeatureFlags = FT_NEXT_ULONG( p ); #else p += 4; #endif GXV_TRACE(( "validating chain subtable %d/%d (%d bytes)\n", i + 1, nSubtables, length )); type = coverage & 0x0007; rest = length - ( 2 + 2 + 4 ); GXV_LIMIT_CHECK( rest ); gxv_mort_coverage_validate( coverage, gxvalid ); if ( type > 5 ) FT_INVALID_FORMAT; func = fmt_funcs_table[type]; if ( !func ) GXV_TRACE(( "morx type %d is reserved\n", type )); func( p, p + rest, gxvalid ); p += rest; /* TODO: validate subFeatureFlags */ } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_mort_chain_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; #ifdef GXV_LOAD_UNUSED_VARS FT_ULong defaultFlags; #endif FT_ULong chainLength; FT_UShort nFeatureFlags; FT_UShort nSubtables; GXV_NAME_ENTER( "mort chain header" ); GXV_LIMIT_CHECK( 4 + 4 + 2 + 2 ); #ifdef GXV_LOAD_UNUSED_VARS defaultFlags = FT_NEXT_ULONG( p ); #else p += 4; #endif chainLength = FT_NEXT_ULONG( p ); nFeatureFlags = FT_NEXT_USHORT( p ); nSubtables = FT_NEXT_USHORT( p ); gxv_mort_featurearray_validate( p, table + chainLength, nFeatureFlags, gxvalid ); p += gxvalid->subtable_length; gxv_mort_subtables_validate( p, table + chainLength, nSubtables, gxvalid ); gxvalid->subtable_length = chainLength; /* TODO: validate defaultFlags */ GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_mort_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_ULong version; FT_ULong nChains; FT_ULong i; gxvalid->root = ftvalid; gxvalid->face = face; limit = gxvalid->root->limit; FT_TRACE3(( "validating `mort' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 4 ); version = FT_NEXT_ULONG( p ); nChains = FT_NEXT_ULONG( p ); if (version != 0x00010000UL) FT_INVALID_FORMAT; for ( i = 0; i < nChains; i++ ) { GXV_TRACE(( "validating chain %lu/%lu\n", i + 1, nChains )); GXV_32BIT_ALIGNMENT_VALIDATE( p - table ); gxv_mort_chain_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; } FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort.c
C++
gpl-3.0
8,297
/**************************************************************************** * * gxvmort.h * * TrueTypeGX/AAT common definition for mort table (specification). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #ifndef GXVMORT_H_ #define GXVMORT_H_ #include "gxvalid.h" #include "gxvcommn.h" #include <freetype/ftsnames.h> FT_BEGIN_HEADER typedef struct GXV_mort_featureRec_ { FT_UShort featureType; FT_UShort featureSetting; FT_ULong enableFlags; FT_ULong disableFlags; } GXV_mort_featureRec, *GXV_mort_feature; #define GXV_MORT_FEATURE_OFF {0, 1, 0x00000000UL, 0x00000000UL} #define IS_GXV_MORT_FEATURE_OFF( f ) \ ( (f).featureType == 0 || \ (f).featureSetting == 1 || \ (f).enableFlags == 0x00000000UL || \ (f).disableFlags == 0x00000000UL ) FT_LOCAL( void ) gxv_mort_featurearray_validate( FT_Bytes table, FT_Bytes limit, FT_ULong nFeatureFlags, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_coverage_validate( FT_UShort coverage, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_subtable_type0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_subtable_type1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_subtable_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_subtable_type4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_mort_subtable_type5_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_END_HEADER #endif /* GXVMORT_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort.h
C++
gpl-3.0
2,971
/**************************************************************************** * * gxvmort0.c * * TrueTypeGX/AAT mort table validation * body for type0 (Indic Script Rearrangement) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.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 gxvmort static const char* GXV_Mort_IndicScript_Msg[] = { "no change", "Ax => xA", "xD => Dx", "AxD => DxA", "ABx => xAB", "ABx => xBA", "xCD => CDx", "xCD => DCx", "AxCD => CDxA", "AxCD => DCxA", "ABxD => DxAB", "ABxD => DxBA", "ABxCD => CDxAB", "ABxCD => CDxBA", "ABxCD => DCxAB", "ABxCD => DCxBA", }; static void gxv_mort_subtable_type0_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_UShort markFirst; FT_UShort dontAdvance; FT_UShort markLast; FT_UShort reserved; FT_UShort verb = 0; FT_UNUSED( state ); FT_UNUSED( table ); FT_UNUSED( limit ); FT_UNUSED( GXV_Mort_IndicScript_Msg[verb] ); /* for the non-debugging */ FT_UNUSED( glyphOffset_p ); /* case */ markFirst = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); markLast = (FT_UShort)( ( flags >> 13 ) & 1 ); reserved = (FT_UShort)( flags & 0x1FF0 ); verb = (FT_UShort)( flags & 0x000F ); GXV_TRACE(( " IndicScript MorphRule for glyphOffset 0x%04x", glyphOffset_p->u )); GXV_TRACE(( " markFirst=%01d", markFirst )); GXV_TRACE(( " dontAdvance=%01d", dontAdvance )); GXV_TRACE(( " markLast=%01d", markLast )); GXV_TRACE(( " %02d", verb )); GXV_TRACE(( " %s\n", GXV_Mort_IndicScript_Msg[verb] )); if ( markFirst > 0 && markLast > 0 ) { GXV_TRACE(( " [odd] a glyph is marked as the first and last" " in Indic rearrangement\n" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } if ( markFirst > 0 && dontAdvance > 0 ) { GXV_TRACE(( " [odd] the first glyph is marked as dontAdvance" " in Indic rearrangement\n" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } if ( 0 < reserved ) { GXV_TRACE(( " non-zero bits found in reserved range\n" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } else GXV_TRACE(( "\n" )); } FT_LOCAL_DEF( void ) gxv_mort_subtable_type0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_NAME_ENTER( "mort chain subtable type0 (Indic-Script Rearrangement)" ); GXV_LIMIT_CHECK( GXV_STATETABLE_HEADER_SIZE ); gxvalid->statetable.optdata = NULL; gxvalid->statetable.optdata_load_func = NULL; gxvalid->statetable.subtable_setup_func = NULL; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; gxvalid->statetable.entry_validate_func = gxv_mort_subtable_type0_entry_validate; gxv_StateTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort0.c
C++
gpl-3.0
4,329
/**************************************************************************** * * gxvmort1.c * * TrueTypeGX/AAT mort table validation * body for type1 (Contextual Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.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 gxvmort typedef struct GXV_mort_subtable_type1_StateOptRec_ { FT_UShort substitutionTable; FT_UShort substitutionTable_length; } GXV_mort_subtable_type1_StateOptRec, *GXV_mort_subtable_type1_StateOptRecData; #define GXV_MORT_SUBTABLE_TYPE1_HEADER_SIZE \ ( GXV_STATETABLE_HEADER_SIZE + 2 ) static void gxv_mort_subtable_type1_substitutionTable_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_mort_subtable_type1_StateOptRecData optdata = (GXV_mort_subtable_type1_StateOptRecData)gxvalid->statetable.optdata; GXV_LIMIT_CHECK( 2 ); optdata->substitutionTable = FT_NEXT_USHORT( p ); } static void gxv_mort_subtable_type1_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ) { FT_UShort o[4]; FT_UShort *l[4]; FT_UShort buff[5]; GXV_mort_subtable_type1_StateOptRecData optdata = (GXV_mort_subtable_type1_StateOptRecData)gxvalid->statetable.optdata; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->substitutionTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &( optdata->substitutionTable_length ); gxv_set_length_by_ushort_offset( o, l, buff, 4, table_size, gxvalid ); } static void gxv_mort_subtable_type1_offset_to_subst_validate( FT_Short wordOffset, const FT_String* tag, FT_Byte state, GXV_Validator gxvalid ) { FT_UShort substTable; FT_UShort substTable_limit; FT_UNUSED( tag ); FT_UNUSED( state ); substTable = ((GXV_mort_subtable_type1_StateOptRec *) (gxvalid->statetable.optdata))->substitutionTable; substTable_limit = (FT_UShort)( substTable + ((GXV_mort_subtable_type1_StateOptRec *) (gxvalid->statetable.optdata))->substitutionTable_length ); gxvalid->min_gid = (FT_UShort)( ( substTable - wordOffset * 2 ) / 2 ); gxvalid->max_gid = (FT_UShort)( ( substTable_limit - wordOffset * 2 ) / 2 ); gxvalid->max_gid = (FT_UShort)( FT_MAX( gxvalid->max_gid, gxvalid->face->num_glyphs ) ); /* XXX: check range? */ /* TODO: min_gid & max_gid comparison with ClassTable contents */ } static void gxv_mort_subtable_type1_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_UShort setMark; FT_UShort dontAdvance; #endif FT_UShort reserved; FT_Short markOffset; FT_Short currentOffset; FT_UNUSED( table ); FT_UNUSED( limit ); #ifdef GXV_LOAD_UNUSED_VARS setMark = (FT_UShort)( flags >> 15 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); #endif reserved = (FT_UShort)( flags & 0x3FFF ); markOffset = (FT_Short)( glyphOffset_p->ul >> 16 ); currentOffset = (FT_Short)( glyphOffset_p->ul ); if ( 0 < reserved ) { GXV_TRACE(( " non-zero bits found in reserved range\n" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } gxv_mort_subtable_type1_offset_to_subst_validate( markOffset, "markOffset", state, gxvalid ); gxv_mort_subtable_type1_offset_to_subst_validate( currentOffset, "currentOffset", state, gxvalid ); } static void gxv_mort_subtable_type1_substTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort num_gids = (FT_UShort)( ((GXV_mort_subtable_type1_StateOptRec *) (gxvalid->statetable.optdata))->substitutionTable_length / 2 ); FT_UShort i; GXV_NAME_ENTER( "validating contents of substitutionTable" ); for ( i = 0; i < num_gids; i++ ) { FT_UShort dst_gid; GXV_LIMIT_CHECK( 2 ); dst_gid = FT_NEXT_USHORT( p ); if ( dst_gid >= 0xFFFFU ) continue; if ( dst_gid < gxvalid->min_gid || gxvalid->max_gid < dst_gid ) { GXV_TRACE(( "substTable include a strange gid[%d]=%d >" " out of define range (%d..%d)\n", i, dst_gid, gxvalid->min_gid, gxvalid->max_gid )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } } GXV_EXIT; } /* * subtable for Contextual glyph substitution is a modified StateTable. * In addition to classTable, stateArray, and entryTable, the field * `substitutionTable' is added. */ FT_LOCAL_DEF( void ) gxv_mort_subtable_type1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_mort_subtable_type1_StateOptRec st_rec; GXV_NAME_ENTER( "mort chain subtable type1 (Contextual Glyph Subst)" ); GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE1_HEADER_SIZE ); gxvalid->statetable.optdata = &st_rec; gxvalid->statetable.optdata_load_func = gxv_mort_subtable_type1_substitutionTable_load; gxvalid->statetable.subtable_setup_func = gxv_mort_subtable_type1_subtable_setup; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; gxvalid->statetable.entry_validate_func = gxv_mort_subtable_type1_entry_validate; gxv_StateTable_validate( p, limit, gxvalid ); gxv_mort_subtable_type1_substTable_validate( table + st_rec.substitutionTable, table + st_rec.substitutionTable + st_rec.substitutionTable_length, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort1.c
C++
gpl-3.0
8,122
/**************************************************************************** * * gxvmort2.c * * TrueTypeGX/AAT mort table validation * body for type2 (Ligature Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.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 gxvmort typedef struct GXV_mort_subtable_type2_StateOptRec_ { FT_UShort ligActionTable; FT_UShort componentTable; FT_UShort ligatureTable; FT_UShort ligActionTable_length; FT_UShort componentTable_length; FT_UShort ligatureTable_length; } GXV_mort_subtable_type2_StateOptRec, *GXV_mort_subtable_type2_StateOptRecData; #define GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE \ ( GXV_STATETABLE_HEADER_SIZE + 2 + 2 + 2 ) static void gxv_mort_subtable_type2_opttable_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_mort_subtable_type2_StateOptRecData optdata = (GXV_mort_subtable_type2_StateOptRecData)gxvalid->statetable.optdata; GXV_LIMIT_CHECK( 2 + 2 + 2 ); optdata->ligActionTable = FT_NEXT_USHORT( p ); optdata->componentTable = FT_NEXT_USHORT( p ); optdata->ligatureTable = FT_NEXT_USHORT( p ); GXV_TRACE(( "offset to ligActionTable=0x%04x\n", optdata->ligActionTable )); GXV_TRACE(( "offset to componentTable=0x%04x\n", optdata->componentTable )); GXV_TRACE(( "offset to ligatureTable=0x%04x\n", optdata->ligatureTable )); } static void gxv_mort_subtable_type2_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort *classTable_length_p, FT_UShort *stateArray_length_p, FT_UShort *entryTable_length_p, GXV_Validator gxvalid ) { FT_UShort o[6]; FT_UShort *l[6]; FT_UShort buff[7]; GXV_mort_subtable_type2_StateOptRecData optdata = (GXV_mort_subtable_type2_StateOptRecData)gxvalid->statetable.optdata; GXV_NAME_ENTER( "subtable boundaries setup" ); o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->ligActionTable; o[4] = optdata->componentTable; o[5] = optdata->ligatureTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &(optdata->ligActionTable_length); l[4] = &(optdata->componentTable_length); l[5] = &(optdata->ligatureTable_length); gxv_set_length_by_ushort_offset( o, l, buff, 6, table_size, gxvalid ); GXV_TRACE(( "classTable: offset=0x%04x length=0x%04x\n", classTable, *classTable_length_p )); GXV_TRACE(( "stateArray: offset=0x%04x length=0x%04x\n", stateArray, *stateArray_length_p )); GXV_TRACE(( "entryTable: offset=0x%04x length=0x%04x\n", entryTable, *entryTable_length_p )); GXV_TRACE(( "ligActionTable: offset=0x%04x length=0x%04x\n", optdata->ligActionTable, optdata->ligActionTable_length )); GXV_TRACE(( "componentTable: offset=0x%04x length=0x%04x\n", optdata->componentTable, optdata->componentTable_length )); GXV_TRACE(( "ligatureTable: offset=0x%04x length=0x%04x\n", optdata->ligatureTable, optdata->ligatureTable_length )); GXV_EXIT; } static void gxv_mort_subtable_type2_ligActionOffset_validate( FT_Bytes table, FT_UShort ligActionOffset, GXV_Validator gxvalid ) { /* access ligActionTable */ GXV_mort_subtable_type2_StateOptRecData optdata = (GXV_mort_subtable_type2_StateOptRecData)gxvalid->statetable.optdata; FT_Bytes lat_base = table + optdata->ligActionTable; FT_Bytes p = table + ligActionOffset; FT_Bytes lat_limit = lat_base + optdata->ligActionTable; GXV_32BIT_ALIGNMENT_VALIDATE( ligActionOffset ); if ( p < lat_base ) { GXV_TRACE(( "too short offset 0x%04x: p < lat_base (%ld byte rewind)\n", ligActionOffset, lat_base - p )); /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } else if ( lat_limit < p ) { GXV_TRACE(( "too large offset 0x%04x: lat_limit < p (%ld byte overrun)\n", ligActionOffset, p - lat_limit )); /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } else { /* validate entry in ligActionTable */ FT_ULong lig_action; #ifdef GXV_LOAD_UNUSED_VARS FT_UShort last; FT_UShort store; #endif FT_ULong offset; lig_action = FT_NEXT_ULONG( p ); #ifdef GXV_LOAD_UNUSED_VARS last = (FT_UShort)( ( lig_action >> 31 ) & 1 ); store = (FT_UShort)( ( lig_action >> 30 ) & 1 ); #endif /* Apple spec defines this offset as a word offset */ offset = lig_action & 0x3FFFFFFFUL; if ( offset * 2 < optdata->ligatureTable ) { GXV_TRACE(( "too short offset 0x%08lx:" " 2 x offset < ligatureTable (%lu byte rewind)\n", offset, optdata->ligatureTable - offset * 2 )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } else if ( offset * 2 > optdata->ligatureTable + optdata->ligatureTable_length ) { GXV_TRACE(( "too long offset 0x%08lx:" " 2 x offset > ligatureTable + ligatureTable_length" " (%lu byte overrun)\n", offset, optdata->ligatureTable + optdata->ligatureTable_length - offset * 2 )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } } } static void gxv_mort_subtable_type2_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_UShort setComponent; FT_UShort dontAdvance; #endif FT_UShort offset; FT_UNUSED( state ); FT_UNUSED( glyphOffset_p ); FT_UNUSED( limit ); #ifdef GXV_LOAD_UNUSED_VARS setComponent = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); #endif offset = (FT_UShort)( flags & 0x3FFFU ); if ( 0 < offset ) gxv_mort_subtable_type2_ligActionOffset_validate( table, offset, gxvalid ); } static void gxv_mort_subtable_type2_ligatureTable_validate( FT_Bytes table, GXV_Validator gxvalid ) { GXV_mort_subtable_type2_StateOptRecData optdata = (GXV_mort_subtable_type2_StateOptRecData)gxvalid->statetable.optdata; FT_Bytes p = table + optdata->ligatureTable; FT_Bytes limit = table + optdata->ligatureTable + optdata->ligatureTable_length; GXV_NAME_ENTER( "mort chain subtable type2 - substitutionTable" ); if ( 0 != optdata->ligatureTable ) { /* Apple does not give specification of ligatureTable format */ while ( p < limit ) { FT_UShort lig_gid; GXV_LIMIT_CHECK( 2 ); lig_gid = FT_NEXT_USHORT( p ); if ( gxvalid->face->num_glyphs < lig_gid ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } } GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_mort_subtable_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_mort_subtable_type2_StateOptRec lig_rec; GXV_NAME_ENTER( "mort chain subtable type2 (Ligature Substitution)" ); GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE ); gxvalid->statetable.optdata = &lig_rec; gxvalid->statetable.optdata_load_func = gxv_mort_subtable_type2_opttable_load; gxvalid->statetable.subtable_setup_func = gxv_mort_subtable_type2_subtable_setup; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; gxvalid->statetable.entry_validate_func = gxv_mort_subtable_type2_entry_validate; gxv_StateTable_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; gxv_mort_subtable_type2_ligatureTable_validate( table, gxvalid ); gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort2.c
C++
gpl-3.0
10,023
/**************************************************************************** * * gxvmort4.c * * TrueTypeGX/AAT mort table validation * body for type4 (Non-Contextual Glyph Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.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 gxvmort static void gxv_mort_subtable_type4_lookupval_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UNUSED( glyph ); gxv_glyphid_validate( value_p->u, gxvalid ); } /* +===============+ --------+ | lookup header | | +===============+ | | BinSrchHeader | | +===============+ | | lastGlyph[0] | | +---------------+ | | firstGlyph[0] | | head of lookup table +---------------+ | + | offset[0] | -> | offset [byte] +===============+ | + | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] +---------------+ | | firstGlyph[1] | | +---------------+ | | offset[1] | | +===============+ | | .... | | 16bit value array | +===============+ | | value | <-------+ .... */ static GXV_LookupValueDesc gxv_mort_subtable_type4_lookupfmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; /* XXX: check range? */ offset = (FT_UShort)( base_value_p->u + relative_gindex * sizeof ( FT_UShort ) ); p = gxvalid->lookuptbl_head + offset; limit = lookuptbl_limit; GXV_LIMIT_CHECK( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } FT_LOCAL_DEF( void ) gxv_mort_subtable_type4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_NAME_ENTER( "mort chain subtable type4 " "(Non-Contextual Glyph Substitution)" ); gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_mort_subtable_type4_lookupval_validate; gxvalid->lookupfmt4_trans = gxv_mort_subtable_type4_lookupfmt4_transit; gxv_LookupTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort4.c
C++
gpl-3.0
3,760
/**************************************************************************** * * gxvmort5.c * * TrueTypeGX/AAT mort table validation * body for type5 (Contextual Glyph Insertion) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmort.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 gxvmort /* * mort subtable type5 (Contextual Glyph Insertion) * has the format of StateTable with insertion-glyph-list, * but without name. The offset is given by glyphOffset in * entryTable. There is no table location declaration * like xxxTable. */ typedef struct GXV_mort_subtable_type5_StateOptRec_ { FT_UShort classTable; FT_UShort stateArray; FT_UShort entryTable; #define GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE GXV_STATETABLE_HEADER_SIZE FT_UShort* classTable_length_p; FT_UShort* stateArray_length_p; FT_UShort* entryTable_length_p; } GXV_mort_subtable_type5_StateOptRec, *GXV_mort_subtable_type5_StateOptRecData; static void gxv_mort_subtable_type5_subtable_setup( FT_UShort table_size, FT_UShort classTable, FT_UShort stateArray, FT_UShort entryTable, FT_UShort* classTable_length_p, FT_UShort* stateArray_length_p, FT_UShort* entryTable_length_p, GXV_Validator gxvalid ) { GXV_mort_subtable_type5_StateOptRecData optdata = (GXV_mort_subtable_type5_StateOptRecData)gxvalid->statetable.optdata; gxv_StateTable_subtable_setup( table_size, classTable, stateArray, entryTable, classTable_length_p, stateArray_length_p, entryTable_length_p, gxvalid ); optdata->classTable = classTable; optdata->stateArray = stateArray; optdata->entryTable = entryTable; optdata->classTable_length_p = classTable_length_p; optdata->stateArray_length_p = stateArray_length_p; optdata->entryTable_length_p = entryTable_length_p; } static void gxv_mort_subtable_type5_InsertList_validate( FT_UShort offset, FT_UShort count, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { /* * We don't know the range of insertion-glyph-list. * Set range by whole of state table. */ FT_Bytes p = table + offset; GXV_mort_subtable_type5_StateOptRecData optdata = (GXV_mort_subtable_type5_StateOptRecData)gxvalid->statetable.optdata; if ( optdata->classTable < offset && offset < optdata->classTable + *(optdata->classTable_length_p) ) GXV_TRACE(( " offset runs into ClassTable" )); if ( optdata->stateArray < offset && offset < optdata->stateArray + *(optdata->stateArray_length_p) ) GXV_TRACE(( " offset runs into StateArray" )); if ( optdata->entryTable < offset && offset < optdata->entryTable + *(optdata->entryTable_length_p) ) GXV_TRACE(( " offset runs into EntryTable" )); #ifndef GXV_LOAD_TRACE_VARS GXV_LIMIT_CHECK( count * 2 ); #else while ( p < table + offset + ( count * 2 ) ) { FT_UShort insert_glyphID; GXV_LIMIT_CHECK( 2 ); insert_glyphID = FT_NEXT_USHORT( p ); GXV_TRACE(( " 0x%04x", insert_glyphID )); } GXV_TRACE(( "\n" )); #endif } static void gxv_mort_subtable_type5_entry_validate( FT_Byte state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_Bool setMark; FT_Bool dontAdvance; FT_Bool currentIsKashidaLike; FT_Bool markedIsKashidaLike; FT_Bool currentInsertBefore; FT_Bool markedInsertBefore; #endif FT_Byte currentInsertCount; FT_Byte markedInsertCount; FT_UShort currentInsertList; FT_UShort markedInsertList; FT_UNUSED( state ); #ifdef GXV_LOAD_UNUSED_VARS setMark = FT_BOOL( ( flags >> 15 ) & 1 ); dontAdvance = FT_BOOL( ( flags >> 14 ) & 1 ); currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 ); markedIsKashidaLike = FT_BOOL( ( flags >> 12 ) & 1 ); currentInsertBefore = FT_BOOL( ( flags >> 11 ) & 1 ); markedInsertBefore = FT_BOOL( ( flags >> 10 ) & 1 ); #endif currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F ); markedInsertCount = (FT_Byte)( flags & 0x001F ); currentInsertList = (FT_UShort)( glyphOffset->ul >> 16 ); markedInsertList = (FT_UShort)( glyphOffset->ul ); if ( 0 != currentInsertList && 0 != currentInsertCount ) { gxv_mort_subtable_type5_InsertList_validate( currentInsertList, currentInsertCount, table, limit, gxvalid ); } if ( 0 != markedInsertList && 0 != markedInsertCount ) { gxv_mort_subtable_type5_InsertList_validate( markedInsertList, markedInsertCount, table, limit, gxvalid ); } } FT_LOCAL_DEF( void ) gxv_mort_subtable_type5_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_mort_subtable_type5_StateOptRec et_rec; GXV_mort_subtable_type5_StateOptRecData et = &et_rec; GXV_NAME_ENTER( "mort chain subtable type5 (Glyph Insertion)" ); GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE ); gxvalid->statetable.optdata = et; gxvalid->statetable.optdata_load_func = NULL; gxvalid->statetable.subtable_setup_func = gxv_mort_subtable_type5_subtable_setup; gxvalid->statetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; gxvalid->statetable.entry_validate_func = gxv_mort_subtable_type5_entry_validate; gxv_StateTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmort5.c
C++
gpl-3.0
8,009
/**************************************************************************** * * gxvmorx.c * * TrueTypeGX/AAT morx table validation (body). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx static void gxv_morx_subtables_validate( FT_Bytes table, FT_Bytes limit, FT_UShort nSubtables, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_Validate_Func fmt_funcs_table[] = { gxv_morx_subtable_type0_validate, /* 0 */ gxv_morx_subtable_type1_validate, /* 1 */ gxv_morx_subtable_type2_validate, /* 2 */ NULL, /* 3 */ gxv_morx_subtable_type4_validate, /* 4 */ gxv_morx_subtable_type5_validate, /* 5 */ }; FT_UShort i; GXV_NAME_ENTER( "subtables in a chain" ); for ( i = 0; i < nSubtables; i++ ) { GXV_Validate_Func func; FT_ULong length; FT_ULong coverage; #ifdef GXV_LOAD_UNUSED_VARS FT_ULong subFeatureFlags; #endif FT_ULong type; FT_ULong rest; GXV_LIMIT_CHECK( 4 + 4 + 4 ); length = FT_NEXT_ULONG( p ); coverage = FT_NEXT_ULONG( p ); #ifdef GXV_LOAD_UNUSED_VARS subFeatureFlags = FT_NEXT_ULONG( p ); #else p += 4; #endif GXV_TRACE(( "validating chain subtable %d/%d (%lu bytes)\n", i + 1, nSubtables, length )); type = coverage & 0x0007; rest = length - ( 4 + 4 + 4 ); GXV_LIMIT_CHECK( rest ); /* morx coverage consists of mort_coverage & 16bit padding */ gxv_mort_coverage_validate( (FT_UShort)( ( coverage >> 16 ) | coverage ), gxvalid ); if ( type > 5 ) FT_INVALID_FORMAT; func = fmt_funcs_table[type]; if ( !func ) GXV_TRACE(( "morx type %lu is reserved\n", type )); func( p, p + rest, gxvalid ); /* TODO: subFeatureFlags should be unique in a table? */ p += rest; } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_morx_chain_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; #ifdef GXV_LOAD_UNUSED_VARS FT_ULong defaultFlags; #endif FT_ULong chainLength; FT_ULong nFeatureFlags; FT_ULong nSubtables; GXV_NAME_ENTER( "morx chain header" ); GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 ); #ifdef GXV_LOAD_UNUSED_VARS defaultFlags = FT_NEXT_ULONG( p ); #else p += 4; #endif chainLength = FT_NEXT_ULONG( p ); nFeatureFlags = FT_NEXT_ULONG( p ); nSubtables = FT_NEXT_ULONG( p ); /* feature-array of morx is same with that of mort */ gxv_mort_featurearray_validate( p, limit, nFeatureFlags, gxvalid ); p += gxvalid->subtable_length; if ( nSubtables >= 0x10000L ) FT_INVALID_DATA; gxv_morx_subtables_validate( p, table + chainLength, (FT_UShort)nSubtables, gxvalid ); gxvalid->subtable_length = chainLength; /* TODO: defaultFlags should be compared with the flags in tables */ GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_morx_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_ULong version; FT_ULong nChains; FT_ULong i; gxvalid->root = ftvalid; gxvalid->face = face; FT_TRACE3(( "validating `morx' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 4 ); version = FT_NEXT_ULONG( p ); nChains = FT_NEXT_ULONG( p ); if ( version != 0x00020000UL ) FT_INVALID_FORMAT; for ( i = 0; i < nChains; i++ ) { GXV_TRACE(( "validating chain %lu/%lu\n", i + 1, nChains )); GXV_32BIT_ALIGNMENT_VALIDATE( p - table ); gxv_morx_chain_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; } FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx.c
C++
gpl-3.0
5,208
/**************************************************************************** * * gxvmorx.h * * TrueTypeGX/AAT common definition for morx table (specification). * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #ifndef GXVMORX_H_ #define GXVMORX_H_ #include "gxvalid.h" #include "gxvcommn.h" #include "gxvmort.h" #include <freetype/ftsnames.h> FT_BEGIN_HEADER FT_LOCAL( void ) gxv_morx_subtable_type0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_morx_subtable_type1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_morx_subtable_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_morx_subtable_type4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_LOCAL( void ) gxv_morx_subtable_type5_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ); FT_END_HEADER #endif /* GXVMORX_H_ */ /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx.h
C++
gpl-3.0
2,076
/**************************************************************************** * * gxvmorx0.c * * TrueTypeGX/AAT morx table validation * body for type0 (Indic Script Rearrangement) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx static void gxv_morx_subtable_type0_entry_validate( FT_UShort state, FT_UShort flags, GXV_XStateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_UShort markFirst; FT_UShort dontAdvance; FT_UShort markLast; #endif FT_UShort reserved; #ifdef GXV_LOAD_UNUSED_VARS FT_UShort verb; #endif FT_UNUSED( state ); FT_UNUSED( glyphOffset_p ); FT_UNUSED( table ); FT_UNUSED( limit ); #ifdef GXV_LOAD_UNUSED_VARS markFirst = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); markLast = (FT_UShort)( ( flags >> 13 ) & 1 ); #endif reserved = (FT_UShort)( flags & 0x1FF0 ); #ifdef GXV_LOAD_UNUSED_VARS verb = (FT_UShort)( flags & 0x000F ); #endif if ( 0 < reserved ) { GXV_TRACE(( " non-zero bits found in reserved range\n" )); FT_INVALID_DATA; } } FT_LOCAL_DEF( void ) gxv_morx_subtable_type0_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_NAME_ENTER( "morx chain subtable type0 (Indic-Script Rearrangement)" ); GXV_LIMIT_CHECK( GXV_STATETABLE_HEADER_SIZE ); gxvalid->xstatetable.optdata = NULL; gxvalid->xstatetable.optdata_load_func = NULL; gxvalid->xstatetable.subtable_setup_func = NULL; gxvalid->xstatetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_NONE; gxvalid->xstatetable.entry_validate_func = gxv_morx_subtable_type0_entry_validate; gxv_XStateTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx0.c
C++
gpl-3.0
3,126
/**************************************************************************** * * gxvmorx1.c * * TrueTypeGX/AAT morx table validation * body for type1 (Contextual Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx typedef struct GXV_morx_subtable_type1_StateOptRec_ { FT_ULong substitutionTable; FT_ULong substitutionTable_length; FT_UShort substitutionTable_num_lookupTables; } GXV_morx_subtable_type1_StateOptRec, *GXV_morx_subtable_type1_StateOptRecData; #define GXV_MORX_SUBTABLE_TYPE1_HEADER_SIZE \ ( GXV_STATETABLE_HEADER_SIZE + 2 ) static void gxv_morx_subtable_type1_substitutionTable_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type1_StateOptRecData optdata = (GXV_morx_subtable_type1_StateOptRecData)gxvalid->xstatetable.optdata; GXV_LIMIT_CHECK( 2 ); optdata->substitutionTable = FT_NEXT_USHORT( p ); } static void gxv_morx_subtable_type1_subtable_setup( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ) { FT_ULong o[4]; FT_ULong *l[4]; FT_ULong buff[5]; GXV_morx_subtable_type1_StateOptRecData optdata = (GXV_morx_subtable_type1_StateOptRecData)gxvalid->xstatetable.optdata; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->substitutionTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &(optdata->substitutionTable_length); gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, gxvalid ); } static void gxv_morx_subtable_type1_entry_validate( FT_UShort state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_TRACE_VARS FT_UShort setMark; FT_UShort dontAdvance; #endif FT_UShort reserved; FT_Short markIndex; FT_Short currentIndex; GXV_morx_subtable_type1_StateOptRecData optdata = (GXV_morx_subtable_type1_StateOptRecData)gxvalid->xstatetable.optdata; FT_UNUSED( state ); FT_UNUSED( table ); FT_UNUSED( limit ); #ifdef GXV_LOAD_TRACE_VARS setMark = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); #endif reserved = (FT_UShort)( flags & 0x3FFF ); markIndex = (FT_Short)( glyphOffset_p->ul >> 16 ); currentIndex = (FT_Short)( glyphOffset_p->ul ); GXV_TRACE(( " setMark=%01d dontAdvance=%01d\n", setMark, dontAdvance )); if ( 0 < reserved ) { GXV_TRACE(( " non-zero bits found in reserved range\n" )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA ); } GXV_TRACE(( "markIndex = %d, currentIndex = %d\n", markIndex, currentIndex )); if ( optdata->substitutionTable_num_lookupTables < markIndex + 1 ) optdata->substitutionTable_num_lookupTables = (FT_UShort)( markIndex + 1 ); if ( optdata->substitutionTable_num_lookupTables < currentIndex + 1 ) optdata->substitutionTable_num_lookupTables = (FT_UShort)( currentIndex + 1 ); } static void gxv_morx_subtable_type1_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { FT_UNUSED( glyph ); /* for the non-debugging case */ GXV_TRACE(( "morx subtable type1 subst.: %d -> %d\n", glyph, value_p->u )); if ( value_p->u > gxvalid->face->num_glyphs ) FT_INVALID_GLYPH_ID; } static GXV_LookupValueDesc gxv_morx_subtable_type1_LookupFmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; /* XXX: check range? */ offset = (FT_UShort)( base_value_p->u + relative_gindex * sizeof ( FT_UShort ) ); p = gxvalid->lookuptbl_head + offset; limit = lookuptbl_limit; GXV_LIMIT_CHECK ( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } /* * TODO: length should be limit? **/ static void gxv_morx_subtable_type1_substitutionTable_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort i; GXV_morx_subtable_type1_StateOptRecData optdata = (GXV_morx_subtable_type1_StateOptRecData)gxvalid->xstatetable.optdata; /* TODO: calculate offset/length for each lookupTables */ gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_morx_subtable_type1_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_morx_subtable_type1_LookupFmt4_transit; for ( i = 0; i < optdata->substitutionTable_num_lookupTables; i++ ) { FT_ULong offset; GXV_LIMIT_CHECK( 4 ); offset = FT_NEXT_ULONG( p ); gxv_LookupTable_validate( table + offset, limit, gxvalid ); } /* TODO: overlapping of lookupTables in substitutionTable */ } /* * subtable for Contextual glyph substitution is a modified StateTable. * In addition to classTable, stateArray, entryTable, the field * `substitutionTable' is added. */ FT_LOCAL_DEF( void ) gxv_morx_subtable_type1_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type1_StateOptRec st_rec; GXV_NAME_ENTER( "morx chain subtable type1 (Contextual Glyph Subst)" ); GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE1_HEADER_SIZE ); st_rec.substitutionTable_num_lookupTables = 0; gxvalid->xstatetable.optdata = &st_rec; gxvalid->xstatetable.optdata_load_func = gxv_morx_subtable_type1_substitutionTable_load; gxvalid->xstatetable.subtable_setup_func = gxv_morx_subtable_type1_subtable_setup; gxvalid->xstatetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; gxvalid->xstatetable.entry_validate_func = gxv_morx_subtable_type1_entry_validate; gxv_XStateTable_validate( p, limit, gxvalid ); gxv_morx_subtable_type1_substitutionTable_validate( table + st_rec.substitutionTable, table + st_rec.substitutionTable + st_rec.substitutionTable_length, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx1.c
C++
gpl-3.0
8,464
/**************************************************************************** * * gxvmorx2.c * * TrueTypeGX/AAT morx table validation * body for type2 (Ligature Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx typedef struct GXV_morx_subtable_type2_StateOptRec_ { FT_ULong ligActionTable; FT_ULong componentTable; FT_ULong ligatureTable; FT_ULong ligActionTable_length; FT_ULong componentTable_length; FT_ULong ligatureTable_length; } GXV_morx_subtable_type2_StateOptRec, *GXV_morx_subtable_type2_StateOptRecData; #define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE \ ( GXV_XSTATETABLE_HEADER_SIZE + 4 + 4 + 4 ) static void gxv_morx_subtable_type2_opttable_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type2_StateOptRecData optdata = (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata; GXV_LIMIT_CHECK( 4 + 4 + 4 ); optdata->ligActionTable = FT_NEXT_ULONG( p ); optdata->componentTable = FT_NEXT_ULONG( p ); optdata->ligatureTable = FT_NEXT_ULONG( p ); GXV_TRACE(( "offset to ligActionTable=0x%08lx\n", optdata->ligActionTable )); GXV_TRACE(( "offset to componentTable=0x%08lx\n", optdata->componentTable )); GXV_TRACE(( "offset to ligatureTable=0x%08lx\n", optdata->ligatureTable )); } static void gxv_morx_subtable_type2_subtable_setup( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ) { FT_ULong o[6]; FT_ULong* l[6]; FT_ULong buff[7]; GXV_morx_subtable_type2_StateOptRecData optdata = (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata; GXV_NAME_ENTER( "subtable boundaries setup" ); o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->ligActionTable; o[4] = optdata->componentTable; o[5] = optdata->ligatureTable; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &(optdata->ligActionTable_length); l[4] = &(optdata->componentTable_length); l[5] = &(optdata->ligatureTable_length); gxv_set_length_by_ulong_offset( o, l, buff, 6, table_size, gxvalid ); GXV_TRACE(( "classTable: offset=0x%08lx length=0x%08lx\n", classTable, *classTable_length_p )); GXV_TRACE(( "stateArray: offset=0x%08lx length=0x%08lx\n", stateArray, *stateArray_length_p )); GXV_TRACE(( "entryTable: offset=0x%08lx length=0x%08lx\n", entryTable, *entryTable_length_p )); GXV_TRACE(( "ligActionTable: offset=0x%08lx length=0x%08lx\n", optdata->ligActionTable, optdata->ligActionTable_length )); GXV_TRACE(( "componentTable: offset=0x%08lx length=0x%08lx\n", optdata->componentTable, optdata->componentTable_length )); GXV_TRACE(( "ligatureTable: offset=0x%08lx length=0x%08lx\n", optdata->ligatureTable, optdata->ligatureTable_length )); GXV_EXIT; } #define GXV_MORX_LIGACTION_ENTRY_SIZE 4 static void gxv_morx_subtable_type2_ligActionIndex_validate( FT_Bytes table, FT_UShort ligActionIndex, GXV_Validator gxvalid ) { /* access ligActionTable */ GXV_morx_subtable_type2_StateOptRecData optdata = (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata; FT_Bytes lat_base = table + optdata->ligActionTable; FT_Bytes p = lat_base + ligActionIndex * GXV_MORX_LIGACTION_ENTRY_SIZE; FT_Bytes lat_limit = lat_base + optdata->ligActionTable; if ( p < lat_base ) { GXV_TRACE(( "p < lat_base (%ld byte rewind)\n", lat_base - p )); FT_INVALID_OFFSET; } else if ( lat_limit < p ) { GXV_TRACE(( "lat_limit < p (%ld byte overrun)\n", p - lat_limit )); FT_INVALID_OFFSET; } { /* validate entry in ligActionTable */ FT_ULong lig_action; #ifdef GXV_LOAD_UNUSED_VARS FT_UShort last; FT_UShort store; #endif FT_ULong offset; FT_Long gid_limit; lig_action = FT_NEXT_ULONG( p ); #ifdef GXV_LOAD_UNUSED_VARS last = (FT_UShort)( ( lig_action >> 31 ) & 1 ); store = (FT_UShort)( ( lig_action >> 30 ) & 1 ); #endif offset = lig_action & 0x3FFFFFFFUL; /* this offset is 30-bit signed value to add to GID */ /* it is different from the location offset in mort */ if ( ( offset & 0x3FFF0000UL ) == 0x3FFF0000UL ) { /* negative offset */ gid_limit = gxvalid->face->num_glyphs - (FT_Long)( offset & 0x0000FFFFUL ); if ( gid_limit > 0 ) return; GXV_TRACE(( "ligature action table includes" " too negative offset moving all GID" " below defined range: 0x%04lx\n", offset & 0xFFFFU )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } else if ( ( offset & 0x3FFF0000UL ) == 0x00000000UL ) { /* positive offset */ if ( (FT_Long)offset < gxvalid->face->num_glyphs ) return; GXV_TRACE(( "ligature action table includes" " too large offset moving all GID" " over defined range: 0x%04lx\n", offset & 0xFFFFU )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } GXV_TRACE(( "ligature action table includes" " invalid offset to add to 16-bit GID:" " 0x%08lx\n", offset )); GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET ); } } static void gxv_morx_subtable_type2_entry_validate( FT_UShort state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_UShort setComponent; FT_UShort dontAdvance; FT_UShort performAction; #endif FT_UShort reserved; FT_UShort ligActionIndex; FT_UNUSED( state ); FT_UNUSED( limit ); #ifdef GXV_LOAD_UNUSED_VARS setComponent = (FT_UShort)( ( flags >> 15 ) & 1 ); dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); performAction = (FT_UShort)( ( flags >> 13 ) & 1 ); #endif reserved = (FT_UShort)( flags & 0x1FFF ); ligActionIndex = glyphOffset_p->u; if ( reserved > 0 ) GXV_TRACE(( " reserved 14bit is non-zero\n" )); if ( 0 < ligActionIndex ) gxv_morx_subtable_type2_ligActionIndex_validate( table, ligActionIndex, gxvalid ); } static void gxv_morx_subtable_type2_ligatureTable_validate( FT_Bytes table, GXV_Validator gxvalid ) { GXV_morx_subtable_type2_StateOptRecData optdata = (GXV_morx_subtable_type2_StateOptRecData)gxvalid->xstatetable.optdata; FT_Bytes p = table + optdata->ligatureTable; FT_Bytes limit = table + optdata->ligatureTable + optdata->ligatureTable_length; GXV_NAME_ENTER( "morx chain subtable type2 - substitutionTable" ); if ( 0 != optdata->ligatureTable ) { /* Apple does not give specification of ligatureTable format */ while ( p < limit ) { FT_UShort lig_gid; GXV_LIMIT_CHECK( 2 ); lig_gid = FT_NEXT_USHORT( p ); if ( lig_gid < gxvalid->face->num_glyphs ) GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID ); } } GXV_EXIT; } FT_LOCAL_DEF( void ) gxv_morx_subtable_type2_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type2_StateOptRec lig_rec; GXV_NAME_ENTER( "morx chain subtable type2 (Ligature Substitution)" ); GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE ); gxvalid->xstatetable.optdata = &lig_rec; gxvalid->xstatetable.optdata_load_func = gxv_morx_subtable_type2_opttable_load; gxvalid->xstatetable.subtable_setup_func = gxv_morx_subtable_type2_subtable_setup; gxvalid->xstatetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_USHORT; gxvalid->xstatetable.entry_validate_func = gxv_morx_subtable_type2_entry_validate; gxv_XStateTable_validate( p, limit, gxvalid ); #if 0 p += gxvalid->subtable_length; #endif gxv_morx_subtable_type2_ligatureTable_validate( table, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx2.c
C++
gpl-3.0
10,356
/**************************************************************************** * * gxvmorx4.c * * TrueTypeGX/AAT morx table validation * body for "morx" type4 (Non-Contextual Glyph Substitution) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx FT_LOCAL_DEF( void ) gxv_morx_subtable_type4_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { GXV_NAME_ENTER( "morx chain subtable type4 " "(Non-Contextual Glyph Substitution)" ); gxv_mort_subtable_type4_validate( table, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx4.c
C++
gpl-3.0
1,674
/**************************************************************************** * * gxvmorx5.c * * TrueTypeGX/AAT morx table validation * body for type5 (Contextual Glyph Insertion) subtable. * * Copyright (C) 2005-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvmorx.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 gxvmorx /* * `morx' subtable type5 (Contextual Glyph Insertion) * has format of a StateTable with insertion-glyph-list * without name. However, the 32bit offset from the head * of subtable to the i-g-l is given after `entryTable', * without variable name specification (the existence of * this offset to the table is different from mort type5). */ typedef struct GXV_morx_subtable_type5_StateOptRec_ { FT_ULong insertionGlyphList; FT_ULong insertionGlyphList_length; } GXV_morx_subtable_type5_StateOptRec, *GXV_morx_subtable_type5_StateOptRecData; #define GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE \ ( GXV_STATETABLE_HEADER_SIZE + 4 ) static void gxv_morx_subtable_type5_insertionGlyphList_load( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type5_StateOptRecData optdata = (GXV_morx_subtable_type5_StateOptRecData)gxvalid->xstatetable.optdata; GXV_LIMIT_CHECK( 4 ); optdata->insertionGlyphList = FT_NEXT_ULONG( p ); } static void gxv_morx_subtable_type5_subtable_setup( FT_ULong table_size, FT_ULong classTable, FT_ULong stateArray, FT_ULong entryTable, FT_ULong* classTable_length_p, FT_ULong* stateArray_length_p, FT_ULong* entryTable_length_p, GXV_Validator gxvalid ) { FT_ULong o[4]; FT_ULong* l[4]; FT_ULong buff[5]; GXV_morx_subtable_type5_StateOptRecData optdata = (GXV_morx_subtable_type5_StateOptRecData)gxvalid->xstatetable.optdata; o[0] = classTable; o[1] = stateArray; o[2] = entryTable; o[3] = optdata->insertionGlyphList; l[0] = classTable_length_p; l[1] = stateArray_length_p; l[2] = entryTable_length_p; l[3] = &(optdata->insertionGlyphList_length); gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, gxvalid ); } static void gxv_morx_subtable_type5_InsertList_validate( FT_UShort table_index, FT_UShort count, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table + table_index * 2; #ifndef GXV_LOAD_TRACE_VARS GXV_LIMIT_CHECK( count * 2 ); #else while ( p < table + count * 2 + table_index * 2 ) { FT_UShort insert_glyphID; GXV_LIMIT_CHECK( 2 ); insert_glyphID = FT_NEXT_USHORT( p ); GXV_TRACE(( " 0x%04x", insert_glyphID )); } GXV_TRACE(( "\n" )); #endif } static void gxv_morx_subtable_type5_entry_validate( FT_UShort state, FT_UShort flags, GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { #ifdef GXV_LOAD_UNUSED_VARS FT_Bool setMark; FT_Bool dontAdvance; FT_Bool currentIsKashidaLike; FT_Bool markedIsKashidaLike; FT_Bool currentInsertBefore; FT_Bool markedInsertBefore; #endif FT_Byte currentInsertCount; FT_Byte markedInsertCount; FT_Byte currentInsertList; FT_UShort markedInsertList; FT_UNUSED( state ); #ifdef GXV_LOAD_UNUSED_VARS setMark = FT_BOOL( ( flags >> 15 ) & 1 ); dontAdvance = FT_BOOL( ( flags >> 14 ) & 1 ); currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 ); markedIsKashidaLike = FT_BOOL( ( flags >> 12 ) & 1 ); currentInsertBefore = FT_BOOL( ( flags >> 11 ) & 1 ); markedInsertBefore = FT_BOOL( ( flags >> 10 ) & 1 ); #endif currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F ); markedInsertCount = (FT_Byte)( flags & 0x001F ); currentInsertList = (FT_Byte) ( glyphOffset_p->ul >> 16 ); markedInsertList = (FT_UShort)( glyphOffset_p->ul ); if ( currentInsertList && 0 != currentInsertCount ) gxv_morx_subtable_type5_InsertList_validate( currentInsertList, currentInsertCount, table, limit, gxvalid ); if ( markedInsertList && 0 != markedInsertCount ) gxv_morx_subtable_type5_InsertList_validate( markedInsertList, markedInsertCount, table, limit, gxvalid ); } FT_LOCAL_DEF( void ) gxv_morx_subtable_type5_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; GXV_morx_subtable_type5_StateOptRec et_rec; GXV_morx_subtable_type5_StateOptRecData et = &et_rec; GXV_NAME_ENTER( "morx chain subtable type5 (Glyph Insertion)" ); GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE ); gxvalid->xstatetable.optdata = et; gxvalid->xstatetable.optdata_load_func = gxv_morx_subtable_type5_insertionGlyphList_load; gxvalid->xstatetable.subtable_setup_func = gxv_morx_subtable_type5_subtable_setup; gxvalid->xstatetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG; gxvalid->xstatetable.entry_validate_func = gxv_morx_subtable_type5_entry_validate; gxv_XStateTable_validate( p, limit, gxvalid ); GXV_EXIT; } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvmorx5.c
C++
gpl-3.0
7,285
/**************************************************************************** * * gxvopbd.c * * TrueTypeGX/AAT opbd table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.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 gxvopbd /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ typedef struct GXV_opbd_DataRec_ { FT_UShort format; FT_UShort valueOffset_min; } GXV_opbd_DataRec, *GXV_opbd_Data; #define GXV_OPBD_DATA( FIELD ) GXV_TABLE_DATA( opbd, FIELD ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_opbd_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { /* offset in LookupTable is measured from the head of opbd table */ FT_Bytes p = gxvalid->root->base + value_p->u; FT_Bytes limit = gxvalid->root->limit; FT_Short delta_value; int i; if ( value_p->u < GXV_OPBD_DATA( valueOffset_min ) ) GXV_OPBD_DATA( valueOffset_min ) = value_p->u; for ( i = 0; i < 4; i++ ) { GXV_LIMIT_CHECK( 2 ); delta_value = FT_NEXT_SHORT( p ); if ( GXV_OPBD_DATA( format ) ) /* format 1, value is ctrl pt. */ { if ( delta_value == -1 ) continue; gxv_ctlPoint_validate( glyph, (FT_UShort)delta_value, gxvalid ); } else /* format 0, value is distance */ continue; } } /* opbd ---------------------+ | +===============+ | | lookup header | | +===============+ | | BinSrchHeader | | +===============+ | | lastGlyph[0] | | +---------------+ | | firstGlyph[0] | | head of opbd sfnt table +---------------+ | + | offset[0] | -> | offset [byte] +===============+ | + | lastGlyph[1] | | (glyphID - firstGlyph) * 4 * sizeof(FT_Short) [byte] +---------------+ | | firstGlyph[1] | | +---------------+ | | offset[1] | | +===============+ | | .... | | 48bit value array | +===============+ | | value | <-------+ | | | | | | +---------------+ .... */ static GXV_LookupValueDesc gxv_opbd_LookupFmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { GXV_LookupValueDesc value; FT_UNUSED( lookuptbl_limit ); FT_UNUSED( gxvalid ); /* XXX: check range? */ value.u = (FT_UShort)( base_value_p->u + relative_gindex * 4 * sizeof ( FT_Short ) ); return value; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** opbd TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_opbd_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_opbd_DataRec opbdrec; GXV_opbd_Data opbd = &opbdrec; FT_Bytes p = table; FT_Bytes limit = 0; FT_ULong version; gxvalid->root = ftvalid; gxvalid->table_data = opbd; gxvalid->face = face; FT_TRACE3(( "validating `opbd' table\n" )); GXV_INIT; GXV_OPBD_DATA( valueOffset_min ) = 0xFFFFU; GXV_LIMIT_CHECK( 4 + 2 ); version = FT_NEXT_ULONG( p ); GXV_OPBD_DATA( format ) = FT_NEXT_USHORT( p ); /* only 0x00010000 is defined (1996) */ GXV_TRACE(( "(version=0x%08lx)\n", version )); if ( 0x00010000UL != version ) FT_INVALID_FORMAT; /* only values 0 and 1 are defined (1996) */ GXV_TRACE(( "(format=0x%04x)\n", GXV_OPBD_DATA( format ) )); if ( 0x0001 < GXV_OPBD_DATA( format ) ) FT_INVALID_FORMAT; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_opbd_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_opbd_LookupFmt4_transit; gxv_LookupTable_validate( p, limit, gxvalid ); p += gxvalid->subtable_length; if ( p > table + GXV_OPBD_DATA( valueOffset_min ) ) { GXV_TRACE(( "found overlap between LookupTable and opbd_value array\n" )); FT_INVALID_OFFSET; } FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvopbd.c
C++
gpl-3.0
7,216
/**************************************************************************** * * gxvprop.c * * TrueTypeGX/AAT prop table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.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 gxvprop /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ #define GXV_PROP_HEADER_SIZE ( 4 + 2 + 2 ) #define GXV_PROP_SIZE_MIN GXV_PROP_HEADER_SIZE typedef struct GXV_prop_DataRec_ { FT_Fixed version; } GXV_prop_DataRec, *GXV_prop_Data; #define GXV_PROP_DATA( field ) GXV_TABLE_DATA( prop, field ) #define GXV_PROP_FLOATER 0x8000U #define GXV_PROP_USE_COMPLEMENTARY_BRACKET 0x1000U #define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET 0x0F00U #define GXV_PROP_ATTACHING_TO_RIGHT 0x0080U #define GXV_PROP_RESERVED 0x0060U #define GXV_PROP_DIRECTIONALITY_CLASS 0x001FU /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_prop_zero_advance_validate( FT_UShort gid, GXV_Validator gxvalid ) { FT_Face face; FT_Error error; FT_GlyphSlot glyph; GXV_NAME_ENTER( "zero advance" ); face = gxvalid->face; error = FT_Load_Glyph( face, gid, FT_LOAD_IGNORE_TRANSFORM ); if ( error ) FT_INVALID_GLYPH_ID; glyph = face->glyph; if ( glyph->advance.x != (FT_Pos)0 || glyph->advance.y != (FT_Pos)0 ) { GXV_TRACE(( " found non-zero advance in zero-advance glyph\n" )); FT_INVALID_DATA; } GXV_EXIT; } /* Pass 0 as GLYPH to check the default property */ static void gxv_prop_property_validate( FT_UShort property, FT_UShort glyph, GXV_Validator gxvalid ) { if ( glyph != 0 && ( property & GXV_PROP_FLOATER ) ) gxv_prop_zero_advance_validate( glyph, gxvalid ); if ( property & GXV_PROP_USE_COMPLEMENTARY_BRACKET ) { FT_UShort offset; char complement; offset = (FT_UShort)( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET ); if ( offset == 0 ) { GXV_TRACE(( " found zero offset to property\n" )); FT_INVALID_OFFSET; } complement = (char)( offset >> 8 ); if ( complement & 0x08 ) { /* Top bit is set: negative */ /* Calculate the absolute offset */ complement = (char)( ( complement & 0x07 ) + 1 ); /* The gid for complement must be greater than 0 */ if ( glyph <= complement ) { GXV_TRACE(( " found non-positive glyph complement\n" )); FT_INVALID_DATA; } } else { /* The gid for complement must be the face. */ gxv_glyphid_validate( (FT_UShort)( glyph + complement ), gxvalid ); } } else { if ( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET ) GXV_TRACE(( "glyph %d cannot have complementary bracketing\n", glyph )); } /* this is introduced in version 2.0 */ if ( property & GXV_PROP_ATTACHING_TO_RIGHT ) { if ( GXV_PROP_DATA( version ) == 0x00010000UL ) { GXV_TRACE(( " found older version (1.0) in new version table\n" )); FT_INVALID_DATA; } } if ( property & GXV_PROP_RESERVED ) { GXV_TRACE(( " found non-zero bits in reserved bits\n" )); FT_INVALID_DATA; } if ( ( property & GXV_PROP_DIRECTIONALITY_CLASS ) > 11 ) { /* TODO: Too restricted. Use the validation level. */ if ( GXV_PROP_DATA( version ) == 0x00010000UL || GXV_PROP_DATA( version ) == 0x00020000UL ) { GXV_TRACE(( " found too old version in directionality class\n" )); FT_INVALID_DATA; } } } static void gxv_prop_LookupValue_validate( FT_UShort glyph, GXV_LookupValueCPtr value_p, GXV_Validator gxvalid ) { gxv_prop_property_validate( value_p->u, glyph, gxvalid ); } /* +===============+ --------+ | lookup header | | +===============+ | | BinSrchHeader | | +===============+ | | lastGlyph[0] | | +---------------+ | | firstGlyph[0] | | head of lookup table +---------------+ | + | offset[0] | -> | offset [byte] +===============+ | + | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte] +---------------+ | | firstGlyph[1] | | +---------------+ | | offset[1] | | +===============+ | | ... | | 16bit value array | +===============+ | | value | <-------+ ... */ static GXV_LookupValueDesc gxv_prop_LookupFmt4_transit( FT_UShort relative_gindex, GXV_LookupValueCPtr base_value_p, FT_Bytes lookuptbl_limit, GXV_Validator gxvalid ) { FT_Bytes p; FT_Bytes limit; FT_UShort offset; GXV_LookupValueDesc value; /* XXX: check range? */ offset = (FT_UShort)( base_value_p->u + relative_gindex * sizeof ( FT_UShort ) ); p = gxvalid->lookuptbl_head + offset; limit = lookuptbl_limit; GXV_LIMIT_CHECK ( 2 ); value.u = FT_NEXT_USHORT( p ); return value; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** prop TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_prop_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { FT_Bytes p = table; FT_Bytes limit = 0; GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_prop_DataRec proprec; GXV_prop_Data prop = &proprec; FT_Fixed version; FT_UShort format; FT_UShort defaultProp; gxvalid->root = ftvalid; gxvalid->table_data = prop; gxvalid->face = face; FT_TRACE3(( "validating `prop' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 2 + 2 ); version = FT_NEXT_LONG( p ); format = FT_NEXT_USHORT( p ); defaultProp = FT_NEXT_USHORT( p ); GXV_TRACE(( " version 0x%08lx\n", version )); GXV_TRACE(( " format 0x%04x\n", format )); GXV_TRACE(( " defaultProp 0x%04x\n", defaultProp )); /* only versions 1.0, 2.0, 3.0 are defined (1996) */ if ( version != 0x00010000UL && version != 0x00020000UL && version != 0x00030000UL ) { GXV_TRACE(( " found unknown version\n" )); FT_INVALID_FORMAT; } /* only formats 0x0000, 0x0001 are defined (1996) */ if ( format > 1 ) { GXV_TRACE(( " found unknown format\n" )); FT_INVALID_FORMAT; } gxv_prop_property_validate( defaultProp, 0, gxvalid ); if ( format == 0 ) { FT_TRACE3(( "(format 0, no per-glyph properties, " "remaining %ld bytes are skipped)", limit - p )); goto Exit; } /* format == 1 */ GXV_PROP_DATA( version ) = version; gxvalid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED; gxvalid->lookupval_func = gxv_prop_LookupValue_validate; gxvalid->lookupfmt4_trans = gxv_prop_LookupFmt4_transit; gxv_LookupTable_validate( p, limit, gxvalid ); Exit: FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvprop.c
C++
gpl-3.0
10,208
/**************************************************************************** * * gxvtrak.c * * TrueTypeGX/AAT trak table validation (body). * * Copyright (C) 2004-2022 by * suzuki toshiya, Masatake YAMATO, Red Hat K.K., * 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. * */ /**************************************************************************** * * gxvalid is derived from both gxlayout module and otvalid module. * Development of gxlayout is supported by the Information-technology * Promotion Agency(IPA), Japan. * */ #include "gxvalid.h" #include "gxvcommn.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 gxvtrak /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** Data and Types *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* * referred track table format specification: * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6trak.html * last update was 1996. * ---------------------------------------------- * [MINIMUM HEADER]: GXV_TRAK_SIZE_MIN * version (fixed: 32bit) = 0x00010000 * format (uint16: 16bit) = 0 is only defined (1996) * horizOffset (uint16: 16bit) * vertOffset (uint16: 16bit) * reserved (uint16: 16bit) = 0 * ---------------------------------------------- * [VARIABLE BODY]: * horizData * header ( 2 + 2 + 4 * trackTable + nTracks * ( 4 + 2 + 2 ) * sizeTable + nSizes * 4 ) * ---------------------------------------------- * vertData * header ( 2 + 2 + 4 * trackTable + nTracks * ( 4 + 2 + 2 ) * sizeTable + nSizes * 4 ) * ---------------------------------------------- */ typedef struct GXV_trak_DataRec_ { FT_UShort trackValueOffset_min; FT_UShort trackValueOffset_max; } GXV_trak_DataRec, *GXV_trak_Data; #define GXV_TRAK_DATA( FIELD ) GXV_TABLE_DATA( trak, FIELD ) /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** UTILITY FUNCTIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ static void gxv_trak_trackTable_validate( FT_Bytes table, FT_Bytes limit, FT_UShort nTracks, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_Fixed track, t; FT_UShort nameIndex; FT_UShort offset; FT_UShort i, j; GXV_NAME_ENTER( "trackTable" ); GXV_TRAK_DATA( trackValueOffset_min ) = 0xFFFFU; GXV_TRAK_DATA( trackValueOffset_max ) = 0x0000; GXV_LIMIT_CHECK( nTracks * ( 4 + 2 + 2 ) ); for ( i = 0; i < nTracks; i++ ) { p = table + i * ( 4 + 2 + 2 ); track = FT_NEXT_LONG( p ); nameIndex = FT_NEXT_USHORT( p ); offset = FT_NEXT_USHORT( p ); if ( offset < GXV_TRAK_DATA( trackValueOffset_min ) ) GXV_TRAK_DATA( trackValueOffset_min ) = offset; if ( offset > GXV_TRAK_DATA( trackValueOffset_max ) ) GXV_TRAK_DATA( trackValueOffset_max ) = offset; gxv_sfntName_validate( nameIndex, 256, 32767, gxvalid ); for ( j = i; j < nTracks; j++ ) { p = table + j * ( 4 + 2 + 2 ); t = FT_NEXT_LONG( p ); if ( t == track ) GXV_TRACE(( "duplicated entries found for track value 0x%lx\n", track )); } } gxvalid->subtable_length = (FT_ULong)( p - table ); GXV_EXIT; } static void gxv_trak_trackData_validate( FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid ) { FT_Bytes p = table; FT_UShort nTracks; FT_UShort nSizes; FT_ULong sizeTableOffset; GXV_ODTECT( 4, odtect ); GXV_ODTECT_INIT( odtect ); GXV_NAME_ENTER( "trackData" ); /* read the header of trackData */ GXV_LIMIT_CHECK( 2 + 2 + 4 ); nTracks = FT_NEXT_USHORT( p ); nSizes = FT_NEXT_USHORT( p ); sizeTableOffset = FT_NEXT_ULONG( p ); gxv_odtect_add_range( table, (FT_ULong)( p - table ), "trackData header", odtect ); /* validate trackTable */ gxv_trak_trackTable_validate( p, limit, nTracks, gxvalid ); gxv_odtect_add_range( p, gxvalid->subtable_length, "trackTable", odtect ); /* sizeTable is array of FT_Fixed, don't check contents */ p = gxvalid->root->base + sizeTableOffset; GXV_LIMIT_CHECK( nSizes * 4 ); gxv_odtect_add_range( p, nSizes * 4, "sizeTable", odtect ); /* validate trackValueOffet */ p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_min ); if ( limit - p < nTracks * nSizes * 2 ) GXV_TRACE(( "too short trackValue array\n" )); p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_max ); GXV_LIMIT_CHECK( nSizes * 2 ); gxv_odtect_add_range( gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_min ), GXV_TRAK_DATA( trackValueOffset_max ) - GXV_TRAK_DATA( trackValueOffset_min ) + nSizes * 2, "trackValue array", odtect ); gxv_odtect_validate( odtect, gxvalid ); GXV_EXIT; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** trak TABLE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF( void ) gxv_trak_validate( FT_Bytes table, FT_Face face, FT_Validator ftvalid ) { FT_Bytes p = table; FT_Bytes limit = 0; GXV_ValidatorRec gxvalidrec; GXV_Validator gxvalid = &gxvalidrec; GXV_trak_DataRec trakrec; GXV_trak_Data trak = &trakrec; FT_ULong version; FT_UShort format; FT_UShort horizOffset; FT_UShort vertOffset; FT_UShort reserved; GXV_ODTECT( 3, odtect ); GXV_ODTECT_INIT( odtect ); gxvalid->root = ftvalid; gxvalid->table_data = trak; gxvalid->face = face; limit = gxvalid->root->limit; FT_TRACE3(( "validating `trak' table\n" )); GXV_INIT; GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 + 2 ); version = FT_NEXT_ULONG( p ); format = FT_NEXT_USHORT( p ); horizOffset = FT_NEXT_USHORT( p ); vertOffset = FT_NEXT_USHORT( p ); reserved = FT_NEXT_USHORT( p ); GXV_TRACE(( " (version = 0x%08lx)\n", version )); GXV_TRACE(( " (format = 0x%04x)\n", format )); GXV_TRACE(( " (horizOffset = 0x%04x)\n", horizOffset )); GXV_TRACE(( " (vertOffset = 0x%04x)\n", vertOffset )); GXV_TRACE(( " (reserved = 0x%04x)\n", reserved )); /* Version 1.0 (always:1996) */ if ( version != 0x00010000UL ) FT_INVALID_FORMAT; /* format 0 (always:1996) */ if ( format != 0x0000 ) FT_INVALID_FORMAT; GXV_32BIT_ALIGNMENT_VALIDATE( horizOffset ); GXV_32BIT_ALIGNMENT_VALIDATE( vertOffset ); /* Reserved Fixed Value (always) */ if ( reserved != 0x0000 ) FT_INVALID_DATA; /* validate trackData */ if ( 0 < horizOffset ) { gxv_trak_trackData_validate( table + horizOffset, limit, gxvalid ); gxv_odtect_add_range( table + horizOffset, gxvalid->subtable_length, "horizJustData", odtect ); } if ( 0 < vertOffset ) { gxv_trak_trackData_validate( table + vertOffset, limit, gxvalid ); gxv_odtect_add_range( table + vertOffset, gxvalid->subtable_length, "vertJustData", odtect ); } gxv_odtect_validate( odtect, gxvalid ); FT_TRACE4(( "\n" )); } /* END */
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/gxvtrak.c
C++
gpl-3.0
9,558
# # FreeType 2 gxvalid module definition # # Copyright (C) 2004-2022 by # suzuki toshiya, Masatake YAMATO, Red Hat K.K., # 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 += GXVALID_MODULE define GXVALID_MODULE $(OPEN_DRIVER) FT_Module_Class, gxv_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)gxvalid $(ECHO_DRIVER_DESC)TrueTypeGX/AAT validation module$(ECHO_DRIVER_DONE) endef # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/module.mk
mk
gpl-3.0
710
# # FreeType 2 TrueTypeGX/AAT validation driver configuration rules # # Copyright (C) 2004-2022 by # suzuki toshiya, Masatake YAMATO, Red Hat K.K., # 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. # GXV driver directory # GXV_DIR := $(SRC_DIR)/gxvalid # compilation flags for the driver # GXV_COMPILE := $(CC) $(ANSIFLAGS) \ $I$(subst /,$(COMPILER_SEP),$(GXV_DIR)) \ $(INCLUDE_FLAGS) \ $(FT_CFLAGS) # GXV driver sources (i.e., C files) # GXV_DRV_SRC := $(GXV_DIR)/gxvcommn.c \ $(GXV_DIR)/gxvfeat.c \ $(GXV_DIR)/gxvbsln.c \ $(GXV_DIR)/gxvtrak.c \ $(GXV_DIR)/gxvopbd.c \ $(GXV_DIR)/gxvprop.c \ $(GXV_DIR)/gxvjust.c \ $(GXV_DIR)/gxvmort.c \ $(GXV_DIR)/gxvmort0.c \ $(GXV_DIR)/gxvmort1.c \ $(GXV_DIR)/gxvmort2.c \ $(GXV_DIR)/gxvmort4.c \ $(GXV_DIR)/gxvmort5.c \ $(GXV_DIR)/gxvmorx.c \ $(GXV_DIR)/gxvmorx0.c \ $(GXV_DIR)/gxvmorx1.c \ $(GXV_DIR)/gxvmorx2.c \ $(GXV_DIR)/gxvmorx4.c \ $(GXV_DIR)/gxvmorx5.c \ $(GXV_DIR)/gxvlcar.c \ $(GXV_DIR)/gxvkern.c \ $(GXV_DIR)/gxvmod.c # GXV driver headers # GXV_DRV_H := $(GXV_DIR)/gxvalid.h \ $(GXV_DIR)/gxverror.h \ $(GXV_DIR)/gxvcommn.h \ $(GXV_DIR)/gxvfeat.h \ $(GXV_DIR)/gxvmod.h \ $(GXV_DIR)/gxvmort.h \ $(GXV_DIR)/gxvmorx.h # GXV driver object(s) # # GXV_DRV_OBJ_M is used during `multi' builds. # GXV_DRV_OBJ_S is used during `single' builds. # GXV_DRV_OBJ_M := $(GXV_DRV_SRC:$(GXV_DIR)/%.c=$(OBJ_DIR)/%.$O) GXV_DRV_OBJ_S := $(OBJ_DIR)/gxvalid.$O # GXV driver source file for single build # GXV_DRV_SRC_S := $(GXV_DIR)/gxvalid.c # GXV driver - single object # $(GXV_DRV_OBJ_S): $(GXV_DRV_SRC_S) $(GXV_DRV_SRC) \ $(FREETYPE_H) $(GXV_DRV_H) $(GXV_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(GXV_DRV_SRC_S)) # GXV driver - multiple objects # $(OBJ_DIR)/%.$O: $(GXV_DIR)/%.c $(FREETYPE_H) $(GXV_DRV_H) $(GXV_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) # update main driver object lists # DRV_OBJS_S += $(GXV_DRV_OBJ_S) DRV_OBJS_M += $(GXV_DRV_OBJ_M) # EOF
whupdup/frame
real/third_party/freetype-2.12.0/src/gxvalid/rules.mk
mk
gpl-3.0
2,759
Name: zlib Short Name: zlib URL: http://zlib.net/ Version: 1.2.11 License: see `zlib.h` Description: "A massively spiffy yet delicately unobtrusive compression library." 'zlib' is a free, general-purpose, legally unencumbered lossless data-compression library. 'zlib' implements the "deflate" compression algorithm described by RFC 1951, which combines the LZ77 (Lempel-Ziv) algorithm with Huffman coding. zlib also implements the zlib (RFC 1950) and gzip (RFC 1952) wrapper formats. Local Modifications: The files in this directory have been prepared as follows. - Take the unmodified source code files from the zlib distribution that are included by `ftgzip.c`. - Run zlib's `zlib2ansi` script on all `.c` files. - Apply the diff file(s) in the `patches` folder.
whupdup/frame
real/third_party/freetype-2.12.0/src/gzip/README.freetype
freetype
gpl-3.0
778
/* adler32.c -- compute the Adler-32 checksum of a data stream * Copyright (C) 1995-2011, 2016 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ /* @(#) $Id$ */ #include "zutil.h" #ifndef Z_FREETYPE local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); #endif #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); #define DO16(buf) DO8(buf,0); DO8(buf,8); /* use NO_DIVIDE if your processor does not do division in hardware -- try it both ways to see which is faster */ #ifdef NO_DIVIDE /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 (thank you to John Reiser for pointing this out) */ # define CHOP(a) \ do { \ unsigned long tmp = a >> 16; \ a &= 0xffffUL; \ a += (tmp << 4) - tmp; \ } while (0) # define MOD28(a) \ do { \ CHOP(a); \ if (a >= BASE) a -= BASE; \ } while (0) # define MOD(a) \ do { \ CHOP(a); \ MOD28(a); \ } while (0) # define MOD63(a) \ do { /* this assumes a is not negative */ \ z_off64_t tmp = a >> 32; \ a &= 0xffffffffL; \ a += (tmp << 8) - (tmp << 5) + tmp; \ tmp = a >> 16; \ a &= 0xffffL; \ a += (tmp << 4) - tmp; \ tmp = a >> 16; \ a &= 0xffffL; \ a += (tmp << 4) - tmp; \ if (a >= BASE) a -= BASE; \ } while (0) #else # define MOD(a) a %= BASE # define MOD28(a) a %= BASE # define MOD63(a) a %= BASE #endif /* ========================================================================= */ uLong ZEXPORT adler32_z( uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; /* split Adler-32 into component sums */ sum2 = (adler >> 16) & 0xffff; adler &= 0xffff; /* in case user likes doing a byte at a time, keep it fast */ if (len == 1) { adler += buf[0]; if (adler >= BASE) adler -= BASE; sum2 += adler; if (sum2 >= BASE) sum2 -= BASE; return adler | (sum2 << 16); } /* initial Adler-32 value (deferred check for len == 1 speed) */ if (buf == Z_NULL) return 1L; /* in case short lengths are provided, keep it somewhat fast */ if (len < 16) { while (len--) { adler += *buf++; sum2 += adler; } if (adler >= BASE) adler -= BASE; MOD28(sum2); /* only added so many BASE's */ return adler | (sum2 << 16); } /* do length NMAX blocks -- requires just one modulo operation */ while (len >= NMAX) { len -= NMAX; n = NMAX / 16; /* NMAX is divisible by 16 */ do { DO16(buf); /* 16 sums unrolled */ buf += 16; } while (--n); MOD(adler); MOD(sum2); } /* do remaining bytes (less than NMAX, still just one modulo) */ if (len) { /* avoid modulos if none remaining */ while (len >= 16) { len -= 16; DO16(buf); buf += 16; } while (len--) { adler += *buf++; sum2 += adler; } MOD(adler); MOD(sum2); } /* return recombined sums */ return adler | (sum2 << 16); } /* ========================================================================= */ uLong ZEXPORT adler32( uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } #ifndef Z_FREETYPE /* ========================================================================= */ local uLong adler32_combine_( uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; /* for negative len, return invalid adler32 as a clue for debugging */ if (len2 < 0) return 0xffffffffUL; /* the derivation of this formula is left as an exercise for the reader */ MOD63(len2); /* assumes len2 >= 0 */ rem = (unsigned)len2; sum1 = adler1 & 0xffff; sum2 = rem * sum1; MOD(sum2); sum1 += (adler2 & 0xffff) + BASE - 1; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE; if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1); if (sum2 >= BASE) sum2 -= BASE; return sum1 | (sum2 << 16); } /* ========================================================================= */ uLong ZEXPORT adler32_combine( uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } uLong ZEXPORT adler32_combine64( uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } #endif /* !Z_FREETYPE */
whupdup/frame
real/third_party/freetype-2.12.0/src/gzip/adler32.c
C++
gpl-3.0
5,182
/* crc32.c -- compute the CRC-32 of a data stream * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h * * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing * tables for updating the shift register in one step with three exclusive-ors * instead of four steps with four exclusive-ors. This results in about a * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. */ /* @(#) $Id$ */ /* Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore protection on the static variables used to control the first-use generation of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should first call get_crc_table() to initialize the tables before allowing more than one thread to use crc32(). DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. */ #ifdef MAKECRCH # include <stdio.h> # ifndef DYNAMIC_CRC_TABLE # define DYNAMIC_CRC_TABLE # endif /* !DYNAMIC_CRC_TABLE */ #endif /* MAKECRCH */ #include "zutil.h" /* for STDC and FAR definitions */ /* Definitions for doing the crc four data bytes at a time. */ #if !defined(NOBYFOUR) && defined(Z_U4) # define BYFOUR #endif #ifdef BYFOUR local unsigned long crc32_little OF((unsigned long, const unsigned char FAR *, z_size_t)); local unsigned long crc32_big OF((unsigned long, const unsigned char FAR *, z_size_t)); # define TBLS 8 #else # define TBLS 1 #endif /* BYFOUR */ /* Local functions for crc concatenation */ local unsigned long gf2_matrix_times OF((unsigned long *mat, unsigned long vec)); local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); #ifdef DYNAMIC_CRC_TABLE local volatile int crc_table_empty = 1; local z_crc_t FAR crc_table[TBLS][256]; local void make_crc_table OF((void)); #ifdef MAKECRCH local void write_table OF((FILE *, const z_crc_t FAR *)); #endif /* MAKECRCH */ /* Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. Polynomials over GF(2) are represented in binary, one bit per coefficient, with the lowest powers in the most significant bit. Then adding polynomials is just exclusive-or, and multiplying a polynomial by x is a right shift by one. If we call the above polynomial p, and represent a byte as the polynomial q, also with the lowest power in the most significant bit (so the byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, where a mod b means the remainder after dividing a by b. This calculation is done using the shift-register method of multiplying and taking the remainder. The register is initialized to zero, and for each incoming bit, x^32 is added mod p to the register if the bit is a one (where x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x (which is shifting right by one and adding x^32 mod p if the bit shifted out is a one). We start with the highest power (least significant bit) of q and repeat for all eight bits of q. The first table is simply the CRC of all possible eight bit values. This is all the information needed to generate CRCs on data a byte at a time for all combinations of CRC register values and incoming bytes. The remaining tables allow for word-at-a-time CRC calculation for both big-endian and little- endian machines, where a word is four bytes. */ local void make_crc_table() { z_crc_t c; int n, k; z_crc_t poly; /* polynomial exclusive-or pattern */ /* terms of polynomial defining this crc (except x^32): */ static volatile int first = 1; /* flag to limit concurrent making */ static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; /* See if another task is already doing this (not thread-safe, but better than nothing -- significantly reduces duration of vulnerability in case the advice about DYNAMIC_CRC_TABLE is ignored) */ if (first) { first = 0; /* make exclusive-or pattern from polynomial (0xedb88320UL) */ poly = 0; for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) poly |= (z_crc_t)1 << (31 - p[n]); /* generate a crc for every 8-bit value */ for (n = 0; n < 256; n++) { c = (z_crc_t)n; for (k = 0; k < 8; k++) c = c & 1 ? poly ^ (c >> 1) : c >> 1; crc_table[0][n] = c; } #ifdef BYFOUR /* generate crc for each value followed by one, two, and three zeros, and then the byte reversal of those as well as the first table */ for (n = 0; n < 256; n++) { c = crc_table[0][n]; crc_table[4][n] = ZSWAP32(c); for (k = 1; k < 4; k++) { c = crc_table[0][c & 0xff] ^ (c >> 8); crc_table[k][n] = c; crc_table[k + 4][n] = ZSWAP32(c); } } #endif /* BYFOUR */ crc_table_empty = 0; } else { /* not first */ /* wait for the other guy to finish (not efficient, but rare) */ while (crc_table_empty) ; } #ifdef MAKECRCH /* write out CRC tables to crc32.h */ { FILE *out; out = fopen("crc32.h", "w"); if (out == NULL) return; fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); fprintf(out, "local const z_crc_t FAR "); fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); write_table(out, crc_table[0]); # ifdef BYFOUR fprintf(out, "#ifdef BYFOUR\n"); for (k = 1; k < 8; k++) { fprintf(out, " },\n {\n"); write_table(out, crc_table[k]); } fprintf(out, "#endif\n"); # endif /* BYFOUR */ fprintf(out, " }\n};\n"); fclose(out); } #endif /* MAKECRCH */ } #ifdef MAKECRCH local void write_table( FILE *out, const z_crc_t FAR *table) { int n; for (n = 0; n < 256; n++) fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", (unsigned long)(table[n]), n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); } #endif /* MAKECRCH */ #else /* !DYNAMIC_CRC_TABLE */ /* ======================================================================== * Tables of CRC-32s of all single-byte values, made by make_crc_table(). */ #include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ /* ========================================================================= * This function can be used by asm versions of crc32() */ const z_crc_t FAR * ZEXPORT get_crc_table() { #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) make_crc_table(); #endif /* DYNAMIC_CRC_TABLE */ return (const z_crc_t FAR *)crc_table; } /* ========================================================================= */ #undef DO1 #undef DO8 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 /* ========================================================================= */ unsigned long ZEXPORT crc32_z( unsigned long crc, const unsigned char FAR *buf, z_size_t len) { if (buf == Z_NULL) return 0UL; #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) make_crc_table(); #endif /* DYNAMIC_CRC_TABLE */ #ifdef BYFOUR if (sizeof(void *) == sizeof(ptrdiff_t)) { z_crc_t endian; endian = 1; if (*((unsigned char *)(&endian))) return crc32_little(crc, buf, len); else return crc32_big(crc, buf, len); } #endif /* BYFOUR */ crc = crc ^ 0xffffffffUL; while (len >= 8) { DO8; len -= 8; } if (len) do { DO1; } while (--len); return crc ^ 0xffffffffUL; } /* ========================================================================= */ unsigned long ZEXPORT crc32( unsigned long crc, const unsigned char FAR *buf, uInt len) { return crc32_z(crc, buf, len); } #ifdef BYFOUR /* This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit integer pointer type. This violates the strict aliasing rule, where a compiler can assume, for optimization purposes, that two pointers to fundamentally different types won't ever point to the same memory. This can manifest as a problem only if one of the pointers is written to. This code only reads from those pointers. So long as this code remains isolated in this compilation unit, there won't be a problem. For this reason, this code should not be copied and pasted into a compilation unit in which other code writes to the buffer that is passed to these routines. */ /* ========================================================================= */ #define DOLIT4 c ^= *buf4++; \ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 /* ========================================================================= */ local unsigned long crc32_little( unsigned long crc, const unsigned char FAR *buf, z_size_t len) { register z_crc_t c; register const z_crc_t FAR *buf4; c = (z_crc_t)crc; c = ~c; while (len && ((ptrdiff_t)buf & 3)) { c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); len--; } buf4 = (const z_crc_t FAR *)(const void FAR *)buf; while (len >= 32) { DOLIT32; len -= 32; } while (len >= 4) { DOLIT4; len -= 4; } buf = (const unsigned char FAR *)buf4; if (len) do { c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); } while (--len); c = ~c; return (unsigned long)c; } /* ========================================================================= */ #define DOBIG4 c ^= *buf4++; \ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 /* ========================================================================= */ local unsigned long crc32_big( unsigned long crc, const unsigned char FAR *buf, z_size_t len) { register z_crc_t c; register const z_crc_t FAR *buf4; c = ZSWAP32((z_crc_t)crc); c = ~c; while (len && ((ptrdiff_t)buf & 3)) { c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); len--; } buf4 = (const z_crc_t FAR *)(const void FAR *)buf; while (len >= 32) { DOBIG32; len -= 32; } while (len >= 4) { DOBIG4; len -= 4; } buf = (const unsigned char FAR *)buf4; if (len) do { c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); } while (--len); c = ~c; return (unsigned long)(ZSWAP32(c)); } #endif /* BYFOUR */ #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ /* ========================================================================= */ local unsigned long gf2_matrix_times( unsigned long *mat, unsigned long vec) { unsigned long sum; sum = 0; while (vec) { if (vec & 1) sum ^= *mat; vec >>= 1; mat++; } return sum; } /* ========================================================================= */ local void gf2_matrix_square( unsigned long *square, unsigned long *mat) { int n; for (n = 0; n < GF2_DIM; n++) square[n] = gf2_matrix_times(mat, mat[n]); } /* ========================================================================= */ local uLong crc32_combine_( uLong crc1, uLong crc2, z_off64_t len2) { int n; unsigned long row; unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ /* degenerate case (also disallow negative lengths) */ if (len2 <= 0) return crc1; /* put operator for one zero bit in odd */ odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ row = 1; for (n = 1; n < GF2_DIM; n++) { odd[n] = row; row <<= 1; } /* put operator for two zero bits in even */ gf2_matrix_square(even, odd); /* put operator for four zero bits in odd */ gf2_matrix_square(odd, even); /* apply len2 zeros to crc1 (first square will put the operator for one zero byte, eight zero bits, in even) */ do { /* apply zeros operator for this bit of len2 */ gf2_matrix_square(even, odd); if (len2 & 1) crc1 = gf2_matrix_times(even, crc1); len2 >>= 1; /* if no more bits set, then done */ if (len2 == 0) break; /* another iteration of the loop with odd and even swapped */ gf2_matrix_square(odd, even); if (len2 & 1) crc1 = gf2_matrix_times(odd, crc1); len2 >>= 1; /* if no more bits set, then done */ } while (len2 != 0); /* return combined crc */ crc1 ^= crc2; return crc1; } /* ========================================================================= */ uLong ZEXPORT crc32_combine( uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine_(crc1, crc2, len2); } uLong ZEXPORT crc32_combine64( uLong crc1, uLong crc2, z_off64_t len2) { return crc32_combine_(crc1, crc2, len2); }
whupdup/frame
real/third_party/freetype-2.12.0/src/gzip/crc32.c
C++
gpl-3.0
13,936
/* crc32.h -- tables for rapid CRC calculation * Generated automatically by crc32.c */ local const z_crc_t FAR crc_table[TBLS][256] = { { 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 0x2d02ef8dUL #ifdef BYFOUR }, { 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, 0x9324fd72UL }, { 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, 0xbe9834edUL }, { 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, 0xde0506f1UL }, { 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, 0x8def022dUL }, { 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, 0x72fd2493UL }, { 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, 0xed3498beUL }, { 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, 0xf10605deUL #endif } };
whupdup/frame
real/third_party/freetype-2.12.0/src/gzip/crc32.h
C++
gpl-3.0
30,562