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_fform.ps < prev    next >
Text File  |  1996-10-12  |  4KB  |  111 lines

  1. %    Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % gs_fform.ps
  16. % Monochrome Form caching implemented in PostScript.
  17.  
  18. % This implementation is pretty unreasonable:
  19. %   - It doesn't remember transparent pixels.
  20. %   - It reduces everything to black and white.
  21. %   - It doesn't handle halftone or Pattern phasing.
  22. % However, it's good enough to produce some useful output.
  23.  
  24. % In order to prevent restore from clearing the cache, we explicitly
  25. % push the cache entries on the stack before a restore and reinstall them.
  26. /formcachedict 20 dict def
  27. currentglobal true setglobal
  28. /restore
  29.  { mark formcachedict { } forall
  30.    counttomark 1 add index { restore } .internalstopped
  31.     { cleartomark restore }
  32.     { counttomark 2 idiv { formcachedict 3 1 roll put } repeat pop pop }
  33.    ifelse
  34.  } bind odef
  35.  
  36. /.form.buffer 65000 string def
  37. /execform
  38.  { dup /Implementation known not
  39.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  40.       formcachedict 1 index .knownget not
  41.        { currentglobal true setglobal
  42.         % Stack: form global
  43.          10 dict
  44.        dup /ImageType 1 put
  45.        dup /ImageMatrix [0 0 0 0 0 0] put
  46.        dup /DataSource
  47.         {   % Stack: y (impl is on dict stack)
  48.           Height 1 index sub
  49.           //.form.buffer length Width 7 add 8 idiv idiv .min
  50.               1 index add exch
  51.           Device exch //.form.buffer copyscanlines
  52.         }
  53.        put
  54.        dup /BitsPerComponent 1 put
  55.        dup /Decode [0 1] put
  56.        dup /Device null put
  57.         % Stack: form global impl
  58.      formcachedict 3 index 2 index put
  59.          exch setglobal
  60.        }
  61.       if 1 index /Implementation 3 -1 roll put
  62.     }
  63.    if
  64.    gsave dup /Matrix get concat
  65.    dup /Implementation get
  66.         % Check whether we can use the cached value.
  67.         % Stack: form implementation
  68.    dup /ImageMatrix get matrix currentmatrix
  69.    true 0 1 3
  70.     {       % Stack: form impl cachemat curmat true index
  71.       3 index 1 index get exch 3 index exch get ne { pop false exit } if
  72.     }
  73.    for      % Stack: form impl cachemat curmat valid
  74.    exch pop exch pop not
  75.     {       % Cache is invalid.  Execute the Form and save the bits.
  76.       gsave begin
  77.       currentglobal exch true setglobal
  78.       ImageMatrix currentmatrix pop
  79.       dup /BBox get aload pop
  80.       exch 3 index sub exch 2 index sub rectclip
  81.         % Make the cache device.
  82.       clippath gsave matrix setmatrix pathbbox grestore
  83.         % We now have the bounding box in device space.
  84.       2 { 4 -1 roll floor cvi } repeat
  85.       2 { 4 -1 roll ceiling cvi } repeat
  86.       2 index sub /Height exch def
  87.       2 index sub /Width exch def
  88.       ImageMatrix aload pop
  89.       exch 7 index sub exch 6 index sub
  90.       6 array astore
  91.       3 1 roll pop pop
  92.       dup ImageMatrix copy pop
  93.       Width Height <00 ff> makeimagedevice
  94.       /Device 1 index def
  95.       nulldevice setdevice initgraphics
  96.       exch setglobal
  97.       dup dup /PaintProc get exec
  98.       nulldevice grestore currentdict end
  99.     }
  100.    if
  101.         % Now paint the bits.
  102.         % Stack: form implementation
  103.    /DeviceGray setcolorspace dup begin 0 exch image end pop
  104.    pop grestore
  105.  } odef
  106.  
  107. setglobal
  108.