星火微课系统客户端
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.

gs_pdfwr.ps 27KB

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