Commit a4d6a1c8d126f62aefaabc6b02c170adc31b93de

Werner Lemberg 2006-07-19T09:54:56

Move creation of field `buildchar' of T1_DecoderRec out of `t1_decoder_init' and let the caller of `t1_decoder_init' take care of it. Call the finisher for T1_Decoder in `cid_face_compute_max_advance' and `T1_Compute_Max_Advance'. * freetype2/include/freetype/internal/psaux.h (T1_DecoderRec): Remove field `face', add `len_buildchar'. * freetype2/include/freetype/internal/t1types.h (T1_FaceRec): Add field `buildchar'. * freetype2/src/cid/cidgload.c (cid_face_compute_max_advance): Call finisher for T1_Decoder. (cid_slot_load_glyph): Do not ignore failure when initializing the T1_Decoder. * freetype2/src/psaux/t1decode.c (t1_decoder_parse_charstrings): Updated. (t1_decoder_init): Remove initialization of fields `buildchar' and `len_buildchar'. (t1_decoder_done): Remove deallocation of field `buildchar'. * freetype/src/type1/t1gload.c (T1_Compute_Max_Advance): Initialize T1_Decoder's `buildchar' and `len_buildchar'; call finisher for T1_Decoder. (T1_Load_Glyph): Initialize T1_Decoder's `buildchar' and `len_buildchar'; make sure to call finisher for T1_Decoder even in case of error. * freetype2/src/type1/t1load.c (T1_Open_Face): Allocate new field `buildchar' of T1_FaceRec. * freetype2/src/type1/t1objs.c (T1_Face_Done): Free new field `buildchar' of T1_FaceRec.

diff --git a/ChangeLog b/ChangeLog
index 07a39f0..7202363 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2006-07-18  Jens Claudius  <jens.claudius@yahoo.com>
+
+	Move creation of field `buildchar' of T1_DecoderRec out of
+	`t1_decoder_init' and let the caller of `t1_decoder_init' take care
+	of it.
+
+	Call the finisher for T1_Decoder in `cid_face_compute_max_advance'
+	and `T1_Compute_Max_Advance'.
+
+	* freetype2/include/freetype/internal/psaux.h (T1_DecoderRec):
+	Remove field `face', add `len_buildchar'.
+
+	* freetype2/include/freetype/internal/t1types.h (T1_FaceRec): Add
+	field `buildchar'.
+
+	* freetype2/src/cid/cidgload.c (cid_face_compute_max_advance): Call
+	finisher for T1_Decoder.
+	(cid_slot_load_glyph): Do not ignore failure when initializing the
+	T1_Decoder.
+
+	* freetype2/src/psaux/t1decode.c (t1_decoder_parse_charstrings):
+	Updated.
+	(t1_decoder_init): Remove initialization of fields `buildchar' and
+	`len_buildchar'.
+	(t1_decoder_done): Remove deallocation of field `buildchar'.
+
+	* freetype/src/type1/t1gload.c (T1_Compute_Max_Advance): Initialize
+	T1_Decoder's `buildchar' and `len_buildchar'; call finisher for
+	T1_Decoder.
+	(T1_Load_Glyph): Initialize T1_Decoder's `buildchar' and
+	`len_buildchar'; make sure to call finisher for T1_Decoder even in
+	case of error.
+
+	* freetype2/src/type1/t1load.c (T1_Open_Face): Allocate new field
+	`buildchar' of T1_FaceRec.
+
+	* freetype2/src/type1/t1objs.c (T1_Face_Done): Free new field
+	`buildchar' of T1_FaceRec.
+
 2006-07-14  Jens Claudius  <jens.claudius@yahoo.com>
 
 	* freetype2/include/freetype/internal/psaux.h: New macros
diff --git a/include/freetype/internal/psaux.h b/include/freetype/internal/psaux.h
index 4afd2b0..2586e95 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -687,8 +687,7 @@ FT_BEGIN_HEADER
     T1_Decoder_FuncsRec  funcs;
 
     FT_Int*              buildchar;
-
-    T1_Face              face;
+    FT_UInt              len_buildchar;
 
   } T1_DecoderRec;
 
diff --git a/include/freetype/internal/t1types.h b/include/freetype/internal/t1types.h
index eca91a7..3075571 100644
--- a/include/freetype/internal/t1types.h
+++ b/include/freetype/internal/t1types.h
@@ -217,6 +217,7 @@ FT_BEGIN_HEADER
     /* undocumented, optional: has the same meaning as len_buildchar */
     /* for Type 2 fonts; manipulated by othersubrs 19, 24, and 25    */
     FT_UInt          len_buildchar;
+    FT_Int*          buildchar;
 
     /* since version 2.1 - interface to PostScript hinter */
     const void*     pshinter;
diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c
index ed706ad..4815aba 100644
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -230,6 +230,9 @@
     if ( error )
       return error;
 
+    /* TODO: initialize decoder.len_buildchar and decoder.buildchar */
+    /*       if we ever support CID-keyed multiple master fonts     */
+
     decoder.builder.metrics_only = 1;
     decoder.builder.load_points  = 0;
 
@@ -245,6 +248,8 @@
 
     *max_advance = decoder.builder.advance.x;
 
+    psaux->t1_decoder_funcs->done( &decoder );
+
     return CID_Err_Ok;
   }
 
@@ -295,17 +300,23 @@
                                              FT_LOAD_TARGET_MODE( load_flags ),
                                              cid_load_glyph );
 
-      /* set up the decoder */
-      decoder.builder.no_recurse = FT_BOOL(
-        ( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) );
+      if ( !error )
+      {
+        /* TODO: initialize decoder.len_buildchar and decoder.buildchar */
+        /*       if we ever support CID-keyed multiple master fonts     */
+
+        /* set up the decoder */
+        decoder.builder.no_recurse = FT_BOOL(
+          ( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) );
 
-      error = cid_load_glyph( &decoder, glyph_index );
+        error = cid_load_glyph( &decoder, glyph_index );
 
-      font_matrix = decoder.font_matrix;
-      font_offset = decoder.font_offset;
+        font_matrix = decoder.font_matrix;
+        font_offset = decoder.font_offset;
 
-      /* save new glyph tables */
-      psaux->t1_decoder_funcs->done( &decoder );
+        /* save new glyph tables */
+        psaux->t1_decoder_funcs->done( &decoder );
+      }
     }
 
     /* now, set the metrics -- this is rather simple, as   */
diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c
index bc799e4..4373d6f 100644
--- a/src/psaux/t1decode.c
+++ b/src/psaux/t1decode.c
@@ -350,11 +350,14 @@
 
     /* a font that reads BuildCharArray without setting */
     /* its values first is buggy, but ...               */
-    if ( decoder->face->len_buildchar > 0 )
+    FT_ASSERT( ( decoder->len_buildchar == 0 ) ==
+               ( decoder->buildchar == NULL ) );
+
+    if ( decoder->len_buildchar > 0 )
       memset( &decoder->buildchar[0],
               0,
               sizeof( decoder->buildchar[0] ) *
-                decoder->face->len_buildchar );
+                decoder->len_buildchar );
 
     FT_TRACE4(( "\nStart charstring\n" ));
 
@@ -839,7 +842,7 @@
 
             idx = top[1];
 
-            if ( idx < 0 || (FT_UInt) idx >= decoder->face->len_buildchar )
+            if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar )
               goto Unexpected_OtherSubr;
 
             decoder->buildchar[idx] = top[0];
@@ -859,7 +862,7 @@
 
             idx = top[0];
 
-            if ( idx < 0 || (FT_UInt) idx >= decoder->face->len_buildchar )
+            if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar )
               goto Unexpected_OtherSubr;
 
             top[0] = decoder->buildchar[idx];
@@ -987,14 +990,14 @@
 
 #ifdef FT_DEBUG_LEVEL_TRACE
 
-          if ( decoder->face->len_buildchar > 0 )
+          if ( decoder->len_buildchar > 0 )
           {
             FT_UInt  i;
 
 
             FT_TRACE4(( "BuildCharArray = [ " ));
 
-            for ( i = 0; i < decoder->face->len_buildchar; ++i )
+            for ( i = 0; i < decoder->len_buildchar; ++i )
               FT_TRACE4(( "%d ", decoder->buildchar[ i ] ));
 
             FT_TRACE4(( "]\n" ));
@@ -1423,10 +1426,6 @@
                    FT_Render_Mode       hint_mode,
                    T1_Decoder_Callback  parse_callback )
   {
-    FT_Error   error;
-    FT_Memory  memory = face->memory;
-
-
     FT_MEM_ZERO( decoder, sizeof ( *decoder ) );
 
     /* retrieve PSNames interface from list of current modules */
@@ -1445,20 +1444,12 @@
       decoder->psnames = psnames;
     }
 
-    decoder->face = (T1_Face) face;
-
-    if ( decoder->face->len_buildchar > 0 )
-    {
-      if ( FT_NEW_ARRAY( decoder->buildchar, decoder->face->len_buildchar ) )
-      {
-        FT_ERROR(( "t1_decoder_init: " ));
-        FT_ERROR(( "cannot allocate memory for BuildCharArray\n" ));
-        return error;
-      }
-    }
-
     t1_builder_init( &decoder->builder, face, size, slot, hinting );
 
+    /* decoder->buildchar and decoder->len_buildchar have to be  */
+    /* initialized by the caller since we cannot know the length */
+    /* of the BuildCharArray                                     */
+
     decoder->num_glyphs     = (FT_UInt)face->num_glyphs;
     decoder->glyph_names    = glyph_names;
     decoder->hint_mode      = hint_mode;
@@ -1467,7 +1458,7 @@
 
     decoder->funcs          = t1_decoder_funcs;
 
-    return 0;
+    return PSaux_Err_Ok;
   }
 
 
@@ -1475,12 +1466,7 @@
   FT_LOCAL_DEF( void )
   t1_decoder_done( T1_Decoder  decoder )
   {
-    FT_Memory  memory = decoder->face->root.memory;
-
-
     t1_builder_done( &decoder->builder );
-
-    FT_FREE( decoder->buildchar );
   }
 
 
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index 804713f..7012b4a 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -155,6 +155,8 @@
     PSAux_Service  psaux = (PSAux_Service)face->psaux;
 
 
+    FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
+
     *max_advance = 0;
 
     /* initialize load decoder */
@@ -173,9 +175,12 @@
     decoder.builder.metrics_only = 1;
     decoder.builder.load_points  = 0;
 
-    decoder.num_subrs = type1->num_subrs;
-    decoder.subrs     = type1->subrs;
-    decoder.subrs_len = type1->subrs_len;
+    decoder.num_subrs     = type1->num_subrs;
+    decoder.subrs         = type1->subrs;
+    decoder.subrs_len     = type1->subrs_len;
+
+    decoder.buildchar     = face->buildchar;
+    decoder.len_buildchar = face->len_buildchar;
 
     *max_advance = 0;
 
@@ -191,6 +196,8 @@
       /* ignore the error if one occurred - skip to next glyph */
     }
 
+    psaux->t1_decoder_funcs->done( &decoder );
+
     return T1_Err_Ok;
   }
 
@@ -212,11 +219,14 @@
     FT_Matrix               font_matrix;
     FT_Vector               font_offset;
     FT_Data                 glyph_data;
+    FT_Bool                 must_finish_decoder = FALSE;
 #ifdef FT_CONFIG_OPTION_INCREMENTAL
     FT_Bool                 glyph_data_loaded = 0;
 #endif
 
 
+    FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
+
     if ( load_flags & FT_LOAD_NO_RECURSE )
       load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
 
@@ -243,12 +253,17 @@
     if ( error )
       goto Exit;
 
+    must_finish_decoder = TRUE;
+
     decoder.builder.no_recurse = FT_BOOL(
                                    ( load_flags & FT_LOAD_NO_RECURSE ) != 0 );
 
-    decoder.num_subrs = type1->num_subrs;
-    decoder.subrs     = type1->subrs;
-    decoder.subrs_len = type1->subrs_len;
+    decoder.num_subrs     = type1->num_subrs;
+    decoder.subrs         = type1->subrs;
+    decoder.subrs_len     = type1->subrs_len;
+
+    decoder.buildchar     = face->buildchar;
+    decoder.len_buildchar = face->len_buildchar;
 
     /* now load the unscaled outline */
     error = T1_Parse_Glyph_And_Get_Char_String( &decoder, glyph_index,
@@ -265,6 +280,8 @@
     /* save new glyph tables */
     decoder_funcs->done( &decoder );
 
+    must_finish_decoder = FALSE;
+
     /* now, set the metrics -- this is rather simple, as   */
     /* the left side bearing is the xMin, and the top side */
     /* bearing the yMax                                    */
@@ -389,6 +406,9 @@
     }
 #endif
 
+    if ( must_finish_decoder )
+      decoder_funcs->done( &decoder );
+
     return error;
   }
 
diff --git a/src/type1/t1load.c b/src/type1/t1load.c
index 635e16c..14fba7f 100644
--- a/src/type1/t1load.c
+++ b/src/type1/t1load.c
@@ -2038,6 +2038,22 @@
         }
     }
 
+    if ( face->blend )
+    {
+      if ( face->len_buildchar > 0 )
+      {
+        FT_Memory  memory = face->root.memory;
+
+
+        if ( FT_NEW_ARRAY( face->buildchar, face->len_buildchar ) )
+        {
+          FT_ERROR(( "T1_Open_Face: cannot allocate BuildCharArray\n" ));
+          face->len_buildchar = 0;
+          goto Exit;
+        }
+      }
+    }
+
 #endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */
 
     /* now, propagate the subrs, charstrings, and glyphnames tables */
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index aa95122..095e7f1 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -201,6 +201,16 @@
 
 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
       /* release multiple masters information */
+      FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
+
+      if ( face->buildchar )
+      {
+        FT_FREE( face->buildchar );
+
+        face->buildchar     = NULL;
+        face->len_buildchar = 0;
+      }
+
       T1_Done_Blend( face );
       face->blend = 0;
 #endif