Commit d42c68e8 authored by David Turner's avatar David Turner
Browse files

many new small, but important, changes there:

  - modified the interface of the "sfnt" module. There is now a function
    called "load_format_tag", and another called "load_directory".

    The first one is in charge of returning the 4-byte tag located at
    the beginning of a given font file. It understand TrueType collections
    and parses them automatically

    The second loads the table directory that is located just after
    the format tag.

    This is useful, because the "SFNT" storage scheme can be used by
    several distinct formats, each with its own format tag.

    The TrueType driver now checks the format tag in "src/truetype/ttobjs.c"

  - made some changes to "src/shared/t1types.h" to clearly separate the
    Type 1 font content from the rest of the T1_Face structure. This
    will be useful when adding the CFF/Type2 driver that will be able
    to reuse the "T1_Font" structure within a "TT_Font" one (which
    really describes a SFNT-based font file).

    Some changes in "src/type1" were thus performed to reflect this.
    Note that the current type1 driver will be discontinued in a
    distant future. More on this later..
parent 76bbd579
......@@ -1340,6 +1340,8 @@
FT_Driver driver;
FT_Memory memory;
FT_DriverInterface* interface;
FT_Size_Metrics* metrics = &face->size->metrics;
FT_Long dim_x, dim_y;
if ( !face || !face->size || !face->driver)
return FT_Err_Invalid_Face_Handle;
......@@ -1360,6 +1362,25 @@
interface = &driver->interface;
memory = driver->memory;
/* default processing - this can be overriden by the driver */
if ( char_width < 1*64 ) char_width = 1*64;
if ( char_height < 1*64 ) char_height = 1*64;
/* Compute pixel sizes in 26.6 units */
dim_x = (((char_width * horz_resolution) / 72) + 32) & -64;
dim_y = (((char_height * vert_resolution) / 72) + 32) & -64;
metrics->x_ppem = (FT_UShort)(dim_x >> 6);
metrics->y_ppem = (FT_UShort)(dim_y >> 6);
metrics->x_scale = 0x10000;
metrics->y_scale = 0x10000;
if ( face->face_flags & FT_FACE_FLAG_SCALABLE)
{
metrics->x_scale = FT_DivFix( dim_x, face->units_per_EM );
metrics->y_scale = FT_DivFix( dim_y, face->units_per_EM );
}
error = interface->set_char_sizes( face->size,
char_width,
char_height,
......@@ -1395,6 +1416,7 @@
FT_Driver driver;
FT_Memory memory;
FT_DriverInterface* interface;
FT_Size_Metrics* metrics = &face->size->metrics;
if ( !face || !face->size || !face->driver )
return FT_Err_Invalid_Face_Handle;
......@@ -1403,8 +1425,25 @@
interface = &driver->interface;
memory = driver->memory;
error = interface->set_pixel_sizes( face->size, pixel_width, pixel_height );
/* default processing - this can be overriden by the driver */
if ( pixel_width < 1 ) pixel_width = 1;
if ( pixel_height < 1 ) pixel_height = 1;
metrics->x_ppem = pixel_width;
metrics->y_ppem = pixel_height;
if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
{
metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
face->units_per_EM );
metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
face->units_per_EM );
}
error = interface->set_pixel_sizes( face->size,
pixel_width,
pixel_height );
return error;
}
......
......@@ -11,6 +11,7 @@
TT_Goto_Table,
TT_Load_Any,
TT_Load_Format_Tag,
TT_Load_Directory,
TT_Load_Header,
......
......@@ -115,39 +115,38 @@
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Directory */
/* <FuncType> */
/* TT_Load_Format_Tag */
/* */
/* <Description> */
/* Loads the table directory into a face object. */
/* Loads the first 4 bytes of the font file. This is a tag that */
/* identifies the font format used. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
/* faceIndex :: The index of the TrueType font, if we're opening a */
/* collection. */
/* <Output> */
/* format_tag :: a 4-byte font format tag */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin */
/* This function recognizes fonts embedded in a "TrueType collection" */
/* */
LOCAL_FUNC
TT_Error TT_Load_Directory( TT_Face face,
FT_Stream stream,
TT_Long faceIndex )
TT_Error TT_Load_Format_Tag( TT_Face face,
FT_Stream stream,
TT_Long faceIndex,
TT_ULong *format_tag )
{
TT_Error error;
FT_Memory memory = stream->memory;
TT_TableDir tableDir;
TT_ULong tag;
TT_Table *entry, *limit;
FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
FT_TRACE2(( "TT_Load_Format_Tag(%08lx, %ld )\n",
(TT_Long)face, faceIndex ));
face->ttc_header.Tag = 0;
......@@ -157,26 +156,24 @@
face->num_tables = 0;
/* first of all, read the first 4 bytes. If it's `ttcf', then the */
/* file is a TrueType collection, otherwise it must be a normal */
/* TrueType file.. */
if ( READ_ULong(tag) )
goto Exit;
/* file is a TrueType collection, otherwise it can be any other */
/* kind of font.. */
if ( READ_ULong(*format_tag) ) goto Exit;
if ( tag == TTAG_ttcf )
if ( *format_tag == TTAG_ttcf )
{
TT_Int n;
FT_TRACE4(( "TT_Load_Directory: file is a collection\n" ));
FT_TRACE4(( "TT_Load_Format_Tag: file is a collection\n" ));
/* it's a TrueType collection, i.e. a file containing several */
/* font files. Read the font directory now */
/* */
if ( ACCESS_Frame( 8 ) ) goto Exit;
face->ttc_header.version = GET_Long();
face->ttc_header.DirCount = GET_Long();
FORGET_Frame();
/* now read the offsets of each font in the file */
......@@ -205,28 +202,54 @@
/* seek to the appropriate TrueType file, then read tag */
if ( FILE_Skip( face->ttc_header.TableDirectory[faceIndex] - 12 ) ||
READ_Long( tableDir.version ) )
READ_Long( *format_tag ) )
goto Exit;
}
else
{
FT_TRACE6(( "TT_Load_Directory: file is not a collection\n" ));
/* the file isn't a collection, exit if we're asking for a */
/* collected font.. */
if (faceIndex > 0)
{
error = TT_Err_File_Is_Not_Collection;
goto Exit;
}
tableDir.version = tag;
}
if ( ACCESS_Frame( 8L ) )
goto Exit;
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_Load_Directory */
/* */
/* <Description> */
/* Loads the table directory into a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
/* faceIndex :: The index of the TrueType font, if we're opening a */
/* collection. */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin */
/* */
LOCAL_FUNC
TT_Error TT_Load_Directory( TT_Face face,
FT_Stream stream,
TT_Long faceIndex )
{
TT_Error error;
FT_Memory memory = stream->memory;
TT_TableDir tableDir;
TT_Table *entry, *limit;
FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
(TT_Long)face, faceIndex ));
tableDir.numTables = GET_UShort();
if ( ACCESS_Frame( 8L ) ) goto Exit;
tableDir.numTables = GET_UShort();
tableDir.searchRange = GET_UShort();
tableDir.entrySelector = GET_UShort();
tableDir.rangeShift = GET_UShort();
......@@ -236,23 +259,6 @@
FT_TRACE2(( "-- Tables count : %12u\n", tableDir.numTables ));
FT_TRACE2(( "-- Format version : %08lx\n", tableDir.version ));
/* Check that we have a `sfnt' format there */
/* We must also be able to accept Mac/GX fonts, as well as OT ones */
if ( tableDir.version != 0x00010000 && /* MS fonts */
tableDir.version != TTAG_true && /* Mac fonts */
tableDir.version != TTAG_OTTO ) /* OT-Type2 fonts */
{
FT_TRACE2(( "[not a valid TTF or OTF font]" ));
error = TT_Err_Invalid_File_Format;
goto Exit;
}
/* if we're performing a font format check, exit immediately */
/* with success */
if ( faceIndex < 0 )
goto Exit;
face->num_tables = tableDir.numTables;
if ( ALLOC_ARRAY( face->dir_tables,
......@@ -267,7 +273,7 @@
limit = entry + face->num_tables;
for ( ; entry < limit; entry++ )
{ /* loop through the tables and get all entries */
{ /* loop through the tables and get all entries */
entry->Tag = GET_Tag4();
entry->CheckSum = GET_ULong();
entry->Offset = GET_Long();
......
This diff is collapsed.
......@@ -23,6 +23,36 @@
#include <tttypes.h>
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Format_Tag */
/* */
/* <Description> */
/* Loads the first 4 bytes of the font file. This is a tag that */
/* identifies the font format used. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
/* faceIndex :: The index of the TrueType font, if we're opening a */
/* collection. */
/* <Output> */
/* format_tag :: a 4-byte tag */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin */
/* This function recognizes fonts embedded in a "TrueType collection" */
/* */
typedef
TT_Error (*TT_Load_Format_Tag_Func)( TT_Face face,
FT_Stream stream,
TT_Long faceIndex,
TT_ULong *format_tag );
/*************************************************************************/
/* */
/* <FuncType> */
......@@ -41,7 +71,9 @@
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin */
/* The stream cursor must be on the first byte after the 4-byte */
/* font format tag. This is the case just after a call to */
/* TT_Load_Format_Tag */
/* */
typedef
TT_Error (*TT_Load_Directory_Func)( TT_Face face,
......@@ -306,6 +338,7 @@
TT_Goto_Table_Func goto_table;
TT_Load_Any_Func load_any;
TT_Load_Format_Tag_Func load_format_tag;
TT_Load_Directory_Func load_directory;
TT_Load_Table_Func load_header;
......
......@@ -270,24 +270,47 @@
/***********************************************************************/
/* */
/* <Struct> T1_FontInfo */
/* <Struct> T1_Encoding */
/* */
/* <Description> */
/* The FontInfo dictionary structure. */
/* A structure modeling a custom encoding */
/* */
/* <Fields> */
/* version :: */
/* notice :: */
/* full_name :: */
/* family_name :: */
/* weight :: */
/* italic_angle :: */
/* is_fixed_pitch :: */
/* underline_position :: */
/* underline_thickness :: */
/* num_chars :: number of char codes in encoding. Usually 256 */
/* code_first :: lower char code in encoding */
/* code_last :: higher char code in encoding */
/* */
typedef struct T1_FontInfo_
/* char_code :: array of character codes */
/* char_index :: array of correpsonding glyph indices */
/* char_name :: array of correpsonding glyph names */
/* */
typedef struct T1_Encoding_
{
T1_Int num_chars;
T1_Int code_first;
T1_Int code_last;
T1_Short* char_index;
T1_String** char_name;
} T1_Encoding;
typedef enum T1_EncodingType_
{
t1_encoding_none = 0,
t1_encoding_array,
t1_encoding_standard,
t1_encoding_expert
} T1_EncodingType;
typedef struct T1_Font_
{
/* font info dictionary */
T1_String* version;
T1_String* notice;
T1_String* full_name;
......@@ -298,53 +321,8 @@
T1_Short underline_position;
T1_UShort underline_thickness;
} T1_FontInfo;
/* private dictionary */
/***********************************************************************/
/* */
/* <Struct> T1_Private */
/* */
/* <Description> */
/* The Private dictionary structure. */
/* */
/* <Fields> */
/* unique_id :: the font's unique id */
/* lenIV :: length of decrypt padding */
/* */
/* num_blues :: number of blue values */
/* num_other_blues :: number of other blue values */
/* num_family_blues :: number of family blue values */
/* num_family_other_blues :: number of family other blue values */
/* */
/* blue_values :: array of blue values */
/* other_blues :: array of other blue values */
/* family_blues :: array of family blue values */
/* family_other_blues :: array of family other blue values */
/* */
/* blue_scale :: */
/* blue_shift :: */
/* blue_scale :: */
/* */
/* standard_width :: */
/* standard_height :: */
/* */
/* num_snap_widths :: */
/* num_snap_heights :: */
/* force_bold :: */
/* round_stem_up :: */
/* */
/* stem_snap_widths :: */
/* stem_snap_heights :: */
/* */
/* language_group :: */
/* password :: */
/* */
/* min_feature :: */
/* */
/* */
typedef struct T1_Private_
{
T1_Int unique_id;
T1_Int lenIV;
......@@ -379,37 +357,36 @@
T1_Short min_feature[2];
} T1_Private;
/* top-level dictionary */
FT_String* font_name;
T1_EncodingType encoding_type;
T1_Encoding encoding;
T1_Byte* subrs_block;
T1_Byte* charstrings_block;
T1_Byte* glyph_names_block;
/***********************************************************************/
/* */
/* <Struct> T1_Private */
/* */
/* <Description> */
/* The Private dictionary structure. */
/* */
/* <Fields> */
/* num_chars :: number of char codes in encoding. Usually 256 */
/* code_first :: lower char code in encoding */
/* code_last :: higher char code in encoding */
/* */
/* char_code :: array of character codes */
/* char_index :: array of correpsonding glyph indices */
/* char_name :: array of correpsonding glyph names */
/* */
typedef struct T1_Encoding_
{
T1_Int num_chars;
T1_Int code_first;
T1_Int code_last;
T1_Int num_subrs;
T1_Byte** subrs;
T1_Int* subrs_len;
T1_Short* char_index;
T1_String** char_name;
T1_Int num_glyphs;
T1_String** glyph_names; /* array of glyph names */
T1_Byte** charstrings; /* array of glyph charstrings */
T1_Int* charstrings_len;
} T1_Encoding;
T1_Byte paint_type;
T1_Byte font_type;
T1_Matrix font_matrix;
T1_BBox font_bbox;
T1_Long font_id;
T1_Int stroke_width;
} T1_Font;
/*************************************************************************/
......@@ -417,7 +394,7 @@
/*************************************************************************/
/*** ***/
/*** ***/
/*** ORIGINAL TT_FACE CLASS DEFINITION ***/
/*** ORIGINAL T1_FACE CLASS DEFINITION ***/
/*** ***/
/*** ***/
/*************************************************************************/
......@@ -451,33 +428,7 @@
typedef struct T1_FaceRec_
{
FT_FaceRec root;
T1_FontInfo font_info;
FT_String* font_name;
T1_Encoding encoding;
T1_Byte* subrs_block;
T1_Byte* charstrings_block;
T1_Int num_subrs;
T1_Byte** subrs;
T1_Int* subrs_len;
T1_Int num_glyphs;
T1_String** glyph_names; /* array of glyph names */
T1_Byte** charstrings; /* array of glyph charstrings */
T1_Int* charstrings_len;
T1_Byte paint_type;
T1_Byte font_type;
T1_Matrix font_matrix;
T1_BBox font_bbox;
T1_Long unique_id;
T1_Long font_id;
T1_Int stroke_width;
T1_Private private_dict;
T1_Font type1;
} T1_FaceRec;
......
......@@ -29,77 +29,6 @@
#define FT_COMPONENT trace_ttdriver
static
TT_Bool string_compare( const TT_String* s1,
const TT_String* s2 )
{
int tries;
for ( tries = 128; tries > 0; tries-- )
{
if ( !*s1 )
return !*s2;
if ( *s1 != *s2 )
return 0;
s1++;
s2++;
}
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* Get_Interface */
/* */
/* <Description> */
/* Some drivers can be compiled with extensions, special code used */
/* only for specific purposes (usually for system-specific uses). */
/* Each extension is registered through a simple name (e.g. `sfnt', */
/* `post_names', etc). */
/* */
/* This function is used to return an extension's interface (i.e., */
/* a table of pointers) when it is present in the driver. */
/* */
/* If the driver wasn't compiled with the requested extension, it */
/* should return NULL. */
/* */
/* <Input> */
/* driver :: A handle to the driver object. */
/* */
/* interface :: The interface's name string. */
/* */
/* <Return> */
/* A typeless pointer to the extension's interface (normally a table */
/* of function pointers). Returns NULL when the requested extension */
/* isn't available (i.e., wasn't compiled in the driver at build */
/* time). */
/* */
/* <Note> */
/* Note that unlike format-specific methods returned by */
/* getFormatInterface(), extensions can be format-independent. */
/* */
static
void* Get_Interface( TT_Driver driver,
const TT_String* interface )
{
/* `sfnt' returns a vtable of functions used to access the tables */
/* of a TrueType or OpenType font resource. */
if ( string_compare( interface, "sfnt" ) )
return (void*)NULL;
/* XXXX : For now, there is no extension support there */
UNUSED( driver );
UNUSED( interface );
return NULL;
}
/*************************************************************************/
/*************************************************************************/
......@@ -500,34 +429,27 @@
TT_Face face = (TT_Face)size->root.face;
TT_Long dim_x, dim_y;
if ( char_width < 1*64 ) char_width = 1*64;
if ( char_height < 1*64 ) char_height = 1*64;
/* Compute pixel sizes in 26.6 units */
dim_x = (char_width * horz_resolution) / 72;
dim_y = (char_height * vert_resolution) / 72;