Bug 7007 - Graphics.SetClip gives incorrect results if PageUnit is not Pixel on Mac runtime
Summary: Graphics.SetClip gives incorrect results if PageUnit is not Pixel on Mac runtime
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Drawing ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-08 09:52 UTC by xamarinbugs
Modified: 2012-09-08 09:52 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 7007 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description xamarinbugs 2012-09-08 09:52:25 UTC
If Graphics.SetClip is used in combination with changing the PageUnit and applying transformations, then the resulting clip area does not match the results in Windows .net 2 runtime.  It appears that some of the transformation and/or unit change logic is applied to the clipping area, which is ignored within the Microsoft runtime.  However the exact results are strange enough that I've been unable to deduce exactly what is occurring in order to devise a work-around.

To reproduce, create a blank Windows.Forms form at least 60mm * 60mm, and add this code to the form Paint event:

			Rectangle rct = new Rectangle(5, 5, 50, 50);
			e.Graphics.PageUnit = GraphicsUnit.Millimeter;
			e.Graphics.DrawRectangle(Pens.Red, rct); // draw expected target area
			// try to set clipping area just inside drawn line...
			rct.Inflate(-1, -1);
			e.Graphics.SetClip(rct);
			e.Graphics.TranslateTransform(5, 5); // has no effect on clipped area in Windows
			e.Graphics.Clear(Color.Green); // shows clipping area by colouring entire (clipped) graphics surface
			// resulting rectangle should be just inside red rectangle
			// or: e.Graphics.FillRectangle(Brushes.Green, 0, 0, 50, 50);

Results differ between Windows and Mac with Mono runtime, with the latter giving illogical/unpredictable results.  The order of changing page unit, clipping and applying transformations appears to make little difference - results are incorrect no matter which order effects are applied.  I believe the same issue occurs with other transformations, not just TranslateTransform.
If the PageUnit is left as pixel, the code above works correctly showing the clipped area inside the (now smaller) rectangle, matching the results on Windows.