[bdf] Add more error messages.

* src/bdf/bdflib.c (_bdf_set_default_spacing, _bdf_add_property):
Add line number argument.
Update all callers.
(ERRMSG5, ERRMSG6, ERRMSG7, ERRMSG8, ERRMSG9): New macros.
(_bdf_readstream, _bdf_set_default_spacing, _bdf_add_property,
_bdf_parse_glyphs, _bdf_parse_start): Add error messages.
This commit is contained in:
Werner Lemberg 2011-11-25 09:44:28 +01:00
parent fd905c02dd
commit e01406bb91
2 changed files with 86 additions and 56 deletions

View File

@ -1,3 +1,14 @@
2011-11-25 Werner Lemberg <wl@gnu.org>
[bdf] Add more error messages.
* src/bdf/bdflib.c (_bdf_set_default_spacing, _bdf_add_property):
Add line number argument.
Update all callers.
(ERRMSG5, ERRMSG6, ERRMSG7, ERRMSG8, ERRMSG9): New macros.
(_bdf_readstream, _bdf_set_default_spacing, _bdf_add_property,
_bdf_parse_glyphs, _bdf_parse_start): Add error messages.
2011-11-24 Werner Lemberg <wl@gnu.org>
* include/freetype/fterrors.h: Remove dead code.

View File

