Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Custom font support #1564
To define a FontFamily you can use the commonly used resm scheme. If you point to a resource folder all containing fonts are automaticly discovered. It also introduces filename globbing or so called wildcard support of filenames. That way you can define a FontFamily and automaticly lookup all typefaces in one line.
You can also define fallbacks for your FontFamily. If a font isnt installed on the system, the logic tries to use the fallback values you defined for your FontFamily to render the text.
Some examples of syntax:
If your font resources are not in your main assembly you have to define the assembly attribute in your uri strings.
To use specific font weights or styles make sure your font is supporting them. If you want to have support for multiple typefaces you have to add them by folder. Your resources would look like this:
Then you can use them like so:
I noticed some ui freaze running this under DotNetCore that is gone after everything is loaded. Have to figure out what is causing this.
With this approach we could also support loading fonts from filesystem. Let me know if thats a wanted feature or if we should introduce that later.
@Gillibald great work, i'll try and test this shortly.
Any ideas on how we can support font family lists:
(from msft docs)
To support a fallback for FontFamily we have to change FontFamily's Name to represent a FontFamilyNamesList. Then we just have to search for installed fonts and if a font is not present we try the next. If no fontname is present we sill use the default font. Skia and DirectWrite already expose a list of installed fonts so we could use that and probably make that accessible threw a SystemFontsCollection. Custom fonts don't need fallbacks so we just use a single name there.
In addition to use a fallback for non present fonts we could use a fallback in case a specific typeface isn't present. For example if we set FontWeight to Bold and the main FontFamily has no face to represent that setting we could check if the fallback has one and use that. Not sure how to cache that properly but should be doable.
Looking really good! Just one question and one change I think we need.
Hey, I don't understand the
IFontFamily changes - I know we talked about this in gitter and I thought that it was supposed to hide some implementation details, but I can't see how it's doing that here.