bdfconv: add characters from utf8 text file #2627
Merged
+97
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to save flash by reducing a font to only those characters that are actually used.
bdfconv converts a bdf font to an u8g2 font.
This PR adds to bdfconv an option -u filename, where filename is a text file in utf8 format.
All characters in the text file are added to the created u8g2 font.
This is useful if a font contains many characters, but only few characters are used.
Examples are programs that have menus in multiple languages, or use Asian languages like Chinese.
One suggested use is generating a font from strings in firmware source files.
To add the characters in file example.txt to the default ascii set:
Two examples where the font is megabytes in size, but the program only needs a kbyte.
example 1
Print a text in multiple languages in Arduino. Code:
Download gnu unifont in bdf format.
Create a font that contains all of ascii, and all characters in the sketch:
where bdfconv_test.ino is the sketch source.
The font uses 1750 bytes of flash. This is 478 bytes more than same font using only the ascii set.
Arduino sketch attached.
sketch.zip
example 2
Simplified Chinese, STM32F103, SSH1306 OLED display. Code:
otf2bdf -p 14 -o AlibabaPuHuiTi-3-35-Thin-14.bdf AlibabaPuHuiTi-3-35-Thin.otf
bdfconv -f 1 -u bdfconv_test_chinese.ino -n u8g2_font_puhuiti_t14 -o u8g2_font_puhuiti_t14.h AlibabaPuHuiTi-3-35-Thin-14.bdf
where bdfconv__test_chinese.ino is the sketch source.
The font uses 4156 bytes of flash. This is 591 bytes more than same font using only the ascii set.
Arduino sketch attached.
bdfconv_test_chinese.zip