Debian Codegraph @

texmf-dist/metapost/cmarrows/sgbx0013.mp

raw
1 %% sgbx0013.mp
2 %% Copyright 2006 Tommy Ekola <[email protected]>
3 %
4 % This work may be distributed and/or modified under the conditions of
5 % the LaTeX Project Public License, either version 1.3 of this license
6 % or (at your option) any later version. The latest version of this
7 % license is in http://www.latex-project.org/lppl.txt
8 %
9 % This work has the LPPL maintenance status `maintained'. The Current
10 % Maintainer of this work is Tommy Ekola. The Base Interpreter is
11 % MetaPost.
12
13 vardef setup_hookrightarrow (expr source_file, cmdname) =
14
15 scantokens ("input tgbx0000");
16
17 scantokens ("input " & source_file);
18
19 expandafter def scantokens cmdname expr p =
20 scantokens (cmdname & "__sgbxww")(p)
21 enddef;
22
23 expandafter vardef scantokens (cmdname & "__sgbxww " & "(expr apth) " &
24 "text text_ = " &
25
26 "save math_spread, x_height, u, rule_thickness, bar, math_axis," &
27 " asc_height, eps, monospace, fudge, crisp, hair;" &
28 "boolean monospace;" &
29
30 "math_spread :=" & decimal math_spread & ";" &
31 "x_height# :=" & decimal x_height# & ";" &
32 "u# :=" & decimal u# & ";" &
33 "rule_thickness# :=" & decimal rule_thickness# & ";" &
34 "bar# :=" & decimal bar# & ";" &
35 "math_axis# :=" & decimal math_axis# & ";" &
36 "asc_height# :=" & decimal asc_height# & ";" &
37 "eps :=" & decimal eps & ";" &
38 "monospace :=" & if monospace: "true" else: "false" fi & ";" &
39 "fudge :=" & decimal fudge & ";" &
40 "crisp# :=" & decimal crisp# & ";" &
41 "hair# :=" & decimal hair# & ";")
42
43 save prevpen;
44 prevpen:=savepen;
45
46 save x,y;
47 numeric x[], x[]', x[]l, x[]'l, x[]r, x[]'r,
48 y[], y[]', y[]l, y[]'l, y[]r, y[]'r;
49 save spread, w;
50 numeric spread, w;
51
52 if crisp#>fudge*hair#:
53 crisp#:=fudge*hair#;
54 fi
55 pickup if crisp#=0: nullpen else: pencircle scaled crisp# fi;
56
57 spread = math_spread[.45x_height#, .55x_height#];
58 w = 18u#;
59
60 penpos1(rule_thickness#, 90); penpos2(rule_thickness#, 90);
61 penpos3(rule_thickness#, 0); penpos4(rule_thickness#, 0);
62 y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#;
63 y3-y0=y0-y4=if monospace: .24 else: .36 fi asc_height#+eps;
64 x3=x4=x0-if monospace: 3u# else: 4u# fi - eps;
65 penpos5(rule_thickness#, angle(z4-z0)); z5l=z0;
66 penpos6(rule_thickness#, angle(z3-z0)); z6l=z0;
67 z9=.2[.5[z3,z4],z0];
68
69 save pp; path pp; pp = z4l{z9-z4}..z6r;
70 save t; numeric t; t = xpart(pp intersectiontimes ((0,y2l)--(w,y2l)));
71 x2=xpart point t of pp;
72
73 % the hook
74 x12-rule_thickness#/2=u#-eps; x11=x13=5u#-x12;
75 y11-y13=spread; y12=.5[y11,y13]; y13=0;
76
77 save mapto, n;
78 vardef mapto(text t) =
79 hide(numeric n; n:=0;
80 numeric x,x_[],y,y_[];
81 for z=t: z_[incr n]:=z; endfor;
82 transform T;
83 z_2 = z_1 transformed T;
84 z_4 = z_3 transformed T;
85 z_6 = z_5 transformed T;)
86 T
87 enddef;
88
89 save T; transform T;
90 save tt; numeric tt; tt = arctime(arclength apth - (x0-x9)) of apth;
91 save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth;
92 save ss; numeric ss; ss = arctime x11-x12 of apth;
93
94 % Draw the right half of the arrow head
95
96 save right_texarrowhead, pa;
97 vardef right_texarrowhead(expr T,s) =
98 (subpath(0, xpart ((z0..{z4-z9}z4r) intersectiontimes
99 (point s of pp -- point s of pp + (2rule_thickness#,0))))
100 of (z0..{z4-z9}z4r)--subpath(s,t) of pp--z2l) transformed T
101 enddef;
102
103 if arclength apth = 0:
104 T:=identity shifted (point (length apth) of apth - z0);
105 elseif arclength apth < x0-x3l:
106 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
107 shifted (point (length apth) of apth - z0);
108 else:
109 T:=mapto(z0,
110 point (length apth) of apth,
111 z2,
112 point ttt of apth,
113 z9-(0,3rule_thickness#),
114 point tt of apth - 3rule_thickness#
115 *(unitvector (direction tt of apth)
116 rotated 90));
117 fi
118
119 save f,s;
120 vardef f(expr s) =
121 length(point s of (pp transformed T) - point tt of apth)
122 < length(point 0 of pp - z9)
123 enddef;
124
125 if f(0) or (arclength apth < x0-x3l): s := 0;
126 else: s := solve f(length pp, 0);
127 fi
128
129 path pa;
130 pa := right_texarrowhead(T,s);
131
132 % Draw the left part of the arrow head
133
134 pp := (z3l{z9-z3}..z5r);
135 save pq; path pq; pq := (z3r{z9-z3}..z0);
136
137 save left_texarrowhead, pb;
138 vardef left_texarrowhead(expr T, s) =
139 (z2r--subpath(t,s) of pp
140 --subpath(xpart ( pq intersectiontimes
141 (point s of pp -- point s of pp + (2rule_thickness#,0)))
142 ,length pq) of pq) transformed T
143 enddef;
144
145 if arclength apth = 0:
146 T:=identity shifted (point (length apth) of apth - z0);
147 elseif arclength apth < x0-x3l:
148 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
149 shifted (point (length apth) of apth - z0);
150 else:
151 T:=mapto(z0,
152 point (length apth) of apth,
153 z2,
154 point ttt of apth,
155 z9+(0,3rule_thickness#),
156 point tt of apth + 3rule_thickness#
157 *(unitvector (direction tt of apth)
158 rotated 90));
159 fi
160
161 vardef f(expr s) =
162 length(point s of (pp transformed T) - point tt of apth)
163 < length(point 0 of pp - z9)
164 enddef;
165
166 if f(0) or (arclength apth < x0-x3l): s := 0;
167 else: s := solve f(length pp, 0);
168 fi
169
170 path pb;
171 pb := left_texarrowhead(T,s);
172
173 filldraw pa--pb--cycle text_;
174
175 % Draw the hook
176
177 save hook;
178 vardef hook(expr T) =
179 (z11{left}...z12{down}...z13{right}) transformed T
180 enddef;
181
182 if arclength apth = 0:
183 T:=identity shifted (point (length apth) of apth - z11);
184 elseif arclength apth < x11-x12:
185 T:=identity rotatedaround(z11,angle (direction 0 of apth))
186 shifted (point 0 of apth - z11)
187 shifted ((x11-x12)*(unitvector
188 (point (length apth) of apth - point 0 of apth)));
189 else:
190 T:=mapto(z11,
191 point ss of apth,
192 z12,
193 point 0 of apth - (y11-y12)*(unitvector (direction 0 of apth)
194 rotated 90),
195 z13,
196 point ss of apth - (y11-y13)*(unitvector (direction ss of apth)
197 rotated 90));
198 fi
199
200 draw hook(T) withpen pencircle scaled rule_thickness# text_;
201
202 % Draw the path
203
204 if arclength apth > x0-x2 + x11-x12:
205 draw subpath(ss,ttt) of apth withpen pencircle scaled rule_thickness#
206 text_;
207 fi
208
209 pickup prevpen;
210
211 enddef;
212
213 enddef;