I have a font that has an option “tabular numbers” - I’m sure this is often wanted in plugins. So in theory I could right-align a number in my plugin’s interface, and the positioning should not change when the number changes. The question is, how can I get to that opentype feature using juce?
Does anybody know if it is possible? Or going to be possible in the future? Or what would need to happen to juce lib in terms of a PR? Any help is appreciated.
Or is there any way that I could maybe extract just those numbers to a different font file, or something?
You could get that behavior from any monospaced font. Is that all you want, or is there some other feature of “tabular numbers” that you’re interested in?
The tabular digits are different characters in the font file. So you can use them by simple text replacements before drawing your text. 1D7F6–1D7FF are the unicode points (or whatever the correct terminology is).
Another way is to use a font editor like https://glyphsapp.com/ (or FontForge, but I was dying inside when using the latter) to replace the regular digits with monispaced ones.
Your idea of just using two font files seems also proper.
As I said, we opted to have two helper functions which replaces the ASCII regular digits with the unicode ones. String toTabularDigits(const String& s) and fromTabularDigits(…)
So it’s a feature of a font, that is normally not monospace, some fonts offer this. So that you can still put lines of numbers under eachother (right aligned), and the numbers and commas/dots still line up.
Yes thank you @PixelPacker!! Going to try this right now.
So it seems that for the font I’m using, the tabular numbers are not a separate unicode point - just the regular “decimal number 0” and so on. You just have to turn a “feature” “on” as evidenced by the attached screenshot from Glyphs where you can see how the different features work. It would just substitute glyphs, no string manipulation required.
If it is still possible to replace with the specific codepoint for tabular numbers, could you help me a bit with the code for it? I have an example in my code for the copyright symbol, it goes something like String (CharPointer_UTF8 ("\u00a9 .... But these codepoints obviously go beyond what’s in a 8 byte character. Is it simply \u0001\ud7f6?
If it’s not possible, is it possible to copy the tabular glyphs to the regular numbers and save it with the demo version of Glyphs or Glyphs Mini? If not, I should just contact the author.
PS got an error with the screenshot. In any case, both in Glyphs demo version as in Font Book on mac, I can find the glyphs for the tabular numbers but they have the same code point as the regular decimal numbers.
This is currently being worked on. The new text system will make OpenType features possible.
I’d like to see this feature too, because the workarounds are quite tedious. Hopefully it’ll arrive in JUCE soon.
I assume this is available in JUCE 8 now? Can you give a quick example of how to enable OT features through juce::Font?
I can’t see anything on the API of juce::Font, juce::FontOptions, or juce::Typeface that allows me to change features. Is there a way to get to the underlying OT/harfbuzz object?
Unfortunately this got cut from the initial JUCE 8 release due to time constraints. However, given that HarfBuzz supports OpenType features, adding support in JUCE should mostly be a question of API design and plumbing. This is still on our radar as a useful feature to add, but I’m not able to provide a timeline for when we’ll be able to work on it.
Okay, that’s a shame but makes sense!
It would be really valuable to us as we currently have to bundle multiple variants of the font which not only inflates the binary size, but also the licensing of the font means we have to pay for each individual variant. Being able to use a variable font and choose the features we need at runtime would be perfect.
It’s available on develop. Have fun ![]()
nice! ![]()
![]()
![]()
![]()
Is there any reference to what the features are and how to use them?
There’s a new demo in the DemoRunner. The source for it can be found in juce_FontFeaturesDemo.h.
You can query what features a typeface supports with Typeface::getSupportedFeatures and enable/disable those features with FontOptions::withFeatureEnabled/Disabled.
