Commit bd8b08513fd7ad3705c48b5d7b55e4ce8c44d15d

Graham Asher 2002-07-18T16:57:43

Added support for incrementally loaded Type 1 faces.

diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index 6bf71cf..9ae4937 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -53,21 +53,62 @@
   /*************************************************************************/
 
 
-  FT_CALLBACK_DEF( FT_Error )
-  T1_Parse_Glyph( T1_Decoder  decoder,
-                  FT_UInt     glyph_index )
+FT_LOCAL_DEF(FT_Error) T1_Parse_Glyph_And_Get_Char_String( T1_Decoder decoder,
+                                                           FT_UInt glyph_index,
+                                                           FT_Data* char_string )
   {
-    T1_Face  face  = (T1_Face)decoder->builder.face;
-    T1_Font  type1 = &face->type1;
-
+    T1_Face face = (T1_Face)decoder->builder.face;
+    T1_Font type1 = &face->type1;
+    FT_Error error = 0;
 
     decoder->font_matrix = type1->font_matrix;
     decoder->font_offset = type1->font_offset;
 
-    return decoder->funcs.parse_charstrings(
-                      decoder,
-                      type1->charstrings    [glyph_index],
-                      type1->charstrings_len[glyph_index] );
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
+    /* For incremental fonts get the character data using the callback function. */
+    if (face->root.incremental_interface)
+      error = face->root.incremental_interface->funcs->get_glyph_data(face->root.incremental_interface->object,
+        glyph_index,char_string);
+    else
+#endif
+
+    /* For ordinary fonts get the character data stored in the face record. */
+    {
+      char_string->pointer = type1->charstrings[glyph_index];
+      char_string->length = type1->charstrings_len[glyph_index];
+    }
+
+    if (!error)
+      error = decoder->funcs.parse_charstrings(decoder,(FT_Byte*)char_string->pointer,char_string->length);
+
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
+    /* Incremental fonts can optionally override the metrics. */
+    if (!error && face->root.incremental_interface && face->root.incremental_interface->funcs->get_glyph_metrics)
+    {
+      FT_Bool found = FALSE;
+      FT_Basic_Glyph_Metrics metrics;
+      error = face->root.incremental_interface->funcs->get_glyph_metrics(face->root.incremental_interface->object,
+        glyph_index,FALSE,&metrics,&found);
+      if (found)
+      {
+        decoder->builder.left_bearing.x = metrics.bearing_x;
+        decoder->builder.left_bearing.y = metrics.bearing_y;
+        decoder->builder.advance.x = metrics.advance;
+        decoder->builder.advance.y = 0;
+      }
+    }
+#endif
+
+  return error;
+  }
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  T1_Parse_Glyph( T1_Decoder  decoder,
+                  FT_UInt     glyph_index )
+  {
+    FT_Data data;
+    return T1_Parse_Glyph_And_Get_Char_String(decoder,glyph_index,&data);
   }
 
 
@@ -154,7 +195,7 @@
 
     FT_Matrix               font_matrix;
     FT_Vector               font_offset;
-
+    FT_Data                 char_string;
 
     if ( load_flags & FT_LOAD_NO_RECURSE )
       load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
@@ -188,9 +229,8 @@
     decoder.subrs     = type1->subrs;
     decoder.subrs_len = type1->subrs_len;
 
-
     /* now load the unscaled outline */
-    error = T1_Parse_Glyph( &decoder, glyph_index );
+    error = T1_Parse_Glyph_And_Get_Char_String( &decoder, glyph_index, &char_string );
     if ( error )
       goto Exit;
 
@@ -311,8 +351,8 @@
 
       /* Set control data to the glyph charstrings.  Note that this is */
       /* _not_ zero-terminated.                                        */
-      glyph->root.control_data = type1->charstrings    [glyph_index];
-      glyph->root.control_len  = type1->charstrings_len[glyph_index];
+      glyph->root.control_data = (FT_Byte*)char_string.pointer;
+      glyph->root.control_len  = char_string.length;
     }
 
   Exit: