@@ -21,7 +21,7 @@ public FontSourceCollectionFactory() { }
2121
2222 public IFontSourceCollection Create ( string uriString )
2323 {
24- return new FontSourceCollection ( new Uri ( uriString ) , false ) ;
24+ return new FontSourceCollection ( new Uri ( uriString ) ) ;
2525 }
2626 }
2727
@@ -30,20 +30,19 @@ public IFontSourceCollection Create(string uriString)
3030 /// </summary>
3131 internal class FontSourceCollection : IFontSourceCollection
3232 {
33- public FontSourceCollection ( Uri folderUri , bool isWindowsFonts )
33+ public FontSourceCollection ( Uri folderUri )
3434 {
35- Initialize ( folderUri , isWindowsFonts , false ) ;
35+ Initialize ( folderUri , false ) ;
3636 }
3737
38- public FontSourceCollection ( Uri folderUri , bool isWindowsFonts , bool tryGetCompositeFontsOnly )
38+ public FontSourceCollection ( Uri folderUri , bool tryGetCompositeFontsOnly )
3939 {
40- Initialize ( folderUri , isWindowsFonts , tryGetCompositeFontsOnly ) ;
40+ Initialize ( folderUri , tryGetCompositeFontsOnly ) ;
4141 }
4242
43- private void Initialize ( Uri folderUri , bool isWindowsFonts , bool tryGetCompositeFontsOnly )
43+ private void Initialize ( Uri folderUri , bool tryGetCompositeFontsOnly )
4444 {
4545 _uri = folderUri ;
46- _isWindowsFonts = isWindowsFonts ;
4746 _tryGetCompositeFontsOnly = tryGetCompositeFontsOnly ;
4847
4948 bool isComposite = false ;
@@ -55,7 +54,7 @@ private void Initialize(Uri folderUri, bool isWindowsFonts, bool tryGetComposite
5554 if ( isSingleSupportedFile || ! Util . IsEnumerableFontUriScheme ( _uri ) )
5655 {
5756 _fontSources = new List < Text . TextInterface . IFontSource > ( 1 ) ;
58- _fontSources . Add ( new FontSource ( _uri , false , isComposite ) ) ;
57+ _fontSources . Add ( new FontSource ( _uri , isComposite ) ) ;
5958 }
6059 else
6160 {
@@ -69,27 +68,11 @@ private void InitializeDirectoryProperties()
6968
7069 if ( _uri . IsFile )
7170 {
72- if ( _isWindowsFonts )
73- {
74- if ( object . ReferenceEquals ( _uri , Util . WindowsFontsUriObject ) )
75- {
76- // We know the local path and that it's a folder
77- _isFileSystemFolder = true ;
78- }
79- else
80- {
81- // It's a file within the Windows Fonts folder
82- _isFileSystemFolder = false ;
83- }
84- }
85- else
86- {
87- // Get the local path
88- string localPath = _uri . LocalPath ;
71+ // Get the local path
72+ string localPath = _uri . LocalPath ;
8973
90- // Decide if it's a file or folder based on syntax, not contents of file system
91- _isFileSystemFolder = localPath [ localPath . Length - 1 ] == Path . DirectorySeparatorChar ;
92- }
74+ // Decide if it's a file or folder based on syntax, not contents of file system
75+ _isFileSystemFolder = localPath [ localPath . Length - 1 ] == Path . DirectorySeparatorChar ;
9376 }
9477 }
9578
@@ -107,55 +90,14 @@ private void SetFontSources()
10790 bool isOnlyCompositeFontFiles = false ;
10891 if ( _isFileSystemFolder )
10992 {
110- if ( _isWindowsFonts )
93+ if ( _tryGetCompositeFontsOnly )
11194 {
112- if ( _tryGetCompositeFontsOnly )
113- {
114- files = Directory . GetFiles ( _uri . LocalPath , "*" + Util . CompositeFontExtension ) ;
115- isOnlyCompositeFontFiles = true ;
116- }
117- else
118- {
119- // fontPaths accumulates font file paths obtained from the registry and the file system
120- // This collection is a set, i.e. only keys matter, not values.
121- HashSet < string > fontPaths = new HashSet < string > ( 512 , StringComparer . OrdinalIgnoreCase ) ;
122-
123- using ( RegistryKey fontsKey = Registry . LocalMachine . OpenSubKey ( InstalledWindowsFontsRegistryKey ) )
124- {
125- // The registry key should be present on a valid Windows installation.
126- Invariant . Assert ( fontsKey != null ) ;
127-
128- foreach ( string fontValue in fontsKey . GetValueNames ( ) )
129- {
130- string fileName = fontsKey . GetValue ( fontValue ) as string ;
131- if ( fileName != null )
132- {
133- // See if the path doesn't contain any directory information.
134- // Shell uses the same method to determine whether to prepend the path with %windir%\fonts.
135- if ( Path . GetFileName ( fileName ) == fileName )
136- fileName = Path . Combine ( Util . WindowsFontsLocalPath , fileName ) ;
137-
138- fontPaths . Add ( fileName ) ;
139- }
140- }
141- }
142-
143- fontPaths . UnionWith ( Directory . EnumerateFiles ( _uri . LocalPath ) ) ;
144-
145- files = fontPaths ;
146- }
147- }
95+ files = Directory . GetFiles ( _uri . LocalPath , "*" + Util . CompositeFontExtension ) ;
96+ isOnlyCompositeFontFiles = true ;
97+ }
14898 else
14999 {
150- if ( _tryGetCompositeFontsOnly )
151- {
152- files = Directory . GetFiles ( _uri . LocalPath , "*" + Util . CompositeFontExtension ) ;
153- isOnlyCompositeFontFiles = true ;
154- }
155- else
156- {
157- files = Directory . GetFiles ( _uri . LocalPath ) ;
158- }
100+ files = Directory . GetFiles ( _uri . LocalPath ) ;
159101 }
160102 }
161103 else
@@ -168,7 +110,7 @@ private void SetFontSources()
168110 {
169111 foreach ( string file in files )
170112 {
171- fontSources . Add ( new FontSource ( new Uri ( file , UriKind . Absolute ) , _isWindowsFonts , true ) ) ;
113+ fontSources . Add ( new FontSource ( new Uri ( file , UriKind . Absolute ) , true ) ) ;
172114 }
173115 }
174116 else
@@ -177,7 +119,7 @@ private void SetFontSources()
177119 foreach ( string file in files )
178120 {
179121 if ( Util . IsSupportedFontExtension ( Path . GetExtension ( file ) , out isComposite ) )
180- fontSources . Add ( new FontSource ( new Uri ( file , UriKind . Absolute ) , _isWindowsFonts , isComposite ) ) ;
122+ fontSources . Add ( new FontSource ( new Uri ( file , UriKind . Absolute ) , isComposite ) ) ;
181123 }
182124 }
183125 }
@@ -201,12 +143,12 @@ private void SetFontSources()
201143 if ( String . IsNullOrEmpty ( resourceName ) )
202144 {
203145 isComposite = Util . IsCompositeFont ( Path . GetExtension ( _uri . AbsoluteUri ) ) ;
204- fontSources . Add ( new FontSource ( _uri , _isWindowsFonts , isComposite ) ) ;
146+ fontSources . Add ( new FontSource ( _uri , isComposite ) ) ;
205147 }
206148 else
207149 {
208150 isComposite = Util . IsCompositeFont ( Path . GetExtension ( resourceName ) ) ;
209- fontSources . Add ( new FontSource ( new Uri ( _uri , resourceName ) , _isWindowsFonts , isComposite ) ) ;
151+ fontSources . Add ( new FontSource ( new Uri ( _uri , resourceName ) , isComposite ) ) ;
210152 }
211153 }
212154 }
@@ -240,17 +182,11 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
240182
241183 private Uri _uri ;
242184
243- private bool _isWindowsFonts ;
244-
245185 // _isFileSystemFolder flag makes sense only when _uri.IsFile is set to true.
246186 private bool _isFileSystemFolder ;
247187 private volatile IList < Text . TextInterface . IFontSource > _fontSources ;
248188
249189 // Flag to indicate that only composite fonts in the provided URI location should be retrieved.
250190 private bool _tryGetCompositeFontsOnly ;
251-
252- private const string InstalledWindowsFontsRegistryKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" ;
253- private const string InstalledWindowsFontsRegistryKeyFullPath = @"HKEY_LOCAL_MACHINE\" + InstalledWindowsFontsRegistryKey ;
254- }
191+ }
255192}
256-
0 commit comments