Reorganization, style fix, Terminus fonts
This commit is contained in:
parent
39b6cd8ce0
commit
861fe94bd3
22 changed files with 62103 additions and 75 deletions
|
|
@ -6,4 +6,14 @@ INC_DIRS += $(fonts_ROOT)..
|
|||
# args for passing into compile rule generation
|
||||
fonts_SRC_DIR = $(fonts_ROOT)
|
||||
|
||||
FONTS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
|
||||
# fonts by default
|
||||
include $(FONTS_DIR)defaults.mk
|
||||
|
||||
fonts_CFLAGS = $(CFLAGS) \
|
||||
-DFONTS_GLCD_5X7=$(FONTS_GLCD_5X7)
|
||||
-DFONTS_ROBOTO_8PT=$(FONTS_ROBOTO_8PT)
|
||||
-DFONTS_ROBOTO_10PT=$(FONTS_ROBOTO_10PT)
|
||||
|
||||
$(eval $(call component_compile_rules,fonts))
|
||||
|
|
|
|||
|
|
@ -1,8 +1,53 @@
|
|||
#ifndef _EXTRAS_FONTS_CONFIG_H_
|
||||
#define _EXTRAS_FONTS_CONFIG_H_
|
||||
|
||||
#ifndef NUM_FONTS
|
||||
#define NUM_FONTS 3
|
||||
#ifndef FONTS_GLCD_5X7
|
||||
#define FONTS_GLCD_5X7 1
|
||||
#endif
|
||||
|
||||
// FIXME: Proportional fonts drawing is broken
|
||||
#ifndef FONTS_ROBOTO_8PT
|
||||
#define FONTS_ROBOTO_8PT 0
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_ROBOTO_10PT
|
||||
#define FONTS_ROBOTO_10PT 0
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_6X12_KOI8_R
|
||||
#define FONTS_TERMINUS_6X12_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_8X14_KOI8_R
|
||||
#define FONTS_TERMINUS_8X14_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||
#define FONTS_TERMINUS_BOLD_8X14_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_8X16_KOI8_R
|
||||
#define FONTS_TERMINUS_8X16_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_BOLD_8X16_KOI8_R
|
||||
#define FONTS_TERMINUS_BOLD_8X16_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_14X28_KOI8_R
|
||||
#define FONTS_TERMINUS_14X28_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||
#define FONTS_TERMINUS_BOLD_14X28_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_16X32_KOI8_R
|
||||
#define FONTS_TERMINUS_16X32_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#ifndef FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||
#define FONTS_TERMINUS_BOLD_16X32_KOI8_R 1
|
||||
#endif
|
||||
|
||||
#endif /* _EXTRAS_FONTS_CONFIG_H_ */
|
||||
|
|
|
|||
2596
extras/fonts/data/font_glcd_5x7.h
Normal file
2596
extras/fonts/data/font_glcd_5x7.h
Normal file
File diff suppressed because it is too large
Load diff
1630
extras/fonts/data/font_roboto_10pt.h
Normal file
1630
extras/fonts/data/font_roboto_10pt.h
Normal file
File diff suppressed because it is too large
Load diff
1348
extras/fonts/data/font_roboto_8pt.h
Normal file
1348
extras/fonts/data/font_roboto_8pt.h
Normal file
File diff suppressed because it is too large
Load diff
7935
extras/fonts/data/font_terminus_14x28_koi8_r.h
Normal file
7935
extras/fonts/data/font_terminus_14x28_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
8955
extras/fonts/data/font_terminus_16x32_koi8_r.h
Normal file
8955
extras/fonts/data/font_terminus_16x32_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
3855
extras/fonts/data/font_terminus_6x12_koi8_r.h
Normal file
3855
extras/fonts/data/font_terminus_6x12_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4365
extras/fonts/data/font_terminus_8x14_koi8_r.h
Normal file
4365
extras/fonts/data/font_terminus_8x14_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4875
extras/fonts/data/font_terminus_8x16_koi8_r.h
Normal file
4875
extras/fonts/data/font_terminus_8x16_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
7935
extras/fonts/data/font_terminus_bold_14x28_koi8_r.h
Normal file
7935
extras/fonts/data/font_terminus_bold_14x28_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
8955
extras/fonts/data/font_terminus_bold_16x32_koi8_r.h
Normal file
8955
extras/fonts/data/font_terminus_bold_16x32_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4365
extras/fonts/data/font_terminus_bold_8x14_koi8_r.h
Normal file
4365
extras/fonts/data/font_terminus_bold_8x14_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
4875
extras/fonts/data/font_terminus_bold_8x16_koi8_r.h
Normal file
4875
extras/fonts/data/font_terminus_bold_8x16_koi8_r.h
Normal file
File diff suppressed because it is too large
Load diff
7
extras/fonts/defaults.mk
Normal file
7
extras/fonts/defaults.mk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#########################################
|
||||
# Default built-in fonts
|
||||
#########################################
|
||||
|
||||
FONTS_GLCD_5X7 ?= 1
|
||||
FONTS_ROBOTO_8PT ?= 0
|
||||
FONTS_ROBOTO_10PT ?= 0
|
||||
|
|
@ -1,18 +1,106 @@
|
|||
/*
|
||||
* oled_fonts.c
|
||||
* fonts.c
|
||||
*
|
||||
* Created on: 8 dec. 2016
|
||||
* Author: zaltora
|
||||
*/
|
||||
#include "fonts.h"
|
||||
|
||||
extern const font_info_t glcd_5x7_font_info;
|
||||
extern const font_info_t roboto_8ptFontInfo;
|
||||
extern const font_info_t roboto_10ptFontInfo;
|
||||
#if FONTS_GLCD_5X7
|
||||
#include "data/font_glcd_5x7.h"
|
||||
#endif
|
||||
|
||||
const font_info_t* fonts[NUM_FONTS] =
|
||||
#if FONTS_ROBOTO_8PT
|
||||
#include "data/font_roboto_8pt.h"
|
||||
#endif
|
||||
#if FONTS_ROBOTO_10PT
|
||||
#include "data/font_roboto_10pt.h"
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_6X12_KOI8_R
|
||||
#include "data/font_terminus_6x12_koi8_r.h"
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_8X14_KOI8_R
|
||||
#include "data/font_terminus_8x14_koi8_r.h"
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||
#include "data/font_terminus_bold_8x14_koi8_r.h"
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_14X28_KOI8_R
|
||||
#include "data/font_terminus_14x28_koi8_r.h"
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||
#include "data/font_terminus_bold_14x28_koi8_r.h"
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_16X32_KOI8_R
|
||||
#include "data/font_terminus_16x32_koi8_r.h"
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||
#include "data/font_terminus_bold_16x32_koi8_r.h"
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
||||
const font_info_t *fonts[] =
|
||||
{
|
||||
&glcd_5x7_font_info,
|
||||
&roboto_8ptFontInfo,
|
||||
&roboto_10ptFontInfo,
|
||||
#if FONTS_GLCD_5X7
|
||||
[FONT_FACE_GLCD5x7] = &_fonts_glcd_5x7_info,
|
||||
#else
|
||||
[FONT_FACE_GLCD5x7] = NULL,
|
||||
#endif
|
||||
|
||||
#if FONTS_ROBOTO_8PT
|
||||
[FONT_FACE_ROBOTO_8PT] = &_fonts_roboto_8pt_info,
|
||||
#else
|
||||
[FONT_FACE_ROBOTO_8PT] = NULL,
|
||||
#endif
|
||||
#if FONTS_ROBOTO_10PT
|
||||
[FONT_FACE_ROBOTO_10PT] = &_fonts_roboto_10pt_info,
|
||||
#else
|
||||
[FONT_FACE_ROBOTO_10PT] = NULL,
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_6X12_KOI8_R
|
||||
[FONT_FACE_TERMINUS_6X12_KOI8_R] = &_fonts_terminus_6x12_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_6X12_KOI8_R] = NULL,
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_8X14_KOI8_R
|
||||
[FONT_FACE_TERMINUS_8X14_KOI8_R] = &_fonts_terminus_8x14_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_8X14_KOI8_R] = NULL,
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_8X14_KOI8_R
|
||||
[FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R] = &_fonts_terminus_bold_8x14_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R] = NULL,
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_14X28_KOI8_R
|
||||
[FONT_FACE_TERMINUS_14X28_KOI8_R] = &_fonts_terminus_14x28_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_14X28_KOI8_R] = NULL,
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_14X28_KOI8_R
|
||||
[FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R] = &_fonts_terminus_bold_14x28_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R] = NULL,
|
||||
#endif
|
||||
|
||||
#if FONTS_TERMINUS_16X32_KOI8_R
|
||||
[FONT_FACE_TERMINUS_16X32_KOI8_R] = &_fonts_terminus_16x32_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_16X32_KOI8_R] = NULL,
|
||||
#endif
|
||||
#if FONTS_TERMINUS_BOLD_16X32_KOI8_R
|
||||
[FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R] = &_fonts_terminus_bold_16x32_koi8_r_info,
|
||||
#else
|
||||
[FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R] = NULL,
|
||||
#endif
|
||||
};
|
||||
|
||||
const size_t fonts_count = (sizeof(fonts) / sizeof(font_info_t *));
|
||||
|
|
|
|||
|
|
@ -4,20 +4,42 @@
|
|||
* Created on: 8 dec. 2016
|
||||
* Author: zaltora
|
||||
*/
|
||||
#ifndef _EXTRAS_FONTS_H_
|
||||
#define _EXTRAS_FONTS_H_
|
||||
|
||||
#ifndef FONTS_H
|
||||
#define FONTS_H
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FONT_FACE_GLCD5x7 = 0,
|
||||
FONT_FACE_ROBOTO_8PT,
|
||||
FONT_FACE_ROBOTO_10PT,
|
||||
FONT_FACE_TERMINUS_6X12_KOI8_R,
|
||||
FONT_FACE_TERMINUS_8X14_KOI8_R,
|
||||
FONT_FACE_TERMINUS_BOLD_8X14_KOI8_R,
|
||||
FONT_FACE_TERMINUS_8X16_KOI8_R,
|
||||
FONT_FACE_TERMINUS_BOLD_8X16_KOI8_R,
|
||||
FONT_FACE_TERMINUS_14X28_KOI8_R,
|
||||
FONT_FACE_TERMINUS_BOLD_14X28_KOI8_R,
|
||||
FONT_FACE_TERMINUS_16X32_KOI8_R,
|
||||
FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R,
|
||||
} font_face_t;
|
||||
|
||||
#define FONT_FACE_MAX FONT_FACE_TERMINUS_BOLD_16X32_KOI8_R
|
||||
|
||||
/**
|
||||
* Character descriptor
|
||||
*/
|
||||
typedef struct _font_char_desc
|
||||
{
|
||||
uint8_t width; //Character width in pixel
|
||||
uint16_t offset; //Offset of this character in bitmap
|
||||
uint8_t width; ///< Character width in pixel
|
||||
uint16_t offset; ///< Offset of this character in bitmap
|
||||
} font_char_desc_t;
|
||||
|
||||
/**
|
||||
|
|
@ -25,14 +47,22 @@ typedef struct _font_char_desc
|
|||
*/
|
||||
typedef struct _font_info
|
||||
{
|
||||
uint8_t height; //Character height in pixel, all characters have same height
|
||||
uint8_t c; //Simulation of "C" width in TrueType term, the space between adjacent characters
|
||||
char char_start; //First character
|
||||
char char_end; //Last character
|
||||
const font_char_desc_t* char_descriptors; //descriptor for each character
|
||||
const uint8_t *bitmap; //Character bitmap
|
||||
uint8_t height; ///< Character height in pixel, all characters have same height
|
||||
uint8_t c; ///< Simulation of "C" width in TrueType term, the space between adjacent characters
|
||||
char char_start; ///< First character
|
||||
char char_end; ///< Last character
|
||||
const font_char_desc_t *char_descriptors; ///< descriptor for each character
|
||||
const uint8_t *bitmap; ///< Character bitmap
|
||||
} font_info_t;
|
||||
|
||||
extern const font_info_t* fonts[NUM_FONTS]; //Built-in fonts
|
||||
/**
|
||||
* Built-in fonts
|
||||
*/
|
||||
extern const font_info_t *fonts[];
|
||||
extern const size_t fonts_count;
|
||||
|
||||
#endif // _FONTS__H_
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _EXTRAS_FONTS_H_ */
|
||||
|
|
|
|||
88
extras/fonts/tools/create_font.py
Executable file
88
extras/fonts/tools/create_font.py
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import sys, os
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
import argparse
|
||||
import jinja2
|
||||
import re
|
||||
|
||||
def gen_char(index, c, im):
|
||||
bw = (im.size[0] + 7) // 8
|
||||
res = {
|
||||
'index': index,
|
||||
'code': c,
|
||||
'offset': bw * im.size[1] * index,
|
||||
'rows': []
|
||||
}
|
||||
|
||||
data = tuple(im.getdata())
|
||||
|
||||
for row in range(im.size[1]):
|
||||
r = {
|
||||
'data': [],
|
||||
'asc': [],
|
||||
}
|
||||
for b in range(bw):
|
||||
byte = 0
|
||||
for i in range(8):
|
||||
idx = b * 8 + i
|
||||
bit = data[row * im.size[0] + idx] if idx < im.size[0] else 0
|
||||
if bit:
|
||||
byte |= 1
|
||||
r['asc'].append('#')
|
||||
else:
|
||||
r['asc'].append('.')
|
||||
byte <<= 1
|
||||
r['data'].append(byte >> 1)
|
||||
|
||||
r['asc'] = ''.join(r['asc'])
|
||||
res['rows'].append(r)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def main(args):
|
||||
fnt = ImageFont.load(args.font)
|
||||
size = fnt.getsize('A')
|
||||
|
||||
im = Image.new('RGB', size)
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
||||
if args.last - args.first < 1:
|
||||
raise ValueError('Invalid --first or --last')
|
||||
|
||||
chars = []
|
||||
for idx in range(args.last - args.first + 1):
|
||||
draw.rectangle(((0, 0), size), fill = 0)
|
||||
draw.text((0, 0), chr(idx + args.first), font=fnt)
|
||||
chars.append(gen_char(idx, idx + args.first, im.convert('1')))
|
||||
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__))), finalize=lambda x: '' if x is None else x)
|
||||
print(env.get_template('template.c').render({
|
||||
'font': {
|
||||
'name': args.name,
|
||||
'size': size,
|
||||
'charset': args.charset,
|
||||
'first': args.first,
|
||||
'last': args.last,
|
||||
},
|
||||
'chars': chars
|
||||
}))
|
||||
|
||||
|
||||
_CLEAN_RE = re.compile(r'[^a-z0-9_]', re.I)
|
||||
|
||||
def clean_str(s):
|
||||
return _CLEAN_RE.sub('_', s)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser=argparse.ArgumentParser(description='Fixed fonts converter')
|
||||
parser.add_argument('-f', '--font', type=str, required=True, help='PIL font filename')
|
||||
parser.add_argument('-n', '--name', type=clean_str, required=True, help='Font name')
|
||||
parser.add_argument('-c', '--charset', type=clean_str, required=True, help='Charset')
|
||||
parser.add_argument('--first', type=int, help='First character', default=1)
|
||||
parser.add_argument('--last', type=int, help='Last character', default=255)
|
||||
parser.add_argument('-t', '--template', type=str, help='Template filename', default='template.c')
|
||||
main(parser.parse_args(sys.argv[1:]))
|
||||
|
||||
49
extras/fonts/tools/template.c
Normal file
49
extras/fonts/tools/template.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{%- set header_id -%}
|
||||
_EXTRAS_FONTS_FONT_{{ font.name|upper }}_{{ font.size[0] }}X{{ font.size[1] }}_{{ font.charset|upper }}_H_
|
||||
{%- endset -%}
|
||||
{%- set font_size -%}
|
||||
{{ font.size[0] }}x{{ font.size[1] }}
|
||||
{%- endset -%}
|
||||
{%- set font_prefix -%}
|
||||
_fonts_{{ font.name|lower }}_{{ font_size }}_{{ font.charset|lower }}
|
||||
{%- endset -%}
|
||||
/**
|
||||
* This file contains generated binary font data.
|
||||
*
|
||||
* Font: {{ font.name }}
|
||||
* Size: {{ font_size }}
|
||||
* Charset: {{ font.charset }}
|
||||
* {{ chars|length }} characters ({{ font.first }}..{{ font.last }})
|
||||
*
|
||||
* Generated: {{ created }}
|
||||
*/
|
||||
#ifndef {{ header_id }}
|
||||
#define {{ header_id }}
|
||||
|
||||
static const uint8_t {{ font_prefix }}_bitmaps[] = {
|
||||
{%- for char in chars %}
|
||||
|
||||
/* {{ 'Index: 0x%02x, char: \\x%02x, offset: 0x%04x'|format(char.index, char.code, char.offset) }} */
|
||||
{%- for row in char.rows %}
|
||||
{% for byte in row.data %}{{ '0x%02x'|format(byte) }}, {% endfor -%} /* {{ row.asc }} */
|
||||
{%- endfor -%}
|
||||
{%- endfor %}
|
||||
};
|
||||
|
||||
const font_char_desc_t {{ font_prefix }}_descriptors[] = {
|
||||
{%- for char in chars %}
|
||||
{ {{ '0x%02x'|format(font.size[0]) }}, {{ '0x%04x'|format(char.offset) }} }, /* {{ 'Index: 0x%02x, char: \\x%02x'|format(char.index, char.code) }} */
|
||||
{%- endfor %}
|
||||
};
|
||||
|
||||
const font_info_t {{ font_prefix }}_info =
|
||||
{
|
||||
.height = {{ font.size[1] }}, /* Character height */
|
||||
.c = 0, /* C */
|
||||
.char_start = {{ font.first }}, /* Start character */
|
||||
.char_end = {{ font.last }}, /* End character */
|
||||
.char_descriptors = {{ font_prefix }}_descriptors, /* Character descriptor array */
|
||||
.bitmap = {{ font_prefix }}_bitmaps, /* Character bitmap array */
|
||||
};
|
||||
|
||||
#endif /* {{ header_id }} */
|
||||
Loading…
Add table
Add a link
Reference in a new issue