You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

1 month ago
  1. %!
  2. % Copyright (C) 2001-2023 Artifex Software, Inc.
  3. % All Rights Reserved.
  4. %
  5. % This software is provided AS-IS with no warranty, either express or
  6. % implied.
  7. %
  8. % This software is distributed under license and may not be copied,
  9. % modified or distributed except as expressly authorized under the terms
  10. % of the license contained in the file LICENSE in this distribution.
  11. %
  12. % Refer to licensing information at http://www.artifex.com or contact
  13. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  14. % CA 94129, USA, for further information.
  15. %
  16. % Prefix this to very well-behaved PostScript files for n-up printing.
  17. /cdef { 1 index where { pop pop } { def } ifelse } def
  18. %%%%%%%%%%%%%%%% Begin parameters %%%%%%%%%%%%%%%%
  19. % All parameters are also settable from the command line with -d, e.g.,
  20. % -d.Nx=3
  21. /.Nx 2 cdef % # of pages across the physical page
  22. /.Ny 2 cdef % # of pages down the physical page
  23. /.Landscape false cdef % if true, rotate page by 90 degrees
  24. %%%%%%%%%%%%%%%% End parameters %%%%%%%%%%%%%%%%
  25. vmstatus pop pop 0 eq { save pop } if
  26. .Landscape {
  27. currentpagedevice /PageSize get aload pop
  28. exch 2 array astore
  29. 1 dict dup /PageSize 4 -1 roll put
  30. setpagedevice
  31. } if
  32. /.BP currentpagedevice /BeginPage get def
  33. /.EP currentpagedevice /EndPage get def
  34. /.Ps 1 string def % survive save/restore
  35. /.Pn { .Ps 0 get } def
  36. true setglobal % protect from restore
  37. /.ELevel [0] def
  38. /.Rmat matrix def
  39. false setglobal
  40. /.max { 2 copy lt { exch } if pop } cdef
  41. % Work around the common save ... showpage ... restore locution.
  42. /restore {
  43. .Rmat currentmatrix pop restore
  44. vmstatus pop pop .ELevel 0 get lt { .Rmat setmatrix } if
  45. } bind def
  46. <<
  47. /BeginPage {
  48. .Nx .Ny .max
  49. gsave
  50. initclip clippath pathbbox exch 4 -1 roll sub 3 1 roll exch sub
  51. grestore
  52. 2 copy exch .Nx div exch .Ny div
  53. .Pn dup .Nx mod exch .Nx idiv .Ny 1 sub exch sub
  54. % Stack: nmax pw ph pw/nx ph/ny ix iy
  55. exch 3 index mul exch 2 index mul
  56. translate
  57. % Stack: nmax pw ph pw/nx ph/ny
  58. 4 -1 roll 4 index div 4 -1 roll 4 index div
  59. % Stack: nmax pw/nx ph/ny pw/nmax ph/nmax
  60. exch 4 -1 roll exch sub 2 div
  61. 3 1 roll sub 2 div
  62. translate
  63. % Stack: nmax
  64. 1 exch div dup scale
  65. .BP
  66. }
  67. /EndPage {
  68. dup 2 lt {
  69. .ELevel 0 vmstatus pop pop put
  70. .Ps 0 .Pn 1 add .Nx .Ny mul mod put
  71. .Pn 0 eq {
  72. .EP
  73. } {
  74. pop pop false
  75. } ifelse
  76. } {
  77. pop pop false
  78. } ifelse
  79. }
  80. >> setpagedevice
  81. /.EOJ {
  82. { .Pn 0 eq { exit } if showpage } loop
  83. } def
  84. { currentfile cvx exec .EOJ } exec