text.ps - Some useful text-handling stuff in PostScript
(/home/wherever/ps/lib/text.ps) run % if run fails with invalidaccess you may need to use gv --nosafer % to send it to a printer see include_run . . . 100 500 moveto /Times-Roman 20 selectfont { pop pop -2 0 rmoveto } (a string) true kcharpath fill /long_string (In every period there have been better or worse types employed in \ better or worse ways. The better types employed in better ways have \ been used by the educated printer acquainted with standards and history.) def /Times-Roman 18 selectfont /y 500 def long_string 180 {20 y moveto show /y y 20 sub def} BreakIntoLines /Times-Roman 18 selectfont 20 500 long_string 180 LeftJustifyText /Times-Roman 18 selectfont 20 500 long_string 180 JustifyText /Helvetica-Bold /Helvetica-Bold-Outline 1000 54 div /Helvetica-Bold findfont dup /UniqueID known { /UniqueID get 1 add } { pop 1 } ifelse MakeOutlineFont /Helvetica-Bold-Outline 54 selectfont 150 170 moveto (Hello outline) show 400 400 translate /Times-Bold 22 selectfont (Symphony No. 9 \(The Choral Symphony\)) 22 90 140 OutsideCircleText /Times-Roman 15 selectfont (Ludwig van Beethoven) 15 90 118 OutsideCircleText (Vienna Philharmonic Orchestra) 15 270 118 InsideCircleText
This module implements in PostScript a few simple procedures for handling text, mostly originating in the Postscript Language Tutorial and Cookbook, and in the PostScript header as generated by muscript -p, and in luser- -droog's postings in comp.lang.postscript
kcharpath
InsideCircleText
OutsideCircleText
MakeOutlineFont
BreakIntoLines
LeftJustifyText
JustifyText
rightshow
leftshow
centreshow
centrexshow
pathbboxwh
warn
This is the kerning equivalent to charpath,
just as kshow is the kerning equivalent to show.
Note: as in kshow,
the proc gets passed the previous char and current char,
so it usually needs to start with
pop pop
See luser- -droog in comp.lang.postscript on 20160516
See the Postscript Language Tutorial and Cookbook p.167
See the Postscript Language Tutorial and Cookbook p.167
The strokewidth must be specified in the
character-coordinate-system (1000 units).
See the PostScript Language Tutorial and Cookbook p.203
and the PostScript Language Reference Manual p.271
The procedure proc will be executed at each end-of-line.
See the Postscript Language Tutorial and Cookbook p.179
LeftJustifyText invokes BreakIntoLines
with a procedure that invokes show on each line,
x and y give the position where the text will start,
i.e. at its top left corner.
LeftJustifyText leaves the currentpoint at the end of the
last character printed, as does ashow.
JustifyText invokes BreakIntoLines
with a procedure that looks at the linestring,
measures its stringwidth, subtracts that from the linewidth,
divides the result by its length in characters,
and then invokes ashow with that ax.
x and y give the position where the text will start,
i.e. at its top left corner.
JustifyText leaves the currentpoint at the end of the
last character printed, as does ashow.
See the Postscript Language Tutorial and Cookbook p.179,
except that the textstring and linewidth arguments
have been swapped, for consistency with BreakIntoLines
This shows the textstring right-justifed up to the given
x y position.
See: muscript -p
This shows the textstring left-justifed at the given
x y position.
See: muscript -p
This shows the textstring centered, horizontally and vertically,
at the given x y position.
See: muscript -p
This shows the textstring centered horizontally around the given x position, with the base-line of the text at the y position.
This is the same as the standard pathbbox procedure,
except that it leaves the box on the stack in the form:
llx lly width height
ready for use by rectclip, rectfill or
rectgradientfill.
The standard pathbbox leaves it
in the form: llx lly urx ury
(a string) charpath clip
clippath pathbboxwh red orange false 0.5 rectgradientfill
This is useful for debugging, eg: at the ghostscript prompt. It takes one array argument, then converts each element to a readable string and prints it. (see: print)
Any array element will be printed in the way that == prints it, including the newline at the end. Otherwise, no newlines are imposed, so if you want one you should use a (\n) string, for example as the last item in the array.
To install: go to
www.pjb.com.au/comp/free/text.ps.txt
and save the file to your local disc.
Rename it to text.ps and move it into some appropriate
directory such as ~/ps/lib
. . .
Or, first change directory to where you keep your PostScript libraries:
cd /home/wherever/ps/lib/
(or wherever) and then either:
wget -O text.ps http://www.pjb.com.au/comp/free/text.ps.txt
or:
curl http://www.pjb.com.au/comp/free/text.ps.txt -o text.ps
Peter J Billam www.pjb.com.au/comp/contact.html
20200129 currentfontBBheight multiplies fontBB height by fontmatrix height 20111101 JustifyText doesn't kern the last word in the paragraph 20111029 LeftJustifyText doesn't justify the right margin 20160607 centrexshow handles the Y dimension in sloped fonts 20160521 add pathbboxwh and warn 20160515 add kcharpath 20160501 first released version
fonts.ps
colours.ps
line_drawing.ps
brownian.ps
include_run
http://www.pjb.com.au/
the PostScript Language Reference Manual (Adobe).
Back to P J B Computing or to www.pjb.com.au . . .