PyX — Example: text/textalongpath.py

0.5 KB
4.5 KB
26.5 KB
13.8 KB

Text along path

textalongpath.png
from pyx import *

c = canvas.canvas()

p = path.path(path.moveto(-2, 0), path.curveto(-1, 0, -1, 1, 0, 1), path.curveto(1, 1, 1, 0, 2, 0))

c.stroke(p, [deco.curvedtext("\PyX{} is fun!"),
             deco.curvedtext("left", textattrs=[text.halign.left, text.vshift.mathaxis], arclenfrombegin=0.5, exclude=0.1),
             deco.curvedtext("right", textattrs=[text.halign.right, text.vshift.mathaxis], arclenfromend=0.5, exclude=0.1)])

c.writeEPSfile("textalongpath")
c.writePDFfile("textalongpath")

Description

In order to set text along a given path, you can use the curvedtext() decorator. The example shows a few useful parameter settings for this decorator.

To output just the curved text, but not the path, you can use the draw method of the canvas instead of the stroke method. By that the path is omitted in the output completely. In contrast, if you set the linewidth to zero instead, the path will still be visible, as those lines will be rendered as the thinnest available linewidth on the output device according to the PostScript and PDF specification.