summaryrefslogtreecommitdiff
path: root/dviware/dvitops/timessc.ps
blob: ec6dd671364f6ad78c6f9a734a75e3067b8b1496 (plain)
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
%!
% $Header: /usr/jjc/dvitops/RCS/timessc.ps,v 1.1 89/02/01 09:24:29 jjc Rel $
% implements Times-SmallCaps

/scdict 25 dict def

scdict begin

/buf 256 string def

% c islower - bool

/islower { %def
	dup 8#141 ge exch 8#172 le and
} bind def


% c toupper - c

/toupper { %def
	dup islower { %if
		8#40 sub
	} if
} bind def

% string proc mapstring - string

/mapstring {
	cvx /proc exch def
	/s exch def
	0 1 s length 1 sub { 
		dup s exch get proc s 3 1 roll put
	} for
	s 
} bind def

/name1 256 string def
/name2 256 string def

/concatname { %def
	name2 cvs /s2 exch def
	name1 cvs /s1 exch def
	buf 0 s1 length s2 length add getinterval
	dup 0 s1 putinterval
	dup s1 length s2 putinterval
	cvn
} def
	
end	 %scdict

% oldname newname uniqueid MakeSmallCapsFont -

/MakeSmallCapsFont { % def
	scdict begin
	/uid exch def
	/newname exch def
	findfont /olddict exch def
	/cs olddict /CharStrings get def

	% build enc and data from cs
	/enc 256 array def
	0 1 255 { %for
		enc exch /.notdef put
	} for
	/i 1 def
	/data cs length dict def
	cs { % forall
		pop
		/c exch def
		c buf cvs dup dup 0 get toupper 0 exch put cvn /C exch def
		cs C known c C ne and { % ifelse (if)
			data c C put
		} {	% ifelse (else)
			c buf cvs /toupper mapstring cvn /C exch def
			cs C known c C ne and { % ifelse (if)
				data c C put
			} { % ifelse (else)
				data c i put
				enc i c put
				/i i 1 add def
			} ifelse
		} ifelse
	} forall
	data /.notdef 0 put

	% reencode the base font
	/basename /$!# newname concatname def
	basename
	olddict maxlength dict begin
		olddict { % forall
			exch dup dup /FID ne exch /Encoding ne and { % ifelse (if)
				exch def
			} { % ifelse (else)
				pop pop 
			} ifelse
		} forall
		/Encoding enc def
		/FontName basename def
	currentdict end
	definefont pop

	20 dict begin
		/UniqueID uid def
		[/FontInfo /FontBBox /Encoding] { %forall
			dup olddict exch get def
		} forall
		/CharStrings data def
		/FontMatrix matrix def
		/FontName newname def
		/BaseFont basename findfont def
		/XScale .9 def
		gsave
			initgraphics % this is necessary; I don't understand why
			olddict setfont
			newpath 0 0 moveto
			(X) true charpath flattenpath pathbbox 4 1 roll pop pop pop
			dup
			3 div
			newpath 0 0 moveto
			(x) true charpath flattenpath pathbbox 4 1 roll pop pop pop
			2 mul 3 div
			add
			exch div
			/YScale exch def
		grestore
		/SmallBaseFont BaseFont [XScale 0 0 YScale 0 0] makefont def
		/OneCharString 1 string def
		/FontType 3 def
		/Widths 256 array def
		gsave
			initgraphics % this is necessary; I don't understand why
			BaseFont setfont 0 0 moveto
			0 1 255 { % for
				dup
				OneCharString 0 3 -1 roll put 
				OneCharString stringwidth pop
				Widths
				3 1 roll
				put
			} for
		grestore
		/BuildChar { % def
			exch begin
			Encoding exch get CharStrings exch get
			dup type /integertype eq { % ifelse (if)
				dup Widths exch get 0 setcharwidth
				BaseFont setfont
			} { % ifelse (else)
				CharStrings exch get
				dup Widths exch get XScale mul 0 setcharwidth
				SmallBaseFont setfont
			} ifelse
			0 0 moveto
			OneCharString 0 3 -1 roll put
			OneCharString show
			end
		} bind def
	currentdict end
	newname exch definefont pop
	end
} bind def

/Times-Roman /Times-SmallCaps 1573 MakeSmallCapsFont