28#define FT_COMPONENT t42
32 T42_Open_Face( T42_Face face )
36 T1_Font type1 = &face->type1;
37 FT_Memory memory = face->root.memory;
40 PSAux_Service psaux = (PSAux_Service)face->psaux;
43 t42_loader_init( &loader, face );
45 parser = &loader.parser;
47 face->ttf_data = NULL;
50 error = t42_parser_init( parser,
57 error = t42_parse_dict( face, &loader,
58 parser->base_dict, parser->base_len );
62 if ( type1->font_type != 42 )
64 FT_ERROR((
"T42_Open_Face: cannot handle FontType %d\n",
66 error = FT_THROW( Unknown_File_Format );
72 type1->num_glyphs = loader.num_glyphs;
74 if ( !loader.charstrings.init )
76 FT_ERROR((
"T42_Open_Face: no charstrings array in face\n" ));
77 error = FT_THROW( Invalid_File_Format );
80 loader.charstrings.init = 0;
81 type1->charstrings_block = loader.charstrings.block;
82 type1->charstrings = loader.charstrings.elements;
83 type1->charstrings_len = loader.charstrings.lengths;
87 type1->glyph_names_block = loader.glyph_names.block;
88 type1->glyph_names = (FT_String**)loader.glyph_names.elements;
89 loader.glyph_names.block = NULL;
90 loader.glyph_names.elements = NULL;
93 if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
95 FT_Int charcode, idx, min_char, max_char;
108 for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
110 const FT_String* char_name =
111 (
const FT_String*)loader.encoding_table.elements[charcode];
114 type1->encoding.char_index[charcode] = 0;
115 type1->encoding.char_name [charcode] =
".notdef";
118 for ( idx = 0; idx < type1->num_glyphs; idx++ )
120 const FT_String* glyph_name = type1->glyph_names[idx];
123 if ( ft_strcmp( char_name, glyph_name ) == 0 )
125 type1->encoding.char_index[charcode] = (FT_UShort)idx;
126 type1->encoding.char_name [charcode] = glyph_name;
130 if ( ft_strcmp(
".notdef", glyph_name ) != 0 )
132 if ( charcode < min_char )
134 if ( charcode >= max_char )
135 max_char = charcode + 1;
142 type1->encoding.code_first = min_char;
143 type1->encoding.code_last = max_char;
144 type1->encoding.num_chars = loader.num_chars;
148 t42_loader_done( &loader );
151 FT_FREE( face->ttf_data );
161 FT_LOCAL_DEF( FT_Error )
162 T42_Face_Init( FT_Stream stream,
166 FT_Parameter* params )
168 T42_Face face = (T42_Face)t42face;
170 FT_Service_PsCMaps psnames;
172 FT_Face root = (FT_Face)&face->root;
173 T1_Font type1 = &face->type1;
174 PS_FontInfo info = &type1->font_info;
176 FT_UNUSED( num_params );
181 face->ttf_face = NULL;
182 face->root.num_faces = 1;
184 FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
185 face->psnames = psnames;
187 face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
189 psaux = (PSAux_Service)face->psaux;
192 FT_ERROR((
"T42_Face_Init: cannot access `psaux' module\n" ));
193 error = FT_THROW( Missing_Module );
197 FT_TRACE2((
"Type 42 driver\n" ));
200 error = T42_Open_Face( face );
205 if ( face_index < 0 )
209 if ( ( face_index & 0xFFFF ) > 0 )
211 FT_ERROR((
"T42_Face_Init: invalid face index\n" ));
212 error = FT_THROW( Invalid_Argument );
221 root->num_glyphs = type1->num_glyphs;
222 root->num_charmaps = 0;
223 root->face_index = 0;
225 root->face_flags |= FT_FACE_FLAG_SCALABLE |
226 FT_FACE_FLAG_HORIZONTAL |
227 FT_FACE_FLAG_GLYPH_NAMES;
229 if ( info->is_fixed_pitch )
230 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
232#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
233 root->face_flags |= FT_FACE_FLAG_HINTER;
240 root->family_name = info->family_name;
242 root->style_name = (
char *)
"Regular";
243 if ( root->family_name )
245 char* full = info->full_name;
246 char* family = root->family_name;
253 if ( *full == *family )
260 if ( *full ==
' ' || *full ==
'-' )
262 else if ( *family ==
' ' || *family ==
'-' )
267 root->style_name = full;
277 if ( type1->font_name )
278 root->family_name = type1->font_name;
282 root->num_fixed_sizes = 0;
283 root->available_sizes = NULL;
290 args.flags = FT_OPEN_MEMORY | FT_OPEN_DRIVER;
291 args.driver = FT_Get_Module( FT_FACE_LIBRARY( face ),
293 args.memory_base = face->ttf_data;
294 args.memory_size = face->ttf_size;
298 args.flags |= FT_OPEN_PARAMS;
299 args.num_params = num_params;
300 args.params = params;
303 error = FT_Open_Face( FT_FACE_LIBRARY( face ),
304 &args, 0, &face->ttf_face );
310 FT_Done_Size( face->ttf_face->size );
314 root->bbox = face->ttf_face->bbox;
315 root->units_per_EM = face->ttf_face->units_per_EM;
317 root->ascender = face->ttf_face->ascender;
318 root->descender = face->ttf_face->descender;
319 root->height = face->ttf_face->height;
321 root->max_advance_width = face->ttf_face->max_advance_width;
322 root->max_advance_height = face->ttf_face->max_advance_height;
324 root->underline_position = (FT_Short)info->underline_position;
325 root->underline_thickness = (FT_Short)info->underline_thickness;
328 root->style_flags = 0;
329 if ( info->italic_angle )
330 root->style_flags |= FT_STYLE_FLAG_ITALIC;
332 if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
333 root->style_flags |= FT_STYLE_FLAG_BOLD;
335 if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
336 root->face_flags |= FT_FACE_FLAG_VERTICAL;
341 FT_CharMapRec charmap;
342 T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes;
349 charmap.platform_id = TT_PLATFORM_MICROSOFT;
350 charmap.encoding_id = TT_MS_ID_UNICODE_CS;
351 charmap.encoding = FT_ENCODING_UNICODE;
353 error = FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
355 FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) &&
356 FT_ERR_NEQ( error, Unimplemented_Feature ) )
361 charmap.platform_id = TT_PLATFORM_ADOBE;
364 switch ( type1->encoding_type )
366 case T1_ENCODING_TYPE_STANDARD:
367 charmap.encoding = FT_ENCODING_ADOBE_STANDARD;
368 charmap.encoding_id = TT_ADOBE_ID_STANDARD;
369 clazz = cmap_classes->standard;
372 case T1_ENCODING_TYPE_EXPERT:
373 charmap.encoding = FT_ENCODING_ADOBE_EXPERT;
374 charmap.encoding_id = TT_ADOBE_ID_EXPERT;
375 clazz = cmap_classes->expert;
378 case T1_ENCODING_TYPE_ARRAY:
379 charmap.encoding = FT_ENCODING_ADOBE_CUSTOM;
380 charmap.encoding_id = TT_ADOBE_ID_CUSTOM;
381 clazz = cmap_classes->custom;
384 case T1_ENCODING_TYPE_ISOLATIN1:
385 charmap.encoding = FT_ENCODING_ADOBE_LATIN_1;
386 charmap.encoding_id = TT_ADOBE_ID_LATIN_1;
387 clazz = cmap_classes->unicode;
395 error = FT_CMap_New( clazz, NULL, &charmap, NULL );
404 T42_Face_Done( FT_Face t42face )
406 T42_Face face = (T42_Face)t42face;
415 type1 = &face->type1;
416 info = &type1->font_info;
417 memory = face->root.memory;
420 if ( face->ttf_face )
421 FT_Done_Face( face->ttf_face );
424 FT_FREE( info->version );
425 FT_FREE( info->notice );
426 FT_FREE( info->full_name );
427 FT_FREE( info->family_name );
428 FT_FREE( info->weight );
431 FT_FREE( type1->charstrings_len );
432 FT_FREE( type1->charstrings );
433 FT_FREE( type1->glyph_names );
435 FT_FREE( type1->charstrings_block );
436 FT_FREE( type1->glyph_names_block );
438 FT_FREE( type1->encoding.char_index );
439 FT_FREE( type1->encoding.char_name );
440 FT_FREE( type1->font_name );
442 FT_FREE( face->ttf_data );
446 if ( face->afm_data )
447 T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
451 FT_FREE( face->unicode_map.maps );
452 face->unicode_map.num_maps = 0;
454 face->root.family_name = NULL;
455 face->root.style_name = NULL;
474 FT_LOCAL_DEF( FT_Error )
475 T42_Driver_Init( FT_Module module )
477 T42_Driver driver = (T42_Driver)module;
481 ttmodule = FT_Get_Module( module->library,
"truetype" );
484 FT_ERROR((
"T42_Driver_Init: cannot access `truetype' module\n" ));
485 return FT_THROW( Missing_Module );
488 driver->ttclazz = (FT_Driver_Class)ttmodule->clazz;
495 T42_Driver_Done( FT_Module module )
501 FT_LOCAL_DEF( FT_Error )
502 T42_Size_Init( FT_Size size )
504 T42_Size t42size = (T42_Size)size;
505 FT_Face face = size->face;
506 T42_Face t42face = (T42_Face)face;
511 error = FT_New_Size( t42face->ttf_face, &ttsize );
514 t42size->ttsize = ttsize;
515 FT_Activate_Size( ttsize );
522 FT_LOCAL_DEF( FT_Error )
523 T42_Size_Request( FT_Size t42size,
524 FT_Size_Request req )
526 T42_Size size = (T42_Size)t42size;
527 T42_Face face = (T42_Face)t42size->face;
531 FT_Activate_Size( size->ttsize );
533 error = FT_Request_Size( face->ttf_face, req );
535 t42size->metrics = face->ttf_face->size->metrics;
541 FT_LOCAL_DEF( FT_Error )
542 T42_Size_Select( FT_Size t42size,
543 FT_ULong strike_index )
545 T42_Size size = (T42_Size)t42size;
546 T42_Face face = (T42_Face)t42size->face;
550 FT_Activate_Size( size->ttsize );
552 error = FT_Select_Size( face->ttf_face, (FT_Int)strike_index );
554 t42size->metrics = face->ttf_face->size->metrics;
562 T42_Size_Done( FT_Size t42size )
564 T42_Size size = (T42_Size)t42size;
565 FT_Face face = t42size->face;
566 T42_Face t42face = (T42_Face)face;
570 node = FT_List_Find( &t42face->ttf_face->sizes_list, size->ttsize );
573 FT_Done_Size( size->ttsize );
579 FT_LOCAL_DEF( FT_Error )
580 T42_GlyphSlot_Init( FT_GlyphSlot t42slot )
582 T42_GlyphSlot slot = (T42_GlyphSlot)t42slot;
583 FT_Face face = t42slot->face;
584 T42_Face t42face = (T42_Face)face;
586 FT_Memory memory = face->memory;
587 FT_Error error = FT_Err_Ok;
593 slot->ttslot = t42face->ttf_face->glyph;
597 error = FT_New_GlyphSlot( t42face->ttf_face, &ttslot );
599 slot->ttslot = ttslot;
603 FT_GlyphLoader_Done( slot->ttslot->internal->loader );
604 FT_FREE( slot->ttslot->internal );
605 slot->ttslot->internal = t42slot->internal;
612 T42_GlyphSlot_Done( FT_GlyphSlot t42slot )
614 T42_GlyphSlot slot = (T42_GlyphSlot)t42slot;
618 slot->ttslot->internal = NULL;
619 FT_Done_GlyphSlot( slot->ttslot );
624 t42_glyphslot_clear( FT_GlyphSlot slot )
627 ft_glyphslot_free_bitmap( slot );
630 FT_ZERO( &slot->metrics );
631 FT_ZERO( &slot->outline );
632 FT_ZERO( &slot->bitmap );
634 slot->bitmap_left = 0;
635 slot->bitmap_top = 0;
636 slot->num_subglyphs = 0;
637 slot->subglyphs = NULL;
638 slot->control_data = NULL;
639 slot->control_len = 0;
641 slot->format = FT_GLYPH_FORMAT_NONE;
643 slot->linearHoriAdvance = 0;
644 slot->linearVertAdvance = 0;
648 FT_LOCAL_DEF( FT_Error )
649 T42_GlyphSlot_Load( FT_GlyphSlot glyph,
652 FT_Int32 load_flags )
655 T42_GlyphSlot t42slot = (T42_GlyphSlot)glyph;
656 T42_Size t42size = (T42_Size)size;
657 T42_Face t42face = (T42_Face)size->face;
658 FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz;
661 FT_TRACE1((
"T42_GlyphSlot_Load: glyph index %u\n", glyph_index ));
664 glyph_index = (FT_UInt)ft_strtol(
665 (
const char *)t42face->type1.charstrings[glyph_index],
668 t42_glyphslot_clear( t42slot->ttslot );
669 error = ttclazz->load_glyph( t42slot->ttslot,
672 load_flags | FT_LOAD_NO_BITMAP );
676 glyph->metrics = t42slot->ttslot->metrics;
678 glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance;
679 glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance;
681 glyph->format = t42slot->ttslot->format;
682 glyph->outline = t42slot->ttslot->outline;
684 glyph->bitmap = t42slot->ttslot->bitmap;
685 glyph->bitmap_left = t42slot->ttslot->bitmap_left;
686 glyph->bitmap_top = t42slot->ttslot->bitmap_top;
688 glyph->num_subglyphs = t42slot->ttslot->num_subglyphs;
689 glyph->subglyphs = t42slot->ttslot->subglyphs;
691 glyph->control_data = t42slot->ttslot->control_data;
692 glyph->control_len = t42slot->ttslot->control_len;