gsnup.ps 2.8 KB

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