From 91a14b1c35a4d3493bfd1e136210ab822c787fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= Date: Sat, 23 Mar 2024 04:02:46 +0000 Subject: [PATCH 1/2] Use process.argv only in CLI version In the web version, process.argv does not contain the font conversion options. --- lib/cli.js | 1 + lib/writers/lvgl/lv_font.js | 2 +- web/index.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 7838498..46a1ff4 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -288,6 +288,7 @@ List of characters to copy, belongs to previously declared "--font". Examples: // let args = parser.parse_args(argv.length ? argv : [ '-h' ]); + args.opts_string = process.argv.slice(2).join(' '); for (let font of args.font) { if (font.ranges.length === 0) { diff --git a/lib/writers/lvgl/lv_font.js b/lib/writers/lvgl/lv_font.js index 8a14620..cf9f776 100644 --- a/lib/writers/lvgl/lv_font.js +++ b/lib/writers/lvgl/lv_font.js @@ -74,7 +74,7 @@ class LvFont extends Font { return `/******************************************************************************* * Size: ${this.src.size} px * Bpp: ${this.opts.bpp} - * Opts: ${process.argv.slice(2).join(' ')} + * Opts: ${this.opts.opts_string} ******************************************************************************/ #ifdef LV_LVGL_H_INCLUDE_SIMPLE diff --git a/web/index.js b/web/index.js index 6277625..12b2658 100644 --- a/web/index.js +++ b/web/index.js @@ -115,6 +115,8 @@ document.querySelector('#converterForm').addEventListener('submit', function han lv_fallback: _fallback }; + args.opts_string = ''; + convert(args).then(result => { const blob = new Blob([ result[_name] ], { type: 'text/plain;charset=utf-8' }); From 7b69b2defba5f7f1ff00698322fd9a837cea6b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= Date: Sat, 23 Mar 2024 05:07:34 +0000 Subject: [PATCH 2/2] Fake a command line in the web version Fixes: https://github.com/lvgl/lv_font_conv/issues/100 --- web/index.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/web/index.js b/web/index.js index 12b2658..4abccb2 100644 --- a/web/index.js +++ b/web/index.js @@ -56,6 +56,62 @@ $('#insert-button').click(addFont); addFontFileChangeHandlers(); +function generate_range(start, end, transpose) { + if (start !== transpose) { + return start + '-' + end + '=>' + transpose; + } + if (start !== end) { + return start + '-' + end; + } + return start; +} + +function generate_opts_string(args) { + var opts = []; + + opts.push('--bpp', args.bpp); + opts.push('--size', args.size); + if (args.no_compress) { + opts.push('--no-compress'); + } + if (args.lcd) { + opts.push('--lcd'); + } + if (args.lcd_v) { + opts.push('--lcd-v'); + } + if (args.use_color_info) { + opts.push('--use-color-info'); + } + + for (var i = 0; i < args.font.length; i++) { + opts.push('--font', args.font[i].source_path); + const r = args.font[i].ranges; + + var symbols = ''; + var ranges = []; + for (var j = 0; j < r.length; j++) { + if (r[i].symbols) { + symbols += r[i].symbols; + } + for (var k = 0; k < r[i].range.length; k += 3) { + ranges.push(generate_range(r[i].range[k + 0], r[i].range[k + 1], r[i].range[k + 2])); + } + } + if (symbols) { + opts.push('--symbols', symbols); + } + if (ranges) { + opts.push('--range', ranges.join(',')); + } + } + + opts.push('--format', args.format); + opts.push('-o', args.output + '.c'); + + return opts.join(' '); +} + document.querySelector('#converterForm').addEventListener('submit', function handleSubmit(e) { e.preventDefault(); @@ -115,7 +171,7 @@ document.querySelector('#converterForm').addEventListener('submit', function han lv_fallback: _fallback }; - args.opts_string = ''; + args.opts_string = generate_opts_string(args); convert(args).then(result => { const blob = new Blob([ result[_name] ], { type: 'text/plain;charset=utf-8' });