Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
%    Copyright (C) 1996 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_diskf.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17
% Support for converting Type 1 fonts without eexec encryption to
18
% Type 4 fonts that load individual character outlines on demand.
19
 
20
% If DISKFONTS is true, we load individual CharStrings as they are needed.
21
% (This is intended primarily for machines with very small memories.)
22
% Initially, the character definition is the file position of the definition;
23
% this gets replaced with the actual CharString.
24
% Note that if we are loading characters lazily, CharStrings is writable.
25
 
26
% _Cstring must be long enough to hold the longest CharString for
27
% a character defined using seac.  This is lenIV + 4 * 5 (for the operands
28
% of sbw, assuming div is not used) + 2 (for sbw) + 3 * 5 (for the operands
29
% of seac other than the character codes) + 2 * 2 (for the character codes)
30
% + 2 (for seac), i.e., lenIV + 43.
31
 
32
/_Cstring 60 string def
33
 
34
% When we initially load the font, we call
35
%	<index|charname> <length> <readproc> cskip_C
36
% to skip over each character definition and return the file position instead.
37
% This substitutes for the procedure
38
%	<index|charname> <length> string currentfile exch read[hex]string pop
39
%	  [encrypt]
40
% What we actually store in the CharString is fileposition * 1000 + length,
41
%   negated if the string is stored in binary form.
42
 
43
/cskip_C
44
 { exch dup 1000 ge 3 index type /nametype ne or
45
    { % This is a Subrs string, or the string is so long we can't represent
46
      % its length.  Load it now.
47
      exch exec
48
    }
49
    { % Record the position and length, and skip the string.
50
      dup currentfile fileposition 1000 mul add
51
      2 index 3 get /readstring cvx eq { neg } if
52
      3 1 roll
53
      dup _Cstring length idiv
54
       { currentfile _Cstring 3 index 3 get exec pop pop
55
       } repeat
56
      _Cstring length mod _Cstring exch 0 exch getinterval
57
      currentfile exch 3 -1 roll 3 get exec pop pop
58
    }
59
   ifelse
60
 } bind def
61
 
62
% Load a CharString from the file.  The font is the top entry
63
% on the dictionary stack.
64
/load_C		% <charname> <fileposandlength> load_C -
65
 { dup abs 1000 idiv FontFile exch setfileposition
66
   CharStrings 3 1 roll
67
   .currentglobal CharStrings .gcheck .setglobal exch
68
   dup 0 lt
69
    { neg 1000 mod string FontFile exch readstring }
70
    { 1000 mod string FontFile exch readhexstring }
71
   ifelse pop
72
   exch .setglobal
73
% If the CharStrings aren't encrypted on the file, encrypt now.
74
   Private /-| get 0 get
75
   dup type /nametype ne
76
    { dup length 5 sub 5 exch getinterval exec }
77
    { pop }
78
   ifelse dup 4 1 roll put
79
% If the character is defined with seac, load its components now.
80
   mark exch seac_C
81
   counttomark
82
    { StandardEncoding exch get dup CharStrings exch get
83
      dup type /integertype eq { load_C } { pop pop } ifelse
84
    } repeat
85
   pop		% the mark
86
 } bind def
87
 
88
/seac_C		% <charstring> seac_C <achar> <bchar> ..or nothing..
89
 { dup length _Cstring length le
90
    { 4330 exch _Cstring .type1decrypt exch pop
91
      dup dup length 2 sub 2 getinterval <0c06> eq	% seac
92
       { dup length
93
         Private /lenIV known { Private /lenIV get } { 4 } ifelse
94
	 exch 1 index sub getinterval
95
% Parse the string just enough to extract the seac information.
96
% We assume that the only possible operators are hsbw, sbw, and seac,
97
% and that there are no 5-byte numbers.
98
	 mark 0 3 -1 roll
99
	  { exch
100
	     { { dup 32 lt
101
	          { pop 0 }
102
		  { dup 247 lt
103
		     { 139 sub 0 }
104
		     { dup 251 lt
105
			{ 247 sub 256 mul 108 add 1 1 }
106
			{ 251 sub -256 mul -108 add -1 1 }
107
		       ifelse
108
		     }
109
		    ifelse
110
		  }
111
		 ifelse
112
	       }			% 0
113
	       { mul add 0 }		% 1
114
	     }
115
	    exch get exec
116
	  }
117
	 forall pop
118
	 counttomark 1 add 2 roll cleartomark	% pop all but achar bchar
119
       }
120
       { pop	% not seac
121
       }
122
      ifelse
123
    }
124
    { pop	% punt
125
    }
126
   ifelse
127
 } bind def
128
 
129
% Define replacement procedures for loading fonts.
130
% If DISKFONTS is true and the body of the font is not encrypted with eexec:
131
%    - Prevent the CharStrings from being made read-only.
132
%    - Substitute a different CharString-reading procedure.
133
% (eexec disables this because the implicit 'systemdict begin' hides
134
% the redefinitions that make the scheme work.)
135
% We assume that:
136
%    - The magic procedures (-|, -!, |-, and |) are defined with
137
%	executeonly or readonly;
138
%    - The contents of the reading procedures are as defined in bdftops.ps;
139
%    - The font includes the code
140
%	<font> /CharStrings <CharStrings> readonly put
141
/.loadfontdict 6 dict def mark
142
 /begin			% push this dict after systemdict
143
  { dup begin
144
    //systemdict eq { //.loadfontdict begin } if
145
  } bind
146
 /end			% match begin
147
  { currentdict end
148
    //.loadfontdict eq currentdict //systemdict eq and { end } if
149
  } bind
150
 /dict			% leave room for FontFile, BuildChar, BuildGlyph
151
  { 3 add dict
152
  } bind
153
 /executeonly		% for reading procedures
154
  { readonly
155
  }
156
 /noaccess		% for Subrs strings and Private dictionary
157
  { readonly
158
  }
159
 /readonly		% for procedures and CharStrings dictionary
160
  {	% We want to take the following non-standard actions here:
161
  	%   - If the operand is the CharStrings dictionary, do nothing;
162
	%   - If the operand is a number (a file position replacing the
163
	%	actual CharString), do nothing;
164
	%   - If the operand is either of the reading procedures (-| or -!),
165
	%	substitute a different one.
166
    dup type /dicttype eq		% CharStrings or Private
167
    count 2 gt and
168
     { 1 index /CharStrings ne { readonly } if }
169
     { dup type /arraytype eq		% procedure or data array
170
	{ dup length 5 ge 1 index xcheck and
171
	   { dup 0 get /string eq
172
	     1 index 1 get /currentfile eq and
173
	     1 index 2 get /exch eq and
174
	     1 index 3 get dup /readstring eq exch /readhexstring eq or and
175
	     1 index 4 get /pop eq and
176
	      { /cskip_C cvx 2 packedarray cvx
177
	      }
178
	      { readonly
179
	      }
180
	     ifelse
181
	   }
182
	   { readonly
183
	   }
184
	  ifelse
185
	}
186
	{ dup type /stringtype eq	% must be a Subr string
187
	   { readonly }
188
	  if
189
	}
190
       ifelse
191
     }
192
    ifelse
193
  } bind
194
 /definefont		% to insert BuildChar/Glyph and change FontType
195
  { dup /FontType get 1 eq
196
     { dup /FontType 4 put
197
       dup /BuildChar /build_C load put
198
       dup /BuildGlyph /build_C load put
199
     }
200
    if definefont
201
  } bind
202
counttomark 2 idiv { .loadfontdict 3 1 roll put } repeat pop
203
.loadfontdict readonly pop
204
 
205
% Define the BuildChar and BuildGlyph procedures for modified fonts.
206
% A single procedure serves for both.
207
/build_C		% <font> <code|name> build_C -
208
 { 1 index begin
209
   dup dup type /integertype eq { Encoding exch get } if
210
		% Stack: font code|name name
211
   dup CharStrings exch .knownget not
212
    { 2 copy eq { exch pop /.notdef exch } if
213
      QUIET not
214
       { (Substituting .notdef for ) print = flush }
215
       { pop }
216
      ifelse
217
      /.notdef CharStrings /.notdef get
218
    } if
219
		% Stack: font code|name name charstring   
220
   dup type /integertype eq
221
    { load_C end build_C }
222
    { end .type1execchar }
223
   ifelse
224
 } bind def