A major refresh of the TrueType driver :

- some #ifdefs were included in order to _not_
  compile support for the bytecode interpreter
  when FT_CONFIG_OPTION_BYTECODE_INTERPRETER
  is not defined in "ttconfig.h"

- the glyph loader has been seriously re-designed. It is now
  smaller, simpler and should load composites a bit faster

- works with the TrueType debugger
This commit is contained in:
David Turner 2000-02-02 12:16:19 +00:00
parent 0360168a4d
commit 8f43c714a5
8 changed files with 857 additions and 1096 deletions

View File

@ -44,7 +44,9 @@
#include <ttdriver.c> /* driver interface */
#include <ttpload.c> /* tables loader */
#include <ttgload.c> /* glyph loader */
#include <ttinterp.c> /* bytecode interpreter */
#include <ttobjs.c> /* object manager */
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
#include <ttinterp.c> /* bytecode interpreter */
#endif
/* END */

View File

@ -28,6 +28,17 @@
#define TTCONFIG_H
/*************************************************************************/
/* */
/* Define TT_CONFIG_OPTION_BYTECODE_INTERPRETER if you want to compile */
/* a bytecode interpreter in the TrueType driver. Note that there are */
/* important patent issues related to the use of the interpreter. */
/* */
/* By undefining this, you'll only compile the code necessary to load */
/* TrueType glyphs without hinting.. */
/* */
#undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
/*************************************************************************/
/* */
/* Define TT_CONFIG_OPTION_INTERPRETER_SWITCH to compile the TrueType */
@ -46,7 +57,7 @@
/* Define TT_CONFIG_OPTION_EMBEDDED_BITMAPS if you want to support */
/* embedded bitmaps in the TrueType/OpenType driver. */
/* */
#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS
#undef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
/*************************************************************************/
@ -55,8 +66,10 @@
/* load and enumerate the glyph Postscript names in a TrueType or */
/* OpenType file. */
/* */
#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES
#undef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
/* The maximum number of sub-glyphs in a TrueType composite glyph */
#define TT_MAX_SUBGLYPHS 32
#define TT_USE_FIXED

View File

@ -683,7 +683,7 @@
EXPORT_FUNC
FT_DriverInterface* getDriverInterface( void )
{
return &truetype_driver_interface;
return &tt_driver_interface;
}
#endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */

View File

@ -26,115 +26,10 @@
#include <ttnameid.h>
/*************************************************************************/
/* */
/* <FuncType> */
/* TTDriver_getFontData */
/* */
/* <Description> */
/* Returns either a single font table or the whole font file into */
/* caller's memory. This function mimics the GetFontData() API */
/* function found in Windows. */
/* */
/* <Input> */
/* face :: A handle to the source TrueType face object. */
/* */
/* tag :: A 32-bit integer used to name the table you want to */
/* read. Use the macro MAKE_TT_TAG (defined in freetype.h) */
/* to create one. Use the value 0 if you want to access */
/* the whole file instead. */
/* */
/* offset :: The offset from the start of the table or file from */
/* which you want to read bytes. */
/* */
/* buffer :: The address of the target/read buffer where data will be */
/* copied. */
/* */
/* <InOut> */
/* length :: The length in bytes of the data to read. If it is set */
/* to 0 when this function is called, it will return */
/* immediately, setting the value of `length' to the */
/* requested table's size (or the whole font file if the */
/* tag is 0). It is thus possible to allocate and read an */
/* arbitrary table in two successive calls. */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
typedef TT_Error (*TTDriver_getFontData)( TT_Face face,
TT_ULong tag,
TT_ULong offset,
void* buffer,
TT_Long* length );
/*************************************************************************/
/* */
/* <FuncType> */
/* TTDriver_getFaceWidths */
/* */
/* <Description> */
/* Returns the widths and/or heights of a given range of glyph from */
/* a face. */
/* */
/* <Input> */
/* face :: A handle to the source FreeType face object. */
/* */
/* first_glyph :: The first glyph in the range. */
/* */
/* last_glyph :: The last glyph in the range. */
/* */
/* <Output> */
/* widths :: The address of the table receiving the widths */
/* expressed in font units (UShorts). Set this */
/* parameter to NULL if you're not interested in these */
/* values. */
/* */
/* heights :: The address of the table receiving the heights */
/* expressed in font units (UShorts). Set this */
/* parameter to NULL if you're not interested in these */
/* values. */
/* */
/* <Return> */
/* Error code. 0 means success. */
/* */
typedef TT_Error (*TTDriver_getFaceWidths)( TT_Face face,
TT_UShort first_glyph,
TT_UShort last_glyph,
TT_UShort* widths,
TT_UShort* heights );
/*************************************************************************/
/* */
/* <Struct> */
/* TT_DriverInterface */
/* */
/* <Description> */
/* The TrueType-specific interface of this driver. Note that some of */
/* the methods defined here are optional, as they're only used for */
/* for specific tasks of the driver. */
/* */
/* <Fields> */
/* get_font_data :: See the declaration of TTDriver_getFontData(). */
/* get_face_widths :: See the declaration of */
/* TTDriver_getFaceWidths(). */
/* */
typedef struct TT_DriverInterface_
{
TTDriver_getFontData get_font_data;
TTDriver_getFaceWidths get_face_widths;
} TT_DriverInterface;
EXPORT_DEF
const FT_DriverInterface tt_driver_interface;
const FT_DriverInterface ttz_driver_interface;
EXPORT_DEF
const TT_DriverInterface tt_format_interface;
#endif /* TTDRIVER_H */

