Formatting, improving comments.

This commit is contained in:
Werner Lemberg 2005-12-20 12:01:58 +00:00
parent ce34d122ba
commit b79b513380
9 changed files with 289 additions and 238 deletions

View File

@ -18,33 +18,65 @@
2005-12-13 David Turner <david@freetype.org> 2005-12-13 David Turner <david@freetype.org>
* src/autofit/aflatin.c, src/autofit/afhints.c: changed the Change the implementation of the LIGHT hinting mode to completely
implementation of the LIGHT hinting mode to completely disable disable horizontal hinting. This is an experimental effort to
horizontal hinting. This is an experimental effort to integrate integrate David Chester's latest patch without affecting the other
David Chester's latest patch without fucking the other hinting hinting modes as well.
modes as well.
Note that this doesn't force auto-hinting for all fonts however. Note that this doesn't force auto-hinting for all fonts, however.
* Jamfile: small fix to ensure that ftexport.sym is placed in the * src/autofit/afhints.c (af_glyph_hints_reload): Don't set
same location than other generated objects (i.e. within the 'objs' scaler_fiags here but...
directory of the current dir) (af_glyph_hints_rescale): Here.
* include/freetype/config/ftoption.h, * src/autofit/aflatin.c (af_latin_hints_init): Disable horizontal
include/freetype/config/ftstdlib.h, hinting for `light' hinting mode.
include/freetype/internal/tttypes.h,
src/sfnt/Jamfile, src/sfnt/rules.mk, src/sfnt/sfdriver.c,
src/sfnt/ttbdf.h, src/sfnt/ttbdf.c, src/sfnt/sfobjs.c:
Added support for an embedded 'BDF ' table within SFNT-based
bitmap font files. This is used to store atoms & properties from
the original BDF fonts that were used to generate the font file.
the feature is controled by TT_CONFIG_OPTION_BDF within 'ftoption.h' * Jamfile: Small fix to ensure that ftexport.sym is placed into the
and is used to implement FT_Get_BDF_Property for these font files. same location as other generated objects (i.e., within the `objs'
directory of the current directory).
At the moment, this is still experimental, the BDF table format isn't
cast into stone yet. Add support for an embedded `BDF ' table within SFNT-based bitmap
font files. This is used to store atoms & properties from the
original BDF fonts that were used to generate the font file.
The feature is controlled by TT_CONFIG_OPTION_BDF within
`ftoption.h' and is used to implement FT_Get_BDF_Property for these
font files.
At the moment, this is still experimental, the BDF table format
isn't cast into stone yet.
* include/freetype/config/ftoption.h (TT_CONFIG_OPTION_BDF): New
macro.
* include/freetype/config/ftstdlib.h (ft_memchr): New macro.
* include/freetype/internal/tttypes.h (TT_BDFRec, TT_BDF)
[TT_CONFIG_OPTION_BDF]: New structure.
(TT_FaceRec) [TT_CONFIG_OPTION_BDF]: New member `bdf'.
* include/freetype/ttags.h (TTAG_BDF): New macro.
* src/sfnt/Jamfile (_sources): Add ttbdf.
* src/sfnt/rules.mk (SFNT_DRV_SRC): Add ttbdf.c.
* src/sfnt/sfdriver.c [TT_CONFIG_OPTION_BDF]: Include ttbdf.h and
FT_SERVICE_BDF_H.
(sfnt_get_charset_it) [TT_CONFIG_OPTION_BDF]: New function.
(sfnt_service_bdf) [TT_CONFIG_OPTION_BDF]: New service.
(sfnt_servives) [TT_CONFIG_OPTION_BDF]: Add sfnt_service_bdf.
* src/sfnt/sfnt.c [TT_CONFIG_OPTION_BDF]: Include ttbdf.c.
* src/sfnt/sfobjs.c [TT_CONFIG_OPTION_BDF]: Include ttbdf.h.
(sfnt_done_face) [TT_CONFIG_OPTION_BDF]: Call
tt_face_free_bdf_props.
* src/sfnt/ttbdf.h, src/sfnt/ttbdf.c: New files.
2005-12-07 Werner Lemberg <wl@gnu.org> 2005-12-07 Werner Lemberg <wl@gnu.org>

View File

@ -14,8 +14,8 @@ LATEST CHANGES BETWEEN 2.2.0 and 2.1.10
II. IMPORTANT CHANGES II. IMPORTANT CHANGES
- Face metrics (face->size->metrics) and glyph metrics are no - Face metrics (face->size->metrics) and glyph metrics are no
longer rounded. If you do not round in your applications too, longer rounded. If you do not round in your applications too,
you may find glyphs become blurry. you may find glyphs become blurry.
- A new API `FT_TrueTypeGX_Validate' (in FT_GX_VALIDATE_H) has - A new API `FT_TrueTypeGX_Validate' (in FT_GX_VALIDATE_H) has

