@@ -30,6 +30,7 @@ public OptionSettingWindow()
30
30
31
31
this . Owner = Application . Current . MainWindow ;
32
32
_config = LazyConfig . Instance . GetConfig ( ) ;
33
+ var lstFonts = GetFonts ( Utils . GetFontsPath ( ) ) ;
33
34
34
35
ViewModel = new OptionSettingViewModel ( this ) ;
35
36
@@ -89,50 +90,7 @@ public OptionSettingWindow()
89
90
cmbSubConvertUrl . Items . Add ( it ) ;
90
91
} ) ;
91
92
92
- //fill fonts
93
- try
94
- {
95
- string [ ] searchPatterns = { "*.ttf" , "*.ttc" } ;
96
- var files = new List < string > ( ) ;
97
- foreach ( var pattern in searchPatterns )
98
- {
99
- files . AddRange ( Directory . GetFiles ( Utils . GetFontsPath ( ) , pattern ) ) ;
100
- }
101
- var culture = _config . uiItem . currentLanguage == Global . Languages [ 0 ] ? "zh-cn" : "en-us" ;
102
- var culture2 = "en-us" ;
103
- foreach ( var ttf in files )
104
- {
105
- var families = Fonts . GetFontFamilies ( Utils . GetFontsPath ( ttf ) ) ;
106
- foreach ( FontFamily family in families )
107
- {
108
- var typefaces = family . GetTypefaces ( ) ;
109
- foreach ( Typeface typeface in typefaces )
110
- {
111
- typeface . TryGetGlyphTypeface ( out GlyphTypeface glyph ) ;
112
- //var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")];
113
- //if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal"))
114
- //{
115
- // continue;
116
- //}
117
- var fontFamily = glyph . Win32FamilyNames [ new CultureInfo ( culture ) ] ;
118
- if ( Utils . IsNullOrEmpty ( fontFamily ) )
119
- {
120
- fontFamily = glyph . Win32FamilyNames [ new CultureInfo ( culture2 ) ] ;
121
- if ( Utils . IsNullOrEmpty ( fontFamily ) )
122
- {
123
- continue ;
124
- }
125
- }
126
- cmbcurrentFontFamily . Items . Add ( fontFamily ) ;
127
- break ;
128
- }
129
- }
130
- }
131
- }
132
- catch ( Exception ex )
133
- {
134
- Logging . SaveLog ( "fill fonts error" , ex ) ;
135
- }
93
+ lstFonts . ForEach ( it => { cmbcurrentFontFamily . Items . Add ( it ) ; } ) ;
136
94
cmbcurrentFontFamily . Items . Add ( string . Empty ) ;
137
95
138
96
this . WhenActivated ( disposables =>
@@ -206,5 +164,54 @@ public OptionSettingWindow()
206
164
this . BindCommand ( ViewModel , vm => vm . SaveCmd , v => v . btnSave ) . DisposeWith ( disposables ) ;
207
165
} ) ;
208
166
}
167
+
168
+ private List < string > GetFonts ( string path )
169
+ {
170
+ var lstFonts = new List < string > ( ) ;
171
+ try
172
+ {
173
+ string [ ] searchPatterns = { "*.ttf" , "*.ttc" } ;
174
+ var files = new List < string > ( ) ;
175
+ foreach ( var pattern in searchPatterns )
176
+ {
177
+ files . AddRange ( Directory . GetFiles ( path , pattern ) ) ;
178
+ }
179
+ var culture = _config . uiItem . currentLanguage == Global . Languages [ 0 ] ? "zh-cn" : "en-us" ;
180
+ var culture2 = "en-us" ;
181
+ foreach ( var ttf in files )
182
+ {
183
+ var families = Fonts . GetFontFamilies ( Utils . GetFontsPath ( ttf ) ) ;
184
+ foreach ( FontFamily family in families )
185
+ {
186
+ var typefaces = family . GetTypefaces ( ) ;
187
+ foreach ( Typeface typeface in typefaces )
188
+ {
189
+ typeface . TryGetGlyphTypeface ( out GlyphTypeface glyph ) ;
190
+ //var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")];
191
+ //if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal"))
192
+ //{
193
+ // continue;
194
+ //}
195
+ var fontFamily = glyph . Win32FamilyNames [ new CultureInfo ( culture ) ] ;
196
+ if ( Utils . IsNullOrEmpty ( fontFamily ) )
197
+ {
198
+ fontFamily = glyph . Win32FamilyNames [ new CultureInfo ( culture2 ) ] ;
199
+ if ( Utils . IsNullOrEmpty ( fontFamily ) )
200
+ {
201
+ continue ;
202
+ }
203
+ }
204
+ lstFonts . Add ( fontFamily ) ;
205
+ break ;
206
+ }
207
+ }
208
+ }
209
+ }
210
+ catch ( Exception ex )
211
+ {
212
+ Logging . SaveLog ( "fill fonts error" , ex ) ;
213
+ }
214
+ return lstFonts ;
215
+ }
209
216
}
210
217
}
0 commit comments