Updated the tests to match the new API
This commit is contained in:
Родитель
15f1263fc7
Коммит
4d2b85f3c1
|
@ -11,6 +11,7 @@ namespace SkiaSharp.Tests
|
|||
public const int GL_TEXTURE_2D = 0x0DE1;
|
||||
public const int GL_UNSIGNED_BYTE = 0x1401;
|
||||
public const int GL_RGBA = 0x1908;
|
||||
public const int GL_RGBA8 = 0x8058;
|
||||
|
||||
[DllImport(libGL)]
|
||||
public extern static void CGLGetVersion(out int majorvers, out int minorvers);
|
||||
|
|
|
@ -63,7 +63,8 @@ namespace SkiaSharp.Tests
|
|||
|
||||
return new GRGlTextureInfo {
|
||||
Id = textureId,
|
||||
Target = Cgl.GL_TEXTURE_2D
|
||||
Target = Cgl.GL_TEXTURE_2D,
|
||||
Format = Cgl.GL_RGBA8
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace SkiaSharp.Tests
|
|||
public const int GL_TEXTURE_2D = 0x0DE1;
|
||||
public const int GL_UNSIGNED_BYTE = 0x1401;
|
||||
public const int GL_RGBA = 0x1908;
|
||||
public const int GL_RGBA8 = 0x8058;
|
||||
|
||||
public const int GLX_USE_GL = 1;
|
||||
public const int GLX_BUFFER_SIZE = 2;
|
||||
|
|
|
@ -153,7 +153,8 @@ namespace SkiaSharp.Tests
|
|||
|
||||
return new GRGlTextureInfo {
|
||||
Id = textureId,
|
||||
Target = Glx.GL_TEXTURE_2D
|
||||
Target = Glx.GL_TEXTURE_2D,
|
||||
Format = Glx.GL_RGBA8
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace SkiaSharp.Tests
|
|||
public const int GL_TEXTURE_2D = 0x0DE1;
|
||||
public const int GL_UNSIGNED_BYTE = 0x1401;
|
||||
public const int GL_RGBA = 0x1908;
|
||||
public const int GL_RGBA8 = 0x8058;
|
||||
|
||||
public const int WGL_NUMBER_PIXEL_FORMATS_ARB = 0x2000;
|
||||
public const int WGL_DRAW_TO_WINDOW_ARB = 0x2001;
|
||||
|
|
|
@ -179,7 +179,8 @@ namespace SkiaSharp.Tests
|
|||
return new GRGlTextureInfo
|
||||
{
|
||||
Id = textureId,
|
||||
Target = Wgl.GL_TEXTURE_2D
|
||||
Target = Wgl.GL_TEXTURE_2D,
|
||||
Format = Wgl.GL_RGBA8
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,10 @@ namespace SkiaSharp.Tests
|
|||
|
||||
Assert.Equal(SKColorType.Rgb565, info.ColorType);
|
||||
|
||||
var copy = info.WithColorType(SKColorType.Index8);
|
||||
var copy = info.WithColorType(SKColorType.Gray8);
|
||||
|
||||
Assert.Equal(SKColorType.Rgb565, info.ColorType);
|
||||
Assert.Equal(SKColorType.Index8, copy.ColorType);
|
||||
Assert.Equal(SKColorType.Gray8, copy.ColorType);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace SkiaSharp.Tests
|
|||
var info = new SKImageInfo(1, 1);
|
||||
var pixels = Marshal.AllocCoTaskMem(info.BytesSize);
|
||||
|
||||
bitmap.InstallPixels(info, pixels, info.RowBytes, null, onRelease, "RELEASING!");
|
||||
bitmap.InstallPixels(info, pixels, info.RowBytes, onRelease, "RELEASING!");
|
||||
}
|
||||
|
||||
Assert.True(released, "The SKBitmapReleaseDelegate was not called.");
|
||||
|
@ -251,7 +251,9 @@ namespace SkiaSharp.Tests
|
|||
|
||||
Assert.True(bitmap.ExtractAlpha(alpha, paint, out offset));
|
||||
|
||||
Assert.Equal(new SKPointI(-7, -7), offset);
|
||||
Assert.Equal(new SKPointI(-12, -12), offset);
|
||||
|
||||
SaveBitmap(alpha);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
|
@ -296,6 +298,7 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
|
||||
[SkippableFact]
|
||||
[Obsolete]
|
||||
public void BitmapResizes()
|
||||
{
|
||||
var srcInfo = new SKImageInfo(200, 200);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace SkiaSharp.Tests
|
||||
|
@ -11,16 +12,19 @@ namespace SkiaSharp.Tests
|
|||
[SkippableFact]
|
||||
public void CanvasCanRestoreOnGpu()
|
||||
{
|
||||
using (var ctx = CreateGlContext()) {
|
||||
using (var ctx = CreateGlContext())
|
||||
{
|
||||
ctx.MakeCurrent();
|
||||
|
||||
using (var grContext = GRContext.Create(GRBackend.OpenGL))
|
||||
using (var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100))) {
|
||||
using (var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100)))
|
||||
{
|
||||
var canvas = surface.Canvas;
|
||||
|
||||
Assert.Equal(SKMatrix.MakeIdentity(), canvas.TotalMatrix);
|
||||
|
||||
using (new SKAutoCanvasRestore(canvas)) {
|
||||
using (new SKAutoCanvasRestore(canvas))
|
||||
{
|
||||
canvas.Translate(10, 10);
|
||||
Assert.Equal(SKMatrix.MakeTranslation(10, 10), canvas.TotalMatrix);
|
||||
}
|
||||
|
@ -86,5 +90,47 @@ namespace SkiaSharp.Tests
|
|||
Assert.Equal(SKColors.Orange, secondBitmap.GetPixel(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void SvgCanvasSavesFile()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
|
||||
using (var wstream = new SKManagedWStream(stream))
|
||||
using (var writer = new SKXmlStreamWriter(wstream))
|
||||
using (var svg = SKSvgCanvas.Create(SKRect.Create(100, 100), writer))
|
||||
{
|
||||
var paint = new SKPaint
|
||||
{
|
||||
Color = SKColors.Red,
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
svg.DrawRect(SKRect.Create(10, 10, 80, 80), paint);
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
var xml = reader.ReadToEnd();
|
||||
var xdoc = XDocument.Parse(xml);
|
||||
|
||||
var svg = xdoc.Root;
|
||||
var ns = svg.Name.Namespace;
|
||||
|
||||
Assert.Equal(ns + "svg", svg.Name);
|
||||
Assert.Equal("100", svg.Attribute("width")?.Value);
|
||||
Assert.Equal("100", svg.Attribute("height")?.Value);
|
||||
|
||||
var rect = svg.Element(ns + "rect");
|
||||
Assert.Equal(ns + "rect", rect.Name);
|
||||
Assert.Equal("rgb(255,0,0)", rect.Attribute("fill")?.Value);
|
||||
Assert.Equal("none", rect.Attribute("stroke")?.Value);
|
||||
Assert.Equal("10", rect.Attribute("x")?.Value);
|
||||
Assert.Equal("10", rect.Attribute("y")?.Value);
|
||||
Assert.Equal("80", rect.Attribute("width")?.Value);
|
||||
Assert.Equal("80", rect.Attribute("height")?.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,38 +45,58 @@ namespace SkiaSharp.Tests
|
|||
var cachedFrames = new SKBitmap [FrameCount];
|
||||
var info = new SKImageInfo (codec.Info.Width, codec.Info.Height);
|
||||
|
||||
var decode = new Action<SKBitmap, bool, int> ((bm, cached, index) => {
|
||||
if (cached) {
|
||||
var requiredFrame = frameInfos [index].RequiredFrame;
|
||||
if (requiredFrame != -1) {
|
||||
Assert.True (cachedFrames [requiredFrame].CopyTo (bm));
|
||||
}
|
||||
var decode = new Action<SKBitmap, int, int> ((bm, cachedIndex, index) => {
|
||||
var decodeInfo = info;
|
||||
if (index > 0) {
|
||||
decodeInfo = info.WithAlphaType (frameInfos [index].AlphaType);
|
||||
}
|
||||
bm.TryAllocPixels (decodeInfo);
|
||||
if (cachedIndex != -1) {
|
||||
Assert.True (cachedFrames [cachedIndex].CopyTo (bm));
|
||||
}
|
||||
var opts = new SKCodecOptions (index, cachedIndex);
|
||||
var result = codec.GetPixels (decodeInfo, bm.GetPixels (), opts);
|
||||
if (cachedIndex != -1 && frameInfos [cachedIndex].DisposalMethod == SKCodecAnimationDisposalMethod.RestorePrevious) {
|
||||
Assert.Equal (SKCodecResult.InvalidParameters, result);
|
||||
}
|
||||
var opts = new SKCodecOptions (index, cached);
|
||||
var result = codec.GetPixels (info, bm.GetPixels (), opts);
|
||||
Assert.Equal (SKCodecResult.Success, result);
|
||||
});
|
||||
|
||||
for (var i = 0; i < FrameCount; i++) {
|
||||
var cachedFrame = cachedFrames [i] = new SKBitmap (info);
|
||||
decode (cachedFrame, true, i);
|
||||
var cachedFrame = cachedFrames [i] = new SKBitmap ();
|
||||
decode (cachedFrame, -1, i);
|
||||
|
||||
var uncachedFrame = new SKBitmap (info);
|
||||
decode (uncachedFrame, false, i);
|
||||
var uncachedFrame = new SKBitmap ();
|
||||
decode (uncachedFrame, frameInfos [i].RequiredFrame, i);
|
||||
|
||||
Assert.Equal (cachedFrame.Bytes, uncachedFrame.Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void GetSingleGifFrame()
|
||||
{
|
||||
var stream = new SKFileStream(Path.Combine(PathToImages, "animated-heart.gif"));
|
||||
using (var codec = SKCodec.Create(stream))
|
||||
{
|
||||
var frameInfos = codec.FrameInfo;
|
||||
for (var i = 0; i < frameInfos.Length; i++)
|
||||
{
|
||||
Assert.True(codec.GetFrameInfo(i, out var info));
|
||||
Assert.Equal(frameInfos[i], info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void GetEncodedInfo ()
|
||||
{
|
||||
var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png"));
|
||||
using (var codec = SKCodec.Create (stream)) {
|
||||
Assert.Equal (SKEncodedInfoColor.Rgba, codec.EncodedInfo.Color);
|
||||
Assert.Equal (SKEncodedInfoAlpha.Unpremul, codec.EncodedInfo.Alpha);
|
||||
Assert.Equal (8, codec.EncodedInfo.BitsPerComponent);
|
||||
Assert.Equal (SKImageInfo.PlatformColorType, codec.Info.ColorType);
|
||||
Assert.Equal (SKAlphaType.Unpremul, codec.Info.AlphaType);
|
||||
Assert.Equal (32, codec.Info.BitsPerPixel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,16 +28,6 @@ namespace SkiaSharp.Tests
|
|||
(SKPMColor)SKColors.Blue
|
||||
};
|
||||
|
||||
[SkippableFact]
|
||||
public void CreateIndex8Bitmap()
|
||||
{
|
||||
var info = new SKImageInfo(320, 240, SKColorType.Index8, SKAlphaType.Opaque);
|
||||
var ct = new SKColorTable(Colors);
|
||||
var bitmap = new SKBitmap(info, ct);
|
||||
Assert.NotNull(bitmap);
|
||||
Assert.Equal(ct, bitmap.ColorTable);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void MembersRetrieveSingleColorWithAlpha()
|
||||
{
|
||||
|
@ -96,72 +86,5 @@ namespace SkiaSharp.Tests
|
|||
var color = colorTable[250];
|
||||
});
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void Index8ImageHasColorTable()
|
||||
{
|
||||
var path = Path.Combine(PathToImages, "index8.png");
|
||||
|
||||
var codec = SKCodec.Create(new SKFileStream(path));
|
||||
|
||||
// It appears I can't use Unpremul as the alpha type, as the color table is not premultiplied then
|
||||
// https://groups.google.com/forum/#!topic/skia-discuss/mNUxQon5OMY
|
||||
var info = new SKImageInfo(codec.Info.Width, codec.Info.Height, SKColorType.Index8, SKAlphaType.Premul);
|
||||
|
||||
var bitmap = SKBitmap.Decode(codec, info);
|
||||
|
||||
var colorTable = bitmap.ColorTable;
|
||||
|
||||
Assert.NotNull(colorTable);
|
||||
|
||||
Assert.Equal((SKPMColor)0x000000, colorTable[0]);
|
||||
Assert.Equal((SKColor)0x000000, colorTable.GetUnPreMultipliedColor(0));
|
||||
|
||||
if (IsWindows || IsLinux) {
|
||||
Assert.Equal((SKPMColor)0xFFA4C639, colorTable[255]);
|
||||
} else {
|
||||
Assert.Equal((SKPMColor)0xFF39C6A4, colorTable[255]);
|
||||
}
|
||||
Assert.Equal((SKColor)0xFFA4C639, colorTable.GetUnPreMultipliedColor(255));
|
||||
|
||||
if (IsWindows || IsLinux) {
|
||||
Assert.Equal((SKPMColor)0x7E51621C, colorTable[140]);
|
||||
} else {
|
||||
Assert.Equal((SKPMColor)0x7E1C6251, colorTable[140]);
|
||||
}
|
||||
Assert.Equal((SKColor)0x7EA4C639, colorTable.GetUnPreMultipliedColor(140));
|
||||
|
||||
if (IsWindows || IsLinux) {
|
||||
Assert.Equal((SKPMColor)0x7E51621C, bitmap.GetIndex8Color(182, 348));
|
||||
} else {
|
||||
Assert.Equal((SKPMColor)0x7E1C6251, bitmap.GetIndex8Color(182, 348));
|
||||
}
|
||||
Assert.Equal((SKColor)0x7EA4C639, bitmap.GetPixel(182, 348));
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void Index8ImageCanChangeColorTable()
|
||||
{
|
||||
var path = Path.Combine(PathToImages, "index8.png");
|
||||
|
||||
var codec = SKCodec.Create(new SKFileStream(path));
|
||||
var info = new SKImageInfo(codec.Info.Width, codec.Info.Height, SKColorType.Index8, SKAlphaType.Premul);
|
||||
var bitmap = SKBitmap.Decode(codec, info);
|
||||
|
||||
var colorTable = bitmap.ColorTable;
|
||||
Assert.Equal((SKColor)0xFFA4C639, colorTable.GetUnPreMultipliedColor(255));
|
||||
|
||||
var invertedColors = colorTable.Colors.Select(c =>
|
||||
{
|
||||
var c2 = (SKColor)c;
|
||||
var inv = new SKColor((byte)(255 - c2.Red), (byte)(255 - c2.Green), (byte)(255 - c2.Blue), c2.Alpha);
|
||||
return (SKPMColor)inv;
|
||||
}).ToArray();
|
||||
|
||||
colorTable = new SKColorTable(invertedColors);
|
||||
bitmap.SetColorTable(colorTable);
|
||||
|
||||
Assert.Equal((SKColor)0xFF5B39C6, colorTable.GetUnPreMultipliedColor(255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
|
||||
namespace SkiaSharp.Tests
|
||||
{
|
||||
public class SKFontManagerTest : SKTest
|
||||
{
|
||||
[SkippableFact]
|
||||
public void TestFontManagerMatchCharacter()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
var emoji = "🚀";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(emoji, SKTextEncoding.Utf32);
|
||||
using (var typeface = fonts.MatchCharacter(emojiChar))
|
||||
{
|
||||
if (IsLinux)
|
||||
Assert.Equal("Symbola", typeface.FamilyName);
|
||||
else if (IsMac)
|
||||
Assert.Equal("Apple Color Emoji", typeface.FamilyName);
|
||||
else if (IsWindows)
|
||||
Assert.Contains(typeface.FamilyName, new[] { "Segoe UI Emoji", "Segoe UI Symbol" });
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestCreateDefault()
|
||||
{
|
||||
Assert.NotNull(SKFontManager.CreateDefault());
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestFamilyCount()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
Assert.True(fonts.FontFamilyCount > 0);
|
||||
|
||||
var families = fonts.GetFontFamilies();
|
||||
Assert.True(families.Length > 0);
|
||||
Assert.Equal(fonts.FontFamilyCount, families.Length);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestMatchFamily()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var set = fonts.MatchFamily("Arial");
|
||||
Assert.NotNull(set);
|
||||
|
||||
Assert.True(set.Count > 0);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestMatchFamilyStyle()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var tf = fonts.MatchFamily("Arial", SKFontStyle.Bold);
|
||||
Assert.NotNull(tf);
|
||||
|
||||
Assert.Equal((int)SKFontStyleWeight.Bold, tf.FontWeight);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestMatchTypeface()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var normal = fonts.MatchFamily("Arial", SKFontStyle.Normal);
|
||||
Assert.NotNull(normal);
|
||||
Assert.Equal((int)SKFontStyleWeight.Normal, normal.FontWeight);
|
||||
|
||||
var bold = fonts.MatchTypeface(normal, SKFontStyle.Bold);
|
||||
Assert.NotNull(bold);
|
||||
Assert.Equal((int)SKFontStyleWeight.Bold, bold.FontWeight);
|
||||
|
||||
Assert.Equal(normal.FamilyName, bold.FamilyName);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void NullWithMissingFile()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
Assert.Null(fonts.FromFile(Path.Combine(PathToFonts, "font that doesn't exist.ttf")));
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestFamilyName()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
using (var typeface = fonts.FromFile(Path.Combine(PathToFonts, "Roboto2-Regular_NoEmbed.ttf")))
|
||||
{
|
||||
Assert.Equal("Roboto2", typeface.FamilyName);
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void CanReadData()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var bytes = File.ReadAllBytes(Path.Combine(PathToFonts, "Distortable.ttf"));
|
||||
using (var data = SKData.CreateCopy(bytes))
|
||||
using (var typeface = fonts.FromData(data))
|
||||
{
|
||||
Assert.NotNull(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void CanReadNonSeekableStream()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
using (var stream = File.OpenRead(Path.Combine(PathToFonts, "Distortable.ttf")))
|
||||
using (var nonSeekable = new NonSeekableReadOnlyStream(stream))
|
||||
using (var typeface = fonts.FromStream(nonSeekable))
|
||||
{
|
||||
Assert.NotNull(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void CanCreateStyleSet()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
Assert.NotNull(fonts.CreateStyleSet(0));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
using Xunit;
|
||||
|
||||
namespace SkiaSharp.Tests
|
||||
{
|
||||
public class SKFontStyleSetTest : SKTest
|
||||
{
|
||||
[SkippableFact]
|
||||
public void TestCanCreateEmpty()
|
||||
{
|
||||
var set = new SKFontStyleSet();
|
||||
|
||||
Assert.Equal(0, set.Count);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestFindsNothing()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var set = fonts.MatchFamily("Missing Font");
|
||||
Assert.NotNull(set);
|
||||
|
||||
Assert.Equal(0, set.Count);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestSetHasAtLeastOne()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
|
||||
var set = fonts.MatchFamily("Arial");
|
||||
Assert.NotNull(set);
|
||||
|
||||
Assert.True(set.Count > 0);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestCanGetStyles()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
var set = fonts.MatchFamily("Arial");
|
||||
|
||||
for (var i = 0; i < set.Count; i++)
|
||||
{
|
||||
set.GetStyle(i, out var style, out var name);
|
||||
|
||||
Assert.NotNull(style);
|
||||
Assert.NotNull(name);
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestCanCreateBoldFromIndex()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
var set = fonts.MatchFamily("Arial");
|
||||
|
||||
int idx;
|
||||
for (idx = 0; idx < set.Count; idx++)
|
||||
{
|
||||
set.GetStyle(idx, out var style, out var name);
|
||||
if (style.Weight == (int)SKFontStyleWeight.Bold)
|
||||
{
|
||||
// flip the sign so we can confirm that we found it
|
||||
idx *= -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check that we found something
|
||||
Assert.True(idx <= 0);
|
||||
|
||||
// flip the sign and get the typeface
|
||||
var typeface = set.CreateTypeface(-idx);
|
||||
|
||||
Assert.NotNull(typeface);
|
||||
Assert.Equal((int)SKFontStyleWeight.Bold, typeface.FontStyle.Weight);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestCanCreateBold()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
var set = fonts.MatchFamily("Arial");
|
||||
|
||||
var typeface = set.CreateTypeface(SKFontStyle.Bold);
|
||||
|
||||
Assert.NotNull(typeface);
|
||||
Assert.Equal((int)SKFontStyleWeight.Bold, typeface.FontStyle.Weight);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,7 +70,7 @@ namespace SkiaSharp.Tests
|
|||
Assert.Equal(data.ToArray(), bitmap.Bytes);
|
||||
}
|
||||
|
||||
private class TestSerializer : SKManagedPixelSerializer
|
||||
private class TestSerializer : SKPixelSerializer
|
||||
{
|
||||
public int DidEncode { get; set; }
|
||||
|
||||
|
|
|
@ -43,6 +43,25 @@ namespace SkiaSharp.Tests
|
|||
mask.FreeImage();
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void AutoMaskFreeImageReleasesMemory()
|
||||
{
|
||||
byte rawMask = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1;
|
||||
var buffer = new byte[] { rawMask };
|
||||
var bounds = new SKRectI(0, 0, 8, 1);
|
||||
UInt32 rowBytes = 1;
|
||||
var format = SKMaskFormat.BW;
|
||||
|
||||
var mask = new SKMask(bounds, rowBytes, format);
|
||||
|
||||
mask.Image = SKMask.AllocateImage(100);
|
||||
|
||||
using (new SKAutoMaskFreeImage(mask.Image))
|
||||
{
|
||||
Assert.Equal(rawMask, mask.GetAddr1(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void Alpha8MaskBufferIsCopied()
|
||||
{
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace SkiaSharp.Tests
|
|||
public void DrawTransparentImageWithHighFilterQualityWithPremul()
|
||||
{
|
||||
var oceanColor = (SKColor)0xFF9EB4D6;
|
||||
var landColor = (SKColor)0xFFACB69B;
|
||||
var landColor = (SKColor)0xFFADB69C;
|
||||
|
||||
using (var bitmap = new SKBitmap(new SKImageInfo(300, 300)))
|
||||
using (var canvas = new SKCanvas(bitmap))
|
||||
|
|
|
@ -30,11 +30,11 @@ namespace SkiaSharp.Tests
|
|||
Assert.Equal(SKColorType.Rgb565, pixmap.ColorType);
|
||||
Assert.Equal((IntPtr)123, pixmap.GetPixels());
|
||||
|
||||
var copy = pixmap.WithColorType(SKColorType.Index8);
|
||||
var copy = pixmap.WithColorType(SKColorType.Gray8);
|
||||
|
||||
Assert.Equal(SKColorType.Rgb565, pixmap.ColorType);
|
||||
Assert.Equal((IntPtr)123, pixmap.GetPixels());
|
||||
Assert.Equal(SKColorType.Index8, copy.ColorType);
|
||||
Assert.Equal(SKColorType.Gray8, copy.ColorType);
|
||||
Assert.Equal((IntPtr)123, copy.GetPixels());
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private void DrawGpuTexture(Action<SKSurface, GRGlBackendTextureDesc> draw)
|
||||
[Obsolete]
|
||||
private void DrawGpuTextureWithDesc(Action<SKSurface, GRGlBackendTextureDesc> draw)
|
||||
{
|
||||
using (var ctx = CreateGlContext())
|
||||
{
|
||||
|
@ -44,13 +45,15 @@ namespace SkiaSharp.Tests
|
|||
|
||||
// create the texture
|
||||
var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));
|
||||
// this is a new field that was added to the struct
|
||||
textureInfo.Format = 0;
|
||||
var textureDesc = new GRGlBackendTextureDesc
|
||||
{
|
||||
Width = 100,
|
||||
Height = 100,
|
||||
Config = GRPixelConfig.Rgba8888,
|
||||
Flags = GRBackendTextureDescFlags.RenderTarget,
|
||||
Origin = GRSurfaceOrigin.TopLeft,
|
||||
Origin = GRSurfaceOrigin.BottomLeft,
|
||||
SampleCount = 0,
|
||||
TextureHandle = textureInfo,
|
||||
};
|
||||
|
@ -69,6 +72,30 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private void DrawGpuTexture(Action<SKSurface, GRBackendTexture> draw)
|
||||
{
|
||||
using (var ctx = CreateGlContext())
|
||||
{
|
||||
ctx.MakeCurrent();
|
||||
|
||||
// create the texture
|
||||
var textureInfo = ctx.CreateTexture(new SKSizeI(100, 100));
|
||||
var texture = new GRBackendTexture(100, 100, false, textureInfo);
|
||||
|
||||
// create the surface
|
||||
using (var grContext = GRContext.Create(GRBackend.OpenGL))
|
||||
using (var surface = SKSurface.CreateAsRenderTarget(grContext, texture, SKColorType.Rgba8888))
|
||||
{
|
||||
Assert.NotNull(surface);
|
||||
|
||||
draw(surface, texture);
|
||||
}
|
||||
|
||||
// clean up
|
||||
ctx.DestroyTexture(textureInfo.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[Trait(Category, GpuCategory)]
|
||||
[SkippableFact]
|
||||
public void GpuBackendSurfaceIsCreated()
|
||||
|
@ -84,11 +111,56 @@ namespace SkiaSharp.Tests
|
|||
});
|
||||
}
|
||||
|
||||
[Trait(Category, GpuCategory)]
|
||||
[SkippableFact]
|
||||
[Obsolete]
|
||||
public void GpuTextureSurfaceIsCreatedWithDesc()
|
||||
{
|
||||
DrawGpuTextureWithDesc((surface, desc) =>
|
||||
{
|
||||
Assert.NotNull(surface);
|
||||
|
||||
var canvas = surface.Canvas;
|
||||
Assert.NotNull(canvas);
|
||||
|
||||
canvas.Clear(SKColors.Transparent);
|
||||
});
|
||||
}
|
||||
|
||||
[Trait(Category, GpuCategory)]
|
||||
[SkippableFact]
|
||||
[Obsolete]
|
||||
public void GpuTextureSurfaceCanBeReadWithDesc()
|
||||
{
|
||||
DrawGpuTextureWithDesc((surface, desc) =>
|
||||
{
|
||||
var canvas = surface.Canvas;
|
||||
|
||||
canvas.Clear(SKColors.Red);
|
||||
canvas.Flush();
|
||||
|
||||
using (var image = surface.Snapshot())
|
||||
{
|
||||
Assert.True(image.IsTextureBacked);
|
||||
|
||||
using (var raster = image.ToRasterImage())
|
||||
{
|
||||
Assert.False(raster.IsTextureBacked);
|
||||
|
||||
using (var bmp = SKBitmap.FromImage(raster))
|
||||
{
|
||||
Assert.Equal(SKColors.Red, bmp.GetPixel(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Trait(Category, GpuCategory)]
|
||||
[SkippableFact]
|
||||
public void GpuTextureSurfaceIsCreated()
|
||||
{
|
||||
DrawGpuTexture((surface, desc) =>
|
||||
DrawGpuTexture((surface, texture) =>
|
||||
{
|
||||
Assert.NotNull(surface);
|
||||
|
||||
|
@ -103,7 +175,7 @@ namespace SkiaSharp.Tests
|
|||
[SkippableFact]
|
||||
public void GpuTextureSurfaceCanBeRead()
|
||||
{
|
||||
DrawGpuTexture((surface, desc) =>
|
||||
DrawGpuTexture((surface, texture) =>
|
||||
{
|
||||
var canvas = surface.Canvas;
|
||||
|
||||
|
@ -134,7 +206,8 @@ namespace SkiaSharp.Tests
|
|||
{
|
||||
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
|
||||
|
||||
using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride))
|
||||
var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
|
||||
using (var surface = SKSurface.Create(info, data.Scan0, data.Stride))
|
||||
{
|
||||
Assert.NotNull(surface);
|
||||
|
||||
|
@ -168,7 +241,8 @@ namespace SkiaSharp.Tests
|
|||
{
|
||||
DrawBitmap((surface, data) =>
|
||||
{
|
||||
var surface2 = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride);
|
||||
var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
|
||||
var surface2 = SKSurface.Create(info, data.Scan0, data.Stride);
|
||||
|
||||
Assert.NotNull(surface2);
|
||||
|
||||
|
|
|
@ -88,23 +88,6 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void TestFontManagerMatchCharacter()
|
||||
{
|
||||
var fonts = SKFontManager.Default;
|
||||
var emoji = "🚀";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(emoji, SKTextEncoding.Utf32);
|
||||
using (var typeface = fonts.MatchCharacter(emojiChar))
|
||||
{
|
||||
if (IsLinux)
|
||||
Assert.Equal("Symbola", typeface.FamilyName);
|
||||
else if (IsMac)
|
||||
Assert.Equal("Apple Color Emoji", typeface.FamilyName);
|
||||
else if (IsWindows)
|
||||
Assert.Contains(typeface.FamilyName, new[] { "Segoe UI Emoji", "Segoe UI Symbol" });
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void ExceptionInInvalidGetTableData()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче