freetype2/src/sfnt/ttload.c

1887 lines
67 KiB
C
Raw Normal View History

1999-12-17 00:11:37 +01:00
/***************************************************************************/
/* */
/* ttload.c */
/* */
/* Load the basic TrueType tables, i.e., tables that can be either in */
/* TTF or OTF fonts (body). */
1999-12-17 00:11:37 +01:00
/* */
/* Copyright 1996-2001, 2002 by */
1999-12-17 00:11:37 +01:00
/* 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 */
1999-12-17 00:11:37 +01:00
/* 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. */
/* */
/***************************************************************************/
2000-12-08 17:17:16 +01:00
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TAGS_H
#include "ttload.h"
#include "ttcmap.h"
1999-12-17 00:11:37 +01:00
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
#include "sferrors.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 trace_ttload
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_LookUp_Table */
/* */
/* <Description> */
/* Looks for a TrueType table by name. */
/* */
/* <Input> */
/* face :: A face object handle. */
/* */
/* tag :: The searched tag. */
1999-12-17 00:11:37 +01:00
/* */
/* <Return> */
/* A pointer to the table directory entry. 0 if not found. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( TT_Table )
2001-06-28 01:25:46 +02:00
TT_LookUp_Table( TT_Face face,
FT_ULong tag )
1999-12-17 00:11:37 +01:00
{
TT_Table entry;
TT_Table limit;
2000-05-17 01:44:38 +02:00
FT_TRACE3(( "TT_LookUp_Table: %08p, `%c%c%c%c' -- ",
2000-11-13 17:58:01 +01:00
face,
(FT_Char)( tag >> 24 ),
(FT_Char)( tag >> 16 ),
(FT_Char)( tag >> 8 ),
(FT_Char)( tag ) ));
1999-12-17 00:11:37 +01:00
entry = face->dir_tables;
limit = entry + face->num_tables;
1999-12-17 00:11:37 +01:00
for ( ; entry < limit; entry++ )
{
if ( entry->Tag == tag )
{
2000-11-13 17:58:01 +01:00
FT_TRACE3(( "found table.\n" ));
1999-12-17 00:11:37 +01:00
return entry;
}
2000-05-17 01:44:38 +02:00
}
FT_TRACE3(( "could not find table!\n" ));
1999-12-17 00:11:37 +01:00
return 0;
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Goto_Table */
/* */
/* <Description> */
/* Looks for a TrueType table by name, then seek a stream to it. */
/* */
/* <Input> */
/* face :: A face object handle. */
/* */
/* tag :: The searched tag. */
/* */
/* stream :: The stream to seek when the table is found. */
/* */
/* <Output> */
/* length :: The length of the table if found, undefined otherwise. */
1999-12-17 00:11:37 +01:00
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Goto_Table( TT_Face face,
FT_ULong tag,
FT_Stream stream,
FT_ULong* length )
1999-12-17 00:11:37 +01:00
{
TT_Table table;
FT_Error error;
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
table = TT_LookUp_Table( face, tag );
if ( table )
1999-12-17 00:11:37 +01:00
{
if ( length )
1999-12-17 00:11:37 +01:00
*length = table->Length;
2000-05-17 01:44:38 +02:00
if ( FT_STREAM_SEEK( table->Offset ) )
goto Exit;
1999-12-17 00:11:37 +01:00
}
else
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Table_Missing;
2000-05-17 01:44:38 +02:00
Exit:
1999-12-17 00:11:37 +01:00
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_SFNT_HeaderRec */
1999-12-17 00:11:37 +01:00
/* */
/* <Description> */
/* Loads the header of a SFNT font file. Supports collections. */
1999-12-17 00:11:37 +01:00
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* face_index :: If the font is a collection, the number of the font */
/* in the collection, ignored otherwise. */
/* */
/* <Output> */
/* sfnt :: The SFNT header. */
1999-12-17 00:11:37 +01:00
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin. */
1999-12-17 00:11:37 +01:00
/* */
/* This function recognizes fonts embedded in a `TrueType collection' */
/* */
/* The header will be checked whether it is valid by looking at the */
/* values of `search_range', `entry_selector', and `range_shift'. */
/* */
FT_LOCAL_DEF( FT_Error )
TT_Load_SFNT_HeaderRec( TT_Face face,
FT_Stream stream,
FT_Long face_index,
SFNT_Header sfnt )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
FT_ULong format_tag;
FT_Memory memory = stream->memory;
2000-06-05 16:32:32 +02:00
const FT_Frame_Field sfnt_header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE SFNT_HeaderRec
FT_FRAME_START( 8 ),
FT_FRAME_USHORT( num_tables ),
FT_FRAME_USHORT( search_range ),
FT_FRAME_USHORT( entry_selector ),
FT_FRAME_USHORT( range_shift ),
FT_FRAME_END
};
2000-06-05 16:32:32 +02:00
const FT_Frame_Field ttc_header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TTC_HeaderRec
FT_FRAME_START( 8 ),
FT_FRAME_LONG( version ),
FT_FRAME_LONG( count ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "TT_Load_SFNT_HeaderRec: %08p, %ld\n",
face, face_index ));
1999-12-17 00:11:37 +01:00
face->ttc_header.tag = 0;
face->ttc_header.version = 0;
face->ttc_header.count = 0;
1999-12-17 00:11:37 +01:00
face->num_tables = 0;
/* first of all, read the first 4 bytes. If it is `ttcf', then the */
/* file is a TrueType collection, otherwise it can be any other */
/* kind of font. */
/* */
if ( FT_READ_ULONG( format_tag ) )
goto Exit;
1999-12-17 00:11:37 +01:00
if ( format_tag == TTAG_ttcf )
1999-12-17 00:11:37 +01:00
{
FT_Int n;
2000-05-17 01:44:38 +02:00
FT_TRACE3(( "TT_Load_SFNT_HeaderRec: file is a collection\n" ));
2000-05-17 01:44:38 +02:00
/* It is a TrueType collection, i.e. a file containing several */
/* font files. Read the font directory now */
if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) )
goto Exit;
1999-12-17 00:11:37 +01:00
/* now read the offsets of each font in the file */
if ( FT_NEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) ||
FT_FRAME_ENTER( face->ttc_header.count * 4L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
2000-07-19 08:25:56 +02:00
for ( n = 0; n < face->ttc_header.count; n++ )
face->ttc_header.offsets[n] = FT_GET_ULONG();
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* check face index */
2000-07-19 08:25:56 +02:00
if ( face_index >= face->ttc_header.count )
1999-12-17 00:11:37 +01:00
{
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Bad_Argument;
1999-12-17 00:11:37 +01:00
goto Exit;
2000-05-17 01:44:38 +02:00
}
1999-12-17 00:11:37 +01:00
/* seek to the appropriate TrueType file, then read tag */
if ( FT_STREAM_SEEK( face->ttc_header.offsets[face_index] ) ||
FT_READ_LONG( format_tag ) )
1999-12-17 00:11:37 +01:00
goto Exit;
}
/* the format tag was read, now check the rest of the header */
sfnt->format_tag = format_tag;
if ( FT_STREAM_READ_FIELDS( sfnt_header_fields, sfnt ) )
goto Exit;
2000-06-05 16:32:32 +02:00
/* now, check the values of `num_tables', `seach_range', etc. */
{
FT_UInt num_tables = sfnt->num_tables;
FT_ULong entry_selector = 1L << sfnt->entry_selector;
/* IMPORTANT: Many fonts have an incorrect `search_range' value, so */
/* we only check the `entry_selector' correctness here. */
/* */
if ( num_tables == 0 ||
entry_selector > num_tables ||
entry_selector * 2 <= num_tables )
{
FT_TRACE2(( "TT_Load_SFNT_HeaderRec: file is not SFNT!\n" ));
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Unknown_File_Format;
}
}
Exit:
return error;
2000-06-05 16:32:32 +02:00
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Directory */
/* */
/* <Description> */
/* Loads the table directory into a face object. */
/* */
/* <InOut> */
/* face :: A handle to the target face object. */
/* */
/* <Input> */
/* stream :: The input stream. */
/* */
/* sfnt :: The SFNT directory header. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin. */
/* */
FT_LOCAL_DEF( FT_Error )
TT_Load_Directory( TT_Face face,
FT_Stream stream,
SFNT_Header sfnt )
{
FT_Error error;
FT_Memory memory = stream->memory;
TT_TableRec *entry, *limit;
FT_TRACE2(( "TT_Load_Directory: %08p\n", face ));
FT_TRACE2(( "-- Tables count: %12u\n", sfnt->num_tables ));
FT_TRACE2(( "-- Format version: %08lx\n", sfnt->format_tag ));
face->num_tables = sfnt->num_tables;
1999-12-17 00:11:37 +01:00
if ( FT_NEW_ARRAY( face->dir_tables, face->num_tables ) )
1999-12-17 00:11:37 +01:00
goto Exit;
if ( FT_FRAME_ENTER( face->num_tables * 16L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
entry = face->dir_tables;
limit = entry + face->num_tables;
for ( ; entry < limit; entry++ )
{ /* loop through the tables and get all entries */
entry->Tag = FT_GET_TAG4();
entry->CheckSum = FT_GET_ULONG();
entry->Offset = FT_GET_LONG();
entry->Length = FT_GET_LONG();
1999-12-17 00:11:37 +01:00
FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n",
(FT_Char)( entry->Tag >> 24 ),
(FT_Char)( entry->Tag >> 16 ),
(FT_Char)( entry->Tag >> 8 ),
(FT_Char)( entry->Tag ),
entry->Offset,
entry->Length ));
1999-12-17 00:11:37 +01:00
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "Directory loaded\n\n" ));
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Any */
/* */
/* <Description> */
2000-07-19 04:59:31 +02:00
/* Loads any font table into client memory. */
1999-12-17 00:11:37 +01:00
/* */
/* <Input> */
/* face :: The face object to look for. */
/* */
/* tag :: The tag of table to load. Use the value 0 if you want */
1999-12-17 00:11:37 +01:00
/* to access the whole font file, else set this parameter */
/* to a valid TrueType table tag that you can forge with */
/* the MAKE_TT_TAG macro. */
/* */
/* offset :: The starting offset in the table (or the file if */
/* tag == 0). */
/* */
/* length :: The address of the decision variable: */
/* */
/* If length == NULL: */
/* Loads the whole table. Returns an error if */
/* `offset' == 0! */
/* */
/* If *length == 0: */
/* Exits immediately; returning the length of the given */
/* table or of the font file, depending on the value of */
/* `tag'. */
/* */
/* If *length != 0: */
/* Loads the next `length' bytes of table or font, */
/* starting at offset `offset' (in table or font too). */
/* */
/* <Output> */
/* buffer :: The address of target buffer. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Any( TT_Face face,
FT_ULong tag,
FT_Long offset,
FT_Byte* buffer,
FT_ULong* length )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
FT_Stream stream;
TT_Table table;
FT_ULong size;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
if ( tag != 0 )
{
/* look for tag in font directory */
table = TT_LookUp_Table( face, tag );
if ( !table )
{
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Table_Missing;
1999-12-17 00:11:37 +01:00
goto Exit;
}
offset += table->Offset;
size = table->Length;
}
else
/* tag == 0 -- the user wants to access the font file directly */
1999-12-17 00:11:37 +01:00
size = face->root.stream->size;
if ( length && *length == 0 )
{
*length = size;
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
}
if ( length )
size = *length;
stream = face->root.stream;
/* the `if' is syntactic sugar for picky compilers */
if ( FT_STREAM_READ_AT( offset, buffer, size ) )
goto Exit;
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Generic_Header */
1999-12-17 00:11:37 +01:00
/* */
/* <Description> */
/* Loads the TrueType table `head' or `bhed'. */
1999-12-17 00:11:37 +01:00
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
static FT_Error
TT_Load_Generic_Header( TT_Face face,
FT_Stream stream,
FT_ULong tag )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
TT_Header* header;
static const FT_Frame_Field header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_Header
FT_FRAME_START( 54 ),
FT_FRAME_ULONG ( Table_Version ),
FT_FRAME_ULONG ( Font_Revision ),
FT_FRAME_LONG ( CheckSum_Adjust ),
FT_FRAME_LONG ( Magic_Number ),
FT_FRAME_USHORT( Flags ),
FT_FRAME_USHORT( Units_Per_EM ),
FT_FRAME_LONG ( Created[0] ),
FT_FRAME_LONG ( Created[1] ),
FT_FRAME_LONG ( Modified[0] ),
FT_FRAME_LONG ( Modified[1] ),
FT_FRAME_SHORT ( xMin ),
FT_FRAME_SHORT ( yMin ),
FT_FRAME_SHORT ( xMax ),
FT_FRAME_SHORT ( yMax ),
FT_FRAME_USHORT( Mac_Style ),
FT_FRAME_USHORT( Lowest_Rec_PPEM ),
FT_FRAME_SHORT ( Font_Direction ),
FT_FRAME_SHORT ( Index_To_Loc_Format ),
FT_FRAME_SHORT ( Glyph_Data_Format ),
FT_FRAME_END
};
2000-11-13 17:58:01 +01:00
FT_TRACE2(( "TT_Load_Generic_Header: "
"%08p, looking up font table `%c%c%c%c'.\n",
face,
(FT_Char)( tag >> 24 ),
(FT_Char)( tag >> 16 ),
(FT_Char)( tag >> 8 ),
(FT_Char)( tag ) ));
1999-12-17 00:11:37 +01:00
error = face->goto_table( face, tag, stream, 0 );
1999-12-17 00:11:37 +01:00
if ( error )
{
FT_TRACE2(( "TT_Load_Generic_Header: Font table is missing!\n" ));
1999-12-17 00:11:37 +01:00
goto Exit;
}
header = &face->header;
if ( FT_STREAM_READ_FIELDS( header_fields, header ) )
1999-12-17 00:11:37 +01:00
goto Exit;
FT_TRACE2(( " Units per EM: %8u\n", header->Units_Per_EM ));
FT_TRACE2(( " IndexToLoc: %8d\n", header->Index_To_Loc_Format ));
FT_TRACE2(( "TT_Load_Generic_Header: Font table loaded.\n" ));
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Header( TT_Face face,
FT_Stream stream )
{
return TT_Load_Generic_Header( face, stream, TTAG_head );
}
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Bitmap_Header( TT_Face face,
FT_Stream stream )
{
return TT_Load_Generic_Header( face, stream, TTAG_bhed );
}
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_MaxProfile */
/* */
/* <Description> */
/* Loads the maximum profile into a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_MaxProfile( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
TT_MaxProfile* maxProfile = &face->max_profile;
const FT_Frame_Field maxp_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_MaxProfile
FT_FRAME_START( 6 ),
FT_FRAME_LONG ( version ),
FT_FRAME_USHORT( numGlyphs ),
FT_FRAME_END
};
const FT_Frame_Field maxp_fields_extra[] =
{
FT_FRAME_START( 26 ),
FT_FRAME_USHORT( maxPoints ),
FT_FRAME_USHORT( maxContours ),
FT_FRAME_USHORT( maxCompositePoints ),
FT_FRAME_USHORT( maxCompositeContours ),
FT_FRAME_USHORT( maxZones ),
FT_FRAME_USHORT( maxTwilightPoints ),
FT_FRAME_USHORT( maxStorage ),
FT_FRAME_USHORT( maxFunctionDefs ),
FT_FRAME_USHORT( maxInstructionDefs ),
FT_FRAME_USHORT( maxStackElements ),
FT_FRAME_USHORT( maxSizeOfInstructions ),
FT_FRAME_USHORT( maxComponentElements ),
FT_FRAME_USHORT( maxComponentDepth ),
FT_FRAME_END
};
FT_TRACE2(( "Load_TT_MaxProfile: %08p\n", face ));
1999-12-17 00:11:37 +01:00
error = face->goto_table( face, TTAG_maxp, stream, 0 );
if ( error )
goto Exit;
1999-12-17 00:11:37 +01:00
if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) )
goto Exit;
1999-12-17 00:11:37 +01:00
maxProfile->maxPoints = 0;
maxProfile->maxContours = 0;
maxProfile->maxCompositePoints = 0;
maxProfile->maxCompositeContours = 0;
maxProfile->maxZones = 0;
maxProfile->maxTwilightPoints = 0;
maxProfile->maxStorage = 0;
maxProfile->maxFunctionDefs = 0;
maxProfile->maxInstructionDefs = 0;
maxProfile->maxStackElements = 0;
maxProfile->maxSizeOfInstructions = 0;
maxProfile->maxComponentElements = 0;
maxProfile->maxComponentDepth = 0;
if ( maxProfile->version >= 0x10000L )
{
if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) )
goto Exit;
1999-12-17 00:11:37 +01:00
/* XXX: an adjustment that is necessary to load certain */
/* broken fonts like `Keystrokes MT' :-( */
/* */
/* We allocate 64 function entries by default when */
/* the maxFunctionDefs field is null. */
1999-12-17 00:11:37 +01:00
if ( maxProfile->maxFunctionDefs == 0 )
maxProfile->maxFunctionDefs = 64;
1999-12-17 00:11:37 +01:00
face->root.num_glyphs = maxProfile->numGlyphs;
1999-12-17 00:11:37 +01:00
face->root.internal->max_points =
(FT_UShort)MAX( maxProfile->maxCompositePoints,
maxProfile->maxPoints );
1999-12-17 00:11:37 +01:00
face->root.internal->max_contours =
(FT_Short)MAX( maxProfile->maxCompositeContours,
maxProfile->maxContours );
1999-12-17 00:11:37 +01:00
face->max_components = (FT_ULong)maxProfile->maxComponentElements +
maxProfile->maxComponentDepth;
1999-12-17 00:11:37 +01:00
/* XXX: some fonts have maxComponents set to 0; we will */
/* then use 16 of them by default. */
if ( face->max_components == 0 )
face->max_components = 16;
/* We also increase maxPoints and maxContours in order to support */
/* some broken fonts. */
2002-01-09 22:01:18 +01:00
face->root.internal->max_points += (FT_UShort)8;
face->root.internal->max_contours += (FT_Short) 4;
}
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "MAXP loaded.\n" ));
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Metrics */
/* */
/* <Description> */
/* Loads the horizontal or vertical metrics table into a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
1999-12-17 00:11:37 +01:00
/* vertical :: A boolean flag. If set, load vertical metrics. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
static FT_Error
TT_Load_Metrics( TT_Face face,
FT_Stream stream,
FT_Bool vertical )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
FT_Memory memory = stream->memory;
FT_ULong table_len;
FT_Long num_shorts, num_longs, num_shorts_checked;
1999-12-17 00:11:37 +01:00
TT_LongMetrics * longs;
1999-12-17 00:11:37 +01:00
TT_ShortMetrics** shorts;
FT_TRACE2(( "TT_Load_%s_Metrics: %08p\n", vertical ? "Vertical"
: "Horizontal",
face ));
1999-12-17 00:11:37 +01:00
if ( vertical )
{
/* The table is optional, quit silently if it wasn't found */
/* */
1999-12-17 00:11:37 +01:00
/* XXX: Some fonts have a valid vertical header with a non-null */
/* `number_of_VMetrics' fields, but no corresponding `vmtx' */
/* table to get the metrics from (e.g. mingliu). */
/* */
/* For safety, we set the field to 0! */
/* */
error = face->goto_table( face, TTAG_vmtx, stream, &table_len );
if ( error )
{
/* Set number_Of_VMetrics to 0! */
1999-12-17 00:11:37 +01:00
FT_TRACE2(( " no vertical header in file.\n" ));
face->vertical.number_Of_VMetrics = 0;
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
goto Exit;
}
num_longs = face->vertical.number_Of_VMetrics;
longs = (TT_LongMetrics *)&face->vertical.long_metrics;
1999-12-17 00:11:37 +01:00
shorts = (TT_ShortMetrics**)&face->vertical.short_metrics;
}
else
{
error = face->goto_table( face, TTAG_hmtx, stream, &table_len );
if ( error )
1999-12-17 00:11:37 +01:00
{
FT_ERROR(( " no horizontal metrics in file!\n" ));
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Hmtx_Table_Missing;
1999-12-17 00:11:37 +01:00
goto Exit;
}
num_longs = face->horizontal.number_Of_HMetrics;
longs = (TT_LongMetrics *)&face->horizontal.long_metrics;
1999-12-17 00:11:37 +01:00
shorts = (TT_ShortMetrics**)&face->horizontal.short_metrics;
}
/* never trust derived values */
num_shorts = face->max_profile.numGlyphs - num_longs;
num_shorts_checked = ( table_len - num_longs * 4L ) / 2;
1999-12-17 00:11:37 +01:00
if ( num_shorts < 0 )
{
FT_ERROR(( "TT_Load_%s_Metrics: more metrics than glyphs!\n",
vertical ? "Vertical"
: "Horizontal" ));
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = vertical ? SFNT_Err_Invalid_Vert_Metrics
: SFNT_Err_Invalid_Horiz_Metrics;
1999-12-17 00:11:37 +01:00
goto Exit;
}
if ( FT_NEW_ARRAY( *longs, num_longs ) ||
FT_NEW_ARRAY( *shorts, num_shorts ) )
1999-12-17 00:11:37 +01:00
goto Exit;
if ( FT_FRAME_ENTER( table_len ) )
1999-12-17 00:11:37 +01:00
goto Exit;
{
TT_LongMetrics cur = *longs;
TT_LongMetrics limit = cur + num_longs;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
for ( ; cur < limit; cur++ )
{
cur->advance = FT_GET_USHORT();
cur->bearing = FT_GET_SHORT();
1999-12-17 00:11:37 +01:00
}
}
/* do we have an inconsistent number of metric values? */
1999-12-17 00:11:37 +01:00
{
TT_ShortMetrics* cur = *shorts;
TT_ShortMetrics* limit = cur + MIN( num_shorts, num_shorts_checked );
1999-12-17 00:11:37 +01:00
for ( ; cur < limit; cur++ )
*cur = FT_GET_SHORT();
1999-12-17 00:11:37 +01:00
/* we fill up the missing left side bearings with the */
/* last valid value. Since this will occur for buggy CJK */
/* fonts usually only, nothing serious will happen */
1999-12-17 00:11:37 +01:00
if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 )
{
FT_Short val = (*shorts)[num_shorts_checked - 1];
1999-12-17 00:11:37 +01:00
limit = *shorts + num_shorts;
for ( ; cur < limit; cur++ )
*cur = val;
}
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "loaded\n" ));
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Metrics_Header */
/* */
/* <Description> */
/* Loads the horizontal or vertical header in a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
1999-12-17 00:11:37 +01:00
/* vertical :: A boolean flag. If set, load vertical metrics. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Metrics_Header( TT_Face face,
FT_Stream stream,
FT_Bool vertical )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
TT_HoriHeader* header;
const FT_Frame_Field metrics_header_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_HoriHeader
FT_FRAME_START( 36 ),
FT_FRAME_ULONG ( Version ),
FT_FRAME_SHORT ( Ascender ),
FT_FRAME_SHORT ( Descender ),
FT_FRAME_SHORT ( Line_Gap ),
FT_FRAME_USHORT( advance_Width_Max ),
FT_FRAME_SHORT ( min_Left_Side_Bearing ),
FT_FRAME_SHORT ( min_Right_Side_Bearing ),
FT_FRAME_SHORT ( xMax_Extent ),
FT_FRAME_SHORT ( caret_Slope_Rise ),
FT_FRAME_SHORT ( caret_Slope_Run ),
FT_FRAME_SHORT ( caret_Offset ),
FT_FRAME_SHORT ( Reserved[0] ),
FT_FRAME_SHORT ( Reserved[1] ),
FT_FRAME_SHORT ( Reserved[2] ),
FT_FRAME_SHORT ( Reserved[3] ),
FT_FRAME_SHORT ( metric_Data_Format ),
FT_FRAME_USHORT( number_Of_HMetrics ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( vertical ? "Vertical header " : "Horizontal header " ));
if ( vertical )
{
face->vertical_info = 0;
/* The vertical header table is optional, so return quietly if */
/* we don't find it. */
error = face->goto_table( face, TTAG_vhea, stream, 0 );
if ( error )
1999-12-17 00:11:37 +01:00
{
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
goto Exit;
}
face->vertical_info = 1;
header = (TT_HoriHeader*)&face->vertical;
}
else
{
/* The horizontal header is mandatory; return an error if we */
1999-12-17 00:11:37 +01:00
/* don't find it. */
error = face->goto_table( face, TTAG_hhea, stream, 0 );
if ( error )
1999-12-17 00:11:37 +01:00
{
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Horiz_Header_Missing;
1999-12-17 00:11:37 +01:00
goto Exit;
}
header = &face->horizontal;
}
if ( FT_STREAM_READ_FIELDS( metrics_header_fields, header ) )
goto Exit;
1999-12-17 00:11:37 +01:00
header->long_metrics = NULL;
header->short_metrics = NULL;
FT_TRACE2(( "loaded\n" ));
/* Now try to load the corresponding metrics */
error = TT_Load_Metrics( face, stream, vertical );
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Names */
/* */
/* <Description> */
/* Loads the name records. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Names( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
FT_Memory memory = stream->memory;
1999-12-17 00:11:37 +01:00
FT_ULong table_pos, table_len;
FT_ULong storageOffset, storageSize;
FT_Byte* storage;
1999-12-17 00:11:37 +01:00
TT_NameTable names;
const FT_Frame_Field name_table_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_NameTableRec
FT_FRAME_START( 6 ),
FT_FRAME_USHORT( format ),
FT_FRAME_USHORT( numNameRecords ),
FT_FRAME_USHORT( storageOffset ),
FT_FRAME_END
};
const FT_Frame_Field name_record_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_NameEntryRec
/* no FT_FRAME_START */
FT_FRAME_USHORT( platformID ),
FT_FRAME_USHORT( encodingID ),
FT_FRAME_USHORT( languageID ),
FT_FRAME_USHORT( nameID ),
FT_FRAME_USHORT( stringLength ),
FT_FRAME_USHORT( stringOffset ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "Names " ));
error = face->goto_table( face, TTAG_name, stream, &table_len );
if ( error )
1999-12-17 00:11:37 +01:00
{
/* The name table is required so indicate failure. */
FT_TRACE2(( "is missing!\n" ));
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Name_Table_Missing;
1999-12-17 00:11:37 +01:00
goto Exit;
}
table_pos = FT_STREAM_POS();
1999-12-17 00:11:37 +01:00
names = &face->name_table;
if ( FT_STREAM_READ_FIELDS( name_table_fields, names ) )
goto Exit;
1999-12-17 00:11:37 +01:00
/* check the 'storageOffset' field */
storageOffset = names->storageOffset;
/* some broken asian fonts have a storage offset whose value is */
/* 12*numNameRecords. We deal with them here.. */
2002-05-01 10:48:35 +02:00
if ( storageOffset == (FT_ULong)(12 * names->numNameRecords) )
storageOffset += 6;
if ( storageOffset < (FT_ULong)( 6 + 12 * names->numNameRecords ) ||
table_len <= storageOffset )
{
FT_ERROR(( "TT_Load_Names: invalid `name' table\n" ));
error = SFNT_Err_Name_Table_Missing;
goto Exit;
}
storageSize = (FT_ULong)(table_len - storageOffset);
1999-12-17 00:11:37 +01:00
/* Allocate the array of name records. */
if ( FT_ALLOC( names->names,
names->numNameRecords * sizeof ( TT_NameEntryRec ) +
storageSize ) ||
FT_FRAME_ENTER( names->numNameRecords * 12L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
storage = (FT_Byte*)( names->names + names->numNameRecords );
1999-12-17 00:11:37 +01:00
/* Load the name records and determine how much storage is needed */
/* to hold the strings themselves. */
{
TT_NameEntryRec* cur = names->names;
TT_NameEntryRec* limit = cur + names->numNameRecords;
1999-12-17 00:11:37 +01:00
for ( ; cur < limit; cur ++ )
{
if ( FT_STREAM_READ_FIELDS( name_record_fields, cur ) )
break;
/* invalid name entries will have "cur->string" set to NULL! */
if ( (FT_ULong)( cur->stringOffset + cur->stringLength ) < storageSize )
cur->string = storage + cur->stringOffset;
else
{
/* that's an invalid entry */
cur->stringOffset = 0;
cur->string = NULL;
}
1999-12-17 00:11:37 +01:00
}
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
if ( error )
goto Exit;
1999-12-17 00:11:37 +01:00
storageOffset -= 6 + 12 * names->numNameRecords;
if ( FT_STREAM_SKIP( storageOffset ) ||
FT_STREAM_READ( storage, storageSize ) )
goto Exit;
2000-05-17 01:44:38 +02:00
#ifdef FT_DEBUG_LEVEL_TRACE
/* print Name Record Table in case of debugging */
1999-12-17 00:11:37 +01:00
{
TT_NameEntryRec* cur = names->names;
TT_NameEntryRec* limit = cur + names->numNameRecords;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
for ( ; cur < limit; cur++ )
{
FT_UInt j;
2000-05-17 01:44:38 +02:00
FT_TRACE3(( "(%2d %2d %4x %2d) ",
cur->platformID,
cur->encodingID,
cur->languageID,
cur->nameID ));
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
/* I know that M$ encoded strings are Unicode, */
/* but this works reasonable well for debugging purposes. */
if ( cur->string )
for ( j = 0; j < (FT_UInt)cur->stringLength; j++ )
1999-12-17 00:11:37 +01:00
{
FT_Byte c = *(FT_Byte*)( cur->string + j );
2000-05-17 01:44:38 +02:00
if ( c >= 32 && c < 128 )
FT_TRACE3(( "%c", c ));
1999-12-17 00:11:37 +01:00
}
else
FT_TRACE3(( "Invalid entry!\n" ));
FT_TRACE3(( "\n" ));
1999-12-17 00:11:37 +01:00
}
}
#endif /* FT_DEBUG_LEVEL_TRACE */
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "loaded\n" ));
/* everything went well, update face->num_names */
face->num_names = names->numNameRecords;
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Free_Names */
/* */
/* <Description> */
/* Frees the name records. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
FT_LOCAL_DEF( void )
2001-06-28 01:25:46 +02:00
TT_Free_Names( TT_Face face )
1999-12-17 00:11:37 +01:00
{
FT_Memory memory = face->root.driver->root.memory;
TT_NameTable names = &face->name_table;
1999-12-17 00:11:37 +01:00
/* free strings table */
FT_FREE( names->names );
1999-12-17 00:11:37 +01:00
/* free strings storage */
FT_FREE( names->storage );
1999-12-17 00:11:37 +01:00
names->numNameRecords = 0;
names->format = 0;
names->storageOffset = 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_CMap */
/* */
/* <Description> */
/* Loads the cmap directory in a face object. The cmaps itselves are */
/* loaded on demand in the `ttcmap.c' module. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: A handle to the input stream. */
1999-12-17 00:11:37 +01:00
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
#ifdef FT_CONFIG_OPTION_USE_CMAPS
FT_LOCAL_DEF( FT_Error )
TT_Load_CMap( TT_Face face,
FT_Stream stream )
{
FT_Error error;
error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size );
if ( error )
{
FT_TRACE2(( "No `cmap' table in font !\n" ));
error = SFNT_Err_CMap_Table_Missing;
goto Exit;
}
if ( !FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) )
FT_TRACE2(( "`cmap' table loaded\n" ));
else
{
FT_ERROR(( "`cmap' table is too short!\n" ));
face->cmap_size = 0;
}
Exit:
return error;
}
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_CMap( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
FT_Memory memory = stream->memory;
FT_Long table_start;
TT_CMapDirRec cmap_dir;
1999-12-17 00:11:37 +01:00
const FT_Frame_Field cmap_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_CMapDirRec
FT_FRAME_START( 4 ),
FT_FRAME_USHORT( tableVersionNumber ),
FT_FRAME_USHORT( numCMaps ),
FT_FRAME_END
};
const FT_Frame_Field cmap_rec_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_CMapTableRec
FT_FRAME_START( 4 ),
FT_FRAME_USHORT( format ),
FT_FRAME_USHORT( length ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "CMaps " ));
error = face->goto_table( face, TTAG_cmap, stream, 0 );
if ( error )
1999-12-17 00:11:37 +01:00
{
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_CMap_Table_Missing;
1999-12-17 00:11:37 +01:00
goto Exit;
}
table_start = FT_STREAM_POS();
1999-12-17 00:11:37 +01:00
if ( FT_STREAM_READ_FIELDS( cmap_fields, &cmap_dir ) )
goto Exit;
1999-12-17 00:11:37 +01:00
/* reserve space in face table for cmap tables */
if ( FT_NEW_ARRAY( face->charmaps, cmap_dir.numCMaps ) )
1999-12-17 00:11:37 +01:00
goto Exit;
face->num_charmaps = cmap_dir.numCMaps;
{
TT_CharMap charmap = face->charmaps;
TT_CharMap limit = charmap + face->num_charmaps;
/* read the header of each charmap first */
if ( FT_FRAME_ENTER( face->num_charmaps * 8L ) )
goto Exit;
1999-12-17 00:11:37 +01:00
for ( ; charmap < limit; charmap++ )
{
TT_CMapTable cmap;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
charmap->root.face = (FT_Face)face;
cmap = &charmap->cmap;
cmap->loaded = FALSE;
cmap->platformID = FT_GET_USHORT();
cmap->platformEncodingID = FT_GET_USHORT();
cmap->offset = (FT_ULong)FT_GET_LONG();
}
FT_FRAME_EXIT();
2000-05-17 01:44:38 +02:00
/* now read the rest of each table */
for ( charmap = face->charmaps; charmap < limit; charmap++ )
{
TT_CMapTable cmap = &charmap->cmap;
2000-05-17 01:44:38 +02:00
if ( FT_STREAM_SEEK( table_start + (FT_Long)cmap->offset ) ||
FT_STREAM_READ_FIELDS( cmap_rec_fields, cmap ) )
1999-12-17 00:11:37 +01:00
goto Exit;
2000-05-17 01:44:38 +02:00
cmap->offset = FT_STREAM_POS();
1999-12-17 00:11:37 +01:00
}
}
FT_TRACE2(( "loaded\n" ));
1999-12-17 00:11:37 +01:00
Exit:
return error;
}
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_OS2 */
/* */
/* <Description> */
/* Loads the OS2 table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: A handle to the input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_OS2( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
TT_OS2* os2;
const FT_Frame_Field os2_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_OS2
FT_FRAME_START( 78 ),
FT_FRAME_USHORT( version ),
FT_FRAME_SHORT ( xAvgCharWidth ),
FT_FRAME_USHORT( usWeightClass ),
FT_FRAME_USHORT( usWidthClass ),
FT_FRAME_SHORT ( fsType ),
FT_FRAME_SHORT ( ySubscriptXSize ),
FT_FRAME_SHORT ( ySubscriptYSize ),
FT_FRAME_SHORT ( ySubscriptXOffset ),
FT_FRAME_SHORT ( ySubscriptYOffset ),
FT_FRAME_SHORT ( ySuperscriptXSize ),
FT_FRAME_SHORT ( ySuperscriptYSize ),
FT_FRAME_SHORT ( ySuperscriptXOffset ),
FT_FRAME_SHORT ( ySuperscriptYOffset ),
FT_FRAME_SHORT ( yStrikeoutSize ),
FT_FRAME_SHORT ( yStrikeoutPosition ),
FT_FRAME_SHORT ( sFamilyClass ),
FT_FRAME_BYTE ( panose[0] ),
FT_FRAME_BYTE ( panose[1] ),
FT_FRAME_BYTE ( panose[2] ),
FT_FRAME_BYTE ( panose[3] ),
FT_FRAME_BYTE ( panose[4] ),
FT_FRAME_BYTE ( panose[5] ),
FT_FRAME_BYTE ( panose[6] ),
FT_FRAME_BYTE ( panose[7] ),
FT_FRAME_BYTE ( panose[8] ),
FT_FRAME_BYTE ( panose[9] ),
FT_FRAME_ULONG ( ulUnicodeRange1 ),
FT_FRAME_ULONG ( ulUnicodeRange2 ),
FT_FRAME_ULONG ( ulUnicodeRange3 ),
FT_FRAME_ULONG ( ulUnicodeRange4 ),
FT_FRAME_BYTE ( achVendID[0] ),
FT_FRAME_BYTE ( achVendID[1] ),
FT_FRAME_BYTE ( achVendID[2] ),
FT_FRAME_BYTE ( achVendID[3] ),
FT_FRAME_USHORT( fsSelection ),
FT_FRAME_USHORT( usFirstCharIndex ),
FT_FRAME_USHORT( usLastCharIndex ),
FT_FRAME_SHORT ( sTypoAscender ),
FT_FRAME_SHORT ( sTypoDescender ),
FT_FRAME_SHORT ( sTypoLineGap ),
FT_FRAME_USHORT( usWinAscent ),
FT_FRAME_USHORT( usWinDescent ),
FT_FRAME_END
};
const FT_Frame_Field os2_fields_extra[] =
{
FT_FRAME_START( 8 ),
FT_FRAME_ULONG( ulCodePageRange1 ),
FT_FRAME_ULONG( ulCodePageRange2 ),
FT_FRAME_END
};
const FT_Frame_Field os2_fields_extra2[] =
{
FT_FRAME_START( 10 ),
FT_FRAME_SHORT ( sxHeight ),
FT_FRAME_SHORT ( sCapHeight ),
FT_FRAME_USHORT( usDefaultChar ),
FT_FRAME_USHORT( usBreakChar ),
FT_FRAME_USHORT( usMaxContext ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "OS/2 Table " ));
/* We now support old Mac fonts where the OS/2 table doesn't */
/* exist. Simply put, we set the `version' field to 0xFFFF */
/* and test this value each time we need to access the table. */
error = face->goto_table( face, TTAG_OS2, stream, 0 );
if ( error )
1999-12-17 00:11:37 +01:00
{
FT_TRACE2(( "is missing!\n" ));
face->os2.version = 0xFFFFU;
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
error = SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
goto Exit;
}
os2 = &face->os2;
if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) )
goto Exit;
1999-12-17 00:11:37 +01:00
os2->ulCodePageRange1 = 0;
os2->ulCodePageRange2 = 0;
os2->sxHeight = 0;
os2->sCapHeight = 0;
os2->usDefaultChar = 0;
os2->usBreakChar = 0;
os2->usMaxContext = 0;
1999-12-17 00:11:37 +01:00
if ( os2->version >= 0x0001 )
{
/* only version 1 tables */
if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) )
goto Exit;
if ( os2->version >= 0x0002 )
{
/* only version 2 tables */
if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) )
goto Exit;
}
1999-12-17 00:11:37 +01:00
}
FT_TRACE2(( "loaded\n" ));
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Postscript */
/* */
/* <Description> */
/* Loads the Postscript table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: A handle to the input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_PostScript( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
TT_Postscript* post = &face->postscript;
static const FT_Frame_Field post_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_Postscript
FT_FRAME_START( 32 ),
FT_FRAME_ULONG( FormatType ),
FT_FRAME_ULONG( italicAngle ),
FT_FRAME_SHORT( underlinePosition ),
FT_FRAME_SHORT( underlineThickness ),
FT_FRAME_ULONG( isFixedPitch ),
FT_FRAME_ULONG( minMemType42 ),
FT_FRAME_ULONG( maxMemType42 ),
FT_FRAME_ULONG( minMemType1 ),
FT_FRAME_ULONG( maxMemType1 ),
FT_FRAME_END
};
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "PostScript " ));
error = face->goto_table( face, TTAG_post, stream, 0 );
if ( error )
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Post_Table_Missing;
1999-12-17 00:11:37 +01:00
if ( FT_STREAM_READ_FIELDS( post_fields, post ) )
return error;
1999-12-17 00:11:37 +01:00
/* we don't load the glyph names, we do that in another */
/* module (ttpost). */
FT_TRACE2(( "loaded\n" ));
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_PCLT */
/* */
/* <Description> */
/* Loads the PCL 5 Table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: A handle to the input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_PCLT( TT_Face face,
FT_Stream stream )
{
static const FT_Frame_Field pclt_fields[] =
{
#undef FT_STRUCTURE
#define FT_STRUCTURE TT_PCLT
FT_FRAME_START( 54 ),
FT_FRAME_ULONG ( Version ),
FT_FRAME_ULONG ( FontNumber ),
FT_FRAME_USHORT( Pitch ),
FT_FRAME_USHORT( xHeight ),
FT_FRAME_USHORT( Style ),
FT_FRAME_USHORT( TypeFamily ),
FT_FRAME_USHORT( CapHeight ),
FT_FRAME_BYTES ( TypeFace, 16 ),
FT_FRAME_BYTES ( CharacterComplement, 8 ),
FT_FRAME_BYTES ( FileName, 6 ),
FT_FRAME_CHAR ( StrokeWeight ),
FT_FRAME_CHAR ( WidthType ),
FT_FRAME_BYTE ( SerifStyle ),
FT_FRAME_BYTE ( Reserved ),
FT_FRAME_END
};
2000-06-05 16:32:32 +02:00
FT_Error error;
TT_PCLT* pclt = &face->pclt;
2000-06-05 16:32:32 +02:00
FT_TRACE2(( "PCLT " ));
/* optional table */
error = face->goto_table( face, TTAG_PCLT, stream, 0 );
if ( error )
{
FT_TRACE2(( "missing (optional)\n" ));
pclt->Version = 0;
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
}
2000-06-05 16:32:32 +02:00
if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) )
goto Exit;
2000-06-05 16:32:32 +02:00
FT_TRACE2(( "loaded\n" ));
2000-06-05 16:32:32 +02:00
Exit:
return error;
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Gasp */
/* */
/* <Description> */
/* Loads the `gasp' table into a face object. */
1999-12-17 00:11:37 +01:00
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Gasp( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
FT_Memory memory = stream->memory;
FT_UInt j,num_ranges;
TT_GaspRange gaspranges;
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "TT_Load_Gasp: %08p\n", face ));
1999-12-17 00:11:37 +01:00
/* the gasp table is optional */
error = face->goto_table( face, TTAG_gasp, stream, 0 );
if ( error )
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
if ( FT_FRAME_ENTER( 4L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
face->gasp.version = FT_GET_USHORT();
face->gasp.numRanges = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
num_ranges = face->gasp.numRanges;
FT_TRACE3(( "number of ranges = %d\n", num_ranges ));
if ( FT_NEW_ARRAY( gaspranges, num_ranges ) ||
FT_FRAME_ENTER( num_ranges * 4L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
face->gasp.gaspRanges = gaspranges;
for ( j = 0; j < num_ranges; j++ )
{
gaspranges[j].maxPPEM = FT_GET_USHORT();
gaspranges[j].gaspFlag = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
FT_TRACE3(( " [max:%d flag:%d]",
gaspranges[j].maxPPEM,
gaspranges[j].gaspFlag ));
1999-12-17 00:11:37 +01:00
}
FT_TRACE3(( "\n" ));
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
FT_TRACE2(( "GASP loaded\n" ));
Exit:
return error;
}
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( int )
tt_kern_pair_compare( const void* a,
const void* b );
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Kern */
/* */
/* <Description> */
/* Loads the first kerning table with format 0 in the font. Only */
/* accepts the first horizontal kerning table. Developers should use */
/* the `ftxkern' extension to access other kerning tables in the font */
/* file, if they really want to. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: The input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Kern( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
1999-12-17 00:11:37 +01:00
FT_Memory memory = stream->memory;
Minor cleanups to remove compiler warnings. * include/freetype/cache/ftcmanag.h (FTC_MAX_BYTES_DEFAULT): Use `L' for constant. * include/freetype/config/ftoption.h (FT_RENDER_POOL_SIZE): Ditto. * src/base/ftcalc.c (FT_MulDiv): Use `L' for constant. * src/base/ftglyph.c (FT_Glyph_Get_CBox): Remove `error' variable. * src/base/fttrigon.c (ft_trig_arctan_table): Use `L' for constants. * src/base/ftobjs.c (FT_Done_Size): Fix return value. (FT_Set_Char_Size, FT_Set_Pixel_Sizes, FT_Get_Kerning): Remove unused `memory' variable. * src/autohint/ahglyph.c (ah_get_orientation): Use `L' for constant. * src/autohint/ahhint.c (ah_hint_edges_3, ah_hinter_align_edge_points): Remove unused `before' and `after' variables. (ah_hinter_align_weak_points): Remove unused `edge_limit' variable. (ah_hinter_load): Remove unused `new_advance', `start_contour', and `metrics' variables. * src/cff/cffload.c (CFF_Load_Encoding): Remove dead code to avoid compiler warning. * src/cff/cffobjs.c (CFF_Init_Face): Remove unused `base_offset' variable. * src/cff/cffgload.c (CFF_Parse_CharStrings): Remove unused `outline' variable. (cff_compute_bias): Use `U' for constant. * src/cid/cidload.c (cid_decrypt): Ditto. * src/psaux/psobjs.c (T1_Decrypt): Ditto. * src/psaux/t1decode.c (T1_Decoder_Parse_CharStrings): Ditto. * src/sfnt/ttload.c (TT_Load_Kern): Remove unused `version' variable. * src/sfnt/ttsbit.c (TT_Load_SBit_Image): Remove unused `top' variable. * src/truetype/ttgload.c (load_truetype_glyph): Remove unused `num_contours' and `ins_offset' variables. (compute_glyph_metrics): Remove unused `Top' and `x_scale' variables. (TT_Load_Glyph): Remove unused `memory' variable. * src/smooth/ftgrays.c (grays_raster_render): Use `L' for constants.
2001-06-18 16:23:45 +02:00
FT_UInt n, num_tables;
1999-12-17 00:11:37 +01:00
/* the kern table is optional; exit silently if it is missing */
1999-12-17 00:11:37 +01:00
error = face->goto_table( face, TTAG_kern, stream, 0 );
if ( error )
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
if ( FT_FRAME_ENTER( 4L ) )
goto Exit;
1999-12-17 00:11:37 +01:00
(void)FT_GET_USHORT(); /* version */
num_tables = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
for ( n = 0; n < num_tables; n++ )
{
FT_UInt coverage;
FT_UInt length;
1999-12-17 00:11:37 +01:00
if ( FT_FRAME_ENTER( 6L ) )
goto Exit;
1999-12-17 00:11:37 +01:00
(void)FT_GET_USHORT(); /* version */
length = FT_GET_USHORT() - 6; /* substract header length */
coverage = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
if ( coverage == 0x0001 )
{
FT_UInt num_pairs;
TT_Kern0_Pair pair;
TT_Kern0_Pair limit;
1999-12-17 00:11:37 +01:00
/* found a horizontal format 0 kerning table! */
if ( FT_FRAME_ENTER( 8L ) )
1999-12-17 00:11:37 +01:00
goto Exit;
num_pairs = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
/* skip the rest */
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* allocate array of kerning pairs */
if ( FT_NEW_ARRAY( face->kern_pairs, num_pairs ) ||
FT_FRAME_ENTER( 6L * num_pairs ) )
1999-12-17 00:11:37 +01:00
goto Exit;
pair = face->kern_pairs;
limit = pair + num_pairs;
for ( ; pair < limit; pair++ )
{
pair->left = FT_GET_USHORT();
pair->right = FT_GET_USHORT();
pair->value = FT_GET_USHORT();
1999-12-17 00:11:37 +01:00
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
face->num_kern_pairs = num_pairs;
face->kern_table_index = n;
/* ensure that the kerning pair table is sorted (yes, some */
/* fonts have unsorted tables!) */
{
FT_UInt i;
TT_Kern0_Pair pair0;
pair0 = face->kern_pairs;
for ( i = 1; i < num_pairs; i++, pair0++ )
{
if ( tt_kern_pair_compare( pair0, pair0 + 1 ) != -1 )
{
ft_qsort( (void*)face->kern_pairs, (int)num_pairs,
sizeof ( TT_Kern0_PairRec ), tt_kern_pair_compare );
break;
}
}
}
1999-12-17 00:11:37 +01:00
goto Exit;
}
2000-05-17 01:44:38 +02:00
if ( FT_STREAM_SKIP( length ) )
1999-12-17 00:11:37 +01:00
goto Exit;
}
/* no kern table found -- doesn't matter */
face->kern_table_index = -1;
face->num_kern_pairs = 0;
face->kern_pairs = NULL;
Exit:
return error;
}
#undef TT_KERN_INDEX
#define TT_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 )
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( int )
tt_kern_pair_compare( const void* a,
const void* b )
{
TT_Kern0_Pair pair1 = (TT_Kern0_Pair)a;
TT_Kern0_Pair pair2 = (TT_Kern0_Pair)b;
FT_ULong index1 = TT_KERN_INDEX( pair1->left, pair1->right );
FT_ULong index2 = TT_KERN_INDEX( pair2->left, pair2->right );
return ( index1 < index2 ? -1 :
( index1 > index2 ? 1 : 0 ));
}
#undef TT_KERN_INDEX
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Hdmx */
/* */
/* <Description> */
/* Loads the horizontal device metrics table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
1999-12-17 00:11:37 +01:00
/* stream :: A handle to the input stream. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_Load_Hdmx( TT_Face face,
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
FT_Memory memory = stream->memory;
1999-12-17 00:11:37 +01:00
TT_Hdmx hdmx = &face->hdmx;
FT_Long num_glyphs;
FT_Long record_size;
1999-12-17 00:11:37 +01:00
hdmx->version = 0;
hdmx->num_records = 0;
hdmx->records = 0;
/* this table is optional */
error = face->goto_table( face, TTAG_hdmx, stream, 0 );
if ( error )
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
if ( FT_FRAME_ENTER( 8L ) )
goto Exit;
1999-12-17 00:11:37 +01:00
hdmx->version = FT_GET_USHORT();
hdmx->num_records = FT_GET_SHORT();
record_size = FT_GET_LONG();
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* Only recognize format 0 */
if ( hdmx->version != 0 )
goto Exit;
if ( FT_NEW_ARRAY( hdmx->records, hdmx->num_records ) )
1999-12-17 00:11:37 +01:00
goto Exit;
num_glyphs = face->root.num_glyphs;
record_size -= num_glyphs + 2;
{
TT_HdmxEntry cur = hdmx->records;
TT_HdmxEntry limit = cur + hdmx->num_records;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
for ( ; cur < limit; cur++ )
{
/* read record */
if ( FT_READ_BYTE( cur->ppem ) ||
FT_READ_BYTE( cur->max_width ) )
1999-12-17 00:11:37 +01:00
goto Exit;
2000-05-17 01:44:38 +02:00
if ( FT_ALLOC( cur->widths, num_glyphs ) ||
FT_STREAM_READ( cur->widths, num_glyphs ) )
1999-12-17 00:11:37 +01:00
goto Exit;
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
/* skip padding bytes */
if ( record_size > 0 && FT_STREAM_SKIP( record_size ) )
1999-12-17 00:11:37 +01:00
goto Exit;
}
}
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Free_Hdmx */
/* */
/* <Description> */
/* Frees the horizontal device metrics table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
FT_LOCAL_DEF( void )
2001-06-28 01:25:46 +02:00
TT_Free_Hdmx( TT_Face face )
1999-12-17 00:11:37 +01:00
{
if ( face )
{
FT_Int n;
- MAJOR INTERNAL REDESIGN: A lot of internal modifications have been performed lately on the source in order to provide the following enhancements: - more generic module support: The FT_Module type is now defined to represent a handle to a given module. The file <freetype/ftmodule.h> contains the FT_Module_Class definition, as well as the module-loading public API The FT_Driver type is still defined, and still represents a pointer to a font driver. Note that FT_Add_Driver is replaced by FT_Add_Module, FT_Get_Driver by FT_Get_Module, etc.. - support for generic glyph image types: The FT_Renderer type is a pointer to a module used to perform various operations on glyph image. Each renderer is capable of handling images in a single format (e.g. ft_glyph_format_outline). Its functions are used to: - transform an glyph image - render a glyph image into a bitmap - return the control box (dimensions) of a given glyph image The scan converters "ftraster.c" and "ftgrays.c" have been moved to the new directory "src/renderer", and are used to provide two default renderer modules. One corresponds to the "standard" scan-converter, the other to the "smooth" one. The current renderer can be set through the new function FT_Set_Renderer. The old raster-related function FT_Set_Raster, FT_Get_Raster and FT_Set_Raster_Mode have now disappeared, in favor of the new: FT_Get_Renderer FT_Set_Renderer see the file <freetype/ftrender.h> for more details.. These changes were necessary to properly support different scalable formats in the future, like bi-color glyphs, etc.. - glyph loader object: A new internal object, called a 'glyph loader' has been introduced in the base layer. It is used by all scalable format font drivers to load glyphs and composites. This object has been created to reduce the code size of each driver, as each one of them basically re-implemented its functionality. See <freetype/internal/ftobjs.h> and the FT_GlyphLoader type for more information.. - FT_GlyphSlot had new fields: In order to support extended features (see below), the FT_GlyphSlot structure has a few new fields: linearHoriAdvance: this field gives the linearly scaled (i.e. scaled but unhinted) advance width for the glyph, expressed as a 16.16 fixed pixel value. This is useful to perform WYSIWYG text. linearVertAdvance: this field gives the linearly scaled advance height for the glyph (relevant in vertical glyph layouts only). This is useful to perform WYSIWYG text. Note that the two above field replace the removed "metrics2" field in the glyph slot. advance: this field is a vector that gives the transformed advance for the glyph. By default, it corresponds to the advance width, unless FT_LOAD_VERTICAL_LAYOUT was specified when calling FT_Load_Glyph or FT_Load_Char bitmap_left: this field gives the distance in integer pixels from the current pen position to the left-most pixel of a glyph image WHEN IT IS A BITMAP. It is only valid when the "format" field is set to "ft_glyph_format_bitmap", for example, after calling the new function FT_Render_Glyph. bitmap_top: this field gives the distance in integer pixels from the current pen position (located on the baseline) to the top-most pixel of the glyph image WHEN IT IS A BITMAP. Positive values correspond to upwards Y. loader: this is a new private field for the glyph slot. Client applications should not touch it.. - support for transforms and direct rendering in FT_Load_Glyph: Most of the functionality found in <freetype/ftglyph.h> has been moved to the core library. Hence, the following: - a transform can be specified for a face through FT_Set_Transform. this transform is applied by FT_Load_Glyph to scalable glyph images (i.e. NOT TO BITMAPS) before the function returns, unless the bit flag FT_LOAD_IGNORE_TRANSFORM was set in the load flags.. - once a glyph image has been loaded, it can be directly converted to a bitmap by using the new FT_Render_Glyph function. Note that this function takes the glyph image from the glyph slot, and converts it to a bitmap whose properties are returned in "face.glyph.bitmap", "face.glyph.bitmap_left" and "face.glyph.bitmap_top". The original native image might be lost after the conversion. - when using the new bit flag FT_LOAD_RENDER, the FT_Load_Glyph and FT_Load_Char functions will call FT_Render_Glyph automatically when needed.
2000-06-22 02:17:42 +02:00
FT_Memory memory = face->root.driver->root.memory;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
for ( n = 0; n < face->hdmx.num_records; n++ )
FT_FREE( face->hdmx.records[n].widths );
1999-12-17 00:11:37 +01:00
FT_FREE( face->hdmx.records );
1999-12-17 00:11:37 +01:00
face->hdmx.num_records = 0;
}
}
/* END */