| 1 |
%% sgbx0018.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_oldtexarrow (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(bar#, 0); penpos4(bar#, 0); |
| 62 |
y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#; |
| 63 |
y3-y0=y0-y4=.24asc_height#+eps; |
| 64 |
x3=x4=x0-3u#-eps; |
| 65 |
penpos5(bar#, angle(z4-z0)); z5l=z0; |
| 66 |
penpos6(bar#, angle(z3-z0)); z6l=z0; |
| 67 |
z9=.381966[.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 |
save mapto, n; |
| 74 |
vardef mapto(text t) = |
| 75 |
hide(numeric n; n:=0; |
| 76 |
numeric x,x_[],y,y_[]; |
| 77 |
for z=t: z_[incr n]:=z; endfor; |
| 78 |
transform T; |
| 79 |
z_2 = z_1 transformed T; |
| 80 |
z_4 = z_3 transformed T; |
| 81 |
z_6 = z_5 transformed T;) |
| 82 |
T |
| 83 |
enddef; |
| 84 |
|
| 85 |
save T; transform T; |
| 86 |
save tt; numeric tt; tt = arctime(arclength apth - (x0-x9)) of apth; |
| 87 |
save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth; |
| 88 |
|
| 89 |
% Draw the right half of the arrow head |
| 90 |
|
| 91 |
save right_texarrowhead, pa; |
| 92 |
vardef right_texarrowhead(expr T,s) = |
| 93 |
(subpath(0, xpart ((z0..{z4-z9}z4r) intersectiontimes |
| 94 |
(point s of pp -- point s of pp + (2rule_thickness#,0)))) |
| 95 |
of (z0..{z4-z9}z4r)--subpath(s,t) of pp--z2l) transformed T |
| 96 |
enddef; |
| 97 |
|
| 98 |
if arclength apth = 0: |
| 99 |
T:=identity shifted (point (length apth) of apth - z0); |
| 100 |
elseif arclength apth < x0-x3l: |
| 101 |
T:=identity rotatedaround(z0,angle (direction (length apth) of apth)) |
| 102 |
shifted (point (length apth) of apth - z0); |
| 103 |
else: |
| 104 |
T:=mapto(z0, |
| 105 |
point (length apth) of apth, |
| 106 |
z2, |
| 107 |
point ttt of apth, |
| 108 |
z9+(0,3rule_thickness#), |
| 109 |
point tt of apth + |
| 110 |
3rule_thickness#*(unitvector (direction tt of apth) |
| 111 |
rotated 90)); |
| 112 |
fi |
| 113 |
|
| 114 |
save f,s; |
| 115 |
vardef f(expr s) = |
| 116 |
length(point s of (pp transformed T) - point tt of apth) |
| 117 |
< length(point 0 of pp - z9) |
| 118 |
enddef; |
| 119 |
|
| 120 |
if f(0) or (arclength apth < x0-x3l): s := 0; |
| 121 |
else: s := solve f(length pp, 0); |
| 122 |
fi |
| 123 |
|
| 124 |
path pa; |
| 125 |
pa := right_texarrowhead(T,s); |
| 126 |
|
| 127 |
% Draw the left half of the arrow head |
| 128 |
|
| 129 |
pp := (z3l{z9-z3}..z5r); |
| 130 |
save pq; path pq; pq := (z3r{z9-z3}..z0); |
| 131 |
|
| 132 |
save left_texarrowhead, pb; |
| 133 |
vardef left_texarrowhead(expr T, s) = |
| 134 |
(z2r--subpath(t,s) of pp |
| 135 |
--subpath(xpart ( pq intersectiontimes |
| 136 |
(point s of pp -- point s of pp + (2rule_thickness#,0))) |
| 137 |
,length pq) of pq) transformed T |
| 138 |
enddef; |
| 139 |
|
| 140 |
if arclength apth = 0: |
| 141 |
T:=identity shifted (point (length apth) of apth - z0); |
| 142 |
elseif arclength apth < x0-x3l: |
| 143 |
T:=identity rotatedaround(z0,angle (direction (length apth) of apth)) |
| 144 |
shifted (point (length apth) of apth - z0); |
| 145 |
else: |
| 146 |
T:=mapto(z0, |
| 147 |
point (length apth) of apth, |
| 148 |
z2, |
| 149 |
point ttt of apth, |
| 150 |
z9+(0,3rule_thickness#), |
| 151 |
point tt of apth + 3rule_thickness# |
| 152 |
*(unitvector (direction tt of apth) |
| 153 |
rotated 90)); |
| 154 |
fi |
| 155 |
|
| 156 |
vardef f(expr s) = |
| 157 |
length(point s of (pp transformed T) - point tt of apth) |
| 158 |
< length(point 0 of pp - z9) |
| 159 |
enddef; |
| 160 |
|
| 161 |
if f(0) or (arclength apth < x0-x3l): s := 0; |
| 162 |
else: s := solve f(length pp, 0); |
| 163 |
fi |
| 164 |
|
| 165 |
path pb; |
| 166 |
pb := left_texarrowhead(T,s); |
| 167 |
|
| 168 |
filldraw pa--pb--cycle text_; |
| 169 |
|
| 170 |
% Draw the path |
| 171 |
|
| 172 |
if arclength apth > x0-x2: |
| 173 |
draw subpath(0,ttt) of apth withpen pencircle scaled rule_thickness# |
| 174 |
text_; |
| 175 |
fi |
| 176 |
|
| 177 |
pickup prevpen; |
| 178 |
|
| 179 |
enddef; |
| 180 |
|
| 181 |
enddef; |