Article View: comp.lang.postscript
Article #3465Re: printf("%8d")
From: Glenn Reid
Date: Thu, 25 Oct 1990 16:42
Date: Thu, 25 Oct 1990 16:42
47 lines
1997 bytes
1997 bytes
In article <4296@altos86.Altos.COM> clp@altos86.Altos.COM (Chuck L. Peterson) writes:
>I use this to print out a number:
> num 4 string cvs show
>
>What do I have to change to do the equivilent of
>printf("%8d",num) here?
Here's what I do. You can adapt this approach for variable notions
of 8 or whatever. The basic idea is to have a string that is the
right field length, fill it with padding (spaces or 0's), then use
"putinterval" to put your string (from cvs) into the buffer, either
flush-left or flush-right. The program below emulates "%8d" exactly
(I think).
%!
/scratch 8 string def
/buff 8 string def
/padding (\040\040\040\040\040\040\040\040) def
% (\040) is a space, but is easier to see and count :-)
% note: padding could be (00000000) if you wanted leading 0's.
% note: also, replace "dup length 8 exch sub" with "0" to make flush-left.
% note: the space is not the same width as a '0' in a non-proportional font.
/printf8 {
buff 0 padding putinterval % put 8 spaces into buff (each time)
scratch cvs % convert the number to a string
0%dup length 8 exch sub % compute its length, subtract from 8
exch buff 3 1 roll putinterval % put numstring into rightmost cols of buff
buff show % buff is now (00000123)
} bind def
100 100 moveto
/Courier findfont 24 scalefont setfont
123 printf8
30 0 rmoveto
3465 printf8
showpage
%%EOF
(Glenn) cvn
--
Glenn Reid RightBrain Software
glenn@heaven.woodside.ca.us PostScript/NeXT developers
..{adobe,next}!heaven!glenn 415-851-1785
Technical Details
Message-ID:
<302@heaven.woodside.ca.us>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!uflorida!gatech!mcnc!decwrl!adobe!heaven!glennReferences:
<4296@altos86.Altos.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!uflorida!gatech!mcnc!decwrl!adobe!heaven!glenn
From: glenn@heaven.woodside.ca.us (Glenn Reid)
Newsgroups: comp.lang.postscript
Subject: Re: printf("%8d")
Message-ID: <302@heaven.woodside.ca.us>
Date: 25 Oct 90 16:42:00 GMT
References: <4296@altos86.Altos.COM>
Reply-To: glenn@heaven.woodside.ca.us (Glenn Reid)
Organization: RightBrain Software, Woodside, CA
Lines: 47