Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemFontFamilies does not return all FontFamilies in Chinese System #304

Closed
z0ow opened this issue Aug 30, 2021 · 4 comments · Fixed by #305
Closed

SystemFontFamilies does not return all FontFamilies in Chinese System #304

z0ow opened this issue Aug 30, 2021 · 4 comments · Fixed by #305
Assignees

Comments

@z0ow
Copy link

z0ow commented Aug 30, 2021

I got an exception thrown in the GetRenderer method when I am trying to change the font name from Arial to 宋体.

image
image

In the VS debugger, I can confirm the Fonts.SystemFontFamilies only contains 204 elements without 宋体, but it indeed exists in my system and can be created through var songti = new Font('宋体', 9). The songti variable shows it could be found at System.Drawing.FontFamily, containing 253 elements.

https://github.com/ForNeVeR/wpf-math/blob/b5d0af65a80e7095addcde247005a8ac1d01b0b6/src/WpfMath/TexFormula.cs#L107

So, using SystemFontFamilies in GetRenderer is aimed to avoid some expectable error or just a bug? Is it possible to change it to the System.Drawing.FontFamily?

@ForNeVeR
Copy link
Owner

Oh, that's interesting. How is the font installed? You should be able to check the installation path in the Windows Font Settings:
image

I suspect that this is either an OTF font, or it was installed to a user-local directory.

@ForNeVeR
Copy link
Owner

I'm classifying this as a feature request, since I believe that eventually we'll come to a conclusion that the existing API should be improved for users to be able to pass any fonts directly (not by name).

@z0ow
Copy link
Author

z0ow commented Aug 31, 2021

Hi @ForNeVeR , thanks for your concern.

image

I am so sorry about confusing the conception of installed and system font. The file of 宋体 is a system font which filename is SIMSUN.TTC. The system automatically installs it during OS install, which means it will exist in all Chinese Windows. Now I am confirmed the SystemFontFamilies contains a font which Source is SimSun, and the 宋体 exists in the FontFamily.FamilyNames.Values.

image

It is probably that this API provides all available alias of Font for different languages.

For example, the MS Gothic font provides name 'MS Gothic' and 'MS ゴシック' in FamilyNames with respect to en-us and ja-jp.

image
image

From the above test, I guess the implementation of the GetSystemFont method can be rewritten as:

        internal static SystemFont GetSystemFont(string fontName, double size)
        {
            var fontFamily = Fonts.SystemFontFamilies.First(ff => ff.FamilyNames.Values.Contains(fontName));
            return new SystemFont(size, fontFamily);
        }

It is working fine in my system and may is a viable solution 😄 .

image

@ForNeVeR
Copy link
Owner

Thanks a lot for help! I've fixed the issue and will prepare a release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants