home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / gs403osk.tgz / gs403osk.tar / gs_pdfwr.ps < prev    next >
Text File  |  1996-09-22  |  9KB  |  284 lines

  1. %    Copyright (C) 1996 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. % gs_pdfwr.ps
  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. /.pdf===dict mark
  24.   /arraytype
  25.    { dup xcheck { ({) (}) } { ([) (]) } ifelse
  26.         % Stack: file obj left right
  27.       4 1 roll 2 index exch writestring () exch
  28.        { exch 2 index exch writestring
  29.      1 index exch pdfmark===only ( )
  30.        }
  31.       forall pop exch writestring
  32.    } bind
  33.   /packedarraytype 1 index
  34.   /dicttype
  35.    { 1 index (<<\n) writestring
  36.       { 2 index 3 -1 roll pdfmark===only 1 index ( ) writestring
  37.     1 index exch pdfmark===only dup (\n) writestring
  38.       }
  39.      forall (>>) writestring
  40.    } bind
  41. .dicttomark readonly def
  42. /pdfmark===only     % <file> <obj> pdfmark===only -
  43.  { .pdf===dict 1 index type .knownget { exec } { write==only } ifelse
  44.  } bind def
  45. /.pdfcvs        % <obj> .pdfcvs <string>
  46.  {      % We can't handle long values yet.
  47.    =string /NullEncode filter dup 2 index pdfmark===only
  48.    dup (\n\000) writestring closefile pop
  49.    =string (\n\000) search
  50.     { dup length string copy exch pop exch pop }
  51.     {       % The converted representation didn't fit.  Punt.
  52.       pop (???)
  53.     }
  54.    ifelse
  55.  } bind def
  56. /.pdfputparams      % <paramarray> <paramname> .pdfputparams <result...>
  57.  { currentdevice null false mark 6 -2 roll exch
  58.         % Don't allow the page device to get cleared....
  59.      {.putdeviceparams} 0 get .currentpagedevice pop {.setpagedevice} 0 get
  60.    3 array astore cvx exec
  61.  } bind def
  62. /pdfmark
  63.  { ] 1 2 2 index length 1 sub { 2 copy 2 copy get .pdfcvs put pop } for
  64.    /pdfmark .pdfputparams
  65.    type /booleantype ne { cleartomark pop pop } if pop
  66.  } odef
  67. userdict /pdfmark .undef
  68.  
  69. % Define setdistillerparams / currentdistillerparams.
  70. % Distiller parameters are currently treated as device parameters.
  71. /.distillerparamkeys mark
  72.         % General parameters
  73.   /CoreDistVersion { }
  74.   /DoThumbnails { }
  75.   /LZWEncodePages { }
  76.   /ASCII85EncodePages { }
  77.         % Color sampled image parameters
  78.   /DownsampleColorImages { }
  79.   /ColorImageResolution { }
  80.   /EncodeColorImages { }
  81.   /ColorImageFilter { }
  82.   /ColorImageDict { }
  83.   /ColorImageDepth { }
  84.   /AntiAliasColorImages { }
  85.   /ConvertCMYKImagesToRGB { }
  86.         % Grayscale sampled image parameters
  87.   /DownsampleGrayImages { }
  88.   /GrayImageResolution { }
  89.   /EncodeGrayImages { }
  90.   /GrayImageFilter { }
  91.   /GrayImageDict { }
  92.   /GrayImageDepth { }
  93.   /AntiAliasGrayImages { }
  94.         % Monochrome sampled image parameters
  95.   /DownsampleMonoImages { }
  96.   /MonoImageResolution { }
  97.   /EncodeMonoImages { }
  98.   /MonoImageFilter { }
  99.   /MonoImageDict { }
  100.   /MonoImageDepth { }
  101.   /AntiAliasMonoImages { }
  102.         % Font embedding parameters
  103.   /AlwaysEmbed
  104.    { dup length 0 gt
  105.       { dup 0 get false eq
  106.          { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  107.          } if
  108.       } if
  109.    }
  110.   /NeverEmbed
  111.    { dup length 0 gt
  112.       { dup 0 get false eq
  113.          { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  114.          } if
  115.       } if
  116.    }
  117.   /EmbedAllFonts { }
  118.   /SubsetFonts { }
  119.   /MaxSubsetPct { }
  120. .dicttomark readonly def
  121. /.distillerdevice
  122.  { currentdevice .devicename /pdfwrite eq
  123.     { currentdevice }
  124.     { /pdfwrite finddevice }
  125.    ifelse
  126.  } bind def
  127. /setdistillerparams     % <dict> setdistillerparams -
  128.  { .distillerdevice null false mark 5 -1 roll
  129.     { //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse }
  130.    forall .putdeviceparams
  131.    type /booleantype eq { pop } { cleartomark pop pop pop } ifelse
  132.  } odef
  133. /currentdistillerparams     % - currentdistillerparams <dict>
  134.  { .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  135.  } odef
  136.  
  137. % Patch the 'show' operators to pass the data to the device.
  138. % We use a pseudo-parameter named /show whose value is a dictionary:
  139. %   /String (str)
  140. %   /Values [cx cy char ax ay px py]
  141. %   /Matrix [xx xy yx yy tx ty]
  142. %   /FontName /fontname
  143. %   /Color [r g b]
  144. %   /Encoding [e0 .. e255]
  145. %   /BaseEncoding [e0 ... e255]
  146. % THIS IS A BIG HACK.
  147. /.findorigfont      % <font> .findorigfont <origfont>
  148.  {          % Check for a known font with this name and
  149.             % the same UniqueID.
  150.    dup /UniqueID .knownget
  151.     { 1 index /FontName .knownget
  152.        {        % Stack: font uniqueid fontname
  153.      FontDirectory exch .knownget
  154.       { dup /UniqueID .knownget
  155.          {      % Stack: font uniqueid knownfont knownid
  156.            3 -1 roll eq { true } { pop false } ifelse
  157.          }
  158.          { pop pop false
  159.          }
  160.         ifelse
  161.       }
  162.       { pop false
  163.       }
  164.      ifelse
  165.        }
  166.        { pop false
  167.        }
  168.       ifelse
  169.     }
  170.     { false
  171.     }
  172.    ifelse
  173.             % Stack: font knownfont -true- | font -false-
  174.     { exch pop
  175.     }
  176.     {  { dup /OrigFont .knownget not { exit } if exch pop } loop
  177.     }
  178.    ifelse
  179.  } .bind def
  180. /.pdfdoshow     % <string> <cxd> <cyd> <char> <axd> <ayd> .pdfdoshow
  181.             %   <bool>
  182.  { mark /String 8 2 roll
  183.    currentpoint transform 7 array astore /Values exch
  184.         % Concatenate the "quotient" of the current FontMatrix
  185.         % and the FontMatrix of the original font.
  186.         % Be sure to include any translation.
  187.    /Matrix
  188.      currentfont .findorigfont /FontMatrix get matrix invertmatrix
  189.      currentfont /FontMatrix get 1 index concatmatrix
  190.      matrix currentmatrix dup 4 0 put dup 5 0 put dup concatmatrix
  191.    /FontName currentfont /FontName get
  192.    /Color [ currentrgbcolor ]
  193.    /Encoding currentfont /Encoding .knownget not { [] } if
  194.     % Make a reasonable guess at the base encoding.
  195.    /BaseEncoding StandardEncoding
  196.    .dicttomark /show .pdfputparams
  197.    dup type /booleantype eq
  198.     { pop pop true }
  199.     { dup /undefined eq
  200.        { cleartomark pop pop pop false }
  201.        { dup mark eq { /unknown /rangecheck } if
  202.      counttomark 4 add 1 roll cleartomark pop pop pop
  203.      /.pdfshow cvx exch signalerror
  204.        }
  205.       ifelse
  206.     }
  207.    ifelse
  208.  } .bind def
  209. /.pdfexecshow       % <proc> .pdfexecshow -
  210.  { matrix currentmatrix gsave nulldevice setmatrix
  211.    exec currentpoint grestore moveto
  212.  } .bind def
  213. % Create a 1-element cache for currentdevice .devicename /pdfwrite eq.
  214. userdict begin
  215.   /.pdfwritedevice null def
  216.   /.pdfwriteenabled false def       % place-holder
  217. end
  218. /.pdfwrite?     % - .pdfwrite? <bool>
  219.  { currentdevice .pdfwritedevice eq
  220.     { .pdfwriteenabled
  221.     }
  222.     { currentdevice .devicename /pdfwrite eq
  223.       userdict /.pdfwriteenabled 2 index put
  224.       userdict /.pdfwritedevice currentdevice put
  225.     }
  226.    ifelse currentfont /FontType get 1 eq and
  227.  } .bind def
  228. /.pdfshow       % <string> <cxd> <cyd> <char> <axd> <ayd> <showproc>
  229.             %   .pdfdoshow -
  230.  { 7 1 roll .pdfwrite?
  231.     { .pdfdoshow }
  232.     { 6 { pop } repeat false }
  233.    ifelse
  234.     { .pdfexecshow }
  235.     { exec }
  236.    ifelse
  237.  } .bind def
  238. /show
  239.  { dup 0 0 32 0 0 { show } .pdfshow
  240.  } .bind odef
  241. /ashow
  242.  { dup 0 0 32 6 index 6 index dtransform { ashow } .pdfshow
  243.  } .bind odef
  244. /widthshow
  245.  { 4 copy 4 -2 roll dtransform 4 -1 roll 0 0 { widthshow } .pdfshow
  246.  } .bind odef
  247. /awidthshow
  248.  { 6 copy 6 -2 roll dtransform 6 -3 roll dtransform { awidthshow } .pdfshow
  249.  } .bind odef
  250. /glyphshow
  251.  { .pdfwrite?
  252.     { currentfont /Encoding .knownget not { {} } if
  253.       0 1 2 index length 1 sub
  254.        {        % Stack: glyph encoding index
  255.      2 copy get 3 index eq { exch pop exch pop null exit } if pop
  256.        }
  257.       for null eq
  258.        { (X) dup 0 4 -1 roll put show }
  259.        { glyphshow }
  260.       ifelse
  261.     }
  262.     { glyphshow
  263.     }
  264.    ifelse
  265.  } .bind odef
  266. % The remaining operators aren't implemented correctly.
  267. /kshow
  268.  { .pdfwrite?
  269.     {  { (X) dup 0 4 -1 roll put show dup exec } forall pop }
  270.     { kshow }
  271.    ifelse
  272.  } .bind odef
  273. /xshow
  274.  { .pdfwrite? { pop show } { xshow } ifelse
  275.  } .bind odef
  276. /yshow
  277.  { .pdfwrite? { pop show } { yshow } ifelse
  278.  } .bind odef
  279. /xyshow
  280.  { .pdfwrite? { pop show } { xyshow } ifelse
  281.  } .bind odef
  282.