[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft-devel] PATCH: Do not do further load font attempts if a previous att
From: |
Dmitry Timoshkov |
Subject: |
[ft-devel] PATCH: Do not do further load font attempts if a previous attempt has failed but returned error FNT_Err_Invalid_File_Format |
Date: |
Tue, 19 Jun 2007 13:38:51 +0900 |
Hello,
this patch speeds up a lot programs that scan a directory of files and load
every font they find using the code like below:
face_index = 0;
while (1)
{
if ((ft_err = FT_New_Face(ft_library, fnt_name, face_index, &ft_face)))
break;
...
FT_Done_Face(ft_face);
face_index++;
}
The patch avoids trying to load a file as a font if a previous attempt has
failed but returned error FNT_Err_Invalid_File_Format, i.e. file format has
been recognized but no fonts found in the file. That's a different error to
FNT_Err_Unknown_File_Format.
Changelog:
* src/winfonts/winfnt.c (fnt_face_get_dll_font): Return error
FNT_Err_Invalid_File_Format if file format was recognized but
file doesn't contain any FNT(NE) or RT_FONT(PE) resources.
Add verbose debug logs to make it easier to debug failing load
attempts.
* src/winfonts/winfnt.c (FNT_Face_Init): A single FNT font can't
contain more than 1 face, so return an error if requested face
index is more than 0.
Do not do further load font attempts if a previous attempt has
failed but returned error FNT_Err_Invalid_File_Format, i.e. file
format has been recognized but no fonts found in the file.
diff -up freetype2/src/winfonts/winfnt.c freetype2/src/winfonts/winfnt.c
--- freetype2/src/winfonts/winfnt.c Sun Jun 17 12:46:50 2007
+++ freetype2/src/winfonts/winfnt.c Tue Jun 19 03:53:03 2007
@@ -343,7 +343,7 @@
if ( !font_count || !font_offset )
{
FT_TRACE2(( "this file doesn't contain any FNT resources!\n" ));
- error = FNT_Err_Unknown_File_Format;
+ error = FNT_Err_Invalid_File_Format;
goto Exit;
}
@@ -413,6 +413,7 @@
pe32_header.size_of_optional_header != 0xe0 /* FIXME */ ||
pe32_header.magic32 != 0x10b )
{
+ FT_TRACE2(( "this file has invalid PE header\n" ));
error = FNT_Err_Invalid_File_Format;
goto Exit;
}
@@ -435,6 +436,7 @@
goto Found_rsrc_section;
}
+ FT_TRACE2(( "this file doesn't contain any resources\n" ));
error = FNT_Err_Invalid_File_Format;
goto Exit;
@@ -553,6 +555,13 @@
}
}
+ if ( !face->root.num_faces )
+ {
+ FT_TRACE2(( "this file doesn't contain any RT_FONT resources\n" ));
+ error = FNT_Err_Invalid_File_Format;
+ goto Exit;
+ }
+
if ( face_index >= face->root.num_faces )
{
error = FNT_Err_Bad_Argument;
@@ -681,12 +690,18 @@
/* try to load font from a DLL */
error = fnt_face_get_dll_font( face, face_index );
- if ( error )
+ if ( error == FNT_Err_Unknown_File_Format )
{
/* this didn't work; try to load a single FNT font */
FNT_Font font;
+ if ( face_index > 0 )
+ {
+ error = FNT_Err_Bad_Argument;
+ goto Exit;
+ }
+
if ( FT_NEW( face->font ) )
goto Exit;
@@ -697,9 +712,10 @@
font->fnt_size = stream->size;
error = fnt_font_load( font, stream );
- if ( error )
- goto Fail;
}
+
+ if ( error )
+ goto Fail;
/* we now need to fill the root FT_Face fields */
/* with relevant information */
- [ft-devel] PATCH: Do not do further load font attempts if a previous attempt has failed but returned error FNT_Err_Invalid_File_Format,
Dmitry Timoshkov <=