From 4d3e56392fd0a89d97cb3f567d713cb15ac74cbf Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 5 May 2000 12:33:23 +0000 Subject: [PATCH] closed most of the memory leaks in the Type 1 driver(s) this is required before any serious work to implement multiple masters --- src/type1/t1afm.c | 2 - src/type1/t1afm.h | 2 - src/type1/t1driver.c | 71 +---------------------------- src/type1/t1objs.c | 102 +++++++++++++++++++++++++++++++++++++++++- src/type1z/rules.mk | 2 +- src/type1z/t1afm.c | 2 - src/type1z/t1afm.h | 2 - src/type1z/t1driver.c | 72 +---------------------------- src/type1z/t1objs.c | 101 ++++++++++++++++++++++++++++++++++++++++- 9 files changed, 204 insertions(+), 152 deletions(-) diff --git a/src/type1/t1afm.c b/src/type1/t1afm.c index 036aa5e66..f619e28e5 100644 --- a/src/type1/t1afm.c +++ b/src/type1/t1afm.c @@ -10,14 +10,12 @@ #include #include /* 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 366c2f2d5..567ed6325 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 23e8d03de..ed5920118 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 7bd19dc81..79d26db9b 100644 --- a/src/type1/t1objs.c +++ b/src/type1/t1objs.c @@ -20,6 +20,7 @@ #include #include +#include #ifndef T1_CONFIG_OPTION_DISABLE_HINTER #include @@ -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 b90220107..93d6072de 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 036aa5e66..f619e28e5 100644 --- a/src/type1z/t1afm.c +++ b/src/type1z/t1afm.c @@ -10,14 +10,12 @@ #include #include /* 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 366c2f2d5..567ed6325 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 5a3ddd2c3..d25b95700 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; - } - /******************************************************************/ /* */ /* 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 32c7cbf25..c034c160c 100644 --- a/src/type1z/t1objs.c +++ b/src/type1z/t1objs.c @@ -21,6 +21,7 @@ #include #include #include +#include /* 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; }