1
0

gs_fform.ps 3.1 KB

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