| 1 | % Copyright (C) 1990, 1991 Aladdin Enterprises. All rights reserved. |
| 2 | % Distributed by Free Software Foundation, Inc. |
| 3 | % |
| 4 | % This file is part of Ghostscript. |
| 5 | % |
| 6 | % Ghostscript is distributed in the hope that it will be useful, but |
| 7 | % WITHOUT ANY WARRANTY. No author or distributor accepts responsibility |
| 8 | % to anyone for the consequences of using it or for whether it serves any |
| 9 | % particular purpose or works at all, unless he says so in writing. Refer |
| 10 | % to the Ghostscript General Public License for full details. |
| 11 | % |
| 12 | % Everyone is granted permission to copy, modify and redistribute |
| 13 | % Ghostscript, but only under the conditions described in the Ghostscript |
| 14 | % General Public License. A copy of this license is supposed to have been |
| 15 | % given to you along with Ghostscript so you can know your rights and |
| 16 | % responsibilities. It should be in a file named COPYING. Among other |
| 17 | % things, the copyright notice and this notice must be preserved on all |
| 18 | % copies. |
| 19 | |
| 20 | % Initialization file for Ghostscript Level 2 functions. |
| 21 | % When this is run, systemdict is still writable. |
| 22 | |
| 23 | % ------ Painting ------ % |
| 24 | |
| 25 | % A straightforward definition of execform that doesn't actually |
| 26 | % do any caching. |
| 27 | /execform |
| 28 | { dup /Implementation known not |
| 29 | { dup /FormType get 1 ne { /rangecheck signalerror } if |
| 30 | dup /Implementation null put readonly } if |
| 31 | gsave dup /Matrix get concat |
| 32 | dup /BBox get aload pop |
| 33 | exch 3 index sub exch 2 index sub rectclip |
| 34 | dup /PaintProc get exec |
| 35 | grestore |
| 36 | } bind def |
| 37 | |
| 38 | % ------ Resources ------ % |
| 39 | |
| 40 | % Currently, we don't implement resource unloading or global/local |
| 41 | % instance sets, and resourceforall only enumerates loaded instances. |
| 42 | % The standard implementation of resource categories is |
| 43 | % simply to have another entry in the resource dictionary, called Instances, |
| 44 | % that keeps track of all the instances. |
| 45 | |
| 46 | % Note that the dictionary that defines a resource category is stored |
| 47 | % in global memory. The PostScript manual says that each category must |
| 48 | % manage global and local instances separately. However, objects in |
| 49 | % global memory can't reference objects in local memory. This means |
| 50 | % that the resource category dictionary, which would otherwise be the |
| 51 | % obvious place to keep track of the instances, can't be used to keep |
| 52 | % track of local instances. Instead, there must be a parallel |
| 53 | % structure in local memory for each resource category. Needless to |
| 54 | % say, we haven't implemented this yet. |
| 55 | |
| 56 | % Define the Category category, except for most of the procedures. |
| 57 | % The dictionary we're about to create will become the Category |
| 58 | % category definition dictionary. |
| 59 | |
| 60 | 10 dict begin |
| 61 | /Category /Category def |
| 62 | /CheckResource |
| 63 | { true |
| 64 | { /DefineResource /FindResource /ResourceForAll /ResourceStatus |
| 65 | /UndefineResource } |
| 66 | { 2 index exch known and } |
| 67 | forall exch pop } bind def |
| 68 | /DefineResource |
| 69 | { dup CheckResource |
| 70 | { dup /Category 3 index put Instances 3 1 roll put } |
| 71 | { /typecheck signalerror } |
| 72 | ifelse } bind def |
| 73 | /FindResource % temporary |
| 74 | { Instances exch get } bind def |
| 75 | /Instances 25 dict def |
| 76 | /InstanceType /dicttype def |
| 77 | |
| 78 | Instances /Category currentdict put |
| 79 | Instances end begin % so we can name the Category definition |
| 80 | |
| 81 | % Define the resource operators. |
| 82 | |
| 83 | mark |
| 84 | /defineresource |
| 85 | { /Category findresource dup begin |
| 86 | /InstanceType known |
| 87 | { dup type InstanceType ne |
| 88 | { dup type /packedarraytype eq InstanceType /arraytype eq and |
| 89 | not { /typecheck signalerror } if } if } if |
| 90 | DefineResource end |
| 91 | } |
| 92 | /findresource |
| 93 | { dup /Category eq |
| 94 | { pop //Category } { /Category findresource } ifelse |
| 95 | begin FindResource end } |
| 96 | /resourceforall |
| 97 | { /Category findresource begin ResourceForAll end } |
| 98 | /resourcestatus |
| 99 | { /Category findresource begin ResourceStatus end } |
| 100 | /undefineresource |
| 101 | { /Category findresource begin UndefineResource end } |
| 102 | end % Instances |
| 103 | counttomark 2 idiv { bind def } repeat pop |
| 104 | |
| 105 | % Define the Generic category. |
| 106 | |
| 107 | 12 dict dup begin |
| 108 | /Instances 0 dict def |
| 109 | /CheckResource % not a standard entry |
| 110 | { pop true } def |
| 111 | /DefineResource |
| 112 | { dup CheckResource |
| 113 | { Instances 3 1 roll put } |
| 114 | { /typecheck signalerror } |
| 115 | ifelse |
| 116 | } bind def |
| 117 | /FindResource |
| 118 | { dup ResourceStatus |
| 119 | { pop 1 gt { dup ResourceFile run } if |
| 120 | Instances exch get } |
| 121 | { /undefinedresource signalerror } |
| 122 | ifelse } bind def |
| 123 | /ResourceFile % not a standard entry |
| 124 | { currentdict /ResourceFileName get 100 string exch exec |
| 125 | (r) file } bind def |
| 126 | /ResourceForAll |
| 127 | { % We construct a new procedure so we don't have to use |
| 128 | % static resources to hold the iteration state. |
| 129 | 3 1 roll cvlit 3 1 roll cvlit 3 1 roll |
| 130 | { % Stack contains: key, instance, template, proc, scratch |
| 131 | 4 index 3 index stringmatch |
| 132 | { 4 index type dup /stringtype eq exch /nametype eq or |
| 133 | { 4 index exch cvs exch 5 2 roll pop pop pop } |
| 134 | { pop exch pop exch pop } |
| 135 | ifelse exec } |
| 136 | { 5 { pop } repeat } |
| 137 | ifelse |
| 138 | } /exec cvx 5 packedarray cvx |
| 139 | Instances exch forall } bind def |
| 140 | /ResourceStatus |
| 141 | { dup Instances exch known |
| 142 | { pop 1 0 true } |
| 143 | { mark exch { ResourceFile } stopped |
| 144 | { cleartomark false } { closefile cleartomark 0 true } |
| 145 | ifelse |
| 146 | } ifelse |
| 147 | } bind def |
| 148 | /UndefineResource |
| 149 | { Instances exch undef } bind def |
| 150 | end |
| 151 | /Generic exch /Category defineresource |
| 152 | |
| 153 | % Fill in the rest of the Category category. |
| 154 | /Category /Category findresource dup |
| 155 | /Generic /Category findresource begin |
| 156 | { /FindResource /ResourceStatus /ResourceForAll } |
| 157 | { dup load put dup } forall |
| 158 | pop pop end |
| 159 | |
| 160 | % Define the fixed categories. |
| 161 | |
| 162 | 7 dict begin % 5 procedures, Category, Instances |
| 163 | /DefineResource |
| 164 | { /invalidaccess signalerror } bind def |
| 165 | /FindResource |
| 166 | { Instances exch get } bind def |
| 167 | /ResourceForAll |
| 168 | /Generic /Category findresource /ResourceForAll get def |
| 169 | /ResourceStatus |
| 170 | { Instances exch known { 0 0 true } { false } ifelse } bind def |
| 171 | /UndefineResource |
| 172 | { /invalidaccess signalerror } bind def |
| 173 | |
| 174 | mark |
| 175 | % Things other than types |
| 176 | /ColorSpaceFamily {/DeviceRGB /DeviceGray} |
| 177 | /Emulator {} |
| 178 | /Filter |
| 179 | [ .filterdict { pop } forall ] |
| 180 | /IODevice {(%os%)} |
| 181 | % Types |
| 182 | /ColorRenderingType {} |
| 183 | /FMapType {2 3 4 5 6 7 8} |
| 184 | /FontType {1 3} |
| 185 | /FormType {1} |
| 186 | /HalftoneType {} |
| 187 | /ImageType {} |
| 188 | /PatternType {} |
| 189 | counttomark 2 idiv |
| 190 | { currentdict dup maxlength dict copy begin |
| 191 | dup length dict dup begin exch { dup def } forall end readonly |
| 192 | /Instances exch def |
| 193 | currentdict /Category defineresource |
| 194 | currentdict end readonly pop |
| 195 | } repeat pop end |
| 196 | |
| 197 | % Define the other built-in categories. |
| 198 | |
| 199 | mark |
| 200 | /ColorRendering /dicttype /ColorSpace /arraytype /Encoding /arraytype |
| 201 | /Font /dicttype /Form /dicttype /Halftone /dicttype /Pattern /dicttype |
| 202 | /ProcSet /dicttype |
| 203 | counttomark 2 idiv |
| 204 | { /Generic /Category findresource dup maxlength dict copy begin |
| 205 | /InstanceType exch def |
| 206 | /Instances 10 dict def |
| 207 | currentdict end /Category defineresource |
| 208 | } repeat pop |
| 209 | |
| 210 | % Complete the Encoding category. |
| 211 | |
| 212 | /findencoding |
| 213 | { /Encoding findresource } bind def |
| 214 | /ISOLatin1Encoding ISOLatin1Encoding /Encoding defineresource |
| 215 | /StandardEncoding StandardEncoding /Encoding defineresource |
| 216 | /SymbolEncoding SymbolEncoding /Encoding defineresource |
| 217 | |
| 218 | % Complete the Font category. |
| 219 | % THIS IMPLEMENTATION IS VERY TENTATIVE. |
| 220 | |
| 221 | /Font /Category findresource begin |
| 222 | /olddefinefont /definefont load def |
| 223 | /oldfindfont /findfont load def |
| 224 | /DefineResource |
| 225 | { 2 copy olddefinefont exch 2 copy |
| 226 | Instances 3 1 roll put exch pop } bind def |
| 227 | /FindResource |
| 228 | { oldfindfont } bind def |
| 229 | end |
| 230 | |
| 231 | /definefont |
| 232 | { /Font defineresource } bind def |
| 233 | /findfont |
| 234 | { /Font findresource } bind def |
| 235 | /undefinefont |
| 236 | { /Font undefineresource } bind def |