Debian Codegraph @

texmf-dist/metapost/cmarrows/tgbx0027.mp

raw
1 %% tgbx0027.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_paren (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 & "__tgbxww")(p)
21 enddef;
22
23 expandafter vardef scantokens (cmdname & "__tgbxww " & "(expr apth) " &
24 "text text_ = " &
25
26 "save u, designsize, curve, stem, rule_thickness, eps, fine, " &
27 " fudge, hair;" &
28
29 "u# := " & decimal u# & ";" &
30 "designsize := " & decimal designsize & ";" &
31 "curve# := " & decimal curve# & ";" &
32 "stem# := " & decimal stem# & ";" &
33 "rule_thickness# := " & decimal rule_thickness# & ";" &
34 "eps := " & decimal eps & ";" &
35 "fine# := " & decimal fine# & ";" &
36 "fudge := " & decimal fudge & ";" &
37 "hair# := " & decimal hair# & ";" &
38
39 % Time for middle piece
40
41 "save st; numeric st;" &
42 "if unknown " & cmdname & "_middle_time:" &
43 " st := arctime (arclength apth)/2 of apth;" &
44 "else: st:=" & cmdname & "_middle_time; fi")
45
46 save prevpen;
47 prevpen:=savepen;
48
49 save w; numeric w; w :=12u#;
50 save h; numeric h; h :=0;
51 save dh; numeric dh; dh:=0.6designsize;
52 save dw; numeric dw; dw:=curve#-stem#;
53 save d; numeric d; d :=1.5dh;
54 save bold; numeric bold; bold := curve#;
55 save min_breadth; numeric min_breadth;
56 min_breadth:=rule_thickness#+0.6dw;
57 save max_breadth; numeric max_breadth;
58 max_breadth:=bold+2dw;
59 save heavy_rule_thickness; numeric heavy_rule_thickness#;
60 heavy_rule_thickness#:=3rule_thickness#;
61
62 save x,y;
63 numeric x[],x[]',x[]l,x[]'l,x[]r,x[]'r,
64 y[],y[]',y[]l,y[]'l,y[]r,y[]'r;
65
66 if fine#>fudge*hair#:
67 fine# := fudge*hair#;
68 fi
69 pickup if fine#=0: nullpen else: pencircle scaled fine# fi;
70
71 penpos3(min_breadth,0); penpos4(max_breadth,0);
72 rt x3r = w-1.25u#+0.5min_breadth; lft x4l = 1.25u#;
73 bot y3=-d; y4=h;
74
75 penpos1(min_breadth,0); penpos2(max_breadth,0);
76 rt x1r = w-1.25u#+0.5min_breadth; lft x2l = 1.25u#;
77 top y1 = h; y2=-d;
78
79 save mapto, n;
80 vardef mapto(text t) =
81 hide(numeric n; n:=0;
82 numeric x,x_[],y,y_[];
83 for z=t: z_[incr n]:=z; endfor;
84 transform T;
85 z_2 = z_1 transformed T;
86 z_4 = z_3 transformed T;
87 z_6 = z_5 transformed T;)
88 T
89 enddef;
90
91 % The bottom part of the parenthesis
92
93 save bottom_part;
94 vardef bottom_part(expr T) =
95 filldraw (z3l{3(x4l-x3l),y4-y3}..{up}z4l
96 --reverse(z3r{3(x4r-x3r),y4-y3}..{up}z4r)
97 --cycle) transformed T text_;
98 enddef;
99
100 save f;
101 vardef f(expr s) =
102 abs(point 0 of apth - (point s of apth +
103 (w-2.5u#+0.5min_breadth+0.5*max_breadth)
104 *(unitvector (direction s of apth) rotated 90)))
105 < ((h+d) ++ (w-2.5u#+0.5min_breadth+0.5*max_breadth))
106 enddef;
107
108 save tolerence; tolerence:=epsilon;
109 save s; numeric s;
110
111 save T; transform T; % transform the bottom part
112 if arclength apth=0:
113 T := identity shifted (point (length apth) of apth - z3r);
114 elseif arclength apth < y1-y2+y4-y3:
115 T := mapto(z4l,
116 0.5[point 0 of apth, point (length apth) of apth]
117 + abs(x3r-x4l)*(unitvector (point (length apth) of apth -
118 point 0 of apth) rotated 90),
119 z4r,
120 0.5[point 0 of apth, point (length apth) of apth]
121 + abs(x3r-x4r)*(unitvector (point (length apth) of apth -
122 point 0 of apth) rotated 90),
123 z3r,
124 point 0 of apth);
125 else:
126 s := solve f(0,length apth);
127 T := mapto(z4l,
128 point s of apth + (w-2.5u#+0.5min_breadth+0.5max_breadth)
129 *(unitvector (direction s of apth) rotated 90),
130 z4r,
131 point s of apth + (w-2.5u#+0.5min_breadth-0.5max_breadth)
132 *(unitvector (direction s of apth) rotated 90),
133 z3r,
134 point 0 of apth);
135 fi;
136
137 bottom_part(T);
138
139 % The top part of the parenthesis
140
141 save top_part;
142 vardef top_part(expr T) =
143 filldraw (z1l{3(x2l-x1l),y2-y1}..{down}z2l
144 --reverse(z1r{3(x2r-x1r),y2-y1}..{down}z2r)
145 --cycle) transformed T text_;
146 enddef;
147
148 save g;
149 vardef g(expr t) =
150 abs(point (length apth) of apth - (point t of apth +
151 (w-2.5u#+0.5min_breadth+0.5max_breadth)
152 *(unitvector (direction s of apth) rotated 90)))
153 < ((h+d) ++ (w-2.5u#+0.5min_breadth+0.5max_breadth))
154 enddef;
155
156 save t; numeric t;
157 transform T; % transform the top part
158 if arclength apth = 0:
159 T := identity shifted (point (length apth) of apth - z1r);
160 elseif arclength apth < y1-y2+y4-y3:
161 T := mapto(z2l,
162 0.5[point 0 of apth, point (length apth) of apth]
163 +abs(x1r-x2l)*(unitvector (point (length apth) of apth
164 - point 0 of apth) rotated 90),
165 z2r,
166 0.5[point 0 of apth, point (length apth) of apth]
167 +abs(x1r-x2r)*(unitvector (point (length apth) of apth
168 - point 0 of apth) rotated 90),
169 z1r,
170 point (length apth) of apth);
171 else:
172 t := solve g(length apth, 0);
173 T := mapto(z2l,
174 point t of apth + (w-2.5u#+0.5min_breadth+0.5max_breadth)
175 *(unitvector (direction t of apth) rotated 90),
176 z2r,
177 point t of apth + (w-2.5u#+0.5min_breadth-0.5max_breadth)
178 *(unitvector (direction t of apth) rotated 90),
179 z1r,
180 point (length apth) of apth);
181 fi;
182
183 top_part(T);
184
185 % The extension part
186
187 save extension_part;
188 vardef extension_part(expr ss,tt) =
189 numeric stp; stp:=(ss-tt) div 5pt;
190 if stp=0: stp:=1; fi
191 stp:=(ss-tt)/stp;
192
193 pickup pencircle scaled heavy_rule_thickness#;
194
195 if stp>0:
196 draw for uu=ss step stp until tt-stp:
197 point uu of apth + (w-2.5u#+.5min_breadth)
198 *(unitvector (direction uu of apth) rotated 90)
199 {direction uu of apth} ..
200 endfor
201 {direction tt of apth}
202 point tt of apth + (w-2.5u#+.5min_breadth)
203 *(unitvector (direction tt of apth) rotated 90) text_;
204 fi
205 enddef;
206
207 if arclength apth > y1-y2+y4-y3:
208 extension_part(s,t);
209 fi
210
211 pickup prevpen;
212
213 enddef;
214
215 enddef;
216