|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using System.Linq; |
| 6 | +using System.Numerics; |
6 | 7 | using System.Text; |
7 | 8 | using SixLabors.Fonts; |
8 | 9 | using SixLabors.ImageSharp.Drawing.Processing; |
@@ -158,6 +159,81 @@ public void FontShapesAreRenderedCorrectly<TPixel>( |
158 | 159 | appendSourceFileOrDescription: true); |
159 | 160 | } |
160 | 161 |
|
| 162 | + [Theory] |
| 163 | + [WithSolidFilledImages(50, 50, "White", PixelTypes.Rgba32, 50, 25, 25, "OpenSans-Regular.ttf", "i", 45, 25, 25)] |
| 164 | + [WithSolidFilledImages(200, 200, "White", PixelTypes.Rgba32, 50, 100, 100, "SixLaborsSampleAB.woff", AB, 45, 100, 100)] |
| 165 | + [WithSolidFilledImages(1100, 1100, "White", PixelTypes.Rgba32, 50, 550, 550, "OpenSans-Regular.ttf", TestText, 45, 550, 550)] |
| 166 | + [WithSolidFilledImages(400, 400, "White", PixelTypes.Rgba32, 20, 200, 200, "OpenSans-Regular.ttf", TestText, 45, 200, 200)] |
| 167 | + public void FontShapesAreRenderedCorrectly_WithRotationApplied<TPixel>( |
| 168 | + TestImageProvider<TPixel> provider, |
| 169 | + int fontSize, |
| 170 | + int x, |
| 171 | + int y, |
| 172 | + string fontName, |
| 173 | + string text, |
| 174 | + float angle, |
| 175 | + float rotationOriginX, |
| 176 | + float rotationOriginY) |
| 177 | + where TPixel : unmanaged, IPixel<TPixel> |
| 178 | + { |
| 179 | + Font font = CreateFont(fontName, fontSize); |
| 180 | + |
| 181 | + var radians = (float)Math.PI * angle / 180f; |
| 182 | + |
| 183 | + provider.RunValidatingProcessorTest( |
| 184 | + c => c |
| 185 | + .SetTextOptions(o => |
| 186 | + { |
| 187 | + o.HorizontalAlignment = HorizontalAlignment.Center; |
| 188 | + o.VerticalAlignment = VerticalAlignment.Center; |
| 189 | + o.Transform = Matrix3x2.CreateRotation(radians, new Vector2(rotationOriginX, rotationOriginY)); |
| 190 | + }) |
| 191 | + .DrawText(text, font, Color.Black, new PointF(x, y)), |
| 192 | + $"{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})", |
| 193 | + TextDrawingComparer, |
| 194 | + appendPixelTypeToFileName: false, |
| 195 | + appendSourceFileOrDescription: true); |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + [Theory] |
| 200 | + [WithSolidFilledImages(50, 50, "White", PixelTypes.Rgba32, 50, 25, 25, "OpenSans-Regular.ttf", "i", -12, 0, 25, 25)] |
| 201 | + [WithSolidFilledImages(200, 200, "White", PixelTypes.Rgba32, 50, 100, 100, "SixLaborsSampleAB.woff", AB, 10, 0, 100, 100)] |
| 202 | + [WithSolidFilledImages(1100, 1100, "White", PixelTypes.Rgba32, 50, 550, 550, "OpenSans-Regular.ttf", TestText, 0, 10, 550, 550)] |
| 203 | + [WithSolidFilledImages(400, 400, "White", PixelTypes.Rgba32, 20, 200, 200, "OpenSans-Regular.ttf", TestText, 0, -10, 200, 200)] |
| 204 | + public void FontShapesAreRenderedCorrectly_WithSkewApplied<TPixel>( |
| 205 | + TestImageProvider<TPixel> provider, |
| 206 | + int fontSize, |
| 207 | + int x, |
| 208 | + int y, |
| 209 | + string fontName, |
| 210 | + string text, |
| 211 | + float angleX, |
| 212 | + float angleY, |
| 213 | + float rotationOriginX, |
| 214 | + float rotationOriginY) |
| 215 | + where TPixel : unmanaged, IPixel<TPixel> |
| 216 | + { |
| 217 | + Font font = CreateFont(fontName, fontSize); |
| 218 | + |
| 219 | + var radianX = (float)Math.PI * angleX / 180f; |
| 220 | + var radianY = (float)Math.PI * angleY / 180f; |
| 221 | + |
| 222 | + provider.RunValidatingProcessorTest( |
| 223 | + c => c |
| 224 | + .SetTextOptions(o => |
| 225 | + { |
| 226 | + o.HorizontalAlignment = HorizontalAlignment.Center; |
| 227 | + o.VerticalAlignment = VerticalAlignment.Center; |
| 228 | + o.Transform = Matrix3x2.CreateSkew(radianX, radianY, new Vector2(rotationOriginX, rotationOriginY)); |
| 229 | + }) |
| 230 | + .DrawText(text, font, Color.Black, new PointF(x, y)), |
| 231 | + $"{fontName}-{fontSize}-{ToTestOutputDisplayText(text)}-({x},{y})", |
| 232 | + TextDrawingComparer, |
| 233 | + appendPixelTypeToFileName: false, |
| 234 | + appendSourceFileOrDescription: true); |
| 235 | + } |
| 236 | + |
161 | 237 | /// <summary> |
162 | 238 | /// Based on: |
163 | 239 | /// https://github.com/SixLabors/ImageSharp/issues/572 |
|
0 commit comments