File: gs_type1.ps

package info (click to toggle)
ghostscript 8.71~dfsg2-9+squeeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 79,896 kB
  • ctags: 80,654
  • sloc: ansic: 501,432; sh: 25,689; python: 4,853; cpp: 3,633; perl: 3,597; tcl: 1,480; makefile: 1,187; lisp: 407; asm: 284; xml: 263; awk: 66; csh: 17; yacc: 15
file content (236 lines) | stat: -rw-r--r-- 8,285 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
%    Copyright (C) 1994, 2000 Aladdin Enterprises.  All rights reserved.
% 
% This software is provided AS-IS with no warranty, either express or
% implied.
% 
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
% 
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.

% $Id: gs_type1.ps 9792 2009-06-13 14:33:18Z alexcher $
% Type 1 font support code.

% The standard representation for PostScript compatible fonts is described
% in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.

/t1_glyph_equivalence mark   % Exported for pf2afm.ps
  /Odblacute /Ohungarumlaut
  /Udblacute /Uhungarumlaut
  /odblacute /ohungarumlaut
  /udblacute /uhungarumlaut
.dicttomark def

% Define an augmented version of .buildfont1 that inserts UnderlinePosition
% and UnderlineThickness entries in FontInfo if they aren't there already,
% and FontBBox isn't degenerate.
% (This works around the incorrect assumption, made by many word processors,
% that these entries are present in the built-in fonts.)
% Also add alternative names to some glyphs.
/.buildfont1
 {
   .currentglobal 3 1 roll
   dup .gcheck .setglobal
   dup .fontbbox {
     pop pop pop pop
     dup /FontInfo known not
      { .growfontdict dup /FontInfo 2 dict put }
     if
     dup dup /FontInfo get dup dup
     /UnderlinePosition known exch /UnderlineThickness known and
      { pop pop		% entries already present
      }
      { dup length 2 add dict .copydict
        dup /UnderlinePosition known not
         { dup /UnderlinePosition 3 index /FontBBox get
           1 get 2 div put 			% 1/2 the font descent
         }
        if
        dup /UnderlineThickness known not
         { dup /UnderlineThickness 3 index /FontBBox get
           dup 3 get exch 1 get sub 20 div put 	% 1/20 the font height
         }
        if
        1 index /FontInfo get wcheck not { readonly } if
        /FontInfo exch put
      }
     ifelse
   } if
   dup /CharStrings get dup dup
   //t1_glyph_equivalence {     % <<>> <<>> <<>> /gl1 /gl2
     2 index 2 index known {
       2 index 1 index known {
         pop pop
       } {
         3 1 roll get //.growput superexec dup dup
       } ifelse
     } {
       2 index 1 index known {
         exch 3 1 roll get //.growput superexec dup dup
       } {
         pop pop
       } ifelse
     } ifelse  
   } forall
   pop pop pop

   //.buildfont1
   3 2 roll .setglobal
 } bind def

% If the diskfont feature isn't included, define a dummy .loadfontdict.
/.loadfontdict where
 { pop }
 { /.loadfontdict 0 dict readonly def }
