diff options
author | Du Huanpeng <u74147@gmail.com> | 2015-11-22 20:24:49 +0800 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-11-23 08:21:08 +0100 |
commit | ea682776db018af2d249097f1a682ef0881e3d0e (patch) | |
tree | f936fb0e5ea8378f6e55c19b8a71c0ee3288dafe /lib/fonts | |
parent | 314b5402d9f90e4be4be2bbe7c0072876f70281c (diff) | |
download | barebox-ea682776db018af2d249097f1a682ef0881e3d0e.tar.gz |
font: fbconsole: add custom font supports
Signed-off-by: Du Huanpeng <u74147@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/fonts')
-rw-r--r-- | lib/fonts/Kconfig | 5 | ||||
-rw-r--r-- | lib/fonts/Makefile | 1 | ||||
-rw-r--r-- | lib/fonts/font_custom_16x.c | 50 | ||||
-rw-r--r-- | lib/fonts/fonts.c | 23 |
4 files changed, 79 insertions, 0 deletions
diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig index 715d5e5bbd..d23b283964 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 b7d4765395..98245b3d65 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 0000000000..2666e1f6d6 --- /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 d59d688950..926f880128 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) { |