internal static void CheckExpectedImage(TextPrimitive primitive, int width, int height, Rect contentRect, string expectedImageFilePath) { byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var textMesh = new TextMesh(); primitiveRenderer.DrawTextPrimitive(textMesh, primitive, contentRect, new StyleRuleSet(), Vector.Zero); context.Clear(); context.DrawTextMesh(textMesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
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); }