Compress TwemojiMozilla

This commit is contained in:
Julien Richard 2022-10-26 13:00:25 +02:00
commit 128436eafd
3 changed files with 28 additions and 6 deletions

View file

@ -38,8 +38,8 @@ Source: {#ReleaseDir}\System.Memory.dll; DestDir: {app}; Components: greenshot;
Source: {#ReleaseDir}\System.Numerics.Vectors.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\System.Numerics.Vectors.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\System.Runtime.CompilerServices.Unsafe.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\System.Runtime.CompilerServices.Unsafe.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\System.Buffers.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\System.Buffers.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\TwemojiMozilla.ttf; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\TwemojiMozilla.ttf.gz; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\emoji-test.txt; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\emoji-test.txt.gz; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#GreenshotProjectDir}\log4net.xml; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion Source: {#GreenshotProjectDir}\log4net.xml; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion
Source: {#ReleaseDir}\checksum.SHA256; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\checksum.SHA256; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
;Source: ..\greenshot-defaults.ini; DestDir: {app}; Flags: overwritereadonly ignoreversion replacesameversion ;Source: ..\greenshot-defaults.ini; DestDir: {app}; Flags: overwritereadonly ignoreversion replacesameversion

View file

@ -20,6 +20,7 @@
*/ */
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Reflection; using System.Reflection;
@ -41,15 +42,31 @@ namespace Greenshot.Editor.Drawing.Emoji
private static readonly Lazy<FontFamily> TwemojiFontFamily = new(() => private static readonly Lazy<FontFamily> TwemojiFontFamily = new(() =>
{ {
var exeDirectory = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); var exeDirectory = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
var twemojiFontFile = Path.Combine(exeDirectory, "TwemojiMozilla.ttf"); var twemojiFontFile = Path.Combine(exeDirectory, "TwemojiMozilla.ttf.gz");
if (!File.Exists(twemojiFontFile)) if (!File.Exists(twemojiFontFile))
{ {
throw new FileNotFoundException($"Can't find {twemojiFontFile}, bad installation?"); throw new FileNotFoundException($"Can't find {twemojiFontFile}, bad installation?");
} }
Stopwatch sw = new();
sw.Start();
using var fileStream = new FileStream(twemojiFontFile, FileMode.Open, FileAccess.Read); using var fileStream = new FileStream(twemojiFontFile, FileMode.Open, FileAccess.Read);
TwemojiFontCollection.Add(fileStream); using var gzStream = new GZipStream(fileStream, CompressionMode.Decompress);
using var memoryStream = new MemoryStream();
gzStream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
sw.Stop();
Console.WriteLine($"Uncompress .ttf: {sw.ElapsedMilliseconds} ms");
sw.Reset();
sw.Start();
TwemojiFontCollection.Add(memoryStream);
TwemojiFontCollection.TryGet("Twemoji Mozilla", out var fontFamily); TwemojiFontCollection.TryGet("Twemoji Mozilla", out var fontFamily);
sw.Stop();
Console.WriteLine($"Parse .ttf: {sw.ElapsedMilliseconds} ms");
return fontFamily; return fontFamily;
}); });

View file

@ -20,6 +20,11 @@
OutputFile="Controls\Emoji\emoji-test.txt.gz" /> OutputFile="Controls\Emoji\emoji-test.txt.gz" />
</Target> </Target>
<Target Name="CompressTwemojiMozillaTtfResource" BeforeTargets="BeforeBuild" Condition="!Exists('Drawing\Emoji\TwemojiMozilla.ttf.gz')">
<GZipTask InputFile="Drawing\Emoji\TwemojiMozilla.ttf"
OutputFile="Drawing\Emoji\TwemojiMozilla.ttf.gz" />
</Target>
<ItemGroup> <ItemGroup>
<Compile Update="Controls\BindableToolStripButton.cs"> <Compile Update="Controls\BindableToolStripButton.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
@ -98,9 +103,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>emoji-test.txt.gz</TargetPath> <TargetPath>emoji-test.txt.gz</TargetPath>
</ContentWithTargetPath> </ContentWithTargetPath>
<ContentWithTargetPath Include="Drawing\Emoji\TwemojiMozilla.ttf"> <ContentWithTargetPath Include="Drawing\Emoji\TwemojiMozilla.ttf.gz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>TwemojiMozilla.ttf</TargetPath> <TargetPath>TwemojiMozilla.ttf.gz</TargetPath>
</ContentWithTargetPath> </ContentWithTargetPath>
</ItemGroup> </ItemGroup>
</Project> </Project>