1
0

gs_pdfwr.ps 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. % Copyright (C) 1996, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_pdfwr.ps,v 1.52 2005/10/20 13:04:16 leonardo Exp $
  16. % PDF writer additions to systemdict.
  17. % This file should be included iff the pdfwrite "device" is included
  18. % in the executable.
  19. % ---------------- Predefined configurations ---------------- %
  20. % These correspond to the 4 predefined settings in Acrobat Distiller 5,
  21. % plus a "default" setting that doesn't downsample images.
  22. /.a2112 [2 1 1 2] readonly def
  23. /.a1111 [1 1 1 1] readonly def
  24. /.standardfonts [
  25. /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
  26. /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
  27. /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
  28. /Symbol /ZapfDingbats
  29. ] readonly def
  30. % Parameters common to all non-default configurations.
  31. % Note that the default configuration overrides a few of these.
  32. /.defaultImageDict mark
  33. /QFactor 0.9 /Blend 1
  34. /HSamples .a2112 /VSamples .a2112
  35. .dicttomark readonly def
  36. /.distillercommon mark
  37. /AlwaysEmbed []
  38. /AntiAliasColorImages false
  39. /AntiAliasGrayImages false
  40. /AntiAliasMonoImages false
  41. /ASCII85EncodePages false
  42. /AutoFilterColorImages true
  43. /AutoFilterGrayImages true
  44. /AutoPositionEPSFiles true
  45. /Binding /Left
  46. /CalCMYKProfile (None) % (U.S. Web Coated (SWOP) v2)
  47. /CalGrayProfile (None) % (Dot Gain 20%)
  48. /CalRGBProfile (None) % (sRGB IEC61966-2.1)
  49. /ColorImageDepth -1
  50. /ColorImageDict .defaultImageDict
  51. /ColorImageDownsampleThreshold 1.5
  52. /ColorImageFilter /DCTEncode
  53. /CompressPages true
  54. /ConvertImagesToIndexed true
  55. /DefaultRenderingIntent /Default
  56. /DetectBlends true
  57. /DownsampleColorImages true
  58. /DownsampleGrayImages true
  59. /DownsampleMonoImages true
  60. /EmitDSCWarnings false
  61. /EncodeColorImages true
  62. /EncodeGrayImages true
  63. /EncodeMonoImages true
  64. /EndPage -1
  65. /GrayImageDepth -1
  66. /GrayImageDict .defaultImageDict
  67. /GrayImageDownsampleThreshold 1.5
  68. /GrayImageFilter /DCTEncode
  69. /ImageMemory 524288
  70. /LockDistillerParams false
  71. /MaxSubsetPct 100
  72. /MonoImageDepth -1
  73. /MonoImageDict mark
  74. /K -1
  75. .dicttomark readonly
  76. /MonoImageDownsampleThreshold 1.5
  77. /MonoImageFilter /CCITTFaxEncode
  78. /OffOptimizations 0
  79. /OPM 1
  80. /Optimize true
  81. /ParseDSCComments true
  82. /ParseDSCCommentsForDocInfo true
  83. /PreserveCopyPage true
  84. /PreserveHalftoneInfo false
  85. /sRGBProfile (None) % (sRGB IEC61966-2.1)
  86. /StartPage 1
  87. /SubsetFonts true
  88. /TransferFunctionInfo /Preserve
  89. /UseFlateCompression true
  90. /UsePrologue false
  91. .dicttomark readonly def
  92. /.distillersettings mark
  93. /default mark
  94. /AutoRotatePages /PageByPage
  95. /CannotEmbedFontPolicy /Warning
  96. /ColorACSImageDict .defaultImageDict
  97. /ColorConversionStrategy /LeaveColorUnchanged
  98. % /ColorImageDownsampleType
  99. % /ColorImageResolution
  100. % /CompatibilityLevel
  101. /CreateJobTicket false
  102. /DoThumbnails false
  103. /DownsampleColorImages false % override
  104. /DownsampleGrayImages false % override
  105. /DownsampleMonoImages false % override
  106. /EmbedAllFonts true
  107. /GrayACSImageDict .defaultImageDict
  108. % /GrayImageDownsampleType
  109. % /GrayImageResolution
  110. % /MonoImageDownsampleType
  111. % /MonoImageResolution
  112. /NeverEmbed .standardfonts
  113. /Optimize false % override
  114. /PreserveEPSInfo true
  115. /PreserveOPIComments true
  116. /PreserveOverprintSettings true
  117. /UCRandBGInfo /Preserve
  118. .dicttomark readonly
  119. /.screenACSImageDict mark
  120. /QFactor 0.76 /Blend 1 /ColorTransform 1
  121. /HSamples .a2112 /VSamples .a2112
  122. .dicttomark readonly def
  123. /screen mark
  124. /AutoRotatePages /PageByPage
  125. % /CalGrayProfile (None)
  126. /CannotEmbedFontPolicy /Warning
  127. /ColorACSImageDict .screenACSImageDict
  128. /ColorConversionStrategy /sRGB
  129. /ColorImageDownsampleType /Average
  130. /ColorImageResolution 72
  131. /CompatibilityLevel 1.3
  132. /CreateJobTicket false
  133. /DoThumbnails false
  134. /EmbedAllFonts true
  135. /GrayACSImageDict .screenACSImageDict
  136. /GrayImageDownsampleType /Average
  137. /GrayImageResolution 72
  138. /MonoImageDownsampleType /Average
  139. /MonoImageResolution 300
  140. /NeverEmbed .standardfonts
  141. /PreserveEPSInfo false
  142. /PreserveOPIComments false
  143. /PreserveOverprintSettings false
  144. /UCRandBGInfo /Remove
  145. .dicttomark readonly
  146. /ebook mark
  147. /AutoRotatePages /All
  148. % /CalGrayProfile (None)
  149. /CannotEmbedFontPolicy /Warning
  150. /ColorACSImageDict .screenACSImageDict
  151. /ColorConversionStrategy /sRGB
  152. /ColorImageDownsampleType /Bicubic
  153. /ColorImageResolution 150
  154. /CompatibilityLevel 1.4
  155. /CreateJobTicket false
  156. /DoThumbnails false
  157. /EmbedAllFonts true
  158. /GrayACSImageDict .screenACSImageDict
  159. /GrayImageDownsampleType /Bicubic
  160. /GrayImageResolution 150
  161. /MonoImageDownsampleType /Bicubic
  162. /MonoImageResolution 300
  163. /NeverEmbed .standardfonts
  164. /PreserveEPSInfo false
  165. /PreserveOPIComments false
  166. /PreserveOverprintSettings false
  167. /UCRandBGInfo /Remove
  168. .dicttomark readonly
  169. /.printerACSImageDict mark
  170. /QFactor 0.4 /Blend 1 /ColorTransform 1
  171. /HSamples .a1111 /VSamples .a1111
  172. .dicttomark readonly def
  173. /printer mark
  174. /AutoRotatePages /None
  175. % /CalGrayProfile (None)
  176. /CannotEmbedFontPolicy /Warning
  177. /ColorACSImageDict .printerACSImageDict
  178. /ColorConversionStrategy /UseDeviceIndependentColor
  179. /ColorImageDownsampleType /Bicubic
  180. /ColorImageResolution 300
  181. /CompatibilityLevel 1.4
  182. /CreateJobTicket true
  183. /DoThumbnails false
  184. /EmbedAllFonts true
  185. /GrayACSImageDict .printerACSImageDict
  186. /GrayImageDownsampleType /Bicubic
  187. /GrayImageResolution 300
  188. /MonoImageDownsampleType /Bicubic
  189. /MonoImageResolution 1200
  190. /NeverEmbed []
  191. /PreserveEPSInfo true
  192. /PreserveOPIComments true
  193. /PreserveOverprintSettings true
  194. /UCRandBGInfo /Preserve
  195. .dicttomark readonly
  196. /.prepressACSImageDict mark
  197. /QFactor 0.15 /Blend 1 /ColorTransform 1
  198. /HSamples .a1111 /VSamples .a1111
  199. .dicttomark readonly def
  200. /prepress mark
  201. /AutoRotatePages /None
  202. /CannotEmbedFontPolicy /Error
  203. /ColorACSImageDict .prepressACSImageDict
  204. /ColorConversionStrategy /LeaveColorUnchanged
  205. /ColorImageDownsampleType /Bicubic
  206. /ColorImageResolution 300
  207. /CompatibilityLevel 1.4
  208. /CreateJobTicket true
  209. /DoThumbnails true
  210. /EmbedAllFonts true
  211. /GrayACSImageDict .prepressACSImageDict
  212. /GrayImageDownsampleType /Bicubic
  213. /GrayImageResolution 300
  214. /MonoImageDownsampleType /Bicubic
  215. /MonoImageResolution 1200
  216. /NeverEmbed []
  217. /PreserveEPSInfo true
  218. /PreserveOPIComments true
  219. /PreserveOverprintSettings true
  220. /UCRandBGInfo /Preserve
  221. .dicttomark readonly
  222. % Define distiller settings for the ps2write device and for the ps2ps2 script :
  223. /PSL2Printer mark
  224. /AutoRotatePages /None
  225. /CannotEmbedFontPolicy /Error
  226. /ColorACSImageDict .prepressACSImageDict
  227. /ColorConversionStrategy /LeaveColorUnchanged
  228. /ColorImageDownsampleType /Bicubic
  229. /ColorImageResolution 600
  230. /CompatibilityLevel 1.2 % Always 1.2 with ps2write.
  231. % /CreateJobTicket true % Not sure
  232. /DoThumbnails false
  233. /EmbedAllFonts true
  234. /GrayACSImageDict .prepressACSImageDict
  235. /GrayImageDownsampleType /Bicubic
  236. /GrayImageResolution 600
  237. /MonoImageDownsampleType /Bicubic
  238. /MonoImageResolution 1200
  239. /NeverEmbed []
  240. /PreserveEPSInfo true
  241. /PreserveOPIComments true
  242. /PreserveOverprintSettings true
  243. /UCRandBGInfo /Preserve
  244. /PreserveHalftoneInfo true
  245. /TransferFunctionInfo /Preserve
  246. /MaxViewerMemorySize 8000000
  247. /CompressPages false
  248. /CompressFonts false
  249. /ASCII85EncodePages true
  250. .dicttomark readonly
  251. .dicttomark readonly def
  252. % ---------------- End of predefined configurations ---------------- %
  253. % Set optimizations for converting PostScript to PDF.
  254. % The ps2pdf* scripts invoke this.
  255. /.setpdfwrite { % - .setpdfwrite -
  256. % Set a large VM threshold to reduce garbage collection.
  257. currentuserparams /VMThreshold get 3000000 .max setvmthreshold
  258. } bind def
  259. % ---------------- pdfmark and DSC processing ---------------- %
  260. /.write_small_positive_real % <file> <real> .write_small_positive_real -
  261. { % The argument must be grater than 0 and must be strongly samller than 0.1.
  262. % The conversion isn't simple due to the low (24 bits) precision
  263. % of the floating point arithmetics in Postscript.
  264. % For best result we first use the 1e8 factor since its binary
  265. % representation 101111101011110000100000000 well rounds into 14 significant
  266. % bits : 101111101011110000000000000 .
  267. 1 index (.) writestring
  268. { dup 100000000 mul
  269. dup 10 mul 1 ge {
  270. % Will need not greater than 0.1 due to a rounding below.
  271. pop exit
  272. } if
  273. exch pop
  274. 1 index (00000000) writestring
  275. } loop
  276. % Now it is not smaller than 1e-9, use simple digitizing.
  277. { dup 10 mul
  278. dup 10 mul 1 ge {
  279. pop exit
  280. } if
  281. exch pop
  282. 1 index (0) writestring
  283. } loop
  284. % Now 0.01 <= n < 0.1, but rounding may give 0.1 .
  285. % Convert to integer with 7 digits precision :
  286. 100000000 % precision factor 1e8 % f n r
  287. dup 10 idiv 3 1 roll mul 0.5 add cvi % f r' N
  288. 2 copy le {
  289. % The rounding overflows, suppress it.
  290. % Note it carries out an additional digit,
  291. % that's why we needed <0.1 above.
  292. pop pop (1) writestring
  293. } {
  294. % Didn't cary out, put 0.
  295. 2 index (0) writestring
  296. exch % f N r
  297. % Continue the simple digitizing :
  298. { 10 idiv dup % f N r' r'
  299. 2 index exch idiv % f N r' d
  300. (0123456789) exch 1 getinterval % f N r' (d)
  301. 3 index exch writestring % f N r'
  302. dup 3 2 roll exch mod % f r' N'
  303. dup 0 eq {
  304. % Don't write trailing zeros.
  305. exit
  306. } if
  307. exch % f N' r'
  308. } loop
  309. pop pop pop
  310. } ifelse
  311. } bind def
  312. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  313. /.pdf===dict mark
  314. /arraytype
  315. { dup xcheck { ({) (}) } { ([) (]) } ifelse
  316. % Stack: file obj left right
  317. 4 1 roll 2 index exch writestring () exch
  318. { exch 2 index exch writestring
  319. 1 index exch pdf===only ( )
  320. }
  321. forall pop exch writestring
  322. } bind
  323. /packedarraytype 1 index
  324. /dicttype
  325. { 1 index (<<\n) writestring
  326. { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  327. 1 index exch pdf===only dup (\n) writestring
  328. }
  329. forall (>>) writestring
  330. } bind
  331. /nametype {
  332. % If the name string includes any non-regular characters,
  333. % write it with two preceding and one following null character(s).
  334. % (Null characters in the name itself are not allowed.)
  335. % This non-standard escape convention is required for passing names
  336. % that include non-regular characters, because PostScript provides
  337. % no way to do this. The pdf_scan_token procedure in the C code of
  338. % the pdfwrite driver is currently the only place that recognizes
  339. % this convention.
  340. dup .namestring (\000\011\012\014\015 %()/<>[]{}) .stringbreak null ne {
  341. dup .namestring (\000) .stringbreak null ne {
  342. /rangecheck signalerror
  343. } if
  344. 1 index <0000> writestring 1 index exch write===only 0 write
  345. } {
  346. write===only
  347. } ifelse
  348. } bind
  349. /realtype {
  350. % Prevent using floating point format - see Bug 688167.
  351. dup dup 0 lt { neg } if 0.01 lt {
  352. dup 0 eq {
  353. pop (0) writestring
  354. } {
  355. dup 0 lt {
  356. 1 index (-) writestring neg
  357. } if
  358. .write_small_positive_real
  359. } ifelse
  360. } {
  361. write===only
  362. } ifelse
  363. } bind
  364. .dicttomark readonly def
  365. /pdf===only { % <file> <obj> pdf===only -
  366. .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  367. } bind def
  368. /.pdfcvbuf 30 string def % enough for most arguments
  369. userdict /.pdfcvstring () put
  370. /.pdfcvs { % <obj> .pdfcvs <string>
  371. currentglobal exch false .setglobal
  372. /.pdfcvstring () store
  373. % We can't handle long values yet.
  374. { pop dup length 0 eq { pop } {
  375. /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  376. } ifelse //.pdfcvbuf
  377. } /NullEncode filter dup 3 -1 roll pdf===only
  378. closefile
  379. .setglobal .pdfcvstring
  380. } bind def
  381. % Redefine pdfmark to pass the data to the driver.
  382. % We use a pseudo-parameter named /pdfmark whose value is an array:
  383. % /key1 (value1) ... (CTM) /type
  384. /.pdfputparams { % -mark- <key1> <value1> ... .pdfputparams <result...>
  385. currentdevice null false counttomark 1 add 3 roll
  386. % Don't allow the page device to get cleared....
  387. {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  388. } bind def
  389. % Convert relevant operands to strings in an array.
  390. /.pdfcvsloop { % -mark- values ... markname start step .pdfcvsloop
  391. % [values ... ctm markname]
  392. matrix currentmatrix .pdfcvs 4 1 roll
  393. counttomark 1 add 2 roll
  394. counttomark .localvmarray astore exch pop
  395. 3 1 roll
  396. % Stack: values start step
  397. 2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  398. } bind def
  399. /.pdfcvsall { % -mark- values ... markname .pdfcvsall <<same>>
  400. 0 1 .pdfcvsloop
  401. } bind def
  402. /.pdfcvseven { % -mark- key value ... markname .pdfcvseven <<same>>
  403. 1 2 .pdfcvsloop
  404. } bind def
  405. /.pdfcvsnone { % -mark- values ... markname .pdfcvsnone <<same>>
  406. 100000 1 .pdfcvsloop
  407. } bind def
  408. /.pdfcvsfirst { % -mark- first values ... markname .pdfcvsfirst<<same>>
  409. .pdfcvsnone
  410. dup 0 2 copy get .pdfcvs put
  411. } bind def
  412. % The procedures in the following dictionary are called with the entire
  413. % pdfmark operand list (including the pdfmark name) on the stack;
  414. % they may modify this ad lib. They must call .pdfcvsxxx.
  415. /.pdfmarkparams mark
  416. % Unpack a dictionary for PUT, and don't convert stream data.
  417. /PUT {
  418. counttomark 3 eq {
  419. 1 index type /dicttype eq {
  420. pop { } forall /.PUTDICT .pdfcvsall
  421. } {
  422. pop dup type /filetype eq {
  423. % Read the file into a sequence of strings.
  424. % This isn't great, but it's simple.
  425. {
  426. dup 64000 string readstring not { exch exit } if
  427. exch
  428. } loop closefile
  429. } if
  430. /.PUTSTREAM .pdfcvsfirst
  431. } ifelse
  432. } {
  433. .pdfcvsall
  434. } ifelse
  435. } bind
  436. % Unpack the array for PUTINTERVAL.
  437. /PUTINTERVAL {
  438. pop aload pop /.PUTINTERVAL .pdfcvsall
  439. } bind
  440. .dicttomark readonly def
  441. /.pdfparamerror { % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  442. counttomark 4 add 2 roll cleartomark pop pop pop
  443. .systemvar exch signalerror
  444. } bind def
  445. /pdfmark { % -mark- <key> <value> ... <markname> pdfmark -
  446. dup /SP eq {
  447. % A hack for synchronizing the clipping path.
  448. gsave
  449. [1 0 0 1 0 0] setmatrix 0 setlinewidth
  450. newpath -3 -3 moveto closepath stroke % Paints outside the device bbox.
  451. grestore
  452. } if
  453. dup /PS eq systemdict /PDFX .knownget not { false } if and {
  454. % Execute it since PDF/X doesn't allow to embed it.
  455. { dup mark eq {
  456. pop exit
  457. } if
  458. 1 index /DataSource eq {
  459. cvx exec
  460. } {
  461. pop pop
  462. } ifelse
  463. } loop
  464. } {
  465. counttomark 1 add copy
  466. //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  467. mark /pdfmark 3 -1 roll .pdfputparams
  468. dup type /booleantype ne {
  469. /pdfmark .pdfparamerror
  470. } if cleartomark
  471. } ifelse
  472. } odef
  473. userdict /pdfmark .undef
  474. currentdict /.pdfmarkparams .undef
  475. % <dict> .hook_DSC_Creator -
  476. /.pdf_hook_DSC_Creator
  477. {
  478. % If the Creator is PScript5.dll, disable the 32 /FontType resource for
  479. % handling GlyphNames2Unicode. Since /FontType category can't redefine,
  480. % we can do only with redefining the operator 'resourcestatus'.
  481. currentdevice .devicename /pdfwrite eq {
  482. /Creator .knownget {
  483. (PScript5.dll) search {
  484. pop pop
  485. systemdict /resourcestatus dup
  486. { dup /FontType eq 2 index 32 eq and {
  487. pop pop false
  488. } {
  489. resourcestatus
  490. } ifelse
  491. } bind .makeoperator .forceput
  492. } if
  493. pop
  494. } if
  495. } {
  496. pop
  497. } ifelse
  498. }
  499. bind def
  500. % Use the DSC processing hook to pass DSC comments to the driver.
  501. % We use a pseudo-parameter named DSC whose value is an array:
  502. % /key1 (value1) ... /type
  503. /.pdfdsc_dict 2 dict def
  504. /.pdfdsc { % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  505. 0 get dup null ne { 4 copy exch pop exec pop } { pop } ifelse 3 -1 roll pop
  506. % Stack: <dsc string> <dsc dict>
  507. 20 .localvmdict 1 index { 3 copy put pop pop } forall
  508. 3 -1 roll .parse_dsc_comments % <dsc dict> <dict> <type>
  509. 1 index //.pdf_hook_DSC_Creator exec
  510. dup /NOP ne 2 index length 1 gt or { % Skip unparsed comments
  511. PDFWRDEBUG { (**** DSC comment: ) print dup == 1 index === flush } if
  512. exch mark 4 1 roll {
  513. % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  514. 3 index 2 index known { % Skip the DSC_struct entry
  515. pop pop
  516. } {
  517. .pdfcvs 4 -2 roll
  518. } ifelse
  519. } forall exch pop counttomark .localvmarray astore
  520. mark /DSC 3 -1 roll .pdfputparams
  521. dup type /booleantype ne {
  522. /DSC .pdfparamerror
  523. } {
  524. cleartomark
  525. } ifelse
  526. } {
  527. pop pop pop
  528. } ifelse
  529. } bind def
  530. currentdict /.pdf_hook_DSC_Creator undef
  531. /.initialize_dsc_parser where {
  532. pop
  533. 3000 % priority
  534. {
  535. currentglobal true setglobal
  536. 2 dict dup .initialize_dsc_parser readonly
  537. currentuserparams /ProcessDSCComment get
  538. 1 array astore % in case the value is executable
  539. //.pdfdsc /exec load 4 array astore cvx readonly
  540. << /ProcessDSCComment 3 -1 roll >> setuserparams
  541. setglobal
  542. } bind .schedule_init
  543. } if
  544. % ---------------- {set,current}distillerparams ---------------- %
  545. % Define setdistillerparams / currentdistillerparams.
  546. % Distiller parameters are currently treated as device parameters.
  547. /.distillerparamkeys mark
  548. % General parameters -- all distillers
  549. /ASCII85EncodePages { }
  550. /AutoRotatePages { }
  551. /Binding { }
  552. /CompressPages { }
  553. /DefaultRenderingIntent { }
  554. /DetectBlends { }
  555. /DoThumbnails { }
  556. /ImageMemory { }
  557. /LockDistillerParams { }
  558. /LZWEncodePages { }
  559. /OPM { }
  560. /PreserveHalftoneInfo { }
  561. /PreserveOPIComments { }
  562. /PreserveOverprintSettings { }
  563. /TransferFunctionInfo { }
  564. /UCRandBGInfo { }
  565. /UseFlateCompression { }
  566. % General parameters -- PDF writer
  567. % StartPage and EndPage are renamed because EndPage
  568. % clashes with a page device parameter.
  569. /CoreDistVersion { }
  570. /CompatibilityLevel { }
  571. % ****** NOTE: StartPage and EndPage are disabled because
  572. % ****** EndPage clashes with a page device parameter.
  573. % /EndPage { exch pop /PDFEndPage exch }
  574. /PDFEndPage { pop pop }
  575. % /StartPage { exch pop /PDFStartPage exch }
  576. /PDFStartPage { pop pop }
  577. /Optimize { }
  578. /ParseDSCCommentsForDocInfo { }
  579. /ParseDSCComments { }
  580. /EmitDSCWarnings { }
  581. /CreateJobTicket { }
  582. /PreserveEPSInfo { }
  583. /AutoPositionEPSFiles { }
  584. /PreserveCopyPage { }
  585. /UsePrologue { }
  586. /OffOptimizations { }
  587. % Color sampled image parameters
  588. /ColorACSImageDict { }
  589. /AntiAliasColorImages { }
  590. /AutoFilterColorImages { }
  591. /ColorImageDepth { }
  592. /ColorImageDict { }
  593. /DownsampleColorImages { }
  594. /ColorImageDownsampleThreshold { }
  595. /ColorImageDownsampleType { }
  596. /EncodeColorImages { }
  597. /ColorImageFilter { }
  598. /ColorImageResolution { }
  599. % Color processing parameters
  600. /CalCMYKProfile { }
  601. /CalGrayProfile { }
  602. /CalRGBProfile { }
  603. /sRGBProfile { }
  604. /ColorConversionStrategy { }
  605. /ConvertCMYKImagesToRGB { }
  606. /ConvertImagesToIndexed { }
  607. % Grayscale sampled image parameters
  608. /GrayACSImageDict { }
  609. /AntiAliasGrayImages { }
  610. /AutoFilterGrayImages { }
  611. /GrayImageDepth { }
  612. /GrayImageDict { }
  613. /DownsampleGrayImages { }
  614. /GrayImageDownsampleThreshold { }
  615. /GrayImageDownsampleType { }
  616. /EncodeGrayImages { }
  617. /GrayImageFilter { }
  618. /GrayImageResolution { }
  619. % Monochrome sampled image parameters
  620. /AntiAliasMonoImages { }
  621. /MonoImageDepth { }
  622. /MonoImageDict { }
  623. /DownsampleMonoImages { }
  624. /MonoImageDownsampleThreshold { }
  625. /MonoImageDownsampleType { }
  626. /EncodeMonoImages { }
  627. /MonoImageFilter { }
  628. /MonoImageResolution { }
  629. % Font embedding parameters
  630. /AlwaysEmbed
  631. { dup length 0 gt
  632. { dup 0 get false eq
  633. { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  634. } if
  635. } if
  636. }
  637. /NeverEmbed
  638. { dup length 0 gt
  639. { dup 0 get false eq
  640. { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  641. } if
  642. } if
  643. }
  644. /CannotEmbedFontPolicy { }
  645. /EmbedAllFonts { }
  646. /MaxSubsetPct { }
  647. /SubsetFonts { }
  648. .dicttomark readonly def
  649. /.distillerdevice
  650. { currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or
  651. { currentdevice }
  652. { /pdfwrite finddevice }
  653. ifelse
  654. } bind def
  655. % Some badly designed PostScript files only expect the current/set
  656. % distillerparams operators to exist in a distiller. Since we have
  657. % this as a runtime option, we enable these operators IFF the
  658. % currentdevice is pdfwrite. Also, we mask their existence in
  659. % systemdict so that 'where' and 'known' don't show them unless
  660. % the currentdevice is pdfwrite.
  661. /.setdistillerparams { % <dict> setdistillerparams -
  662. .distillerdevice //null false mark 4 index {
  663. //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  664. } forall .putdeviceparamsonly
  665. dup type /booleantype ne {
  666. /setdistillerparams .pdfparamerror
  667. } {
  668. pop pop pop
  669. } ifelse
  670. } odef
  671. /.currentdistillerparams { % - currentdistillerparams <dict>
  672. .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  673. % Patch StartPage and EndPage
  674. % ****** NOTE: StartPage and EndPage are disabled because
  675. % ****** EndPage clashes with a page device parameter.
  676. % begin /StartPage PDFStartPage /EndPage PDFEndPage
  677. % currentdict dup /PDFStartPage undef /PDFEndPage undef
  678. % def def currentdict end
  679. } odef
  680. /setdistillerparams {
  681. currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and {
  682. /setdistillerparams /undefined signalerror
  683. } if
  684. .setdistillerparams
  685. } bind odef
  686. /currentdistillerparams {
  687. currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and {
  688. /currentdistillerparams /undefined signalerror
  689. } if
  690. .currentdistillerparams
  691. } bind odef
  692. % Patch 'where' so that the distiller operators are only visible
  693. % if the pdfwrite device is the current one.
  694. { currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or{
  695. .where
  696. } {
  697. .where pop dup //systemdict eq { pop false } { true } ifelse
  698. } ifelse
  699. } bind
  700. { /currentdistillerparams /setdistillerparams /pdfmark }
  701. { .wheredict exch 2 index put } forall pop
  702. % Patch 'known' to hide the systemdict version of distiller operators
  703. % unless the currentdevice is pdfwrite.
  704. /known {
  705. /currentdistillerparams 1 index eq /setdistillerparams 2 index eq or
  706. /pdfmark 2 index eq or {
  707. systemdict 2 index eq { % only mask the operator in systemdict
  708. known currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and { pop false } if
  709. } {
  710. known
  711. } ifelse
  712. } {
  713. known
  714. } ifelse
  715. } .bind odef
  716. 1000 % priority
  717. {
  718. % Note, this may not work if the initial device is not pdfwrite
  719. % and may require the use of -dProvideUnicode on the command line.
  720. currentdevice .devicename /pdfwrite eq
  721. systemdict /ProvideUnicode .knownget not { false } if or {
  722. currentglobal true setglobal
  723. systemdict /.setupUnicodeDecoder known {
  724. /Unicode /Decoding resourcestatus {
  725. pop pop
  726. /Unicode /Decoding findresource
  727. .setupUnicodeDecoder
  728. } {
  729. QUIET not {
  730. (WARNING: /Unicode /Decoding resource is not accessible but it is useful for generating ToUnicode CMap.) =
  731. } if
  732. } ifelse
  733. } if
  734. setglobal
  735. } if
  736. } bind .schedule_init
  737. 1010 % priority
  738. {
  739. % Set a predefined configuration in the distiller device (pdfwrite)
  740. /PDFSETTINGS where {
  741. pop /PDFSETTINGS load
  742. } {
  743. currentdevice .devicename /ps2write eq { /PSL2Printer } { /default } ifelse
  744. } ifelse
  745. .distillersettings exch get
  746. % Don't override parameters defined on the command line.
  747. dup length .distillercommon length add dict begin
  748. .distillercommon 2 {
  749. {
  750. systemdict 2 index known { pop pop } { def } ifelse
  751. } forall
  752. } repeat
  753. currentdict end .setdistillerparams
  754. .distillerdevice //null false mark .putdeviceparams
  755. dup type /booleantype eq not { cleartomark pop } if pop pop
  756. } bind .schedule_init
  757. 1011 % priority
  758. {
  759. % Set a path to library files (ps2write)
  760. currentdevice .devicename /ps2write eq {
  761. mark
  762. systemdict /OPDFReadProcsetPath .knownget not {
  763. (gs_mgl_e.ps) (gs_mro_e.ps) (gs_agl.ps) (opdfread.ps) % Reverse order !
  764. () counttomark 1 sub {
  765. exch
  766. .libfile { .filename } { false } ifelse not {
  767. (Configuration error : library file opdfread.ps not found !) =
  768. (opdfread.ps) /undefinedfilename signalerror
  769. } if
  770. .filenamelistseparator concatstrings concatstrings
  771. } repeat
  772. } if
  773. /OPDFReadProcsetPath exch .dicttomark setpagedevice
  774. } if
  775. } bind .schedule_init
  776. 2000 % priority
  777. { % Note, this may not work if the initial device is not pdfwrite
  778. currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or {
  779. % Inform the device with initial graphic state. See gdev_pdf_fill_path.
  780. newpath fill
  781. } if
  782. } bind .schedule_init