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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
diff --git a/ChangeLog b/ChangeLog
index bc5046f..fa13292 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 12361fa..00d2b79 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -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;
}
diff --git a/src/winfonts/winfnt.c b/src/winfonts/winfnt.c
index abca96a..26e4930 100644
--- a/src/winfonts/winfnt.c
+++ b/src/winfonts/winfnt.c
@@ -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;
diff --git a/src/winfonts/winfnt.h b/src/winfonts/winfnt.h
index f36901e..32ab6da 100644
--- a/src/winfonts/winfnt.h
+++ b/src/winfonts/winfnt.h
@@ -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;