diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c index 438017a8b..081713979 100644 --- a/src/bdf/bdflib.c +++ b/src/bdf/bdflib.c @@ -631,10 +631,6 @@ { error = (*cb)( buf + start, end - start, lineno, (void*)&cb, client_data ); - /* Redo if we have encountered CHARS without properties. */ - if ( error == -1 ) - error = (*cb)( buf + start, end - start, lineno, - (void*)&cb, client_data ); if ( error ) break; } @@ -1267,7 +1263,15 @@ } - /* Line function prototype. */ + /* Line function prototypes. */ + static FT_Error + bdf_parse_start_( char* line, + unsigned long linelen, + unsigned long lineno, + void* call_data, + void* client_data ); + + static FT_Error bdf_parse_glyphs_( char* line, unsigned long linelen, @@ -1367,49 +1371,6 @@ goto Exit; } - /* The very first thing expected is the number of glyphs. */ - if ( !( p->flags & BDF_GLYPHS_ ) ) - { - if ( _bdf_strncmp( line, "CHARS", 5 ) != 0 ) - { - FT_ERROR(( "bdf_parse_glyphs_: " ERRMSG1, lineno, "CHARS" )); - error = FT_THROW( Missing_Chars_Field ); - goto Exit; - } - - error = bdf_list_split_( &p->list, " +", line, linelen ); - if ( error ) - goto Exit; - p->cnt = font->glyphs_size = bdf_atoul_( p->list.field[1] ); - - /* We need at least 20 bytes per glyph. */ - if ( p->cnt > p->size / 20 ) - { - p->cnt = font->glyphs_size = p->size / 20; - FT_TRACE2(( "bdf_parse_glyphs_: " ACMSG17, p->cnt )); - } - - /* Make sure the number of glyphs is non-zero. */ - if ( p->cnt == 0 ) - font->glyphs_size = 64; - - /* Limit ourselves to 1,114,112 glyphs in the font (this is the */ - /* number of code points available in Unicode). */ - if ( p->cnt >= 0x110000UL ) - { - FT_ERROR(( "bdf_parse_glyphs_: " ERRMSG5, lineno, "CHARS" )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) ) - goto Exit; - - p->flags |= BDF_GLYPHS_; - - goto Exit; - } - /* Check for the ENDFONT field. */ if ( _bdf_strncmp( line, "ENDFONT", 7 ) == 0 ) { @@ -1747,7 +1708,6 @@ unsigned long vlen; char* name; char* value; - char nbuf[BUFSIZE]; FT_UNUSED( lineno ); @@ -1755,38 +1715,8 @@ /* Check for the end of the properties. */ if ( _bdf_strncmp( line, "ENDPROPERTIES", 13 ) == 0 ) { - /* If the FONT_ASCENT or FONT_DESCENT properties have not been */ - /* encountered yet, then make sure they are added as properties and */ - /* make sure they are set from the font bounding box info. */ - /* */ - /* This is *always* done regardless of the options, because X11 */ - /* requires these two fields to compile fonts. */ - if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 ) - { - p->font->font_ascent = p->font->bbx.ascent; - ft_snprintf( nbuf, BUFSIZE, "%hd", p->font->bbx.ascent ); - error = bdf_add_property_( p->font, "FONT_ASCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - - FT_TRACE2(( "bdf_parse_properties_: " ACMSG1, p->font->bbx.ascent )); - } - - if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 ) - { - p->font->font_descent = p->font->bbx.descent; - ft_snprintf( nbuf, BUFSIZE, "%hd", p->font->bbx.descent ); - error = bdf_add_property_( p->font, "FONT_DESCENT", - nbuf, lineno ); - if ( error ) - goto Exit; - - FT_TRACE2(( "bdf_parse_properties_: " ACMSG2, p->font->bbx.descent )); - } - p->flags &= ~BDF_PROPS_; - *next = bdf_parse_glyphs_; + *next = bdf_parse_start_; goto Exit; } @@ -1843,6 +1773,7 @@ { bdf_line_func_t_* next = (bdf_line_func_t_ *)call_data; bdf_parse_t_* p = (bdf_parse_t_ *) client_data; + bdf_font_t* font; FT_Memory memory = p->memory; FT_Error error = FT_Err_Ok; @@ -1917,6 +1848,9 @@ goto Exit; } + /* Point at the font being constructed. */ + font = p->font; + /* Check for the start of the properties. */ if ( _bdf_strncmp( line, "STARTPROPERTIES", 15 ) == 0 ) { @@ -1932,21 +1866,20 @@ if ( error ) goto Exit; - /* at this point, `p->font' can't be NULL */ - p->cnt = p->font->props_size = bdf_atoul_( p->list.field[1] ); + p->cnt = font->props_size = bdf_atoul_( p->list.field[1] ); /* We need at least 4 bytes per property. */ if ( p->cnt > p->size / 4 ) { - p->font->props_size = 0; + font->props_size = 0; FT_ERROR(( "bdf_parse_start_: " ERRMSG5, lineno, "STARTPROPERTIES" )); error = FT_THROW( Invalid_Argument ); goto Exit; } - if ( FT_NEW_ARRAY( p->font->props, p->cnt ) ) + if ( FT_NEW_ARRAY( font->props, p->cnt ) ) { - p->font->props_size = 0; + font->props_size = 0; goto Exit; } @@ -1971,16 +1904,16 @@ if ( error ) goto Exit; - p->font->bbx.width = bdf_atous_( p->list.field[1] ); - p->font->bbx.height = bdf_atous_( p->list.field[2] ); + font->bbx.width = bdf_atous_( p->list.field[1] ); + font->bbx.height = bdf_atous_( p->list.field[2] ); - p->font->bbx.x_offset = bdf_atos_( p->list.field[3] ); - p->font->bbx.y_offset = bdf_atos_( p->list.field[4] ); + font->bbx.x_offset = bdf_atos_( p->list.field[3] ); + font->bbx.y_offset = bdf_atos_( p->list.field[4] ); - p->font->bbx.ascent = (short)( p->font->bbx.height + - p->font->bbx.y_offset ); + font->bbx.ascent = (short)( font->bbx.height + + font->bbx.y_offset ); - p->font->bbx.descent = (short)( -p->font->bbx.y_offset ); + font->bbx.descent = (short)( -font->bbx.y_offset ); p->flags |= BDF_FONT_BBX_; @@ -2005,14 +1938,14 @@ } /* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */ - FT_FREE( p->font->name ); + FT_FREE( font->name ); - if ( FT_DUP( p->font->name, s, slen + 1 ) ) + if ( FT_DUP( font->name, s, slen + 1 ) ) goto Exit; /* 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, lineno ); + error = bdf_set_default_spacing_( font, p->opts, lineno ); if ( error ) goto Exit; @@ -2036,9 +1969,9 @@ if ( error ) goto Exit; - p->font->point_size = bdf_atoul_( p->list.field[1] ); - p->font->resolution_x = bdf_atoul_( p->list.field[2] ); - p->font->resolution_y = bdf_atoul_( p->list.field[3] ); + font->point_size = bdf_atoul_( p->list.field[1] ); + font->resolution_x = bdf_atoul_( p->list.field[2] ); + font->resolution_y = bdf_atoul_( p->list.field[3] ); /* Check for the bits per pixel field. */ if ( p->list.used == 5 ) @@ -2050,26 +1983,26 @@ /* Only values 1, 2, 4, 8 are allowed for greymap fonts. */ if ( bpp > 4 ) - p->font->bpp = 8; + font->bpp = 8; else if ( bpp > 2 ) - p->font->bpp = 4; + font->bpp = 4; else if ( bpp > 1 ) - p->font->bpp = 2; + font->bpp = 2; else - p->font->bpp = 1; + font->bpp = 1; - if ( p->font->bpp != bpp ) - FT_TRACE2(( "bdf_parse_start_: " ACMSG11, p->font->bpp )); + if ( font->bpp != bpp ) + FT_TRACE2(( "bdf_parse_start_: " ACMSG11, font->bpp )); } else - p->font->bpp = 1; + font->bpp = 1; p->flags |= BDF_SIZE_; goto Exit; } - /* Check for the CHARS field -- font properties are optional */ + /* Check for the CHARS field */ if ( _bdf_strncmp( line, "CHARS", 5 ) == 0 ) { char nbuf[BUFSIZE]; @@ -2083,28 +2016,65 @@ goto Exit; } - /* Add the two standard X11 properties which are required */ - /* for compiling fonts. */ - p->font->font_ascent = p->font->bbx.ascent; - ft_snprintf( nbuf, BUFSIZE, "%hd", p->font->bbx.ascent ); - error = bdf_add_property_( p->font, "FONT_ASCENT", - nbuf, lineno ); + /* If the FONT_ASCENT or FONT_DESCENT properties have not been */ + /* encountered yet, then make sure they are added as properties and */ + /* make sure they are set from the font bounding box info. */ + /* */ + /* This is *always* done regardless of the options, because X11 */ + /* requires these two fields to compile fonts. */ + if ( bdf_get_font_property( font, "FONT_ASCENT" ) == 0 ) + { + font->font_ascent = font->bbx.ascent; + ft_snprintf( nbuf, BUFSIZE, "%hd", font->bbx.ascent ); + error = bdf_add_property_( font, "FONT_ASCENT", nbuf, lineno ); + if ( error ) + goto Exit; + + FT_TRACE2(( "bdf_parse_start_: " ACMSG1, font->bbx.ascent )); + } + + if ( bdf_get_font_property( font, "FONT_DESCENT" ) == 0 ) + { + font->font_descent = font->bbx.descent; + ft_snprintf( nbuf, BUFSIZE, "%hd", font->bbx.descent ); + error = bdf_add_property_( font, "FONT_DESCENT", nbuf, lineno ); + if ( error ) + goto Exit; + + FT_TRACE2(( "bdf_parse_start_: " ACMSG2, font->bbx.descent )); + } + + error = bdf_list_split_( &p->list, " +", line, linelen ); if ( error ) goto Exit; - FT_TRACE2(( "bdf_parse_start_: " ACMSG1, p->font->bbx.ascent )); + p->cnt = font->glyphs_size = bdf_atoul_( p->list.field[1] ); - p->font->font_descent = p->font->bbx.descent; - ft_snprintf( nbuf, BUFSIZE, "%hd", p->font->bbx.descent ); - error = bdf_add_property_( p->font, "FONT_DESCENT", - nbuf, lineno ); - if ( error ) + /* We need at least 20 bytes per glyph. */ + if ( p->cnt > p->size / 20 ) + { + p->cnt = font->glyphs_size = p->size / 20; + FT_TRACE2(( "bdf_parse_start_: " ACMSG17, p->cnt )); + } + + /* Make sure the number of glyphs is non-zero. */ + if ( p->cnt == 0 ) + font->glyphs_size = 64; + + /* Limit ourselves to 1,114,112 glyphs in the font (this is the */ + /* number of code points available in Unicode). */ + if ( p->cnt >= 0x110000UL ) + { + FT_ERROR(( "bdf_parse_start_: " ERRMSG5, lineno, "CHARS" )); + error = FT_THROW( Invalid_Argument ); goto Exit; - FT_TRACE2(( "bdf_parse_start_: " ACMSG2, p->font->bbx.descent )); + } - *next = bdf_parse_glyphs_; + if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) ) + goto Exit; + + p->flags |= BDF_GLYPHS_; + *next = bdf_parse_glyphs_; - /* A special return value. */ - error = -1; goto Exit; }