Skip to content

Commit

Permalink
Add --lv-fallback option, to specify fallback font
Browse files Browse the repository at this point in the history
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: #87
  • Loading branch information
neuschaefer committed Mar 14, 2024
1 parent 968adde commit 5a33974
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
8 changes: 8 additions & 0 deletions lib/writers/lvgl/lv_font.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
5 changes: 3 additions & 2 deletions lib/writers/lvgl/lv_table_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static lv_font_fmt_txt_dsc_t font_dsc = {
#endif
};
${f.fallback_declaration}
/*-----------------
* PUBLIC FONT
Expand All @@ -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();
}
Expand Down

0 comments on commit 5a33974

Please sign in to comment.