home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gsnup.ps < prev    next >
Text File  |  2000-03-09  |  3KB  |  91 lines

  1. %!
  2. %    Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  3. % This file is part of Aladdin Ghostscript.
  4. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  5. % or distributor accepts any responsibility for the consequences of using it,
  6. % or for whether it serves any particular purpose or works at all, unless he
  7. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  8. % License (the "License") for full details.
  9. % Every copy of Aladdin Ghostscript must include a copy of the License,
  10. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  11. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  12. % under certain conditions described in the License.  Among other things, the
  13. % License requires that the copyright notice and this notice be preserved on
  14. % all copies.
  15.  
  16. % $Id: gsnup.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  17. % Prefix this to very well-behaved PostScript files for n-up printing.
  18.  
  19. /cdef { 1 index where { pop pop } { def } ifelse } def
  20.  
  21. %%%%%%%%%%%%%%%% Begin parameters %%%%%%%%%%%%%%%%
  22.  
  23. % All parameters are also settable from the command line with -d, e.g.,
  24. % -d.Nx=3
  25.  
  26. /.Nx 2 cdef            % # of pages across the physical page
  27. /.Ny 2 cdef            % # of pages down the physical page
  28. /.Landscape false cdef        % if true, rotate page by 90 degrees
  29.  
  30. %%%%%%%%%%%%%%%% End parameters %%%%%%%%%%%%%%%%
  31.  
  32. vmstatus pop pop 0 eq { save pop } if
  33. .Landscape {
  34.   currentpagedevice /PageSize get aload pop
  35.   exch 2 array astore
  36.   1 dict dup /PageSize 4 -1 roll put
  37.   setpagedevice
  38. } if
  39. /.BP currentpagedevice /BeginPage get def
  40. /.EP currentpagedevice /EndPage get def
  41. /.Ps 1 string def    % survive save/restore
  42. /.Pn { .Ps 0 get } def
  43. true setglobal        % protect from restore
  44. /.ELevel [0] def
  45. /.Rmat matrix def
  46. false setglobal
  47. /.max { 2 copy lt { exch } if pop } cdef
  48. % Work around the common save ... showpage ... restore locution.
  49. /restore {
  50.   .Rmat currentmatrix pop restore
  51.   vmstatus pop pop .ELevel 0 get lt { .Rmat setmatrix } if
  52. } bind def
  53. <<
  54.   /BeginPage {
  55.     .BP .Nx .Ny .max
  56.     gsave
  57.       initclip clippath pathbbox exch 4 -1 roll sub 3 1 roll exch sub
  58.     grestore
  59.     2 copy exch .Nx div exch .Ny div
  60.     .Pn dup .Nx mod exch .Nx idiv .Ny 1 sub exch sub
  61.         % Stack: nmax pw ph pw/nx ph/ny ix iy
  62.     exch 3 index mul exch 2 index mul
  63.     translate
  64.         % Stack: nmax pw ph pw/nx ph/ny
  65.     4 -1 roll 4 index div 4 -1 roll 4 index div
  66.         % Stack: nmax pw/nx ph/ny pw/nmax ph/nmax
  67.     exch 4 -1 roll exch sub 2 div
  68.     3 1 roll sub 2 div
  69.     translate
  70.         % Stack: nmax
  71.     1 exch div dup scale
  72.   }
  73.   /EndPage {
  74.     .ELevel 0 vmstatus pop pop put
  75.     .Ps 0 .Pn 1 add .Nx .Ny mul mod put    
  76.     .Pn 0 eq {
  77.       .EP
  78.     } {
  79.       pop pop false
  80.     } ifelse
  81.   }
  82. >> setpagedevice
  83. /.EOJ {
  84.   { .Pn 0 eq { exit } if showpage } loop
  85. } def
  86.  
  87. { currentfile cvx exec .EOJ } exec
  88.