From 6ac4a4c055d4712609fbe4cb3771cfb6eaf3af4e Mon Sep 17 00:00:00 2001 From: pavmick <107577405+pavmick@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:55:35 +0300 Subject: [PATCH 1/2] See issue https://github.com/lvgl/lv_font_conv/issues/120 In LVGL export format, avoid storing duplicate bitmap data for identical glyphs. Instead, reference existing bitmap data. --- lib/writers/lvgl/lv_table_glyf.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/writers/lvgl/lv_table_glyf.js b/lib/writers/lvgl/lv_table_glyf.js index 3f14851..5a26103 100644 --- a/lib/writers/lvgl/lv_table_glyf.js +++ b/lib/writers/lvgl/lv_table_glyf.js @@ -41,12 +41,13 @@ class LvGlyf extends Glyf { f.src.glyphs.forEach(g => { const id = f.glyph_id[g.code]; const bin = this.lv_bitmap(g); + const dup = this.lv_data.find(d => d && d.bin.equals(bin)); this.lv_data[id] = { - bin, - offset, + bin: dup ? Buffer.from([]) : bin, + offset: dup ? dup.offset : offset, glyph: g }; - offset += bin.length; + offset += dup ? 0 : bin.length; }); } @@ -55,17 +56,14 @@ class LvGlyf extends Glyf { let result = []; this.lv_data.forEach((d, idx) => { - if (idx === 0) return; + if (idx === 0 || d.bin.length == 0) return; const code_hex = d.glyph.code.toString(16).toUpperCase(); const code_str = JSON.stringify(String.fromCodePoint(d.glyph.code)); let txt = ` /* U+${code_hex.padStart(4, '0')} ${code_str} */ -${u.long_dump(d.bin, { hex: true })}`; +${u.long_dump(d.bin, { hex: true })},`; - if (idx < this.lv_data.length - 1) { - // skip comma for zero data - txt += d.bin.length ? ',\n\n' : '\n'; - } + result.length > 0 && result.push('\n\n'); result.push(txt); }); From 256f4cccefba38de8a39b0c5577e83c3a65a4d74 Mon Sep 17 00:00:00 2001 From: pavmick <107577405+pavmick@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:15:17 +0300 Subject: [PATCH 2/2] Attempt to pass eslint check --- lib/writers/lvgl/lv_table_glyf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/writers/lvgl/lv_table_glyf.js b/lib/writers/lvgl/lv_table_glyf.js index 5a26103..07b24fc 100644 --- a/lib/writers/lvgl/lv_table_glyf.js +++ b/lib/writers/lvgl/lv_table_glyf.js @@ -56,14 +56,14 @@ class LvGlyf extends Glyf { let result = []; this.lv_data.forEach((d, idx) => { - if (idx === 0 || d.bin.length == 0) return; + if (idx === 0 || d.bin.length === 0) return; const code_hex = d.glyph.code.toString(16).toUpperCase(); const code_str = JSON.stringify(String.fromCodePoint(d.glyph.code)); let txt = ` /* U+${code_hex.padStart(4, '0')} ${code_str} */ ${u.long_dump(d.bin, { hex: true })},`; - result.length > 0 && result.push('\n\n'); + if (result.length > 0) result.push('\n\n'); result.push(txt); });