mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 22:13:23 -07:00
SixLabors.ImageSharp.Drawing@1.0.0-beta15
+ clean useSystemFont + adjust vertical offset
This commit is contained in:
parent
c2a5d1c961
commit
8fc49c47a9
5 changed files with 15 additions and 28 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -30,30 +30,22 @@ namespace Greenshot.Editor.Drawing
|
|||
return fontFamily;
|
||||
});
|
||||
|
||||
private static Lazy<FontFamily> _segoeUI = new Lazy<FontFamily>(() =>
|
||||
{
|
||||
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<Rgba32> GetImage(string emoji, int iconSize, bool useSystemFont)
|
||||
public static Image<Rgba32> GetImage(string emoji, int iconSize)
|
||||
{
|
||||
var image = new Image<Rgba32>(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<Bgra32>((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<Bgra32>(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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
|
||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue