Debian Codegraph @

texmf-dist/fonts/source/public/fdsymbol/fdbase.mf

raw
1 %
2 % Copyright (c) 2011-2025, Michael Ummels <[email protected]>
3 %
4 % This Font Software is licensed under the SIL Open Font License,
5 % Version 1.1. This license is in the accompanying file OFL.txt, and
6 % is also available with a FAQ at: http://scripts.sil.org/OFL
7 %
8
9 design_size := 10;
10 font_size design_size * pt#;
11
12 if known ps_output:
13 font_version := "1.010";
14 font_comment := "Copyright (c) 2011-2025, Michael Ummels. This Font Software is licensed under the SIL Open Font License, Version 1.1.";
15 fi
16
17 u# := 0.6pt#;
18 asc_height# := 7.54pt#; % 8.56pt#;
19 cap_height# := 7.07pt#; %7.37pt#;
20 desc_depth# := 2.2pt#; % 2.94pt#;
21 x_height# := 5.46pt#;
22 math_axis# := 3.0pt#;
23 if weight_index = 0: % Book
24 line_thickness# := 0.64pt#;
25 rule_thickness# := 0.56pt#;
26 dot_size# := 0.75pt#;
27 equal_spread# := 1.8pt#;
28 elseif weight_index = 1: % Demi
29 line_thickness# := 0.74pt#;
30 rule_thickness# := 0.58pt#;
31 dot_size# := 0.84pt#;
32 equal_spread# := 1.9pt#;
33 elseif weight_index = 2: % Medium
34 line_thickness# := 0.86pt#;
35 rule_thickness# := 0.6pt#;
36 dot_size# := 0.94pt#;
37 equal_spread# := 1.95pt#;
38 else: % Bold
39 line_thickness# := 1.0pt#;
40 rule_thickness# := 0.64pt#;
41 dot_size# := 1.06pt#;
42 equal_spread# := 1.99pt#;
43 fi;
44
45 side_bearing# := 1.5u#;
46 small_op_size# := 8u#; % radius of small operators
47 med_op_size# := 12.5u#; % radius of medium operators
48 plus_size# := 9u#;
49 large_op_size# := 18u#; % radius of large operators
50 order_width# := 8u#; % width of equal sign
51 turnstile_width# := 11u#; % width of turnstile symbols
52 greater_spread# := 10/4equal_spread#; % distance between the ends of the greater sign
53 arrow_horiz_len# := 12.5u#; % length of horizontal arrows
54 arrow_vert_len# := 12.5u#; % length of vertical arrows
55 arrow_diag_len# := 1/2(arrow_horiz_len# + arrow_vert_len#);
56 arrow_spread# := 1.6equal_spread#;
57 delim_height# := 5.3pt#; % half the height of normal delimiters
58 bigop_height# := 10.7pt#; % height of big operators
59
60 mode_setup;
61
62 define_pixels(u, asc_height, cap_height, desc_depth, delim_height, bigop_height, x_height);
63 define_whole_pixels(dot_size, small_op_size, med_op_size, large_op_size, plus_size,
64 order_width, turnstile_width, equal_spread, greater_spread,
65 arrow_horiz_len, arrow_vert_len, arrow_diag_len, arrow_spread);
66
67 if known ps_output:
68 define_pixels(math_axis, line_thickness, rule_thickness, side_bearing);
69 else:
70 math_axis := good.y(math_axis# * hppp);
71 line_thickness := ceiling(line_thickness# * hppp);
72 rule_thickness := ceiling(rule_thickness# * hppp);
73 side_bearing := ceiling(side_bearing# * hppp);
74 fi
75
76 stroke_through_thickness := 9/10line_thickness;
77
78 % Macros
79
80 % Redefine clockwise and counterclockwise (turningnumber seems more stable)
81 if known ps_output:
82 vardef counterclockwise primary p =
83 (if turningnumber p>0: p else: (reverse p) fi)
84 enddef;
85
86 vardef clockwise primary p =
87 (if turningnumber p<0: p else: (reverse p) fi)
88 enddef;
89 fi
90
91 % Selects the n-th element of a list
92 def select(expr n)(text values) =
93 begingroup;
94 i := 0;
95 for v = values:
96 result := v;
97 exitif i = n;
98 i := i + 1;
99 endfor;
100 result
101 endgroup
102 enddef;
103
104 % Splits a length at the math axis
105 def vcentre(expr size) =
106 size/2 + math_axis#, size/2 - math_axis#
107 enddef;
108
109 current_char := -1;
110
111 def beginsymbol(expr width, height, depth) =
112 current_char := current_char + 1;
113 beginchar(current_char, width, height, depth);
114 if not known ps_output:
115 proofrule((side_bearing, math_axis),(w - side_bearing, math_axis));
116 proofrule((side_bearing, h),(side_bearing, -d));
117 proofrule((w - side_bearing, h),(w - side_bearing, -d));
118 fi
119 enddef;
120
121 def beginoperator(expr size, ratio) =
122 beginsymbol(size + 2side_bearing#, vcentre(ratio * size));
123 pair centre;
124 centre := (w/2, (h-d)/2);
125 radius := w/2 - side_bearing - 1/2line_thickness;
126 enddef;
127
128 def beginbigop(expr xscale, yscale) =
129 beginsymbol(xscale * 3/2order_width# + 2side_bearing#, vcentre(yscale * bigop_height#));
130 pair centre;
131 centre := (w/2, (h-d)/2);
132 op_width := xscale * 3/2order_width;
133 op_height := yscale * bigop_height;
134 enddef;
135
136 def beginsquarebigop(expr xscale, yscale) =
137 beginsymbol(xscale * bigop_height# + 2side_bearing#, vcentre(yscale * bigop_height#));
138 pair centre;
139 centre := (w/2, (h-d)/2);
140 op_width := xscale * bigop_height;
141 op_height := yscale * bigop_height;
142 enddef;
143
144 def beginarrow(expr angle, scale, spread) =
145 arrow_len# := scale *
146 if angle mod 180 = 0: arrow_horiz_len#
147 elseif angle mod 180 = 90: arrow_vert_len#
148 else: arrow_diag_len#
149 fi;
150 arrow_len := scale *
151 if angle mod 180 = 0: arrow_horiz_len
152 elseif angle mod 180 = 90: arrow_vert_len
153 else: arrow_diag_len
154 fi;
155
156 beginsymbol(arrow_len# * abs(cosd(angle)) + (spread + line_thickness#) * abs(sind(angle)) + 2side_bearing#, vcentre(arrow_len# * abs(sind(angle)) + (spread + line_thickness#) * abs(cosd(angle))));
157 pair centre, head, head_ex, foot, foot_ex;
158
159 centre := (w/2, (h-d)/2);
160 head := centre + (arrow_len - line_thickness)/2 * dir angle;
161 head_ex := centre + arrow_len/2 * dir angle;
162 foot := centre - (arrow_len - line_thickness)/2 * dir angle;
163 foot_ex := centre - arrow_len/2 * dir angle;
164 enddef;
165
166 def beginorder(expr sign, width, spread) =
167 beginsymbol(width + 2side_bearing#, vcentre(spread + line_thickness#));
168 pair centre, left_ex, right_ex, left_point, right_point;
169 centre := (w/2, (h-d)/2);
170 left_ex := centre - sign * (w/2 - side_bearing) * right;
171 left_point := centre - sign * (w/2 - side_bearing - line_thickness/2) * right;
172 right_ex := centre + sign * (w/2 - side_bearing) * right;
173 right_point := centre + sign * (w/2 - side_bearing - line_thickness/2) * right;
174 enddef;
175
176 def beginturnstile(expr angle, scale) =
177 beginsymbol(abs(sind(angle) + scale * cosd(angle)) * turnstile_width# + 2side_bearing#, abs(min(scale, 1 + (scale - 1)/2) * sind(angle) + cosd(angle)) * cap_height#, abs(max(0, (scale - 1)/2) * sind(angle)) * cap_height#);
178 pair foot;
179
180 if angle mod 180 = 0:
181 len := scale * turnstile_width;
182 spread := cap_height - line_thickness;
183 else:
184 len := scale * cap_height;
185 spread := turnstile_width - line_thickness;;
186 fi
187 foot = (w/2, (h - d)/2) - (len - line_thickness)/2 * dir angle;
188 enddef;
189
190 % Strokes a pen path
191 vardef stroke text t =
192 forsuffixes e = l, r:
193 path_.e := t;
194 endfor
195 path_.r -- reverse path_.l -- cycle
196 enddef;
197
198 % Shapes
199
200 def circle(expr centre, radius) =
201 (centre + radius * right){up} ...
202 (centre + radius * dir 45){dir 135} ...
203 (centre + radius * up){left} ...
204 (centre + radius * dir 135){dir 225} ...
205 (centre + radius * left){down} ...
206 (centre + radius * dir 225){dir 315} ...
207 (centre + radius * down){right} ...
208 (centre + radius * dir 315){dir 45} ...
209 cycle
210 enddef;
211
212 def square(expr centre, radius, angle) =
213 (centre + sqrt(2) * radius * dir (angle + 45)) --
214 (centre + sqrt(2) * radius * dir (angle + 135)) --
215 (centre + sqrt(2) * radius * dir (angle + 225)) --
216 (centre + sqrt(2) * radius * dir (angle + 315)) --
217 cycle
218 enddef;
219
220 def triangle(expr centre, radius, angle) =
221 (centre + radius * dir angle) --
222 (centre + radius * dir (angle + 120)) --
223 (centre + radius * dir (angle + 240)) --
224 cycle
225 enddef;
226
227 def reg_poly_points(suffix $)(expr n, centre, radius, angle) =
228 for i = 0 upto n-1:
229 z$[i] = centre + radius * dir (angle + i/n * 360);
230 endfor;
231 enddef;
232
233 def dot(expr centre, radius) =
234 superellipse(centre + radius * right, centre + radius * up,
235 centre - radius * right, centre - radius * up, 0.6)
236 enddef;
237
238 % Draw macros
239
240 def draw_straight(expr orig, dest, thick, extend) =
241 begingroup;
242 pair p[].l, p[].r;
243
244 theta := angle (dest - orig);
245 if extend:
246 1/2[p1.l,p1.r] = orig - 1/2thick * dir theta;
247 1/2[p2.l,p2.r] = dest + 1/2thick * dir theta;
248 else:
249 1/2[p1.l,p1.r] = orig;
250 1/2[p2.l,p2.r] = dest;
251 fi
252 p1.l - p1.r = p2.l - p2.r = thick * dir (theta + 90);
253 fill stroke p1.e -- p2.e;
254 endgroup;
255 enddef;
256
257 def draw_line(expr orig, dest, extend) =
258 draw_straight(orig, dest, line_thickness, extend);
259 enddef;
260
261 def draw_circle(expr centre, radius, thick) =
262 fill circle(centre, radius + 1/2thick);
263 unfill circle(centre, radius - 1/2thick);
264 enddef;
265
266 def filldraw_circle(expr centre, radius, thick) =
267 fill circle(centre, radius + 1/2thick);
268 enddef;
269
270 def draw_square(expr centre, radius, angle, thick) =
271 fill square(centre, radius + 1/2thick, angle);
272 unfill square(centre, radius - 1/2thick, angle);
273 enddef;
274
275 def filldraw_square(expr centre, radius, angle, thick) =
276 fill square(centre, radius + 1/2thick, angle);
277 enddef;
278
279 def draw_triangle(suffix $)(expr centre, radius, angle, thick) =
280 fill triangle(centre, radius + thick, angle);
281 unfill triangle(centre, radius - thick, angle);
282 enddef;
283
284 def filldraw_triangle(suffix $)(expr centre, radius, angle, thick) =
285 fill triangle(centre, radius + thick, angle);
286 enddef;
287
288 def draw_sim(suffix $)(expr lc, rc, spread, thick) =
289 theta := angle (length(rc - lc), 10spread);
290 signum := cosd (angle (rc - lc)) + sind (angle (lc - rc));
291
292 z0$.l = lc;
293 z4$.r = rc;
294 z2$ = 1/2[lc, rc];
295 z4$.r = rc;
296 1/2[z1$,z3$] = z2$;
297 z1$ = 1/4[lc, rc] + 1/6thick * dir (angle (rc - lc)) +
298 signum * spread * dir (angle (rc - lc) + 90);
299
300 penpos0$(5/6thick, angle(rc - lc) - signum * (90 - theta));
301 penpos1$(thick, angle(rc - lc) - signum * 90);
302 penpos2$(thick, angle(rc - lc) - signum * (theta + 90 - 5));
303 penpos3$(thick, angle(rc - lc) - signum * 90);
304 penpos4$(5/6thick, angle(rc - lc) - signum * (90 - theta));
305
306 fill stroke z0$.e{dir (angle(rc - lc) + signum * theta)} .. {dir angle(rc - lc)}z1$.e .. {dir (angle(rc - lc) - signum * (theta - 5))}z2$.e .. {dir angle(rc - lc)}z3$.e .. {dir (angle(rc - lc) + signum * theta)}z4$.e;
307
308 penlabels(0$,1$,3$,4$);
309 enddef;
310
311 def draw_bump(suffix $)(expr sign, lc, rc, rad, thick) =
312 z0$ = lc;
313 z1$ = rc;
314 z2$ = 1/2[lc, rc] + sign * rad * dir (angle (rc - lc) + 90);
315 z3$ = 1/2[lc, rc] - rad * dir (angle (rc - lc));
316 1/2[z3$,z4$] = 1/2[lc, rc];
317
318 penpos0$(thick, angle (rc - lc) + sign * 90);
319 penpos1$(thick, angle (rc - lc) + sign * 90);
320 penpos2$(thick, angle (rc - lc) + sign * 90);
321 penpos3$(thick, angle (rc - lc));
322 penpos4$(thick, angle (rc - lc));
323
324 z5$ = z3$.r;
325 z6$ = z4$.l;
326
327 penpos5$(thick, angle (rc - lc) + sign * 90);
328 penpos6$(thick, angle (rc - lc) + sign * 90);
329
330 path p$, q$;
331 numeric s$, t$;
332
333 p$ = z3$.l{dir (angle(rc - lc) + sign * 90)} .. {rc - lc}z2$.r;
334 q$ = z2$.r{rc - lc} .. {dir (angle(rc - lc) - sign * 90)}z4$.r;
335 s$ = xpart (p$ intersectiontimes (z0$.r -- z1$.r));
336 t$ = xpart (q$ intersectiontimes (z0$.r -- z1$.r));
337
338 fill z0$.r -- point s$ of p$ & subpath (s$,1) of p$ & subpath (0,t$) of q$ & point t$ of q$ -- z1$.r -- z1$.l -- z6$l. -- z6${dir (angle (rc - lc) + sign * 90)} .. z2$.l{lc - rc} .. {dir (angle (rc - lc) - sign * 90)}z5$ -- z5$.l -- z0$.l -- cycle;
339
340 penlabels(0$,1$,2$,3$,4$,5$,6$);
341 enddef;
342
343 def draw_less(suffix $)(expr lc, rc, spread, thick, closed) =
344 theta := angle((length(rc - lc) - thick/2) * right + spread/2 * up);
345
346 z2$ = lc + 1/2thick * dir (angle (rc - lc));
347 1/2[z0$.r,z1$.r] = rc;
348 z0$ = z2$ + whatever * dir (angle (rc - lc) + theta);
349 z1$ = z2$ + whatever * dir (angle (rc - lc) - theta);
350
351 penpos0$(thick, angle(rc - lc) - 90 + theta);
352 penpos1$(thick, angle(rc - lc) + 90 - theta);
353 penpos3$(thick, angle(rc - lc) - 90 + theta);
354 penpos4$(thick, angle(rc - lc) + 90 - theta);
355
356 z3$.l = z0$.l + whatever * (z2$ - z0$);
357 z4$.l = z1$.l + whatever * (z2$ - z1$);
358 1/2[z3$.l,z4$.l] = lc;
359 z5$ = z0$.r + whatever * (z2$ - z0$);
360 z5$ = z1$.r + whatever * (z2$ - z1$);
361
362 fill z0$.l -- z3$.l -- z4$.l -- z1$.l -- z1$.r -- z5$ -- z0$.r -- cycle;
363
364 if closed:
365 penpos6$(thick, angle(rc - lc));
366 penpos7$(thick, angle(rc - lc));
367 z6$.l = whatever[z0$.l,z3$.l];
368 z6$.r = whatever[z0$.r,z1$.r];
369 z7$.l = whatever[z1$.l,z4$.l];
370 z7$.r = whatever[z0$.r,z1$.r];
371 fill z0$.l -- z6$.l -- z7$.l -- z1$.l -- z7$.r -- z6$.r -- cycle;
372 fi;
373
374 penlabels(0$,1$,3$,4$,5$,6$,7$);
375 enddef;
376
377 def draw_prec(suffix $)(expr lc, rc, spread, thick, closed) =
378 theta := 43;
379
380 z0$ - z1$ = spread * dir (angle (rc - lc) + 90);
381 1/2[z0$.r,z1$.l] = rc;
382 z2$ = lc;
383 z2$' = lc + 1/2thick * dir angle(rc - lc);
384
385 penpos0$(thick, angle(rc - lc) - theta);
386 penpos1$(thick, angle(rc - lc) + 180 + theta);
387 penpos2$(thick, angle(rc - lc) - 90);
388 penpos2$'(thick, angle(rc - lc) - 90);
389
390 fill stroke z2$.e -- z2$'.e{dir angle(rc - lc)} .. {dir (angle (rc - lc) + 90 - theta)}z0$.e;
391 fill stroke z2$.e -- z2$'.e{dir angle(rc - lc)} .. {dir (angle (rc - lc) - 90 + theta)}z1$.e;
392
393 if closed:
394 z3$ = point 1/2 of (z0${dir (angle (rc - lc) - 90 - theta + 10)}
395 .. {dir (angle (rc - lc) - 90 + theta - 10)}z1$);
396 penpos3$(thick, angle(rc - lc));
397
398 fill z0$.l .. z3$.l .. z1$.r -- z1$.l .. z3$.r .. z0$.r -- cycle;
399 fi;
400
401 penlabels(0$,1$,2$,3$);
402 enddef;
403
404 def draw_subset(suffix $)(expr lc, rc, spread, thick) =
405 1/2[z0$,z1$] = rc;
406 1/2[z2$,z3$] = (4spread / 9abs(rc - lc))[z4$, rc];
407 z0$ - z1$ = z2$ - z3$ = spread * dir (angle (rc - lc) + 90);
408 z4$ = lc + 1/2thick * dir (angle (rc - lc));
409
410 penpos0$(thick, angle(rc - lc) - 90);
411 penpos1$(thick, angle(rc - lc) + 90);
412 penpos2$(thick, angle(rc - lc) - 90);
413 penpos3$(thick, angle(rc - lc) + 90);
414 penpos4$(thick, angle(rc - lc));
415
416 fill stroke z0$.e -- z2$.e{lc - rc} .. z4$.e .. {rc - lc}z3$.e -- z1$.e;
417
418 penlabels(0$,1$,2$,3$,4$)
419 enddef;
420
421 def draw_smile(suffix $)(expr sign, lc, rc, spread, thick, round) =
422 z0$ = lc + sign * 1/2spread * dir (angle(rc - lc) + 90) +
423 whatever * (rc - lc);
424 z0$.l = lc + whatever * dir (angle(rc - lc) + 90);
425 z1$ = rc + sign * 1/2spread * dir (angle(rc - lc) + 90) +
426 whatever * (rc - lc);
427 z1$.l = rc + whatever * dir (angle(rc - lc) + 90);
428 z2$ = 1/2[lc,rc] - sign * 1/2spread * dir (angle(rc - lc) + 90);
429
430 if round:
431 theta := angle (length(lc - rc), 5spread);
432 else:
433 theta := angle (length(lc - rc), 2spread);
434 fi;
435
436 penpos0$(thick, angle(rc - lc) + sign * (90 - theta));
437 penpos1$(thick, angle(rc - lc) + sign * (90 + theta));
438
439 if round:
440 penpos2$(thick, angle(rc - lc) + sign * 90);
441
442 fill stroke z0$.e{dir (angle(rc - lc) - sign * theta)} ..
443 {rc - lc}z2$.e{rc - lc} .. {dir (angle(rc - lc) + sign * theta)}z1$.e;
444 else:
445 penpos2$(thick / cosd theta, angle(rc - lc) + sign * 90);
446
447 fill stroke z0$.e -- z2$.e -- z1$.e;
448 fi;
449
450 penlabels(0$, 1$, 2$);
451 enddef;
452
453 def stroke_through_angle(expr pos, spread, angle) =
454 begingroup;
455 stroke_len := 1/2spread / cosd (90 - angle);
456
457 draw_straight(pos + stroke_len * dir angle, pos - stroke_len * dir angle, stroke_through_thickness, true);
458 endgroup;
459 enddef;
460
461 def stroke_through(expr pos, spread) =
462 stroke_through_angle(pos, spread, 75);
463 enddef;
464
465 def stroke_through_arrow(expr pos, alpha, spread)(text angles) =
466 begingroup;
467 stroke_dir := alpha + select(alpha / 45)(angles);
468 stroke_len := 1/2spread / sind (stroke_dir - alpha);
469
470 draw_straight(pos + stroke_len * dir stroke_dir, pos - stroke_len * dir stroke_dir, stroke_through_thickness, true);
471 endgroup;
472 enddef;
473
474 def draw_product(expr centre, width, height, sign, thick, serifs) =
475 if serifs:
476 thicker := 11/8thick;
477 thinner := 5/8thick;
478 else:
479 thicker := 4/3thick;
480 thinner := thick;
481 fi
482
483 z1r - z0r = z3r - z2r = width * right;
484 y2r - y0l = sign * height;
485 x2r = x0r;
486 1/2[1/2[z0l,z1l], 1/2[z2r,z3r]] = centre;
487 z4 - z0 = z1 - z5 = min(3thicker, 2/5width) * right;
488 x6 = x8 = 1/2[x0,x4];
489 x7 = x9 = 1/2[x1,x5];
490 if serifs:
491 y6 - y0 = y7 - y1 = sign * 1/4(x4 - x0);
492 y2 - y8 = y3 - y9 = sign * 1/4(x4 - x0);
493 else:
494 y6 = y7 = y0l;
495 y8 = y9 = y2l;
496 fi
497
498 penpos0(thinner, sign * 100);
499 penpos1(thinner, sign * 80);
500 if serifs:
501 penpos2(thinner, sign * 93);
502 penpos3(thinner, sign * 87);
503 else:
504 penpos2(thicker, sign * 90);
505 penpos3(thicker, sign * 90);
506 fi
507 penpos4(thinner, sign * 80);
508 penpos5(thinner, sign * 100);
509 penpos6(thicker, 0);
510 penpos7(thicker, 0);
511 penpos8(thicker, 0);
512 penpos9(thicker, 0);
513
514 y10 = y11 = y2r - sign * 1/2[thinner,thicker];
515 x10 = x6r;
516 x11 = x7l;
517
518 if serifs:
519 fill z0l -- z4l -- z4r{dir (sign * 165)} ... {sign * up}z6r -- z10 -- z11 -- z7l{sign * down} ... {dir (-sign * 165)}z5r -- z5l -- z1l -- z1r{dir (sign * 165)} ... {sign * up}z7r -- z9r{sign * up} ... {dir (sign * 15)}z3l -- z3r -- z2r -- z2l{dir (-sign * 15)} ... {sign * down}z8l -- z6l{sign * down} ... {dir (-sign * 165)}z0r -- cycle;
520 penlabels(0,1,2,3,4,5,6,7,8,9,10,11);
521 else:
522 fill z6l -- z8l -- z2l -- z2r -- z3r -- z3l -- z9r -- z7r -- z7l -- z9l -- z8r -- z6r -- cycle;
523 penlabels(2,3,6,7,8,9);
524 fi
525 enddef;
526
527 def draw_sum(suffix $)(expr centre, width, height, thick, serifs) =
528 thicker := 11/8thick;
529 thinner := 1/2thick;
530 alpha := angle(width, height - thicker);
531
532 z1$ - z0$ = z3$ - z2$ = width * right;
533 z2$ - z0$ = height * up;
534 1/2[1/2[z0$,z1$], 1/2[z2$,z3$]] = centre;
535 z4$ - z1$ = z3$ - z5$.l = 3/2thicker * up;
536 if serifs:
537 z6$ = whatever[z0$,z1$] + thicker/2 * up = z4$ - whatever * dir 77;
538 z3$ - z7$ = 2/3thicker * up;
539 else:
540 z6$l = z1$;
541 z3$ - z7$ = thicker * up;
542 fi
543 z8$r = z2$ + whatever * right;
544 z8$l = z2$ + whatever * down;
545 z10$r = z0$ + whatever * up;
546 z10$l = z0$ + whatever * right;
547 z9$' = 1/4[z7$,z8$l];
548 z11$' = 1/4[z6$r,z10$r];
549 z12$ = centre;
550
551 if serifs:
552 penpos4$(thinner, 167);
553 penpos5$(thinner, 180);
554 penpos6$(thicker, 90);
555 penpos8$(5/6thicker, 77);
556 penpos10$(3/4thicker, 103);
557 penpos12$(thicker / sind alpha, 10);
558 else:
559 penpos6$(thicker, 90);
560 penpos8$(thicker, 90);
561 penpos10$(thicker, 90);
562 penpos12$(thicker / sind alpha, 0);
563 fi
564
565 z9$ = z12$r + whatever * (z8$l - z12$l) = z7$ + whatever * right;
566 z11$ = z12$r + whatever * (z10$r - z12$l);
567 y11$ = y10$r;
568
569 if serifs:
570 fill z10$l -- z6$l -- z4$l -- z4$r{-dir 77} ... {z11$ - z11$'}z11$' -- z11$ -- z12$r -- z9$ -- z9$'{z9$' - z9$} ... {-dir 113}z5$r -- z5$l -- z3$ -- z8$r -- z8$l -- z12$l -- z10$r -- cycle;
571 penlabels(3$,4$,5$,6$,7$,8$,9$,10$,11$,12$);
572 else:
573 fill z10$l -- z6$l -- z6$r -- z11$ -- z12$r -- z9$ -- z7$ -- z3$ -- z8$r -- z8$l -- z12$l -- z10$r -- cycle;
574 penlabels(3$,6$,7$,8$,9$,10$,11$,12$);
575 fi
576 enddef;
577
578 def draw_integral(suffix $)(expr scale, centre, thick) =
579 thicker := 4/3thick;
580
581 penpos0$(thicker, 0);
582 penpos1$(thicker, 0);
583 penpos2$(9/8thick, -105);
584 penpos3$(thicker, 0);
585 penpos4$(thick, -90);
586
587 z0$ = 1/2[z1$,z3$] = 1/2[z2$,z4$];
588 z1$ - z3$ = whatever * up;
589 z2$ - z4$ = whatever * dir 75;
590
591 x0$ = xpart centre;
592 y2$l = h;
593 y6$r = -d;
594 y1$ = 2/3[y0$,y2$];
595
596 penpos5$(9/8thick,-105);
597 penpos6$(9/8thick,-82);
598
599 y5$l = y2$l - 1/12thick;
600 x5$r = 5/4[x1$, x2$];
601 y6$l = y4$l;
602 x6$r = 5/4[x3$, x4$];
603
604 ucorr := max (x2$r, x1$r + 3/8thick) - x2$r;
605 x2$ := x2$ + ucorr;
606 x2$l := x2$l + ucorr;
607 x2$r := x2$r + ucorr;
608 x5$ := x5$ + ucorr;
609 x5$r := x5$r + ucorr;
610 x5$l := x5$l + ucorr;
611
612 lcorr := min (x4$l, x1$l - 3/8thick) - x4$l;
613 x4$ := x4$ + lcorr;
614 x4$l := x4$l + lcorr;
615 x4$r := x4$r + lcorr;
616 x6$ := x6$ + lcorr;
617 x6$r := x6$r + lcorr;
618 x6$l := x6$l + lcorr;
619
620 fill z5$l .. z2$l ... {down}z1$l -- z3$l{down} ... z4$l{left} .. z6$l -- z6$r
621 .. {up}z3$r -- z1$r{up} .. z2$r{right} .. z5$r -- cycle;
622
623 penlabels(0$,1$,2$,3$,4$,5$,6$);
624 enddef;
625
626 def draw_arrowhead_left(expr pos, angle, spread, thick) =
627 begingroup;
628 pair p[], p[].l, p[].r;
629
630 p1 = pos;
631 p2 = pos + sqrt(2) * (spread + 1/2thick)/2 * dir (angle + 135);
632 1/2[p1.l, p1.r] = p1;
633 1/2[p2.l, p2.r] = p2;
634 p1.r - p1 = thick/(2 * sind 45) * dir angle;
635 p2.r - p2 = thick/2 * dir (angle + 45);
636 p3.l = whatever[p2.l,p1.l];
637 p3.l = pos + 1/2thick * dir (angle - 90) + whatever * dir angle;
638 p3.r - p1.r = whatever * dir (angle - 105);
639 p3.r = pos + 1/2thick * dir (angle - 90) + whatever * dir angle;
640 fill p1.r -- p2.r -- p2.l -- p3.l -- p3.r -- cycle;
641 endgroup;
642 enddef;
643
644 def draw_arrowhead_right(expr pos, angle, spread, thick) =
645 begingroup;
646 pair p[], p[].l, p[].r;
647
648 p1 = pos;
649 p2 = pos + sqrt(2) * (spread + 1/2thick)/2 * dir (angle - 135);
650 1/2[p1.l, p1.r] = p1;
651 1/2[p2.l, p2.r] = p2;
652 p1.r - p1 = thick/(2 * sind 45) * dir angle;
653 p2.r - p2 = thick/2 * dir (angle - 45);
654 p3.l = whatever[p2.l,p1.l];
655 p3.l = pos + 1/2thick * dir (angle + 90) + whatever * dir angle;
656 p3.r - p1.r = whatever * dir (angle + 105);
657 p3.r = pos + 1/2thick * dir (angle + 90) + whatever * dir angle;
658 fill p1.r -- p3.r -- p3.l -- p2.l -- p2.r -- cycle;
659 endgroup;
660 enddef;
661
662 def draw_arrowhead(expr pos, angle, spread, thick) =
663 begingroup;
664 pair p[], p[].l, p[].r;
665
666 p1 = pos;
667 p2 = pos + sqrt(2) * spread/2 * dir (angle + 135);
668 p3 = pos + sqrt(2) * spread/2 * dir (angle - 135);
669 1/2[p1.l, p1.r] = p1;
670 1/2[p2.l, p2.r] = p2;
671 1/2[p3.l, p3.r] = p3;
672 p1.r - p1 = thick/(2 * sind 45) * dir angle;
673 p2.r - p2 = thick/2 * dir (angle + 45);
674 p3.r - p3 = thick/2 * dir (angle - 45);
675
676 fill p1.r -- p2.r -- p2.l -- p1.l -- p3.l -- p3.r -- cycle;
677 endgroup;
678 enddef;
679
680 % intersect the arrowhead curve with a path
681 def arrowhead_intersection(expr pos, angle, spread, p) =
682 (p intersectionpoint
683 ((pos + sqrt(2) * spread/2 * dir (angle + 135)) --
684 pos -- (pos + sqrt(2) * spread/2 * dir (angle - 135)))
685 )
686 enddef;
687
688 def draw_bracket(expr sign, thick, draw_top, draw_mid, draw_bot, draw_double) =
689 penpos0(thick, 90 - sign * 90);
690 penpos1(thick, 90 - sign * 90);
691 penpos2(thick, 90);
692 penpos3(thick, 90);
693 penpos4(thick, 90);
694 penpos5(thick, 90);
695 penpos6(thick, 0);
696 penpos7(thick, 0);
697
698 x3 - x2 = x5 - x4 = sign * (w - 2side_bearing);
699 1/2[x2,x3] = w/2;
700
701 if draw_top:
702 y1 = h;
703 else:
704 y1 = h + 1/2line_thickness;
705 fi;
706
707 if draw_bot:
708 y0 = -d;
709 else:
710 y0 = -d - 1/2line_thickness;
711 fi;
712
713 x1 = x0;
714 z6 = 1/2[z2l,z3l] + sign * 1/2thick * right;
715 z7 = 1/2[z4r,z5r] + sign * 1/2thick * right;
716 y2l = y3l;
717 y4r = y5r;
718 z2l = z0l;
719 z4r = z1l;
720
721 if draw_mid:
722 fill stroke z0e -- z1e;
723 else:
724 if draw_bot: fill stroke z0e -- z0e + (w - 2side_bearing) * up; fi;
725 if draw_top: fill stroke z1e -- z1e + (w - 2side_bearing) * down; fi;
726 fi;
727 if draw_top: fill stroke z4e -- z5e; fi;
728 if draw_bot: fill stroke z2e -- z3e; fi;
729 if draw_double: fill stroke z6e -- z7e; fi;
730 enddef;
731
732 def draw_angle(suffix $)(expr shift, sign, thick) =
733 x0$ = x1$ = x2$ + sign * (w - 2side_bearing -2abs shift - thick);
734
735 top y1$ = h;
736 bot y0$ = -d;
737 1/2[y0$,y1$] = y2$;
738 1/2[x0$,x2$] = w/2 + shift;
739
740 theta := angle(z0$ - z2$) + 90;
741
742 penpos0$ (thick, theta);
743 penpos1$ (thick, -theta);
744 penpos2$ (thick * cosd theta, 0);
745
746 fill stroke z0$e -- z2$e -- z1$e;
747
748 penlabels(0$, 1$, 2$);
749 enddef;
750
751 def draw_paren(expr sign, thick) =
752 penpos0(thick, 90 - sign * 45);
753 penpos1(thick, -90 + sign * 45);
754 penpos2(thick, 90 - sign * 90);
755
756 x0 = x1 = x2 + sign * (w - 2side_bearing - thick);
757 y1.l = h;
758 y0.l = -d;
759 1/2[y0,y1] = y2;
760 1/2[x0r,x2l] = w/2;
761
762 fill stroke z0e{3(x2e - x0e), y2e - y0e} .. z2e .. {3(x1e - x2e), y1e - y2e}z1e;
763
764 penlabels(0,1,2);
765 enddef;
766
767 def draw_brace(expr centre, size, width, alpha, thick, top_size, mid_size, bot_size) =
768 penpos1(5/6thick, alpha + 90);
769 penpos2(thick, alpha);
770 penpos2'(thick,alpha);
771 penpos3(thick, alpha);
772 penpos3'(thick,alpha);
773 penpos4(11/12thick, alpha+90);
774 penpos5(thick, alpha+180);
775 penpos5'(thick, alpha+180);
776 penpos6(thick, alpha+180);
777 penpos6'(thick, alpha+180);
778 penpos7(5/6thick, alpha+90);
779
780 z1r - z7l = size * dir (alpha + 90);
781
782 centre - 1/2[z1,z7] = z4 - centre = width/2 * dir alpha;
783
784 z0 = centre;
785
786 z3 = z0 + (1/3width + 1/2thick) * dir (alpha + 90);
787 z5 = z0 - (1/3width + 1/2thick) * dir (alpha + 90);
788
789 z2 = z0 + (size/2 - 1/3width - thick) * dir (alpha + 90);
790 z6 = z0 - (size/2 - 1/3width - thick) * dir (alpha + 90);
791
792 z3' = z0 + (mid_size/2 + 1/2line_thickness) * dir (alpha + 90);
793 z5' = z0 - (mid_size/2 + 1/2line_thickness) * dir (alpha + 90);
794
795 z2' = z0 + (size/2 - top_size - 1/2line_thickness) * dir (alpha + 90);
796 z6' = z0 - (size/2 - bot_size - 1/2line_thickness) * dir (alpha + 90);
797
798 beta := 0;
799
800 if top_size > 0:
801 fill stroke z1e{dir alpha} .. {dir (alpha - 90)}z2e -- z2'e;
802 penlabels(1,2,2');
803 elseif bot_size > 0:
804 fill stroke z7e{dir alpha} .. {dir (alpha + 90)}z6e -- z6'e;
805 penlabels(6',6,7);
806 elseif mid_size > 0:
807 fill stroke z3'e -- z3e{dir (alpha - 90)} .. {dir alpha}z4e;
808 fill stroke z5'e -- z5e{dir (alpha + 90)} .. {dir alpha}z4e;
809 penlabels(3',3,4,5,5');
810 else:
811 fill stroke z1e{dir alpha} .. z2e{dir (alpha - 90)} -- z3e{dir (alpha - 90)} .. z4e{dir alpha};
812 fill stroke z7e{dir alpha} .. {dir (alpha + 90)}z6e -- z5e{dir (alpha + 90)} .. {dir alpha}z4e;
813 penlabels(1,2,3,4,5,6,7);
814 fi;
815 enddef;
816
817 def draw_root(expr thick) =
818 penpos0(rule_thickness, -90);
819 penpos0'(rule_thickness, -90);
820 penpos2(3/2thick, 0);
821
822 y0l = h;
823 x0 = w;
824 z0' = z0 + 1/2line_thickness * right;
825 y1 = -d;
826 x1 = 4/9w;
827 x2 = 2/9w;
828 y2 = 1/2[y0, y1];
829 z1' = z1 + thick * dir (angle (z1 - z2l) + 90);
830 y6 = h;
831 z6 = z0r + thick * dir (angle (z0r - z1') + 90) + whatever * (z0r - z1');
832
833 penpos3(1/2thick, angle (z1 - z2l));
834
835 z3l = z2r + 5/2thick * dir (angle (z1 - z2l) - 90);
836 z4 = z6 + whatever * (z0 - z1') = z2r + whatever * (z2l - z1);
837 z5 = whatever[z2l, z1] = z3r + whatever * dir (angle (z1 - z2l) - 90);
838
839 fill z3r -- z5 -- z1 -- z1' -- z0r -- z0'r -- z0'l -- z6 -- z4 -- z2r -- z3l -- cycle;
840
841 penlabels (0,0',1,1',2,3,4,5,6);
842 enddef;
843
844 def draw_root_top(expr thick) =
845 y0 = h - 1/2rule_thickness;
846 x0 = w;
847 y1 = -d;
848 x1 = x2 = 4/9w + 1/2thick;
849 y2 = h - 1/2thick;
850
851 draw_straight(z1, z2, thick, true);
852 draw_straight((x1,y0), z0, rule_thickness, true);
853 enddef;
854
855 def draw_root_bot(expr thick) =
856 penpos0(thick, 0);
857 penpos0'(thick, -90);
858 penpos2(3/2thick, 0);
859
860 y0 = h + 1/2thick;
861 x0l = x1;
862 y1 = -d;
863 x1 = 4/9w;
864 x2l = 1/9w;
865 y2 = 1/2[y0, y1];
866 z1' = z1 + whatever * dir (angle (z1 - z2l) + 90);
867 x1' = x0r;
868
869 penpos3(1/2thick, angle (z1 - z2l));
870
871 z3l = z2r + 5/2thick * dir (angle (z1 - z2l) - 90);
872 z4 = z0l + whatever * up = z2r + whatever * (z2l - z1);
873 z5 = whatever[z2l, z1] = z3r + whatever * dir (angle (z1 - z2l) - 90);
874
875 fill z3r -- z5 -- z1 -- z1' -- z0r -- z0l -- z4 -- z2r -- z3l -- cycle;
876
877 penlabels (0,1,1',2,3,4,5);
878 enddef;
879
880 % Weierstrass macros
881
882 def ellipse_set(suffix $,@,@@,$$) =
883 % given |z$,x@,z$$|, find |y@| and |z@@|
884 % such that the path |z${x@-x$,0}..z@{0,y@-y$}..{z$$-z@@}z@@|
885 % is consistent with an ellipse
886 % and such that the line |z@@--z$$| has a given |slope|
887 alpha_ := slope * (x@ - x$);
888 beta_ := y$$ - y$ - slope * (x$$ - x$);
889 gamma_ := alpha_ / beta_;
890 y@ - y$ = .5(beta_ - alpha_ * gamma_);
891 x@@ - x$ = -2gamma_ * (x@ - x$) / (1 + gamma_ * gamma_);
892 y@@ - y$$ = slope * (x@@ - x$$)
893 enddef;
894
895 vardef super_arc.r(suffix $,$$) =
896 % outside of super-ellipse
897
898 pair centre, corner;
899
900 if y$ = y$r:
901 centre = (x$$r, y$r);
902 corner = (x$r, y$$r);
903 else:
904 centre = (x$r, y$$r);
905 corner = (x$$r, y$r);
906 fi
907 z$.r{corner - z$.r} ... superness[centre,corner]{z$$.r - z$.r}
908 ... {z$$.r - corner}z$$.r
909 enddef;
910
911 vardef super_arc.l(suffix $,$$) =
912 % inside of super-ellipse
913
914 pair centre, corner;
915 if y$ = y$r:
916 centre = (x$$l, y$l);
917 corner = (x$l, y$$l);
918 else:
919 centre = (x$l, y$$l);
920 corner = (x$$l, y$l);
921 fi
922 z$l{corner - z$l} ... superness[centre,corner]{z$$l - z$l}
923 ... {z$$l - corner}z$$l
924 enddef;
925
926 vardef pulled_super_arc.r(suffix $,$$)(expr superpull) =
927 pair centre, corner;
928
929 if y$ = y$r:
930 centre = (x$$r, y$r);
931 corner = (x$r, y$$r);
932 else:
933 centre = (x$r, y$$r);
934 corner = (x$$r, y$r);
935 fi
936 z$r{corner - z$r} ... superness[centre,corner]{z$$r - z$r}
937 ... {z$$r - corner}z$$r
938 enddef;
939
940 vardef pulled_super_arc.l(suffix $,$$)(expr superpull) =
941 pair centre, corner, outer_point;
942
943 if y$ = y$r:
944 centre = (x$$l, y$l);
945 corner = (x$l, y$$l);
946 outer_point = superness[(x$$r, y$r), (x$r, y$$r)];
947 else:
948 centre = (x$l, y$$l);
949 corner = (x$$l, y$l);
950 outer_point = superness[(x$r, y$$r), (x$$r, y$r)];
951 fi
952 z$l{corner - z$l}
953 ... superpull[superness[centre,corner], outer_point]{z$$l - z$l}
954 ... {z$$l - corner}z$$l
955 enddef;
956
957 vardef pulled_arc@#(suffix $,$$) =
958 pulled_super_arc@#($,$$)(superpull)
959 enddef;