Skip to content

Commit

Permalink
fix: custom fonts in font dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Nov 14, 2024
1 parent f8d33dc commit aa46bb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AvaloniaVersion>11.2.0</AvaloniaVersion>
<ClassicAvaloniaVersion>11.2.0.5</ClassicAvaloniaVersion>
<ClassicAvaloniaVersion>11.2.0.6</ClassicAvaloniaVersion>
<DockVersion>11.2.0</DockVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class FontDialogViewModel : INotifyPropertyChanged
public ObservableCollection<LegacyFontStyle> FontStyles { get; } = new();
public List<double> FontSizes { get; } = new() { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };

private FontFamily? selectedFont;
public FontFamily? SelectedFont
private FontFamily selectedFont;
public FontFamily SelectedFont
{
get => selectedFont;
set
{
SetField(ref selectedFont, value);
SetField(ref fontNameText, value?.Name, nameof(FontNameText));
SetField(ref fontNameText, value.Name, nameof(FontNameText));
UpdateFontStyles();
}
}
Expand All @@ -37,8 +37,8 @@ public double SelectedFontSize
set => SetField(ref selectedFontSize, value);
}

private string? fontNameText;
public string? FontNameText
private string fontNameText;
public string FontNameText
{
get => fontNameText;
set
Expand Down Expand Up @@ -68,7 +68,13 @@ public FontDialogViewModel(FontDialogResult? initial) : this()
if (initial == null)
return;

selectedFont = Fonts.FirstOrDefault(x => x == initial.Family) ?? Fonts.FirstOrDefault();
if (Fonts.FirstOrDefault(x => x == initial.Family) is { } font)
selectedFont = font;
else
{
Fonts.Add(initial.Family);
selectedFont = initial.Family;
}
UpdateFontStyles();
selectedFontSize = initial.Size;
selectedFontStyle = FontStyles.FirstOrDefault(x => x.FontWeight == initial.Weight && x.FontStyle == initial.Style);
Expand Down

0 comments on commit aa46bb5

Please sign in to comment.