From db0f909b461a6f2b706262cb4c2bae72007dc3f9 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Tue, 10 May 2022 23:48:41 +0200 Subject: generalize lv-font creation In https://github.com/InfiniTimeOrg/InfiniTime/pull/1097 new font generation capabilites were added. Generalize the font creation to make it possible to reuse the `displayapp/fonts/CMakeLists.txt` file for `InfiniSim` and just add the new cmake file to the project and link against the new `infinitime_fonts` target. In the following a list of changes. Allow non-global installed `lv_font_conv` executable installed with ```sh npm install lv_font_conv@1.5.2 ``` In CMake we search for `lv_font_conv` executable. Add the found executable to the python script `generate.py`, to remove the need for `lv_font_conv` to be in the path. Search for `python3` executable, if CMake version 3.12 is available. Otherwise use `python` as hard coded executable. Instead of adding the generated fonts to `SOURCE_FILES` variable, create a static library `infinitime_fonts`. Link this library to the executables instead. Use `add_custom_target()` together with `add_custom_command()` to generate the font.c files once (like the original PR does). --- src/displayapp/fonts/generate.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/displayapp/fonts/generate.py') diff --git a/src/displayapp/fonts/generate.py b/src/displayapp/fonts/generate.py index 401d47ab..89810614 100755 --- a/src/displayapp/fonts/generate.py +++ b/src/displayapp/fonts/generate.py @@ -18,8 +18,8 @@ class Source(object): self.symbols = d.get('symbols') -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'] +def gen_lvconv_line(lv_font_conv: str, 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 source in sources: @@ -35,9 +35,10 @@ def main(): ap = argparse.ArgumentParser(description='auto generate LVGL font files from fonts') ap.add_argument('config', type=str, help='config file to use') ap.add_argument('-f', '--font', type=str, action='append', help='Choose specific fonts to generate (default: all)', default=[]) + ap.add_argument('--lv-font-conv', type=str, help='Path to "lv_font_conf" executable', default="lv_font_conv") args = ap.parse_args() - if not shutil.which('lv_font_conv'): + if not shutil.which(args.lv_font_conv): sys.exit(f'Missing lv_font_conv. (make sure it is installed and in PATH)') if not os.path.exists(args.config): sys.exit(f'Error: the config file {args.config} does not exist.') @@ -62,7 +63,7 @@ def main(): sources = font.pop('sources') patches = font.pop('patches') if 'patches' in font else [] font['sources'] = [Source(thing) for thing in sources] - line = gen_lvconv_line(f'{name}.c', **font) + line = gen_lvconv_line(args.lv_font_conv, f'{name}.c', **font) subprocess.check_call(line) if patches: for patch in patches: -- cgit v1.2.3-70-g09d2