Article View: comp.lang.postscript
Article #6250Re: 0 0 moveto (+) show: how to center the (+)?
From: Bill Lee
Date: Fri, 07 Jun 1991 14:12
Date: Fri, 07 Jun 1991 14:12
74 lines
3362 bytes
3362 bytes
In article <78801@eerie.acsu.Buffalo.EDU> xiaofei@acsu.buffalo.edu (X. F. Wang) writes:
>/* swx@cs.nott.ac.uk (Stephen Woolston) wrote */:
>* In article <9106020627.AA01346@einstein.physics.buffalo.edu>
>* xiaofei@EINSTEIN.PHYSICS.BUFFALO.EDU (X. F. Wang) writes:
>* >I need something
>* >
>* >x y moveto
>* >( symbol ) show
>* >
>* >in drawing agraph. The probem is the symbol is not centered at
>* >currentpoint [The lower left corner is at currentpoint]. How do I
>* >symbol centered at currentpoint ?
>*
>* Haven't tried it, but off the top of my head ...
>*
>* x y moveto
>* (symbol) dup % stack[ (symbol) (symbol) ]
>* stringwidth % stack[ (symbol) xwid ywid ]
>* 2 div neg % stack[ (symbol) xwid -ywid/2 ]
>* exch % stack[ (symbol) -ywid/2 xwid ]
>* 2 div neg % stack[ (symbol) -ywid/2 -xwid/2 ]
>* exch % stack[ (symbol) -xwid/2 -ywid/2 ]
>* rmoveto show % stack[ ]
>*
>* You might like to define {dup ... show} as a procedure.
>
>Believe it or not, ywid is always 0. So (symbol) does not get vertically
>centered. If it is (symbol), one can use charpath flattenpath pathbox
>to get (symbol) vertically centered. However if it is a (string),
>I pick up a letter, say (M), to calculate the height. But this is not a
>perfect way of doing things. (abc) and (XYZ) do not have the same size
>as (M). So the question is how to calculate (AbiTaRy) string height as
>this? Or how to center an (aBItArY) string like this *vertically* ?
>--
> (___) | Xiaofei Wang | (___)
> (o o) | Physics Department / 239 Fronczak Hall | (o o)
> /-------\ / | State University of New York at {Buffalo} | \ /-------\
> / | ||O | {Buffalo}, New York 14260 | O|| | \
Here is a procedure that does what you want. The only caveat is that the
flattenpath operator when working on a long character string may get a
limit check if the string is too "verbose".
Bill Lee lee@shell.com
Shell Oil Co.
------------------------------cut here---------------------------------------
%*___________________________ CenterChar _______________________________________
%* Procedure to reposition the currentpoint so that the input character string
%* will be centered both horizontally and vertically at the current point.
%*
%* Usage: string CenterChar string
%*
%*
/CenterChar {
dup
gsave
true charpath flattenpath
pathbbox % llx lly urx ury
grestore
exch % llx lly ury urx
3 1 roll % llx urx lly ury
add 2 div % llx urx CenterY
3 1 roll % CenterY llx urx
add 2 div % CenterY CenterX
currentpoint % CenterY CenterX cx cy
3 1 roll % CenterY cy CenterX cx
sub neg % CenterY cy MoveX
3 1 roll sub neg % MoveX MoveY
rmoveto
} def
Technical Details
Message-ID:
<1991Jun7.141203.14783@shell.shell.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!mips!dimacs.rutgers.edu!bcm!shell!leo!leeReferences:
<9106020627.AA01346@einstein.physics.buffalo.edu> <1991Jun3.084911.20213@cs.nott.ac.uk> <78801@eerie.acsu.Buffalo.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!mips!dimacs.rutgers.edu!bcm!shell!leo!lee From: lee@leo (Bill Lee) Newsgroups: comp.lang.postscript Subject: Re: 0 0 moveto (+) show: how to center the (+)? Message-ID: <1991Jun7.141203.14783@shell.shell.com> Date: 7 Jun 91 14:12:03 GMT References: <9106020627.AA01346@einstein.physics.buffalo.edu> <1991Jun3.084911.20213@cs.nott.ac.uk> <78801@eerie.acsu.Buffalo.EDU> Sender: usenet@shell.shell.com (USENET News System) Organization: Shell Oil Lines: 74