shithub: freetype+ttf2subf

Download patch

ref: 4d3e56392fd0a89d97cb3f567d713cb15ac74cbf
parent: a1656abd8f9acb5a1a546eee66a7a73fc6bfc076
author: David Turner <[email protected]>
date: Fri May 5 08:33:23 EDT 2000

closed most of the memory leaks in the Type 1 driver(s)
this is required before any serious work to implement
multiple masters

git/fs: mount .git/fs: mount/attach disallowed
--- a/src/type1/t1afm.c
+++ b/src/type1/t1afm.c
@@ -10,7 +10,6 @@
 #include <t1types.h>
 #include <stdlib.h>  /* for qsort */
 
-#if 0
   LOCAL_FUNC
   void  T1_Done_AFM( FT_Memory memory, T1_AFM*  afm )
   {
@@ -17,7 +16,6 @@
     FREE( afm->kern_pairs );
     afm->num_pairs = 0;
   }
-#endif
 
 #undef  IS_KERN_PAIR
 #define IS_KERN_PAIR(p)  ( p[0] == 'K'  &&  p[1] == 'P' )
--- a/src/type1/t1afm.h
+++ b/src/type1/t1afm.h
@@ -34,11 +34,9 @@
 FT_Error  T1_Read_AFM( FT_Face   face,
                        FT_Stream stream );
 
-#if 0
 LOCAL_DEF
 void      T1_Done_AFM( FT_Memory  memory,
                        T1_AFM*    afm );
-#endif
 
 LOCAL_DEF
 void  T1_Get_Kerning( T1_AFM*     afm,
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -285,76 +285,7 @@
   }
 
 
-  static
-  T1_Error   Init_Face( FT_Stream  stream,
-                        FT_Int     face_index,
-                        T1_Face    face )
-  {
-    T1_Error  error;
-    
-    error = T1_Init_Face(stream, face_index, face);
-    if (!error)
-    {
-      FT_Face      root    = &face->root;
-      FT_CharMap   charmap = face->charmaprecs;
 
-      /* synthesize a Unicode charmap if there is support in the "psnames" */
-      /* module..                                                          */
-      if (face->psnames)
-      {
-        PSNames_Interface*  psnames = (PSNames_Interface*)face->psnames;
-        if (psnames->unicode_value)
-        {
-          error = psnames->build_unicodes( root->memory,
-                                           face->type1.num_glyphs,
-                                           (const char**)face->type1.glyph_names,
-                                           &face->unicode_map );
-          if (!error)
-          {
-            root->charmap        = charmap;
-            charmap->face        = (FT_Face)face;
-            charmap->encoding    = ft_encoding_unicode;
-            charmap->platform_id = 3;
-            charmap->encoding_id = 1;
-            charmap++;
-          }
-          
-          /* simply clear the error in case of failure (which really) */
-          /* means that out of memory or no unicode glyph names       */
-          error = 0;
-        }
-      }
-
-      /* now, support either the standard, expert, or custom encodings */
-      charmap->face        = (FT_Face)face;
-      charmap->platform_id = 7;  /* a new platform id for Adobe fonts ?? */
-      
-      switch (face->type1.encoding_type)
-      {
-        case t1_encoding_standard:
-          charmap->encoding    = ft_encoding_adobe_standard;
-          charmap->encoding_id = 0;
-          break;
-        
-        case t1_encoding_expert:
-          charmap->encoding    = ft_encoding_adobe_expert;
-          charmap->encoding_id = 1;
-          break;
-        
-        default:
-          charmap->encoding    = ft_encoding_adobe_custom;
-          charmap->encoding_id = 2;
-          break;
-      }
-      
-      root->charmaps = face->charmaps;
-      root->num_charmaps = charmap - face->charmaprecs + 1;
-      face->charmaps[0] = &face->charmaprecs[0];
-      face->charmaps[1] = &face->charmaprecs[1];
-    }
-    return error;
-  }
-
   /******************************************************************/
   /*                                                                */
   /* <Struct> FT_DriverInterface                                    */
@@ -452,7 +383,7 @@
     (FTDriver_getInterface)         Get_Interface,
 #endif
 
-    (FTDriver_initFace)             Init_Face,
+    (FTDriver_initFace)             T1_Init_Face,
     (FTDriver_doneFace)             T1_Done_Face,
 
 #ifdef T1_CONFIG_OPTION_NO_AFM    
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -20,6 +20,7 @@
 
 #include <t1gload.h>
 #include <t1load.h>
+#include <t1afm.h>
 
 #ifndef T1_CONFIG_OPTION_DISABLE_HINTER
 #include <t1hinter.h>
@@ -155,11 +156,50 @@
   void  T1_Done_Face( T1_Face  face )
   {
     FT_Memory  memory;
+    T1_Font*   type1 = &face->type1;
 
     if (face)
     {
       memory = face->root.memory;
-      /* XXXX : TO DO */
+      
+      /* release font info strings */      
+      {
+        T1_FontInfo*  info = &type1->font_info;
+        
+        FREE( info->version );
+        FREE( info->notice );
+        FREE( info->full_name );
+        FREE( info->family_name );
+        FREE( info->weight );
+      }
+
+      /* release top dictionary */      
+      FREE( type1->charstrings_len );
+      FREE( type1->charstrings );
+      FREE( type1->glyph_names );
+
+      FREE( type1->subrs );
+      FREE( type1->subrs_len );
+      
+      FREE( type1->subrs_block );
+      FREE( type1->charstrings_block );
+      FREE( type1->glyph_names_block );
+
+      FREE( type1->encoding.char_index );
+      FREE( type1->font_name );
+      
+#ifndef T1_CONFIG_OPTION_NO_AFM
+      /* release afm data if present */
+      if ( face->afm_data)
+        T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
+#endif
+
+      /* release unicode map, if any */
+      FREE( face->unicode_map.maps );
+      face->unicode_map.num_maps = 0;
+
+      face->root.family_name = 0;
+      face->root.style_name  = 0;
     }
   }
 
@@ -310,6 +350,66 @@
         root->max_points   = 0;
         root->max_contours = 0;
       }
+    }
+
+    /* charmap support - synthetize unicode charmap when possible */
+    {
+      FT_Face      root    = &face->root;
+      FT_CharMap   charmap = face->charmaprecs;
+
+      /* synthesize a Unicode charmap if there is support in the "psnames" */
+      /* module..                                                          */
+      if (face->psnames)
+      {
+        PSNames_Interface*  psnames = (PSNames_Interface*)face->psnames;
+        if (psnames->unicode_value)
+        {
+          error = psnames->build_unicodes( root->memory,
+                                           face->type1.num_glyphs,
+                                           (const char**)face->type1.glyph_names,
+                                           &face->unicode_map );
+          if (!error)
+          {
+            root->charmap        = charmap;
+            charmap->face        = (FT_Face)face;
+            charmap->encoding    = ft_encoding_unicode;
+            charmap->platform_id = 3;
+            charmap->encoding_id = 1;
+            charmap++;
+          }
+          
+          /* simply clear the error in case of failure (which really) */
+          /* means that out of memory or no unicode glyph names       */
+          error = 0;
+        }
+      }
+
+      /* now, support either the standard, expert, or custom encodings */
+      charmap->face        = (FT_Face)face;
+      charmap->platform_id = 7;  /* a new platform id for Adobe fonts ?? */
+      
+      switch (face->type1.encoding_type)
+      {
+        case t1_encoding_standard:
+          charmap->encoding    = ft_encoding_adobe_standard;
+          charmap->encoding_id = 0;
+          break;
+        
+        case t1_encoding_expert:
+          charmap->encoding    = ft_encoding_adobe_expert;
+          charmap->encoding_id = 1;
+          break;
+        
+        default:
+          charmap->encoding    = ft_encoding_adobe_custom;
+          charmap->encoding_id = 2;
+          break;
+      }
+      
+      root->charmaps = face->charmaps;
+      root->num_charmaps = charmap - face->charmaprecs + 1;
+      face->charmaps[0] = &face->charmaprecs[0];
+      face->charmaps[1] = &face->charmaprecs[1];
     }
 
   Leave:
