Commit 4d3e56392fd0a89d97cb3f567d713cb15ac74cbf

David Turner 2000-05-05T12:33:23

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
diff --git a/src/type1/t1afm.c b/src/type1/t1afm.c
index 036aa5e..f619e28 100644
--- a/src/type1/t1afm.c
+++ b/src/type1/t1afm.c
@@ -10,14 +10,12 @@
 #include <t1types.h>
 #include <stdlib.h>  /* for qsort */
 
-#if 0
   LOCAL_FUNC
   void  T1_Done_AFM( FT_Memory memory, T1_AFM*  afm )
   {
     FREE( afm->kern_pairs );
     afm->num_pairs = 0;
   }
-#endif
 
 #undef  IS_KERN_PAIR
 #define IS_KERN_PAIR(p)  ( p[0] == 'K'  &&  p[1] == 'P' )
diff --git a/src/type1/t1afm.h b/src/type1/t1afm.h
index 366c2f2..567ed63 100644
--- a/src/type1/t1afm.h
+++ b/src/type1/t1afm.h
@@ -34,11 +34,9 @@ LOCAL_DEF
 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,
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index 23e8d03..ed59201 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -285,75 +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;
-
-      /* 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;
-  }
 
   /******************************************************************/
   /*                                                                */
@@ -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    
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 7bd19dc..79d26db 100644
--- 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;
     }
   }
 
@@ -312,6 +352,66 @@
       }
     }
 
+    /* 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:
     Done_Tokenizer( tokenizer );
 
diff --git a/src/type1z/rules.mk b/src/type1z/rules.mk
index b902201..93d6072 100644
--- a/src/type1z/rules.mk
+++ b/src/type1z/rules.mk
@@ -59,7 +59,7 @@ T1Z_DRV_H := $(T1Z_DIR_)t1errors.h  \
 #   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
 
 
diff --git a/src/type1z/t1afm.c b/src/type1z/t1afm.c
index 036aa5e..f619e28 100644
--- a/src/type1z/t1afm.c
+++ b/src/type1z/t1afm.c
@@ -10,14 +10,12 @@
 #include <t1types.h>
 #include <stdlib.h>  /* for qsort */
 
-#if 0
   LOCAL_FUNC
   void  T1_Done_AFM( FT_Memory memory, T1_AFM*  afm )
   {
     FREE( afm->kern_pairs );
     afm->num_pairs = 0;
   }
-#endif
 
 #undef  IS_KERN_PAIR
 #define IS_KERN_PAIR(p)  ( p[0] == 'K'  &&  p[1] == 'P' )
diff --git a/src/type1z/t1afm.h b/src/type1z/t1afm.h
index 366c2f2..567ed63 100644
--- a/src/type1z/t1afm.h
+++ b/src/type1z/t1afm.h
@@ -34,11 +34,9 @@ LOCAL_DEF
 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,
diff --git a/src/type1z/t1driver.c b/src/type1z/t1driver.c
index 5a3ddd2..d25b957 100644
--- 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    
diff --git a/src/type1z/t1objs.c b/src/type1z/t1objs.c
index 32c7cbf..c034c16 100644
--- 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;
   }