mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-20 21:01:06 +08:00
code_style: move App.FixFontFamilyNames to StringExtensions.FormatFontNames
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit
|
||||
{
|
||||
@@ -14,6 +17,47 @@ namespace SourceGit
|
||||
{
|
||||
return value.Replace("\"", "\\\"", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static string FormatFontNames(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return string.Empty;
|
||||
|
||||
var parts = input.Split(',');
|
||||
var trimmed = new List<string>();
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
var t = part.Trim();
|
||||
if (string.IsNullOrEmpty(t))
|
||||
continue;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var prevChar = '\0';
|
||||
|
||||
foreach (var c in t)
|
||||
{
|
||||
if (c == ' ' && prevChar == ' ')
|
||||
continue;
|
||||
sb.Append(c);
|
||||
prevChar = c;
|
||||
}
|
||||
|
||||
var name = sb.ToString();
|
||||
try
|
||||
{
|
||||
var fontFamily = FontFamily.Parse(name);
|
||||
if (fontFamily.FamilyTypefaces.Count > 0)
|
||||
trimmed.Add(name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exceptions.
|
||||
}
|
||||
}
|
||||
|
||||
return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandExtensions
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -180,8 +178,8 @@ namespace SourceGit
|
||||
app._fontsOverrides = null;
|
||||
}
|
||||
|
||||
defaultFont = app.FixFontFamilyName(defaultFont);
|
||||
monospaceFont = app.FixFontFamilyName(monospaceFont);
|
||||
defaultFont = StringExtensions.FormatFontNames(defaultFont);
|
||||
monospaceFont = StringExtensions.FormatFontNames(monospaceFont);
|
||||
|
||||
var resDic = new ResourceDictionary();
|
||||
if (!string.IsNullOrEmpty(defaultFont))
|
||||
@@ -570,47 +568,6 @@ namespace SourceGit
|
||||
}
|
||||
#endregion
|
||||
|
||||
private string FixFontFamilyName(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return string.Empty;
|
||||
|
||||
var parts = input.Split(',');
|
||||
var trimmed = new List<string>();
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
var t = part.Trim();
|
||||
if (string.IsNullOrEmpty(t))
|
||||
continue;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var prevChar = '\0';
|
||||
|
||||
foreach (var c in t)
|
||||
{
|
||||
if (c == ' ' && prevChar == ' ')
|
||||
continue;
|
||||
sb.Append(c);
|
||||
prevChar = c;
|
||||
}
|
||||
|
||||
var name = sb.ToString();
|
||||
try
|
||||
{
|
||||
var fontFamily = FontFamily.Parse(name);
|
||||
if (fontFamily.FamilyTypefaces.Count > 0)
|
||||
trimmed.Add(name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exceptions.
|
||||
}
|
||||
}
|
||||
|
||||
return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty;
|
||||
}
|
||||
|
||||
private Models.IpcChannel _ipcChannel = null;
|
||||
private ViewModels.Launcher _launcher = null;
|
||||
private ResourceDictionary _activeLocale = null;
|
||||
|
||||
Reference in New Issue
Block a user