From 27a4f9c4ac45ff65f941964f7351b64b1e6a9f35 Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 20 Oct 2009 17:20:18 +0000 Subject: *** empty log message *** --- src/freetype2/type1/t1objs.c | 137 ++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 55 deletions(-) (limited to 'src/freetype2/type1/t1objs.c') diff --git a/src/freetype2/type1/t1objs.c b/src/freetype2/type1/t1objs.c index 3d08336..e9357e6 100644 --- a/src/freetype2/type1/t1objs.c +++ b/src/freetype2/type1/t1objs.c @@ -4,7 +4,7 @@ /* */ /* Type 1 objects manager (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,7 @@ #include +#include FT_INTERNAL_CALC_H #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_TRUETYPE_IDS_H @@ -90,7 +91,7 @@ FT_LOCAL_DEF( FT_Error ) T1_Size_Init( T1_Size size ) { - FT_Error error = 0; + FT_Error error = T1_Err_Ok; PSH_Globals_Funcs funcs = T1_Size_Get_Globals_Funcs( size ); @@ -191,72 +192,75 @@ FT_LOCAL_DEF( void ) T1_Face_Done( T1_Face face ) { - if ( face ) - { - FT_Memory memory = face->root.memory; - T1_Font type1 = &face->type1; + FT_Memory memory; + T1_Font type1; + + + if ( !face ) + return; + memory = face->root.memory; + type1 = &face->type1; #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT - /* release multiple masters information */ - FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) ); + /* release multiple masters information */ + FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) ); - if ( face->buildchar ) - { - FT_FREE( face->buildchar ); + if ( face->buildchar ) + { + FT_FREE( face->buildchar ); - face->buildchar = NULL; - face->len_buildchar = 0; - } + face->buildchar = NULL; + face->len_buildchar = 0; + } - T1_Done_Blend( face ); - face->blend = 0; + T1_Done_Blend( face ); + face->blend = 0; #endif - /* release font info strings */ - { - PS_FontInfo info = &type1->font_info; + /* release font info strings */ + { + PS_FontInfo info = &type1->font_info; - FT_FREE( info->version ); - FT_FREE( info->notice ); - FT_FREE( info->full_name ); - FT_FREE( info->family_name ); - FT_FREE( info->weight ); - } + FT_FREE( info->version ); + FT_FREE( info->notice ); + FT_FREE( info->full_name ); + FT_FREE( info->family_name ); + FT_FREE( info->weight ); + } - /* release top dictionary */ - FT_FREE( type1->charstrings_len ); - FT_FREE( type1->charstrings ); - FT_FREE( type1->glyph_names ); + /* release top dictionary */ + FT_FREE( type1->charstrings_len ); + FT_FREE( type1->charstrings ); + FT_FREE( type1->glyph_names ); - FT_FREE( type1->subrs ); - FT_FREE( type1->subrs_len ); + FT_FREE( type1->subrs ); + FT_FREE( type1->subrs_len ); - FT_FREE( type1->subrs_block ); - FT_FREE( type1->charstrings_block ); - FT_FREE( type1->glyph_names_block ); + FT_FREE( type1->subrs_block ); + FT_FREE( type1->charstrings_block ); + FT_FREE( type1->glyph_names_block ); - FT_FREE( type1->encoding.char_index ); - FT_FREE( type1->encoding.char_name ); - FT_FREE( type1->font_name ); + FT_FREE( type1->encoding.char_index ); + FT_FREE( type1->encoding.char_name ); + FT_FREE( type1->font_name ); #ifndef T1_CONFIG_OPTION_NO_AFM - /* release afm data if present */ - if ( face->afm_data ) - T1_Done_Metrics( memory, (AFM_FontInfo)face->afm_data ); + /* release afm data if present */ + if ( face->afm_data ) + T1_Done_Metrics( memory, (AFM_FontInfo)face->afm_data ); #endif - /* release unicode map, if any */ + /* release unicode map, if any */ #if 0 - FT_FREE( face->unicode_map_rec.maps ); - face->unicode_map_rec.num_maps = 0; - face->unicode_map = NULL; + FT_FREE( face->unicode_map_rec.maps ); + face->unicode_map_rec.num_maps = 0; + face->unicode_map = NULL; #endif - face->root.family_name = 0; - face->root.style_name = 0; - } + face->root.family_name = NULL; + face->root.style_name = NULL; } @@ -298,7 +302,6 @@ FT_UNUSED( num_params ); FT_UNUSED( params ); - FT_UNUSED( face_index ); FT_UNUSED( stream ); @@ -324,7 +327,7 @@ goto Exit; /* check the face index */ - if ( face_index != 0 ) + if ( face_index > 0 ) { FT_ERROR(( "T1_Face_Init: invalid face index\n" )); error = T1_Err_Invalid_Argument; @@ -341,7 +344,7 @@ root->num_glyphs = type1->num_glyphs; - root->face_index = face_index; + root->face_index = 0; root->face_flags = FT_FACE_FLAG_SCALABLE | FT_FACE_FLAG_HORIZONTAL | @@ -356,11 +359,18 @@ /* XXX: TODO -- add kerning with .afm support */ + + /* The following code to extract the family and the style is very */ + /* simplistic and might get some things wrong. For a full-featured */ + /* algorithm you might have a look at the whitepaper given at */ + /* */ + /* http://blogs.msdn.com/text/archive/2007/04/23/wpf-font-selection-model.aspx */ + /* get style name -- be careful, some broken fonts only */ /* have a `/FontName' dictionary entry! */ root->family_name = info->family_name; - /* assume "Regular" style if we don't know better */ - root->style_name = (char *)"Regular"; + root->style_name = NULL; + if ( root->family_name ) { char* full = info->full_name; @@ -369,6 +379,9 @@ if ( full ) { + FT_Bool the_same = TRUE; + + while ( *full ) { if ( *full == *family ) @@ -384,12 +397,17 @@ family++; else { + the_same = FALSE; + if ( !*family ) root->style_name = full; break; } } } + + if ( the_same ) + root->style_name = (char *)"Regular"; } } else @@ -399,6 +417,15 @@ root->family_name = type1->font_name; } + if ( !root->style_name ) + { + if ( info->weight ) + root->style_name = info->weight; + else + /* assume `Regular' style because we don't know better */ + root->style_name = (char *)"Regular"; + } + /* compute style flags */ root->style_flags = 0; if ( info->italic_angle ) @@ -441,9 +468,9 @@ /* in case of error, keep the standard width */ if ( !error ) - root->max_advance_width = (FT_Short)max_advance; + root->max_advance_width = (FT_Short)FIXED_TO_INT( max_advance ); else - error = 0; /* clear error */ + error = T1_Err_Ok; /* clear error */ } root->max_advance_height = root->height; @@ -465,7 +492,7 @@ charmap.face = root; - /* first of all, try to synthetize a Unicode charmap */ + /* first of all, try to synthesize a Unicode charmap */ charmap.platform_id = 3; charmap.encoding_id = 1; charmap.encoding = FT_ENCODING_UNICODE; -- cgit v1.2.3