-/***************************************************************************/\r
-/* */\r
-/* t42objs.c */\r
-/* */\r
-/* Type 42 objects manager (body). */\r
-/* */\r
-/* Copyright 2002, 2003, 2004, 2005, 2006, 2007 by Roberto Alameda. */\r
-/* */\r
-/* This file is part of the FreeType project, and may only be used, */\r
-/* modified, and distributed under the terms of the FreeType project */\r
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */\r
-/* this file you indicate that you have read the license and */\r
-/* understand and accept it fully. */\r
-/* */\r
-/***************************************************************************/\r
-\r
-\r
-#include "t42objs.h"\r
-#include "t42parse.h"\r
-#include "t42error.h"\r
-#include FT_INTERNAL_DEBUG_H\r
-#include FT_INTERNAL_STREAM_H\r
-#include FT_LIST_H\r
-\r
-\r
-#undef FT_COMPONENT\r
-#define FT_COMPONENT trace_t42\r
-\r
-\r
- static FT_Error\r
- T42_Open_Face( T42_Face face )\r
- {\r
- T42_LoaderRec loader;\r
- T42_Parser parser;\r
- T1_Font type1 = &face->type1;\r
- FT_Memory memory = face->root.memory;\r
- FT_Error error;\r
-\r
- PSAux_Service psaux = (PSAux_Service)face->psaux;\r
-\r
-\r
- t42_loader_init( &loader, face );\r
-\r
- parser = &loader.parser;\r
-\r
- if ( FT_ALLOC( face->ttf_data, 12 ) )\r
- goto Exit;\r
-\r
- error = t42_parser_init( parser,\r
- face->root.stream,\r
- memory,\r
- psaux);\r
- if ( error )\r
- goto Exit;\r
-\r
- error = t42_parse_dict( face, &loader,\r
- parser->base_dict, parser->base_len );\r
- if ( error )\r
- goto Exit;\r
-\r
- if ( type1->font_type != 42 )\r
- {\r
- error = T42_Err_Unknown_File_Format;\r
- goto Exit;\r
- }\r
-\r
- /* now, propagate the charstrings and glyphnames tables */\r
- /* to the Type1 data */\r
- type1->num_glyphs = loader.num_glyphs;\r
-\r
- if ( !loader.charstrings.init )\r
- {\r
- FT_ERROR(( "T42_Open_Face: no charstrings array in face!\n" ));\r
- error = T42_Err_Invalid_File_Format;\r
- }\r
-\r
- loader.charstrings.init = 0;\r
- type1->charstrings_block = loader.charstrings.block;\r
- type1->charstrings = loader.charstrings.elements;\r
- type1->charstrings_len = loader.charstrings.lengths;\r
-\r
- /* we copy the glyph names `block' and `elements' fields; */\r
- /* the `lengths' field must be released later */\r
- type1->glyph_names_block = loader.glyph_names.block;\r
- type1->glyph_names = (FT_String**)loader.glyph_names.elements;\r
- loader.glyph_names.block = 0;\r
- loader.glyph_names.elements = 0;\r
-\r
- /* we must now build type1.encoding when we have a custom array */\r
- if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )\r
- {\r
- FT_Int charcode, idx, min_char, max_char;\r
- FT_Byte* char_name;\r
- FT_Byte* glyph_name;\r
-\r
-\r
- /* OK, we do the following: for each element in the encoding */\r
- /* table, look up the index of the glyph having the same name */\r
- /* as defined in the CharStrings array. */\r
- /* The index is then stored in type1.encoding.char_index, and */\r
- /* the name in type1.encoding.char_name */\r
-\r
- min_char = +32000;\r
- max_char = -32000;\r
-\r
- charcode = 0;\r
- for ( ; charcode < loader.encoding_table.max_elems; charcode++ )\r
- {\r
- type1->encoding.char_index[charcode] = 0;\r
- type1->encoding.char_name [charcode] = (char *)".notdef";\r
-\r
- char_name = loader.encoding_table.elements[charcode];\r
- if ( char_name )\r
- for ( idx = 0; idx < type1->num_glyphs; idx++ )\r
- {\r
- glyph_name = (FT_Byte*)type1->glyph_names[idx];\r
- if ( ft_strcmp( (const char*)char_name,\r
- (const char*)glyph_name ) == 0 )\r
- {\r
- type1->encoding.char_index[charcode] = (FT_UShort)idx;\r
- type1->encoding.char_name [charcode] = (char*)glyph_name;\r
-\r
- /* Change min/max encoded char only if glyph name is */\r
- /* not /.notdef */\r
- if ( ft_strcmp( (const char*)".notdef",\r
- (const char*)glyph_name ) != 0 )\r
- {\r
- if ( charcode < min_char )\r
- min_char = charcode;\r
- if ( charcode > max_char )\r
- max_char = charcode;\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- type1->encoding.code_first = min_char;\r
- type1->encoding.code_last = max_char;\r
- type1->encoding.num_chars = loader.num_chars;\r
- }\r
-\r
- Exit:\r
- t42_loader_done( &loader );\r
- return error;\r
- }\r
-\r
-\r
- /***************** Driver Functions *************/\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_Face_Init( FT_Stream stream,\r
- T42_Face face,\r
- FT_Int face_index,\r
- FT_Int num_params,\r
- FT_Parameter* params )\r
- {\r
- FT_Error error;\r
- FT_Service_PsCMaps psnames;\r
- PSAux_Service psaux;\r
- FT_Face root = (FT_Face)&face->root;\r
- T1_Font type1 = &face->type1;\r
- PS_FontInfo info = &type1->font_info;\r
-\r
- FT_UNUSED( num_params );\r
- FT_UNUSED( params );\r
- FT_UNUSED( face_index );\r
- FT_UNUSED( stream );\r
-\r
-\r
- face->ttf_face = NULL;\r
- face->root.num_faces = 1;\r
-\r
- FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );\r
- face->psnames = psnames;\r
-\r
- face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),\r
- "psaux" );\r
- psaux = (PSAux_Service)face->psaux;\r
-\r
- /* open the tokenizer, this will also check the font format */\r
- error = T42_Open_Face( face );\r
- if ( error )\r
- goto Exit;\r
-\r
- /* if we just wanted to check the format, leave successfully now */\r
- if ( face_index < 0 )\r
- goto Exit;\r
-\r
- /* check the face index */\r
- if ( face_index != 0 )\r
- {\r
- FT_ERROR(( "T42_Face_Init: invalid face index\n" ));\r
- error = T42_Err_Invalid_Argument;\r
- goto Exit;\r
- }\r
-\r
- /* Now load the font program into the face object */\r
-\r
- /* Init the face object fields */\r
- /* Now set up root face fields */\r
-\r
- root->num_glyphs = type1->num_glyphs;\r
- root->num_charmaps = 0;\r
- root->face_index = face_index;\r
-\r
- root->face_flags = FT_FACE_FLAG_SCALABLE |\r
- FT_FACE_FLAG_HORIZONTAL |\r
- FT_FACE_FLAG_GLYPH_NAMES;\r
-\r
- if ( info->is_fixed_pitch )\r
- root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;\r
-\r
- /* We only set this flag if we have the patented bytecode interpreter. */\r
- /* There are no known `tricky' Type42 fonts that could be loaded with */\r
- /* the unpatented interpreter. */\r
-#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER\r
- root->face_flags |= FT_FACE_FLAG_HINTER;\r
-#endif\r
-\r
- /* XXX: TODO -- add kerning with .afm support */\r
-\r
- /* get style name -- be careful, some broken fonts only */\r
- /* have a `/FontName' dictionary entry! */\r
- root->family_name = info->family_name;\r
- /* assume "Regular" style if we don't know better */\r
- root->style_name = (char *)"Regular";\r
- if ( root->family_name )\r
- {\r
- char* full = info->full_name;\r
- char* family = root->family_name;\r
-\r
-\r
- if ( full )\r
- {\r
- while ( *full )\r
- {\r
- if ( *full == *family )\r
- {\r
- family++;\r
- full++;\r
- }\r
- else\r
- {\r
- if ( *full == ' ' || *full == '-' )\r
- full++;\r
- else if ( *family == ' ' || *family == '-' )\r
- family++;\r
- else\r
- {\r
- if ( !*family )\r
- root->style_name = full;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- else\r
- {\r
- /* do we have a `/FontName'? */\r
- if ( type1->font_name )\r
- root->family_name = type1->font_name;\r
- }\r
-\r
- /* no embedded bitmap support */\r
- root->num_fixed_sizes = 0;\r
- root->available_sizes = 0;\r
-\r
- /* Load the TTF font embedded in the T42 font */\r
- {\r
- FT_Open_Args args;\r
-\r
-\r
- args.flags = FT_OPEN_MEMORY;\r
- args.memory_base = face->ttf_data;\r
- args.memory_size = face->ttf_size;\r
-\r
- if ( num_params )\r
- {\r
- args.flags |= FT_OPEN_PARAMS;\r
- args.num_params = num_params;\r
- args.params = params;\r
- }\r
-\r
- error = FT_Open_Face( FT_FACE_LIBRARY( face ),\r
- &args, 0, &face->ttf_face );\r
- }\r
-\r
- if ( error )\r
- goto Exit;\r
-\r
- FT_Done_Size( face->ttf_face->size );\r
-\r
- /* Ignore info in FontInfo dictionary and use the info from the */\r
- /* loaded TTF font. The PostScript interpreter also ignores it. */\r
- root->bbox = face->ttf_face->bbox;\r
- root->units_per_EM = face->ttf_face->units_per_EM;\r
-\r
- root->ascender = face->ttf_face->ascender;\r
- root->descender = face->ttf_face->descender;\r
- root->height = face->ttf_face->height;\r
-\r
- root->max_advance_width = face->ttf_face->max_advance_width;\r
- root->max_advance_height = face->ttf_face->max_advance_height;\r
-\r
- root->underline_position = (FT_Short)info->underline_position;\r
- root->underline_thickness = (FT_Short)info->underline_thickness;\r
-\r
- /* compute style flags */\r
- root->style_flags = 0;\r
- if ( info->italic_angle )\r
- root->style_flags |= FT_STYLE_FLAG_ITALIC;\r
-\r
- if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )\r
- root->style_flags |= FT_STYLE_FLAG_BOLD;\r
-\r
- if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )\r
- root->face_flags |= FT_FACE_FLAG_VERTICAL;\r
-\r
- {\r
- if ( psnames && psaux )\r
- {\r
- FT_CharMapRec charmap;\r
- T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes;\r
- FT_CMap_Class clazz;\r
-\r
-\r
- charmap.face = root;\r
-\r
- /* first of all, try to synthetize a Unicode charmap */\r
- charmap.platform_id = 3;\r
- charmap.encoding_id = 1;\r
- charmap.encoding = FT_ENCODING_UNICODE;\r
-\r
- FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );\r
-\r
- /* now, generate an Adobe Standard encoding when appropriate */\r
- charmap.platform_id = 7;\r
- clazz = NULL;\r
-\r
- switch ( type1->encoding_type )\r
- {\r
- case T1_ENCODING_TYPE_STANDARD:\r
- charmap.encoding = FT_ENCODING_ADOBE_STANDARD;\r
- charmap.encoding_id = 0;\r
- clazz = cmap_classes->standard;\r
- break;\r
-\r
- case T1_ENCODING_TYPE_EXPERT:\r
- charmap.encoding = FT_ENCODING_ADOBE_EXPERT;\r
- charmap.encoding_id = 1;\r
- clazz = cmap_classes->expert;\r
- break;\r
-\r
- case T1_ENCODING_TYPE_ARRAY:\r
- charmap.encoding = FT_ENCODING_ADOBE_CUSTOM;\r
- charmap.encoding_id = 2;\r
- clazz = cmap_classes->custom;\r
- break;\r
-\r
- case T1_ENCODING_TYPE_ISOLATIN1:\r
- charmap.encoding = FT_ENCODING_ADOBE_LATIN_1;\r
- charmap.encoding_id = 3;\r
- clazz = cmap_classes->unicode;\r
- break;\r
-\r
- default:\r
- ;\r
- }\r
-\r
- if ( clazz )\r
- FT_CMap_New( clazz, NULL, &charmap, NULL );\r
-\r
-#if 0\r
- /* Select default charmap */\r
- if ( root->num_charmaps )\r
- root->charmap = root->charmaps[0];\r
-#endif\r
- }\r
- }\r
- Exit:\r
- return error;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( void )\r
- T42_Face_Done( T42_Face face )\r
- {\r
- T1_Font type1;\r
- PS_FontInfo info;\r
- FT_Memory memory;\r
-\r
-\r
- if ( face )\r
- {\r
- type1 = &face->type1;\r
- info = &type1->font_info;\r
- memory = face->root.memory;\r
-\r
- /* delete internal ttf face prior to freeing face->ttf_data */\r
- if ( face->ttf_face )\r
- FT_Done_Face( face->ttf_face );\r
-\r
- /* release font info strings */\r
- FT_FREE( info->version );\r
- FT_FREE( info->notice );\r
- FT_FREE( info->full_name );\r
- FT_FREE( info->family_name );\r
- FT_FREE( info->weight );\r
-\r
- /* release top dictionary */\r
- FT_FREE( type1->charstrings_len );\r
- FT_FREE( type1->charstrings );\r
- FT_FREE( type1->glyph_names );\r
-\r
- FT_FREE( type1->charstrings_block );\r
- FT_FREE( type1->glyph_names_block );\r
-\r
- FT_FREE( type1->encoding.char_index );\r
- FT_FREE( type1->encoding.char_name );\r
- FT_FREE( type1->font_name );\r
-\r
- FT_FREE( face->ttf_data );\r
-\r
-#if 0\r
- /* release afm data if present */\r
- if ( face->afm_data )\r
- T1_Done_AFM( memory, (T1_AFM*)face->afm_data );\r
-#endif\r
-\r
- /* release unicode map, if any */\r
- FT_FREE( face->unicode_map.maps );\r
- face->unicode_map.num_maps = 0;\r
-\r
- face->root.family_name = 0;\r
- face->root.style_name = 0;\r
- }\r
- }\r
-\r
-\r
- /*************************************************************************/\r
- /* */\r
- /* <Function> */\r
- /* T42_Driver_Init */\r
- /* */\r
- /* <Description> */\r
- /* Initializes a given Type 42 driver object. */\r
- /* */\r
- /* <Input> */\r
- /* driver :: A handle to the target driver object. */\r
- /* */\r
- /* <Return> */\r
- /* FreeType error code. 0 means success. */\r
- /* */\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_Driver_Init( T42_Driver driver )\r
- {\r
- FT_Module ttmodule;\r
-\r
-\r
- ttmodule = FT_Get_Module( FT_MODULE(driver)->library, "truetype" );\r
- driver->ttclazz = (FT_Driver_Class)ttmodule->clazz;\r
-\r
- return T42_Err_Ok;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( void )\r
- T42_Driver_Done( T42_Driver driver )\r
- {\r
- FT_UNUSED( driver );\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_Size_Init( T42_Size size )\r
- {\r
- FT_Face face = size->root.face;\r
- T42_Face t42face = (T42_Face)face;\r
- FT_Size ttsize;\r
- FT_Error error = T42_Err_Ok;\r
-\r
-\r
- error = FT_New_Size( t42face->ttf_face, &ttsize );\r
- size->ttsize = ttsize;\r
-\r
- FT_Activate_Size( ttsize );\r
-\r
- return error;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_Size_Request( T42_Size size,\r
- FT_Size_Request req )\r
- {\r
- T42_Face face = (T42_Face)size->root.face;\r
- FT_Error error;\r
-\r
-\r
- FT_Activate_Size( size->ttsize );\r
-\r
- error = FT_Request_Size( face->ttf_face, req );\r
- if ( !error )\r
- ( (FT_Size)size )->metrics = face->ttf_face->size->metrics;\r
-\r
- return error;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_Size_Select( T42_Size size,\r
- FT_ULong strike_index )\r
- {\r
- T42_Face face = (T42_Face)size->root.face;\r
- FT_Error error;\r
-\r
-\r
- FT_Activate_Size( size->ttsize );\r
-\r
- error = FT_Select_Size( face->ttf_face, strike_index );\r
- if ( !error )\r
- ( (FT_Size)size )->metrics = face->ttf_face->size->metrics;\r
-\r
- return error;\r
-\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( void )\r
- T42_Size_Done( T42_Size size )\r
- {\r
- FT_Face face = size->root.face;\r
- T42_Face t42face = (T42_Face)face;\r
- FT_ListNode node;\r
-\r
-\r
- node = FT_List_Find( &t42face->ttf_face->sizes_list, size->ttsize );\r
- if ( node )\r
- {\r
- FT_Done_Size( size->ttsize );\r
- size->ttsize = NULL;\r
- }\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_GlyphSlot_Init( T42_GlyphSlot slot )\r
- {\r
- FT_Face face = slot->root.face;\r
- T42_Face t42face = (T42_Face)face;\r
- FT_GlyphSlot ttslot;\r
- FT_Error error = T42_Err_Ok;\r
-\r
-\r
- if ( face->glyph == NULL )\r
- {\r
- /* First glyph slot for this face */\r
- slot->ttslot = t42face->ttf_face->glyph;\r
- }\r
- else\r
- {\r
- error = FT_New_GlyphSlot( t42face->ttf_face, &ttslot );\r
- slot->ttslot = ttslot;\r
- }\r
-\r
- return error;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( void )\r
- T42_GlyphSlot_Done( T42_GlyphSlot slot )\r
- {\r
- FT_Done_GlyphSlot( slot->ttslot );\r
- }\r
-\r
-\r
- static void\r
- t42_glyphslot_clear( FT_GlyphSlot slot )\r
- {\r
- /* free bitmap if needed */\r
- ft_glyphslot_free_bitmap( slot );\r
-\r
- /* clear all public fields in the glyph slot */\r
- FT_ZERO( &slot->metrics );\r
- FT_ZERO( &slot->outline );\r
- FT_ZERO( &slot->bitmap );\r
-\r
- slot->bitmap_left = 0;\r
- slot->bitmap_top = 0;\r
- slot->num_subglyphs = 0;\r
- slot->subglyphs = 0;\r
- slot->control_data = 0;\r
- slot->control_len = 0;\r
- slot->other = 0;\r
- slot->format = FT_GLYPH_FORMAT_NONE;\r
-\r
- slot->linearHoriAdvance = 0;\r
- slot->linearVertAdvance = 0;\r
- }\r
-\r
-\r
- FT_LOCAL_DEF( FT_Error )\r
- T42_GlyphSlot_Load( FT_GlyphSlot glyph,\r
- FT_Size size,\r
- FT_UInt glyph_index,\r
- FT_Int32 load_flags )\r
- {\r
- FT_Error error;\r
- T42_GlyphSlot t42slot = (T42_GlyphSlot)glyph;\r
- T42_Size t42size = (T42_Size)size;\r
- FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz;\r
-\r
-\r
- t42_glyphslot_clear( t42slot->ttslot );\r
- error = ttclazz->load_glyph( t42slot->ttslot,\r
- t42size->ttsize,\r
- glyph_index,\r
- load_flags | FT_LOAD_NO_BITMAP );\r
-\r
- if ( !error )\r
- {\r
- glyph->metrics = t42slot->ttslot->metrics;\r
-\r
- glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance;\r
- glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance;\r
-\r
- glyph->format = t42slot->ttslot->format;\r
- glyph->outline = t42slot->ttslot->outline;\r
-\r
- glyph->bitmap = t42slot->ttslot->bitmap;\r
- glyph->bitmap_left = t42slot->ttslot->bitmap_left;\r
- glyph->bitmap_top = t42slot->ttslot->bitmap_top;\r
-\r
- glyph->num_subglyphs = t42slot->ttslot->num_subglyphs;\r
- glyph->subglyphs = t42slot->ttslot->subglyphs;\r
-\r
- glyph->control_data = t42slot->ttslot->control_data;\r
- glyph->control_len = t42slot->ttslot->control_len;\r
- }\r
-\r
- return error;\r
- }\r
-\r
-\r
-/* END */\r
+/***************************************************************************/
+/* */
+/* t42objs.c */
+/* */
+/* Type 42 objects manager (body). */
+/* */
+/* Copyright 2002, 2003, 2004, 2005, 2006, 2007 by Roberto Alameda. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#include "t42objs.h"
+#include "t42parse.h"
+#include "t42error.h"
+#include FT_INTERNAL_DEBUG_H
+#include FT_INTERNAL_STREAM_H
+#include FT_LIST_H
+
+
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_t42
+
+
+ static FT_Error
+ T42_Open_Face( T42_Face face )
+ {
+ T42_LoaderRec loader;
+ T42_Parser parser;
+ T1_Font type1 = &face->type1;
+ FT_Memory memory = face->root.memory;
+ FT_Error error;
+
+ PSAux_Service psaux = (PSAux_Service)face->psaux;
+
+
+ t42_loader_init( &loader, face );
+
+ parser = &loader.parser;
+
+ if ( FT_ALLOC( face->ttf_data, 12 ) )
+ goto Exit;
+
+ error = t42_parser_init( parser,
+ face->root.stream,
+ memory,
+ psaux);
+ if ( error )
+ goto Exit;
+
+ error = t42_parse_dict( face, &loader,
+ parser->base_dict, parser->base_len );
+ if ( error )
+ goto Exit;
+
+ if ( type1->font_type != 42 )
+ {
+ error = T42_Err_Unknown_File_Format;
+ goto Exit;
+ }
+
+ /* now, propagate the charstrings and glyphnames tables */
+ /* to the Type1 data */
+ type1->num_glyphs = loader.num_glyphs;
+
+ if ( !loader.charstrings.init )
+ {
+ FT_ERROR(( "T42_Open_Face: no charstrings array in face!\n" ));
+ error = T42_Err_Invalid_File_Format;
+ }
+
+ loader.charstrings.init = 0;
+ type1->charstrings_block = loader.charstrings.block;
+ type1->charstrings = loader.charstrings.elements;
+ type1->charstrings_len = loader.charstrings.lengths;
+
+ /* we copy the glyph names `block' and `elements' fields; */
+ /* the `lengths' field must be released later */
+ type1->glyph_names_block = loader.glyph_names.block;
+ type1->glyph_names = (FT_String**)loader.glyph_names.elements;
+ loader.glyph_names.block = 0;
+ loader.glyph_names.elements = 0;
+
+ /* we must now build type1.encoding when we have a custom array */
+ if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
+ {
+ FT_Int charcode, idx, min_char, max_char;
+ FT_Byte* char_name;
+ FT_Byte* glyph_name;
+
+
+ /* OK, we do the following: for each element in the encoding */
+ /* table, look up the index of the glyph having the same name */
+ /* as defined in the CharStrings array. */
+ /* The index is then stored in type1.encoding.char_index, and */
+ /* the name in type1.encoding.char_name */
+
+ min_char = +32000;
+ max_char = -32000;
+
+ charcode = 0;
+ for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
+ {
+ type1->encoding.char_index[charcode] = 0;
+ type1->encoding.char_name [charcode] = (char *)".notdef";
+
+ char_name = loader.encoding_table.elements[charcode];
+ if ( char_name )
+ for ( idx = 0; idx < type1->num_glyphs; idx++ )
+ {
+ glyph_name = (FT_Byte*)type1->glyph_names[idx];
+ if ( ft_strcmp( (const char*)char_name,
+ (const char*)glyph_name ) == 0 )
+ {
+ type1->encoding.char_index[charcode] = (FT_UShort)idx;
+ type1->encoding.char_name [charcode] = (char*)glyph_name;
+
+ /* Change min/max encoded char only if glyph name is */
+ /* not /.notdef */
+ if ( ft_strcmp( (const char*)".notdef",
+ (const char*)glyph_name ) != 0 )
+ {
+ if ( charcode < min_char )
+ min_char = charcode;
+ if ( charcode > max_char )
+ max_char = charcode;
+ }
+ break;
+ }
+ }
+ }
+ type1->encoding.code_first = min_char;
+ type1->encoding.code_last = max_char;
+ type1->encoding.num_chars = loader.num_chars;
+ }
+
+ Exit:
+ t42_loader_done( &loader );
+ return error;
+ }
+
+
+ /***************** Driver Functions *************/
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_Face_Init( FT_Stream stream,
+ T42_Face face,
+ FT_Int face_index,
+ FT_Int num_params,
+ FT_Parameter* params )
+ {
+ FT_Error error;
+ FT_Service_PsCMaps psnames;
+ PSAux_Service psaux;
+ FT_Face root = (FT_Face)&face->root;
+ T1_Font type1 = &face->type1;
+ PS_FontInfo info = &type1->font_info;
+
+ FT_UNUSED( num_params );
+ FT_UNUSED( params );
+ FT_UNUSED( face_index );
+ FT_UNUSED( stream );
+
+
+ face->ttf_face = NULL;
+ face->root.num_faces = 1;
+
+ FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
+ face->psnames = psnames;
+
+ face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
+ "psaux" );
+ psaux = (PSAux_Service)face->psaux;
+
+ /* open the tokenizer, this will also check the font format */
+ error = T42_Open_Face( face );
+ if ( error )
+ goto Exit;
+
+ /* if we just wanted to check the format, leave successfully now */
+ if ( face_index < 0 )
+ goto Exit;
+
+ /* check the face index */
+ if ( face_index != 0 )
+ {
+ FT_ERROR(( "T42_Face_Init: invalid face index\n" ));
+ error = T42_Err_Invalid_Argument;
+ goto Exit;
+ }
+
+ /* Now load the font program into the face object */
+
+ /* Init the face object fields */
+ /* Now set up root face fields */
+
+ root->num_glyphs = type1->num_glyphs;
+ root->num_charmaps = 0;
+ root->face_index = face_index;
+
+ root->face_flags = FT_FACE_FLAG_SCALABLE |
+ FT_FACE_FLAG_HORIZONTAL |
+ FT_FACE_FLAG_GLYPH_NAMES;
+
+ if ( info->is_fixed_pitch )
+ root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+
+ /* We only set this flag if we have the patented bytecode interpreter. */
+ /* There are no known `tricky' Type42 fonts that could be loaded with */
+ /* the unpatented interpreter. */
+#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+ root->face_flags |= FT_FACE_FLAG_HINTER;
+#endif
+
+ /* XXX: TODO -- add kerning with .afm support */
+
+ /* 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";
+ if ( root->family_name )
+ {
+ char* full = info->full_name;
+ char* family = root->family_name;
+
+
+ if ( full )
+ {
+ while ( *full )
+ {
+ if ( *full == *family )
+ {
+ family++;
+ full++;
+ }
+ else
+ {
+ if ( *full == ' ' || *full == '-' )
+ full++;
+ else if ( *family == ' ' || *family == '-' )
+ family++;
+ else
+ {
+ if ( !*family )
+ root->style_name = full;
+ break;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ /* do we have a `/FontName'? */
+ if ( type1->font_name )
+ root->family_name = type1->font_name;
+ }
+
+ /* no embedded bitmap support */
+ root->num_fixed_sizes = 0;
+ root->available_sizes = 0;
+
+ /* Load the TTF font embedded in the T42 font */
+ {
+ FT_Open_Args args;
+
+
+ args.flags = FT_OPEN_MEMORY;
+ args.memory_base = face->ttf_data;
+ args.memory_size = face->ttf_size;
+
+ if ( num_params )
+ {
+ args.flags |= FT_OPEN_PARAMS;
+ args.num_params = num_params;
+ args.params = params;
+ }
+
+ error = FT_Open_Face( FT_FACE_LIBRARY( face ),
+ &args, 0, &face->ttf_face );
+ }
+
+ if ( error )
+ goto Exit;
+
+ FT_Done_Size( face->ttf_face->size );
+
+ /* Ignore info in FontInfo dictionary and use the info from the */
+ /* loaded TTF font. The PostScript interpreter also ignores it. */
+ root->bbox = face->ttf_face->bbox;
+ root->units_per_EM = face->ttf_face->units_per_EM;
+
+ root->ascender = face->ttf_face->ascender;
+ root->descender = face->ttf_face->descender;
+ root->height = face->ttf_face->height;
+
+ root->max_advance_width = face->ttf_face->max_advance_width;
+ root->max_advance_height = face->ttf_face->max_advance_height;
+
+ root->underline_position = (FT_Short)info->underline_position;
+ root->underline_thickness = (FT_Short)info->underline_thickness;
+
+ /* compute style flags */
+ root->style_flags = 0;
+ if ( info->italic_angle )
+ root->style_flags |= FT_STYLE_FLAG_ITALIC;
+
+ if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
+ root->style_flags |= FT_STYLE_FLAG_BOLD;
+
+ if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
+ root->face_flags |= FT_FACE_FLAG_VERTICAL;
+
+ {
+ if ( psnames && psaux )
+ {
+ FT_CharMapRec charmap;
+ T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes;
+ FT_CMap_Class clazz;
+
+
+ charmap.face = root;
+
+ /* first of all, try to synthetize a Unicode charmap */
+ charmap.platform_id = 3;
+ charmap.encoding_id = 1;
+ charmap.encoding = FT_ENCODING_UNICODE;
+
+ FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
+
+ /* now, generate an Adobe Standard encoding when appropriate */
+ charmap.platform_id = 7;
+ clazz = NULL;
+
+ switch ( type1->encoding_type )
+ {
+ case T1_ENCODING_TYPE_STANDARD:
+ charmap.encoding = FT_ENCODING_ADOBE_STANDARD;
+ charmap.encoding_id = 0;
+ clazz = cmap_classes->standard;
+ break;
+
+ case T1_ENCODING_TYPE_EXPERT:
+ charmap.encoding = FT_ENCODING_ADOBE_EXPERT;
+ charmap.encoding_id = 1;
+ clazz = cmap_classes->expert;
+ break;
+
+ case T1_ENCODING_TYPE_ARRAY:
+ charmap.encoding = FT_ENCODING_ADOBE_CUSTOM;
+ charmap.encoding_id = 2;
+ clazz = cmap_classes->custom;
+ break;
+
+ case T1_ENCODING_TYPE_ISOLATIN1:
+ charmap.encoding = FT_ENCODING_ADOBE_LATIN_1;
+ charmap.encoding_id = 3;
+ clazz = cmap_classes->unicode;
+ break;
+
+ default:
+ ;
+ }
+
+ if ( clazz )
+ FT_CMap_New( clazz, NULL, &charmap, NULL );
+
+#if 0
+ /* Select default charmap */
+ if ( root->num_charmaps )
+ root->charmap = root->charmaps[0];
+#endif
+ }
+ }
+ Exit:
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( void )
+ T42_Face_Done( T42_Face face )
+ {
+ T1_Font type1;
+ PS_FontInfo info;
+ FT_Memory memory;
+
+
+ if ( face )
+ {
+ type1 = &face->type1;
+ info = &type1->font_info;
+ memory = face->root.memory;
+
+ /* delete internal ttf face prior to freeing face->ttf_data */
+ if ( face->ttf_face )
+ FT_Done_Face( face->ttf_face );
+
+ /* release font info strings */
+ 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 );
+
+ 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( face->ttf_data );
+
+#if 0
+ /* release afm data if present */
+ if ( face->afm_data )
+ T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
+#endif
+
+ /* release unicode map, if any */
+ FT_FREE( face->unicode_map.maps );
+ face->unicode_map.num_maps = 0;
+
+ face->root.family_name = 0;
+ face->root.style_name = 0;
+ }
+ }
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* T42_Driver_Init */
+ /* */
+ /* <Description> */
+ /* Initializes a given Type 42 driver object. */
+ /* */
+ /* <Input> */
+ /* driver :: A handle to the target driver object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_LOCAL_DEF( FT_Error )
+ T42_Driver_Init( T42_Driver driver )
+ {
+ FT_Module ttmodule;
+
+
+ ttmodule = FT_Get_Module( FT_MODULE(driver)->library, "truetype" );
+ driver->ttclazz = (FT_Driver_Class)ttmodule->clazz;
+
+ return T42_Err_Ok;
+ }
+
+
+ FT_LOCAL_DEF( void )
+ T42_Driver_Done( T42_Driver driver )
+ {
+ FT_UNUSED( driver );
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_Size_Init( T42_Size size )
+ {
+ FT_Face face = size->root.face;
+ T42_Face t42face = (T42_Face)face;
+ FT_Size ttsize;
+ FT_Error error = T42_Err_Ok;
+
+
+ error = FT_New_Size( t42face->ttf_face, &ttsize );
+ size->ttsize = ttsize;
+
+ FT_Activate_Size( ttsize );
+
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_Size_Request( T42_Size size,
+ FT_Size_Request req )
+ {
+ T42_Face face = (T42_Face)size->root.face;
+ FT_Error error;
+
+
+ FT_Activate_Size( size->ttsize );
+
+ error = FT_Request_Size( face->ttf_face, req );
+ if ( !error )
+ ( (FT_Size)size )->metrics = face->ttf_face->size->metrics;
+
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_Size_Select( T42_Size size,
+ FT_ULong strike_index )
+ {
+ T42_Face face = (T42_Face)size->root.face;
+ FT_Error error;
+
+
+ FT_Activate_Size( size->ttsize );
+
+ error = FT_Select_Size( face->ttf_face, strike_index );
+ if ( !error )
+ ( (FT_Size)size )->metrics = face->ttf_face->size->metrics;
+
+ return error;
+
+ }
+
+
+ FT_LOCAL_DEF( void )
+ T42_Size_Done( T42_Size size )
+ {
+ FT_Face face = size->root.face;
+ T42_Face t42face = (T42_Face)face;
+ FT_ListNode node;
+
+
+ node = FT_List_Find( &t42face->ttf_face->sizes_list, size->ttsize );
+ if ( node )
+ {
+ FT_Done_Size( size->ttsize );
+ size->ttsize = NULL;
+ }
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_GlyphSlot_Init( T42_GlyphSlot slot )
+ {
+ FT_Face face = slot->root.face;
+ T42_Face t42face = (T42_Face)face;
+ FT_GlyphSlot ttslot;
+ FT_Error error = T42_Err_Ok;
+
+
+ if ( face->glyph == NULL )
+ {
+ /* First glyph slot for this face */
+ slot->ttslot = t42face->ttf_face->glyph;
+ }
+ else
+ {
+ error = FT_New_GlyphSlot( t42face->ttf_face, &ttslot );
+ slot->ttslot = ttslot;
+ }
+
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( void )
+ T42_GlyphSlot_Done( T42_GlyphSlot slot )
+ {
+ FT_Done_GlyphSlot( slot->ttslot );
+ }
+
+
+ static void
+ t42_glyphslot_clear( FT_GlyphSlot slot )
+ {
+ /* free bitmap if needed */
+ ft_glyphslot_free_bitmap( slot );
+
+ /* clear all public fields in the glyph slot */
+ FT_ZERO( &slot->metrics );
+ FT_ZERO( &slot->outline );
+ FT_ZERO( &slot->bitmap );
+
+ slot->bitmap_left = 0;
+ slot->bitmap_top = 0;
+ slot->num_subglyphs = 0;
+ slot->subglyphs = 0;
+ slot->control_data = 0;
+ slot->control_len = 0;
+ slot->other = 0;
+ slot->format = FT_GLYPH_FORMAT_NONE;
+
+ slot->linearHoriAdvance = 0;
+ slot->linearVertAdvance = 0;
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ T42_GlyphSlot_Load( FT_GlyphSlot glyph,
+ FT_Size size,
+ FT_UInt glyph_index,
+ FT_Int32 load_flags )
+ {
+ FT_Error error;
+ T42_GlyphSlot t42slot = (T42_GlyphSlot)glyph;
+ T42_Size t42size = (T42_Size)size;
+ FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz;
+
+
+ t42_glyphslot_clear( t42slot->ttslot );
+ error = ttclazz->load_glyph( t42slot->ttslot,
+ t42size->ttsize,
+ glyph_index,
+ load_flags | FT_LOAD_NO_BITMAP );
+
+ if ( !error )
+ {
+ glyph->metrics = t42slot->ttslot->metrics;
+
+ glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance;
+ glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance;
+
+ glyph->format = t42slot->ttslot->format;
+ glyph->outline = t42slot->ttslot->outline;
+
+ glyph->bitmap = t42slot->ttslot->bitmap;
+ glyph->bitmap_left = t42slot->ttslot->bitmap_left;
+ glyph->bitmap_top = t42slot->ttslot->bitmap_top;
+
+ glyph->num_subglyphs = t42slot->ttslot->num_subglyphs;
+ glyph->subglyphs = t42slot->ttslot->subglyphs;
+
+ glyph->control_data = t42slot->ttslot->control_data;
+ glyph->control_len = t42slot->ttslot->control_len;
+ }
+
+ return error;
+ }
+
+
+/* END */