* font/font.c: Indented.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-04-09 19:38:23 +02:00
parent 7d65244782
commit 1118c32ec7
2 changed files with 233 additions and 233 deletions

View file

@ -1,3 +1,7 @@
2010-04-09 Vladimir Serbinenko <phcoder@gmail.com>
* font/font.c: Indented.
2010-04-09 BVK Chaitanya <bvk.groups@gmail.com>
Elif support to GRUB script (by Deepak Vankadaru).

View file

@ -91,25 +91,24 @@ struct font_file_section
};
/* Replace unknown glyphs with a rounded question mark. */
static grub_uint8_t unknown_glyph_bitmap[] =
{
/* 76543210 */
0x7C, /* ooooo */
0x82, /* o o */
0xBA, /* o ooo o */
0xAA, /* o o o o */
0xAA, /* o o o o */
0x8A, /* o o o */
0x9A, /* o oo o */
0x92, /* o o o */
0x92, /* o o o */
0x92, /* o o o */
0x92, /* o o o */
0x82, /* o o */
0x92, /* o o o */
0x82, /* o o */
0x7C, /* ooooo */
0x00 /* */
static grub_uint8_t unknown_glyph_bitmap[] = {
/* 76543210 */
0x7C, /* ooooo */
0x82, /* o o */
0xBA, /* o ooo o */
0xAA, /* o o o o */
0xAA, /* o o o o */
0x8A, /* o o o */
0x9A, /* o oo o */
0x92, /* o o o */
0x92, /* o o o */
0x92, /* o o o */
0x92, /* o o o */
0x82, /* o o */
0x92, /* o o o */
0x82, /* o o */
0x7C, /* ooooo */
0x00 /* */
};
/* The "unknown glyph" glyph, used as a last resort. */
@ -130,7 +129,7 @@ static struct grub_font_glyph *ascii_font_glyph[0x80];
static struct grub_font_glyph *
ascii_glyph_lookup (grub_uint32_t code)
{
#ifdef USE_ASCII_FAILBACK
#ifdef USE_ASCII_FAILBACK
static int ascii_failback_initialized = 0;
if (code >= 0x80)
@ -140,14 +139,14 @@ ascii_glyph_lookup (grub_uint32_t code)
{
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] =
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]->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,
@ -173,9 +172,9 @@ grub_font_loader_init (void)
return;
/* Make glyph for unknown glyph. */
unknown_glyph = grub_malloc(sizeof(struct grub_font_glyph)
+ sizeof(unknown_glyph_bitmap));
if (! unknown_glyph)
unknown_glyph = grub_malloc (sizeof (struct grub_font_glyph)
+ sizeof (unknown_glyph_bitmap));
if (!unknown_glyph)
return;
unknown_glyph->width = 8;
@ -183,13 +182,13 @@ grub_font_loader_init (void)
unknown_glyph->offset_x = 0;
unknown_glyph->offset_y = -3;
unknown_glyph->device_width = 8;
grub_memcpy(unknown_glyph->bitmap,
unknown_glyph_bitmap, sizeof(unknown_glyph_bitmap));
grub_memcpy (unknown_glyph->bitmap,
unknown_glyph_bitmap, sizeof (unknown_glyph_bitmap));
/* Initialize the null font. */
font_init (&null_font);
null_font.name = "<No Font>";
null_font.ascent = unknown_glyph->height-3;
null_font.ascent = unknown_glyph->height - 3;
null_font.descent = 3;
null_font.max_char_width = unknown_glyph->width;
null_font.max_char_height = unknown_glyph->height;
@ -247,7 +246,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;
}
@ -262,7 +261,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;
}
@ -283,22 +282,22 @@ open_section (grub_file_t file, struct font_file_section *section)
grub_errno is set appropriately). */
static int
load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
grub_font *font)
grub_font *font)
{
unsigned i;
grub_uint32_t last_code;
#if FONT_DEBUG >= 2
grub_printf("load_font_index(sect_length=%d)\n", sect_length);
grub_printf ("load_font_index(sect_length=%d)\n", sect_length);
#endif
/* Sanity check: ensure section length is divisible by the entry size. */
if ((sect_length % FONT_CHAR_INDEX_ENTRY_SIZE) != 0)
{
grub_error (GRUB_ERR_BAD_FONT,
"font file format error: character index length %d "
"is not a multiple of the entry size %d",
sect_length, FONT_CHAR_INDEX_ENTRY_SIZE);
"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;
}
@ -307,11 +306,11 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
/* Allocate the character index array. */
font->char_index = grub_malloc (font->num_chars
* sizeof (struct char_index_entry));
if (! font->char_index)
* sizeof (struct char_index_entry));
if (!font->char_index)
return 1;
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
if (! font->bmp_idx)
if (!font->bmp_idx)
{
grub_free (font->char_index);
return 1;
@ -320,7 +319,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
#if FONT_DEBUG >= 2
grub_printf("num_chars=%d)\n", font->num_chars);
grub_printf ("num_chars=%d)\n", font->num_chars);
#endif
last_code = 0;
@ -332,17 +331,17 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
/* Read code point value; convert to native byte order. */
if (grub_file_read (file, &entry->code, 4) != 4)
return 1;
return 1;
entry->code = grub_be_to_cpu32 (entry->code);
/* Verify that characters are in ascending order. */
if (i != 0 && entry->code <= last_code)
{
grub_error (GRUB_ERR_BAD_FONT,
"font characters not in ascending order: %u <= %u",
entry->code, last_code);
return 1;
}
{
grub_error (GRUB_ERR_BAD_FONT,
"font characters not in ascending order: %u <= %u",
entry->code, last_code);
return 1;
}
if (entry->code < 0x10000)
font->bmp_idx[entry->code] = i;
@ -351,11 +350,11 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
/* Read storage flags byte. */
if (grub_file_read (file, &entry->storage_flags, 1) != 1)
return 1;
return 1;
/* Read glyph data offset; convert to native byte order. */
if (grub_file_read (file, &entry->offset, 4) != 4)
return 1;
return 1;
entry->offset = grub_be_to_cpu32 (entry->offset);
/* No glyph loaded. Will be loaded on demand and cached thereafter. */
@ -364,7 +363,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
#if FONT_DEBUG >= 5
/* Print the 1st 10 characters. */
if (i < 10)
grub_printf("c=%d o=%d\n", entry->code, entry->offset);
grub_printf ("c=%d o=%d\n", entry->code, entry->offset);
#endif
}
@ -380,7 +379,7 @@ read_section_as_string (struct font_file_section *section)
grub_ssize_t ret;
str = grub_malloc (section->length + 1);
if (! str)
if (!str)
return 0;
ret = grub_file_read (section->file, str, section->length);
@ -398,18 +397,18 @@ read_section_as_string (struct font_file_section *section)
which is stored into *VALUE.
Returns 0 upon success, nonzero upon failure. */
static int
read_section_as_short (struct font_file_section *section, grub_int16_t *value)
read_section_as_short (struct font_file_section *section,
grub_int16_t * value)
{
grub_uint16_t raw_value;
if (section->length != 2)
{
grub_error (GRUB_ERR_BAD_FONT,
"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],
section->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], section->length);
return 1;
}
if (grub_file_read (section->file, &raw_value, 2) != 2)
@ -430,7 +429,7 @@ grub_font_load (const char *filename)
grub_font_t font = 0;
#if FONT_DEBUG >= 1
grub_printf("add_font(%s)\n", filename);
grub_printf ("add_font(%s)\n", filename);
#endif
file = grub_buffile_open (filename, 1024);
@ -438,7 +437,7 @@ grub_font_load (const char *filename)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("file opened\n");
grub_printf ("file opened\n");
#endif
/* Read the FILE section. It indicates the file format. */
@ -446,159 +445,166 @@ grub_font_load (const char *filename)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("opened FILE section\n");
grub_printf ("opened FILE section\n");
#endif
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE,
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0)
sizeof (FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 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;
}
#if FONT_DEBUG >= 3
grub_printf("section name ok\n");
grub_printf ("section name ok\n");
#endif
if (section.length != 4)
{
grub_error (GRUB_ERR_BAD_FONT,
"font file format error (file type ID length is %d "
"but should be 4)", section.length);
"font file format error (file type ID length is %d "
"but should be 4)", section.length);
goto fail;
}
#if FONT_DEBUG >= 3
grub_printf("section length ok\n");
grub_printf ("section length ok\n");
#endif
/* Check the file format type code. */
if (grub_file_read (file, magic, 4) != 4)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("read magic ok\n");
grub_printf ("read magic ok\n");
#endif
if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0)
{
grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x",
magic[0], magic[1], magic[2], magic[3]);
magic[0], magic[1], magic[2], magic[3]);
goto fail;
}
#if FONT_DEBUG >= 3
grub_printf("compare magic ok\n");
grub_printf ("compare magic ok\n");
#endif
/* Allocate the font object. */
font = (grub_font_t) grub_malloc (sizeof (struct grub_font));
if (! font)
if (!font)
goto fail;
font_init (font);
font->file = file;
#if FONT_DEBUG >= 3
grub_printf("allocate font ok; loading font info\n");
grub_printf ("allocate font ok; loading font info\n");
#endif
/* Load the font information. */
while (1)
{
if (open_section (file, &section) != 0)
{
if (section.eof)
break; /* Done reading the font file. */
else
goto fail;
}
{
if (section.eof)
break; /* Done reading the font file. */
else
goto fail;
}
#if FONT_DEBUG >= 2
grub_printf("opened section %c%c%c%c ok\n",
section.name[0], section.name[1],
section.name[2], section.name[3]);
grub_printf ("opened section %c%c%c%c ok\n",
section.name[0], section.name[1],
section.name[2], section.name[3]);
#endif
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME,
sizeof(FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
{
font->name = read_section_as_string (&section);
if (!font->name)
goto fail;
}
sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
{
font->name = read_section_as_string (&section);
if (!font->name)
goto fail;
}
else if (grub_memcmp (section.name,
FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
sizeof(FONT_FORMAT_SECTION_NAMES_POINT_SIZE) - 1) == 0)
{
if (read_section_as_short (&section, &font->point_size) != 0)
goto fail;
}
FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
sizeof (FONT_FORMAT_SECTION_NAMES_POINT_SIZE) -
1) == 0)
{
if (read_section_as_short (&section, &font->point_size) != 0)
goto fail;
}
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT,
sizeof(FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1) == 0)
{
char *wt;
wt = read_section_as_string (&section);
if (!wt)
continue;
/* Convert the weight string 'normal' or 'bold' into a number. */
if (grub_strcmp (wt, "normal") == 0)
font->weight = FONT_WEIGHT_NORMAL;
else if (grub_strcmp (wt, "bold") == 0)
font->weight = FONT_WEIGHT_BOLD;
grub_free (wt);
}
sizeof (FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1)
== 0)
{
char *wt;
wt = read_section_as_string (&section);
if (!wt)
continue;
/* Convert the weight string 'normal' or 'bold' into a number. */
if (grub_strcmp (wt, "normal") == 0)
font->weight = FONT_WEIGHT_NORMAL;
else if (grub_strcmp (wt, "bold") == 0)
font->weight = FONT_WEIGHT_BOLD;
grub_free (wt);
}
else if (grub_memcmp (section.name,
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH) - 1) == 0)
{
if (read_section_as_short (&section, &font->max_char_width) != 0)
goto fail;
}
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH)
- 1) == 0)
{
if (read_section_as_short (&section, &font->max_char_width) != 0)
goto fail;
}
else if (grub_memcmp (section.name,
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT) - 1) == 0)
{
if (read_section_as_short (&section, &font->max_char_height) != 0)
goto fail;
}
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT)
- 1) == 0)
{
if (read_section_as_short (&section, &font->max_char_height) != 0)
goto fail;
}
else if (grub_memcmp (section.name,
FONT_FORMAT_SECTION_NAMES_ASCENT,
sizeof(FONT_FORMAT_SECTION_NAMES_ASCENT) - 1) == 0)
{
if (read_section_as_short (&section, &font->ascent) != 0)
goto fail;
}
FONT_FORMAT_SECTION_NAMES_ASCENT,
sizeof (FONT_FORMAT_SECTION_NAMES_ASCENT) - 1)
== 0)
{
if (read_section_as_short (&section, &font->ascent) != 0)
goto fail;
}
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT,
sizeof(FONT_FORMAT_SECTION_NAMES_DESCENT) - 1) == 0)
{
if (read_section_as_short (&section, &font->descent) != 0)
goto fail;
}
sizeof (FONT_FORMAT_SECTION_NAMES_DESCENT) - 1)
== 0)
{
if (read_section_as_short (&section, &font->descent) != 0)
goto fail;
}
else if (grub_memcmp (section.name,
FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1) == 0)
{
if (load_font_index (file, section.length, font) != 0)
goto fail;
}
FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
sizeof (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) -
1) == 0)
{
if (load_font_index (file, section.length, font) != 0)
goto fail;
}
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA,
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
{
/* When the DATA section marker is reached, we stop reading. */
break;
}
sizeof (FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
{
/* When the DATA section marker is reached, we stop reading. */
break;
}
else
{
/* Unhandled section type, simply skip past it. */
{
/* Unhandled section type, simply skip past it. */
#if FONT_DEBUG >= 3
grub_printf("Unhandled section type, skipping.\n");
grub_printf ("Unhandled section type, skipping.\n");
#endif
grub_off_t section_end = grub_file_tell (file) + section.length;
if ((int) grub_file_seek (file, section_end) == -1)
goto fail;
}
grub_off_t section_end = grub_file_tell (file) + section.length;
if ((int) grub_file_seek (file, section_end) == -1)
goto fail;
}
}
if (! font->name)
if (!font->name)
{
grub_printf ("Note: Font has no name.\n");
font->name = grub_strdup ("Unknown");
@ -606,22 +612,19 @@ grub_font_load (const char *filename)
#if FONT_DEBUG >= 1
grub_printf ("Loaded font `%s'.\n"
"Ascent=%d Descent=%d MaxW=%d MaxH=%d Number of characters=%d.\n",
font->name,
font->ascent, font->descent,
font->max_char_width, font->max_char_height,
font->num_chars);
"Ascent=%d Descent=%d MaxW=%d MaxH=%d Number of characters=%d.\n",
font->name,
font->ascent, font->descent,
font->max_char_width, font->max_char_height, font->num_chars);
#endif
if (font->max_char_width == 0
|| font->max_char_height == 0
|| font->num_chars == 0
|| font->char_index == 0
|| font->ascent == 0
|| font->descent == 0)
|| font->char_index == 0 || font->ascent == 0 || 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;
}
@ -679,18 +682,18 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
lo = 0;
hi = font->num_chars - 1;
if (! table)
if (!table)
return 0;
while (lo <= hi)
{
mid = lo + (hi - lo) / 2;
if (code < table[mid].code)
hi = mid - 1;
hi = mid - 1;
else if (code > table[mid].code)
lo = mid + 1;
lo = mid + 1;
else
return &table[mid];
return &table[mid];
}
return 0;
@ -716,12 +719,12 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
int len;
if (index_entry->glyph)
/* Return cached glyph. */
return index_entry->glyph;
/* Return cached glyph. */
return index_entry->glyph;
if (! font->file)
/* No open file, can't load any glyphs. */
return 0;
if (!font->file)
/* No open file, can't load any glyphs. */
return 0;
/* Make sure we can find glyphs for error messages. Push active
error message to error stack and reset error message. */
@ -730,23 +733,23 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
grub_file_seek (font->file, index_entry->offset);
/* Read the glyph width, height, and baseline. */
if (read_be_uint16(font->file, &width) != 0
|| read_be_uint16(font->file, &height) != 0
|| read_be_int16(font->file, &xoff) != 0
|| read_be_int16(font->file, &yoff) != 0
|| read_be_int16(font->file, &dwidth) != 0)
{
remove_font (font);
return 0;
}
if (read_be_uint16 (font->file, &width) != 0
|| read_be_uint16 (font->file, &height) != 0
|| read_be_int16 (font->file, &xoff) != 0
|| read_be_int16 (font->file, &yoff) != 0
|| read_be_int16 (font->file, &dwidth) != 0)
{
remove_font (font);
return 0;
}
len = (width * height + 7) / 8;
glyph = grub_malloc (sizeof (struct grub_font_glyph) + len);
if (! glyph)
{
remove_font (font);
return 0;
}
if (!glyph)
{
remove_font (font);
return 0;
}
glyph->font = font;
glyph->width = width;
@ -757,13 +760,13 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
/* Don't try to read empty bitmaps (e.g., space characters). */
if (len != 0)
{
if (grub_file_read (font->file, glyph->bitmap, len) != len)
{
remove_font (font);
return 0;
}
}
{
if (grub_file_read (font->file, glyph->bitmap, len) != len)
{
remove_font (font);
return 0;
}
}
/* Restore old error message. */
grub_error_pop ();
@ -787,7 +790,7 @@ free_font (grub_font_t font)
if (font)
{
if (font->file)
grub_file_close (font->file);
grub_file_close (font->file);
grub_free (font->name);
grub_free (font->family);
grub_free (font->char_index);
@ -804,7 +807,7 @@ register_font (grub_font_t font)
struct grub_font_node *node = 0;
node = grub_malloc (sizeof (struct grub_font_node));
if (! node)
if (!node)
return 1;
node->value = font;
@ -822,18 +825,17 @@ remove_font (grub_font_t font)
struct grub_font_node **nextp, *cur;
for (nextp = &grub_font_list, cur = *nextp;
cur;
nextp = &cur->next, cur = cur->next)
cur; nextp = &cur->next, cur = cur->next)
{
if (cur->value == font)
{
*nextp = cur->next;
{
*nextp = cur->next;
/* Free the node, but not the font itself. */
grub_free (cur);
/* Free the node, but not the font itself. */
grub_free (cur);
return;
}
return;
}
}
}
@ -850,7 +852,7 @@ grub_font_get (const char *font_name)
{
grub_font_t font = node->value;
if (grub_strcmp (font->name, font_name) == 0)
return font;
return font;
}
/* If no font by that name is found, return the first font in the list
@ -927,7 +929,7 @@ grub_font_get_string_width (grub_font_t font, const char *str)
const grub_uint8_t *ptr;
for (ptr = (const grub_uint8_t *) str, width = 0;
grub_utf8_to_ucs4 (&code, 1, ptr, -1, &ptr) > 0; )
grub_utf8_to_ucs4 (&code, 1, ptr, -1, &ptr) > 0;)
{
glyph = grub_font_get_glyph_with_fallback (font, code);
width += glyph->device_width;
@ -961,7 +963,7 @@ grub_font_get_glyph (grub_font_t font, grub_uint32_t code)
sizes are used so that tiny 8 point glyphs are not mixed into a string
of 24 point text unless there is no other choice. */
static int
get_font_diversity(grub_font_t a, grub_font_t b)
get_font_diversity (grub_font_t a, grub_font_t b)
{
int d;
@ -1011,7 +1013,7 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code)
/* First try to get the glyph from the specified font. */
glyph = grub_font_get_glyph_internal (font, code);
if (glyph)
return glyph;
return glyph;
}
/* Otherwise, search all loaded fonts for the glyph and use the one from
@ -1028,16 +1030,16 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code)
glyph = grub_font_get_glyph_internal (curfont, code);
if (glyph)
{
int d;
{
int d;
d = get_font_diversity (curfont, font);
if (d < best_diversity)
{
best_diversity = d;
best_glyph = glyph;
}
}
d = get_font_diversity (curfont, font);
if (d < best_diversity)
{
best_diversity = d;
best_glyph = glyph;
}
}
}
if (best_glyph)
@ -1052,9 +1054,8 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code)
baseline of the character, while the x coordinate designates the left
side location of the character. */
grub_err_t
grub_font_draw_glyph (struct grub_font_glyph *glyph,
grub_video_color_t color,
int left_x, int baseline_y)
grub_font_draw_glyph (struct grub_font_glyph * glyph,
grub_video_color_t color, int left_x, int baseline_y)
{
struct grub_video_bitmap glyph_bitmap;
@ -1065,8 +1066,7 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
glyph_bitmap.mode_info.width = glyph->width;
glyph_bitmap.mode_info.height = glyph->height;
glyph_bitmap.mode_info.mode_type =
(1 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS)
| GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
(1 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) | GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
glyph_bitmap.mode_info.blit_format = GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED;
glyph_bitmap.mode_info.bpp = 1;
@ -1081,11 +1081,11 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
glyph_bitmap.mode_info.bg_green = 0;
glyph_bitmap.mode_info.bg_blue = 0;
glyph_bitmap.mode_info.bg_alpha = 0;
grub_video_unmap_color(color,
&glyph_bitmap.mode_info.fg_red,
&glyph_bitmap.mode_info.fg_green,
&glyph_bitmap.mode_info.fg_blue,
&glyph_bitmap.mode_info.fg_alpha);
grub_video_unmap_color (color,
&glyph_bitmap.mode_info.fg_red,
&glyph_bitmap.mode_info.fg_green,
&glyph_bitmap.mode_info.fg_blue,
&glyph_bitmap.mode_info.fg_alpha);
glyph_bitmap.data = glyph->bitmap;
int bitmap_left = left_x + glyph->offset_x;
@ -1093,9 +1093,8 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
int bitmap_top = bitmap_bottom - glyph->height;
return grub_video_blit_bitmap (&glyph_bitmap, GRUB_VIDEO_BLIT_BLEND,
bitmap_left, bitmap_top,
0, 0,
glyph->width, glyph->height);
bitmap_left, bitmap_top,
0, 0, glyph->width, glyph->height);
}
/* Draw a UTF-8 string of text on the current video render target.
@ -1105,8 +1104,7 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
a glyph from another loaded font may be used instead. */
grub_err_t
grub_font_draw_string (const char *str, grub_font_t font,
grub_video_color_t color,
int left_x, int baseline_y)
grub_video_color_t color, int left_x, int baseline_y)
{
int x;
struct grub_font_glyph *glyph;
@ -1114,15 +1112,13 @@ grub_font_draw_string (const char *str, grub_font_t font,
const grub_uint8_t *ptr;
for (ptr = (const grub_uint8_t *) str, x = left_x;
grub_utf8_to_ucs4 (&code, 1, ptr, -1, &ptr) > 0; )
grub_utf8_to_ucs4 (&code, 1, ptr, -1, &ptr) > 0;)
{
glyph = grub_font_get_glyph_with_fallback (font, code);
if (grub_font_draw_glyph (glyph, color, x, baseline_y)
!= GRUB_ERR_NONE)
return grub_errno;
if (grub_font_draw_glyph (glyph, color, x, baseline_y) != GRUB_ERR_NONE)
return grub_errno;
x += glyph->device_width;
}
return GRUB_ERR_NONE;
}