Debian Codegraph @

texmf-dist/source/latex/makeshape/makeshape.dtx

raw
1 % \iffalse meta-comment
2 %
3 % makeshape.dtx
4 % 25 January 2013
5 %
6 % This is version 1.0 of makeshape.dtx
7 % It generates a style file (makeshape.sty), a sample shape (sampleshape.tex),
8 % and a user guide and documentation (makeshape.pdf).
9 %
10 % Generation of the makeshape.sty and sampleshape.tex is with
11 % pdflatex makeshape.ins
12 % which contains
13 % \generate{\file{makeshape.sty}
14 % {\from{makeshape.dtx}{package}}}
15 % \generate{\file{sampleshape.tex}
16 % {\from{makeshape.dtx}{sample}}}
17 %
18 % Generation of makeshape.pdf is with
19 % pdflatex makeshape.dtx
20 %
21 % The \OnlyDescription command is used to suppress implementation
22 % documentation.
23 %
24 % This is part of Silhouette 2.1
25 %
26 % -----------------------------------------------------------
27 % \fi
28 %
29 %^^A-------------------------------------------------------------------
30 %^^A .sty file header
31 %^^A-------------------------------------------------------------------
32 % \iffalse
33 %<package>\NeedsTeXFormat{LaTeX2e}[2011/06/27]
34 %^^A - ** Use package version number (not file version) **
35 %<package>\ProvidesPackage{makeshape}
36 %<package> [2013/01/25 2.1 Making custom shapes for PGF/TikZ]
37 %<package>\RequirePackage{tikz}
38 %<package>\usepgflibrary{intersections}
39 %
40 %^^A-------------------------------------------------------------------
41 %^^A Preamble for documentation
42 %^^A-------------------------------------------------------------------
43 %<*driver>
44 \documentclass[10pt,a4paper]{ltxdoc}
45
46 \usepackage[T1]{fontenc}
47 \usepackage{lmodern}
48
49 \usepackage{fancyvrb}
50 \usepackage{enumitem}
51 \usepackage{url}
52 \usepackage{bigstrut}
53 \usepackage[draft]{hyperref}
54 %\usepackage{hyperref}
55
56 \usepackage{tikz}
57 \usetikzlibrary{patterns}
58 \usetikzlibrary{arrows}
59 \usetikzlibrary{positioning}
60 \usepgflibrary{intersections}
61
62 \input{sampleshape} % includes makeshape.sty
63
64 \newcommand{\mnote}[1]
65 {\marginpar{\scriptsize \raggedright #1 }}
66
67 \newcommand{\pfgManCiteA}{\cite{pgfMan}, \emph{Constructing Paths}, \S71, pp 579-589}
68 \newcommand{\pfgManCiteB}{\cite{pgfMan}, \emph{Declaring New Shapes}, \S75.5, pp 625-631}
69
70 \EnableCrossrefs
71 \CodelineIndex
72 \RecordChanges
73 \OnlyDescription % comment out for code implementation
74
75 \begin{document}
76 \DocInput{makeshape.dtx}
77 \end{document}
78 %</driver>
79 % \fi
80 %
81 %^^A-------------------------------------------------------------------
82 %^^A Change log...
83 %^^A-------------------------------------------------------------------
84 %^^A
85 %^^A 0.0 - 5 January 2013
86 % \changes{0.0}{2013/01/05}{
87 % Experimental -
88 % Develop the style file and a sample shape.
89 % Write the user guide.
90 % Incorporate makeshape.sty generation and documentation.
91 % Generate the samplshape.tex file.
92 % }
93 %^^A
94 %^^A 0.1 - 11 January 2013
95 % \changes{0.1}{2013/01/11}{
96 % Experimental -
97 % Fix the sample shape's cardinal anchor points problem by
98 % correcting a bug in the north-east saved anchor.
99 % Correct errors in the user guide and fill in omissions.
100 % \emph{Experimental phase complete.}}
101 %^^A
102 %^^A 25 January 2013
103 % \changes{1.0}{2013/01/25}{
104 % Prepare for publication -
105 % Very minor changes made to the style file code.
106 % Standard path commands used in sample shape code.
107 % A lot of the report is rewritten.
108 % An abstract is added, and its contents removed. }
109 %^^A
110 %^^A-------------------------------------------------------------------
111 %^^A Check sums...
112 %^^A-------------------------------------------------------------------
113 %
114 %^^A \CheckSum{0} ^^A no checksum for development
115 % \CheckSum{272}
116 % \CharacterTable
117 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
118 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
119 % Digits \0\1\2\3\4\5\6\7\8\9
120 % Exclamation \! Double quote \" Hash (number) \#
121 % Dollar \$ Percent \% Ampersand \&
122 % Acute accent \' Left paren \( Right paren \)
123 % Asterisk \* Plus \+ Comma \,
124 % Minus \- Point \. Solidus \/
125 % Colon \: Semicolon \; Less than \<
126 % Equals \= Greater than \> Question mark \?
127 % Commercial at \@ Left bracket \[ Backslash \\
128 % Right bracket \] Circumflex \^ Underscore \_
129 % Grave accent \` Left brace \{ Vertical bar \|
130 % Right brace \} Tilde \~}
131 %
132 %^^A===========================================================================
133 %^^A Generate figure files for input into this report
134 %^^A===========================================================================
135 %
136 %^^A---------------------------------------------------------------------------
137 %^^A Background path diagram file
138 %^^A---------------------------------------------------------------------------
139 % \begin{VerbatimOut}[gobble=5]{msbackground.tmp}
140 % %^^A - The background path diagram, part of makeshape,dtx
141 % %^^A - This is a temporary file and should be deleted
142 % %^^A
143 % \begin{tikzpicture}[>=latex',font={\sf \small}]
144 %
145 % %^^A-- diagram 1 --------------------------------------------
146 % \begin{scope}
147 %
148 % \def\ctbw{88pt}
149 % \def\ctbh{14pt}
150 %
151 % \def\ctbnex{\ctbw/2}
152 % \def\ctbney{\ctbh/2}
153 %
154 % \node (outer) at (0,0) [draw, rectangle, pattern=crosshatch dots,
155 % minimum width=\ctbw+20pt,
156 % minimum height=\ctbh+20pt,
157 % ] {} ;
158 %
159 % \node at (\ctbnex,\ctbney) [circle, fill=white] {};
160 %
161 % \node (ctb) at (0,0) [draw, rectangle, fill=white,
162 % minimum width=\ctbw,
163 % minimum height=\ctbh,
164 % ] {};
165 %
166 % \node (ctbne) at (\ctbnex,\ctbney) [draw, circle] {};
167 %
168 % %^^A - Labels
169 % \node (ctbneLabel) at (4cm,1cm)
170 % [inner sep = 0] {(\verb|\ctbnex|,\verb|\ctbney|)};
171 % \node (ctbLabel) at (2cm,-1.2cm)
172 % [inner sep = 0] {corrected text box};
173 % \node (innerLabel) at (-1.8cm,1.2cm)
174 % [] {inner surface};
175 % \node (outerLabel) at (-2cm,-1.2cm)
176 % [inner sep = 0] {outer surface};
177 %
178 % \draw [->] (ctbneLabel.south west) -- (ctbne);
179 % \draw [->] (ctbLabel.north west) -- (ctb.320);
180 % \draw [->] (innerLabel.320) -- (ctb.160);
181 % \draw [->] (outerLabel.north east) -- (outer);
182 %
183 % %^^A - xy axis
184 % \draw [dotted] (0,0) -- ++(2.5cm,0); % origin
185 % \draw [dotted] (0,0) -- ++(-2.5cm,0); % origin
186 % \draw [dotted] (0,0) -- ++(0,1cm); % origin
187 % \draw [dotted] (0,0) -- ++(0,-1cm); % origin
188 %
189 % \end{scope}
190 %
191 % %^^A-- diagram 2 --------------------------------------------
192 % \begin{scope}[yshift=-4cm]
193 %
194 % \def\ctbw{88pt}
195 % \def\ctbh{14pt}
196 %
197 % \def\ctbnex{\ctbw/2}
198 % \def\ctbney{\ctbh/2}
199 %
200 % \node (outer) at (0,0) [draw, rectangle, pattern=crosshatch dots,
201 % minimum width=\ctbw+40pt,
202 % minimum height=\ctbh+40pt,
203 % ] {} ;
204 %
205 % \node at (\ctbnex,\ctbney) [circle, fill=white] {};
206 %
207 % \node (inner) at (0,0) [draw, rectangle, fill=white,
208 % minimum width=\ctbw+20pt,
209 % minimum height=\ctbh+20pt,
210 % ] {};
211 %
212 % \node (ctb) at (0,0) [draw, rectangle, fill=white,
213 % minimum width=\ctbw,
214 % minimum height=\ctbh,
215 % ] {};
216 %
217 % \node at (\ctbnex,\ctbney) [draw, circle] (ctbne) {};
218 %
219 % %^^A - Labels
220 % \node (ctbneLabel) at (4cm,1cm)
221 % [inner sep = 0] {(\verb|\ctbnex|,\verb|\ctbney|)};
222 % \node (ctbLabel) at (2cm,-1.5cm)
223 % [inner sep = 0] {corrected text box};
224 % \node (innerLabel) at (-2cm,-2cm)
225 % [inner sep = 0] {inner surface};
226 % \node (outerLabel) at (-2.5cm,-1.5cm)
227 % [inner sep = 0] {outer surface};
228 %
229 % \draw [->] (ctbneLabel.south west) -- (ctbne);
230 % \draw [->] (ctbLabel.north west) -- (ctb.320);
231 % \draw [->] (innerLabel.north east) -- (inner.250);
232 % \draw [->] (outerLabel.north east) -- (outer);
233 %
234 % %^^A - minimum dimensions
235 % \node (a) [coordinate, left=15pt of outer.south west] {};
236 % \node (b) [coordinate, left=15pt of outer.north west] {};
237 % \draw [|<->|] (a) -- (b) node [midway,left] {\tt minimum height};
238 %
239 % \node (c) [coordinate, above=15pt of outer.north west] {};
240 % \node (d) [coordinate, above=15pt of outer.north east] {};
241 % \draw [|<->|] (c) -- (d) node [midway,above] {\tt minimum width};
242 %
243 % %^^A - xy axis
244 % \draw [dotted] (0,0) -- ++(2.8cm,0); % origin
245 % \draw [dotted] (0,0) -- ++(-2.5cm,0); % origin
246 % \draw [dotted] (0,0) -- ++(0,1.2cm); % origin
247 % \draw [dotted] (0,0) -- ++(0,-1.2cm); % origin
248 %
249 % \end{scope}
250 %
251 % \end{tikzpicture}
252 % \end{VerbatimOut}
253 %
254 %^^A---------------------------------------------------------------------------
255 %^^A Anchor path diagram file
256 %^^A---------------------------------------------------------------------------
257 % \begin{VerbatimOut}[gobble=5]{msanchor.tmp}
258 % %^^A - The anchor path diagram, part of makeshape,dtx
259 % %^^A - This is a temporary file and should be deleted
260 % %^^A
261 % \begin{tikzpicture}[>=latex',font={\sf \small}]
262 %
263 % \def\ctbw{88pt}
264 % \def\ctbh{14pt}
265 %
266 % \def\ctbnex{\ctbw/2}
267 % \def\ctbney{\ctbh/2}
268 %
269 % %^^A-- diagram 1 --------------------------------------------
270 % \begin{scope}
271 %
272 % \node (outer) at (0,0) [draw, rectangle, pattern=crosshatch dots,
273 % minimum width=\ctbw+20pt,
274 % minimum height=\ctbh+20pt,
275 % ] {};
276 %
277 % \node at (\ctbnex,\ctbney) [circle, fill=white] {};
278 %
279 % \node (ctb) at (0,0) [draw, rectangle, fill=white,
280 % minimum width=\ctbw,
281 % minimum height=\ctbh,
282 % ] {};
283 %
284 % \node (ctbne) at (\ctbnex,\ctbney) [draw, circle] {};
285 %
286 % %^^A - Labels
287 % \node (ctbneLabel) at (4cm,1cm)
288 % [inner sep = 0] {(\verb|\ctbnex|,\verb|\ctbney|)};
289 % \node (ctbLabel) at (2cm,-1.2cm)
290 % [inner sep = 0] {corrected text box};
291 % \node (spaceLabel) at (-1.8cm,1.2cm)
292 % [] {background path space};
293 % \node (outerLabel) at (-2.3cm,-1.2cm)
294 % [inner sep = 0] {outer shape surface};
295 % \node (anchorLabel) at (-1.5cm,-1.7cm)
296 % [inner sep = 0] {anchor surface};
297 %
298 % \draw [->] (ctbneLabel.south west) -- (ctbne);
299 % \draw [->] (ctbLabel.north west) -- (ctb.320);
300 % \draw [->, shorten >=5pt] (spaceLabel.320) -- (ctb.160);
301 % \draw [->] (outerLabel.north east) -- (outer);
302 % \draw [->] (anchorLabel.north east) -- (outer);
303 %
304 % %^^A - xy axis
305 % \draw [dotted] (0,0) -- ++(2.5cm,0); % origin
306 % \draw [dotted] (0,0) -- ++(-2.5cm,0); % origin
307 % \draw [dotted] (0,0) -- ++(0,1cm); % origin
308 % \draw [dotted] (0,0) -- ++(0,-1cm); % origin
309 %
310 % \end{scope}
311 %
312 % %^^A-- diagram 2 --------------------------------------------
313 % \begin{scope}[yshift=-5cm]
314 %
315 % \node (anchor) at (0,0) [draw, rectangle,
316 % minimum width=\ctbw+70pt,
317 % minimum height=\ctbh+70pt,
318 % ] {} ;
319 %
320 % \node (outer) at (0,0) [draw, rectangle, pattern=crosshatch dots,
321 % minimum width=\ctbw+40pt,
322 % minimum height=\ctbh+40pt,
323 % ] {} ;
324 %
325 % \node at (\ctbnex,\ctbney) [circle, fill=white] {};
326 %
327 % \node (inner) at (0,0) [draw, rectangle, fill=white,
328 % minimum width=\ctbw+20pt,
329 % minimum height=\ctbh+20pt,
330 % ] {};
331 %
332 % \node (ctb) at (0,0) [draw, rectangle, fill=white,
333 % minimum width=\ctbw,
334 % minimum height=\ctbh,
335 % ] {};
336 %
337 % \node at (\ctbnex,\ctbney) [draw, circle] (ctbne) {};
338 %
339 % %^^A - Labels
340 % \node (ctbneLabel) at (4.3cm,1cm)
341 % [inner sep = 0] {(\verb|\ctbnex|,\verb|\ctbney|)};
342 % \node (ctbLabel) at (2cm,-1.8cm)
343 % [inner sep = 0] {corrected text box};
344 % \node (spaceLabel) at (-3.3cm,-1.8cm)
345 % [inner sep = 0] {background path space};
346 % \node (outerLabel) at (-2.8cm,-2.3cm)
347 % [inner sep = 0] {outer path surface};
348 % \node (anchorLabel) at (-2.7cm,-2.8cm)
349 % [inner sep = 0] {anchor path surface};
350 %
351 % \draw [->] (ctbneLabel.south west) -- (ctbne);
352 % \draw [->] (ctbLabel.north west) -- (ctb.320);
353 % \draw [->, shorten >=4pt] (spaceLabel.north east) -- (inner.210);
354 % \draw [->] (outerLabel.north east) -- (outer.227);
355 % \draw [->] (anchorLabel.north east) -- (anchor);
356 %
357 % %^^A - minimum dimensions
358 % \node (a) [coordinate, left=30pt of outer.south west] {};
359 % \node (b) [coordinate, left=30pt of outer.north west] {};
360 % \draw [|<->|] (a) -- (b) node [midway,left] {\tt minimum height};
361 %
362 % \node (c) [coordinate, above=30pt of outer.north west] {};
363 % \node (d) [coordinate, above=30pt of outer.north east] {};
364 % \draw [|<->|] (c) -- (d) node [midway,above] {\tt minimum width};
365 %
366 % \node (e) [coordinate, left=15pt of anchor.north west] {};
367 % \draw [<->|] (b) -- (e) node [midway,left] {\tt outer ysep};
368 %
369 % \node (f) [coordinate, above=15pt of anchor.north east] {};
370 % \draw [<->|] (d) -- (f) node [right,above] {\hspace{30pt}\tt outer xsep};
371 %
372 % \draw [dotted] (a) -- ++(30pt,0);
373 % \draw [dotted] (b) -- ++(30pt,0);
374 % \draw [dotted] (c) -- ++(0,-30pt);
375 % \draw [dotted] (d) -- ++(0,-30pt);
376 %
377 % %^^A - xy axis
378 % \draw [dotted] (0,0) -- ++(3cm,0); % origin
379 % \draw [dotted] (0,0) -- ++(-3cm,0); % origin
380 % \draw [dotted] (0,0) -- ++(0,1.2cm); % origin
381 % \draw [dotted] (0,0) -- ++(0,-1.2cm); % origin
382 %
383 % \end{scope}
384 %
385 % \end{tikzpicture}
386 % \end{VerbatimOut}
387 %
388 %^^A===========================================================================
389 %^^A Start report body
390 %^^A===========================================================================
391 %
392 % \GetFileInfo{makeshape.sty}
393 %
394 % \title{The {\sf makeshape} package\thanks{
395 % This document corresponds to \textsf{makeshape}~\fileversion,
396 % dated~\filedate.}\\
397 % and\\
398 % A Method for Creating Custom Shapes in PGF}
399 %
400 % \author{Adrian P. Robson\thanks{\texttt{[email protected]}}}
401 % \date{25 January 2013}
402 %
403 % \maketitle
404 %
405 %^^A - Abstract
406 % \vspace{-3ex}
407 % \begin{quote}
408 % The {\sf makeshape} package simplifies writing PGF shapes.
409 % Declaring a custom shape with a correct anchor border can be difficult.
410 % Complex shapes often need complicated calculations to find the touching point
411 % of a connecting line.
412 % This package only requires that a developer write a PGF path describing the
413 % anchor border.
414 % It also provides macros that help with the management of shape parameters
415 % and the definition of anchor points.
416 % \end{quote}
417 %
418 %
419 %^^A \tableofcontents
420 %
421 %\section{Introduction}
422 %
423 % The |\pgfdeclareshape| command can be used to create new shapes with the PGF package
424 % (\pfgManCiteB).
425 % The following are typically needed:
426 % \begin{itemize} [itemsep=-0.5ex]
427 % \item A shape name.
428 % \item Code for computing saved anchors and saved dimensions.
429 % \item Code for computing anchor positions in terms of the saved anchors.
430 % \item Code for computing border anchors (|\anchorborder|).
431 % \item Code for drawing a background path.
432 % \end{itemize}
433 % Writing these can be hard for completely new shapes, and in particular the declaration of a
434 % suitable |\anchorborder| command can be very difficult for complex shapes.
435 %
436 % \emph{This paper presents a method that makes the process of writing new shapes from scratch
437 % a little easier.}
438 % Its key features are:
439 % a mechanism for specifying the |\anchorborder| behaviour as a path;
440 % a package that provides a set of useful macros for writing and allocating anchor
441 % and background paths;
442 % and an example |\pgfdeclareshape| command that can be used as a template for new shapes.
443 %
444 % The method involves writing some original code and modifying the template.
445 % In brief, the process involves:
446 % \begin{enumerate} [itemsep=-0.5ex]
447 % \item Writing \emph{background path} and \emph{anchor path} macros.
448 % \item Writing one or more \emph{saved anchors}.
449 % \item Writing \emph{anchors} using the above saved anchors.
450 % \end{enumerate}
451 %
452 %
453 % \section{Preliminaries}
454 %
455 % \subsection{Background Path Macro}\label{sec:backgroundpath}
456 %
457 % \begin{figure}
458 % \begin{center}
459 % \input{msbackground.tmp}
460 % \end{center}
461 % \caption{The Background Path}\label{fig:backgroundpath}
462 % \end{figure}
463 %
464 % The \emph{background path}, as illustrated in figure~\ref{fig:backgroundpath},
465 % describes the curves that form the actual shape.
466 % It can be just a single line and does not have to be closed.
467 % However, there are no limits on is complexity.
468 % If it is more than a simple outline, then its \emph{inner} and \emph{outer} surfaces
469 % need to be considered separately.
470 %
471 % The inner surface should contain the \emph{corrected text box},
472 % which is the shape's text box surrounded by the space specified by its
473 % {\tt inner xsep} and {\tt inner ysep} keys.
474 % The coordinates of this box are given by the package's |\ctbnex| and |\ctbnex| macros,
475 % which are described in \S\ref{sec:corrctdTextBox}.
476 %
477 % The outer surface should have height and width dimensions that are the same as
478 % the shape's {\tt minimum} {\tt width} and {\tt minimum} {\tt height}
479 % keys if these are larger than the basic dimensions.
480 % These keys can be obtained with the |\pgfshapeminwidth| and |\pgfshapeminheight| macros,
481 % as described in \S\ref{sec:keycommands}.
482 % The |\mincorrect| macro described in \S\ref{sec:mincorrmacro} can be used make the necessary
483 % comparison and assignment.
484 %
485 % \subsubsection{Background Path Algorithm}\label{sec:backgroundpathmacro}
486 %
487 % The background path should be implemented as a macro with the following structure:
488 % \begin{enumerate}
489 %
490 % \item \label{item:ctb} Use |\ctbnex| and |\ctbnex|,
491 % which give the north east corner of the corrected text box,
492 % to calculate significant reference coordinates.
493 %
494 % \item \label{item:mindim} Use |\mincorrect| to modify the reference coordinates to
495 % take account of the shape's minimum dimension keys,
496 % which are given by |\pgfshapeminwidth| and |\pgfshapeminheight|.
497 %
498 %
499 % \item Use the reference coordinates from step \ref{item:mindim} to draw the actual path
500 % using PGF path commands (\pfgManCiteA). Typical commands are
501 % |\pgfpathmoveto|,
502 % |\pgfpathlineto| and
503 % |\pgfpathclose|.
504 % The |\pgfpoint| command will also be needed.
505 % Do this for
506 % \begin{enumerate}
507 % \item the outer surface curve, and \label{item:outer}
508 % \item curves in the shape's inner path space
509 % \end{enumerate}
510 % Usually when a path is defined, it is displayed with |\pgfusepath{stroke}|.
511 % However, it is not needed here.
512 %
513 % \end{enumerate}
514 %
515 % \subsection{Anchor Path Macro}\label{sec:anchorpath}
516 %
517 % The \emph{anchor path}, as illustrated in figure~\ref{fig:anchorpath},
518 % describes the curve that forms the surface where connecting lines meet the shape.
519 % It it must be a single closed path, and it is normally strongly related to
520 % background path's outer surface (see \S\ref{sec:backgroundpath}).
521 %
522 % Like the background path, it should use the fundamental reference point of the
523 % \emph{corrected text box}, which automatically includes the shape's inner
524 % separation.
525 % It should also take regard of the shape's {\tt minimum} {\tt width}
526 % and {\tt minimum} {\tt height} keys if these are larger than the basic dimensions.
527 % Furthermore, it should compensate for the {\tt outer} {\tt xsep} and {\tt outer} {\tt ysep}
528 % keys as shown in figure~\ref{fig:anchorpath}.
529 %
530 % The corrected text box macros are decribed in \S\ref{sec:corrctdTextBox}.
531 % The minimum dimension keys are given by |\pgfshapeminwidth| and |\pgfshapeminheight|,
532 % and the outer separation keys are given by |\pgfshapeouterxsep| and
533 % |\pgfshapeouterysep|, as described in \S\ref{sec:keycommands}.
534 % The minimum dimension comparision and assignment is provided by |\mincorect| macro,
535 % which is discussed in \S\ref{sec:mincorrmacro}.
536 %
537 % \subsubsection{Anchor Path Algorithm}\label{sec:anchorpathmacro}
538 %
539 %
540 % The anchor path should be implemented as a macro with the following structure:
541 % \begin{enumerate}
542 %
543 % \item Use |\ctbnex| and |\ctbnex|,
544 % which give the north east corner of the corrected text box,
545 % to calculate significant reference coordinates. (Normally the same as
546 % \S\ref{sec:backgroundpathmacro} step \ref{item:ctb}).
547 % \label{item:apctb}
548 %
549 % \item Use |\mincorrect| to modify the reference coordinates to
550 % take account of the shape's minimum dimension keys,
551 % which given by |\pgfshapeminwidth| and |\pgfshapeminheight|.
552 % (Normally the same as \S\ref{sec:backgroundpathmacro} step \ref{item:mindim}).
553 % \label{item:apmindim}
554 %
555 % \item Modify the reference coordinates to take account of outer separation,
556 % which is given by |\pgfshapeouterxsep| and |\pgfshapeouterysep|.
557 % \label{item:apouter}
558 %
559 % \item Use the corrected reference coordinates from step \ref{item:apouter} to specify
560 % the anchor path using PGF path commands (\pfgManCiteA).
561 % The path should be closed so a |\pgfpathclose| command is required.
562 % The path will not actually be drawn, and the |\pgfusepath{stroke}| macro
563 % should not be used.
564 % (Normally the same as \S\ref{sec:backgroundpathmacro} step \ref{item:outer}).
565 % \label{item:appath}
566 %
567 % \end{enumerate}
568 %
569 % \subsection{Anchors}
570 %
571 % A PGF shape requires the definition of a set of anchor point commands,
572 % and these need \emph{saved anchors} to provide necessary coordinates.
573 % All anchor macros should return a point coordinate by assigning values to the
574 % registers |\pgf@x| and |\pgf@y|.
575 %
576 % Like the anchor path macro, saved anchors should use the fundamental reference point of the
577 % \emph{corrected text box}, which automatically includes the shape's inner
578 % separation.
579 % They should also take regard of the shape's {\tt minimum} {\tt width}
580 % and {\tt minimum} {\tt height} keys if these are larger than the basic dimensions.
581 % Furthermore, they should compensate for the {\tt outer} {\tt xsep} and {\tt outer} {\tt ysep}
582 % keys as shown in figure~\ref{fig:anchorpath}.
583 %
584 % The corrected text box macros are decribed in \S\ref{sec:corrctdTextBox}.
585 % The minimum dimension keys are given by |\pgfshapeminwidth| and |\pgfshapeminheight|,
586 % and the outer separation keys are given by |\pgfshapeouterxsep| and
587 % |\pgfshapeouterysep|, as described in \S\ref{sec:keycommands}.
588 % The minimum dimension comparision and assignment is provided by |\mincorect| macro,
589 % which is discussed in \S\ref{sec:mincorrmacro}.
590 %
591 % \begin{figure}
592 % \begin{center}
593 % \input{msanchor.tmp}
594 % \end{center}
595 % \caption{The Anchor Path}\label{fig:anchorpath}
596 % \end{figure}
597 %
598 % \subsubsection{Saved Anchor Algorithm}
599 %
600 % A saved anchor must set the PGF registers |\pgf@x| and |\pgf@y|
601 % with the required coordinates.
602 % It has a structure similar to the anchor path.
603 %
604 % \begin{enumerate}
605 %
606 % \item Use |\ctbnex| and |\ctbnex|,
607 % which give the north east corner of the corrected text box,
608 % to calculate significant reference coordinates.
609 % (Normally similar to \S\ref{sec:anchorpathmacro} step \ref{item:apctb}).
610 %
611 % \item Use |\mincorrect| to modify the reference coordinates to
612 % take account of the shape's minimum dimension keys,
613 % which given by |\pgfshapeminwidth| and |\pgfshapeminheight|.
614 % (Normally the same as \S\ref{sec:anchorpathmacro} step \ref{item:apmindim}).
615 %
616 % \item Modify the reference coordinates to take account of outer separation,
617 % which is given by |\pgfshapeouterxsep| and |\pgfshapeouterxsep|.
618 % (Normally the same as \S\ref{sec:anchorpathmacro} step \ref{item:apouter}).
619 % \label{item:sanchosep}
620 %
621 % \item Use the reference coordinates from step \ref{item:sanchosep} to calculate the
622 % location of the anchor point, and assign values to the |\pgf@x| and |\pgf@y|
623 % registers.
624 %
625 % \end{enumerate}
626 %
627 % \section{Making a Shape}
628 %
629 % \subsection{Helper Macros}\label{sec:macros}
630 %
631 % The following macros are available for use in the anchor path,
632 % background path and saved anchors.
633 %
634 % \subsubsection{Corrected text box}\label{sec:corrctdTextBox}
635 %
636 % The \emph{corrected text box} is a bounding box for the
637 % shape's text that includes the shape's {\tt inner} {\tt xsep} and {\tt inner} {\tt ysep} keys.
638 % The box is symmetric about the origin.
639 % Its x and y coordinates are given by the following commands:
640 %
641 % \begin{description} [itemsep=-0.5ex, labelindent=-0.5em]
642 %
643 % \item[] |\ctbnex|:
644 % The x-coordinate of the north east corner of the shape's corrected text box.
645 %
646 % \item[] |\ctbney|:
647 % The y-coordinate of the north east corner of the shape's
648 % corrected text box.
649 %
650 % \end{description}
651 %
652 % \subsubsection{Correcting for minimum dimensions}\label{sec:mincorrmacro}
653 %
654 % A shape's size should be corrected for its
655 % {\tt minimum} {\tt width} and {\tt minimum} {\tt height} keys.
656 % The |\mincorrect| macro is provided to help with this.
657 %
658 % \begin{description} [itemsep=-0.5ex, labelindent=-0.5em]
659 %
660 % \item[] |\mincorrect{|{\it dimreg\/}|}{|{\it minkey\/}|}|:
661 % Correct an x or y outer bound dimension for {\tt minimum} {\tt width} or
662 % {\tt minimum} {\tt height} keys.
663 %
664 % \vspace{-1.5ex}
665 % \begin{description}
666 %
667 % \item[{\it dimreg} \rm --] A dimension register.
668 % On entry, it should hold the normal dimension of the shape.
669 % On exit, $dimreg$ is assigned the larger of its original value or $minkey/2$.
670 %
671 % \item[{\it minkey} \rm--] A minimum dimension key value.
672 % In practice, one of the minimum height or width commands given in
673 % \S\ref{sec:keycommands} below.
674 %
675 % \end{description}
676 %
677 % \end{description}
678 %
679 % \subsubsection{Getting key values}\label{sec:keycommands}
680 %
681 % The shape's key values can be accesses with the following commands:
682 %
683 % \begin{center}
684 % \begin{tabular}{ll}
685 % \hline
686 % key & command \bigstrut\\\hline
687 % {\tt minimum} {\tt width} & |\pgfshapeminwidth| \bigstrut[t]\\
688 % {\tt minimum} {\tt height} & |\pgfshapeminheight| \\
689 % {\tt outer} {\tt xsep} & |\pgfshapeouterxsep| \\
690 % {\tt outer} {\tt ysep} & |\pgfshapeouterysep| \bigstrut[b]\\\hline
691 % \end{tabular}
692 % \end{center}
693 %
694 % \noindent
695 % The outer separation keys are not relevant to the background path,
696 % but should be used by the anchor path and saved anchors.
697 %
698 % The shape's inner separation keys are automatically included in the \emph{corrected text box}
699 % coordinates |\ctbnex| and |\ctbney|.
700 %
701 % \subsubsection{Testing support}
702 %
703 % There are a couple of macros can be used in the background path to delineate a
704 % shape's text box during development:
705 %\begin{description}[nosep]
706 % \item[{\tt \textbackslash path@textbox}] draws a line around the the shape's text
707 % that is the uncorrected text box.
708 % \item[{\tt \textbackslash path@ctextbox}] shows the shape's corrected text box,
709 % which includes inner separation.
710 % \end{description}
711 % These macros should not be used in `production' shapes.
712 %
713 % \subsection{Procedure}
714 %
715 % The procedure in outline for making a new shape is as follows:
716 % \medskip
717 %
718 % \begin{enumerate}[nosep]
719 % \item Create the border path
720 % \item Create the anchor path
721 %\item Declare the shape
722 % \begin{enumerate}[nosep]
723 % \item Use |\setpaths| to employ the paths
724 % \item Create the anchors
725 % \end{enumerate}
726 % \end{enumerate}
727 % \medskip
728 %
729 % The sample shape given in \S\ref{sec:samplecode} can be used as a template to
730 % create a new shape.
731 % The code can be copied from there, or it can be acquired as the file |sampleshape.tex|,
732 % which is part of the package's distribution.
733 %
734 % The procedure for adapting the template code is as follows:
735 % \begin{enumerate}
736 %
737 % \item Change the name of the shape in the |\pgfdeclareshape| command
738 % from `{\tt sample}' to the name of the new shape.
739 %
740 % \item \label{item:steppaths} Write \emph{anchor path} and \emph{background path} macros.
741 %
742 % These and any sub macros are placed at the start of the file and replace
743 % the sample |\sampleanchor| and |\sampleborder| macros.
744 %
745 % As discussed in \S\ref{sec:backgroundpath} and \S\ref{sec:anchorpath},
746 % the background path should take account of the minimum dimension keys,
747 % and the anchor path should handle the minimum keys, and outer
748 % separation.
749 % The macros given in \S\ref{sec:macros} are provided to help with this,
750 % and the sample code gives an indication of how they can be used.
751 %
752 % \item Change the arguments of |\setpaths| in the template to the macros written
753 % in step \ref{item:steppaths}.
754 % The first is the anchor path and the second is the background path.
755 %
756 % \item \label{item:stepsavedanchors} Write the saved anchors that will needed by the anchors
757 % written in step~\ref{item:stepanchors}.
758 %
759 % Saved anchors, like the anchor path written in step \ref{item:steppaths},
760 % should correct for outer separation, and minimum dimensions
761 % using the macros in \S\ref{sec:macros}.
762 % They should set the |\pgf@x| and |\pgf@y| registers.
763 %
764 % \item \label{item:stepanchors}
765 % Write anchors that set |\pgf@x| and |\pgf@y| registers using
766 % the saved anchors from step \ref{item:stepsavedanchors}.
767 %
768 % \begin{enumerate}
769 %
770 % \item Write anchors for the cardinal and sub cardinal points:
771 %
772 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
773 % \anchor{north}{ ... }
774 % \anchor{north east}{ ... }
775 % \anchor{east}{ ... }
776 % \anchor{south east}{ ... }
777 % \anchor{south}{ ... }
778 % \anchor{south west}{ ... }
779 % \anchor{west}{ ... }
780 % \anchor{north west}{ ... }
781 % \end{VerbatimOut}
782 % \VerbatimInput{\jobname.tmp}
783 %
784 % \item Write any additional anchors that the shape needs.
785 %
786 % \end{enumerate}
787 %
788 % \end{enumerate}
789 %
790 % The PGF registers used throughout this method of declaring new shapes have the
791 % |@| character in their names.
792 % Unfortunately, this character has a special role in \LaTeX{}.
793 % So either the |\makeatletter| and |\makeatother| commands must be used as in
794 % |sampleshape.tex|, or the shape must be defined in a |sty| file.
795 %
796 % \section{Path and Anchor Examples}
797 %
798 % Here an example of an actual shape that is implemented using the {\sf makeshape} method:
799 %
800 % \bigskip
801 %
802 % \begin{tikzpicture}%[>=latex',font={\sf \small}]
803 % \node at (0,0) [draw, sample,
804 % minimum width=2cm,
805 % minimum height=1cm] {};
806 % \end{tikzpicture}
807 % \bigskip
808 %
809 % Its background path, anchor path, and anchor points use a common macro that gives
810 % the space between the outer and inner boundaries of the shape.
811 %
812 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
813 % \def\gap{4pt}
814 % \end{VerbatimOut}
815 % \VerbatimInput{\jobname.tmp}
816 %
817 % \subsection{Background Path}\label{sec:backgroundpathexmpl}
818 %
819 % In this example, the background path macro is called {\tt sampleshape}.
820 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
821 % \def\sampleshape{
822 % \end{VerbatimOut}
823 % \VerbatimInput[numbers=left]{\jobname.tmp}
824 % First we get the corrected text box coordinates,
825 % and add space for the shape using the |\gap| macro.
826 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
827 % \pgf@xa=\ctbnex
828 % \pgf@ya=\ctbney
829 % \advance\pgf@xa by \gap
830 % \advance\pgf@ya by \gap
831 % \end{VerbatimOut}
832 % \VerbatimInput[numbers=left, firstnumber=2]{\jobname.tmp}
833 % Then the standard correction for minimum size is applied using the |\mincorrect| macro.
834 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
835 % \mincorrect{\pgf@xa}{\pgfshapeminwidth}
836 % \mincorrect{\pgf@ya}{\pgfshapeminheight}
837 % \end{VerbatimOut}
838 % \VerbatimInput[numbers=left, firstnumber=6]{\jobname.tmp}
839 % Using these coordinates the outer boundary of the shape can be drawn
840 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
841 % \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
842 % \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
843 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
844 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
845 % \pgfpathclose
846 % \end{VerbatimOut}
847 % \VerbatimInput[numbers=left, firstnumber=8]{\jobname.tmp}
848 % Finally, the reference coordinates are moved to the inner boundary and the shape is completed
849 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
850 % \advance\pgf@xa by -\gap
851 % \advance\pgf@ya by -\gap
852 % \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
853 % \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
854 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
855 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
856 % \pgfpathclose
857 % }
858 % \end{VerbatimOut}
859 % \VerbatimInput[numbers=left, firstnumber=13]{\jobname.tmp}
860 %
861 % \subsection{Anchor Path}\label{sec:anchorpathexmpl}
862 %
863 % The shape's anchor path macro called {\tt sampleanchor},
864 % and is similar to the path macro in \S\ref{sec:backgroundpathexmpl},
865 % but it also handles outer separation.
866 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
867 % \def\sampleanchor{
868 % \end{VerbatimOut}
869 % \VerbatimInput[numbers=left]{\jobname.tmp}
870 % First we get the corrected text box coordinates, and add space for the shape using
871 % the |\gap| macro.
872 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
873 % \pgf@xa=\ctbnex
874 % \pgf@ya=\ctbney
875 % \advance\pgf@xa by \gap
876 % \advance\pgf@ya by \gap
877 % \end{VerbatimOut}
878 % \VerbatimInput[numbers=left, firstnumber=2]{\jobname.tmp}
879 % Then corrections for minimum size and outer separation are applied:
880 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
881 % \mincorrect{\pgf@xa}{\pgfshapeminwidth}
882 % \advance\pgf@xa\pgfshapeouterxsep
883 % \mincorrect{\pgf@ya}{\pgfshapeminheight}
884 % \advance\pgf@ya\pgfshapeouterysep
885 % \end{VerbatimOut}
886 % \VerbatimInput[numbers=left, firstnumber=6]{\jobname.tmp}
887 % Using these coordinates the anchor boundary path is finally drawn
888 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
889 % \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
890 % \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
891 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
892 % \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
893 % \pgfpathclose
894 % }
895 % \end{VerbatimOut}
896 % \VerbatimInput[numbers=left, firstnumber=10]{\jobname.tmp}
897 %
898 % \subsection{Shape Declaration and Anchor Points}
899 %
900 % The {\tt sample} shape declaration is started with
901 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
902 % \pgfdeclareshape{sample}{
903 % \end{VerbatimOut}
904 % \VerbatimInput[numbers=left]{\jobname.tmp}
905 % Then the shape and anchor paths, which were defined in \S\ref{sec:backgroundpathexmpl}
906 % and \S\ref{sec:anchorpathexmpl}, are employed with
907 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
908 % \setpaths{\sampleanchor}{\sampleshape}
909 % \end{VerbatimOut}
910 % \VerbatimInput[numbers=left, firstnumber=2]{\jobname.tmp}
911 %
912 % \subsubsection{Anchors}
913 %
914 % Next in the shape's declaration are its saved anchors.
915 % In this case, we establish the north east anchor location with code that is equivalent
916 % to the first part of the anchor path macro (\S\ref{sec:anchorpathexmpl}).
917 % Note how the anchor point's coordinate is returned in |\pgf@x| and |\pgf@y|.
918 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
919 % \savedanchor{\northeast}{
920 % \pgf@x = \ctbnex
921 % \pgf@y = \ctbney
922 % \advance\pgf@xa by \gap
923 % \advance\pgf@ya by \gap
924 % \mincorrect{\pgf@x}{\pgfshapeminwidth}
925 % \mincorrect{\pgf@y}{\pgfshapeminheight}
926 % \advance\pgf@x\pgfshapeouterxsep
927 % \advance\pgf@y\pgfshapeouterysep
928 % }
929 % \end{VerbatimOut}
930 % \VerbatimInput[numbers=left, firstnumber=3]{\jobname.tmp}
931 %
932 % \noindent
933 % The saved anchor is then used to construct the shape's anchors,
934 % and the declaration is ended as follows:
935 %
936 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
937 % \anchor{north}{\northeast \pgf@x=0pt}
938 % \anchor{north east}{\northeast}
939 % \anchor{east}{\northeast \pgf@y=0pt}
940 % \anchor{south east}{\northeast \pgf@y=-\pgf@y}
941 % \anchor{south}{\northeast \pgf@x=0pt \pgf@y=-\pgf@y}
942 % \anchor{south west}{\northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
943 % \anchor{west}{\northeast \pgf@x=-\pgf@x \pgf@y=0pt}
944 % \anchor{north west}{\northeast \pgf@x=-\pgf@x}
945 % }
946 % \end{VerbatimOut}
947 % \VerbatimInput[numbers=left, firstnumber=13]{\jobname.tmp}
948 %
949 %
950 % \subsection{Sample Shape Code}\label{sec:samplecode}
951 %
952 % The following is a full listing of the code needed to make the sample shape
953 % described above.
954 % It can be used as a templete for new shapes.
955 % A copy of this code can be found in the the file {\tt sampleshape.tex},
956 % which is included in the package's distribution.
957 % Note the use of the |\makeatletter| and |\makeatother| commands, which are required
958 % because the sample shape is in a |tex| file.
959 %
960 %^^A - Code must be < 67 characters to fit on page at 10pt ...
961 % \VerbatimInput[ ^^A numbers=left,
962 % firstline=40, lastline=127]{sampleshape}
963 %
964 %
965 %^^A===========================================================================
966 %^^A References
967 %^^A===========================================================================
968 %
969 %^^A - Used in \StopEventually ...
970 %
971 % \def\printBib{
972 % \begin{thebibliography}{9}
973 % \raggedright
974 %
975 % \bibitem{pgfMan}
976 % Till Tantau,
977 % \emph{The TikZ and PGF Packages, Manual for version 2.10},
978 % 2010.
979 % Available as
980 % \href{http://mirrors.ctan.org/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf}
981 % {\tt pgfmanual.pdf}
982 % from the \href{http://ctan.org}{Comprehensive TeX Archive Network}.
983 %
984 %^^A in pgfMan \emph{Constructing Paths}, section 71, pp 579-589.
985 %^^A in pgfMan \emph{Declaring New Shapes}, section 75.5, pp 625-631.
986 %
987 % \end{thebibliography}
988 % }
989 %
990 %
991 %^^A===========================================================================
992 %^^A Start code implementation
993 %^^A===========================================================================
994 %
995 % \StopEventually{ \printBib }
996 %^^A \StopEventually{ \printBib \PrintChanges }
997 %^^A -> Run pdfLaTeX makeshape.dtx
998 %^^A makeindex -s gglo.ist -o makeshape.gls makeshape.glo
999 %^^A pdfLaTeX makeshape.dtx
1000 %
1001 % \section{Implementation}
1002 %
1003 % \subsection{Text Box Calculations}\label{sec:textboxcalc}
1004 %
1005 % The shape's text is at its centre for shape's made with this package.
1006 % The text box position is defined by the shape's |text| anchor, which must give the coordinate
1007 % of the west end of the text's base line.
1008 % PGF provides three useful dimensions:
1009 %
1010 % \smallskip
1011 % \begin{tabular}{lll}
1012 % |\wd\pgfnodeparttextbox| & width & $wd$\\
1013 % |\ht\pgfnodeparttextbox| & height & $ht$\\
1014 % |\dp\pgfnodeparttextbox| & depth & $dp$\\
1015 % \end{tabular}
1016 %
1017 % \smallskip\noindent
1018 % These are related as follows:
1019 % \medskip
1020 %
1021 %^^A----------------------------------
1022 %^^A- Text box diagram - start
1023 %^^A----------------------------------
1024 % \begin{tikzpicture}[>=latex',font={\sf \small}]
1025 %
1026 % \def\tbht{30pt} ^^A - text box height
1027 % \def\tbdp{15pt} ^^A - text box depth
1028 % \def\tbwd{150pt} ^^A - text box width
1029 %
1030 % \def\blwx{-\tbwd/2} ^^A - baseline west x
1031 % \def\blwy{-\tbht/2+\tbdp/2} ^^A - baseline west y
1032 %
1033 % \def\tbnex{\tbwd/2} ^^A - text box north east x
1034 % \def\tbney{\tbht/2+\tbdp/2} ^^A - text box north east y
1035 %
1036 % \node (textbox) at (0,0) [draw, rectangle, fill=white,
1037 % minimum width=\tbwd,
1038 % minimum height=\tbht+\tbdp,
1039 % ] {};
1040 % \draw [] (\blwx,\blwy) -- ++(\tbwd,0);
1041 %
1042 % \node (textanchor) [coordinate] at (\blwx,\blwy){};
1043 %
1044 % \node at (textanchor) [draw, circle] (blinewest) {};
1045 %
1046 %^^A - Labels
1047 % \node (blinelable) at (3.5cm,\blwy) [inner sep = 0] {baseline};
1048 % \node (textanchlabel) at (\blwx+28pt,\blwy+8pt) [inner sep = 0] {text anchor};
1049 %
1050 %^^A - Dimensions
1051 % \node (hta) [coordinate, left=15pt of textbox.south west] {};
1052 % \node (htc) [coordinate, left=15pt of textbox.north west] {};
1053 % \node (htb) [coordinate, left=15pt of textanchor] {};
1054 % \draw [|<->|] (hta) -- (htb) node [midway,left] {depth};
1055 % \draw [<->|] (htb) -- (htc) node [midway,left] {height};
1056 % \node (wda) [coordinate, above=10pt of textbox.north west] {};
1057 % \node (wdb) [coordinate, above=10pt of textbox.north east] {};
1058 % \draw [|<->|] (wda) -- (wdb) node [midway,above] {width};
1059 %
1060 %^^A - xy axis
1061 % \def\xaxisdim{0.5cm}
1062 % \def\yaxisdim{0.5cm}
1063 % \draw [dotted] (0,0) -- ++(\xaxisdim,0); ^^A - origin
1064 % \draw [dotted] (0,0) -- ++(-\xaxisdim,0); ^^A - origin
1065 % \draw [dotted] (0,0) -- ++(0,\yaxisdim); ^^A - origin
1066 % \draw [dotted] (0,0) -- ++(0,-\yaxisdim); ^^A - origin
1067 %
1068 % \end{tikzpicture}
1069 %^^A----------------------------------
1070 %^^A- Text box diagram - end
1071 %^^A----------------------------------
1072 %\medskip
1073 %
1074 % For this box to be centred on the origin, we need to calculate suitable coordinates for
1075 % the |text| anchor.
1076 % So, if the box's south west corner is at $(x_{sw},y_{sw})$ and the box is centred, then
1077 % $x_{sw} = -wd/2$ and $y_{sw}=-(ht+dp)/2$.
1078 % If the |text| anchor is at $(x_{text},y_{text})$, then
1079 % \vspace{-2ex}
1080 %\begin{eqnarray}
1081 % x_{text} & = & x_{sw} = -\frac{wd}{2}\label{eqn:xtext}\\
1082 % y_{text} & = & y_{sw} + dp = -\frac{ht}{2} - \frac{dp}{2} + dp
1083 % = \frac{dp}{2} - \frac{ht}{2} \label{eqn:ytext}
1084 %\end{eqnarray}
1085 %
1086 % Furthermore, the shape's north east corner $(x_{ne},y_{ne})$ is at
1087 %\begin{eqnarray}
1088 % x_{ne} & = & \frac{wd}{2} \label{eqn:xne}\\[1ex]
1089 % y_{ne} & = & \frac{ht+dp}{2} \label{eqn:yne}
1090 %\end{eqnarray}
1091 %
1092 %\iffalse
1093 %<*package>
1094 %\fi
1095 %
1096 %\subsection{Symetric bounding box}\label{sec:symbbox}
1097 %
1098 % We require a rectangle that contains the anchor path, and has its centre at the origin.
1099 % Such a rectangle, defined by the coordinate of its north east corner, is needed
1100 % in the anchor border algorithm described in \S\ref{sec:anchoralgorithm}.
1101 %
1102 % \vspace{2ex}
1103 %
1104 %^^A----------------------------------
1105 %^^A- Bounding box diagram - start
1106 %^^A----------------------------------
1107 % \begin{tikzpicture}[>=latex',font={\sf \small}]
1108 %
1109 % \def\bbnex{60pt} ^^A - box ne x
1110 % \def\bbney{30pt} ^^A - box ne y
1111 %
1112 % \node (boundingbox) at (0,0) [draw, rectangle, dashed,
1113 % minimum width=2*\bbnex,
1114 % minimum height=2*\bbney,
1115 % ] {};
1116 %
1117 % \node at (\bbnex,\bbney) [draw, circle] (boxne) {};
1118 %
1119 % \def\nx{0pt} \def\ny{20pt}
1120 % \def\ex{30pt} \def\ey{-10pt}
1121 % \def\sx{-20pt} \def\sy{-\bbney}
1122 % \def\wx{-\bbnex} \def\wy{10pt}
1123 %
1124 %^^A - Anchor path
1125 % \draw [] (\nx,\ny) -- (\ex,\ey);
1126 % \draw [] (\ex,\ey) -- (\sx,\sy);
1127 % \draw [] (\sx,\sy) -- (\wx,\wy);
1128 % \draw [] (\wx,\wy) -- (\nx,\ny);
1129 %
1130 %^^A - mins and maxs with labels
1131 % \draw [dotted] (\nx,\ny) -- (\bbnex+10pt,\ny);
1132 % \draw [dotted] (\bbnex,\sy) -- (\bbnex+10pt,\sy);
1133 % \draw [dotted] (\ex,\ey) -- (\ex,-\bbney-10pt);
1134 % \draw [dotted] (\wx,-\bbney) -- (\wx,-\bbney-10pt);
1135 % \node (maxy) at (\bbnex+24pt,\ny) [inner sep = 0] {$y_{max}$};
1136 % \node (miny) at (\bbnex+24pt,\sy) [inner sep = 0] {$y_{min}$};
1137 % \node (maxx) at (\wx,-\bbney-16pt) [inner sep = 0] {$x_{min}$};
1138 % \node (maxx) at (\ex,-\bbney-16pt) [inner sep = 0] {$x_{max}$};%
1139 %
1140 %^^A - Labels
1141 % \node (path) at (\wx-40pt,\wy-32pt) [inner sep = 0] {anchor path};
1142 % \draw [->] (path.east) -- (-40pt,-10pt);
1143 % \node (box) at (\wx-40pt,\wy+13pt) [inner sep = 0] {bounding box};
1144 % \draw [->] (box.east) -- (\wx,23pt);
1145 % \node (bbne) at (\bbnex+25pt,\bbney+10pt) [inner sep = 0] {$(x_{ne},y_{ne})$};
1146 %
1147 %^^A - xy axis
1148 % \def\xaxisdim{0.2cm}
1149 % \def\yaxisdim{0.2cm}
1150 % \draw [] (0,0) -- ++(\xaxisdim,0); ^^A - origin
1151 % \draw [] (0,0) -- ++(-\xaxisdim,0); ^^A - origin
1152 % \draw [] (0,0) -- ++(0,\yaxisdim); ^^A - origin
1153 % \draw [] (0,0) -- ++(0,-\yaxisdim); ^^A - origin
1154 %
1155 % \end{tikzpicture}
1156 %^^A----------------------------------
1157 %^^A- Bounding box diagram - end
1158 %^^A----------------------------------
1159 %
1160 % \medskip
1161 % The \emph{symmetric bounding box} is defined by the coordinate of its north east corner:
1162 % \vspace{-3ex}
1163 % \begin{eqnarray}
1164 % x_{ne} &=& \max{(\vert x_{min} \vert \, ,\vert x_{max} \vert )} \label{eqn:bbx}\\
1165 % y_{ne} &=& \max{(\vert y_{min} \vert \, ,\vert y_{max} \vert )} \label{eqn:bby}
1166 % \end{eqnarray}
1167 %
1168 % \subsection{The Anchor Border Algorithm}\label{sec:anchoralgorithm}
1169 %
1170 % A shape's |\anchorborder| command must calculate the intersection of a line drawn
1171 % between the origin and a target point, and the shape's border.
1172 % The aim here is to do this calculation using an \emph{anchor path} that describes
1173 % the shapes outer border.
1174 %
1175 % The |\pgfintersectionofpaths| command can be used to do this, but it will only work
1176 % for points that are outside the anchor path.
1177 % The solution is to \emph{externalise the point} using the |\pgfpointborderrectangle| command.
1178 %
1179 % \bigskip
1180 %^^A------------------------------------------------
1181 %^^A- Anchor border point algorithm diagram - start
1182 %^^A------------------------------------------------
1183 % \begin{tikzpicture}[>=latex',font={\sf \small}]
1184 %
1185 %^^A - xy axis
1186 % \def\xaxisdim{0.2cm}
1187 % \def\yaxisdim{0.2cm}
1188 % \draw [] (0,0) -- ++(-\xaxisdim,0); ^^A - origin
1189 % \draw [] (0,0) -- ++(0,\yaxisdim); ^^A - origin
1190 % \draw [] (0,0) -- ++(0,-\yaxisdim); ^^A - origin
1191 % \filldraw[white] (0,0) circle (2pt);
1192 %
1193 %^^A - Bounding box
1194 % \def\bbnex{60pt} ^^A - box ne x
1195 % \def\bbney{30pt} ^^A - box ne y
1196 %
1197 % \node (boundingbox) at (0,0) [draw, rectangle, dashed,
1198 % minimum width=2*\bbnex,
1199 % minimum height=2*\bbney,
1200 % ] {};
1201 %
1202 % \draw ((\bbnex,\bbney) circle (2pt);
1203 %
1204 %^^A - Anchor path
1205 % \def\nx{30pt} \def\ny{20pt}
1206 % \def\ex{50pt} \def\ey{-20pt}
1207 % \def\sx{-20pt} \def\sy{-\bbney}
1208 % \def\wx{-\bbnex} \def\wy{10pt}
1209 %
1210 % \def\apath{
1211 % \pgfpathmoveto{\pgfpoint{\nx}{\ny}}
1212 % \pgfpathlineto{\pgfpoint{\ex}{\ey}}
1213 % \pgfpathlineto{\pgfpoint{\sx}{\sy}}
1214 % \pgfpathlineto{\pgfpoint{\wx}{\wy}}
1215 % \pgfpathclose }
1216 %
1217 %^^A - Draw the anchor path
1218 % \apath
1219 % \pgfusepath{stroke}
1220 %
1221 %^^A - Target point and vectors
1222 % \def\tx{20pt}
1223 % \def\ty{5pt}
1224 % \def\endx{3.5*\tx}
1225 % \def\endy{3.5*\ty}
1226 %
1227 % \draw [] (0,0) -- (\tx,\ty);
1228 % \draw [dotted] (\tx,\ty) -- (\endx,\endy);
1229 % \filldraw (\tx,\ty) circle (2pt);
1230 %
1231 %^^A - Intersection with bounding box
1232 % \pgfpathcircle{\pgfpointborderrectangle{\pgfpoint{\tx}{\ty}}
1233 % {\pgfpoint{\bbnex}{\bbney}}}{2pt}
1234 % \pgfusepath{stroke}
1235 %
1236 %^^A - intersection with anchor path
1237 % \pgfintersectionofpaths{\apath}
1238 % { \pgfpathmoveto{\pgfpoint{0}{0}}
1239 % \pgfpathlineto{\pgfpoint{\endx}{\endy}} }
1240 % \pgfpathcircle{\pgfpointintersectionsolution{1}}{2pt}
1241 % \pgfusepath{stroke}
1242 %
1243 %^^A - Labels
1244 % \node (path) at (\wx-40pt,\wy-32pt) [inner sep = 0] {anchor path};
1245 % \draw [->] (path.east) -- (-40pt,-10pt);
1246 % \node (box) at (\wx-40pt,\wy+13pt) [inner sep = 0] {bounding box};
1247 % \draw [->] (box.east) -- (\wx,23pt);
1248 % \node (p1) at (\tx+5pt,\ty-8pt) [inner sep = 0] {p1};
1249 % \node (p2) at (\bbnex+10pt,\bbney+5pt) [inner sep = 0] {p2};
1250 % \node (p3) at (\bbnex+10pt,8pt) [inner sep = 0] {p3};
1251 % \node (p4) at (40pt,18pt) [inner sep = 0] {p4};
1252 %
1253 %^^A - point key
1254 %^^A \def\pkeyx{90pt}
1255 %^^A \def\pkeyy{10pt}
1256 %^^A \def\pkeystep{-10pt}
1257 %^^A \node (key1) at (\pkeyx,\pkeyy) [right, inner sep = 0] {p1 = target point};
1258 %^^A \node (key2) at (\pkeyx,\pkeyy+\pkeystep) [right, inner sep = 0] {p2 = bounding box corner};
1259 %^^A \node (key3) at (\pkeyx,\pkeyy+2*\pkeystep) [right, inner sep = 0]
1260 %^^A {p3 = bounding box intersection};
1261 %^^A \node (key4) at (\pkeyx,\pkeyy+3*\pkeystep) [right, inner sep = 0]
1262 %^^A {p4 = anchor path intersection};
1263 %
1264 % \end{tikzpicture}
1265 %^^A------------------------------------------------
1266 %^^A- Anchor border point algorithm diagram - end
1267 %^^A------------------------------------------------
1268 %
1269 %\bigskip
1270 %
1271 %\begin{description}
1272 %
1273 % \item[Step 1 - Externalise the target point]
1274 %
1275 % The vector to the target point {\sf p1} is extended to the bounding box to find
1276 % the intersection {\sf p3}.
1277 % The bounding box is by definition outside the anchor path.
1278 % Thus point {\sf p3} must also be outside the anchor path.
1279 %
1280 % To achieve this, the |\pgfpointborderrectangle| command is applied to the target point {\sf p1}
1281 % and the centred rectangle defined by {\sf p2}, which is the symmetric bounding box defined
1282 % in \S\ref{sec:symbbox}.
1283 %
1284 % \item[Step 2 - Find the border intersection]
1285 %
1286 % The line from the origin to the point {\sf p3} passes through {\sf p1},
1287 % and its intersection with the anchor path is the required point {\sf p4}.
1288 %
1289 % The intersection is found with the |\pgfintersectionofpaths| command,
1290 % which takes the anchor path and the path of the line from the origin to {\sf p3} as input.
1291 % Since {\sf p3} is always outside the anchor path, such an intersection will always be found.
1292 %
1293 % \end{description}
1294 %
1295 % \subsection{Declare Shape Commands}
1296 %
1297 % \begin{macro}{\setpaths}
1298 % The |\setpaths| macro is used in |\pgfdeclareshape| definitions to specify the shape's paths.
1299 % It has two parameters:
1300 % \begin{description}[nosep]
1301 % \item[\tt ~\#1] is a macro defining the anchor path.
1302 % \item[\tt ~\#2] is a macro defining the background path.
1303 % \end{description}
1304 %
1305 % \begin{macrocode}
1306 \def\setpaths#1#2{
1307 % \end{macrocode}
1308 %
1309 % \noindent
1310 % It defines saved macros for use in the shape's path macros and saved anchors.
1311 % There are also macros defined that are only used within the packages other macros.
1312 %
1313 % \subsubsection{Corrected text box saved macros}
1314 %
1315 % These two saved macros give the x and y coordinates of the corrected text box's north east corner.
1316 % They are invoked by users of the package to define a shape's path macros.
1317 %
1318 % \begin{macro}{\ctbnex}
1319 % The |\ctbnex| saved macro gives the x-coordinate,
1320 % which is calculated as described by equation \ref{eqn:xne} in \S\ref{sec:textboxcalc}.
1321 % \begin{macrocode}
1322 \savedmacro\ctbnex{
1323 \pgf@x=.5\wd\pgfnodeparttextbox
1324 \pgfmathsetlength\pgf@xa{\pgfshapeinnerxsep}
1325 \advance\pgf@x\pgf@xa
1326 \edef\temp@x{\the\pgf@x}
1327 \let\ctbnex\temp@x
1328 }
1329 % \end{macrocode}
1330 % \end{macro}
1331 %
1332 % \begin{macro}{\ctbney}
1333 % The y-coordinate is given by the |\ctbney| saved macro,
1334 % which implements equation \ref{eqn:yne} in \S\ref{sec:textboxcalc}.
1335 % \begin{macrocode}
1336 \savedmacro\ctbney{
1337 \pgf@y=.5\ht\pgfnodeparttextbox
1338 \advance\[email protected]\dp\pgfnodeparttextbox
1339 \pgfmathsetlength\pgf@ya{\pgfshapeinnerysep}
1340 \advance\pgf@y\pgf@ya
1341 \edef\temp@y{\the\pgf@y}
1342 \let\ctbney\temp@y
1343 }
1344 % \end{macrocode}
1345 % \end{macro}
1346 %
1347 % \subsubsection{Key value saved macros}
1348 %
1349 % These saved macros give the values of significant shape keys.
1350 % They have the same names as the standard PGF macros,
1351 % and allow the user's anchor and background path macros to use the standard names.
1352 %
1353 % \begin{macro}{\pgfshapeouterxsep}
1354 % The value of the x outer separation key is given by |\pgfshapeouterxsep|.
1355 % \begin{macrocode}
1356 \savedmacro\pgfshapeouterxsep{
1357 \pgfkeysgetvalue{/pgf/outer xsep}{\temp@sep}
1358 \let\pgfshapeouterxsep\temp@sep
1359 }
1360 % \end{macrocode}
1361 % \end{macro}
1362 %
1363 % \begin{macro}{\pgfshapeouterysep}
1364 % The value of the y outer separation key is given by |\pgfshapeouterysep|.
1365 % \begin{macrocode}
1366 \savedmacro\pgfshapeouterysep{
1367 \pgfkeysgetvalue{/pgf/outer ysep}{\temp@sep}
1368 \let\pgfshapeouterysep\temp@sep
1369 }
1370 % \end{macrocode}
1371 % \end{macro}
1372 %
1373 % \begin{macro}{\pgfshapeminwidth}
1374 % The value of the minimum width key is given by |\pgfshapeminwidth|.
1375 % \begin{macrocode}
1376 \savedmacro{\pgfshapeminwidth}{
1377 \pgfkeysgetvalue{/pgf/minimum width}{\temp@wd}
1378 \let\pgfshapeminwidth\temp@wd
1379 }
1380 % \end{macrocode}
1381 % \end{macro}
1382 %
1383 % \begin{macro}{\pgfshapeminheight}
1384 % The value of the minimum height key is given by |\pgfshapeminheight|.
1385 % \begin{macrocode}
1386 \savedmacro{\pgfshapeminheight}{
1387 \pgfkeysgetvalue{/pgf/minimum height}{\temp@ht}
1388 \let\pgfshapeminheight\temp@ht
1389 }
1390 % \end{macrocode}
1391 % \end{macro}
1392 %
1393 % \subsubsection{Saved anchors}\label{sec:savedanchors}
1394 %
1395 % The saved anchors are used to implement the anchors provided by the package,
1396 % but can be used by the user to define custom anchors if required.
1397 % They are required to return the coordinates of a point in |\pgf@x| and |\pgf@y|.
1398 %
1399 % \begin{macro}{\centre}
1400 % The |\centre| saved anchor is used to implement the package |center| anchor.
1401 % The |\pgfpointorigin| command sets |\pgf@x| and |\pgf@y|.
1402 % \begin{macrocode}
1403 \savedanchor{\centre}{
1404 \pgfpointorigin
1405 }
1406 % \end{macrocode}
1407 % \end{macro}
1408 %
1409 % \begin{macro}{\text}
1410 % The |\text| saved anchor is used to implement the package |text| anchor.
1411 % It gives the coordinate of the west end of the text base line.
1412 % The calculation it uses is explained in \S\ref{sec:textboxcalc}.
1413 % Equation \ref{eqn:xtext} gives the x-coordinate
1414 % and equation \ref{eqn:ytext} gives the y-coordinate.
1415 % \begin{macrocode}
1416 \savedanchor{\text}{
1417 \pgf@y=-0.5\ht\pgfnodeparttextbox
1418 \advance\pgf@y by 0.5\dp\pgfnodeparttextbox
1419 \pgf@x=-0.5\wd\pgfnodeparttextbox
1420 }
1421 % \end{macrocode}
1422 % \end{macro}
1423 %
1424 % \begin{macro}{\boundbox@ne}
1425 % The |\boundbox@ne| saved anchor gives the north east corner of the
1426 % anchor path's symmetric bounding rectangle (see \S\ref{sec:symbbox}).
1427 % \begin{macrocode}
1428 \savedanchor{\boundbox@ne}{
1429 % \end{macrocode}
1430 %
1431 % First clear any existing path, and then execute the anchor path macro given as
1432 % the first parameter of |\setpaths|.
1433 % \begin{macrocode}
1434 \pgfusepath{}
1435 #1
1436 % \end{macrocode}
1437 % Store the path's minimum and maximum coordinates, and then discard the path.
1438 % \begin{macrocode}
1439 \pgf@xb=\pgf@pathmaxx
1440 \pgf@yb=\pgf@pathmaxy
1441 \pgf@xc=\pgf@pathminx
1442 \pgf@yc=\pgf@pathminy
1443 \pgfusepath{}
1444 % \end{macrocode}
1445 %
1446 % The north east corner x-coordinate of the symmetric bounding box is calculated using
1447 % equation \ref{eqn:bbx} from \S\ref{sec:symbbox}.
1448 %
1449 % \begin{macrocode}
1450 \ifdim\pgf@xb<0pt \pgf@xb=-\pgf@xb \fi
1451 \ifdim\pgf@xc<0pt \pgf@xc=-\pgf@xc \fi
1452 \ifdim\pgf@xb<\pgf@xc
1453 \pgf@x=\pgf@xc
1454 \else
1455 \pgf@x=\pgf@xb
1456 \fi
1457 % \end{macrocode}
1458 % The y-coordinate is calculated with equation \ref{eqn:bby}:
1459 % \begin{macrocode}
1460 \ifdim\pgf@yb<0pt \pgf@yb=-\pgf@yb \fi
1461 \ifdim\pgf@yc<0pt \pgf@yc=-\pgf@yc \fi
1462 \ifdim\pgf@yb<\pgf@yc
1463 \pgf@y=\pgf@yc
1464 \else
1465 \pgf@y=\pgf@yb
1466 \fi
1467 }
1468 % \end{macrocode}
1469 % \end{macro}
1470 %
1471 % \subsubsection{Anchors}
1472 %
1473 % \begin{macro}{center}
1474 % \begin{macro}{text}
1475 % PGF shapes require |center| and |text| anchors.
1476 % They are implemented by the saved anchors |\center| and |\text| (see \ref{sec:savedanchors}),
1477 % and in effect centre the shape's text on the origin.
1478 % \begin{macrocode}
1479 \anchor{center}{\centre}
1480 \anchor{text}{\text}
1481 % \end{macrocode}
1482 % \end{macro}
1483 % \end{macro}
1484 %
1485 % \begin{macro}{\anchorborder}
1486 % The |\anchorborder| anchor is critically responsible for calculating points on
1487 % the shape's boundary
1488 % Its algoritm is explained in \S\ref{sec:anchoralgorithm}.
1489 % \begin{macrocode}
1490 \anchorborder{
1491 % \end{macrocode}
1492 % On entry, the coordinates of the target point are supplied in |\pgf@x| and |\pgf@y|,
1493 % and these are immediately saved:
1494 % \begin{macrocode}
1495 \edef\targpointx{\the\pgf@x}
1496 \edef\targpointy{\the\pgf@y}
1497 % \end{macrocode}
1498 %
1499 % A couple of settings are needed to support shapes that are not centred on the origin:
1500 % \begin{macrocode}
1501 \pgf@relevantforpicturesizefalse
1502 \pgftransformreset
1503 % \end{macrocode}
1504 % The first suppresses updating of the picture bounding box and ensures correct positioning
1505 % of the shape.
1506 % The second stops coordinate transformations being applied,
1507 % which is needed for the correct behaviour of points relying on the |\anchorborder| command.
1508 %
1509 % Start the computation by finding the north east corner of the anchor path's bounding box:
1510 % \begin{macrocode}
1511 \boundbox@ne
1512 \pgf@xa=\pgf@x
1513 \pgf@ya=\pgf@y
1514 % \end{macrocode}
1515 % Perform step 1 of the algorithm described in \S\ref{sec:anchoralgorithm} to externalise
1516 % the target to a point on the bounding box:
1517 % \begin{macrocode}
1518 \pgfpointborderrectangle{\pgfpoint{\targpointx}{\targpointy}}
1519 {\pgfpoint{\pgf@xa}{\pgf@ya}}
1520 \edef\corrx{\the\pgf@x}
1521 \edef\corry{\the\pgf@y}
1522 % \end{macrocode}
1523 % Next, use this externalised point to find the required boundary point with step 2 of
1524 % the algorithm.
1525 % The anchor path is |#1|, which is the first argument |setpaths|.
1526 % \begin{macrocode}
1527 \pgfintersectionofpaths {
1528 #1
1529 }{
1530 \pgfpathmoveto{\pgfpoint{0}{0}}
1531 \pgfpathlineto{\pgfpoint{\corrx}{\corry}}
1532 }
1533 % \end{macrocode}
1534 % Finally, the command |\pgfpointintersectionsolution| puts the point's coordinates in
1535 % |\pgf@x| and |\pgf@y|.
1536 % \begin{macrocode}
1537 \pgfpointintersectionsolution{1}
1538 }
1539 % \end{macrocode}
1540 % \end{macro}
1541 %
1542 % \subsubsection{Background path}
1543 %
1544 % \begin{macro}{\backgroundpath}
1545 % The shape is actually drawn by |\backgroundpath|, which executes the second argument of
1546 % |\setpaths|, which is the shape's background path.
1547 % \begin{macrocode}
1548 \backgroundpath{
1549 #2
1550 }
1551 % \end{macrocode}
1552 % \end{macro}
1553 % Finally, |setpaths| is completed.
1554 % \begin{macrocode}
1555 }
1556 % \end{macrocode}
1557 % \end{macro}
1558 %
1559 % \subsection{Utility macros}
1560 %
1561 % \subsubsection{Dimension correction}
1562 %
1563 % \begin{macro}{\mincorrect}
1564 % The |\mincorrect| macro finds the larger of two dimensions.
1565 % It is applied to shape coordinates and keys.
1566 % It uses a working dimension register, and has two parameters
1567 % \begin{macrocode}
1568 \newdimen\crct@dim
1569 \def\mincorrect#1#2{
1570 % \end{macrocode}
1571 % The parameters have the following roles:
1572 % \begin{description}[nosep]
1573 % \item[\tt ~\#1] A register holding the normal outer bound dimension of the shape,
1574 % and then the largest value, in a PGF register such as |\pgf@xa|.
1575 % \item[\tt ~\#2] A key value, normally one of |\pgfshapeminwidth| or |\pgfshapeminheight|.
1576 % \end{description}
1577 % The |\crct@dim| register is used to calculate half of |#2|:
1578 % \begin{macrocode}
1579 \pgfmathsetlength\crct@dim{#2}
1580 \pgfmathsetlength\crct@dim{0.5\crct@dim}
1581 % \end{macrocode}
1582 %
1583 % Then if |#1| is larger than |\crct@dim|, |#1| is assigned this value
1584 % otherwise |#1| remains unchanged.
1585 % \begin{macrocode}
1586 \ifdim#1<\crct@dim
1587 #1=\crct@dim
1588 \fi
1589 }
1590 % \end{macrocode}
1591 % \end{macro}
1592 %
1593 % \subsubsection{Macros for testing}
1594 %
1595 % There are a couple of macros can be used to delineate a shape's text box during development.
1596 % They should not be used in `production' shapes.
1597 %
1598 % \begin{macro}{\path@textbox}
1599 % The |\path@textbox| macro draws a line around the the shape's text that is the
1600 % uncorrected text box.
1601 % \begin{macrocode}
1602 \def\path@textbox{
1603 \pgf@xa=.5\wd\pgfnodeparttextbox
1604 \pgf@ya=.5\ht\pgfnodeparttextbox
1605 \advance\[email protected]\dp\pgfnodeparttextbox
1606 \typeout{**** TEST text box (x,y) = (\the\pgf@xa,\the\pgf@ya) }
1607 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1608 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
1609 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
1610 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
1611 \pgfpathclose
1612 }
1613 % \end{macrocode}
1614 % \end{macro}
1615 %
1616 % \begin{macro}{\path@ctextbox}
1617 % The |\path@ctextbox| macro shows the shape's corrected text box,
1618 % which includes inner separation.
1619 % \begin{macrocode}
1620 \def\path@ctextbox{
1621 \pgf@xa=.5\wd\pgfnodeparttextbox
1622 \pgfmathsetlength\pgf@xc{\pgfshapeinnerxsep}
1623 \advance\pgf@xa\pgf@xc
1624 \pgf@ya=.5\ht\pgfnodeparttextbox
1625 \advance\[email protected]\dp\pgfnodeparttextbox
1626 \pgfmathsetlength\pgf@yc{\pgfshapeinnerysep}
1627 \advance\pgf@ya\pgf@yc
1628 \typeout{**** TEST corrected text box (x,y) =
1629 (\the\pgf@xa,\the\pgf@ya) }
1630 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1631 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
1632 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
1633 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
1634 \pgfpathclose
1635 }
1636 % \end{macrocode}
1637 % \end{macro}
1638 %
1639 %\iffalse
1640 %</package>
1641 %\fi
1642 %
1643 % \Finale
1644 %
1645 %^^A###########################################################################
1646 %^^A# Additional installed files #
1647 %^^A###########################################################################
1648 %
1649 %^^A - Option = sample ...
1650 %^^A - This is the package's sample shape.
1651 %^^A - It is included in the report, and it is given as a file to be used as
1652 %^^A - a template for new shapes.
1653 %\iffalse
1654 %<*sample>
1655 %%--------------------------------------------------
1656 %%
1657 %% This is a sample shape for the makeshape package
1658 %%
1659 %% It can be adapted for other shapes. See
1660 %% makeshape.pdf for instructions.
1661 %%
1662 %% 25 January 2013
1663
1664 \usepackage{makeshape}
1665 \makeatletter
1666
1667 %% Constant for sample shape
1668 \def\gap{4pt}
1669
1670 %% Anchor path <- change and rename as required
1671 \def\sampleanchor{
1672 % get corrected text box
1673 \pgf@xa=\ctbnex
1674 \pgf@ya=\ctbney
1675 % make room for shape
1676 \advance\pgf@xa by \gap
1677 \advance\pgf@ya by \gap
1678 % correct for minheight and minwidth and
1679 % for outerxsep or outerysep
1680 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1681 \advance\pgf@xa\pgfshapeouterxsep
1682 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1683 \advance\pgf@ya\pgfshapeouterysep
1684 % draw the path
1685 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1686 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
1687 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
1688 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
1689 \pgfpathclose
1690 }
1691
1692 %% Background path <- change and rename as required
1693 \def\sampleborder{
1694 % get corrected text box
1695 \pgf@xa=\ctbnex
1696 \pgf@ya=\ctbney
1697 % make room for shape
1698 \advance\pgf@xa by \gap
1699 \advance\pgf@ya by \gap
1700 % correct for minheight and minwidth but
1701 % not for outerxsep or outerysep
1702 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1703 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1704 % draw outer shape
1705 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1706 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
1707 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
1708 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
1709 \pgfpathclose
1710 % draw inner shape
1711 \advance\pgf@xa by -\gap
1712 \advance\pgf@ya by -\gap
1713 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
1714 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
1715 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
1716 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
1717 \pgfpathclose
1718 }
1719
1720 %%------------------------------------------------
1721 %% Shape declaration <- Change name as required
1722 \pgfdeclareshape{sample}{
1723
1724 % Set paths <- change path macros as required
1725 \setpaths{\sampleanchor}{\sampleborder}
1726
1727 % Saved anchors <- change as required
1728 \savedanchor{\northeast}{
1729 \pgf@x = \ctbnex
1730 \pgf@y = \ctbney
1731 \advance\pgf@x by \gap
1732 \advance\pgf@y by \gap
1733 \mincorrect{\pgf@x}{\pgfshapeminwidth}
1734 \mincorrect{\pgf@y}{\pgfshapeminheight}
1735 \advance\pgf@x\pgfshapeouterxsep
1736 \advance\pgf@y\pgfshapeouterysep
1737 }
1738
1739 % Anchors <- change as required
1740 \anchor{north}{\northeast \pgf@x=0pt}
1741 \anchor{north east}{\northeast}
1742 \anchor{east}{\northeast \pgf@y=0pt}
1743 \anchor{south east}{\northeast \pgf@y=-\pgf@y}
1744 \anchor{south}{\northeast \pgf@x=0pt \pgf@y=-\pgf@y}
1745 \anchor{south west}{\northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
1746 \anchor{west}{\northeast \pgf@x=-\pgf@x \pgf@y=0pt}
1747 \anchor{north west}{\northeast \pgf@x=-\pgf@x}
1748
1749 }
1750
1751 \makeatother
1752
1753 %</sample>
1754 %\fi
1755 %
1756 \endinput
1757