gs_resst.ps 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. % Copyright (C) 2000 artofcode LLC. 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_resst.ps,v 1.3 2003/08/08 18:45:05 ray Exp $
  16. % Redefine generic category with static resource table.
  17. languagelevel 2 .setlanguagelevel
  18. 15 dict begin % a temporary dictionary for local binding.
  19. /sep (/) def % The %static% device uses platform independent paths.
  20. /tempstring 8192 string def
  21. /IsMyRecord % <raw_record> IsMyRecord <raw_record> bool
  22. { dup type /dicttype eq { dup /StaticFilePos known } { false } ifelse
  23. } bind def
  24. /append_string % <scratch> <index> <string> append_string <scratch> <index>
  25. {
  26. dup length 3 index 3 index 2 index getinterval % (scratch) index (string) l (scr_substr)
  27. 3 2 roll exch copy pop add % (scratch) index'
  28. } bind def
  29. /StaticResourceRecordVirtualMethods 4 dict begin
  30. /GetFilePath % <scratch> <Name> <record> GetFilePath <filepath>
  31. { pop exch % /Name (scratch)
  32. (%static%) dup length exch 2 index copy pop % /Name (scratch) l
  33. //sep //append_string exec % /Name (scratch) l
  34. Category //tempstring cvs //append_string exec % /Name (scratch) l
  35. //sep //append_string exec % /Name (scratch) l
  36. 3 2 roll //tempstring cvs % (scratch) l (Name)
  37. //append_string exec % (scratch) l
  38. 0 exch getinterval % (path)
  39. } bind def
  40. /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
  41. {
  42. begin
  43. STRESDEBUG { (Loading a static resource ) print dup = } if
  44. 8192 string 2 index 2 index //GetFilePath exec
  45. (r) file run
  46. STRESDEBUG { (Completed loading the static resource ) print dup = } if
  47. StaticFileEnd StaticFilePos sub
  48. end
  49. 1 index Category findresource
  50. exch
  51. } bind def
  52. /GetSize % <Name> <record> GetSize <size>
  53. {
  54. % WARNING : this retrives file sise rather than VM size
  55. begin
  56. pop
  57. StaticFileEnd StaticFilePos sub
  58. end
  59. } bind def
  60. /IsActive % <record> IsActive <bool>
  61. { pop true
  62. } bind def
  63. currentdict end def
  64. mark
  65. /MappedCategoryRedefiner /ProcSet findresource begin
  66. /.StaticResourcesBeg % <end_string> <no_of_resources> <category_name> .StaticResourcesBeg <category_name>
  67. % Puts .map dictionary to dstack.
  68. {
  69. STRESDEBUG { (Starting static resources for category ) print dup = } if
  70. dup /Category resourcestatus {
  71. pop pop exch dict begin exch pop
  72. } {
  73. STRESDEBUG { (Skipping the resources because the category isn't defined.) = } if
  74. pop pop .skipeof
  75. } ifelse
  76. } bind
  77. /.StaticResourcesEnd % <category_name> .StaticResourcesEnd -
  78. % Removes .map dictionary from dstack.
  79. {
  80. STRESDEBUG { (Completting static resources for category ) print dup = } if
  81. currentdict end dup % /CatName <map> <map>
  82. systemdict /.io_static_root .knownget not {
  83. 10 dict % /CatName <map> <map> <dir>
  84. % Save it for garbager and for debug purpose :
  85. dup systemdict exch /.io_static_root exch put % /CatName <map> <map> <dir>
  86. dup .setup_io_static % /CatName <map> <map> <dir>
  87. } if % /CatName <map> <map> <dir>
  88. exch 3 index exch put % /CatName <map>
  89. 14 dict begin
  90. /.map exch def % /CatName
  91. /CategoryName exch def %
  92. /IsMapFileOptional true def
  93. /VerifyMap { pop } bind def
  94. /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
  95. { //IsMyRecord exec dup {
  96. pop dup /RecordVirtualMethods //StaticResourceRecordVirtualMethods put
  97. true
  98. } if
  99. } bind def
  100. currentdict end
  101. //Redefine exec
  102. } bind
  103. end % MappedCategoryRedefiner
  104. end % the temporary dictionary for local binding.
  105. /.BeginResource % <instance_name> BeginResource <instance_name>
  106. % Puts a record dictionary to dstack.
  107. {
  108. STRESDEBUG { (Static resource ) print dup =string cvs print } if
  109. currentfile fileposition
  110. currentfile =string readline pop dup length 0 exch 10 .min getinterval (%% Replace) ne {
  111. % We are in COMPILE_INITS=1 .
  112. 4 dict begin
  113. /StaticFilePos exch def
  114. } {
  115. % We are in COMPILE_INITS=0 .
  116. pop
  117. } ifelse
  118. (%END_RESOURCE) .skipeof
  119. } bind
  120. /.EndResource % <instance_name> EndResource -
  121. % Removes a record dictionary from dstack.
  122. {
  123. currentdict /StaticFilePos known {
  124. /StaticFileEnd currentfile fileposition
  125. (.EndResource) length sub
  126. def
  127. STRESDEBUG { ( from position ) print StaticFilePos =string cvs print ( to position ) print StaticFileEnd = } if
  128. currentdict end def
  129. } {
  130. pop
  131. STRESDEBUG { ( ignored with COMPILE_INITS=0. ) = } if
  132. } ifelse
  133. } bind
  134. .dicttomark /StaticCategoryRedefiner exch /ProcSet defineresource pop
  135. .setlanguagelevel