1
0

gsnup.ps 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. %!
  2. % Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % For more information about licensing, please refer to
  12. % http://www.ghostscript.com/licensing/. For information on
  13. % commercial licensing, go to http://www.artifex.com/licensing/ or
  14. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  15. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  16. % $Id: gsnup.ps,v 1.5 2005/06/07 19:24:33 ray Exp $
  17. % Prefix this to very well-behaved PostScript files for n-up printing.
  18. /cdef { 1 index where { pop pop } { def } ifelse } def
  19. %%%%%%%%%%%%%%%% Begin parameters %%%%%%%%%%%%%%%%
  20. % All parameters are also settable from the command line with -d, e.g.,
  21. % -d.Nx=3
  22. /.Nx 2 cdef % # of pages across the physical page
  23. /.Ny 2 cdef % # of pages down the physical page
  24. /.Landscape false cdef % if true, rotate page by 90 degrees
  25. %%%%%%%%%%%%%%%% End parameters %%%%%%%%%%%%%%%%
  26. vmstatus pop pop 0 eq { save pop } if
  27. .Landscape {
  28. currentpagedevice /PageSize get aload pop
  29. exch 2 array astore
  30. 1 dict dup /PageSize 4 -1 roll put
  31. setpagedevice
  32. } if
  33. /.BP currentpagedevice /BeginPage get def
  34. /.EP currentpagedevice /EndPage get def
  35. /.Ps 1 string def % survive save/restore
  36. /.Pn { .Ps 0 get } def
  37. true setglobal % protect from restore
  38. /.ELevel [0] def
  39. /.Rmat matrix def
  40. false setglobal
  41. /.max { 2 copy lt { exch } if pop } cdef
  42. % Work around the common save ... showpage ... restore locution.
  43. /restore {
  44. .Rmat currentmatrix pop restore
  45. vmstatus pop pop .ELevel 0 get lt { .Rmat setmatrix } if
  46. } bind def
  47. <<
  48. /BeginPage {
  49. .Nx .Ny .max
  50. gsave
  51. initclip clippath pathbbox exch 4 -1 roll sub 3 1 roll exch sub
  52. grestore
  53. 2 copy exch .Nx div exch .Ny div
  54. .Pn dup .Nx mod exch .Nx idiv .Ny 1 sub exch sub
  55. % Stack: nmax pw ph pw/nx ph/ny ix iy
  56. exch 3 index mul exch 2 index mul
  57. translate
  58. % Stack: nmax pw ph pw/nx ph/ny
  59. 4 -1 roll 4 index div 4 -1 roll 4 index div
  60. % Stack: nmax pw/nx ph/ny pw/nmax ph/nmax
  61. exch 4 -1 roll exch sub 2 div
  62. 3 1 roll sub 2 div
  63. translate
  64. % Stack: nmax
  65. 1 exch div dup scale
  66. .BP
  67. }
  68. /EndPage {
  69. dup 2 lt {
  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. pop pop false
  79. } ifelse
  80. }
  81. >> setpagedevice
  82. /.EOJ {
  83. { .Pn 0 eq { exit } if showpage } loop
  84. } def
  85. { currentfile cvx exec .EOJ } exec