pfr_face_init( FT_Stream stream, FT_Face pfrface, FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { PFR_Face face = (PFR_Face)pfrface; FT_Error error; FT_UNUSED( num_params ); FT_UNUSED( params ); /* load the header and check it */ error = pfr_header_load( &face->header, stream ); if ( error ) goto Exit; if ( !pfr_header_check( &face->header ) ) { FT_TRACE4(( "pfr_face_init: not a valid PFR font\n" )); error = PFR_Err_Unknown_File_Format; goto Exit; } /* check face index */ { FT_UInt num_faces; error = pfr_log_font_count( stream, face->header.log_dir_offset, &num_faces ); if ( error ) goto Exit; pfrface->num_faces = num_faces; } if ( face_index < 0 ) goto Exit; if ( face_index >= pfrface->num_faces ) { FT_ERROR(( "pfr_face_init: invalid face index\n" )); error = PFR_Err_Invalid_Argument; goto Exit; } /* load the face */ error = pfr_log_font_load( &face->log_font, stream, face_index, face->header.log_dir_offset, FT_BOOL( face->header.phy_font_max_size_high != 0 ) ); if ( error ) goto Exit; /* now load the physical font descriptor */ error = pfr_phy_font_load( &face->phy_font, stream, face->log_font.phys_offset, face->log_font.phys_size ); if ( error ) goto Exit; /* now, set-up all root face fields */ { PFR_PhyFont phy_font = &face->phy_font; pfrface->face_index = face_index; pfrface->num_glyphs = phy_font->num_chars; pfrface->face_flags = FT_FACE_FLAG_SCALABLE; if ( (phy_font->flags & PFR_PHY_PROPORTIONAL) == 0 ) pfrface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; if ( phy_font->flags & PFR_PHY_VERTICAL ) pfrface->face_flags |= FT_FACE_FLAG_VERTICAL; else pfrface->face_flags |= FT_FACE_FLAG_HORIZONTAL; if ( phy_font->num_strikes > 0 ) pfrface->face_flags |= FT_FACE_FLAG_FIXED_SIZES; if ( phy_font->num_kern_pairs > 0 ) pfrface->face_flags |= FT_FACE_FLAG_KERNING; /* If no family name was found in the "undocumented" auxiliary * data, use the font ID instead. This sucks but is better than * nothing. */ pfrface->family_name = phy_font->family_name; if ( pfrface->family_name == NULL ) pfrface->family_name = phy_font->font_id; /* note that the style name can be NULL in certain PFR fonts, * probably meaning "Regular" */ pfrface->style_name = phy_font->style_name; pfrface->num_fixed_sizes = 0; pfrface->available_sizes = 0; pfrface->bbox = phy_font->bbox; pfrface->units_per_EM = (FT_UShort)phy_font->outline_resolution; pfrface->ascender = (FT_Short) phy_font->bbox.yMax; pfrface->descender = (FT_Short) phy_font->bbox.yMin; pfrface->height = (FT_Short)( ( ( pfrface->ascender - pfrface->descender ) * 12 ) / 10 ); if ( phy_font->num_strikes > 0 ) { FT_UInt n, count = phy_font->num_strikes; FT_Bitmap_Size* size; PFR_Strike strike; FT_Memory memory = pfrface->stream->memory; if ( FT_NEW_ARRAY( pfrface->available_sizes, count ) ) goto Exit; size = pfrface->available_sizes; strike = phy_font->strikes; for ( n = 0; n < count; n++, size++, strike++ ) { size->height = (FT_UShort)strike->y_ppm; size->width = (FT_UShort)strike->x_ppm; } pfrface->num_fixed_sizes = count; } /* now compute maximum advance width */ if ( ( phy_font->flags & PFR_PHY_PROPORTIONAL ) == 0 ) pfrface->max_advance_width = (FT_Short)phy_font->standard_advance; else { FT_Int max = 0; FT_UInt count = phy_font->num_chars; PFR_Char gchar = phy_font->chars; for ( ; count > 0; count--, gchar++ ) { if ( max < gchar->advance ) max = gchar->advance; } pfrface->max_advance_width = (FT_Short)max; } pfrface->max_advance_height = pfrface->height; pfrface->underline_position = (FT_Short)( -pfrface->units_per_EM / 10 ); pfrface->underline_thickness = (FT_Short)( pfrface->units_per_EM / 30 ); /* create charmap */ { FT_CharMapRec charmap; charmap.face = pfrface; charmap.platform_id = 3; charmap.encoding_id = 1; charmap.encoding = FT_ENCODING_UNICODE; FT_CMap_New( &pfr_cmap_class_rec, NULL, &charmap, NULL ); #if 0 /* Select default charmap */ if ( pfrface->num_charmaps ) pfrface->charmap = pfrface->charmaps[0]; #endif } /* check whether we've loaded any kerning pairs */ if ( phy_font->num_kern_pairs ) pfrface->face_flags |= FT_FACE_FLAG_KERNING; } Exit: return error; }
pfr_face_init( FT_Stream stream, PFR_Face face, FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error; FT_UNUSED( num_params ); FT_UNUSED( params ); /* load the header and check it */ error = pfr_header_load( &face->header, stream ); if ( error ) goto Exit; if ( !pfr_header_check( &face->header ) ) { FT_TRACE4(( "pfr_face_init: not a valid PFR font\n" )); error = PFR_Err_Unknown_File_Format; goto Exit; } /* check face index */ { FT_UInt num_faces; error = pfr_log_font_count( stream, face->header.log_dir_offset, &num_faces ); if ( error ) goto Exit; face->root.num_faces = num_faces; } if ( face_index < 0 ) goto Exit; if ( face_index >= face->root.num_faces ) { FT_ERROR(( "pfr_face_init: invalid face index\n" )); error = PFR_Err_Invalid_Argument; goto Exit; } /* load the face */ error = pfr_log_font_load( &face->log_font, stream, face_index, face->header.log_dir_offset, FT_BOOL( face->header.phy_font_max_size_high != 0 ) ); if ( error ) goto Exit; /* now load the physical font descriptor */ error = pfr_phy_font_load( &face->phy_font, stream, face->log_font.phys_offset, face->log_font.phys_size ); if ( error ) goto Exit; /* now, set-up all root face fields */ { FT_Face root = FT_FACE( face ); PFR_PhyFont phy_font = &face->phy_font; root->face_index = face_index; root->num_glyphs = phy_font->num_chars; root->face_flags = FT_FACE_FLAG_SCALABLE; if ( (phy_font->flags & PFR_PHY_PROPORTIONAL) == 0 ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; if ( phy_font->flags & PFR_PHY_VERTICAL ) root->face_flags |= FT_FACE_FLAG_VERTICAL; else root->face_flags |= FT_FACE_FLAG_HORIZONTAL; if ( phy_font->num_strikes > 0 ) root->face_flags |= FT_FACE_FLAG_FIXED_SIZES; if ( phy_font->num_kern_pairs > 0 ) root->face_flags |= FT_FACE_FLAG_KERNING; root->family_name = phy_font->font_id; root->style_name = NULL; /* no style name in font file */ root->num_fixed_sizes = 0; root->available_sizes = 0; root->bbox = phy_font->bbox; root->units_per_EM = (FT_UShort)phy_font->outline_resolution; root->ascender = (FT_Short) phy_font->bbox.yMax; root->descender = (FT_Short) phy_font->bbox.yMin; root->height = (FT_Short) ( ( ( root->ascender - root->descender ) * 12 ) / 10 ); /* now compute maximum advance width */ if ( ( phy_font->flags & PFR_PHY_PROPORTIONAL ) == 0 ) root->max_advance_width = (FT_Short)phy_font->standard_advance; else { FT_Int max = 0; FT_UInt count = phy_font->num_chars; PFR_Char gchar = phy_font->chars; for ( ; count > 0; count--, gchar++ ) { if ( max < gchar->advance ) max = gchar->advance; } root->max_advance_width = (FT_Short)max; } root->max_advance_height = root->height; root->underline_position = (FT_Short)( - root->units_per_EM / 10 ); root->underline_thickness = (FT_Short)( root->units_per_EM / 30 ); /* create charmap */ { FT_CharMapRec charmap; charmap.face = root; charmap.platform_id = 3; charmap.encoding_id = 1; charmap.encoding = FT_ENCODING_UNICODE; FT_CMap_New( &pfr_cmap_class_rec, NULL, &charmap, NULL ); #if 0 /* Select default charmap */ if (root->num_charmaps) root->charmap = root->charmaps[0]; #endif } /* check whether we've loaded any kerning pairs */ if ( phy_font->num_kern_pairs ) root->face_flags |= FT_FACE_FLAG_KERNING; } Exit: return error; }