+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'.
+
2010-01-10 Robert Millan <rmh.grub@aybabtu.com>
* conf/common.rmk (bin_UTILITIES): Add `grub-bin2h'.
* 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>
#include <grub/video.h>
#include <grub/bitmap.h>
+#ifdef GENERATE_ASCII
+#include "ascii.h"
+#endif
+
#ifndef FONT_DEBUG
#define FONT_DEBUG 0
#endif
#define FONT_WEIGHT_NORMAL 100
#define FONT_WEIGHT_BOLD 200
+#define ASCII_BITMAP_SIZE 16
struct grub_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)
{
}
/* 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;
}
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);
}
grub_uint8_t bitmap[0];
};
+enum file_formats
+{
+ PF2,
+ ASCII_BITMAPS
+};
+
#define GRUB_FONT_FLAG_BOLD 1
#define GRUB_FONT_FLAG_NOBITMAP 2
#define GRUB_FONT_FLAG_NOHINTING 4
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
+ {"ascii-bitmaps", no_argument, 0, 0x102},
{0, 0, 0, 0}
};
Usage: %s [OPTIONS] FONT_FILES\n\
\nOptions:\n\
-o, --output=FILE_NAME set output file name\n\
+ --ascii-bitmaps save only the ASCII bitmaps\n\
-i, --index=N set face index\n\
-r, --range=A-B[,C-D] set font range\n\
-n, --name=S set font family name\n\
}
void
-write_font (struct grub_font_info *font_info, char *output_file)
+write_font_ascii_bitmap (struct grub_font_info *font_info, char *output_file)
+{
+ FILE *file;
+ struct grub_glyph_info *glyph;
+ int num;
+
+ file = fopen (output_file, "wb");
+ if (! file)
+ grub_util_error ("Can\'t write to file %s.", output_file);
+
+ int correct_size;
+ for (glyph = font_info->glyph, num = 0; glyph; glyph = glyph->next, num++)
+ {
+ correct_size = 1;
+ if (glyph->width != 8 || glyph->height != 16)
+ {
+ // printf ("Width or height from glyph U+%04x not supported, skipping.\n", glyph->char_code);
+ correct_size = 0;
+ }
+ int row;
+ for (row = 0; row < glyph->height; row++)
+ {
+ if (correct_size)
+ fwrite (&glyph->bitmap[row], sizeof(glyph->bitmap[row]), 1, file);
+ else
+ fwrite (&correct_size, 1, 1, file);
+ }
+ }
+ fclose (file);
+}
+
+void
+write_font_pf2 (struct grub_font_info *font_info, char *output_file)
{
FILE *file;
grub_uint32_t leng, data;
grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size, file);
}
- if (font_verbosity > 1)
- print_glyphs (font_info);
-
fclose (file);
}
int font_index = 0;
int font_size = 0;
char *output_file = NULL;
+ enum file_formats file_format = PF2;
memset (&font_info, 0, sizeof (font_info));
font_info.ranges = xrealloc (font_info.ranges,
(font_info.num_range +
GRUB_FONT_RANGE_BLOCK) *
- sizeof (int) * 2);
+ sizeof (grub_uint32_t) * 2);
font_info.ranges[font_info.num_range * 2] = a;
font_info.ranges[font_info.num_range * 2 + 1] = b;
font_verbosity++;
break;
+ case 0x102:
+ file_format = ASCII_BITMAPS;
+ break;
+
default:
usage (1);
break;
}
}
+ if (file_format == ASCII_BITMAPS && font_info.num_range > 0)
+ {
+ grub_util_error ("Option --ascii-bitmaps doesn't accept ranges (use ASCII).");
+ return 1;
+ }
+
+ else if (file_format == ASCII_BITMAPS)
+ {
+ font_info.ranges = xrealloc (font_info.ranges,
+ GRUB_FONT_RANGE_BLOCK *
+ sizeof (grub_uint32_t) * 2);
+
+ font_info.ranges[0] = (grub_uint32_t) 0x00;
+ font_info.ranges[1] = (grub_uint32_t) 0x7f;
+ font_info.num_range = 1;
+ }
+
if (! output_file)
grub_util_error ("No output file is specified.");
FT_Done_FreeType (ft_lib);
- write_font (&font_info, output_file);
+ if (file_format == PF2)
+ write_font_pf2 (&font_info, output_file);
+ else if (file_format == ASCII_BITMAPS)
+ write_font_ascii_bitmap (&font_info, output_file);
+
+ if (font_verbosity > 1)
+ print_glyphs (&font_info);
return 0;
}