Skip to content

Commit

Permalink
Add --lv-fallback option, to specify fallback font
Browse files Browse the repository at this point in the history
Fixes: #87
  • Loading branch information
neuschaefer committed Mar 13, 2024
1 parent 968adde commit d5445df
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;

Check failure on line 25 in lib/writers/lvgl/lv_font.js

View workflow job for this annotation

GitHub Actions / test (14)

Strings must use singlequote
this.fallback_declaration = "const lv_font_t " + options.lv_fallback + ';\n';

Check failure on line 26 in lib/writers/lvgl/lv_font.js

View workflow job for this annotation

GitHub Actions / test (14)

Strings must use singlequote
} else {
this.fallback = "NULL";

Check failure on line 28 in lib/writers/lvgl/lv_font.js

View workflow job for this annotation

GitHub Actions / test (14)

Strings must use singlequote
this.fallback_declaration = "";

Check failure on line 29 in lib/writers/lvgl/lv_font.js

View workflow job for this annotation

GitHub Actions / test (14)

Strings must use singlequote
}

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 d5445df

Please sign in to comment.