merge mainline into bmpidx
This commit is contained in:
commit
e6d5d6e624
454 changed files with 22976 additions and 8798 deletions
79
font/font.c
79
font/font.c
|
@ -1,7 +1,7 @@
|
|||
/* font.c - Font API and font file loader. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2003,2005,2006,2007,2008,2009,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
|
||||
|
@ -27,6 +27,10 @@
|
|||
#include <grub/video.h>
|
||||
#include <grub/bitmap.h>
|
||||
|
||||
#ifdef USE_ASCII_FAILBACK
|
||||
#include "ascii.h"
|
||||
#endif
|
||||
|
||||
#ifndef FONT_DEBUG
|
||||
#define FONT_DEBUG 0
|
||||
#endif
|
||||
|
@ -43,6 +47,7 @@ struct char_index_entry
|
|||
|
||||
#define FONT_WEIGHT_NORMAL 100
|
||||
#define FONT_WEIGHT_BOLD 200
|
||||
#define ASCII_BITMAP_SIZE 16
|
||||
|
||||
struct grub_font
|
||||
{
|
||||
|
@ -130,6 +135,48 @@ static struct grub_font null_font;
|
|||
/* Flag to ensure module is initialized only once. */
|
||||
static grub_uint8_t font_loader_initialized;
|
||||
|
||||
#ifdef USE_ASCII_FAILBACK
|
||||
static struct grub_font_glyph *ascii_font_glyph[0x80];
|
||||
#endif
|
||||
|
||||
static struct grub_font_glyph *
|
||||
ascii_glyph_lookup (grub_uint32_t code)
|
||||
{
|
||||
#ifdef USE_ASCII_FAILBACK
|
||||
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)
|
||||
{
|
||||
|
@ -212,7 +259,7 @@ open_section (grub_file_t file, struct font_file_section *section)
|
|||
else if (retval < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font format error: can't read section name");
|
||||
"font format error: can't read section name");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -227,7 +274,7 @@ open_section (grub_file_t file, struct font_file_section *section)
|
|||
else if (retval < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font format error: can't read section length");
|
||||
"font format error: can't read section length");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -261,7 +308,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
|
|||
if ((sect_length % FONT_CHAR_INDEX_ENTRY_SIZE) != 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font file format error: character index length %d "
|
||||
"font file format error: character index length %d "
|
||||
"is not a multiple of the entry size %d",
|
||||
sect_length, FONT_CHAR_INDEX_ENTRY_SIZE);
|
||||
return 1;
|
||||
|
@ -304,7 +351,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
|
|||
if (i != 0 && entry->code <= last_code)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font characters not in ascending order: %u <= %u",
|
||||
"font characters not in ascending order: %u <= %u",
|
||||
entry->code, last_code);
|
||||
return 1;
|
||||
}
|
||||
|
@ -370,7 +417,7 @@ read_section_as_short (struct font_file_section *section, grub_int16_t *value)
|
|||
if (section->length != 2)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font file format error: section %c%c%c%c length "
|
||||
"font file format error: section %c%c%c%c length "
|
||||
"is %d but should be 2",
|
||||
section->name[0], section->name[1],
|
||||
section->name[2], section->name[3],
|
||||
|
@ -416,7 +463,7 @@ grub_font_load (const char *filename)
|
|||
if (grub_memcmp (section.name, section_names_file, 4) != 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font file format error: 1st section must be FILE");
|
||||
"font file format error: 1st section must be FILE");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -426,7 +473,7 @@ grub_font_load (const char *filename)
|
|||
if (section.length != 4)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Font file format error (file type ID length is %d "
|
||||
"font file format error (file type ID length is %d "
|
||||
"but should be 4)", section.length);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -444,7 +491,7 @@ grub_font_load (const char *filename)
|
|||
|
||||
if (grub_memcmp (magic, 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]);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -571,7 +618,7 @@ grub_font_load (const char *filename)
|
|||
|| font->descent == 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"Invalid font file: missing some required data.");
|
||||
"invalid font file: missing some required data");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -887,15 +934,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;
|
||||
}
|
||||
|
||||
|
@ -990,8 +1039,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