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);
1240 [ExpectedException (typeof (ArgumentNullException))]
1242 [ExpectedException (typeof (NullReferenceException))]
1244 public void EndContainer_Null ()
1246 Bitmap bitmap = new Bitmap (20, 20);
1247 Graphics g = Graphics.FromImage (bitmap);
1248 g.EndContainer (null);
1254 Bitmap bitmap = new Bitmap (20, 20);
1255 Graphics g = Graphics.FromImage (bitmap);
1257 CheckDefaultProperties ("default", g);
1258 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1260 GraphicsState gs1 = g.Save ();
1261 // nothing is changed after a save
1262 CheckDefaultProperties ("save1", g);
1263 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "save1.RenderingOrigin");
1265 g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1266 g.CompositingMode = CompositingMode.SourceCopy;
1267 g.CompositingQuality = CompositingQuality.HighQuality;
1268 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1270 g.PageUnit = GraphicsUnit.Inch;
1271 g.PixelOffsetMode = PixelOffsetMode.Half;
1272 g.RenderingOrigin = new Point (-1, -1);
1273 g.RotateTransform (45);
1274 g.SmoothingMode = SmoothingMode.AntiAlias;
1276 g.TextRenderingHint = TextRenderingHint.AntiAlias;
1277 CheckCustomProperties ("modified", g);
1278 CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1280 GraphicsState gs2 = g.Save ();
1281 CheckCustomProperties ("save2", g);
1284 CheckCustomProperties ("restored1", g);
1285 CheckMatrix ("restored1.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1288 CheckDefaultProperties ("restored2", g);
1289 Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "restored2.RenderingOrigin");
1293 [ExpectedException (typeof (NullReferenceException))]
1294 public void Restore_Null ()
1296 Bitmap bitmap = new Bitmap (20, 20);
1297 Graphics g = Graphics.FromImage (bitmap);
1302 [ExpectedException (typeof (ArgumentNullException))]
1303 public void FillRectangles_BrushNull_Rectangle ()
1305 using (Bitmap bitmap = new Bitmap (20, 20)) {
1306 using (Graphics g = Graphics.FromImage (bitmap)) {
1307 g.FillRectangles (null, new Rectangle[1]);
1313 [ExpectedException (typeof (ArgumentNullException))]
1314 public void FillRectangles_Rectangle_Null ()
1316 using (Bitmap bitmap = new Bitmap (20, 20)) {
1317 using (Graphics g = Graphics.FromImage (bitmap)) {
1318 g.FillRectangles (Brushes.Red, (Rectangle[]) null);
1323 [Test] // see bug #78408
1324 [ExpectedException (typeof (ArgumentException))]
1325 public void FillRectanglesZeroRectangle ()
1327 using (Bitmap bitmap = new Bitmap (20, 20)) {
1328 using (Graphics g = Graphics.FromImage (bitmap)) {
1329 g.FillRectangles (Brushes.Red, new Rectangle[0]);
1335 [ExpectedException (typeof (ArgumentNullException))]
1336 public void FillRectangles_BrushNull_RectangleF ()
1338 using (Bitmap bitmap = new Bitmap (20, 20)) {
1339 using (Graphics g = Graphics.FromImage (bitmap)) {
1340 g.FillRectangles (null, new RectangleF[1]);
1346 [ExpectedException (typeof (ArgumentNullException))]
1347 public void FillRectangles_RectangleF_Null ()
1349 using (Bitmap bitmap = new Bitmap (20, 20)) {
1350 using (Graphics g = Graphics.FromImage (bitmap)) {
1351 g.FillRectangles (Brushes.Red, (RectangleF[]) null);
1356 [Test] // see bug #78408
1357 [ExpectedException (typeof (ArgumentException))]
1358 public void FillRectanglesZeroRectangleF ()
1360 using (Bitmap bitmap = new Bitmap (20, 20)) {
1361 using (Graphics g = Graphics.FromImage (bitmap)) {
1362 g.FillRectangles (Brushes.Red, new RectangleF[0]);
1368 public void FillRectangles_NormalBehavior ()
1370 using (Bitmap bitmap = new Bitmap (20, 20)) {
1371 using (Graphics g = Graphics.FromImage (bitmap)) {
1372 g.Clear (Color.Fuchsia);
1373 Rectangle rect = new Rectangle (5, 5, 10, 10);
1374 g.Clip = new Region (rect);
1375 g.FillRectangle (Brushes.Red, rect);
1377 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1378 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1379 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1380 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1382 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1383 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1384 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1388 // see bug #81737 for details
1389 private Bitmap FillDrawRectangle (float width)
1391 Bitmap bitmap = new Bitmap (20, 20);
1392 using (Graphics g = Graphics.FromImage (bitmap)) {
1393 g.Clear (Color.Red);
1394 Rectangle rect = new Rectangle (5, 5, 10, 10);
1395 g.FillRectangle (Brushes.Green, rect);
1397 using (Pen pen = new Pen (Color.Blue, width)) {
1398 g.DrawRectangle (pen, rect);
1401 g.DrawRectangle (Pens.Blue, rect);
1408 public void FillDrawRectangle_Width_Default ()
1411 using (Bitmap bitmap = FillDrawRectangle (Single.MinValue)) {
1413 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1414 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1415 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1417 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1418 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1419 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1421 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1422 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1423 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1425 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1426 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1427 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1429 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1430 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1431 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1433 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1434 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1435 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1437 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1438 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1439 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1441 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1442 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1443 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1448 [Category ("NotOnMac")]
1449 public void FillDrawRectangle_Width_2 ()
1452 using (Bitmap bitmap = FillDrawRectangle (2.0f)) {
1454 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1455 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1456 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1457 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1459 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1460 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1461 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1462 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1464 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1465 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1466 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1467 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1469 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1470 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1471 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1472 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1474 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1475 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1476 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1477 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1479 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1480 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1481 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1482 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1484 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "3,16");
1485 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "4,15");
1486 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1487 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 13).ToArgb (), "6,13");
1489 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1490 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1491 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1492 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1497 public void FillDrawRectangle_Width_3 ()
1500 using (Bitmap bitmap = FillDrawRectangle (3.0f)) {
1502 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1503 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1504 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1505 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1506 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 7).ToArgb (), "7,7");
1508 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1509 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1510 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1511 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1512 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 7).ToArgb (), "9,7");
1514 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1515 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1516 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1517 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1518 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1520 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1521 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1522 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1523 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1524 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1526 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1527 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1528 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1529 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1530 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1532 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1533 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1534 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1535 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1536 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1538 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1539 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1540 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1541 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1542 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 13).ToArgb (), "7,13");
1544 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1545 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1546 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1547 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1548 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 9).ToArgb (), "7,9");
1552 // reverse, draw the fill over
1553 private Bitmap DrawFillRectangle (float width)
1555 Bitmap bitmap = new Bitmap (20, 20);
1556 using (Graphics g = Graphics.FromImage (bitmap)) {
1557 g.Clear (Color.Red);
1558 Rectangle rect = new Rectangle (5, 5, 10, 10);
1560 using (Pen pen = new Pen (Color.Blue, width)) {
1561 g.DrawRectangle (pen, rect);
1564 g.DrawRectangle (Pens.Blue, rect);
1566 g.FillRectangle (Brushes.Green, rect);
1572 public void DrawFillRectangle_Width_Default ()
1575 using (Bitmap bitmap = DrawFillRectangle (Single.MinValue)) {
1576 // NW - no blue border
1577 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1578 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1579 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1580 // N - no blue border
1581 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1582 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1583 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1585 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1586 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1587 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1589 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1590 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1591 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1593 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1594 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1595 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1597 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1598 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1599 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1601 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1602 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1603 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1604 // W - no blue border
1605 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1606 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1607 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1612 [Category ("NotOnMac")]
1613 public void DrawFillRectangle_Width_2 ()
1616 using (Bitmap bitmap = DrawFillRectangle (2.0f)) {
1617 // looks like a one pixel border - but enlarged
1619 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1620 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1621 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1623 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1624 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1625 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1627 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1628 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1629 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1631 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1632 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1633 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1635 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1636 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1637 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1639 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1640 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1641 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1643 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "4,16");
1644 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "5,15");
1645 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 14).ToArgb (), "6,14");
1647 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1648 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1649 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1654 public void DrawFillRectangle_Width_3 ()
1657 using (Bitmap bitmap = DrawFillRectangle (3.0f)) {
1659 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1660 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1661 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1663 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1664 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1665 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1667 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1668 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1669 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1670 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1672 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1673 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1674 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1675 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1677 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1678 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1679 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1680 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1682 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1683 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1684 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1685 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1687 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1688 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1689 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1690 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1692 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1693 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1694 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1698 private Bitmap DrawLines (float width)
1700 Bitmap bitmap = new Bitmap (20, 20);
1701 using (Graphics g = Graphics.FromImage (bitmap)) {
1702 g.Clear (Color.Red);
1703 Point[] pts = new Point[3] { new Point (5, 5), new Point (15, 5), new Point (15, 15) };
1705 using (Pen pen = new Pen (Color.Blue, width)) {
1706 g.DrawLines (pen, pts);
1709 g.DrawLines (Pens.Blue, pts);
1716 public void DrawLines_Width_Default ()
1719 using (Bitmap bitmap = DrawLines (Single.MinValue)) {
1721 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1722 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1723 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1724 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1725 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1726 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1728 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1729 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1730 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1731 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1732 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1733 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1734 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1735 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1736 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1738 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1739 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1740 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1741 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 16).ToArgb (), "14,16");
1742 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 16).ToArgb (), "15,16");
1743 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1748 [Category ("NotWorking")]
1749 public void DrawLines_Width_2 ()
1752 using (Bitmap bitmap = DrawLines (2.0f)) {
1754 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1755 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1756 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1757 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1758 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1759 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1760 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1761 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1763 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1764 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1765 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1766 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1767 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1768 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1769 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1770 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1771 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1772 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1773 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1774 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1775 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1776 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1777 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1778 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1780 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1781 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1782 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1783 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1784 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1785 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1786 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1787 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1792 [Category ("NotWorking")]
1793 public void DrawLines_Width_3 ()
1796 using (Bitmap bitmap = DrawLines (3.0f)) {
1798 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1799 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1800 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1801 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1802 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 7).ToArgb (), "4,7");
1803 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1804 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1805 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1806 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1807 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 7).ToArgb (), "5,7");
1809 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1810 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1811 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1812 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1813 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1814 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1815 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1816 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1817 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1818 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 7).ToArgb (), "14,7");
1819 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1820 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1821 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1822 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1823 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 7).ToArgb (), "15,7");
1824 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1825 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1826 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1827 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1828 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 7).ToArgb (), "16,7");
1829 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1830 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 4).ToArgb (), "17,4");
1831 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 5).ToArgb (), "17,5");
1832 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 6).ToArgb (), "17,6");
1833 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 7).ToArgb (), "17,7");
1835 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1836 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1837 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1838 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1839 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 14).ToArgb (), "17,14");
1840 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1841 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1842 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1843 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1844 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 15).ToArgb (), "17,15");
1849 public void MeasureString_StringFont ()
1851 using (Bitmap bitmap = new Bitmap (20, 20)) {
1852 using (Graphics g = Graphics.FromImage (bitmap)) {
1853 SizeF size = g.MeasureString (null, font);
1854 Assert.IsTrue (size.IsEmpty, "MeasureString(null,font)");
1855 size = g.MeasureString (String.Empty, font);
1856 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font)");
1858 size = g.MeasureString (null, null);
1859 Assert.IsTrue (size.IsEmpty, "MeasureString(null,null)");
1860 size = g.MeasureString (String.Empty, null);
1861 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,null)");
1867 [ExpectedException (typeof (ArgumentNullException))]
1868 public void MeasureString_StringFont_Null ()
1870 using (Bitmap bitmap = new Bitmap (20, 20)) {
1871 using (Graphics g = Graphics.FromImage (bitmap)) {
1872 g.MeasureString ("a", null);
1878 public void MeasureString_StringFontSizeF ()
1881 Assert.Ignore ("Couldn't create required font");
1883 using (Bitmap bitmap = new Bitmap (20, 20)) {
1884 using (Graphics g = Graphics.FromImage (bitmap)) {
1885 SizeF size = g.MeasureString ("a", font, SizeF.Empty);
1886 Assert.IsFalse (size.IsEmpty, "MeasureString(a,font,empty)");
1888 size = g.MeasureString (String.Empty, font, SizeF.Empty);
1889 Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font,empty)");
1894 private void MeasureString_StringFontInt (string s)
1897 Assert.Ignore ("Couldn't create required font");
1899 using (Bitmap bitmap = new Bitmap (20, 20)) {
1900 using (Graphics g = Graphics.FromImage (bitmap)) {
1901 SizeF size0 = g.MeasureString (s, font, 0);
1902 SizeF sizeN = g.MeasureString (s, font, Int32.MinValue);
1903 SizeF sizeP = g.MeasureString (s, font, Int32.MaxValue);
1904 Assert.AreEqual (size0, sizeN, "0-Min");
1905 Assert.AreEqual (size0, sizeP, "0-Max");
1911 public void MeasureString_StringFontInt_ShortString ()
1913 MeasureString_StringFontInt ("a");
1917 public void MeasureString_StringFontInt_LongString ()
1919 HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_StringFontInt_LongString");
1920 MeasureString_StringFontInt ("A very long string..."); // see bug #79643
1924 public void MeasureString_StringFormat_Alignment ()
1927 Assert.Ignore ("Couldn't create required font");
1929 string text = "Hello Mono::";
1930 StringFormat string_format = new StringFormat ();
1932 using (Bitmap bitmap = new Bitmap (20, 20)) {
1933 using (Graphics g = Graphics.FromImage (bitmap)) {
1934 string_format.Alignment = StringAlignment.Near;
1935 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1937 string_format.Alignment = StringAlignment.Center;
1938 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1940 string_format.Alignment = StringAlignment.Far;
1941 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1943 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1944 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1946 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1947 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1953 public void MeasureString_StringFormat_Alignment_DirectionVertical ()
1956 Assert.Ignore ("Couldn't create required font");
1958 string text = "Hello Mono::";
1959 StringFormat string_format = new StringFormat ();
1960 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1962 using (Bitmap bitmap = new Bitmap (20, 20)) {
1963 using (Graphics g = Graphics.FromImage (bitmap)) {
1964 string_format.Alignment = StringAlignment.Near;
1965 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1967 string_format.Alignment = StringAlignment.Center;
1968 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1970 string_format.Alignment = StringAlignment.Far;
1971 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1973 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1974 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1976 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1977 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1983 public void MeasureString_StringFormat_LineAlignment ()
1986 Assert.Ignore ("Couldn't create required font");
1988 string text = "Hello Mono::";
1989 StringFormat string_format = new StringFormat ();
1991 using (Bitmap bitmap = new Bitmap (20, 20)) {
1992 using (Graphics g = Graphics.FromImage (bitmap)) {
1993 string_format.LineAlignment = StringAlignment.Near;
1994 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1996 string_format.LineAlignment = StringAlignment.Center;
1997 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1999 string_format.LineAlignment = StringAlignment.Far;
2000 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2002 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2003 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2005 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2006 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2012 public void MeasureString_StringFormat_LineAlignment_DirectionVertical ()
2015 Assert.Ignore ("Couldn't create required font");
2017 string text = "Hello Mono::";
2018 StringFormat string_format = new StringFormat ();
2019 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2021 using (Bitmap bitmap = new Bitmap (20, 20)) {
2022 using (Graphics g = Graphics.FromImage (bitmap)) {
2023 string_format.LineAlignment = StringAlignment.Near;
2024 SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
2026 string_format.LineAlignment = StringAlignment.Center;
2027 SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
2029 string_format.LineAlignment = StringAlignment.Far;
2030 SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2032 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2033 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2035 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2036 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2042 public void MeasureString_MultlineString_Width ()
2044 using (Bitmap bitmap = new Bitmap (20, 20)) {
2045 using (Graphics g = Graphics.FromImage (bitmap)) {
2046 StringFormat string_format = new StringFormat ();
2048 string text1 = "Test\nTest123\nTest 456\nTest 1,2,3,4,5...";
2049 string text2 = "Test 1,2,3,4,5...";
2051 SizeF size1 = g.MeasureString (text1, font, SizeF.Empty, string_format);
2052 SizeF size2 = g.MeasureString (text2, font, SizeF.Empty, string_format);
2054 Assert.AreEqual ((int) size1.Width, (int) size2.Width, "Multiline Text Width");
2060 public void MeasureString_Bug76664 ()
2063 Assert.Ignore ("Couldn't create required font");
2065 using (Bitmap bitmap = new Bitmap (20, 20)) {
2066 using (Graphics g = Graphics.FromImage (bitmap)) {
2067 string s = "aaa aa aaaa a aaa";
2068 SizeF size = g.MeasureString (s, font);
2071 SizeF size2 = g.MeasureString (s, font, new SizeF (80, size.Height), null, out chars, out lines);
2074 Assert.IsTrue (size2.Width < size.Width, "Width/pixel");
2075 Assert.AreEqual (size2.Height, size.Height, "Height/pixel");
2077 Assert.AreEqual (1, lines, "lines fitted");
2078 // LAMESPEC: documentation seems to suggest chars is total length
2079 Assert.IsTrue (chars < s.Length, "characters fitted");
2085 public void MeasureString_Bug80680 ()
2088 Assert.Ignore ("Couldn't create required font");
2090 using (Bitmap bitmap = new Bitmap (20, 20)) {
2091 using (Graphics g = Graphics.FromImage (bitmap)) {
2092 string s = String.Empty;
2093 SizeF size = g.MeasureString (s, font);
2094 Assert.AreEqual (0, size.Height, "Empty.Height");
2095 Assert.AreEqual (0, size.Width, "Empty.Width");
2098 SizeF expected = g.MeasureString (s, font);
2099 for (int i = 1; i < 10; i++) {
2101 size = g.MeasureString (s, font);
2102 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2103 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2107 expected = g.MeasureString (s, font);
2109 size = g.MeasureString (s, font);
2110 float space_width = size.Width - expected.Width;
2111 for (int i = 1; i < 10; i++) {
2112 size = g.MeasureString (s, font);
2113 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2114 Assert.AreEqual (expected.Width + i * space_width, size.Width, 0.1, ">" + s + "< Width");
2119 expected = g.MeasureString (s, font);
2120 for (int i = 1; i < 10; i++) {
2122 size = g.MeasureString (s, font);
2123 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2124 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2131 public void MeasureCharacterRanges_NullOrEmptyText ()
2133 using (Bitmap bitmap = new Bitmap (20, 20)) {
2134 using (Graphics g = Graphics.FromImage (bitmap)) {
2135 Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
2136 Assert.AreEqual (0, regions.Length, "text null");
2137 regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
2138 Assert.AreEqual (0, regions.Length, "text empty");
2139 // null font is ok with null or empty string
2140 regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
2141 Assert.AreEqual (0, regions.Length, "text null/null font");
2142 regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
2143 Assert.AreEqual (0, regions.Length, "text empty/null font");
2149 public void MeasureCharacterRanges_EmptyStringFormat ()
2152 Assert.Ignore ("Couldn't create required font");
2154 using (Bitmap bitmap = new Bitmap (20, 20)) {
2155 using (Graphics g = Graphics.FromImage (bitmap)) {
2156 // string format without character ranges
2157 Region[] regions = g.MeasureCharacterRanges ("Mono", font, new RectangleF (), new StringFormat ());
2158 Assert.AreEqual (0, regions.Length, "empty stringformat");
2164 [ExpectedException (typeof (ArgumentNullException))]
2165 public void MeasureCharacterRanges_FontNull ()
2167 using (Bitmap bitmap = new Bitmap (20, 20)) {
2168 using (Graphics g = Graphics.FromImage (bitmap)) {
2169 g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
2174 [Test] // adapted from bug #78777
2175 public void MeasureCharacterRanges_TwoLines ()
2178 Assert.Ignore ("Couldn't create required font");
2180 string text = "this\nis a test";
2181 CharacterRange[] ranges = new CharacterRange[2];
2182 ranges[0] = new CharacterRange (0, 5);
2183 ranges[1] = new CharacterRange (5, 9);
2185 StringFormat string_format = new StringFormat ();
2186 string_format.FormatFlags = StringFormatFlags.NoClip;
2187 string_format.SetMeasurableCharacterRanges (ranges);
2189 using (Bitmap bitmap = new Bitmap (20, 20)) {
2190 using (Graphics g = Graphics.FromImage (bitmap)) {
2191 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2192 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2193 Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2195 Assert.AreEqual (2, regions.Length, "Length");
2196 Assert.AreEqual (regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height, "Height");
2201 private void MeasureCharacterRanges (string text, int first, int length)
2204 Assert.Ignore ("Couldn't create required font");
2206 CharacterRange[] ranges = new CharacterRange[1];
2207 ranges[0] = new CharacterRange (first, length);
2209 StringFormat string_format = new StringFormat ();
2210 string_format.FormatFlags = StringFormatFlags.NoClip;
2211 string_format.SetMeasurableCharacterRanges (ranges);
2213 using (Bitmap bitmap = new Bitmap (20, 20)) {
2214 using (Graphics g = Graphics.FromImage (bitmap)) {
2215 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2216 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2217 g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2223 [ExpectedException (typeof (ArgumentException))]
2224 public void MeasureCharacterRanges_FirstTooFar ()
2226 string text = "this\nis a test";
2227 MeasureCharacterRanges (text, text.Length, 1);
2231 [ExpectedException (typeof (ArgumentException))]
2232 public void MeasureCharacterRanges_LengthTooLong ()
2234 string text = "this\nis a test";
2235 MeasureCharacterRanges (text, 0, text.Length + 1);
2239 public void MeasureCharacterRanges_Prefix ()
2242 Assert.Ignore ("Couldn't create required font");
2244 string text = "Hello &Mono::";
2245 CharacterRange[] ranges = new CharacterRange[1];
2246 ranges[0] = new CharacterRange (5, 4);
2248 StringFormat string_format = new StringFormat ();
2249 string_format.SetMeasurableCharacterRanges (ranges);
2251 using (Bitmap bitmap = new Bitmap (20, 20)) {
2252 using (Graphics g = Graphics.FromImage (bitmap)) {
2253 SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2254 RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2256 // here & is part of the measure and visible
2257 string_format.HotkeyPrefix = HotkeyPrefix.None;
2258 Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2259 RectangleF bounds_none = regions[0].GetBounds (g);
2261 // here & is part of the measure (range) but visible as an underline
2262 string_format.HotkeyPrefix = HotkeyPrefix.Show;
2263 regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2264 RectangleF bounds_show = regions[0].GetBounds (g);
2265 Assert.IsTrue (bounds_show.Width < bounds_none.Width, "Show<None");
2267 // here & is part of the measure (range) but invisible
2268 string_format.HotkeyPrefix = HotkeyPrefix.Hide;
2269 regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2270 RectangleF bounds_hide = regions[0].GetBounds (g);
2271 Assert.AreEqual (bounds_hide.Width, bounds_show.Width, "Hide==None");
2277 [ExpectedException (typeof (ArgumentException))]
2278 public void MeasureCharacterRanges_NullStringFormat ()
2281 Assert.Ignore ("Couldn't create required font");
2283 using (Bitmap bitmap = new Bitmap (20, 20)) {
2284 using (Graphics g = Graphics.FromImage (bitmap)) {
2285 g.MeasureCharacterRanges ("Mono", font, new RectangleF (), null);
2291 [Category ("NotWorking")]
2292 public void MeasureCharacterRanges_StringFormat_Alignment ()
2295 Assert.Ignore ("Couldn't create required font");
2297 string text = "Hello Mono::";
2298 CharacterRange[] ranges = new CharacterRange[1];
2299 ranges[0] = new CharacterRange (5, 4);
2300 StringFormat string_format = new StringFormat ();
2301 string_format.SetMeasurableCharacterRanges (ranges);
2303 using (Bitmap bitmap = new Bitmap (20, 20)) {
2304 using (Graphics g = Graphics.FromImage (bitmap)) {
2305 string_format.Alignment = StringAlignment.Near;
2306 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2307 Assert.AreEqual (1, regions.Length, "Near.Region");
2308 RectangleF near = regions[0].GetBounds (g);
2310 string_format.Alignment = StringAlignment.Center;
2311 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2312 Assert.AreEqual (1, regions.Length, "Center.Region");
2313 RectangleF center = regions[0].GetBounds (g);
2315 string_format.Alignment = StringAlignment.Far;
2316 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2317 Assert.AreEqual (1, regions.Length, "Far.Region");
2318 RectangleF far = regions[0].GetBounds (g);
2320 Assert.IsTrue (near.X < center.X, "near-center/X");
2321 Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2322 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2323 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2325 Assert.IsTrue (center.X < far.X, "center-far/X");
2326 Assert.AreEqual (center.Y, far.Y, "center-far/Y");
2327 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2328 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2334 [Category ("NotWorking")]
2335 public void MeasureCharacterRanges_StringFormat_LineAlignment ()
2338 Assert.Ignore ("Couldn't create required font");
2340 string text = "Hello Mono::";
2341 CharacterRange[] ranges = new CharacterRange[1];
2342 ranges[0] = new CharacterRange (5, 4);
2343 StringFormat string_format = new StringFormat ();
2344 string_format.SetMeasurableCharacterRanges (ranges);
2346 using (Bitmap bitmap = new Bitmap (20, 20)) {
2347 using (Graphics g = Graphics.FromImage (bitmap)) {
2348 string_format.LineAlignment = StringAlignment.Near;
2349 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2350 Assert.AreEqual (1, regions.Length, "Near.Region");
2351 RectangleF near = regions[0].GetBounds (g);
2353 string_format.LineAlignment = StringAlignment.Center;
2354 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2355 Assert.AreEqual (1, regions.Length, "Center.Region");
2356 RectangleF center = regions[0].GetBounds (g);
2358 string_format.LineAlignment = StringAlignment.Far;
2359 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2360 Assert.AreEqual (1, regions.Length, "Far.Region");
2361 RectangleF far = regions[0].GetBounds (g);
2363 Assert.AreEqual (near.X, center.X, 0.1, "near-center/X");
2364 Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2365 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2366 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2368 Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2369 Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2370 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2371 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2377 [Category ("NotWorking")]
2378 public void MeasureCharacterRanges_StringFormat_Alignment_DirectionVertical ()
2381 Assert.Ignore ("Couldn't create required font");
2383 string text = "Hello Mono::";
2384 CharacterRange[] ranges = new CharacterRange[1];
2385 ranges[0] = new CharacterRange (5, 4);
2386 StringFormat string_format = new StringFormat ();
2387 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2388 string_format.SetMeasurableCharacterRanges (ranges);
2390 using (Bitmap bitmap = new Bitmap (20, 20)) {
2391 using (Graphics g = Graphics.FromImage (bitmap)) {
2392 string_format.Alignment = StringAlignment.Near;
2393 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2394 Assert.AreEqual (1, regions.Length, "Near.Region");
2395 RectangleF near = regions[0].GetBounds (g);
2397 string_format.Alignment = StringAlignment.Center;
2398 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2399 Assert.AreEqual (1, regions.Length, "Center.Region");
2400 RectangleF center = regions[0].GetBounds (g);
2402 string_format.Alignment = StringAlignment.Far;
2403 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2404 Assert.AreEqual (1, regions.Length, "Far.Region");
2405 RectangleF far = regions[0].GetBounds (g);
2407 Assert.IsTrue (near.X == center.X, "near-center/X"); // ???
2408 Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2409 Assert.IsTrue (near.Width == center.Width, "near-center/Width"); // ???
2410 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2412 Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2413 Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2414 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2415 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2421 [Category ("NotWorking")]
2422 public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
2425 Assert.Ignore ("Couldn't create required font");
2427 string text = "Hello Mono::";
2428 CharacterRange[] ranges = new CharacterRange[1];
2429 ranges[0] = new CharacterRange (5, 4);
2430 StringFormat string_format = new StringFormat ();
2431 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2432 string_format.SetMeasurableCharacterRanges (ranges);
2434 using (Bitmap bitmap = new Bitmap (20, 20)) {
2435 using (Graphics g = Graphics.FromImage (bitmap)) {
2436 string_format.LineAlignment = StringAlignment.Near;
2437 Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2438 Assert.AreEqual (1, regions.Length, "Near.Region");
2439 RectangleF near = regions[0].GetBounds (g);
2441 string_format.LineAlignment = StringAlignment.Center;
2442 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2443 Assert.AreEqual (1, regions.Length, "Center.Region");
2444 RectangleF center = regions[0].GetBounds (g);
2446 string_format.LineAlignment = StringAlignment.Far;
2447 regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2448 Assert.AreEqual (1, regions.Length, "Far.Region");
2449 RectangleF far = regions[0].GetBounds (g);
2451 Assert.IsTrue (near.X < center.X, "near-center/X");
2452 Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2453 Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2454 Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2456 Assert.IsTrue (center.X < far.X, "center-far/X");
2457 Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
2458 Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2459 Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2464 static CharacterRange [] ranges = new CharacterRange [] {
2465 new CharacterRange (0, 1),
2466 new CharacterRange (1, 1),
2467 new CharacterRange (2, 1)
2470 Region [] Measure (Graphics gfx, RectangleF rect)
2472 using (StringFormat format = StringFormat.GenericTypographic) {
2473 format.SetMeasurableCharacterRanges (ranges);
2475 using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
2476 return gfx.MeasureCharacterRanges ("abc", font, rect, format);
2482 public void Measure ()
2484 using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2485 Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
2486 Assert.AreEqual (3, zero.Length, "zero.Length");
2488 Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
2489 Assert.AreEqual (3, small.Length, "small.Length");
2490 for (int i = 0; i < 3; i++ ) {
2491 RectangleF zb = zero [i].GetBounds (gfx);
2492 RectangleF sb = small [i].GetBounds (gfx);
2493 Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
2494 Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
2495 Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
2496 Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
2499 Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
2500 Assert.AreEqual (3, max.Length, "empty.Length");
2501 for (int i = 0; i < 3; i++) {
2502 RectangleF zb = zero [i].GetBounds (gfx);
2503 RectangleF mb = max [i].GetBounds (gfx);
2504 Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
2505 Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
2506 Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
2507 Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
2513 public void MeasureLimits ()
2515 using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2516 Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
2517 Assert.AreEqual (3, min.Length, "origin.Length");
2518 for (int i = 0; i < 3; i++) {
2519 RectangleF mb = min [i].GetBounds (gfx);
2520 Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2521 Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2522 Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2523 Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2526 Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
2527 Assert.AreEqual (3, neg.Length, "neg.Length");
2528 for (int i = 0; i < 3; i++) {
2529 RectangleF mb = neg [i].GetBounds (gfx);
2530 Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2531 Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2532 Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2533 Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2539 public void DrawString_EndlessLoop_Bug77699 ()
2542 Assert.Ignore ("Couldn't create required font");
2544 using (Bitmap bitmap = new Bitmap (20, 20)) {
2545 using (Graphics g = Graphics.FromImage (bitmap)) {
2546 Rectangle rect = Rectangle.Empty;
2547 rect.Location = new Point (10, 10);
2548 rect.Size = new Size (1, 20);
2549 StringFormat fmt = new StringFormat ();
2550 fmt.Alignment = StringAlignment.Center;
2551 fmt.LineAlignment = StringAlignment.Center;
2552 fmt.FormatFlags = StringFormatFlags.NoWrap;
2553 fmt.Trimming = StringTrimming.EllipsisWord;
2554 g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2560 public void DrawString_EndlessLoop_Wrapping ()
2563 Assert.Ignore ("Couldn't create required font");
2565 using (Bitmap bitmap = new Bitmap (20, 20)) {
2566 using (Graphics g = Graphics.FromImage (bitmap)) {
2567 Rectangle rect = Rectangle.Empty;
2568 rect.Location = new Point (10, 10);
2569 rect.Size = new Size (1, 20);
2570 StringFormat fmt = new StringFormat ();
2571 fmt.Alignment = StringAlignment.Center;
2572 fmt.LineAlignment = StringAlignment.Center;
2573 fmt.Trimming = StringTrimming.EllipsisWord;
2574 g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2580 public void MeasureString_Wrapping_Dots ()
2582 HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_Wrapping_Dots");
2585 Assert.Ignore ("Couldn't create required font");
2587 string text = "this is really long text........................................... with a lot o periods.";
2588 using (Bitmap bitmap = new Bitmap (20, 20)) {
2589 using (Graphics g = Graphics.FromImage (bitmap)) {
2590 using (StringFormat format = new StringFormat ()) {
2591 format.Alignment = StringAlignment.Center;
2592 SizeF sz = g.MeasureString (text, font, 80, format);
2593 Assert.IsTrue (sz.Width < 80, "Width");
2594 Assert.IsTrue (sz.Height > font.Height * 2, "Height");
2601 public void GetReleaseHdcInternal ()
2603 using (Bitmap b = new Bitmap (10, 10)) {
2604 using (Graphics g = Graphics.FromImage (b)) {
2605 IntPtr hdc1 = g.GetHdc ();
2606 g.ReleaseHdcInternal (hdc1);
2607 IntPtr hdc2 = g.GetHdc ();
2608 g.ReleaseHdcInternal (hdc2);
2609 Assert.AreEqual (hdc1, hdc2, "hdc");
2615 [ExpectedException (typeof (ArgumentException))]
2616 public void ReleaseHdcInternal_IntPtrZero ()
2618 using (Bitmap b = new Bitmap (10, 10)) {
2619 using (Graphics g = Graphics.FromImage (b)) {
2620 g.ReleaseHdcInternal (IntPtr.Zero);
2626 [ExpectedException (typeof (ArgumentException))]
2627 public void ReleaseHdcInternal_TwoTimes ()
2629 using (Bitmap b = new Bitmap (10, 10)) {
2630 using (Graphics g = Graphics.FromImage (b)) {
2631 IntPtr hdc = g.GetHdc ();
2632 g.ReleaseHdcInternal (hdc);
2633 g.ReleaseHdcInternal (hdc);
2639 public void TestReleaseHdc ()
2641 using (Bitmap b = new Bitmap (10, 10)) {
2642 using (Graphics g = Graphics.FromImage (b)) {
2643 IntPtr hdc1 = g.GetHdc ();
2645 IntPtr hdc2 = g.GetHdc ();
2647 Assert.AreEqual (hdc1, hdc2, "hdc");
2653 [ExpectedException (typeof (ArgumentException))]
2654 public void TestReleaseHdcException ()
2656 using (Bitmap b = new Bitmap (10, 10)) {
2657 using (Graphics g = Graphics.FromImage (b)) {
2664 [ExpectedException (typeof (ArgumentException))]
2665 public void TestReleaseHdcException2 ()
2667 using (Bitmap b = new Bitmap (10, 10)) {
2668 using (Graphics g = Graphics.FromImage (b)) {
2677 public void VisibleClipBound ()
2680 using (Bitmap bmp = new Bitmap (100, 100)) {
2681 using (Graphics g = Graphics.FromImage (bmp)) {
2682 RectangleF noclip = g.VisibleClipBounds;
2683 Assert.AreEqual (0, noclip.X, "noclip.X");
2684 Assert.AreEqual (0, noclip.Y, "noclip.Y");
2685 Assert.AreEqual (100, noclip.Width, "noclip.Width");
2686 Assert.AreEqual (100, noclip.Height, "noclip.Height");
2688 // note: libgdiplus regions are precise to multiple of multiple of 8
2689 g.Clip = new Region (new RectangleF (0, 0, 32, 32));
2690 RectangleF clip = g.VisibleClipBounds;
2691 Assert.AreEqual (0, clip.X, "clip.X");
2692 Assert.AreEqual (0, clip.Y, "clip.Y");
2693 Assert.AreEqual (32, clip.Width, "clip.Width");
2694 Assert.AreEqual (32, clip.Height, "clip.Height");
2696 g.RotateTransform (90);
2697 RectangleF rotclip = g.VisibleClipBounds;
2698 Assert.AreEqual (0, rotclip.X, "rotclip.X");
2699 Assert.AreEqual (-32, rotclip.Y, "rotclip.Y");
2700 Assert.AreEqual (32, rotclip.Width, "rotclip.Width");
2701 Assert.AreEqual (32, rotclip.Height, "rotclip.Height");
2707 public void VisibleClipBound_BigClip ()
2709 using (Bitmap bmp = new Bitmap (100, 100)) {
2710 using (Graphics g = Graphics.FromImage (bmp)) {
2711 RectangleF noclip = g.VisibleClipBounds;
2712 Assert.AreEqual (0, noclip.X, "noclip.X");
2713 Assert.AreEqual (0, noclip.Y, "noclip.Y");
2714 Assert.AreEqual (100, noclip.Width, "noclip.Width");
2715 Assert.AreEqual (100, noclip.Height, "noclip.Height");
2717 // clip is larger than bitmap
2718 g.Clip = new Region (new RectangleF (0, 0, 200, 200));
2719 RectangleF clipbound = g.ClipBounds;
2720 Assert.AreEqual (0, clipbound.X, "clipbound.X");
2721 Assert.AreEqual (0, clipbound.Y, "clipbound.Y");
2722 Assert.AreEqual (200, clipbound.Width, "clipbound.Width");
2723 Assert.AreEqual (200, clipbound.Height, "clipbound.Height");
2725 RectangleF clip = g.VisibleClipBounds;
2726 Assert.AreEqual (0, clip.X, "clip.X");
2727 Assert.AreEqual (0, clip.Y, "clip.Y");
2728 Assert.AreEqual (100, clip.Width, "clip.Width");
2729 Assert.AreEqual (100, clip.Height, "clip.Height");
2731 g.RotateTransform (90);
2732 RectangleF rotclipbound = g.ClipBounds;
2733 Assert.AreEqual (0, rotclipbound.X, "rotclipbound.X");
2734 Assert.AreEqual (-200, rotclipbound.Y, "rotclipbound.Y");
2735 Assert.AreEqual (200, rotclipbound.Width, "rotclipbound.Width");
2736 Assert.AreEqual (200, rotclipbound.Height, "rotclipbound.Height");
2738 RectangleF rotclip = g.VisibleClipBounds;
2739 Assert.AreEqual (0, rotclip.X, "rotclip.X");
2740 Assert.AreEqual (-100, rotclip.Y, "rotclip.Y");
2741 Assert.AreEqual (100, rotclip.Width, "rotclip.Width");
2742 Assert.AreEqual (100, rotclip.Height, "rotclip.Height");
2748 public void Rotate ()
2750 using (Bitmap bmp = new Bitmap (100, 50)) {
2751 using (Graphics g = Graphics.FromImage (bmp)) {
2752 RectangleF vcb = g.VisibleClipBounds;
2753 Assert.AreEqual (0, vcb.X, "vcb.X");
2754 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2755 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2756 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2758 g.RotateTransform (90);
2759 RectangleF rvcb = g.VisibleClipBounds;
2760 Assert.AreEqual (0, rvcb.X, "rvcb.X");
2761 Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
2762 Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
2763 Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
2769 public void Scale ()
2771 using (Bitmap bmp = new Bitmap (100, 50)) {
2772 using (Graphics g = Graphics.FromImage (bmp)) {
2773 RectangleF vcb = g.VisibleClipBounds;
2774 Assert.AreEqual (0, vcb.X, "vcb.X");
2775 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2776 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2777 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2779 g.ScaleTransform (2, 0.5f);
2780 RectangleF svcb = g.VisibleClipBounds;
2781 Assert.AreEqual (0, svcb.X, "svcb.X");
2782 Assert.AreEqual (0, svcb.Y, "svcb.Y");
2783 Assert.AreEqual (50, svcb.Width, "svcb.Width");
2784 Assert.AreEqual (100, svcb.Height, "svcb.Height");
2790 public void Translate ()
2792 using (Bitmap bmp = new Bitmap (100, 50)) {
2793 using (Graphics g = Graphics.FromImage (bmp)) {
2794 RectangleF vcb = g.VisibleClipBounds;
2795 Assert.AreEqual (0, vcb.X, "vcb.X");
2796 Assert.AreEqual (0, vcb.Y, "vcb.Y");
2797 Assert.AreEqual (100, vcb.Width, "vcb.Width");
2798 Assert.AreEqual (50, vcb.Height, "vcb.Height");
2800 g.TranslateTransform (-25, 25);
2801 RectangleF tvcb = g.VisibleClipBounds;
2802 Assert.AreEqual (25, tvcb.X, "tvcb.X");
2803 Assert.AreEqual (-25, tvcb.Y, "tvcb.Y");
2804 Assert.AreEqual (100, tvcb.Width, "tvcb.Width");
2805 Assert.AreEqual (50, tvcb.Height, "tvcb.Height");
2811 [ExpectedException (typeof (ArgumentNullException))]
2812 public void DrawIcon_NullRectangle ()
2814 using (Bitmap bmp = new Bitmap (40, 40)) {
2815 using (Graphics g = Graphics.FromImage (bmp)) {
2816 g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
2822 public void DrawIcon_IconRectangle ()
2824 using (Bitmap bmp = new Bitmap (40, 40)) {
2825 using (Graphics g = Graphics.FromImage (bmp)) {
2826 g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
2827 // Rectangle is empty when X, Y, Width and Height == 0
2828 // (yep X and Y too, RectangleF only checks for Width and Height)
2829 g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
2830 // so this one is half-empty ;-)
2831 g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
2832 // negative width or height isn't empty (for Rectangle)
2833 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2834 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2840 [ExpectedException (typeof (ArgumentNullException))]
2841 public void DrawIcon_NullIntInt ()
2843 using (Bitmap bmp = new Bitmap (40, 40)) {
2844 using (Graphics g = Graphics.FromImage (bmp)) {
2845 g.DrawIcon (null, 4, 2);
2851 public void DrawIcon_IconIntInt ()
2853 using (Bitmap bmp = new Bitmap (40, 40)) {
2854 using (Graphics g = Graphics.FromImage (bmp)) {
2855 g.DrawIcon (SystemIcons.Exclamation, 4, 2);
2856 g.DrawIcon (SystemIcons.Hand, 0, 0);
2862 [ExpectedException (typeof (ArgumentNullException))]
2863 public void DrawIconUnstretched_NullRectangle ()
2865 using (Bitmap bmp = new Bitmap (40, 40)) {
2866 using (Graphics g = Graphics.FromImage (bmp)) {
2867 g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
2873 public void DrawIconUnstretched_IconRectangle ()
2875 using (Bitmap bmp = new Bitmap (40, 40)) {
2876 using (Graphics g = Graphics.FromImage (bmp)) {
2877 g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
2878 // Rectangle is empty when X, Y, Width and Height == 0
2879 // (yep X and Y too, RectangleF only checks for Width and Height)
2880 g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
2881 // so this one is half-empty ;-)
2882 g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
2883 // negative width or height isn't empty (for Rectangle)
2884 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2885 g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2891 [ExpectedException (typeof (ArgumentNullException))]
2892 public void DrawImage_NullRectangleF ()
2894 using (Bitmap bmp = new Bitmap (40, 40)) {
2895 using (Graphics g = Graphics.FromImage (bmp)) {
2896 g.DrawImage (null, new RectangleF (0, 0, 0, 0));
2902 public void DrawImage_ImageRectangleF ()
2904 using (Bitmap bmp = new Bitmap (40, 40)) {
2905 using (Graphics g = Graphics.FromImage (bmp)) {
2906 g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
2907 g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
2908 g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
2909 g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
2915 [ExpectedException (typeof (ArgumentNullException))]
2916 public void DrawImage_NullPointF ()
2918 using (Bitmap bmp = new Bitmap (40, 40)) {
2919 using (Graphics g = Graphics.FromImage (bmp)) {
2920 g.DrawImage (null, new PointF (0, 0));
2926 public void DrawImage_ImagePointF ()
2928 using (Bitmap bmp = new Bitmap (40, 40)) {
2929 using (Graphics g = Graphics.FromImage (bmp)) {
2930 g.DrawImage (bmp, new PointF (0, 0));
2936 [ExpectedException (typeof (ArgumentNullException))]
2937 public void DrawImage_NullPointFArray ()
2939 using (Bitmap bmp = new Bitmap (40, 40)) {
2940 using (Graphics g = Graphics.FromImage (bmp)) {
2941 g.DrawImage (null, new PointF[0]);
2947 [ExpectedException (typeof (ArgumentNullException))]
2948 public void DrawImage_ImagePointFArrayNull ()
2950 using (Bitmap bmp = new Bitmap (40, 40)) {
2951 using (Graphics g = Graphics.FromImage (bmp)) {
2952 g.DrawImage (bmp, (PointF[]) null);
2958 [ExpectedException (typeof (ArgumentException))]
2959 public void DrawImage_ImagePointFArrayEmpty ()
2961 using (Bitmap bmp = new Bitmap (40, 40)) {
2962 using (Graphics g = Graphics.FromImage (bmp)) {
2963 g.DrawImage (bmp, new PointF[0]);
2969 public void DrawImage_ImagePointFArray ()
2971 using (Bitmap bmp = new Bitmap (40, 40)) {
2972 using (Graphics g = Graphics.FromImage (bmp)) {
2973 g.DrawImage (bmp, new PointF[] {
2974 new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
2980 [ExpectedException (typeof (ArgumentNullException))]
2981 public void DrawImage_NullRectangle ()
2983 using (Bitmap bmp = new Bitmap (40, 40)) {
2984 using (Graphics g = Graphics.FromImage (bmp)) {
2985 g.DrawImage (null, new Rectangle (0, 0, 0, 0));
2991 public void DrawImage_ImageRectangle ()
2993 using (Bitmap bmp = new Bitmap (40, 40)) {
2994 using (Graphics g = Graphics.FromImage (bmp)) {
2995 // Rectangle is empty when X, Y, Width and Height == 0
2996 // (yep X and Y too, RectangleF only checks for Width and Height)
2997 g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
2998 // so this one is half-empty ;-)
2999 g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
3000 // negative width or height isn't empty (for Rectangle)
3001 g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
3002 g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
3008 [ExpectedException (typeof (ArgumentNullException))]
3009 public void DrawImage_NullPoint ()
3011 using (Bitmap bmp = new Bitmap (40, 40)) {
3012 using (Graphics g = Graphics.FromImage (bmp)) {
3013 g.DrawImage (null, new Point (0, 0));
3019 public void DrawImage_ImagePoint ()
3021 using (Bitmap bmp = new Bitmap (40, 40)) {
3022 using (Graphics g = Graphics.FromImage (bmp)) {
3023 g.DrawImage (bmp, new Point (0, 0));
3029 [ExpectedException (typeof (ArgumentNullException))]
3030 public void DrawImage_NullPointArray ()
3032 using (Bitmap bmp = new Bitmap (40, 40)) {
3033 using (Graphics g = Graphics.FromImage (bmp)) {
3034 g.DrawImage (null, new Point[0]);
3040 [ExpectedException (typeof (ArgumentNullException))]
3041 public void DrawImage_ImagePointArrayNull ()
3043 using (Bitmap bmp = new Bitmap (40, 40)) {
3044 using (Graphics g = Graphics.FromImage (bmp)) {
3045 g.DrawImage (bmp, (Point[]) null);
3051 [ExpectedException (typeof (ArgumentException))]
3052 public void DrawImage_ImagePointArrayEmpty ()
3054 using (Bitmap bmp = new Bitmap (40, 40)) {
3055 using (Graphics g = Graphics.FromImage (bmp)) {
3056 g.DrawImage (bmp, new Point[0]);
3062 public void DrawImage_ImagePointArray ()
3064 using (Bitmap bmp = new Bitmap (40, 40)) {
3065 using (Graphics g = Graphics.FromImage (bmp)) {
3066 g.DrawImage (bmp, new Point[] {
3067 new Point (0, 0), new Point (1, 1), new Point (2, 2) });
3073 [ExpectedException (typeof (ArgumentNullException))]
3074 public void DrawImage_NullIntInt ()
3076 using (Bitmap bmp = new Bitmap (40, 40)) {
3077 using (Graphics g = Graphics.FromImage (bmp)) {
3078 g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
3084 [ExpectedException (typeof (OverflowException))]
3085 public void DrawImage_ImageIntInt_Overflow ()
3087 using (Bitmap bmp = new Bitmap (40, 40)) {
3088 using (Graphics g = Graphics.FromImage (bmp)) {
3089 g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
3095 public void DrawImage_ImageIntInt ()
3097 using (Bitmap bmp = new Bitmap (40, 40)) {
3098 using (Graphics g = Graphics.FromImage (bmp)) {
3099 g.DrawImage (bmp, -40, -40);
3105 [ExpectedException (typeof (ArgumentNullException))]
3106 public void DrawImage_NullFloat ()
3108 using (Bitmap bmp = new Bitmap (40, 40)) {
3109 using (Graphics g = Graphics.FromImage (bmp)) {
3110 g.DrawImage (null, Single.MaxValue, Single.MinValue);
3116 [ExpectedException (typeof (OverflowException))]
3117 public void DrawImage_ImageFloatFloat_Overflow ()
3119 using (Bitmap bmp = new Bitmap (40, 40)) {
3120 using (Graphics g = Graphics.FromImage (bmp)) {
3121 g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
3127 public void DrawImage_ImageFloatFloat ()
3129 using (Bitmap bmp = new Bitmap (40, 40)) {
3130 using (Graphics g = Graphics.FromImage (bmp)) {
3131 g.DrawImage (bmp, -40.0f, -40.0f);
3137 [ExpectedException (typeof (ArgumentNullException))]
3138 public void DrawImage_NullRectangleRectangleGraphicsUnit ()
3140 using (Bitmap bmp = new Bitmap (40, 40)) {
3141 using (Graphics g = Graphics.FromImage (bmp)) {
3142 g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
3147 private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
3149 using (Bitmap bmp = new Bitmap (40, 40)) {
3150 using (Graphics g = Graphics.FromImage (bmp)) {
3151 Rectangle r = new Rectangle (0, 0, 40, 40);
3152 g.DrawImage (bmp, r, r, unit);
3158 [ExpectedException (typeof (ArgumentException))]
3159 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
3161 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
3165 [ExpectedException (typeof (NotImplementedException))]
3166 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
3168 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
3172 [ExpectedException (typeof (NotImplementedException))]
3173 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
3175 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
3179 [ExpectedException (typeof (NotImplementedException))]
3180 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
3182 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
3186 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
3189 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
3193 [ExpectedException (typeof (NotImplementedException))]
3194 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
3196 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
3200 [ExpectedException (typeof (ArgumentException))]
3201 public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
3203 DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
3207 [ExpectedException (typeof (ArgumentNullException))]
3208 public void DrawImage_NullPointRectangleGraphicsUnit ()
3210 Rectangle r = new Rectangle (1, 2, 3, 4);
3211 Point[] pts = new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) };
3212 using (Bitmap bmp = new Bitmap (40, 40)) {
3213 using (Graphics g = Graphics.FromImage (bmp)) {
3214 g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3219 private void DrawImage_ImagePointRectangleGraphicsUnit (Point[] pts)
3221 Rectangle r = new Rectangle (1, 2, 3, 4);
3222 using (Bitmap bmp = new Bitmap (40, 40)) {
3223 using (Graphics g = Graphics.FromImage (bmp)) {
3224 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3230 [ExpectedException (typeof (ArgumentNullException))]
3231 public void DrawImage_ImageNullRectangleGraphicsUnit ()
3233 DrawImage_ImagePointRectangleGraphicsUnit (null);
3237 [ExpectedException (typeof (ArgumentException))]
3238 public void DrawImage_ImagePoint0RectangleGraphicsUnit ()
3240 DrawImage_ImagePointRectangleGraphicsUnit (new Point[0]);
3244 [ExpectedException (typeof (ArgumentException))]
3245 public void DrawImage_ImagePoint1RectangleGraphicsUnit ()
3247 Point p = new Point (1, 1);
3248 DrawImage_ImagePointRectangleGraphicsUnit (new Point[1] { p });
3252 [ExpectedException (typeof (ArgumentException))]
3253 public void DrawImage_ImagePoint2RectangleGraphicsUnit ()
3255 Point p = new Point (1, 1);
3256 DrawImage_ImagePointRectangleGraphicsUnit (new Point[2] { p, p });
3260 public void DrawImage_ImagePoint3RectangleGraphicsUnit ()
3262 Point p = new Point (1, 1);
3263 DrawImage_ImagePointRectangleGraphicsUnit (new Point[3] { p, p, p });
3267 [ExpectedException (typeof (NotImplementedException))]
3268 public void DrawImage_ImagePoint4RectangleGraphicsUnit ()
3270 Point p = new Point (1, 1);
3271 DrawImage_ImagePointRectangleGraphicsUnit (new Point[4] { p, p, p, p });
3275 [ExpectedException (typeof (ArgumentNullException))]
3276 public void DrawImage_NullPointFRectangleGraphicsUnit ()
3278 Rectangle r = new Rectangle (1, 2, 3, 4);
3279 PointF[] pts = new PointF[3] { new PointF (1, 1), new PointF (2, 2), new PointF (3, 3) };
3280 using (Bitmap bmp = new Bitmap (40, 40)) {
3281 using (Graphics g = Graphics.FromImage (bmp)) {
3282 g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3287 private void DrawImage_ImagePointFRectangleGraphicsUnit (PointF[] pts)
3289 Rectangle r = new Rectangle (1, 2, 3, 4);
3290 using (Bitmap bmp = new Bitmap (40, 40)) {
3291 using (Graphics g = Graphics.FromImage (bmp)) {
3292 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3298 [ExpectedException (typeof (ArgumentNullException))]
3299 public void DrawImage_ImageNullFRectangleGraphicsUnit ()
3301 DrawImage_ImagePointFRectangleGraphicsUnit (null);
3305 [ExpectedException (typeof (ArgumentException))]
3306 public void DrawImage_ImagePointF0RectangleGraphicsUnit ()
3308 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[0]);
3312 [ExpectedException (typeof (ArgumentException))]
3313 public void DrawImage_ImagePointF1RectangleGraphicsUnit ()
3315 PointF p = new PointF (1, 1);
3316 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[1] { p });
3320 [ExpectedException (typeof (ArgumentException))]
3321 public void DrawImage_ImagePointF2RectangleGraphicsUnit ()
3323 PointF p = new PointF (1, 1);
3324 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[2] { p, p });
3328 public void DrawImage_ImagePointF3RectangleGraphicsUnit ()
3330 PointF p = new PointF (1, 1);
3331 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[3] { p, p, p });
3335 [ExpectedException (typeof (NotImplementedException))]
3336 public void DrawImage_ImagePointF4RectangleGraphicsUnit ()
3338 PointF p = new PointF (1, 1);
3339 DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[4] { p, p, p, p });
3343 public void DrawImage_ImagePointRectangleGraphicsUnitNull ()
3345 Point p = new Point (1, 1);
3346 Point[] pts = new Point[3] { p, p, p };
3347 Rectangle r = new Rectangle (1, 2, 3, 4);
3348 using (Bitmap bmp = new Bitmap (40, 40)) {
3349 using (Graphics g = Graphics.FromImage (bmp)) {
3350 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, null);
3356 public void DrawImage_ImagePointRectangleGraphicsUnitAttributes ()
3358 Point p = new Point (1, 1);
3359 Point[] pts = new Point[3] { p, p, p };
3360 Rectangle r = new Rectangle (1, 2, 3, 4);
3361 using (Bitmap bmp = new Bitmap (40, 40)) {
3362 using (Graphics g = Graphics.FromImage (bmp)) {
3363 ImageAttributes ia = new ImageAttributes ();
3364 g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, ia);
3370 [ExpectedException (typeof (ArgumentNullException))]
3371 public void DrawImageUnscaled_NullPoint ()
3373 using (Bitmap bmp = new Bitmap (40, 40)) {
3374 using (Graphics g = Graphics.FromImage (bmp)) {
3375 g.DrawImageUnscaled (null, new Point (0, 0));
3381 public void DrawImageUnscaled_ImagePoint ()
3383 using (Bitmap bmp = new Bitmap (40, 40)) {
3384 using (Graphics g = Graphics.FromImage (bmp)) {
3385 g.DrawImageUnscaled (bmp, new Point (0, 0));
3391 [ExpectedException (typeof (ArgumentNullException))]
3392 public void DrawImageUnscaled_NullRectangle ()
3394 using (Bitmap bmp = new Bitmap (40, 40)) {
3395 using (Graphics g = Graphics.FromImage (bmp)) {
3396 g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
3402 public void DrawImageUnscaled_ImageRectangle ()
3404 using (Bitmap bmp = new Bitmap (40, 40)) {
3405 using (Graphics g = Graphics.FromImage (bmp)) {
3406 g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
3412 [ExpectedException (typeof (ArgumentNullException))]
3413 public void DrawImageUnscaled_NullIntInt ()
3415 using (Bitmap bmp = new Bitmap (40, 40)) {
3416 using (Graphics g = Graphics.FromImage (bmp)) {
3417 g.DrawImageUnscaled (null, 0, 0);
3423 public void DrawImageUnscaled_ImageIntInt ()
3425 using (Bitmap bmp = new Bitmap (40, 40)) {
3426 using (Graphics g = Graphics.FromImage (bmp)) {
3427 g.DrawImageUnscaled (bmp, 0, 0);
3433 [ExpectedException (typeof (ArgumentNullException))]
3434 public void DrawImageUnscaled_NullIntIntIntInt ()
3436 using (Bitmap bmp = new Bitmap (40, 40)) {
3437 using (Graphics g = Graphics.FromImage (bmp)) {
3438 g.DrawImageUnscaled (null, 0, 0, -1, -1);
3444 public void DrawImageUnscaled_ImageIntIntIntInt ()
3446 using (Bitmap bmp = new Bitmap (40, 40)) {
3447 using (Graphics g = Graphics.FromImage (bmp)) {
3448 g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
3454 [ExpectedException (typeof (ArgumentNullException))]
3455 public void DrawImageUnscaledAndClipped_Null ()
3457 using (Bitmap bmp = new Bitmap (40, 40)) {
3458 using (Graphics g = Graphics.FromImage (bmp)) {
3459 g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
3465 public void DrawImageUnscaledAndClipped ()
3467 using (Bitmap bmp = new Bitmap (40, 40)) {
3468 using (Graphics g = Graphics.FromImage (bmp)) {
3469 // Rectangle is empty when X, Y, Width and Height == 0
3470 // (yep X and Y too, RectangleF only checks for Width and Height)
3471 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
3472 // so this one is half-empty ;-)
3473 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
3474 // negative width or height isn't empty (for Rectangle)
3475 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
3476 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
3478 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
3479 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
3480 g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
3487 [ExpectedException (typeof (ArgumentNullException))]
3488 public void DrawPath_Pen_Null ()
3490 using (Bitmap bmp = new Bitmap (20, 20)) {
3491 using (Graphics g = Graphics.FromImage (bmp)) {
3492 using (GraphicsPath path = new GraphicsPath ()) {
3493 g.DrawPath (null, path);
3500 [ExpectedException (typeof (ArgumentNullException))]
3501 public void DrawPath_Path_Null ()
3503 using (Bitmap bmp = new Bitmap (20, 20)) {
3504 using (Graphics g = Graphics.FromImage (bmp)) {
3505 g.DrawPath (Pens.Black, null);
3511 public void DrawPath_82202 ()
3513 // based on test case from bug #82202
3514 using (Bitmap bmp = new Bitmap (20, 20)) {
3515 using (Graphics g = Graphics.FromImage (bmp)) {
3516 using (GraphicsPath path = new GraphicsPath ()) {
3518 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3519 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3521 path.AddArc (arcrect, 180, 90);
3522 arcrect.X = baserect.Right - d;
3523 path.AddArc (arcrect, 270, 90);
3524 arcrect.Y = baserect.Bottom - d;
3525 path.AddArc (arcrect, 0, 90);
3526 arcrect.X = baserect.Left;
3527 path.AddArc (arcrect, 90, 90);
3528 path.CloseFigure ();
3529 g.Clear (Color.White);
3530 g.DrawPath (Pens.SteelBlue, path);
3532 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3533 Assert.AreEqual (-1, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3540 [ExpectedException (typeof (ArgumentNullException))]
3541 public void FillPath_Brush_Null ()
3543 using (Bitmap bmp = new Bitmap (20, 20)) {
3544 using (Graphics g = Graphics.FromImage (bmp)) {
3545 using (GraphicsPath path = new GraphicsPath ()) {
3546 g.FillPath (null, path);
3553 [ExpectedException (typeof (ArgumentNullException))]
3554 public void FillPath_Path_Null ()
3556 using (Bitmap bmp = new Bitmap (20, 20)) {
3557 using (Graphics g = Graphics.FromImage (bmp)) {
3558 g.FillPath (Brushes.Black, null);
3564 public void FillPath_82202 ()
3566 // based on test case from bug #82202
3567 using (Bitmap bmp = new Bitmap (20, 20)) {
3568 using (Graphics g = Graphics.FromImage (bmp)) {
3569 using (GraphicsPath path = new GraphicsPath ()) {
3571 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3572 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3574 path.AddArc (arcrect, 180, 90);
3575 arcrect.X = baserect.Right - d;
3576 path.AddArc (arcrect, 270, 90);
3577 arcrect.Y = baserect.Bottom - d;
3578 path.AddArc (arcrect, 0, 90);
3579 arcrect.X = baserect.Left;
3580 path.AddArc (arcrect, 90, 90);
3581 path.CloseFigure ();
3582 g.Clear (Color.White);
3583 g.FillPath (Brushes.SteelBlue, path);
3585 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3586 Assert.AreEqual (-12156236, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3593 public void TransformPoints_349800 ()
3595 using (Bitmap bmp = new Bitmap (10, 10)) {
3596 using (Graphics g = Graphics.FromImage (bmp)) {
3597 Point [] pts = new Point [5];
3598 PointF [] ptf = new PointF [5];
3599 for (int i = 0; i < 5; i++) {
3600 pts [i] = new Point (i, i);
3601 ptf [i] = new PointF (i, i);
3604 g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, pts);
3605 g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, ptf);
3607 for (int i = 0; i < 5; i++) {
3608 Assert.AreEqual (i, pts [i].X, "Point.X " + i.ToString ());
3609 Assert.AreEqual (i, pts [i].Y, "Point.Y " + i.ToString ());
3610 Assert.AreEqual (i, ptf [i].X, "PointF.X " + i.ToString ());
3611 Assert.AreEqual (i, ptf [i].Y, "PointF.Y " + i.ToString ());
3618 public void Dpi_556181 ()
3621 using (Bitmap bmp = new Bitmap (10, 10)) {
3622 using (Graphics g = Graphics.FromImage (bmp)) {
3626 bmp.SetResolution (x, y);
3627 using (Graphics g = Graphics.FromImage (bmp)) {
3628 Assert.AreEqual (x, g.DpiX, "DpiX");
3629 Assert.AreEqual (y, g.DpiY, "DpiY");
3636 public class GraphicsFullTrustTest {
3638 // note: this test would fail, on ReleaseHdc, without fulltrust
3639 // i.e. it's a demand and not a linkdemand
3641 public void GetReleaseHdc ()
3643 using (Bitmap b = new Bitmap (100, 100)) {
3644 using (Graphics g = Graphics.FromImage (b)) {
3645 IntPtr hdc1 = g.GetHdc ();
3646 g.ReleaseHdc (hdc1);
3647 IntPtr hdc2 = g.GetHdc ();
3648 g.ReleaseHdc (hdc2);
3649 Assert.AreEqual (hdc1, hdc2, "hdc");