@ -657,8 +657,8 @@
FT_LOCAL_DEF ( FT_Error )
tt_face_load_header ( TT_Face face ,
FT_Stream stream )
tt_face_load_head ( TT_Face face ,
FT_Stream stream )
{
return tt_face_load_generic_header ( face , stream , TTAG_head ) ;
}
@ -667,8 +667,8 @@
# ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
FT_LOCAL_DEF ( FT_Error )
tt_face_load_bitmap_ hea der ( TT_Face face ,
FT_Stream stream )
tt_face_load_bhed ( TT_Face face ,
FT_Stream stream )
{
return tt_face_load_generic_header ( face , stream , TTAG_bhed ) ;
}
@ -693,8 +693,8 @@
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF ( FT_Error )
tt_face_load_max_ profile ( TT_Face face ,
FT_Stream stream )
tt_face_load_maxp ( TT_Face face ,
FT_Stream stream )
{
FT_Error error ;
TT_MaxProfile * maxProfile = & face - > max_profile ;
@ -798,358 +798,6 @@
}
/*************************************************************************/
/* */
/* <Function> */
/* tt_face_load_metrics */
/* */
/* <Description> */
/* Loads the horizontal or vertical metrics table into a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* vertical :: A boolean flag. If set, load vertical metrics. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
# ifdef FT_OPTIMIZE_MEMORY
static FT_Error
tt_face_load_metrics ( TT_Face face ,
FT_Stream stream ,
FT_Bool vertical )
{
FT_Error error ;
FT_ULong table_size ;
FT_Byte * * ptable ;
FT_ULong * ptable_size ;
FT_TRACE2 ( ( " TT_Load_%s_Metrics: %08p \n " , vertical ? " Vertical "
: " Horizontal " ,
face ) ) ;
if ( vertical )
{
ptable = & face - > vert_metrics ;
ptable_size = & face - > vert_metrics_size ;
/* The table is optional, quit silently if it wasn't found. */
/* */
/* 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_size ) ;
if ( error )
{
/* Set number_Of_VMetrics to 0! */
FT_TRACE2 ( ( " no vertical header in file. \n " ) ) ;
error = SFNT_Err_Ok ;
goto Exit ;
}
}
else
{
ptable = & face - > horz_metrics ;
ptable_size = & face - > horz_metrics_size ;
error = face - > goto_table ( face , TTAG_hmtx , stream , & table_size ) ;
if ( error )
{
# ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font and there are */
/* overriding metrics, tolerate a missing `hmtx' table. */
if ( face - > root . internal - > incremental_interface & &
face - > root . internal - > incremental_interface - > funcs - >
get_glyph_metrics )
{
face - > horizontal . number_Of_HMetrics = 0 ;
error = SFNT_Err_Ok ;
goto Exit ;
}
# endif
FT_ERROR ( ( " no horizontal metrics in file! \n " ) ) ;
error = SFNT_Err_Hmtx_Table_Missing ;
goto Exit ;
}
}
if ( FT_FRAME_EXTRACT ( table_size , * ptable ) )
goto Exit ;
* ptable_size = table_size ;
Exit :
return error ;
}
# else /* !OPTIMIZE_MEMORY */
static FT_Error
tt_face_load_metrics ( TT_Face face ,
FT_Stream stream ,
FT_Bool vertical )
{
FT_Error error ;
FT_Memory memory = stream - > memory ;
FT_ULong table_len ;
FT_Long num_shorts , num_longs , num_shorts_checked ;
TT_LongMetrics * longs ;
TT_ShortMetrics * * shorts ;
FT_TRACE2 ( ( " TT_Load_%s_Metrics: %08p \n " , vertical ? " Vertical "
: " Horizontal " ,
face ) ) ;
if ( vertical )
{
/* The table is optional, quit silently if it wasn't found. */
/* */
/* 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! */
FT_TRACE2 ( ( " no vertical header in file. \n " ) ) ;
face - > vertical . number_Of_VMetrics = 0 ;
error = SFNT_Err_Ok ;
goto Exit ;
}
num_longs = face - > vertical . number_Of_VMetrics ;
longs = ( TT_LongMetrics * ) & face - > vertical . long_metrics ;
shorts = ( TT_ShortMetrics * * ) & face - > vertical . short_metrics ;
}
else
{
error = face - > goto_table ( face , TTAG_hmtx , stream , & table_len ) ;
if ( error )
{
# ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font and there are */
/* overriding metrics, tolerate a missing `hmtx' table. */
if ( face - > root . internal - > incremental_interface & &
face - > root . internal - > incremental_interface - > funcs - >
get_glyph_metrics )
{
face - > horizontal . number_Of_HMetrics = 0 ;
error = SFNT_Err_Ok ;
goto Exit ;
}
# endif
FT_ERROR ( ( " no horizontal metrics in file! \n " ) ) ;
error = SFNT_Err_Hmtx_Table_Missing ;
goto Exit ;
}
num_longs = face - > horizontal . number_Of_HMetrics ;
longs = ( TT_LongMetrics * ) & face - > horizontal . long_metrics ;
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 ;
if ( num_shorts < 0 )
{
FT_ERROR ( ( " TT_Load_%s_Metrics: more metrics than glyphs! \n " ,
vertical ? " Vertical "
: " Horizontal " ) ) ;
/* Adobe simply ignores this problem. So we shall do the same. */
#if 0
error = vertical ? SFNT_Err_Invalid_Vert_Metrics
: SFNT_Err_Invalid_Horiz_Metrics ;
goto Exit ;
# else
num_shorts = 0 ;
# endif
}
if ( FT_QNEW_ARRAY ( * longs , num_longs ) | |
FT_QNEW_ARRAY ( * shorts , num_shorts ) )
goto Exit ;
if ( FT_FRAME_ENTER ( table_len ) )
goto Exit ;
{
TT_LongMetrics cur = * longs ;
TT_LongMetrics limit = cur + num_longs ;
for ( ; cur < limit ; cur + + )
{
cur - > advance = FT_GET_USHORT ( ) ;
cur - > bearing = FT_GET_SHORT ( ) ;
}
}
/* do we have an inconsistent number of metric values? */
{
TT_ShortMetrics * cur = * shorts ;
TT_ShortMetrics * limit = cur +
FT_MIN ( num_shorts , num_shorts_checked ) ;
for ( ; cur < limit ; cur + + )
* cur = FT_GET_SHORT ( ) ;
/* 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. */
if ( num_shorts > num_shorts_checked & & num_shorts_checked > 0 )
{
FT_Short val = ( * shorts ) [ num_shorts_checked - 1 ] ;
limit = * shorts + num_shorts ;
for ( ; cur < limit ; cur + + )
* cur = val ;
}
}
FT_FRAME_EXIT ( ) ;
FT_TRACE2 ( ( " loaded \n " ) ) ;
Exit :
return error ;
}
# endif /* !FT_OPTIMIZE_METRICS */
/*************************************************************************/
/* */
/* <Function> */
/* tt_face_load_metrics_header */
/* */
/* <Description> */
/* Loads the horizontal or vertical header in a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* vertical :: A boolean flag. If set, load vertical metrics. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF ( FT_Error )
tt_face_load_metrics_header ( TT_Face face ,
FT_Stream stream ,
FT_Bool vertical )
{
FT_Error error ;
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
} ;
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 )
{
error = SFNT_Err_Ok ;
goto Exit ;
}
face - > vertical_info = 1 ;
header = ( TT_HoriHeader * ) & face - > vertical ;
}
else
{
/* The horizontal header is mandatory for most fonts; return */
/* an error if we don't find it. */
error = face - > goto_table ( face , TTAG_hhea , stream , 0 ) ;
if ( error )
{
error = SFNT_Err_Horiz_Header_Missing ;
/* No `hhea' table necessary for SFNT Mac fonts. */
if ( face - > format_tag = = TTAG_true )
{
FT_TRACE2 ( ( " missing. This is an SFNT Mac font. \n " ) ) ;
error = SFNT_Err_Ok ;
}
goto Exit ;
}
header = & face - > horizontal ;
}
if ( FT_STREAM_READ_FIELDS ( metrics_header_fields , header ) )
goto Exit ;
header - > long_metrics = NULL ;
header - > short_metrics = NULL ;
FT_TRACE2 ( ( " loaded \n " ) ) ;
/* Now try to load the corresponding metrics */
error = tt_face_load_metrics ( face , stream , vertical ) ;
Exit :
return error ;
}
/*************************************************************************/
/* */
/* <Function> */
@ -1167,8 +815,8 @@
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF ( FT_Error )
tt_face_load_names ( TT_Face face ,
FT_Stream stream )
tt_face_load_name ( TT_Face face ,
FT_Stream stream )
{
FT_Error error ;
FT_Memory memory = stream - > memory ;
@ -1306,7 +954,7 @@
/* face :: A handle to the target face object. */
/* */
FT_LOCAL_DEF ( void )
tt_face_free_names ( TT_Face face )
tt_face_free_name ( TT_Face face )
{
FT_Memory memory = face - > root . driver - > root . memory ;
TT_NameTable table = & face - > name_table ;
@ -1539,8 +1187,8 @@
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF ( FT_Error )
tt_face_load_postscript ( TT_Face face ,
FT_Stream stream )
tt_face_load_post ( TT_Face face ,
FT_Stream stream )
{
FT_Error error ;
TT_Postscript * post = & face - > postscript ;
@ -1719,187 +1367,4 @@
}
/*************************************************************************/
/* */
/* <Function> */
/* tt_face_load_hdmx */
/* */
/* <Description> */
/* Loads the horizontal device metrics table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: A handle to the input stream. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
# ifdef FT_OPTIMIZE_MEMORY
FT_LOCAL_DEF ( FT_Error )
tt_face_load_hdmx ( TT_Face face ,
FT_Stream stream )
{
FT_Error error ;
FT_Memory memory = stream - > memory ;
FT_UInt version , nn , num_records ;
FT_ULong table_size , record_size ;
FT_Byte * p ;
FT_Byte * limit ;
/* this table is optional */
error = face - > goto_table ( face , TTAG_hdmx , stream , & table_size ) ;
if ( error | | table_size < 8 )
return SFNT_Err_Ok ;
if ( FT_FRAME_EXTRACT ( table_size , face - > hdmx_table ) )
goto Exit ;
p = face - > hdmx_table ;
limit = p + table_size ;
version = FT_NEXT_USHORT ( p ) ;
num_records = FT_NEXT_USHORT ( p ) ;
record_size = FT_NEXT_ULONG ( p ) ;
if ( version ! = 0 | | num_records > 255 | | record_size > 0x40000 )
{
error = SFNT_Err_Invalid_File_Format ;
goto Fail ;
}
if ( FT_NEW_ARRAY ( face - > hdmx_record_sizes , num_records ) )
goto Fail ;
for ( nn = 0 ; nn < num_records ; nn + + )
{
if ( p + record_size > limit )
break ;
face - > hdmx_record_sizes [ nn ] = p [ 0 ] ;
p + = record_size ;
}
face - > hdmx_record_count = nn ;
face - > hdmx_table_size = table_size ;
Exit :
return error ;
Fail :
FT_FRAME_RELEASE ( face - > hdmx_table ) ;
face - > hdmx_table_size = 0 ;
goto Exit ;
}
FT_LOCAL_DEF ( void )
tt_face_free_hdmx ( TT_Face face )
{
FT_Stream stream = face - > root . stream ;
FT_Memory memory = stream - > memory ;
FT_FREE ( face - > hdmx_record_sizes ) ;
FT_FRAME_RELEASE ( face - > hdmx_table ) ;
}
# else /* !FT_OPTIMIZE_MEMORY */
FT_LOCAL_DEF ( FT_Error )
tt_face_load_hdmx ( TT_Face face ,
FT_Stream stream )
{
FT_Error error ;
FT_Memory memory = stream - > memory ;
TT_Hdmx hdmx = & face - > hdmx ;
FT_Short num_records ;
FT_Long num_glyphs ;
FT_Long record_size ;
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 )
return SFNT_Err_Ok ;
if ( FT_FRAME_ENTER ( 8L ) )
goto Exit ;
hdmx - > version = FT_GET_USHORT ( ) ;
num_records = FT_GET_SHORT ( ) ;
record_size = FT_GET_LONG ( ) ;
FT_FRAME_EXIT ( ) ;
if ( record_size < 0 | | num_records < 0 )
return SFNT_Err_Invalid_File_Format ;
/* Only recognize format 0 */
if ( hdmx - > version ! = 0 )
goto Exit ;
/* we can't use FT_QNEW_ARRAY here; otherwise tt_face_free_hdmx */
/* could fail during deallocation */
if ( FT_NEW_ARRAY ( hdmx - > records , num_records ) )
goto Exit ;
hdmx - > num_records = num_records ;
num_glyphs = face - > root . num_glyphs ;
record_size - = num_glyphs + 2 ;
{
TT_HdmxEntry cur = hdmx - > records ;
TT_HdmxEntry limit = cur + hdmx - > num_records ;
for ( ; cur < limit ; cur + + )
{
/* read record */
if ( FT_READ_BYTE ( cur - > ppem ) | |
FT_READ_BYTE ( cur - > max_width ) )
goto Exit ;
if ( FT_QALLOC ( cur - > widths , num_glyphs ) | |
FT_STREAM_READ ( cur - > widths , num_glyphs ) )
goto Exit ;
/* skip padding bytes */
if ( record_size > 0 & & FT_STREAM_SKIP ( record_size ) )
goto Exit ;
}
}
Exit :
return error ;
}
FT_LOCAL_DEF ( void )
tt_face_free_hdmx ( TT_Face face )
{
if ( face )
{
FT_Int n ;
FT_Memory memory = face - > root . driver - > root . memory ;
for ( n = 0 ; n < face - > hdmx . num_records ; n + + )
FT_FREE ( face - > hdmx . records [ n ] . widths ) ;
FT_FREE ( face - > hdmx . records ) ;
face - > hdmx . num_records = 0 ;
}
}
# endif /* !OPTIMIZE_MEMORY */
/* END */