paw3c@galen.acc.virginia.edu (Pat Wilson) (08/26/88)
I'm writing PostScript to generate NIH grant forms and fill them in. I've gotten all the forms created, but now I've arrived at 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? Thanks. -- Pat Wilson paw3c@acc.virginia.edu || uunet!virginia!paw3c || paw3c@virginia.BITNET
tedcrane@batcomputer.tn.cornell.edu (Ted Crane) (09/01/88)
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?