Support multiple fonts with the same full name.
This commit is contained in:
@@ -6,20 +6,24 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace Cryville.Common.Font {
|
namespace Cryville.Common.Font {
|
||||||
public abstract class FontManager {
|
public abstract class FontManager {
|
||||||
protected IReadOnlyDictionary<string, Typeface> MapFullNameToTypeface { get; private set; }
|
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapFullNameToTypeface { get; private set; }
|
||||||
protected IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapNameToTypefaces { get; private set; }
|
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapNameToTypefaces { get; private set; }
|
||||||
public FontManager() {
|
public FontManager() {
|
||||||
var map1 = new Dictionary<string, Typeface>();
|
var map1 = new Dictionary<string, List<Typeface>>();
|
||||||
var map2 = new Dictionary<string, List<Typeface>>();
|
var map2 = new Dictionary<string, List<Typeface>>();
|
||||||
foreach (var f in EnumerateAllTypefaces()) {
|
foreach (var f in EnumerateAllTypefaces()) {
|
||||||
map1.Add(f.FullName, f);
|
List<Typeface> set1;
|
||||||
List<Typeface> set;
|
if (!map1.TryGetValue(f.FullName, out set1)) {
|
||||||
if (!map2.TryGetValue(f.FamilyName, out set)) {
|
map1.Add(f.FullName, set1 = new List<Typeface>());
|
||||||
map2.Add(f.FamilyName, set = new List<Typeface>());
|
|
||||||
}
|
}
|
||||||
set.Add(f);
|
set1.Add(f);
|
||||||
|
List<Typeface> set2;
|
||||||
|
if (!map2.TryGetValue(f.FamilyName, out set2)) {
|
||||||
|
map2.Add(f.FamilyName, set2 = new List<Typeface>());
|
||||||
}
|
}
|
||||||
MapFullNameToTypeface = map1;
|
set2.Add(f);
|
||||||
|
}
|
||||||
|
MapFullNameToTypeface = map1.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||||
MapNameToTypefaces = map2.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
MapNameToTypefaces = map2.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||||
}
|
}
|
||||||
protected abstract IEnumerable<Typeface> EnumerateAllTypefaces();
|
protected abstract IEnumerable<Typeface> EnumerateAllTypefaces();
|
||||||
|
|||||||
Reference in New Issue
Block a user