fontconvert: remap characters, for smaller custom fonts #395
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.
This change modifies
fontconvert
to add support for a new (optional) "remap" parameter.If given, that parameter replaces the glyphs for certain characters with glyphs of a different character.
It's interpreted as a utf8 encoded string of pairs of characters, for example
xy! 😉
would mean: for characterx
, put the glyph ofy
into the font, and for the character!
put the winking emoji into the font.This way a font can be created which still only contains a single contiguous range of characters (thus stays small), while no longer being limited to 7 bit ASCII.
The downside of this approach is, that the characters as they appear in the code won't show up on screen the same way.
Example:
Suppose I need the following set of characters:
0123456789+-.%°
.The first 14 characters are all in the ASCII plane, so without remapping, I could get them by converting the range 37 (
%
) to 57 (9
):(
°
is not on the ASCII plane, so I couldn't get that character this way, no matter the range).Note that even though I needed only 15 characters, I had to specify a 20 character range to get only 14 of them. There are 6
characters (
&'()*,/
) for which glyphs will be included as well, but I'll never use those.This isn't ideal, so "remap" to the rescue!
First I'm choosing an ASCII range that includes as many of the characters as I need, by having as little extra characters as
possible.
In this case that range is 43 (
+
) to 57 (9
), which has two characters I don't need:,
and/
. Luckily I also have two characters which are not in that range (%
and°
).By using the
°
glyph for the,
character and the%
glyph for the/
character, I get a single range of characters which contains only the symbols I need:+
+
,
°
-
-
.
.
/
%
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
The remap parameter for this case is
,°/%
:From arduino code then, I can just write:
Which will render "37.5°".