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

SvgFontManager fails to initialize if multiple fonts of the same name exist #452

Closed
chucker opened this issue May 10, 2019 · 3 comments
Closed
Labels

Comments

@chucker
Copy link
Contributor

chucker commented May 10, 2019

(This may be a platform-specific quirk in .NET Standard. It's not clear to me from the description of https://docs.microsoft.com/en-us/dotnet/api/system.drawing.fontfamily.families?view=netframework-4.8 what happens if two fonts of the same name exist — it could be that this isn't possible in Windows but is in macOS.)

The type initializer in SvgFontManager creates a dictionary by font name. If names aren't unique, this will throw:

System.ArgumentException: "An item with the same key has already been added. Key: hiragino sans gb"
  at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\n   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey](TSource[] source, Func`2 keySelector, IEqualityComparer`1 comparer)\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)\n   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)\n   at Svg.SvgFontManager..cctor() in /Users/chucker/Repositories/SVG-448-netcore/Source/SvgFontManager.cs:22

This breaks the test LargeEmbeddedImageTest and possibly others on my machine.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented May 12, 2019

Reading up about font names, it looks as if it is allowed to have several fonts with the same name, as long as they have different weight and/or style.
As far as I understand the code, it doesn't matter if there is more than one font for a name, as the font name is only used to lookup the font family, so maybe your workaround is already sufficient to resolve this issue.

@mrbean-bremen
Copy link
Member

Actually, this has been introduced with the recent introduction of the font manager - before that FirstOrDefault has been used. So this is probably a regression...

mrbean-bremen added a commit that referenced this issue May 27, 2019
- workaround for #452
- provided by @chucker
@mrbean-bremen
Copy link
Member

@chucker - I think this can be closed. As I wrote, I do not consider your fix a workaround, as it shouldn't matter for the usage if there is more than one font for the name.

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

No branches or pull requests

2 participants