home *** CD-ROM | disk | FTP | other *** search
/ Mixa 155: Dogs / MIXA 155: Dogs.iso / pc / Viewer / BROWSER(W) / フィルタ / PDF / LIB / gs_pdfwr.ps < prev    next >
Encoding:
Text File  |  2002-10-29  |  15.0 KB  |  483 lines

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