Commit 662b344c23125a19abcd503c267699afeeabdf7d

David Turner 2002-01-03T16:56:59

* src/type1/t1objs.c (T1_Face_Init): fixed a bug that crashed the library when dealing with certain weird fonts (like "Stalingrad", in "sadn.pfb". This font has no full font name entry.. ) * src/base/ftoutln.c, include/freetype/ftoutln.h: added the FT_Outline_Check API to check the consistency of outline data * src/base/ftobjs.c (FT_Load_Glyph): added a call to the new FT_Outline_Check to ensure that loaded glyphs are valid. This allows certain fonts like "tt1095m_.ttf" to be loaded even though it appears they contain really funky glyphs.. there still is a bug there though.. !!

diff --git a/ChangeLog b/ChangeLog
index 8e8f4ee..7f68f47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2002-01-03  David Turner  <david@freetype.org>
+
+        * src/type1/t1objs.c (T1_Face_Init): fixed a bug that crashed the
+        library when dealing with certain weird fonts (like "Stalingrad",
+        in "sadn.pfb". This font has no full font name entry.. )
+
+        * src/base/ftoutln.c, include/freetype/ftoutln.h: added the
+        FT_Outline_Check API to check the consistency of outline data
+        
+        * src/base/ftobjs.c (FT_Load_Glyph): added a call to the new
+        FT_Outline_Check to ensure that loaded glyphs are valid. This
+        allows certain fonts like "tt1095m_.ttf" to be loaded even though
+        it appears they contain really funky glyphs..
+        
+        there still is a bug there though.. !!
+
+
 2001-12-30  David Turner  <david@freetype.org>
 
 	* src/autohint/ahhint.c (ah_hinter_load): Fix advance width
diff --git a/include/freetype/ftoutln.h b/include/freetype/ftoutln.h
index 9dc1c64..fcf527a 100644
--- a/include/freetype/ftoutln.h
+++ b/include/freetype/ftoutln.h
@@ -181,6 +181,24 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Outline_Check                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Check the content of an outline descriptor                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    outline :: handle to source outline                                */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Outline_Check( FT_Outline*  outline );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Outline_Get_CBox                                                */
   /*                                                                       */
   /* <Description>                                                         */
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index b11ab7f..28b25fc 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -906,12 +906,19 @@
                                      glyph_index, load_flags );
     }
     else
+    {
       error = driver->clazz->load_glyph( slot,
                                          face->size,
                                          glyph_index,
                                          load_flags );
-    if ( error )
-      goto Exit;
+      if ( error )
+        goto Exit;
+
+      /* check that the loaded outline is correct !! */      
+      error = FT_Outline_Check( &slot->outline );
+      if ( error )
+        goto Exit;
+    }
 
   Load_Ok:
     /* compute the advance */
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index c7e3c08..18c8d77 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -299,6 +299,49 @@
 
 
   /* documentation is in ftoutln.h */
+  
+  FT_EXPORT_DEF( FT_Error )
+  FT_Outline_Check( FT_Outline*  outline )
+  {
+    if ( outline )
+    {
+      FT_Int  n_points   = outline->n_points;
+      FT_Int  n_contours = outline->n_contours;
+      FT_Int  end0, end;
+      FT_Int  n;
+
+      /* empty glyph ?? */
+      if ( n_points == 0 && n_contours == 0 )
+        return 0;
+      
+      /* check point and contour counts */
+      if ( n_points <= 0 || n_contours <= 0 )
+        goto Bad;
+      
+      end0 = -1;
+      for ( n = 0; n < n_contours; n++ )
+      {
+        end  = outline->contours[n];
+
+        /* note that we don't accept empty contours */
+        if ( end <= end0 || end >= n_points )
+          goto Bad;
+
+        end0 = end;
+      }
+      
+      if ( end != n_points-1 )
+        goto Bad;
+
+      /* XXX: check the that array */
+      return 0;
+    }
+  Bad:
+    return FT_Err_Invalid_Argument;
+  }
+
+
+  /* documentation is in ftoutln.h */
 
   FT_EXPORT_DEF( FT_Error )
   FT_Outline_Copy( FT_Outline*  source,
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index dd10779..32cc4fb 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1034,7 +1034,8 @@
           {
             FT_TRACE0(( "Too many instructions (%d) in composite glyph %ld\n",
                         n_ins, subglyph->index ));
-            return TT_Err_Too_Many_Hints;
+            error = TT_Err_Too_Many_Hints;
+            goto Fail;
           }
 
           /* read the instructions */
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 4d4faf0..8335f6c 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -365,15 +365,19 @@
         char*  full   = face->type1.font_info.full_name;
         char*  family = root->family_name;
 
-
-        while ( *family && *full == *family )
+        if ( full )
         {
-          family++;
-          full++;
+          while ( *family && *full == *family )
+          {
+            family++;
+            full++;
+          }
+  
+          root->style_name = ( *full == ' ' ? full + 1
+                                            : (char *)"Regular" );
         }
-
-        root->style_name = ( *full == ' ' ? full + 1
-                                          : (char *)"Regular" );
+        else
+          root->style_name = "Regular";
       }
       else
       {