Debian Codegraph @

texmf-dist/source/metapost/roundrect/roundrect.dtx

raw
1 % \iffalse
2 % +AMDG This document was begun on 1E June 11EE, the vigil
3 % of the Nativity of St. John the Baptist, and it is humbly
4 % dedicated to him and to the Immaculate Heart of Mary, for
5 % their prayers, and to the Sacred Heart of Jesus, for His
6 % mercy.
7 %
8 % This document is copyright 2015 by Donald P. Goodman, and is
9 % released publicly under the LaTeX Project Public License. The
10 % distribution and modification of this work is constrained by the
11 % conditions of that license. See
12 % http://www.latex-project.org/lppl.txt
13 % for the text of the license. This document is released
14 % under version 1.3 of that license, and this work may be distributed
15 % or modified under the terms of that license or, at your option, any
16 % later version.
17 %
18 % This work has the LPPL maintenance status 'maintained'.
19 %
20 % The Current Maintainer of this work is Donald P. Goodman
21 % ([email protected]).
22 %
23 % This work consists of the files roundrect.dtx and
24 % roundrect.ins, along with the generated file roundrect.mp
25 % and roundrect.pdf, and the README.
26 % \fi
27
28 % \iffalse
29 %<*driver>
30
31 \documentclass{ltxdoc}
32 \usepackage{docmfp}
33 \usepackage{url}
34 \usepackage[typeone]{dozenal}
35 \usepackage{verbatim}
36 \usepackage{mflogo}
37 \usepackage[everymp={input roundrect;},latex]{gmp}
38 \usepackage{makeidx}
39 \makeindex
40 \def\hanger{\parindent=0em\hangindent=2em\hangafter=1}
41 \def\thepar#1{\hbox{\parbox{0.5\linewidth}{\hanger\raggedright\ttfamily #1}}}
42 \long\def\demonstrate#1#2{%
43 \bigskip%
44 \hrule%
45 \hbox to\linewidth{%
46 \hbox to0.5\linewidth{%
47 \vbox to2in{\vfil#1\vfil}%
48 }\hbox to0.5\linewidth{%
49 \vbox to2in{\vfil#2\vfil}%
50 }%
51 }%
52 \hrule%
53 \bigskip%
54 }
55
56 \begin{document}
57 \DocInput{roundrect.dtx}
58 \end{document}
59 %</driver>
60 % \fi
61 % \title{The \texttt{roundrect} Macros, v2.2}
62 % \author{Donald P.\ Goodman III}
63 % \date{\today}
64 %
65 % \maketitle
66 % \begin{abstract}\noindent
67 % The |roundrect| macros for \MP\ provide extremely
68 % configurable, extremely versatile rectangles (including
69 % rounded corners), intended primarily for inclusion in
70 % documents produced by \TeX\ and friends. The idea was to
71 % provide a \MP-based replacement for the incredibly
72 % versatile |tcolorbox| package; the macros are far from
73 % achieving that goal. But they are nevertheless extremely
74 % useful.
75 % \end{abstract}
76 %
77 % \tableofcontents
78 %
79 % \section{Introduction}
80 %
81 % While Ti\textit{k}Z and its many accompanying packages,
82 % particularly |tcolorbox|, are wonderful and powerful
83 % tools, whenever using them I inevitably feel completely
84 % lost, and I exert great effort doing comparatively simple
85 % things. Contrariwise, thanks to my experience with the
86 % |drm| and |dozenal| packages, writing in \MP\ is quite
87 % straightforward for me. So I decided to try to write some
88 % generalized macros to provide functionality similar to
89 % that of |tcolorbox|. It's not even close to that kind of
90 % flexibility or power, but it's still quite useful and
91 % versatile, so I make it available for anyone who might be
92 % interested.
93 %
94 % This document was typeset in accordance with the
95 % |docstrip| utility, which allows the automatic extraction
96 % of code and documentation from the same document.
97 %
98 % \section{Prerequisites and Conventions}
99 %
100 % Some prerequesites for using this package are \MP\ itself
101 % (obviously). If you're using the package with \LaTeX, the
102 % |gmp| package would probably be helpful; be sure to use
103 % the |latex| package option. Finally, the
104 % package internally calls |TEX.mp|, so that is also
105 % required. All of these should be packaged in any
106 % reasonably modern \LaTeX\ system, such as \TeX Live or
107 % Mik\TeX.
108 %
109 % This documentation assumes nothing about your personal
110 % \TeX\ or \MP\ environment. Con\TeX t and the various
111 % forms of Lua\TeX\ have \MP\ built-in; with pdf\LaTeX, the
112 % author's choice, one can use the |gmp| package to
113 % include the source directly in one's document (that's
114 % what's been done in this documentation) or develop a
115 % simple script to compile them afterwards and include them
116 % in the source via |\includegraphics| (probably the
117 % quickest option, since compilation is done in advance).
118 % Here, we simply post the plain vanilla \MP\ code, and let
119 % you work out those details however you prefer.
120 %
121 % \section{Shapes and Styles}
122 %
123 % The core of all the action is the
124 % \DescribeMacro{roundrect}|roundrect| macro; this
125 % will set up your rounded rectangle in the plainest
126 % way possible. The first argument is the box's height, the
127 % second its width, and the third its name, by which you
128 % will draw it later:
129 %
130 % \demonstrate{%
131 % \thepar{roundrect(1in,2in)(rectangle);}
132 % \thepar{draw rectangle;}
133 % }{%
134 % \begin{mpost}
135 % roundrect(1in,2in)(rectangle);
136 % draw rectangle;
137 % \end{mpost}
138 % }%
139 %
140 % All the corners don't \emph{have} to be rounded; we can
141 % make them square if we want. To do things like this, we
142 % use the macro
143 % \DescribeMacro{rrborderrad()}|rrborderrad()|, which takes
144 % a single argument giving the border radius we want; that
145 % is, how rounded we want the corners of our rectangle.
146 % Higher values will be more rounded, lower values will be
147 % less:
148 %
149 % \demonstrate{%
150 % \thepar{rrborderrad(10pt);}
151 % \thepar{roundrect(1in,2in)(rectangle);}
152 % \thepar{draw rectangle;}
153 % }{%
154 % \begin{mpost}
155 % rrborderrad(10pt);
156 % roundrect(1in,2in)(rectangle);
157 % draw rectangle;
158 % \end{mpost}
159 % }%
160 %
161 % Notice that the corners in this, with |rrborderrad()| set
162 % to |10pt|, are much less rounded than the previous
163 % example. The default border radius is |40pt|, which is
164 % quite rounded.
165 %
166 % |rrborderrad()| provides an easy way to set the border
167 % radius of all four corners at once; however, we can also
168 % control each corner individually, with
169 % \DescribeMacro{rrtoplftborderrad}|rrtoplftborderrad|,
170 % \DescribeMacro{rrbotlftborderrad}|rrbotlftborderrad|,
171 % \DescribeMacro{rrtoprtborderrad}|rrtoprtborderrad|, and
172 % \DescribeMacro{rrbotrtborderrad}|rrbotrtborderrad|, which
173 % are parameters rather than macros; that is, we define them
174 % using |:=| rather than as an argument in parentheses:
175 %
176 % \demonstrate{%
177 % \thepar{rrtoplftborderrad := 20pt;}
178 % \thepar{rrbotlftborderrad := 40pt;}
179 % \thepar{rrtoprtborderrad := 10pt;}
180 % \thepar{rrbotrtborderrad := 60pt;}
181 % \thepar{roundrect(1in,2in)(rectangle);}
182 % \thepar{draw rectangle;}
183 % }{%
184 % \begin{mpost}
185 % rrtoplftborderrad := 20pt;
186 % rrbotlftborderrad := 40pt;
187 % rrtoprtborderrad := 10pt;
188 % rrbotrtborderrad := 60pt;
189 % roundrect(1in,2in)(rectangle);
190 % draw rectangle;
191 % \end{mpost}
192 % }%
193 %
194 % As you can see, this makes it possible to create a large
195 % variety of shapes, including the ability to arbitrarily
196 % flatten any side of the rectangle desired just by setting
197 % the border radius of the appropriate corners to |0pt|:
198 %
199 % \demonstrate{%
200 % \thepar{rrtoplftborderrad := 0pt;}
201 % \thepar{rrtoprtborderrad := 0pt;}
202 % \thepar{roundrect(1in,2in)(rectangle);}
203 % \thepar{draw rectangle;}
204 % }{%
205 % \begin{mpost}
206 % rrtoplftborderrad := 0pt;
207 % rrtoprtborderrad := 0pt;
208 % roundrect(1in,2in)(rectangle);
209 % draw rectangle;
210 % \end{mpost}
211 % }%
212 %
213 % Here, we've flattened the top border by setting the top
214 % right and top left corners' border radii to |0pt|.
215 % This ability to flatten any given side of the rectangle
216 % makes it much easier to combine multiple rectangles into
217 % interesting forms, which we'll see a bit more about later.
218 %
219 % \section{Coloring the Parts}
220 % \label{sect:colorpart}
221 %
222 % The colors of the |roundrect| are extremely configurable,
223 % both on the whole and for individual parts. The
224 % background color of the |roundrect| is controlled by
225 % \DescribeMacro{rrinnercolor}|rrinnercolor|, while the
226 % border is colored by
227 % \DescribeMacro{rrbordercolor}|rrbordercolor()|.
228 %
229 % \demonstrate{%
230 % \thepar{rrbordercolor(blue);}
231 % \thepar{rrinnercolor := red;}
232 % \thepar{roundrect(1in,2in)(rectangle);}
233 % \thepar{draw rectangle;}
234 % }{%
235 % \begin{mpost}
236 % rrbordercolor(blue);
237 % rrinnercolor := red;
238 % roundrect(1in,2in)(rectangle);
239 % draw rectangle;
240 % \end{mpost}
241 % }%
242 %
243 % By default, |rrinnercolor| is white and |rrbordercolor| is
244 % black. Notice that |rrbordercolor| is a \emph{macro}, not
245 % a parameter; that's because each border can be
246 % individually colored, and this macro simply does all of
247 % them at once. We'll see more about that later.
248 %
249 % You can also completely suppress the border by using
250 % \DescribeMacro{rrnotop}|rrnotop|,
251 % \DescribeMacro{rrnobot}|rrnobot|,
252 % \DescribeMacro{rrnolft}|rrnolft|, and
253 % \DescribeMacro{rrnort}|rrnort|, which is particularly
254 % useful when you want to combine multiple rectangles
255 % without making an obvious border between them. You can
256 % combine these in any way you like:
257 %
258 % \demonstrate{%
259 % \thepar{rrbordercolor(blue);}
260 % \thepar{rrinnercolor := red;}
261 % \thepar{rrnotop := true;}
262 % \thepar{rrnobot := true;}
263 % \thepar{rrborderrad(0pt);}
264 % \thepar{roundrect(1in,2in)(rectangle);}
265 % \thepar{draw rectangle;}
266 % }{%
267 % \begin{mpost}
268 % rrbordercolor(blue);
269 % rrinnercolor := red;
270 % rrnotop := true;
271 % rrnobot := true;
272 % rrborderrad(0pt);
273 % roundrect(1in,2in)(rectangle);
274 % draw rectangle;
275 % \end{mpost}
276 % }%
277 %
278 % Here we've squared all the corners to make it easier to
279 % see what's going on.
280 %
281 % Each border can be colored individually and separately
282 % from the others, using the commands you'd expect:
283 %
284 % \demonstrate{%
285 % \thepar{rrtopbordercolor := blue;}
286 % \thepar{rrbotbordercolor := green;}
287 % \thepar{rrlftbordercolor := red;}
288 % \thepar{rrrtbordercolor := black;}
289 % \thepar{rrborderrad(20pt);}
290 % \thepar{roundrect(1in,2in)(rectangle);}
291 % \thepar{draw rectangle;}
292 % }{%
293 % \begin{mpost}
294 % rrtopbordercolor := blue;
295 % rrbotbordercolor := green;
296 % rrlftbordercolor := red;
297 % rrrtbordercolor := black;
298 % rrborderrad(20pt);
299 % roundrect(1in,2in)(rectangle);
300 % draw rectangle;
301 % \end{mpost}
302 % }%
303 %
304 % There is obviously some difficulty in determining what
305 % part of each rounded corner should be colored how; this
306 % ability is typically more useful with a single, flattened
307 % side, to help it blend in better when combined with other
308 % constructs:
309 %
310 % \demonstrate{%
311 % \thepar{rrbordercolor(black);}
312 % \thepar{rrbotbordercolor := green;}
313 % \thepar{rrinnercolor := red;}
314 % \thepar{rrborderrad(20pt);}
315 % \thepar{rrbotlftborderrad := 0pt;}
316 % \thepar{rrbotrtborderrad := 0pt;}
317 % \thepar{roundrect(1in,2in)(rectangle);}
318 % \thepar{draw rectangle;}
319 % }{%
320 % \begin{mpost}
321 % rrbordercolor(black);
322 % rrbotbordercolor := green;
323 % rrinnercolor := red;
324 % rrborderrad(20pt);
325 % rrbotlftborderrad := 0pt;
326 % rrbotrtborderrad := 0pt;
327 % roundrect(1in,2in)(rectangle);
328 % draw rectangle;
329 % \end{mpost}
330 % }
331 %
332 % Perhaps you don't like the border; you'd like it thicker,
333 % or drawn with a square rather than a circular pen. You're
334 % in luck; \DescribeMacro{rrborderpen()}|rrborderpen()|
335 % takes the single argument of the pen you'd like to draw
336 % the border with, defined like any other \MP\ pen:
337 %
338 % \demonstrate{%
339 % \thepar{rrborderpen(pensquare scaled 3);}
340 % \thepar{roundrect(1in,2in)(rectangle);}
341 % \thepar{draw rectangle;}
342 % }{%
343 % \begin{mpost}
344 % rrborderpen(pensquare scaled 3);
345 % roundrect(1in,2in)(rectangle);
346 % draw rectangle;
347 % \end{mpost}
348 % }
349 %
350 % The default border pen is |pencircle scaled 1.5|, so this
351 % results in a square pen rather than a circular one, twice
352 % as thick. You can also use individual pens for each
353 % border, as expected:
354 %
355 % \demonstrate{%
356 % \thepar{rrbotlftborderrad := 0pt;}
357 % \thepar{rrbotrtborderrad := 0pt;}
358 % \thepar{rrbotbordercolor := green;}
359 % \thepar{rrbotborderpen := pensquare yscaled 6;}
360 % \thepar{roundrect(1in,2in)(rectangle);}
361 % \thepar{draw rectangle;}
362 % }{%
363 % \begin{mpost}
364 % rrbotlftborderrad := 0pt;
365 % rrbotrtborderrad := 0pt;
366 % rrbotbordercolor := green;
367 % rrbotborderpen := pensquare yscaled 6;
368 % roundrect(1in,2in)(rectangle);
369 % draw rectangle;
370 % \end{mpost}
371 % }
372 %
373 % Here we've flattened the bottom border, colored it green,
374 % and drawn it with a square pen scaled on the y-axis only
375 % by 6. Clearly, there are huge possibilities here.
376 %
377 % \section{Drop Shadows}
378 % \label{sect:dropshadows}
379 %
380 % We can also put a \emph{shadow} on the boxes using
381 % \DescribeMacro{rrdropshadow}|rrdropshadow|, a boolean
382 % value which defaults to |false|:
383 %
384 % \demonstrate{%
385 % \thepar{rrdropshadow := true;}
386 % \thepar{roundrect(1in,2in)(rectangle);}
387 % \thepar{draw rectangle;}
388 % }{%
389 % \begin{mpost}
390 % rrdropshadow := true;
391 % roundrect(1in,2in)(rectangle);
392 % draw rectangle;
393 % \end{mpost}
394 % }%
395 %
396 % The drop shadow always mimics the shape of the box itself;
397 % there is presently no way to avoid that. If for some
398 % reason you want to, you'll have to create a separate
399 % |roundrect| and place it manually.
400 %
401 % We can control the size and direction of the drop shadow
402 % fairly easily, however, along with its color. Its color
403 % is controlled by
404 % \DescribeMacro{rrshadowcolor}|rrshadowcolor|, which
405 % can be set to any arbitrary \MP\ color:
406 %
407 % \demonstrate{%
408 % \thepar{rrdropshadow := true;}
409 % \thepar{rrshadowcolor := blue;}
410 % \thepar{roundrect(1in,2in)(rectangle);}
411 % \thepar{draw rectangle;}
412 % }{%
413 % \begin{mpost}
414 % rrdropshadow := true;
415 % rrshadowcolor := blue;
416 % roundrect(1in,2in)(rectangle);
417 % draw rectangle;
418 % \end{mpost}
419 % }%
420 %
421 % The position of the drop shadow is governed by
422 % \DescribeMacro{rrshadowx}|rrshadowx| and
423 % \DescribeMacro{rrshadowy}|rrshadowy|, which will shift the
424 % |roundrect| on the |x| or |y| axis, respectively. By
425 % default, these are set to one quarter of the border radius
426 % in effect for the bottom left corner:
427 %
428 % \demonstrate{%
429 % \thepar{rrdropshadow := true;}
430 % \thepar{rrshadowcolor := blue;}
431 % \thepar{rrshadowx := -rrbotlftborderrad/4;}
432 % \thepar{rrshadowy := rrbotlftborderrad/4;}
433 % \thepar{roundrect(1in,2in)(rectangle);}
434 % \thepar{draw rectangle;}
435 % }{%
436 % \begin{mpost}
437 % rrdropshadow := true;
438 % rrshadowcolor := blue;
439 % rrshadowx := -rrbotlftborderrad/4;
440 % rrshadowy := rrbotlftborderrad/4;
441 % roundrect(1in,2in)(rectangle);
442 % draw rectangle shifted (1in,0.5in);
443 % \end{mpost}
444 % }%
445 %
446 % \section{Including Text}
447 % \label{sect:text}
448 %
449 % Finally, we can put text in the rectangles; this is as
450 % configurable as everything else:
451 %
452 % \demonstrate{%
453 % \thepar{rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";}
454 % \thepar{roundrect(1in,2in)(rectangle);}
455 % \thepar{draw rectangle;}
456 % }{%
457 % \begin{mpost}
458 % rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";
459 % roundrect(1in,2in)(rectangle);
460 % draw rectangle;
461 % \end{mpost}
462 % }
463 %
464 % The font and style of the text can be controlled with
465 % \DescribeMacro{rrtextfont}|rrtextfont|, and the color of
466 % the text can be controlled with
467 % \DescribeMacro{rrtextcolor}|rrtextcolor|:
468 %
469 % \demonstrate{%
470 % \thepar{rrbodytext := "Text in a label";}
471 % \thepar{rrtextcolor := green;}
472 % \thepar{rrtextalign := "$\backslash$raggedleft";}
473 % \thepar{rrtextfont := "$\backslash$fontsize{17pt}{19pt}$\backslash$ selectfont$\backslash$ itshape";}
474 % \thepar{roundrect(1in,2in)(rectangle);}
475 % \thepar{draw rectangle;}
476 % }{%
477 % \begin{mpost}
478 % rrbodytext := "Text in a label";
479 % rrtextcolor := green;
480 % rrtextalign := "\unexpanded{\raggedleft}";
481 % rrtextfont := "\unexpanded{\fontsize{17pt}{19pt}\selectfont\itshape"};
482 % roundrect(1in,2in)(rectangle);
483 % draw rectangle;
484 % \end{mpost}
485 % }
486 %
487 % We also used, without explaining it first,
488 % \DescribeMacro{rrtextalign}|rrtextalign|, which allows
489 % insertion of text alignment commands. This can also be
490 % inserted in the |rrtextfont| variable, but it seemed
491 % logical to have a separate parameter for it. It's default
492 % is |\centering|.
493 %
494 % The width of the text is governed by
495 % \DescribeMacro{rrtextwd}|rrtextwd|, which defaults to the
496 % same width as the rectangle with a |3pt| buffer on either
497 % side. The buffer is not directly controllable, but the
498 % width can be set however you like:
499 %
500 % \demonstrate{%
501 % \thepar{rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";}
502 % \thepar{rrtextwd := 80pt;}
503 % \thepar{roundrect(1in,2in)(rectangle);}
504 % \thepar{draw rectangle;}
505 % }{%
506 % \begin{mpost}
507 % rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";
508 % rrtextwd := 80pt;
509 % roundrect(1in,2in)(rectangle);
510 % draw rectangle;
511 % \end{mpost}
512 % }
513 %
514 % Finally, to restore all these values to the default, use
515 % the |rrrestorevals;| directive. This will clear
516 % everything to default so you can have a completely
517 % different |roundrect| in the same figure.
518 %
519 % \section{Using External Packages in Text}
520 %
521 % Frequently, of course, the |rrtextfont| options will be
522 % either insufficient or overly cumbersome for your needs.
523 % For example, you might want \emph{all} the text in your
524 % labels to be in a different font; to match your main body
525 % font, for example.
526 %
527 % |roundrect| offers
528 % \DescribeMacro{rrusepackage}|rrusepackage| for this
529 % purpose. It is a string, designed specifically for the
530 % purpose of including arbitrary \LaTeX\ packages for
531 % typesetting text. For example, if your main body font is
532 % EB Garamond, the easiest way to get your text to match
533 % that is to ask \MP\ to use the |ebgaramond| package when
534 % it typesets:
535 %
536 % \demonstrate{%
537 % \thepar{rrusepackage := "$\backslash$usepackage\{ebgaramond\}";\hfill\break}
538 % \thepar{rrbodytext := "This is $\backslash$textsw\{EB\} Garamond, not Computer Modern.";\hfill\break}
539 % \thepar{roundrect(1in,2in)(rectangle);\hfill\break}
540 % \thepar{draw rectangle;\hfill\break}
541 % }{%
542 % \begin{mpost}
543 % rrbodytext := "This is \unexpanded{\textsw{EB}} Garamond, not Computer Modern.";
544 % rrusepackage := "\unexpanded{\usepackage{ebgaramond}}";
545 % roundrect(1in,2in)(rectangle);
546 % draw rectangle;
547 % \end{mpost}
548 % }
549 %
550 % Notice that |rrusepackage := "\usepackage{ebgaramond}";|
551 % takes care of changing the body font \emph{and} of
552 % defining the |\textsw| environment (itself defined in
553 % |ebgaramond|), which we would otherwise have to do
554 % separately.
555 %
556 % To switch this back, simply reset the string to empty:
557 %
558 % \demonstrate{%
559 % \thepar{rrusepackage := "";\hfill\break}
560 % \thepar{rrbodytext := "This is Computer Modern, not EB Garamond.";\hfill\break}
561 % \thepar{roundrect(1in,2in)(rectangle);\hfill\break}
562 % \thepar{draw rectangle;\hfill\break}
563 % }{%
564 % \begin{mpost}
565 % rrbodytext := "This is Computer Modern, not EB Garamond.";
566 % rrusepackage := "";
567 % roundrect(1in,2in)(rectangle);
568 % draw rectangle;
569 % \end{mpost}
570 % }
571 %
572 % Using color commands (e.g., from |color| or |xcolor|) will
573 % not throw errors, provided the appropriate package is
574 % included; however, it will not work. This seems to be an
575 % unavoidable consequence of the way that |TEX.mp| works;
576 % \TeX\ |\special| commands are destroyed in the process,
577 % and there isn't really a robust way to do it without this
578 % effect.
579 %
580 % \section{Implementation}
581 %
582 % \begin{macrocode}
583 input TEX;
584 color rrinnercolor; rrinnercolor := white;
585 numeric rrtoprtborderrad; rrtoprtborderrad := 40pt;
586 numeric rrbotrtborderrad; rrbotrtborderrad := 40pt;
587 numeric rrbotlftborderrad; rrbotlftborderrad := 40pt;
588 numeric rrtoplftborderrad; rrtoplftborderrad := 40pt;
589 numeric rrtextwd; rrtextwd := 0;
590 numeric rrshadowx; rrshadowx := rrbotrtborderrad/4;
591 numeric rrshadowy; rrshadowy := -rrbotrtborderrad/4;
592 string rrtextfont; rrtextfont := "\fontsize{10pt}{12pt}\selectfont ";
593 color rrtextcolor; rrtextcolor := black;
594 string rrbodytext; rrbodytext := "";
595 string rrtextalign; rrtextalign := "\centering";
596 string rrusepackage; rrusepackage := "";
597 boolean rrnotop; rrnotop := false;
598 boolean rrnobot; rrnobot := false;
599 boolean rrnolft; rrnolft := false;
600 boolean rrnort; rrnort := false;
601 boolean rrdropshadow; rrdropshadow := false;
602 color rrtopbordercolor; rrtopbordercolor := black;
603 color rrbotbordercolor; rrbotbordercolor := black;
604 color rrlftbordercolor; rrlftbordercolor := black;
605 color rrrtbordercolor; rrrtbordercolor := black;
606 color rrshadowcolor; rrshadowcolor := black;
607 def rrbordercolor(expr x) =
608 rrtopbordercolor := x;
609 rrbotbordercolor := x;
610 rrlftbordercolor := x;
611 rrrtbordercolor := x;
612 enddef;
613 def rrborderrad(expr x) =
614 rrtoplftborderrad := x;
615 rrbotlftborderrad := x;
616 rrtoprtborderrad := x;
617 rrbotrtborderrad := x;
618 enddef;
619 pen rrtopborderpen; rrtopborderpen := pencircle scaled 1.5;
620 pen rrbotborderpen; rrbotborderpen := pencircle scaled 1.5;
621 pen rrlftborderpen; rrlftborderpen := pencircle scaled 1.5;
622 pen rrrtborderpen; rrrtborderpen := pencircle scaled 1.5;
623 def rrborderpen(expr x) =
624 rrtopborderpen := x;
625 rrbotborderpen := x;
626 rrlftborderpen := x;
627 rrrtborderpen := x;
628 enddef;
629 def rrrestorevals =
630 rrborderrad(40pt);
631 rrbordercolor(black);
632 rrborderpen(pencircle scaled 1.5);
633 rrinnercolor := white;
634 rrnotop := false;
635 rrnobot := false;
636 rrnolft := false;
637 rrnort := false;
638 rrtextwd := 0;
639 rrtextfont := "\fontsize{10pt}{12pt}\selectfont ";
640 rrtextcolor := black;
641 rrbodytext := "";
642 rrtextalign; rrtextalign := "\centering";
643 rrdropshadow := false;
644 rrshadowcolor := black;
645 rrshadowx := rrbotrtborderrad/4;
646 rrshadowy := -rrbotrtborderrad/4;
647 enddef;
648 def roundrect(expr rrht, rrwd)(suffix name) =
649 TEXPRE("%&latex" & char(10) & "\documentclass{article}" & rrusepackage & "\begin{document}");
650 TEXPOST("\end{document}");
651 if (rrtextwd = 0):
652 rrtextwd := rrwd - 12pt;
653 fi
654 path rra; path rrb; path rrc; path rrd;
655 pair a; pair b; pair c; pair d;
656 a := (0,0) shifted (-rrwd/2,-rrht/2);
657 b := (0,0) shifted (rrwd/2,-rrht/2);
658 c := (0,0) shifted (rrwd/2,rrht/2);
659 d := (0,0) shifted (-rrwd/2,rrht/2);
660 rra := fullcircle scaled rrbotlftborderrad shifted (xpart a +
661 (rrbotlftborderrad/2),ypart a + (rrbotlftborderrad/2));
662 rrb := fullcircle scaled rrbotrtborderrad shifted (xpart b -
663 (rrbotrtborderrad/2),ypart b + (rrbotrtborderrad/2));
664 rrd := fullcircle scaled rrtoplftborderrad shifted (xpart d +
665 (rrtoplftborderrad/2),ypart d - (rrtoplftborderrad/2));
666 rrc := fullcircle scaled rrtoprtborderrad shifted (xpart c -
667 (rrtoprtborderrad/2),ypart c - (rrtoprtborderrad/2));
668 pair f; f := (a--b) intersectionpoint rra;
669 pair g; g := (a--b) intersectionpoint rrb;
670 pair h; h := (b--c) intersectionpoint rrb;
671 pair i; i := (b--c) intersectionpoint rrc;
672 pair j; j := (c--d) intersectionpoint rrc;
673 pair k; k := (c--d) intersectionpoint rrd;
674 pair l; l := (d--a) intersectionpoint rrd;
675 pair m; m := (d--a) intersectionpoint rra;
676 picture name;
677 picture border;
678 picture rrtext;
679 pair n; pair o;
680 path rrtoplftcorner; path rrbotlftcorner;
681 path rrtoprtcorner; path rrbotrtcorner;
682 path rrtopborder; path rrbotborder;
683 path rrlftborder; path rrrtborder;
684 rrtoplftcorner := l{up}..{right}k;
685 rrtoprtcorner := j{right}..{down}i;
686 rrbotrtcorner := h{down}..{left}g;
687 rrbotlftcorner := f{left}..{up}m;
688 rrtopborder := rrtoplftcorner--rrtoprtcorner;
689 rrbotborder := rrbotrtcorner--rrbotlftcorner;
690 rrlftborder := rrbotlftcorner--rrtoplftcorner;
691 rrrtborder := rrtoprtcorner--rrbotrtcorner;
692 picture rrdropshadowpic;
693 if (rrdropshadow = true):
694 rrdropshadowpic := image(fill rrtoplftcorner--rrtoprtcorner--
695 rrbotrtcorner--rrbotlftcorner--cycle
696 shifted (rrshadowx,rrshadowy) withcolor
697 rrshadowcolor);
698 else:
699 rrdropshadowpic := currentpicture;
700 fi
701 name := currentpicture;
702 addto name also rrdropshadowpic;
703 rrdropshadowpic := image(fill rrtoplftcorner--rrtoprtcorner--
704 rrbotrtcorner--rrbotlftcorner--cycle withcolor
705 rrinnercolor);
706 addto name also rrdropshadowpic;
707 % name := image(fill rrtoplftcorner--rrtoprtcorner--
708 % rrbotrtcorner--rrbotlftcorner--cycle withcolor
709 % rrinnercolor);
710 picture rrtmpborder;
711 border := currentpicture;
712 if (rrnotop = false):
713 rrtmpborder := image(draw rrtopborder withcolor
714 rrtopbordercolor withpen rrtopborderpen);
715 addto border also rrtmpborder;
716 fi
717 if (rrnobot = false):
718 rrtmpborder := image(draw rrbotborder withcolor
719 rrbotbordercolor withpen rrbotborderpen);
720 addto border also rrtmpborder;
721 fi
722 if (rrnolft = false):
723 rrtmpborder := image(draw rrlftborder withcolor
724 rrlftbordercolor withpen rrlftborderpen);
725 addto border also rrtmpborder;
726 fi
727 if (rrnort = false):
728 rrtmpborder := image(draw rrrtborder withcolor
729 rrrtbordercolor withpen rrrtborderpen);
730 addto border also rrtmpborder;
731 fi
732 addto name also border;
733 rrtext :=
734 image(label(TEX("\parbox{"&decimal(rrtextwd)&"bp}{"&rrtextalign&rrtextfont&" "&rrbodytext&"}"),(0,0)) withcolor rrtextcolor;);
735 addto name also rrtext;
736 enddef;
737 % \end{macrocode}