|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System.Numerics; |
| 5 | +using SixLabors.Fonts; |
| 6 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 7 | +using SixLabors.ImageSharp.PixelFormats; |
| 8 | +using SixLabors.ImageSharp.Processing; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace SixLabors.ImageSharp.Drawing.Tests.Issues |
| 12 | +{ |
| 13 | + public class Issue_270 |
| 14 | + { |
| 15 | + [Fact] |
| 16 | + public void DoesNotThrowArgumentOutOfRangeException() |
| 17 | + { |
| 18 | + if (!TestEnvironment.IsWindows) |
| 19 | + { |
| 20 | + return; |
| 21 | + } |
| 22 | + |
| 23 | + const int sourceImageWidth = 256; |
| 24 | + const int sourceImageHeight = 256; |
| 25 | + const int targetImageWidth = 350; |
| 26 | + const int targetImageHeight = 350; |
| 27 | + const float minimumCrashingFontSize = 47; |
| 28 | + const string text = "Hello, World!"; |
| 29 | + |
| 30 | + Font font = SystemFonts.CreateFont("Arial", minimumCrashingFontSize); |
| 31 | + Pen pen = Pens.Solid(Color.Black, 1); |
| 32 | + |
| 33 | + using Image<Rgba32> targetImage = new(targetImageWidth, targetImageHeight, Color.Wheat); |
| 34 | + using Image<Rgba32> imageBrushImage = new(sourceImageWidth, sourceImageHeight, Color.Black); |
| 35 | + ImageBrush imageBrush = new(imageBrushImage); |
| 36 | + |
| 37 | + targetImage.Mutate(x => x.DrawText(CreateTextOptions(font, targetImageWidth), text, imageBrush, pen)); |
| 38 | + } |
| 39 | + |
| 40 | + private static RichTextOptions CreateTextOptions(Font font, int wrappingLength) |
| 41 | + => new(font) |
| 42 | + { |
| 43 | + Origin = new Vector2(175, 175), |
| 44 | + TextAlignment = TextAlignment.Center, |
| 45 | + LayoutMode = LayoutMode.HorizontalTopBottom, |
| 46 | + WrappingLength = wrappingLength, |
| 47 | + WordBreaking = WordBreaking.Standard, |
| 48 | + HorizontalAlignment = HorizontalAlignment.Center, |
| 49 | + VerticalAlignment = VerticalAlignment.Center, |
| 50 | + KerningMode = KerningMode.None, |
| 51 | + }; |
| 52 | + } |
| 53 | +} |
0 commit comments