internal static void CheckExpectedImage(PathPrimitive primitive, int width, int height, string expectedImageFilePath) { byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); primitiveRenderer.DrawPathPrimitive(mesh, primitive, Vector.Zero); context.Clear(); context.DrawShapeMesh(mesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
public void DrawBoxModelWithImageContent() { byte[] imageRawBytes; int width, height; using (var context = new RenderContextForTest(500, 500)) { var primitive = new ImagePrimitive(@"assets\images\logo.png"); var ruleSet = new StyleRuleSet(); var styleSetBuilder = new StyleRuleSetBuilder(ruleSet); styleSetBuilder .BackgroundColor(Color.White) .Border((top: 1, right: 3, bottom: 1, left: 3)) .BorderColor(Color.LightBlue) .Padding((10, 5, 10, 5)); BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var imageMesh = new Mesh(); imageMesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetImageMesh(imageMesh); primitiveRenderer.DrawBoxModel(primitive, new Rect(10, 10, 300, 400), ruleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawImageMesh(imageMesh); imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithImageContent.png"; #if GenerateExpectedImages Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath);//generate expected image #else var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #endif }
public void DrawBoxModelWithTextContent() { byte[] imageRawBytes; int width, height; using (var context = new RenderContextForTest(400, 100)) { TextPrimitive textPrimitive = new TextPrimitive("Hello你好こんにちは"); var styleRuleSet = new StyleRuleSet(); var styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet); styleRuleSetBuilder .BackgroundColor(Color.White) .Border((1, 3, 1, 3)) .BorderColor(Color.Black) .Padding((10, 5, 10, 5)) .FontSize(24) .FontColor(Color.Black); BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var textMesh = new TextMesh(); primitiveRenderer.SetTextMesh(textMesh); primitiveRenderer.DrawBoxModel(textPrimitive, new Rect(10, 10, 350, 60), styleRuleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawTextMesh(textMesh); imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithTextContent.png"; #if GenerateExpectedImages Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath);//generate expected image #else var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #endif }
public void DrawBoxModelWithTextContent() { TextPrimitive textPrimitive = new TextPrimitive("Hello你好こんにちは"); var styleRuleSet = new StyleRuleSet(); var styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet); styleRuleSetBuilder .BackgroundColor(Color.White) .Border((1, 3, 1, 3)) .BorderColor(Color.Black) .Padding((10, 5, 10, 5)) .FontSize(24) .FontColor(Color.Black); var rect = new Rect(10, 10, 350, 60); const string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithTextContent.png"; const int width = 400, height = 100; byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var textMesh = new TextMesh(); primitiveRenderer.SetTextMesh(textMesh); var imageMesh = new Mesh(); primitiveRenderer.SetImageMesh(imageMesh); primitiveRenderer.DrawBoxModel(textPrimitive, rect, styleRuleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawTextMesh(textMesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
public void DrawBoxModelWithImageContent() { var primitive = new ImagePrimitive(@"assets\images\logo.png"); var ruleSet = new StyleRuleSet(); var styleSetBuilder = new StyleRuleSetBuilder(ruleSet); styleSetBuilder .BackgroundColor(Color.White) .Border((top: 1, right: 3, bottom: 1, left: 3)) .BorderColor(Color.LightBlue) .Padding((10, 5, 10, 5)); var rect = new Rect(10, 10, 300, 400); const string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithImageContent.png"; const int width = 500, height = 500; byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var imageMesh = new Mesh(); primitiveRenderer.SetImageMesh(imageMesh); primitiveRenderer.DrawBoxModel(primitive, rect, ruleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawImageMesh(imageMesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }