fontgen: simplfy json after removed external features key

This commit is contained in:
Yehoshua Pesach Wallach 2022-04-20 17:15:30 +03:00 committed by JF
parent 9d3671561f
commit c006f05c99
2 changed files with 95 additions and 93 deletions

View File

@ -1,23 +1,22 @@
{ {
"fonts": {
"jetbrains_mono_bold_20": { "jetbrains_mono_bold_20": {
"sources": [ "sources": [
{ {
"font": "JetBrainsMono-Bold.ttf", "file": "JetBrainsMono-Bold.ttf",
"range": "0x20-0x7e, 0x410-0x44f" "range": "0x20-0x7e, 0x410-0x44f"
}, },
{ {
"font": "FontAwesome5-Solid+Brands+Regular.woff", "file": "FontAwesome5-Solid+Brands+Regular.woff",
"range": "0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015" "range": "0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015"
} }
], ],
"bpp": 1, "bpp": 1,
"size": 20, "size": 20,
"patches": [["patch", "jetbrains_mono_bold_20.c", "jetbrains_mono_bold_20.c_zero.patch"]], "patches": [["patch", "{file}", "{file}_zero.patch"]],
"features": { "features": {
"hebrew": [ "hebrew": [
{ {
"font": "SimpleCLM-Medium.ttf", "file": "SimpleCLM-Medium.ttf",
"range": "0x05D0-0x05EA,0x05F3,0x05F4" "range": "0x05D0-0x05EA,0x05F3,0x05F4"
} }
] ]
@ -26,7 +25,7 @@
"jetbrains_mono_42": { "jetbrains_mono_42": {
"sources": [ "sources": [
{ {
"font": "JetBrainsMono-Regular.ttf", "file": "JetBrainsMono-Regular.ttf",
"range": "0x25, 0x30-0x3a" "range": "0x25, 0x30-0x3a"
} }
], ],
@ -36,7 +35,7 @@
"jetbrains_mono_76": { "jetbrains_mono_76": {
"sources": [ "sources": [
{ {
"font": "JetBrainsMono-Regular.ttf", "file": "JetBrainsMono-Regular.ttf",
"range": "0x25, 0x2D, 0x2F, 0x30-0x3a" "range": "0x25, 0x2D, 0x2F, 0x30-0x3a"
} }
], ],
@ -46,7 +45,7 @@
"jetbrains_mono_extrabold_compressed": { "jetbrains_mono_extrabold_compressed": {
"sources": [ "sources": [
{ {
"font": "JetBrainsMono-ExtraBold.ttf", "file": "JetBrainsMono-ExtraBold.ttf",
"range": "0x30-0x3a" "range": "0x30-0x3a"
} }
], ],
@ -56,7 +55,7 @@
"open_sans_light": { "open_sans_light": {
"sources": [ "sources": [
{ {
"font": "open_sans_light.ttf", "file": "open_sans_light.ttf",
"symbols": "0123456789" "symbols": "0123456789"
} }
], ],
@ -66,7 +65,7 @@
"lv_font_sys_48": { "lv_font_sys_48": {
"sources": [ "sources": [
{ {
"font": "icons_sys_48.ttf", "file": "icons_sys_48.ttf",
"range": "0xe902, 0xe904-0xe907, 0xe90b-0xe90c" "range": "0xe902, 0xe904-0xe907, 0xe90b-0xe90c"
} }
], ],
@ -76,7 +75,7 @@
"lv_font_navi_80": { "lv_font_navi_80": {
"sources": [ "sources": [
{ {
"font": "navigation.ttf", "file": "navigation.ttf",
"range": "0xe900-0xe929" "range": "0xe900-0xe929"
} }
], ],
@ -84,5 +83,4 @@
"size": 80, "size": 80,
"compress": true "compress": true
} }
}
} }

View File

@ -8,23 +8,23 @@ import os.path
import argparse import argparse
import subprocess import subprocess
class FontArg(object): class Source(object):
def __init__(self, d): def __init__(self, d):
self.font = d['font'] self.file = d['file']
self.range = d.get('range') self.range = d.get('range')
self.symbols = d.get('symbols') self.symbols = d.get('symbols')
def gen_lvconv_line(dest: str, size: int, bpp: int, fonts: typing.List[FontArg], compress:bool=False): def gen_lvconv_line(dest: str, size: int, bpp: int, sources: typing.List[Source], compress:bool=False):
args = ['lv_font_conv', '--size', str(size), '--output', dest, '--bpp', str(bpp), '--format', 'lvgl'] args = ['lv_font_conv', '--size', str(size), '--output', dest, '--bpp', str(bpp), '--format', 'lvgl']
if not compress: if not compress:
args.append('--no-compress') args.append('--no-compress')
for font in fonts: for source in sources:
args.extend(['--font', font.font]) args.extend(['--font', source.file])
if font.range: if source.range:
args.extend(['--range', font.range]) args.extend(['--range', source.range])
if font.symbols: if source.symbols:
args.extend(['--symbols', font.symbols]) args.extend(['--symbols', source.symbols])
return args return args
@ -42,7 +42,7 @@ def main():
with open(args.config, 'r') as fd: with open(args.config, 'r') as fd:
data = json.load(fd) data = json.load(fd)
fonts_to_run = set(data['fonts'].keys()) fonts_to_run = set(data.keys())
if args.font: if args.font:
enabled_fonts = set() enabled_fonts = set()
@ -54,18 +54,22 @@ def main():
fonts_to_run = fonts_to_run.intersection(enabled_fonts) fonts_to_run = fonts_to_run.intersection(enabled_fonts)
for name in fonts_to_run: for name in fonts_to_run:
font = data['fonts'][name] font = data[name]
sources = font.pop('sources') sources = font.pop('sources')
patches = font.pop('patches') if 'patches' in font else [] patches = font.pop('patches') if 'patches' in font else []
features = font.pop('features') if 'features' in font else [] features = font.pop('features') if 'features' in font else []
for enabled_feature in args.features: for enabled_feature in args.features:
if enabled_feature in features: if enabled_feature in features:
sources.extend(features[enabled_feature]) sources.extend(features[enabled_feature])
font['fonts'] = [FontArg(thing) for thing in sources] font['sources'] = [Source(thing) for thing in sources]
line = gen_lvconv_line(f'{name}.c', **font) line = gen_lvconv_line(f'{name}.c', **font)
subprocess.check_call(line) subprocess.check_call(line)
if patches: if patches:
for patch in patches: for patch in patches:
try: patch = patch.format(name=name, file=name+'.c')
except: pass
try: patch = [arg.format(name=name, file=name+'.c') for arg in patch]
except: pass
subprocess.check_call(patch) subprocess.check_call(patch)