From c006f05c9966f786d5d3855350b91b0379e5b1f7 Mon Sep 17 00:00:00 2001 From: Yehoshua Pesach Wallach Date: Wed, 20 Apr 2022 17:15:30 +0300 Subject: [PATCH] fontgen: simplfy json after removed external features key --- src/displayapp/fonts/fonts.json | 160 +++++++++++++++---------------- src/displayapp/fonts/generate.py | 28 +++--- 2 files changed, 95 insertions(+), 93 deletions(-) diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json index c04bd213..fb9e1acb 100644 --- a/src/displayapp/fonts/fonts.json +++ b/src/displayapp/fonts/fonts.json @@ -1,88 +1,86 @@ { - "fonts": { - "jetbrains_mono_bold_20": { - "sources": [ - { - "font": "JetBrainsMono-Bold.ttf", - "range": "0x20-0x7e, 0x410-0x44f" - }, - { - "font": "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" - } - ], - "bpp": 1, - "size": 20, - "patches": [["patch", "jetbrains_mono_bold_20.c", "jetbrains_mono_bold_20.c_zero.patch"]], - "features": { - "hebrew": [ - { - "font": "SimpleCLM-Medium.ttf", - "range": "0x05D0-0x05EA,0x05F3,0x05F4" - } - ] + "jetbrains_mono_bold_20": { + "sources": [ + { + "file": "JetBrainsMono-Bold.ttf", + "range": "0x20-0x7e, 0x410-0x44f" + }, + { + "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" } - }, - "jetbrains_mono_42": { - "sources": [ + ], + "bpp": 1, + "size": 20, + "patches": [["patch", "{file}", "{file}_zero.patch"]], + "features": { + "hebrew": [ { - "font": "JetBrainsMono-Regular.ttf", - "range": "0x25, 0x30-0x3a" + "file": "SimpleCLM-Medium.ttf", + "range": "0x05D0-0x05EA,0x05F3,0x05F4" } - ], - "bpp": 1, - "size": 42 - }, - "jetbrains_mono_76": { - "sources": [ - { - "font": "JetBrainsMono-Regular.ttf", - "range": "0x25, 0x2D, 0x2F, 0x30-0x3a" - } - ], - "bpp": 1, - "size": 76 - }, - "jetbrains_mono_extrabold_compressed": { - "sources": [ - { - "font": "JetBrainsMono-ExtraBold.ttf", - "range": "0x30-0x3a" - } - ], - "bpp": 1, - "size": 80 - }, - "open_sans_light": { - "sources": [ - { - "font": "open_sans_light.ttf", - "symbols": "0123456789" - } - ], - "bpp": 1, - "size": 150 - }, - "lv_font_sys_48": { - "sources": [ - { - "font": "icons_sys_48.ttf", - "range": "0xe902, 0xe904-0xe907, 0xe90b-0xe90c" - } - ], - "bpp": 1, - "size": 48 - }, - "lv_font_navi_80": { - "sources": [ - { - "font": "navigation.ttf", - "range": "0xe900-0xe929" - } - ], - "bpp": 2, - "size": 80, - "compress": true + ] } + }, + "jetbrains_mono_42": { + "sources": [ + { + "file": "JetBrainsMono-Regular.ttf", + "range": "0x25, 0x30-0x3a" + } + ], + "bpp": 1, + "size": 42 + }, + "jetbrains_mono_76": { + "sources": [ + { + "file": "JetBrainsMono-Regular.ttf", + "range": "0x25, 0x2D, 0x2F, 0x30-0x3a" + } + ], + "bpp": 1, + "size": 76 + }, + "jetbrains_mono_extrabold_compressed": { + "sources": [ + { + "file": "JetBrainsMono-ExtraBold.ttf", + "range": "0x30-0x3a" + } + ], + "bpp": 1, + "size": 80 + }, + "open_sans_light": { + "sources": [ + { + "file": "open_sans_light.ttf", + "symbols": "0123456789" + } + ], + "bpp": 1, + "size": 150 + }, + "lv_font_sys_48": { + "sources": [ + { + "file": "icons_sys_48.ttf", + "range": "0xe902, 0xe904-0xe907, 0xe90b-0xe90c" + } + ], + "bpp": 1, + "size": 48 + }, + "lv_font_navi_80": { + "sources": [ + { + "file": "navigation.ttf", + "range": "0xe900-0xe929" + } + ], + "bpp": 2, + "size": 80, + "compress": true } } diff --git a/src/displayapp/fonts/generate.py b/src/displayapp/fonts/generate.py index 7c9c81af..d1756a79 100755 --- a/src/displayapp/fonts/generate.py +++ b/src/displayapp/fonts/generate.py @@ -8,23 +8,23 @@ import os.path import argparse import subprocess -class FontArg(object): +class Source(object): def __init__(self, d): - self.font = d['font'] + self.file = d['file'] self.range = d.get('range') 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'] if not compress: args.append('--no-compress') - for font in fonts: - args.extend(['--font', font.font]) - if font.range: - args.extend(['--range', font.range]) - if font.symbols: - args.extend(['--symbols', font.symbols]) + for source in sources: + args.extend(['--font', source.file]) + if source.range: + args.extend(['--range', source.range]) + if source.symbols: + args.extend(['--symbols', source.symbols]) return args @@ -42,7 +42,7 @@ def main(): with open(args.config, 'r') as fd: data = json.load(fd) - fonts_to_run = set(data['fonts'].keys()) + fonts_to_run = set(data.keys()) if args.font: enabled_fonts = set() @@ -54,18 +54,22 @@ def main(): fonts_to_run = fonts_to_run.intersection(enabled_fonts) for name in fonts_to_run: - font = data['fonts'][name] + font = data[name] sources = font.pop('sources') patches = font.pop('patches') if 'patches' in font else [] features = font.pop('features') if 'features' in font else [] for enabled_feature in args.features: if enabled_feature in features: 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) subprocess.check_call(line) if 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)