home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Actualizar / Impressora_PDF / converter.exe / GPLGS / gs_pdfwr.ps < prev    next >
Text File  |  2004-12-02  |  22KB  |  674 lines

  1. %    Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_pdfwr.ps,v 1.31.2.3 2004/08/11 13:12:24 ray Exp $
  14. % PDF writer additions to systemdict.
  15.  
  16. % This file should be included iff the pdfwrite "device" is included
  17. % in the executable.
  18.  
  19. % ---------------- Predefined configurations ---------------- %
  20.  
  21. % These correspond to the 4 predefined settings in Acrobat Distiller 5,
  22. % plus a "default" setting that doesn't downsample images.
  23.  
  24. /.a2112 [2 1 1 2] readonly def
  25. /.a1111 [1 1 1 1] readonly def
  26. /.standardfonts [
  27.   /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
  28.   /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
  29.   /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
  30.   /Symbol /ZapfDingbats
  31. ] readonly def
  32.  
  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 1
  83.   /Optimize true
  84.   /ParseDSCComments true
  85.   /ParseDSCCommentsForDocInfo true
  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.  
  96. /.distillersettings mark
  97.  
  98. /default mark
  99.   /AutoRotatePages /PageByPage
  100.   /CannotEmbedFontPolicy /Warning
  101.   /ColorACSImageDict .defaultImageDict
  102.   /ColorConversionStrategy /LeaveColorUnchanged
  103. %  /ColorImageDownsampleType
  104. %  /ColorImageResolution
  105. %  /CompatibilityLevel
  106.   /CreateJobTicket false
  107.   /DoThumbnails false
  108.   /DownsampleColorImages false        % override
  109.   /DownsampleGrayImages false        % override
  110.   /DownsampleMonoImages false        % override
  111.   /EmbedAllFonts true
  112.   /GrayACSImageDict .defaultImageDict
  113. %  /GrayImageDownsampleType
  114. %  /GrayImageResolution
  115. %  /MonoImageDownsampleType
  116. %  /MonoImageResolution
  117.   /NeverEmbed .standardfonts
  118.   /Optimize false            % override
  119.   /PreserveEPSInfo true
  120.   /PreserveOPIComments true
  121.   /PreserveOverprintSettings true
  122.   /UCRandBGInfo /Preserve
  123. .dicttomark readonly
  124.  
  125. /.screenACSImageDict mark
  126.   /QFactor 0.76 /Blend 1 /ColorTransform 1
  127.   /HSamples .a2112 /VSamples .a2112
  128. .dicttomark readonly def
  129. /screen mark
  130.   /AutoRotatePages /PageByPage
  131. %  /CalGrayProfile (None)
  132.   /CannotEmbedFontPolicy /Warning
  133.   /ColorACSImageDict .screenACSImageDict
  134.   /ColorConversionStrategy /sRGB
  135.   /ColorImageDownsampleType /Average
  136.   /ColorImageResolution 72
  137.   /CompatibilityLevel 1.2
  138.   /CreateJobTicket false
  139.   /DoThumbnails false
  140.   /EmbedAllFonts true
  141.   /GrayACSImageDict .screenACSImageDict
  142.   /GrayImageDownsampleType /Average
  143.   /GrayImageResolution 72
  144.   /MonoImageDownsampleType /Average
  145.   /MonoImageResolution 300
  146.   /NeverEmbed .standardfonts
  147.   /PreserveEPSInfo false
  148.   /PreserveOPIComments false
  149.   /PreserveOverprintSettings false
  150.   /UCRandBGInfo /Remove
  151. .dicttomark readonly
  152.  
  153. /ebook mark
  154.   /AutoRotatePages /All
  155. %  /CalGrayProfile (None)
  156.   /CannotEmbedFontPolicy /Warning
  157.   /ColorACSImageDict .screenACSImageDict
  158.   /ColorConversionStrategy /sRGB
  159.   /ColorImageDownsampleType /Bicubic
  160.   /ColorImageResolution 150
  161.   /CompatibilityLevel 1.3
  162.   /CreateJobTicket false
  163.   /DoThumbnails false
  164.   /EmbedAllFonts true
  165.   /GrayACSImageDict .screenACSImageDict
  166.   /GrayImageDownsampleType /Bicubic
  167.   /GrayImageResolution 150
  168.   /MonoImageDownsampleType /Bicubic
  169.   /MonoImageResolution 300
  170.   /NeverEmbed .standardfonts
  171.   /PreserveEPSInfo false
  172.   /PreserveOPIComments false
  173.   /PreserveOverprintSettings false
  174.   /UCRandBGInfo /Remove
  175. .dicttomark readonly
  176.  
  177. /.printerACSImageDict mark
  178.   /QFactor 0.4 /Blend 1 /ColorTransform 1
  179.   /HSamples .a1111 /VSamples .a1111
  180. .dicttomark readonly def
  181. /printer mark
  182.   /AutoRotatePages /PageByPage
  183. %  /CalGrayProfile (None)
  184.   /CannotEmbedFontPolicy /Warning
  185.   /ColorACSImageDict .printerACSImageDict
  186.   /ColorConversionStrategy /UseDeviceIndependentColor
  187.   /ColorImageDownsampleType /Bicubic
  188.   /ColorImageResolution 300
  189.   /CompatibilityLevel 1.3
  190.   /CreateJobTicket true
  191.   /DoThumbnails false
  192.   /EmbedAllFonts true
  193.   /GrayACSImageDict .printerACSImageDict
  194.   /GrayImageDownsampleType /Bicubic
  195.   /GrayImageResolution 300
  196.   /MonoImageDownsampleType /Bicubic
  197.   /MonoImageResolution 1200
  198.   /NeverEmbed []
  199.   /PreserveEPSInfo true
  200.   /PreserveOPIComments true
  201.   /PreserveOverprintSettings true
  202.   /UCRandBGInfo /Preserve
  203. .dicttomark readonly
  204.  
  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 /PageByPage
  211.   /CannotEmbedFontPolicy /Error
  212.   /ColorACSImageDict .prepressACSImageDict
  213.   /ColorConversionStrategy /LeaveColorUnchanged
  214.   /ColorImageDownsampleType /Bicubic
  215.   /ColorImageResolution 300
  216.   /CompatibilityLevel 1.3
  217.   /CreateJobTicket true
  218.   /DoThumbnails true
  219.   /EmbedAllFonts true
  220.   /GrayACSImageDict .prepressACSImageDict
  221.   /GrayImageDownsampleType /Bicubic
  222.   /GrayImageResolution 300
  223.   /MonoImageDownsampleType /Bicubic
  224.   /MonoImageResolution 1200
  225.   /NeverEmbed []
  226.   /PreserveEPSInfo true
  227.   /PreserveOPIComments true
  228.   /PreserveOverprintSettings true
  229.   /UCRandBGInfo /Preserve
  230. .dicttomark readonly
  231.  
  232. .dicttomark readonly def
  233.  
  234. % ---------------- End of predefined configurations ---------------- %
  235.  
  236. % Set optimizations for converting PostScript to PDF.
  237. % The ps2pdf* scripts invoke this.
  238. /.setpdfwrite {        % - .setpdfwrite -
  239.         % Set a large VM threshold to reduce garbage collection.
  240.   currentuserparams /VMThreshold get 3000000 .max setvmthreshold
  241. } bind def
  242.  
  243. % ---------------- pdfmark and DSC processing ---------------- %
  244.  
  245. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  246. /.pdf===dict mark
  247.   /arraytype
  248.    { dup xcheck { ({) (}) } { ([) (]) } ifelse
  249.         % Stack: file obj left right
  250.       4 1 roll 2 index exch writestring () exch
  251.        { exch 2 index exch writestring
  252.      1 index exch pdf===only ( )
  253.        }
  254.       forall pop exch writestring
  255.    } bind
  256.   /packedarraytype 1 index
  257.   /dicttype
  258.    { 1 index (<<\n) writestring
  259.       { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  260.     1 index exch pdf===only dup (\n) writestring
  261.       }
  262.      forall (>>) writestring
  263.    } bind
  264.   /nametype {
  265.     % If the name string includes any non-regular characters,
  266.     % write it with two preceding and one following null character(s).
  267.     % (Null characters in the name itself are not allowed.)
  268.     % This non-standard escape convention is required for passing names
  269.     % that include non-regular characters, because PostScript provides
  270.     % no way to do this.  The pdf_scan_token procedure in the C code of
  271.     % the pdfwrite driver is currently the only place that recognizes
  272.     % this convention.
  273.     dup .namestring (\000\011\012\014\015 %()/<>[]{}) .stringbreak null ne {
  274.       dup .namestring (\000) .stringbreak null ne {
  275.     /rangecheck signalerror
  276.       } if
  277.       1 index <0000> writestring 1 index exch write===only 0 write
  278.     } {
  279.       write===only
  280.     } ifelse
  281.   } bind
  282. .dicttomark readonly def
  283. /pdf===only {    % <file> <obj> pdf===only -
  284.   .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  285. } bind def
  286. /.pdfcvbuf 30 string def    % enough for most arguments
  287. userdict /.pdfcvstring () put
  288. /.pdfcvs {        % <obj> .pdfcvs <string>
  289.   currentglobal exch false .setglobal
  290.   /.pdfcvstring () store
  291.         % We can't handle long values yet.
  292.   { pop dup length 0 eq { pop } {
  293.       /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  294.     } ifelse //.pdfcvbuf
  295.   } /NullEncode filter dup 3 -1 roll pdf===only
  296.   closefile
  297.   .setglobal .pdfcvstring
  298. } bind def
  299.  
  300. % Redefine pdfmark to pass the data to the driver.
  301. % We use a pseudo-parameter named /pdfmark whose value is an array:
  302. %    /key1 (value1) ... (CTM) /type
  303. /.pdfputparams {    % -mark- <key1> <value1> ... .pdfputparams <result...>
  304.   currentdevice null false counttomark 1 add 3 roll
  305.         % Don't allow the page device to get cleared....
  306.   {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  307. } bind def
  308. % Convert relevant operands to strings in an array.
  309. /.pdfcvsloop {        % -mark- values ... markname start step .pdfcvsloop
  310.             %   [values ... ctm markname]
  311.    matrix currentmatrix .pdfcvs 4 1 roll
  312.    counttomark 1 add 2 roll 
  313.    counttomark .localvmarray astore exch pop
  314.    3 1 roll
  315.             % Stack: values start step
  316.    2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  317. } bind def
  318. /.pdfcvsall {        % -mark- values ... markname .pdfcvsall <<same>>
  319.   0 1 .pdfcvsloop
  320. } bind def
  321. /.pdfcvseven {        % -mark- key value ... markname .pdfcvseven <<same>>
  322.   1 2 .pdfcvsloop
  323. } bind def
  324. /.pdfcvsnone {        % -mark- values ... markname .pdfcvsnone <<same>>
  325.   100000 1 .pdfcvsloop
  326. } bind def
  327. /.pdfcvsfirst {        % -mark- first values ... markname .pdfcvsfirst<<same>>
  328.   .pdfcvsnone
  329.   dup 0 2 copy get .pdfcvs put
  330. } bind def
  331. % The procedures in the following dictionary are called with the entire
  332. % pdfmark operand list (including the pdfmark name) on the stack;
  333. % they may modify this ad lib.  They must call .pdfcvsxxx.
  334. /.pdfmarkparams mark
  335.     % Unpack a dictionary for PUT, and don't convert stream data.
  336.   /PUT {
  337.     counttomark 3 eq {
  338.       1 index type /dicttype eq {
  339.     pop { } forall /.PUTDICT .pdfcvsall
  340.       } {
  341.     pop dup type /filetype eq {
  342.         % Read the file into a sequence of strings.
  343.         % This isn't great, but it's simple.
  344.       {
  345.         dup 64000 string readstring not { exch exit } if
  346.         exch
  347.       } loop closefile
  348.     } if
  349.     /.PUTSTREAM .pdfcvsfirst
  350.       } ifelse
  351.     } {
  352.       .pdfcvsall
  353.     } ifelse
  354.   } bind
  355.     % Unpack the array for PUTINTERVAL.
  356.   /PUTINTERVAL {
  357.     pop aload pop /.PUTINTERVAL .pdfcvsall
  358.   } bind
  359. .dicttomark readonly def
  360. /.pdfparamerror {    % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  361.     counttomark 4 add 2 roll cleartomark pop pop pop
  362.     .systemvar exch signalerror
  363. } bind def
  364. /pdfmark {        % -mark- <key> <value> ... <markname> pdfmark -
  365.   counttomark 1 add copy
  366.   //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  367.   mark /pdfmark 3 -1 roll .pdfputparams
  368.   dup type /booleantype ne {
  369.     /pdfmark .pdfparamerror
  370.   } if cleartomark
  371. } odef
  372. userdict /pdfmark .undef
  373. currentdict /.pdfmarkparams .undef
  374.  
  375.  
  376. %    <dict> .hook_DSC_Creator -
  377. /.pdf_hook_DSC_Creator
  378. {
  379.   % If the Creator is PScript5.dll, disable the 32 /FontType resource for
  380.   % handling GlyphNames2Unicode. Since /FontType category can't redefine,
  381.   % we can do only with redefining the operator 'resourcestatus'.
  382.   currentdevice .devicename /pdfwrite eq {
  383.     /Creator .knownget {
  384.       (PScript5.dll) search {
  385.         pop pop
  386.         systemdict /resourcestatus dup
  387.         { dup /FontType eq 2 index 32 eq and {
  388.             pop pop false
  389.           } {
  390.             resourcestatus
  391.           } ifelse
  392.         } bind .makeoperator .forceput
  393.       } if
  394.       pop
  395.     } if
  396.   } {
  397.     pop
  398.   } ifelse
  399. bind def
  400.  
  401. % Use the DSC processing hook to pass DSC comments to the driver.
  402. % We use a pseudo-parameter named DSC whose value is an array:
  403. %    /key1 (value1) ... /type
  404. /.pdfdsc_dict 2 dict def
  405. /.pdfdsc {    % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  406.   0 get dup null ne { 4 copy exch pop exec pop } { pop } ifelse 3 -1 roll pop
  407.         % Stack: <dsc string> <dsc dict>
  408.   20 .localvmdict 1 index { 3 copy put pop pop } forall
  409.   3 -1 roll .parse_dsc_comments    % <dsc dict> <dict> <type>
  410.   1 index //.pdf_hook_DSC_Creator exec
  411.   dup /NOP ne 2 index length 1 gt or {    % Skip unparsed comments
  412.     PDFWRDEBUG { (**** DSC comment: ) print dup == 1 index === flush } if
  413.     exch mark 4 1 roll {
  414.         % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  415.       3 index 2 index known {    % Skip the DSC_struct entry
  416.         pop pop
  417.       } {
  418.         .pdfcvs 4 -2 roll
  419.       } ifelse
  420.     } forall exch pop counttomark .localvmarray astore
  421.     mark /DSC 3 -1 roll .pdfputparams
  422.     dup type /booleantype ne {
  423.       /DSC .pdfparamerror
  424.     } {
  425.       cleartomark
  426.     } ifelse
  427.   } {
  428.     pop pop pop
  429.   } ifelse
  430. } bind def
  431. currentdict /.pdf_hook_DSC_Creator undef
  432. /.initialize_dsc_parser where {
  433.   pop
  434.   3000 % priority 
  435.   {
  436.     currentglobal true setglobal
  437.     2 dict dup .initialize_dsc_parser readonly
  438.     currentuserparams /ProcessDSCComment get
  439.     1 array astore    % in case the value is executable
  440.     //.pdfdsc /exec load 4 array astore cvx readonly
  441.     << /ProcessDSCComment 3 -1 roll >> setuserparams
  442.     setglobal
  443.   } bind .schedule_init
  444. } if
  445.  
  446. % ---------------- {set,current}distillerparams ---------------- %
  447.  
  448. % Define setdistillerparams / currentdistillerparams.
  449. % Distiller parameters are currently treated as device parameters.
  450. /.distillerparamkeys mark
  451.         % General parameters -- all distillers
  452.   /ASCII85EncodePages { }
  453.   /AutoRotatePages { }
  454.   /Binding { }
  455.   /CompressPages { }
  456.   /DefaultRenderingIntent { }
  457.   /DetectBlends { }
  458.   /DoThumbnails { }
  459.   /ImageMemory { }
  460.   /LockDistillerParams { }
  461.   /LZWEncodePages { }
  462.   /OPM { }
  463.   /PreserveHalftoneInfo { }
  464.   /PreserveOPIComments { }
  465.   /PreserveOverprintSettings { }
  466.   /TransferFunctionInfo { }
  467.   /UCRandBGInfo { }
  468.   /UseFlateCompression { }
  469.         % General parameters -- PDF writer
  470.         % StartPage and EndPage are renamed because EndPage
  471.         % clashes with a page device parameter.
  472.   /CoreDistVersion { }
  473.   /CompatibilityLevel { }
  474.         % ****** NOTE: StartPage and EndPage are disabled because
  475.         % ****** EndPage clashes with a page device parameter.
  476. %  /EndPage { exch pop /PDFEndPage exch }
  477.     /PDFEndPage { pop pop }
  478. %  /StartPage { exch pop /PDFStartPage exch }
  479.     /PDFStartPage { pop pop }
  480.   /Optimize { }
  481.   /ParseDSCCommentsForDocInfo { }
  482.   /ParseDSCComments { }
  483.   /EmitDSCWarnings { }
  484.   /CreateJobTicket { }
  485.   /PreserveEPSInfo { }
  486.   /AutoPositionEPSFiles { }
  487.   /PreserveCopyPage { }
  488.   /UsePrologue { }
  489.   /OffOptimizations { }
  490.         % Color sampled image parameters
  491.   /ColorACSImageDict { }
  492.   /AntiAliasColorImages { }
  493.   /AutoFilterColorImages { }
  494.   /ColorImageDepth { }
  495.   /ColorImageDict { }
  496.   /DownsampleColorImages { }
  497.   /ColorImageDownsampleThreshold { }
  498.   /ColorImageDownsampleType { }
  499.   /EncodeColorImages { }
  500.   /ColorImageFilter { }
  501.   /ColorImageResolution { }
  502.         % Color processing parameters
  503.   /CalCMYKProfile { }
  504.   /CalGrayProfile { }
  505.   /CalRGBProfile { }
  506.   /sRGBProfile { }
  507.   /ColorConversionStrategy { }
  508.   /ConvertCMYKImagesToRGB { }
  509.   /ConvertImagesToIndexed { }
  510.         % Grayscale sampled image parameters
  511.   /GrayACSImageDict { }
  512.   /AntiAliasGrayImages { }
  513.   /AutoFilterGrayImages { }
  514.   /GrayImageDepth { }
  515.   /GrayImageDict { }
  516.   /DownsampleGrayImages { }
  517.   /GrayImageDownsampleThreshold { }
  518.   /GrayImageDownsampleType { }
  519.   /EncodeGrayImages { }
  520.   /GrayImageFilter { }
  521.   /GrayImageResolution { }
  522.         % Monochrome sampled image parameters
  523.   /AntiAliasMonoImages { }
  524.   /MonoImageDepth { }
  525.   /MonoImageDict { }
  526.   /DownsampleMonoImages { }
  527.   /MonoImageDownsampleThreshold { }
  528.   /MonoImageDownsampleType { }
  529.   /EncodeMonoImages { }
  530.   /MonoImageFilter { }
  531.   /MonoImageResolution { }
  532.         % Font embedding parameters
  533.   /AlwaysEmbed
  534.    { dup length 0 gt
  535.       { dup 0 get false eq
  536.          { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  537.          } if
  538.       } if
  539.    }
  540.   /NeverEmbed
  541.    { dup length 0 gt
  542.       { dup 0 get false eq
  543.          { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  544.          } if
  545.       } if
  546.    }
  547.   /CannotEmbedFontPolicy { }
  548.   /EmbedAllFonts { }
  549.   /MaxSubsetPct { }
  550.   /SubsetFonts { }
  551. .dicttomark readonly def
  552. /.distillerdevice
  553.  { currentdevice .devicename /pdfwrite eq
  554.     { currentdevice }
  555.     { /pdfwrite finddevice }
  556.    ifelse
  557.  } bind def
  558.  
  559. % Some badly designed PostScript files only expect the current/set
  560. % distillerparams operators to exist in a distiller. Since we have
  561. % this as a runtime option, we enable these operators IFF the
  562. % currentdevice is pdfwrite. Also, we mask their existence in 
  563. % systemdict so that 'where' and 'known' don't show them unless
  564. % the currentdevice is pdfwrite.
  565. /.setdistillerparams {        % <dict> setdistillerparams -
  566.   .distillerdevice //null false mark 4 index {
  567.     //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  568.   } forall .putdeviceparamsonly
  569.   dup type /booleantype ne {
  570.     /setdistillerparams .pdfparamerror
  571.   } {
  572.     pop pop pop
  573.   } ifelse
  574. } odef
  575. /.currentdistillerparams {    % - currentdistillerparams <dict>
  576.   .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  577.         % Patch StartPage and EndPage
  578.         % ****** NOTE: StartPage and EndPage are disabled because
  579.         % ****** EndPage clashes with a page device parameter.
  580. %  begin /StartPage PDFStartPage /EndPage PDFEndPage
  581. %  currentdict dup /PDFStartPage undef /PDFEndPage undef
  582. %  def def currentdict end
  583. } odef
  584. /setdistillerparams {
  585.   currentdevice .devicename /pdfwrite ne {
  586.     /setdistillerparams /undefined signalerror
  587.   } if
  588.   .setdistillerparams
  589. } bind odef
  590. /currentdistillerparams {
  591.   currentdevice .devicename /pdfwrite ne {
  592.     /currentdistillerparams /undefined signalerror
  593.   } if
  594.   .currentdistillerparams
  595. } bind odef
  596.  
  597. % Patch 'where' so that the distiller operators are only visible
  598. % if the pdfwrite device is the current one.
  599. { currentdevice .devicename /pdfwrite eq {
  600.     .where
  601.   } {
  602.     .where pop dup //systemdict eq { pop false } { true } ifelse
  603.   } ifelse
  604. } bind
  605. { /currentdistillerparams /setdistillerparams /pdfmark }
  606. { .wheredict exch 2 index put } forall pop
  607.  
  608. % Patch 'known' to hide the systemdict version of distiller operators
  609. % unless the currentdevice is pdfwrite.
  610. /known {
  611.   /currentdistillerparams 1 index eq /setdistillerparams 2 index eq or 
  612.   /pdfmark 2 index eq or {
  613.     systemdict 2 index eq {    % only mask the operator in systemdict
  614.       known currentdevice .devicename /pdfwrite ne { pop false } if
  615.   } {
  616.     known
  617.   } ifelse
  618.   } {
  619.     known
  620.   } ifelse
  621. } .bind odef
  622.  
  623. 1000 % priority
  624. {
  625.   % Note, this may not work if the initial device is not pdfwrite
  626.   % and may require the use of -dProvideUnicode on the command line.
  627.   currentdevice .devicename /pdfwrite eq
  628.   systemdict /ProvideUnicode .knownget not { false } if or {
  629.     currentglobal true setglobal
  630.     systemdict /.setupUnicodeDecoder known {
  631.       /Unicode /Decoding resourcestatus {
  632.         pop pop
  633.         /Unicode /Decoding findresource
  634.         .setupUnicodeDecoder
  635.       } {
  636.         QUIET not {
  637.           (WARNING: /Unicode /Decoding resource is not accessible but it is useful for generating ToUnicode CMap.) =
  638.         } if
  639.       } ifelse
  640.     } if
  641.     setglobal
  642.   } if
  643. } bind .schedule_init
  644.  
  645. 1010 % priority
  646. {
  647.     % Set a predefined configuration in the distiller device (pdfwrite)
  648.     /PDFSETTINGS where { pop /PDFSETTINGS load } { /default } ifelse
  649.     .distillersettings exch get
  650.     % Don't override parameters defined on the command line.
  651.     dup length .distillercommon length add dict begin
  652.     .distillercommon 2 {
  653.       {
  654.         systemdict 2 index known { pop pop } { def } ifelse
  655.       } forall
  656.     } repeat
  657.     currentdict end .setdistillerparams
  658.     .distillerdevice //null false mark .putdeviceparams 
  659.     dup type /booleantype eq not { cleartomark pop } if pop pop
  660. } bind .schedule_init
  661.  
  662. 2000 % priority
  663. { % Note, this may not work if the initial device is not pdfwrite
  664.   currentdevice .devicename /pdfwrite eq {
  665.     % Inform the device with initial graphic state. See gdev_pdf_fill_path.
  666.     newpath fill
  667.   } if
  668. } bind .schedule_init
  669.  
  670.