Skip to contentSkip to conversation

GSoC #10 new font engine

PATCH New Colin D Bennett 7 participants 27 messages Sep 1, 2008 – Jan 5, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 GSoC #10 new font engine

This patch introduces a re-written font engine that supports fonts of arbitrary sizes as well as proportional fonts. The font file format used is a new format created for GRUB called PFF2 (nominal .pf2 file extension) -- perhaps this stands for portable font file format version 2...

Font metrics are provided, such as getting the width of a glyph or a string, and getting the ascent and descent of a font. For more information on the font format and how the ascent, descent, and baseline relate, see <http://grub.gibibit.com/New_font_format>.

The VBE driver now blits glyphs using the bitmap blit functionality, for potentially much better performance than the old glyph blit method. A new video color format (1-bit color) was added to support this, as well as a new blit format (1-bit packed bitmap).

The font tools (BDF->PFF2 font converter, and BDF/PFF2 viewer) are written in Java and are coming in the next patch.

Regards,
Colin

2008-08-30 Colin D Bennett <[email protected]>

New font engine supporting large and proportional fonts, PFF2 file format.

* commands/videotest.c (grub_cmd_videotest): Use new font API, getting pointers to glyphs.

* font/font.c: New file.
* font/font_cmd.c: New file.
* font/loader.c: New file.
* font/manager.c: Deleted.
* include/grub/font_internal.h: New file.

* conf/common.rmk (font_mod_SOURCES): Update source file list.
* conf/sparc64-ieee1275.rmk (font_mod_SOURCES): Likewise.

* include/grub/font.h: Update copyright years. (GRUB_FONT_MAGIC): Removed.
(grub_font): New forward declaration of struct. (grub_font_t): New typedef.
(grub_font_glyph): Updated data structure to support larger, variable size fonts and to support font metrics. (grub_font_glyph_t): Removed.
(grub_font_get): New prototype.
(grub_font_get_name): New prototype. (grub_font_get_max_char_width): New prototype. (grub_font_get_max_char_height): New prototype. (grub_font_get_ascent): New prototype. (grub_font_get_descent): New prototype. (grub_font_get_string_width): New prototype. (grub_font_load): New prototype.
(grub_font_get_glyph): New prototype. (grub_font_get_glyph_any): New prototype.

* include/grub/video.h (grub_font_glyph): Removed forward struct declaration.
(GRUB_VIDEO_MODE_TYPE_ALPHA): Changed bit mask value to make space for 1BIT_BITMAP.
(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise. (GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): New bit mask constant. (GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Updated to a wider mask to make space for 1BIT_BITMAP. (GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED): New blit format enum value. (grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, fg_red, fg_green, fg_blue, and fg_alpha fields. (grub_video_adapter): Added draw_string function pointer. Updated argument names for blit_glyph coordinates to indicate that the y coordinate specifies the text baseline, not the top of the text. (grub_video_blit_glyph): Updated argument names for clarity. (grub_video_draw_string): New prototype.

* term/gfxterm.c (DEFAULT_CHAR_WIDTH): Removed. (DEFAULT_CHAR_HEIGHT): Removed.
(grub_virtual_screen): Added font field. (grub_virtual_screen_setup): Add font_name parameter. Initialize terminal font information.
(grub_gfxterm_init): Get font name from gfxterm_font environment variable. Pass font name to grub_virtual_screen_setup. (write_char): Place glyphs using their baseline, based on the font ascent.
(write_cursor): Draw cursor using font ascent as a reference. (grub_gfxterm_putchar): Use new font API. Breaks bi-width font support.
(grub_gfxterm_getcharwidth): Assume all characters are 1 character in width. Breaks bi-width font support. (grub_vga_getcharwidth): Always return a width of 1.

* term/i386/pc/vesafb.c (grub_virtual_screen_get_glyph): Use new font API. Breaks vesafb glyph drawing, since it copied the glyph data directly, but now glyphs use a different storage format.

* term/i386/pc/vga.c (font): New static variable. (grub_vga_mod_init): Get a font using the new font API. (write_char): Broken. Commented out code with #if 0 since it will need to be rewritten to handle the new glyph storage format if we want to maintain the vga terminal.
(grub_vga_putchar): Update to use new font API; breaks support for bi-width fonts.

* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Support GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color_int): Likewise. (grub_video_vbe_blit_glyph): Support new font glyph format and use grub_video_vbe_blit_bitmap to draw them. Coordinates specify the glyph baseline.
(grub_video_vbe_draw_string): New function. (grub_video_vbe_adapter): Added draw_string function pointer.

* video/i386/pc/vbeutil.c (get_data_ptr): Add a comment to the switch statement inidicating why it is unimplemented for 1-bit bitmaps. (get_pixel): Support 1-bit bitmaps.
(set_pixel): Support 1-bit bitmaps.

* video/video.c (grub_video_blit_glyph): Renamed coordinate arguments for clarity.
(grub_video_draw_string): New function.

=== modified file 'commands/videotest.c'

videotest.c +14 -9
@@ -44,7 +44,8 @@
   unsigned int width;
   unsigned int height;
   int i;
-  struct grub_font_glyph glyph;
+  grub_font_t font;
+  struct grub_font_glyph *glyph;
   struct grub_video_render_target *text_layer;
   grub_video_color_t palette[16];
 
@@ -65,8 +66,12 @@
   color = grub_video_map_rgb (0, 255, 255);
   grub_video_fill_rect (color, 100, 100, 100, 100);
 
-  grub_font_get_glyph ('*', &glyph);  
-  grub_video_blit_glyph (&glyph, color, 200 ,0);
+  font = grub_font_get ("Helvetica Bold 14");
+  if (! font)
+    return grub_error (GRUB_ERR_BAD_FONT, "No font loaded.");
+
+  glyph = grub_font_get_glyph (font, '*');  
+  grub_video_blit_glyph (glyph, color, 200 ,0);
 
   grub_video_set_viewport (x + 150, y + 150,
                            width - 150 * 2, height - 150 * 2);
@@ -77,18 +82,18 @@
 
   color = grub_video_map_rgb (255, 255, 255);
 
-  grub_font_get_glyph ('A', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16, 16);
-  grub_font_get_glyph ('B', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16 * 2, 16);
+  glyph = grub_font_get_glyph (font, 'A');
+  grub_video_blit_glyph (glyph, color, 16, 16);
+  glyph = grub_font_get_glyph (font, 'B');
+  grub_video_blit_glyph (glyph, color, 16 * 2, 16);
 
-  grub_font_get_glyph ('*', &glyph);
+  glyph = grub_font_get_glyph (font, '*');
 
   for (i = 0; i < 16; i++)
     {
       color = grub_video_map_color (i);
       palette[i] = color;
-      grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32);
+      grub_video_blit_glyph (glyph, color, 16 + i * 16, 32);
     }
 
   grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

=== modified file 'conf/common.rmk'

common.rmk +1 -1
@@ -358,7 +358,7 @@
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c font/loader.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== modified file 'conf/sparc64-ieee1275.rmk'

sparc64-ieee1275.rmk +1 -1
@@ -196,7 +196,7 @@
 cat_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c font/loader.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== added file 'font/font.c'

font.c +92 -0

92 lines not on this page · raw message

=== added file 'font/font_cmd.c'

font_cmd.c +75 -0

75 lines not on this page · raw message

=== added file 'font/loader.c'

loader.c +689 -0

689 lines not on this page · raw message

=== removed file 'font/manager.c'

manager.c +0 -283

283 lines not on this page · raw message

=== modified file 'include/grub/font.h'

grub/font.h +76 -24

115 lines not on this page · raw message

=== added file 'include/grub/font_internal.h'

grub/font_internal.h +71 -0

71 lines not on this page · raw message

=== modified file 'include/grub/video.h'

grub/video.h +32 -7
@@ -21,6 +21,7 @@
 
 #include <grub/err.h>
 #include <grub/types.h>
+#include <grub/font.h>
 
 /* Video color in hardware dependent format.  Users should not assume any
    specific coding format.  */
@@ -31,17 +32,17 @@
 struct grub_video_render_target;
 
 /* Forward declarations for used data structures.  */
-struct grub_font_glyph;
 struct grub_video_bitmap;
 
 /* Defines used to describe video mode or rendering target.  */
-#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000008
-#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000004
+#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000020
+#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000010
+#define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP	0x00000004
 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR	0x00000002
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
 /* Defines used to mask flags.  */
-#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x00000003
+#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x0000000F
 
 /* Defines used to specify requested bit depth.  */
 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK		0x0000ff00
@@ -63,7 +64,9 @@
     GRUB_VIDEO_BLIT_FORMAT_RGB_888,    /* Optimized format. */
     GRUB_VIDEO_BLIT_FORMAT_BGR_888,    /* Optimized format. */
     /* When needed, decode color or just use value as is.  */
-    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
+    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+    /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
+    GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
   };
 
 /* Define blitting operators.  */
@@ -126,6 +129,18 @@
   /* What is location of reserved color bits.  In Index Color mode, 
      this is 0.  */
   unsigned int reserved_field_pos;
+
+  /* For 1-bit bitmaps, the background color.  Used for bits = 0. */
+  grub_uint8_t bg_red;
+  grub_uint8_t bg_green;
+  grub_uint8_t bg_blue;
+  grub_uint8_t bg_alpha;
+
+  /* For 1-bit bitmaps, the foreground color.  Used for bits = 1. */
+  grub_uint8_t fg_red;
+  grub_uint8_t fg_green;
+  grub_uint8_t fg_blue;
+  grub_uint8_t fg_alpha;
 };
 
 struct grub_video_palette_data
@@ -180,7 +195,12 @@
                            unsigned int width, unsigned int height);
 
   grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph,
-                            grub_video_color_t color, int x, int y);
+                            grub_video_color_t color, 
+                            int left_x, int baseline_y);
+
+  grub_err_t (*draw_string) (const char *str, grub_font_t font, 
+                             grub_video_color_t color, 
+                             int left_x, int baseline_y);
 
   grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
                              enum grub_video_blit_operators oper,
@@ -252,7 +272,12 @@
                                  unsigned int width, unsigned int height);
 
 grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                                  grub_video_color_t color, int x, int y);
+                                  grub_video_color_t color, 
+                                  int left_x, int baseline_y);
+
+grub_err_t grub_video_draw_string (const char *str, grub_font_t font, 
+                                   grub_video_color_t color, 
+                                   int left_x, int baseline_y);
 
 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
                                    enum grub_video_blit_operators oper,

=== modified file 'term/gfxterm.c'

gfxterm.c +51 -26

191 lines not on this page · raw message

=== modified file 'term/i386/pc/vesafb.c'

i386/pc/vesafb.c +2 -1
@@ -250,10 +250,11 @@
 	  break;
 
 	default:
-	  return grub_font_get_glyph (code, bitmap, width);
+	  return grub_font_get_glyph_any (code, bitmap, width);
 	}
     }
 
+  /* TODO This is wrong for the new font module.  Should it be fixed?  */
   if (bitmap)
     grub_memcpy (bitmap,
 		 vga_font + code * virtual_screen.char_height,

=== modified file 'term/i386/pc/vga.c'

i386/pc/vga.c +28 -14

120 lines not on this page · raw message

=== modified file 'video/i386/pc/vbe.c'

i386/pc/vbe.c +111 -70

217 lines not on this page · raw message

=== modified file 'video/i386/pc/vbeutil.c'

i386/pc/vbeutil.c +27 -0
@@ -52,6 +52,11 @@
             + y * source->mode_info->pitch
             + x;
       break;
+
+    /* case 1: */
+      /* For 1-bit bitmaps, addressing needs to be done at the bit level
+       * and it doesn't make sense, in general, to ask for a pointer
+       * to a particular pixel's data. */
     }
 
   return ptr;
@@ -86,6 +91,17 @@
       color = *(grub_uint8_t *)get_data_ptr (source, x, y);
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          color = (*ptr >> bit_pos) & 0x01;
+        }
+      break;
+
     default:
       break;
     }
@@ -143,6 +159,17 @@
       }
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
+        }
+      break;
+
     default:
       break;
     }

=== modified file 'video/video.c'

video.c +21 -6
@@ -313,12 +313,27 @@
 /* Blit glyph to screen using specified color.  */
 grub_err_t
 grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                       grub_video_color_t color, int x, int y)
-{
-  if (! grub_video_adapter_active)
-    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
-
-  return grub_video_adapter_active->blit_glyph (glyph, color, x, y);
+                       grub_video_color_t color, 
+                       int left_x, int baseline_y)
+{
+  if (! grub_video_adapter_active)
+    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
+
+  return grub_video_adapter_active->blit_glyph (glyph, color,
+                                                left_x, baseline_y);
+}
+
+/* Draw string to screen using specified color and font.  */
+grub_err_t
+grub_video_draw_string (const char *str, grub_font_t font, 
+                        grub_video_color_t color, 
+                        int left_x, int baseline_y)
+{
+  if (! grub_video_adapter_active)
+    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
+
+  return grub_video_adapter_active->draw_string (str, font, color, 
+                                                 left_x, baseline_y);
 }
 
 /* Blit bitmap to screen.  */
#1 lore raw

PATCH 1/1 GSoC #10 new font engine (vs r1885)

Clean patch against SVN revision 1885.

Regards,
Colin

=== modified file 'commands/videotest.c'

videotest.c +14 -9
@@ -44,7 +44,8 @@
   unsigned int width;
   unsigned int height;
   int i;
-  struct grub_font_glyph glyph;
+  grub_font_t font;
+  struct grub_font_glyph *glyph;
   struct grub_video_render_target *text_layer;
   grub_video_color_t palette[16];
 
@@ -65,8 +66,12 @@
   color = grub_video_map_rgb (0, 255, 255);
   grub_video_fill_rect (color, 100, 100, 100, 100);
 
-  grub_font_get_glyph ('*', &glyph);  
-  grub_video_blit_glyph (&glyph, color, 200 ,0);
+  font = grub_font_get ("Helvetica Bold 14");
+  if (! font)
+    return grub_error (GRUB_ERR_BAD_FONT, "No font loaded.");
+
+  glyph = grub_font_get_glyph (font, '*');  
+  grub_video_blit_glyph (glyph, color, 200 ,0);
 
   grub_video_set_viewport (x + 150, y + 150,
                            width - 150 * 2, height - 150 * 2);
@@ -77,18 +82,18 @@
 
   color = grub_video_map_rgb (255, 255, 255);
 
-  grub_font_get_glyph ('A', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16, 16);
-  grub_font_get_glyph ('B', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16 * 2, 16);
+  glyph = grub_font_get_glyph (font, 'A');
+  grub_video_blit_glyph (glyph, color, 16, 16);
+  glyph = grub_font_get_glyph (font, 'B');
+  grub_video_blit_glyph (glyph, color, 16 * 2, 16);
 
-  grub_font_get_glyph ('*', &glyph);
+  glyph = grub_font_get_glyph (font, '*');
 
   for (i = 0; i < 16; i++)
     {
       color = grub_video_map_color (i);
       palette[i] = color;
-      grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32);
+      grub_video_blit_glyph (glyph, color, 16 + i * 16, 32);
     }
 
   grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

=== modified file 'conf/common.rmk'

common.rmk +1 -1
@@ -364,7 +364,7 @@
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c font/loader.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== modified file 'conf/sparc64-ieee1275.rmk'

sparc64-ieee1275.rmk +1 -1
@@ -196,7 +196,7 @@
 cat_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c font/loader.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== added file 'font/font.c'

font.c +92 -0

92 lines not on this page · raw message

=== added file 'font/font_cmd.c'

font_cmd.c +75 -0

75 lines not on this page · raw message

=== added file 'font/loader.c'

loader.c +689 -0

689 lines not on this page · raw message

=== removed file 'font/manager.c'

manager.c +0 -283

283 lines not on this page · raw message

=== modified file 'include/grub/font.h'

grub/font.h +76 -24

115 lines not on this page · raw message

=== added file 'include/grub/font_internal.h'

grub/font_internal.h +71 -0

71 lines not on this page · raw message

=== modified file 'include/grub/video.h'

grub/video.h +32 -7
@@ -21,6 +21,7 @@
 
 #include <grub/err.h>
 #include <grub/types.h>
+#include <grub/font.h>
 
 /* Video color in hardware dependent format.  Users should not assume any
    specific coding format.  */
@@ -31,17 +32,17 @@
 struct grub_video_render_target;
 
 /* Forward declarations for used data structures.  */
-struct grub_font_glyph;
 struct grub_video_bitmap;
 
 /* Defines used to describe video mode or rendering target.  */
-#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000008
-#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000004
+#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000020
+#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000010
+#define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP	0x00000004
 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR	0x00000002
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
 /* Defines used to mask flags.  */
-#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x00000003
+#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x0000000F
 
 /* Defines used to specify requested bit depth.  */
 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK		0x0000ff00
@@ -72,7 +73,9 @@
     GRUB_VIDEO_BLIT_FORMAT_BGR_565,
 
     /* When needed, decode color or just use value as is.  */
-    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
+    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+    /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
+    GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
   };
 
 /* Define blitting operators.  */
@@ -135,6 +138,18 @@
   /* What is location of reserved color bits.  In Index Color mode,
      this is 0.  */
   unsigned int reserved_field_pos;
+
+  /* For 1-bit bitmaps, the background color.  Used for bits = 0. */
+  grub_uint8_t bg_red;
+  grub_uint8_t bg_green;
+  grub_uint8_t bg_blue;
+  grub_uint8_t bg_alpha;
+
+  /* For 1-bit bitmaps, the foreground color.  Used for bits = 1. */
+  grub_uint8_t fg_red;
+  grub_uint8_t fg_green;
+  grub_uint8_t fg_blue;
+  grub_uint8_t fg_alpha;
 };
 
 struct grub_video_palette_data
@@ -189,7 +204,12 @@
                            unsigned int width, unsigned int height);
 
   grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph,
-                            grub_video_color_t color, int x, int y);
+                            grub_video_color_t color, 
+                            int left_x, int baseline_y);
+
+  grub_err_t (*draw_string) (const char *str, grub_font_t font, 
+                             grub_video_color_t color, 
+                             int left_x, int baseline_y);
 
   grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
                              enum grub_video_blit_operators oper,
@@ -261,7 +281,12 @@
                                  unsigned int width, unsigned int height);
 
 grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                                  grub_video_color_t color, int x, int y);
+                                  grub_video_color_t color, 
+                                  int left_x, int baseline_y);
+
+grub_err_t grub_video_draw_string (const char *str, grub_font_t font, 
+                                   grub_video_color_t color, 
+                                   int left_x, int baseline_y);
 
 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
                                    enum grub_video_blit_operators oper,

=== modified file 'term/gfxterm.c'

gfxterm.c +51 -26

191 lines not on this page · raw message

=== modified file 'term/i386/pc/vesafb.c'

i386/pc/vesafb.c +2 -1
@@ -250,10 +250,11 @@
 	  break;
 
 	default:
-	  return grub_font_get_glyph (code, bitmap, width);
+	  return grub_font_get_glyph_any (code, bitmap, width);
 	}
     }
 
+  /* TODO This is wrong for the new font module.  Should it be fixed?  */
   if (bitmap)
     grub_memcpy (bitmap,
 		 vga_font + code * virtual_screen.char_height,

=== modified file 'term/i386/pc/vga.c'

i386/pc/vga.c +28 -14

120 lines not on this page · raw message

=== modified file 'video/i386/pc/vbe.c'

i386/pc/vbe.c +111 -70

217 lines not on this page · raw message

=== modified file 'video/i386/pc/vbeutil.c'

i386/pc/vbeutil.c +27 -0
@@ -52,6 +52,11 @@
             + y * source->mode_info->pitch
             + x;
       break;
+
+    /* case 1: */
+      /* For 1-bit bitmaps, addressing needs to be done at the bit level
+       * and it doesn't make sense, in general, to ask for a pointer
+       * to a particular pixel's data. */
     }
 
   return ptr;
@@ -86,6 +91,17 @@
       color = *(grub_uint8_t *)get_data_ptr (source, x, y);
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          color = (*ptr >> bit_pos) & 0x01;
+        }
+      break;
+
     default:
       break;
     }
@@ -143,6 +159,17 @@
       }
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
+        }
+      break;
+
     default:
       break;
     }

=== modified file 'video/video.c'

video.c +21 -6
@@ -339,12 +339,27 @@
 /* Blit glyph to screen using specified color.  */
 grub_err_t
 grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                       grub_video_color_t color, int x, int y)
-{
-  if (! grub_video_adapter_active)
-    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
-
-  return grub_video_adapter_active->blit_glyph (glyph, color, x, y);
+                       grub_video_color_t color, 
+                       int left_x, int baseline_y)
+{
+  if (! grub_video_adapter_active)
+    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
+
+  return grub_video_adapter_active->blit_glyph (glyph, color,
+                                                left_x, baseline_y);
+}
+
+/* Draw string to screen using specified color and font.  */
+grub_err_t
+grub_video_draw_string (const char *str, grub_font_t font, 
+                        grub_video_color_t color, 
+                        int left_x, int baseline_y)
+{
+  if (! grub_video_adapter_active)
+    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
+
+  return grub_video_adapter_active->draw_string (str, font, color, 
+                                                 left_x, baseline_y);
 }
 
 /* Blit bitmap to screen.  */
#2 lore raw

Re: [PATCH] GSoC #10 new font engine (vs r1885)

Quoted 4 lines · Colin D Bennett

Clean patch against SVN revision 1885.

Regards,
Colin

Thanks for the re-base.

Here are some comments about the patch.

Check the commenting of multi line comments.

Quoted 8 lines
font.c +8 -0
+int
+grub_font_get_string_width (grub_font_t font, const char *str)
+{
+  int i;
+  int width;
+  struct grub_font_glyph *glyph;
+  grub_size_t len;
+

font.c line 92

Quoted 10 lines
font.c +10 -0
+  len = grub_strlen (str);
+
+  for (i = 0, width = 0; i < len; i++)
+    {
+      glyph = grub_font_get_glyph (font, str[i]);
+      width += glyph->device_width;
+    }
+
+  return width;
+}

I do not see this being utf-8 compatible eg. it breaks our Unicode displaying support. See how grub_putchar() handles this.

There is also the same problem in grub_video_vbe_draw_string().

sparc64-ieee1275.rmk

Quoted 3 lines

=== modified file 'conf/sparc64-ieee1275.rmk'

sparc64-ieee1275.rmk +0 -0

As font code is common code. There is no need to modify sparc64 specific makefile. You have correctly modified common.rmk so that is enough. If sparc64 support should be moved to use common.rmk like any other arch. Let it rot.

loader.c line 472

Quoted 11 lines

=== added file 'font/loader.c'

loader.c +7 -0
 
+/*
+   Read a 16-bit big-endian integer from FILE, convert it to native byte
+   order, and store it in *VALUE.
+   Returns 0 on success, 1 on failure.
+ */
+static int
+read_be_uint16 (grub_file_t file, grub_uint16_t * value)

Are you fan of bigendian or why did you choose that :) ?

loader.c line 585

Quoted 2 lines
loader.c +2 -0
+struct grub_font_glyph *
+grub_font_get_glyph (grub_font_t font, grub_uint32_t code)

I would propose to but all public API's to one file.

grub/video.h

Quoted 3 lines

=== modified file 'include/grub/video.h'

grub/video.h +0 -0

Now that you have moved glyph rendering out from specialized glyph rendering to bitmap rendering I would propose that no font rendering code resides in Video API. I think this is a good move.

I would move that to font.mod (or perhaps to graphical terminal?). We can adapt other graphical terminals to use video API to render stuff. It just takes a bit time. But I think this time is as good as any to start that process.

Lets have another look at it after those modifications :)

Thanks,
Vesa Jääskeläinen

#3 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support)

Hi Vesa,

I have implemented UTF-8 support in the new font engine.

I have also added smart glyph fallback behavior, which is used when the requested font is missing a glyph from the text being rendered. In that case, all other loaded fonts are checked to see if any of them have the requested character. The font most similar (mainly in size) to the current font is selected. My example in the 'videotest' command uses the '10x20' fixed font (the name is "Fixed 20" when requesting the font) which provides all the Unicode characters that the test uses. However, when the test uses Helvetica, which is missing many of the non-ASCII characters, the smart glyph substitution uses glyphs from other fonts (including Fixed 20) to render those characters.

To see what this looks like, look at
<http://grub.gibibit.com/Journal_2008-10-30_utf8_test.png>. This is a screen shot of the enhanced videotest (GSoC patch #12) rendering UTF-8 strings. I don't have many good fonts here, but it is nice to see that Helvetica 8 (the bottom font) uses smaller replacement glyphs for its missing characters than the others do. Without the glyph substitution, you would see the 'unknown glyph' question-mark symbol instead.

Attached is my new patch which hopefully addresses your points below.

Summary of changes since the previous patch:
- UTF-8 text support (including 'videotest' changes to test it)
- Smart substitution for missing glyphs
- Text rendering code is in the font module instead of vbe
- Comment formatting fixed
- Single font.c file instead of multiple source files

Responses to your comments follow.

Quoted 11 lines · On Sun, 05 Oct 2008 11:50:01 +0300 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 4 lines · Colin D Bennett

Clean patch against SVN revision 1885.

Regards,
Colin

Thanks for the re-base.

Here are some comments about the patch.

Check the commenting of multi line comments.

Ok, fixed.

Quoted 23 lines
Quoted 9 lines
(quoted diff) +8 -0
+int
+grub_font_get_string_width (grub_font_t font, const char *str)
+{
+  int i;
+  int width;
+  struct grub_font_glyph *glyph;
+  grub_size_t len;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+  len = grub_strlen (str);
+
+  for (i = 0, width = 0; i < len; i++)
+    {
+      glyph = grub_font_get_glyph (font, str[i]);
+      width += glyph->device_width;
+    }
+
+  return width;
+}

I do not see this being utf-8 compatible eg. it breaks our Unicode displaying support. See how grub_putchar() handles this.

Quoted 1 line

There is also the same problem in grub_video_vbe_draw_string().

Fixed.

Quoted 8 lines

sparc64-ieee1275.rmk

Quoted 3 lines

=== modified file 'conf/sparc64-ieee1275.rmk'

sparc64-ieee1275.rmk +0 -0

As font code is common code. There is no need to modify sparc64 specific makefile. You have correctly modified common.rmk so that is enough. If sparc64 support should be moved to use common.rmk like any other arch. Let it rot.

Ok, I reverted my changes to the sparc64 file.

Quoted 4 lines
Quoted 3 lines

=== added file 'font/loader.c'

loader.c +0 -0
Quoted 10 lines

loader.c

Quoted 8 lines
loader.c +2 -0
+/*
+   Read a 16-bit big-endian integer from FILE, convert it to

native byte

loader.c +5 -0
+   order, and store it in *VALUE.
+   Returns 0 on success, 1 on failure.
+ */
+static int
+read_be_uint16 (grub_file_t file, grub_uint16_t * value)

Are you fan of bigendian or why did you choose that :) ?

Well, I had to choose a byte order, and I arbitrarily chose big-endian (isn't that the "network byte order" used for TCP/IP, etc.?)

Quoted 4 lines

loader.c

Quoted 2 lines
loader.c +2 -0
+struct grub_font_glyph *
+grub_font_get_glyph (grub_font_t font, grub_uint32_t code)

I would propose to but all public API's to one file.

Ok, it's unified into a single font.c -- this is good for encapsulation, as well. The 'font_internal.h' is gone.

Quoted 8 lines

grub/video.h

Quoted 3 lines

=== modified file 'include/grub/video.h'

grub/video.h +0 -0

Now that you have moved glyph rendering out from specialized glyph rendering to bitmap rendering I would propose that no font rendering code resides in Video API. I think this is a good move.

Quoted 4 lines

I would move that to font.mod (or perhaps to graphical terminal?). We can adapt other graphical terminals to use video API to render stuff. It just takes a bit time. But I think this time is as good as any to start that process.

All font rendering functions are in the font module now. Yes, this is a much cleaner way to do it.

Quoted 4 lines

Lets have another look at it after those modifications :)

Thanks,
Vesa Jääskeläinen

Let me know how this looks.

Regards,
Colin

2008-10-30 Colin D Bennett <[email protected]>

New font engine supporting large and proportional fonts, PFF2 file format.

* commands/videotest.c (grub_cmd_videotest): Use new font API, test drawing UTF-8 Unicode text.
* conf/common.rmk (font_mod_SOURCES): Update source file list.
* font/font.c: New file.
* font/font_cmd.c: New file.
* font/manager.c: Deleted.

* include/grub/font.h: Update copyright years. (GRUB_FONT_MAGIC): Removed.
(grub_font): New forward declaration of struct. (grub_font_t): New typedef.
(grub_font_node): New struct.
(grub_font_list): New global symbol.
(grub_font_glyph): Updated data structure to support larger, variable size fonts and to support font metrics. (grub_font_glyph_t): Removed.
(grub_font_loader_init): New prototype.
(grub_font_load): New prototype.
(grub_font_get): New prototype.
(grub_font_get_name): New prototype. (grub_font_get_max_char_width): New prototype. (grub_font_get_max_char_height): New prototype. (grub_font_get_ascent): New prototype. (grub_font_get_descent): New prototype. (grub_font_get_leading): New prototype. (grub_font_get_height): New prototype. (grub_font_get_string_width): New prototype. (grub_font_load): New prototype.
(grub_font_get_glyph): New prototype. (grub_font_get_glyph_with_fallback): New prototype. (grub_font_draw_glyph): New prototype. (grub_font_draw_string): New prototype.

* include/grub/misc.h (grub_utf8_to_ucs4): Added parameters.

* include/grub/video.h (grub_font_glyph): Removed forward struct declaration.
(GRUB_VIDEO_MODE_TYPE_ALPHA): Changed bit mask value to make space for 1BIT_BITMAP.
(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise. (GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): New bit mask constant. (GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Updated to a wider mask to make space for 1BIT_BITMAP. (GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED): New blit format enum value. (grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, fg_red, fg_green, fg_blue, and fg_alpha fields.

* kern/misc.c (grub_utf8_to_ucs4): Support null-terminated UTF-8 strings and allow limiting the number of Unicode characters decoded.
* kern/term.c (grub_putchar): Pass additional arguments to grub_utf8_to_ucs4.
* normal/menu.c (print_entry): Pass destination maximum length to grub_utf8_to_ucs4.

* term/gfxterm.c (DEFAULT_CHAR_WIDTH): Removed. (DEFAULT_CHAR_HEIGHT): Removed.
(grub_virtual_screen): Added font field. (grub_virtual_screen_setup): Add font_name parameter. Initialize terminal font information.
(grub_gfxterm_init): Get font name from gfxterm_font environment variable. Pass font name to grub_virtual_screen_setup. (write_char): Place glyphs using their baseline, based on the font ascent.
(write_cursor): Draw cursor using font ascent as a reference. (grub_gfxterm_putchar): Use new font API. Breaks bi-width font support.
(grub_gfxterm_getcharwidth): Assume all characters are 1 character in width. Breaks bi-width font support. (grub_vga_getcharwidth): Always return a width of 1.

* term/i386/pc/vesafb.c (grub_virtual_screen_get_glyph): Use new font API. Breaks vesafb glyph drawing, since it copied the glyph data directly, but now glyphs use a different storage format. This code shouldn't compile, but GRUB builds ok!
* term/i386/pc/vga.c (font): New static variable. (grub_vga_mod_init): Get a font using the new font API. (write_char): Broken. Commented out code with #if 0 since it will need to be rewritten to handle the new glyph storage format if we want to maintain the vga terminal.
(grub_vga_putchar): Update to use new font API; breaks support for bi-width fonts.

* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Support GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color_int): Likewise. (grub_video_vbe_blit_glyph): Deleted. (grub_video_vbe_adapter): Deleted blit_glyph member.

* video/i386/pc/vbeutil.c (get_data_ptr): Add a comment to the switch statement indicating why it is unimplemented for 1-bit bitmaps. (get_pixel): Support 1-bit bitmaps.
(set_pixel): Support 1-bit bitmaps.

* video/video.c (grub_video_blit_glyph): Renamed coordinate arguments for clarity.
(grub_video_draw_string): New function.

=== modified file 'commands/videotest.c'

videotest.c +75 -13
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  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
@@ -36,17 +36,21 @@
                         GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != GRUB_ERR_NONE)
     return grub_errno;
 
-  grub_getkey ();
-
   grub_video_color_t color;
   unsigned int x;
   unsigned int y;
   unsigned int width;
   unsigned int height;
   int i;
-  struct grub_font_glyph glyph;
+  grub_font_t sansbig;
+  grub_font_t sans;
+  grub_font_t sanssmall;
+  grub_font_t fixed;
+  struct grub_font_glyph *glyph;
   struct grub_video_render_target *text_layer;
   grub_video_color_t palette[16];
+  const char *str;
+  int texty;
 
   grub_video_get_viewport (&x, &y, &width, &height);
 
@@ -65,8 +69,15 @@
   color = grub_video_map_rgb (0, 255, 255);
   grub_video_fill_rect (color, 100, 100, 100, 100);
 
-  grub_font_get_glyph ('*', &glyph);  
-  grub_video_blit_glyph (&glyph, color, 200 ,0);
+  sansbig = grub_font_get ("Helvetica Bold 24");
+  sans = grub_font_get ("Helvetica Bold 14");
+  sanssmall = grub_font_get ("Helvetica 8");
+  fixed = grub_font_get ("Fixed 20");
+  if (! sansbig || ! sans || ! sanssmall || ! fixed)
+    return grub_error (GRUB_ERR_BAD_FONT, "No font loaded.");
+
+  glyph = grub_font_get_glyph (fixed, '*');
+  grub_font_draw_glyph (glyph, color, 200 ,0);
 
   grub_video_set_viewport (x + 150, y + 150,
                            width - 150 * 2, height - 150 * 2);
@@ -77,18 +88,69 @@
 
   color = grub_video_map_rgb (255, 255, 255);
 
-  grub_font_get_glyph ('A', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16, 16);
-  grub_font_get_glyph ('B', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16 * 2, 16);
-
-  grub_font_get_glyph ('*', &glyph);
+  texty = 32;
+  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
+                         sans, color, 16, texty);
+  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
+
+  texty += grub_font_get_ascent (fixed);
+  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
+                         fixed, color, 16, texty);
+  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
+
+  /* To convert Unicode characters into UTF-8 for this test, the following
+     command is useful:
+       echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
+     This converts the Unicode character U+263A to UTF-8.  */
+
+  /* Characters used:
+     Code point  Description                    UTF-8 encoding
+     ----------- ------------------------------ --------------
+     U+263A      unfilled smiley face           E2 98 BA
+     U+00A1      inverted exclamation point     C2 A1
+     U+00A3      British pound currency symbol  C2 A3
+     U+03C4      Greek tau                      CF 84
+     U+00E4      lowercase letter a with umlaut C3 A4
+     U+2124      set 'Z' symbol (integers)      E2 84 A4
+     U+2287      subset symbol                  E2 8A 87
+     U+211D      set 'R' symbol (real numbers)  E2 84 9D  */
+
+  str =
+    "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
+    " \xC2\xA1\xCF\x84\xC3\xA4u! "
+    " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
+  color = grub_video_map_rgb (128, 128, 255);
+
+  /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
+  texty += grub_font_get_ascent(fixed);
+  grub_font_draw_string (str, fixed, color, 16, texty);
+  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
+
+  /* Some character don't exist in the Helvetica font, so the font engine
+     will fall back to using glyphs from another font that does contain them.
+     TODO The font engine should be smart about selecting a replacement font
+     and prioritize fonts with similar sizes.  */
+
+  texty += grub_font_get_ascent(sansbig);
+  grub_font_draw_string (str, sansbig, color, 16, texty);
+  texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
+
+  texty += grub_font_get_ascent(sans);
+  grub_font_draw_string (str, sans, color, 16, texty);
+  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
+
+  texty += grub_font_get_ascent(sanssmall);
+  grub_font_draw_string (str, sanssmall, color, 16, texty);
+  texty += (grub_font_get_descent (sanssmall)
+            + grub_font_get_leading (sanssmall));
+
+  glyph = grub_font_get_glyph (fixed, '*');
 
   for (i = 0; i < 16; i++)
     {
       color = grub_video_map_color (i);
       palette[i] = color;
-      grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32);
+      grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
     }
 
   grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

=== modified file 'conf/common.rmk'

common.rmk +1 -1
@@ -364,7 +364,7 @@
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== added file 'font/font.c'

font.c +971 -0

971 lines not on this page · raw message

=== added file 'font/font_cmd.c'

font_cmd.c +77 -0

77 lines not on this page · raw message

=== removed file 'font/manager.c'

manager.c +0 -283

283 lines not on this page · raw message

=== modified file 'include/grub/font.h'

grub/font.h +87 -25

127 lines not on this page · raw message

=== modified file 'include/grub/misc.h'

grub/misc.h +3 -1
@@ -77,8 +77,10 @@
 					       grub_uint16_t *src,
 					       grub_size_t size);
 grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
+					     grub_size_t destsize,
 					     const grub_uint8_t *src,
-					     grub_size_t size);
+					     grub_size_t srcsize,
+					     const grub_uint8_t **srcend);
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint32_t d, grub_uint32_t *r);
 

=== modified file 'include/grub/video.h'

grub/video.h +19 -11
@@ -31,17 +31,17 @@
 struct grub_video_render_target;
 
 /* Forward declarations for used data structures.  */
-struct grub_font_glyph;
 struct grub_video_bitmap;
 
 /* Defines used to describe video mode or rendering target.  */
-#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000008
-#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000004
+#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000020
+#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000010
+#define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP	0x00000004
 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR	0x00000002
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
 /* Defines used to mask flags.  */
-#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x00000003
+#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x0000000F
 
 /* Defines used to specify requested bit depth.  */
 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK		0x0000ff00
@@ -72,7 +72,9 @@
     GRUB_VIDEO_BLIT_FORMAT_BGR_565,
 
     /* When needed, decode color or just use value as is.  */
-    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
+    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+    /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
+    GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
   };
 
 /* Define blitting operators.  */
@@ -135,6 +137,18 @@
   /* What is location of reserved color bits.  In Index Color mode,
      this is 0.  */
   unsigned int reserved_field_pos;
+
+  /* For 1-bit bitmaps, the background color.  Used for bits = 0. */
+  grub_uint8_t bg_red;
+  grub_uint8_t bg_green;
+  grub_uint8_t bg_blue;
+  grub_uint8_t bg_alpha;
+
+  /* For 1-bit bitmaps, the foreground color.  Used for bits = 1. */
+  grub_uint8_t fg_red;
+  grub_uint8_t fg_green;
+  grub_uint8_t fg_blue;
+  grub_uint8_t fg_alpha;
 };
 
 struct grub_video_palette_data
@@ -188,9 +202,6 @@
   grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
                            unsigned int width, unsigned int height);
 
-  grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph,
-                            grub_video_color_t color, int x, int y);
-
   grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
                              enum grub_video_blit_operators oper,
                              int x, int y, int offset_x, int offset_y,
@@ -260,9 +271,6 @@
 grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y,
                                  unsigned int width, unsigned int height);
 
-grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                                  grub_video_color_t color, int x, int y);
-
 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
                                    enum grub_video_blit_operators oper,
                                    int x, int y, int offset_x, int offset_y,

=== modified file 'kern/misc.c'

misc.c +23 -10
@@ -951,22 +951,29 @@
   return dest;
 }
 
-/* Convert an UTF-8 string to an UCS-4 string. Return the number of
-   characters converted. DEST must be able to hold at least SIZE
-   characters (when the input is unknown). If an invalid sequence is found,
-   return -1.  */
+/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
+   bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
+   Return the number of characters converted. DEST must be able to hold
+   at least DESTSIZE characters. If an invalid sequence is found, return -1.
+   If SRCEND is not NULL, then *SRCEND is set to the next byte after the
+   last byte used in SRC.  */
 grub_ssize_t
-grub_utf8_to_ucs4 (grub_uint32_t *dest, const grub_uint8_t *src,
-		   grub_size_t size)
+grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
+		   const grub_uint8_t *src, grub_size_t srcsize,
+		   const grub_uint8_t **srcend)
 {
   grub_uint32_t *p = dest;
   int count = 0;
   grub_uint32_t code = 0;
   
-  while (size--)
+  if (*srcend)
+    *srcend = src;
+
+  while (srcsize && destsize)
     {
       grub_uint32_t c = *src++;
-      
+      if (srcsize != -1)
+	srcsize--;
       if (count)
 	{
 	  if ((c & 0xc0) != 0x80)
@@ -983,6 +990,8 @@
 	}
       else
 	{
+	  if (c == 0)
+	    break;        /* NUL character terminates the string.  */
 	  if ((c & 0x80) == 0x00)
 	    code = c;
 	  else if ((c & 0xe0) == 0xc0)
@@ -1011,14 +1020,18 @@
 	      code = c & 0x01;
 	    }
 	  else
-	    /* invalid */
 	    return -1;
 	}
 
       if (count == 0)
-	*p++ = code;
+	{
+	  *p++ = code;
+	  destsize--;
+	}
     }
 
+  if (srcend)
+    *srcend = src;
   return p - dest;
 }
 

=== modified file 'kern/term.c'

term.c +1 -1
@@ -153,7 +153,7 @@
   grub_ssize_t ret;
 
   buf[size++] = c;
-  ret = grub_utf8_to_ucs4 (&code, buf, size);
+  ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0);
   
   if (ret > 0)
     {

=== modified file 'normal/menu.c'

menu.c +5 -3
@@ -117,19 +117,21 @@
 {
   int x;
   const char *title;
+  grub_size_t title_len;
   grub_ssize_t len;
   grub_uint32_t *unicode_title;
   grub_ssize_t i;
   grub_uint8_t old_color_normal, old_color_highlight;
 
   title = entry ? entry->title : "";
-  unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
+  title_len = grub_strlen (title);
+  unicode_title = grub_malloc (title_len * sizeof (*unicode_title));
   if (! unicode_title)
     /* XXX How to show this error?  */
     return;
   
-  len = grub_utf8_to_ucs4 (unicode_title, (grub_uint8_t *) title,
-			   grub_strlen (title));
+  len = grub_utf8_to_ucs4 (unicode_title, title_len,
+                           (grub_uint8_t *) title, -1, 0);
   if (len < 0)
     {
       /* It is an invalid sequence.  */

=== modified file 'term/gfxterm.c'

gfxterm.c +51 -26

191 lines not on this page · raw message

=== modified file 'term/i386/pc/vesafb.c'

i386/pc/vesafb.c +2 -1
@@ -250,10 +250,11 @@
 	  break;
 
 	default:
-	  return grub_font_get_glyph (code, bitmap, width);
+	  return grub_font_get_glyph_any (code, bitmap, width);
 	}
     }
 
+  /* TODO This is wrong for the new font module.  Should it be fixed?  */
   if (bitmap)
     grub_memcpy (bitmap,
 		 vga_font + code * virtual_screen.char_height,

=== modified file 'term/i386/pc/vga.c'

i386/pc/vga.c +28 -14

120 lines not on this page · raw message

=== modified file 'video/i386/pc/vbe.c'

i386/pc/vbe.c +39 -72

147 lines not on this page · raw message

=== modified file 'video/i386/pc/vbeutil.c'

i386/pc/vbeutil.c +27 -0
@@ -52,6 +52,11 @@
             + y * source->mode_info->pitch
             + x;
       break;
+
+    /* case 1: */
+      /* For 1-bit bitmaps, addressing needs to be done at the bit level
+       * and it doesn't make sense, in general, to ask for a pointer
+       * to a particular pixel's data. */
     }
 
   return ptr;
@@ -86,6 +91,17 @@
       color = *(grub_uint8_t *)get_data_ptr (source, x, y);
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          color = (*ptr >> bit_pos) & 0x01;
+        }
+      break;
+
     default:
       break;
     }
@@ -143,6 +159,17 @@
       }
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
+        }
+      break;
+
     default:
       break;
     }

=== modified file 'video/video.c'

video.c +0 -11
@@ -336,17 +336,6 @@
   return grub_video_adapter_active->fill_rect (color, x, y, width, height);
 }
 
-/* Blit glyph to screen using specified color.  */
-grub_err_t
-grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                       grub_video_color_t color, int x, int y)
-{
-  if (! grub_video_adapter_active)
-    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
-
-  return grub_video_adapter_active->blit_glyph (glyph, color, x, y);
-}
-
 /* Blit bitmap to screen.  */
 grub_err_t
 grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
#4 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Regards,
Colin

2008-10-30 Colin D Bennett <[email protected]>

New font engine supporting large and proportional fonts, PFF2 file format.

* commands/videotest.c (grub_cmd_videotest): Use new font API, test drawing UTF-8 Unicode text.
* conf/common.rmk (font_mod_SOURCES): Update source file list.
* font/font.c: New file.
* font/font_cmd.c: New file.
* font/manager.c: Deleted.

* include/grub/font.h: Update copyright years. (GRUB_FONT_MAGIC): Removed.
(grub_font): New forward declaration of struct. (grub_font_t): New typedef.
(grub_font_node): New struct.
(grub_font_list): New global symbol.
(grub_font_glyph): Updated data structure to support larger, variable size fonts and to support font metrics. (grub_font_glyph_t): Removed.
(grub_font_loader_init): New prototype.
(grub_font_load): New prototype.
(grub_font_get): New prototype.
(grub_font_get_name): New prototype. (grub_font_get_max_char_width): New prototype. (grub_font_get_max_char_height): New prototype. (grub_font_get_ascent): New prototype. (grub_font_get_descent): New prototype. (grub_font_get_leading): New prototype. (grub_font_get_height): New prototype. (grub_font_get_string_width): New prototype. (grub_font_load): New prototype.
(grub_font_get_glyph): New prototype. (grub_font_get_glyph_with_fallback): New prototype. (grub_font_draw_glyph): New prototype. (grub_font_draw_string): New prototype.

* include/grub/misc.h (grub_utf8_to_ucs4): Added parameters.

* include/grub/video.h (grub_font_glyph): Removed forward struct declaration.
(GRUB_VIDEO_MODE_TYPE_ALPHA): Changed bit mask value to make space for 1BIT_BITMAP.
(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise. (GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): New bit mask constant. (GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Updated to a wider mask to make space for 1BIT_BITMAP. (GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED): New blit format enum value. (grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, fg_red, fg_green, fg_blue, and fg_alpha fields.

* kern/misc.c (grub_utf8_to_ucs4): Support null-terminated UTF-8 strings and allow limiting the number of Unicode characters decoded.
* kern/term.c (grub_putchar): Pass additional arguments to grub_utf8_to_ucs4.
* normal/menu.c (print_entry): Pass destination maximum length to grub_utf8_to_ucs4.

* term/gfxterm.c (DEFAULT_CHAR_WIDTH): Removed. (DEFAULT_CHAR_HEIGHT): Removed.
(grub_virtual_screen): Added font field. (grub_virtual_screen_setup): Add font_name parameter. Initialize terminal font information.
(grub_gfxterm_init): Get font name from gfxterm_font environment variable. Pass font name to grub_virtual_screen_setup. (write_char): Place glyphs using their baseline, based on the font ascent.
(write_cursor): Draw cursor using font ascent as a reference. (grub_gfxterm_putchar): Use new font API. Breaks bi-width font support.
(grub_gfxterm_getcharwidth): Assume all characters are 1 character in width. Breaks bi-width font support. (grub_vga_getcharwidth): Always return a width of 1.

* term/i386/pc/vesafb.c (grub_virtual_screen_get_glyph): Use new font API. Breaks vesafb glyph drawing, since it copied the glyph data directly, but now glyphs use a different storage format. This code shouldn't compile, but GRUB builds ok!
* term/i386/pc/vga.c (font): New static variable. (grub_vga_mod_init): Get a font using the new font API. (write_char): Broken. Commented out code with #if 0 since it will need to be rewritten to handle the new glyph storage format if we want to maintain the vga terminal.
(grub_vga_putchar): Update to use new font API; breaks support for bi-width fonts.

* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Support GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color_int): Likewise. (grub_video_vbe_blit_glyph): Deleted. (grub_video_vbe_adapter): Deleted blit_glyph member.

* video/i386/pc/vbeutil.c (get_data_ptr): Add a comment to the switch statement indicating why it is unimplemented for 1-bit bitmaps. (get_pixel): Support 1-bit bitmaps.
(set_pixel): Support 1-bit bitmaps.

* video/video.c (grub_video_blit_glyph): Renamed coordinate arguments for clarity.
(grub_video_draw_string): New function.

=== modified file 'commands/videotest.c'

videotest.c +75 -13
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  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
@@ -36,17 +36,21 @@
                         GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != GRUB_ERR_NONE)
     return grub_errno;
 
-  grub_getkey ();
-
   grub_video_color_t color;
   unsigned int x;
   unsigned int y;
   unsigned int width;
   unsigned int height;
   int i;
-  struct grub_font_glyph glyph;
+  grub_font_t sansbig;
+  grub_font_t sans;
+  grub_font_t sanssmall;
+  grub_font_t fixed;
+  struct grub_font_glyph *glyph;
   struct grub_video_render_target *text_layer;
   grub_video_color_t palette[16];
+  const char *str;
+  int texty;
 
   grub_video_get_viewport (&x, &y, &width, &height);
 
@@ -65,8 +69,15 @@
   color = grub_video_map_rgb (0, 255, 255);
   grub_video_fill_rect (color, 100, 100, 100, 100);
 
-  grub_font_get_glyph ('*', &glyph);  
-  grub_video_blit_glyph (&glyph, color, 200 ,0);
+  sansbig = grub_font_get ("Helvetica Bold 24");
+  sans = grub_font_get ("Helvetica Bold 14");
+  sanssmall = grub_font_get ("Helvetica 8");
+  fixed = grub_font_get ("Fixed 20");
+  if (! sansbig || ! sans || ! sanssmall || ! fixed)
+    return grub_error (GRUB_ERR_BAD_FONT, "No font loaded.");
+
+  glyph = grub_font_get_glyph (fixed, '*');
+  grub_font_draw_glyph (glyph, color, 200 ,0);
 
   grub_video_set_viewport (x + 150, y + 150,
                            width - 150 * 2, height - 150 * 2);
@@ -77,18 +88,69 @@
 
   color = grub_video_map_rgb (255, 255, 255);
 
-  grub_font_get_glyph ('A', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16, 16);
-  grub_font_get_glyph ('B', &glyph);
-  grub_video_blit_glyph (&glyph, color, 16 * 2, 16);
-
-  grub_font_get_glyph ('*', &glyph);
+  texty = 32;
+  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
+                         sans, color, 16, texty);
+  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
+
+  texty += grub_font_get_ascent (fixed);
+  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
+                         fixed, color, 16, texty);
+  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
+
+  /* To convert Unicode characters into UTF-8 for this test, the following
+     command is useful:
+       echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
+     This converts the Unicode character U+263A to UTF-8.  */
+
+  /* Characters used:
+     Code point  Description                    UTF-8 encoding
+     ----------- ------------------------------ --------------
+     U+263A      unfilled smiley face           E2 98 BA
+     U+00A1      inverted exclamation point     C2 A1
+     U+00A3      British pound currency symbol  C2 A3
+     U+03C4      Greek tau                      CF 84
+     U+00E4      lowercase letter a with umlaut C3 A4
+     U+2124      set 'Z' symbol (integers)      E2 84 A4
+     U+2287      subset symbol                  E2 8A 87
+     U+211D      set 'R' symbol (real numbers)  E2 84 9D  */
+
+  str =
+    "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
+    " \xC2\xA1\xCF\x84\xC3\xA4u! "
+    " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
+  color = grub_video_map_rgb (128, 128, 255);
+
+  /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
+  texty += grub_font_get_ascent(fixed);
+  grub_font_draw_string (str, fixed, color, 16, texty);
+  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
+
+  /* Some character don't exist in the Helvetica font, so the font engine
+     will fall back to using glyphs from another font that does contain them.
+     TODO The font engine should be smart about selecting a replacement font
+     and prioritize fonts with similar sizes.  */
+
+  texty += grub_font_get_ascent(sansbig);
+  grub_font_draw_string (str, sansbig, color, 16, texty);
+  texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
+
+  texty += grub_font_get_ascent(sans);
+  grub_font_draw_string (str, sans, color, 16, texty);
+  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
+
+  texty += grub_font_get_ascent(sanssmall);
+  grub_font_draw_string (str, sanssmall, color, 16, texty);
+  texty += (grub_font_get_descent (sanssmall)
+            + grub_font_get_leading (sanssmall));
+
+  glyph = grub_font_get_glyph (fixed, '*');
 
   for (i = 0; i < 16; i++)
     {
       color = grub_video_map_color (i);
       palette[i] = color;
-      grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32);
+      grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
     }
 
   grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

=== modified file 'conf/common.rmk'

common.rmk +1 -1
@@ -364,7 +364,7 @@
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 

=== added file 'font/font.c'

font.c +1004 -0

1,004 lines not on this page · raw message

=== added file 'font/font_cmd.c'

font_cmd.c +77 -0

77 lines not on this page · raw message

=== removed file 'font/manager.c'

manager.c +0 -283

283 lines not on this page · raw message

=== modified file 'include/grub/font.h'

grub/font.h +87 -25

127 lines not on this page · raw message

=== modified file 'include/grub/misc.h'

grub/misc.h +3 -1
@@ -77,8 +77,10 @@
 					       grub_uint16_t *src,
 					       grub_size_t size);
 grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
+					     grub_size_t destsize,
 					     const grub_uint8_t *src,
-					     grub_size_t size);
+					     grub_size_t srcsize,
+					     const grub_uint8_t **srcend);
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint32_t d, grub_uint32_t *r);
 

=== modified file 'include/grub/video.h'

grub/video.h +19 -11
@@ -31,17 +31,17 @@
 struct grub_video_render_target;
 
 /* Forward declarations for used data structures.  */
-struct grub_font_glyph;
 struct grub_video_bitmap;
 
 /* Defines used to describe video mode or rendering target.  */
-#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000008
-#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000004
+#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000020
+#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000010
+#define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP	0x00000004
 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR	0x00000002
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
 /* Defines used to mask flags.  */
-#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x00000003
+#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x0000000F
 
 /* Defines used to specify requested bit depth.  */
 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK		0x0000ff00
@@ -72,7 +72,9 @@
     GRUB_VIDEO_BLIT_FORMAT_BGR_565,
 
     /* When needed, decode color or just use value as is.  */
-    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
+    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+    /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
+    GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
   };
 
 /* Define blitting operators.  */
@@ -135,6 +137,18 @@
   /* What is location of reserved color bits.  In Index Color mode,
      this is 0.  */
   unsigned int reserved_field_pos;
+
+  /* For 1-bit bitmaps, the background color.  Used for bits = 0. */
+  grub_uint8_t bg_red;
+  grub_uint8_t bg_green;
+  grub_uint8_t bg_blue;
+  grub_uint8_t bg_alpha;
+
+  /* For 1-bit bitmaps, the foreground color.  Used for bits = 1. */
+  grub_uint8_t fg_red;
+  grub_uint8_t fg_green;
+  grub_uint8_t fg_blue;
+  grub_uint8_t fg_alpha;
 };
 
 struct grub_video_palette_data
@@ -188,9 +202,6 @@
   grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
                            unsigned int width, unsigned int height);
 
-  grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph,
-                            grub_video_color_t color, int x, int y);
-
   grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
                              enum grub_video_blit_operators oper,
                              int x, int y, int offset_x, int offset_y,
@@ -260,9 +271,6 @@
 grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y,
                                  unsigned int width, unsigned int height);
 
-grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                                  grub_video_color_t color, int x, int y);
-
 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
                                    enum grub_video_blit_operators oper,
                                    int x, int y, int offset_x, int offset_y,

=== modified file 'kern/misc.c'

misc.c +23 -10
@@ -951,22 +951,29 @@
   return dest;
 }
 
-/* Convert an UTF-8 string to an UCS-4 string. Return the number of
-   characters converted. DEST must be able to hold at least SIZE
-   characters (when the input is unknown). If an invalid sequence is found,
-   return -1.  */
+/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
+   bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
+   Return the number of characters converted. DEST must be able to hold
+   at least DESTSIZE characters. If an invalid sequence is found, return -1.
+   If SRCEND is not NULL, then *SRCEND is set to the next byte after the
+   last byte used in SRC.  */
 grub_ssize_t
-grub_utf8_to_ucs4 (grub_uint32_t *dest, const grub_uint8_t *src,
-		   grub_size_t size)
+grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
+		   const grub_uint8_t *src, grub_size_t srcsize,
+		   const grub_uint8_t **srcend)
 {
   grub_uint32_t *p = dest;
   int count = 0;
   grub_uint32_t code = 0;
   
-  while (size--)
+  if (*srcend)
+    *srcend = src;
+
+  while (srcsize && destsize)
     {
       grub_uint32_t c = *src++;
-      
+      if (srcsize != -1)
+	srcsize--;
       if (count)
 	{
 	  if ((c & 0xc0) != 0x80)
@@ -983,6 +990,8 @@
 	}
       else
 	{
+	  if (c == 0)
+	    break;        /* NUL character terminates the string.  */
 	  if ((c & 0x80) == 0x00)
 	    code = c;
 	  else if ((c & 0xe0) == 0xc0)
@@ -1011,14 +1020,18 @@
 	      code = c & 0x01;
 	    }
 	  else
-	    /* invalid */
 	    return -1;
 	}
 
       if (count == 0)
-	*p++ = code;
+	{
+	  *p++ = code;
+	  destsize--;
+	}
     }
 
+  if (srcend)
+    *srcend = src;
   return p - dest;
 }
 

=== modified file 'kern/term.c'

term.c +1 -1
@@ -153,7 +153,7 @@
   grub_ssize_t ret;
 
   buf[size++] = c;
-  ret = grub_utf8_to_ucs4 (&code, buf, size);
+  ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0);
   
   if (ret > 0)
     {

=== modified file 'normal/menu.c'

menu.c +5 -3
@@ -117,19 +117,21 @@
 {
   int x;
   const char *title;
+  grub_size_t title_len;
   grub_ssize_t len;
   grub_uint32_t *unicode_title;
   grub_ssize_t i;
   grub_uint8_t old_color_normal, old_color_highlight;
 
   title = entry ? entry->title : "";
-  unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
+  title_len = grub_strlen (title);
+  unicode_title = grub_malloc (title_len * sizeof (*unicode_title));
   if (! unicode_title)
     /* XXX How to show this error?  */
     return;
   
-  len = grub_utf8_to_ucs4 (unicode_title, (grub_uint8_t *) title,
-			   grub_strlen (title));
+  len = grub_utf8_to_ucs4 (unicode_title, title_len,
+                           (grub_uint8_t *) title, -1, 0);
   if (len < 0)
     {
       /* It is an invalid sequence.  */

=== modified file 'term/gfxterm.c'

gfxterm.c +51 -26

191 lines not on this page · raw message

=== modified file 'term/i386/pc/vesafb.c'

i386/pc/vesafb.c +2 -1
@@ -250,10 +250,11 @@
 	  break;
 
 	default:
-	  return grub_font_get_glyph (code, bitmap, width);
+	  return grub_font_get_glyph_any (code, bitmap, width);
 	}
     }
 
+  /* TODO This is wrong for the new font module.  Should it be fixed?  */
   if (bitmap)
     grub_memcpy (bitmap,
 		 vga_font + code * virtual_screen.char_height,

=== modified file 'term/i386/pc/vga.c'

i386/pc/vga.c +28 -14

120 lines not on this page · raw message

=== modified file 'video/i386/pc/vbe.c'

i386/pc/vbe.c +39 -72

147 lines not on this page · raw message

=== modified file 'video/i386/pc/vbeutil.c'

i386/pc/vbeutil.c +27 -0
@@ -52,6 +52,11 @@
             + y * source->mode_info->pitch
             + x;
       break;
+
+    /* case 1: */
+      /* For 1-bit bitmaps, addressing needs to be done at the bit level
+       * and it doesn't make sense, in general, to ask for a pointer
+       * to a particular pixel's data. */
     }
 
   return ptr;
@@ -86,6 +91,17 @@
       color = *(grub_uint8_t *)get_data_ptr (source, x, y);
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          color = (*ptr >> bit_pos) & 0x01;
+        }
+      break;
+
     default:
       break;
     }
@@ -143,6 +159,17 @@
       }
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
+        }
+      break;
+
     default:
       break;
     }

=== modified file 'video/video.c'

video.c +0 -11
@@ -336,17 +336,6 @@
   return grub_video_adapter_active->fill_rect (color, x, y, width, height);
 }
 
-/* Blit glyph to screen using specified color.  */
-grub_err_t
-grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                       grub_video_color_t color, int x, int y)
-{
-  if (! grub_video_adapter_active)
-    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
-
-  return grub_video_adapter_active->blit_glyph (glyph, color, x, y);
-}
-
 /* Blit bitmap to screen.  */
 grub_err_t
 grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
#5 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

will all these fonts be included in the next release of GRUB 2?

2008/10/31 Colin D Bennett <[email protected]>

Quoted 21 lines

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Regards,
Colin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 1 line · On Fri, 31 Oct 2008 18:31:31 +0000 "Matt Sturgeon" <[email protected]> wrote:

will all these fonts be included in the next release of GRUB 2?

Probably not; the licenses may not be compatible with GPLv3. These fonts are ones that came with X.Org on my system, and I just exported them to BDF files with 'xmbdfed' and then converted the BDF files to PF2 files with the GRUB font converter.

Some of the fonts I used during my development of the graphical menu system are from the "Artwiz" bitmap font collection, which is a set of several fonts, but most all quite small in size (really no selection of font size within a font).

I haven't spent a lot of time seeking out good free fonts that we could include in GRUB. I use the fabulous Liberation TrueType fonts on my desktop, but these are outline fonts, not bitmap fonts. I tried creating a bitmap font from some decent TrueType outline fonts using xmbdfed, but the results were quite ugly, so I gave up on that.

Regards,
Colin

#7 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 15 lines · Colin D Bennett
Quoted 1 line · On Fri, 31 Oct 2008 18:31:31 +0000 "Matt Sturgeon" <[email protected]> wrote:

will all these fonts be included in the next release of GRUB 2?

Probably not; the licenses may not be compatible with GPLv3. These fonts are ones that came with X.Org on my system, and I just exported them to BDF files with 'xmbdfed' and then converted the BDF files to PF2 files with the GRUB font converter.

Some of the fonts I used during my development of the graphical menu system are from the "Artwiz" bitmap font collection, which is a set of several fonts, but most all quite small in size (really no selection of font size within a font).

Quoted 5 lines

I haven't spent a lot of time seeking out good free fonts that we could include in GRUB. I use the fabulous Liberation TrueType fonts on my desktop, but these are outline fonts, not bitmap fonts. I tried creating a bitmap font from some decent TrueType outline fonts using xmbdfed, but the results were quite ugly, so I gave up on that.

Font issue is actually a bit problematic. At least there has to be some font somewhere that we can give to users so they can actually use graphical terminal :)

Are there any free fonts that we can use ?

#8 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 6 lines · Vesa Jääskeläinen

Font issue is actually a bit problematic. At least there has to be some font somewhere that we can give to users so they can actually use graphical terminal :)

Are there any free fonts that we can use ?

Isn't unifont good enough? The Debian packages have been using that for ages.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#9 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 10 lines · On Tue, 4 Nov 2008 21:31:38 +0100 Robert Millan <[email protected]> wrote:
Quoted 6 lines · Vesa Jääskeläinen

Font issue is actually a bit problematic. At least there has to be some font somewhere that we can give to users so they can actually use graphical terminal :)

Are there any free fonts that we can use ?

Isn't unifont good enough? The Debian packages have been using that for ages.

For graphical terminal, yes, but for a nice theme as users will expect we need multiple font sizes, as well as proportional fonts.

I am sure there are additional free bitmap fonts we can use, I just haven't had a chance to look into it in detail yet.

Regards,
Colin

#10 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

In reply to Colin D Bennett
Quoted 11 lines · Colin D Bennett

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Hi Colin,

I applied this patch against SVN today and tried it out. And noticed that gfxterm gets a bit "broken" after this. Was this the thing that I promised to look at :) ? Or was my merge just incomplete?

Videotest was fine however. (or how fine it can be with just unifont.bdf)

After:
loadfont /boot/grub/unifont.pf2

lsfonts gives:
Loaded fonts:
Unknown -1

Is this expected?

Thanks,
Vesa Jääskeläinen

#11 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 13 lines · On Sat, 06 Dec 2008 22:18:14 +0200 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 11 lines · Colin D Bennett

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Quoted 5 lines

Hi Colin,

I applied this patch against SVN today and tried it out. And noticed that gfxterm gets a bit "broken" after this. Was this the thing that I promised to look at :) ? Or was my merge just incomplete?

There are two problems with gfxterm now:

1. unifont has problems rendering glyphs: they seem to be rendered too wide (maybe), and the cursor ends up being drawn after each character resulting in t_e_x_t_ _t_h_a_t_ _l_o_o_k_s like this.

2. With fonts that otherwise work (i.e. "Fixed 10" for me), sometimes a few random junk characters with weird background/foreground colors show up in gfxterm -- mainly when it is first set as the terminal, leading me to think that there is some uninitialized memory.

Quoted 2 lines

Videotest was fine however. (or how fine it can be with just unifont.bdf)

I should look closely at unifont.bdf and the .pf2 conversion and see why GRUB is rendering it weirdly in gfxterm.

Quoted 8 lines

After:
loadfont /boot/grub/unifont.pf2

lsfonts gives:
Loaded fonts:
Unknown -1

Is this expected?

Yes, since there is no 'POINT_SIZE' or 'FAMILY_NAME' attribute in the unifont.bdf file. I added these manually, and it then showed up properly in the lsfonts listing (and can then be specified using the name/size in GRUB).

--- gnu-unifont-2008-04-06.bdf 2008-12-22 08:48:00.000000000
-0800 +++ gnu-unifont-2008-04-06_tagged.bdf 2008-12-22
09:10:22.000000000 -0800 @@ -1,5 +1,8 @@
STARTFONT 2.1
FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1
+FAMILY_NAME "unifont"
+WEIGHT_NAME "medium"
+POINT_SIZE 100
SIZE 16 75 75
FONTBOUNDINGBOX 16 16 0 -2
STARTPROPERTIES 3

The font converter should probably fall back on the file's name and the font's pixel size if such specifications are missing in the BDF file.

