home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / Chip_2002-10_cd1.bin / zkuste / pdf / download / gs704w32.exe / gs7.04 / lib / gs_pdfwr.ps < prev    next >
Encoding:
Text File  |  2002-01-31  |  15.7 KB  |  497 lines

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