gs_fform.ps 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. % Copyright (C) 1995, 1996, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_fform.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  18. % 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....
  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. /.execform1 {
  37. dup /Implementation known not {
  38. dup /FormType get 1 ne { /rangecheck signalerror } if
  39. % The Implementation is a Pattern that will draw the form.
  40. currentglobal 1 index gcheck setglobal
  41. % Stack: form global
  42. 10 dict begin
  43. /PatternType 1 def
  44. /PaintType 1 def % colored
  45. /TilingType 1 def % irrelevant
  46. % Copy the BBox to the correct VM.
  47. /BBox 2 index /BBox get 4 array copy exch 1 index def
  48. % Set XStep and YStep to very large numbers,
  49. % so we won't get multiple copies of the form.
  50. /XStep 1 index dup 2 get exch 0 get sub 100 mul def
  51. /YStep exch dup 3 get exch 1 get sub 100 mul def
  52. /PaintProc 2 index /PaintProc get def
  53. currentdict end readonly
  54. % Stack: form global impl
  55. exch setglobal
  56. 1 index /Implementation 3 -1 roll .forceput
  57. } if
  58. .formcachedict 1 index .knownget {
  59. % Check whether we can use the cached value.
  60. % Stack: form cachevalue
  61. matrix currentmatrix true 0 1 3 {
  62. % Stack: form cachevalue curmat true index
  63. 3 index 0 get 1 index get exch 3 index exch get ne {
  64. pop pop false exit
  65. } if
  66. } for exch pop
  67. } {
  68. false
  69. } ifelse not
  70. { % Make a new cache entry.
  71. gsave
  72. matrix currentmatrix dup 4 0 put dup 5 0 put dup setmatrix
  73. % Stack: form mat
  74. 1 index /Implementation get
  75. 2 index /Matrix get
  76. makepattern 2 array astore
  77. .formcachedict 2 index 2 index put
  78. grestore
  79. } if
  80. % Stack: form cachevalue
  81. -1 0 0 transform
  82. 2 { exch round cvi } repeat .setscreenphase
  83. 1 get setpattern
  84. /BBox get aload pop
  85. exch 3 index sub exch 2 index sub rectfill
  86. } .bind odef % must bind .forceput
  87. .formtypes 1 /.execform1 load put
  88. setglobal