diff --git a/src/Greenshot.Editor/Controls/EmojiControl.cs b/src/Greenshot.Editor/Controls/EmojiControl.cs index c32100174..c3fc09b6e 100644 --- a/src/Greenshot.Editor/Controls/EmojiControl.cs +++ b/src/Greenshot.Editor/Controls/EmojiControl.cs @@ -20,16 +20,11 @@ namespace Greenshot.Editor.Controls set { SetValue(EmojiProperty, value); } } - private static void OnUseSystemFontPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - ((EmojiControl)d).Source = null; - } - protected override void OnRender(DrawingContext dc) { if (Source == null && !string.IsNullOrEmpty(Emoji)) { - Source = EmojiRenderer.GetBitmapSource(Emoji, iconSize: 48, useSystemFont: false); + Source = EmojiRenderer.GetBitmapSource(Emoji, iconSize: 48); } base.OnRender(dc); diff --git a/src/Greenshot.Editor/Drawing/EmojiContainer.cs b/src/Greenshot.Editor/Drawing/EmojiContainer.cs index d84c205ab..17b11cc8e 100644 --- a/src/Greenshot.Editor/Drawing/EmojiContainer.cs +++ b/src/Greenshot.Editor/Drawing/EmojiContainer.cs @@ -155,7 +155,7 @@ namespace Greenshot.Editor.Drawing var iconSize = Math.Min(Bounds.Width, Bounds.Height); if (iconSize <= 0) return null; - var image = EmojiRenderer.GetBitmap(Emoji, iconSize, useSystemFont: false); + var image = EmojiRenderer.GetBitmap(Emoji, iconSize); if (RotationAngle != 0) { var newImage = image.Rotate(RotationAngle); diff --git a/src/Greenshot.Editor/Drawing/EmojiRenderer.cs b/src/Greenshot.Editor/Drawing/EmojiRenderer.cs index a2036dde2..37d827cb4 100644 --- a/src/Greenshot.Editor/Drawing/EmojiRenderer.cs +++ b/src/Greenshot.Editor/Drawing/EmojiRenderer.cs @@ -30,30 +30,22 @@ namespace Greenshot.Editor.Drawing return fontFamily; }); - private static Lazy _segoeUI = new Lazy(() => - { - using var fileStream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Fonts\seguiemj.ttf"), FileMode.Open, FileAccess.Read); - _fontCollection.Add(fileStream); - _fontCollection.TryGet("Segoe UI Emoji", out var fontFamily); - return fontFamily; - }); - - public static Image GetImage(string emoji, int iconSize, bool useSystemFont) + public static Image GetImage(string emoji, int iconSize) { var image = new Image(iconSize, iconSize); - RenderEmoji(emoji, iconSize, image, useSystemFont); + RenderEmoji(emoji, iconSize, image); return image; } - private static void RenderEmoji(string emoji, int iconSize, SixLabors.ImageSharp.Image image, bool useSystemFont) + private static void RenderEmoji(string emoji, int iconSize, SixLabors.ImageSharp.Image image) { - var fontFamily = useSystemFont ? _segoeUI.Value : _twemoji.Value; - var font = fontFamily.CreateFont(useSystemFont ? iconSize * 0.95f : iconSize, FontStyle.Regular); - var verticalOffset = useSystemFont ? -font.Size * 0.050f : font.Size * 0.045f; + var fontFamily = _twemoji.Value; + var font = fontFamily.CreateFont(iconSize, FontStyle.Regular); + var verticalOffset = font.Size * 0.045f; var textOptions = new TextOptions(font) { - Origin = new SixLabors.ImageSharp.PointF(font.Size / 2.0f, font.Size / 2.0f - verticalOffset), + Origin = new SixLabors.ImageSharp.PointF(font.Size / 2.0f, font.Size / 2.0f + verticalOffset), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; @@ -61,7 +53,7 @@ namespace Greenshot.Editor.Drawing image.Mutate(x => x.DrawText(textOptions, emoji, SixLabors.ImageSharp.Color.Black)); } - public static Image GetBitmap(string emoji, int iconSize, bool useSystemFont) + public static Image GetBitmap(string emoji, int iconSize) { int width = iconSize; int height = iconSize; @@ -74,7 +66,7 @@ namespace Greenshot.Editor.Drawing unsafe { var image = SixLabors.ImageSharp.Image.WrapMemory((void*)bitmapData.Scan0, width: width, height: height); - RenderEmoji(emoji, iconSize, image, useSystemFont); + RenderEmoji(emoji, iconSize, image); } } finally @@ -85,7 +77,7 @@ namespace Greenshot.Editor.Drawing return bitmap; } - public static BitmapSource GetBitmapSource(string emoji, int iconSize, bool useSystemFont) + public static BitmapSource GetBitmapSource(string emoji, int iconSize) { var pixelFormat = PixelFormats.Bgra32; int width = iconSize; @@ -95,7 +87,7 @@ namespace Greenshot.Editor.Drawing var image = SixLabors.ImageSharp.Image.WrapMemory(byteMemory: pixels, width: width, height: height); - RenderEmoji(emoji, iconSize, image, useSystemFont); + RenderEmoji(emoji, iconSize, image); var source = BitmapSource.Create(pixelWidth: width, pixelHeight: height, dpiX: 96, dpiY: 96, pixelFormat: pixelFormat, palette: null, pixels: pixels, stride: stride); source.Freeze(); diff --git a/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs b/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs index 4d6c9a5c2..34e7c55fc 100644 --- a/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs +++ b/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs @@ -452,7 +452,7 @@ namespace Greenshot.Editor.Forms { // this.btnEmoji.CheckOnClick = true; this.btnEmoji.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.btnEmoji.Image = EmojiRenderer.GetBitmap("🙂", 32, useSystemFont: false); + this.btnEmoji.Image = EmojiRenderer.GetBitmap("🙂", 32); this.btnEmoji.ImageTransparentColor = System.Drawing.Color.Magenta; this.btnEmoji.Text = "Emoji (M)"; this.btnEmoji.Name = "btnEmoji"; diff --git a/src/Greenshot.Editor/Greenshot.Editor.csproj b/src/Greenshot.Editor/Greenshot.Editor.csproj index c7798832b..a343853f4 100644 --- a/src/Greenshot.Editor/Greenshot.Editor.csproj +++ b/src/Greenshot.Editor/Greenshot.Editor.csproj @@ -8,7 +8,7 @@ - +