lib:font:fbconsole: add custom font support for review
Subsystems (2)
PATCH 1/1 lib:font:fbconsole: add custom font support for review
--- drivers/video/fbconsole.c | 39 ++++----- include/linux/font.h | 11 ++- lib/fonts/Kconfig | 5 ++ lib/fonts/Makefile | 4 + lib/fonts/font_7x14.c | 1 + lib/fonts/font_8x16.c | 1 + lib/fonts/font_custom_16x.c | 206 ++++++++++++++++++++++++++++++++++++++++++++ lib/fonts/font_mini_4x6.c | 1 + lib/fonts/fonts.c | 32 +++++++ 9 files changed, 279 insertions(+), 21 deletions(-) create mode 100644 lib/fonts/font_custom_16x.c
drivers/video/fbconsole.c +19 -20
@@ -22,8 +22,8 @@ struct fbc_priv {struct param_d *par_font;int par_font_val; -int font_width, font_height; -const u8 *fontdata; +struct font_desc font; +unsigned int cols, rows;unsigned int x, y;/* cursor position */
@@ -84,7 +84,7 @@ static struct rgb colors[] = { { 255, 255, 255 }, }; -static void drawchar (struct fbc_priv *priv,int x,int y,char c) +static void drawchar (struct fbc_priv *priv,int x,int y,int c) {void *buf;int bpp = priv->fb->bits_per_pixel >>3 ;
@@ -97,7 +97,8 @@ static void drawchar(struct fbc_priv *priv, int x, int y, char c) buf =gui_screen_render_buffer (priv->sc); - inbuf = &priv->fontdata[c * priv->font_height]; + i =find_font_index (&priv->font, c); + inbuf = priv->font.data + i; line_length = priv->fb->line_length;
@@ -113,13 +114,13 @@ static void drawchar(struct fbc_priv *priv, int x, int y, char c) rgb = &colors[bgcolor]; bgcolor =gu_rgb_to_pixel (priv->fb, rgb->r, rgb->g, rgb->b,0xff ); -for (i =0 ; i < priv->font_height; i++) { +for (i =0 ; i < priv->font.height; i++) {uint8_t t = inbuf[i];int j; - adr = buf + line_length * (y * priv->font_height + i) + x * priv->font_width * bpp; + adr = buf + line_length * (y * priv->font.height + i) + x * priv->font.width * bpp; -for (j =0 ; j < priv->font_width; j++) { +for (j =0 ; j < priv->font.width; j++) {if (t &0x80 )gu_set_pixel (priv->fb, adr, color);else
@@ -137,10 +138,10 @@ static void video_invertchar(struct fbc_priv *priv, int x, int y) buf =gui_screen_render_buffer (priv->sc); -gu_invert_area (priv->fb, buf, x * priv->font_width, y * priv->font_height, - priv->font_width, priv->font_height); -gu_screen_blit_area (priv->sc, x * priv->font_width, y * priv->font_height, - priv->font_width, priv->font_height); +gu_invert_area (priv->fb, buf, x * priv->font.width, y * priv->font.height, + priv->font.width, priv->font.height); +gu_screen_blit_area (priv->sc, x * priv->font.width, y * priv->font.height, + priv->font.width, priv->font.height); }static void printchar (struct fbc_priv *priv,int c)
@@ -174,9 +175,9 @@ static void printchar(struct fbc_priv *priv, int c)default :drawchar (priv, priv->x, priv->y, c); -gu_screen_blit_area (priv->sc, priv->x * priv->font_width, - priv->y * priv->font_height, - priv->font_width, priv->font_height); +gu_screen_blit_area (priv->sc, priv->x * priv->font.width, + priv->y * priv->font.height, + priv->font.width, priv->font.height); priv->x++;if (priv->x > priv->cols) {
@@ -188,7 +189,7 @@ static void printchar(struct fbc_priv *priv, int c)if (priv->y > priv->rows) {void *buf;u32 line_length = priv->fb->line_length; -int line_height = line_length * priv->font_height; +int line_height = line_length * priv->font.height; buf =gui_screen_render_buffer (priv->sc);
@@ -355,12 +356,10 @@ static int setup_font(struct fbc_priv *priv)return -ENOENT ; } - priv->font_width = font->width; - priv->font_height = font->height; - priv->fontdata = font->data; + priv->font = *font; - priv->rows = fb->yres / priv->font_height -1 ; - priv->cols = fb->xres / priv->font_width -1 ; + priv->rows = fb->yres / priv->font.height -1 ; + priv->cols = fb->xres / priv->font.width -1 ;return 0 ; }
include/linux/font.h +10 -1
@@ -12,20 +12,29 @@#define _VIDEO_FONT_H#include <param.h> +#include <wchar.h> +struct font_index { +wchar_t wc; +short index; +};struct font_desc {const char *name;int width, height; +struct font_index *index;const void *data; +int num_chars; };extern const struct font_desc font_vga_8x16, font_7x14, - font_mini_4x6; + font_mini_4x6, + font_custom_16x;/* Max. length for the name of a predefined font */ #define MAX_FONT_NAME 32 +extern int find_font_index (struct font_desc *font,int ch);extern const struct font_desc *find_font_enum (int n); extern struct param_d *add_param_font(struct device_d *dev, int (*set)(struct param_d *p, void *priv),
lib/fonts/Kconfig +5 -0
@@ -20,6 +20,11 @@ config FONT_7x14 config FONT_MINI_4x6 bool "Mini 4x6 font" +config FONT_CUSTOM_16X + bool "Custom 16x16 font" + help + This font is useful for Chinese and other non ascii chars. + config FONT_AUTOSELECT def_bool y depends on !FONT_MINI_4x6
lib/fonts/Makefile +4 -0
@@ -5,7 +5,11 @@ font-objs := fonts.o font-objs-$(CONFIG_FONT_8x16) += font_8x16.o font-objs-$(CONFIG_FONT_7x14) += font_7x14.o font-objs-$(CONFIG_FONT_MINI_4x6) += font_mini_4x6.o +font-objs-$(CONFIG_FONT_CUSTOM_16X)+= font_custom_16x.o font-objs += $(font-objs-y) obj-$(CONFIG_FONTS) += font.o + +hostprogs-y += hello +
lib/fonts/font_7x14.c +1 -0
@@ -4113,4 +4113,5 @@ const struct font_desc font_7x14 = { .width = 7, .height = 14, .data = fontdata_7x14, + .index = NULL, };
lib/fonts/font_8x16.c +1 -0
@@ -4626,5 +4626,6 @@ const struct font_desc font_vga_8x16 = { .width = 8, .height = 16, .data = fontdata_8x16, + .index = NULL, };EXPORT_SYMBOL (font_vga_8x16);
lib/fonts/font_custom_16x.c new file +206 -0
206 lines not on this page · raw message
lib/fonts/font_mini_4x6.c +1 -0
@@ -2152,4 +2152,5 @@ const struct font_desc font_mini_4x6 = { .width = 4, .height = 6, .data = fontdata_mini_4x6, + .index = NULL, };
lib/fonts/fonts.c +32 -0
@@ -7,6 +7,10 @@* 2001 - Documented with DocBook * - Brad Douglas <[email protected]> * +* 2015 - Add custom font supports +* - Du Huanpeng <[email protected]> +* +* * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details.
@@ -33,6 +37,10 @@ static const struct font_desc *fonts[] = {#undef NO_FONTS &font_mini_4x6,#endif +#ifdef CONFIG_FONT_CUSTOM_16X +#undef NO_FONTS + &font_custom_16x, +#endif };#define num_fonts ARRAY_SIZE(fonts)
@@ -51,6 +59,30 @@ const struct font_desc *find_font_enum(int n)return fonts[n]; } +int find_font_index (struct font_desc *font,int ch) +{ +int index; +if (font->index ==NULL ) { + index = font->width +7 ; + index /=8 ; + index *= font->height; + index *= ch; + } +else { +/* +* FIXME: use binary search instead! +*/ + index = font->num_chars -1 ; + +while (index && font->index[index].wc != ch) index--; + +/* return 0 if not found. */ + index = font->index->index; + } + +return index; +} + struct param_d *add_param_font(struct device_d *dev, int (*set)(struct param_d *p, void *priv), int (*get)(struct param_d *p, void *priv),
Signature · 7 lines
2.1.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 52 lines · Du Huanpeng
Signed-off-by Du Huanpeng <[email protected]>--- drivers/video/fbconsole.c | 39 ++++----- include/linux/font.h | 11 ++- lib/fonts/Kconfig | 5 ++ lib/fonts/Makefile | 4 + lib/fonts/font_7x14.c | 1 + lib/fonts/font_8x16.c | 1 + lib/fonts/font_custom_16x.c | 206 ++++++++++++++++++++++++++++++++++++++++++++ lib/fonts/font_mini_4x6.c | 1 + lib/fonts/fonts.c | 32 +++++++ 9 files changed, 279 insertions(+), 21 deletions(-) create mode 100644 lib/fonts/font_custom_16x.cdrivers/video/fbconsole.c +5
-4@@ -22,8 +22,8 @@ struct fbc_priv {struct param_d *par_font;int par_font_val; -int font_width, font_height; -const u8 *fontdata; +struct font_desc font; +unsigned int cols, rows;unsigned int x, y;/* cursor position */ @@ -84,7 +84,7 @@ static struct rgb colors[] = { { 255, 255, 255 }, }; -static void drawchar (struct fbc_priv *priv,int x,int y,char c) +static void drawchar (struct fbc_priv *priv,int x,int y,int c) {void *buf;int bpp = priv->fb->bits_per_pixel >>3 ;@@ -97,7 +97,8 @@ static void drawchar(struct fbc_priv *priv, int x, int y, char c) buf =gui_screen_render_buffer (priv->sc); - inbuf = &priv->fontdata[c * priv->font_height]; + i =find_font_index (&priv->font, c); + inbuf = priv->font.data + i; line_length = priv->fb->line_length;@@ -113,13 +114,13 @@ static void drawchar(struct fbc_priv *priv, int x, int y, char c) rgb = &colors[bgcolor]; bgcolor =gu_rgb_to_pixel (priv->fb, rgb->r, rgb->g, rgb->b,0xff );
drivers/video/fbconsole.c static void drawchar(struct fbc_priv *priv, int x, int y, char c) · line 123
Quoted 10 lines
drivers/video/fbconsole.c +3
-3-for (i =0 ; i < priv->font_height; i++) { +for (i =0 ; i < priv->font.height; i++) {uint8_t t = inbuf[i];int j; - adr = buf + line_length * (y * priv->font_height + i) + x * priv->font_width * bpp; + adr = buf + line_length * (y * priv->font.height + i) + x * priv->font.width * bpp; -for (j =0 ; j < priv->font_width; j++) { +for (j =0 ; j < priv->font.width; j++) {
This patch has several hunks without changes which makes it hard to look at.
Somehow this looks like beginning unicode support. Wouldn't it be better to pick the relevant parts we need from unicode and support them?
Quoted 10 lines
drivers/video/fbconsole.c +10
-0+const struct font_index fontdata_custom_16x_index[] = { + {0x0000 ,0x0000 }, + {0x54C0 ,0x00E0 }, + {0x54CE ,0x00A0 }, + {0x554A ,0x0020 }, + {0x57C3 ,0x0060 }, + {0x5509 ,0x00C0 }, + {0x6328 ,0x0080 }, + {0x769A ,0x0100 }, + {0x963F ,0x0040 },
drivers/video/fbconsole.c static void drawchar(struct fbc_priv *priv, int x, int y, char c)
Quoted 10 lines
drivers/video/fbconsole.c +10
-0+ { 0xFFFF, 0x0120 }, +}; + +const struct font_desc font_custom_16x = { + .name ="CUSTOM-16x" , + .width =16 , + .height =16 , + .data = fontdata_custom_16x, + .index = fontdata_custom_16x_index, + .num_chars = 10,
.num_chars = ARRAY_SIZE(fontdata_custom_16x_index),
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 6 lines · Sascha Hauer
This patch has several hunks without changes which makes it hard to look at.
Somehow this looks like beginning unicode support. Wouldn't it be better to pick the relevant parts we need from unicode and support them?
How about store the font data externally, for reasons
1. the font data maybe hurge, it take time to burn it to flash make barebox fat.
2. the part of font data namally don't change durning the devolopment.
3. 'custom' means usless for other application.
4. the fontdata maybe stored in a external spi flash and share with OS.
just pass the base address of index and fontdata or tell barebox how to get the font data.
- - -
Du Huanpeng
+86.13719074147
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Hi,
Quoted 9 lines · Kevin Du Huanpeng
Quoted 6 lines · Sascha Hauer
This patch has several hunks without changes which makes it hard to look at.
Somehow this looks like beginning unicode support. Wouldn't it be better to pick the relevant parts we need from unicode and support them?
Quoted 7 lines
How about store the font data externally, for reasons
1. the font data maybe hurge, it take time to burn it to flash make barebox fat.
2. the part of font data namally don't change durning the devolopment.
3. 'custom' means usless for other application.
4. the fontdata maybe stored in a external spi flash and share with OS.
just pass the base address of index and fontdata or tell barebox how to get the font data.
Do you know the pf2 font format? That may be the right candidate for a font format. See: http://grub.gibibit.com/New_font_format
If we could read this font format we could throw arbitrary unicode fonts into barebox.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
2015-10-28 14:59 GMT+08:00 Sascha Hauer <[email protected]>:
Quoted 20 lines
Hi,
Quoted 9 lines · Kevin Du Huanpeng
Quoted 6 lines · Sascha Hauer
This patch has several hunks without changes which makes it hard to look at.
Somehow this looks like beginning unicode support. Wouldn't it be better to pick the relevant parts we need from unicode and support them?
Quoted 7 lines
How about store the font data externally, for reasons
1. the font data maybe hurge, it take time to burn it to flash make barebox fat.
2. the part of font data namally don't change durning the devolopment.
3. 'custom' means usless for other application.
4. the fontdata maybe stored in a external spi flash and share with OS.
just pass the base address of index and fontdata or tell barebox how to get the font data.
Quoted 5 lines
Do you know the pf2 font format? That may be the right candidate for a font format. See: http://grub.gibibit.com/New_font_format
If we could read this font format we could throw arbitrary unicode fonts into barebox.
Nice font! it designed for bootloader!
but it needs more learning, if being a bootloader user, for supportting several dozens of chars. the barebox user have to get font data from some .ttf or other format font, or hardware font(hardware font chip). and convert it to pf2 format. need more work.
but maybe some people use barebox as a bare-metal application, not a bootloader, it will be useful. I guess.
How about simply support the 'bitmap' font, simple and friendly to barebox user. next step, support pf2.
----
Du Huanpeng
+86.13719074147
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 27 lines · Kevin Du Huanpeng
2015-10-28 14:59 GMT+08:00 Sascha Hauer <[email protected]>:
Quoted 20 lines
Hi,
Quoted 9 lines · Kevin Du Huanpeng
Quoted 6 lines · Sascha Hauer
This patch has several hunks without changes which makes it hard to look at.
Somehow this looks like beginning unicode support. Wouldn't it be better to pick the relevant parts we need from unicode and support them?
Quoted 7 lines
How about store the font data externally, for reasons
1. the font data maybe hurge, it take time to burn it to flash make barebox fat.
2. the part of font data namally don't change durning the devolopment.
3. 'custom' means usless for other application.
4. the fontdata maybe stored in a external spi flash and share with OS.
just pass the base address of index and fontdata or tell barebox how to get the font data.Quoted 5 lines
Do you know the pf2 font format? That may be the right candidate for a font format. See: http://grub.gibibit.com/New_font_format
If we could read this font format we could throw arbitrary unicode fonts into barebox.
Quoted 5 lines
Nice font! it designed for bootloader!
but it needs more learning, if being a bootloader user, for supportting several dozens of chars. the barebox user have to get font data from some .ttf or other format font, or hardware font(hardware font chip). and convert it to pf2 format. need more work.
My system already has a full unicode font under /boot/grub/unicode.pf2, it probably came with a grub standard installation.
Quoted 2 lines
but maybe some people use barebox as a bare-metal application, not a bootloader, it will be useful. I guess.
I don't think that people are doing that.
Quoted 2 lines
How about simply support the 'bitmap' font, simple and friendly to barebox user. next step, support pf2.
I don't know what you are planning. Your current approach looks fine to me if you are fine with keeping the unicode characters you need out of tree. It doesn't scale very well if everybody starts to merge his favourite characters to the tree.
If you want to be able to load external font files then these files should describe themselves. We shouldn't use a file format which needs additional informations like the widths of a font passed on the commandline when loading a file.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox