home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gs_pdfwr.ps < prev    next >
Text File  |  2000-03-29  |  8KB  |  263 lines

  1. %    Copyright (C) 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Aladdin Ghostscript.
  4. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  5. % or distributor accepts any responsibility for the consequences of using it,
  6. % or for whether it serves any particular purpose or works at all, unless he
  7. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  8. % License (the "License") for full details.
  9. % Every copy of Aladdin Ghostscript must include a copy of the License,
  10. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  11. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  12. % under certain conditions described in the License.  Among other things, the
  13. % License requires that the copyright notice and this notice be preserved on
  14. % all copies.
  15.  
  16. % $Id: gs_pdfwr.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  17. % PDF writer additions to systemdict.
  18.  
  19. % This file should be included iff the pdfwrite "device" is included
  20. % in the executable.
  21.  
  22. % Redefine pdfmark to pass the data to the driver.
  23. % We use a pseudo-parameter named /pdfmark whose value is an array:
  24. %    key1 value1 ... CTM /type
  25. /.pdf===dict mark
  26.   /arraytype
  27.    { dup xcheck { ({) (}) } { ([) (]) } ifelse
  28.         % Stack: file obj left right
  29.       4 1 roll 2 index exch writestring () exch
  30.        { exch 2 index exch writestring
  31.      1 index exch pdfmark===only ( )
  32.        }
  33.       forall pop exch writestring
  34.    } bind
  35.   /packedarraytype 1 index
  36.   /dicttype
  37.    { 1 index (<<\n) writestring
  38.       { 2 index 3 -1 roll pdfmark===only 1 index ( ) writestring
  39.     1 index exch pdfmark===only dup (\n) writestring
  40.       }
  41.      forall (>>) writestring
  42.    } bind
  43. .dicttomark readonly def
  44. /pdfmark===only {    % <file> <obj> pdfmark===only -
  45.   .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  46. } bind def
  47. /.pdfcvbuf 10 string def    % enough for most arguments
  48. userdict /.pdfcvstring () put
  49. /.pdfcvs {        % <obj> .pdfcvs <string>
  50.   currentglobal exch false .setglobal
  51.   /.pdfcvstring () store
  52.         % We can't handle long values yet.
  53.   { pop dup length 0 eq { pop } {
  54.       /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  55.     } ifelse //.pdfcvbuf
  56.   } /NullEncode filter dup 3 -1 roll pdfmark===only
  57.   closefile
  58.   .setglobal .pdfcvstring
  59. } bind def
  60. /.pdfputparams {    % -mark- <key1> <value1> ... .pdfputparams <result...>
  61.   currentdevice null false counttomark 1 add 3 roll
  62.         % Don't allow the page device to get cleared....
  63.   {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  64. } bind def
  65. % Convert relevant operands to strings in an array.
  66. /.pdfcvsloop {        % -mark- values ... markname start step .pdfcvsloop
  67.             %   [values ... ctm markname]
  68.    matrix currentmatrix .pdfcvs 4 1 roll
  69.    counttomark 1 add 2 roll ] 3 1 roll
  70.             % Stack: values start step
  71.    2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  72. } bind def
  73. /.pdfcvsall {        % -mark- values ... markname .pdfcvsall <<same>>
  74.   0 1 .pdfcvsloop
  75. } bind def
  76. /.pdfcvseven {        % -mark- key value ... markname .pdfcvseven <<same>>
  77.   1 2 .pdfcvsloop
  78. } bind def
  79. /.pdfcvsnone {        % -mark- values ... markname .pdfcvsnone <<same>>
  80.   100000 1 .pdfcvsloop
  81. } bind def
  82. /.pdfcvsfirst {        % -mark- first values ... markname .pdfcvsfirst<<same>>
  83.   .pdfcvsnone
  84.   dup 0 2 copy get .pdfcvs put
  85. } bind def
  86. % The procedures in the following dictionary are called with the entire
  87. % pdfmark operand list (including the pdfmark name) on the stack;
  88. % they may modify this ad lib.  They must call .pdfcvsxxx.
  89. /.pdfmarkparams mark
  90.     % Unpack a dictionary for PUT, and don't convert stream data.
  91.   /PUT {
  92.     counttomark 3 eq {
  93.       1 index type /dicttype eq {
  94.     pop { } forall /.PUTDICT .pdfcvsall
  95.       } {
  96.     pop dup type /filetype eq {
  97.         % Read the file into a sequence of strings.
  98.         % This isn't great, but it's simple.
  99.       {
  100.         dup 1000 string readstring not { exch exit } if
  101.         exch
  102.       } loop closefile
  103.     } if
  104.     /.PUTSTREAM .pdfcvsfirst
  105.       } ifelse
  106.     } {
  107.       .pdfcvsall
  108.     } ifelse
  109.   } bind
  110.     % Unpack the array for PUTINTERVAL.
  111.   /PUTINTERVAL {
  112.     pop aload pop /.PUTINTERVAL .pdfcvsall
  113.   } bind
  114. .dicttomark readonly def
  115. /.pdfparamerror {    % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  116.     counttomark 4 add 2 roll cleartomark pop pop pop
  117.     .systemvar exch signalerror
  118. } bind def
  119. /pdfmark {        % -mark- <key> <value> ... <markname> pdfmark -
  120.   counttomark 1 add copy
  121.   //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  122.   mark /pdfmark 3 -1 roll .pdfputparams
  123.   dup type /booleantype ne {
  124.     /pdfmark .pdfparamerror
  125.   } if cleartomark
  126. } odef
  127. userdict /pdfmark .undef
  128. currentdict /.pdfmarkparams .undef
  129.  
  130. % Define setdistillerparams / currentdistillerparams.
  131. % Distiller parameters are currently treated as device parameters.
  132. /.distillerparamkeys mark
  133.         % General parameters -- all distillers
  134.         % ****** NOTE: StartPage and EndPage are disabled because
  135.         % ****** EndPage clashes with a page device parameter.
  136.   /ASCII85EncodePages { }
  137.   /AutoRotatePages { }
  138.   /Binding { }
  139.   /CompressPages { }
  140.   /DefaultRenderingIntent { }
  141.   /DetectBlends { }
  142.   /DoThumbnails { }
  143. %  /EndPage { }
  144.   /ImageMemory { }
  145.   /LockDistillerParams { }
  146.   /LZWEncodePages { }
  147.   /OPM { }
  148.   /PreserveHalftoneInfo { }
  149.   /PreserveOPIComments { }
  150.   /PreserveOverprintSettings { }
  151. %  /StartPage { }
  152.   /TransferFunctionInfo { }
  153.   /UCRandBGInfo { }
  154.   /UseFlateCompression { }
  155.         % General parameters -- PDF writer
  156.   /CoreDistVersion { }
  157.   /CompatibilityLevel { }
  158.   /Optimize { }
  159.   /ParseDSCCommentsForDocInfo { }
  160.   /ParseDSCComments { }
  161.   /EmitDSCWarnings { }
  162.   /CreateJobTicket { }
  163.   /PreserveEPSInfo { }
  164.   /AutoPositionEPSFile { }
  165.   /PreserveCopyPage { }
  166.   /UsePrologue { }
  167.         % Color sampled image parameters
  168.   /ColorACSDict { }
  169.   /AntiAliasColorImages { }
  170.   /AutoFilterColorImages { }
  171.   /ColorImageDepth { }
  172.   /ColorImageDict { }
  173.   /DownsampleColorImages { }
  174.   /ColorImageDownsampleThreshold { }
  175.   /ColorImageDownsampleType { }
  176.   /EncodeColorImages { }
  177.   /ColorImageFilter { }
  178.   /ColorImageResolution { }
  179.         % Color processing parameters
  180.   /CalCMYKProfile { }
  181.   /CalGrayProfile { }
  182.   /CalRGBProfile { }
  183.   /sRGBProfile { }
  184.   /ColorConversionStrategy { }
  185.   /ConvertCMYKImagesToRGB { }
  186.   /ConvertImagesToIndexed { }
  187.         % Grayscale sampled image parameters
  188.   /GrayACSDict { }
  189.   /AntiAliasGrayImages { }
  190.   /AutoFilterGrayImages { }
  191.   /GrayImageDepth { }
  192.   /GrayImageDict { }
  193.   /DownsampleGrayImages { }
  194.   /GrayImageDownsampleThreshold { }
  195.   /GrayImageDownsampleType { }
  196.   /EncodeGrayImages { }
  197.   /GrayImageFilter { }
  198.   /GrayImageResolution { }
  199.         % Monochrome sampled image parameters
  200.   /AntiAliasMonoImages { }
  201.   /MonoImageDepth { }
  202.   /MonoImageDict { }
  203.   /DownsampleMonoImages { }
  204.   /MonoImageDownsampleThreshold { }
  205.   /MonoImageDownsampleType { }
  206.   /EncodeMonoImages { }
  207.   /MonoImageFilter { }
  208.   /MonoImageResolution { }
  209.         % Font embedding parameters
  210.   /AlwaysEmbed
  211.    { dup length 0 gt
  212.       { dup 0 get false eq
  213.          { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  214.          } if
  215.       } if
  216.    }
  217.   /NeverEmbed
  218.    { dup length 0 gt
  219.       { dup 0 get false eq
  220.          { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  221.          } if
  222.       } if
  223.    }
  224.   /CannotEmbedFontPolicy { }
  225.   /EmbedAllFonts { }
  226.   /MaxSubsetPct { }
  227.   /SubsetFonts { }
  228. .dicttomark readonly def
  229. /.distillerdevice
  230.  { currentdevice .devicename /pdfwrite eq
  231.     { currentdevice }
  232.     { /pdfwrite finddevice }
  233.    ifelse
  234.  } bind def
  235. /setdistillerparams {        % <dict> setdistillerparams -
  236.   .distillerdevice null false mark 4 index {
  237.     //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  238.   } forall .putdeviceparams
  239.   dup type /booleantype ne {
  240.     /setdistillerparams .pdfparamerror
  241.   } {
  242.     pop pop pop
  243.   } ifelse
  244. } odef
  245. /currentdistillerparams        % - currentdistillerparams <dict>
  246.  { .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  247.  } odef
  248.  
  249. % Patch 'where' so that the distillerparams operators are only visible
  250. % if the pdfwrite device is the current one, for the benefit of badly
  251. % designed PostScript files that "know" they have to do something different
  252. % if a distiller is processing them.
  253. .wheredict /currentdistillerparams {
  254.   currentdevice .devicename /pdfwrite eq {
  255.     .where
  256.   } {
  257.     .where pop dup //systemdict eq { pop false } { true } ifelse
  258.   } ifelse
  259. } bind put
  260. .wheredict /setdistillerparams .wheredict /currentdistillerparams get put
  261.