* src/sfnt/ttload.c (TT_Load_Names), src/sfnt/sfobjs.c (Get_Name), src/sfnt/sfdriver.c (get_sfnt_postscript_name): Fixed the loader so that it accepts broken fonts like "foxjump.ttf", which made FreeType crash when trying to load them. Also improved the name table parser to be able to load Windows-encoded entries before Macintosh or Unicode ones, since it seems some fonts don't have reliable values here anyway.
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
diff --git a/ChangeLog b/ChangeLog
index 96856a0..f8ce135 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,16 @@
caused the CID driver to return Postscript font names with a leading
slash ("/") as in "/MOEKai-Regular"
+ * src/sfnt/ttload.c (TT_Load_Names), src/sfnt/sfobjs.c (Get_Name),
+ src/sfnt/sfdriver.c (get_sfnt_postscript_name): Fixed the loader so
+ that it accepts broken fonts like "foxjump.ttf", which made FreeType
+ crash when trying to load them.
+
+ Also improved the name table parser to be able to load
+ Windows-encoded entries before Macintosh or Unicode ones, since it
+ seems some fonts don't have reliable values here anyway.
+
+
2002-03-05 Werner Lemberg <wl@gnu.org>
* builds/unix/aclocal.m4, builds/unix/ltmain.sh: Update to libtool
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index e023c0b..af92ed2 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -114,7 +114,7 @@
static const char*
get_sfnt_postscript_name( TT_Face face )
{
- FT_Int n;
+ FT_Int n, found_win, found_apple;
/* shouldn't happen, but just in case to avoid memory leaks */
@@ -123,40 +123,65 @@
/* scan the name table to see whether we have a Postscript name here, */
/* either in Macintosh or Windows platform encodings */
+ found_win = -1;
+ found_apple = -1;
+
for ( n = 0; n < face->num_names; n++ )
{
TT_NameRec* name = face->name_table.names + n;
- if ( name->nameID == 6 )
+ if ( name->nameID == 6 && name->string != NULL )
{
- if ( ( name->platformID == 3 &&
- name->encodingID == 1 &&
- name->languageID == 0x409 ) ||
-
- ( name->platformID == 1 &&
- name->encodingID == 0 &&
- name->languageID == 0 ) )
+ if ( name->platformID == 3 &&
+ name->encodingID == 1 &&
+ name->languageID == 0x409 )
+ found_win = n;
+
+ if ( name->platformID == 1 &&
+ name->encodingID == 0 &&
+ name->languageID == 0 )
+ found_apple = n;
+ }
+ }
+
+ if ( found_win )
+ {
+ FT_Memory memory = face->root.memory;
+ TT_NameRec* name = face->name_table.names + found_win;
+ FT_UInt len = name->stringLength/2;
+ FT_Error error;
+ FT_String* result;
+
+ if ( !ALLOC( result, len+1 ) )
+ {
+ FT_String* r = result;
+ FT_Byte* p = (FT_Byte*) name->string;
+
+ for ( ; len > 0; len--, p += 2 )
{
- FT_UInt len = name->stringLength;
- FT_Error error;
- FT_Memory memory = face->root.memory;
- FT_String* result;
-
-
- if ( !ALLOC( result, len + 1 ) )
- {
- memcpy( result, name->string, len );
- result[len] = '\0';
-
- face->root.internal->postscript_name = result;
- }
-
- FT_UNUSED( error );
-
- return result;
+ if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
+ *r++ = p[1];
}
+ *r = '\0';
+ }
+ return result;
+ }
+
+ if ( found_apple )
+ {
+ FT_Memory memory = face->root.memory;
+ TT_NameRec* name = face->name_table.names + found_win;
+ FT_UInt len = name->stringLength;
+ FT_Error error;
+ FT_String* result;
+
+ if ( !ALLOC( result, len+1 ) )
+ {
+ MEM_Copy( result, name->string, len );
+ result[len] = '\0';
}
+ return result;
}
return NULL;
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index 967c93c..03db182 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -60,68 +60,94 @@
FT_Memory memory = face->root.memory;
FT_UShort n;
TT_NameRec* rec;
- FT_Bool wide_chars = 1;
+ FT_Bool wide_chars = 1;
+ FT_Int found_apple = -1;
+ FT_Int found_win = -1;
+ FT_Int found_unicode = -1;
+ FT_Int found;
rec = face->name_table.names;
for ( n = 0; n < face->name_table.numNameRecords; n++, rec++ )
{
- if ( rec->nameID == nameid )
+ if ( rec->nameID == nameid && rec->string )
{
- /* found the name -- now create an ASCII string from it */
- FT_Bool found = 0;
-
-
- /* test for Microsoft English language */
- if ( rec->platformID == TT_PLATFORM_MICROSOFT &&
- rec->encodingID <= TT_MS_ID_UNICODE_CS &&
- ( rec->languageID & 0x3FF ) == 0x009 )
- found = 1;
-
- /* test for Apple Unicode encoding */
- else if ( rec->platformID == TT_PLATFORM_APPLE_UNICODE )
- found = 1;
-
- /* test for Apple Roman */
- else if ( rec->platformID == TT_PLATFORM_MACINTOSH &&
- rec->languageID == TT_MAC_ID_ROMAN )
+ switch ( rec->platformID )
{
- found = 1;
- wide_chars = 0;
+ case TT_PLATFORM_APPLE_UNICODE:
+ {
+ found_unicode = n;
+ break;
+ }
+
+ case TT_PLATFORM_MACINTOSH:
+ {
+ if ( rec->languageID == TT_MAC_ID_ROMAN )
+ found_apple = n;
+
+ break;
+ }
+
+ case TT_PLATFORM_MICROSOFT:
+ {
+ if ( rec->encodingID <= TT_MS_ID_UNICODE_CS &&
+ (rec->languageID & 0x3FF) == 0x009 )
+ {
+ found_win = n;
+ }
+ break;
+ }
+
+ default:
+ ;
}
+ }
+ }
- /* found a Unicode name */
- if ( found )
- {
- FT_String* string;
- FT_UInt len;
-
+ /* some fonts contain invalid Unicode or Macintosh formatted entries */
+ /* we will thus favor name encoded in Windows formats when they're */
+ /* available.. */
+ /* */
+ found = found_win;
+ if ( found < 0 )
+ {
+ found = found_apple;
+ if ( found_apple < 0 )
+ found = found_unicode;
+ else
+ wide_chars = 0;
+ }
- if ( wide_chars )
- {
- FT_UInt m;
+ /* found a Unicode name */
+ if ( found >= 0 )
+ {
+ FT_String* string;
+ FT_UInt len;
+ rec = face->name_table.names + found;
+ if ( wide_chars )
+ {
+ FT_UInt m;
- len = (FT_UInt)rec->stringLength / 2;
- if ( MEM_Alloc( string, len + 1 ) )
- return NULL;
- for ( m = 0; m < len; m ++ )
- string[m] = rec->string[2 * m + 1];
- }
- else
- {
- len = rec->stringLength;
- if ( MEM_Alloc( string, len + 1 ) )
- return NULL;
+ len = (FT_UInt)rec->stringLength / 2;
+ if ( MEM_Alloc( string, len + 1 ) )
+ return NULL;
- MEM_Copy( string, rec->string, len );
- }
+ for ( m = 0; m < len; m ++ )
+ string[m] = rec->string[2 * m + 1];
+ }
+ else
+ {
+ len = rec->stringLength;
+ if ( MEM_Alloc( string, len + 1 ) )
+ return NULL;
- string[len] = '\0';
- return string;
- }
+ MEM_Copy( string, rec->string, len );
}
+
+ string[len] = '\0';
+ return string;
}
return NULL;
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 4127bbd..84ae9bc 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -1003,15 +1003,18 @@
for ( ; cur < limit; cur ++ )
{
- FT_ULong upper;
-
-
if ( READ_Fields( name_record_fields, cur ) )
break;
/* invalid name entries will have "cur->string" set to NULL !! */
if ( (FT_ULong)(cur->stringOffset + cur->stringLength) < storageSize )
cur->string = storage + cur->stringOffset;
+ else
+ {
+ /* that's an invalid entry */
+ cur->stringOffset = 0;
+ cur->string = NULL;
+ }
}
}
@@ -1020,6 +1023,12 @@
if (error)
goto Exit;
+ storageOffset -= 6 + 12*names->numNameRecords;
+ if ( FILE_Skip( storageOffset ) ||
+ FILE_Read( storage, storageSize ) )
+ goto Exit;
+
+
#ifdef FT_DEBUG_LEVEL_TRACE
/* Print Name Record Table in case of debugging */