From 5a33974764ce1187913610d8a824d92fc9fbd694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= Date: Wed, 13 Mar 2024 21:13:24 +0000 Subject: [PATCH] Add --lv-fallback option, to specify fallback font Note that the fallback font is declared extern in the generated file. This is done so that it's possible to use fallback fonts that are not declared in LVGL's headers. Fixes: https://github.com/lvgl/lv_font_conv/issues/87 --- lib/cli.js | 4 ++++ lib/writers/lvgl/lv_font.js | 8 ++++++++ lib/writers/lvgl/lv_table_head.js | 5 +++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 830cfb5..7838498 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -279,6 +279,10 @@ List of characters to copy, belongs to previously declared "--font". Examples: help: 'Don\'t shorten "font_info.json" (include pixels data).' }); + parser.add_argument('--lv-fallback', { + help: 'Variable name of the lvgl font structure to use as fallback for this font. Defaults to NULL.' + }); + // // Process CLI options // diff --git a/lib/writers/lvgl/lv_font.js b/lib/writers/lvgl/lv_font.js index f1d917d..8a14620 100644 --- a/lib/writers/lvgl/lv_font.js +++ b/lib/writers/lvgl/lv_font.js @@ -21,6 +21,14 @@ class LvFont extends Font { this.font_name = path.basename(options.output, ext); } + if (options.lv_fallback) { + this.fallback = '&' + options.lv_fallback; + this.fallback_declaration = 'extern const lv_font_t ' + options.lv_fallback + ';\n'; + } else { + this.fallback = 'NULL'; + this.fallback_declaration = ''; + } + if (options.bpp === 3 & options.no_compress) { throw new AppError('LittlevGL supports "--bpp 3" with compression only'); } diff --git a/lib/writers/lvgl/lv_table_head.js b/lib/writers/lvgl/lv_table_head.js index 3c68d13..558d0a9 100644 --- a/lib/writers/lvgl/lv_table_head.js +++ b/lib/writers/lvgl/lv_table_head.js @@ -70,6 +70,7 @@ static lv_font_fmt_txt_dsc_t font_dsc = { #endif }; +${f.fallback_declaration} /*----------------- * PUBLIC FONT @@ -93,8 +94,8 @@ lv_font_t ${f.font_name} = { .underline_thickness = ${f.src.underlineThickness}, #endif .dsc = &font_dsc, /*The custom font data. Will be accessed by \`get_glyph_bitmap/dsc\` */ - .fallback = NULL, - .user_data = NULL + .fallback = ${f.fallback}, + .user_data = NULL, }; `.trim(); }