Autore Topic: Cairo: le Coordinate  (Letto 377 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.301
  • Ne mors quidem nos iunget
    • Mostra profilo
Cairo: le Coordinate
« il: 20 Agosto 2013, 16:36:08 »
Riporto questa domanda inserita nella M.L.I.:


" 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


  
Codice: gambas [Seleziona]
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


  
Codice: gambas [Seleziona]
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


 
Codice: gambas [Seleziona]
Cairo.MoveTo((Cairo.SurfaceExtents.Width / 2) - (Cairo.TextExtents("Hell world").Width / 2), 40)


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

Rolf
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »