@@ -26,25 +26,6 @@ public SettingPageViewModel(Func<Type, ViewModelBase> getService)
2626 //初始化系统信息
2727 Task . Run ( async ( ) =>
2828 {
29- //用skia接口获取系统字体列表
30- var fontMgr = SkiaSharp . SKFontManager . Default ;
31- var fonts = new List < string > ( ) ;
32- var monoFonts = new List < string > ( ) ;
33- foreach ( var f in fontMgr . FontFamilies )
34- {
35- fonts . Add ( f ) ;
36- using var typeface = fontMgr . MatchFamily ( f ) ;
37- if ( typeface . IsFixedPitch )
38- monoFonts . Add ( f ) ;
39- }
40- //把列表内容按字母排序
41- fonts . Sort ( ) ;
42- monoFonts . Sort ( ) ;
43- //添加到系统字体列表
44- foreach ( var f in fonts )
45- SystemFontList . Add ( f ) ;
46- foreach ( var f in monoFonts )
47- MonoFontList . Add ( f ) ;
4829 //找找看当前设置的是什么字体,对应上
4930 RefreshFontIndex ( ) ;
5031
@@ -84,9 +65,7 @@ public SettingPageViewModel(Func<Type, ViewModelBase> getService)
8465 #region FontSettings
8566
8667 [ ObservableProperty ]
87- private ObservableCollection < FontFamily > _systemFontList = new ( ) ;
88- [ ObservableProperty ]
89- private ObservableCollection < FontFamily > _monoFontList = new ( ) ;
68+ private ObservableCollection < FontFamily > _fontList = new ( ) ;
9069 [ ObservableProperty ]
9170 private int _packetFontIndex ;
9271 [ ObservableProperty ]
@@ -95,16 +74,40 @@ public SettingPageViewModel(Func<Type, ViewModelBase> getService)
9574 private int _packetHeaderFontIndex ;
9675 [ ObservableProperty ]
9776 private int _packetExtraFontIndex ;
77+ [ ObservableProperty ]
78+ private bool _isMonoFont = false ;
9879
9980 [ RelayCommand ]
10081 private void RefreshFontIndex ( )
10182 {
102- var list = SystemFontList ;
83+ //用skia接口获取系统字体列表
84+ var fontMgr = SkiaSharp . SKFontManager . Default ;
85+ var fonts = new List < string > ( ) ;
86+ foreach ( var f in fontMgr . FontFamilies )
87+ {
88+ if ( IsMonoFont )
89+ {
90+ using var typeface = fontMgr . MatchFamily ( f ) ;
91+ if ( typeface . IsFixedPitch )
92+ fonts . Add ( f ) ;
93+ }
94+ else
95+ {
96+ fonts . Add ( f ) ;
97+ }
98+ }
99+ //把列表内容按字母排序
100+ fonts . Sort ( ) ;
101+ //添加到系统字体列表
102+ FontList . Clear ( ) ;
103+ foreach ( var f in fonts )
104+ FontList . Add ( f ) ;
105+
103106 //刷新字体索引
104- PacketFontIndex = list . IndexOf ( Services . Utils . Setting . PacketFontFamily ?? "" ) ;
105- PacketHexFontIndex = list . IndexOf ( Services . Utils . Setting . PacketHexFontFamily ?? "" ) ;
106- PacketHeaderFontIndex = list . IndexOf ( Services . Utils . Setting . PacketHeaderFontFamily ?? "" ) ;
107- PacketExtraFontIndex = list . IndexOf ( Services . Utils . Setting . PacketExtraFontFamily ?? "" ) ;
107+ PacketFontIndex = FontList . IndexOf ( Services . Utils . Setting . PacketFontFamily ?? "" ) ;
108+ PacketHexFontIndex = FontList . IndexOf ( Services . Utils . Setting . PacketHexFontFamily ?? "" ) ;
109+ PacketHeaderFontIndex = FontList . IndexOf ( Services . Utils . Setting . PacketHeaderFontFamily ?? "" ) ;
110+ PacketExtraFontIndex = FontList . IndexOf ( Services . Utils . Setting . PacketExtraFontFamily ?? "" ) ;
108111 }
109112
110113 #endregion
0 commit comments