Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --lv-fallback option, to specify fallback font #102

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions web/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ <h3>How to use the generated fonts in LVGL?</h3>
</div>
</div>

<div class="form-group row">
<label for="name" class="form-label col-md-2">Fallback</label>
<div class="col-md-5">
<input type="text" name="fallback" id="fallback" class="form-control" placeholder="E.g. lv_font_montserrat_24">
</div>
</div>

<div class="form-group row">
<label for="height" class="col-md-2 col-form-label">Size</label>
<div class="col-md-5">
Expand Down
4 changes: 3 additions & 1 deletion web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 => {
Expand Down
Loading