Article View: comp.lang.postscript
Article #3569Re: Variable characters
From: Tom Schneider
Date: Tue, 06 Nov 1990 18:18
Date: Tue, 06 Nov 1990 18:18
163 lines
5208 bytes
5208 bytes
In article <21131@well.sf.ca.us> shiva@well.sf.ca.us (Kenneth Porter) writes:
>
>When I need to get characters to fit a pre-defined space (such
>as is the case on my business card), I always calculate the
>point size, sometimes with x and y computed independently. The
>x size can be calculated by using stringwidth after setting the
>font at 1 point. The y size can be calculated by iterating
>over the string and reading the metric info for each character.
>If you need to set x and y scale independently, use makefont
>instead of scalefont and provide a scale matrix.
>
>This allows me to substitute fonts ad hoc without digging out
>my calculator to recalculate all of the sizes. Just let the PS
>interpreter do the grunt work.
>
>Ken (shiva@well.sf.ca.us)
Without an exact program, it is next to impossible to replicate what you do. I
have ALMOST solved my problem, but not quite! To prove that I am able to
control the character sizes, I decided to make the characters appear inside
boxes. Unfortunately, they don't match the boxes exactly, and I don't know
why. Following is my latest attempt. Can you tell me why the characters STILL
don't fit the boxes exactly? What is the problem with this code, and how do I
fix it? (I print this on a LaserWriter ntxII. NeWS 1.0 fails utterly.)
Tom Schneider
National Cancer Institute
Laboratory of Mathematical Biology
Frederick, Maryland 21702-1201
toms@ncifcrf.gov
- snip - snip - snip - snip - snip - snip - snip - snip - snip - snip
(version = 2.31 of charbox.ps TDS 1990 November 6 \n) dup print
% Show the 4 characters ACGT surrounded by boxes that exactly match
% the characters. Unfortunately, this version of the program ALMOST
% works. The C and G characters are displaced downward by about 1mm
% relative to A and T. The reason for this is unknown, can you figure
% it out?
% Tom Schneider
% National Cancer Institute
% Laboratory of Mathematical Biology
% Frederick, Maryland 21702-1201
% toms@ncifcrf.gov
/cmfactor {72 2.54 div} def % defines points -> centimeters conversion
/cm {cmfactor mul} def % defines centimeters
% Show the version number on the page
initgraphics
erasepage
gsave
/Helvetica findfont 14 scalefont setfont
1 cm 25 cm moveto show
grestore
1 setlinewidth % define the width of the dashed lines
1 setflat % define the accurcy with which curved path segments
% are to be rendered on the raster output device.
% Even setting this to 0.01 makes no difference!
% Set up the font for the graphics
/fontsize 30 def
/Helvetica-Bold findfont fontsize scalefont setfont
/charparams { % char charparams => uy ux ly lx
% takes a single character and returns the coordinates that (supposedly)
% defines the outer bounds of where the ink goes
gsave
newpath
0 0 moveto
% take the character off the stack and use it here:
true charpath
flattenpath
pathbbox % compute bounding box of 1 pt. char => lx ly ux uy
% the path is here, but toss it away ...
grestore
/uy exch def
/ux exch def
/ly exch def
/lx exch def
% print the parameters to the user:
(lx) lx
(ly) ly
(ux) ux
(uy) uy
pstack
clear % clean up the stack, having printed all that
} bind def
/box { % xsize ysize box -
% draw a dashed box of xsize by ysize
/ysize exch def % the x size of the box
/xsize exch def % the y size of the box
gsave
newpath
0 0 moveto
xsize 0 lineto
xsize ysize lineto
0 ysize lineto
0 0 lineto
%
[3] 0 setdash
stroke
grestore
} bind def
/boxshow { % xsize ysize char boxshow
% show the character with a box around it
gsave
/tc exch def % define the character
/ysize exch def % the x size of the character
/xsize exch def % the y size of the character
xsize ysize box
tc charparams
ysize % desired size of character in points
uy ly sub % height of character in points
div % factor by which to scale up the character
/ymulfactor exch def
xsize % desired size of character in points
ux lx sub % height of character in points
div % factor by which to scale up the character
/xmulfactor exch def
/xmove xmulfactor lx mul neg def
/ymove ymulfactor ly mul neg def
newpath
xmove ymove moveto
xmulfactor ymulfactor scale
tc show
grestore
} def
gsave
2 cm 2 cm translate
/size 22 def
3 cm 0 translate
0 0 moveto
1 cm size cm (A) boxshow
3 cm 0 translate
0 0 moveto
1 cm size cm (C) boxshow
3 cm 0 translate
0 0 moveto
1 cm size cm (G) boxshow
3 cm 0 translate
0 0 moveto
1 cm size cm (T) boxshow
grestore
showpage
Technical Details
Message-ID:
<1936@fcs280s.ncifcrf.gov>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!ncifcrf!fcs260c2!tomsReferences:
<1902@fcs280s.ncifcrf.gov> <21131@well.sf.ca.us>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!ncifcrf!fcs260c2!toms From: toms@fcs260c2.ncifcrf.gov (Tom Schneider) Newsgroups: comp.lang.postscript Subject: Re: Variable characters Keywords: font, character size Message-ID: <1936@fcs280s.ncifcrf.gov> Date: 6 Nov 90 18:18:08 GMT References: <1902@fcs280s.ncifcrf.gov> <21131@well.sf.ca.us> Sender: news@ncifcrf.gov Organization: NCI Supercomputer Facility, Frederick, MD Lines: 163