File diff suppressed because it is too large Load Diff

View File

@ -21,10 +21,47 @@
#include <ttobjs.h>
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
#include <ttinterp.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TT_Loader_
{
TT_Face face;
TT_Size size;
TT_GlyphSlot glyph;
TT_ULong load_flags;
FT_Stream stream;
TT_Int byte_len;
TT_Int left_points;
TT_Int left_contours;
TT_BBox bbox;
TT_Int left_bearing;
TT_Int advance;
TT_Bool preserve_pps;
TT_Vector pp1;
TT_Vector pp2;
TT_ULong glyf_offset;
/* the zone where we load our glyphs */
TT_GlyphZone base;
TT_GlyphZone zone;
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
TT_ExecContext exec;
TT_Byte* instructions;
#endif
} TT_Loader;
/*************************************************************************/
/* */
@ -53,7 +90,7 @@
/* */
LOCAL_DEF
void TT_Get_Metrics( TT_HoriHeader* header,
TT_UShort index,
TT_UInt index,
TT_Short* bearing,
TT_UShort* advance );

View File

@ -21,13 +21,18 @@
#include <ftcalc.h>
#include <ftstream.h>
#include <ttnameid.h>
#include <tttags.h>
#include <sfnt.h>
#include <ttobjs.h>
#include <ttpload.h>
#include <ttinterp.h>
#include <tterrors.h>
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
#include <ttinterp.h>
#endif
/* required by tracing mode */
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttobjs
@ -442,14 +447,16 @@
LOCAL_DEF
TT_Error TT_Init_Size( TT_Size size )
{
TT_Error error = 0;
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
TT_Face face = (TT_Face)size->root.face;
FT_Memory memory = face->root.memory;
TT_Error error;
TT_Int i;
TT_UShort n_twilight;
TT_MaxProfile* maxp = &face->max_profile;
TT_ExecContext exec;
TT_UShort n_twilight;
TT_MaxProfile* maxp = &face->max_profile;
size->ttmetrics.valid = FALSE;
@ -587,14 +594,19 @@
if ( !size->debug )
TT_Done_Context( exec );
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
size->ttmetrics.valid = FALSE;
return error;
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
Fail_Exec:
if ( !size->debug )
TT_Done_Context( exec );
Fail_Memory:
#endif
TT_Done_Size( size );
return error;
}
@ -614,9 +626,9 @@
LOCAL_FUNC
void TT_Done_Size( TT_Size size )
{
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
FT_Memory memory = size->root.face->memory;
if ( size->debug )
{
/* the debug context must be deleted by the debugger itself */
@ -643,6 +655,7 @@
size->max_func = 0;
size->max_ins = 0;
#endif
size->ttmetrics.valid = FALSE;
}
@ -663,10 +676,8 @@
LOCAL_DEF
TT_Error TT_Reset_Size( TT_Size size )
{
TT_ExecContext exec;
TT_Error error;
TT_UShort i, j;
TT_Face face;
TT_Face face;
TT_Error error = TT_Err_Ok;
FT_Size_Metrics* metrics;
@ -713,72 +724,79 @@
metrics->max_advance = ( FT_MulFix( face->root.max_advance_width,
metrics->x_scale ) + 32 ) & -64;
/* Scale the cvt values to the new ppem. */
/* We use by default the y ppem to scale the CVT. */
for ( i = 0; i < size->cvt_size; i++ )
size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
/* All twilight points are originally zero */
for ( j = 0; j < size->twilight.n_points; j++ )
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
{
size->twilight.org[j].x = 0;
size->twilight.org[j].y = 0;
size->twilight.cur[j].x = 0;
size->twilight.cur[j].y = 0;
}
/* clear storage area */
for ( i = 0; i < size->storage_size; i++ )
size->storage[i] = 0;
size->GS = tt_default_graphics_state;
/* get execution context and run prep program */
if ( size->debug )
exec = size->context;
else
exec = TT_New_Context( face );
/* debugging instances have their own context */
if ( !exec )
return TT_Err_Could_Not_Find_Context;
TT_Load_Context( exec, face, size );
TT_Set_CodeRange( exec,
tt_coderange_cvt,
face->cvt_program,
face->cvt_program_size );
TT_Clear_CodeRange( exec, tt_coderange_glyph );
exec->instruction_trap = FALSE;
exec->top = 0;
exec->callTop = 0;
if ( face->cvt_program_size > 0 )
{
error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
if ( error )
goto Fin;
TT_ExecContext exec;
TT_UInt i, j;
/* Scale the cvt values to the new ppem. */
/* We use by default the y ppem to scale the CVT. */
for ( i = 0; i < size->cvt_size; i++ )
size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
/* All twilight points are originally zero */
for ( j = 0; j < size->twilight.n_points; j++ )
{
size->twilight.org[j].x = 0;
size->twilight.org[j].y = 0;
size->twilight.cur[j].x = 0;
size->twilight.cur[j].y = 0;
}
/* clear storage area */
for ( i = 0; i < size->storage_size; i++ )
size->storage[i] = 0;
size->GS = tt_default_graphics_state;
/* get execution context and run prep program */
if ( size->debug )
exec = size->context;
else
exec = TT_New_Context( face );
/* debugging instances have their own context */
if ( !exec )
return TT_Err_Could_Not_Find_Context;
TT_Load_Context( exec, face, size );
TT_Set_CodeRange( exec,
tt_coderange_cvt,
face->cvt_program,
face->cvt_program_size );
TT_Clear_CodeRange( exec, tt_coderange_glyph );
exec->instruction_trap = FALSE;
exec->top = 0;
exec->callTop = 0;
if ( face->cvt_program_size > 0 )
{
error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
if ( error )
goto Fin;
if ( !size->debug )
error = face->interpreter( exec );
}
else
error = TT_Err_Ok;
size->GS = exec->GS;
/* save default graphics state */
Fin:
TT_Save_Context( exec, size );
if ( !size->debug )
error = face->interpreter( exec );
TT_Done_Context( exec );
/* debugging instances keep their context */
}
else
error = TT_Err_Ok;
size->GS = exec->GS;
/* save default graphics state */
Fin:
TT_Save_Context( exec, size );
if ( !size->debug )
TT_Done_Context( exec );
/* debugging instances keep their context */
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
if ( !error )
size->ttmetrics.valid = TRUE;
@ -888,12 +906,14 @@
TT_Done_Extensions( driver );
#endif
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
/* destroy the execution context */
if ( driver->context )
{
TT_Destroy_Context( driver->context, driver->root.memory );
driver->context = NULL;
}
#endif
}

View File

@ -330,6 +330,7 @@
TT_Size_Metrics ttmetrics;
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
TT_UInt num_function_defs; /* number of function definitions */
TT_UInt max_function_defs;
TT_DefArray function_defs; /* table of function definitions */
@ -362,6 +363,8 @@
TT_Bool debug;
TT_ExecContext context;
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
} TT_SizeRec;