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
61
font/font.c
61
font/font.c
|
@ -17,6 +17,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GENERATE_ASCII
|
||||
|
||||
#include <grub/bufio.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/file.h>
|
||||
|
@ -27,6 +29,10 @@
|
|||
#include <grub/video.h>
|
||||
#include <grub/bitmap.h>
|
||||
|
||||
#ifdef GENERATE_ASCII
|
||||
#include "ascii.h"
|
||||
#endif
|
||||
|
||||
#ifndef FONT_DEBUG
|
||||
#define FONT_DEBUG 0
|
||||
#endif
|
||||
|
@ -43,6 +49,7 @@ struct char_index_entry
|
|||
|
||||
#define FONT_WEIGHT_NORMAL 100
|
||||
#define FONT_WEIGHT_BOLD 200
|
||||
#define ASCII_BITMAP_SIZE 16
|
||||
|
||||
struct grub_font
|
||||
{
|
||||
|
@ -129,6 +136,48 @@ static struct grub_font null_font;
|
|||
/* Flag to ensure module is initialized only once. */
|
||||
static grub_uint8_t font_loader_initialized;
|
||||
|
||||
#ifdef GENERATE_ASCII
|
||||
static struct grub_font_glyph *ascii_font_glyph[0x80];
|
||||
#endif
|
||||
|
||||
static struct grub_font_glyph *
|
||||
ascii_glyph_lookup (grub_uint32_t code)
|
||||
{
|
||||
#ifdef GENERATE_ASCII
|
||||
static int ascii_failback_initialized = 0;
|
||||
|
||||
if (code >= 0x80)
|
||||
return unknown_glyph;
|
||||
|
||||
if (ascii_failback_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;
|
||||
|
||||
grub_memcpy (ascii_font_glyph[current]->bitmap,
|
||||
&ascii_bitmaps[(0x7f - current) * ASCII_BITMAP_SIZE],
|
||||
ASCII_BITMAP_SIZE);
|
||||
}
|
||||
|
||||
ascii_failback_initialized = 1;
|
||||
}
|
||||
|
||||
return ascii_font_glyph[code];
|
||||
#else
|
||||
(void) code;
|
||||
return unknown_glyph;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
grub_font_loader_init (void)
|
||||
{
|
||||
|
@ -865,15 +914,17 @@ grub_font_get_string_width (grub_font_t font, const char *str)
|
|||
}
|
||||
|
||||
/* Get the glyph for FONT corresponding to the Unicode code point CODE.
|
||||
Returns a pointer to an glyph indicating there is no glyph available
|
||||
if CODE does not exist in the font. The glyphs are cached once loaded. */
|
||||
Returns the ASCII glyph for the code if no other fonts are available.
|
||||
The glyphs are cached once loaded. */
|
||||
struct grub_font_glyph *
|
||||
grub_font_get_glyph (grub_font_t font, grub_uint32_t code)
|
||||
{
|
||||
struct grub_font_glyph *glyph;
|
||||
glyph = grub_font_get_glyph_internal (font, code);
|
||||
if (glyph == 0)
|
||||
glyph = unknown_glyph;
|
||||
{
|
||||
glyph = ascii_glyph_lookup (code);
|
||||
}
|
||||
return glyph;
|
||||
}
|
||||
|
||||
|
@ -968,8 +1019,8 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code)
|
|||
if (best_glyph)
|
||||
return best_glyph;
|
||||
else
|
||||
/* Glyph not available in any font. Return unknown glyph. */
|
||||
return unknown_glyph;
|
||||
/* Glyph not available in any font. Return ASCII failback. */
|
||||
return ascii_glyph_lookup (code);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue