Index of BMP for faster font lookup
This commit is contained in:
parent
dc9837ea5f
commit
f9e4ed6a45
1 changed files with 24 additions and 2 deletions
26
font/font.c
26
font/font.c
|
@ -58,6 +58,7 @@ struct grub_font
|
||||||
short leading;
|
short leading;
|
||||||
grub_uint32_t num_chars;
|
grub_uint32_t num_chars;
|
||||||
struct char_index_entry *char_index;
|
struct char_index_entry *char_index;
|
||||||
|
grub_uint16_t *bmp_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Definition of font registry. */
|
/* Definition of font registry. */
|
||||||
|
@ -180,6 +181,7 @@ font_init (grub_font_t font)
|
||||||
font->descent = 0;
|
font->descent = 0;
|
||||||
font->num_chars = 0;
|
font->num_chars = 0;
|
||||||
font->char_index = 0;
|
font->char_index = 0;
|
||||||
|
font->bmp_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the next section in the file.
|
/* Open the next section in the file.
|
||||||
|
@ -273,6 +275,14 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
|
||||||
* sizeof (struct char_index_entry));
|
* sizeof (struct char_index_entry));
|
||||||
if (! font->char_index)
|
if (! font->char_index)
|
||||||
return 1;
|
return 1;
|
||||||
|
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
|
||||||
|
if (! font->bmp_idx)
|
||||||
|
{
|
||||||
|
grub_free (font->char_index);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));
|
||||||
|
|
||||||
|
|
||||||
#if FONT_DEBUG >= 2
|
#if FONT_DEBUG >= 2
|
||||||
grub_printf("num_chars=%d)\n", font->num_chars);
|
grub_printf("num_chars=%d)\n", font->num_chars);
|
||||||
|
@ -299,6 +309,9 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry->code < 0x10000)
|
||||||
|
font->bmp_idx[entry->code] = i;
|
||||||
|
|
||||||
last_code = entry->code;
|
last_code = entry->code;
|
||||||
|
|
||||||
/* Read storage flags byte. */
|
/* Read storage flags byte. */
|
||||||
|
@ -594,7 +607,7 @@ read_be_int16 (grub_file_t file, grub_int16_t * value)
|
||||||
|
|
||||||
/* Return a pointer to the character index entry for the glyph corresponding to
|
/* Return a pointer to the character index entry for the glyph corresponding to
|
||||||
the codepoint CODE in the font FONT. If not found, return zero. */
|
the codepoint CODE in the font FONT. If not found, return zero. */
|
||||||
static struct char_index_entry *
|
static inline struct char_index_entry *
|
||||||
find_glyph (const grub_font_t font, grub_uint32_t code)
|
find_glyph (const grub_font_t font, grub_uint32_t code)
|
||||||
{
|
{
|
||||||
struct char_index_entry *table;
|
struct char_index_entry *table;
|
||||||
|
@ -602,8 +615,17 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
|
||||||
grub_size_t hi;
|
grub_size_t hi;
|
||||||
grub_size_t mid;
|
grub_size_t mid;
|
||||||
|
|
||||||
/* Do a binary search in `char_index', which is ordered by code point. */
|
|
||||||
table = font->char_index;
|
table = font->char_index;
|
||||||
|
|
||||||
|
/* Use BMP index if possible. */
|
||||||
|
if (code < 0x10000)
|
||||||
|
{
|
||||||
|
if (font->bmp_idx[code] == 0xffff)
|
||||||
|
return 0;
|
||||||
|
return &table[font->bmp_idx[code]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do a binary search in `char_index', which is ordered by code point. */
|
||||||
lo = 0;
|
lo = 0;
|
||||||
hi = font->num_chars - 1;
|
hi = font->num_chars - 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue