Determine if font supports options (e.g. superscript and index)

WPF has an attached property Typography.Variants , which allows you to do superscript and index. However, it only works for some fonts. For other fonts, the option is completely ignored, and the text is displayed normally. (Sample code and screenshot here )

Since he silently returns to no-op, I have no idea that something went wrong; but my user will see lousy behavior.

Is there a way that I can programmatically determine if a given font supports Typography.Variants? If so, I could provide a more meaningful behavior if the user selects an invariant font for something that requires superscripts / indexes.

I looked at the GlyphTypeface , as it is used to ask if a font can be embedded, but I haven’t anything there about options. I also did not see anything obvious on FontFamily , and the only thing I could find on Typography was the property attached to the options (and its recipients and setters).

+2
source share
1 answer

As far as I can tell, WPF does not provide any information about the available GSUB tables (which tell you this information). Everything is hidden inside PresentationCore private classes.

One way would be to use WPF's advanced text services to create a TextFormatter , and then get GlyphRun created GlyphRun piece of text with options, and one with options turned off, and then compare the glyph indices used.

Another way is to physically examine the font data through GlyphTypeFace.GetFontStream() . The TrueType font format is not very complex, so you will probably find some information on the net about how to analyze binary font data to find information about GSUB tables.

Note that just asking for a fade option is also a bit ambiguous. The font may say that it supports the option, but nothing requires it to actually provide any meaningful replacements. Most Adobe fonts provide only a few lowercase alphabetic characters for things like superscript and index (not even the whole Latin alphabet, mind you). This is pretty useless, IMHO, since you can't ask WPF to fake indexes or superscripts like Word and other word processors.

However, it would be nice if you could just ask TypeFace.GetSupportedOpenTypeFeatures() .

+3
source

Source: https://habr.com/ru/post/959327/


All Articles