7
7
using Flow . Launcher . Infrastructure . UserSettings ;
8
8
using Flow . Launcher . Plugin ;
9
9
using System . IO ;
10
+ using System . Drawing . Text ;
11
+ using System . Collections . Generic ;
10
12
11
13
namespace Flow . Launcher . ViewModel
12
14
{
13
15
public class ResultViewModel : BaseModel
14
16
{
17
+ private static PrivateFontCollection fontCollection = new ( ) ;
18
+ private static Dictionary < string , string > fonts = new ( ) ;
19
+
15
20
public ResultViewModel ( Result result , Settings settings )
16
21
{
17
22
if ( result != null )
@@ -23,13 +28,29 @@ public ResultViewModel(Result result, Settings settings)
23
28
// Checks if it's a system installed font, which does not require path to be provided.
24
29
if ( glyph . FontFamily . EndsWith ( ".ttf" ) || glyph . FontFamily . EndsWith ( ".otf" ) )
25
30
{
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
41
+ {
42
+ FontFamily = fonts [ fontFamilyPath ]
43
+ } ;
44
+ }
45
+ else
46
+ {
47
+ fontCollection . AddFontFile ( fontFamilyPath ) ;
48
+ fonts [ fontFamilyPath ] = $ "{ Path . GetDirectoryName ( fontFamilyPath ) } /#{ fontCollection . Families [ ^ 1 ] . Name } ";
49
+ Glyph = glyph with
30
50
{
31
- FontFamily = Path . Combine ( Result . PluginDirectory , fontPath )
51
+ FontFamily = fonts [ fontFamilyPath ]
32
52
} ;
53
+ }
33
54
}
34
55
else
35
56
{
0 commit comments