Debian Codegraph @

texmf-dist/metapost/slideshow/pathalong.mp

raw
1 %% draw some text (t) along a curve (p)
2
3 vardef pathalong (expr _p, t) =
4 save l, ll, del,let, pos, p;
5 picture let, ll;
6 path del, p;
7
8 l := length(t) - 1;
9 pos = 0;
10 p := _p;
11
12 ll := nullpicture;
13
14 for i := 0 upto l:
15
16 let := substring (i,i+1) of t infont defaultfont scaled defaultscale;
17
18 addto ll also (let rotated(angle(direction pos of p)))
19 shifted point pos of p;
20
21 del := (((xpart urcorner let, infinity)--(xpart urcorner let, -infinity))
22 rotated(angle(direction pos of p)))
23 shifted point pos of p;
24
25 p := subpath(pos,length(p)) of p;
26 pos := ypart (del intersectiontimes p);
27 exitif pos <= 0;
28
29 endfor;
30
31 ll
32 enddef;
33
34 %% draw the text contained in t so that the bottoms of the letters are on
35 %% the base-line and the tops abut path p
36 vardef textunder(expr p,t) =
37 save l, ll, pos, h, i;
38 picture l, ll;
39 numeric pos, h, i;
40 ll := nullpicture;
41 pos := 0;
42 for i = 0 upto (length t - 1):
43 l := substring(i, i+1) of t infont defaultfont scaled defaultscale;
44 h := ypart urcorner l;
45 if h > 0:
46 addto ll also (l yscaled ((ypart (((pos,-infinity)--(pos,infinity)) intersectionpoint p)) / ypart ulcorner l)) shifted (pos, 0);
47 fi;
48 pos := pos + xpart lrcorner l;
49 endfor;
50
51 ll
52 enddef;
53