From: Vladimir Serbinenko Date: Sat, 7 Dec 2013 12:59:15 +0000 (+0100) Subject: Include arrows and lines in ascii.h X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67a51e8e151a58d8a1ca41da7bef9032f942eff8;p=thirdparty%2Fgrub.git Include arrows and lines in ascii.h --- diff --git a/grub-core/font/font.c b/grub-core/font/font.c index 14b93e172..d47f70a13 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -111,42 +111,64 @@ static struct grub_font null_font; static grub_uint8_t font_loader_initialized; #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 static struct grub_font_glyph * ascii_glyph_lookup (grub_uint32_t code) { #if HAVE_FONT_SOURCE - static int ascii_failback_initialized = 0; - - if (code >= 0x80) + static int ascii_fallback_initialized = 0; + struct grub_font_glyph **p; + + 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; - if (ascii_failback_initialized == 0) + if (ascii_fallback_initialized == 0) { - int current; - for (current = 0; current < 0x80; current++) - { - ascii_font_glyph[current] = - 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; + init_fallback (ascii_font_glyph, ascii_bitmaps, ASCII_NUM); + init_fallback (arrows_font_glyph, arrows_bitmaps, ARROWS_NUM); + init_fallback (lines_font_glyph, lines_bitmaps, LINES_NUM); + ascii_fallback_initialized = 1; } - return ascii_font_glyph[code]; + return *p; #else (void) code; return NULL; diff --git a/util/grub-gen-asciih.c b/util/grub-gen-asciih.c index e01447ae9..3e3154bcd 100644 --- a/util/grub-gen-asciih.c +++ b/util/grub-gen-asciih.c @@ -126,61 +126,90 @@ add_glyph (FT_UInt glyph_idx, FT_Face face, } static void -write_font_ascii_bitmap (FILE *file, FT_Face face) +write_code (FILE *file, FT_Face face, unsigned int char_code) { + FT_UInt glyph_idx; 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"); + glyph_idx = FT_Get_Char_Index (face, char_code); + if (!glyph_idx) + { + fprintf (stderr, "grub-gen-asciih: error: couldn't retrieve code %x", + (unsigned) char_code); + exit (1); + } + add_glyph (glyph_idx, face, char_code, &glyph); - for (char_code = 0; char_code <= 0x7f; char_code++) + if (glyph.width == 8 && glyph.height == 16 + && glyph.x_ofs == 0 && glyph.y_ofs == 0) { - FT_UInt glyph_idx; - - glyph_idx = FT_Get_Char_Index (face, char_code); - if (!glyph_idx) - return; - add_glyph (glyph_idx, face, char_code, &glyph); - - if (glyph.width == 8 && glyph.height == 16 - && glyph.x_ofs == 0 && glyph.y_ofs == 0) - { - int row; - for (row = 0; row < 16; row++) - fprintf (file, "0x%02x, ", glyph.bitmap[row]); - } - else - { - unsigned char glph[16]; - int p = 0, mask = 0x80; - int row, col; - int dy = 12 - glyph.height - glyph.y_ofs; - for (row = 0; row < 16; row++) - glph[row] = 0; - for (row = 0; row < glyph.height; row++) - for (col = 0; col < glyph.width; col++) + int row; + for (row = 0; row < 16; row++) + fprintf (file, "0x%02x, ", glyph.bitmap[row]); + } + else + { + unsigned char glph[16]; + int p = 0, mask = 0x80; + int row, col; + int dy = 12 - glyph.height - glyph.y_ofs; + for (row = 0; row < 16; row++) + glph[row] = 0; + for (row = 0; row < glyph.height; row++) + for (col = 0; col < glyph.width; col++) + { + int val = glyph.bitmap[p] & mask; + mask >>= 1; + if (mask == 0) { - int val = glyph.bitmap[p] & mask; - mask >>= 1; - if (mask == 0) - { - mask = 0x80; - p++; - } - if (val && dy + row >= 0 - && dy + row < 16 - && glyph.x_ofs + col >= 0 - && glyph.x_ofs + col < 8) - glph[dy + row] |= 1 << (7 - (glyph.x_ofs + col)); + mask = 0x80; + p++; } - for (row = 0; row < 16; row++) - fprintf (file, "0x%02x, ", glph[row]); - } - fprintf (file, "\n"); - free (glyph.bitmap); + if (val && dy + row >= 0 + && dy + row < 16 + && glyph.x_ofs + col >= 0 + && glyph.x_ofs + col < 8) + glph[dy + row] |= 1 << (7 - (glyph.x_ofs + col)); + } + for (row = 0; row < 16; row++) + fprintf (file, "0x%02x, ", glph[row]); } + fprintf (file, "\n"); + 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"); }