static FT_Error FNT_Face_Init( FT_Stream stream, FNT_Face face, FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error; FT_Memory memory = FT_FACE_MEMORY( face ); FT_UNUSED( num_params ); FT_UNUSED( params ); FT_UNUSED( face_index ); /* try to load several fonts from a DLL */ error = fnt_face_get_dll_fonts( face ); if ( error ) { /* this didn't work, now try to load a single FNT font */ FNT_Font* font; if ( ALLOC( face->fonts, sizeof ( *face->fonts ) ) ) goto Exit; face->num_fonts = 1; font = face->fonts; font->offset = 0; font->fnt_size = stream->size; error = fnt_font_load( font, stream ); if ( error ) goto Fail; } /* all right, one or more fonts were loaded; we now need to */ /* fill the root FT_Face fields with relevant information */ { FT_Face root = FT_FACE( face ); FNT_Font* fonts = face->fonts; FNT_Font* limit = fonts + face->num_fonts; FNT_Font* cur; root->num_faces = 1; root->face_flags = FT_FACE_FLAG_FIXED_SIZES | FT_FACE_FLAG_HORIZONTAL; if ( fonts->header.avg_width == fonts->header.max_width ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; if ( fonts->header.italic ) root->style_flags |= FT_STYLE_FLAG_ITALIC; if ( fonts->header.weight >= 800 ) root->style_flags |= FT_STYLE_FLAG_BOLD; /* Setup the `fixed_sizes' array */ if ( ALLOC_ARRAY( root->available_sizes, face->num_fonts, FT_Bitmap_Size ) ) goto Fail; root->num_fixed_sizes = face->num_fonts; { FT_Bitmap_Size* size = root->available_sizes; for ( cur = fonts; cur < limit; cur++, size++ ) { size->width = cur->header.pixel_width; size->height = cur->header.pixel_height; } } /* Setup the `charmaps' array */ root->charmaps = &face->charmap_handle; root->num_charmaps = 1; face->charmap.encoding = ft_encoding_unicode; face->charmap.platform_id = 3; face->charmap.encoding_id = 1; face->charmap.face = root; face->charmap_handle = &face->charmap; root->charmap = face->charmap_handle; /* setup remaining flags */ root->num_glyphs = fonts->header.last_char - fonts->header.first_char + 1; root->family_name = (FT_String*)fonts->fnt_frame + fonts->header.face_name_offset; root->style_name = (char *)"Regular"; if ( root->style_flags & FT_STYLE_FLAG_BOLD ) { if ( root->style_flags & FT_STYLE_FLAG_ITALIC ) root->style_name = (char *)"Bold Italic"; else root->style_name = (char *)"Bold"; } else if ( root->style_flags & FT_STYLE_FLAG_ITALIC ) root->style_name = (char *)"Italic"; } Fail: if ( error ) FNT_Face_Done( face ); Exit: return error; }
static FT_Error FNT_Face_Init( FT_Stream stream, FNT_Face face, FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { FT_Error error; FT_Memory memory = FT_FACE_MEMORY( face ); FT_UNUSED( num_params ); FT_UNUSED( params ); /* try to load font from a DLL */ error = fnt_face_get_dll_font( face, face_index ); if ( error ) { /* this didn't work; try to load a single FNT font */ FNT_Font font; if ( FT_NEW( face->font ) ) goto Exit; face->root.num_faces = 1; font = face->font; font->offset = 0; font->fnt_size = stream->size; error = fnt_font_load( font, stream ); if ( error ) goto Fail; } /* we now need to fill the root FT_Face fields */ /* with relevant information */ { FT_Face root = FT_FACE( face ); FNT_Font font = face->font; root->face_flags = FT_FACE_FLAG_FIXED_SIZES | FT_FACE_FLAG_HORIZONTAL; if ( font->header.avg_width == font->header.max_width ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; if ( font->header.italic ) root->style_flags |= FT_STYLE_FLAG_ITALIC; if ( font->header.weight >= 800 ) root->style_flags |= FT_STYLE_FLAG_BOLD; /* set up the `fixed_sizes' array */ if ( FT_NEW_ARRAY( root->available_sizes, 1 ) ) goto Fail; root->num_fixed_sizes = 1; { FT_Bitmap_Size* bsize = root->available_sizes; bsize->width = font->header.avg_width; bsize->height = font->header.pixel_height + font->header.external_leading; bsize->size = font->header.nominal_point_size << 6; bsize->x_ppem = (FT_Pos)( ( font->header.horizontal_resolution * bsize->size + 36 ) / 72 ); bsize->y_ppem = (FT_Pos)( ( font->header.vertical_resolution* bsize->size + 36 ) / 72 ); } { FT_CharMapRec charmap; charmap.encoding = FT_ENCODING_UNICODE; charmap.platform_id = 3; charmap.encoding_id = 1; charmap.face = root; error = FT_CMap_New( fnt_cmap_class, NULL, &charmap, NULL ); if ( error ) goto Fail; /* Select default charmap */ if ( root->num_charmaps ) root->charmap = root->charmaps[0]; } /* setup remaining flags */ /* reserve one slot for the .notdef glyph at index 0 */ root->num_glyphs = font->header.last_char - font->header.first_char + 1 + 1; root->family_name = (FT_String*)font->fnt_frame + font->header.face_name_offset; root->style_name = (char *)"Regular"; if ( root->style_flags & FT_STYLE_FLAG_BOLD ) { if ( root->style_flags & FT_STYLE_FLAG_ITALIC ) root->style_name = (char *)"Bold Italic"; else root->style_name = (char *)"Bold"; } else if ( root->style_flags & FT_STYLE_FLAG_ITALIC ) root->style_name = (char *)"Italic"; } Fail: if ( error ) FNT_Face_Done( face ); Exit: return error; }
static FT_Error fnt_face_get_dll_fonts( FNT_Face face ) { FT_Error error; FT_Stream stream = FT_FACE(face)->stream; FT_Memory memory = FT_FACE(face)->memory; WinMZ_Header mz_header; face->fonts = 0; face->num_fonts = 0; /* does it begin with a MZ header? */ if ( FILE_Seek( 0 ) || READ_Fields( winmz_header_fields, &mz_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( mz_header.magic == WINFNT_MZ_MAGIC ) { /* yes, now look for a NE header in the file */ WinNE_Header ne_header; if ( FILE_Seek( mz_header.lfanew ) || READ_Fields( winne_header_fields, &ne_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( ne_header.magic == WINFNT_NE_MAGIC ) { /* good, now look in the resource table for each FNT resource */ FT_ULong res_offset = mz_header.lfanew + ne_header.resource_tab_offset; FT_UShort size_shift; FT_UShort font_count = 0; FT_ULong font_offset = 0; if ( FILE_Seek( res_offset ) || ACCESS_Frame( ne_header.rname_tab_offset - ne_header.resource_tab_offset ) ) goto Exit; size_shift = GET_UShortLE(); for (;;) { FT_UShort type_id, count; type_id = GET_UShortLE(); if ( !type_id ) break; count = GET_UShortLE(); if ( type_id == 0x8008 ) { font_count = count; font_offset = (FT_ULong)( FILE_Pos() + 4 + ( stream->cursor - stream->limit ) ); break; } stream->cursor += 4 + count * 12; } FORGET_Frame(); if ( !font_count || !font_offset ) { FT_TRACE2(( "this file doesn't contain any FNT resources!\n" )); error = FNT_Err_Unknown_File_Format; goto Exit; } if ( FILE_Seek( font_offset ) || ALLOC_ARRAY( face->fonts, font_count, FNT_Font ) ) goto Exit; face->num_fonts = font_count; if ( ACCESS_Frame( (FT_Long)font_count * 12 ) ) goto Exit; /* now read the offset and position of each FNT font */ { FNT_Font* cur = face->fonts; FNT_Font* limit = cur + font_count; for ( ; cur < limit; cur++ ) { cur->offset = (FT_ULong)GET_UShortLE() << size_shift; cur->fnt_size = (FT_ULong)GET_UShortLE() << size_shift; cur->size_shift = size_shift; stream->cursor += 8; } } FORGET_Frame(); /* finally, try to load each font there */ { FNT_Font* cur = face->fonts; FNT_Font* limit = cur + font_count; for ( ; cur < limit; cur++ ) { error = fnt_font_load( cur, stream ); if ( error ) goto Fail; } } } } Fail: if ( error ) fnt_face_done_fonts( face ); Exit: return error; }
static FT_Error fnt_face_get_dll_font( FNT_Face face, FT_Int face_index ) { FT_Error error; FT_Stream stream = FT_FACE( face )->stream; FT_Memory memory = FT_FACE( face )->memory; WinMZ_HeaderRec mz_header; face->font = 0; /* does it begin with an MZ header? */ if ( FT_STREAM_SEEK( 0 ) || FT_STREAM_READ_FIELDS( winmz_header_fields, &mz_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( mz_header.magic == WINFNT_MZ_MAGIC ) { /* yes, now look for an NE header in the file */ WinNE_HeaderRec ne_header; if ( FT_STREAM_SEEK( mz_header.lfanew ) || FT_STREAM_READ_FIELDS( winne_header_fields, &ne_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( ne_header.magic == WINFNT_NE_MAGIC ) { /* good, now look into the resource table for each FNT resource */ FT_ULong res_offset = mz_header.lfanew + ne_header.resource_tab_offset; FT_UShort size_shift; FT_UShort font_count = 0; FT_ULong font_offset = 0; if ( FT_STREAM_SEEK( res_offset ) || FT_FRAME_ENTER( ne_header.rname_tab_offset - ne_header.resource_tab_offset ) ) goto Exit; size_shift = FT_GET_USHORT_LE(); for (;;) { FT_UShort type_id, count; type_id = FT_GET_USHORT_LE(); if ( !type_id ) break; count = FT_GET_USHORT_LE(); if ( type_id == 0x8008U ) { font_count = count; font_offset = (FT_ULong)( FT_STREAM_POS() + 4 + ( stream->cursor - stream->limit ) ); break; } stream->cursor += 4 + count * 12; } FT_FRAME_EXIT(); if ( !font_count || !font_offset ) { FT_TRACE2(( "this file doesn't contain any FNT resources!\n" )); error = FNT_Err_Unknown_File_Format; goto Exit; } face->root.num_faces = font_count; if ( face_index >= font_count ) { error = FNT_Err_Bad_Argument; goto Exit; } if ( FT_NEW( face->font ) ) goto Exit; if ( FT_STREAM_SEEK( font_offset + face_index * 12 ) || FT_FRAME_ENTER( 12 ) ) goto Fail; face->font->offset = (FT_ULong)FT_GET_USHORT_LE() << size_shift; face->font->fnt_size = (FT_ULong)FT_GET_USHORT_LE() << size_shift; face->font->size_shift = size_shift; stream->cursor += 8; FT_FRAME_EXIT(); error = fnt_font_load( face->font, stream ); } } Fail: if ( error ) fnt_font_done( face ); Exit: return error; }