Skip to content

Commit c887c37

Browse files
Move missing font detection to ConfigManager
1 parent 4edd203 commit c887c37

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/LogExpert.UI/Controls/LogWindow/LogWindow.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7179,20 +7179,7 @@ public void PreferencesChanged (string fontName, float fontSize, bool setLastCol
71797179
{
71807180
if ((flags & SettingsFlags.GuiOrColors) == SettingsFlags.GuiOrColors)
71817181
{
7182-
Font NormalFont;
7183-
7184-
try
7185-
{
7186-
NormalFont = new Font(new FontFamily(fontName), fontSize);
7187-
}
7188-
catch (ArgumentException ex)
7189-
{
7190-
_logger.Warn($"Specified font '{fontName}' not found. Falling back to default. {ex.Message}");
7191-
// NOTE: Checking for invalid font name and falling back to default font might belong in LogExpert.Config.ConfigManager
7192-
NormalFont = new Font(FontFamily.GenericMonospace, fontSize);
7193-
Preferences.FontName = NormalFont.Name;
7194-
}
7195-
7182+
NormalFont = new Font(new FontFamily(fontName), fontSize);
71967183
BoldFont = new Font(NormalFont, FontStyle.Bold);
71977184
MonospacedFont = new Font("Courier New", Preferences.FontSize, FontStyle.Bold);
71987185

src/LogExpert/Config/ConfigManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ private Settings LoadOrCreateNew (FileInfo fileInfo)
204204

205205
settings.FileColors ??= [];
206206

207+
try
208+
{
209+
var fontFamily = new FontFamily(settings.Preferences.FontName);
210+
settings.Preferences.FontName = fontFamily.Name;
211+
}
212+
catch (ArgumentException ex)
213+
{
214+
_logger.Warn($"Specified font '{settings.Preferences.FontName}' not found. Falling back to default: '{FontFamily.GenericMonospace.Name}'. {ex.Message}");
215+
settings.Preferences.FontName = FontFamily.GenericMonospace.Name;
216+
}
217+
207218
if (settings.Preferences.ShowTailColor == Color.Empty)
208219
{
209220
settings.Preferences.ShowTailColor = Color.FromKnownColor(KnownColor.Blue);

0 commit comments

Comments
 (0)