ifelse
/.loadfontfile		% <file> .loadfontfile -
 { mark exch
   DISKFONTS { .loadfontdict begin } if
	% In order to load fonts reliably, we should push systemdict
	% here.  However, Ed Taft says that Adobe implementations
	% push userdict and nothing else!
	% We really would just like systemdict on the stack,
	% but fonts produced by Fontographer require a writable dictionary.
	% However, we can't use any of the other well-known dictionaries
	% (such as userdict), since the whole point of pushing systemdict
	% is to make sure that nothing important has been redefined.
   /userdict .systemvar begin
	% We can't just use `run', because we want to check for .PFB files.
   currentpacking
    { //false setpacking .loadfont1 //true setpacking }
    { .loadfont1 }
   ifelse end
    { stop } if
   DISKFONTS { end } if
   cleartomark
 } bind def
 % container for CloseSource flag (default //true to prevent buildup of file handles)
 /closesourcedict mark
   /CloseSource //true
 .dicttomark readonly def
/.loadfont1 {		% <file> .loadfont1 <errorflag>
  {	% We would like to use `false /PFBDecode filter',
	% but this occasionally produces a whitespace character as
	% the first of an eexec section, so we can't do it.
	% Also, since the real input file never reaches EOF if we are using
	% a PFBDecode filter (the filter stops just after reading the last
	% character), we must explicitly close the real file in this case.
	% Since the file might leave garbage on the operand stack,
	% we have to create a procedure to close the file reliably.
    dup read not { -1 } if
    2 copy unread 16#80 eq {
	dup //closesourcedict //true /PFBDecode filter cvx
	exch .currentresourcefile eq {
	  dup /.execasresource .systemvar
	} {
	  {exec}
	} ifelse
	2 index cvlit
	/closefile .systemvar 3 .execn
      } {
	cvx exec
    } ifelse
  } stopped
} bind def
% undefine a dict that is only used internally, and is immediately bound
currentdict /closesourcedict .undef

% Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
% The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
% The real work is done in an operator:
%	<font> <code|name> <name> <charstring> .type1execchar -

(%Type1BuildChar)  cvn {	% <font> <code> %Type1BuildChar -
  1 index /Encoding get 1 index get .type1build .type1execchar
} bind def
(%Type1BuildGlyph) cvn {	% <font> <name> %Type1BuildGlyph -
  dup .type1build .type1execchar
} bind def
% Note: this procedure is used for both Type 1 and Type 2 fonts.
/.type1build {		% <font> <code|name> <name> .type1build
			%   <font> <code|name> <name> <charstring>
  2 index begin
    dup CharStrings exch .knownget not {
      2 copy eq { exch pop /.notdef exch } if
       QUIET not
	{ (Substituting .notdef for ) print
	  =string cvs print ( in the font ) print
	  1 index /FontName get = flush
	}
	{ pop }
       ifelse
       /.notdef CharStrings /.notdef get
    } if
  end
} bind def

1183615869 internaldict begin
% CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
% Apparently there are two different argument lists for CCRun.
% Handling the one with the extra Private dictionary requires fabricating
% a Type 1 font on the fly, since we aren't currently prepared to parse the
% dictionary any other way.
/CCRun {	% <font> <code|name> <charstring> CCRun -
		% <font> <code|name> <charstring> <Private> CCRun -
  dup type /dicttype eq {
    dup 4 index /Private .knownget { ne } { pop //true } ifelse {
		% The Private dictionary was supplied, and is different
		% from the Private dictionary of the font.  Fabricate a
		% Type 1 font with this Private dictionary.  Most of the
		% font entries are arbitrary or not needed.
      .currentglobal //false .setglobal 10 dict exch .setglobal begin
	/Private exch def
	/FontType 1 def
	/FontMatrix 3 index /FontMatrix get def
	/Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
	/FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
	/PaintType 0 def
	/CharStrings 1 dict dup /.notdef () put def
      3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
    } {
      pop
    } ifelse
  } if
  1 index dup type /integertype eq {
    3 index /Encoding get exch get
  } if exch .type1execchar
} bind def

% setweightvector is an undocumented procedure that force writes
% weight vector to the font. Do extra checks for safety.
/setweightvector { % <font> <vector> setweightvector -
  dup type dup /arraytype ne exch /packedarraytype ne and
  2 index type /dicttype ne or {
    /setweightvector cvx /typecheck signalerror
  } if
  1 index /FontType known not {
    /setweightvector cvx /invalidfont signalerror
  } if
  dup gcheck 2 index gcheck not and {
    /setweightvector cvx /invalidaccess signalerror
  } if
  2 copy /WeightVector exch .forceput
  .setweightvector
} .bind executeonly def 
end

% Register the font types for definefont.
buildfontdict 1 /.buildfont1 cvx put
buildfontdict 4 /.buildfont4 cvx put

% Add Type 2 support if applicable.
/.buildfont2 where not { (%END2) .skipeof } if
pop
(%Type2BuildChar)  cvn {	% <font> <code> %Type2BuildChar -
  1 index /Encoding get 1 index get .type1build .type2execchar
} bind def
(%Type2BuildGlyph) cvn {	% <font> <name> %Type2BuildGlyph -
  dup .type1build .type2execchar
} bind def
buildfontdict 2 /.buildfont2 cvx put
%END2