TestGraphics.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. //
  2. // Graphics class testing unit
  3. //
  4. // Authors:
  5. // Jordi Mas, [email protected]
  6. // Sebastien Pouliot <[email protected]>
  7. //
  8. // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Drawing;
  32. using System.Drawing.Text;
  33. using System.Drawing.Drawing2D;
  34. using System.IO;
  35. using System.Reflection;
  36. namespace MonoTests.System.Drawing
  37. {
  38. [TestFixture]
  39. public class GraphicsTest : Assertion
  40. {
  41. private RectangleF[] rects;
  42. [Test]
  43. public void DefaultProperties ()
  44. {
  45. Bitmap bmp = new Bitmap (200, 200);
  46. Graphics g = Graphics.FromImage (bmp);
  47. Region r = new Region ();
  48. AssertEquals ("DefaultProperties1", r.GetBounds (g) , g.ClipBounds);
  49. AssertEquals ("DefaultProperties2", CompositingMode.SourceOver, g.CompositingMode);
  50. AssertEquals ("DefaultProperties3", CompositingQuality.Default, g.CompositingQuality);
  51. AssertEquals ("DefaultProperties4", InterpolationMode.Bilinear, g.InterpolationMode);
  52. AssertEquals ("DefaultProperties5", 1, g.PageScale);
  53. AssertEquals ("DefaultProperties6", GraphicsUnit.Display, g.PageUnit);
  54. AssertEquals ("DefaultProperties7", PixelOffsetMode.Default, g.PixelOffsetMode);
  55. AssertEquals ("DefaultProperties8", new Point (0, 0) , g.RenderingOrigin);
  56. AssertEquals ("DefaultProperties9", SmoothingMode.None, g.SmoothingMode);
  57. AssertEquals ("DefaultProperties10", TextRenderingHint.SystemDefault, g.TextRenderingHint);
  58. r.Dispose ();
  59. }
  60. [Test]
  61. public void SetGetProperties ()
  62. {
  63. Bitmap bmp = new Bitmap (200, 200);
  64. Graphics g = Graphics.FromImage (bmp);
  65. g.CompositingMode = CompositingMode.SourceCopy;
  66. g.CompositingQuality = CompositingQuality.GammaCorrected;
  67. g.InterpolationMode = InterpolationMode.HighQualityBilinear;
  68. g.PageScale = 2;
  69. g.PageUnit = GraphicsUnit.Inch;
  70. g.PixelOffsetMode = PixelOffsetMode.Half;
  71. g.RenderingOrigin = new Point (10, 20);
  72. g.SmoothingMode = SmoothingMode.AntiAlias;
  73. g.TextRenderingHint = TextRenderingHint.SystemDefault;
  74. //Clipping set/get tested in clipping functions
  75. AssertEquals ("SetGetProperties2", CompositingMode.SourceCopy, g.CompositingMode);
  76. AssertEquals ("SetGetProperties3", CompositingQuality.GammaCorrected, g.CompositingQuality);
  77. AssertEquals ("SetGetProperties4", InterpolationMode.HighQualityBilinear, g.InterpolationMode);
  78. AssertEquals ("SetGetProperties5", 2, g.PageScale);
  79. AssertEquals ("SetGetProperties6", GraphicsUnit.Inch, g.PageUnit);
  80. AssertEquals ("SetGetProperties7", PixelOffsetMode.Half, g.PixelOffsetMode);
  81. AssertEquals ("SetGetProperties8", new Point (10, 20), g.RenderingOrigin);
  82. AssertEquals ("SetGetProperties9", SmoothingMode.AntiAlias, g.SmoothingMode);
  83. AssertEquals ("SetGetProperties10", TextRenderingHint.SystemDefault, g.TextRenderingHint);
  84. }
  85. // Properties
  86. [Test]
  87. public void Clip ()
  88. {
  89. RectangleF[] rects ;
  90. Bitmap bmp = new Bitmap (200, 200);
  91. Graphics g = Graphics.FromImage (bmp);
  92. g.Clip = new Region (new Rectangle (50, 40, 210, 220));
  93. rects = g.Clip.GetRegionScans (new Matrix ());
  94. AssertEquals ("Clip1", 1, rects.Length);
  95. AssertEquals ("Clip2", 50, rects[0].X);
  96. AssertEquals ("Clip3", 40, rects[0].Y);
  97. AssertEquals ("Clip4", 210, rects[0].Width);
  98. AssertEquals ("Clip5", 220, rects[0].Height);
  99. }
  100. [Test]
  101. public void Clip_NotAReference ()
  102. {
  103. Bitmap bmp = new Bitmap (200, 200);
  104. Graphics g = Graphics.FromImage (bmp);
  105. Assert ("IsInfinite", g.Clip.IsInfinite (g));
  106. g.Clip.IsEmpty (g);
  107. Assert ("!IsEmpty", !g.Clip.IsEmpty (g));
  108. Assert ("IsInfinite-2", g.Clip.IsInfinite (g));
  109. }
  110. [Test]
  111. public void ExcludeClip ()
  112. {
  113. Bitmap bmp = new Bitmap (200, 200);
  114. Graphics g = Graphics.FromImage (bmp);
  115. g.Clip = new Region (new RectangleF (10, 10, 100, 100));
  116. g.ExcludeClip (new Rectangle (40, 60, 100, 20));
  117. rects = g.Clip.GetRegionScans (new Matrix ());
  118. AssertEquals ("ExcludeClip1", 3, rects.Length);
  119. AssertEquals ("ExcludeClip2", 10, rects[0].X);
  120. AssertEquals ("ExcludeClip3", 10, rects[0].Y);
  121. AssertEquals ("ExcludeClip4", 100, rects[0].Width);
  122. AssertEquals ("ExcludeClip5", 50, rects[0].Height);
  123. AssertEquals ("ExcludeClip6", 10, rects[1].X);
  124. AssertEquals ("ExcludeClip7", 60, rects[1].Y);
  125. AssertEquals ("ExcludeClip8", 30, rects[1].Width);
  126. AssertEquals ("ExcludeClip9", 20, rects[1].Height);
  127. AssertEquals ("ExcludeClip10", 10, rects[2].X);
  128. AssertEquals ("ExcludeClip11", 80, rects[2].Y);
  129. AssertEquals ("ExcludeClip12", 100, rects[2].Width);
  130. AssertEquals ("ExcludeClip13", 30, rects[2].Height);
  131. }
  132. [Test]
  133. public void IntersectClip ()
  134. {
  135. Bitmap bmp = new Bitmap (200, 200);
  136. Graphics g = Graphics.FromImage (bmp);
  137. g.Clip = new Region (new RectangleF (260, 30, 60, 80));
  138. g.IntersectClip (new Rectangle (290, 40, 60, 80));
  139. rects = g.Clip.GetRegionScans (new Matrix ());
  140. AssertEquals ("IntersectClip", 1, rects.Length);
  141. AssertEquals ("IntersectClip", 290, rects[0].X);
  142. AssertEquals ("IntersectClip", 40, rects[0].Y);
  143. AssertEquals ("IntersectClip", 30, rects[0].Width);
  144. AssertEquals ("IntersectClip", 70, rects[0].Height);
  145. }
  146. [Test]
  147. public void ResetClip ()
  148. {
  149. Bitmap bmp = new Bitmap (200, 200);
  150. Graphics g = Graphics.FromImage (bmp);
  151. g.Clip = new Region (new RectangleF (260, 30, 60, 80));
  152. g.IntersectClip (new Rectangle (290, 40, 60, 80));
  153. g.ResetClip ();
  154. rects = g.Clip.GetRegionScans (new Matrix ());
  155. AssertEquals ("ResetClip", 1, rects.Length);
  156. AssertEquals ("ResetClip", -4194304, rects[0].X);
  157. AssertEquals ("ResetClip", -4194304, rects[0].Y);
  158. AssertEquals ("ResetClip", 8388608, rects[0].Width);
  159. AssertEquals ("ResetClip", 8388608, rects[0].Height);
  160. }
  161. [Test]
  162. public void SetClip ()
  163. {
  164. RectangleF[] rects ;
  165. Bitmap bmp = new Bitmap (200, 200);
  166. Graphics g = Graphics.FromImage (bmp);
  167. // Region
  168. g.SetClip (new Region (new Rectangle (50, 40, 210, 220)), CombineMode.Replace);
  169. rects = g.Clip.GetRegionScans (new Matrix ());
  170. AssertEquals ("SetClip1", 1, rects.Length);
  171. AssertEquals ("SetClip2", 50, rects[0].X);
  172. AssertEquals ("SetClip3", 40, rects[0].Y);
  173. AssertEquals ("SetClip4", 210, rects[0].Width);
  174. AssertEquals ("SetClip5", 220, rects[0].Height);
  175. // RectangleF
  176. g = Graphics.FromImage (bmp);
  177. g.SetClip (new RectangleF (50, 40, 210, 220));
  178. rects = g.Clip.GetRegionScans (new Matrix ());
  179. AssertEquals ("SetClip6", 1, rects.Length);
  180. AssertEquals ("SetClip7", 50, rects[0].X);
  181. AssertEquals ("SetClip8", 40, rects[0].Y);
  182. AssertEquals ("SetClip9", 210, rects[0].Width);
  183. AssertEquals ("SetClip10", 220, rects[0].Height);
  184. // Rectangle
  185. g = Graphics.FromImage (bmp);
  186. g.SetClip (new Rectangle (50, 40, 210, 220));
  187. rects = g.Clip.GetRegionScans (new Matrix ());
  188. AssertEquals ("SetClip10", 1, rects.Length);
  189. AssertEquals ("SetClip11", 50, rects[0].X);
  190. AssertEquals ("SetClip12", 40, rects[0].Y);
  191. AssertEquals ("SetClip13", 210, rects[0].Width);
  192. AssertEquals ("SetClip14", 220, rects[0].Height);
  193. }
  194. [Test]
  195. public void SetSaveReset ()
  196. {
  197. Bitmap bmp = new Bitmap (200, 200);
  198. Graphics g = Graphics.FromImage (bmp);
  199. GraphicsState state_default, state_modified;
  200. state_default = g.Save (); // Default
  201. g.CompositingMode = CompositingMode.SourceCopy;
  202. g.CompositingQuality = CompositingQuality.GammaCorrected;
  203. g.InterpolationMode = InterpolationMode.HighQualityBilinear;
  204. g.PageScale = 2;
  205. g.PageUnit = GraphicsUnit.Inch;
  206. g.PixelOffsetMode = PixelOffsetMode.Half;
  207. g.Clip = new Region (new Rectangle (0, 0, 100, 100));
  208. g.RenderingOrigin = new Point (10, 20);
  209. g.SmoothingMode = SmoothingMode.AntiAlias;
  210. g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
  211. state_modified = g.Save (); // Modified
  212. g.CompositingMode = CompositingMode.SourceOver;
  213. g.CompositingQuality = CompositingQuality.Default;
  214. g.InterpolationMode = InterpolationMode.Bilinear;
  215. g.PageScale = 5;
  216. g.PageUnit = GraphicsUnit.Display;
  217. g.PixelOffsetMode = PixelOffsetMode.Default;
  218. g.Clip = new Region (new Rectangle (1, 2, 20, 25));
  219. g.RenderingOrigin = new Point (5, 6);
  220. g.SmoothingMode = SmoothingMode.None;
  221. g.TextRenderingHint = TextRenderingHint.SystemDefault;
  222. g.Restore (state_modified);
  223. AssertEquals ("SetSaveReset1", CompositingMode.SourceCopy, g.CompositingMode);
  224. AssertEquals ("SetSaveReset2", CompositingQuality.GammaCorrected, g.CompositingQuality);
  225. AssertEquals ("SetSaveReset3", InterpolationMode.HighQualityBilinear, g.InterpolationMode);
  226. AssertEquals ("SetSaveReset4", 2, g.PageScale);
  227. AssertEquals ("SetSaveReset5", GraphicsUnit.Inch, g.PageUnit);
  228. AssertEquals ("SetSaveReset6", PixelOffsetMode.Half, g.PixelOffsetMode);
  229. AssertEquals ("SetSaveReset7", new Point (10, 20), g.RenderingOrigin);
  230. AssertEquals ("SetSaveReset8", SmoothingMode.AntiAlias, g.SmoothingMode);
  231. AssertEquals ("SetSaveReset9", TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint);
  232. AssertEquals ("SetSaveReset10", 0, (int) g.ClipBounds.X);
  233. AssertEquals ("SetSaveReset10", 0, (int) g.ClipBounds.Y);
  234. g.Restore (state_default);
  235. AssertEquals ("SetSaveReset11", CompositingMode.SourceOver, g.CompositingMode);
  236. AssertEquals ("SetSaveReset12", CompositingQuality.Default, g.CompositingQuality);
  237. AssertEquals ("SetSaveReset13", InterpolationMode.Bilinear, g.InterpolationMode);
  238. AssertEquals ("SetSaveReset14", 1, g.PageScale);
  239. AssertEquals ("SetSaveReset15", GraphicsUnit.Display, g.PageUnit);
  240. AssertEquals ("SetSaveReset16", PixelOffsetMode.Default, g.PixelOffsetMode);
  241. AssertEquals ("SetSaveReset17", new Point (0, 0) , g.RenderingOrigin);
  242. AssertEquals ("SetSaveReset18", SmoothingMode.None, g.SmoothingMode);
  243. AssertEquals ("SetSaveReset19", TextRenderingHint.SystemDefault, g.TextRenderingHint);
  244. Region r = new Region ();
  245. AssertEquals ("SetSaveReset20", r.GetBounds (g) , g.ClipBounds);
  246. g.Dispose ();
  247. }
  248. [Test]
  249. public void LoadIndexed ()
  250. {
  251. //
  252. // Tests that we can load an indexed file
  253. //
  254. Stream str = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("indexed.png");
  255. Image x = Image.FromStream (str);
  256. Graphics g = Graphics.FromImage (x);
  257. }
  258. [Test]
  259. [ExpectedException (typeof (ArgumentNullException))]
  260. public void FromImage ()
  261. {
  262. Graphics g = Graphics.FromImage (null);
  263. }
  264. private Graphics Get (int w, int h)
  265. {
  266. Bitmap bitmap = new Bitmap (w, h);
  267. Graphics g = Graphics.FromImage (bitmap);
  268. g.Clip = new Region (new Rectangle (0, 0, w, h));
  269. return g;
  270. }
  271. private void Compare (string msg, RectangleF b1, RectangleF b2)
  272. {
  273. AssertEquals (msg + ".compare.X", b1.X, b2.X);
  274. AssertEquals (msg + ".compare.Y", b1.Y, b2.Y);
  275. AssertEquals (msg + ".compare.Width", b1.Width, b2.Width);
  276. AssertEquals (msg + ".compare.Height", b1.Height, b2.Height);
  277. }
  278. [Test]
  279. public void Clip_GetBounds ()
  280. {
  281. Graphics g = Get (16, 16);
  282. RectangleF bounds = g.Clip.GetBounds (g);
  283. AssertEquals ("X", 0, bounds.X);
  284. AssertEquals ("Y", 0, bounds.Y);
  285. AssertEquals ("Width", 16, bounds.Width);
  286. AssertEquals ("Height", 16, bounds.Height);
  287. Assert ("Identity", g.Transform.IsIdentity);
  288. g.Dispose ();
  289. }
  290. [Test]
  291. public void Clip_TranslateTransform ()
  292. {
  293. Graphics g = Get (16, 16);
  294. g.TranslateTransform (12.22f, 10.10f);
  295. RectangleF bounds = g.Clip.GetBounds (g);
  296. Compare ("translate", bounds, g.ClipBounds);
  297. AssertEquals ("translate.X", -12.22, bounds.X);
  298. AssertEquals ("translate.Y", -10.10, bounds.Y);
  299. AssertEquals ("translate.Width", 16, bounds.Width);
  300. AssertEquals ("translate.Height", 16, bounds.Height);
  301. float[] elements = g.Transform.Elements;
  302. AssertEquals ("translate.0", 1, elements[0]);
  303. AssertEquals ("translate.1", 0, elements[1]);
  304. AssertEquals ("translate.2", 0, elements[2]);
  305. AssertEquals ("translate.3", 1, elements[3]);
  306. AssertEquals ("translate.4", 12.22, elements[4]);
  307. AssertEquals ("translate.5", 10.10, elements[5]);
  308. g.ResetTransform ();
  309. bounds = g.Clip.GetBounds (g);
  310. Compare ("reset", bounds, g.ClipBounds);
  311. AssertEquals ("reset.X", 0, bounds.X);
  312. AssertEquals ("reset.Y", 0, bounds.Y);
  313. AssertEquals ("reset.Width", 16, bounds.Width);
  314. AssertEquals ("reset.Height", 16, bounds.Height);
  315. Assert ("Identity", g.Transform.IsIdentity);
  316. g.Dispose ();
  317. }
  318. [Test]
  319. [ExpectedException (typeof (ArgumentException))]
  320. public void Transform_NonInvertibleMatrix ()
  321. {
  322. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  323. Assert ("IsInvertible", !matrix.IsInvertible);
  324. Graphics g = Get (16, 16);
  325. g.Transform = matrix;
  326. }
  327. private void CheckBounds (string msg, RectangleF bounds, float x, float y, float w, float h)
  328. {
  329. AssertEquals (msg + ".X", x, bounds.X, 0.1);
  330. AssertEquals (msg + ".Y", y, bounds.Y, 0.1);
  331. AssertEquals (msg + ".Width", w, bounds.Width, 0.1);
  332. AssertEquals (msg + ".Height", h, bounds.Height, 0.1);
  333. }
  334. [Test]
  335. public void ClipBounds ()
  336. {
  337. Graphics g = Get (16, 16);
  338. CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
  339. CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
  340. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  341. CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
  342. CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  343. }
  344. [Test]
  345. public void ClipBounds_Rotate ()
  346. {
  347. Graphics g = Get (16, 16);
  348. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  349. g.RotateTransform (90);
  350. CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
  351. CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
  352. g.Transform = new Matrix ();
  353. CheckBounds ("identity.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  354. CheckBounds ("identity.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  355. }
  356. [Test]
  357. public void ClipBounds_Scale ()
  358. {
  359. RectangleF clip = new Rectangle (0, 0, 8, 8);
  360. Graphics g = Get (16, 16);
  361. g.Clip = new Region (clip);
  362. g.ScaleTransform (0.25f, 0.5f);
  363. CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 32, 16);
  364. CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 32, 16);
  365. g.SetClip (clip);
  366. CheckBounds ("setclip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
  367. CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  368. }
  369. [Test]
  370. public void ClipBounds_Translate ()
  371. {
  372. Graphics g = Get (16, 16);
  373. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  374. Region clone = g.Clip.Clone ();
  375. g.TranslateTransform (8, 8);
  376. CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
  377. CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
  378. g.SetClip (clone, CombineMode.Replace);
  379. CheckBounds ("setclip.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  380. CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  381. }
  382. [Test]
  383. public void ClipBounds_Transform_Translation ()
  384. {
  385. Graphics g = Get (16, 16);
  386. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  387. g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
  388. CheckBounds ("transform.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
  389. CheckBounds ("transform.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
  390. g.ResetTransform ();
  391. CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
  392. CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  393. }
  394. [Test]
  395. public void ClipBounds_Transform_Scale ()
  396. {
  397. Graphics g = Get (16, 16);
  398. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  399. g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
  400. CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
  401. CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
  402. g.ResetClip ();
  403. // see next test for ClipBounds
  404. CheckBounds ("resetclip.Clip.GetBounds", g.Clip.GetBounds (g), -4194304, -4194304, 8388608, 8388608);
  405. Assert ("IsInfinite", g.Clip.IsInfinite (g));
  406. }
  407. [Test]
  408. [Category ("NotWorking")]
  409. public void ClipBounds_Transform_Scale_Strange ()
  410. {
  411. Graphics g = Get (16, 16);
  412. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  413. g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
  414. CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
  415. CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
  416. g.ResetClip ();
  417. // note: strange case where g.ClipBounds and g.Clip.GetBounds are different
  418. CheckBounds ("resetclip.ClipBounds", g.ClipBounds, -8388608, -16777216, 16777216, 33554432);
  419. }
  420. [Test]
  421. public void ClipBounds_Multiply ()
  422. {
  423. Graphics g = Get (16, 16);
  424. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  425. g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
  426. g.MultiplyTransform (g.Transform);
  427. CheckBounds ("multiply.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
  428. CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
  429. g.ResetTransform ();
  430. CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
  431. CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  432. }
  433. [Test]
  434. public void ClipBounds_Cumulative_Effects ()
  435. {
  436. Graphics g = Get (16, 16);
  437. CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
  438. CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
  439. g.Clip = new Region (new Rectangle (0, 0, 8, 8));
  440. CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
  441. CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
  442. g.RotateTransform (90);
  443. CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
  444. CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
  445. g.ScaleTransform (0.25f, 0.5f);
  446. CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, -16, 32, 16);
  447. CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 32, 16);
  448. g.TranslateTransform (8, 8);
  449. CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -24, 32, 16);
  450. CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -24, 32, 16);
  451. g.MultiplyTransform (g.Transform);
  452. CheckBounds ("multiply.ClipBounds", g.ClipBounds, -104, -56, 64, 64);
  453. CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -104, -56, 64, 64);
  454. }
  455. [Test]
  456. [ExpectedException (typeof (ArgumentException))]
  457. public void ScaleTransform_X0 ()
  458. {
  459. Graphics g = Get (16, 16);
  460. g.ScaleTransform (0, 1);
  461. }
  462. [Test]
  463. [ExpectedException (typeof (ArgumentException))]
  464. public void ScaleTransform_Y0 ()
  465. {
  466. Graphics g = Get (16, 16);
  467. g.ScaleTransform (1, 0);
  468. }
  469. }
  470. }