77using Flow . Launcher . Infrastructure . UserSettings ;
88using Flow . Launcher . Plugin ;
99using System . IO ;
10+ using System . Drawing . Text ;
11+ using System . Collections . Generic ;
1012
1113namespace Flow . Launcher . ViewModel
1214{
1315 public class ResultViewModel : BaseModel
1416 {
17+ private static PrivateFontCollection fontCollection = new ( ) ;
18+ private static Dictionary < string , string > fonts = new ( ) ;
19+
1520 public ResultViewModel ( Result result , Settings settings )
1621 {
1722 if ( result != null )
@@ -23,13 +28,29 @@ public ResultViewModel(Result result, Settings settings)
2328 // Checks if it's a system installed font, which does not require path to be provided.
2429 if ( glyph . FontFamily . EndsWith ( ".ttf" ) || glyph . FontFamily . EndsWith ( ".otf" ) )
2530 {
26- var fontPath = Result . Glyph . FontFamily ;
27- Glyph = Path . IsPathRooted ( fontPath )
28- ? Result . Glyph
29- : Result . Glyph with
31+ string fontFamilyPath = glyph . FontFamily ;
32+
33+ if ( ! Path . IsPathRooted ( fontFamilyPath ) )
34+ {
35+ fontFamilyPath = Path . Combine ( Result . PluginDirectory , fontFamilyPath ) ;
36+ }
37+
38+ if ( fonts . ContainsKey ( fontFamilyPath ) )
39+ {
40+ Glyph = glyph with
3041 {
31- FontFamily = Path . Combine ( Result . PluginDirectory , fontPath )
42+ FontFamily = fonts [ fontFamilyPath ]
3243 } ;
44+ }
45+ else
46+ {
47+ fontCollection . AddFontFile ( fontFamilyPath ) ;
48+ fonts [ fontFamilyPath ] = $ "{ Path . GetDirectoryName ( fontFamilyPath ) } /#{ fontCollection . Families [ ^ 1 ] . Name } ";
49+ Glyph = glyph with
50+ {
51+ FontFamily = fonts [ fontFamilyPath ]
52+ } ;
53+ }
3354 }
3455 else
3556 {
@@ -41,6 +62,8 @@ public ResultViewModel(Result result, Settings settings)
4162 Settings = settings ;
4263 }
4364
65+
66+
4467 private Settings Settings { get ; }
4568
4669 public Visibility ShowOpenResultHotkey =>
0 commit comments