Article View: comp.lang.postscript
Article #4143FAQ? Text centered in a box!
From: Willi Staudt AG-Linder
Date: Tue, 13 Oct 1992 18:15
Date: Tue, 13 Oct 1992 18:15
68 lines
3217 bytes
3217 bytes
% Hello all!
% I hope I don't bother you with an frequently asked question, but I'm a
beginner
% in postscript and I can't find the (maybe simple?) solution to the problem in
% the handbooks I have access to.
% All I want is a text printed in the center of a box!
% I included a fragment of my program, just to illustrate the problem:
% 'Box' and 'CenterShow' work fine and the text is left/right centered.
% Obviously the problem is the font height!
% When I calculated the y-coordinate I started with 'y-start + half-box-height'
% and the text showed above the middle. So I substracted 'half-font-height',
% but now the small letters 'g' and 'j' are partially outside the box!
% My question now is threefold:
% a. Why is the starting point of a letter not the lower left corner of the
% matrix?
% b. How can I calculate the right 'offset' when I know the font height?
% c. It appears to me as if the font height 50 is not equal to my definition
% of the box height 50 ?? Why is that so?
% Thanks a lot for any help!
% Willi
%!
/Box { %---------------------------------------
4 2 roll % draw a box
newpath % stack: x-start y-start width height
moveto %---------------------------------------
dup 0 exch rlineto
exch 0 rlineto
neg 0 exch rlineto
closepath
} def
/CenterShow { %---------------------------------------
dup % print a string centered
stringwidth pop 2 div neg %---------------------------------------
0 rmoveto
show
} def
/x 100 def % lower left corner of box
/y 100 def
/w 200 def % width of box
/h 50 def % height of box
/f 50 def % font height
/Helvetica findfont f scalefont setfont
x y w h Box stroke % print the box
x w 2 div add % x-start + half-box-width
y h 2 div add f 2 div sub % y-start + half-box-height - half-font-height
moveto
(Agthijkl) CenterShow % show arbitrary text
showpage
% <>==============================<>=============================<>========<>
% || Wilhelm F.Staudt || E-Mail: || \ ||
% || Department of Physics || || \ ||
% || University of Kaiserslautern || staudt@physik.uni-kl.de || /\ ||
% || FRG - 6750 Kaiserslautern || staudt@rhrk.uni-kl.de || / \ ||
% <>==============================<>=============================<>========<>
Technical Details
Message-ID:
<1992Oct13.181507.4697@rhrk.uni-kl.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ira.uka.de!rz.uni-karlsruhe.de!stepsun.uni-kl.de!sun.rhrk.uni-kl.de!physik.uni-kl.de!staudtShow Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ira.uka.de!rz.uni-karlsruhe.de!stepsun.uni-kl.de!sun.rhrk.uni-kl.de!physik.uni-kl.de!staudt From: staudt@physik.uni-kl.de (Willi Staudt AG-Linder) Subject: FAQ? Text centered in a box! Message-ID: <1992Oct13.181507.4697@rhrk.uni-kl.de> Sender: news@rhrk.uni-kl.de Reply-To: staudt@physik.uni-kl.de (Willi Staudt AG-Linder) Organization: University of Kaiserslautern (Germany) Date: Tue, 13 Oct 1992 18:15:07 GMT Lines: 69