freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] tt_face_load_sfnt_header() ignoring face index for TTF files


From: Steve Hartwell
Subject: [Devel] tt_face_load_sfnt_header() ignoring face index for TTF files
Date: Sat, 13 Mar 2004 09:02:35 -0800

Hi, all,

Currently, my code (would like to :-) determine how many faces are in a font file simply by looping on the face 'index' :

do { err = FT_New_Face(ftLib, path, index++, pFTFaces++); } while (!err);

until FT_New_Face returns an error, which in the case of simple .TTF files, would be for index 1, but for TTC or Mac dfont files, can be > 1. I would prefer this method rather than checking for each font format specifically.

However, ttload.c:tt_face_load_sfnt_header() only examines the face index in the case of TTC files, and ignores it in the standard TTF case, so FT_New_Face will return no error for index > 0 and open the face multiple times (now I know my per-process open file limit :-)

Would it be OK to change tt_face_load_sfnt_header() to return SFNT_Err_Bad_Argument for TTF files where index > 0? This would be the same behavior as passing a too-large index for a TTC file. I doubt that it would break existing code, unless some callers are passing random data for index, which doesn't seem likely.

To do this, we also have to adjust ftmac.c not to propagate the index to FT_Open_Face(), which I should have included in my last patch anyway but I must have missed it.

Suggested patches below,

Best regards,

Steve Hartwell

---------------

Index: ttload.c
===================================================================
RCS file: /cvs/freetype/freetype2/src/sfnt/ttload.c,v
retrieving revision 1.104
diff -d -p --unified=3 -w -B -r1.104 ttload.c
--- ttload.c    2004/03/05 09:26:22     1.104
+++ ttload.c    2004/03/13 16:28:08
@@ -314,8 +314,8 @@
     face->num_tables = 0;

/* first of all, read the first 4 bytes. If it is `ttcf', then the */ - /* file is a TrueType collection, otherwise it can be any other */ - /* kind of font. */ + /* file is a TrueType collection, otherwise it is a single-face font*/ + /* and its face_index must be 0 (or < 0?) (SHH 2004/01/10) */ /* */
     offset = FT_STREAM_POS();

@@ -356,6 +356,11 @@

       if ( FT_STREAM_SEEK( offset ) ||
            FT_READ_LONG( format_tag )                             )
+        goto Exit;
+    }
+    else if ( face_index > 0 )    /* SHH 2004/01/10 */
+    {
+        error = SFNT_Err_Bad_Argument;
         goto Exit;
     }

Index: ftmac.c
===================================================================
RCS file: /cvs/freetype/freetype2/src/base/ftmac.c,v
retrieving revision 1.32
diff -d -p --unified=3 -w -B -r1.32 ftmac.c
--- ftmac.c     2004/02/28 19:12:01     1.32
+++ ftmac.c     2004/03/13 16:52:53
@@ -611,6 +611,14 @@
       args.driver = FT_Get_Module( library, driver_name );
     }

+    /* SHH: At this point, face_index has served  */
+    /* its purpose; whoever calls this function has */
+    /* already used it to locate the correct font data. */
+    /* We should not propagate this index to FT_Open_Face() */
+    /* (unless it's that funky -1 :-) */
+
+    if (face_index > 0) face_index = 0;
+
     error = FT_Open_Face( library, &args, face_index, aface );
     if ( error == FT_Err_Ok )
       (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]