2 // Graphics class testing unit
5 // Jordi Mas, jordi@ximian.com
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005-2008 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Text;
37 using System.Reflection;
38 using System.Security.Permissions;
40 namespace MonoTests.System.Drawing {
43 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
44 public class GraphicsTest {
46 private RectangleF[] rects;
50 public void FixtureSetUp ()
53 font = new Font ("Arial", 12);
60 public void FixtureTearDown ()
67 private bool IsEmptyBitmap (Bitmap bitmap, out int x, out int y)
70 int empty = Color.Empty.ToArgb ();
72 for (y = 0; y < bitmap.Height; y++) {
73 for (x = 0; x < bitmap.Width; x++) {
74 if (bitmap.GetPixel (x, y).ToArgb () != empty) {
83 for (y = 0; y < bitmap.Height; y++) {
84 for (x = 0; x < bitmap.Width; x++) {
85 if (bitmap.GetPixel (x, y).ToArgb () != empty)
95 private void CheckForEmptyBitmap (Bitmap bitmap)
98 if (!IsEmptyBitmap (bitmap, out x, out y))
99 Assert.Fail (String.Format ("Position {0},{1}", x, y));
102 private void CheckForNonEmptyBitmap (Bitmap bitmap)
105 if (IsEmptyBitmap (bitmap, out x, out y))
106 Assert.Fail ("Bitmap was empty");
109 private void AssertEquals (string msg, object expected, object actual)
111 Assert.AreEqual (expected, actual, msg);
114 private void AssertEquals (string msg, double expected, double actual, double delta)
116 Assert.AreEqual (expected, actual, delta, msg);
120 public void DefaultProperties ()
122 Bitmap bmp = new Bitmap (200, 200);
123 Graphics g = Graphics.FromImage (bmp);
124 Region r = new Region ();
126 Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "DefaultProperties1");
127 Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "DefaultProperties2");
128 Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "DefaultProperties3");
129 Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "DefaultProperties4");
130 Assert.AreEqual (1, g.PageScale, "DefaultProperties5");
131 Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "DefaultProperties6");
132 Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "DefaultProperties7");
133 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "DefaultProperties8");
134 Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "DefaultProperties9");
135 Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "DefaultProperties10");
141 public void SetGetProperties ()
143 Bitmap bmp = new Bitmap (200, 200);
144 Graphics g = Graphics.FromImage (bmp);
146 g.CompositingMode = CompositingMode.SourceCopy;
147 g.CompositingQuality = CompositingQuality.GammaCorrected;
148 g.InterpolationMode = InterpolationMode.HighQualityBilinear;
150 g.PageUnit = GraphicsUnit.Inch;
151 g.PixelOffsetMode = PixelOffsetMode.Half;
152 g.RenderingOrigin = new Point (10, 20);
153 g.SmoothingMode = SmoothingMode.AntiAlias;
154 g.TextRenderingHint = TextRenderingHint.SystemDefault;
156 //Clipping set/get tested in clipping functions
157 Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetGetProperties2");
158 Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetGetProperties3");
159 Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetGetProperties4");
160 Assert.AreEqual (2, g.PageScale, "SetGetProperties5");
161 Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetGetProperties6");
162 Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetGetProperties7");
163 Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetGetProperties8");
164 Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetGetProperties9");
165 Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetGetProperties10");
173 Bitmap bmp = new Bitmap (200, 200);
174 Graphics g = Graphics.FromImage (bmp);
175 g.Clip = new Region (new Rectangle (50, 40, 210, 220));
176 rects = g.Clip.GetRegionScans (new Matrix ());
178 Assert.AreEqual (1, rects.Length, "Clip1");
179 Assert.AreEqual (50, rects[0].X, "Clip2");
180 Assert.AreEqual (40, rects[0].Y, "Clip3");
181 Assert.AreEqual (210, rects[0].Width, "Clip4");
182 Assert.AreEqual (220, rects[0].Height, "Clip5");
186 public void Clip_NotAReference ()
188 Bitmap bmp = new Bitmap (200, 200);
189 Graphics g = Graphics.FromImage (bmp);
190 Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
192 Assert.IsFalse (g.Clip.IsEmpty (g), "!IsEmpty");
193 Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite-2");
197 public void ExcludeClip ()
199 Bitmap bmp = new Bitmap (200, 200);
200 Graphics g = Graphics.FromImage (bmp);
202 g.Clip = new Region (new RectangleF (10, 10, 100, 100));
203 g.ExcludeClip (new Rectangle (40, 60, 100, 20));
204 rects = g.Clip.GetRegionScans (new Matrix ());
206 Assert.AreEqual (3, rects.Length, "ExcludeClip1");
208 Assert.AreEqual (10, rects[0].X, "ExcludeClip2");
209 Assert.AreEqual (10, rects[0].Y, "ExcludeClip3");
210 Assert.AreEqual (100, rects[0].Width, "ExcludeClip4");
211 Assert.AreEqual (50, rects[0].Height, "ExcludeClip5");
213 Assert.AreEqual (10, rects[1].X, "ExcludeClip6");
214 Assert.AreEqual (60, rects[1].Y, "ExcludeClip7");
215 Assert.AreEqual (30, rects[1].Width, "ExcludeClip8");
216 Assert.AreEqual (20, rects[1].Height, "ExcludeClip9");
218 Assert.AreEqual (10, rects[2].X, "ExcludeClip10");
219 Assert.AreEqual (80, rects[2].Y, "ExcludeClip11");
220 Assert.AreEqual (100, rects[2].Width, "ExcludeClip12");
221 Assert.AreEqual (30, rects[2].Height, "ExcludeClip13");
225 public void IntersectClip ()
227 Bitmap bmp = new Bitmap (200, 200);
228 Graphics g = Graphics.FromImage (bmp);
230 g.Clip = new Region (new RectangleF (260, 30, 60, 80));
231 g.IntersectClip (new Rectangle (290, 40, 60, 80));
232 rects = g.Clip.GetRegionScans (new Matrix ());
234 Assert.AreEqual (1, rects.Length, "IntersectClip");
236 Assert.AreEqual (290, rects[0].X, "IntersectClip");
237 Assert.AreEqual (40, rects[0].Y, "IntersectClip");
238 Assert.AreEqual (30, rects[0].Width, "IntersectClip");
239 Assert.AreEqual (70, rects[0].Height, "IntersectClip");
243 public void ResetClip ()
245 Bitmap bmp = new Bitmap (200, 200);
246 Graphics g = Graphics.FromImage (bmp);
248 g.Clip = new Region (new RectangleF (260, 30, 60, 80));
249 g.IntersectClip (new Rectangle (290, 40, 60, 80));
251 rects = g.Clip.GetRegionScans (new Matrix ());
253 Assert.AreEqual (1, rects.Length, "ResetClip");
255 Assert.AreEqual (-4194304, rects[0].X, "ResetClip");
256 Assert.AreEqual (-4194304, rects[0].Y, "ResetClip");
257 Assert.AreEqual (8388608, rects[0].Width, "ResetClip");
258 Assert.AreEqual (8388608, rects[0].Height, "ResetClip");
262 public void SetClip ()
265 Bitmap bmp = new Bitmap (200, 200);
266 Graphics g = Graphics.FromImage (bmp);
269 g.SetClip (new Region (new Rectangle (50, 40, 210, 220)), CombineMode.Replace);
270 rects = g.Clip.GetRegionScans (new Matrix ());
271 Assert.AreEqual (1, rects.Length, "SetClip1");
272 Assert.AreEqual (50, rects[0].X, "SetClip2");
273 Assert.AreEqual (40, rects[0].Y, "SetClip3");
274 Assert.AreEqual (210, rects[0].Width, "SetClip4");
275 Assert.AreEqual (220, rects[0].Height, "SetClip5");
278 g = Graphics.FromImage (bmp);
279 g.SetClip (new RectangleF (50, 40, 210, 220));
280 rects = g.Clip.GetRegionScans (new Matrix ());
281 Assert.AreEqual (1, rects.Length, "SetClip6");
282 Assert.AreEqual (50, rects[0].X, "SetClip7");
283 Assert.AreEqual (40, rects[0].Y, "SetClip8");
284 Assert.AreEqual (210, rects[0].Width, "SetClip9");
285 Assert.AreEqual (220, rects[0].Height, "SetClip10");
288 g = Graphics.FromImage (bmp);
289 g.SetClip (new Rectangle (50, 40, 210, 220));
290 rects = g.Clip.GetRegionScans (new Matrix ());
291 Assert.AreEqual (1, rects.Length, "SetClip10");
292 Assert.AreEqual (50, rects[0].X, "SetClip11");
293 Assert.AreEqual (40, rects[0].Y, "SetClip12");
294 Assert.AreEqual (210, rects[0].Width, "SetClip13");
295 Assert.AreEqual (220, rects[0].Height, "SetClip14");
299 public void SetSaveReset ()
301 Bitmap bmp = new Bitmap (200, 200);
302 Graphics g = Graphics.FromImage (bmp);
303 GraphicsState state_default, state_modified;
305 state_default = g.Save (); // Default
307 g.CompositingMode = CompositingMode.SourceCopy;
308 g.CompositingQuality = CompositingQuality.GammaCorrected;
309 g.InterpolationMode = InterpolationMode.HighQualityBilinear;
311 g.PageUnit = GraphicsUnit.Inch;
312 g.PixelOffsetMode = PixelOffsetMode.Half;
313 g.Clip = new Region (new Rectangle (0, 0, 100, 100));
314 g.RenderingOrigin = new Point (10, 20);
315 g.SmoothingMode = SmoothingMode.AntiAlias;
316 g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
319 state_modified = g.Save (); // Modified
321 g.CompositingMode = CompositingMode.SourceOver;
322 g.CompositingQuality = CompositingQuality.Default;
323 g.InterpolationMode = InterpolationMode.Bilinear;
325 g.PageUnit = GraphicsUnit.Display;
326 g.PixelOffsetMode = PixelOffsetMode.Default;
327 g.Clip = new Region (new Rectangle (1, 2, 20, 25));
328 g.RenderingOrigin = new Point (5, 6);
329 g.SmoothingMode = SmoothingMode.None;
330 g.TextRenderingHint = TextRenderingHint.SystemDefault;
332 g.Restore (state_modified);
334 Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetSaveReset1");
335 Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetSaveReset2");
336 Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetSaveReset3");
337 Assert.AreEqual (2, g.PageScale, "SetSaveReset4");
338 Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetSaveReset5");
339 Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetSaveReset6");
340 Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetSaveReset7");
341 Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetSaveReset8");
342 Assert.AreEqual (TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint, "SetSaveReset9");
343 Assert.AreEqual (0, (int) g.ClipBounds.X, "SetSaveReset10");
344 Assert.AreEqual (0, (int) g.ClipBounds.Y, "SetSaveReset10");
346 g.Restore (state_default);
348 Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "SetSaveReset11");
349 Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "SetSaveReset12");
350 Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "SetSaveReset13");
351 Assert.AreEqual (1, g.PageScale, "SetSaveReset14");
352 Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "SetSaveReset15");
353 Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "SetSaveReset16");
354 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "SetSaveReset17");
355 Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "SetSaveReset18");
356 Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetSaveReset19");
358 Region r = new Region ();
359 Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "SetSaveReset20");
365 [Category ("NotWorking")] // looks like MS PNG codec promote indexed format to 32bpp ARGB
366 public void LoadIndexed_PngStream ()
368 // Tests that we can load an indexed file
369 using (Stream s = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("indexed.png")) {
370 using (Image img = Image.FromStream (s)) {
371 // however it's no more indexed once loaded
372 Assert.AreEqual (PixelFormat.Format32bppArgb, img.PixelFormat, "PixelFormat");
373 using (Graphics g = Graphics.FromImage (img)) {
374 Assert.AreEqual (img.Height, g.VisibleClipBounds.Height, "Height");
375 Assert.AreEqual (img.Width, g.VisibleClipBounds.Width, "Width");
382 [ExpectedException (typeof (Exception))]
383 public void LoadIndexed_BmpFile ()
385 // Tests that we can load an indexed file, but...
386 string sInFile = TestBitmap.getInFile ("bitmaps/almogaver1bit.bmp");
387 // note: file is misnamed (it's a 4bpp bitmap)
388 using (Image img = Image.FromFile (sInFile)) {
389 Assert.AreEqual (PixelFormat.Format4bppIndexed, img.PixelFormat, "PixelFormat");
390 Graphics.FromImage (img);
395 [ExpectedException (typeof (ArgumentNullException))]
396 public void FromImage ()
398 Graphics g = Graphics.FromImage (null);
401 private Graphics Get (int w, int h)
403 Bitmap bitmap = new Bitmap (w, h);
404 Graphics g = Graphics.FromImage (bitmap);
405 g.Clip = new Region (new Rectangle (0, 0, w, h));
409 private void Compare (string msg, RectangleF b1, RectangleF b2)
411 AssertEquals (msg + ".compare.X", b1.X, b2.X);
412 AssertEquals (msg + ".compare.Y", b1.Y, b2.Y);
413 AssertEquals (msg + ".compare.Width", b1.Width, b2.Width);
414 AssertEquals (msg + ".compare.Height", b1.Height, b2.Height);
418 public void Clip_GetBounds ()
420 Graphics g = Get (16, 16);
421 RectangleF bounds = g.Clip.GetBounds (g);
422 Assert.AreEqual (0, bounds.X, "X");
423 Assert.AreEqual (0, bounds.Y, "Y");
424 Assert.AreEqual (16, bounds.Width, "Width");
425 Assert.AreEqual (16, bounds.Height, "Height");
426 Assert.IsTrue (g.Transform.IsIdentity, "Identity");
431 public void Clip_TranslateTransform ()
433 Graphics g = Get (16, 16);
434 g.TranslateTransform (12.22f, 10.10f);
435 RectangleF bounds = g.Clip.GetBounds (g);
436 Compare ("translate", bounds, g.ClipBounds);
437 Assert.AreEqual (-12.2200003f, bounds.X, "translate.X");
438 Assert.AreEqual (-10.1000004f, bounds.Y, "translate.Y");
439 Assert.AreEqual (16, bounds.Width, "translate.Width");
440 Assert.AreEqual (16, bounds.Height, "translate.Height");
441 float[] elements = g.Transform.Elements;
442 Assert.AreEqual (1, elements[0], "translate.0");
443 Assert.AreEqual (0, elements[1], "translate.1");
444 Assert.AreEqual (0, elements[2], "translate.2");
445 Assert.AreEqual (1, elements[3], "translate.3");
446 Assert.AreEqual (12.2200003f, elements[4], "translate.4");
447 Assert.AreEqual (10.1000004f, elements[5], "translate.5");
450 bounds = g.Clip.GetBounds (g);
451 Compare ("reset", bounds, g.ClipBounds);
452 Assert.AreEqual (0, bounds.X, "reset.X");
453 Assert.AreEqual (0, bounds.Y, "reset.Y");
454 Assert.AreEqual (16, bounds.Width, "reset.Width");
455 Assert.AreEqual (16, bounds.Height, "reset.Height");
456 Assert.IsTrue (g.Transform.IsIdentity, "Identity");
461 [ExpectedException (typeof (ArgumentException))]
462 public void Transform_NonInvertibleMatrix ()
464 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
465 Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
466 Graphics g = Get (16, 16);
467 g.Transform = matrix;
472 [ExpectedException (typeof (ArgumentException))]
473 public void Multiply_NonInvertibleMatrix ()
475 Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
476 Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
477 Graphics g = Get (16, 16);
478 g.MultiplyTransform (matrix);
482 [ExpectedException (typeof (ArgumentNullException))]
483 public void Multiply_Null ()
485 Graphics g = Get (16, 16);
486 g.MultiplyTransform (null);
489 private void CheckBounds (string msg, RectangleF bounds, float x, float y, float w, float h)
491 AssertEquals (msg + ".X", x, bounds.X, 0.1);
492 AssertEquals (msg + ".Y", y, bounds.Y, 0.1);
493 AssertEquals (msg + ".Width", w, bounds.Width, 0.1);
494 AssertEquals (msg + ".Height", h, bounds.Height, 0.1);
498 public void ClipBounds ()
500 Graphics g = Get (16, 16);
501 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
502 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
504 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
505 CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
506 CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
510 public void ClipBounds_Rotate ()
512 Graphics g = Get (16, 16);
513 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
514 g.RotateTransform (90);
515 CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
516 CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
518 g.Transform = new Matrix ();
519 CheckBounds ("identity.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
520 CheckBounds ("identity.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
524 public void ClipBounds_Scale ()
526 RectangleF clip = new Rectangle (0, 0, 8, 8);
527 Graphics g = Get (16, 16);
528 g.Clip = new Region (clip);
529 g.ScaleTransform (0.25f, 0.5f);
530 CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 32, 16);
531 CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 32, 16);
534 CheckBounds ("setclip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
535 CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
539 public void ClipBounds_Translate ()
541 Graphics g = Get (16, 16);
542 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
543 Region clone = g.Clip.Clone ();
544 g.TranslateTransform (8, 8);
545 CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
546 CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
548 g.SetClip (clone, CombineMode.Replace);
549 CheckBounds ("setclip.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
550 CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
554 public void ClipBounds_Transform_Translation ()
556 Graphics g = Get (16, 16);
557 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
558 g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
559 CheckBounds ("transform.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
560 CheckBounds ("transform.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
563 CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
564 CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
568 public void ClipBounds_Transform_Scale ()
570 Graphics g = Get (16, 16);
571 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
572 g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
573 CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
574 CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
577 // see next test for ClipBounds
578 CheckBounds ("resetclip.Clip.GetBounds", g.Clip.GetBounds (g), -4194304, -4194304, 8388608, 8388608);
579 Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
583 [Category ("NotWorking")]
584 public void ClipBounds_Transform_Scale_Strange ()
586 Graphics g = Get (16, 16);
587 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
588 g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
589 CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
590 CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
593 // note: strange case where g.ClipBounds and g.Clip.GetBounds are different
594 CheckBounds ("resetclip.ClipBounds", g.ClipBounds, -8388608, -16777216, 16777216, 33554432);
598 public void ClipBounds_Multiply ()
600 Graphics g = Get (16, 16);
601 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
602 g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
603 g.MultiplyTransform (g.Transform);
604 CheckBounds ("multiply.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
605 CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
608 CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
609 CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
613 public void ClipBounds_Cumulative_Effects ()
615 Graphics g = Get (16, 16);
616 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
617 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
619 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
620 CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
621 CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
623 g.RotateTransform (90);
624 CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
625 CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
627 g.ScaleTransform (0.25f, 0.5f);
628 CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, -16, 32, 16);
629 CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 32, 16);
631 g.TranslateTransform (8, 8);
632 CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -24, 32, 16);
633 CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -24, 32, 16);
635 g.MultiplyTransform (g.Transform);
636 CheckBounds ("multiply.ClipBounds", g.ClipBounds, -104, -56, 64, 64);
637 CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -104, -56, 64, 64);
640 CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
641 CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
645 public void Clip_TranslateTransform_BoundsChange ()
647 Graphics g = Get (16, 16);
648 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
649 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
650 g.TranslateTransform (-16, -16);
651 CheckBounds ("translated.ClipBounds", g.ClipBounds, 16, 16, 16, 16);
652 CheckBounds ("translated.Clip.GetBounds", g.Clip.GetBounds (g), 16, 16, 16, 16);
654 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
655 // ClipBounds isn't affected by a previous translation
656 CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
657 // Clip.GetBounds isn't affected by a previous translation
658 CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
661 CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
662 CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
666 public void Clip_RotateTransform_BoundsChange ()
668 Graphics g = Get (16, 16);
669 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
670 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
671 // we select a "simple" angle because the region will be converted into
672 // a bitmap (well for libgdiplus) and we would lose precision after that
673 g.RotateTransform (90);
674 CheckBounds ("rotated.ClipBounds", g.ClipBounds, 0, -16, 16, 16);
675 CheckBounds ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 16, 16);
676 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
677 // ClipBounds isn't affected by a previous rotation (90)
678 CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
679 // Clip.GetBounds isn't affected by a previous rotation
680 CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
683 CheckBounds ("reseted.ClipBounds", g.ClipBounds, -8, 0, 8, 8);
684 CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -8, 0, 8, 8);
687 private void CheckBoundsInt (string msg, RectangleF bounds, int x, int y, int w, int h)
689 // currently bounds are rounded at 8 pixels (FIXME - we can go down to 1 pixel)
690 AssertEquals (msg + ".X", x, bounds.X, 4f);
691 AssertEquals (msg + ".Y", y, bounds.Y, 4f);
692 AssertEquals (msg + ".Width", w, bounds.Width, 4f);
693 AssertEquals (msg + ".Height", h, bounds.Height, 4f);
697 [Category ("NotWorking")]
698 public void Clip_RotateTransform_BoundsChange_45 ()
700 Graphics g = Get (16, 16);
701 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
702 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
703 g.RotateTransform (45);
704 // we can't use the "normal" CheckBound here because of libgdiplus crude rounding
705 CheckBoundsInt ("rotated.ClipBounds", g.ClipBounds, 0, -11, 24, 24);
706 CheckBoundsInt ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -11, 24, 24);
707 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
708 // ClipBounds IS affected by a previous rotation (45)
709 CheckBoundsInt ("rectangle.ClipBounds", g.ClipBounds, -3, -4, 16, 16);
710 // Clip.GetBounds isn't affected by a previous rotation
711 CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
714 CheckBounds ("reseted.ClipBounds", g.ClipBounds, -5, 1, 11, 11);
715 CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -5.6f, 0, 11.3f, 11.3f);
719 public void Clip_ScaleTransform_NoBoundsChange ()
721 Graphics g = Get (16, 16);
722 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
723 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
724 g.ScaleTransform (2, 0.5f);
725 CheckBounds ("scaled.ClipBounds", g.ClipBounds, 0, 0, 8, 32);
726 CheckBounds ("scaled.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 32);
727 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
728 // ClipBounds isn't affected by a previous scaling
729 CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
730 // Clip.GetBounds isn't affected by a previous scaling
731 CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
734 CheckBounds ("reseted.ClipBounds", g.ClipBounds, 0, 0, 16, 4);
735 CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 4);
739 [Category ("NotWorking")]
740 public void Clip_MultiplyTransform_NoBoundsChange ()
742 Graphics g = Get (16, 16);
743 CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
744 CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
745 g.MultiplyTransform (new Matrix (2.5f, 0.5f, -2.5f, 0.5f, 4, -4));
746 CheckBounds ("multiplied.ClipBounds", g.ClipBounds, 3.2f, 1.6f, 19.2f, 19.2f);
747 CheckBounds ("multiplied.Clip.GetBounds", g.Clip.GetBounds (g), 3.2f, 1.6f, 19.2f, 19.2f);
748 g.Clip = new Region (new Rectangle (0, 0, 8, 8));
749 // ClipBounds IS affected by the previous multiplication
750 CheckBounds ("rectangle.ClipBounds", g.ClipBounds, -3, -3, 15, 15);
751 // Clip.GetBounds isn't affected by the previous multiplication
752 CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
755 CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -3, 40, 7);
756 CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -4, 40, 8);
760 [ExpectedException (typeof (ArgumentException))]
761 public void ScaleTransform_X0 ()
763 Graphics g = Get (16, 16);
764 g.ScaleTransform (0, 1);
768 [ExpectedException (typeof (ArgumentException))]
769 public void ScaleTransform_Y0 ()
771 Graphics g = Get (16, 16);
772 g.ScaleTransform (1, 0);
776 public void TranslateTransform_Order ()
778 Graphics g = Get (16, 16);
779 g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
780 g.TranslateTransform (3, -3);
781 float[] elements = g.Transform.Elements;
782 Assert.AreEqual (1, elements[0], "default.0");
783 Assert.AreEqual (2, elements[1], "default.1");
784 Assert.AreEqual (3, elements[2], "default.2");
785 Assert.AreEqual (4, elements[3], "default.3");
786 Assert.AreEqual (-1, elements[4], "default.4");
787 Assert.AreEqual (0, elements[5], "default.5");
789 g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
790 g.TranslateTransform (3, -3, MatrixOrder.Prepend);
791 elements = g.Transform.Elements;
792 Assert.AreEqual (1, elements[0], "prepend.0");
793 Assert.AreEqual (2, elements[1], "prepend.1");
794 Assert.AreEqual (3, elements[2], "prepend.2");
795 Assert.AreEqual (4, elements[3], "prepend.3");
796 Assert.AreEqual (-1, elements[4], "prepend.4");
797 Assert.AreEqual (0, elements[5], "prepend.5");
799 g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
800 g.TranslateTransform (3, -3, MatrixOrder.Append);
801 elements = g.Transform.Elements;
802 Assert.AreEqual (1, elements[0], "append.0");
803 Assert.AreEqual (2, elements[1], "append.1");
804 Assert.AreEqual (3, elements[2], "append.2");
805 Assert.AreEqual (4, elements[3], "append.3");
806 Assert.AreEqual (8, elements[4], "append.4");
807 Assert.AreEqual (3, elements[5], "append.5");
810 static Point[] SmallCurve = new Point[3] { new Point (0, 0), new Point (15, 5), new Point (5, 15) };
811 static PointF[] SmallCurveF = new PointF[3] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15) };
813 static Point[] TooSmallCurve = new Point[2] { new Point (0, 0), new Point (15, 5) };
814 static PointF[] LargeCurveF = new PointF[4] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15), new PointF (0, 20) };
817 [ExpectedException (typeof (ArgumentNullException))]
818 public void DrawCurve_PenNull ()
820 Bitmap bitmap = new Bitmap (20, 20);
821 Graphics g = Graphics.FromImage (bitmap);
822 g.DrawCurve (null, SmallCurveF);
826 [ExpectedException (typeof (ArgumentNullException))]
827 public void DrawCurve_PointFNull ()
829 Bitmap bitmap = new Bitmap (20, 20);
830 Graphics g = Graphics.FromImage (bitmap);
831 g.DrawCurve (Pens.Black, (PointF[]) null);
835 [ExpectedException (typeof (ArgumentNullException))]
836 public void DrawCurve_PointNull ()
838 Bitmap bitmap = new Bitmap (20, 20);
839 Graphics g = Graphics.FromImage (bitmap);
840 g.DrawCurve (Pens.Black, (Point[]) null);
844 public void DrawCurve_NotEnoughPoints ()
846 Bitmap bitmap = new Bitmap (20, 20);
847 Graphics g = Graphics.FromImage (bitmap);
848 CheckForEmptyBitmap (bitmap);
849 g.DrawCurve (Pens.Black, TooSmallCurve, 0.5f);
850 CheckForNonEmptyBitmap (bitmap);
851 // so a "curve" can be drawn with less than 3 points!
852 // actually I used to call that a line... (and it's not related to tension)
858 [ExpectedException (typeof (ArgumentException))]
859 public void DrawCurve_SinglePoint ()
861 Bitmap bitmap = new Bitmap (20, 20);
862 Graphics g = Graphics.FromImage (bitmap);
863 g.DrawCurve (Pens.Black, new Point[1] { new Point (10, 10) }, 0.5f);
864 // a single point isn't enough
868 [ExpectedException (typeof (ArgumentException))]
869 public void DrawCurve3_NotEnoughPoints ()
871 Bitmap bitmap = new Bitmap (20, 20);
872 Graphics g = Graphics.FromImage (bitmap);
873 g.DrawCurve (Pens.Black, TooSmallCurve, 0, 2, 0.5f);
874 // aha, this is API dependent
878 public void DrawCurve_NegativeTension ()
880 Bitmap bitmap = new Bitmap (20, 20);
881 Graphics g = Graphics.FromImage (bitmap);
882 // documented as bigger (or equals) to 0
883 g.DrawCurve (Pens.Black, SmallCurveF, -0.9f);
884 CheckForNonEmptyBitmap (bitmap);
890 public void DrawCurve_PositiveTension ()
892 Bitmap bitmap = new Bitmap (20, 20);
893 Graphics g = Graphics.FromImage (bitmap);
894 g.DrawCurve (Pens.Black, SmallCurveF, 0.9f);
895 // this is not the same as -1
896 CheckForNonEmptyBitmap (bitmap);
902 [Category ("NotWorking")] // libgdiplus is drawing something
903 public void DrawCurve_LargeTension ()
905 Bitmap bitmap = new Bitmap (20, 20);
906 Graphics g = Graphics.FromImage (bitmap);
907 g.DrawCurve (Pens.Black, SmallCurve, Single.MaxValue);
908 CheckForEmptyBitmap (bitmap);
909 // too much tension ;)
915 [ExpectedException (typeof (ArgumentException))]
916 public void DrawCurve_ZeroSegments ()
918 Bitmap bitmap = new Bitmap (20, 20);
919 Graphics g = Graphics.FromImage (bitmap);
920 g.DrawCurve (Pens.Black, SmallCurveF, 0, 0);
924 [ExpectedException (typeof (ArgumentException))]
925 public void DrawCurve_NegativeSegments ()
927 Bitmap bitmap = new Bitmap (20, 20);
928 Graphics g = Graphics.FromImage (bitmap);
929 g.DrawCurve (Pens.Black, SmallCurveF, 0, -1);
933 [ExpectedException (typeof (ArgumentException))]
934 public void DrawCurve_OffsetTooLarge ()
936 Bitmap bitmap = new Bitmap (20, 20);
937 Graphics g = Graphics.FromImage (bitmap);
938 // starting offset 1 doesn't give 3 points to make a curve
939 g.DrawCurve (Pens.Black, SmallCurveF, 1, 2);
940 // and in this case 2 points aren't enough to draw something
944 public void DrawCurve_Offset_0 ()
946 Bitmap bitmap = new Bitmap (20, 20);
947 Graphics g = Graphics.FromImage (bitmap);
948 g.DrawCurve (Pens.Black, LargeCurveF, 0, 2, 0.5f);
949 CheckForNonEmptyBitmap (bitmap);
955 public void DrawCurve_Offset_1 ()
957 Bitmap bitmap = new Bitmap (20, 20);
958 Graphics g = Graphics.FromImage (bitmap);
959 g.DrawCurve (Pens.Black, LargeCurveF, 1, 2, 0.5f);
960 CheckForNonEmptyBitmap (bitmap);
966 public void DrawCurve_Offset_2 ()
968 Bitmap bitmap = new Bitmap (20, 20);
969 Graphics g = Graphics.FromImage (bitmap);
970 // it works even with two points because we know the previous ones
971 g.DrawCurve (Pens.Black, LargeCurveF, 2, 1, 0.5f);
972 CheckForNonEmptyBitmap (bitmap);
978 public void DrawRectangle_Negative ()
980 Bitmap bitmap = new Bitmap (20, 20);
981 Graphics g = Graphics.FromImage (bitmap);
982 Pen pen = new Pen (Color.Red);
983 g.DrawRectangle (pen, 5, 5, -10, -10);
984 g.DrawRectangle (pen, 0.0f, 0.0f, 5.0f, -10.0f);
985 g.DrawRectangle (pen, new Rectangle (15, 0, -10, 5));
986 CheckForEmptyBitmap (bitmap);
993 public void DrawRectangles_Negative ()
995 Bitmap bitmap = new Bitmap (20, 20);
996 Graphics g = Graphics.FromImage (bitmap);
997 Pen pen = new Pen (Color.Red);
998 Rectangle[] rects = new Rectangle[2] {
999 new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
1001 RectangleF[] rectf = new RectangleF[2] {
1002 new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
1004 g.DrawRectangles (pen, rects);
1005 g.DrawRectangles (pen, rectf);
1006 CheckForEmptyBitmap (bitmap);
1013 public void FillRectangle_Negative ()
1015 Bitmap bitmap = new Bitmap (20, 20);
1016 Graphics g = Graphics.FromImage (bitmap);
1017 SolidBrush brush = new SolidBrush (Color.Red);
1018 g.FillRectangle (brush, 5, 5, -10, -10);
1019 g.FillRectangle (brush, 0.0f, 0.0f, 5.0f, -10.0f);
1020 g.FillRectangle (brush, new Rectangle (15, 0, -10, 5));
1021 CheckForEmptyBitmap (bitmap);
1028 public void FillRectangles_Negative ()
1030 Bitmap bitmap = new Bitmap (20, 20);
1031 Graphics g = Graphics.FromImage (bitmap);
1032 SolidBrush brush = new SolidBrush (Color.Red);
1033 Rectangle[] rects = new Rectangle[2] {
1034 new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
1036 RectangleF[] rectf = new RectangleF[2] {
1037 new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
1039 g.FillRectangles (brush, rects);
1040 g.FillRectangles (brush, rectf);
1041 CheckForEmptyBitmap (bitmap);
1047 [Test] // bug #355141
1049 public void FromHwnd_Zero ()
1051 Graphics g = Graphics.FromHwnd (IntPtr.Zero);
1052 Assert.IsNotNull (g);
1055 private void CheckDefaultProperties (string message, Graphics g)
1057 Assert.IsTrue (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
1058 AssertEquals (message + ".CompositingMode", CompositingMode.SourceOver, g.CompositingMode);
1059 AssertEquals (message + ".CompositingQuality", CompositingQuality.Default, g.CompositingQuality);
1060 AssertEquals (message + ".InterpolationMode", InterpolationMode.Bilinear, g.InterpolationMode);
1061 AssertEquals (message + ".PageScale", 1.0f, g.PageScale);
1062 AssertEquals (message + ".PageUnit", GraphicsUnit.Display, g.PageUnit);
1063 AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Default, g.PixelOffsetMode);
1064 AssertEquals (message + ".SmoothingMode", SmoothingMode.None, g.SmoothingMode);
1065 AssertEquals (message + ".TextContrast", 4, g.TextContrast);
1066 AssertEquals (message + ".TextRenderingHint", TextRenderingHint.SystemDefault, g.TextRenderingHint);
1067 Assert.IsTrue (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
1070 private void CheckCustomProperties (string message, Graphics g)
1072 Assert.IsFalse (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
1073 AssertEquals (message + ".CompositingMode", CompositingMode.SourceCopy, g.CompositingMode);
1074 AssertEquals (message + ".CompositingQuality", CompositingQuality.HighQuality, g.CompositingQuality);
1075 AssertEquals (message + ".InterpolationMode", InterpolationMode.HighQualityBicubic, g.InterpolationMode);
1076 AssertEquals (message + ".PageScale", 0.5f, g.PageScale);
1077 AssertEquals (message + ".PageUnit", GraphicsUnit.Inch, g.PageUnit);
1078 AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Half, g.PixelOffsetMode);
1079 AssertEquals (message + ".RenderingOrigin", new Point (-1, -1), g.RenderingOrigin);
1080 AssertEquals (message + ".SmoothingMode", SmoothingMode.AntiAlias, g.SmoothingMode);
1081 AssertEquals (message + ".TextContrast", 0, g.TextContrast);
1082 AssertEquals (message + ".TextRenderingHint", TextRenderingHint.AntiAlias, g.TextRenderingHint);
1083 Assert.IsFalse (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
1086 private void CheckMatrix (string message, Matrix m, float xx, float yx, float xy, float yy, float x0, float y0)
1088 float[] elements = m.Elements;
1089 AssertEquals (message + ".Matrix.xx", xx, elements[0], 0.01);
1090 AssertEquals (message + ".Matrix.yx", yx, elements[1], 0.01);
1091 AssertEquals (message + ".Matrix.xy", xy, elements[2], 0.01);
1092 AssertEquals (message + ".Matrix.yy", yy, elements[3], 0.01);
1093 AssertEquals (message + ".Matrix.x0", x0, elements[4], 0.01);
1094 AssertEquals (message + ".Matrix.y0", y0, elements[5], 0.01);
1098 public void BeginContainer ()
1100 Bitmap bitmap = new Bitmap (20, 20);
1101 Graphics g = Graphics.FromImage (bitmap);
1103 CheckDefaultProperties ("default", g);
1104 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1106 g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1107 g.CompositingMode = CompositingMode.SourceCopy;
1108 g.CompositingQuality = CompositingQuality.HighQuality;
1109 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1111 g.PageUnit = GraphicsUnit.Inch;
1112 g.PixelOffsetMode = PixelOffsetMode.Half;
1113 g.RenderingOrigin = new Point (-1, -1);
1114 g.RotateTransform (45);
1115 g.SmoothingMode = SmoothingMode.AntiAlias;
1117 g.TextRenderingHint = TextRenderingHint.AntiAlias;
1118 CheckCustomProperties ("modified", g);
1119 CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1121 GraphicsContainer gc = g.BeginContainer ();
1122 // things gets reseted after calling BeginContainer
1123 CheckDefaultProperties ("BeginContainer", g);
1124 // but not everything
1125 Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1127 g.EndContainer (gc);
1128 CheckCustomProperties ("EndContainer", g);
1132 public void BeginContainer_Rect ()
1134 Bitmap bitmap = new Bitmap (20, 20);
1135 Graphics g = Graphics.FromImage (bitmap);
1137 CheckDefaultProperties ("default", g);
1138 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1140 g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1141 g.CompositingMode = CompositingMode.SourceCopy;
1142 g.CompositingQuality = CompositingQuality.HighQuality;
1143 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1145 g.PageUnit = GraphicsUnit.Inch;
1146 g.PixelOffsetMode = PixelOffsetMode.Half;
1147 g.RenderingOrigin = new Point (-1, -1);
1148 g.RotateTransform (45);
1149 g.SmoothingMode = SmoothingMode.AntiAlias;
1151 g.TextRenderingHint = TextRenderingHint.AntiAlias;
1152 CheckCustomProperties ("modified", g);
1153 CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1155 GraphicsContainer gc = g.BeginContainer (new Rectangle (10, 20, 30, 40), new Rectangle (10, 20, 300, 400), GraphicsUnit.Millimeter);
1156 // things gets reseted after calling BeginContainer
1157 CheckDefaultProperties ("BeginContainer", g);
1158 // but not everything
1159 Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1161 g.EndContainer (gc);
1162 CheckCustomProperties ("EndContainer", g);
1163 CheckMatrix ("EndContainer.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1167 public void BeginContainer_RectF ()
1169 Bitmap bitmap = new Bitmap (20, 20);
1170 Graphics g = Graphics.FromImage (bitmap);
1172 CheckDefaultProperties ("default", g);
1173 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1175 g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1176 g.CompositingMode = CompositingMode.SourceCopy;
1177 g.CompositingQuality = CompositingQuality.HighQuality;
1178 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1180 g.PageUnit = GraphicsUnit.Inch;
1181 g.PixelOffsetMode = PixelOffsetMode.Half;
1182 g.RenderingOrigin = new Point (-1, -1);
1183 g.RotateTransform (45);
1184 g.SmoothingMode = SmoothingMode.AntiAlias;
1186 g.TextRenderingHint = TextRenderingHint.AntiAlias;
1187 CheckCustomProperties ("modified", g);
1188 CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1190 GraphicsContainer gc = g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), GraphicsUnit.Inch);
1191 // things gets reseted after calling BeginContainer
1192 CheckDefaultProperties ("BeginContainer", g);
1193 // but not everything
1194 Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1196 g.EndContainer (gc);
1197 CheckCustomProperties ("EndContainer", g);
1200 private void BeginContainer_GraphicsUnit (GraphicsUnit unit)
1202 Bitmap bitmap = new Bitmap (20, 20);
1203 Graphics g = Graphics.FromImage (bitmap);
1204 g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), unit);
1208 [ExpectedException (typeof (ArgumentException))]
1209 public void BeginContainer_GraphicsUnit_Display ()
1211 BeginContainer_GraphicsUnit (GraphicsUnit.Display);
1215 public void BeginContainer_GraphicsUnit_Valid ()
1217 BeginContainer_GraphicsUnit (GraphicsUnit.Document);
1218 BeginContainer_GraphicsUnit (GraphicsUnit.Inch);
1219 BeginContainer_GraphicsUnit (GraphicsUnit.Millimeter);
1220 BeginContainer_GraphicsUnit (GraphicsUnit.Pixel);
1221 BeginContainer_GraphicsUnit (GraphicsUnit.Point);
1225 [ExpectedException (typeof (ArgumentException))]
1226 public void BeginContainer_GraphicsUnit_World ()
1228 BeginContainer_GraphicsUnit (GraphicsUnit.World);
1232 [ExpectedException (typeof (ArgumentException))]
1233 public void BeginContainer_GraphicsUnit_Bad ()
1235 BeginContainer_GraphicsUnit ((GraphicsUnit) Int32.MinValue);
1239 [ExpectedException (typeof (ArgumentNullException))]
1240 public void EndContainer_Null ()
1242 Bitmap bitmap = new Bitmap (20, 20);
1243 Graphics g = Graphics.FromImage (bitmap);
1244 g.EndContainer (null);
1250 Bitmap bitmap = new Bitmap (20, 20);
1251 Graphics g = Graphics.FromImage (bitmap);
1253 CheckDefaultProperties ("default", g);
1254 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1256 GraphicsState gs1 = g.Save ();
1257 // nothing is changed after a save
1258 CheckDefaultProperties ("save1", g);
1259 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "save1.RenderingOrigin");
1261 g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1262 g.CompositingMode = CompositingMode.SourceCopy;
1263 g.CompositingQuality = CompositingQuality.HighQuality;
1264 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1266 g.PageUnit = GraphicsUnit.Inch;
1267 g.PixelOffsetMode = PixelOffsetMode.Half;
1268 g.RenderingOrigin = new Point (-1, -1);
1269 g.RotateTransform (45);
1270 g.SmoothingMode = SmoothingMode.AntiAlias;
1272 g.TextRenderingHint = TextRenderingHint.AntiAlias;
1273 CheckCustomProperties ("modified", g);
1274 CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1276 GraphicsState gs2 = g.Save ();
1277 CheckCustomProperties ("save2", g);
1280 CheckCustomProperties ("restored1", g);
1281 CheckMatrix ("restored1.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1284 CheckDefaultProperties ("restored2", g);
1285 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "restored2.RenderingOrigin");
1289 [ExpectedException (typeof (NullReferenceException))]
1290 public void Restore_Null ()
1292 Bitmap bitmap = new Bitmap (20, 20);
1293 Graphics g = Graphics.FromImage (bitmap);
1298 [ExpectedException (typeof (ArgumentNullException))]
1299 public void FillRectangles_BrushNull_Rectangle ()
1301 using (Bitmap bitmap = new Bitmap (20, 20)) {
1302 using (Graphics g = Graphics.FromImage (bitmap)) {
1303 g.FillRectangles (null, new Rectangle[1]);
1309 [ExpectedException (typeof (ArgumentNullException))]
1310 public void FillRectangles_Rectangle_Null ()
1312 using (Bitmap bitmap = new Bitmap (20, 20)) {
1313 using (Graphics g = Graphics.FromImage (bitmap)) {
1314 g.FillRectangles (Brushes.Red, (Rectangle[]) null);
1319 [Test] // see bug #78408
1320 [ExpectedException (typeof (ArgumentException))]
1321 public void FillRectanglesZeroRectangle ()
1323 using (Bitmap bitmap = new Bitmap (20, 20)) {
1324 using (Graphics g = Graphics.FromImage (bitmap)) {
1325 g.FillRectangles (Brushes.Red, new Rectangle[0]);
1331 [ExpectedException (typeof (ArgumentNullException))]
1332 public void FillRectangles_BrushNull_RectangleF ()
1334 using (Bitmap bitmap = new Bitmap (20, 20)) {
1335 using (Graphics g = Graphics.FromImage (bitmap)) {
1336 g.FillRectangles (null, new RectangleF[1]);
1342 [ExpectedException (typeof (ArgumentNullException))]
1343 public void FillRectangles_RectangleF_Null ()
1345 using (Bitmap bitmap = new Bitmap (20, 20)) {
1346 using (Graphics g = Graphics.FromImage (bitmap)) {
1347 g.FillRectangles (Brushes.Red, (RectangleF[]) null);
1352 [Test] // see bug #78408
1353 [ExpectedException (typeof (ArgumentException))]
1354 public void FillRectanglesZeroRectangleF ()
1356 using (Bitmap bitmap = new Bitmap (20, 20)) {
1357 using (Graphics g = Graphics.FromImage (bitmap)) {
1358 g.FillRectangles (Brushes.Red, new RectangleF[0]);
1364 public void FillRectangles_NormalBehavior ()
1366 using (Bitmap bitmap = new Bitmap (20, 20)) {
1367 using (Graphics g = Graphics.FromImage (bitmap)) {
1368 g.Clear (Color.Fuchsia);
1369 Rectangle rect = new Rectangle (5, 5, 10, 10);
1370 g.Clip = new Region (rect);
1371 g.FillRectangle (Brushes.Red, rect);
1373 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1374 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1375 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1376 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1378 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1379 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1380 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1384 // see bug #81737 for details
1385 private Bitmap FillDrawRectangle (float width)
1387 Bitmap bitmap = new Bitmap (20, 20);
1388 using (Graphics g = Graphics.FromImage (bitmap)) {
1389 g.Clear (Color.Red);
1390 Rectangle rect = new Rectangle (5, 5, 10, 10);
1391 g.FillRectangle (Brushes.Green, rect);
1393 using (Pen pen = new Pen (Color.Blue, width)) {
1394 g.DrawRectangle (pen, rect);
1397 g.DrawRectangle (Pens.Blue, rect);
1404 public void FillDrawRectangle_Width_Default ()
1407 using (Bitmap bitmap = FillDrawRectangle (Single.MinValue)) {
1409 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1410 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1411 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1413 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1414 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1415 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1417 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1418 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1419 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1421 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1422 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1423 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1425 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1426 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1427 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1429 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1430 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1431 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1433 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1434 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1435 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1437 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1438 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1439 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1444 [Category ("NotOnMac")]
1445 public void FillDrawRectangle_Width_2 ()
1448 using (Bitmap bitmap = FillDrawRectangle (2.0f)) {
1450 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1451 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1452 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1453 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1455 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1456 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1457 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1458 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1460 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1461 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1462 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1463 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1465 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1466 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1467 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1468 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1470 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1471 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1472 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1473 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1475 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1476 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1477 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1478 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1480 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "3,16");
1481 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "4,15");
1482 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1483 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 13).ToArgb (), "6,13");
1485 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1486 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1487 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1488 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1493 public void FillDrawRectangle_Width_3 ()
1496 using (Bitmap bitmap = FillDrawRectangle (3.0f)) {
1498 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1499 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1500 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1501 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1502 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 7).ToArgb (), "7,7");
1504 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1505 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1506 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1507 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1508 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 7).ToArgb (), "9,7");
1510 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1511 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1512 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1513 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1514 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1516 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1517 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1518 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1519 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1520 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1522 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1523 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1524 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1525 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1526 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1528 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1529 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1530 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1531 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1532 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1534 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1535 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1536 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1537 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1538 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 13).ToArgb (), "7,13");
1540 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1541 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1542 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1543 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1544 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 9).ToArgb (), "7,9");
1548 // reverse, draw the fill over
1549 private Bitmap DrawFillRectangle (float width)
1551 Bitmap bitmap = new Bitmap (20, 20);
1552 using (Graphics g = Graphics.FromImage (bitmap)) {
1553 g.Clear (Color.Red);
1554 Rectangle rect = new Rectangle (5, 5, 10, 10);
1556 using (Pen pen = new Pen (Color.Blue, width)) {
1557 g.DrawRectangle (pen, rect);
1560 g.DrawRectangle (Pens.Blue, rect);
1562 g.FillRectangle (Brushes.Green, rect);
1568 public void DrawFillRectangle_Width_Default ()
1571 using (Bitmap bitmap = DrawFillRectangle (Single.MinValue)) {
1572 // NW - no blue border
1573 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1574 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1575 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1576 // N - no blue border
1577 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1578 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1579 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1581 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1582 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1583 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1585 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1586 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1587 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1589 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1590 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1591 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1593 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1594 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1595 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1597 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1598 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1599 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1600 // W - no blue border
1601 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1602 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1603 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1608 [Category ("NotOnMac")]
1609 public void DrawFillRectangle_Width_2 ()
1612 using (Bitmap bitmap = DrawFillRectangle (2.0f)) {
1613 // looks like a one pixel border - but enlarged
1615 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1616 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1617 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1619 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1620 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1621 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1623 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1624 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1625 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1627 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1628 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1629 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1631 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1632 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1633 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1635 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1636 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1637 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1639 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "4,16");
1640 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "5,15");
1641 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 14).ToArgb (), "6,14");
1643 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1644 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1645 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1650 public void DrawFillRectangle_Width_3 ()
1653 using (Bitmap bitmap = DrawFillRectangle (3.0f)) {
1655 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1656 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1657 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1659 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1660 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1661 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1663 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1664 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1665 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1666 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1668 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1669 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1670 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1671 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1673 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1674 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1675 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1676 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1678 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1679 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1680 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1681 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1683 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1684 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1685 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1686 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1688 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1689 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1690 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1694 private Bitmap DrawLines (float width)
1696 Bitmap bitmap = new Bitmap (20, 20);
1697 using (Graphics g = Graphics.FromImage (bitmap)) {
1698 g.Clear (Color.Red);
1699 Point[] pts = new Point[3] { new Point (5, 5), new Point (15, 5), new Point (15, 15) };
1701 using (Pen pen = new Pen (Color.Blue, width)) {
1702 g.DrawLines (pen, pts);
1705 g.DrawLines (Pens.Blue, pts);
1712 public void DrawLines_Width_Default ()
1715 using (Bitmap bitmap = DrawLines (Single.MinValue)) {
1717 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1718 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1719 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1720 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1721 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1722 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1724 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1725 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1726 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1727 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1728 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1729 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1730 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1731 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1732 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1734 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1735 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1736 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1737 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 16).ToArgb (), "14,16");
1738 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 16).ToArgb (), "15,16");
1739 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1744 [Category ("NotWorking")]
1745 public void DrawLines_Width_2 ()
1748 using (Bitmap bitmap = DrawLines (2.0f)) {
1750 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1751 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1752 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1753 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1754 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1755 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1756 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1757 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1759 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1760 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1761 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1762 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1763 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1764 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1765 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1766 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1767 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1768 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1769 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1770 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1771 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1772 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1773 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1774 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1776 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1777 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1778 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1779 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1780 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1781 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1782 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1783 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1788 [Category ("NotWorking")]
1789 public void DrawLines_Width_3 ()
1792 using (Bitmap bitmap = DrawLines (3.0f)) {
1794 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1795 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1796 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1797 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1798 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 7).ToArgb (), "4,7");
1799 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1800 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1801 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1802 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1803 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 7).ToArgb (), "5,7");
1805 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1806 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1807 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1808 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1809 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1810 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1811 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1812 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1813 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1814 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 7).ToArgb (), "14,7");
1815 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1816 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1817 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1818 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1819 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 7).ToArgb (), "15,7");
1820 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1821 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1822 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1823 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1824 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 7).ToArgb (), "16,7");
1825 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1826 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 4).ToArgb (), "17,4");
1827 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 5).ToArgb (), "17,5");
1828 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 6).ToArgb (), "17,6");
1829 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 7).ToArgb (), "17,7");
1831 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1832 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1833 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1834 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1835 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 14).ToArgb (), "17,14");
1836 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1837 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1838 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1839 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1840 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 15).ToArgb (), "17,15");
1845 public void MeasureString_StringFont ()
1847 using (Bitmap bitmap = new Bitmap (20, 20)) {
1848 using (Graphics g = Graphics.FromImage (bitmap)) {
1849 SizeF size = g.MeasureString (null, font);
1850 Assert.IsTrue (size.IsEmpty, "MeasureString(null,font)");
1851 size = g.MeasureString (String.Empty, font);
1852 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font)");
1854 size = g.MeasureString (null, null);
1855 Assert.IsTrue (size.IsEmpty, "MeasureString(null,null)");
1856 size = g.MeasureString (String.Empty, null);
1857 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,null)");
1863 [ExpectedException (typeof (ArgumentNullException))]
1864 public void MeasureString_StringFont_Null ()
1866 using (Bitmap bitmap = new Bitmap (20, 20)) {
1867 using (Graphics g = Graphics.FromImage (bitmap)) {
1868 g.MeasureString ("a", null);
1874 public void MeasureString_StringFontSizeF ()
1877 Assert.Ignore ("Couldn't create required font");
1879 using (Bitmap bitmap = new Bitmap (20, 20)) {
1880 using (Graphics g = Graphics.FromImage (bitmap)) {
1881 SizeF size = g.MeasureString ("a", font, SizeF.Empty);
1882 Assert.IsFalse (size.IsEmpty, "MeasureString(a,font,empty)");
1884 size = g.MeasureString (String.Empty, font, SizeF.Empty);
1885 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font,empty)");
1890 private void MeasureString_StringFontInt (string s)
1893 Assert.Ignore ("Couldn't create required font");
1895 using (Bitmap bitmap = new Bitmap (20, 20)) {
1896 using (Graphics g = Graphics.FromImage (bitmap)) {
1897 SizeF size0 = g.MeasureString (s, font, 0);
1898 SizeF sizeN = g.MeasureString (s, font, Int32.MinValue);
1899 SizeF sizeP = g.MeasureString (s, font, Int32.MaxValue);
1900 Assert.AreEqual (size0, sizeN, "0-Min");
1901 Assert.AreEqual (size0, sizeP, "0-Max");
1907 public void MeasureString_StringFontInt_ShortString ()
1909 MeasureString_StringFontInt ("a");
1913 public void MeasureString_StringFontInt_LongString ()
1915 HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_StringFontInt_LongString");
1916 MeasureString_StringFontInt ("A very long string..."); // see bug #79643
1920 public void MeasureString_StringFormat_Alignment ()
1923 Assert.Ignore ("Couldn't create required font");
1925 string text = "Hello Mono::";
1926 StringFormat string_format = new StringFormat ();
1928 using (Bitmap bitmap = new Bitmap (20, 20)) {
1929 using (Graphics g = Graphics.FromImage (bitmap)) {
1930 string_format.Alignment = StringAlignment.Near;
1931 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1933 string_format.Alignment = StringAlignment.Center;
1934 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1936 string_format.Alignment = StringAlignment.Far;
1937 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1939 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1940 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1942 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1943 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1949 public void MeasureString_StringFormat_Alignment_DirectionVertical ()
1952 Assert.Ignore ("Couldn't create required font");
1954 string text = "Hello Mono::";
1955 StringFormat string_format = new StringFormat ();
1956 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1958 using (Bitmap bitmap = new Bitmap (20, 20)) {
1959 using (Graphics g = Graphics.FromImage (bitmap)) {
1960 string_format.Alignment = StringAlignment.Near;
1961 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1963 string_format.Alignment = StringAlignment.Center;
1964 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1966 string_format.Alignment = StringAlignment.Far;
1967 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1969 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1970 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1972 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1973 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1979 public void MeasureString_StringFormat_LineAlignment ()
1982 Assert.Ignore ("Couldn't create required font");
1984 string text = "Hello Mono::";
1985 StringFormat string_format = new StringFormat ();
1987 using (Bitmap bitmap = new Bitmap (20, 20)) {
1988 using (Graphics g = Graphics.FromImage (bitmap)) {
1989 string_format.LineAlignment = StringAlignment.Near;
1990 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1992 string_format.LineAlignment = StringAlignment.Center;
1993 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1995 string_format.LineAlignment = StringAlignment.Far;
1996 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1998 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1999 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2001 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2002 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2008 public void MeasureString_StringFormat_LineAlignment_DirectionVertical ()
2011 Assert.Ignore ("Couldn't create required font");
2013 string text = "Hello Mono::";
2014 StringFormat string_format = new StringFormat ();
2015 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2017 using (Bitmap bitmap = new Bitmap (20, 20)) {
2018 using (Graphics g = Graphics.FromImage (bitmap)) {
2019 string_format.LineAlignment = StringAlignment.Near;
2020 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
2022 string_format.LineAlignment = StringAlignment.Center;
2023 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
2025 string_format.LineAlignment = StringAlignment.Far;
2026 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2028 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2029 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2031 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2032 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2038 public void MeasureString_MultlineString_Width ()
2040 using (Bitmap bitmap = new Bitmap (20, 20)) {
2041 using (Graphics g = Graphics.FromImage (bitmap)) {
2042 StringFormat string_format = new StringFormat ();
2044 string text1 = "Test\nTest123\nTest 456\nTest 1,2,3,4,5...";
2045 string text2 = "Test 1,2,3,4,5...";
2047 SizeF size1 = g.MeasureString (text1, font, SizeF.Empty, string_format);
2048 SizeF size2 = g.MeasureString (text2, font, SizeF.Empty, string_format);
2050 Assert.AreEqual ((int) size1.Width, (int) size2.Width, "Multiline Text Width");
2056 public void MeasureString_Bug76664 ()
2059 Assert.Ignore ("Couldn't create required font");
2061 using (Bitmap bitmap = new Bitmap (20, 20)) {
2062 using (Graphics g = Graphics.FromImage (bitmap)) {
2063 string s = "aaa aa aaaa a aaa";
2064 SizeF size = g.MeasureString (s, font);
2067 SizeF size2 = g.MeasureString (s, font, new SizeF (80, size.Height), null, out chars, out lines);
2070 Assert.IsTrue (size2.Width < size.Width, "Width/pixel");
2071 Assert.AreEqual (size2.Height, size.Height, "Height/pixel");
2073 Assert.AreEqual (1, lines, "lines fitted");
2074 // LAMESPEC: documentation seems to suggest chars is total length
2075 Assert.IsTrue (chars < s.Length, "characters fitted");
2081 public void MeasureString_Bug80680 ()
2084 Assert.Ignore ("Couldn't create required font");
2086 using (Bitmap bitmap = new Bitmap (20, 20)) {
2087 using (Graphics g = Graphics.FromImage (bitmap)) {
2088 string s = String.Empty;
2089 SizeF size = g.MeasureString (s, font);
2090 Assert.AreEqual (0, size.Height, "Empty.Height");
2091 Assert.AreEqual (0, size.Width, "Empty.Width");
2094 SizeF expected = g.MeasureString (s, font);
2095 for (int i = 1; i < 10; i++) {
2097 size = g.MeasureString (s, font);
2098 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2099 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2103 expected = g.MeasureString (s, font);
2105 size = g.MeasureString (s, font);
2106 float space_width = size.Width - expected.Width;
2107 for (int i = 1; i < 10; i++) {
2108 size = g.MeasureString (s, font);
2109 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2110 Assert.AreEqual (expected.Width + i * space_width, size.Width, 0.1, ">" + s + "< Width");
2115 expected = g.MeasureString (s, font);
2116 for (int i = 1; i < 10; i++) {
2118 size = g.MeasureString (s, font);
2119 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2120 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2127 public void MeasureCharacterRanges_NullOrEmptyText ()
2129 using (Bitmap bitmap = new Bitmap (20, 20)) {
2130 using (Graphics g = Graphics.FromImage (bitmap)) {
2131 Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
2132 Assert.AreEqual (0, regions.Length, "text null");
2133 regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
2134 Assert.AreEqual (0, regions.Length, "text empty");
2135 // null font is ok with null or empty string
2136 regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
2137 Assert.AreEqual (0, regions.Length, "text null/null font");
2138 regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
2139 Assert.AreEqual (0, regions.Length, "text empty/null font");
2145 public void MeasureCharacterRanges_EmptyStringFormat ()
2148 Assert.Ignore ("Couldn't create required font");
2150 using (Bitmap bitmap = new Bitmap (20, 20)) {
2151 using (Graphics g = Graphics.FromImage (bitmap)) {
2152 // string format without character ranges
2153 Region[] regions = g.MeasureCharacterRanges ("Mono", font, new RectangleF (), new StringFormat ());
2154 Assert.AreEqual (0, regions.Length, "empty stringformat");
2160 [ExpectedException (typeof (ArgumentNullException))]
2161 public void MeasureCharacterRanges_FontNull ()
2163 using (Bitmap bitmap = new Bitmap (20, 20)) {
2164 using (Graphics g = Graphics.FromImage (bitmap)) {
2165 g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
2170 [Test] // adapted from bug #78777
2171 public void MeasureCharacterRanges_TwoLines ()
2174 Assert.Ignore ("Couldn't create required font");
2176 string text = "this\nis a test";
2177 CharacterRange[] ranges = new CharacterRange[2];
2178 ranges[0] = new CharacterRange (0, 5);
2179 ranges[1] = new CharacterRange (5, 9);
2181 StringFormat string_format = new StringFormat ();
2182 string_format.FormatFlags = StringFormatFlags.NoClip;
2183 string_format.SetMeasurableCharacterRanges (ranges);
2185 using (Bitmap bitmap = new Bitmap (20, 20)) {
2186 using (Graphics g = Graphics.FromImage (bitmap)) {
2187 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2188 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2189 Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2191 Assert.AreEqual (2, regions.Length, "Length");
2192 Assert.AreEqual (regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height, "Height");
2197 private void MeasureCharacterRanges (string text, int first, int length)
2200 Assert.Ignore ("Couldn't create required font");
2202 CharacterRange[] ranges = new CharacterRange[1];
2203 ranges[0] = new CharacterRange (first, length);
2205 StringFormat string_format = new StringFormat ();
2206 string_format.FormatFlags = StringFormatFlags.NoClip;
2207 string_format.SetMeasurableCharacterRanges (ranges);
2209 using (Bitmap bitmap = new Bitmap (20, 20)) {
2210 using (Graphics g = Graphics.FromImage (bitmap)) {
2211 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2212 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2213 g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2219 [ExpectedException (typeof (ArgumentException))]
2220 public void MeasureCharacterRanges_FirstTooFar ()
2222 string text = "this\nis a test";
2223 MeasureCharacterRanges (text, text.Length, 1);
2227 [ExpectedException (typeof (ArgumentException))]
2228 public void MeasureCharacterRanges_LengthTooLong ()
2230 string text = "this\nis a test";
2231 MeasureCharacterRanges (text, 0, text.Length + 1);
2235 public void MeasureCharacterRanges_Prefix ()
2238 Assert.Ignore ("Couldn't create required font");
2240 string text = "Hello &Mono::";
2241 CharacterRange[] ranges = new CharacterRange[1];
2242 ranges[0] = new CharacterRange (5, 4);
2244 StringFormat string_format = new StringFormat ();
2245 string_format.SetMeasurableCharacterRanges (ranges);
2247 using (Bitmap bitmap = new Bitmap (20, 20)) {
2248 using (Graphics g = Graphics.FromImage (bitmap)) {
2249 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2250 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2252 // here & is part of the measure and visible
2253 string_format.HotkeyPrefix = HotkeyPrefix.None;
2254 Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2255 RectangleF bounds_none = regions[0].GetBounds (g);
2257 // here & is part of the measure (range) but visible as an underline
2258 string_format.HotkeyPrefix = HotkeyPrefix.Show;
2259 regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2260 RectangleF bounds_show = regions[0].GetBounds (g);
2261 Assert.IsTrue (bounds_show.Width < bounds_none.Width, "Show<None");
2263 // here & is part of the measure (range) but invisible
2264 string_format.HotkeyPrefix = HotkeyPrefix.Hide;
2265 regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2266 RectangleF bounds_hide = regions[0].GetBounds (g);
2267 Assert.AreEqual (bounds_hide.Width, bounds_show.Width, "Hide==None");
2273 [ExpectedException (typeof (ArgumentException))]
2274 public void MeasureCharacterRanges_NullStringFormat ()
2277 Assert.Ignore ("Couldn't create required font");
2279 using (Bitmap bitmap = new Bitmap (20, 20)) {
2280 using (Graphics g = Graphics.FromImage (bitmap)) {
2281 g.MeasureCharacterRanges ("Mono", font, new RectangleF (), null);
2287 [Category ("NotWorking")]
2288 public void MeasureCharacterRanges_StringFormat_Alignment ()
2291 Assert.Ignore ("Couldn't create required font");
2293 string text = "Hello Mono::";
2294 CharacterRange[] ranges = new CharacterRange[1];
2295 ranges[0] = new CharacterRange (5, 4);
2296 StringFormat string_format = new StringFormat ();
2297 string_format.SetMeasurableCharacterRanges (ranges);
2299 using (Bitmap bitmap = new Bitmap (20, 20)) {
2300 using (Graphics g = Graphics.FromImage (bitmap)) {
2301 string_format.Alignment = StringAlignment.Near;
2302 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2303 Assert.AreEqual (1, regions.Length, "Near.Region");
2304 RectangleF near = regions[0].GetBounds (g);
2306 string_format.Alignment = StringAlignment.Center;
2307 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2308 Assert.AreEqual (1, regions.Length, "Center.Region");
2309 RectangleF center = regions[0].GetBounds (g);
2311 string_format.Alignment = StringAlignment.Far;
2312 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2313 Assert.AreEqual (1, regions.Length, "Far.Region");
2314 RectangleF far = regions[0].GetBounds (g);
2316 Assert.IsTrue (near.X < center.X, "near-center/X");
2317 Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2318 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2319 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2321 Assert.IsTrue (center.X < far.X, "center-far/X");
2322 Assert.AreEqual (center.Y, far.Y, "center-far/Y");
2323 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2324 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2330 [Category ("NotWorking")]
2331 public void MeasureCharacterRanges_StringFormat_LineAlignment ()
2334 Assert.Ignore ("Couldn't create required font");
2336 string text = "Hello Mono::";
2337 CharacterRange[] ranges = new CharacterRange[1];
2338 ranges[0] = new CharacterRange (5, 4);
2339 StringFormat string_format = new StringFormat ();
2340 string_format.SetMeasurableCharacterRanges (ranges);
2342 using (Bitmap bitmap = new Bitmap (20, 20)) {
2343 using (Graphics g = Graphics.FromImage (bitmap)) {
2344 string_format.LineAlignment = StringAlignment.Near;
2345 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2346 Assert.AreEqual (1, regions.Length, "Near.Region");
2347 RectangleF near = regions[0].GetBounds (g);
2349 string_format.LineAlignment = StringAlignment.Center;
2350 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2351 Assert.AreEqual (1, regions.Length, "Center.Region");
2352 RectangleF center = regions[0].GetBounds (g);
2354 string_format.LineAlignment = StringAlignment.Far;
2355 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2356 Assert.AreEqual (1, regions.Length, "Far.Region");
2357 RectangleF far = regions[0].GetBounds (g);
2359 Assert.AreEqual (near.X, center.X, 0.1, "near-center/X");
2360 Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2361 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2362 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2364 Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2365 Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2366 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2367 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2373 [Category ("NotWorking")]
2374 public void MeasureCharacterRanges_StringFormat_Alignment_DirectionVertical ()
2377 Assert.Ignore ("Couldn't create required font");
2379 string text = "Hello Mono::";
2380 CharacterRange[] ranges = new CharacterRange[1];
2381 ranges[0] = new CharacterRange (5, 4);
2382 StringFormat string_format = new StringFormat ();
2383 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2384 string_format.SetMeasurableCharacterRanges (ranges);
2386 using (Bitmap bitmap = new Bitmap (20, 20)) {
2387 using (Graphics g = Graphics.FromImage (bitmap)) {
2388 string_format.Alignment = StringAlignment.Near;
2389 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2390 Assert.AreEqual (1, regions.Length, "Near.Region");
2391 RectangleF near = regions[0].GetBounds (g);
2393 string_format.Alignment = StringAlignment.Center;
2394 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2395 Assert.AreEqual (1, regions.Length, "Center.Region");
2396 RectangleF center = regions[0].GetBounds (g);
2398 string_format.Alignment = StringAlignment.Far;
2399 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2400 Assert.AreEqual (1, regions.Length, "Far.Region");
2401 RectangleF far = regions[0].GetBounds (g);
2403 Assert.IsTrue (near.X == center.X, "near-center/X"); // ???
2404 Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2405 Assert.IsTrue (near.Width == center.Width, "near-center/Width"); // ???
2406 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2408 Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2409 Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2410 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2411 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2417 [Category ("NotWorking")]
2418 public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
2421 Assert.Ignore ("Couldn't create required font");
2423 string text = "Hello Mono::";
2424 CharacterRange[] ranges = new CharacterRange[1];
2425 ranges[0] = new CharacterRange (5, 4);
2426 StringFormat string_format = new StringFormat ();
2427 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2428 string_format.SetMeasurableCharacterRanges (ranges);
2430 using (Bitmap bitmap = new Bitmap (20, 20)) {
2431 using (Graphics g = Graphics.FromImage (bitmap)) {
2432 string_format.LineAlignment = StringAlignment.Near;
2433 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2434 Assert.AreEqual (1, regions.Length, "Near.Region");
2435 RectangleF near = regions[0].GetBounds (g);
2437 string_format.LineAlignment = StringAlignment.Center;
2438 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2439 Assert.AreEqual (1, regions.Length, "Center.Region");
2440 RectangleF center = regions[0].GetBounds (g);
2442 string_format.LineAlignment = StringAlignment.Far;
2443 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2444 Assert.AreEqual (1, regions.Length, "Far.Region");
2445 RectangleF far = regions[0].GetBounds (g);
2447 Assert.IsTrue (near.X < center.X, "near-center/X");
2448 Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2449 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2450 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2452 Assert.IsTrue (center.X < far.X, "center-far/X");
2453 Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
2454 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2455 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2460 static CharacterRange [] ranges = new CharacterRange [] {
2461 new CharacterRange (0, 1),
2462 new CharacterRange (1, 1),
2463 new CharacterRange (2, 1)
2466 Region [] Measure (Graphics gfx, RectangleF rect)
2468 using (StringFormat format = StringFormat.GenericTypographic) {
2469 format.SetMeasurableCharacterRanges (ranges);
2471 using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
2472 return gfx.MeasureCharacterRanges ("abc", font, rect, format);
2478 public void Measure ()
2480 using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2481 Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
2482 Assert.AreEqual (3, zero.Length, "zero.Length");
2484 Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
2485 Assert.AreEqual (3, small.Length, "small.Length");
2486 for (int i = 0; i < 3; i++ ) {
2487 RectangleF zb = zero [i].GetBounds (gfx);
2488 RectangleF sb = small [i].GetBounds (gfx);
2489 Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
2490 Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
2491 Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
2492 Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
2495 Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
2496 Assert.AreEqual (3, max.Length, "empty.Length");
2497 for (int i = 0; i < 3; i++) {
2498 RectangleF zb = zero [i].GetBounds (gfx);
2499 RectangleF mb = max [i].GetBounds (gfx);
2500 Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
2501 Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
2502 Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
2503 Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
2509 public void MeasureLimits ()
2511 using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2512 Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
2513 Assert.AreEqual (3, min.Length, "origin.Length");
2514 for (int i = 0; i < 3; i++) {
2515 RectangleF mb = min [i].GetBounds (gfx);
2516 Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2517 Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2518 Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2519 Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2522 Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
2523 Assert.AreEqual (3, neg.Length, "neg.Length");
2524 for (int i = 0; i < 3; i++) {
2525 RectangleF mb = neg [i].GetBounds (gfx);
2526 Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2527 Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2528 Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2529 Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2535 public void DrawString_EndlessLoop_Bug77699 ()
2538 Assert.Ignore ("Couldn't create required font");
2540 using (Bitmap bitmap = new Bitmap (20, 20)) {
2541 using (Graphics g = Graphics.FromImage (bitmap)) {
2542 Rectangle rect = Rectangle.Empty;
2543 rect.Location = new Point (10, 10);
2544 rect.Size = new Size (1, 20);
2545 StringFormat fmt = new StringFormat ();
2546 fmt.Alignment = StringAlignment.Center;
2547 fmt.LineAlignment = StringAlignment.Center;
2548 fmt.FormatFlags = StringFormatFlags.NoWrap;
2549 fmt.Trimming = StringTrimming.EllipsisWord;
2550 g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2556 public void DrawString_EndlessLoop_Wrapping ()
2559 Assert.Ignore ("Couldn't create required font");
2561 using (Bitmap bitmap = new Bitmap (20, 20)) {
2562 using (Graphics g = Graphics.FromImage (bitmap)) {
2563 Rectangle rect = Rectangle.Empty;
2564 rect.Location = new Point (10, 10);
2565 rect.Size = new Size (1, 20);
2566 StringFormat fmt = new StringFormat ();
2567 fmt.Alignment = StringAlignment.Center;
2568 fmt.LineAlignment = StringAlignment.Center;
2569 fmt.Trimming = StringTrimming.EllipsisWord;
2570 g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2576 public void MeasureString_Wrapping_Dots ()
2578 HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_Wrapping_Dots");
2581 Assert.Ignore ("Couldn't create required font");
2583 string text = "this is really long text........................................... with a lot o periods.";
2584 using (Bitmap bitmap = new Bitmap (20, 20)) {
2585 using (Graphics g = Graphics.FromImage (bitmap)) {
2586 using (StringFormat format = new StringFormat ()) {
2587 format.Alignment = StringAlignment.Center;
2588 SizeF sz = g.MeasureString (text, font, 80, format);
2589 Assert.IsTrue (sz.Width < 80, "Width");
2590 Assert.IsTrue (sz.Height > font.Height * 2, "Height");
2597 public void GetReleaseHdcInternal ()
2599 using (Bitmap b = new Bitmap (10, 10)) {
2600 using (Graphics g = Graphics.FromImage (b)) {
2601 IntPtr hdc1 = g.GetHdc ();
2602 g.ReleaseHdcInternal (hdc1);
2603 IntPtr hdc2 = g.GetHdc ();
2604 g.ReleaseHdcInternal (hdc2);
2605 Assert.AreEqual (hdc1, hdc2, "hdc");
2611 [ExpectedException (typeof (ArgumentException))]
2612 public void ReleaseHdcInternal_IntPtrZero ()
2614 using (Bitmap b = new Bitmap (10, 10)) {
2615 using (Graphics g = Graphics.FromImage (b)) {
2616 g.ReleaseHdcInternal (IntPtr.Zero);
2622 [ExpectedException (typeof (ArgumentException))]
2623 public void ReleaseHdcInternal_TwoTimes ()
2625 using (Bitmap b = new Bitmap (10, 10)) {
2626 using (Graphics g = Graphics.FromImage (b)) {
2627 IntPtr hdc = g.GetHdc ();
2628 g.ReleaseHdcInternal (hdc);
2629 g.ReleaseHdcInternal (hdc);
2634 public void TestReleaseHdc ()
2636 using (Bitmap b = new Bitmap (10, 10)) {
2637 using (Graphics g = Graphics.FromImage (b)) {
2638 IntPtr hdc1 = g.GetHdc ();
2640 IntPtr hdc2 = g.GetHdc ();
2642 Assert.AreEqual (hdc1, hdc2, "hdc");
2648 [ExpectedException (typeof (ArgumentException))]
2649 public void TestReleaseHdcException ()
2651 using (Bitmap b = new Bitmap (10, 10)) {
2652 using (Graphics g = Graphics.FromImage (b)) {
2659 [ExpectedException (typeof (ArgumentException))]
2660 public void TestReleaseHdcException2 ()
2662 using (Bitmap b = new Bitmap (10, 10)) {
2663 using (Graphics g = Graphics.FromImage (b)) {
2671 public void VisibleClipBound ()
2674 using (Bitmap bmp = new Bitmap (100, 100)) {
2675 using (Graphics g = Graphics.FromImage (bmp)) {
2676 RectangleF noclip = g.VisibleClipBounds;
2677 Assert.AreEqual (0, noclip.X, "noclip.X");
2678 Assert.AreEqual (0, noclip.Y, "noclip.Y");
2679 Assert.AreEqual (100, noclip.Width, "noclip.Width");
2680 Assert.AreEqual (100, noclip.Height, "noclip.Height");
2682 // note: libgdiplus regions are precise to multiple of multiple of 8
2683 g.Clip = new Region (new RectangleF (0, 0, 32, 32));
2684 RectangleF clip = g.VisibleClipBounds;
2685 Assert.AreEqual (0, clip.X, "clip.X");
2686 Assert.AreEqual (0, clip.Y, "clip.Y");
2687 Assert.AreEqual (32, clip.Width, "clip.Width");
2688 Assert.AreEqual (32, clip.Height, "clip.Height");
2690 g.RotateTransform (90);
2691 RectangleF rotclip = g.VisibleClipBounds;
2692 Assert.AreEqual (0, rotclip.X, "rotclip.X");
2693 Assert.AreEqual (-32, rotclip.Y, "rotclip.Y");
2694 Assert.AreEqual (32, rotclip.Width, "rotclip.Width");
2695 Assert.AreEqual (32, rotclip.Height, "rotclip.Height");
2701 public void VisibleClipBound_BigClip ()
2703 using (Bitmap bmp = new Bitmap (100, 100)) {
2704 using (Graphics g = Graphics.FromImage (bmp)) {
2705 RectangleF noclip = g.VisibleClipBounds;
2706 Assert.AreEqual (0, noclip.X, "noclip.X");
2707 Assert.AreEqual (0, noclip.Y, "noclip.Y");
2708 Assert.AreEqual (100, noclip.Width, "noclip.Width");
2709 Assert.AreEqual (100, noclip.Height, "noclip.Height");
2711 // clip is larger than bitmap
2712 g.Clip = new Region (new RectangleF (0, 0, 200, 200));
2713 RectangleF clipbound = g.ClipBounds;
2714 Assert.AreEqual (0, clipbound.X, "clipbound.X");
2715 Assert.AreEqual (0, clipbound.Y, "clipbound.Y");
2716 Assert.AreEqual (200, clipbound.Width, "clipbound.Width");
2717 Assert.AreEqual (200, clipbound.Height, "clipbound.Height");
2719 RectangleF clip = g.VisibleClipBounds;
2720 Assert.AreEqual (0, clip.X, "clip.X");
2721 Assert.AreEqual (0, clip.Y, "clip.Y");
2722 Assert.AreEqual (100, clip.Width, "clip.Width");
2723 Assert.AreEqual (100, clip.Height, "clip.Height");
2725 g.RotateTransform (90);
2726 RectangleF rotclipbound = g.ClipBounds;
2727 Assert.AreEqual (0, rotclipbound.X, "rotclipbound.X");
2728 Assert.AreEqual (-200, rotclipbound.Y, "rotclipbound.Y");
2729 Assert.AreEqual (200, rotclipbound.Width, "rotclipbound.Width");
2730 Assert.AreEqual (200, rotclipbound.Height, "rotclipbound.Height");
2732 RectangleF rotclip = g.VisibleClipBounds;
2733 Assert.AreEqual (0, rotclip.X, "rotclip.X");
2734 Assert.AreEqual (-100, rotclip.Y, "rotclip.Y");
2735 Assert.AreEqual (100, rotclip.Width, "rotclip.Width");
2736 Assert.AreEqual (100, rotclip.Height, "rotclip.Height");
2742 public void Rotate ()
2744 using (Bitmap bmp = new Bitmap (100, 50)) {
2745 using (Graphics g = Graphics.FromImage (bmp)) {
2746 RectangleF vcb = g.VisibleClipBounds;
2747 Assert.AreEqual (0, vcb.X, "vcb.X");
2748 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2749 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2750 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2752 g.RotateTransform (90);
2753 RectangleF rvcb = g.VisibleClipBounds;
2754 Assert.AreEqual (0, rvcb.X, "rvcb.X");
2755 Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
2756 Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
2757 Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
2763 public void Scale ()
2765 using (Bitmap bmp = new Bitmap (100, 50)) {
2766 using (Graphics g = Graphics.FromImage (bmp)) {
2767 RectangleF vcb = g.VisibleClipBounds;
2768 Assert.AreEqual (0, vcb.X, "vcb.X");
2769 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2770 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2771 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2773 g.ScaleTransform (2, 0.5f);
2774 RectangleF svcb = g.VisibleClipBounds;
2775 Assert.AreEqual (0, svcb.X, "svcb.X");
2776 Assert.AreEqual (0, svcb.Y, "svcb.Y");
2777 Assert.AreEqual (50, svcb.Width, "svcb.Width");
2778 Assert.AreEqual (100, svcb.Height, "svcb.Height");
2784 public void Translate ()
2786 using (Bitmap bmp = new Bitmap (100, 50)) {
2787 using (Graphics g = Graphics.FromImage (bmp)) {
2788 RectangleF vcb = g.VisibleClipBounds;
2789 Assert.AreEqual (0, vcb.X, "vcb.X");
2790 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2791 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2792 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2794 g.TranslateTransform (-25, 25);
2795 RectangleF tvcb = g.VisibleClipBounds;
2796 Assert.AreEqual (25, tvcb.X, "tvcb.X");
2797 Assert.AreEqual (-25, tvcb.Y, "tvcb.Y");
2798 Assert.AreEqual (100, tvcb.Width, "tvcb.Width");
2799 Assert.AreEqual (50, tvcb.Height, "tvcb.Height");
2805 [ExpectedException (typeof (ArgumentNullException))]
2806 public void DrawIcon_NullRectangle ()
2808 using (Bitmap bmp = new Bitmap (40, 40)) {
2809 using (Graphics g = Graphics.FromImage (bmp)) {
2810 g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
2816 public void DrawIcon_IconRectangle ()
2818 using (Bitmap bmp = new Bitmap (40, 40)) {
2819 using (Graphics g = Graphics.FromImage (bmp)) {
2820 g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
2821 // Rectangle is empty when X, Y, Width and Height == 0
2822 // (yep X and Y too, RectangleF only checks for Width and Height)
2823 g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
2824 // so this one is half-empty ;-)
2825 g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
2826 // negative width or height isn't empty (for Rectangle)
2827 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2828 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2834 [ExpectedException (typeof (ArgumentNullException))]
2835 public void DrawIcon_NullIntInt ()
2837 using (Bitmap bmp = new Bitmap (40, 40)) {
2838 using (Graphics g = Graphics.FromImage (bmp)) {
2839 g.DrawIcon (null, 4, 2);
2845 public void DrawIcon_IconIntInt ()
2847 using (Bitmap bmp = new Bitmap (40, 40)) {
2848 using (Graphics g = Graphics.FromImage (bmp)) {
2849 g.DrawIcon (SystemIcons.Exclamation, 4, 2);
2850 g.DrawIcon (SystemIcons.Hand, 0, 0);
2856 [ExpectedException (typeof (ArgumentNullException))]
2857 public void DrawIconUnstretched_NullRectangle ()
2859 using (Bitmap bmp = new Bitmap (40, 40)) {
2860 using (Graphics g = Graphics.FromImage (bmp)) {
2861 g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
2867 public void DrawIconUnstretched_IconRectangle ()
2869 using (Bitmap bmp = new Bitmap (40, 40)) {
2870 using (Graphics g = Graphics.FromImage (bmp)) {
2871 g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
2872 // Rectangle is empty when X, Y, Width and Height == 0
2873 // (yep X and Y too, RectangleF only checks for Width and Height)
2874 g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
2875 // so this one is half-empty ;-)
2876 g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
2877 // negative width or height isn't empty (for Rectangle)
2878 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2879 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2885 [ExpectedException (typeof (ArgumentNullException))]
2886 public void DrawImage_NullRectangleF ()
2888 using (Bitmap bmp = new Bitmap (40, 40)) {
2889 using (Graphics g = Graphics.FromImage (bmp)) {
2890 g.DrawImage (null, new RectangleF (0, 0, 0, 0));
2896 public void DrawImage_ImageRectangleF ()
2898 using (Bitmap bmp = new Bitmap (40, 40)) {
2899 using (Graphics g = Graphics.FromImage (bmp)) {
2900 g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
2901 g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
2902 g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
2903 g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
2909 [ExpectedException (typeof (ArgumentNullException))]
2910 public void DrawImage_NullPointF ()
2912 using (Bitmap bmp = new Bitmap (40, 40)) {
2913 using (Graphics g = Graphics.FromImage (bmp)) {
2914 g.DrawImage (null, new PointF (0, 0));
2920 public void DrawImage_ImagePointF ()
2922 using (Bitmap bmp = new Bitmap (40, 40)) {
2923 using (Graphics g = Graphics.FromImage (bmp)) {
2924 g.DrawImage (bmp, new PointF (0, 0));
2930 [ExpectedException (typeof (ArgumentNullException))]
2931 public void DrawImage_NullPointFArray ()
2933 using (Bitmap bmp = new Bitmap (40, 40)) {
2934 using (Graphics g = Graphics.FromImage (bmp)) {
2935 g.DrawImage (null, new PointF[0]);
2941 [ExpectedException (typeof (ArgumentNullException))]
2942 public void DrawImage_ImagePointFArrayNull ()
2944 using (Bitmap bmp = new Bitmap (40, 40)) {
2945 using (Graphics g = Graphics.FromImage (bmp)) {
2946 g.DrawImage (bmp, (PointF[]) null);
2952 [ExpectedException (typeof (ArgumentException))]
2953 public void DrawImage_ImagePointFArrayEmpty ()
2955 using (Bitmap bmp = new Bitmap (40, 40)) {
2956 using (Graphics g = Graphics.FromImage (bmp)) {
2957 g.DrawImage (bmp, new PointF[0]);
2963 public void DrawImage_ImagePointFArray ()
2965 using (Bitmap bmp = new Bitmap (40, 40)) {
2966 using (Graphics g = Graphics.FromImage (bmp)) {
2967 g.DrawImage (bmp, new PointF[] {
2968 new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
2974 [ExpectedException (typeof (ArgumentNullException))]
2975 public void DrawImage_NullRectangle ()
2977 using (Bitmap bmp = new Bitmap (40, 40)) {
2978 using (Graphics g = Graphics.FromImage (bmp)) {
2979 g.DrawImage (null, new Rectangle (0, 0, 0, 0));
2985 public void DrawImage_ImageRectangle ()
2987 using (Bitmap bmp = new Bitmap (40, 40)) {
2988 using (Graphics g = Graphics.FromImage (bmp)) {
2989 // Rectangle is empty when X, Y, Width and Height == 0
2990 // (yep X and Y too, RectangleF only checks for Width and Height)
2991 g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
2992 // so this one is half-empty ;-)
2993 g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
2994 // negative width or height isn't empty (for Rectangle)
2995 g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
2996 g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
3002 [ExpectedException (typeof (ArgumentNullException))]
3003 public void DrawImage_NullPoint ()
3005 using (Bitmap bmp = new Bitmap (40, 40)) {
3006 using (Graphics g = Graphics.FromImage (bmp)) {
3007 g.DrawImage (null, new Point (0, 0));
3013 public void DrawImage_ImagePoint ()
3015 using (Bitmap bmp = new Bitmap (40, 40)) {
3016 using (Graphics g = Graphics.FromImage (bmp)) {
3017 g.DrawImage (bmp, new Point (0, 0));
3023 [ExpectedException (typeof (ArgumentNullException))]
3024 public void DrawImage_NullPointArray ()
3026 using (Bitmap bmp = new Bitmap (40, 40)) {
3027 using (Graphics g = Graphics.FromImage (bmp)) {
3028 g.DrawImage (null, new Point[0]);
3034 [ExpectedException (typeof (ArgumentNullException))]
3035 public void DrawImage_ImagePointArrayNull ()
3037 using (Bitmap bmp = new Bitmap (40, 40)) {
3038 using (Graphics g = Graphics.FromImage (bmp)) {
3039 g.DrawImage (bmp, (Point[]) null);
3045 [ExpectedException (typeof (ArgumentException))]
3046 public void DrawImage_ImagePointArrayEmpty ()
3048 using (Bitmap bmp = new Bitmap (40, 40)) {
3049 using (Graphics g = Graphics.FromImage (bmp)) {
3050 g.DrawImage (bmp, new Point[0]);
3056 public void DrawImage_ImagePointArray ()
3058 using (Bitmap bmp = new Bitmap (40, 40)) {
3059 using (Graphics g = Graphics.FromImage (bmp)) {
3060 g.DrawImage (bmp, new Point[] {
3061 new Point (0, 0), new Point (1, 1), new Point (2, 2) });
3067 [ExpectedException (typeof (ArgumentNullException))]
3068 public void DrawImage_NullIntInt ()
3070 using (Bitmap bmp = new Bitmap (40, 40)) {
3071 using (Graphics g = Graphics.FromImage (bmp)) {
3072 g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
3078 [ExpectedException (typeof (OverflowException))]
3079 public void DrawImage_ImageIntInt_Overflow ()
3081 using (Bitmap bmp = new Bitmap (40, 40)) {
3082 using (Graphics g = Graphics.FromImage (bmp)) {
3083 g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
3089 public void DrawImage_ImageIntInt ()
3091 using (Bitmap bmp = new Bitmap (40, 40)) {
3092 using (Graphics g = Graphics.FromImage (bmp)) {
3093 g.DrawImage (bmp, -40, -40);
3099 [ExpectedException (typeof (ArgumentNullException))]
3100 public void DrawImage_NullFloat ()
3102 using (Bitmap bmp = new Bitmap (40, 40)) {
3103 using (Graphics g = Graphics.FromImage (bmp)) {
3104 g.DrawImage (null, Single.MaxValue, Single.MinValue);
3110 [ExpectedException (typeof (OverflowException))]
3111 public void DrawImage_ImageFloatFloat_Overflow ()
3113 using (Bitmap bmp = new Bitmap (40, 40)) {
3114 using (Graphics g = Graphics.FromImage (bmp)) {
3115 g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
3121 public void DrawImage_ImageFloatFloat ()
3123 using (Bitmap bmp = new Bitmap (40, 40)) {
3124 using (Graphics g = Graphics.FromImage (bmp)) {
3125 g.DrawImage (bmp, -40.0f, -40.0f);
3131 [ExpectedException (typeof (ArgumentNullException))]
3132 public void DrawImage_NullRectangleRectangleGraphicsUnit ()
3134 using (Bitmap bmp = new Bitmap (40, 40)) {
3135 using (Graphics g = Graphics.FromImage (bmp)) {
3136 g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
3141 private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
3143 using (Bitmap bmp = new Bitmap (40, 40)) {
3144 using (Graphics g = Graphics.FromImage (bmp)) {
3145 Rectangle r = new Rectangle (0, 0, 40, 40);
3146 g.DrawImage (bmp, r, r, unit);
3152 [ExpectedException (typeof (ArgumentException))]
3153 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
3155 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
3159 [ExpectedException (typeof (NotImplementedException))]
3160 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
3162 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
3166 [ExpectedException (typeof (NotImplementedException))]
3167 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
3169 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
3173 [ExpectedException (typeof (NotImplementedException))]
3174 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
3176 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
3180 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
3183 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
3187 [ExpectedException (typeof (NotImplementedException))]
3188 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
3190 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
3194 [ExpectedException (typeof (ArgumentException))]
3195 public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
3197 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
3201 [ExpectedException (typeof (ArgumentNullException))]
3202 public void DrawImage_NullPointRectangleGraphicsUnit ()
3204 Rectangle r = new Rectangle (1, 2, 3, 4);
3205 Point[] pts = new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) };
3206 using (Bitmap bmp = new Bitmap (40, 40)) {
3207 using (Graphics g = Graphics.FromImage (bmp)) {
3208 g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3213 private void DrawImage_ImagePointRectangleGraphicsUnit (Point[] pts)
3215 Rectangle r = new Rectangle (1, 2, 3, 4);
3216 using (Bitmap bmp = new Bitmap (40, 40)) {
3217 using (Graphics g = Graphics.FromImage (bmp)) {
3218 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3224 [ExpectedException (typeof (ArgumentNullException))]
3225 public void DrawImage_ImageNullRectangleGraphicsUnit ()
3227 DrawImage_ImagePointRectangleGraphicsUnit (null);
3231 [ExpectedException (typeof (ArgumentException))]
3232 public void DrawImage_ImagePoint0RectangleGraphicsUnit ()
3234 DrawImage_ImagePointRectangleGraphicsUnit (new Point[0]);
3238 [ExpectedException (typeof (ArgumentException))]
3239 public void DrawImage_ImagePoint1RectangleGraphicsUnit ()
3241 Point p = new Point (1, 1);
3242 DrawImage_ImagePointRectangleGraphicsUnit (new Point[1] { p });
3246 [ExpectedException (typeof (ArgumentException))]
3247 public void DrawImage_ImagePoint2RectangleGraphicsUnit ()
3249 Point p = new Point (1, 1);
3250 DrawImage_ImagePointRectangleGraphicsUnit (new Point[2] { p, p });
3254 public void DrawImage_ImagePoint3RectangleGraphicsUnit ()
3256 Point p = new Point (1, 1);
3257 DrawImage_ImagePointRectangleGraphicsUnit (new Point[3] { p, p, p });
3261 [ExpectedException (typeof (NotImplementedException))]
3262 public void DrawImage_ImagePoint4RectangleGraphicsUnit ()
3264 Point p = new Point (1, 1);
3265 DrawImage_ImagePointRectangleGraphicsUnit (new Point[4] { p, p, p, p });
3269 [ExpectedException (typeof (ArgumentNullException))]
3270 public void DrawImage_NullPointFRectangleGraphicsUnit ()
3272 Rectangle r = new Rectangle (1, 2, 3, 4);
3273 PointF[] pts = new PointF[3] { new PointF (1, 1), new PointF (2, 2), new PointF (3, 3) };
3274 using (Bitmap bmp = new Bitmap (40, 40)) {
3275 using (Graphics g = Graphics.FromImage (bmp)) {
3276 g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3281 private void DrawImage_ImagePointFRectangleGraphicsUnit (PointF[] pts)
3283 Rectangle r = new Rectangle (1, 2, 3, 4);
3284 using (Bitmap bmp = new Bitmap (40, 40)) {
3285 using (Graphics g = Graphics.FromImage (bmp)) {
3286 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3292 [ExpectedException (typeof (ArgumentNullException))]
3293 public void DrawImage_ImageNullFRectangleGraphicsUnit ()
3295 DrawImage_ImagePointFRectangleGraphicsUnit (null);
3299 [ExpectedException (typeof (ArgumentException))]
3300 public void DrawImage_ImagePointF0RectangleGraphicsUnit ()
3302 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[0]);
3306 [ExpectedException (typeof (ArgumentException))]
3307 public void DrawImage_ImagePointF1RectangleGraphicsUnit ()
3309 PointF p = new PointF (1, 1);
3310 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[1] { p });
3314 [ExpectedException (typeof (ArgumentException))]
3315 public void DrawImage_ImagePointF2RectangleGraphicsUnit ()
3317 PointF p = new PointF (1, 1);
3318 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[2] { p, p });
3322 public void DrawImage_ImagePointF3RectangleGraphicsUnit ()
3324 PointF p = new PointF (1, 1);
3325 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[3] { p, p, p });
3329 [ExpectedException (typeof (NotImplementedException))]
3330 public void DrawImage_ImagePointF4RectangleGraphicsUnit ()
3332 PointF p = new PointF (1, 1);
3333 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[4] { p, p, p, p });
3337 public void DrawImage_ImagePointRectangleGraphicsUnitNull ()
3339 Point p = new Point (1, 1);
3340 Point[] pts = new Point[3] { p, p, p };
3341 Rectangle r = new Rectangle (1, 2, 3, 4);
3342 using (Bitmap bmp = new Bitmap (40, 40)) {
3343 using (Graphics g = Graphics.FromImage (bmp)) {
3344 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, null);
3350 public void DrawImage_ImagePointRectangleGraphicsUnitAttributes ()
3352 Point p = new Point (1, 1);
3353 Point[] pts = new Point[3] { p, p, p };
3354 Rectangle r = new Rectangle (1, 2, 3, 4);
3355 using (Bitmap bmp = new Bitmap (40, 40)) {
3356 using (Graphics g = Graphics.FromImage (bmp)) {
3357 ImageAttributes ia = new ImageAttributes ();
3358 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, ia);
3364 [ExpectedException (typeof (ArgumentNullException))]
3365 public void DrawImageUnscaled_NullPoint ()
3367 using (Bitmap bmp = new Bitmap (40, 40)) {
3368 using (Graphics g = Graphics.FromImage (bmp)) {
3369 g.DrawImageUnscaled (null, new Point (0, 0));
3375 public void DrawImageUnscaled_ImagePoint ()
3377 using (Bitmap bmp = new Bitmap (40, 40)) {
3378 using (Graphics g = Graphics.FromImage (bmp)) {
3379 g.DrawImageUnscaled (bmp, new Point (0, 0));
3385 [ExpectedException (typeof (ArgumentNullException))]
3386 public void DrawImageUnscaled_NullRectangle ()
3388 using (Bitmap bmp = new Bitmap (40, 40)) {
3389 using (Graphics g = Graphics.FromImage (bmp)) {
3390 g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
3396 public void DrawImageUnscaled_ImageRectangle ()
3398 using (Bitmap bmp = new Bitmap (40, 40)) {
3399 using (Graphics g = Graphics.FromImage (bmp)) {
3400 g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
3406 [ExpectedException (typeof (ArgumentNullException))]
3407 public void DrawImageUnscaled_NullIntInt ()
3409 using (Bitmap bmp = new Bitmap (40, 40)) {
3410 using (Graphics g = Graphics.FromImage (bmp)) {
3411 g.DrawImageUnscaled (null, 0, 0);
3417 public void DrawImageUnscaled_ImageIntInt ()
3419 using (Bitmap bmp = new Bitmap (40, 40)) {
3420 using (Graphics g = Graphics.FromImage (bmp)) {
3421 g.DrawImageUnscaled (bmp, 0, 0);
3427 [ExpectedException (typeof (ArgumentNullException))]
3428 public void DrawImageUnscaled_NullIntIntIntInt ()
3430 using (Bitmap bmp = new Bitmap (40, 40)) {
3431 using (Graphics g = Graphics.FromImage (bmp)) {
3432 g.DrawImageUnscaled (null, 0, 0, -1, -1);
3438 public void DrawImageUnscaled_ImageIntIntIntInt ()
3440 using (Bitmap bmp = new Bitmap (40, 40)) {
3441 using (Graphics g = Graphics.FromImage (bmp)) {
3442 g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
3447 [ExpectedException (typeof (ArgumentNullException))]
3448 public void DrawImageUnscaledAndClipped_Null ()
3450 using (Bitmap bmp = new Bitmap (40, 40)) {
3451 using (Graphics g = Graphics.FromImage (bmp)) {
3452 g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
3458 public void DrawImageUnscaledAndClipped ()
3460 using (Bitmap bmp = new Bitmap (40, 40)) {
3461 using (Graphics g = Graphics.FromImage (bmp)) {
3462 // Rectangle is empty when X, Y, Width and Height == 0
3463 // (yep X and Y too, RectangleF only checks for Width and Height)
3464 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
3465 // so this one is half-empty ;-)
3466 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
3467 // negative width or height isn't empty (for Rectangle)
3468 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
3469 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
3471 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
3472 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
3473 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
3479 [ExpectedException (typeof (ArgumentNullException))]
3480 public void DrawPath_Pen_Null ()
3482 using (Bitmap bmp = new Bitmap (20, 20)) {
3483 using (Graphics g = Graphics.FromImage (bmp)) {
3484 using (GraphicsPath path = new GraphicsPath ()) {
3485 g.DrawPath (null, path);
3492 [ExpectedException (typeof (ArgumentNullException))]
3493 public void DrawPath_Path_Null ()
3495 using (Bitmap bmp = new Bitmap (20, 20)) {
3496 using (Graphics g = Graphics.FromImage (bmp)) {
3497 g.DrawPath (Pens.Black, null);
3503 public void DrawPath_82202 ()
3505 // based on test case from bug #82202
3506 using (Bitmap bmp = new Bitmap (20, 20)) {
3507 using (Graphics g = Graphics.FromImage (bmp)) {
3508 using (GraphicsPath path = new GraphicsPath ()) {
3510 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3511 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3513 path.AddArc (arcrect, 180, 90);
3514 arcrect.X = baserect.Right - d;
3515 path.AddArc (arcrect, 270, 90);
3516 arcrect.Y = baserect.Bottom - d;
3517 path.AddArc (arcrect, 0, 90);
3518 arcrect.X = baserect.Left;
3519 path.AddArc (arcrect, 90, 90);
3520 path.CloseFigure ();
3521 g.Clear (Color.White);
3522 g.DrawPath (Pens.SteelBlue, path);
3524 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3525 Assert.AreEqual (-1, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3532 [ExpectedException (typeof (ArgumentNullException))]
3533 public void FillPath_Brush_Null ()
3535 using (Bitmap bmp = new Bitmap (20, 20)) {
3536 using (Graphics g = Graphics.FromImage (bmp)) {
3537 using (GraphicsPath path = new GraphicsPath ()) {
3538 g.FillPath (null, path);
3545 [ExpectedException (typeof (ArgumentNullException))]
3546 public void FillPath_Path_Null ()
3548 using (Bitmap bmp = new Bitmap (20, 20)) {
3549 using (Graphics g = Graphics.FromImage (bmp)) {
3550 g.FillPath (Brushes.Black, null);
3556 public void FillPath_82202 ()
3558 // based on test case from bug #82202
3559 using (Bitmap bmp = new Bitmap (20, 20)) {
3560 using (Graphics g = Graphics.FromImage (bmp)) {
3561 using (GraphicsPath path = new GraphicsPath ()) {
3563 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3564 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3566 path.AddArc (arcrect, 180, 90);
3567 arcrect.X = baserect.Right - d;
3568 path.AddArc (arcrect, 270, 90);
3569 arcrect.Y = baserect.Bottom - d;
3570 path.AddArc (arcrect, 0, 90);
3571 arcrect.X = baserect.Left;
3572 path.AddArc (arcrect, 90, 90);
3573 path.CloseFigure ();
3574 g.Clear (Color.White);
3575 g.FillPath (Brushes.SteelBlue, path);
3577 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3578 Assert.AreEqual (-12156236, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3585 public void TransformPoints_349800 ()
3587 using (Bitmap bmp = new Bitmap (10, 10)) {
3588 using (Graphics g = Graphics.FromImage (bmp)) {
3589 Point [] pts = new Point [5];
3590 PointF [] ptf = new PointF [5];
3591 for (int i = 0; i < 5; i++) {
3592 pts [i] = new Point (i, i);
3593 ptf [i] = new PointF (i, i);
3596 g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, pts);
3597 g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, ptf);
3599 for (int i = 0; i < 5; i++) {
3600 Assert.AreEqual (i, pts [i].X, "Point.X " + i.ToString ());
3601 Assert.AreEqual (i, pts [i].Y, "Point.Y " + i.ToString ());
3602 Assert.AreEqual (i, ptf [i].X, "PointF.X " + i.ToString ());
3603 Assert.AreEqual (i, ptf [i].Y, "PointF.Y " + i.ToString ());
3610 public void Dpi_556181 ()
3613 using (Bitmap bmp = new Bitmap (10, 10)) {
3614 using (Graphics g = Graphics.FromImage (bmp)) {
3618 bmp.SetResolution (x, y);
3619 using (Graphics g = Graphics.FromImage (bmp)) {
3620 Assert.AreEqual (x, g.DpiX, "DpiX");
3621 Assert.AreEqual (y, g.DpiY, "DpiY");
3628 public class GraphicsFullTrustTest {
3630 // note: this test would fail, on ReleaseHdc, without fulltrust
3631 // i.e. it's a demand and not a linkdemand
3633 public void GetReleaseHdc ()
3635 using (Bitmap b = new Bitmap (100, 100)) {
3636 using (Graphics g = Graphics.FromImage (b)) {
3637 IntPtr hdc1 = g.GetHdc ();
3638 g.ReleaseHdc (hdc1);
3639 IntPtr hdc2 = g.GetHdc ();
3640 g.ReleaseHdc (hdc2);
3641 Assert.AreEqual (hdc1, hdc2, "hdc");