Sorry for the delay getting back to you; now that the font patches are going in, I will be ready to continue work on submitting the graphical menu system patches. I've received e-mails from a number of people who have found my project web site and want to try out the graphical menu, and are asking when it will be merged into GRUB.

Regards,
Colin

#12 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 27 lines · Colin D Bennett
Quoted 12 lines · On Sat, 06 Dec 2008 22:18:14 +0200 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 11 lines · Colin D Bennett

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Quoted 5 lines

Hi Colin,

I applied this patch against SVN today and tried it out. And noticed that gfxterm gets a bit "broken" after this. Was this the thing that I promised to look at :) ? Or was my merge just incomplete?

There are two problems with gfxterm now:

1. unifont has problems rendering glyphs: they seem to be rendered too wide (maybe), and the cursor ends up being drawn after each character resulting in t_e_x_t_ _t_h_a_t_ _l_o_o_k_s like this.

Quoted 5 lines

2. With fonts that otherwise work (i.e. "Fixed 10" for me), sometimes a few random junk characters with weird background/foreground colors show up in gfxterm -- mainly when it is first set as the terminal, leading me to think that there is some uninitialized memory.

I think I have workable solution for these now in my local copy.

Quoted 5 lines
Quoted 2 lines

Videotest was fine however. (or how fine it can be with just unifont.bdf)

I should look closely at unifont.bdf and the .pf2 conversion and see why GRUB is rendering it weirdly in gfxterm.

Actually what we want is to have improved conversion tool.

If I make full conversion it generates ~1.7 MiB font file which does not fit to floppy. Now if we could specify unicode ranges what to put there it would make them smaller.

This would be similar to how you specify ranges to old pff converter. I was planning to make such modification to handle near term goal.

Actually it would be nice if converter tool would be in C. Then it could be compiled and executed easily during normal compilation process. Viewer application is not so important and it can be external to project . Same time with C implementation it would be easy to add compression there too.

Quoted 7 lines
Quoted 7 lines

After:
loadfont /boot/grub/unifont.pf2

lsfonts gives:
Loaded fonts:
Unknown -1

Quoted 6 lines
Quoted 1 line

Is this expected?

Yes, since there is no 'POINT_SIZE' or 'FAMILY_NAME' attribute in the unifont.bdf file. I added these manually, and it then showed up properly in the lsfonts listing (and can then be specified using the name/size in GRUB).

Perhaps this addition should be moved to GNU Unifont's upstream?

Quoted 16 lines

--- gnu-unifont-2008-04-06.bdf 2008-12-22 08:48:00.000000000
-0800 +++ gnu-unifont-2008-04-06_tagged.bdf 2008-12-22
09:10:22.000000000 -0800 @@ -1,5 +1,8 @@
STARTFONT 2.1
FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1

(quoted diff) +3 -0
+FAMILY_NAME "unifont"
+WEIGHT_NAME "medium"
+POINT_SIZE 100
 SIZE 16 75 75
 FONTBOUNDINGBOX 16 16 0 -2
 STARTPROPERTIES 3

The font converter should probably fall back on the file's name and the font's pixel size if such specifications are missing in the BDF file.

Quoted 5 lines

Sorry for the delay getting back to you; now that the font patches are going in, I will be ready to continue work on submitting the graphical menu system patches. I've received e-mails from a number of people who have found my project web site and want to try out the graphical menu, and are asking when it will be merged into GRUB.

I'll try to get them in. But I have to make it in way to normal grub operation do not break at same time. Temporary this means probably that toolchain is there in Java form unless you can make quickly the new converter. It can start without compression. What we want is to match functionality of old font converter. Eg. specify ranges and then generate file based on that one.

Thanks,
Vesa Jääskeläinen

#13 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 29 lines · On Tue, 23 Dec 2008 20:39:15 +0200 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 28 lines · Colin D Bennett
Quoted 12 lines · On Sat, 06 Dec 2008 22:18:14 +0200 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 11 lines · Colin D Bennett

Update:

I fixed an error pointed out to me by Y.Volta:
In grub_font_get(), if no fonts are loaded, a null pointer is dereferenced. This is fixed in the attached patch.

The grub_font_get() function now returns a dummy font object (a statically allocated font object with no characters) so that callers of grub_font_get() can be assured that the return value will never be NULL. If no fonts are loaded, then the "unknown glyph" will be used for all characters, but it will be safe.

Quoted 6 lines

Hi Colin,

I applied this patch against SVN today and tried it out. And noticed that gfxterm gets a bit "broken" after this. Was this the thing that I promised to look at :) ? Or was my merge just incomplete?

There are two problems with gfxterm now:

1. unifont has problems rendering glyphs: they seem to be rendered too wide (maybe), and the cursor ends up being drawn after each character resulting in t_e_x_t_ _t_h_a_t_ _l_o_o_k_s like this.

Quoted 7 lines
Quoted 5 lines

2. With fonts that otherwise work (i.e. "Fixed 10" for me), sometimes a few random junk characters with weird background/foreground colors show up in gfxterm -- mainly when it is first set as the terminal, leading me to think that there is some uninitialized memory.

I think I have workable solution for these now in my local copy.

Great.

Quoted 11 lines
Quoted 5 lines
Quoted 2 lines

Videotest was fine however. (or how fine it can be with just unifont.bdf)

I should look closely at unifont.bdf and the .pf2 conversion and see why GRUB is rendering it weirdly in gfxterm.

Actually what we want is to have improved conversion tool.

If I make full conversion it generates ~1.7 MiB font file which does not fit to floppy. Now if we could specify unicode ranges what to put there it would make them smaller.

Also, I'd like to add LZMA compression as previously discussed, which I think would give a huge improvement.

Quoted 8 lines

This would be similar to how you specify ranges to old pff converter. I was planning to make such modification to handle near term goal.

Actually it would be nice if converter tool would be in C. Then it could be compiled and executed easily during normal compilation process. Viewer application is not so important and it can be external to project . Same time with C implementation it would be easy to add compression there too.

It certainly could be rewritten in C, but it would take some time.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

After:
loadfont /boot/grub/unifont.pf2

lsfonts gives:
Loaded fonts:
Unknown -1

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Is this expected?

Yes, since there is no 'POINT_SIZE' or 'FAMILY_NAME' attribute in the unifont.bdf file. I added these manually, and it then showed up properly in the lsfonts listing (and can then be specified using the name/size in GRUB).

Perhaps this addition should be moved to GNU Unifont's upstream?

Perhaps.

Quoted 6 lines
Quoted 5 lines

Sorry for the delay getting back to you; now that the font patches are going in, I will be ready to continue work on submitting the graphical menu system patches. I've received e-mails from a number of people who have found my project web site and want to try out the graphical menu, and are asking when it will be merged into GRUB.

Quoted 6 lines

I'll try to get them in. But I have to make it in way to normal grub operation do not break at same time. Temporary this means probably that toolchain is there in Java form unless you can make quickly the new converter. It can start without compression. What we want is to match functionality of old font converter. Eg. specify ranges and then generate file based on that one.

Well, I don't have time right now to rewrite the converter; not for a couple of weeks, at least. I'm certainly willing to do it, so I'll get to it when I can, and then we can replace the Java converter.

Regards,
Colin

#14 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 3 lines · Colin D Bennett

Well, I don't have time right now to rewrite the converter; not for a couple of weeks, at least. I'm certainly willing to do it, so I'll get to it when I can, and then we can replace the Java converter.

While we wait for that I have here a counter patch for the font engine.

If there are no comments about it in near term this will be committed to SVN.

To use automatic font conversion (unifont.bdf->ascii.pf2 and unicode.pf2), install bf-utf-source (ubuntu and probably debian). Font converter uses Java temporary. So when font compilation is enable font converter will be compiled and executed. Otherwise Java is not needed in anyway. Tested with Sun Java 1.6 on x86-64.

grub-mkconfig should generate new grub.cfg with changed font commands.

To convert custom fonts look for ascii.pf2 in Makefile.in and use matching commands to convert your fonts. These will be documented on Wiki once committed.

2008-12-28 Colin D Bennett <[email protected]>

New font engine.

Additional changes by Vesa Jääskeläinen <[email protected]> to adapt to
build system and fixed gfxterm.c to work with different sized fonts.

* configure.ac: Changed UNIFONT_HEX to UNIFONT_BDF.

* configure: Re-generated.

* DISTLIST: Removed font/manager.c.
Added font/font.c.
Added font/font_cmd.c.

* Makefile.in: Changed UNIFONT_HEX to UNIFONT_BDF. Added Font tool compilation.

* include/grub/misc.h (grub_utf8_to_ucs4): Changed prototype. Changed
users.

* kern/misc.c (grub_utf8_to_ucs4): Changed prototype.

* kern/term.c: Changed users of grub_utf8_to_ucs4.

* normal/menu.c: Likewise.

* conf/common.rmk (font_mod_SOURCES): Removed font/manager.c. (font_mod_SOURCES): Added font/font_cmd.c, font/font.c.

* include/grub/font.h: Replaced with new file.

* include/grub/video.h (GRUB_VIDEO_MODE_TYPE_ALPHA): Changed value. (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise. (GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Likewise. (GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): Added. (grub_video_blit_format): Added GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED. (grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, fg_red, fg_green, fg_blue, fg_alpha. (grub_video_adapter): Removed blit_glyph. (grub_video_blit_glyph): Removed.

* font/manager.c: Removed file.

* font/font.c: New file.

* font/font_cmd.c: Likewise.

* video/video.c (grub_video_blit_glyph): Removed.

* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Added 1-bit support. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color_int): Likewise. (grub_video_vbe_blit_glyph): Removed. (grub_video_vbe_adapter): Removed blit_glyph.

* video/i386/pc/vbeutil.c (get_data_ptr): Added 1-bit support. (get_pixel): Likewise.
(set_pixel): Likewise.

* commands/videotest.c (grub_cmd_videotest): Added more tests for fonts.

* term/gfxterm.c: Adapted to new font engine.

* term/i386/pc/vesafb.c: Marked as deprecated. Made it compile.

* term/i386/pc/vga.c: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/BDFLoader.java: New file.

* util/fonttool/src/org/gnu/grub/fonttool/CharDefs.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Converter.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Font.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Glyph.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/PFF2Sections.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/PFF2Writer.java: Likewise.

* util/grub.d/00_header.in: Changed to use new loadfont command.

* util/grub-mkconfig_lib.in: Changed font extension.

#15 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

And the actual patch...

ChangeLog +89 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,92 @@
+2008-12-28  Colin D Bennett  <[email protected]>
+
+	New font engine.
+	
+	Additional changes by Vesa Jääskeläinen <[email protected]> to adapt to
+	build system and fixed gfxterm.c to work with different	sized fonts.
+
+	* configure.ac: Changed UNIFONT_HEX to UNIFONT_BDF.
+	
+	* configure: Re-generated.
+	
+	* DISTLIST: Removed font/manager.c.
+	Added font/font.c.
+	Added font/font_cmd.c.
+	
+	* Makefile.in: Changed UNIFONT_HEX to UNIFONT_BDF.  Added Font tool
+	compilation.
+	
+	* include/grub/misc.h (grub_utf8_to_ucs4): Changed prototype.  Changed users.
+	
+	* kern/misc.c (grub_utf8_to_ucs4): Changed prototype. 
+
+	* kern/term.c: Changed users of grub_utf8_to_ucs4.
+	
+	* normal/menu.c: Likewise.
+		
+	* conf/common.rmk (font_mod_SOURCES): Removed font/manager.c.
+	(font_mod_SOURCES): Added font/font_cmd.c, font/font.c.
+	
+	* include/grub/font.h: Replaced with new file.
+	
+	* include/grub/video.h (GRUB_VIDEO_MODE_TYPE_ALPHA): Changed value.
+	(GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise.
+	(GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Likewise.
+	(GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): Added.
+	(grub_video_blit_format): Added GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED.
+	(grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, 
+	fg_red, fg_green, fg_blue, fg_alpha.
+	(grub_video_adapter): Removed blit_glyph.
+	(grub_video_blit_glyph): Removed.	
+	
+	* font/manager.c: Removed file.
+	
+	* font/font.c: New file. 
+	
+	* font/font_cmd.c: Likewise.
+	
+	* video/video.c (grub_video_blit_glyph): Removed.
+	
+	* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Added 1-bit support.
+	(grub_video_vbe_map_rgba): Likewise.
+	(grub_video_vbe_unmap_color_int): Likewise.
+	(grub_video_vbe_blit_glyph): Removed.
+	(grub_video_vbe_adapter): Removed blit_glyph.
+	
+	* video/i386/pc/vbeutil.c (get_data_ptr): Added 1-bit support.
+	(get_pixel): Likewise.
+	(set_pixel): Likewise. 
+	
+	* commands/videotest.c (grub_cmd_videotest): Added more tests for fonts.
+	
+	* term/gfxterm.c: Adapted to new font engine.
+	
+	* term/i386/pc/vesafb.c: Marked as deprecated.  Made it compile.
+	
+	* term/i386/pc/vga.c: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/BDFLoader.java: New file.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/CharDefs.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/Converter.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/Font.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/Glyph.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/PFF2Sections.java: Likewise.
+	
+	* util/fonttool/src/org/gnu/grub/fonttool/PFF2Writer.java: Likewise.
+
+	* util/grub.d/00_header.in: Changed to use new loadfont command.
+	
+	* util/grub-mkconfig_lib.in: Changed font extension.
+	
 2008-12-12  Alex Smith  <[email protected]>
 
 	* fs/i386/pc/pxe.c (grub_pxefs_open): Handle the one open connection
term.c +2 -2
Index: kern/term.c
===================================================================
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003,2005,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2005,2007,2008  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
@@ -208,7 +208,7 @@
   grub_ssize_t ret;
 
   buf[size++] = c;
-  ret = grub_utf8_to_ucs4 (&code, buf, size);
+  ret = grub_utf8_to_ucs4 (&code, 1, buf, size, 0);
   
   if (ret > 0)
     {
misc.c +24 -10
Index: kern/misc.c
===================================================================
@@ -951,13 +951,16 @@
   return dest;
 }
 
-/* Convert an UTF-8 string to an UCS-4 string. Return the number of
-   characters converted. DEST must be able to hold at least SIZE
-   characters (when the input is unknown). If an invalid sequence is found,
-   return -1.  */
+/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
+   bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
+   Return the number of characters converted. DEST must be able to hold
+   at least DESTSIZE characters. If an invalid sequence is found, return -1.
+   If SRCEND is not NULL, then *SRCEND is set to the next byte after the
+   last byte used in SRC.  */
 grub_ssize_t
-grub_utf8_to_ucs4 (grub_uint32_t *dest, const grub_uint8_t *src,
-		   grub_size_t size)
+grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
+		   const grub_uint8_t *src, grub_size_t srcsize,
+		   const grub_uint8_t **srcend)
 {
   grub_uint32_t *p = dest;
   int count = 0;
@@ -963,10 +966,14 @@
   int count = 0;
   grub_uint32_t code = 0;
   
-  while (size--)
+  if (srcend)
+    *srcend = src;
+
+  while (srcsize && destsize)
     {
       grub_uint32_t c = *src++;
-      
+      if (srcsize != (grub_size_t)-1)
+	srcsize--;
       if (count)
 	{
 	  if ((c & 0xc0) != 0x80)
@@ -983,6 +990,9 @@
 	}
       else
 	{
+	  if (c == 0)
+	    break;
+	  
 	  if ((c & 0x80) == 0x00)
 	    code = c;
 	  else if ((c & 0xe0) == 0xc0)
@@ -1011,7 +1021,6 @@
 	      code = c & 0x01;
 	    }
 	  else
-	    /* invalid */
 	    return -1;
 	}
 
@@ -1016,9 +1025,14 @@
 	}
 
       if (count == 0)
-	*p++ = code;
+	{
+	  *p++ = code;
+	  destsize--;
+	}
     }
 
+  if (srcend)
+    *srcend = src;
   return p - dest;
 }
 
gfxterm.c +137 -55

406 lines not on this page · raw message

i386/pc/vesafb.c +5 -2
Index: term/i386/pc/vesafb.c
===================================================================
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2005,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2005,2007,2008  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
@@ -16,6 +16,8 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+// TODO: Deprecated and broken. Scheduled for removal as there is VBE driver in Video subsystem.
+
 #include <grub/machine/memory.h>
 #include <grub/machine/vga.h>
 #include <grub/machine/vbe.h>
@@ -250,10 +252,11 @@
 	  break;
 
 	default:
-	  return grub_font_get_glyph (code, bitmap, width);
+	  return grub_font_get_glyph_any (code, bitmap, width);
 	}
     }
 
