1 % Copyright (C) 1995, 1996, 1998, 1999 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: gs_fform.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Form caching implemented in PostScript.
19 % This implementation doesn't do the right thing about halftone or
20 % Pattern phase, but the Pattern cache doesn't either....
22 % The Form cache key is the Form dictionary; the value is an array
23 % of 2 elements [CTM pattern_instance].
25 % In order to prevent restore from clearing the cache, we explicitly
26 % push the cache entries on the stack before a restore and reinstall them.
27 currentglobal false setglobal
28 /.formcachedict 20 dict def % must be local
31 mark .formcachedict { } forall
32 counttomark 1 add index { //restore } .internalstopped
33 { cleartomark //restore }
34 { counttomark 2 idiv { .formcachedict 3 1 roll put } repeat pop pop }
39 dup /Implementation known not {
40 dup /FormType get 1 ne { /rangecheck signalerror } if
41 % The Implementation is a Pattern that will draw the form.
42 currentglobal 1 index gcheck setglobal
46 /PaintType 1 def % colored
47 /TilingType 1 def % irrelevant
48 % Copy the BBox to the correct VM.
49 /BBox 2 index /BBox get 4 array copy exch 1 index def
50 % Set XStep and YStep to very large numbers,
51 % so we won't get multiple copies of the form.
52 /XStep 1 index dup 2 get exch 0 get sub 100 mul def
53 /YStep exch dup 3 get exch 1 get sub 100 mul def
54 /PaintProc 2 index /PaintProc get def
55 currentdict end readonly
56 % Stack: form global impl
58 1 index /Implementation 3 -1 roll .forceput
60 .formcachedict 1 index .knownget {
61 % Check whether we can use the cached value.
62 % Stack: form cachevalue
63 matrix currentmatrix true 0 1 3 {
64 % Stack: form cachevalue curmat true index
65 3 index 0 get 1 index get exch 3 index exch get ne {
72 { % Make a new cache entry.
74 matrix currentmatrix dup 4 0 put dup 5 0 put dup setmatrix
76 1 index /Implementation get
78 makepattern 2 array astore
79 .formcachedict 2 index 2 index put
82 % Stack: form cachevalue
84 2 { exch round cvi } repeat .setscreenphase
87 exch 3 index sub exch 2 index sub rectfill
88 } .bind odef % must bind .forceput
90 .formtypes 1 /.execform1 load put