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

  1. %    Copyright (C) 1995, 1996, 1998, 1999 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. % $Id: gs_fform.ps,v 1.1 2000/03/09 08:40:39 lpd Exp $
  16. % Form caching implemented in PostScript.
  17.  
  18. % This implementation doesn't do the right thing about halftone or
  19. % Pattern phase, but the Pattern cache doesn't either....
  20.  
  21. % The Form cache key is the Form dictionary; the value is an array
  22. % of 2 elements [CTM pattern_instance].
  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. currentglobal false setglobal
  27. /.formcachedict 20 dict def    % must be local
  28. true setglobal
  29. /restore {
  30.   mark .formcachedict { } forall
  31.   counttomark 1 add index { //restore } .internalstopped
  32.     { cleartomark //restore }
  33.     { counttomark 2 idiv { .formcachedict 3 1 roll put } repeat pop pop }
  34.   ifelse
  35. } bind odef
  36.  
  37. /.execform1 {
  38.   dup /Implementation known not {
  39.     dup /FormType get 1 ne { /rangecheck signalerror } if
  40.         % The Implementation is a Pattern that will draw the form.
  41.     currentglobal 1 index gcheck setglobal
  42.         % Stack: form global
  43.     10 dict begin
  44.       /PatternType 1 def
  45.       /PaintType 1 def    % colored
  46.       /TilingType 1 def    % irrelevant
  47.         % Copy the BBox to the correct VM.
  48.       /BBox 2 index /BBox get 4 array copy exch 1 index def
  49.         % Set XStep and YStep to very large numbers,
  50.         % so we won't get multiple copies of the form.
  51.       /XStep 1 index dup 2 get exch 0 get sub 100 mul def
  52.       /YStep exch dup 3 get exch 1 get sub 100 mul def
  53.       /PaintProc 2 index /PaintProc get def
  54.     currentdict end readonly
  55.         % Stack: form global impl
  56.     exch setglobal
  57.     1 index /Implementation 3 -1 roll .forceput
  58.   } if
  59.   .formcachedict 1 index .knownget {
  60.         % Check whether we can use the cached value.
  61.         % Stack: form cachevalue
  62.     matrix currentmatrix true 0 1 3 {
  63.         % Stack: form cachevalue curmat true index
  64.       3 index 0 get 1 index get exch 3 index exch get ne {
  65.     pop pop false exit
  66.       } if
  67.     } for exch pop
  68.   } {
  69.     false
  70.   } ifelse not
  71.   {        % Make a new cache entry.
  72.     gsave
  73.     matrix currentmatrix dup 4 0 put dup 5 0 put dup setmatrix
  74.         % Stack: form mat
  75.     1 index /Implementation get
  76.     2 index /Matrix get
  77.     makepattern 2 array astore
  78.     .formcachedict 2 index 2 index put
  79.     grestore
  80.   } if
  81.         % Stack: form cachevalue
  82.   -1 0 0 transform
  83.   2 { exch round cvi } repeat .setscreenphase
  84.   1 get setpattern
  85.   /BBox get aload pop
  86.   exch 3 index sub exch 2 index sub rectfill
  87. } .bind odef    % must bind .forceput
  88.  
  89. .formtypes 1 /.execform1 load put
  90.  
  91. setglobal
  92.