+  /* TODO This is wrong for the new font module.  Should it be fixed?  */
   if (bitmap)
     grub_memcpy (bitmap,
 		 vga_font + code * virtual_screen.char_height,
i386/pc/vga.c +30 -14

129 lines not on this page · raw message

common.rmk +1 -1
Index: conf/common.rmk
===================================================================
@@ -364,7 +364,7 @@
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For font.mod.
-font_mod_SOURCES = font/manager.c
+font_mod_SOURCES = font/font_cmd.c font/font.c
 font_mod_CFLAGS = $(COMMON_CFLAGS)
 font_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
menu.c +5 -3
Index: normal/menu.c
===================================================================
@@ -116,6 +116,7 @@
 {
   int x;
   const char *title;
+  grub_size_t title_len;
   grub_ssize_t len;
   grub_uint32_t *unicode_title;
   grub_ssize_t i;
@@ -122,7 +123,8 @@
   grub_uint8_t old_color_normal, old_color_highlight;
 
   title = entry ? entry->title : "";
-  unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
+  title_len = grub_strlen (title);
+  unicode_title = grub_malloc (title_len * sizeof (*unicode_title));
   if (! unicode_title)
     /* XXX How to show this error?  */
     return;
@@ -127,8 +129,8 @@
     /* XXX How to show this error?  */
     return;
   
-  len = grub_utf8_to_ucs4 (unicode_title, (grub_uint8_t *) title,
-			   grub_strlen (title));
+  len = grub_utf8_to_ucs4 (unicode_title, title_len,
+                           (grub_uint8_t *) title, -1, 0);
   if (len < 0)
     {
       /* It is an invalid sequence.  */
grub/misc.h +4 -2
Index: include/grub/misc.h
===================================================================
@@ -1,7 +1,7 @@
 /* misc.h - prototypes for misc functions */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003,2005,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2005,2006,2007,2008  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
@@ -77,8 +77,10 @@
 					       grub_uint16_t *src,
 					       grub_size_t size);
 grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
+					     grub_size_t destsize,
 					     const grub_uint8_t *src,
-					     grub_size_t size);
+					     grub_size_t srcsize,
+					     const grub_uint8_t **srcend);
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint32_t d, grub_uint32_t *r);
 
grub/font.h +85 -23

125 lines not on this page · raw message

grub/video.h +20 -11
Index: include/grub/video.h
===================================================================
@@ -31,12 +31,12 @@
 struct grub_video_render_target;
 
 /* Forward declarations for used data structures.  */
-struct grub_font_glyph;
 struct grub_video_bitmap;
 
 /* Defines used to describe video mode or rendering target.  */
-#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000008
-#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000004
+#define GRUB_VIDEO_MODE_TYPE_ALPHA		0x00000020
+#define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED	0x00000010
+#define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP	0x00000004
 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR	0x00000002
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
@@ -41,7 +41,7 @@
 #define GRUB_VIDEO_MODE_TYPE_RGB		0x00000001
 
 /* Defines used to mask flags.  */
-#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x00000003
+#define GRUB_VIDEO_MODE_TYPE_COLOR_MASK		0x0000000F
 
 /* Defines used to specify requested bit depth.  */
 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK		0x0000ff00
@@ -72,7 +72,10 @@
     GRUB_VIDEO_BLIT_FORMAT_BGR_565,
 
     /* When needed, decode color or just use value as is.  */
-    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
+    GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+    
+    /* Two color bitmap; bits packed: rows are not padded to byte boundary.  */
+    GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
   };
 
 /* Define blitting operators.  */
@@ -135,6 +138,18 @@
   /* What is location of reserved color bits.  In Index Color mode,
      this is 0.  */
   unsigned int reserved_field_pos;
+
+  /* For 1-bit bitmaps, the background color.  Used for bits = 0.  */
+  grub_uint8_t bg_red;
+  grub_uint8_t bg_green;
+  grub_uint8_t bg_blue;
+  grub_uint8_t bg_alpha;
+
+  /* For 1-bit bitmaps, the foreground color.  Used for bits = 1.  */
+  grub_uint8_t fg_red;
+  grub_uint8_t fg_green;
+  grub_uint8_t fg_blue;
+  grub_uint8_t fg_alpha;
 };
 
 struct grub_video_palette_data
@@ -188,9 +203,6 @@
   grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
                            unsigned int width, unsigned int height);
 
-  grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph,
-                            grub_video_color_t color, int x, int y);
-
   grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
                              enum grub_video_blit_operators oper,
                              int x, int y, int offset_x, int offset_y,
@@ -260,9 +272,6 @@
 grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y,
                                  unsigned int width, unsigned int height);
 
-grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                                  grub_video_color_t color, int x, int y);
-
 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
                                    enum grub_video_blit_operators oper,
                                    int x, int y, int offset_x, int offset_y,
Makefile.in +15 -8
Index: Makefile.in
===================================================================
@@ -1,6 +1,6 @@
 # -*- makefile -*-
 #
-# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007 Free Software Foundation, Inc.
+# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
 #
 # This Makefile.in is free software; the author
 # gives unlimited permission to copy and/or distribute it,
@@ -88,7 +88,7 @@
 LIBCURSES = @LIBCURSES@
 LIBLZO = @LIBLZO@
 YACC = @YACC@
-UNIFONT_HEX = @UNIFONT_HEX@
+UNIFONT_BDF = @UNIFONT_BDF@
 
 # Options.
 enable_grub_emu = @enable_grub_emu@
@@ -148,9 +148,9 @@
 partmap.lst: $(PARTMAPFILES)
 	cat $^ /dev/null | sort > $@
 
-ifeq (, $(UNIFONT_HEX))
+ifeq (, $(UNIFONT_BDF))
 else
-pkgdata_DATA += unicode.pff ascii.pff
+pkgdata_DATA += unicode.pf2 ascii.pf2
 
 # Arrows and lines are needed to draw the menu, so we always include them
 UNICODE_ARROWS=0x2190-0x2193
@@ -156,11 +156,18 @@
 UNICODE_ARROWS=0x2190-0x2193
 UNICODE_LINES=0x2501-0x251B
 
-unicode.pff: $(UNIFONT_HEX)
-	ruby $(srcdir)/util/unifont2pff.rb $(UNIFONT_HEX) > $@
+# Note: fonttool should be replaced with C only implementation
+
+$(builddir)/fonttool/fonttool.jar: 
+	mkdir -p "$(builddir)/fonttool/src"
+	javac -source 1.5 -target 1.5 -g -deprecation -encoding UTF-8 -d "$(builddir)/fonttool/src" `find "$(srcdir)/util/fonttool/src/" -name '*.java'`
+	jar cf $(builddir)/fonttool/fonttool.jar -C $(builddir)/fonttool/src .
 
-ascii.pff: $(UNIFONT_HEX)
-	ruby $(srcdir)/util/unifont2pff.rb 0x0-0x7f $(UNICODE_ARROWS) $(UNICODE_LINES) $(UNIFONT_HEX) > $@
+unicode.pf2: $(UNIFONT_BDF) $(builddir)/fonttool/fonttool.jar
+	java -cp $(builddir)/fonttool/fonttool.jar org.gnu.grub.fonttool.Converter --in=$(UNIFONT_BDF) --out=$@
+
+ascii.pf2: $(UNIFONT_BDF) $(builddir)/fonttool/fonttool.jar
+	java -cp $(builddir)/fonttool/fonttool.jar org.gnu.grub.fonttool.Converter --in=$(UNIFONT_BDF) --out=$@ 0x0-0x7f $(UNICODE_ARROWS) $(UNICODE_LINES)
 endif
 
 # Used for building modules externally
DISTLIST +2 -1
Index: DISTLIST
===================================================================
@@ -103,7 +103,8 @@
 docs/grub.cfg
 docs/grub.texi
 docs/texinfo.tex
-font/manager.c
+font/font.c
+font/font_cmd.c
 fs/affs.c
 fs/afs.c
 fs/cpio.c
configure +4 -4
Index: configure
===================================================================
@@ -667,7 +667,7 @@
 platform
 CMP
 YACC
-UNIFONT_HEX
+UNIFONT_BDF
 INSTALL_PROGRAM
 INSTALL_SCRIPT
 INSTALL_DATA
@@ -2107,9 +2107,9 @@
    { (exit 1); exit 1; }; }
 fi
 
-for file in /usr/share/unifont/unifont.hex ; do
+for file in /usr/src/unifont.bdf ; do
   if test -e $file ; then
-    UNIFONT_HEX=$file
+    UNIFONT_BDF=$file
 
     break
   fi
@@ -9110,7 +9110,7 @@
 platform!$platform$ac_delim
 CMP!$CMP$ac_delim
 YACC!$YACC$ac_delim
-UNIFONT_HEX!$UNIFONT_HEX$ac_delim
+UNIFONT_BDF!$UNIFONT_BDF$ac_delim
 INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim
 INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim
 INSTALL_DATA!$INSTALL_DATA$ac_delim
video.c +0 -11
Index: video/video.c
===================================================================
@@ -336,17 +336,6 @@
   return grub_video_adapter_active->fill_rect (color, x, y, width, height);
 }
 
-/* Blit glyph to screen using specified color.  */
-grub_err_t
-grub_video_blit_glyph (struct grub_font_glyph *glyph,
-                       grub_video_color_t color, int x, int y)
-{
-  if (! grub_video_adapter_active)
-    return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
-
-  return grub_video_adapter_active->blit_glyph (glyph, color, x, y);
-}
-
 /* Blit bitmap to screen.  */
 grub_err_t
 grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
i386/pc/vbe.c +39 -72

147 lines not on this page · raw message

i386/pc/vbeutil.c +29 -1
Index: video/i386/pc/vbeutil.c
===================================================================
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  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
@@ -52,6 +52,12 @@
             + y * source->mode_info->pitch
             + x;
       break;
+
+    case 1:
+      /* For 1-bit bitmaps, addressing needs to be done at the bit level
+         and it doesn't make sense, in general, to ask for a pointer
+         to a particular pixel's data.  */
+      break;
     }
 
   return ptr;
@@ -86,6 +92,17 @@
       color = *(grub_uint8_t *)get_data_ptr (source, x, y);
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          color = (*ptr >> bit_pos) & 0x01;
+        }
+      break;
+
     default:
       break;
     }
@@ -143,6 +160,17 @@
       }
       break;
 
