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(); } diff --git a/web/content.html b/web/content.html index 8c1a6eb..7abde5d 100644 --- a/web/content.html +++ b/web/content.html @@ -40,6 +40,13 @@

How to use the generated fonts in LVGL?

+
+ +
+ +
+
+
diff --git a/web/index.js b/web/index.js index cacfb3e..6277625 100644 --- a/web/index.js +++ b/web/index.js @@ -60,6 +60,7 @@ document.querySelector('#converterForm').addEventListener('submit', function han e.preventDefault(); var _name = document.getElementById('name').value; + var _fallback = document.getElementById('fallback').value; var _size = document.getElementById('height').value; var _bpp = document.getElementById('bpp').value; /* eslint-disable max-depth, radix */ @@ -110,7 +111,8 @@ document.querySelector('#converterForm').addEventListener('submit', function han lcd_v: document.getElementById('subpixel3').checked, use_color_info: document.getElementById('use_color_info').checked, format: 'lvgl', - output: _name + output: _name, + lv_fallback: _fallback }; convert(args).then(result => {