%% Placing text along an arbitrary path                                     
%%                PostScript Language Tutorial and Cookbook

/pathtextdict 26 dict def
/pathtext {
  pathtextdict begin
  /offset exch def
  /str exch def
  /pathdist 0 def
  /setdist offset def
  /charcount 0 def
  gsave
    flattenpath
    { movetoproc } { linetoproc } 
    { curvetoproc } {closepathproc} pathforall
    grestore
  newpath
  end
  } def

pathtextdict begin
  /movetoproc {
    /newy exch def
    /newx exch def
    /firstx newx def
    /firsty newy def
    /ovr 0 def
    newx newy transform
    /cpy exch def /cpx exch def
    } def

  /linetoproc {
    /oldx newx def /oldy newy def
    /newy exch def /newx exch def
    /dx newx oldx sub def
    /dy newy oldy sub def
    /dist dx dup mul dy dup mul add sqrt def
    dist 0 ne {
      /dsx dx dist div ovr mul def
      /dsy dy dist div ovr mul def
      oldx dsx add oldy dsy add transform
      /cpy exch def /cpx exch def
      /pathdist pathdist dist add def
      {
        setdist pathdist le
        { charcount str length lt
          {setchar} {exit} ifelse }
        { /ovr setdist pathdist sub def
          exit } ifelse
        } loop
      } if
    } def

  /curvetoproc {
    (ERROR : No curveto's after flattenpath!\n) print
    } def

  /closepathproc {
    firstx firsty linetoproc
    firstx firsty movetoproc
    } def

  /setchar {
    /char str charcount 1 getinterval def
    /charcount charcount 1 add def
    /charwidth char stringwidth pop def
    gsave
      cpx cpy itransform translate
      dy dx atan rotate
      0 0 moveto char show
      currentpoint transform
      /cpy exch def /cpx exch def
      grestore
    /setdist setdist charwidth add def
    } def
  end


/Times-Roman findfont 15 scalefont setfont
newpath
  270 500 moveto
  200 500 70 0 270 arc
  200 110 add 500 70 270 180 arc

(If my film makes one more person feel\
 miserable I'll feel I've done my job.\
 -- WOODY ALLEN) 55 pathtext

newpath
  150 310 moveto 360 310 lineto
  360 400 lineto 150 400 lineto
  closepath
  360 347 moveto 410 330 lineto
  410 380 lineto 360 363 lineto
2 setlinewidth stroke
showpage

