Compare commits

...
Author SHA1 Message Date
Vladimir Serbinenko 67a51e8e15 Include arrows and lines in ascii.h 2013-12-07 13:59:15 +01:00
2 changed files with 86 additions and 35 deletions

No files matched your search

+46 -24
View File
@@ -111,42 +111,64 @@ static struct grub_font null_font;
static grub_uint8_t font_loader_initialized; static grub_uint8_t font_loader_initialized;
#if HAVE_FONT_SOURCE #if HAVE_FONT_SOURCE
static struct grub_font_glyph *ascii_font_glyph[0x80]; static struct grub_font_glyph *ascii_font_glyph[ASCII_NUM];
static struct grub_font_glyph *arrows_font_glyph[ARROWS_NUM];
static struct grub_font_glyph *lines_font_glyph[LINES_NUM];
static void
init_fallback (struct grub_font_glyph **glyphs, const unsigned char *stored,
grub_uint32_t len)
{
grub_uint32_t current;
for (current = 0; current < len; current++)
{
glyphs[current] =
grub_malloc (sizeof (struct grub_font_glyph) + ASCII_BITMAP_SIZE);
if (!glyphs[current])
{
grub_errno = GRUB_ERR_NONE;
continue;
}
glyphs[current]->width = 8;
glyphs[current]->height = 16;
glyphs[current]->offset_x = 0;
glyphs[current]->offset_y = -2;
glyphs[current]->device_width = 8;
glyphs[current]->font = NULL;
grub_memcpy (glyphs[current]->bitmap,
&stored[current * ASCII_BITMAP_SIZE],
ASCII_BITMAP_SIZE);
}
}
#endif #endif
static struct grub_font_glyph * static struct grub_font_glyph *
ascii_glyph_lookup (grub_uint32_t code) ascii_glyph_lookup (grub_uint32_t code)
{ {
#if HAVE_FONT_SOURCE #if HAVE_FONT_SOURCE
static int ascii_failback_initialized = 0; static int ascii_fallback_initialized = 0;
struct grub_font_glyph **p;
if (code >= 0x80) if (code < ASCII_NUM)
p = &ascii_font_glyph[code];
else if (code >= ARROWS_START && code < ARROWS_START + ARROWS_NUM)
p = &arrows_font_glyph[code - ARROWS_START];
else if (code >= LINES_START && code < LINES_START + LINES_NUM)
p = &lines_font_glyph[code - LINES_START];
else
return NULL; return NULL;
if (ascii_failback_initialized == 0) if (ascii_fallback_initialized == 0)
{ {
int current; init_fallback (ascii_font_glyph, ascii_bitmaps, ASCII_NUM);
for (current = 0; current < 0x80; current++) init_fallback (arrows_font_glyph, arrows_bitmaps, ARROWS_NUM);
{ init_fallback (lines_font_glyph, lines_bitmaps, LINES_NUM);
ascii_font_glyph[current] = ascii_fallback_initialized = 1;
grub_malloc (sizeof (struct grub_font_glyph) + ASCII_BITMAP_SIZE);
ascii_font_glyph[current]->width = 8;
ascii_font_glyph[current]->height = 16;
ascii_font_glyph[current]->offset_x = 0;
ascii_font_glyph[current]->offset_y = -2;
ascii_font_glyph[current]->device_width = 8;
ascii_font_glyph[current]->font = NULL;
grub_memcpy (ascii_font_glyph[current]->bitmap,
&ascii_bitmaps[current * ASCII_BITMAP_SIZE],
ASCII_BITMAP_SIZE);
} }
ascii_failback_initialized = 1; return *p;
}
return ascii_font_glyph[code];
#else #else
(void) code; (void) code;
return NULL; return NULL;
+40 -11
View File
@@ -126,22 +126,18 @@ add_glyph (FT_UInt glyph_idx, FT_Face face,
} }
static void static void
write_font_ascii_bitmap (FILE *file, FT_Face face) write_code (FILE *file, FT_Face face, unsigned int char_code)
{
struct grub_glyph_info glyph;
int char_code;
fprintf (file, "/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n");
fprintf (file, "unsigned char ascii_bitmaps[] =\n");
fprintf (file, "{\n");
for (char_code = 0; char_code <= 0x7f; char_code++)
{ {
FT_UInt glyph_idx; FT_UInt glyph_idx;
struct grub_glyph_info glyph;
glyph_idx = FT_Get_Char_Index (face, char_code); glyph_idx = FT_Get_Char_Index (face, char_code);
if (!glyph_idx) if (!glyph_idx)
return; {
fprintf (stderr, "grub-gen-asciih: error: couldn't retrieve code %x",
(unsigned) char_code);
exit (1);
}
add_glyph (glyph_idx, face, char_code, &glyph); add_glyph (glyph_idx, face, char_code, &glyph);
if (glyph.width == 8 && glyph.height == 16 if (glyph.width == 8 && glyph.height == 16
@@ -181,6 +177,39 @@ write_font_ascii_bitmap (FILE *file, FT_Face face)
fprintf (file, "\n"); fprintf (file, "\n");
free (glyph.bitmap); free (glyph.bitmap);
} }
static void
write_font_ascii_bitmap (FILE *file, FT_Face face)
{
int char_code;
fprintf (file, "/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n");
fprintf (file, "#define ASCII_START 0\n");
fprintf (file, "#define ASCII_NUM 128\n");
fprintf (file, "static unsigned char ascii_bitmaps[] =\n");
fprintf (file, "{\n");
for (char_code = 0; char_code <= 0x7f; char_code++)
write_code (file, face, char_code);
fprintf (file, "};\n");
fprintf (file, "#define ARROWS_START 0x2190\n");
fprintf (file, "#define ARROWS_NUM 4\n");
fprintf (file, "static unsigned char arrows_bitmaps[] =\n");
fprintf (file, "{\n");
for (char_code = 0x2190; char_code <= 0x2193; char_code++)
write_code (file, face, char_code);
fprintf (file, "};\n");
fprintf (file, "#define LINES_START 0x2501\n");
fprintf (file, "#define LINES_NUM 0x1b\n");
fprintf (file, "static unsigned char lines_bitmaps[] =\n");
fprintf (file, "{\n");
for (char_code = 0x2501; char_code <= 0x251b; char_code++)
write_code (file, face, char_code);
fprintf (file, "};\n"); fprintf (file, "};\n");
} }