@ -169,6 +169,38 @@
sizeof ( _bdf_properties[0] );
/* Auto correction messages. */
#define ACMSG1 "FONT_ASCENT property missing. " \
"Added `FONT_ASCENT %hd'.\n"
#define ACMSG2 "FONT_DESCENT property missing. " \
"Added `FONT_DESCENT %hd'.\n"
#define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n"
#define ACMSG4 "Font left bearing != actual left bearing. " \
"Old: %hd New: %hd.\n"
#define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n"
#define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n"
#define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n"
#define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n"
#define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n"
#define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n"
#define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n"
#define ACMSG12 "Duplicate encoding %ld (%s) changed to unencoded.\n"
#define ACMSG13 "Glyph %ld extra rows removed.\n"
#define ACMSG14 "Glyph %ld extra columns removed.\n"
#define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n"
/* Error messages. */
#define ERRMSG1 "[line %ld] Missing `%s' line.\n"
#define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n"
#define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n"
#define ERRMSG4 "[line %ld] BBX too big.\n"
#define ERRMSG5 "[line %ld] `%s' value too big.\n"
#define ERRMSG6 "[line %ld] Input line too long.\n"
#define ERRMSG7 "[line %ld] Font name too long.\n"
#define ERRMSG8 "[line %ld] Invalid `%s' value.\n"
#define ERRMSG9 "[line %ld] Invalid keyword.\n"
/*************************************************************************/
/* */
/* Hash table utilities for the properties. */
@ -687,6 +719,7 @@
if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */
{
FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno ));
error = BDF_Err_Invalid_Argument;
goto Exit;
}
@ -1079,33 +1112,6 @@
#define _BDF_GLYPH_HEIGHT_CHECK 0x80000000UL
/* Auto correction messages. */
#define ACMSG1 "FONT_ASCENT property missing. " \
"Added \"FONT_ASCENT %hd\".\n"
#define ACMSG2 "FONT_DESCENT property missing. " \
"Added \"FONT_DESCENT %hd\".\n"
#define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n"
#define ACMSG4 "Font left bearing != actual left bearing. " \
"Old: %hd New: %hd.\n"
#define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n"
#define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n"
#define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n"
#define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n"
#define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n"
#define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n"
#define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n"
#define ACMSG12 "Duplicate encoding %ld (%s) changed to unencoded.\n"
#define ACMSG13 "Glyph %ld extra rows removed.\n"
#define ACMSG14 "Glyph %ld extra columns removed.\n"
#define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n"
/* Error messages. */
#define ERRMSG1 "[line %ld] Missing \"%s\" line.\n"
#define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n"
#define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n"
#define ERRMSG4 "[line %ld] BBX too big.\n"
static FT_Error
_bdf_add_comment( bdf_font_t* font,
char* comment,
@ -1137,7 +1143,8 @@
/* default specified in the options. */
static FT_Error
_bdf_set_default_spacing( bdf_font_t* font,
bdf_options_t* opts )
bdf_options_t* opts,
unsigned long lineno )
{
size_t len;
char name[256];
@ -1162,6 +1169,7 @@
/* Limit ourselves to 256 characters in the font name. */
if ( len >= 256 )
{
FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno ));
error = BDF_Err_Invalid_Argument;
goto Exit;
}
@ -1265,9 +1273,10 @@
static FT_Error
_bdf_add_property( bdf_font_t* font,
char* name,
char* value )
_bdf_add_property( bdf_font_t* font,
char* name,
char* value,
unsigned long lineno )
{
size_t propid;
hashnode hn;
@ -1405,6 +1414,7 @@
{
if ( !fp->value.atom )
{
FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
@ -1493,8 +1503,9 @@
/* Limit ourselves to 1,114,112 glyphs in the font (this is the */
/* number of code points available in Unicode). */
if ( p->cnt >= 1114112UL )
if ( p->cnt >= 0x110000UL )
{
FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "CHARS" ));
error = BDF_Err_Invalid_Argument;
goto Exit;
}
@ -1554,6 +1565,7 @@
if ( !s )
{
FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG8, lineno, "STARTCHAR" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
@ -1590,6 +1602,7 @@
if ( p->glyph_enc > 0 &&
(size_t)p->glyph_enc >= sizeof ( p->have ) * 8 )
{
FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "ENCODING" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
@ -1851,7 +1864,7 @@
}
/* Allocate enough space for the bitmap. */
glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3;
glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3;
bitmap_size = glyph->bpr * glyph->bbx.height;
if ( bitmap_size > 0xFFFFU )
@ -1872,6 +1885,7 @@
goto Exit;
}
FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG9, lineno ));
error = BDF_Err_Invalid_File_Format;
Exit:
@ -1917,7 +1931,8 @@
{
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", nbuf );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
@ -1929,7 +1944,8 @@
{
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", nbuf );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
@ -1955,13 +1971,13 @@
value += 7;
if ( *value )
*value++ = 0;
error = _bdf_add_property( p->font, name, value );
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) )
{
error = _bdf_add_property( p->font, name, value );
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
@ -1975,7 +1991,7 @@
_bdf_list_shift( &p->list, 1 );
value = _bdf_list_join( &p->list, ' ', &vlen );
error = _bdf_add_property( p->font, name, value );
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
@ -2042,6 +2058,7 @@
if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
{
/* No STARTFONT field is a good indication of a problem. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "STARTFONT" ));
error = BDF_Err_Missing_Startfont_Field;
goto Exit;
}
@ -2154,6 +2171,7 @@
if ( !s )
{
FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
@ -2167,7 +2185,7 @@
/* If the font name is an XLFD name, set the spacing to the one in */
/* the font name. If there is no spacing fall back on the default. */
error = _bdf_set_default_spacing( p->font, p->opts );
error = _bdf_set_default_spacing( p->font, p->opts, lineno );
if ( error )
goto Exit;
@ -2248,14 +2266,16 @@
/* for compiling fonts. */
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", nbuf );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", nbuf );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
@ -2269,6 +2289,7 @@
goto Exit;
}
FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno ));
error = BDF_Err_Invalid_File_Format;
Exit:
@ -2381,22 +2402,20 @@
if ( p->flags & _BDF_START )
{
/* The ENDFONT field was never reached or did not exist. */
if ( !( p->flags & _BDF_GLYPHS ) )
{
/* The ENDFONT field was never reached or did not exist. */
if ( !( p->flags & _BDF_GLYPHS ) )
{
/* Error happened while parsing header. */
FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
error = BDF_Err_Corrupted_Font_Header;
goto Exit;
}
else
{
/* Error happened when parsing glyphs. */
FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
error = BDF_Err_Corrupted_Font_Glyphs;
goto Exit;
}
/* Error happened while parsing header. */
FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
error = BDF_Err_Corrupted_Font_Header;
goto Exit;
}
else
{
/* Error happened when parsing glyphs. */
FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
error = BDF_Err_Corrupted_Font_Glyphs;
goto Exit;
}
}