Add a test for text align (#1207)
This commit is contained in:
Родитель
14813f82e0
Коммит
4559061eb7
|
@ -253,8 +253,9 @@ namespace SkiaSharp
|
|||
if (bitmap == null)
|
||||
throw new ArgumentNullException (nameof (bitmap));
|
||||
|
||||
var handle = SkiaApi.sk_image_new_from_bitmap (bitmap.Handle);
|
||||
return GetObject<SKImage> (handle);
|
||||
var image = GetObject<SKImage> (SkiaApi.sk_image_new_from_bitmap (bitmap.Handle));
|
||||
GC.KeepAlive (bitmap);
|
||||
return image;
|
||||
}
|
||||
|
||||
// create a new image from a GPU texture
|
||||
|
|
Двоичный файл не отображается.
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Xunit;
|
||||
|
||||
|
@ -470,5 +469,46 @@ namespace SkiaSharp.Tests
|
|||
Assert.Equal("80", rect.Attribute("height")?.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableTheory]
|
||||
[InlineData(SKTextAlign.Left, 300)]
|
||||
[InlineData(SKTextAlign.Center, 162)]
|
||||
[InlineData(SKTextAlign.Right, 23)]
|
||||
public void TextAlignMovesTextPosition(SKTextAlign align, int offset)
|
||||
{
|
||||
var font = Path.Combine(PathToFonts, "segoeui.ttf");
|
||||
using var tf = SKTypeface.FromFile(font);
|
||||
|
||||
using var bitmap = new SKBitmap(600, 200);
|
||||
using var canvas = new SKCanvas(bitmap);
|
||||
|
||||
canvas.Clear(SKColors.White);
|
||||
|
||||
using var paint = new SKPaint();
|
||||
paint.Typeface = tf;
|
||||
paint.IsAntialias = true;
|
||||
paint.TextSize = 64;
|
||||
paint.Color = SKColors.Black;
|
||||
|
||||
paint.TextAlign = align;
|
||||
canvas.DrawText("SkiaSharp", 300, 100, paint);
|
||||
|
||||
// [S]kia[S]har[p]
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 6, 66));
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 28, 87));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 28, 66));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 6, 87));
|
||||
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 120, 66));
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 142, 87));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 142, 66));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 120, 87));
|
||||
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 246, 70));
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 246, 113));
|
||||
Assert.Equal(SKColors.Black, bitmap.GetPixel(offset + 271, 83));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 258, 83));
|
||||
Assert.Equal(SKColors.White, bitmap.GetPixel(offset + 258, 113));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче