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.

1073 lines
33 KiB

1 month ago
  1. % Copyright (C) 2001-2024 Artifex Software, Inc.
  2. % 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. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % PDF writer additions to systemdict.
  16. % This file should be included iff the pdfwrite "device" is included
  17. % in the executable.
  18. % ---------------- Predefined configurations ---------------- %
  19. % These correspond to the 4 predefined settings in Acrobat Distiller 5,
  20. % plus a "default" setting that doesn't downsample images.
  21. mark
  22. { /pdfwrite finddevice pop } .internalstopped
  23. {cleartomark (%END PDFWR) .skipeof} {cleartomark} ifelse
  24. languagelevel 2 .setlanguagelevel
  25. /.a2112 [2 1 1 2] readonly def
  26. /.a1111 [1 1 1 1] readonly def
  27. /.standardfonts [
  28. /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
  29. /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
  30. /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
  31. /Symbol /ZapfDingbats
  32. ] readonly def
  33. % Parameters common to all non-default configurations.
  34. % Note that the default configuration overrides a few of these.
  35. /.defaultImageDict mark
  36. /QFactor 0.9 /Blend 1
  37. /HSamples .a2112 /VSamples .a2112
  38. .dicttomark readonly def
  39. /.distillercommon mark
  40. /AlwaysEmbed []
  41. /AntiAliasColorImages //false
  42. /AntiAliasGrayImages //false
  43. /AntiAliasMonoImages //false
  44. /ASCII85EncodePages //false
  45. /AutoFilterColorImages //true
  46. /AutoFilterGrayImages //true
  47. /AutoPositionEPSFiles //true
  48. /Binding /Left
  49. /CalCMYKProfile (None) % (U.S. Web Coated (SWOP) v2)
  50. /CalGrayProfile (None) % (Dot Gain 20%)
  51. /CalRGBProfile (None) % (sRGB IEC61966-2.1)
  52. /ColorImageDepth -1
  53. /ColorImageDict .defaultImageDict
  54. /ColorImageDownsampleThreshold 1.5
  55. /ColorImageFilter /DCTEncode
  56. /CompressPages //true
  57. /ConvertImagesToIndexed //true
  58. /DefaultRenderingIntent /Default
  59. /DetectBlends //true
  60. /DownsampleColorImages //true
  61. /DownsampleGrayImages //true
  62. /DownsampleMonoImages //true
  63. /EmitDSCWarnings //false
  64. /EncodeColorImages //true
  65. /EncodeGrayImages //true
  66. /EncodeMonoImages //true
  67. /EndPage -1
  68. /GrayImageDepth -1
  69. /GrayImageDict .defaultImageDict
  70. /GrayImageDownsampleThreshold 1.5
  71. /GrayImageFilter /DCTEncode
  72. /ImageMemory 524288
  73. /LockDistillerParams //false
  74. /MaxSubsetPct 100
  75. /MonoImageDepth -1
  76. /MonoImageDict mark
  77. /K -1
  78. .dicttomark readonly
  79. /MonoImageDownsampleThreshold 1.5
  80. /MonoImageFilter /CCITTFaxEncode
  81. /OffOptimizations 0
  82. /OPM 0
  83. /Optimize //true
  84. /ParseDSCComments //true
  85. /ParseDSCCommentsForDocInfo //true
  86. /PDFXTrimBoxToMediaBoxOffset [0 0 0 0]
  87. /PDFXSetBleedBoxToMediaBox //true
  88. /PDFXBleedBoxToTrimBoxOffset [0 0 0 0]
  89. /PreserveCopyPage //true
  90. /PreserveHalftoneInfo //false
  91. /sRGBProfile (None) % (sRGB IEC61966-2.1)
  92. /StartPage 1
  93. /SubsetFonts //true
  94. /TransferFunctionInfo /Preserve
  95. /UseFlateCompression //true
  96. /UsePrologue //false
  97. /PassThroughJPEGImages //true
  98. /PassThroughJPXImages //true
  99. /PSPageOptionsWrap //true
  100. .dicttomark readonly def
  101. /.distillersettings mark
  102. /default mark
  103. /AutoRotatePages /PageByPage
  104. /CannotEmbedFontPolicy /Warning
  105. /ColorACSImageDict .defaultImageDict
  106. /ColorConversionStrategy /LeaveColorUnchanged
  107. % /ColorImageDownsampleType
  108. % /ColorImageResolution
  109. % /CompatibilityLevel
  110. /CreateJobTicket //false
  111. /DoThumbnails //false
  112. /DownsampleColorImages //false % override
  113. /DownsampleGrayImages //false % override
  114. /DownsampleMonoImages //false % override
  115. /EmbedAllFonts //true
  116. /GrayACSImageDict .defaultImageDict
  117. % /GrayImageDownsampleType
  118. % /GrayImageResolution
  119. % /MonoImageDownsampleType
  120. % /MonoImageResolution
  121. /NeverEmbed .standardfonts
  122. /Optimize //false % override
  123. /PreserveEPSInfo //true
  124. /PreserveOPIComments //true
  125. /PreserveOverprintSettings //true
  126. /UCRandBGInfo /Preserve
  127. .dicttomark readonly
  128. /.screenACSImageDict mark
  129. /QFactor 0.76 /Blend 1 /ColorTransform 1
  130. /HSamples .a2112 /VSamples .a2112
  131. .dicttomark readonly def
  132. /screen mark
  133. /AutoRotatePages /PageByPage
  134. % /CalGrayProfile (None)
  135. /CannotEmbedFontPolicy /Warning
  136. /ColorACSImageDict .screenACSImageDict
  137. /ColorConversionStrategy /sRGB
  138. /ColorImageDownsampleType /Average
  139. /ColorImageResolution 72
  140. /CompatibilityLevel 1.5
  141. /CreateJobTicket //false
  142. /DoThumbnails //false
  143. /EmbedAllFonts //true
  144. /GrayACSImageDict .screenACSImageDict
  145. /GrayImageDownsampleType /Average
  146. /GrayImageResolution 72
  147. /MonoImageDownsampleType /Subsample
  148. /MonoImageResolution 300
  149. /NeverEmbed .standardfonts
  150. /PreserveEPSInfo //false
  151. /PreserveOPIComments //false
  152. /PreserveOverprintSettings //false
  153. /UCRandBGInfo /Remove
  154. .dicttomark readonly
  155. /ebook mark
  156. /AutoRotatePages /All
  157. % /CalGrayProfile (None)
  158. /CannotEmbedFontPolicy /Warning
  159. /ColorACSImageDict .screenACSImageDict
  160. /ColorConversionStrategy /sRGB
  161. /ColorImageDownsampleType /Average
  162. /ColorImageResolution 150
  163. /CompatibilityLevel 1.5
  164. /CreateJobTicket //false
  165. /DoThumbnails //false
  166. /EmbedAllFonts //true
  167. /GrayACSImageDict .screenACSImageDict
  168. /GrayImageDownsampleType /Average
  169. /GrayImageResolution 150
  170. /MonoImageDownsampleType /Subsample
  171. /MonoImageResolution 300
  172. /NeverEmbed .standardfonts
  173. /PreserveEPSInfo //false
  174. /PreserveOPIComments //false
  175. /PreserveOverprintSettings //false
  176. /UCRandBGInfo /Remove
  177. .dicttomark readonly
  178. /.printerACSImageDict mark
  179. /QFactor 0.4 /Blend 1 /ColorTransform 1
  180. /HSamples .a1111 /VSamples .a1111
  181. .dicttomark readonly def
  182. /printer mark
  183. /AutoRotatePages /None
  184. % /CalGrayProfile (None)
  185. /CannotEmbedFontPolicy /Warning
  186. /ColorACSImageDict .printerACSImageDict
  187. /ColorConversionStrategy /UseDeviceIndependentColor
  188. /ColorImageDownsampleType /Average
  189. /ColorImageResolution 300
  190. /CompatibilityLevel 1.7
  191. /CreateJobTicket //true
  192. /DoThumbnails //false
  193. /EmbedAllFonts //true
  194. /GrayACSImageDict .printerACSImageDict
  195. /GrayImageDownsampleType /Average
  196. /GrayImageResolution 300
  197. /MonoImageDownsampleType /Subsample
  198. /MonoImageResolution 1200
  199. /NeverEmbed []
  200. /PreserveEPSInfo //true
  201. /PreserveOPIComments //true
  202. /PreserveOverprintSettings //true
  203. /UCRandBGInfo /Preserve
  204. .dicttomark readonly
  205. /.prepressACSImageDict mark
  206. /QFactor 0.15 /Blend 1 /ColorTransform 1
  207. /HSamples .a1111 /VSamples .a1111
  208. .dicttomark readonly def
  209. /prepress mark
  210. /AutoRotatePages /None
  211. /CannotEmbedFontPolicy /Error
  212. /ColorACSImageDict .prepressACSImageDict
  213. /ColorConversionStrategy /LeaveColorUnchanged
  214. /ColorImageDownsampleType /Bicubic
  215. /ColorImageResolution 300
  216. /CompatibilityLevel 1.7
  217. /CreateJobTicket //true
  218. /DoThumbnails //true
  219. /EmbedAllFonts //true
  220. /GrayACSImageDict .prepressACSImageDict
  221. /GrayImageDownsampleType /Bicubic
  222. /GrayImageResolution 300
  223. /MonoImageDownsampleType /Subsample
  224. /MonoImageResolution 1200
  225. /NeverEmbed []
  226. /PreserveEPSInfo //true
  227. /PreserveOPIComments //true
  228. /PreserveOverprintSettings //true
  229. /UCRandBGInfo /Preserve
  230. .dicttomark readonly
  231. % Define distiller settings for the ps2write device and for the ps2ps2 script :
  232. /PSL2Printer mark
  233. /AutoRotatePages /None
  234. /CannotEmbedFontPolicy /Error
  235. /ColorACSImageDict .prepressACSImageDict
  236. /ColorConversionStrategy /LeaveColorUnchanged
  237. /ColorImageDownsampleType /Subsample
  238. /ColorImageResolution 600
  239. /DownsampleColorImages //false
  240. /CompatibilityLevel 1.2 % Always 1.2 with ps2write.
  241. % /CreateJobTicket //true % Not sure
  242. /DoThumbnails //false
  243. /EmbedAllFonts //true
  244. /GrayACSImageDict .prepressACSImageDict
  245. /GrayImageDownsampleType /Subsample
  246. /GrayImageResolution 600
  247. /DownsampleGrayImages //false
  248. /MonoImageDownsampleType /Subsample
  249. /MonoImageResolution 1200
  250. /DownsampleMonoImages //false
  251. /NeverEmbed []
  252. /PreserveEPSInfo //true
  253. /PreserveOPIComments //true
  254. /PreserveOverprintSettings //true
  255. /UCRandBGInfo /Preserve
  256. /PreserveHalftoneInfo //true
  257. /TransferFunctionInfo /Preserve
  258. %% Deprecated in 9.06
  259. %% /MaxViewerMemorySize 8000000
  260. /CompressPages //false
  261. /CompressFonts //true
  262. /ASCII85EncodePages //true
  263. .dicttomark readonly
  264. .dicttomark readonly def
  265. % ---------------- End of predefined configurations ---------------- %
  266. % ---------------- pdfmark and DSC processing ---------------- %
  267. /.write_small_positive_real % <file> <real> .write_small_positive_real -
  268. { % The argument must be grater than 0 and must be strongly samller than 0.1.
  269. % The conversion isn't simple due to the low (24 bits) precision
  270. % of the floating point arithmetics in Postscript.
  271. % For best result we first use the 1e8 factor since its binary
  272. % representation 101111101011110000100000000 well rounds into 14 significant
  273. % bits : 101111101011110000000000000 .
  274. 1 index (.) writestring
  275. { dup 100000000 mul
  276. dup 10 mul 1 ge {
  277. % Will need not greater than 0.1 due to a rounding below.
  278. pop exit
  279. } if
  280. exch pop
  281. 1 index (00000000) writestring
  282. } loop
  283. % Now it is not smaller than 1e-9, use simple digitizing.
  284. { dup 10 mul
  285. dup 10 mul 1 ge {
  286. pop exit
  287. } if
  288. exch pop
  289. 1 index (0) writestring
  290. } loop
  291. % Now 0.01 <= n < 0.1, but rounding may give 0.1 .
  292. % Convert to integer with 7 digits precision :
  293. 100000000 % precision factor 1e8 % f n r
  294. dup 10 idiv 3 1 roll mul 0.5 add cvi % f r' N
  295. 2 copy le {
  296. % The rounding overflows, suppress it.
  297. % Note it carries out an additional digit,
  298. % that's why we needed <0.1 above.
  299. pop pop (1) writestring
  300. } {
  301. % Didn't cary out, put 0.
  302. 2 index (0) writestring
  303. exch % f N r
  304. % Continue the simple digitizing :
  305. { 10 idiv dup % f N r' r'
  306. 2 index exch idiv % f N r' d
  307. (0123456789) exch 1 getinterval % f N r' (d)
  308. 3 index exch writestring % f N r'
  309. dup 3 2 roll exch mod % f r' N'
  310. dup 0 eq {
  311. % Don't write trailing zeros.
  312. exit
  313. } if
  314. exch % f N' r'
  315. } loop
  316. pop pop pop
  317. } ifelse
  318. } .internalbind def
  319. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  320. /.pdf===dict mark
  321. /arraytype
  322. { dup xcheck { ({) (}) } { ([) (]) } ifelse
  323. % Stack: file obj left right
  324. 4 1 roll 2 index exch writestring () exch
  325. { exch 2 index exch writestring
  326. 1 index exch pdf===only ( )
  327. }
  328. forall pop exch writestring
  329. } .internalbind
  330. /packedarraytype 1 index
  331. /dicttype
  332. { 1 index (<<\n) writestring
  333. { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  334. 1 index exch pdf===only dup (\n) writestring
  335. }
  336. forall (>>) writestring
  337. } .internalbind
  338. /nametype {
  339. % If the name string includes any non-regular characters,
  340. % write it with two preceding and one following null character(s).
  341. % (Null characters in the name itself are not allowed.)
  342. % This non-standard escape convention is required for passing names
  343. % that include non-regular characters, because PostScript provides
  344. % no way to do this. The pdf_scan_token procedure in the C code of
  345. % the pdfwrite driver is currently the only place that recognizes
  346. % this convention.
  347. % Note that \004 may be self-delimiting in gs, but is not in standard PS.
  348. dup .namestring (\000\004\011\012\014\015 %()/<>[]{}) .stringbreak //null ne {
  349. dup .namestring (\000) .stringbreak //null ne {
  350. 1 index <000000> writestring 1 index exch write===only 1 index exch 0 write 0 write
  351. }{
  352. 1 index <0000> writestring 1 index exch write===only 0 write
  353. }ifelse
  354. } {
  355. write===only
  356. } ifelse
  357. } .internalbind
  358. /realtype {
  359. % Prevent using floating point format - see Bug 688167.
  360. dup dup 0 lt { neg } if 0.01 lt {
  361. dup 0 eq {
  362. pop (0) writestring
  363. } {
  364. dup 0 lt {
  365. 1 index (-) writestring neg
  366. } if
  367. .write_small_positive_real
  368. } ifelse
  369. } {
  370. write===only
  371. } ifelse
  372. } .internalbind
  373. .dicttomark readonly def
  374. /pdf===only { % <file> <obj> pdf===only -
  375. .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  376. } .internalbind def
  377. /.pdfcvbuf 30 string def % enough for most arguments
  378. userdict /.pdfcvstring () put
  379. /.pdfcvs { % <obj> .pdfcvs <string>
  380. currentglobal exch //false .setglobal
  381. /.pdfcvstring () store
  382. % We can't handle long values yet.
  383. { pop dup length 0 eq { pop } {
  384. /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  385. } ifelse //.pdfcvbuf
  386. } /NullEncode filter dup 3 -1 roll pdf===only
  387. closefile
  388. .setglobal .pdfcvstring
  389. } .internalbind def
  390. % Redefine pdfmark to pass the data to the driver.
  391. % We use a pseudo-parameter named /pdfmark whose value is an array:
  392. % /key1 (value1) ... (CTM) /type
  393. /.pdfputparams { % -mark- <key1> <value1> ... .pdfputparams <result...>
  394. currentdevice //null //false counttomark 1 add 3 roll
  395. % Don't allow the page device to get cleared....
  396. {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  397. } .internalbind def
  398. % Convert relevant operands to strings in an array.
  399. /.pdfcvsloop { % -mark- values ... markname start step .pdfcvsloop
  400. % [values ... ctm markname]
  401. matrix currentmatrix .pdfcvs 4 1 roll
  402. counttomark 1 add 2 roll
  403. counttomark .localvmarray astore exch pop
  404. 3 1 roll
  405. % Stack: values start step
  406. 2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  407. } .internalbind def
  408. /.pdfcvsall { % -mark- values ... markname .pdfcvsall <<same>>
  409. 0 1 .pdfcvsloop
  410. } .internalbind def
  411. /.pdfcvseven { % -mark- key value ... markname .pdfcvseven <<same>>
  412. 1 2 .pdfcvsloop
  413. } .internalbind def
  414. /.pdfcvsnone { % -mark- values ... markname .pdfcvsnone <<same>>
  415. 100000 1 .pdfcvsloop
  416. } .internalbind def
  417. /.pdfcvsfirst { % -mark- first values ... markname .pdfcvsfirst<<same>>
  418. .pdfcvsnone
  419. dup 0 2 copy get .pdfcvs put
  420. } .internalbind def
  421. % The procedures in the following dictionary are called with the entire
  422. % pdfmark operand list (including the pdfmark name) on the stack;
  423. % they may modify this ad lib. They must call .pdfcvsxxx.
  424. /.pdfmarkparams mark
  425. % Unpack a dictionary for PUT, and don't convert stream data.
  426. /PUT {
  427. counttomark 3 eq {
  428. 1 index type /dicttype eq {
  429. pop { } forall /.PUTDICT .pdfcvsall
  430. } {
  431. pop dup type /filetype eq {
  432. % Read the file into a sequence of strings.
  433. % This isn't great, but it's simple.
  434. {
  435. dup 64000 string readstring not { exch exit } if
  436. exch
  437. } loop closefile
  438. } if
  439. /.PUTSTREAM .pdfcvsfirst
  440. } ifelse
  441. } {
  442. .pdfcvsall
  443. } ifelse
  444. } .internalbind
  445. % Unpack the array for PUTINTERVAL.
  446. /PUTINTERVAL {
  447. pop aload pop /.PUTINTERVAL .pdfcvsall
  448. } .internalbind
  449. .dicttomark readonly def
  450. /.pdfparamerror { % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  451. counttomark 4 add 2 roll cleartomark pop pop pop
  452. .systemvar exch signalerror
  453. } .internalbind def
  454. /.CountLeafs {
  455. 0 exch
  456. {
  457. oforce dup type /dicttype eq {
  458. /Limits knownoget {
  459. dup type /arraytype eq {
  460. 1 get 2 copy lt {
  461. exch pop
  462. }{
  463. pop
  464. }ifelse
  465. }{
  466. (invalid number tree, /Limits not an array\n) print
  467. pop pop 0 exit
  468. } ifelse
  469. }{
  470. (invalid number tree, /Limits not defined in intermediate or leaf node\n) print
  471. pop pop 0 exit
  472. }ifelse
  473. } {
  474. (invalid number tree, /Kids entry not a dictionary\n) print
  475. pop pop 0 exit
  476. } ifelse
  477. } forall
  478. } .internalbind def
  479. /.ExtractLeafs
  480. {
  481. {
  482. oforce dup /Nums knownoget {
  483. exch pop
  484. dup length 1 sub 0 2 3 -1 roll {
  485. %% dict array index
  486. dup %% dict array index index
  487. 2 index exch get %% dict array index
  488. 20 string cvs cvn %% dict array index name
  489. exch 1 add %% dict array name index+1
  490. 2 index exch oget %% dict array name object
  491. 3 index %% dict array name object dict
  492. 3 1 roll %% dict array dict name object
  493. put %% dict array
  494. } for
  495. pop %% array
  496. }{
  497. /Kids knownoget {
  498. .ExtractLeafs
  499. } if
  500. } ifelse
  501. } forall
  502. } .internalbind def
  503. /.pdfpagelabels {
  504. dup type /dicttype eq {
  505. dup /Nums knownoget {
  506. exch pop
  507. mark exch
  508. 0 1 2 index length 1 sub {
  509. 1 index exch oget
  510. exch
  511. } for
  512. pop
  513. counttomark array astore
  514. 1 dict dup begin exch /Nums exch def end
  515. .pdfcvs
  516. mark /pdfpagelabels 3 -1 roll .pdfputparams
  517. dup type /booleantype ne {
  518. /pdfpagelabels .pdfparamerror
  519. } if cleartomark
  520. }{
  521. /Kids knownoget {
  522. dup .CountLeafs dup 1000 ge {
  523. (PageLabel tree too complex, ignoring PageLabels\n) print flush
  524. pop pop
  525. }{
  526. dict exch .ExtractLeafs mark exch dup length 0 1 3 -1 roll {
  527. dup 20 string cvs cvn %% mark dict index name
  528. 2 index exch .knownget{
  529. %% mark ... dict index object
  530. 3 -1 roll %% mark ... index object dict
  531. }{
  532. pop
  533. }ifelse
  534. } for
  535. pop
  536. counttomark array astore
  537. 1 dict dup begin exch /Nums exch def end
  538. .pdfcvs
  539. mark /pdfpagelabels 3 -1 roll .pdfputparams
  540. dup type /booleantype ne {
  541. /pdfpagelabels .pdfparamerror
  542. } if cleartomark
  543. }ifelse
  544. }{
  545. (Invalid number tree in PageLabels, ignoring PageLabels\n) print flush
  546. }ifelse
  547. }ifelse
  548. }{
  549. /pdfpagelabels .pdfparamerror
  550. } ifelse
  551. } .internalbind def
  552. /pdfmark { % -mark- <key> <value> ... <markname> pdfmark -
  553. counttomark 0 eq {
  554. /pdfmark cvx /stackunderflow signalerror
  555. } if
  556. dup type /nametype eq not {
  557. /pdfmark cvx /typecheck signalerror
  558. } if
  559. dup /SP eq {
  560. % A hack for synchronizing the clipping path.
  561. gsave
  562. [1 0 0 1 0 0] setmatrix 0 setlinewidth
  563. newpath -3 -3 moveto closepath stroke % Paints outside the device bbox.
  564. grestore
  565. } if
  566. dup /PS eq systemdict /PDFX .knownget not { //false } if
  567. systemdict /PDFA .knownget not { //false }{0 eq {//false}{//true} ifelse} ifelse or and {
  568. % Execute it since PDF/X doesn't allow to embed it.
  569. pop
  570. { dup mark eq {
  571. pop exit
  572. } if
  573. 1 index /DataSource eq {
  574. exch pop
  575. cvx exec
  576. } {
  577. pop pop
  578. } ifelse
  579. } loop
  580. } {
  581. counttomark 1 add copy
  582. //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  583. mark /pdfmark 3 -1 roll .pdfputparams
  584. dup type /booleantype ne {
  585. /pdfmark .pdfparamerror
  586. } if cleartomark
  587. } ifelse
  588. } odef
  589. userdict /pdfmark .undef
  590. currentdict /.pdfmarkparams .undef
  591. % <dict> .hook_DSC_Creator -
  592. /.pdf_hook_DSC_Creator
  593. {
  594. % If the Creator is PScript5.dll, disable the 32 /FontType resource for
  595. % handling GlyphNames2Unicode. Since /FontType category can't redefine,
  596. % we can do only with redefining the operator 'resourcestatus'.
  597. systemdict /.pdf_hooked_DSC_Creator .knownget
  598. {
  599. {//false}{//true} ifelse
  600. }
  601. {
  602. //true
  603. } ifelse
  604. {
  605. /WantsToUnicode /GetDeviceParam .special_op {
  606. exch pop
  607. }{
  608. //true
  609. }ifelse
  610. {
  611. /Creator .knownget {
  612. (PScript5.dll) search {
  613. pop pop
  614. systemdict /resourcestatus dup
  615. { dup /FontType eq 2 index 32 eq and {
  616. pop pop //false
  617. } {
  618. resourcestatus
  619. } ifelse
  620. } .internalbind .makeoperator .forceput
  621. systemdict /.pdf_hooked_DSC_Creator //true .forceput
  622. } executeonly if
  623. pop
  624. } executeonly if
  625. } {
  626. pop
  627. } ifelse
  628. } executeonly
  629. {
  630. pop
  631. } ifelse
  632. } .forcebind odef % must be bound and hidden for .forceput
  633. % Use the DSC processing hook to pass DSC comments to the driver.
  634. % We use a pseudo-parameter named DSC whose value is an array:
  635. % /key1 (value1) ... /type
  636. /.pdfdsc_dict 2 dict def
  637. /.pdfdsc { % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  638. 0 get dup //null ne { 4 copy exch pop exec pop } { pop } ifelse 3 -1 roll pop
  639. % Stack: <dsc string> <dsc dict>
  640. 20 .localvmdict 1 index { 3 copy put pop pop } forall
  641. 3 -1 roll .parse_dsc_comments % <dsc dict> <dict> <type>
  642. 1 index //.pdf_hook_DSC_Creator exec
  643. dup /NOP ne 2 index length 1 gt or { % Skip unparsed comments
  644. PDFWRDEBUG { (**** DSC comment: ) print dup //== exec 1 index === flush } if
  645. exch mark 4 1 roll {
  646. % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  647. 3 index 2 index known { % Skip the DSC_struct entry
  648. pop pop
  649. } {
  650. .pdfcvs 4 -2 roll
  651. } ifelse
  652. } forall exch pop counttomark .localvmarray astore
  653. mark /DSC 3 -1 roll .pdfputparams
  654. dup type /booleantype ne {
  655. /DSC .pdfparamerror
  656. } {
  657. cleartomark
  658. } ifelse
  659. } {
  660. pop pop pop
  661. } ifelse
  662. } .internalbind def
  663. currentdict /.pdf_hook_DSC_Creator undef
  664. /.initialize_dsc_parser where {
  665. pop
  666. 3000 % priority
  667. {
  668. % When running gpdl, due to the way gpdl has to do job encapsulation
  669. % the scheduled initialisation procedures get run at the start of each
  670. % job. Because this patches the existing procedure, it could end up
  671. % patching itself, so the procedure got larger/deeper with each job.
  672. % Eventually, copying the user params (see /.setuserparams2 in gs_lev2.ps)
  673. % would end up overflowing the exec stack.
  674. % So, as part of the patching, we push and pop a sacrificial name object
  675. % at the start of the executable array and before patching, we check that
  676. % first element, and if it is that name, we skip the patching
  677. currentuserparams /ProcessDSCComment .knownget
  678. {
  679. dup type /arraytype eq
  680. {
  681. 0 get /.pdf_hook_DSC_Creator eq
  682. { //false } { //true } ifelse
  683. } { //true } ifelse
  684. } { //true } ifelse
  685. {
  686. currentglobal //true setglobal
  687. 2 dict dup .initialize_dsc_parser readonly
  688. currentuserparams /ProcessDSCComment get
  689. 1 array astore % in case the value is executable
  690. /.pdf_hook_DSC_Creator /pop load 4 2 roll //.pdfdsc /exec load 6 array astore cvx readonly
  691. << /ProcessDSCComment 3 -1 roll >> setuserparams
  692. setglobal
  693. } if
  694. } .internalbind .schedule_init
  695. } if
  696. % ---------------- {set,current}distillerparams ---------------- %
  697. % Define setdistillerparams / currentdistillerparams.
  698. % Distiller parameters are currently treated as device parameters.
  699. /.distillerparamkeys mark
  700. % General parameters -- all distillers
  701. /ASCII85EncodePages { }
  702. /AutoRotatePages { }
  703. /Binding { }
  704. /CompressPages { }
  705. /DefaultRenderingIntent { }
  706. /DetectBlends { }
  707. /DoThumbnails { }
  708. /ImageMemory { }
  709. /LockDistillerParams { }
  710. /LZWEncodePages { }
  711. /OPM { }
  712. /PreserveHalftoneInfo { }
  713. /PreserveOPIComments { }
  714. /PreserveOverprintSettings { }
  715. /TransferFunctionInfo { }
  716. /UCRandBGInfo { }
  717. /UseFlateCompression { }
  718. % General parameters -- PDF writer
  719. % StartPage and EndPage are renamed because EndPage
  720. % clashes with a page device parameter.
  721. /CoreDistVersion { }
  722. /CompatibilityLevel { }
  723. % ****** NOTE: StartPage and EndPage are disabled because
  724. % ****** EndPage clashes with a page device parameter.
  725. % /EndPage { exch pop /PDFEndPage exch }
  726. /PDFEndPage { pop pop }
  727. % /StartPage { exch pop /PDFStartPage exch }
  728. /PDFStartPage { pop pop }
  729. /Optimize { }
  730. /ParseDSCCommentsForDocInfo { }
  731. /ParseDSCComments { }
  732. /EmitDSCWarnings { }
  733. /CreateJobTicket { }
  734. /PreserveEPSInfo { }
  735. /AutoPositionEPSFiles { }
  736. /PreserveCopyPage { }
  737. /UsePrologue { }
  738. /OffOptimizations { }
  739. % PDF/X parameters
  740. /PDFXTrimBoxToMediaBoxOffset { }
  741. /PDFXSetBleedBoxToMediaBox { }
  742. /PDFXBleedBoxToTrimBoxOffset { }
  743. % Color sampled image parameters
  744. /ColorACSImageDict { }
  745. /AntiAliasColorImages { }
  746. /AutoFilterColorImages { }
  747. /ColorImageDepth { }
  748. /ColorImageDict { }
  749. /DownsampleColorImages { }
  750. /ColorImageDownsampleThreshold { }
  751. /ColorImageDownsampleType { }
  752. /ColorImageAutoFilterStrategy { }
  753. /EncodeColorImages { }
  754. /ColorImageFilter { }
  755. /ColorImageResolution { }
  756. % Color processing parameters
  757. /CalCMYKProfile { }
  758. /CalGrayProfile { }
  759. /CalRGBProfile { }
  760. /sRGBProfile { }
  761. /ColorConversionStrategy { }
  762. /ConvertCMYKImagesToRGB { }
  763. /ConvertImagesToIndexed { }
  764. % Grayscale sampled image parameters
  765. /GrayACSImageDict { }
  766. /AntiAliasGrayImages { }
  767. /AutoFilterGrayImages { }
  768. /GrayImageDepth { }
  769. /GrayImageDict { }
  770. /DownsampleGrayImages { }
  771. /GrayImageDownsampleThreshold { }
  772. /GrayImageDownsampleType { }
  773. /GrayImageAutoFilterStrategy { }
  774. /EncodeGrayImages { }
  775. /GrayImageFilter { }
  776. /GrayImageResolution { }
  777. % Monochrome sampled image parameters
  778. /AntiAliasMonoImages { }
  779. /MonoImageDepth { }
  780. /MonoImageDict { }
  781. /DownsampleMonoImages { }
  782. /MonoImageDownsampleThreshold { }
  783. /MonoImageDownsampleType { }
  784. /EncodeMonoImages { }
  785. /MonoImageFilter { }
  786. /MonoImageResolution { }
  787. % Font embedding parameters
  788. /AlwaysEmbed
  789. { dup length 0 gt
  790. { dup 0 get type /booleantype eq } { //false } ifelse
  791. { dup 0 get
  792. { dup length 1 sub 1 exch getinterval
  793. }
  794. { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  795. } ifelse
  796. }
  797. { exch pop /.AlwaysEmbed exch
  798. } ifelse
  799. }
  800. /NeverEmbed
  801. { dup length 0 gt
  802. { dup 0 get type /booleantype eq } { //false } ifelse
  803. { dup 0 get
  804. { dup length 1 sub 1 exch getinterval
  805. }
  806. { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  807. } ifelse
  808. }
  809. { exch pop /.NeverEmbed exch
  810. } ifelse
  811. }
  812. /CannotEmbedFontPolicy { }
  813. /EmbedAllFonts { }
  814. /MaxSubsetPct { }
  815. /SubsetFonts { }
  816. /DSCEncodingToUnicode { }
  817. /PassThroughJPEGImages { }
  818. /PassThroughJPXImages { }
  819. /PSDocOptions { }
  820. /PSPageOptions { }
  821. /PSPageOptionsWrap { }
  822. /AlwaysOutline { }
  823. /NeverOutline { }
  824. .dicttomark readonly def
  825. /.distillerdevice
  826. {
  827. % Check to see if the current device is a Distiller
  828. % and return it if so.
  829. /IsDistiller /GetDeviceParam .special_op {
  830. exch pop
  831. }{
  832. //false
  833. }ifelse
  834. { currentdevice }
  835. { /pdfwrite finddevice }
  836. ifelse
  837. } .internalbind def
  838. % Some badly designed PostScript files only expect the current/set
  839. % distillerparams operators to exist in a distiller. Since we have
  840. % this as a runtime option, we enable these operators IFF the
  841. % currentdevice is pdfwrite. Also, we mask their existence in
  842. % systemdict so that 'where' and 'known' don't show them unless
  843. % the currentdevice is pdfwrite.
  844. /.setdistillerparams { % <dict> setdistillerparams -
  845. .distillerdevice //null //false mark 4 index {
  846. //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  847. } forall .putdeviceparamsonly
  848. dup type /booleantype ne {
  849. /setdistillerparams .pdfparamerror
  850. } {
  851. pop pop pop
  852. } ifelse
  853. } odef
  854. /.currentdistillerparams { % - currentdistillerparams <dict>
  855. .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  856. % Patch StartPage and EndPage
  857. % ****** NOTE: StartPage and EndPage are disabled because
  858. % ****** EndPage clashes with a page device parameter.
  859. % begin /StartPage PDFStartPage /EndPage PDFEndPage
  860. % currentdict dup /PDFStartPage undef /PDFEndPage undef
  861. % def def currentdict end
  862. } odef
  863. /setdistillerparams {
  864. % Check to see if the current device is a Distiller
  865. /IsDistiller /GetDeviceParam .special_op {
  866. exch pop not
  867. }{
  868. //true
  869. }ifelse
  870. {
  871. /setdistillerparams cvx /undefined signalerror
  872. } if
  873. .setdistillerparams
  874. } .internalbind odef
  875. /currentdistillerparams {
  876. % Check to see if the current device is a Distiller
  877. /IsDistiller /GetDeviceParam .special_op {
  878. exch pop not
  879. }{
  880. //true
  881. }ifelse
  882. {
  883. /currentdistillerparams cvx /undefined signalerror
  884. } if
  885. .currentdistillerparams
  886. } .internalbind odef
  887. % Patch 'where' so that the distiller operators are only visible
  888. % if the pdfwrite device is the current one.
  889. {
  890. % Check to see if the current device is a Distiller
  891. /IsDistiller /GetDeviceParam .special_op {
  892. exch pop
  893. }{
  894. //false
  895. }ifelse
  896. {
  897. .where
  898. } {
  899. .where pop dup //systemdict eq { pop //false } { //true } ifelse
  900. } ifelse
  901. } .internalbind
  902. { /currentdistillerparams /setdistillerparams /pdfmark }
  903. { .wheredict exch 2 index put } forall pop
  904. % Patch 'known' to hide the systemdict version of distiller operators
  905. % unless the currentdevice is pdfwrite.
  906. /known {
  907. /currentdistillerparams 1 index eq /setdistillerparams 2 index eq or
  908. /pdfmark 2 index eq or {
  909. systemdict 2 index eq { % only mask the operator in systemdict
  910. known
  911. % Check to see if the current device is a Distiller
  912. /IsDistiller /GetDeviceParam .special_op {
  913. exch pop not
  914. }{
  915. //true
  916. }ifelse
  917. { pop //false } if
  918. } {
  919. known
  920. } ifelse
  921. } {
  922. known
  923. } ifelse
  924. } .forcebind odef
  925. % Create a table for translation DSC comments into Unicode UTF-16
  926. /.make_DSC_translation_table { % <encoding> .make_DSC_translation_table <array>
  927. dup type /stringtype eq {
  928. cvn
  929. } if
  930. dup type /nametype eq {
  931. /Encoding findresource
  932. } if
  933. dup length array exch % [out] [in]
  934. 0 1 2 index length 1 sub { % [out] [in] i
  935. dup 2 index exch get % [out] [in] i n
  936. dup dup //null eq exch /.notdef eq or {
  937. pop -1
  938. } {
  939. dup //AdobeGlyphList exch .knownget { % [out] [in] i n c
  940. dup type dup /arraytype eq exch /packedarraytype eq or {
  941. 0 get % fixme: using the 1st char
  942. } if
  943. exch pop % [out] [in] i c
  944. } { % [out] [in] i n
  945. (DSCEncoding defines a character that is not in AdobeGlyphList : )
  946. exch .namestring concatstrings =
  947. /.make_DSC_translation_table cvx /undefined signalerror
  948. } ifelse
  949. } ifelse
  950. 3 index % [out] [in] i c [out]
  951. 3 1 roll put % [out] [in]
  952. } for
  953. pop % [out]
  954. } .internalbind def
  955. 1000 % priority
  956. {
  957. % Note, this may not work if the initial device is not pdfwrite
  958. % and may require the use of -dProvideUnicode on the command line.
  959. % Check to see if the current device wants ToUnicode info
  960. /WantsToUnicode /GetDeviceParam .special_op {
  961. exch pop
  962. }{
  963. //false
  964. }ifelse
  965. systemdict /ProvideUnicode .knownget not { //false } if or
  966. {
  967. currentglobal //true setglobal
  968. /Unicode /Decoding resourcestatus {
  969. pop pop
  970. /Unicode /Decoding findresource
  971. .setupUnicodeDecoder
  972. } {
  973. QUIET not {
  974. (WARNING: /Unicode /Decoding resource is not accessible but it is useful for generating ToUnicode CMap.) =
  975. } if
  976. } ifelse
  977. setglobal
  978. } if
  979. } .internalbind .schedule_init
  980. 1010 % priority
  981. {
  982. % Set a predefined configuration in the distiller device (pdfwrite)
  983. /PDFSETTINGS where {
  984. pop /PDFSETTINGS load
  985. } {
  986. % We use the presence of the OPDFRead key as a proxy for a pdfwrite-family device
  987. /ForOPDFRead /GetDeviceParam .special_op {
  988. % Get rid of the OPDFRead key
  989. exch pop
  990. % and then check the value to see if its pdfwrite or ps2write
  991. { /PSL2Printer } { /default } ifelse
  992. } {
  993. /default
  994. } ifelse
  995. } ifelse
  996. .distillersettings exch get
  997. % Don't override parameters defined on the command line.
  998. dup length .distillercommon length add dict begin
  999. .distillercommon 2 {
  1000. {
  1001. systemdict 2 index known { pop pop } { def } ifelse
  1002. } forall
  1003. } repeat
  1004. % We use the presence of the OPDFRead key as a proxy for a pdfwrite-family device
  1005. /ForOPDFRead /GetDeviceParam .special_op {
  1006. % Get rid of the OPDFRead key
  1007. exch pop
  1008. % Then check to see if OPDFRead is true or not
  1009. not {
  1010. systemdict /PDFX known systemdict /PDFA known or {
  1011. /DSCEncoding where {
  1012. /DSCEncoding get .make_DSC_translation_table
  1013. /DSCEncodingToUnicode exch def
  1014. } if
  1015. } if
  1016. } if
  1017. } if
  1018. currentdict end .setdistillerparams
  1019. .distillerdevice //null //false mark .putdeviceparams
  1020. dup type /booleantype eq not { cleartomark pop } if pop pop
  1021. } .internalbind .schedule_init
  1022. 2000 % priority
  1023. { % Note, this may not work if the initial device is not pdfwrite
  1024. % We use the presence of the OPDFRead key as a proxy for a pdfwrite-family device
  1025. /ForOPDFRead /GetDeviceParam .special_op {
  1026. % Get rid of the OPDFRead key and value
  1027. pop pop
  1028. % Inform the device with initial graphic state. See gdev_pdf_fill_path.
  1029. newpath fill
  1030. } if
  1031. } .internalbind .schedule_init
  1032. .setlanguagelevel
  1033. %END PDFWR