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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.