39#define FT_COMPONENT winfnt
42 static const FT_Frame_Field winmz_header_fields[] =
45#define FT_STRUCTURE WinMZ_HeaderRec
48 FT_FRAME_USHORT_LE ( magic ),
49 FT_FRAME_SKIP_BYTES( 29 * 2 ),
50 FT_FRAME_ULONG_LE ( lfanew ),
54 static const FT_Frame_Field winne_header_fields[] =
57#define FT_STRUCTURE WinNE_HeaderRec
60 FT_FRAME_USHORT_LE ( magic ),
61 FT_FRAME_SKIP_BYTES( 34 ),
62 FT_FRAME_USHORT_LE ( resource_tab_offset ),
63 FT_FRAME_USHORT_LE ( rname_tab_offset ),
67 static const FT_Frame_Field winpe32_header_fields[] =
70#define FT_STRUCTURE WinPE32_HeaderRec
72 FT_FRAME_START( 248 ),
73 FT_FRAME_ULONG_LE ( magic ),
74 FT_FRAME_USHORT_LE ( machine ),
75 FT_FRAME_USHORT_LE ( number_of_sections ),
76 FT_FRAME_SKIP_BYTES( 12 ),
77 FT_FRAME_USHORT_LE ( size_of_optional_header ),
78 FT_FRAME_SKIP_BYTES( 2 ),
79 FT_FRAME_USHORT_LE ( magic32 ),
80 FT_FRAME_SKIP_BYTES( 110 ),
81 FT_FRAME_ULONG_LE ( rsrc_virtual_address ),
82 FT_FRAME_ULONG_LE ( rsrc_size ),
83 FT_FRAME_SKIP_BYTES( 104 ),
87 static const FT_Frame_Field winpe32_section_fields[] =
90#define FT_STRUCTURE WinPE32_SectionRec
93 FT_FRAME_BYTES ( name, 8 ),
94 FT_FRAME_SKIP_BYTES( 4 ),
95 FT_FRAME_ULONG_LE ( virtual_address ),
96 FT_FRAME_ULONG_LE ( size_of_raw_data ),
97 FT_FRAME_ULONG_LE ( pointer_to_raw_data ),
98 FT_FRAME_SKIP_BYTES( 16 ),
102 static const FT_Frame_Field winpe_rsrc_dir_fields[] =
105#define FT_STRUCTURE WinPE_RsrcDirRec
107 FT_FRAME_START( 16 ),
108 FT_FRAME_ULONG_LE ( characteristics ),
109 FT_FRAME_ULONG_LE ( time_date_stamp ),
110 FT_FRAME_USHORT_LE( major_version ),
111 FT_FRAME_USHORT_LE( minor_version ),
112 FT_FRAME_USHORT_LE( number_of_named_entries ),
113 FT_FRAME_USHORT_LE( number_of_id_entries ),
117 static const FT_Frame_Field winpe_rsrc_dir_entry_fields[] =
120#define FT_STRUCTURE WinPE_RsrcDirEntryRec
123 FT_FRAME_ULONG_LE( name ),
124 FT_FRAME_ULONG_LE( offset ),
128 static const FT_Frame_Field winpe_rsrc_data_entry_fields[] =
131#define FT_STRUCTURE WinPE_RsrcDataEntryRec
133 FT_FRAME_START( 16 ),
134 FT_FRAME_ULONG_LE( offset_to_data ),
135 FT_FRAME_ULONG_LE( size ),
136 FT_FRAME_ULONG_LE( code_page ),
137 FT_FRAME_ULONG_LE( reserved ),
141 static const FT_Frame_Field winfnt_header_fields[] =
144#define FT_STRUCTURE FT_WinFNT_HeaderRec
146 FT_FRAME_START( 148 ),
147 FT_FRAME_USHORT_LE( version ),
148 FT_FRAME_ULONG_LE ( file_size ),
149 FT_FRAME_BYTES ( copyright, 60 ),
150 FT_FRAME_USHORT_LE( file_type ),
151 FT_FRAME_USHORT_LE( nominal_point_size ),
152 FT_FRAME_USHORT_LE( vertical_resolution ),
153 FT_FRAME_USHORT_LE( horizontal_resolution ),
154 FT_FRAME_USHORT_LE( ascent ),
155 FT_FRAME_USHORT_LE( internal_leading ),
156 FT_FRAME_USHORT_LE( external_leading ),
157 FT_FRAME_BYTE ( italic ),
158 FT_FRAME_BYTE ( underline ),
159 FT_FRAME_BYTE ( strike_out ),
160 FT_FRAME_USHORT_LE( weight ),
161 FT_FRAME_BYTE ( charset ),
162 FT_FRAME_USHORT_LE( pixel_width ),
163 FT_FRAME_USHORT_LE( pixel_height ),
164 FT_FRAME_BYTE ( pitch_and_family ),
165 FT_FRAME_USHORT_LE( avg_width ),
166 FT_FRAME_USHORT_LE( max_width ),
167 FT_FRAME_BYTE ( first_char ),
168 FT_FRAME_BYTE ( last_char ),
169 FT_FRAME_BYTE ( default_char ),
170 FT_FRAME_BYTE ( break_char ),
171 FT_FRAME_USHORT_LE( bytes_per_row ),
172 FT_FRAME_ULONG_LE ( device_offset ),
173 FT_FRAME_ULONG_LE ( face_name_offset ),
174 FT_FRAME_ULONG_LE ( bits_pointer ),
175 FT_FRAME_ULONG_LE ( bits_offset ),
176 FT_FRAME_BYTE ( reserved ),
177 FT_FRAME_ULONG_LE ( flags ),
178 FT_FRAME_USHORT_LE( A_space ),
179 FT_FRAME_USHORT_LE( B_space ),
180 FT_FRAME_USHORT_LE( C_space ),
181 FT_FRAME_ULONG_LE ( color_table_offset ),
182 FT_FRAME_BYTES ( reserved1, 16 ),
188 fnt_font_done( FNT_Face face )
190 FT_Memory memory = FT_FACE( face )->memory;
191 FT_Stream stream = FT_FACE( face )->stream;
192 FNT_Font font = face->font;
198 if ( font->fnt_frame )
199 FT_FRAME_RELEASE( font->fnt_frame );
200 FT_FREE( font->family_name );
208 fnt_font_load( FNT_Font font,
212 FT_WinFNT_Header header = &font->header;
218 if ( FT_STREAM_SEEK( font->offset ) ||
219 FT_STREAM_READ_FIELDS( winfnt_header_fields, header ) )
221 FT_TRACE2((
" not a Windows FNT file\n" ));
222 error = FT_THROW( Unknown_File_Format );
227 if ( header->version != 0x200 &&
228 header->version != 0x300 )
230 FT_TRACE2((
" not a Windows FNT file\n" ));
231 error = FT_THROW( Unknown_File_Format );
235 new_format = FT_BOOL( font->header.version == 0x300 );
236 size = new_format ? 148 : 118;
238 if ( header->file_size < size )
240 FT_TRACE2((
" not a Windows FNT file\n" ));
241 error = FT_THROW( Unknown_File_Format );
246 if ( header->version == 0x200 )
253 header->color_table_offset = 0;
256 if ( header->file_type & 1 )
258 FT_TRACE2((
"[can't handle vector FNT fonts]\n" ));
259 error = FT_THROW( Unknown_File_Format );
264 if ( FT_STREAM_SEEK( font->offset ) ||
265 FT_FRAME_EXTRACT( header->file_size, font->fnt_frame ) )
274 fnt_face_get_dll_font( FNT_Face face,
275 FT_Int face_instance_index )
278 FT_Stream stream = FT_FACE( face )->stream;
279 FT_Memory memory = FT_FACE( face )->memory;
280 WinMZ_HeaderRec mz_header;
286 face_index = FT_ABS( face_instance_index ) & 0xFFFF;
289 if ( FT_STREAM_SEEK( 0 ) ||
290 FT_STREAM_READ_FIELDS( winmz_header_fields, &mz_header ) )
292 error = FT_ERR( Unknown_File_Format );
296 error = FT_ERR( Unknown_File_Format );
297 if ( mz_header.magic == WINFNT_MZ_MAGIC )
300 WinNE_HeaderRec ne_header;
303 FT_TRACE2((
"MZ signature found\n" ));
305 if ( FT_STREAM_SEEK( mz_header.lfanew ) ||
306 FT_STREAM_READ_FIELDS( winne_header_fields, &ne_header ) )
309 error = FT_ERR( Unknown_File_Format );
310 if ( ne_header.magic == WINFNT_NE_MAGIC )
313 FT_ULong res_offset = mz_header.lfanew +
314 ne_header.resource_tab_offset;
315 FT_UShort size_shift;
316 FT_UShort font_count = 0;
317 FT_ULong font_offset = 0;
320 FT_TRACE2((
"NE signature found\n" ));
322 if ( FT_STREAM_SEEK( res_offset ) ||
323 FT_FRAME_ENTER( ne_header.rname_tab_offset -
324 ne_header.resource_tab_offset ) )
327 size_shift = FT_GET_USHORT_LE();
336 if ( size_shift > 16 )
338 FT_TRACE2((
"invalid alignment shift count for resource data\n" ));
339 error = FT_THROW( Invalid_File_Format );
346 FT_UShort type_id, count;
349 type_id = FT_GET_USHORT_LE();
353 count = FT_GET_USHORT_LE();
355 FT_TRACE2(( type_id == 0x8007U ?
"RT_FONTDIR count %hu\n" :
356 type_id == 0x8008U ?
"RT_FONT count %hu\n" :
"",
359 if ( type_id == 0x8008U )
362 font_offset = FT_STREAM_POS() + 4 -
363 (FT_ULong)( stream->limit - stream->cursor );
367 stream->cursor += 4 + count * 12;
372 if ( !font_count || !font_offset )
374 FT_TRACE2((
"this file doesn't contain any FNT resources\n" ));
375 error = FT_THROW( Invalid_File_Format );
381 if ( font_count * 118UL > stream->size )
383 FT_TRACE2((
"invalid number of faces\n" ));
384 error = FT_THROW( Invalid_File_Format );
388 face->root.num_faces = font_count;
390 if ( face_instance_index < 0 )
393 if ( face_index >= font_count )
395 error = FT_THROW( Invalid_Argument );
399 if ( FT_NEW( face->font ) )
402 if ( FT_STREAM_SEEK( font_offset + (FT_ULong)face_index * 12 ) ||
403 FT_FRAME_ENTER( 12 ) )
406 face->font->offset = (FT_ULong)FT_GET_USHORT_LE() << size_shift;
407 face->font->fnt_size = (FT_ULong)FT_GET_USHORT_LE() << size_shift;
413 error = fnt_font_load( face->font, stream );
415 else if ( ne_header.magic == WINFNT_PE_MAGIC )
417 WinPE32_HeaderRec pe32_header;
418 WinPE32_SectionRec pe32_section;
419 WinPE_RsrcDirRec root_dir, name_dir, lang_dir;
420 WinPE_RsrcDirEntryRec dir_entry1, dir_entry2, dir_entry3;
421 WinPE_RsrcDataEntryRec data_entry;
423 FT_ULong root_dir_offset, name_dir_offset, lang_dir_offset;
427 FT_TRACE2((
"PE signature found\n" ));
429 if ( FT_STREAM_SEEK( mz_header.lfanew ) ||
430 FT_STREAM_READ_FIELDS( winpe32_header_fields, &pe32_header ) )
433 FT_TRACE2((
"magic %04lx, machine %02x, number_of_sections %u, "
434 "size_of_optional_header %02x\n",
435 pe32_header.magic, pe32_header.machine,
436 pe32_header.number_of_sections,
437 pe32_header.size_of_optional_header ));
438 FT_TRACE2((
"magic32 %02x, rsrc_virtual_address %04lx, "
440 pe32_header.magic32, pe32_header.rsrc_virtual_address,
441 pe32_header.rsrc_size ));
443 if ( pe32_header.magic != WINFNT_PE_MAGIC ||
444 pe32_header.machine != 0x014C ||
445 pe32_header.size_of_optional_header != 0xE0 ||
446 pe32_header.magic32 != 0x10B )
448 FT_TRACE2((
"this file has an invalid PE header\n" ));
449 error = FT_THROW( Invalid_File_Format );
453 face->root.num_faces = 0;
455 for ( i = 0; i < pe32_header.number_of_sections; i++ )
457 if ( FT_STREAM_READ_FIELDS( winpe32_section_fields,
461 FT_TRACE2((
"name %.8s, va %04lx, size %04lx, offset %04lx\n",
462 pe32_section.name, pe32_section.virtual_address,
463 pe32_section.size_of_raw_data,
464 pe32_section.pointer_to_raw_data ));
466 if ( pe32_header.rsrc_virtual_address ==
467 pe32_section.virtual_address )
468 goto Found_rsrc_section;
471 FT_TRACE2((
"this file doesn't contain any resources\n" ));
472 error = FT_THROW( Invalid_File_Format );
476 FT_TRACE2((
"found resources section %.8s\n", pe32_section.name ));
478 if ( FT_STREAM_SEEK( pe32_section.pointer_to_raw_data ) ||
479 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_fields, &root_dir ) )
482 root_dir_offset = pe32_section.pointer_to_raw_data;
484 for ( i = 0; i < root_dir.number_of_named_entries +
485 root_dir.number_of_id_entries; i++ )
487 if ( FT_STREAM_SEEK( root_dir_offset + 16 + i * 8 ) ||
488 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_entry_fields,
492 if ( !( dir_entry1.offset & 0x80000000UL ) )
494 error = FT_THROW( Invalid_File_Format );
498 dir_entry1.offset &= ~0x80000000UL;
500 name_dir_offset = pe32_section.pointer_to_raw_data +
503 if ( FT_STREAM_SEEK( pe32_section.pointer_to_raw_data +
504 dir_entry1.offset ) ||
505 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_fields, &name_dir ) )
508 for ( j = 0; j < name_dir.number_of_named_entries +
509 name_dir.number_of_id_entries; j++ )
511 if ( FT_STREAM_SEEK( name_dir_offset + 16 + j * 8 ) ||
512 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_entry_fields,
516 if ( !( dir_entry2.offset & 0x80000000UL ) )
518 error = FT_THROW( Invalid_File_Format );
522 dir_entry2.offset &= ~0x80000000UL;
524 lang_dir_offset = pe32_section.pointer_to_raw_data +
527 if ( FT_STREAM_SEEK( pe32_section.pointer_to_raw_data +
528 dir_entry2.offset ) ||
529 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_fields, &lang_dir ) )
532 for ( k = 0; k < lang_dir.number_of_named_entries +
533 lang_dir.number_of_id_entries; k++ )
535 if ( FT_STREAM_SEEK( lang_dir_offset + 16 + k * 8 ) ||
536 FT_STREAM_READ_FIELDS( winpe_rsrc_dir_entry_fields,
540 if ( dir_entry2.offset & 0x80000000UL )
542 error = FT_THROW( Invalid_File_Format );
546 if ( dir_entry1.name == 8 )
548 if ( FT_STREAM_SEEK( root_dir_offset + dir_entry3.offset ) ||
549 FT_STREAM_READ_FIELDS( winpe_rsrc_data_entry_fields,
553 FT_TRACE2((
"found font #%lu, offset %04lx, "
554 "size %04lx, cp %lu\n",
556 pe32_section.pointer_to_raw_data +
557 data_entry.offset_to_data -
558 pe32_section.virtual_address,
559 data_entry.size, data_entry.code_page ));
561 if ( face_index == face->root.num_faces )
563 if ( FT_NEW( face->font ) )
566 face->font->offset = pe32_section.pointer_to_raw_data +
567 data_entry.offset_to_data -
568 pe32_section.virtual_address;
569 face->font->fnt_size = data_entry.size;
571 error = fnt_font_load( face->font, stream );
574 FT_TRACE2((
"font #%lu load error 0x%x\n",
575 dir_entry2.name, error ));
579 FT_TRACE2((
"font #%lu successfully loaded\n",
583 face->root.num_faces++;
590 if ( !face->root.num_faces )
592 FT_TRACE2((
"this file doesn't contain any RT_FONT resources\n" ));
593 error = FT_THROW( Invalid_File_Format );
597 if ( face_index >= face->root.num_faces )
599 error = FT_THROW( Invalid_Argument );
606 fnt_font_done( face );
623 } FNT_CMapRec, *FNT_CMap;
627 fnt_cmap_init( FT_CMap cmap,
630 FNT_CMap fntcmap = (FNT_CMap)cmap;
631 FNT_Face face = (FNT_Face)FT_CMAP_FACE( cmap );
632 FNT_Font font = face->font;
634 FT_UNUSED( pointer );
637 fntcmap->first = (FT_UInt32)font->header.first_char;
638 fntcmap->count = (FT_UInt32)( font->header.last_char -
639 fntcmap->first + 1 );
646 fnt_cmap_char_index( FT_CMap cmap,
647 FT_UInt32 char_code )
649 FNT_CMap fntcmap = (FNT_CMap)cmap;
653 char_code -= fntcmap->first;
654 if ( char_code < fntcmap->count )
657 gindex = (FT_UInt)( char_code + 1 );
663 fnt_cmap_char_next( FT_CMap cmap,
664 FT_UInt32 *pchar_code )
666 FNT_CMap fntcmap = (FNT_CMap)cmap;
668 FT_UInt32 result = 0;
669 FT_UInt32 char_code = *pchar_code + 1;
672 if ( char_code <= fntcmap->first )
674 result = fntcmap->first;
679 char_code -= fntcmap->first;
680 if ( char_code < fntcmap->count )
682 result = fntcmap->first + char_code;
683 gindex = (FT_UInt)( char_code + 1 );
687 *pchar_code = result;
692 static const FT_CMap_ClassRec fnt_cmap_class_rec =
694 sizeof ( FNT_CMapRec ),
696 (FT_CMap_InitFunc) fnt_cmap_init,
697 (FT_CMap_DoneFunc) NULL,
698 (FT_CMap_CharIndexFunc)fnt_cmap_char_index,
699 (FT_CMap_CharNextFunc) fnt_cmap_char_next,
701 NULL, NULL, NULL, NULL, NULL
704 static FT_CMap_Class
const fnt_cmap_class = &fnt_cmap_class_rec;
708 FNT_Face_Done( FT_Face fntface )
710 FNT_Face face = (FNT_Face)fntface;
717 memory = FT_FACE_MEMORY( face );
719 fnt_font_done( face );
721 FT_FREE( fntface->available_sizes );
722 fntface->num_fixed_sizes = 0;
727 FNT_Face_Init( FT_Stream stream,
729 FT_Int face_instance_index,
731 FT_Parameter* params )
733 FNT_Face face = (FNT_Face)fntface;
735 FT_Memory memory = FT_FACE_MEMORY( face );
738 FT_UNUSED( num_params );
742 FT_TRACE2((
"Windows FNT driver\n" ));
744 face_index = FT_ABS( face_instance_index ) & 0xFFFF;
747 error = fnt_face_get_dll_font( face, face_instance_index );
748 if ( !error && face_instance_index < 0 )
751 if ( FT_ERR_EQ( error, Unknown_File_Format ) )
756 if ( FT_NEW( face->font ) )
759 fntface->num_faces = 1;
763 font->fnt_size = stream->size;
765 error = fnt_font_load( font, stream );
769 if ( face_instance_index < 0 )
772 if ( face_index > 0 )
773 error = FT_THROW( Invalid_Argument );
781 if ( !face->font->header.pixel_height )
783 FT_TRACE2((
"invalid pixel height\n" ));
784 error = FT_THROW( Invalid_File_Format );
791 FT_Face root = FT_FACE( face );
792 FNT_Font font = face->font;
793 FT_ULong family_size;
796 root->face_index = face_index;
798 root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
799 FT_FACE_FLAG_HORIZONTAL;
801 if ( font->header.avg_width == font->header.max_width )
802 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
804 if ( font->header.italic )
805 root->style_flags |= FT_STYLE_FLAG_ITALIC;
807 if ( font->header.weight >= 800 )
808 root->style_flags |= FT_STYLE_FLAG_BOLD;
811 if ( FT_QNEW( root->available_sizes ) )
814 root->num_fixed_sizes = 1;
817 FT_Bitmap_Size* bsize = root->available_sizes;
818 FT_UShort x_res, y_res;
821 bsize->width = (FT_Short)font->header.avg_width;
822 bsize->height = (FT_Short)( font->header.pixel_height +
823 font->header.external_leading );
824 bsize->size = font->header.nominal_point_size << 6;
826 x_res = font->header.horizontal_resolution;
830 y_res = font->header.vertical_resolution;
834 bsize->y_ppem = FT_MulDiv( bsize->size, y_res, 72 );
835 bsize->y_ppem = FT_PIX_ROUND( bsize->y_ppem );
845 if ( bsize->y_ppem > ( font->header.pixel_height << 6 ) )
847 FT_TRACE2((
"use pixel_height as the nominal height\n" ));
849 bsize->y_ppem = font->header.pixel_height << 6;
850 bsize->size = FT_MulDiv( bsize->y_ppem, 72, y_res );
853 bsize->x_ppem = FT_MulDiv( bsize->size, x_res, 72 );
854 bsize->x_ppem = FT_PIX_ROUND( bsize->x_ppem );
858 FT_CharMapRec charmap;
861 charmap.encoding = FT_ENCODING_NONE;
863 charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
864 charmap.encoding_id = TT_APPLE_ID_DEFAULT;
867 if ( font->header.charset == FT_WinFNT_ID_MAC )
869 charmap.encoding = FT_ENCODING_APPLE_ROMAN;
870 charmap.platform_id = TT_PLATFORM_MACINTOSH;
874 error = FT_CMap_New( fnt_cmap_class,
884 if ( font->header.last_char < font->header.first_char )
886 FT_TRACE2((
"invalid number of glyphs\n" ));
887 error = FT_THROW( Invalid_File_Format );
892 root->num_glyphs = font->header.last_char -
893 font->header.first_char + 1 + 1;
895 if ( font->header.face_name_offset >= font->header.file_size )
897 FT_TRACE2((
"invalid family name offset\n" ));
898 error = FT_THROW( Invalid_File_Format );
901 family_size = font->header.file_size - font->header.face_name_offset;
906 if ( FT_QALLOC( font->family_name, family_size + 1 ) )
909 FT_MEM_COPY( font->family_name,
910 font->fnt_frame + font->header.face_name_offset,
913 font->family_name[family_size] =
'\0';
916 if ( FT_QREALLOC( font->family_name,
918 ft_strlen( font->family_name ) + 1 ) )
921 root->family_name = font->family_name;
922 root->style_name = (
char *)
"Regular";
924 if ( root->style_flags & FT_STYLE_FLAG_BOLD )
926 if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
927 root->style_name = (
char *)
"Bold Italic";
929 root->style_name = (
char *)
"Bold";
931 else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
932 root->style_name = (
char *)
"Italic";
937 FNT_Face_Done( fntface );
945 FNT_Size_Select( FT_Size size,
946 FT_ULong strike_index )
948 FNT_Face face = (FNT_Face)size->face;
949 FT_WinFNT_Header header = &face->font->header;
951 FT_UNUSED( strike_index );
954 FT_Select_Metrics( size->face, 0 );
956 size->metrics.ascender = header->ascent * 64;
957 size->metrics.descender = -( header->pixel_height -
958 header->ascent ) * 64;
959 size->metrics.max_advance = header->max_width * 64;
966 FNT_Size_Request( FT_Size size,
967 FT_Size_Request req )
969 FNT_Face face = (FNT_Face)size->face;
970 FT_WinFNT_Header header = &face->font->header;
971 FT_Bitmap_Size* bsize = size->face->available_sizes;
972 FT_Error error = FT_ERR( Invalid_Pixel_Size );
976 height = FT_REQUEST_HEIGHT( req );
977 height = ( height + 32 ) >> 6;
981 case FT_SIZE_REQUEST_TYPE_NOMINAL:
982 if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
986 case FT_SIZE_REQUEST_TYPE_REAL_DIM:
987 if ( height == header->pixel_height )
992 error = FT_THROW( Unimplemented_Feature );
999 return FNT_Size_Select( size, 0 );
1004 FNT_Load_Glyph( FT_GlyphSlot slot,
1006 FT_UInt glyph_index,
1007 FT_Int32 load_flags )
1009 FNT_Face face = (FNT_Face)size->face;
1011 FT_Error error = FT_Err_Ok;
1014 FT_Bitmap* bitmap = &slot->bitmap;
1021 error = FT_THROW( Invalid_Face_Handle );
1028 glyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) )
1030 error = FT_THROW( Invalid_Argument );
1034 FT_TRACE1((
"FNT_Load_Glyph: glyph index %u\n", glyph_index ));
1036 if ( glyph_index > 0 )
1039 glyph_index = font->header.default_char;
1041 new_format = FT_BOOL( font->header.version == 0x300 );
1042 len = new_format ? 6 : 4;
1045 offset = ( new_format ? 148 : 118 ) + len * glyph_index;
1047 if ( offset >= font->header.file_size - 2 - ( new_format ? 4 : 2 ) )
1049 FT_TRACE2((
"invalid FNT offset\n" ));
1050 error = FT_THROW( Invalid_File_Format );
1054 p = font->fnt_frame + offset;
1056 bitmap->width = FT_NEXT_USHORT_LE( p );
1060 offset = FT_NEXT_ULONG_LE( p );
1062 offset = FT_NEXT_USHORT_LE( p );
1064 if ( offset >= font->header.file_size )
1066 FT_TRACE2((
"invalid FNT offset\n" ));
1067 error = FT_THROW( Invalid_File_Format );
1071 bitmap->rows = font->header.pixel_height;
1072 bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
1074 slot->bitmap_left = 0;
1075 slot->bitmap_top = font->header.ascent;
1076 slot->format = FT_GLYPH_FORMAT_BITMAP;
1079 slot->metrics.width = (FT_Pos)( bitmap->width << 6 );
1080 slot->metrics.height = (FT_Pos)( bitmap->rows << 6 );
1081 slot->metrics.horiAdvance = (FT_Pos)( bitmap->width << 6 );
1082 slot->metrics.horiBearingX = 0;
1083 slot->metrics.horiBearingY = slot->bitmap_top << 6;
1085 ft_synthesize_vertical_metrics( &slot->metrics,
1086 (FT_Pos)( bitmap->rows << 6 ) );
1088 if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
1092 p = font->fnt_frame + + offset;
1096 FT_Memory memory = FT_FACE_MEMORY( slot->face );
1097 FT_UInt pitch = ( bitmap->width + 7 ) >> 3;
1102 bitmap->pitch = (int)pitch;
1104 offset + pitch * bitmap->rows > font->header.file_size )
1106 FT_TRACE2((
"invalid bitmap width\n" ));
1107 error = FT_THROW( Invalid_File_Format );
1113 if ( FT_QALLOC_MULT( bitmap->buffer, bitmap->rows, pitch ) )
1116 column = (FT_Byte*)bitmap->buffer;
1118 for ( ; pitch > 0; pitch--, column++ )
1120 FT_Byte* limit = p + bitmap->rows;
1123 for ( write = column; p < limit; p++, write += bitmap->pitch )
1127 slot->internal->flags = FT_GLYPH_OWN_BITMAP;
1136 winfnt_get_header( FT_Face face,
1137 FT_WinFNT_HeaderRec *aheader )
1139 FNT_Font font = ((FNT_Face)face)->font;
1142 *aheader = font->header;
1148 static const FT_Service_WinFntRec winfnt_service_rec =
1158 static const FT_ServiceDescRec winfnt_services[] =
1160 { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_WINFNT },
1161 { FT_SERVICE_ID_WINFNT, &winfnt_service_rec },
1166 static FT_Module_Interface
1167 winfnt_get_service( FT_Module module,
1168 const FT_String* service_id )
1170 FT_UNUSED( module );
1172 return ft_service_list_lookup( winfnt_services, service_id );
1178 FT_CALLBACK_TABLE_DEF
1179 const FT_Driver_ClassRec winfnt_driver_class =
1182 FT_MODULE_FONT_DRIVER |
1183 FT_MODULE_DRIVER_NO_OUTLINES,
1184 sizeof ( FT_DriverRec ),
1197 sizeof ( FNT_FaceRec ),
1198 sizeof ( FT_SizeRec ),
1199 sizeof ( FT_GlyphSlotRec ),