View File

@ -493,11 +493,12 @@ FT_BEGIN_HEADER
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* Define TT_CONFIG_OPTION_BDF if upi want to include support for */ /* Define TT_CONFIG_OPTION_BDF if you want to include support for */
/* an embedded 'BDF' table within SFNT-based bitmap formats. */ /* an embedded `BDF ' table within SFNT-based bitmap formats. */
/* */ /* */
#define TT_CONFIG_OPTION_BDF #define TT_CONFIG_OPTION_BDF
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/**** ****/ /**** ****/

View File

@ -5,7 +5,7 @@
/* ANSI-specific library and header configuration file (specification */ /* ANSI-specific library and header configuration file (specification */
/* only). */ /* only). */
/* */ /* */
/* Copyright 2002, 2003, 2004 by */ /* Copyright 2002, 2003, 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */

View File

@ -848,59 +848,63 @@ FT_BEGIN_HEADER
/*************************************************************************/ /*************************************************************************/
/*** ***/ /*** ***/
/*** ***/ /*** ***/
/*** EMBEDDED BDF PROPERTIES TABLE SUPPORT ***/ /*** EMBEDDED BDF PROPERTIES TABLE SUPPORT ***/
/*** ***/ /*** ***/
/*** ***/ /*** ***/
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/* these types are used to support a 'BDF' table that isn't part of the /*
* official TrueType specification. It is mainly used in SFNT-based bitmap * These types are used to support a `BDF ' table that isn't part of the
* fonts that were generated from a set of BDF fonts * official TrueType specification. It is mainly used in SFNT-based
* * bitmap fonts that were generated from a set of BDF fonts.
* the format of the table is the following: *
* * The format of the table is as follows.
* USHORT version 'BDF' table version number, should be 0x0001 *
* USHORT strikeCount number of strikes (bitmap sizes) in this table * USHORT version `BDF ' table version number, should be 0x0001.
* ULONG stringTable offset (froms start of BDF table) to string table * USHORT strikeCount Number of strikes (bitmap sizes) in this table.
* * ULONG stringTable Offset (froms start of BDF table) to string
* followed by an array of 'strikeCount' descriptors that look like: * table.
* *
* USHORT ppem vertical pixels per EM for this strike * This is followed by an array of `strikeCount' descriptors, having the
* USHORT numItems number of items for this strike (properties and * following format.
* atoms), max is 255 *
* * USHORT ppem Vertical pixels per EM for this strike.
* this array is followed by 'strikeCount' value sets. Each "value set" * USHORT numItems Number of items for this strike (properties and
* is an array of 'numItems' items that look like the following: * atoms). Maximum is 255.
* *
* ULONG item_name offset in string table to item name * This array in turn is followed by `strikeCount' value sets. Each
* USHORT item_type 0 => string (e.g. COMMENT) * `value set' is an array of `numItems' items with the following format.
* 1 => atom (e.g. FONT or even SIZE) *
* 2 => int32 * ULONG item_name Offset in string table to item name.
* 3 => uint32 * USHORT item_type The item type. Possible values are
* 0x10 => flag for properties, ored with above values * 0 => string (e.g., COMMENT)
* * 1 => atom (e.g., FONT or even SIZE)
* ULONG item_value for strings => offset in string table without * 2 => int32
* the corresponding double quotes * 3 => uint32
* * 0x10 => A flag to indicate a properties. This
* atoms => offset in string table * is ORed with the above values.
* * ULONG item_value For strings => Offset into string table without
* integers => direct value * the corresponding double quotes.
* * For atoms => Offset into string table.
* all strings in the string table are 8-bit, zero-terminated * For integers => Direct value.
*/ *
* All strings in the string table consist of bytes and are
* zero-terminated.
*
*/
#ifdef TT_CONFIG_OPTION_BDF #ifdef TT_CONFIG_OPTION_BDF
typedef struct TT_BDFRec_ typedef struct TT_BDFRec_
{ {
FT_Byte* table; FT_Byte* table;
FT_Byte* table_end; FT_Byte* table_end;
FT_Byte* strings; FT_Byte* strings;
FT_UInt32 strings_size; FT_UInt32 strings_size;
FT_UInt num_strikes; FT_UInt num_strikes;
FT_Bool loaded; FT_Bool loaded;
} TT_BDFRec, *TT_BDF; } TT_BDFRec, *TT_BDF;
@ -1405,7 +1409,7 @@ FT_BEGIN_HEADER
#endif #endif
#ifdef TT_CONFIG_OPTION_BDF #ifdef TT_CONFIG_OPTION_BDF
TT_BDFRec bdf; TT_BDFRec bdf;
#endif /* TT_CONFIG_OPTION_BDF */ #endif /* TT_CONFIG_OPTION_BDF */
/***********************************************************************/ /***********************************************************************/

View File

@ -1308,7 +1308,7 @@
hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale; hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta; hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
/* compute flags depending on render mode, etc... */ /* compute flags depending on render mode, etc. */
mode = metrics->root.scaler.render_mode; mode = metrics->root.scaler.render_mode;
scaler_flags = hints->scaler_flags; scaler_flags = hints->scaler_flags;
@ -1337,7 +1337,8 @@
if ( mode == FT_RENDER_MODE_MONO ) if ( mode == FT_RENDER_MODE_MONO )
other_flags |= AF_LATIN_HINTS_MONO; other_flags |= AF_LATIN_HINTS_MONO;
/* in 'light' hinting mode, we disable horizontal hinting completely /*
* In `light' hinting mode we disable horizontal hinting completely.
*/ */
if ( mode == FT_RENDER_MODE_LIGHT ) if ( mode == FT_RENDER_MODE_LIGHT )
scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL; scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;

View File

@ -289,15 +289,15 @@
}; };
/* /*
* TT CMAP INFO * TT CMAP INFO
* */
*/
static const FT_Service_TTCMapsRec tt_service_get_cmap_info = static const FT_Service_TTCMapsRec tt_service_get_cmap_info =
{ {
(TT_CMap_Info_GetFunc)tt_get_cmap_info (TT_CMap_Info_GetFunc)tt_get_cmap_info
}; };
#ifdef TT_CONFIG_OPTION_BDF #ifdef TT_CONFIG_OPTION_BDF
static FT_Error static FT_Error
@ -305,15 +305,16 @@
const char* *acharset_encoding, const char* *acharset_encoding,
const char* *acharset_registry ) const char* *acharset_registry )
{ {
BDF_PropertyRec encoding, registry; BDF_PropertyRec encoding, registry;
FT_Error error; FT_Error error;
/* XXX: I don't know if this is correct, since tt_face_find_bdf_prop
* will only return something correct if we have previously /* XXX: I don't know whether this is correct, since
* selected a size that is listed in the BDF table. * tt_face_find_bdf_prop only returns something correct if we have
* should we change the BDF table format to include single * previously selected a size that is listed in the BDF table.
* offsets for "CHARSET_REGISTRY" and "CHARSET_ENCODING" ? * Should we change the BDF table format to include single offsets
*/ * for `CHARSET_REGISTRY' and `CHARSET_ENCODING'?
*/
error = tt_face_find_bdf_prop( face, "CHARSET_REGISTRY", &registry ); error = tt_face_find_bdf_prop( face, "CHARSET_REGISTRY", &registry );
if ( !error ) if ( !error )
{ {
@ -344,10 +345,9 @@
#endif /* TT_CONFIG_OPTION_BDF */ #endif /* TT_CONFIG_OPTION_BDF */
/* /*
* SERVICE LIST * SERVICE LIST
* */
*/
static const FT_ServiceDescRec sfnt_services[] = static const FT_ServiceDescRec sfnt_services[] =
{ {

View File

@ -31,6 +31,7 @@
#include "ttbdf.h" #include "ttbdf.h"
#endif #endif
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */

View File

@ -24,6 +24,7 @@
#include "sferrors.h" #include "sferrors.h"
#ifdef TT_CONFIG_OPTION_BDF #ifdef TT_CONFIG_OPTION_BDF
/*************************************************************************/ /*************************************************************************/
@ -35,168 +36,176 @@
#undef FT_COMPONENT #undef FT_COMPONENT
#define FT_COMPONENT trace_ttbdf #define FT_COMPONENT trace_ttbdf
FT_LOCAL_DEF( void )
tt_face_free_bdf_props( TT_Face face )
{
TT_BDF bdf = &face->bdf;
if ( bdf->loaded ) FT_LOCAL_DEF( void )
tt_face_free_bdf_props( TT_Face face )
{ {
FT_Stream stream = FT_FACE(face)->stream; TT_BDF bdf = &face->bdf;
if ( bdf->table != NULL )
FT_FRAME_RELEASE( bdf->table );
bdf->table_end = NULL;
bdf->strings = NULL;
bdf->strings_size = 0;
}
}
static FT_Error if ( bdf->loaded )
tt_face_load_bdf_props( TT_Face face, {
FT_Stream stream ) FT_Stream stream = FT_FACE(face)->stream;
{
TT_BDF bdf = &face->bdf;
FT_ULong length; if ( bdf->table != NULL )
FT_Error error; FT_FRAME_RELEASE( bdf->table );
FT_ZERO( bdf ); bdf->table_end = NULL;
bdf->strings = NULL;
error = tt_face_goto_table( face, TTAG_BDF, stream, &length ); bdf->strings_size = 0;
if ( error || }
length < 8 || }
FT_FRAME_EXTRACT( length, bdf->table ) )
{
error = FT_Err_Invalid_Table; static FT_Error
goto Exit; tt_face_load_bdf_props( TT_Face face,
} FT_Stream stream )
{
bdf->table_end = bdf->table + length; TT_BDF bdf = &face->bdf;
FT_ULong length;
{ FT_Error error;
FT_Byte* p = bdf->table;
FT_UInt version = FT_NEXT_USHORT(p);
FT_UInt num_strikes = FT_NEXT_USHORT(p); FT_ZERO( bdf );
FT_UInt32 strings = FT_NEXT_ULONG(p);
error = tt_face_goto_table( face, TTAG_BDF, stream, &length );
if ( version != 0x0001 || if ( error ||
strings < 8 || length < 8 ||
(strings-8)/4 < num_strikes || FT_FRAME_EXTRACT( length, bdf->table ) )
strings+1 > length )
{ {
BadTable:
FT_FRAME_RELEASE( bdf->table );
FT_ZERO( bdf );
error = FT_Err_Invalid_Table; error = FT_Err_Invalid_Table;
goto Exit; goto Exit;
} }
bdf->num_strikes = num_strikes; bdf->table_end = bdf->table + length;
bdf->strings = bdf->table + strings;
bdf->strings_size = length - strings; {
FT_Byte* p = bdf->table;
FT_UInt version = FT_NEXT_USHORT( p );
FT_UInt num_strikes = FT_NEXT_USHORT( p );
FT_UInt32 strings = FT_NEXT_ULONG ( p );
if ( version != 0x0001 ||
strings < 8 ||
( strings - 8 ) / 4 < num_strikes ||
strings + 1 > length )
{
BadTable:
FT_FRAME_RELEASE( bdf->table );
FT_ZERO( bdf );
error = FT_Err_Invalid_Table;
goto Exit;
}
bdf->num_strikes = num_strikes;
bdf->strings = bdf->table + strings;
bdf->strings_size = length - strings;
}
/* check the strike descriptors */
{
FT_UInt count = bdf->num_strikes;
FT_Byte* p = bdf->table + 8;
FT_Byte* strike = p + count * 4;
for ( ; count > 0; count-- )
{
FT_UInt num_items = FT_PEEK_USHORT( p + 2 );
/*
* We don't need to check the value sets themselves, since this
* is done later.
*/
strike += 10 * num_items;
p += 4;
}
if ( strike > bdf->strings )
goto BadTable;
}
bdf->loaded = 1;
Exit:
return error;
} }
/* check the strike descriptors
*/ FT_LOCAL_DEF( FT_Error )
tt_face_find_bdf_prop( TT_Face face,
const char* property_name,
BDF_PropertyRec *aprop )
{ {
FT_UInt count = bdf->num_strikes; TT_BDF bdf = &face->bdf;
FT_Byte* p = bdf->table + 8; FT_Size size = FT_FACE(face)->size;
FT_Byte* strike = p + count*4; FT_Error error = 0;
FT_Byte* p;
FT_UInt count;
FT_Byte* strike;
FT_UInt property_len;
aprop->type = BDF_PROPERTY_TYPE_NONE;
if ( bdf->loaded == 0 )
{
error = tt_face_load_bdf_props( face, FT_FACE( face )->stream );
if ( error )
goto Exit;
}
count = bdf->num_strikes;
p = bdf->table + 8;
strike = p + 4 * count;
error = FT_Err_Invalid_Argument;
if ( size == NULL || property_name == NULL )
goto Exit;
property_len = ft_strlen( property_name );
if ( property_len == 0 )
goto Exit;
for ( ; count > 0; count-- ) for ( ; count > 0; count-- )
{ {
FT_UInt num_items = FT_PEEK_USHORT(p+2); FT_UInt _ppem = FT_NEXT_USHORT( p );
FT_UInt _count = FT_NEXT_USHORT( p );
/* we don't need to check the value sets themselves, since this if ( _ppem == size->metrics.y_ppem )
* is done later
*/
strike += 10*num_items;
p += 4;
}
if ( strike > bdf->strings )
goto BadTable;
}
bdf->loaded = 1;
Exit:
return error;
}
FT_LOCAL_DEF( FT_Error )
tt_face_find_bdf_prop( TT_Face face,
const char* property_name,
BDF_PropertyRec *aprop )
{
TT_BDF bdf = &face->bdf;
FT_Size size = FT_FACE(face)->size;
FT_Error error = 0;
FT_Byte* p;
FT_UInt count;
FT_Byte* strike;
FT_UInt property_len;
aprop->type = BDF_PROPERTY_TYPE_NONE;
if ( bdf->loaded == 0 )
{
error = tt_face_load_bdf_props( face, FT_FACE(face)->stream );
if ( error )
goto Exit;
}
count = bdf->num_strikes;
p = bdf->table + 8;
strike = p + 4*count;
error = FT_Err_Invalid_Argument;
if ( size == NULL || property_name == NULL )
goto Exit;
property_len = ft_strlen( property_name );
if ( property_len == 0 )
goto Exit;
for ( ; count > 0; count-- )
{
FT_UInt _ppem = FT_NEXT_USHORT(p);
FT_UInt _count = FT_NEXT_USHORT(p);
if ( _ppem == size->metrics.y_ppem )
{
count = _count;
goto FoundStrike;
}
strike += 10*_count;
}
goto Exit;
FoundStrike:
p = strike;
for ( ; count > 0; count-- )
{
FT_UInt type = FT_PEEK_USHORT(p+4);
if ( (type & 0x10) != 0 )
{
FT_UInt32 name_offset = FT_PEEK_ULONG(p);
FT_UInt32 value = FT_PEEK_ULONG(p+6);
/* be a bit paranoid for invalid entries here */
if ( name_offset < bdf->strings_size &&
property_len < bdf->strings_size - name_offset &&
ft_strncmp( property_name, (const char*)bdf->strings + name_offset,
bdf->strings_size - name_offset ) == 0 )
{ {
switch ( type & 0x0F ) count = _count;
goto FoundStrike;
}
strike += 10 * _count;
}
goto Exit;
FoundStrike:
p = strike;
for ( ; count > 0; count-- )
{
FT_UInt type = FT_PEEK_USHORT( p + 4 );
if ( ( type & 0x10 ) != 0 )
{
FT_UInt32 name_offset = FT_PEEK_ULONG( p );
FT_UInt32 value = FT_PEEK_ULONG( p + 6 );
/* be a bit paranoid for invalid entries here */
if ( name_offset < bdf->strings_size &&
property_len < bdf->strings_size - name_offset &&
ft_strncmp( property_name,
(const char*)bdf->strings + name_offset,
bdf->strings_size - name_offset ) == 0 )
{ {
switch ( type & 0x0F )
{
case 0x00: /* string */ case 0x00: /* string */
case 0x01: /* atoms */ case 0x01: /* atoms */
/* check that the content is really 0-terminated */ /* check that the content is really 0-terminated */
@ -204,7 +213,7 @@ FoundStrike:
ft_memchr( bdf->strings + value, 0, bdf->strings_size ) ) ft_memchr( bdf->strings + value, 0, bdf->strings_size ) )
{ {
aprop->type = BDF_PROPERTY_TYPE_ATOM; aprop->type = BDF_PROPERTY_TYPE_ATOM;
aprop->u.atom = (const char*) bdf->strings + value; aprop->u.atom = (const char*)bdf->strings + value;
error = 0; error = 0;
goto Exit; goto Exit;
} }
@ -224,14 +233,17 @@ FoundStrike:
default: default:
; ;
}
} }
} }
p += 10;
} }
p += 10;
Exit:
return error;
} }
Exit:
return error;
}
#endif /* TT_CONFIG_OPTION_BDF */ #endif /* TT_CONFIG_OPTION_BDF */
/* END */