Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!dino!hascall From: hascall@cs.iastate.edu (John Hascall) Newsgroups: comp.lang.postscript Subject: Re: PS Center Text??? Message-ID: <2280@dino.cs.iastate.edu> Date: 18 Jul 90 03:11:02 GMT References: <6558.26a0b0a2@umiami.miami.edu> Sender: usenet@dino.cs.iastate.edu Organization: ISU Lines: 43 gross@umiami.miami.edu (JD144) writes: }Well, does anyone out there have a PS centering procedure? Something }that can take a text string and center it on the page? As penance for asking a lame question on left-side-bearings I'll take a shot at this one... (I wrote this yesterday, but don't have it in front of me, so excuse any minor oopses :-) ---------------cut here------------ %!PS % % Many ways to do this: you might want to leave the left and right % margins in "global variables" if you were going to do a lot of % these with the same margins, and you might want to keep the y % position global (and advance it with each CenterShow [use the % value popped after stringwidth]). /CenterShow { % % xleft xright y str CenterShow % % implict inputs include: current font, current color, etc... % 6 dict begin /str exch def /y exch def /xright exch def /xleft exch def xright xleft sub /xspace exch def % between margins str stringwidth pop /xwidth exch def % string width xspace xwidth sub 2 div y moveto % into position str show % show it end } bind def % === a simple sample === /inch {72 mul} bind def /Times-Roman findfont 14 scalefont setfont 1.25 inch 7.25 inch 9.5 inch (John Hascall was here) CenterShow showpage %-----------------cut here------------ John Hascall