1818using QuickLook . Common . Helpers ;
1919using QuickLook . Common . Plugin ;
2020using QuickLook . Plugin . HtmlViewer ;
21- using SampleWinForms ;
21+ using QuickLook . Typography . OpenFont ;
2222using System ;
2323using System . IO ;
2424using System . IO . Packaging ;
2727using System . Text ;
2828using System . Windows ;
2929using System . Windows . Resources ;
30- using Typography . OpenFont . WebFont ;
3130
3231namespace QuickLook . Plugin . FontViewer ;
3332
@@ -112,23 +111,9 @@ private string GenerateFontHtml(string path)
112111 // url('xxx.ttf') format('truetype'),
113112 // url('xxx.svg#xxx') format('svg');
114113 var fileName = Path . GetFileName ( path ) ;
115- var fileNameWithoutExt = Path . GetFileNameWithoutExtension ( path ) ;
116114 var fileExt = Path . GetExtension ( fileName ) ;
117- static string GenerateRandomString ( int length )
118- {
119- const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
120- Random random = new ( ) ;
121- char [ ] result = new char [ length ] ;
122-
123- for ( int i = 0 ; i < length ; i ++ )
124- {
125- result [ i ] = chars [ random . Next ( chars . Length ) ] ;
126- }
127-
128- return new string ( result ) ;
129- }
130115
131- string cssUrl = $ "src: url('{ fileName } '), url(' { fileNameWithoutExt } ?# { GenerateRandomString ( 5 ) } { fileExt } ') "
116+ string cssUrl = $ "src: url('{ fileName } ')"
132117 + fileExt switch
133118 {
134119 ".eot" => " format('embedded-opentype');" ,
@@ -141,43 +126,10 @@ static string GenerateRandomString(int length)
141126
142127 if ( string . IsNullOrEmpty ( fontFamilyName ) )
143128 {
144- string GetWoff2FontFamilyName ( )
145- {
146- OurOpenFontSystemSetup . SetupWoffDecompressFunctions ( ) ;
147- using var fs = new FileStream ( path , FileMode . Open , FileAccess . Read ) ;
148- using var input = new BinaryReader ( fs ) ;
149- var woffReader = new Woff2Reader
150- {
151- DecompressHandler = Woff2DefaultBrotliDecompressFunc . DecompressHandler
152- } ;
153- input . BaseStream . Position = 0 ;
154- var info = woffReader . ReadPreview ( input ) ;
155-
156- return info ? . Name ;
157- }
158- //string GetWoffFontFamilyName()
159- //{
160- // OurOpenFontSystemSetup.SetupWoffDecompressFunctions();
161- // using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
162- // using var input = new BinaryReader(fs);
163- // var woffReader = new WoffReader
164- // {
165- // DecompressHandler = WoffDefaultZlibDecompressFunc.DecompressHandler
166- // };
167- // input.BaseStream.Position = 0;
168- // var info = woffReader.ReadPreview(input);
169-
170- // return info?.Name;
171- //}
172-
173129 if ( fileExt . ToLower ( ) . Equals ( ".woff2" ) )
174130 {
175- fontFamilyName = GetWoff2FontFamilyName ( ) ;
131+ fontFamilyName = Woff2 . GetFontInfo ( path ) ? . Name ;
176132 }
177- //else if (fileExt.ToLower().Equals(".woff"))
178- //{
179- // fontFamilyName = GetWoffFontFamilyName();
180- //}
181133 }
182134
183135 html = html . Replace ( "--font-family;" , $ "font-family: '{ fontFamilyName } ';")
0 commit comments