Haskell 为什么';你不能翻译文本吗?
在下面的程序中,我使用Haskell 为什么';你不能翻译文本吗?,haskell,cairo,Haskell,Cairo,在下面的程序中,我使用cairo-0.12.2绘制了一些带有字母的小方框。不幸的是,当我使用translate函数移动用户空间原点时,矩形会被平移,但文本不会被平移 import Graphics.Rendering.Cairo main = withSVGSurface "test.svg" 600 600 (`renderWith` draw) draw = do color white rectangle 0 0 600 600 fill newPath co
cairo-0.12.2
绘制了一些带有字母的小方框。不幸的是,当我使用translate
函数移动用户空间原点时,矩形会被平移,但文本不会被平移
import Graphics.Rendering.Cairo
main = withSVGSurface "test.svg" 600 600
(`renderWith` draw)
draw = do
color white
rectangle 0 0 600 600
fill
newPath
color black
translate 300 300
drawSortBox
translate 200 200
drawSortBox
stroke
drawSortBox = do
showText "V Ʌ"
a <- textExtents "V Ʌ"
rectangle (textExtentsXbearing a - 2) (textExtentsYbearing a - 2) (textExtentsWidth a / 2 + 2) (textExtentsHeight a + 4)
rectangle (textExtentsXbearing a - 2) (textExtentsYbearing a - 2) (textExtentsWidth a + 4) (textExtentsHeight a + 4)
color (a,b,c) = setSourceRGB a b c
white = (255,255,255)
black =(0,0,0)
import Graphics.Rendering.Cairo
main=withSVGSurface“test.svg”600
(`renderWith`draw)
画=做
白色
矩形0 0 600 600
填满
新路径
黑色
翻译300 300
牵引箱
翻译200
牵引箱
(打、击等的)一下
drawSortBox=do
showText“VɅ”
a根据文档,showText
从当前位置开始绘制文本<代码>平移
移动原点,但不移动当前位置。您必须使用moveTo
而不是translate
来选择文本的位置。(第一次调用时,translate
恰好起作用的事实与newPath
删除当前位置有关。)