Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

http://www.cairographics.org/manual/cairo-Transformations.html

I have been using Cairo Vector Graphics Library for some work, and I can't quite understand some parts:

What is the default value of the transformation matrix?

When do I need the transformation matrix anyway?

Suppose I don't want to rotate text, will I still need to set it, will it still be set?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

First, see the wikipedia page on transformation matrices. That should help with the terminology. Next, understand that there are two matrices involved at any given time.

  1. The "prime" matrix
  2. The "item" matrix

The prime matrix usually starts out as a bunch of zeros and a one:

[0 0 0]
[0 0 0]
[0 0 1]

This means do nothing. Next the item's matrix is determined. Once it's time to start laying things onto the device, then these two matrices are combined with an affine transformation.

This transformation gives you a point off of the starting position to draw your item, with any appropriate scaling or rotation.

Since the prime matrix is used across all of the items, we can adjust it to have some universal effect. Say we want to shift everything "left" 50 points. You're lucky in that you wouldn't have to manually set your matrix to do this, just call cairo_translate(cr, -50, 0) or something similar.

Now every new item rendered will be modified.

share|improve this answer
    
Spencer : I would like to ask that inorder to rotate the text would I need to call the function cairo_get_matrix or set its value using cairo_set_matrix,or calling the cairo_rotate() set the matrix by itself ? –  potato man Jun 18 '12 at 17:16
    
@Aaditya Do you wish to rotate all the text, or just a specific text element? Whichever you decide, use the appropriate matrix pointer, *cr, and run cairo_rotate(cr, your_angle). This will update the matrix you gave it to the new value. If you have already determined what the matrix should be, then you would call cairo_set_matrix(cr, new_cr). –  Spencer Rathbun Jun 18 '12 at 17:24
    
I need to rotate the entire text for now, but I understand what you are saying, also can you please tell me what do you mean by **use the appropriate matrix pointer, *cr ** Does cr point to the transformation matrix ? –  potato man Jun 18 '12 at 17:29
    
@Aaditya *cr is what the docs you linked to uses in the example. In general * means pointer, and cr is just a var name. I assume that means they want your pointer to the appropriate matrix. See here for details on pointers. –  Spencer Rathbun Jun 18 '12 at 17:33
    
I know about pointers :P thanks for the help :) –  potato man Jun 18 '12 at 17:36

As far as I can tell from the documentation, you have an structure "Cairo_t", this "Cairo T" is what the transformations get placed into. Each "Cairo Matrix" is a "Transformation Matrix" regardless of whether or not it is "doing stuff" to the text. The initial structure has no values, it's just a block of memory assigned to a rendering device.

In order to make that do anything and thus pass the changes to the rendering device you have to perform actions on the structure by assigning transformations to it. These transformations include getting and setting matrices and transforming them.

The fact that it is called "Cairo Transformation Matrix" is due to the fact that it can be transformed not that it will be. Although one could argue that all actions on the structure in question are transforms.

share|improve this answer
    
what you mean is that cairo_t is the structure that contains information about, current state of the rendering device, including coordinates. And multiplication by the transformation matrix sets its value. –  potato man Jun 18 '12 at 15:21
    
Also what I want to ask is that inorder to rotate the text would I need to call the function cairo_get_matrix or set its value using cairo_set_matrix, or the function call to cairo_rotate() be enough ? –  potato man Jun 18 '12 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.