xiaofei@EINSTEIN.PHYSICS.BUFFALO.EDU (X. F. Wang) (06/02/91)
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 ?
swx@cs.nott.ac.uk (Stephen Woolston) (06/03/91)
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.
jos@bull.nl (Jos Vos) (06/03/91)
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 ? /centershow { dup stringwidth pop 2 div neg 0 rmoveto show } def Now use: x y moveto (string) centershow -- -- Jos Vos <jos@bull.nl> (UUCP: ...!{uunet,mcsun,hp4nl}!nlbull!jos) -- Bull Nederland NV, Product Support Unix, Amsterdam, The Netherlands
davis@3d.enet.dec.com (Peter Davis) (06/03/91)
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 ? Something like this should work: x y moveto (symbol) dup true charpath flattenpath pathbbox /y2 exch def /x2 exch def /y1 exch def /x1 exch def newpath x2 x1 sub 2 div neg y2 y1 sub 2 div neg rmoveto show
xiaofei@acsu.buffalo.edu (X. F. Wang) (06/04/91)
/* jos@bull.nl (Jos Vos) 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 ?
*
* /centershow { dup stringwidth pop 2 div neg 0 rmoveto show } def
*
* Now use:
*
* x y moveto
* (string) centershow
This does not get (string) vertically centered.
--
(___) | Xiaofei Wang | (___)
(o o) | Physics Department / 239 Fronczak Hall | (o o)
/-------\ / | State University of New York at {Buffalo} | \ /-------\
/ | ||O | {Buffalo}, New York 14260 | O|| | \
xiaofei@acsu.buffalo.edu (X. F. Wang) (06/04/91)
/* 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|| | \
woody@chinacat.unicom.com (Woody Baker @ Eagle Signal) (06/04/91)
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 try something like this x (symbol) stringwidth pop 2 div sub y moveto (symbol) show This should compute the width of the symbol, divide it by 2, subtract that result from the x direction, put the y coordinate on the stack on top of the x coordinate, ready for the moveto.... Cheers Woody
lee@leo (Bill Lee) (06/07/91)
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