📄 psobjs.c
字号:
FT_Long result = 0; FT_Byte* cur = *cursor; FT_Byte c = '\0', d; for ( ; cur < limit; cur++ ) { c = *cur; d = (FT_Byte)( c - '0' ); if ( d < 10 ) break; if ( c == '-' ) { cur++; break; } } if ( cur < limit ) { do { d = (FT_Byte)( cur[0] - '0' ); if ( d >= 10 ) { if ( cur[0] == '#' ) { cur++; result = T1Radix( result, &cur, limit ); } break; } result = result * 10 + d; cur++; } while ( cur < limit ); if ( c == '-' ) result = -result; } *cursor = cur; return result; } /* <...>: hexadecimal string */ static FT_Error ps_tobytes( FT_Byte** cursor, FT_Byte* limit, FT_Int max_bytes, FT_Byte* bytes, FT_Int* pnum_bytes ) { FT_Error error = PSaux_Err_Ok; FT_Byte* cur = *cursor; FT_Int n = 0; FT_Byte b; skip_spaces( &cur, limit ); if ( *cur != '<' ) { error = PSaux_Err_Invalid_File_Format; goto Exit; } cur++; for ( ; cur < limit; n++ ) { FT_Byte* cur2 = cur; if ( n + 1 > max_bytes * 2 ) goto Exit; /* All white-space charcters are ignored. */ skip_spaces( &cur, limit ); b = T1Radix( 16, &cur, cur + 1 ); if ( cur == cur2 ) break; /* <f> == <f0> != <0f> */ bytes[n / 2] = ( n % 2 ) ? bytes[n / 2] + b : b * 16; } skip_spaces( &cur, limit ); if ( *cur != '>' ) { error = PSaux_Err_Invalid_File_Format; goto Exit; } *cursor = ++cur; Exit: *pnum_bytes = ( n + 1 ) / 2; return error; } static FT_Long t1_tofixed( FT_Byte** cursor, FT_Byte* limit, FT_Long power_ten ) { FT_Byte* cur = *cursor; FT_Long num, divider, result; FT_Int sign = 0; FT_Byte d; if ( cur >= limit ) return 0; /* first of all, check the sign */ if ( *cur == '-' ) { sign = 1; cur++; } /* then, read the integer part, if any */ if ( *cur != '.' ) result = t1_toint( &cur, limit ) << 16; else result = 0; num = 0; divider = 1; if ( cur >= limit ) goto Exit; /* read decimal part, if any */ if ( *cur == '.' && cur + 1 < limit ) { cur++; for (;;) { d = (FT_Byte)( *cur - '0' ); if ( d >= 10 ) break; if ( divider < 10000000L ) { num = num * 10 + d; divider *= 10; } cur++; if ( cur >= limit ) break; } } /* read exponent, if any */ if ( cur + 1 < limit && ( *cur == 'e' || *cur == 'E' ) ) { cur++; power_ten += t1_toint( &cur, limit ); } Exit: /* raise to power of ten if needed */ while ( power_ten > 0 ) { result = result * 10; num = num * 10; power_ten--; } while ( power_ten < 0 ) { result = result / 10; divider = divider * 10; power_ten++; } if ( num ) result += FT_DivFix( num, divider ); if ( sign ) result = -result; *cursor = cur; return result; } static FT_Int t1_tocoordarray( FT_Byte** cursor, FT_Byte* limit, FT_Int max_coords, FT_Short* coords ) { FT_Byte* cur = *cursor; FT_Int count = 0; FT_Byte c, ender; if ( cur >= limit ) goto Exit; /* check for the beginning of an array; if not, only one number will */ /* be read */ c = *cur; ender = 0; if ( c == '[' ) ender = ']'; if ( c == '{' ) ender = '}'; if ( ender ) cur++; /* now, read the coordinates */ for ( ; cur < limit; ) { /* skip whitespace in front of data */ for (;;) { c = *cur; if ( c != ' ' && c != '\t' ) break; cur++; if ( cur >= limit ) goto Exit; } if ( count >= max_coords || c == ender ) break; coords[count] = (FT_Short)( t1_tofixed( &cur, limit, 0 ) >> 16 ); count++; if ( !ender ) break; } Exit: *cursor = cur; return count; } static FT_Int t1_tofixedarray( FT_Byte** cursor, FT_Byte* limit, FT_Int max_values, FT_Fixed* values, FT_Int power_ten ) { FT_Byte* cur = *cursor; FT_Int count = 0; FT_Byte c, ender; if ( cur >= limit ) goto Exit; /* check for the beginning of an array. If not, only one number will */ /* be read */ c = *cur; ender = 0; if ( c == '[' ) ender = ']'; if ( c == '{' ) ender = '}'; if ( ender ) cur++; /* now, read the values */ for ( ; cur < limit; ) { /* skip whitespace in front of data */ for (;;) { c = *cur; if ( c != ' ' && c != '\t' ) break; cur++; if ( cur >= limit ) goto Exit; } if ( count >= max_values || c == ender ) break; values[count] = t1_tofixed( &cur, limit, power_ten ); count++; if ( !ender ) break; } Exit: *cursor = cur; return count; }#if 0 static FT_String* t1_tostring( FT_Byte** cursor, FT_Byte* limit, FT_Memory memory ) { FT_Byte* cur = *cursor; FT_PtrDist len = 0; FT_Int count; FT_String* result; FT_Error error; /* XXX: some stupid fonts have a `Notice' or `Copyright' string */ /* that simply doesn't begin with an opening parenthesis, even */ /* though they have a closing one! E.g. "amuncial.pfb" */ /* */ /* We must deal with these ill-fated cases there. Note that */ /* these fonts didn't work with the old Type 1 driver as the */ /* notice/copyright was not recognized as a valid string token */ /* and made the old token parser commit errors. */ while ( cur < limit && ( *cur == ' ' || *cur == '\t' ) ) cur++; if ( cur + 1 >= limit ) return 0; if ( *cur == '(' ) cur++; /* skip the opening parenthesis, if there is one */ *cursor = cur; count = 0; /* then, count its length */ for ( ; cur < limit; cur++ ) { if ( *cur == '(' ) count++; else if ( *cur == ')' ) { count--; if ( count < 0 ) break; } } len = cur - *cursor; if ( cur >= limit || FT_ALLOC( result, len + 1 ) ) return 0; /* now copy the string */ FT_MEM_COPY( result, *cursor, len ); result[len] = '\0'; *cursor = cur; return result; }#endif /* 0 */ static int t1_tobool( FT_Byte** cursor, FT_Byte* limit ) { FT_Byte* cur = *cursor; FT_Bool result = 0; /* return 1 if we find `true', 0 otherwise */ if ( cur + 3 < limit && cur[0] == 't' && cur[1] == 'r' && cur[2] == 'u' && cur[3] == 'e' ) { result = 1; cur += 5; } else if ( cur + 4 < limit && cur[0] == 'f' && cur[1] == 'a' && cur[2] == 'l' && cur[3] == 's' && cur[4] == 'e' ) { result = 0; cur += 6; } *cursor = cur; return result; } /* Load a simple field (i.e. non-table) into the current list of objects */ FT_LOCAL_DEF( FT_Error ) ps_parser_load_field( PS_Parser parser, const T1_Field field, void** objects, FT_UInt max_objects, FT_ULong* pflags ) { T1_TokenRec token; FT_Byte* cur; FT_Byte* limit; FT_UInt count; FT_UInt idx; FT_Error error; ps_parser_to_token( parser, &token ); if ( !token.type ) goto Fail; count = 1; idx = 0; cur = token.start; limit = token.limit; /* we must detect arrays */ if ( field->type == T1_FIELD_TYPE_BBOX ) { T1_TokenRec token2; FT_Byte* old_cur = parser->cursor; FT_Byte* old_limit = parser->limit; parser->cursor = token.start; parser->limit = token.limit; ps_parser_to_token( parser, &token2 ); parser->cursor = old_cur; parser->limit = old_limit; if ( token2.type == T1_TOKEN_TYPE_ARRAY ) goto FieldArray; } else if ( token.type == T1_TOKEN_TYPE_ARRAY ) { FieldArray: /* if this is an array, and we have no blend, an error occurs */ if ( max_objects == 0 ) goto Fail; count = max_objects; idx = 1; } for ( ; count > 0; count--, idx++ ) { FT_Byte* q = (FT_Byte*)objects[idx] + field->offset; FT_Long val; FT_String* string; switch ( field->type ) { case T1_FIELD_TYPE_BOOL: val = t1_tobool( &cur, limit ); goto Store_Integer; case T1_FIELD_TYPE_FIXED: val = t1_tofixed( &cur, limit, 0 ); goto Store_Integer; case T1_FIELD_TYPE_FIXED_1000: val = t1_tofixed( &cur, limit, 3 ); goto Store_Integer; case T1_FIELD_TYPE_INTEGER: val = t1_toint( &cur, limit ); goto Store_Integer; Store_Integer: switch ( field->size ) { case 1: *(FT_Byte*)q = (FT_Byte)val; break; case 2: *(FT_UShort*)q = (FT_UShort)val; break; case 4: *(FT_UInt32*)q = (FT_UInt32)val;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -