<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">I have a strange problem,
which is so elementary that I think I must be missing something...<br>
<br>
In GTK2HS, when I draw text using using textPath, the text is located
at different locations depending on which backend is used. I'm not
talking about a difference of a couple of pixels , but in my case it's
half a page off. The PNG and Win32 backend work fine, but the PDF/PS
backends get it wrong. <br>
<br>
For example, I modified the Text.hs demo in the demos/Cairo
subdirectory so it also outputs PDF. Here the text is also at different
locations, so I guess it's not just my code. Code is pasted below.<br>
<br>
I'm using Windows, and GTK2HS version 0.9.12 from
<a class="moz-txt-link-freetext" href="http://www.haskell.org/gtk2hs">http://www.haskell.org/gtk2hs</a><br>
<br>
Maybe someone could give this a quick test on Linux? <br>
<br>
I guess this is most likely a Cairo problem, and has nothing to do with
the Haskell wrapper? Still this is hard to believe, since these kinds
of bugs would be quickly found.<br>
<br>
Thanks,<br>
Peter<br>
<br>
</font><tt>----------------------------------------<br>
</tt><font face="Helvetica, Arial, sans-serif"><br>
import Graphics.Rendering.Cairo<br>
import qualified Graphics.Rendering.Cairo.Matrix as M<br>
<br>
boxText :: String -> Double -> Double -> Render ()<br>
boxText text x y = do<br>
save<br>
<br>
lineWidth <- getLineWidth<br>
<br>
(TextExtents xb yb w h _ _) <- textExtents text<br>
<br>
rectangle (x + xb - lineWidth)<br>
(y + yb - lineWidth)<br>
(w + 2 * lineWidth)<br>
(h + 2 * lineWidth)<br>
stroke<br>
moveTo x y<br>
textPath text<br>
fillPreserve<br>
setSourceRGBA 0 0 1 0.5<br>
setLineWidth 3.0<br>
stroke<br>
<br>
restore<br>
<br>
transpSurface :: Double -> Double -> Render ()<br>
transpSurface w h = do<br>
save<br>
rectangle 0 0 w h<br>
setSourceRGBA 0 0 0 0<br>
setOperator OperatorSource<br>
fill<br>
restore<br>
<br>
width = 400<br>
height = 300<br>
<br>
main :: IO ()<br>
main = withImageSurface FormatARGB32 width height $ \surface -> do<br>
<br>
let render = do<br>
setSourceRGB 0.0 0.0 0.0<br>
setLineWidth 2.0<br>
<br>
transpSurface (fromIntegral width) (fromIntegral height)<br>
<br>
selectFontFace "sans" FontSlantNormal FontWeightNormal<br>
setFontSize 40<br>
<br>
extents <- fontExtents<br>
let fontHeight = fontExtentsHeight extents<br>
<br>
boxText "Howdy, world!" 10 fontHeight<br>
<br>
translate 0 fontHeight<br>
<br>
save<br>
translate 10 fontHeight<br>
rotate (10.0 * pi / 180.0)<br>
boxText "Yay for Haskell!" 0 0<br>
restore<br>
<br>
translate 0 (3 * fontHeight)<br>
<br>
save<br>
setFontMatrix $ M.rotate ((-10.0) * pi / 180.0) $ M.scale 40.0
40.0 M.identity<br>
boxText "...and Cairo!" 10 fontHeight<br>
restore<br>
<br>
renderWith surface render<br>
<br>
surfaceWriteToPNG surface "Text.png"<br>
<br>
withPDFSurface "Text.pdf" (realToFrac width) (realToFrac height)
(flip renderWith $ render >> showPage)<br>
<br>
return ()<br>
<br>
<br>
<br>
<br>
</font>
</body>
</html>