|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | +using SixLabors.Fonts; |
| 4 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 5 | +using SixLabors.ImageSharp.Drawing.Tests.TestUtilities.Attributes; |
| 6 | +using SixLabors.ImageSharp.PixelFormats; |
| 7 | +using SixLabors.ImageSharp.Processing; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace SixLabors.ImageSharp.Drawing.Tests.Issues |
| 11 | +{ |
| 12 | + public class Issue_54 |
| 13 | + { |
| 14 | + [WindowsFact] |
| 15 | + public void CanDrawWithoutMemoryException() |
| 16 | + { |
| 17 | + int width = 768; |
| 18 | + int height = 438; |
| 19 | + |
| 20 | + // Creates a new image with empty pixel data. |
| 21 | + using (var image = new Image<Rgba32>(width, height)) |
| 22 | + { |
| 23 | + FontFamily family = SystemFonts.Find("verdana"); |
| 24 | + Font font = family.CreateFont(48, FontStyle.Bold); |
| 25 | + |
| 26 | + // The options are optional |
| 27 | + TextGraphicsOptions options = new TextGraphicsOptions() |
| 28 | + { |
| 29 | + TextOptions = new TextOptions() |
| 30 | + { |
| 31 | + ApplyKerning = true, |
| 32 | + TabWidth = 8, // a tab renders as 8 spaces wide |
| 33 | + WrapTextWidth = width, // greater than zero so we will word wrap at 100 pixels wide |
| 34 | + HorizontalAlignment = HorizontalAlignment.Center // right align |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + IBrush brush = Brushes.Solid(Color.White); |
| 39 | + IPen pen = Pens.Solid(Color.White, 1); |
| 40 | + string text = "sample text"; |
| 41 | + |
| 42 | + // Draw the text |
| 43 | + image.Mutate(x => x.DrawText(options, text, font, brush, pen, new PointF(0, 100))); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void PenMustHaveAWidthGraterThanZero() |
| 49 | + { |
| 50 | + ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => |
| 51 | + { |
| 52 | + IPen pen = new Pen(Color.White, 0); |
| 53 | + }); |
| 54 | + |
| 55 | + Assert.StartsWith("Parameter \"width\" (System.Single) must be greater than 0, was 0", ex.Message); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void ComplexPolygoWithZeroPathsCausesBoundsToBeNonSensicalValue() |
| 61 | + { |
| 62 | + var polygon = new ComplexPolygon(Array.Empty<IPath>()); |
| 63 | + |
| 64 | + Assert.NotEqual(float.NegativeInfinity, polygon.Bounds.Width); |
| 65 | + Assert.NotEqual(float.PositiveInfinity, polygon.Bounds.Width); |
| 66 | + Assert.NotEqual(float.NaN, polygon.Bounds.Width); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments