Skip to content

Commit 2ecd1d0

Browse files
committed
Upgrade
1 parent a21aea2 commit 2ecd1d0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

test/NosCore.PathFinder.Tests/TestHelper.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@ public static void VerifyFile(string linearPathfinderPng, Image<Rgba32> image, L
4444
public static int Scale = 50;
4545

4646
private static Font? _font;
47-
public static Font GetFont()
47+
private static bool _fontLoaded;
48+
public static Font? GetFont()
4849
{
49-
if (_font == null)
50+
if (!_fontLoaded)
5051
{
51-
var fontCollection = new FontCollection();
52-
_font = SystemFonts.CreateFont("Arial", 16);
52+
_fontLoaded = true;
53+
var fontNames = new[] { "Arial", "DejaVu Sans", "Liberation Sans", "Noto Sans", "FreeSans" };
54+
foreach (var fontName in fontNames)
55+
{
56+
if (SystemFonts.TryGet(fontName, out var family))
57+
{
58+
_font = family.CreateFont(16);
59+
break;
60+
}
61+
}
62+
63+
_font ??= SystemFonts.Collection.Families.FirstOrDefault()?.CreateFont(16);
5364
}
5465
return _font;
5566
}
@@ -106,7 +117,7 @@ public static void DrawMap(TestMap map, int scale, List<Rgba32> listPixel, Image
106117
color = Color.DarkRed;
107118
}
108119
ctx.Fill(color, rect);
109-
if (text != null)
120+
if (text != null && font != null)
110121
{
111122
var textOptions = new RichTextOptions(font)
112123
{

0 commit comments

Comments
 (0)