fix: improve font string processing in SetFonts method (#1092)

This commit is contained in:
Gadfly 2025-03-13 15:05:30 +08:00 committed by GitHub
parent 519bdf1ddc
commit b9b684a83d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -181,6 +181,9 @@ namespace SourceGit
app._fontsOverrides = null;
}
defaultFont = ProcessFontString(defaultFont);
monospaceFont = ProcessFontString(monospaceFont);
var resDic = new ResourceDictionary();
if (!string.IsNullOrEmpty(defaultFont))
resDic.Add("Fonts.Default", new FontFamily(defaultFont));
@ -437,6 +440,28 @@ namespace SourceGit
return true;
}
private static string ProcessFontString(string input)
{
if (string.IsNullOrEmpty(input)) return string.Empty;
var parts = input.Split(',');
var result = new StringBuilder();
var isFirst = true;
foreach (var part in parts)
{
var trimmed = part.Trim();
if (!string.IsNullOrEmpty(trimmed))
{
if (!isFirst) result.Append(',');
result.Append(trimmed);
isFirst = false;
}
}
return result.ToString();
}
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
{
var args = desktop.Args;