home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2003 #12 / K-CD-12-2003.ISO / pdf995 / res / convert / gs_pdfwr.ps < prev    next >
Encoding:
Text File  |  2002-05-20  |  15.6 KB  |  496 lines

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