2 using System.Drawing;
\r
3 using System.Drawing.Drawing2D;
\r
4 using NUnit.Framework;
\r
5 using DrawingTestHelper;
\r
7 namespace Test.Sys.Drawing
\r
10 /// Summary description for Pen.
\r
13 public class PenFixture {
\r
14 //TODO: Brush, CompoundArray, CustomEndCap, CustomStartCap,
\r
15 //StartCap, EndCap, PenType, Transform
\r
19 public void SetUp () {
\r
20 t = DrawingTest.Create (256, 256);
\r
21 p = new Pen (Color.Blue);
\r
25 public void InitAlignment () {
\r
26 Pen p = new Pen (Color.Blue);
\r
27 Assert.AreEqual (PenAlignment.Center, p.Alignment);
\r
30 public void Width () {
\r
31 Assert.AreEqual (10, p.Width);
\r
32 t.Graphics.DrawLine (p, 0, 0, 64, 64);
\r
34 Assert.IsTrue (t.Compare (10));
\r
36 t.Graphics.DrawLine (p, 32, 0, 35, 64);
\r
38 Assert.IsTrue (t.Compare (10));
\r
40 t.Graphics.DrawLine (p, 0, 64, 64, 70);
\r
42 Assert.IsTrue (t.Compare (10));
\r
45 public void DashStyleTest () {
\r
46 Assert.AreEqual (DashStyle.Solid, p.DashStyle);
\r
47 t.Graphics.DrawLine (p, 0, 30, 256, 30);
\r
49 Assert.IsTrue (t.Compare (10));
\r
51 p.DashStyle = DashStyle.Dash;
\r
53 t.Graphics.DrawLine (p, 0, 600, 200, 60);
\r
55 Assert.IsTrue (t.Compare (10));
\r
57 p.DashStyle = DashStyle.DashDot;
\r
58 t.Graphics.FillRectangle (Brushes.Black, 0, 0, 256, 256);
\r
59 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
61 Assert.IsTrue (t.Compare (10));
\r
63 p.DashStyle = DashStyle.DashDotDot;
\r
64 t.Graphics.FillRectangle (Brushes.Black, 0, 0, 256, 256);
\r
65 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
67 Assert.IsTrue (t.Compare (10));
\r
69 p.DashStyle = DashStyle.Dot;
\r
70 t.Graphics.FillRectangle (Brushes.Black, 0, 0, 256, 256);
\r
71 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
73 Assert.IsTrue (t.Compare (10));
\r
75 p.DashStyle = DashStyle.Custom;
\r
76 t.Graphics.FillRectangle (Brushes.Black, 0, 0, 256, 256);
\r
77 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
79 Assert.IsTrue (t.Compare (10));
\r
81 //The following tests DashOffset and DashPattern
\r
83 public void DashCustomStyle () {
\r
84 p.DashStyle = DashStyle.Custom;
\r
86 Assert.AreEqual (new float [] {1F}, p.DashPattern);
\r
87 Assert.AreEqual (0F, p.DashOffset);
\r
89 p.DashPattern = new float [] {2, 3, 1.15F, 0.05F};
\r
90 t.Graphics.FillRectangle (Brushes.Black, 0, 0, 256, 256);
\r
91 t.Graphics.DrawLine (p, 0, 0, 200, 10);
\r
93 Assert.IsTrue (t.Compare (10));
\r
95 t.Graphics.DrawLine (p, 0, 50, 200, 50);
\r
97 Assert.IsTrue (t.Compare (10));
\r
98 p.DashPattern = new float [] {2, 3, 1.15F, 0.05F, 1.74321F};
\r
99 p.DashOffset = 10.2F;
\r
100 t.Graphics.DrawLine (p, 0, 100, 200, 90);
\r
102 Assert.IsTrue (t.Compare (10));
\r
103 p.DashPattern = new float [] {2, 3, 1.15F, 0.05F, 1.74321F};
\r
104 p.DashOffset = 10.2F;
\r
105 t.Graphics.DrawLine (p, 0, 100, 200, 90);
\r
107 Assert.IsTrue (t.Compare (10));
\r
110 public void DashCapTest () {
\r
111 Assert.AreEqual (DashCap.Flat, p.DashCap);
\r
112 p.DashStyle = DashStyle.DashDot;
\r
113 t.Graphics.DrawLine (p, 0, 0, 200, 10);
\r
115 Assert.IsTrue (t.Compare (10));
\r
117 p.DashCap = DashCap.Round;
\r
118 t.Graphics.DrawLine (p, 0, 50, 200, 61.7F);
\r
120 Assert.IsTrue (t.Compare (10));
\r
122 p.DashCap = DashCap.Triangle;
\r
123 t.Graphics.DrawLine (p, 0F, 92.3F, 200F, 117.9F);
\r
125 Assert.IsTrue (t.Compare (10));
\r
128 public void LineJoinTest () {
\r
129 Assert.AreEqual (LineJoin.Miter, p.LineJoin);
\r
130 Point [] points = new Point [] {
\r
131 new Point(40, 10), new Point (200, 11),
\r
132 new Point (100, 40)};
\r
133 t.Graphics.DrawPolygon (p, points);
\r
134 t.Graphics.DrawPolygon (Pens.White, points);
\r
136 Assert.IsTrue (t.Compare (10));
\r
138 p.LineJoin = LineJoin.Bevel;
\r
139 points =new Point [] {
\r
140 new Point(40, 70), new Point (200, 79),
\r
141 new Point (100, 100)};
\r
142 t.Graphics.DrawPolygon (p, points);
\r
143 t.Graphics.DrawPolygon (Pens.White, points);
\r
145 Assert.IsTrue (t.Compare (35));
\r
147 p.LineJoin = LineJoin.MiterClipped;
\r
148 points = new Point [] {
\r
149 new Point(40, 120), new Point (200, 117),
\r
150 new Point (80, 135)};
\r
151 t.Graphics.DrawPolygon (p, points);
\r
152 t.Graphics.DrawPolygon (Pens.White, points);
\r
154 Assert.IsTrue (t.Compare (50));
\r
156 p.LineJoin = LineJoin.Round;
\r
157 points = new Point [] {
\r
158 new Point(40, 170), new Point (200, 175),
\r
159 new Point (100, 210)};
\r
160 t.Graphics.DrawPolygon (p, points);
\r
161 t.Graphics.DrawPolygon (Pens.White, points);
\r
163 Assert.IsTrue (t.Compare (60));
\r
166 public void LineJoinTest_Miter () {
\r
167 p.LineJoin = LineJoin.Miter;
\r
168 Point [] points = new Point [] {
\r
169 new Point(200, 217), new Point (215, 55),
\r
170 new Point (230, 217)};
\r
171 t.Graphics.DrawLines (p, points);
\r
172 t.Graphics.DrawLines (Pens.White, points);
\r
174 Assert.IsTrue (t.Compare (10));
\r
176 p.LineJoin = LineJoin.Miter;
\r
177 points = new Point [] {
\r
178 new Point(140, 217), new Point (155, 75),
\r
179 new Point (170, 217)};
\r
180 t.Graphics.DrawLines (p, points);
\r
181 t.Graphics.DrawLines (Pens.White, points);
\r
183 Assert.IsTrue (t.Compare (10));
\r
185 p.LineJoin = LineJoin.Miter;
\r
186 points = new Point [] {
\r
187 new Point(100, 217), new Point (105, 100),
\r
188 new Point (110, 217)};
\r
189 t.Graphics.DrawLines (p, points);
\r
190 t.Graphics.DrawLines (Pens.White, points);
\r
192 Assert.IsTrue (t.Compare (10));
\r
194 p.LineJoin = LineJoin.Miter;
\r
195 points = new Point [] {
\r
196 new Point(43, 210), new Point (70, 100),
\r
197 new Point (80, 20)};
\r
198 t.Graphics.DrawLines (p, points);
\r
199 t.Graphics.DrawLines (Pens.White, points);
\r
201 Assert.IsTrue (t.Compare (10));
\r
204 public void LineJoinTest_MiterClipped () {
\r
205 p.LineJoin = LineJoin.MiterClipped;
\r
206 Point [] points = new Point [] {
\r
207 new Point(200, 217), new Point (215, 55),
\r
208 new Point (230, 217)};
\r
209 t.Graphics.DrawLines (p, points);
\r
210 t.Graphics.DrawLines (Pens.White, points);
\r
212 Assert.IsTrue (t.Compare (10));
\r
214 p.LineJoin = LineJoin.MiterClipped;
\r
215 points = new Point [] {
\r
216 new Point(140, 217), new Point (155, 75),
\r
217 new Point (170, 217)};
\r
218 t.Graphics.DrawLines (p, points);
\r
219 t.Graphics.DrawLines (Pens.White, points);
\r
221 Assert.IsTrue (t.Compare (10));
\r
223 p.LineJoin = LineJoin.MiterClipped;
\r
224 points = new Point [] {
\r
225 new Point(100, 217), new Point (105, 100),
\r
226 new Point (110, 217)};
\r
227 t.Graphics.DrawLines (p, points);
\r
228 t.Graphics.DrawLines (Pens.White, points);
\r
230 Assert.IsTrue (t.Compare (10));
\r
232 p.LineJoin = LineJoin.MiterClipped;
\r
233 points = new Point [] {
\r
234 new Point(43, 210), new Point (70, 100),
\r
235 new Point (80, 20)};
\r
236 t.Graphics.DrawLines (p, points);
\r
237 t.Graphics.DrawLines (Pens.White, points);
\r
239 Assert.IsTrue (t.Compare (10));
\r
242 public void LineJoinTest_Bevel () {
\r
243 p.LineJoin = LineJoin.Bevel;
\r
244 Point [] points = new Point [] {
\r
245 new Point(200, 217), new Point (215, 55),
\r
246 new Point (230, 217)};
\r
247 t.Graphics.DrawLines (p, points);
\r
248 t.Graphics.DrawLines (Pens.White, points);
\r
250 Assert.IsTrue (t.Compare (10));
\r
252 p.LineJoin = LineJoin.Bevel;
\r
253 points = new Point [] {
\r
254 new Point(140, 217), new Point (155, 75),
\r
255 new Point (170, 217)};
\r
256 t.Graphics.DrawLines (p, points);
\r
257 t.Graphics.DrawLines (Pens.White, points);
\r
259 Assert.IsTrue (t.Compare (10));
\r
261 p.LineJoin = LineJoin.Bevel;
\r
262 points = new Point [] {
\r
263 new Point(100, 217), new Point (105, 100),
\r
264 new Point (110, 217)};
\r
265 t.Graphics.DrawLines (p, points);
\r
266 t.Graphics.DrawLines (Pens.White, points);
\r
268 Assert.IsTrue (t.Compare (10));
\r
270 p.LineJoin = LineJoin.Bevel;
\r
271 points = new Point [] {
\r
272 new Point(43, 210), new Point (70, 100),
\r
273 new Point (80, 20)};
\r
274 t.Graphics.DrawLines (p, points);
\r
275 t.Graphics.DrawLines (Pens.White, points);
\r
277 Assert.IsTrue (t.Compare (10));
\r
279 p.LineJoin = LineJoin.Bevel;
\r
280 points = new Point [] {
\r
281 new Point(100, 50), new Point (150, 50),
\r
282 new Point (150, 20), new Point (200, 20)};
\r
283 t.Graphics.DrawLines (p, points);
\r
284 t.Graphics.DrawLines (Pens.White, points);
\r
286 Assert.IsTrue (t.Compare (10));
\r
289 public void PenAlignmentTest () {
\r
290 Point [] points = new Point [] {
\r
291 new Point (20, 20), new Point (40, 40), new Point (60, 20),
\r
292 new Point (60, 60), new Point (20, 60)};
\r
293 GraphicsPath path = new GraphicsPath ();
\r
294 path.AddPolygon (points);
\r
295 Matrix mx = new Matrix (1, 0, 0, 1, 90, 0);
\r
296 Matrix mrx = new Matrix (1, 0, 0, 1, -180, 0);
\r
297 Matrix my = new Matrix (1, 0, 0, 1, 0, 100);
\r
299 Assert.AreEqual (PenAlignment.Center, p.Alignment);
\r
300 t.Graphics.DrawPath (p, path);
\r
301 t.Graphics.DrawPath (Pens.White, path);
\r
303 Assert.IsTrue (t.Compare (10));
\r
305 p.Alignment = PenAlignment.Left;
\r
306 path.Transform (mx);
\r
307 t.Graphics.DrawPath (p, path);
\r
308 t.Graphics.DrawPath (Pens.White, path);
\r
310 Assert.IsTrue (t.Compare (10));
\r
312 p.Alignment = PenAlignment.Inset;
\r
313 path.Transform (mx);
\r
314 t.Graphics.DrawPath (p, path);
\r
315 t.Graphics.DrawPath (Pens.White, path);
\r
317 Assert.IsTrue (t.Compare (10));
\r
319 p.Alignment = PenAlignment.Outset;
\r
320 path.Transform (mrx);
\r
321 path.Transform (my);
\r
322 t.Graphics.DrawPath (p, path);
\r
323 t.Graphics.DrawPath (Pens.White, path);
\r
325 Assert.IsTrue (t.Compare (10));
\r
327 p.Alignment = PenAlignment.Right;
\r
328 path.Transform (mx);
\r
329 t.Graphics.DrawPath (p, path);
\r
330 t.Graphics.DrawPath (Pens.White, path);
\r
332 Assert.IsTrue (t.Compare (10));
\r
335 public void ColorTest () {
\r
336 Assert.AreEqual (Color.Blue, p.Color);
\r
337 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
339 Assert.IsTrue (t.Compare (10));
\r
341 p.Color = Color.Red;
\r
342 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
344 Assert.IsTrue (t.Compare (10));
\r
346 p.Color = Color.BurlyWood;
\r
347 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
349 Assert.IsTrue (t.Compare (10));
\r
351 p.Color = Color.FromArgb (100, 120, 255);
\r
352 t.Graphics.DrawLine (p, 0, 0, 200, 200);
\r
354 Assert.IsTrue (t.Compare (10));
\r
356 p.Color = Color.FromArgb (128, Color.White);
\r
357 t.Graphics.DrawLine (p, 0, 200, 200, 0);
\r
359 Assert.IsTrue (t.Compare (10));
\r
362 public void MitterLimit () {
\r
363 p.LineJoin = LineJoin.MiterClipped;
\r
364 Point [] points = new Point [] {new Point (0,30), new Point (180, 31),
\r
365 new Point (0, 90)};
\r
367 Assert.AreEqual (10F, p.MiterLimit);
\r
368 t.Graphics.DrawLines (p, points);
\r
369 t.Graphics.DrawLines (Pens.White, points);
\r
371 Assert.IsTrue (t.Compare (10));
\r
373 Matrix dy = new Matrix (1, 0, 0, 1, 0, 110);
\r
374 dy.TransformPoints (points);
\r
376 t.Graphics.DrawLines (p, points);
\r
377 t.Graphics.DrawLines (Pens.White, points);
\r
379 Assert.IsTrue (t.Compare (10));
\r
382 public void Transform () {
\r
383 p.ScaleTransform (0.5F, 2);
\r
384 t.Graphics.DrawArc (p, 0, 0, 100, 100, 0, 360);
\r
385 t.Graphics.DrawArc (Pens.White, 0, 0, 100, 100, 0, 360);
\r
389 [Category ("Extended")]
\r
390 public void StartCap() {
\r
391 Assert.AreEqual(LineCap.Flat, p.StartCap);
\r
395 p.StartCap = LineCap.Flat;
\r
396 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
397 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
399 Assert.IsTrue (t.Compare (10));
\r
402 p.StartCap = LineCap.Round;
\r
403 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
404 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
406 Assert.IsTrue (t.Compare (10));
\r
409 p.StartCap = LineCap.Square;
\r
410 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
411 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
413 Assert.IsTrue (t.Compare (10));
\r
416 p.StartCap = LineCap.AnchorMask;
\r
417 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
418 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
420 Assert.IsTrue (t.Compare (10));
\r
423 p.StartCap = LineCap.ArrowAnchor;
\r
424 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
425 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
427 Assert.IsTrue (t.Compare (10));
\r
430 p.StartCap = LineCap.DiamondAnchor;
\r
431 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
432 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
434 Assert.IsTrue (t.Compare (10));
\r
437 p.StartCap = LineCap.NoAnchor;
\r
438 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
439 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
441 Assert.IsTrue (t.Compare (10));
\r
446 p.StartCap = LineCap.RoundAnchor;
\r
447 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
448 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
450 Assert.IsTrue (t.Compare (10));
\r
453 p.StartCap = LineCap.SquareAnchor;
\r
454 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
455 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
457 Assert.IsTrue (t.Compare (10));
\r
460 p.StartCap = LineCap.Triangle;
\r
461 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
462 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
464 Assert.IsTrue (t.Compare (10));
\r
467 p.StartCap = LineCap.Custom;
\r
468 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
469 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
471 Assert.IsTrue (t.Compare (10));
\r
475 [Category ("Extended")]
\r
476 public void EndCap() {
\r
477 Assert.AreEqual(LineCap.Flat, p.EndCap);
\r
481 p.EndCap = LineCap.Flat;
\r
482 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
483 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
485 Assert.IsTrue (t.Compare (10));
\r
488 p.EndCap = LineCap.Round;
\r
489 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
490 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
492 Assert.IsTrue (t.Compare (10));
\r
495 p.EndCap = LineCap.Square;
\r
496 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
497 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
499 Assert.IsTrue (t.Compare (10));
\r
502 p.EndCap = LineCap.AnchorMask;
\r
503 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
504 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
506 Assert.IsTrue (t.Compare (10));
\r
509 p.EndCap = LineCap.ArrowAnchor;
\r
510 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
511 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
513 Assert.IsTrue (t.Compare (10));
\r
516 p.EndCap = LineCap.DiamondAnchor;
\r
517 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
518 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
520 Assert.IsTrue (t.Compare (10));
\r
523 p.EndCap = LineCap.NoAnchor;
\r
524 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
525 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
527 Assert.IsTrue (t.Compare (10));
\r
532 p.EndCap = LineCap.RoundAnchor;
\r
533 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
534 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
536 Assert.IsTrue (t.Compare (10));
\r
539 p.EndCap = LineCap.SquareAnchor;
\r
540 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
541 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
543 Assert.IsTrue (t.Compare (10));
\r
546 p.EndCap = LineCap.Triangle;
\r
547 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
548 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
550 Assert.IsTrue (t.Compare (10));
\r
553 p.EndCap = LineCap.Custom;
\r
554 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
555 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
557 Assert.IsTrue (t.Compare (10));
\r
561 public void StartEndCapBasic() {
\r
562 Assert.AreEqual(LineCap.Flat, p.StartCap);
\r
568 p.EndCap = LineCap.Flat;
\r
569 p.StartCap = LineCap.Flat;
\r
570 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
571 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
573 Assert.IsTrue (t.Compare (10));
\r
576 p.EndCap = LineCap.Round;
\r
577 p.StartCap = LineCap.Round;
\r
578 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
579 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
581 Assert.IsTrue (t.Compare (40));
\r
584 p.EndCap = LineCap.Square;
\r
585 p.StartCap = LineCap.Square;
\r
586 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
587 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
589 Assert.IsTrue (t.Compare (50));
\r
592 p.EndCap = LineCap.Round;
\r
593 p.StartCap = LineCap.Round;
\r
594 p.DashCap = DashCap.Round;
\r
596 p.DashStyle = DashStyle.DashDotDot;
\r
597 t.Graphics.DrawLine (p, x, y, x+200, y);
\r
598 t.Graphics.DrawLine (Pens.White, x, y, x+200, y);
\r
600 Assert.IsTrue (t.Compare (10));
\r
603 public void SetLineCap() {
\r
604 Assert.AreEqual(LineCap.Flat, p.StartCap);
\r
610 p.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat);
\r
611 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
612 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
614 Assert.IsTrue (t.Compare (10));
\r
617 p.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
\r
618 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
619 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
621 Assert.IsTrue (t.Compare (10));
\r
624 p.SetLineCap(LineCap.Square, LineCap.Square, DashCap.Flat);
\r
625 t.Graphics.DrawLine (p, x, y, x+80, y);
\r
626 t.Graphics.DrawLine (Pens.White, x, y, x+80, y);
\r
628 Assert.IsTrue (t.Compare (10));
\r