closed most of the memory leaks in the Type 1 driver(s)

this is required before any serious work to implement
multiple masters
This commit is contained in:
David Turner 2000-05-05 12:33:23 +00:00
parent a1656abd8f
commit 4d3e56392f
9 changed files with 204 additions and 152 deletions

View File

@ -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' )

View File

@ -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,

View File

@ -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

View File

@ -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 );

View File

@ -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

View File

@ -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' )

View File

@ -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,

View File

@ -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

View File

@ -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;
}