2010-01-25 Carles Pina i Estany <carles@pina.cat>
* font/font.c: Include `grub/fontformat.h. Remove font file format constants. (grub_font_load): Use the new macros. * include/grub/fontformat.h: New file. * util/grub-mkfont.c: Include `grub/fontformat.c'. (write_font_pf2): Use the new macros.
This commit is contained in:
parent
94e7e71281
commit
de0b7a4ed1
4 changed files with 99 additions and 37 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2010-01-25 Carles Pina i Estany <carles@pina.cat>
|
||||||
|
|
||||||
|
* font/font.c: Include `grub/fontformat.h.
|
||||||
|
Remove font file format constants.
|
||||||
|
(grub_font_load): Use the new macros.
|
||||||
|
* include/grub/fontformat.h: New file.
|
||||||
|
* util/grub-mkfont.c: Include `grub/fontformat.c'.
|
||||||
|
(write_font_pf2): Use the new macros.
|
||||||
|
|
||||||
2010-01-26 Robert Millan <rmh.grub@aybabtu.com>
|
2010-01-26 Robert Millan <rmh.grub@aybabtu.com>
|
||||||
|
|
||||||
* util/bin2h.c (usage): Make --help actually explain what `grub-bin2h'
|
* util/bin2h.c (usage): Make --help actually explain what `grub-bin2h'
|
||||||
|
|
51
font/font.c
51
font/font.c
|
@ -26,6 +26,7 @@
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
#include <grub/video.h>
|
#include <grub/video.h>
|
||||||
#include <grub/bitmap.h>
|
#include <grub/bitmap.h>
|
||||||
|
#include <grub/fontformat.h>
|
||||||
|
|
||||||
#ifdef USE_ASCII_FAILBACK
|
#ifdef USE_ASCII_FAILBACK
|
||||||
#include "ascii.h"
|
#include "ascii.h"
|
||||||
|
@ -89,19 +90,6 @@ struct font_file_section
|
||||||
int eof;
|
int eof;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Font file format constants. */
|
|
||||||
static const char pff2_magic[4] = { 'P', 'F', 'F', '2' };
|
|
||||||
static const char section_names_file[4] = { 'F', 'I', 'L', 'E' };
|
|
||||||
static const char section_names_font_name[4] = { 'N', 'A', 'M', 'E' };
|
|
||||||
static const char section_names_point_size[4] = { 'P', 'T', 'S', 'Z' };
|
|
||||||
static const char section_names_weight[4] = { 'W', 'E', 'I', 'G' };
|
|
||||||
static const char section_names_max_char_width[4] = { 'M', 'A', 'X', 'W' };
|
|
||||||
static const char section_names_max_char_height[4] = { 'M', 'A', 'X', 'H' };
|
|
||||||
static const char section_names_ascent[4] = { 'A', 'S', 'C', 'E' };
|
|
||||||
static const char section_names_descent[4] = { 'D', 'E', 'S', 'C' };
|
|
||||||
static const char section_names_char_index[4] = { 'C', 'H', 'I', 'X' };
|
|
||||||
static const char section_names_data[4] = { 'D', 'A', 'T', 'A' };
|
|
||||||
|
|
||||||
/* Replace unknown glyphs with a rounded question mark. */
|
/* Replace unknown glyphs with a rounded question mark. */
|
||||||
static grub_uint8_t unknown_glyph_bitmap[] =
|
static grub_uint8_t unknown_glyph_bitmap[] =
|
||||||
{
|
{
|
||||||
|
@ -460,7 +448,8 @@ grub_font_load (const char *filename)
|
||||||
#if FONT_DEBUG >= 3
|
#if FONT_DEBUG >= 3
|
||||||
grub_printf("opened FILE section\n");
|
grub_printf("opened FILE section\n");
|
||||||
#endif
|
#endif
|
||||||
if (grub_memcmp (section.name, section_names_file, 4) != 0)
|
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_BAD_FONT,
|
grub_error (GRUB_ERR_BAD_FONT,
|
||||||
"font file format error: 1st section must be FILE");
|
"font file format error: 1st section must be FILE");
|
||||||
|
@ -489,7 +478,7 @@ grub_font_load (const char *filename)
|
||||||
grub_printf("read magic ok\n");
|
grub_printf("read magic ok\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (grub_memcmp (magic, pff2_magic, 4) != 0)
|
if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x",
|
grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x",
|
||||||
magic[0], magic[1], magic[2], magic[3]);
|
magic[0], magic[1], magic[2], magic[3]);
|
||||||
|
@ -529,18 +518,22 @@ grub_font_load (const char *filename)
|
||||||
section.name[2], section.name[3]);
|
section.name[2], section.name[3]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (grub_memcmp (section.name, section_names_font_name, 4) == 0)
|
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
|
||||||
{
|
{
|
||||||
font->name = read_section_as_string (§ion);
|
font->name = read_section_as_string (§ion);
|
||||||
if (!font->name)
|
if (!font->name)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_point_size, 4) == 0)
|
else if (grub_memcmp (section.name,
|
||||||
|
FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_POINT_SIZE) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (read_section_as_short (§ion, &font->point_size) != 0)
|
if (read_section_as_short (§ion, &font->point_size) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_weight, 4) == 0)
|
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1) == 0)
|
||||||
{
|
{
|
||||||
char *wt;
|
char *wt;
|
||||||
wt = read_section_as_string (§ion);
|
wt = read_section_as_string (§ion);
|
||||||
|
@ -553,32 +546,42 @@ grub_font_load (const char *filename)
|
||||||
font->weight = FONT_WEIGHT_BOLD;
|
font->weight = FONT_WEIGHT_BOLD;
|
||||||
grub_free (wt);
|
grub_free (wt);
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_max_char_width, 4) == 0)
|
else if (grub_memcmp (section.name,
|
||||||
|
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (read_section_as_short (§ion, &font->max_char_width) != 0)
|
if (read_section_as_short (§ion, &font->max_char_width) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_max_char_height, 4) == 0)
|
else if (grub_memcmp (section.name,
|
||||||
|
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (read_section_as_short (§ion, &font->max_char_height) != 0)
|
if (read_section_as_short (§ion, &font->max_char_height) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_ascent, 4) == 0)
|
else if (grub_memcmp (section.name,
|
||||||
|
FONT_FORMAT_SECTION_NAMES_ASCENT,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_ASCENT) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (read_section_as_short (§ion, &font->ascent) != 0)
|
if (read_section_as_short (§ion, &font->ascent) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_descent, 4) == 0)
|
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_DESCENT) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (read_section_as_short (§ion, &font->descent) != 0)
|
if (read_section_as_short (§ion, &font->descent) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_char_index, 4) == 0)
|
else if (grub_memcmp (section.name,
|
||||||
|
FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1) == 0)
|
||||||
{
|
{
|
||||||
if (load_font_index (file, section.length, font) != 0)
|
if (load_font_index (file, section.length, font) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (grub_memcmp (section.name, section_names_data, 4) == 0)
|
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
|
||||||
{
|
{
|
||||||
/* When the DATA section marker is reached, we stop reading. */
|
/* When the DATA section marker is reached, we stop reading. */
|
||||||
break;
|
break;
|
||||||
|
|
38
include/grub/fontformat.h
Normal file
38
include/grub/fontformat.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRUB_FONT_FORMAT_HEADER
|
||||||
|
#define GRUB_FONT_FORMAT_HEADER 1
|
||||||
|
|
||||||
|
/* FONT_FORMAT_PFF2_MAGIC use only 4 relevants bytes and the \0. */
|
||||||
|
#define FONT_FORMAT_PFF2_MAGIC "PFF2"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_FILE "FILE"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_FONT_NAME "NAME"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_POINT_SIZE "PTSZ"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_WEIGHT "WEIG"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH "MAXW"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT "MAXH"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_ASCENT "ASCE"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_DESCENT "DESC"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_CHAR_INDEX "CHIX"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_DATA "DATA"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_FAMILY "FAMI"
|
||||||
|
#define FONT_FORMAT_SECTION_NAMES_SLAN "SLAN"
|
||||||
|
|
||||||
|
#endif /* ! GRUB_FONT_FORMAT_HEADER */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
#include <grub/util/misc.h>
|
#include <grub/util/misc.h>
|
||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
|
#include <grub/fontformat.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -392,9 +393,10 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
leng = grub_cpu_to_be32 (4);
|
leng = grub_cpu_to_be32 (4);
|
||||||
grub_util_write_image ("FILE", 4, file);
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file);
|
||||||
grub_util_write_image ((char *) &leng, 4, file);
|
grub_util_write_image ((char *) &leng, 4, file);
|
||||||
grub_util_write_image ("PFF2", 4, file);
|
grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file);
|
||||||
offset += 12;
|
offset += 12;
|
||||||
|
|
||||||
if (! font_info->name)
|
if (! font_info->name)
|
||||||
|
@ -416,20 +418,25 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
|
font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
|
||||||
font_info->size);
|
font_info->size);
|
||||||
|
|
||||||
write_string_section ("NAME", font_name, &offset, file);
|
write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME,
|
||||||
write_string_section ("FAMI", font_info->name, &offset, file);
|
font_name, &offset, file);
|
||||||
write_string_section ("WEIG",
|
write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY,
|
||||||
|
font_info->name, &offset, file);
|
||||||
|
write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT,
|
||||||
(font_info->style & FT_STYLE_FLAG_BOLD) ?
|
(font_info->style & FT_STYLE_FLAG_BOLD) ?
|
||||||
"bold" : "normal",
|
"bold" : "normal",
|
||||||
&offset, file);
|
&offset, file);
|
||||||
write_string_section ("SLAN",
|
write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN,
|
||||||
(font_info->style & FT_STYLE_FLAG_ITALIC) ?
|
(font_info->style & FT_STYLE_FLAG_ITALIC) ?
|
||||||
"italic" : "normal",
|
"italic" : "normal",
|
||||||
&offset, file);
|
&offset, file);
|
||||||
|
|
||||||
write_be16_section ("PTSZ", font_info->size, &offset, file);
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
|
||||||
write_be16_section ("MAXW", font_info->max_width, &offset, file);
|
font_info->size, &offset, file);
|
||||||
write_be16_section ("MAXH", font_info->max_height, &offset, file);
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
|
||||||
|
font_info->max_width, &offset, file);
|
||||||
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
|
||||||
|
font_info->max_height, &offset, file);
|
||||||
|
|
||||||
if (! font_info->desc)
|
if (! font_info->desc)
|
||||||
{
|
{
|
||||||
|
@ -447,8 +454,10 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
font_info->asce = font_info->max_y;
|
font_info->asce = font_info->max_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_be16_section ("ASCE", font_info->asce, &offset, file);
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_ASCENT,
|
||||||
write_be16_section ("DESC", font_info->desc, &offset, file);
|
font_info->asce, &offset, file);
|
||||||
|
write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT,
|
||||||
|
font_info->desc, &offset, file);
|
||||||
|
|
||||||
if (font_verbosity > 0)
|
if (font_verbosity > 0)
|
||||||
{
|
{
|
||||||
|
@ -479,7 +488,9 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
printf ("Number of glyph: %d\n", num);
|
printf ("Number of glyph: %d\n", num);
|
||||||
|
|
||||||
leng = grub_cpu_to_be32 (num * 9);
|
leng = grub_cpu_to_be32 (num * 9);
|
||||||
grub_util_write_image ("CHIX", 4, file);
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1,
|
||||||
|
file);
|
||||||
grub_util_write_image ((char *) &leng, 4, file);
|
grub_util_write_image ((char *) &leng, 4, file);
|
||||||
offset += 8 + num * 9 + 8;
|
offset += 8 + num * 9 + 8;
|
||||||
|
|
||||||
|
@ -495,7 +506,8 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
leng = 0xffffffff;
|
leng = 0xffffffff;
|
||||||
grub_util_write_image ("DATA", 4, file);
|
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA,
|
||||||
|
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1, file);
|
||||||
grub_util_write_image ((char *) &leng, 4, file);
|
grub_util_write_image ((char *) &leng, 4, file);
|
||||||
|
|
||||||
for (cur = font_info->glyph; cur; cur = cur->next)
|
for (cur = font_info->glyph; cur; cur = cur->next)
|
||||||
|
|
Loading…
Reference in a new issue