2 |
- |
1 |
% Copyright (C) 1992, 1997, 1998, 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: type1ops.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
|
|
|
17 |
% type1ops.ps
|
|
|
18 |
% Define the Type 1 and Type 2 font opcodes for use by Ghostscript utilities.
|
|
|
19 |
|
|
|
20 |
% Define the default value of lenIV.
|
|
|
21 |
% Note that this expects the current font to be on the dictionary stack.
|
|
|
22 |
|
|
|
23 |
/lenIV { FontType 2 eq { -1 } { 4 } ifelse } def
|
|
|
24 |
|
|
|
25 |
% ---------------- Encoding ---------------- %
|
|
|
26 |
|
|
|
27 |
/Type1encode 70 dict
|
|
|
28 |
|
|
|
29 |
% Data types
|
|
|
30 |
|
|
|
31 |
dup /nulltype {
|
|
|
32 |
pop ()
|
|
|
33 |
} put
|
|
|
34 |
dup /nametype {
|
|
|
35 |
Type1encode exch get
|
|
|
36 |
} put
|
|
|
37 |
dup /stringtype {
|
|
|
38 |
} put
|
|
|
39 |
dup /integertype {
|
|
|
40 |
dup dup -107 ge exch 107 le and {
|
|
|
41 |
139 add (x) dup 0 4 -1 roll put
|
|
|
42 |
} {
|
|
|
43 |
dup dup -1131 ge exch 1131 le and {
|
|
|
44 |
dup 0 ge { 16#f694 } { neg 16#fa94 } ifelse add
|
|
|
45 |
(xx) dup dup 0 4 index -8 bitshift put
|
|
|
46 |
1 4 -1 roll 255 and put
|
|
|
47 |
} {
|
|
|
48 |
(\377xxxx) 1 1 4 {
|
|
|
49 |
dup 8 mul 32 sub 3 index exch bitshift 255 and
|
|
|
50 |
2 index 3 1 roll put
|
|
|
51 |
} for exch pop
|
|
|
52 |
} ifelse
|
|
|
53 |
} ifelse
|
|
|
54 |
} put
|
|
|
55 |
|
|
|
56 |
% Operators
|
|
|
57 |
|
|
|
58 |
% Identical or similar in Type 1 and Type 2.
|
|
|
59 |
/c_hstem 1 def dup /hstem <01> put
|
|
|
60 |
/c_vstem 3 def dup /vstem <03> put
|
|
|
61 |
/c_vmoveto 4 def dup /vmoveto <04> put
|
|
|
62 |
/c_rlineto 5 def dup /rlineto <05> put
|
|
|
63 |
/c_hlineto 6 def dup /hlineto <06> put
|
|
|
64 |
/c_vlineto 7 def dup /vlineto <07> put
|
|
|
65 |
/c_rrcurveto 8 def dup /rrcurveto <08> put
|
|
|
66 |
/c_callsubr 10 def /s_callsubr <0a> def dup /callsubr s_callsubr put
|
|
|
67 |
/c_return 11 def dup /return <0b> put
|
|
|
68 |
/c_escape 12 def
|
|
|
69 |
/ce_div 12 def /s_div <0c0c> def dup /div s_div put
|
|
|
70 |
/c_endchar 14 def /s_endchar <0e> def dup /endchar s_endchar put
|
|
|
71 |
/c_rmoveto 21 def dup /rmoveto <15> put
|
|
|
72 |
/c_hmoveto 22 def dup /hmoveto <16> put
|
|
|
73 |
/c_vhcurveto 30 def dup /vhcurveto <1e> put
|
|
|
74 |
/c_hvcurveto 31 def dup /hvcurveto <1f> put
|
|
|
75 |
% Only in Type 1.
|
|
|
76 |
/c_closepath 9 def dup /closepath <09> put
|
|
|
77 |
/c_hsbw 13 def /s_hsbw <0d> def dup /hsbw s_hsbw put
|
|
|
78 |
/ce_dotsection 0 def /s_dotsection <0c06> def dup /dotsection s_dotsection put
|
|
|
79 |
/ce_vstem3 1 def /s_vstem3 <0c01> def dup /vstem3 s_vstem3 put
|
|
|
80 |
/ce_hstem3 2 def /s_hstem3 <0c02> def dup /hstem3 s_hstem3 put
|
|
|
81 |
/ce_seac 6 def /s_seac <0c06> def dup /seac s_seac put
|
|
|
82 |
/ce_sbw 7 def /s_sbw <0c07> def dup /sbw s_sbw put
|
|
|
83 |
/ce_callothersubr 16 def /s_callothersubr <0c10> def dup /callothersubr s_callothersubr put
|
|
|
84 |
/ce_pop 17 def /s_pop <0c11> def dup /pop s_pop put
|
|
|
85 |
/ce_setcurrentpoint 33 def /s_setcurrentpoint <0c21> def dup /setcurrentpoint s_setcurrentpoint put
|
|
|
86 |
/s_setcurrentpoint_hmoveto s_setcurrentpoint <8b16> concatstrings def
|
|
|
87 |
% Only in Type 2.
|
|
|
88 |
dup /blend <10> put
|
|
|
89 |
dup /hstemhm <12> put
|
|
|
90 |
dup /hintmask <13> put
|
|
|
91 |
dup /cntrmask <14> put
|
|
|
92 |
dup /vstemhm <17> put
|
|
|
93 |
dup /rcurveline <18> put
|
|
|
94 |
dup /rlinecurve <19> put
|
|
|
95 |
dup /vvcurveto <1a> put
|
|
|
96 |
dup /hhcurveto <1b> put
|
|
|
97 |
dup /callgsubr <1d> put
|
|
|
98 |
dup /and <0c03> put
|
|
|
99 |
dup /or <0c04> put
|
|
|
100 |
dup /not <0c05> put
|
|
|
101 |
dup /store <0c08> put
|
|
|
102 |
dup /abs <0c09> put
|
|
|
103 |
dup /add <0c0a> put
|
|
|
104 |
dup /sub <0c0b> put
|
|
|
105 |
dup /load <0c0d> put
|
|
|
106 |
dup /neg <0c0c> put
|
|
|
107 |
dup /eq <0c0f> put
|
|
|
108 |
dup /drop <0c12> put
|
|
|
109 |
dup /put <0c14> put
|
|
|
110 |
dup /get <0c15> put
|
|
|
111 |
dup /ifelse <0c16> put
|
|
|
112 |
dup /random <0c17> put
|
|
|
113 |
dup /mul <0c18> put
|
|
|
114 |
dup /sqrt <0c1a> put
|
|
|
115 |
dup /dup <0c1b> put
|
|
|
116 |
dup /exch <0c1c> put
|
|
|
117 |
dup /index <0c1d> put
|
|
|
118 |
dup /roll <0c1e> put
|
|
|
119 |
dup /hflex <0c22> put
|
|
|
120 |
dup /flex <0c23> put
|
|
|
121 |
dup /hflex1 <0c24> put
|
|
|
122 |
dup /flex1 <0c25> put
|
|
|
123 |
|
|
|
124 |
readonly def
|
|
|
125 |
|
|
|
126 |
% ---------------- Decoding ---------------- %
|
|
|
127 |
|
|
|
128 |
/Type1decode 512 array
|
|
|
129 |
|
|
|
130 |
Type1encode {
|
|
|
131 |
dup type /stringtype eq {
|
|
|
132 |
dup length 1 eq { 0 get } { 1 get 256 add } ifelse
|
|
|
133 |
% stack: array key code
|
|
|
134 |
exch 2 index 3 1 roll put
|
|
|
135 |
} {
|
|
|
136 |
pop pop
|
|
|
137 |
} ifelse
|
|
|
138 |
} forall
|
|
|
139 |
|
|
|
140 |
dup 12 {
|
|
|
141 |
dup read pop dup Type1decode exch 256 add get dup null ne
|
|
|
142 |
{ exch pop }
|
|
|
143 |
{ pop 2 string dup 0 12 put dup 1 4 -1 roll put }
|
|
|
144 |
ifelse
|
|
|
145 |
} put
|
|
|
146 |
dup 28 { % Type 2 only
|
|
|
147 |
dup read pop 128 xor 128 sub 8 bitshift
|
|
|
148 |
1 index read pop add
|
|
|
149 |
} put
|
|
|
150 |
32 1 246 { 2 copy dup 139 sub put pop } for
|
|
|
151 |
dup 247 { dup read pop 108 add } put
|
|
|
152 |
dup 248 { dup read pop 364 add } put
|
|
|
153 |
dup 249 { dup read pop 620 add } put
|
|
|
154 |
dup 250 { dup read pop 876 add } put
|
|
|
155 |
dup 251 { dup read pop 108 add neg } put
|
|
|
156 |
dup 252 { dup read pop 364 add neg } put
|
|
|
157 |
dup 253 { dup read pop 620 add neg } put
|
|
|
158 |
dup 254 { dup read pop 876 add neg } put
|
|
|
159 |
dup 255 { % Different for Type 1 and Type 2
|
|
|
160 |
dup read pop 128 xor 128 sub
|
|
|
161 |
3 { 8 bitshift 1 index read pop add } repeat
|
|
|
162 |
FontType 2 eq { 65536.0 div } if
|
|
|
163 |
} put
|
|
|
164 |
|
|
|
165 |
readonly def
|
|
|
166 |
|
|
|
167 |
% ---------------- Procedures ---------------- %
|
|
|
168 |
|
|
|
169 |
% For these utilities, a CharString is represented by a sequence of
|
|
|
170 |
% integers, reals, strings, and names, either in an array or on the stack.
|
|
|
171 |
% Integers and reals represent themselves; strings are other data that
|
|
|
172 |
% appears in the CharString; names are CharString operator names.
|
|
|
173 |
% A CharString in an array is called a "charproc"; a CharString on
|
|
|
174 |
% the stack is called a "charstack", and is delimited by a mark.
|
|
|
175 |
% Individual elements are called "chartokens".
|
|
|
176 |
|
|
|
177 |
% ------ Encoding ------ %
|
|
|
178 |
|
|
|
179 |
% Get the string for a chartoken.
|
|
|
180 |
% Note that this string may be overwritten by the next call.
|
|
|
181 |
/chartoken_string { % <chartoken> chartoken_string <string>
|
|
|
182 |
dup type Type1encode exch get exec
|
|
|
183 |
} bind def
|
|
|
184 |
% Compute the length of a CharString.
|
|
|
185 |
/chartoken_length { % <chartoken> chartoken_length <length>
|
|
|
186 |
chartoken_string length
|
|
|
187 |
} bind def
|
|
|
188 |
/charproc_length { % <charproc> charproc_length <length>
|
|
|
189 |
|
|
|
190 |
} bind def
|
|
|
191 |
/charstack_length { % <charstack> charstack_length <charstack> <length>
|
|
|
192 |
counttomark 0 exch -1 1 { index chartoken_length add } for
|
|
|
193 |
} bind def
|
|
|
194 |
|
|
|
195 |
% Write a CharString to a file. Normally this will be a NullEncode filter
|
|
|
196 |
% writing on a string of the correct length.
|
|
|
197 |
/chartoken_write { % <file> <chartoken> chartoken_write -
|
|
|
198 |
chartoken_string writestring
|
|
|
199 |
} bind def
|
|
|
200 |
/charproc_write { % <file> <charproc> charproc_write -
|
|
|
201 |
{ 1 index exch chartoken_write } forall pop
|
|
|
202 |
} bind def
|
|
|
203 |
% Note that the arguments of charstack_write are backwards.
|
|
|
204 |
/charstack_write { % <charstack> <file> charstack_write -
|
|
|
205 |
counttomark 1 sub -1 1 { index 1 index exch chartoken_write } for
|
|
|
206 |
cleartomark
|
|
|
207 |
} bind def
|
|
|
208 |
|
|
|
209 |
% Convert a charproc or charstack to an *un*encrypted CharString.
|
|
|
210 |
/charproc_string { % <charproc> charproc_string <string>
|
|
|
211 |
mark exch aload pop charstack_string
|
|
|
212 |
} bind def
|
|
|
213 |
/charstack_string { % <charstack> charstack_string <string>
|
|
|
214 |
charstack_length lenIV 0 gt {
|
|
|
215 |
lenIV add string
|
|
|
216 |
dup dup length lenIV sub lenIV exch getinterval % skip lenIV
|
|
|
217 |
} {
|
|
|
218 |
string
|
|
|
219 |
} ifelse
|
|
|
220 |
/NullEncode filter
|
|
|
221 |
exch 1 index counttomark 1 add 2 roll
|
|
|
222 |
charstack_write closefile
|
|
|
223 |
% lenIV 0 ge { 4330 exch dup .type1encrypt exch pop readonly } if
|
|
|
224 |
} bind def
|
|
|
225 |
|
|
|
226 |
% ------ Decoding ------ %
|
|
|
227 |
|
|
|
228 |
% Decode a CharString (unencrypted).
|
|
|
229 |
/charstack_read { % <file> charstack_read <no-mark-charstack>
|
|
|
230 |
{ dup read not { pop exit } if
|
|
|
231 |
Type1decode 1 index get dup null eq {
|
|
|
232 |
pop 1 string dup 0 4 -1 roll put
|
|
|
233 |
} {
|
|
|
234 |
exch pop exec
|
|
|
235 |
} ifelse exch
|
|
|
236 |
} loop
|
|
|
237 |
} bind def
|