#include "tttypes.h"
#include "ttdebug.h"
#include "ttcalc.h"
#include "ttfile.h"
#include "tttables.h"
#include "ttobjs.h"
#include "ttmemory.h"
#include "tttags.h"
#include "ttload.h"
#undef TT_COMPONENT
#define TT_COMPONENT trace_load
#define DEFINE_LOCALS DEFINE_LOAD_LOCALS( face->stream )
#define DEFINE_LOCALS_WO_FRAME DEFINE_LOAD_LOCALS_WO_FRAME( face->stream )
EXPORT_FUNC
Long TT_LookUp_Table( PFace face,
ULong tag )
{
UShort i;
PTRACE4(( "TT_LookUp_Table( %08lx, %c%c%c%c )\n",
(Long)face,
(Char)(tag >> 24),
(Char)(tag >> 16),
(Char)(tag >> 8),
(Char)(tag) ));
for ( i = 0; i < face->numTables; i++ )
if ( face->dirTables[i].Tag == tag )
return i;
PTRACE4(( " Could not find table!\n" ));
return -1;
}
static TT_Error Load_TrueType_Collection( PFace face )
{
DEFINE_LOCALS;
ULong n;
PTRACE3(( "Load_TrueType_Collection( %08lx )\n", (long)face ));
if ( FILE_Seek ( 0L ) ||
ACCESS_Frame( 12L ) )
return error;
face->ttcHeader.Tag = GET_Tag4();
face->ttcHeader.version = GET_Long();
face->ttcHeader.DirCount = GET_Long();
FORGET_Frame();
if ( face->ttcHeader.Tag != TTAG_ttcf )
{
face->ttcHeader.Tag = 0;
face->ttcHeader.version = 0;
face->ttcHeader.DirCount = 0;
face->ttcHeader.TableDirectory = NULL;
PTRACE3(("skipped.\n"));
return TT_Err_File_Is_Not_Collection;
}
if ( ALLOC_ARRAY( face->ttcHeader.TableDirectory,
face->ttcHeader.DirCount,
ULong ) ||
ACCESS_Frame( face->ttcHeader.DirCount * 4L ) )
return error;
for ( n = 0; n < face->ttcHeader.DirCount; n++ )
face->ttcHeader.TableDirectory[n] = GET_ULong();
FORGET_Frame();
PTRACE3(( "collections directory loaded.\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Directory( PFace face, ULong faceIndex )
{
DEFINE_LOCALS;
UShort n, limit;
TTableDir tableDir;
PTableDirEntry entry;
PTRACE2(("Load_TT_Directory( %08lx, %ld )\n", (long)face, faceIndex));
error = Load_TrueType_Collection( face );
if ( error )
{
if ( error != TT_Err_File_Is_Not_Collection )
return error;
if ( faceIndex != 0 )
return error;
if ( FILE_Seek( 0L ) )
return error;
}
else
{
if ( faceIndex >= face->ttcHeader.DirCount )
return TT_Err_Invalid_Argument;
if ( FILE_Seek( face->ttcHeader.TableDirectory[faceIndex] ) )
return error;
}
if ( ACCESS_Frame( 12L ) )
return error;
tableDir.version = GET_Long();
tableDir.numTables = GET_UShort();
tableDir.searchRange = GET_UShort();
tableDir.entrySelector = GET_UShort();
tableDir.rangeShift = GET_UShort();
FORGET_Frame();
PTRACE2(( "-- Tables count : %12u\n", tableDir.numTables ));
PTRACE2(( "-- Format version : %08lx\n", tableDir.version ));
if ( tableDir.version != 0x00010000 &&
tableDir.version != 0x74727565 &&
tableDir.version != 0x00000000 )
{
PERROR(( "!! invalid file format" ));
return TT_Err_Invalid_File_Format;
}
face->numTables = tableDir.numTables;
if ( ALLOC_ARRAY( face->dirTables,
face->numTables,
TTableDirEntry ) )
return error;
if ( ACCESS_Frame( face->numTables * 16L ) )
return error;
limit = face->numTables;
entry = face->dirTables;
for ( n = 0; n < limit; n++ )
{
entry->Tag = GET_Tag4();
entry->CheckSum = GET_ULong();
entry->Offset = GET_Long();
entry->Length = GET_Long();
PTRACE2(( " %c%c%c%c - %08lx - %08lx\n",
(Char)(entry->Tag >> 24),
(Char)(entry->Tag >> 16),
(Char)(entry->Tag >> 8 ),
(Char)(entry->Tag),
entry->Offset,
entry->Length ));
entry++;
}
FORGET_Frame();
PTRACE2(( "Directory loaded\n\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_MaxProfile( PFace face )
{
DEFINE_LOCALS;
Long i;
PMaxProfile maxProfile = &face->maxProfile;
PTRACE2(( "Load_TT_MaxProfile( %08lx )\n", (long)face ));
if ( ( i = TT_LookUp_Table( face, TTAG_maxp ) ) < 0 )
return TT_Err_Max_Profile_Missing;
if ( FILE_Seek( face->dirTables[i].Offset ) )
return error;
if ( ACCESS_Frame( 32L ) )
return error;
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();
FORGET_Frame();
if (maxProfile->maxFunctionDefs == 0)
maxProfile->maxFunctionDefs = 64;
face->numGlyphs = maxProfile->numGlyphs;
face->maxPoints = MAX( maxProfile->maxCompositePoints,
maxProfile->maxPoints );
face->maxContours = MAX( maxProfile->maxCompositeContours,
maxProfile->maxContours );
face->maxComponents = maxProfile->maxComponentElements +
maxProfile->maxComponentDepth;
if ( face->maxComponents == 0 )
face->maxComponents = 16;
face->maxPoints += 8;
face->maxContours += 4;
PTRACE2(( "GASP loaded.\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Gasp( PFace face )
{
DEFINE_LOCALS;
Long i;
UShort j;
TGasp* gas;
GaspRange* gaspranges;
PTRACE2(( "Load_TT_Gasp( %08lx )\n", (long)face ));
if ( ( i = TT_LookUp_Table( face, TTAG_gasp ) ) < 0 )
return TT_Err_Ok;
if ( FILE_Seek( face->dirTables[i].Offset ) ||
ACCESS_Frame( 4L ) )
return error;
gas = &face->gasp;
gas->version = GET_UShort();
gas->numRanges = GET_UShort();
FORGET_Frame();
PTRACE3(( "number of ranges = %d\n", gas->numRanges ));
if ( ALLOC_ARRAY( gaspranges, gas->numRanges, GaspRange ) ||
ACCESS_Frame( gas->numRanges * 4L ) )
goto Fail;
face->gasp.gaspRanges = gaspranges;
for ( j = 0; j < gas->numRanges; j++ )
{
gaspranges[j].maxPPEM = GET_UShort();
gaspranges[j].gaspFlag = GET_UShort();
PTRACE3(( " [max:%d flag:%d]",
gaspranges[j].maxPPEM,
gaspranges[j].gaspFlag ));
}
PTRACE3(("\n"));
FORGET_Frame();
PTRACE2(( "GASP loaded\n" ));
return TT_Err_Ok;
Fail:
FREE( gaspranges );
gas->numRanges = 0;
return error;
}
LOCAL_FUNC
TT_Error Load_TrueType_Header( PFace face )
{
DEFINE_LOCALS;
Long i;
TT_Header* header;
PTRACE2(( "Load_TT_Header( %08lx )\n", (long)face ));
if ( ( i = TT_LookUp_Table( face, TTAG_head ) ) < 0 )
{
PTRACE0(( "Font Header is missing !!\n" ));
return TT_Err_Header_Table_Missing;
}
if ( FILE_Seek( face->dirTables[i].Offset ) ||
ACCESS_Frame( 54L ) )
return error;
header = &face->fontHeader;
header->Table_Version = GET_ULong();
header->Font_Revision = GET_ULong();
header->CheckSum_Adjust = GET_Long();
header->Magic_Number = GET_Long();
header->Flags = GET_UShort();
header->Units_Per_EM = GET_UShort();
header->Created [0] = GET_Long();
header->Created [1] = GET_Long();
header->Modified[0] = GET_Long();
header->Modified[1] = GET_Long();
header->xMin = GET_Short();
header->yMin = GET_Short();
header->xMax = GET_Short();
header->yMax = GET_Short();
header->Mac_Style = GET_UShort();
header->Lowest_Rec_PPEM = GET_UShort();
header->Font_Direction = GET_Short();
header->Index_To_Loc_Format = GET_Short();
header->Glyph_Data_Format = GET_Short();
FORGET_Frame();
PTRACE2(( " Units per EM : %8u\n", header->Units_Per_EM ));
PTRACE2(( " IndexToLoc : %8d\n", header->Index_To_Loc_Format ));
PTRACE2(( "Font Header Loaded.\n" ));
return TT_Err_Ok;
}
static
TT_Error Load_TrueType_Metrics( PFace face,
Bool vertical )
{
DEFINE_LOCALS;
Long n, num_shorts, num_shorts_checked, num_longs;
PLongMetrics* longs;
PShortMetrics* shorts;
PLongMetrics long_metric;
PTRACE2(( "Load_TT_%s_Metrics( %08lx )\n",
vertical ? "Vertical" : "Horizontal",
(long)face ));
if ( vertical )
{
n = TT_LookUp_Table( face, TTAG_vmtx );
if ( n < 0 )
{
PTRACE2(( " no vertical header in file.\n" ));
face->verticalHeader.number_Of_VMetrics = 0;
return TT_Err_Ok;
}
num_longs = face->verticalHeader.number_Of_VMetrics;
longs = (PLongMetrics*)&face->verticalHeader.long_metrics;
shorts = (PShortMetrics*)&face->verticalHeader.short_metrics;
}
else
{
if ( ( n = TT_LookUp_Table( face, TTAG_hmtx ) ) < 0 )
{
PERROR(( "!! No Horizontal metrics in file !!\n" ));
return TT_Err_Hmtx_Table_Missing;
}
num_longs = face->horizontalHeader.number_Of_HMetrics;
longs = (PLongMetrics*)&face->horizontalHeader.long_metrics;
shorts = (PShortMetrics*)&face->horizontalHeader.short_metrics;
}
num_shorts = face->maxProfile.numGlyphs - num_longs;
num_shorts_checked = ( face->dirTables[n].Length - num_longs * 4 ) / 2;
if ( num_shorts < 0 )
{
PERROR(( "!! more metrics than glyphs!\n" ));
if ( vertical )
return TT_Err_Invalid_Vert_Metrics;
else
return TT_Err_Invalid_Horiz_Metrics;
}
if ( ALLOC_ARRAY( *longs, num_longs, TLongMetrics ) ||
ALLOC_ARRAY( *shorts, num_shorts, TShortMetrics ) )
return error;
if ( FILE_Seek( face->dirTables[n].Offset ) ||
ACCESS_Frame( face->dirTables[n].Length ) )
return error;
long_metric = *longs;
for ( n = 0; n < num_longs; n++ )
{
long_metric->advance = GET_UShort();
long_metric->bearing = GET_Short();
long_metric++;
}
if ( num_shorts > num_shorts_checked )
{
for ( n = 0; n < num_shorts_checked; n++ )
(*shorts)[n] = GET_Short();
for ( n = num_shorts_checked; n < num_shorts; n++ )
(*shorts)[n] = (*shorts)[num_shorts_checked - 1];
}
else
{
for ( n = 0; n < num_shorts; n++ )
(*shorts)[n] = GET_Short();
}
FORGET_Frame();
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Metrics_Header( PFace face,
Bool vertical )
{
DEFINE_LOCALS;
Long i;
TT_Horizontal_Header* header;
PTRACE2(( vertical ? "Vertical header" : "Horizontal header " ));
if ( vertical )
{
face->verticalInfo = 0;
if ( ( i = TT_LookUp_Table( face, TTAG_vhea ) ) < 0 )
return TT_Err_Ok;
face->verticalInfo = 1;
header = (TT_Horizontal_Header*)&face->verticalHeader;
}
else
{
if ( ( i = TT_LookUp_Table( face, TTAG_hhea ) ) < 0 )
return TT_Err_Horiz_Header_Missing;
header = &face->horizontalHeader;
}
if ( FILE_Seek( face->dirTables[i].Offset ) ||
ACCESS_Frame( 36L ) )
return error;
header->Version = GET_ULong();
header->Ascender = GET_Short();
header->Descender = GET_Short();
header->Line_Gap = GET_Short();
header->advance_Width_Max = GET_UShort();
header->min_Left_Side_Bearing = GET_Short();
header->min_Right_Side_Bearing = GET_Short();
header->xMax_Extent = GET_Short();
header->caret_Slope_Rise = GET_Short();
header->caret_Slope_Run = GET_Short();
header->Reserved0 = GET_Short();
header->Reserved1 = GET_Short();
header->Reserved2 = GET_Short();
header->Reserved3 = GET_Short();
header->Reserved4 = GET_Short();
header->metric_Data_Format = GET_Short();
header->number_Of_HMetrics = GET_UShort();
FORGET_Frame();
header->long_metrics = NULL;
header->short_metrics = NULL;
PTRACE2(( "loaded\n" ));
return Load_TrueType_Metrics( face, vertical );
}
LOCAL_FUNC
TT_Error Load_TrueType_Locations( PFace face )
{
DEFINE_LOCALS;
Long n, limit;
Short LongOffsets;
PTRACE2(( "Locations " ));
LongOffsets = face->fontHeader.Index_To_Loc_Format;
if ( ( n = TT_LookUp_Table( face, TTAG_loca ) ) < 0 )
return TT_Err_Locations_Missing;
if ( FILE_Seek( face->dirTables[n].Offset ) )
return error;
if ( LongOffsets != 0 )
{
face->numLocations = face->dirTables[n].Length >> 2;
PTRACE2(( "(32 bit offsets): %12lu ",
face->numLocations ));
if ( ALLOC_ARRAY( face->glyphLocations,
face->numLocations,
Long ) )
return error;
if ( ACCESS_Frame( face->numLocations * 4L ) )
return error;
limit = face->numLocations;
for ( n = 0; n < limit; n++ )
face->glyphLocations[n] = GET_Long();
FORGET_Frame();
}
else
{
face->numLocations = face->dirTables[n].Length >> 1;
PTRACE2(( "(16 bit offsets): %12lu ",
face->numLocations ));
if ( ALLOC_ARRAY( face->glyphLocations,
face->numLocations,
Long ) )
return error;
if ( ACCESS_Frame( face->numLocations * 2L ) )
return error;
limit = face->numLocations;
for ( n = 0; n < limit; n++ )
face->glyphLocations[n] =
(Long)((ULong)GET_UShort() * 2);
FORGET_Frame();
}
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Names( PFace face )
{
DEFINE_LOCALS;
UShort i, bytes;
Long n;
PByte storage;
TName_Table* names;
TNameRec* namerec;
PTRACE2(( "Names " ));
if ( ( n = TT_LookUp_Table( face, TTAG_name ) ) < 0 )
{
PTRACE2(( "is missing!\n" ));
return TT_Err_Name_Table_Missing;
}
if ( FILE_Seek( face->dirTables[n].Offset ) ||
ACCESS_Frame( 6L ) )
return error;
names = &face->nameTable;
names->format = GET_UShort();
names->numNameRecords = GET_UShort();
names->storageOffset = GET_UShort();
FORGET_Frame();
if ( ALLOC_ARRAY( names->names,
names->numNameRecords,
TNameRec ) ||
ACCESS_Frame( names->numNameRecords * 12L ) )
{
names->numNameRecords = 0;
goto Fail;
}
for ( i = bytes = 0; i < names->numNameRecords; i++ )
{
namerec = names->names + i;
namerec->platformID = GET_UShort();
namerec->encodingID = GET_UShort();
namerec->languageID = GET_UShort();
namerec->nameID = GET_UShort();
namerec->stringLength = GET_UShort();
namerec->stringOffset = GET_UShort();
#if 0
if ( namerec->platformID <= 3 )
{
#endif
if ( (namerec->stringOffset + namerec->stringLength) > bytes )
bytes = namerec->stringOffset + namerec->stringLength;
#if 0
}
#endif
}
FORGET_Frame();
names->storage = NULL;
if ( bytes > 0 )
{
if ( ALLOC( storage, bytes ) ||
FILE_Read_At( face->dirTables[n].Offset + names->storageOffset,
(void*)storage,
bytes ) )
goto Fail_Storage;
names->storage = storage;
for ( i = 0; i < names->numNameRecords; i++ )
{
namerec = names->names + i;
namerec->string = storage + names->names[i].stringOffset;
#if 0
if ( namerec->platformID <= 3 )
namerec->string = storage + names->names[i].stringOffset;
else
{
namerec->string = NULL;
namerec->stringLength = 0;
}
#endif
}
}
#ifdef DEBUG_LEVEL_TRACE
for ( i = 0; i < names->numNameRecords; i++ )
{
int j;
PTRACE2(( "%d %d %x %d ",
names->names[i].platformID,
names->names[i].encodingID,
names->names[i].languageID,
names->names[i].nameID ));
for ( j = 0; j < names->names[i].stringLength; j++ )
{
if (names->names[i].string)
{
Char c = *(names->names[i].string + j);
if ( (Byte)c < 128 )
PTRACE2(( "%c", c ));
}
}
PTRACE2(( "\n" ));
}
#endif
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
Fail_Storage:
FREE( storage );
Fail:
Free_TrueType_Names( face );
return error;
}
LOCAL_FUNC
TT_Error Free_TrueType_Names( PFace face )
{
TName_Table* names = &face->nameTable;
FREE( names->names );
FREE( names->storage );
names->numNameRecords = 0;
names->format = 0;
names->storageOffset = 0;
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_CVT( PFace face )
{
DEFINE_LOCALS;
Long n, limit;
PTRACE2(( "CVT " ));
if ( ( n = TT_LookUp_Table( face, TTAG_cvt ) ) < 0 )
{
PTRACE2(( "is missing!\n" ));
face->cvtSize = 0;
face->cvt = NULL;
return TT_Err_Ok;
}
face->cvtSize = face->dirTables[n].Length / 2;
if ( ALLOC_ARRAY( face->cvt,
face->cvtSize,
Short ) )
return error;
if ( FILE_Seek( face->dirTables[n].Offset ) ||
ACCESS_Frame( face->cvtSize * 2L ) )
return error;
limit = face->cvtSize;
for ( n = 0; n < limit; n++ )
face->cvt[n] = GET_Short();
FORGET_Frame();
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_CMap( PFace face )
{
DEFINE_LOCALS;
Long off, table_start;
Long n, limit;
TCMapDir cmap_dir;
TCMapDirEntry entry_;
PCMapTable cmap;
PTRACE2(( "CMaps " ));
if ( ( n = TT_LookUp_Table( face, TTAG_cmap ) ) < 0 )
return TT_Err_CMap_Table_Missing;
table_start = face->dirTables[n].Offset;
if ( ( FILE_Seek( table_start ) ) ||
( ACCESS_Frame( 4L ) ) )
return error;
cmap_dir.tableVersionNumber = GET_UShort();
cmap_dir.numCMaps = GET_UShort();
FORGET_Frame();
off = FILE_Pos();
if ( ALLOC_ARRAY( face->cMaps,
cmap_dir.numCMaps,
TCMapTable ) )
return error;
face->numCMaps = cmap_dir.numCMaps;
limit = face->numCMaps;
cmap = face->cMaps;
for ( n = 0; n < limit; n++ )
{
if ( FILE_Seek( off ) ||
ACCESS_Frame( 8L ) )
return error;
cmap->loaded = FALSE;
cmap->platformID = entry_.platformID = GET_UShort();
cmap->platformEncodingID = entry_.platformEncodingID = GET_UShort();
entry_.offset = GET_Long();
FORGET_Frame();
off = FILE_Pos();
if ( FILE_Seek( table_start + entry_.offset ) ||
ACCESS_Frame( 6L ) )
return error;
cmap->format = GET_UShort();
cmap->length = GET_UShort();
cmap->version = GET_UShort();
FORGET_Frame();
cmap->offset = FILE_Pos();
cmap++;
}
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Programs( PFace face )
{
DEFINE_LOCALS_WO_FRAME;
Long n;
PTRACE2(( "Font program " ));
if ( ( n = TT_LookUp_Table( face, TTAG_fpgm ) ) < 0 )
{
face->fontProgram = NULL;
face->fontPgmSize = 0;
PTRACE2(( "is missing!\n" ));
}
else
{
face->fontPgmSize = face->dirTables[n].Length;
if ( ALLOC( face->fontProgram,
face->fontPgmSize ) ||
FILE_Read_At( face->dirTables[n].Offset,
(void*)face->fontProgram,
face->fontPgmSize ) )
return error;
PTRACE2(( "loaded, %12d bytes\n", face->fontPgmSize ));
}
PTRACE2(( "Prep program " ));
if ( ( n = TT_LookUp_Table( face, TTAG_prep ) ) < 0 )
{
face->cvtProgram = NULL;
face->cvtPgmSize = 0;
PTRACE2(( "is missing!\n" ));
}
else
{
face->cvtPgmSize = face->dirTables[n].Length;
if ( ALLOC( face->cvtProgram,
face->cvtPgmSize ) ||
FILE_Read_At( face->dirTables[n].Offset,
(void*)face->cvtProgram,
face->cvtPgmSize ) )
return error;
PTRACE2(( "loaded, %12d bytes\n", face->cvtPgmSize ));
}
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_OS2( PFace face )
{
DEFINE_LOCALS;
Long i;
TT_OS2* os2;
PTRACE2(( "OS/2 Table " ));
if ( ( i = TT_LookUp_Table( face, TTAG_OS2 ) ) < 0 )
{
PTRACE2(( "is missing\n!" ));
face->os2.version = 0xFFFF;
error = TT_Err_Ok;
return TT_Err_Ok;
}
if ( FILE_Seek( face->dirTables[i].Offset ) ||
ACCESS_Frame( 78L ) )
return error;
os2 = &face->os2;
os2->version = GET_UShort();
os2->xAvgCharWidth = GET_Short();
os2->usWeightClass = GET_UShort();
os2->usWidthClass = GET_UShort();
os2->fsType = GET_Short();
os2->ySubscriptXSize = GET_Short();
os2->ySubscriptYSize = GET_Short();
os2->ySubscriptXOffset = GET_Short();
os2->ySubscriptYOffset = GET_Short();
os2->ySuperscriptXSize = GET_Short();
os2->ySuperscriptYSize = GET_Short();
os2->ySuperscriptXOffset = GET_Short();
os2->ySuperscriptYOffset = GET_Short();
os2->yStrikeoutSize = GET_Short();
os2->yStrikeoutPosition = GET_Short();
os2->sFamilyClass = GET_Short();
for ( i = 0; i < 10; i++ )
os2->panose[i] = GET_Byte();
os2->ulUnicodeRange1 = GET_ULong();
os2->ulUnicodeRange2 = GET_ULong();
os2->ulUnicodeRange3 = GET_ULong();
os2->ulUnicodeRange4 = GET_ULong();
for ( i = 0; i < 4; i++ )
os2->achVendID[i] = GET_Byte();
os2->fsSelection = GET_UShort();
os2->usFirstCharIndex = GET_UShort();
os2->usLastCharIndex = GET_UShort();
os2->sTypoAscender = GET_Short();
os2->sTypoDescender = GET_Short();
os2->sTypoLineGap = GET_Short();
os2->usWinAscent = GET_UShort();
os2->usWinDescent = GET_UShort();
FORGET_Frame();
if ( os2->version >= 0x0001 )
{
if ( ACCESS_Frame( 8L ) )
return error;
os2->ulCodePageRange1 = GET_ULong();
os2->ulCodePageRange2 = GET_ULong();
FORGET_Frame();
}
else
{
os2->ulCodePageRange1 = 0;
os2->ulCodePageRange2 = 0;
}
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_PostScript( PFace face )
{
DEFINE_LOCALS;
Long i;
TT_Postscript* post = &face->postscript;
PTRACE2(( "PostScript " ));
if ( ( i = TT_LookUp_Table( face, TTAG_post ) ) < 0 )
return TT_Err_Post_Table_Missing;
if ( FILE_Seek( face->dirTables[i].Offset ) ||
ACCESS_Frame( 32L ) )
return error;
post->FormatType = GET_ULong();
post->italicAngle = GET_ULong();
post->underlinePosition = GET_Short();
post->underlineThickness = GET_Short();
post->isFixedPitch = GET_ULong();
post->minMemType42 = GET_ULong();
post->maxMemType42 = GET_ULong();
post->minMemType1 = GET_ULong();
post->maxMemType1 = GET_ULong();
FORGET_Frame();
PTRACE2(( "loaded\n" ));
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Hdmx( PFace face )
{
DEFINE_LOCALS;
TT_Hdmx_Record* rec;
TT_Hdmx hdmx;
Long table;
UShort n, num_glyphs;
Long record_size;
hdmx.version = 0;
hdmx.num_records = 0;
hdmx.records = 0;
face->hdmx = hdmx;
if ( ( table = TT_LookUp_Table( face, TTAG_hdmx ) ) < 0 )
return TT_Err_Ok;
if ( FILE_Seek( face->dirTables[table].Offset ) ||
ACCESS_Frame( 8L ) )
return error;
hdmx.version = GET_UShort();
hdmx.num_records = GET_Short();
record_size = GET_Long();
FORGET_Frame();
if ( hdmx.version != 0 )
return TT_Err_Ok;
if ( ALLOC( hdmx.records, sizeof ( TT_Hdmx_Record ) * hdmx.num_records ) )
return error;
num_glyphs = face->numGlyphs;
record_size -= num_glyphs+2;
rec = hdmx.records;
for ( n = 0; n < hdmx.num_records; n++ )
{
if ( ACCESS_Frame( 2L ) )
goto Fail;
rec->ppem = GET_Byte();
rec->max_width = GET_Byte();
FORGET_Frame();
if ( ALLOC( rec->widths, num_glyphs ) ||
FILE_Read( rec->widths, num_glyphs ) )
goto Fail;
if ( record_size > 0 )
if ( FILE_Skip( record_size ) )
goto Fail;
rec++;
}
face->hdmx = hdmx;
return TT_Err_Ok;
Fail:
for ( n = 0; n < hdmx.num_records; n++ )
FREE( hdmx.records[n].widths );
FREE( hdmx.records );
return error;
}
LOCAL_FUNC
TT_Error Free_TrueType_Hdmx( PFace face )
{
UShort n;
if ( !face )
return TT_Err_Ok;
for ( n = 0; n < face->hdmx.num_records; n++ )
FREE( face->hdmx.records[n].widths );
FREE( face->hdmx.records );
face->hdmx.num_records = 0;
return TT_Err_Ok;
}
LOCAL_FUNC
TT_Error Load_TrueType_Any( PFace face,
ULong tag,
Long offset,
void* buffer,
Long* length )
{
TT_Stream stream;
TT_Error error;
Long table;
ULong size;
if ( tag != 0 )
{
table = TT_LookUp_Table( face, tag );
if ( table < 0 )
return TT_Err_Table_Missing;
offset += face->dirTables[table].Offset;
size = face->dirTables[table].Length;
}
else
size = TT_Stream_Size( face->stream );
if ( length && *length == 0 )
{
*length = size;
return TT_Err_Ok;
}
if ( length )
size = *length;
if ( !USE_Stream( face->stream, stream ) )
(void)FILE_Read_At( offset, buffer, size );
DONE_Stream( stream );
return error;
}