[Gtk-sharp-list] Anomaly/bug with Cairo.Context Transformation Matrix?

chubbs sol.chubb at gmail.com
Sat Dec 31 15:16:11 EST 2011


I've noticed that it is not possible to set the individual elements of 
the Current Transformation Matrix (CTM) via the Context.Matrix property, 
even though the class reference suggests that this should be OK. For 
example,

public void SetX0( Cairo.Context cr, double x0){
     cr.Matrix.X0 = x0;    // this doesn't work

     Cairo.Matrix m = cr.Matrix; // but this does
     m.X0 = x0;
     cr.Matrix = m;
}

Since Cairo.Matrix is a class, cr.Matrix should be a reference to the 
CTM, so the first version might be expected to work.  However, looking 
at the source code 
(https://github.com/mono/gtk-sharp/blob/master/cairo/Context.cs) the get 
accessor for cr.Matrix actually returns a cloned copy of the CTM, so any 
changes to the elements will be on this copy, not on the actual CTM.  
(Digging a bit more, the same approach is taken in the System.Drawing 
namespace, with the Graphics class and the equivalent CTM property).  
Using the second approach is no big problem (and can actually have its 
uses, when keeping partial transforms around) but can anyone with more 
knowledge provide any enlightenment as to why it's done this way, rather 
than follow the class API correctly?



More information about the Gtk-sharp-list mailing list