Article View: comp.lang.postscript
Article #8607Re: PostScript utility for font changes, subscripts within string
From: Ned Batchelder
Date: Wed, 20 Dec 1989 16:09
Date: Wed, 20 Dec 1989 16:09
51 lines
2009 bytes
2009 bytes
Rather than limit yourself to the idea that your data representation must be
a string, which is inert and must be decoded, pick a more convenient
representation for your text-with-font-changes. I've done something like
this and it was very easy.
Text is represented as a procedure which when executed shows the text. For
example:
/tr /Times-Roman findfont def % Base font
/rm tr 10 scalefont def % font for Roman
/sc tr [ 8 0 0 8.5 0 0 ] makefont def % font for small caps
{ rm setfont (P) show
sc setfont (OST) show
rm setfont (S) show
sc setfont (CRIPT) show }
The procedure at the end is the representation of the caps/small-caps form
of the word "PostScript". Now to show this text, you define "textshow":
/textshow /exec load def
To compute the width of the text, you have to be a little trickier. Nulldevice
comes in very handy here:
/textwidth {
gsave nulldevice
0 0 moveto
textshow
currentpoint
grestore
} def
Then you can center text:
/textcentershow {
dup textwidth pop
-2 div 0 rmoveto
textshow
} def
Etc.
It isn't a very compact representation, but it sounds like your application
won't be doing much text anyway, and it can be made compacter by the proper
definition of procedure to use within the text itself.
[I typed this in off the top of my head, so there may be errors, but the ideas
are sound: I've used it and it works.]
Ned Batchelder, Digital Equipment Corp., BatchelderN@Hannah.enet.DEC.com
Technical Details
Message-ID:
<7026@shlump.nac.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!sun-barr!decwrl!shlump.nac.dec.com!minim.dec.com!batcheldernReferences:
<12294@phoenix.Princeton.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!sun-barr!decwrl!shlump.nac.dec.com!minim.dec.com!batcheldern From: batcheldern@hannah.enet.dec.com (Ned Batchelder) Newsgroups: comp.lang.postscript Subject: Re: PostScript utility for font changes, subscripts within string Message-ID: <7026@shlump.nac.dec.com> Date: 20 Dec 89 16:09:04 GMT References: <12294@phoenix.Princeton.EDU> Sender: newsdaemon@shlump.nac.dec.com Distribution: na Lines: 51