--- a/src/type1z/rules.mk
+++ b/src/type1z/rules.mk
@@ -59,7 +59,7 @@
 #   T1Z_DRV_OBJ_S is used during `release' builds
 #
 T1Z_DRV_OBJ_M := $(T1Z_DRV_SRC:$(T1Z_DIR_)%.c=$(OBJ_)%.$O) \
-                $(T1SHARED:$(T1SHARED_DIR_)%.c=$(OBJ_)%.$O)
+                 $(T1SHARED:$(T1SHARED_DIR_)%.c=$(OBJ_)%.$O)
 T1Z_DRV_OBJ_S := $(OBJ_)type1z.$O
 
 
--- a/src/type1z/t1afm.c
+++ b/src/type1z/t1afm.c
@@ -10,7 +10,6 @@
 #include <t1types.h>
 #include <stdlib.h>  /* for qsort */
 
-#if 0
   LOCAL_FUNC
   void  T1_Done_AFM( FT_Memory memory, T1_AFM*  afm )
   {
@@ -17,7 +16,6 @@
     FREE( afm->kern_pairs );
     afm->num_pairs = 0;
   }
-#endif
 
 #undef  IS_KERN_PAIR
 #define IS_KERN_PAIR(p)  ( p[0] == 'K'  &&  p[1] == 'P' )
--- a/src/type1z/t1afm.h
+++ b/src/type1z/t1afm.h
@@ -34,11 +34,9 @@
 FT_Error  T1_Read_AFM( FT_Face   face,
                        FT_Stream stream );
 
-#if 0
 LOCAL_DEF
 void      T1_Done_AFM( FT_Memory  memory,
                        T1_AFM*    afm );
-#endif
 
 LOCAL_DEF
 void  T1_Get_Kerning( T1_AFM*     afm,
--- a/src/type1z/t1driver.c
+++ b/src/type1z/t1driver.c
@@ -285,76 +285,6 @@
   }
 
 
-  static
-  T1_Error   Init_Face( FT_Stream  stream,
-                        FT_Int     face_index,
-                        T1_Face    face )
-  {
-    T1_Error  error;
-    
-    error = T1_Init_Face(stream, face_index, face);
-    if (!error)
-    {
-      FT_Face      root    = &face->root;
-      FT_CharMap   charmap = face->charmaprecs;
-
-      /* synthetize a Unicode charmap if there is support in the "psnames" */
-      /* module..                                                          */
-      if (face->psnames)
-      {
-        PSNames_Interface*  psnames = (PSNames_Interface*)face->psnames;
-        if (psnames->unicode_value)
-        {
-          error = psnames->build_unicodes( root->memory,
-                                           face->type1.num_glyphs,
-                                           (const char**)face->type1.glyph_names,
-                                           &face->unicode_map );
-          if (!error)
-          {
-            root->charmap        = charmap;
-            charmap->face        = (FT_Face)face;
-            charmap->encoding    = ft_encoding_unicode;
-            charmap->platform_id = 3;
-            charmap->encoding_id = 1;
-            charmap++;
-          }
-          
-          /* simply clear the error in case of failure (which really) */
-          /* means that out of memory or no unicode glyph names       */
-          error = 0;
-        }
-      }
-
-      /* now, support either the standard, expert, or custom encodings */
-      charmap->face        = (FT_Face)face;
-      charmap->platform_id = 7;  /* a new platform id for Adobe fonts ?? */
-      
-      switch (face->type1.encoding_type)
-      {
-        case t1_encoding_standard:
-          charmap->encoding    = ft_encoding_adobe_standard;
-          charmap->encoding_id = 0;
-          break;
-        
-        case t1_encoding_expert:
-          charmap->encoding    = ft_encoding_adobe_expert;
-          charmap->encoding_id = 1;
-          break;
-        
-        default:
-          charmap->encoding    = ft_encoding_adobe_custom;
-          charmap->encoding_id = 2;
-          break;
-      }
-      
-      root->charmaps = face->charmaps;
-      root->num_charmaps = charmap - face->charmaprecs + 1;
-      face->charmaps[0] = &face->charmaprecs[0];
-      face->charmaps[1] = &face->charmaprecs[1];
-    }
-    return error;
-  }
-
   /******************************************************************/
   /*                                                                */
   /* <Struct> FT_DriverInterface                                    */
@@ -452,7 +382,7 @@
     (FTDriver_getInterface)         Get_Interface,
 #endif
 
-    (FTDriver_initFace)             Init_Face,
+    (FTDriver_initFace)             T1_Init_Face,
     (FTDriver_doneFace)             T1_Done_Face,
 
 #ifdef T1_CONFIG_OPTION_NO_AFM    
--- a/src/type1z/t1objs.c
+++ b/src/type1z/t1objs.c
@@ -21,6 +21,7 @@
 #include <t1gload.h>
 #include <t1load.h>
 #include <psnames.h>
+#include <t1afm.h>
 
 /* Required by tracing mode */
 #undef   FT_COMPONENT
@@ -135,11 +136,50 @@
   void  T1_Done_Face( T1_Face  face )
   {
     FT_Memory  memory;
+    T1_Font*   type1 = &face->type1;
 
     if (face)
     {
       memory = face->root.memory;
-      /* XXXX : TO DO */
+
+      /* release font info strings */      
+      {
+        T1_FontInfo*  info = &type1->font_info;
+        
+        FREE( info->version );
+        FREE( info->notice );
+        FREE( info->full_name );
+        FREE( info->family_name );
+        FREE( info->weight );
+      }
+
+      /* release top dictionary */      
+      FREE( type1->charstrings_len );
+      FREE( type1->charstrings );
+      FREE( type1->glyph_names );
+
+      FREE( type1->subrs );
+      FREE( type1->subrs_len );
+      
+      FREE( type1->subrs_block );
+      FREE( type1->charstrings_block );
+      FREE( type1->glyph_names_block );
+
+      FREE( type1->encoding.char_index );
+      FREE( type1->font_name );
+      
+#ifndef T1_CONFIG_OPTION_NO_AFM
+      /* release afm data if present */
+      if ( face->afm_data)
+        T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
+#endif
+
+      /* release unicode map, if any */
+      FREE( face->unicode_map.maps );
+      face->unicode_map.num_maps = 0;
+
+      face->root.family_name = 0;
+      face->root.style_name  = 0;
     }
   }
 
@@ -285,6 +325,65 @@
       }
     }
 
+    /* charmap support - synthetize unicode charmap when possible */
+    {
+      FT_Face      root    = &face->root;
+      FT_CharMap   charmap = face->charmaprecs;
+
+      /* synthesize a Unicode charmap if there is support in the "psnames" */
+      /* module..                                                          */
+      if (face->psnames)
+      {
+        PSNames_Interface*  psnames = (PSNames_Interface*)face->psnames;
+        if (psnames->unicode_value)
+        {
+          error = psnames->build_unicodes( root->memory,
+                                           face->type1.num_glyphs,
+                                           (const char**)face->type1.glyph_names,
+                                           &face->unicode_map );
+          if (!error)
+          {
+            root->charmap        = charmap;
+            charmap->face        = (FT_Face)face;
+            charmap->encoding    = ft_encoding_unicode;
+            charmap->platform_id = 3;
+            charmap->encoding_id = 1;
+            charmap++;
+          }
+          
+          /* simply clear the error in case of failure (which really) */
+          /* means that out of memory or no unicode glyph names       */
+          error = 0;
+        }
+      }
+
+      /* now, support either the standard, expert, or custom encodings */
+      charmap->face        = (FT_Face)face;
+      charmap->platform_id = 7;  /* a new platform id for Adobe fonts ?? */
+      
+      switch (face->type1.encoding_type)
+      {
+        case t1_encoding_standard:
+          charmap->encoding    = ft_encoding_adobe_standard;
+          charmap->encoding_id = 0;
+          break;
+        
+        case t1_encoding_expert:
+          charmap->encoding    = ft_encoding_adobe_expert;
+          charmap->encoding_id = 1;
+          break;
+        
+        default:
+          charmap->encoding    = ft_encoding_adobe_custom;
+          charmap->encoding_id = 2;
+          break;
+      }
+      
+      root->charmaps = face->charmaps;
+      root->num_charmaps = charmap - face->charmaprecs + 1;
+      face->charmaps[0] = &face->charmaprecs[0];
+      face->charmaps[1] = &face->charmaprecs[1];
+    }
   Exit:
     return error;
   }