[comp.lang.postscript] PS Center Text???

gross@umiami.miami.edu (JD144) (07/16/90)

Well, does anyone out there have a PS centering procedure?  Something
that can take a text string and center it on the page?

If you do, please e-mail to me....thanks so much.

Have a day.

-- 
Jason Gross     Comp Sci Ugrad     University of Miami     Class of '91 (?)
===========================================================================
Hey, wanna save the world? | Got sumtin' to say?        gross@umiami.bitnet
Nuke a Godless, Communist, | Pick and choose!        gross@umiami.miami.edu  
gay whale for Christ.      |                      gross@miavax.ir.miami.edu
              - Anonymous  |                     jgross@umbio.med.miami.edu
===========================================================================
               The University of Miami has a lovely fountain. 

hascall@cs.iastate.edu (John Hascall) (07/18/90)

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

mitch@hq.af.mil (Mitch Wright) (07/19/90)

/*
 * 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?

% Center String between 2 points 
% Call as: (string) Left_Point Right_Point Y_position center
%
/center {
	/ypos exch def
	add 2 div exch
	dup stringwidth pop
	/sw exch def
	exch sw 2 div
	neg add ypos moveto
} def

--
   ..mitch

   mitch@hq.af.mil (Mitch Wright) | The Pentagon, 1B1046 | (202) 695-0262

   The two most common things in the universe are hydrogen and stupidity,
   but not necessarily in that order.