1+ using System ;
12using SixLabors . Fonts ;
23using SixLabors . ImageSharp . Drawing . Processing ;
34using SixLabors . ImageSharp . PixelFormats ;
@@ -17,33 +18,50 @@ public void CanDrawWithoutMemoryException()
1718 // Creates a new image with empty pixel data.
1819 using ( var image = new Image < Rgba32 > ( width , height ) )
1920 {
20- {
21- FontCollection collection = new FontCollection ( ) ;
22- FontFamily family = collection . Install ( @"C:\Windows\Fonts\verdana.ttf" ) ;
23- Font font = family . CreateFont ( 48 , FontStyle . Bold ) ;
21+ FontFamily family = SystemFonts . Find ( "verdana" ) ;
22+ Font font = family . CreateFont ( 48 , FontStyle . Bold ) ;
2423
25- // The options are optional
26- TextGraphicsOptions options = new TextGraphicsOptions ( )
24+ // The options are optional
25+ TextGraphicsOptions options = new TextGraphicsOptions ( )
26+ {
27+ TextOptions = new TextOptions ( )
2728 {
28- TextOptions = new TextOptions ( )
29- {
30- ApplyKerning = true ,
31- TabWidth = 8 , // a tab renders as 8 spaces wide
32- WrapTextWidth = width , // greater than zero so we will word wrap at 100 pixels wide
33- HorizontalAlignment = HorizontalAlignment . Center // right align
34- }
35- } ;
36-
37- IBrush brush = Brushes . Solid ( Color . White ) ;
38- //IPen pen = Pens.DashDot(Color.White, 0); //0 makes application freeze and eat memory
39- IPen pen = Pens . Solid ( Color . White , 0 ) ; //0 makes application crash
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- } // Dispose - releasing memory into a memory pool ready for the next image you wish to process.
29+ ApplyKerning = true ,
30+ TabWidth = 8 , // a tab renders as 8 spaces wide
31+ WrapTextWidth = width , // greater than zero so we will word wrap at 100 pixels wide
32+ HorizontalAlignment = HorizontalAlignment . Center // right align
33+ }
34+ } ;
35+
36+ IBrush brush = Brushes . Solid ( Color . White ) ;
37+ IPen pen = Pens . Solid ( Color . White , 1 ) ;
38+ string text = "sample text" ;
39+
40+ // Draw the text
41+ image . Mutate ( x => x . DrawText ( options , text , font , brush , pen , new PointF ( 0 , 100 ) ) ) ;
42+ }
43+ }
44+
45+ [ Fact ]
46+ public void PenMustHaveAWidthGraterThanZero ( )
47+ {
48+ ArgumentOutOfRangeException ex = Assert . Throws < ArgumentOutOfRangeException > ( ( ) =>
49+ {
50+ IPen pen = new Pen ( Color . White , 0 ) ;
51+ } ) ;
52+
53+ Assert . Equal ( "Parameter \" width\" (System.Single) must be greater than 0, was 0 (Parameter 'width')" , ex . Message ) ;
54+ }
55+
56+
57+ [ Fact ]
58+ public void ComplexPolygoWithZeroPathsCausesBoundsToBeNonSensicalValue ( )
59+ {
60+ var polygon = new ComplexPolygon ( Array . Empty < IPath > ( ) ) ;
61+
62+ Assert . NotEqual ( float . NegativeInfinity , polygon . Bounds . Width ) ;
63+ Assert . NotEqual ( float . PositiveInfinity , polygon . Bounds . Width ) ;
64+ Assert . NotEqual ( float . NaN , polygon . Bounds . Width ) ;
4765 }
4866 }
4967}
0 commit comments