Commit ea5c781afaba862426a077ace7382a3e5381f1b3

Werner Lemberg 2013-11-12T08:55:26

[truetype] Fix last `truetype' commit. * src/truetype/ttgload.c (tt_get_metrics): Preserve stream position. Return error value. (load_truetype_glyph): Updated.

diff --git a/ChangeLog b/ChangeLog
index 8c95b96..9614fca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-11-12  Werner Lemberg  <wl@gnu.org>
+
+	[truetype] Fix last `truetype' commit.
+
+	* src/truetype/ttgload.c (tt_get_metrics): Preserve stream position.
+	Return error value.
+	(load_truetype_glyph): Updated.
+
 2013-11-10  Werner Lemberg  <wl@gnu.org>
 
 	* docs/CMAKE: New dummy file.
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 5497562..aaeae34 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -114,7 +114,7 @@
   }
 
 
-  static void
+  static FT_Error
   tt_get_metrics( TT_Loader  loader,
                   FT_UInt    glyph_index )
   {
@@ -123,9 +123,16 @@
     TT_Driver  driver = (TT_Driver)FT_FACE_DRIVER( face );
 #endif
 
+    FT_Error   error;
+    FT_Stream  stream = loader->stream;
+
     FT_Short   left_bearing = 0, top_bearing = 0;
     FT_UShort  advance_width = 0, advance_height = 0;
 
+    /* we must preserve the stream position          */
+    /* (which gets altered by the metrics functions) */
+    FT_ULong  pos = FT_STREAM_POS();
+
 
     TT_Get_HMetrics( face, glyph_index,
                      &left_bearing,
@@ -135,6 +142,9 @@
                      &top_bearing,
                      &advance_height );
 
+    if ( FT_STREAM_SEEK( pos ) )
+      return error;
+
     loader->left_bearing = left_bearing;
     loader->advance      = advance_width;
     loader->top_bearing  = top_bearing;
@@ -157,6 +167,8 @@
       loader->linear_def = 1;
       loader->linear     = advance_width;
     }
+
+    return FT_Err_Ok;
   }
 
 
@@ -1452,7 +1464,9 @@
       /* the metrics must be computed after loading the glyph header */
       /* since we need the glyph's `yMax' value in case the vertical */
       /* metrics must be emulated                                    */
-      tt_get_metrics( loader, glyph_index );
+      error = tt_get_metrics( loader, glyph_index );
+      if ( error )
+        goto Exit;
 
       if ( header_only )
         goto Exit;
@@ -1465,7 +1479,9 @@
       loader->bbox.yMin = 0;
       loader->bbox.yMax = 0;
 
-      tt_get_metrics( loader, glyph_index );
+      error = tt_get_metrics( loader, glyph_index );
+      if ( error )
+        goto Exit;
 
       if ( header_only )
         goto Exit;