[cairo] Two usage questions( matrix and fill with dash stroke)

Markus Schumann go4shoe at hotmail.com
Tue Apr 8 14:42:50 PDT 2008


Below an answer to your first question:

 

Assume for all answers:

 

class Transformation : public cairo_matrix_t

 

a) rotation: 

 

////////////////////////////////////////////////////////////////////////////
///////////////////////

double Transformation::getRotation() const

////////////////////////////////////////////////////////////////////////////
///////////////////////

{

   double x1 = 0;

   double y1 = 0;

   double x2 = 1;

   double y2 = 0;

 

   cairo_matrix_transform_point( this,

                                 & x1,

                                 & y1 );

 

   cairo_matrix_transform_point( this,

                                 & x2,

                                 & y2 );

 

   double dy       = abs(y2-y1);

   double l        = sqrt( pow(x2-x1,2) + pow(y2-y1,2) );

   double rotation = asin(dy/l);

 

   //

   // correct for quadrant

   //

   if (y2 - y1 > 0.0)

   {

      if (x2 - x1 < 0.0)

      {

         rotation = PI - rotation;

      }

   }

   else

   {

      if (x2 - x1 > 0.0)

      {

         rotation = 2 * PI - rotation;

      }

      else

      {

         rotation = rotation + PI;

      }

   }

 

   return rotation;

   

}

 

b) scale

 

////////////////////////////////////////////////////////////////////////////
///////////////////////

double Transformation::getScale() const

////////////////////////////////////////////////////////////////////////////
///////////////////////

{

   double x1 = 0;

   double y1 = 0;

   double x2 = 1;

   double y2 = 0;

 

   cairo_matrix_transform_point( this,

                                 & x1,

                                 & y1 );

 

   cairo_matrix_transform_point( this,

                                 & x2,

                                 & y2 );

 

   double l_dScale = sqrt( pow(x2-x1,2) + pow(y2-y1,2) );

 

   return l_dScale;

}

 

c:) offset

 

////////////////////////////////////////////////////////////////////////////
///////////////////////

double Transformation::getTranslateY() const

////////////////////////////////////////////////////////////////////////////
///////////////////////

{

   return y0;

}

 

////////////////////////////////////////////////////////////////////////////
///////////////////////

double Transformation::getTranslateX() const

////////////////////////////////////////////////////////////////////////////
///////////////////////

{

   return x0;

}

 

 

 

  _____  

From: cairo-bounces at cairographics.org
[mailto:cairo-bounces at cairographics.org] On Behalf Of Cong Chen
Sent: Tuesday, April 08, 2008 9:49 AM
To: cairo at cairographics.org
Subject: [cairo] Two usage questions( matrix and fill with dash stroke)

 

Hi there

 

1.	If I have cairo_matrix_t, any ways that I can get the rotation
angle, scale size and the translation offset from it?

 

2.   When I use cairo_fill_preserve(), then use cairo_stroke() to stroke the
shape with a dash stroke, the fill and stroke overlap and looks ugly. Any
way to make the fill just fill inside the stroke, not overlap with it?

 

Thanks

 

 

Cong Chen         
Core Assets Developer
SMART Technologies ULC.
* Ph. (403) 769-8762

* congchen at smarttech.com
* www.smarttech.com <http://www.smarttech.com/> 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080408/532cb053/attachment-0001.htm 


More information about the cairo mailing list