gpt4 book ai didi

haskell - 为什么 cairo 不翻译文本?

转载 作者:行者123 更新时间:2023-12-02 05:24:22 24 4
gpt4 key购买 nike

在下面的程序中,我使用 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)

最佳答案

根据文档,showText 从当前位置开始绘制文本。 translate 移动原点,但不移动当前位置。您必须使用 moveTo 而不是 translate 来选择文本的位置。 (translate 碰巧在第一次调用时起作用的事实与 newPath 删除当前位置的事实有关。)

关于haskell - 为什么 cairo 不翻译文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com