diff --git a/installer/innosetup/setup.iss b/installer/innosetup/setup.iss index b4d7b878d..e3bc94302 100644 --- a/installer/innosetup/setup.iss +++ b/installer/innosetup/setup.iss @@ -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 diff --git a/src/Greenshot.Editor/Controls/EmojiData.cs b/src/Greenshot.Editor/Controls/EmojiData.cs index f4099c9cc..88e90c6f0 100644 --- a/src/Greenshot.Editor/Controls/EmojiData.cs +++ b/src/Greenshot.Editor/Controls/EmojiData.cs @@ -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; diff --git a/src/Greenshot.Editor/Drawing/EmojiRenderer.cs b/src/Greenshot.Editor/Drawing/EmojiRenderer.cs index fd263dc22..4e165a784 100644 --- a/src/Greenshot.Editor/Drawing/EmojiRenderer.cs +++ b/src/Greenshot.Editor/Drawing/EmojiRenderer.cs @@ -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 = new Lazy(() => + { + 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 _iconCache = new ConcurrentDictionary(); public static Image 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(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 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(64, 64); + RenderEmoji(emoji, font, image); + _iconCache[emoji] = image.ToBitmapSource(); + } } public static BitmapSource GetIcon(string emoji) diff --git a/src/Greenshot.Editor/Greenshot.Editor.csproj b/src/Greenshot.Editor/Greenshot.Editor.csproj index da3979874..ad79051a7 100644 --- a/src/Greenshot.Editor/Greenshot.Editor.csproj +++ b/src/Greenshot.Editor/Greenshot.Editor.csproj @@ -5,7 +5,7 @@ - + @@ -86,13 +86,4 @@ - - - - ..\SixLabors.Fonts.dll - - - ..\SixLabors.ImageSharp.Drawing.dll - - \ No newline at end of file diff --git a/src/SixLabors.Fonts.dll b/src/SixLabors.Fonts.dll deleted file mode 100644 index b9e1da71f..000000000 Binary files a/src/SixLabors.Fonts.dll and /dev/null differ diff --git a/src/SixLabors.ImageSharp.Drawing.dll b/src/SixLabors.ImageSharp.Drawing.dll deleted file mode 100644 index 1daf3c727..000000000 Binary files a/src/SixLabors.ImageSharp.Drawing.dll and /dev/null differ