Skip to content

Commit

Permalink
Change built-in font on macOS to "Monaco"
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Sep 3, 2024
1 parent abefee8 commit 072b545
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Studio/CelesteStudio/FontManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Eto;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -20,6 +21,11 @@ public static class FontManager {

private static FontFamily? builtinFontFamily;
public static Font CreateFont(string fontFamily, float size, FontStyle style = FontStyle.None) {
if (Platform.Instance.IsMac && fontFamily == FontFamilyBuiltin) {
// The built-in font is broken on macOS for some reason, so fallback to a system font
fontFamily = "Monaco";
}

if (fontFamily == FontFamilyBuiltin) {
var asm = Assembly.GetExecutingAssembly();
builtinFontFamily ??= FontFamily.FromStreams(asm.GetManifestResourceNames()
Expand All @@ -34,8 +40,9 @@ public static Font CreateFont(string fontFamily, float size, FontStyle style = F

private static readonly Dictionary<Font, float> charWidthCache = new();
public static float CharWidth(this Font font) {
if (charWidthCache.TryGetValue(font, out float width))
if (charWidthCache.TryGetValue(font, out float width)) {
return width;
}

width = font.MeasureString("X").Width;
charWidthCache.Add(font, width);
Expand Down

0 comments on commit 072b545

Please sign in to comment.