SixLabors vanillia

This commit is contained in:
Julien Richard 2022-01-23 13:37:48 +01:00
commit 4f1478ec34
6 changed files with 32 additions and 32 deletions

View file

@ -30,9 +30,9 @@ Source: {#ReleaseDir}\Svg.dll; DestDir: {app}; Components: greenshot; Flags: ove
Source: {#ReleaseDir}\Fizzler.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\HtmlAgilityPack.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\Newtonsoft.Json.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\Emoji.Wpf.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\Typography.GlyphLayout.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\Typography.OpenFont.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\SixLabors.ImageSharp.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\SixLabors.ImageSharp.Drawing.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\SixLabors.Fonts.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#GreenshotProjectDir}\log4net.xml; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion
Source: {#ReleaseDir}\checksum.SHA256; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
;Source: ..\greenshot-defaults.ini; DestDir: {app}; Flags: overwritereadonly ignoreversion replacesameversion

View file

@ -19,6 +19,7 @@ using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Greenshot.Editor.Drawing;
using SixLabors.Fonts.Unicode;
namespace Greenshot.Editor.Controls
{
@ -44,7 +45,7 @@ namespace Greenshot.Editor.Controls
public static void Load()
{
_init = Task.Run(() =>
_init ??= Task.Run(() =>
{
ParseEmojiList();
@ -194,6 +195,12 @@ namespace Greenshot.Editor.Controls
var unqualified = text.Replace("\ufe0f", "");
if (qualified_lut.ContainsKey(unqualified))
continue;
// Fix simple fully-qualified emojis
if (CodePoint.GetCodePointCount(text.AsSpan()) == 2)
{
text = text.TrimEnd('\ufe0f');
}
qualified_lut[unqualified] = text;

View file

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
@ -13,6 +14,7 @@ using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using Font = SixLabors.Fonts.Font;
using FontFamily = SixLabors.Fonts.FontFamily;
using FontStyle = SixLabors.Fonts.FontStyle;
using Image = System.Drawing.Image;
using TextOptions = SixLabors.Fonts.TextOptions;
@ -21,23 +23,19 @@ namespace Greenshot.Editor.Drawing
{
internal static class EmojiRenderer
{
private static SixLabors.Fonts.FontFamily? _fontFamily;
private static Lazy<FontFamily> _fontFamily = new Lazy<FontFamily>(() =>
{
using var stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Greenshot.Editor.Resources.TwemojiMozilla.ttf");
var fontCollection = new FontCollection();
fontCollection.Add(stream);
fontCollection.TryGet("Twemoji Mozilla", out var fontFamily);
return fontFamily;
});
private static ConcurrentDictionary<string, BitmapSource> _iconCache = new ConcurrentDictionary<string, BitmapSource>();
public static Image<Rgba32> GetImage(string emoji, int iconSize)
{
if (_fontFamily == null)
{
using var stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Greenshot.Editor.Resources.TwemojiMozilla.ttf");
var fontCollection = new FontCollection();
fontCollection.Add(stream);
if (fontCollection.TryGet("Twemoji Mozilla", out var fontFamily))
{
_fontFamily = fontFamily;
}
}
var font = _fontFamily.Value.CreateFont(iconSize, FontStyle.Regular);
var image = new Image<Rgba32>(iconSize, iconSize);
@ -51,8 +49,8 @@ namespace Greenshot.Editor.Drawing
var verticalOffset = font.Size * 0.045f;
var textOptions = new TextOptions(font)
{
Origin = new SixLabors.ImageSharp.PointF(0, font.Size / 2.0f - verticalOffset),
HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center
Origin = new SixLabors.ImageSharp.PointF(font.Size / 2.0f, font.Size / 2.0f - verticalOffset),
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
};
image.Mutate(x => x.DrawText(textOptions, emoji, SixLabors.ImageSharp.Color.Black));
@ -103,10 +101,14 @@ namespace Greenshot.Editor.Drawing
public static void FillIconCache(IEnumerable<string> emojis)
{
Parallel.ForEach(emojis, emoji =>
var font = _fontFamily.Value.CreateFont(64, FontStyle.Regular);
var metric = font.FontMetrics;
foreach (var emoji in emojis)
{
GetIcon(emoji);
});
var image = new Image<Rgba32>(64, 64);
RenderEmoji(emoji, font, image);
_iconCache[emoji] = image.ToBitmapSource();
}
}
public static BitmapSource GetIcon(string emoji)

View file

@ -5,7 +5,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0-alpha.0.156" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta13.15" />
</ItemGroup>
<ItemGroup>
@ -86,13 +86,4 @@
<EmbeddedResource Include="Resources\emoji-test.txt" />
<EmbeddedResource Include="Resources\TwemojiMozilla.ttf" />
</ItemGroup>
<ItemGroup>
<Reference Include="SixLabors.Fonts">
<HintPath>..\SixLabors.Fonts.dll</HintPath>
</Reference>
<Reference Include="SixLabors.ImageSharp.Drawing">
<HintPath>..\SixLabors.ImageSharp.Drawing.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.