| 1 |
%% tgbx0005.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_extensiblebrace (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, hair, rule_thickness, eps, fine, " & |
| 27 |
"fudge;" & |
| 28 |
|
| 29 |
"u# := " & decimal u# & ";" & |
| 30 |
"designsize := " & decimal designsize & ";" & |
| 31 |
"curve# := " & decimal curve# & ";" & |
| 32 |
"stem# := " & decimal stem# & ";" & |
| 33 |
"hair# := " & decimal hair# & ";" & |
| 34 |
"rule_thickness# := " & decimal rule_thickness# & ";" & |
| 35 |
"eps := " & decimal eps & ";" & |
| 36 |
"fine# := " & decimal fine# & ";" & |
| 37 |
"fudge := " & decimal fudge & ";" & |
| 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 min_breadth; numeric min_breadth#; |
| 55 |
min_breadth#:=rule_thickness#+0.6dw; |
| 56 |
save heavy_rule_thickness; numeric heavy_rule_thickness#; |
| 57 |
heavy_rule_thickness#:=3rule_thickness#; |
| 58 |
|
| 59 |
save x,y; |
| 60 |
numeric x[],x[]',x[]l,x[]'l,x[]r,x[]'r, |
| 61 |
y[],y[]',y[]l,y[]'l,y[]r,y[]'r; |
| 62 |
|
| 63 |
if fine#>fudge*hair#: |
| 64 |
fine#:=fudge*hair#; |
| 65 |
fi |
| 66 |
pickup if fine#=0: nullpen else: pencircle scaled fine# fi; |
| 67 |
|
| 68 |
penpos7(min_breadth#,0); penpos7'(min_breadth#,0); |
| 69 |
penpos6(heavy_rule_thickness#,0); |
| 70 |
rt x7r = rt x7'r = w-1.5u#+.5min_breadth#; |
| 71 |
lft x6l = .5w-.5heavy_rule_thickness#; |
| 72 |
bot y7 = -d; y6 = .5[h+eps,y7]; y7'-y7 = min_breadth#-fine#; |
| 73 |
|
| 74 |
penpos1(min_breadth#,0); penpos1'(min_breadth#,0); |
| 75 |
penpos2(heavy_rule_thickness#,0); |
| 76 |
rt x1r = rt x1'r = w-1.5u#+.5min_breadth#; |
| 77 |
lft x2 = .5w; |
| 78 |
top y1 = h; y2 = .5[y1,-d-eps]; y1-y1' = min_breadth#-fine#; |
| 79 |
|
| 80 |
penpos4'(min_breadth#,0); penpos4(min_breadth#,0); |
| 81 |
penpos5(heavy_rule_thickness#,0); |
| 82 |
penpos3(heavy_rule_thickness#,0); |
| 83 |
lft x4l=lft x4'l=1.5u#-.5min_breadth#; |
| 84 |
lft x5l=.5w-.5heavy_rule_thickness#; |
| 85 |
y4'-y5=(h+2d+2eps)/4; |
| 86 |
y4-y4'=min_breadth#-fine#; y4=0; |
| 87 |
lft x3l = .5w-.5heavy_rule_thickness#; |
| 88 |
y3-y4 = (h+2d+2eps)/4; |
| 89 |
|
| 90 |
save mapto, n; |
| 91 |
vardef mapto(text t) = |
| 92 |
hide(numeric n; n:=0; |
| 93 |
numeric x,x_[],y,y_[]; |
| 94 |
for z=t: z_[incr n]:=z; endfor; |
| 95 |
transform T; |
| 96 |
z_2 = z_1 transformed T; |
| 97 |
z_4 = z_3 transformed T; |
| 98 |
z_6 = z_5 transformed T;) |
| 99 |
T |
| 100 |
enddef; |
| 101 |
|
| 102 |
% The bottom part of the brace |
| 103 |
|
| 104 |
save bottom_part; |
| 105 |
vardef bottom_part(expr T) = |
| 106 |
filldraw (z6l{down}...{3(x7l-x6l),y7-y6}z7l |
| 107 |
--z7r--z7'r{3(x6r-x7r),y6-y7'}...{up}z6r--z6l & cycle) |
| 108 |
transformed T text_; |
| 109 |
enddef; |
| 110 |
|
| 111 |
save f; |
| 112 |
vardef f(expr s) = |
| 113 |
abs(point 0 of apth - (point s of apth + (.5w-1.5u#+.5min_breadth#) |
| 114 |
*(unitvector (direction s of apth) rotated 90))) |
| 115 |
< ((d/2) ++ (.5w-1.5u#+.5min_breadth#)) |
| 116 |
enddef; |
| 117 |
|
| 118 |
save tolerence; tolerence := epsilon; |
| 119 |
save s; numeric s; |
| 120 |
|
| 121 |
save T; transform T; % transform for the bottom part |
| 122 |
if arclength apth = 0: |
| 123 |
T:=identity shifted (point (length apth) of apth - z7r); |
| 124 |
elseif arclength apth < y1-y2+y3-y5+y6-y7: |
| 125 |
T:=mapto(z6l, |
| 126 |
.25[point 0 of apth, point (length apth) of apth]+ |
| 127 |
+abs(x7r-x6l)*(unitvector (point (length apth) of apth - |
| 128 |
point 0 of apth) rotated 90), |
| 129 |
z6r, |
| 130 |
.25[point 0 of apth, point (length apth) of apth]+ |
| 131 |
+abs(x7r-x6r)*(unitvector (point (length apth) of apth - |
| 132 |
point 0 of apth) rotated 90), |
| 133 |
z7r, |
| 134 |
point 0 of apth); |
| 135 |
else: |
| 136 |
s := solve f(0,length apth); |
| 137 |
T := mapto(z6l, |
| 138 |
point s of apth |
| 139 |
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#) |
| 140 |
*(unitvector (direction s of apth) rotated 90), |
| 141 |
z6r, |
| 142 |
point s of apth |
| 143 |
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#) |
| 144 |
*(unitvector (direction s of apth) rotated 90), |
| 145 |
z7r, |
| 146 |
point 0 of apth); |
| 147 |
fi |
| 148 |
bottom_part(T); |
| 149 |
|
| 150 |
% The top part of the brace |
| 151 |
|
| 152 |
save top_part; |
| 153 |
vardef top_part(expr T) = |
| 154 |
filldraw (z1l{3(x2l-x1l),y2-y1}...{down}z2l |
| 155 |
--z2r{up}...{3(x1r-x2r),y1'-y2}z1'r--z1r--cycle) |
| 156 |
transformed T text_; |
| 157 |
enddef; |
| 158 |
|
| 159 |
save g; |
| 160 |
vardef g(expr t) = |
| 161 |
abs(point (length apth) of apth |
| 162 |
- (point t of apth + (.5w-1.5u#+.5min_breadth#) |
| 163 |
*(unitvector (direction t of apth) rotated 90))) |
| 164 |
< ((d/2) ++ (.5w-1.5u#+.5min_breadth#)) |
| 165 |
enddef; |
| 166 |
|
| 167 |
save t; numeric t; |
| 168 |
|
| 169 |
transform T; % transform the top part |
| 170 |
if arclength apth = 0: |
| 171 |
T:=identity shifted (point (length apth) of apth - z1r); |
| 172 |
elseif arclength apth < y1-y2+y3-y5+y6-y7: |
| 173 |
T := mapto(z2l, |
| 174 |
.75[point 0 of apth, point (length apth) of apth] + |
| 175 |
abs(x1r-x2l)*(unitvector (point (length apth) of apth - |
| 176 |
point 0 of apth) rotated 90), |
| 177 |
z2r, |
| 178 |
.75[point 0 of apth, point (length apth) of apth] + |
| 179 |
abs(x1r-x2r)*(unitvector (point (length apth) of apth - |
| 180 |
point 0 of apth) rotated 90), |
| 181 |
z1r, |
| 182 |
point (length apth) of apth); |
| 183 |
else: |
| 184 |
t := solve g(length apth,0); |
| 185 |
T := mapto(z2l, |
| 186 |
point t of apth |
| 187 |
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#) |
| 188 |
*(unitvector (direction t of apth) rotated 90), |
| 189 |
z2r, |
| 190 |
point t of apth |
| 191 |
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#) |
| 192 |
*(unitvector (direction t of apth) rotated 90), |
| 193 |
z1r, |
| 194 |
point (length apth) of apth); |
| 195 |
fi |
| 196 |
top_part(T); |
| 197 |
|
| 198 |
% The lower part of the middle piece |
| 199 |
|
| 200 |
save middle_part_bottom; |
| 201 |
vardef middle_part_bottom(expr T) = |
| 202 |
(.5[z4r,z4'r]{3(x5r-x4r),y5-.5[y4,y4']}...{down}z5r |
| 203 |
--z5l{up}...{3(x4l-x5l),y4'-y5}z4'l) transformed T |
| 204 |
enddef; |
| 205 |
|
| 206 |
save ff; |
| 207 |
vardef ff(expr ss) = |
| 208 |
abs(point st of apth |
| 209 |
+(w-3u#)*(unitvector (direction st of apth) rotated 90) |
| 210 |
-(point ss of apth + (.5w-1.5u#+.5min_breadth#) |
| 211 |
*(unitvector (direction ss of apth) rotated 90))) |
| 212 |
> ((h+2d+2eps)/4+(min_breadth#-fine#)/2) ++ (.5w-1.5u#-.5min_breadth#) |
| 213 |
enddef; |
| 214 |
|
| 215 |
save ss; numeric ss; |
| 216 |
|
| 217 |
if arclength apth = 0: |
| 218 |
T:=identity shifted (point (length apth) of apth - z4'l); |
| 219 |
elseif arclength apth < y1-y2+y3-y5+y6-y7: |
| 220 |
T:=mapto(.5[z4r,z4'r], |
| 221 |
.5[point 0 of apth, point (length apth) of apth]+ |
| 222 |
abs(x1r-.5[x4r,x4'r]) |
| 223 |
*(unitvector (point (length apth) of apth - |
| 224 |
point 0 of apth) rotated 90), |
| 225 |
z5l, |
| 226 |
.25[point 0 of apth, point (length apth) of apth]+ |
| 227 |
abs(x1r-x5l)*(unitvector (point (length apth) of apth - |
| 228 |
point 0 of apth) rotated 90), |
| 229 |
z5r, |
| 230 |
.25[point 0 of apth, point (length apth) of apth]+ |
| 231 |
abs(x1r-x5r)*(unitvector (point (length apth) of apth - |
| 232 |
point 0 of apth) rotated 90)); |
| 233 |
else: |
| 234 |
ss := solve ff(0,st); |
| 235 |
T:=mapto(.5[z4r,z4'r], |
| 236 |
point st of apth |
| 237 |
+(w-3u#)*(unitvector (direction st of apth) rotated 90), |
| 238 |
z5l, |
| 239 |
point ss of apth |
| 240 |
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#) |
| 241 |
*(unitvector (direction ss of apth) rotated 90), |
| 242 |
z5r, |
| 243 |
point ss of apth |
| 244 |
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#) |
| 245 |
*(unitvector (direction ss of apth) rotated 90)); |
| 246 |
fi |
| 247 |
|
| 248 |
save pb; path pb; |
| 249 |
pb:=middle_part_bottom(T); |
| 250 |
|
| 251 |
% The upper part of the middle piece |
| 252 |
|
| 253 |
save middle_part_top; |
| 254 |
vardef middle_part_top(expr T) = |
| 255 |
(z4l{3(x3l-x4l),y3-y4}...{up}z3l--z3r{down} |
| 256 |
...{3(x4r-x3r),.5[y4,y4']-y3}.5[z4r,z4'r]) transformed T |
| 257 |
enddef; |
| 258 |
|
| 259 |
save gg; |
| 260 |
vardef gg(expr tt) = |
| 261 |
abs(point st of apth |
| 262 |
+(w-3u#)*(unitvector (direction st of apth) rotated 90) |
| 263 |
-(point tt of apth + (.5w-1.5u#+.5min_breadth#) |
| 264 |
*(unitvector (direction tt of apth) rotated 90))) |
| 265 |
> ((h+2d+2eps)/4+(min_breadth#-fine#)/2) ++ (.5w-1.5u#-.5min_breadth#) |
| 266 |
enddef; |
| 267 |
|
| 268 |
save tt; numeric tt; |
| 269 |
|
| 270 |
if arclength apth = 0: |
| 271 |
T:=identity shifted (point (length apth) of apth - z4l); |
| 272 |
elseif arclength apth < y1-y2+y3-y5+y6-y7: |
| 273 |
T:=mapto(.5[z4r,z4'r], |
| 274 |
.5[point 0 of apth, point (length apth) of apth]+ |
| 275 |
abs(x1r-.5[x4r,x4'r]) |
| 276 |
*(unitvector (point (length apth) of apth - |
| 277 |
point 0 of apth) rotated 90), |
| 278 |
z3l, |
| 279 |
.75[point 0 of apth, point (length apth) of apth]+ |
| 280 |
abs(x1r-x3l)*(unitvector (point (length apth) of apth - |
| 281 |
point 0 of apth) rotated 90), |
| 282 |
z3r, |
| 283 |
.75[point 0 of apth, point (length apth) of apth]+ |
| 284 |
abs(x1r-x3r)*(unitvector (point (length apth) of apth - |
| 285 |
point 0 of apth) rotated 90)); |
| 286 |
else: |
| 287 |
tt := solve gg(length apth, st); |
| 288 |
T := mapto(.5[z4r,z4'r], |
| 289 |
point st of apth |
| 290 |
+(w-3u#)*(unitvector (direction st of apth) rotated 90), |
| 291 |
z3l, |
| 292 |
point tt of apth |
| 293 |
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#) |
| 294 |
*(unitvector (direction tt of apth) rotated 90), |
| 295 |
z3r, |
| 296 |
point tt of apth |
| 297 |
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#) |
| 298 |
*(unitvector (direction tt of apth) rotated 90)); |
| 299 |
fi |
| 300 |
|
| 301 |
save ptt; path ptt; |
| 302 |
ptt:=middle_part_top(T); |
| 303 |
|
| 304 |
filldraw pb--ptt--cycle text_; |
| 305 |
|
| 306 |
% The extension parts |
| 307 |
|
| 308 |
save extension_part; |
| 309 |
vardef extension_part(expr ss,tt) = |
| 310 |
numeric stp; stp:=(ss-tt) div 5pt; |
| 311 |
if stp=0: stp:=1; fi |
| 312 |
stp:=(ss-tt)/stp; |
| 313 |
|
| 314 |
pickup pencircle scaled (heavy_rule_thickness#+fine#); |
| 315 |
|
| 316 |
if stp>0: |
| 317 |
draw for uu=ss step stp until tt-stp: |
| 318 |
point uu of apth + (.5w-1.5u#+.5min_breadth#) |
| 319 |
*(unitvector (direction uu of apth) rotated 90) |
| 320 |
{direction uu of apth} .. |
| 321 |
endfor |
| 322 |
{direction tt of apth} |
| 323 |
point tt of apth + (.5w-1.5u#+.5min_breadth#) |
| 324 |
*(unitvector (direction tt of apth) rotated 90) text_; |
| 325 |
fi |
| 326 |
enddef; |
| 327 |
|
| 328 |
if arclength apth > y1-y2+y3-y5+y6-y7: |
| 329 |
extension_part(s,ss); extension_part(tt,t); |
| 330 |
fi |
| 331 |
|
| 332 |
pickup prevpen; |
| 333 |
|
| 334 |
enddef; |
| 335 |
|
| 336 |
enddef; |