%PDF-
%!PS-Adobe-3.0

% International paper sizes, version of 5 July 2007
% Author Dave Barber

% This program, in the Adobe PostScript language, draws a 
% diagram of European paper sizes. Submit it to Acrobat 
% Distiller or Macintosh Preview to make it run. 

% For best results, ensure that the name of this file 
% ends in .ps (not .html or .txt, for instance). 

% You indicate the size of sheet to print on by setting 
% GeneralSize, below. The program draws the outlines of 
% various sheet sizes, with suitable legends. 

% The .pdf file produced by the Distiller knows on what size 
% of paper it is supposed to be printed. If you print it at that 
% size, the diagram will be at 100% scale. 
% Most print drivers will let you 
% print it at some other scale if you want.

% We recommend that you modify this file with a text editor 
% (for instance Macintosh TextEdit or Microsoft Notepad), 
% not a word processor (for instance AppleWorks or 
% Microsoft Word).

% Define GeneralSize as one of the following integers, to 
% represent the size of sheet on which to print the chart. The 
% largest size this program attempts to support is 16A0 because 
% of Acrobat's 200-inch size limit.

%    -16: 16A0   -15: 16D0   -14: 8B0    -13: 8C0    
%    -12: 8A0    -11: 8D0    -10: 4B0     -9: 4C0    
%     -8: 4A0     -7: 4D0     -6: 2B0     -5: 2C0   
%     -4: 2A0     -3: 2D0     -2: B0      -1: C0  
%      0: A0       1: D0       2: B1       3: C1  
%      4: A1       5: D1       6: B2       7: C2  
%      8: A2       9: D2      10: B3      11: C3  
%     12: A3      13: D3      14: B4      15: C4  
%     16: A4      17: D4      18: B5      19: C5  
%     20: A5      21: D5      22: B6      23: C6  
%     24: A6      25: D6      26: B7      27: C7  
%     28: A7      29: D7      30: B8      31: C8  

/GeneralSize 16 def   % not sure? then use 16 for A4

% HowMany different sizes to show; it's any "reasonable" positive 
% integer, but if it's too big, you'll run off the end of an array
% and get an error message.

/HowMany 48 def  

% don't have a color printer? change false to true

/Monochrome false def

% printer won't do shading? change false to true

/LineArt false def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Don't modify anything below this line unless you know
% something about PostScript.

/Root 2.0 0.125 neg exp def
/Power { Root exch exp 1000 mul } bind def

% Unlike many graphics utilities, PostScript lets you 
% parameterize the page size: 

/PageWideMM GeneralSize 2 add Power def
/PageHighMM GeneralSize 2 sub Power def
/PageWidePt PageWideMM 25.4 div 72 mul def
/PageHighPt PageHighMM 25.4 div 72 mul def

%%BeginFeature: 
<< /PageSize [PageWidePt PageHighPt] >> setpagedevice
%%EndFeature

/LftMargin PageWideMM 0.5 2.0 -1.25 exp sub mul def
/BotMargin PageHighMM 0.5 2.0 -1.25 exp sub mul def

% The following character strings could be calculated by
% ingenious algorithm, but we just enumerate them instead.

/SmallDesig   [ (A0)  (D0)
    (B1)  (C1)  (A1)  (D1)
    (B2)  (C2)  (A2)  (D2)
    (B3)  (C3)  (A3)  (D3)
    (B4)  (C4)  (A4)  (D4)  
    (B5)  (C5)  (A5)  (D5)
    (B6)  (C6)  (A6)  (D6)  
    (B7)  (C7)  (A7)  (D7)
    (B8)  (C8)  (A8)  (D8)  
    (B9)  (C9)  (A9)  (D9)
    (B10) (C10) (A10) (D10) 
    (B11) (C11) (A11) (D11)
    (B12) (C12) (A12) (D12) 
    (B13) (C13) (A13) (D13)
    (B14) (C14) (A14) (D14) 
    (B15) (C15) (A15) (D15)
    (B16) (C16) (A16) (D16) 
    (B17) (C17) (A17) (D17)
    (B18) (C18) (A18) (D18) 
    (B19) (C19) (A19) (D19) ] def

/LargeDesig [ (A0)   (C0)   (B0)  
      (2D0)  (2A0)  (2C0)  (2B0) 
      (4D0)  (4A0)  (4C0)  (4B0)  
      (8D0)  (8A0)  (8C0)  (8B0) 
     (16D0) (16A0) ] def

/GetDesig { 
    /Param exch def
    Param 0 gt { SmallDesig Param get } 
               { LargeDesig Param neg get } ifelse
} bind def

% we have lighter and darker versions of several colors.
% these are the components of the darker versions, followed by
% the formula for calculating the lighter ones:

Monochrome true eq {
   /ColorARed 0 def  /ColorAGrn 0 def  /ColorABlu 0 def
   /ColorBRed 0 def  /ColorBGrn 0 def  /ColorBBlu 0 def
   /ColorCRed 0 def  /ColorCGrn 0 def  /ColorCBlu 0 def
   /ColorDRed 0 def  /ColorDGrn 0 def  /ColorDBlu 0 def
   /Lighten { 1 exch sub 0 mul 1 exch sub } bind def
} {
   /ColorARed 0.40 def  /ColorAGrn 0.25 def  /ColorABlu 0.00 def
   /ColorBRed 0.80 def  /ColorBGrn 0.00 def  /ColorBBlu 0.00 def
   /ColorCRed 0.20 def  /ColorCGrn 0.20 def  /ColorCBlu 1.00 def
   /ColorDRed 0.00 def  /ColorDGrn 0.60 def  /ColorDBlu 0.00 def
   LineArt true eq {
      /Lighten { 1 exch sub 0 mul 1 exch sub } bind def
   } {
      /Lighten { 1 exch sub 0.15 mul 1 exch sub } bind def
   } ifelse
} ifelse


/ColorADark { ColorARed ColorAGrn ColorABlu setrgbcolor} bind def % dark brown
/ColorBDark { ColorBRed ColorBGrn ColorBBlu setrgbcolor} bind def % dark red
/ColorCDark { ColorCRed ColorCGrn ColorCBlu setrgbcolor} bind def % dark blue
/ColorDDark { ColorDRed ColorDGrn ColorDBlu setrgbcolor} bind def % dark green
/DarkTable [ /ColorBDark load /ColorCDark load /ColorADark load /ColorDDark load ] def

/ColorALite { ColorARed Lighten ColorAGrn Lighten ColorABlu Lighten setrgbcolor } bind def
/ColorBLite { ColorBRed Lighten ColorBGrn Lighten ColorBBlu Lighten setrgbcolor } bind def
/ColorCLite { ColorCRed Lighten ColorCGrn Lighten ColorCBlu Lighten setrgbcolor } bind def
/ColorDLite { ColorDRed Lighten ColorDGrn Lighten ColorDBlu Lighten setrgbcolor } bind def
/LiteTable [ /ColorBLite load /ColorCLite load /ColorALite load /ColorDLite load ] def

% We never found a PostScript operator for formatting numbers,
% so we do it by brute force.

/Format4p0 {
   /Buffer (xxxx.) def
   /IParam Param 0.5 add cvi def
   /HeadStr (hhhh) def
   IParam HeadStr cvs pop
   Buffer 0 HeadStr putinterval
   Buffer
} bind def

/Format3p1 {
   /Buffer (xxx.y) def
   /IParam Param 0.05 add 10 mul cvi def
   /HeadStr (hhh) def
   IParam 10 idiv HeadStr cvs pop
   Buffer 0 HeadStr putinterval
   /TailStr (t) def
   IParam 10 mod TailStr cvs pop
   Buffer 4 TailStr putinterval
   Buffer
} bind def

/Format2p2 {  
   /Buffer (xx.yy) def
   /IParam Param 0.005 add 100 mul cvi def
   /HeadStr (hh) def
   IParam 100 idiv HeadStr cvs pop
   Buffer 0 HeadStr putinterval
   /TailInt IParam 100 mod def
   TailInt 10 ge {
      /TailStr (tt) def
      TailInt TailStr cvs pop
      Buffer 3 TailStr putinterval
   } {
      /TailStr (t) def
      TailInt TailStr cvs pop
      Buffer 3 48 put
      Buffer 4 TailStr putinterval
   } ifelse
   Buffer
} bind def

/Format1p3 {
   /Buffer (x.yyy) def
   /IParam Param 0.0005 add 1000 mul cvi def
   /HeadStr (h) def
   IParam 1000 idiv HeadStr cvs pop
   Buffer 0 HeadStr putinterval
   /TailInt IParam 1000 mod def
   TailInt 100 ge {
      /TailStr (ttt) def
      TailInt TailStr cvs pop
      Buffer 2 TailStr putinterval
   } { TailInt 10 ge {
          /TailStr (tt) def
          TailInt TailStr cvs pop
          Buffer 2 48 put
          Buffer 3 TailStr putinterval
       } {
          /TailStr (t) def
          TailInt TailStr cvs pop
          Buffer 2 48 put
          Buffer 3 48 put
          Buffer 4 TailStr putinterval
       } ifelse
   } ifelse
   Buffer
} bind def

/FormatNo {
   /Param exch def
   Param 1000.0 ge {
      Format4p0 
   } {
   Param 100.0 ge {
      Format3p1
   } { 
   Param 10.0 ge {    
      Format2p2
   } {
      Format1p3
   } ifelse
   } ifelse
   } ifelse     
} bind def

/InfoScale 0.6 def

% call the following procedure one time for each sheet to be depicted:

/DrawSheet {
   gsave

   % general

      % give the parameter a name
      /Factor exch def

      % what colors will we use?
      /Switch Factor 26 add 4 mod def

      % how big is this sheet?  
      /FullWide Factor 2 add Power def
      /FullHigh Factor 2 sub Power def

      % how big is the next smaller sheet? 
      /MiniWide Factor 3 add Power def
      /MiniHigh Factor 1 sub Power def

      % how wide will the dark stripe around each sheet be?
      /Edging FullWide 0.005 mul def

   % draw two boxes, a lite one on top of a dark one.
   % because the lite one is smaller, we get a dark border.

      DarkTable Switch get exec
      LftMargin BotMargin FullWide FullHigh rectfill

      LiteTable Switch get exec 
      LftMargin Edging add
      BotMargin Edging add
      FullWide Edging 2 mul sub
      FullHigh Edging 2 mul sub rectfill

   % prepare text. the text location is based upon the 
   % next-smaller size sheet.

      DarkTable Switch get exec
      /DiffWide FullWide MiniWide sub def
      /DiffHigh FullHigh MiniHigh sub def
      /TextSize DiffWide 0.55 mul def
      /TextMargin DiffWide 0.18 mul def

   % display width in mm

      /Helvetica findfont
      TextSize scalefont setfont
      LftMargin FullWide add BotMargin FullHigh add translate

      /BufferC FullWide FormatNo def
      % BufferC stringwidth /WY exch def /WX exch def
      180 rotate
      DiffWide TextMargin moveto
      BufferC show

   % display height in mm
	
      /BufferD FullHigh FormatNo def 
      BufferD stringwidth /HY exch def /HX exch def
      270 rotate
      DiffHigh neg HX sub TextMargin moveto
      BufferD show

   % display designation
  
      /Helvetica-Bold findfont
      TextSize scalefont setfont
      /Legend Factor GetDesig def 
      Legend stringwidth /BY exch def /BX exch def
      BX neg TextMargin sub TextMargin moveto
      Legend show 

   % legends

      Factor GeneralSize 2 add eq {
	FullHigh neg TextMargin add TextMargin moveto
	InfoScale dup scale
	0.0 0.0 0.0 setrgbcolor
        /Helvetica-Bold findfont
        TextSize scalefont setfont
        (some international paper sizes) show
      } if

      Factor GeneralSize 3 add eq {
        FullHigh neg TextMargin add TextMargin moveto
        InfoScale dup scale
        0.1 0.1 0.1 setrgbcolor
        /Helvetica findfont
        TextSize scalefont setfont
        (dimensions in millimeters -- ) show
        (measure to the outer edge of the border lines) show
      } if

      Factor GeneralSize 4 add eq {
        FullHigh neg TextMargin add TextMargin moveto
        InfoScale dup scale
        0.2 0.2 0.2 setrgbcolor
        /Helvetica findfont
        TextSize scalefont setfont
        (for 100% scale, print this chart on a sheet of size ) show
        GeneralSize GetDesig show
      } if

      Factor GeneralSize 5 add eq {
        FullHigh neg TextMargin add TextMargin moveto
        InfoScale dup scale
        0.3 0.3 0.3 setrgbcolor
        /Helvetica findfont
        TextSize scalefont setfont
        (home.comcast.net/~tamivox/dave/IntlPaper/index.html) show
      } if

      Factor GeneralSize 6 add eq {
        FullHigh neg TextMargin add TextMargin moveto
        InfoScale dup scale
        0.4 0.4 0.4 setrgbcolor
        /Helvetica findfont
        TextSize scalefont setfont
        (tamivox@comcast.net) show
      } if

   grestore

} bind def

% and now for the main routine ...

gsave
   % use a scale of millimeters, of course
      72.0 25.4 div dup scale

   GeneralSize 2 add 1 GeneralSize HowMany 1 add add { DrawSheet } for
   showpage
grestore