Skip to content

Commit e446538

Browse files
committed
fix issue with duplicate font names, fixes #117
1 parent 592fb5c commit e446538

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Source/SVGImage/SVG/Utils/FontResolver.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4+
using System.Globalization;
45
using System.Linq;
6+
using System.Linq.Expressions;
57
using System.Text.RegularExpressions;
68
using System.Windows.Media;
9+
using System.Xml.Linq;
710

811
namespace SVGImage.SVG.Utils
912
{
@@ -27,11 +30,13 @@ public FontResolver(int maxLevenshteinDistance = 0)
2730
.Select(ff => new { NormalName = ff.Source, Family = ff })
2831
.ToDictionary(x => x.NormalName, x => x.Family, StringComparer.OrdinalIgnoreCase);
2932

30-
_normalizedFontNameMap = _availableFonts.Keys
31-
.ToDictionary(
32-
name => Normalize(name),
33-
name => name,
34-
StringComparer.OrdinalIgnoreCase);
33+
_normalizedFontNameMap = new Dictionary<string, string>(_availableFonts.Count);
34+
foreach (var font in _availableFonts.Keys)
35+
{
36+
var name = Normalize(font);
37+
if (!_normalizedFontNameMap.ContainsKey(name))
38+
_normalizedFontNameMap.Add(name, font);
39+
}
3540
MaxLevenshteinDistance = maxLevenshteinDistance;
3641
}
3742
/// <summary>

0 commit comments

Comments
 (0)