mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] font: fbconsole: add custom font supports
@ 2015-11-22 12:24 Du Huanpeng
  2015-11-23  7:21 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Du Huanpeng @ 2015-11-22 12:24 UTC (permalink / raw)
  To: barebox; +Cc: Du Huanpeng

Signed-off-by: Du Huanpeng <u74147@gmail.com>
---
 drivers/video/fbconsole.c   |  5 +++--
 include/linux/font.h        |  8 ++++++++
 lib/fonts/Kconfig           |  5 +++++
 lib/fonts/Makefile          |  1 +
 lib/fonts/font_custom_16x.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
 lib/fonts/fonts.c           | 23 +++++++++++++++++++++
 6 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 lib/fonts/font_custom_16x.c

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 3842f63..693c21f 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -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->font->data + c * priv->font->height;
+	i = find_font_index(priv->font, c);
+	inbuf = priv->font->data + i;
 
 	line_length = priv->fb->line_length;
 
diff --git a/include/linux/font.h b/include/linux/font.h
index f8b0e94..feeab97 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -12,17 +12,25 @@
 #define _VIDEO_FONT_H
 
 #include <param.h>
+#include <wchar.h>
 
+struct font_index {
+	wchar_t wc;	/* code of the char. */
+	short index;	/* offset of the char in the bitmap. */
+};
 struct font_desc {
 	const char *name;
 	int width, height;
+	struct font_index *index;
 	const void *data;
+	int num_chars;
 	struct list_head list;
 };
 
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+extern int find_font_index(const 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),
diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
index 715d5e5..d23b283 100644
--- a/lib/fonts/Kconfig
+++ b/lib/fonts/Kconfig
@@ -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
diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile
index b7d4765..98245b3 100644
--- a/lib/fonts/Makefile
+++ b/lib/fonts/Makefile
@@ -5,6 +5,7 @@ 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)
 
diff --git a/lib/fonts/font_custom_16x.c b/lib/fonts/font_custom_16x.c
new file mode 100644
index 0000000..2666e1f
--- /dev/null
+++ b/lib/fonts/font_custom_16x.c
@@ -0,0 +1,50 @@
+/*
+ * by Du Huanpeng <u74147@gmail.com>
+ */
+
+#include <init.h>
+#include <module.h>
+#include <linux/font.h>
+#include <common.h>
+
+/* place real font data here or set fontdata_custom_16x points to
+ * the address of font data and also setup the index.
+ */
+
+static const unsigned char fontdata_custom_16x[] = {
+	0xFF, 0xFF,	/*OOOOOOOOOOOOOOOO*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0x80, 0x01,	/*O______________O*/
+	0xFF, 0xFF,	/*OOOOOOOOOOOOOOOO*/
+};
+
+static struct font_index fontdata_custom_16x_index[] = {
+	{ 0x0000, 0x0000 },
+};
+
+static struct font_desc font_custom_16x = {
+	.name	= "CUSTOM-16x",
+	.width	= 16,
+	.height	= 16,
+	.data	= fontdata_custom_16x,
+	.index	= fontdata_custom_16x_index,
+	.num_chars = ARRAY_SIZE(fontdata_custom_16x_index),
+};
+
+static int font_custom_16x_register(void)
+{
+	return font_register(&font_custom_16x);
+}
+postcore_initcall(font_custom_16x_register);
diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
index d59d688..926f880 100644
--- a/lib/fonts/fonts.c
+++ b/lib/fonts/fonts.c
@@ -31,6 +31,29 @@ int font_register(struct font_desc *font)
 
 	return 0;
 }
+int find_font_index(const 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;
+}
 
 const struct font_desc *find_font_enum(int n)
 {
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] font: fbconsole: add custom font supports
  2015-11-22 12:24 [PATCH] font: fbconsole: add custom font supports Du Huanpeng
@ 2015-11-23  7:21 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-11-23  7:21 UTC (permalink / raw)
  To: Du Huanpeng; +Cc: barebox

