qdot
qdot

Reputation: 6335

Change letter spacing in PostScript

In writing a postscript file, one can select a font like this:

/Courier-Bold findfont 16 scalefont setfont
(bar baz) show

I would like to change the letter spacing of my font - is there a way to do that? Either directly as a font operator, or perhaps just by being able to insert arbitrary postscript commands between glyph rendering?

Upvotes: 2

Views: 2019

Answers (1)

luser droog
luser droog

Reputation: 19504

Yes, there are several variants of the show operator that can be used for things like this:

  • ax ay string   ashow   -
    add (ax, ay) to width of each char while showing string

  • cx cy char string   widthshow   -
    add (cx, cy) to width of char while showing string

  • cx cy char ax ay string   awidthshow   -
    combine effects of ashow and widthshow

  • proc string   kshow   -
    execute proc between characters shown from string

A few tips. Since postscript doesn't have character literals, a common idiom is to extract the integer value from a 1-byte string literal to supply the char argument for widthshow and awidthshow. Eg.

( ) 0 get %the space char, aka 32 or 16#20

And unless you're going for some kind of stair-case effect, all the y values should be 0.

The proc executed by kshow between each character receives as arguments the char-just-shown and the char-about-to-be-shown, in that order. This is presumably to allow you to look up the pair in some kind of "kerning table". But I've never actually seen this done. But remember to pop them if they're not needed (usually).


As for making a derived font, I refer you to this answer of mine on codegolf.SE which creates a Crossword Font by drawing boxes around Times-Roman. The width of the character is declared with the setcachedevice operator in the /BuildChar procedure. For mine, I just needed a constant width so I used 1 to tie it directly to the font size.

Upvotes: 5

Related Questions