Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!batcomputer!tedcrane From: tedcrane@batcomputer.tn.cornell.edu (Ted Crane) Newsgroups: comp.lang.postscript Subject: Re: Block Center? Message-ID: <6173@batcomputer.tn.cornell.edu> Date: 31 Aug 88 20:28:08 GMT References: <235@galen.acc.virginia.edu> Reply-To: tedcrane@tcgould.tn.cornell.edu (Ted Crane) Organization: Tompkins County Computing, Ithaca, NY Lines: 19 In article <235@galen.acc.virginia.edu> paw3c@galen.acc.virginia.edu (Pat Wilson) writes: >the point where I have to figure out how to center an arbitrarily >sized block of text (an address, for example) within a bounded >space on the form. I've been playing with various ways to do >this, but none of them seem very elegant. Has anyone come up >with an algorithm (or even a heuristic) to do this? Well, assuming you haven't missed the trivial case which can be solved by: width = max ( "stringwidth pop" for each line) height = sum ( "stringwidth exch pop" for each line ) + leading Try this: Assuming you don't know how many lines of text in the block... Place each line into an array (alternately, mark the stack, then place on stack). Now you know how many lines and can perform the (width,height) arithmetic above. Centering the block is now an exercise for the reader. Is this elegant or just one of the various ways?