gs_pdfwr.ps 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. % Copyright (C) 1996, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_pdfwr.ps,v 1.11 2001/05/04 20:59:33 alexcher Exp $
  18. % PDF writer additions to systemdict.
  19. % This file should be included iff the pdfwrite "device" is included
  20. % in the executable.
  21. % ---------------- Predefined configurations ---------------- %
  22. % These correspond to the 3 predefined settings in Acrobat Distiller 4,
  23. % plus a "default" setting.
  24. % Parameters common to all configurations.
  25. % Note that we don't set AlwaysEmbed or NeverEmbed, since the default values
  26. % depend on the CompatibilityLevel and are initialized internally.
  27. /.defaultImageDict mark
  28. /QFactor 0.9 /Blend 1
  29. /HSamples [2 1 1 2] /VSamples [2 1 1 2]
  30. .dicttomark readonly def
  31. /.distillercommon mark
  32. /ASCII85EncodePages false
  33. /AntiAliasColorImages false
  34. /AntiAliasGrayImages false
  35. /AntiAliasMonoImages false
  36. /AutoFilterColorImages true
  37. /AutoFilterGrayImages true
  38. /AutoFilterMonoImages true
  39. /AutoPositionEPSFiles true
  40. /Binding /Left
  41. % What to do about the CalxxxProfiles?
  42. /ColorACSImageDict .defaultImageDict
  43. /ColorImageDepth -1
  44. /ColorImageDict .defaultImageDict
  45. /ColorImageDownsampleThreshold 1.5
  46. /ColorImageFilter /DCTEncode
  47. /CompressPages true
  48. /ConvertImagesToIndexed true
  49. /DefaultRenderingIntent /Default
  50. /DetectBlends true
  51. /DownsampleColorImages true
  52. /DownsampleGrayImages true
  53. /DownsampleMonoImages true
  54. /EmitDSCWarnings false
  55. /EncodeColorImages true
  56. /EncodeGrayImages true
  57. /EncodeMonoImages true
  58. /EndPage -1
  59. /GrayACSImageDict .defaultImageDict
  60. /GrayImageDepth -1
  61. /GrayImageDict .defaultImageDict
  62. /GrayImageDownsampleThreshold 1.5
  63. /GrayImageFilter /DCTEncode
  64. /ImageMemory 500000
  65. /LockDistillerParams false
  66. /MaxSubsetPct 100
  67. /MonoImageDepth -1
  68. /MonoImageDict mark
  69. /K -1
  70. .dicttomark readonly
  71. /MonoImageDownsampleThreshold 1.5
  72. /MonoImageFilter /CCITTFaxEncode
  73. /OPM 1
  74. /Optimize true
  75. /ParseDSCComments true
  76. /ParseDSCCommentsForDocInfo true
  77. /PreserveCopyPage true
  78. /PreserveEPSInfo true
  79. /PreserveHalftoneInfo false
  80. /StartPage 1
  81. /SubsetFonts true
  82. /TransferFunctionInfo /Preserve
  83. /UseFlateCompression true
  84. /UsePrologue false
  85. .dicttomark readonly def
  86. /.distillersettings mark
  87. /default mark
  88. /AutoRotatePages /PageByPage
  89. /CannotEmbedFontPolicy /Warning
  90. /DownsampleColorImages false
  91. /DownsampleGrayImages false
  92. /DownsampleMonoImages false
  93. /Optimize false
  94. .dicttomark readonly
  95. /screen mark
  96. /AutoRotatePages /PageByPage
  97. /CannotEmbedFontPolicy /Warning
  98. /ColorConversionStrategy /sRGB
  99. /ColorImageDownsampleType /Average
  100. /ColorImageResolution 72
  101. /CompatibilityLevel 1.2
  102. /CreateJobTicket false
  103. /DoThumbnails false
  104. /DownsampleColorImages true
  105. /DownsampleGrayImages true
  106. /DownsampleMonoImages true
  107. /EmbedAllFonts false
  108. /GrayImageDownsampleType /Average
  109. /GrayImageResolution 72
  110. /MonoImageDownsampleType /Average
  111. /MonoImageResolution 300
  112. /ParseDSCCommentsForDocInfo false
  113. /PreserveOPIComments false
  114. /PreserveOverprintSettings false
  115. /UCRandBGInfo /Remove
  116. .dicttomark readonly
  117. /.printerACSImageDict mark
  118. /QFactor 0.55 /Blend 1
  119. /HSamples [2 1 1 2] /VSamples [2 1 1 2]
  120. .dicttomark readonly def
  121. /printer mark
  122. /AutoRotatePages /None
  123. /CannotEmbedFontPolicy /Warning
  124. /ColorACSImageDict .printerACSImageDict
  125. /ColorConversionStrategy /UseDeviceIndependentColor
  126. /ColorImageDownsampleType /Bicubic
  127. /ColorImageResolution 300
  128. /CompatibilityLevel 1.3
  129. /CreateJobTicket true
  130. /DoThumbnails false
  131. /EmbedAllFonts true
  132. /GrayACSImageDict .printerACSImageDict
  133. /GrayImageDownsampleType /Bicubic
  134. /GrayImageResolution 300
  135. /MonoImageDownsampleType /Bicubic
  136. /MonoImageResolution 1200
  137. /ParseDSCCommentsForDocInfo true
  138. /PreserveOPIComments true
  139. /PreserveOverprintSettings true
  140. /UCRandBGInfo /Preserve
  141. .dicttomark readonly
  142. /.prepressACSImageDict mark
  143. /QFactor 0.25
  144. /HSamples [1 1 1 1] /VSamples [1 1 1 1]
  145. .dicttomark readonly def
  146. /prepress mark
  147. /AutoRotatePages /None
  148. /CannotEmbedFontPolicy /Error
  149. /ColorACSImageDict .prepressACSImageDict
  150. /ColorConversionStrategy /LeaveColorUnchanged
  151. /ColorImageDownsampleType /Bicubic
  152. /ColorImageResolution 300
  153. /CompatibilityLevel 1.3
  154. /CreateJobTicket true
  155. /DoThumbnails true
  156. /EmbedAllFonts true
  157. /GrayACSImageDict .prepressACSImageDict
  158. /GrayImageDownsampleType /Bicubic
  159. /GrayImageResolution 300
  160. /MonoImageDownsampleType /Bicubic
  161. /MonoImageResolution 1200
  162. /ParseDSCCommentsForDocInfo true
  163. /PreserveOPIComments true
  164. /PreserveOverprintSettings true
  165. /UCRandBGInfo /Preserve
  166. .dicttomark readonly
  167. .dicttomark readonly def
  168. % ---------------- End of predefined configurations ---------------- %
  169. % Set optimizations for converting PostScript to PDF.
  170. % The ps2pdf* scripts invoke this.
  171. /.setpdfwrite { % - .setpdfwrite -
  172. % Set a large VM threshold to reduce garbage collection.
  173. currentuserparams /VMThreshold get 3000000 .max setvmthreshold
  174. % Install a level of 'save' to reduce font loading.
  175. save pop
  176. } bind def
  177. % ---------------- pdfmark and DSC processing ---------------- %
  178. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  179. /.pdf===dict mark
  180. /arraytype
  181. { dup xcheck { ({) (}) } { ([) (]) } ifelse
  182. % Stack: file obj left right
  183. 4 1 roll 2 index exch writestring () exch
  184. { exch 2 index exch writestring
  185. 1 index exch pdf===only ( )
  186. }
  187. forall pop exch writestring
  188. } bind
  189. /packedarraytype 1 index
  190. /dicttype
  191. { 1 index (<<\n) writestring
  192. { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  193. 1 index exch pdf===only dup (\n) writestring
  194. }
  195. forall (>>) writestring
  196. } bind
  197. .dicttomark readonly def
  198. /pdf===only { % <file> <obj> pdf===only -
  199. .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  200. } bind def
  201. /.pdfcvbuf 10 string def % enough for most arguments
  202. userdict /.pdfcvstring () put
  203. /.pdfcvs { % <obj> .pdfcvs <string>
  204. currentglobal exch false .setglobal
  205. /.pdfcvstring () store
  206. % We can't handle long values yet.
  207. { pop dup length 0 eq { pop } {
  208. /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  209. } ifelse //.pdfcvbuf
  210. } /NullEncode filter dup 3 -1 roll pdf===only
  211. closefile
  212. .setglobal .pdfcvstring
  213. } bind def
  214. % Redefine pdfmark to pass the data to the driver.
  215. % We use a pseudo-parameter named /pdfmark whose value is an array:
  216. % /key1 (value1) ... (CTM) /type
  217. /.pdfputparams { % -mark- <key1> <value1> ... .pdfputparams <result...>
  218. currentdevice null false counttomark 1 add 3 roll
  219. % Don't allow the page device to get cleared....
  220. {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  221. } bind def
  222. % Convert relevant operands to strings in an array.
  223. /.pdfcvsloop { % -mark- values ... markname start step .pdfcvsloop
  224. % [values ... ctm markname]
  225. matrix currentmatrix .pdfcvs 4 1 roll
  226. counttomark 1 add 2 roll
  227. counttomark .localvmarray astore exch pop
  228. 3 1 roll
  229. % Stack: values start step
  230. 2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  231. } bind def
  232. /.pdfcvsall { % -mark- values ... markname .pdfcvsall <<same>>
  233. 0 1 .pdfcvsloop
  234. } bind def
  235. /.pdfcvseven { % -mark- key value ... markname .pdfcvseven <<same>>
  236. 1 2 .pdfcvsloop
  237. } bind def
  238. /.pdfcvsnone { % -mark- values ... markname .pdfcvsnone <<same>>
  239. 100000 1 .pdfcvsloop
  240. } bind def
  241. /.pdfcvsfirst { % -mark- first values ... markname .pdfcvsfirst<<same>>
  242. .pdfcvsnone
  243. dup 0 2 copy get .pdfcvs put
  244. } bind def
  245. % The procedures in the following dictionary are called with the entire
  246. % pdfmark operand list (including the pdfmark name) on the stack;
  247. % they may modify this ad lib. They must call .pdfcvsxxx.
  248. /.pdfmarkparams mark
  249. % Unpack a dictionary for PUT, and don't convert stream data.
  250. /PUT {
  251. counttomark 3 eq {
  252. 1 index type /dicttype eq {
  253. pop { } forall /.PUTDICT .pdfcvsall
  254. } {
  255. pop dup type /filetype eq {
  256. % Read the file into a sequence of strings.
  257. % This isn't great, but it's simple.
  258. {
  259. dup 1000 string readstring not { exch exit } if
  260. exch
  261. } loop closefile
  262. } if
  263. /.PUTSTREAM .pdfcvsfirst
  264. } ifelse
  265. } {
  266. .pdfcvsall
  267. } ifelse
  268. } bind
  269. % Unpack the array for PUTINTERVAL.
  270. /PUTINTERVAL {
  271. pop aload pop /.PUTINTERVAL .pdfcvsall
  272. } bind
  273. .dicttomark readonly def
  274. /.pdfparamerror { % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  275. counttomark 4 add 2 roll cleartomark pop pop pop
  276. .systemvar exch signalerror
  277. } bind def
  278. /pdfmark { % -mark- <key> <value> ... <markname> pdfmark -
  279. counttomark 1 add copy
  280. //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  281. mark /pdfmark 3 -1 roll .pdfputparams
  282. dup type /booleantype ne {
  283. /pdfmark .pdfparamerror
  284. } if cleartomark
  285. } odef
  286. userdict /pdfmark .undef
  287. currentdict /.pdfmarkparams .undef
  288. % Use the DSC processing hook to pass DSC comments to the driver.
  289. % We use a pseudo-parameter named DSC whose value is an array:
  290. % /key1 (value1) ... /type
  291. /.pdfdsc_dict 2 dict def
  292. /.pdfdsc { % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  293. 0 get dup null ne { 4 copy exch pop exec } { pop } ifelse 3 -1 roll pop
  294. % Stack: <dsc string> <dsc dict>
  295. 20 .localvmdict 1 index { 3 copy put pop pop } forall
  296. 3 -1 roll .parse_dsc_comments % <dsc dict> <dict> <type>
  297. dup /NOP ne 2 index length 1 gt or { % Skip unparsed comments
  298. DEBUG { (**** DSC comment: ) print dup == 1 index === flush } if
  299. exch mark 4 1 roll {
  300. % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  301. 3 index 2 index known { % Skip the DSC_struct entry
  302. pop pop
  303. } {
  304. .pdfcvs 4 -2 roll
  305. } ifelse
  306. } forall exch pop counttomark .localvmarray astore
  307. mark /DSC 3 -1 roll .pdfputparams
  308. dup type /booleantype ne {
  309. /DSC .pdfparamerror
  310. } {
  311. cleartomark
  312. } ifelse
  313. } {
  314. pop pop pop
  315. } ifelse
  316. } bind def
  317. /.initialize_dsc_parser where {
  318. pop 2 dict dup .initialize_dsc_parser readonly
  319. currentuserparams /ProcessDSCComment get
  320. 1 array astore % in case the value is executable
  321. //.pdfdsc /exec load 4 array astore cvx readonly
  322. << /ProcessDSCComment 3 -1 roll >> setuserparams
  323. } if
  324. % ---------------- {set,current}distillerparams ---------------- %
  325. % Define setdistillerparams / currentdistillerparams.
  326. % Distiller parameters are currently treated as device parameters.
  327. /.distillerparamkeys mark
  328. % General parameters -- all distillers
  329. /ASCII85EncodePages { }
  330. /AutoRotatePages { }
  331. /Binding { }
  332. /CompressPages { }
  333. /DefaultRenderingIntent { }
  334. /DetectBlends { }
  335. /DoThumbnails { }
  336. /ImageMemory { }
  337. /LockDistillerParams { }
  338. /LZWEncodePages { }
  339. /OPM { }
  340. /PreserveHalftoneInfo { }
  341. /PreserveOPIComments { }
  342. /PreserveOverprintSettings { }
  343. /TransferFunctionInfo { }
  344. /UCRandBGInfo { }
  345. /UseFlateCompression { }
  346. % General parameters -- PDF writer
  347. % StartPage and EndPage are renamed because EndPage
  348. % clashes with a page device parameter.
  349. /CoreDistVersion { }
  350. /CompatibilityLevel { }
  351. % ****** NOTE: StartPage and EndPage are disabled because
  352. % ****** EndPage clashes with a page device parameter.
  353. % /EndPage { exch pop /PDFEndPage exch }
  354. /PDFEndPage { pop pop }
  355. % /StartPage { exch pop /PDFStartPage exch }
  356. /PDFStartPage { pop pop }
  357. /Optimize { }
  358. /ParseDSCCommentsForDocInfo { }
  359. /ParseDSCComments { }
  360. /EmitDSCWarnings { }
  361. /CreateJobTicket { }
  362. /PreserveEPSInfo { }
  363. /AutoPositionEPSFiles { }
  364. /PreserveCopyPage { }
  365. /UsePrologue { }
  366. % Color sampled image parameters
  367. /ColorACSImageDict { }
  368. /AntiAliasColorImages { }
  369. /AutoFilterColorImages { }
  370. /ColorImageDepth { }
  371. /ColorImageDict { }
  372. /DownsampleColorImages { }
  373. /ColorImageDownsampleThreshold { }
  374. /ColorImageDownsampleType { }
  375. /EncodeColorImages { }
  376. /ColorImageFilter { }
  377. /ColorImageResolution { }
  378. % Color processing parameters
  379. /CalCMYKProfile { }
  380. /CalGrayProfile { }
  381. /CalRGBProfile { }
  382. /sRGBProfile { }
  383. /ColorConversionStrategy { }
  384. /ConvertCMYKImagesToRGB { }
  385. /ConvertImagesToIndexed { }
  386. % Grayscale sampled image parameters
  387. /GrayACSImageDict { }
  388. /AntiAliasGrayImages { }
  389. /AutoFilterGrayImages { }
  390. /GrayImageDepth { }
  391. /GrayImageDict { }
  392. /DownsampleGrayImages { }
  393. /GrayImageDownsampleThreshold { }
  394. /GrayImageDownsampleType { }
  395. /EncodeGrayImages { }
  396. /GrayImageFilter { }
  397. /GrayImageResolution { }
  398. % Monochrome sampled image parameters
  399. /AntiAliasMonoImages { }
  400. /MonoImageDepth { }
  401. /MonoImageDict { }
  402. /DownsampleMonoImages { }
  403. /MonoImageDownsampleThreshold { }
  404. /MonoImageDownsampleType { }
  405. /EncodeMonoImages { }
  406. /MonoImageFilter { }
  407. /MonoImageResolution { }
  408. % Font embedding parameters
  409. /AlwaysEmbed
  410. { dup length 0 gt
  411. { dup 0 get false eq
  412. { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  413. } if
  414. } if
  415. }
  416. /NeverEmbed
  417. { dup length 0 gt
  418. { dup 0 get false eq
  419. { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  420. } if
  421. } if
  422. }
  423. /CannotEmbedFontPolicy { }
  424. /EmbedAllFonts { }
  425. /MaxSubsetPct { }
  426. /SubsetFonts { }
  427. .dicttomark readonly def
  428. /.distillerdevice
  429. { currentdevice .devicename /pdfwrite eq
  430. { currentdevice }
  431. { /pdfwrite finddevice }
  432. ifelse
  433. } bind def
  434. /setdistillerparams { % <dict> setdistillerparams -
  435. .distillerdevice null false mark 4 index {
  436. //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  437. } forall .putdeviceparams
  438. dup type /booleantype ne {
  439. /setdistillerparams .pdfparamerror
  440. } {
  441. pop pop pop
  442. } ifelse
  443. } odef
  444. /currentdistillerparams { % - currentdistillerparams <dict>
  445. .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  446. % Patch StartPage and EndPage
  447. % ****** NOTE: StartPage and EndPage are disabled because
  448. % ****** EndPage clashes with a page device parameter.
  449. % begin /StartPage PDFStartPage /EndPage PDFEndPage
  450. % currentdict dup /PDFStartPage undef /PDFEndPage undef
  451. % def def currentdict end
  452. } odef
  453. % Patch 'where' so that the distillerparams operators are only visible
  454. % if the pdfwrite device is the current one, for the benefit of badly
  455. % designed PostScript files that "know" they have to do something different
  456. % if a distiller is processing them.
  457. .wheredict /currentdistillerparams {
  458. currentdevice .devicename /pdfwrite eq {
  459. .where
  460. } {
  461. .where pop dup //systemdict eq { pop false } { true } ifelse
  462. } ifelse
  463. } bind put
  464. .wheredict /setdistillerparams .wheredict /currentdistillerparams get put
  465. % Set a predefined configuration if PDFSETTINGS is defined.
  466. /PDFSETTINGS where { pop /PDFSETTINGS load } { /default } ifelse
  467. .distillersettings exch get
  468. % Don't override parameters defined on the command line.
  469. dup length .distillercommon length add dict begin
  470. .distillercommon 2 {
  471. {
  472. systemdict 2 index known { pop pop } { def } ifelse
  473. } forall
  474. } repeat
  475. currentdict end setdistillerparams