TT_Error Load_TrueType_MaxProfile( PFace face ) { ttfReader *r = face->r; ttfFont *font = face->font; PMaxProfile maxProfile = &face->maxProfile; r->Seek(r, font->t_maxp.nPos); DebugTrace(font, "MaxProfile " ); /* read frame data into face table */ maxProfile->version = GET_ULong(); maxProfile->numGlyphs = GET_UShort(); maxProfile->maxPoints = GET_UShort(); maxProfile->maxContours = GET_UShort(); maxProfile->maxCompositePoints = GET_UShort(); maxProfile->maxCompositeContours = GET_UShort(); maxProfile->maxZones = GET_UShort(); maxProfile->maxTwilightPoints = GET_UShort(); maxProfile->maxStorage = GET_UShort(); maxProfile->maxFunctionDefs = GET_UShort(); maxProfile->maxInstructionDefs = GET_UShort(); maxProfile->maxStackElements = GET_UShort(); maxProfile->maxSizeOfInstructions = GET_UShort(); maxProfile->maxComponentElements = GET_UShort(); maxProfile->maxComponentDepth = GET_UShort(); face->numGlyphs = maxProfile->numGlyphs; face->maxPoints = MAX( maxProfile->maxCompositePoints, maxProfile->maxPoints ); face->maxContours = MAX( maxProfile->maxCompositeContours, maxProfile->maxContours ); face->maxComponents = maxProfile->maxComponentElements + maxProfile->maxComponentDepth; DebugTrace(font, "loaded\n"); return TT_Err_Ok; }
static FT_Error GDEF_Create( void* ext, PFace face ) { DEFINE_LOAD_LOCALS( face->stream ); HB_GDEFHeader* gdef = (HB_GDEFHeader*)ext; Long table; /* by convention */ if ( !gdef ) return FT_Err_Ok; /* a null offset indicates that there is no GDEF table */ gdef->offset = 0; /* we store the start offset and the size of the subtable */ table = HB_LookUp_Table( face, TTAG_GDEF ); if ( table < 0 ) return FT_Err_Ok; /* The table is optional */ if ( FILE_Seek( face->dirTables[table].Offset ) || ACCESS_Frame( 4L ) ) return error; gdef->offset = FILE_Pos() - 4L; /* undo ACCESS_Frame() */ gdef->Version = GET_ULong(); FORGET_Frame(); gdef->loaded = FALSE; return FT_Err_Ok; }
BASE_FUNC(FT_Error) FT_Read_Fields(FT_Stream stream, const FT_Frame_Field *fields, void *structure) { FT_Error error; FT_Bool frame_accessed = 0; if(!fields || !stream) { return FT_Err_Invalid_Argument; } error = FT_Err_Ok; do { FT_ULong value; FT_Int sign_shift; FT_Byte *p; switch(fields->value) { case ft_frame_start: /* access a new frame */ error = FT_Access_Frame(stream, fields->offset); if(error) { goto Exit; } frame_accessed = 1; fields++; continue; /* loop! */ case ft_frame_bytes: /* read a byte sequence */ case ft_frame_skip: /* skip some bytes */ { FT_Int len = fields->size; if(stream->cursor + len > stream->limit) { error = FT_Err_Invalid_Stream_Operation; goto Exit; } if(fields->value == ft_frame_bytes) { p = (FT_Byte *)structure + fields->offset; MEM_Copy(p, stream->cursor, len); } stream->cursor += len; fields++; continue; } case ft_frame_byte: case ft_frame_schar: /* read a single byte */ value = GET_Byte(); sign_shift = 24; break; case ft_frame_short_be: case ft_frame_ushort_be: /* read a 2-byte big-endian short */ value = GET_UShort(); sign_shift = 16; break; case ft_frame_short_le: case ft_frame_ushort_le: /* read a 2-byte little-endian short */ { FT_Byte *p; value = 0; p = stream->cursor; if(p + 1 < stream->limit) { value = (FT_UShort)p[0] | ((FT_UShort)p[1] << 8); stream->cursor += 2; } sign_shift = 16; break; } case ft_frame_long_be: case ft_frame_ulong_be: /* read a 4-byte big-endian long */ value = GET_ULong(); sign_shift = 0; break; case ft_frame_long_le: case ft_frame_ulong_le: /* read a 4-byte little-endian long */ { FT_Byte *p; value = 0; p = stream->cursor; if(p + 3 < stream->limit) { value = (FT_ULong)p[0] | ((FT_ULong)p[1] << 8) | ((FT_ULong)p[2] << 16) | ((FT_ULong)p[3] << 24); stream->cursor += 4; } sign_shift = 0; break; } case ft_frame_off3_be: case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ value = GET_UOffset(); sign_shift = 8; break; case ft_frame_off3_le: case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ { FT_Byte *p; value = 0; p = stream->cursor; if(p + 2 < stream->limit) { value = (FT_ULong)p[0] | ((FT_ULong)p[1] << 8) | ((FT_ULong)p[2] << 16); stream->cursor += 3; } sign_shift = 8; break; } default: /* otherwise, exit the loop */ goto Exit; } /* now, compute the signed value is necessary */ if(fields->value & FT_FRAME_OP_SIGNED) { value = (FT_ULong)((FT_Int32)(value << sign_shift) >> sign_shift); } /* finally, store the value in the object */ p = (FT_Byte *)structure + fields->offset; switch(fields->size) { case 1: *(FT_Byte *)p = (FT_Byte)value; break; case 2: *(FT_UShort *)p = (FT_UShort)value; break; case 4: *(FT_UInt32 *)p = (FT_UInt32)value; break; default: /* for 64-bit systems */ *(FT_ULong *)p = (FT_ULong)value; } /* go to next field */ fields++; }