IsAntialias should also control the Edging (#1802)
This commit is contained in:
Родитель
8b060e6237
Коммит
5ab62b5a4d
|
@ -14,6 +14,7 @@ namespace SkiaSharp
|
|||
public unsafe class SKPaint : SKObject, ISKSkipObjectRegistration
|
||||
{
|
||||
private SKFont font;
|
||||
private bool lcdRenderText;
|
||||
|
||||
internal SKPaint (IntPtr handle, bool owns)
|
||||
: base (handle, owns)
|
||||
|
@ -38,6 +39,8 @@ namespace SkiaSharp
|
|||
|
||||
if (Handle == IntPtr.Zero)
|
||||
throw new InvalidOperationException ("Unable to create a new SKPaint instance.");
|
||||
|
||||
LcdRenderText = font.Edging == SKFontEdging.SubpixelAntialias;
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing) =>
|
||||
|
@ -55,7 +58,10 @@ namespace SkiaSharp
|
|||
|
||||
public bool IsAntialias {
|
||||
get => SkiaApi.sk_paint_is_antialias (Handle);
|
||||
set => SkiaApi.sk_paint_set_antialias (Handle, value);
|
||||
set {
|
||||
SkiaApi.sk_paint_set_antialias (Handle, value);
|
||||
UpdateFontEdging (value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDither {
|
||||
|
@ -81,8 +87,11 @@ namespace SkiaSharp
|
|||
}
|
||||
|
||||
public bool LcdRenderText {
|
||||
get => GetFont ().Edging == SKFontEdging.SubpixelAntialias;
|
||||
set => GetFont ().Edging = value ? SKFontEdging.SubpixelAntialias : SKFontEdging.Antialias;
|
||||
get => lcdRenderText;
|
||||
set {
|
||||
lcdRenderText = value;
|
||||
UpdateFontEdging (IsAntialias);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmbeddedBitmapText {
|
||||
|
@ -701,6 +710,17 @@ namespace SkiaSharp
|
|||
internal SKFont GetFont () =>
|
||||
font ??= OwnedBy (SKFont.GetObject (SkiaApi.sk_compatpaint_get_font (Handle), false), this);
|
||||
|
||||
private void UpdateFontEdging (bool antialias)
|
||||
{
|
||||
var edging = SKFontEdging.Alias;
|
||||
if (antialias) {
|
||||
edging = lcdRenderText
|
||||
? SKFontEdging.SubpixelAntialias
|
||||
: SKFontEdging.Antialias;
|
||||
}
|
||||
GetFont ().Edging = edging;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
internal static SKPaint GetObject (IntPtr handle) =>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 173debd238b1a55ab12f5994c5dc074fd141ccd6
|
||||
Subproject commit bdfa2ee20ac9f8aefb4bc7a1aa9d04de510539ad
|
|
@ -554,5 +554,92 @@ namespace SkiaSharp.Tests
|
|||
|
||||
Assert.NotNull(paint.GetTextPath("", 0, 0));
|
||||
}
|
||||
|
||||
[SkippableTheory]
|
||||
[InlineData(true, true, SKFontEdging.SubpixelAntialias)]
|
||||
[InlineData(false, true, SKFontEdging.Alias)]
|
||||
[InlineData(true, false, SKFontEdging.Antialias)]
|
||||
[InlineData(false, false, SKFontEdging.Alias)]
|
||||
public void UpdatingPropertiesIsAntialiasLcdRenderText(bool isAntialias, bool lcd, SKFontEdging newEdging)
|
||||
{
|
||||
var paint = new SKPaint();
|
||||
|
||||
paint.IsAntialias = isAntialias;
|
||||
paint.LcdRenderText = lcd;
|
||||
|
||||
Assert.Equal(newEdging, paint.GetFont().Edging);
|
||||
}
|
||||
|
||||
[SkippableTheory]
|
||||
[InlineData(true, true, SKFontEdging.SubpixelAntialias)]
|
||||
[InlineData(false, true, SKFontEdging.Alias)]
|
||||
[InlineData(true, false, SKFontEdging.Antialias)]
|
||||
[InlineData(false, false, SKFontEdging.Alias)]
|
||||
public void UpdatingPropertiesLcdRenderTextIsAntialias(bool isAntialias, bool lcd, SKFontEdging newEdging)
|
||||
{
|
||||
var paint = new SKPaint();
|
||||
|
||||
paint.LcdRenderText = lcd;
|
||||
paint.IsAntialias = isAntialias;
|
||||
|
||||
Assert.Equal(newEdging, paint.GetFont().Edging);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void PaintWithSubpixelEdgingIsPreserved()
|
||||
{
|
||||
var font = new SKFont();
|
||||
font.Edging = SKFontEdging.SubpixelAntialias;
|
||||
|
||||
var paint = new SKPaint(font);
|
||||
|
||||
Assert.True(paint.LcdRenderText);
|
||||
Assert.False(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);
|
||||
|
||||
paint.IsAntialias = true;
|
||||
|
||||
Assert.True(paint.LcdRenderText);
|
||||
Assert.True(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.SubpixelAntialias, paint.GetFont().Edging);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void PaintWithAntialiasEdgingIsPreserved()
|
||||
{
|
||||
var font = new SKFont();
|
||||
font.Edging = SKFontEdging.Antialias;
|
||||
|
||||
var paint = new SKPaint(font);
|
||||
|
||||
Assert.False(paint.LcdRenderText);
|
||||
Assert.False(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);
|
||||
|
||||
paint.IsAntialias = true;
|
||||
|
||||
Assert.False(paint.LcdRenderText);
|
||||
Assert.True(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.Antialias, paint.GetFont().Edging);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void PaintWithAliasEdgingIsPreserved()
|
||||
{
|
||||
var font = new SKFont();
|
||||
font.Edging = SKFontEdging.Alias;
|
||||
|
||||
var paint = new SKPaint(font);
|
||||
|
||||
Assert.False(paint.LcdRenderText);
|
||||
Assert.False(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.Alias, paint.GetFont().Edging);
|
||||
|
||||
paint.IsAntialias = true;
|
||||
|
||||
Assert.False(paint.LcdRenderText);
|
||||
Assert.True(paint.IsAntialias);
|
||||
Assert.Equal(SKFontEdging.Antialias, paint.GetFont().Edging);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче