/* * PROPERTY SERVICE * */ static FT_Error tt_property_set( FT_Module module, /* TT_Driver */ const char* property_name, const void* value, FT_Bool value_is_string ) { FT_Error error = FT_Err_Ok; TT_Driver driver = (TT_Driver)module; #ifndef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES FT_UNUSED( value_is_string ); #endif if ( !ft_strcmp( property_name, "interpreter-version" ) ) { FT_UInt interpreter_version; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) { const char* s = (const char*)value; interpreter_version = (FT_UInt)ft_strtol( s, NULL, 10 ); } else #endif { FT_UInt* iv = (FT_UInt*)value; interpreter_version = *iv; } if ( interpreter_version == TT_INTERPRETER_VERSION_35 #ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY || interpreter_version == TT_INTERPRETER_VERSION_38 #endif #ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL || interpreter_version == TT_INTERPRETER_VERSION_40 #endif ) driver->interpreter_version = interpreter_version; else error = FT_ERR( Unimplemented_Feature ); return error; } FT_TRACE0(( "tt_property_set: missing property `%s'\n", property_name )); return FT_THROW( Missing_Property ); }
t_rgb ft_create_rgb(char *col) { t_rgb rgbtosend; t_color collu; collu = ft_strtol(col); rgbtosend.r = (collu & 0xFF0000) >> 16; rgbtosend.g = (collu & 0xFF00) >> 8; rgbtosend.b = (collu & 0xFF); return (rgbtosend); }
int ft_atoi(char *str) { long int n; char *endptr; n = ft_strtol(str, &endptr); if (n > 0 && n > INT_MAX) return (0); else if (n < 0 && n < INT_MIN) return (0); return ((int)n); }
T42_GlyphSlot_Load( FT_GlyphSlot glyph, FT_Size size, FT_UInt glyph_index, FT_Int32 load_flags ) { FT_Error error; T42_GlyphSlot t42slot = (T42_GlyphSlot)glyph; T42_Size t42size = (T42_Size)size; T42_Face t42face = (T42_Face)size->face; FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz; FT_TRACE1(( "T42_GlyphSlot_Load: glyph index %d\n", glyph_index )); /* map T42 glyph index to embedded TTF's glyph index */ glyph_index = (FT_UInt)ft_strtol( (const char *)t42face->type1.charstrings[glyph_index], NULL, 10 ); t42_glyphslot_clear( t42slot->ttslot ); error = ttclazz->load_glyph( t42slot->ttslot, t42size->ttsize, glyph_index, load_flags | FT_LOAD_NO_BITMAP ); if ( !error ) { glyph->metrics = t42slot->ttslot->metrics; glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance; glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance; glyph->format = t42slot->ttslot->format; glyph->outline = t42slot->ttslot->outline; glyph->bitmap = t42slot->ttslot->bitmap; glyph->bitmap_left = t42slot->ttslot->bitmap_left; glyph->bitmap_top = t42slot->ttslot->bitmap_top; glyph->num_subglyphs = t42slot->ttslot->num_subglyphs; glyph->subglyphs = t42slot->ttslot->subglyphs; glyph->control_data = t42slot->ttslot->control_data; glyph->control_len = t42slot->ttslot->control_len; } return error; }
extern FT_Int ft_mem_debug_init( FT_Memory memory ) { FT_MemTable table; FT_Int result = 0; if ( ft_getenv( "FT2_DEBUG_MEMORY" ) ) { table = ft_mem_table_new( memory ); if ( table ) { const char* p; memory->user = table; memory->alloc = ft_mem_debug_alloc; memory->realloc = ft_mem_debug_realloc; memory->free = ft_mem_debug_free; p = ft_getenv( "FT2_ALLOC_TOTAL_MAX" ); if ( p ) { FT_Long total_max = ft_strtol( p, NULL, 10 ); if ( total_max > 0 ) { table->bound_total = 1; table->alloc_total_max = total_max; } } p = ft_getenv( "FT2_ALLOC_COUNT_MAX" ); if ( p ) { FT_Long total_count = ft_strtol( p, NULL, 10 ); if ( total_count > 0 ) { table->bound_count = 1; table->alloc_count_max = total_count; } } p = ft_getenv( "FT2_KEEP_ALIVE" ); if ( p ) { FT_Long keep_alive = ft_strtol( p, NULL, 10 ); if ( keep_alive > 0 ) table->keep_alive = 1; } result = 1; } } return result; }
static FT_Error af_property_set( FT_Module ft_module, const char* property_name, const void* value, FT_Bool value_is_string ) { FT_Error error = FT_Err_Ok; AF_Module module = (AF_Module)ft_module; #ifndef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES FT_UNUSED( value_is_string ); #endif if ( !ft_strcmp( property_name, "fallback-script" ) ) { FT_UInt* fallback_script; FT_UInt ss; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) return FT_THROW( Invalid_Argument ); #endif fallback_script = (FT_UInt*)value; /* We translate the fallback script to a fallback style that uses */ /* `fallback-script' as its script and `AF_COVERAGE_NONE' as its */ /* coverage value. */ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ ) { AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss]; if ( (FT_UInt)style_class->script == *fallback_script && style_class->coverage == AF_COVERAGE_DEFAULT ) { module->fallback_style = ss; break; } } if ( !AF_STYLE_CLASSES_GET[ss] ) { FT_TRACE0(( "af_property_set: Invalid value %d for property `%s'\n", fallback_script, property_name )); return FT_THROW( Invalid_Argument ); } return error; } else if ( !ft_strcmp( property_name, "default-script" ) ) { FT_UInt* default_script; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) return FT_THROW( Invalid_Argument ); #endif default_script = (FT_UInt*)value; module->default_script = *default_script; return error; } else if ( !ft_strcmp( property_name, "increase-x-height" ) ) { FT_Prop_IncreaseXHeight* prop; AF_FaceGlobals globals; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) return FT_THROW( Invalid_Argument ); #endif prop = (FT_Prop_IncreaseXHeight*)value; error = af_property_get_face_globals( prop->face, &globals, module ); if ( !error ) globals->increase_x_height = prop->limit; return error; } #ifdef AF_CONFIG_OPTION_USE_WARPER else if ( !ft_strcmp( property_name, "warping" ) ) { #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) { const char* s = (const char*)value; long w = ft_strtol( s, NULL, 10 ); if ( w == 0 ) module->warping = 0; else if ( w == 1 ) module->warping = 1; else return FT_THROW( Invalid_Argument ); } else #endif { FT_Bool* warping = (FT_Bool*)value; module->warping = *warping; } return error; } #endif /* AF_CONFIG_OPTION_USE_WARPER */ else if ( !ft_strcmp( property_name, "darkening-parameters" ) ) { FT_Int* darken_params; FT_Int x1, y1, x2, y2, x3, y3, x4, y4; #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES FT_Int dp[8]; if ( value_is_string ) { const char* s = (const char*)value; char* ep; int i; /* eight comma-separated numbers */ for ( i = 0; i < 7; i++ ) { dp[i] = (FT_Int)ft_strtol( s, &ep, 10 ); if ( *ep != ',' || s == ep ) return FT_THROW( Invalid_Argument ); s = ep + 1; } dp[7] = (FT_Int)ft_strtol( s, &ep, 10 ); if ( !( *ep == '\0' || *ep == ' ' ) || s == ep ) return FT_THROW( Invalid_Argument ); darken_params = dp; } else #endif darken_params = (FT_Int*)value; x1 = darken_params[0]; y1 = darken_params[1]; x2 = darken_params[2]; y2 = darken_params[3]; x3 = darken_params[4]; y3 = darken_params[5]; x4 = darken_params[6]; y4 = darken_params[7]; if ( x1 < 0 || x2 < 0 || x3 < 0 || x4 < 0 || y1 < 0 || y2 < 0 || y3 < 0 || y4 < 0 || x1 > x2 || x2 > x3 || x3 > x4 || y1 > 500 || y2 > 500 || y3 > 500 || y4 > 500 ) return FT_THROW( Invalid_Argument ); module->darken_params[0] = x1; module->darken_params[1] = y1; module->darken_params[2] = x2; module->darken_params[3] = y2; module->darken_params[4] = x3; module->darken_params[5] = y3; module->darken_params[6] = x4; module->darken_params[7] = y4; return error; } else if ( !ft_strcmp( property_name, "no-stem-darkening" ) ) { #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES if ( value_is_string ) { const char* s = (const char*)value; long nsd = ft_strtol( s, NULL, 10 ); if ( nsd == 0 ) module->no_stem_darkening = 0; else if ( nsd == 1 ) module->no_stem_darkening = 1; else return FT_THROW( Invalid_Argument ); } else #endif { FT_Bool* no_stem_darkening = (FT_Bool*)value; module->no_stem_darkening = *no_stem_darkening; } return error; } FT_TRACE0(( "af_property_set: missing property `%s'\n", property_name )); return FT_THROW( Missing_Property ); }
int ft_atoi(const char *str) { return ((int)ft_strtol(str, 0, 10)); }
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 ) ) 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 = -1; /* 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; }