shithub: freetype+ttf2subf

Download patch

ref: a4d6a1c8d126f62aefaabc6b02c170adc31b93de
parent: 1a380e02d1668d559a073d75200e3866d37b8e4d
author: Werner Lemberg <[email protected]>
date: Wed Jul 19 05:54:56 EDT 2006

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.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2006-07-18  Jens Claudius  <[email protected]>
+
+	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  <[email protected]>
 
 	* freetype2/include/freetype/internal/psaux.h: New macros
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -687,8 +687,7 @@
     T1_Decoder_FuncsRec  funcs;
 
     FT_Int*              buildchar;
-
-    T1_Face              face;
+    FT_UInt              len_buildchar;
 
   } T1_DecoderRec;
 
--- a/include/freetype/internal/t1types.h
+++ b/include/freetype/internal/t1types.h
@@ -217,6 +217,7 @@
     /* 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;
--- 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     */
 
-      error = cid_load_glyph( &decoder, glyph_index );
+        /* set up the decoder */
+        decoder.builder.no_recurse = FT_BOOL(
+          ( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) );
 
-      font_matrix = decoder.font_matrix;
-      font_offset = decoder.font_offset;
+        error = cid_load_glyph( &decoder, glyph_index );
 
-      /* save new glyph tables */
-      psaux->t1_decoder_funcs->done( &decoder );
+        font_matrix = decoder.font_matrix;
+        font_offset = decoder.font_offset;
+
+        /* save new glyph tables */
+        psaux->t1_decoder_funcs->done( &decoder );
+      }
     }
 
     /* now, set the metrics -- this is rather simple, as   */
--- 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,7 +990,7 @@
 
 #ifdef FT_DEBUG_LEVEL_TRACE
 
-          if ( decoder->face->len_buildchar > 0 )
+          if ( decoder->len_buildchar > 0 )
           {
             FT_UInt  i;
 
@@ -994,7 +997,7 @@
 
             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 );
   }
 
 
--- 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,10 +175,13 @@
     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;
 
     /* for each glyph, parse the glyph charstring and extract */
@@ -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,13 +253,18 @@
     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,
                                                 &glyph_data );
@@ -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                                    */
@@ -388,6 +405,9 @@
       glyph->root.control_len  = 0;
     }
 #endif
+
+    if ( must_finish_decoder )
+      decoder_funcs->done( &decoder );
 
     return error;
   }
--- 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 */
--- 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