[Gambas-user] Cairo: coordinates

Rolf-Werner Eilert eilert-sprachen at ...221...
Tue Aug 20 09:41:30 CEST 2013



Am 20.08.2013 09:28, schrieb Rolf-Werner Eilert:
> What confused me a bit when using Cairo was the coordinates system.
>
> Initiating the page with width = 210 mm and height = 297 mm, I would
> expect to be able to center a string of text with
>
>    Cairo.MoveTo((210 / 2) - (Cairo.TextExtents("Hello world").Width / 2), 40)
>
> for example (in practice, I would write 105 instead of 210 / 2 of course...)
>
> Now, it turned out instead that I had to write
>
>    Cairo.MoveTo(297 - (Cairo.TextExtents("Hello world").Width / 2), 40)
>
> to center the line, so obviously the page is 297 * 2 wide, not 210 mm.
>
> Why's that?
>
> Rolf
>

I have to add that this problem only came up because there seems to be 
no property delivering the page width (or surface width) in user 
coordinates. At least I haven't found one. If there was, the line would 
go something like

  Cairo.MoveTo((Cairo.SurfaceExtents.Width / 2) - 
(Cairo.TextExtents("Hell world").Width / 2), 40)

That's why I had to use a fixed value.

Rolf





More information about the User mailing list