+    case 1:
+      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
+        {
+          int bit_index = y * source->mode_info->width + x;
+          grub_uint8_t *ptr = (grub_uint8_t *)source->data
+                              + bit_index / 8;
+          int bit_pos = 7 - bit_index % 8;
+          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
+        }
+      break;
+
     default:
       break;
     }
configure.ac +2 -2
Index: configure.ac
===================================================================
@@ -127,9 +127,9 @@
   AC_MSG_ERROR([bison is not found])
 fi
 
-for file in /usr/share/unifont/unifont.hex ; do
+for file in /usr/src/unifont.bdf ; do
   if test -e $file ; then
-    AC_SUBST([UNIFONT_HEX], [$file])
+    AC_SUBST([UNIFONT_BDF], [$file])
     break
   fi
 done
font_cmd.c +77 -0

77 lines not on this page · raw message

font.c +1026 -0

1,026 lines not on this page · raw message

manager.c +0 -283

283 lines not on this page · raw message

videotest.c +74 -12

124 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/BDFLoader.java +271 -0

192 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/CharDefs.java +181 -0

181 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/CharStorageInfo.java +36 -0
Index: util/fonttool/src/org/gnu/grub/fonttool/CharStorageInfo.java
===================================================================

Lines of this file are not shown. View the raw message.

fonttool/src/org/gnu/grub/fonttool/CharacterRange.java +75 -0

75 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/Converter.java +168 -0

168 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/Font.java +123 -0

123 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/Glyph.java +100 -0

100 lines not on this page · raw message

fonttool/src/org/gnu/grub/fonttool/PFF2Sections.java +36 -0
Index: util/fonttool/src/org/gnu/grub/fonttool/PFF2Sections.java
===================================================================

Lines of this file are not shown. View the raw message.

fonttool/src/org/gnu/grub/fonttool/PFF2Writer.java +154 -0

154 lines not on this page · raw message

grub.d/00_header.in +1 -1
Index: util/grub.d/00_header.in
===================================================================

Lines of this file are not shown. View the raw message.

grub-mkconfig_lib.in +1 -1
Index: util/grub-mkconfig_lib.in
===================================================================

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#16 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 1 line · Vesa Jääskeläinen

And the actual patch...

... went it. Instructions being updated... with another post when ready.

#17 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

In reply to Vesa Jääskeläinen

Vesa Jääskeläinen wrote, on 2008-12-28 11:04:

Quoted 7 lines
Quoted 3 lines · Colin D Bennett

Well, I don't have time right now to rewrite the converter; not for a couple of weeks, at least. I'm certainly willing to do it, so I'll get to it when I can, and then we can replace the Java converter.

While we wait for that I have here a counter patch for the font engine.

Quoted 8 lines

If there are no comments about it in near term this will be committed to SVN.

To use automatic font conversion (unifont.bdf->ascii.pf2 and unicode.pf2), install bf-utf-source (ubuntu and probably debian). Font converter uses Java temporary. So when font compilation is enable font converter will be compiled and executed. Otherwise Java is not needed in anyway. Tested with Sun Java 1.6 on x86-64.

bf-utf-source is in Debian:

Package bf-utf-source

* etch (stable) (devel): Source for fonts needed to build Debian
installers
0.05-0.1: all
* etch-m68k (devel): Source for fonts needed to build Debian installers 0.05-0.1: all
* lenny (testing) (devel): Source for fonts needed to build Debian
installers
0.05-0.1: all
* sid (unstable) (devel): Source for fonts needed to build Debian
installers

      0.05-0.1: all

Arthur.

#18 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

In reply to Vesa Jääskeläinen

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

Quoted 124 lines · Vesa Jääskeläinen
Quoted 3 lines · Colin D Bennett

Well, I don't have time right now to rewrite the converter; not for a couple of weeks, at least. I'm certainly willing to do it, so I'll get to it when I can, and then we can replace the Java converter.

While we wait for that I have here a counter patch for the font engine.

If there are no comments about it in near term this will be committed to SVN.

To use automatic font conversion (unifont.bdf->ascii.pf2 and unicode.pf2), install bf-utf-source (ubuntu and probably debian). Font converter uses Java temporary. So when font compilation is enable font converter will be compiled and executed. Otherwise Java is not needed in anyway. Tested with Sun Java 1.6 on x86-64.

grub-mkconfig should generate new grub.cfg with changed font commands.

To convert custom fonts look for ascii.pf2 in Makefile.in and use matching commands to convert your fonts. These will be documented on Wiki once committed.

2008-12-28 Colin D Bennett <[email protected]>

New font engine.

Additional changes by Vesa Jääskeläinen <[email protected]> to adapt to build system and fixed gfxterm.c to work with different sized fonts.

* configure.ac: Changed UNIFONT_HEX to UNIFONT_BDF.

* configure: Re-generated.

* DISTLIST: Removed font/manager.c.
Added font/font.c.
Added font/font_cmd.c.

* Makefile.in: Changed UNIFONT_HEX to UNIFONT_BDF. Added Font tool compilation.

* include/grub/misc.h (grub_utf8_to_ucs4): Changed prototype.
Changed
users.

* kern/misc.c (grub_utf8_to_ucs4): Changed prototype.

* kern/term.c: Changed users of grub_utf8_to_ucs4.

* normal/menu.c: Likewise.

* conf/common.rmk (font_mod_SOURCES): Removed font/manager.c. (font_mod_SOURCES): Added font/font_cmd.c, font/font.c.

* include/grub/font.h: Replaced with new file.

* include/grub/video.h (GRUB_VIDEO_MODE_TYPE_ALPHA): Changed value. (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED): Likewise. (GRUB_VIDEO_MODE_TYPE_COLOR_MASK): Likewise. (GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP): Added. (grub_video_blit_format): Added GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED. (grub_video_mode_info): Added bg_red, bg_green, bg_blue, bg_alpha, fg_red, fg_green, fg_blue, fg_alpha. (grub_video_adapter): Removed blit_glyph. (grub_video_blit_glyph): Removed.

* font/manager.c: Removed file.

* font/font.c: New file.

* font/font_cmd.c: Likewise.

* video/video.c (grub_video_blit_glyph): Removed.

* video/i386/pc/vbe.c (grub_video_vbe_map_rgb): Added 1-bit support. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color_int): Likewise. (grub_video_vbe_blit_glyph): Removed. (grub_video_vbe_adapter): Removed blit_glyph.

* video/i386/pc/vbeutil.c (get_data_ptr): Added 1-bit support. (get_pixel): Likewise.
(set_pixel): Likewise.

* commands/videotest.c (grub_cmd_videotest): Added more tests for
fonts.

* term/gfxterm.c: Adapted to new font engine.

* term/i386/pc/vesafb.c: Marked as deprecated. Made it compile.

* term/i386/pc/vga.c: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/BDFLoader.java: New file.

* util/fonttool/src/org/gnu/grub/fonttool/CharDefs.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java:
Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/CharacterRange.java:
Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Converter.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Font.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/Glyph.java: Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/PFF2Sections.java:
Likewise.

* util/fonttool/src/org/gnu/grub/fonttool/PFF2Writer.java: Likewise.

* util/grub.d/00_header.in: Changed to use new loadfont command.

* util/grub-mkconfig_lib.in: Changed font extension.

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#19 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 3 lines · Jerone Young

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

Paying attention is not a bad thing as such :)

Never tried it myself but it should work. There isn't anything special on it. As long as Java 1.5 is being supported.

Anyway... idea was to get rid of it as soon as possible. I just didn't feel right to hold features because of this.

#20 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 5 lines · Vesa Jääskeläinen
Quoted 3 lines · Jerone Young

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

Quoted 7 lines

Paying attention is not a bad thing as such :)

Never tried it myself but it should work. There isn't anything special on it. As long as Java 1.5 is being supported.

Anyway... idea was to get rid of it as soon as possible. I just didn't feel right to hold features because of this.

Hi,

I think we can use freetype2 library. It supports both bitmap and outline fonts, and we don't need to parse font file ourselves. BTW, where can I find document on the new font format ?

Signature · 1 line
Bean
#21 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 12 lines · On Sat, 3 Jan 2009 12:52:51 +0800 Bean <[email protected]> wrote:
Quoted 10 lines · Vesa Jääskeläinen
Quoted 3 lines · Jerone Young

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

Paying attention is not a bad thing as such :)

Never tried it myself but it should work. There isn't anything special on it. As long as Java 1.5 is being supported.

Quoted 7 lines
Quoted 2 lines

Anyway... idea was to get rid of it as soon as possible. I just didn't feel right to hold features because of this.

Hi,

I think we can use freetype2 library. It supports both bitmap and outline fonts, and we don't need to parse font file ourselves.

That's an idea worth looking into. I did look into it early on in the graphical menu design process, and I can't recall why I abandoned the idea at the time.

Quoted 1 line

BTW, where can I find document on the new font format ?

See <http://grub.gibibit.com/New_font_format>
or its mirror on the GRUB wiki, <http://grub.enbug.org/FontFormat>.

Regards,
Colin

#22 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

In reply to Jerone Young
Quoted 3 lines · On Fri, 2 Jan 2009 16:44:49 -0600 "Jerone Young" <[email protected]> wrote:

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

The font tool does work with gcj (gcc's Java compiler). I just had to make a trivial change (see attached) since gcj 4.3.2 does not yet implement the String(byte[], Charset) constructor.

Regards,
Colin

=== modified file 'util/fonttool/src/org/gnu/grub/fonttool/PFF2Loader.java'

fonttool/src/org/gnu/grub/fonttool/PFF2Loader.java +1 -1
@@ -180,7 +180,7 @@
     private String openSection() throws IOException {
         byte[] b = new byte[4];
         f.readFully(b);
-        return new String(b, Charset.forName("US-ASCII"));
+        return new String(b, "US-ASCII");
     }
 
     private String readCompleteSectionAsString() throws IOException {
#23 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 10 lines · Colin D Bennett
Quoted 3 lines · On Fri, 2 Jan 2009 16:44:49 -0600 "Jerone Young" <[email protected]> wrote:

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

The font tool does work with gcj (gcc's Java compiler). I just had to make a trivial change (see attached) since gcj 4.3.2 does not yet implement the String(byte[], Charset) constructor.

Please feel free to make a commit with it. Just add Changelog entry.

#24 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

In reply to Colin D Bennett

File util/fonttool/src/org/gnu/grub/fonttool/PFF2Loader.java didn't make it into the repository.

Jerone

Quoted 14 lines · Colin D Bennett
Quoted 3 lines · On Fri, 2 Jan 2009 16:44:49 -0600 "Jerone Young" <[email protected]> wrote:

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

The font tool does work with gcj (gcc's Java compiler). I just had to make a trivial change (see attached) since gcj 4.3.2 does not yet implement the String(byte[], Charset) constructor.

Regards,
Colin

#25 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

Quoted 4 lines · On Sun, 4 Jan 2009 23:05:40 -0600 "Jerone Young" <[email protected]> wrote:

File util/fonttool/src/org/gnu/grub/fonttool/PFF2Loader.java didn't make it into the repository.

Jerone

Oops! You're right; my patch is irrelevant since PFF2Loader.java is used only for the 'Viewer' tools, which Vesa decided not to include. I had not yet synced with GRUB SVN since Vesa checked in the font utilities, so I was working with my own feature branch.

Never mind, then. I can still do a temporary hack to support building the font converter tool with gcj. I made this work in my shell script, and though I think doing it properly would require some autotools magic, I could add a quick-and-dirty target to a makefile to build using gcj. Should I try to do this?

Regards,
Colin

Quoted 17 lines
Quoted 14 lines · Colin D Bennett
Quoted 3 lines · On Fri, 2 Jan 2009 16:44:49 -0600 "Jerone Young" <[email protected]> wrote:

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

The font tool does work with gcj (gcc's Java compiler). I just had to make a trivial change (see attached) since gcj 4.3.2 does not yet implement the String(byte[], Charset) constructor.

Regards,
Colin

#26 lore raw

Re: [PATCH] GSoC #10 new font engine (UTF-8 support+bugfix)

I think if it's not too much work it would be worth a try. The thing I see is often times we think something is temporary and that ends up being a long time. So having something that works with gcj would be better.

Thanks,
Jerone

Quoted 41 lines · Colin D Bennett
Quoted 4 lines · On Sun, 4 Jan 2009 23:05:40 -0600 "Jerone Young" <[email protected]> wrote:

File util/fonttool/src/org/gnu/grub/fonttool/PFF2Loader.java didn't make it into the repository.

Jerone

Oops! You're right; my patch is irrelevant since PFF2Loader.java is used only for the 'Viewer' tools, which Vesa decided not to include. I had not yet synced with GRUB SVN since Vesa checked in the font utilities, so I was working with my own feature branch.

Never mind, then. I can still do a temporary hack to support building the font converter tool with gcj. I made this work in my shell script, and though I think doing it properly would require some autotools magic, I could add a quick-and-dirty target to a makefile to build using gcj. Should I try to do this?

Regards,
Colin

Quoted 17 lines
Quoted 14 lines · Colin D Bennett
Quoted 3 lines · On Fri, 2 Jan 2009 16:44:49 -0600 "Jerone Young" <[email protected]> wrote:

I just paid attention to this (sorry). So everything seems fine. But the dependency on a proprietary java stack to generate fonts isn't good. Does it happen to work with gcc java ?

The font tool does work with gcj (gcc's Java compiler). I just had to make a trivial change (see attached) since gcj 4.3.2 does not yet implement the String(byte[], Charset) constructor.

Regards,
Colin