2010-01-10 Carles Pina i Estany <carles@pina.cat>
* font/font.c: Include `ascii.h'. (ASCII_BITMAP_SIZE): New macro. (ascii_font_glyph): Define. (ascii_glyph_lookup): New function. (grub_font_get_string_width): Change comment. If glyph not found, use ascii_glyph_lookup. (grub_font_get_glyph_with_fallback): If glyph not available returns ascii_glyph_lookup. * util/grub-mkfont.c (file_formats): New enum. (options): Add `ascii-bitmaps' new option. (usage): Add `asii-bitmaps' new option. (write_font_ascii_bitmap): New function. (write_font): Rename to ... (write_font_p2): ... this. Remove print_glyphs call. (main): Use file_format. Implement code for ranges if ascii-bitmaps is used. Call print_glyphs. * Makefile.in (pkgdata_DATA): Add `font/ascii.h'.
This commit is contained in:
parent
f40f890a12
commit
26ba5c2262
4 changed files with 154 additions and 12 deletions
|
@ -49,6 +49,12 @@ struct grub_glyph_info
|
|||
grub_uint8_t bitmap[0];
|
||||
};
|
||||
|
||||
enum file_formats
|
||||
{
|
||||
PF2,
|
||||
ASCII_BITMAPS
|
||||
};
|
||||
|
||||
#define GRUB_FONT_FLAG_BOLD 1
|
||||
#define GRUB_FONT_FLAG_NOBITMAP 2
|
||||
#define GRUB_FONT_FLAG_NOHINTING 4
|
||||
|
@ -87,6 +93,7 @@ static struct option options[] =
|
|||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"ascii-bitmaps", no_argument, 0, 0x102},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -102,6 +109,7 @@ usage (int status)
|
|||
Usage: %s [OPTIONS] FONT_FILES\n\
|
||||
\nOptions:\n\
|
||||
-o, --output=FILE_NAME set output file name\n\
|
||||
--ascii-bitmaps save only the ASCII bitmaps\n\
|
||||
-i, --index=N set face index\n\
|
||||
-r, --range=A-B[,C-D] set font range\n\
|
||||
-n, --name=S set font family name\n\
|
||||
|
@ -337,7 +345,39 @@ print_glyphs (struct grub_font_info *font_info)
|
|||
}
|
||||
|
||||
void
|
||||
write_font (struct grub_font_info *font_info, char *output_file)
|
||||
write_font_ascii_bitmap (struct grub_font_info *font_info, char *output_file)
|
||||
{
|
||||
FILE *file;
|
||||
struct grub_glyph_info *glyph;
|
||||
int num;
|
||||
|
||||
file = fopen (output_file, "wb");
|
||||
if (! file)
|
||||
grub_util_error ("Can\'t write to file %s.", output_file);
|
||||
|
||||
int correct_size;
|
||||
for (glyph = font_info->glyph, num = 0; glyph; glyph = glyph->next, num++)
|
||||
{
|
||||
correct_size = 1;
|
||||
if (glyph->width != 8 || glyph->height != 16)
|
||||
{
|
||||
// printf ("Width or height from glyph U+%04x not supported, skipping.\n", glyph->char_code);
|
||||
correct_size = 0;
|
||||
}
|
||||
int row;
|
||||
for (row = 0; row < glyph->height; row++)
|
||||
{
|
||||
if (correct_size)
|
||||
fwrite (&glyph->bitmap[row], sizeof(glyph->bitmap[row]), 1, file);
|
||||
else
|
||||
fwrite (&correct_size, 1, 1, file);
|
||||
}
|
||||
}
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
void
|
||||
write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||
{
|
||||
FILE *file;
|
||||
grub_uint32_t leng, data;
|
||||
|
@ -473,9 +513,6 @@ write_font (struct grub_font_info *font_info, char *output_file)
|
|||
grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size, file);
|
||||
}
|
||||
|
||||
if (font_verbosity > 1)
|
||||
print_glyphs (font_info);
|
||||
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
|
@ -487,6 +524,7 @@ main (int argc, char *argv[])
|
|||
int font_index = 0;
|
||||
int font_size = 0;
|
||||
char *output_file = NULL;
|
||||
enum file_formats file_format = PF2;
|
||||
|
||||
memset (&font_info, 0, sizeof (font_info));
|
||||
|
||||
|
@ -552,7 +590,7 @@ main (int argc, char *argv[])
|
|||
font_info.ranges = xrealloc (font_info.ranges,
|
||||
(font_info.num_range +
|
||||
GRUB_FONT_RANGE_BLOCK) *
|
||||
sizeof (int) * 2);
|
||||
sizeof (grub_uint32_t) * 2);
|
||||
|
||||
font_info.ranges[font_info.num_range * 2] = a;
|
||||
font_info.ranges[font_info.num_range * 2 + 1] = b;
|
||||
|
@ -591,12 +629,33 @@ main (int argc, char *argv[])
|
|||
font_verbosity++;
|
||||
break;
|
||||
|
||||
case 0x102:
|
||||
file_format = ASCII_BITMAPS;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage (1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_format == ASCII_BITMAPS && font_info.num_range > 0)
|
||||
{
|
||||
grub_util_error ("Option --ascii-bitmaps doesn't accept ranges (use ASCII).");
|
||||
return 1;
|
||||
}
|
||||
|
||||
else if (file_format == ASCII_BITMAPS)
|
||||
{
|
||||
font_info.ranges = xrealloc (font_info.ranges,
|
||||
GRUB_FONT_RANGE_BLOCK *
|
||||
sizeof (grub_uint32_t) * 2);
|
||||
|
||||
font_info.ranges[0] = (grub_uint32_t) 0x00;
|
||||
font_info.ranges[1] = (grub_uint32_t) 0x7f;
|
||||
font_info.num_range = 1;
|
||||
}
|
||||
|
||||
if (! output_file)
|
||||
grub_util_error ("No output file is specified.");
|
||||
|
||||
|
@ -638,7 +697,13 @@ main (int argc, char *argv[])
|
|||
|
||||
FT_Done_FreeType (ft_lib);
|
||||
|
||||
write_font (&font_info, output_file);
|
||||
if (file_format == PF2)
|
||||
write_font_pf2 (&font_info, output_file);
|
||||
else if (file_format == ASCII_BITMAPS)
|
||||
write_font_ascii_bitmap (&font_info, output_file);
|
||||
|
||||
if (font_verbosity > 1)
|
||||
print_glyphs (&font_info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue