Handle broken FNT files which don't have a trailing NULL byte

in the face name string.

* src/winfnt/winfnt.h (FNT_FontRec): New member `family_name'.
* src/winfnt/winfnt.c (fnt_font_done): Free font->family_name.
(FNT_Face_Init): Append a final zero byte to the font face name.

* src/sfnt/ttload.c (tt_face_load_sfnt_header): Fix change from
2004-03-19.
This commit is contained in:
Werner Lemberg 2004-04-01 20:35:57 +00:00
parent aeaafaa291
commit 611eaa7f3f
4 changed files with 43 additions and 12 deletions

View File

@ -1,3 +1,17 @@
2004-03-31 Werner Lemberg <wl@gnu.org>
Handle broken FNT files which don't have a trailing NULL byte
in the face name string.
* src/winfnt/winfnt.h (FNT_FontRec): New member `family_name'.
* src/winfnt/winfnt.c (fnt_font_done): Free font->family_name.
(FNT_Face_Init): Append a final zero byte to the font face name.
2004-03-30 Werner Lemberg <wl@gnu.org>
* src/sfnt/ttload.c (tt_face_load_sfnt_header): Fix change from
2004-03-19.
2004-03-27 Werner Lemberg <wl@gnu.org>
* src/base/descrip.mms (OBJS): Add ftbbox.obj.

View File

@ -357,11 +357,6 @@
FT_READ_LONG( format_tag ) )
goto Exit;
}
else if ( face_index > 0 )
{
error = SFNT_Err_Bad_Argument;
goto Exit;
}
/* the format tag was read, now check the rest of the header */
sfnt->format_tag = format_tag;
@ -376,8 +371,13 @@
{
FT_TRACE2(( "tt_face_load_sfnt_header: file is not SFNT!\n" ));
error = SFNT_Err_Unknown_File_Format;
goto Exit;
}
/* disallow face index values > 0 for non-TTC files */
if ( format_tag != TTAG_ttcf && face_index > 0 )
error = SFNT_Err_Bad_Argument;
Exit:
return error;
}

View File

@ -121,6 +121,7 @@
if ( font->fnt_frame )
FT_FRAME_RELEASE( font->fnt_frame );
FT_FREE( font->family_name );
FT_FREE( font );
face->font = 0;
@ -434,8 +435,9 @@
/* we now need to fill the root FT_Face fields */
/* with relevant information */
{
FT_Face root = FT_FACE( face );
FNT_Font font = face->font;
FT_Face root = FT_FACE( face );
FNT_Font font = face->font;
FT_PtrDist family_size;
root->face_flags = FT_FACE_FLAG_FIXED_SIZES |
@ -506,8 +508,22 @@
root->num_glyphs = font->header.last_char -
font->header.first_char + 1 + 1;
root->family_name = (FT_String*)font->fnt_frame +
font->header.face_name_offset;
/* Some broken fonts don't delimit the face name with a final */
/* NULL byte -- the frame is erroneously one byte too small. */
/* We thus allocate one more byte, setting it explicitly to */
/* zero. */
family_size = font->header.file_size - font->header.face_name_offset;
if ( FT_ALLOC( font->family_name, family_size + 1 ) )
goto Fail;
FT_MEM_COPY( font->family_name,
font->fnt_frame + font->header.face_name_offset,
family_size );
font->family_name[family_size] = '\0';
if ( FT_REALLOC( font->family_name,
family_size,
ft_strlen( font->family_name ) + 1 ) )
goto Fail;
root->family_name = font->family_name;
root->style_name = (char *)"Regular";
if ( root->style_flags & FT_STYLE_FLAG_BOLD )
@ -520,10 +536,10 @@
else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
root->style_name = (char *)"Italic";
}
goto Exit;
Fail:
if ( error )
FNT_Face_Done( face );
FNT_Face_Done( face );
Exit:
return error;

View File

@ -4,7 +4,7 @@
/* */
/* FreeType font driver for Windows FNT/FON files */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2001, 2002, 2003, 2004 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -79,6 +79,7 @@ FT_BEGIN_HEADER
FT_Byte* fnt_frame;
FT_ULong fnt_size;
FT_String* family_name;
} FNT_FontRec, *FNT_Font;