Bug 19632 - Problems with transforms
Summary: Problems with transforms
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: libgdiplus ()
Version: 3.0.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-09 00:34 UTC by contact
Modified: 2014-05-09 02:25 UTC (History)
1 user (show)

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 19632 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:

Description contact 2014-05-09 00:34:02 UTC
I'm trying to use a .Net SVG library to render an SVG, and getting strange results with transforms (which Inkscape uses a lot).

The layer has a transform of -62, -204. A text object in it has a scale transform of 0.36, 2.75. This gives a matrix of [0.36, 0, 0, 2.75, 0, 0]. Before setting System.Drawing.Graphics.Transform (which simply calls libgdiplus's GdipSetWorldTransform), it returns an identity matrix. After setting Graphics.Transform with the afore-mentioned matrix, it returns [0.36, 0, 0, 2.75, 62, 204]. The text object contains a tspan with the actual text, with no transform. Graphics.Transform once again returns an identity matrix. Since the tspan has no transform, Graphics.Transform is assigned an identity matrix. Graphics.Transform now returns [2.75, 0, 0, 0.36, 0, 0]. The same thing happens with the other text, groups and paths in the SVG. The end result is exactly the same as going into Inkscape, opening the XML editor, and deleting all the transform attributes. On Windows (.Net), it works perfectly. 

What I'm seeing is that setting the transform produces a transform such that the previous transform is undone, rather than simply setting the transform to what is specified. And what is strange is that assigning an identity matrix changes the result (including in what is drawn). Unfortunately I'm not a C programmer or particularly experienced with matrix transforms, or I'd have a go at fixing it -- this is probably a difference in how Cairo handles cairo_set_matrix compared to how Windows handles SetWorldTransform.

I've also tested with the latest Git as of a couple of days ago, with little difference and no improvement.
Comment 1 contact 2014-05-09 02:25:54 UTC
Here's a workaround that I found works for me:

Matrix TransformMatrix = new Matrix(m11, m12, m21, m22, dx, dy);
Type t = Type.GetType ("Mono.Runtime");
if (t != null) {
    if (this.Parent != null) {
        var parent = this.Parent;
        TransformMatrix.Multiply(parent.TransformMatrix, MatrixOrder.Append);
graphics.Transform = TransformMatrix;