Digit alignment not optimal because "FIGURE SPACE" not used (feature request)
I want to align digits without prepending with 0. So %3d instead of %03d.
000:00
100:00
10:00
1:00
With non-monospaced fonts, such as verdana this doesn't work due to the space character not having the same width as digits. I don't care about the width of punctuation. All digits do have the same width in most non-monospaced fonts, but the space differs.
Unicode has different space types. Such as U+2007 "FIGURE SPACE" (https://jkorpela.fi/chars/spaces.html). This character should be a space character with the same width as a digit. Not all fonts support this character(https://www.fileformat.info/info/unicode/char/2007/fontsupport.htm). Arial is non-monospaced, but supports this character.
Below is a demonstration with ARIAL with regular space and "FIGURE SPACE"
WWW:WW
lll:ll
000:00
100:00
10:00
1:00
WWW:WW
lll:ll
000:00
100:00
10:00
1:00
As you can see (if the forum renders this correctly) the width of characters differs, but digits have the same width. And the "FIGURE SPACE" is the same width as the digits. So that's good.
But if I try this in TouchGFX it doesn't work as regular spaces are used. I wrote some code to add this, but ideally this should be implemented inside TouchGFX snprintf method:
textArea1.setLinespacing(-5); // alignment is easier to see this way
textArea1.invalidateContent();
Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "WWW\nlll\n%3d\n%3d\n%3d\n", 100,10,1);
textArea1.resizeToCurrentText();
textArea1.invalidateContent();
textArea2.setLinespacing(-5);// alignment is easier to see this way
textArea2.invalidateContent();
Unicode::snprintf(textArea2Buffer, TEXTAREA2_SIZE, "WWW\nlll\n%3d\n%3d\n%3d\n", 100,10,1);
bool typographySupportsFigureSpace = true;// TODO: how to detect this?
if (typographySupportsFigureSpace)
{
auto len = Unicode::strlen(textArea2Buffer);
for(auto i = 0; i < len; ++i)
{
if (textArea2Buffer[i] == 0x0020)
{
textArea2Buffer[i] = 0x2007; // "FIGURE SPACE"
}
}
}
textArea2.resizeToCurrentText();
textArea2.invalidateContent();
Result (when using ARIAL and adding the needed characters to the typography):

So it works. But I would have to implement this for every single aligned text field. And I cannot simply replace all spaces since some of them should be normal spaces. In my opinion aligning digits is a huge aesthetic improvement over having them jump around and it doesn't add much CPU overhead. I was able to succesfully modify an existing font that lacked "FIGURE SPACE" and didn't have monospaced digits using fontforge. I made all digits equal width, centered them, removed kerning pairs and added the "FIGURE SPACE" character. This worked. So adding support for "FIGURE SPACE" in an snprintf variant is a huge benefit since you can make it work with all fonts if you are willing to edit them.
My questions are:
- Can ST implement the use of figure space inside a variant of snprintf when using width specification (such as %3d)?
- If not, how would I implement it? (I would need a way to overload snprintf and also a way to detect if the character is supported by the current typography, because I rather have a regular space than the fallback character and I think most users would too, so then I would need to overload the text render functions too to not insert a fallback character for the "FIGURE SPACE" but a regular space.)
- How do I add invisible typography wildcard characters in unicode format instead of pasting them in the field and not seeing them in the field. In other words: the field in TouchGFX Designer doesn't show the invisible characters, but they are there. I add them in the middle of the list of wildcard characters so you can see there are white space characters in there.
