Skip to content

Commit ee884f1

Browse files
committed
Replace FontViewer source with DLL reference
1 parent e0f581e commit ee884f1

File tree

91 files changed

+5
-34878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+5
-34878
lines changed

QuickLook.Plugin/QuickLook.Plugin.FontViewer/OurOpenFontSystemSetup.cs

Lines changed: 0 additions & 85 deletions
This file was deleted.

QuickLook.Plugin/QuickLook.Plugin.FontViewer/Plugin.cs

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using QuickLook.Common.Helpers;
1919
using QuickLook.Common.Plugin;
2020
using QuickLook.Plugin.HtmlViewer;
21-
using SampleWinForms;
21+
using QuickLook.Typography.OpenFont;
2222
using System;
2323
using System.IO;
2424
using System.IO.Packaging;
@@ -27,7 +27,6 @@
2727
using System.Text;
2828
using System.Windows;
2929
using System.Windows.Resources;
30-
using Typography.OpenFont.WebFont;
3130

3231
namespace 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}';")

QuickLook.Plugin/QuickLook.Plugin.FontViewer/QuickLook.Plugin.FontViewer.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@
8080

8181
<ItemGroup>
8282
<PackageReference Include="FreeTypeSharp" Version="3.0.0" />
83-
<!--<Reference Include="Typography.OpenFont">
84-
<HintPath>.\Typography.OpenFont.dll</HintPath>
85-
</Reference>-->
86-
<!--<PackageReference Include="SharpZipLib" Version="1.4.2" />-->
87-
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
83+
<PackageReference Include="QuickLook.Typography.OpenFont" Version="1.0.1" />
8884
</ItemGroup>
8985

9086
<ItemGroup>
@@ -105,5 +101,5 @@
105101
<Link>Properties\GitVersion.cs</Link>
106102
</Compile>
107103
</ItemGroup>
108-
104+
109105
</Project>

0 commit comments

Comments
 (0)