]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/gs_dps1.ps
merge
[plan9front.git] / sys / lib / ghostscript / gs_dps1.ps
1 %    Copyright (C) 1997, 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
16 % $Id: gs_dps1.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Initialization file for most of the Display PostScript functions
18 % that are also included in Level 2.
19
20 level2dict begin
21
22 % ------ Virtual memory ------ %
23
24 /currentshared /.currentglobal load def
25 /scheck /.gcheck load def
26 %****** FOLLOWING IS WRONG ******
27 /shareddict currentdict /globaldict .knownget not { 20 dict } if def
28
29 % Global and LocalFontDirectory must remain in systemdict
30 % even if we temporarily exit Level 2 mode.
31
32 end                             % level2dict
33 systemdict begin
34
35 /SharedFontDirectory .FontDirectory .gcheck
36  { .currentglobal false .setglobal
37    /LocalFontDirectory .FontDirectory dup maxlength dict copy
38    .forcedef    % LocalFontDirectory is local, systemdict is global
39    .setglobal .FontDirectory
40  }
41  { /LocalFontDirectory .FontDirectory
42    .forcedef    % LocalFontDirectory is local, systemdict is global
43    50 dict
44  }
45 ifelse def
46
47 end                             % systemdict
48 level2dict begin
49
50 % setshared must rebind FontDirectory to the appropriate one of
51 % Local or SharedFontDirectory.
52
53 /.setglobal             % <bool> .setglobal -
54  { dup .setglobal
55    //systemdict /FontDirectory .currentglobal
56     { //SharedFontDirectory }
57     { /LocalFontDirectory .systemvar }  % can't embed ref to local VM
58    ifelse .forceput pop % LocalFontDirectory is local, systemdict is global
59  } .bind odef           % must bind .forceput and .setglobal
60                         % even if NOBIND in effect
61 % Don't just copy (load) the definition of .setglobal:
62 % it gets redefined for LL3.
63 /setshared { /.setglobal .systemvar exec } odef
64 .currentglobal setshared
65
66 % See below for changes in save and restore.
67
68 % ------ Fonts ------ %
69
70 /selectfont             % <fontname> <size> selectfont -
71  { 1 index findfont
72    1 index dup type /arraytype eq { makefont } { scalefont } ifelse
73    setfont pop pop
74  } odef
75 % undefinefont has to take local/global VM into account.
76 /undefinefont           % <fontname> undefinefont -
77  { .FontDirectory 1 index .undef
78    .currentglobal
79     {           % Current mode is global; delete from local directory too.
80       //systemdict /LocalFontDirectory .knownget
81        { 1 index .undef }
82       if
83     }
84     {           % Current mode is local; if there was a shadowed global
85                 % definition, copy it into the local directory.
86       //systemdict /SharedFontDirectory .knownget
87        { 1 index .knownget
88           { .FontDirectory 2 index 3 -1 roll put }
89          if
90        }
91       if
92     }
93    ifelse pop
94  } odef
95
96 % If we load a font into global VM within an inner save, the restore
97 % will delete it from FontDirectory but not from SharedFontDirectory.
98 % We have to handle this by making restore copy missing entries from
99 % SharedFontDirectory to FontDirectory.  Since this could slow down restore
100 % considerably, we define a new operator .dictcopynew for this purpose.
101 % Furthermore, if FAKEFONTS is in effect, we want global real fonts to
102 % override fake local ones.  We handle this by brute force.
103 /restore                % <save> restore -
104  { dup //restore        % bind even if NOBIND
105    /LocalFontDirectory .systemvar
106    FAKEFONTS
107     { mark
108                 % We want to delete a fake font from the local directory
109                 % iff the global directory now has no definition for it,
110                 % or a non-fake definition.
111       1 index dup
112        {                % Stack: lfd mark lfd key ... lfd key value
113          length 1 gt
114           {             % This is a real local definition; don't do anything.
115             pop
116           }
117           {             % This is a fake local definition, check for global.
118             //SharedFontDirectory 1 index .knownget
119              {          % A global definition exists, check for fake.
120                length 1 eq { pop } { 1 index } ifelse
121              }
122              {          % No global definition, delete the local one.
123                1 index
124              }
125             ifelse
126           }
127          ifelse
128        } forall
129       pop counttomark 2 idiv { .undef } repeat pop
130     }
131    if
132    //SharedFontDirectory exch .dictcopynew pop
133    .currentglobal .setglobal    % Rebind FontDirectory according to current VM.
134    pop
135  } bind odef
136
137 % ------ Miscellaneous ------ %
138
139 /undef /.undef load def
140
141 end                             % level2dict