Re: [gnome-print] gnome-print coordinate system



Hello!

The best would be to read some good textbook about elementary
computational geometry, or PostScript printer control language.
Gnome-print uses very common notation of coordinates and
coordinate transformation, but to explain it fully goes
beyound my tutoring skill ;)

Background:

All graphic operations are specified in 'user coordinates'. The
actual (device) coordinates are calculated by gnome-print, using
3x2 matrix, called CTM (current transformation matrix). Initially
this matrix is identity (i.e. user-coords are the same as device
coords, but applications can modify matrix).

The transformation algoritm is:

X' = A0 * x + A2 * y + A4
Y' = A1 * x + A3 * y + A5

X', Y' - final (output, device) coordinates
x, y - user (input, local) coordinates

Using that 6-element matrix, one can easily describe all affine
transformations (moving, scaling, rotating, tilting and
all combinations of these), without using different set of
parameters for each operation.

This is extremely convenient - take, for example, bonobo component
inside some bigger application. Without automatic coordinate
transformation, this component has to know its exact position
on page, if printed. But having coordinate transformation,
container can set up user coordinate system for component, so
that component can print everything in, say, 0,0-1,1 square. The
same technique allows EPS (encapsulated PostScript) files to be
embedded in PostScript jobs - they print right, however they are
placed, scaled etc...

OK, operators:

gnome_print_concat (ctx, matrix)

Multiplies CTM with given matrix. If you do not know, how
to set matrix up, you should be not using it anyways.

gnome_print_translate (ctx, x, y)

Adds translation to CTM. The new user 0,0 is now at previous
x,y - so everything appears moved by x, y

gnome_print_scale (ctx, sx, sy)

Adds scaling to CTM. Everything printed afterwards appears scaled by
dx, dy in x and y directions

gnome_print_rotate (ctx, theta)

Add rotation. Everyting printed afterwards appears rotated by theta
degrees around 0,0

Now, say you want to rotate image around center 100,200 instead of
0,0. To do that, you have to combine operations:

gnome_print_translate (ctx, 100, 200)
gnome_print_rotate (ctx, theta)

Remember - translate changes the position of new 0,0 to old 100,200.

OK. All operations are cumulative. To get rid of complex transformations
you have to use gsave/grestore methods:

gnome_print_gsave (ctx)
/* Do some scaling, rotating, translating, etc... */
gnome_print_grestore (ctx)

after calling grestore, CTM is again the same, as it was before
gsave method (to be precise - not only CTM, but also colors,
line styles and font settings are resored).

CTM operations are necessary to print bitmaps at all - all bitmaps
are positioned in 0,0-1,1 rectangle in user coordinates - so if you
do not want these to appear in tiny dot in lower-left corner of
paper, you have to set up coordinate system. Look at
http://www.gnome.org/projects/gnome-print
FAQ section for how to do that ;)

Ah, and little hint:
  gnome_print_scale (ctx, sx, sy);
does the same as:
  double affine[6];
  art_affine_scale (affine, sx, sy);
  gnome_print_concat (ctx, affine);
So in reality, there is only single coordinate operation in gnome-print 
API - all other are just convenience frontends to that...

Hope this helps

Best wishes,
Lauris Kaplinski

On Sat, 2002-02-23 at 09:55, Harsha Kodnad wrote:
> 
> 
> can anybody explain me what is this 
> gnome_print_translate and
> gnome_print_scale
> gnome_print_concat ?
> 
> what are the arguments ?
> how to use it
> 
> regards
> 
> 
> 
> =====
> Harsha Kodnad
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - Coverage of the 2002 Olympic Games
> http://sports.yahoo.com
> 
> _______________________________________________
> Gnome-print maillist  -  Gnome-print@ximian.com
> http://lists.ximian.com/mailman/listinfo/gnome-print






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]