On Sun, Nov 22, 2015 at 08:24:49PM +0800, Du Huanpeng wrote:
> Signed-off-by: Du Huanpeng <u74147@gmail.com>
> ---
>  drivers/video/fbconsole.c   |  5 +++--
>  include/linux/font.h        |  8 ++++++++
>  lib/fonts/Kconfig           |  5 +++++
>  lib/fonts/Makefile          |  1 +
>  lib/fonts/font_custom_16x.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
>  lib/fonts/fonts.c           | 23 +++++++++++++++++++++
>  6 files changed, 90 insertions(+), 2 deletions(-)
>  create mode 100644 lib/fonts/font_custom_16x.c

Applied, thanks

Sascha

> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 3842f63..693c21f 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -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->font->data + c * priv->font->height;
> +	i = find_font_index(priv->font, c);
> +	inbuf = priv->font->data + i;
>  
>  	line_length = priv->fb->line_length;
>  
> diff --git a/include/linux/font.h b/include/linux/font.h
> index f8b0e94..feeab97 100644
> --- a/include/linux/font.h
> +++ b/include/linux/font.h
> @@ -12,17 +12,25 @@
>  #define _VIDEO_FONT_H
>  
>  #include <param.h>
> +#include <wchar.h>
>  
> +struct font_index {
> +	wchar_t wc;	/* code of the char. */
> +	short index;	/* offset of the char in the bitmap. */
> +};
>  struct font_desc {
>  	const char *name;
>  	int width, height;
> +	struct font_index *index;
>  	const void *data;
> +	int num_chars;
>  	struct list_head list;
>  };
>  
>  /* Max. length for the name of a predefined font */
>  #define MAX_FONT_NAME	32
>  
> +extern int find_font_index(const 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),
> diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
> index 715d5e5..d23b283 100644
> --- a/lib/fonts/Kconfig
> +++ b/lib/fonts/Kconfig
> @@ -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
> diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile
> index b7d4765..98245b3 100644
> --- a/lib/fonts/Makefile
> +++ b/lib/fonts/Makefile
> @@ -5,6 +5,7 @@ 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)
>  
> diff --git a/lib/fonts/font_custom_16x.c b/lib/fonts/font_custom_16x.c
> new file mode 100644
> index 0000000..2666e1f
> --- /dev/null
> +++ b/lib/fonts/font_custom_16x.c
> @@ -0,0 +1,50 @@
> +/*
> + * by Du Huanpeng <u74147@gmail.com>
> + */
> +
> +#include <init.h>
> +#include <module.h>
> +#include <linux/font.h>
> +#include <common.h>
> +
> +/* place real font data here or set fontdata_custom_16x points to
> + * the address of font data and also setup the index.
> + */
> +
> +static const unsigned char fontdata_custom_16x[] = {
> +	0xFF, 0xFF,	/*OOOOOOOOOOOOOOOO*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0x80, 0x01,	/*O______________O*/
> +	0xFF, 0xFF,	/*OOOOOOOOOOOOOOOO*/
> +};
> +
> +static struct font_index fontdata_custom_16x_index[] = {
> +	{ 0x0000, 0x0000 },
> +};
> +
> +static struct font_desc font_custom_16x = {
> +	.name	= "CUSTOM-16x",
> +	.width	= 16,
> +	.height	= 16,
> +	.data	= fontdata_custom_16x,
> +	.index	= fontdata_custom_16x_index,
> +	.num_chars = ARRAY_SIZE(fontdata_custom_16x_index),
> +};
> +
> +static int font_custom_16x_register(void)
> +{
> +	return font_register(&font_custom_16x);
> +}
> +postcore_initcall(font_custom_16x_register);
> diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
> index d59d688..926f880 100644
> --- a/lib/fonts/fonts.c
> +++ b/lib/fonts/fonts.c
> @@ -31,6 +31,29 @@ int font_register(struct font_desc *font)
>  
>  	return 0;
>  }
> +int find_font_index(const 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;
> +}
>  
>  const struct font_desc *find_font_enum(int n)
>  {
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-23  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-22 12:24 [PATCH] font: fbconsole: add custom font supports Du Huanpeng
2015-11-23  7:21 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox