You also could've generated the Lisp code directly using PostScript :)
%!PS % load font file % (you don't need this, if you have a .pfa file, in which case % you can directly specify it on the gs command line: % $ gs -q -dNODISPLAY ZURIFB__.pfa 683209.ps ) (./ZURIFB__.pfb) % or whatever your .pfb file is (r) file true /PFBDecode filter cvx mark exch exec cleartomark /ZurichFigurine-Bold findfont 12 scalefont setfont /print_width { dup ( \(" " ) dup 4 4 -1 roll putinterval print % '("X" ' stringwidth pop 20 string cvs print % width (\)) print % ')' } bind def /i2s { % int/char to string ( ) dup 0 4 -1 roll put } bind def (\(setq ZURIFB__afm12 '\() = % 1st line (RNBQKO-x+.abcdefgh1234567890) { % char list i2s dup print_width (0) ne {()=} if % "\n", unless last char } forall (\)\)) = % "))\n" quit
Running this with Ghostscript
$ gs -q -dNODISPLAY 683209.ps
would've produced something like (note that I don't have the (apparently commercial) ZurichFigurine font, so I substituted Helvetica for demo purposes — you should get the proper widths with the real font...)
(setq ZURIFB__afm12 '( ("R" 8.66016) ("N" 8.66016) ("B" 8.00391) ("Q" 9.33594) ("K" 8.00391) ("O" 9.33594) ("-" 3.99219) ("x" 6.0) ("+" 7.00781) ("." 3.33594) ("a" 6.67188) ("b" 6.67188) ("c" 6.0) ("d" 6.67188) ("e" 6.67188) ("f" 3.33594) ("g" 6.67188) ("h" 6.67188) ("1" 6.67188) ("2" 6.67188) ("3" 6.67188) ("4" 6.67188) ("5" 6.67188) ("6" 6.67188) ("7" 6.67188) ("8" 6.67188) ("9" 6.67188) ("0" 6.67188)))
BTW, as you might have inferred from the above snippet, PostScript has a native stringwidth function which determines the actual display width of a string (for a given font and fontsize). IOW, for the PS output of your module, you wouldn't necessarily even need the explicit font metrics. You could simply define a center routine in PS like this
%!PS /center { % move cursor position to the left by half the width dup stringwidth pop 2 div neg 0 rmoveto } bind def /Helvetica findfont 12 scalefont setfont % draw "ABC" left-aligned (as normal) at (100,100) 100 100 moveto (ABC) show % draw "ABC" horizontally centered around (100,100) 100 100 moveto (ABC) center show
Of course, this wouldn't help with the LaTeX and other backends... (but as you mentioned having fun :)
In reply to Re: Code that writes code that writes code: Perl to Lisp to Postscript
by almut
in thread Code that writes code that writes code: Perl to Lisp to Postscript
by hsmyers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |