|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 7 | +using SixLabors.ImageSharp.Drawing.Tests.TestUtilities.ImageComparison; |
| 8 | +using SixLabors.ImageSharp.PixelFormats; |
| 9 | +using SixLabors.ImageSharp.Processing; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace SixLabors.ImageSharp.Drawing.Tests.Issues |
| 13 | +{ |
| 14 | + public class Issue_175 |
| 15 | + { |
| 16 | + [Fact] |
| 17 | + public void CanRotateFilledFont() |
| 18 | + { |
| 19 | + if (!TestEnvironment.IsWindows) |
| 20 | + { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + using (var image = new Image<Rgba32>(300, 200)) |
| 25 | + { |
| 26 | + string text = "QuickTYZ"; |
| 27 | + int rotationAngle = 90; |
| 28 | + Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 40, Fonts.FontStyle.Regular); |
| 29 | + |
| 30 | + AffineTransformBuilder builder = new AffineTransformBuilder() |
| 31 | + .AppendRotationDegrees(rotationAngle) |
| 32 | + .AppendTranslation(new PointF(0, 0)); |
| 33 | + var drawingOptions = new DrawingOptions |
| 34 | + { |
| 35 | + Transform = builder.BuildMatrix(image.Bounds()) |
| 36 | + }; |
| 37 | + |
| 38 | + image.Mutate(c => c.DrawText(drawingOptions, text, font, Brushes.Solid(Color.Red), new PointF(0, 0))); |
| 39 | + |
| 40 | + // ensure the font renders the same as the test image |
| 41 | + IEnumerable<ImageSimilarityReport> reports = ExactImageComparer.Instance.CompareImages(Image.Load<Rgba32>(TestFile.GetInputFileFullPath(TestImages.Png.Issue175Filled)), image); |
| 42 | + Assert.False(reports.Any()); |
| 43 | + |
| 44 | + // image.SaveAsPng(@"./issue175_filled.png"); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void CanRotateOutlineFont() |
| 50 | + { |
| 51 | + if (!TestEnvironment.IsWindows) |
| 52 | + { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + using (var image = new Image<Rgba32>(300, 200)) |
| 57 | + { |
| 58 | + string text = "QuickTYZ"; |
| 59 | + int rotationAngle = 90; |
| 60 | + Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 40, Fonts.FontStyle.Regular); |
| 61 | + |
| 62 | + AffineTransformBuilder builder = new AffineTransformBuilder() |
| 63 | + .AppendRotationDegrees(rotationAngle) |
| 64 | + .AppendTranslation(new PointF(0, 0)); |
| 65 | + var drawingOptions = new DrawingOptions |
| 66 | + { |
| 67 | + Transform = builder.BuildMatrix(image.Bounds()) |
| 68 | + }; |
| 69 | + image.Mutate(c => c.DrawText(drawingOptions, text, font, Pens.Solid(Color.Blue, 1), new PointF(0, 0))); |
| 70 | + |
| 71 | + // ensure the font renders the same as the test image |
| 72 | + IEnumerable<ImageSimilarityReport> reports = ExactImageComparer.Instance.CompareImages(Image.Load<Rgba32>(TestFile.GetInputFileFullPath(TestImages.Png.Issue175Outlined)), image); |
| 73 | + Assert.False(reports.Any()); |
| 74 | + |
| 75 | + // image.SaveAsPng(@"./issue175_outlined.png"); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments