2010-01-06 Vladimir Serbinenko <phcoder@gmail.com>

Fix descent and ascent calculation.

	* util/grub-mkfont.c (grub_font_info): New fields 'asce' and 'max_y'.
	(options): New option "asce".
	(usage): Likewise.
	(add_char): Ignore invalid glyphs for descent calculation.
	Calculate ascent from actual content.
	(print_glyphs): Use 'asce'.
	(write_font): Likewise. Allow ascent override.
	(main): Handle "asce" option.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-06 23:25:57 +01:00
parent e7730de786
commit 42841caa75
2 changed files with 38 additions and 6 deletions

View file

@ -1,3 +1,16 @@
2010-01-06 Vladimir Serbinenko <phcoder@gmail.com>
Fix descent and ascent calculation.
* util/grub-mkfont.c (grub_font_info): New fields 'asce' and 'max_y'.
(options): New option "asce".
(usage): Likewise.
(add_char): Ignore invalid glyphs for descent calculation.
Calculate ascent from actual content.
(print_glyphs): Use 'asce'.
(write_font): Likewise. Allow ascent override.
(main): Handle "asce" option.
2010-01-06 Carles Pina i Estany <carles@pina.cat>
* kern/err.c: Include `<grub/i18n.h>'.

View file

@ -59,10 +59,12 @@ struct grub_font_info
char* name;
int style;
int desc;
int asce;
int size;
int max_width;
int max_height;
int min_y;
int max_y;
int flags;
int num_range;
grub_uint32_t *ranges;
@ -77,6 +79,7 @@ static struct option options[] =
{"range", required_argument, 0, 'r'},
{"size", required_argument, 0, 's'},
{"desc", required_argument, 0, 'd'},
{"asce", required_argument, 0, 'c'},
{"bold", no_argument, 0, 'b'},
{"no-bitmap", no_argument, 0, 0x100},
{"no-hinting", no_argument, 0, 0x101},
@ -104,6 +107,7 @@ Usage: %s [OPTIONS] FONT_FILES\n\
-n, --name=S set font family name\n\
-s, --size=N set font size\n\
-d, --desc=N set font descent\n\
-c, --asce=N set font ascent\n\
-b, --bold convert to bold font\n\
-a, --force-autohint force autohint\n\
--no-hinting disable hinting\n\
@ -193,9 +197,12 @@ add_char (struct grub_font_info *font_info, FT_Face face,
if (height > font_info->max_height)
font_info->max_height = height;
if (glyph_info->y_ofs < font_info->min_y)
if (glyph_info->y_ofs < font_info->min_y && glyph_info->y_ofs > -font_info->size)
font_info->min_y = glyph_info->y_ofs;
if (glyph_info->y_ofs + height > font_info->max_y)
font_info->max_y = glyph_info->y_ofs + height;
mask = 0;
data = &glyph_info->bitmap[0] - 1;
for (j = 0; j < height; j++)
@ -284,8 +291,8 @@ print_glyphs (struct grub_font_info *font_info)
xmin = 0;
ymax = glyph->y_ofs + glyph->height;
if (ymax < font_info->size - font_info->desc)
ymax = font_info->size - font_info->desc;
if (ymax < font_info->asce)
ymax = font_info->asce;
ymin = glyph->y_ofs;
if (ymin > - font_info->desc)
@ -316,7 +323,7 @@ print_glyphs (struct grub_font_info *font_info)
else if ((x >= 0) &&
(x < glyph->device_width) &&
(y >= - font_info->desc) &&
(y < font_info->size - font_info->desc))
(y < font_info->asce))
{
line[line_pos++] = ((x == 0) || (y == 0)) ? '+' : '.';
}
@ -392,7 +399,15 @@ write_font (struct grub_font_info *font_info, char *output_file)
font_info->desc = - font_info->min_y;
}
write_be16_section ("ASCE", font_info->size - font_info->desc, &offset, file);
if (! font_info->asce)
{
if (font_info->max_y <= 0)
font_info->asce = 1;
else
font_info->asce = font_info->max_y;
}
write_be16_section ("ASCE", font_info->asce, &offset, file);
write_be16_section ("DESC", font_info->desc, &offset, file);
if (font_verbosity > 0)
@ -400,7 +415,7 @@ write_font (struct grub_font_info *font_info, char *output_file)
printf ("Font name: %s\n", font_name);
printf ("Max width: %d\n", font_info->max_width);
printf ("Max height: %d\n", font_info->max_height);
printf ("Font ascent: %d\n", font_info->size - font_info->desc);
printf ("Font ascent: %d\n", font_info->asce);
printf ("Font descent: %d\n", font_info->desc);
}
@ -560,6 +575,10 @@ main (int argc, char *argv[])
font_info.desc = strtoul (optarg, NULL, 0);
break;
case 'e':
font_info.asce = strtoul (optarg, NULL, 0);
break;
case 'h':
usage (0);
break;