首页 文章

为什么cairo不翻译文本?

提问于
浏览
2

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

1 回答

  • 5

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

相关问题