Debian Codegraph @

texmf-dist/fonts/source/public/bbold/bbbase.mf

raw
1 % Blackboard bold base file, containing lots of horrible hacks.
2 % Alan Jeffrey, 12--18 Dec 1989.
3
4 % DIGITIZATION
5
6 % I'm doing all my own digitization, so I don't need help from MF.
7 autorounding := 0;
8
9 % To get the unsharp version of x#, say unsharp x#.
10 def unsharp = hppp * enddef;
11
12 % The only pen I'm working with is of size pen_size. This makes life
13 % rather easier. To find the x-coordinate whose left-hand edge is
14 % at hround x, say leftround x, and similarly for rightround,
15 % topround and bottomround.
16 def leftround expr x = hround x + 1/2 pen_size enddef;
17 def rightround expr x = hround x - 1/2 pen_size enddef;
18 def topround expr y = vround y - 1/2 pen_size enddef;
19 def bottomround expr y = vround y + 1/2 pen_size enddef;
20
21 % Using this, I can give the equivalent of define_whole_pixels...
22 def define_whole_top_pixels (text t) =
23 forsuffixes $ = t:
24 $ := topround unsharp $.#;
25 endfor
26 enddef;
27
28 def define_whole_bottom_pixels (text t) =
29 forsuffixes $ = t:
30 $ := bottomround unsharp $.#;
31 endfor
32 enddef;
33
34 % POINTS
35
36 % The point y~x is short for (x,y). The reason for switching the
37 % points around is that I find it easier to say Top~Left than
38 % (Left, Top).
39 primarydef x ~ y = (y,x) enddef;
40
41 % To find the average of two points, say p -+- q.
42 primarydef x ~ y = (y,x) enddef;
43 tertiarydef x -+- y = .5[x,y] enddef;
44
45 % To get the point 1/2fatness above p, say above p. This is useful
46 % for drawing lines fatness in width. Similarly we have commands
47 % below, leftof and rightof.
48 def above secondary p =
49 p + 1/2fatness * up
50 enddef;
51
52 def below secondary p =
53 p + 1/2fatness * down
54 enddef;
55
56 def leftof secondary p =
57 p + 1/2fatness * left
58 enddef;
59
60 def rightof secondary p =
61 p + 1/2fatness * right
62 enddef;
63
64 % The command farleftof is equivalent to leftof leftof, and similarly
65 % farrightof.
66 def farleftof secondary p =
67 p + fatness * left
68 enddef;
69
70 def farrightof secondary p =
71 p + fatness * right
72 enddef;
73
74 % To get curves with o-correction, we need to be able to move
75 % o pixels up or down.
76 def oabove secondary p =
77 p + o * up
78 enddef;
79
80 def obelow secondary p =
81 p + o * down
82 enddef;
83
84 % DECLARATIONS
85
86 % To declare a new variable foo of type T, say var (T) foo.
87 def var (text type) text declarations =
88 save declarations;
89 type declarations
90 enddef;
91
92 % PATHS
93
94 % Given a cyclic path p, outline p draws the path and fills the inside
95 % with white. This is stolen from the MF book, exercise 13.11.
96 def outline expr c =
97 begingroup
98 picture region;
99 region := nullpicture;
100 interim turningcheck := 0;
101 addto region contour c;
102 cull region dropping (0,0);
103 cullit;
104 addto currentpicture also -region;
105 cullit;
106 draw c
107 endgroup
108 enddef;
109
110 % Given a path p, leftside p is the path 1/2 fatness to its left,
111 % and similarly rightside.
112 def leftside primary apath =
113 apath shifted (1/2fatness * left)
114 enddef;
115
116 def rightside primary apath =
117 apath shifted (1/2fatness * right)
118 enddef;
119
120 % Given a path p, fatten p draws the leftside of p,
121 % the rightside of p, and joins them up with straight lines.
122 def fatten expr apath =
123 leftside apath
124 -- (reverse rightside apath)
125 -- cycle
126 enddef;
127
128 % Given a point p, splodge p draws an o-corrected circle of radius
129 % fatness around p.
130 def splodge expr apoint =
131 above apoint + o*up {right}
132 .. rightof apoint + o*right {down}
133 .. below apoint + o*down {left}
134 .. leftof apoint + o*left {up}
135 .. cycle
136 enddef;
137
138 % The command splodgel does the same, but doesn't close the cycle,
139 % and leaves the current point at the left of the circle.
140 def splodgel tertiary apoint =
141 leftof apoint + o*left {up}
142 .. above apoint + o*up {right}
143 .. rightof apoint + o*right {down}
144 .. below apoint + o*down {left}
145 .. leftof apoint + o*left {up}
146 enddef;
147
148 % Similarly, splodger leaves the current point at the right of the
149 % circle.
150 def splodger tertiary apoint =
151 rightof apoint + o*right {down}
152 .. below apoint + o*down {left}
153 .. leftof apoint + o*left {up}
154 .. above apoint + o*up {right}
155 .. rightof apoint + o*right {down}
156 enddef;
157
158 % CLIPPING
159
160 % sometime (p, q) gives the time along p when it intersects q.
161 def sometime (expr apath, bpath) =
162 xpart (apath intersectiontimes bpath)
163 enddef;
164
165 % othertime (p, q) gives another time at which p intersects q.
166 def othertime (expr apath, bpath) =
167 length apath - sometime (reverse apath) (reverse bpath)
168 enddef;
169
170 % firsttime (p, q) gives the smallest of sometime (p,q) and othertime (p,q).
171 def firsttime (expr apath, bpath) =
172 min (sometime (apath) (bpath), othertime (apath) (bpath))
173 enddef;
174
175 % lasttime (p, q) gives the largest of the two times.
176 def lasttime (expr apath, bpath) =
177 max (sometime (apath) (bpath), othertime (apath) (bpath))
178 enddef;
179
180 % We can then clip p with q by finding the subpath of p from 0 to
181 % the time p intersects q.
182 def cliponce (expr apath, clippath) =
183 subpath (0, sometime (apath) (clippath)) of apath
184 enddef;
185
186 % Similarly, if p intersects q twice, we can find the path between
187 % the two times it intersects with cliptwice.
188 def cliptwice (expr apath, clippath) =
189 subpath
190 (firsttime (apath) (clippath), lasttime (apath) (clippath))
191 of apath
192 enddef;
193
194 % Given a path p and two paths q and r which intersect p,
195 % we can find the path between when p crosses q and when p crosses r.
196 % someclipbetween (p, q, r) will always start at q and finish at r.
197 def someclipbetween (expr apath, firstclip, secondclip) =
198 subpath
199 (sometime (apath) (firstclip),
200 sometime (apath) (secondclip))
201 of
202 apath
203 enddef;
204
205 % firstclipbetween does the same, but if p intersects q and r more
206 % than once, it gives the first clipping.
207 def firstclipbetween (expr apath, firstclip, secondclip) =
208 subpath
209 (firsttime (apath) (firstclip),
210 firsttime (apath) (secondclip))
211 of
212 apath
213 enddef;
214
215 % lastclipbetween gives the last clipping.
216 def lastclipbetween (expr apath, firstclip, secondclip) =
217 subpath
218 (lasttime (apath) (firstclip),
219 lasttime (apath) (secondclip))
220 of
221 apath
222 enddef;
223
224 % We can join these together and clip fat lines.
225 def fatcliponce (expr apath, clippath) =
226 cliponce (leftside apath) (clippath)
227 -- someclipbetween (clippath) (leftside apath) (rightside apath)
228 -- reverse cliponce (rightside apath) (clippath)
229 -- cycle
230 enddef;
231
232 def fatcliptwice (expr apath, clippath) =
233 cliptwice (leftside apath) (clippath)
234 -- lastclipbetween (clippath) (leftside apath) (rightside apath)
235 -- cliptwice (rightside apath) (reverse clippath)
236 -- firstclipbetween (clippath) (rightside apath) (leftside apath)
237 -- cycle
238 enddef;
239
240 % BBCHAR.
241
242 % bbchar (c) (l#, w#, r#) (t#, b#) begins a character at code c,
243 % of width w# with l# gap at the left and r# gap at the right.
244 % It's topmost point is at t# and its bottommost point at b#.
245 % From these parameters we calculate Width (the width of the character
246 % in whole pixels) and hardTop and hardBottom (the exact top and bottom
247 % of the character). Top is then 1/2 pensize from the top of the character,
248 % and Bottom is 1/2 pensize from the bottom. This means if we draw a line
249 % through top, the top of it will exactly touch the top. We then calculate
250 % Left, Middle, and Right in the same way, using calculateLeftetc.
251
252 def bbchar
253 (expr code)
254 (expr sharphardLeft, sharpWidth, sharprightgap)
255 (expr sharphardTop, sharphardBottom) =
256
257 beginchar
258 (code)
259 (sharphardLeft + sharpWidth + sharprightgap)
260 (max (sharphardTop, 0pt#))
261 (max (-sharphardBottom, 0pt#));
262
263 save Top, Bottom, Horizon, hardTop, hardBottom,
264 Width, hardLeft, hardRight, Left, Right, Middle;
265
266 hardTop# = sharphardTop;
267 hardBottom# = sharphardBottom;
268 Width# = sharpWidth;
269 hardLeft# = sharphardLeft;
270 hardRight# = sharphardLeft + sharpWidth;
271
272 define_whole_pixels (Width);
273 define_whole_vertical_pixels (hardTop, hardBottom);
274 Top = topround hardTop;
275 Bottom = bottomround hardBottom;
276
277 Horizon = .5 [Top, Bottom];
278
279 calculateLeftetc;
280
281 pickup pencircle scaled pen_size;
282
283 enddef;
284
285 def calculateLeftetc =
286 hardLeft := floor (unsharp hardLeft#);
287 hardRight := hardLeft + Width;
288
289 Left := (hardLeft + 1/2pen_size);
290 Middle := (hardLeft + 1/2Width);
291 Right := (hardRight - 1/2pen_size);
292 enddef;
293
294 % bbcap is bbchar with the top at ATop# and the bottom at aBottom#.
295 def bbcap (expr code, leftgap, width, rightgap) =
296 bbchar (code) (leftgap, width, rightgap) (ATop#, aBottom#);
297 enddef;
298
299 % bbnum is bbchar with the dimensions of a number hard-wired.
300 def bbnum (expr code) =
301 bbchar (code) (medgap#, numeral#, medgap#) (oneTop#, aBottom#);
302 enddef;
303
304 % For characters such as < and > which appear a lot blacker than the
305 % others, we can surround the character by beginblacker n ... endblacker,
306 % which temporarily multiplies fatness by n.
307 def beginblacker expr blackness =
308 begingroup
309 save oldfatness;
310 oldfatness# := fatness#;
311 save fatness;
312 fatness# := oldfatness# * blackness;
313 define_whole_pixels (fatness)
314 enddef;
315
316 let endblacker = endgroup;
317
318 % SYMMETRY
319
320 % To try to get characters symmetric, we need to round the width so there
321 % are the same number of characters on the left of the central vertical
322 % as there are on the right. So if we are symmetrical around a pen of
323 % size 2n, we need to make the width even. If we are symmetrical around
324 % a pen of size 2n+1 we need to make the width odd. This is done with
325 % roundlike (x) y, which rounds y to be even iff x is even.
326
327 def roundlike (expr x) expr y =
328 2 * (round (x -+- y)) - x
329 enddef;
330
331 % To make the character symmetric, we round Width like pen_size.
332 def symmetric =
333 Width := roundlike (pen_size) unsharp Width#;
334 calculateLeftetc
335 enddef;
336
337 % To make the character symmetric around a fat vertical, we round
338 % Width like fatness + pen_size.
339 def fatsymmetric =
340 Width := roundlike (fatness + pen_size) unsharp Width#;
341 calculateLeftetc
342 enddef;
343
344 % DRAWING THE CHARACTERS ON THE SCREEN
345
346 % makebox and maketicks nicked from cmbase, adjusted for this job.
347
348 def makebox(text rule) =
349 for y=0, hardBottom, hardTop:
350 rule((0,y)t_,(w,y)t_); endfor % horizontals
351 for x=0,hardLeft,hardRight,w:
352 rule((x,hardBottom)t_,(x,hardTop)t_); endfor % verticals
353 enddef;
354
355 def maketicks(text rule) =
356 for y=0, hardBottom, hardTop:
357 rule((-10,y)t_,(0,y)t_); % horizontals at left
358 rule((w,y)t_,(w+10,y)t_); % horizontals at right
359 endfor
360 for x=0,hardLeft,hardRight,w:
361 rule((x,hardBottom-10)t_,(x,hardBottom)t_); % verticals at bottom
362 rule((x,hardTop)t_,(x,hardTop+10)t_); % verticals at top
363 endfor % verticals at top
364 enddef;
365
366 % HACKS TO MAKE CMR WORK
367
368 % Some parameters I never use, but are needed by the cmr parameter files.
369 boolean
370 square_dots, hefty, serifs, monospace,
371 variant_g, low_asterisk, math_fitting;
372
373 % And that's that.
374