Debian Codegraph @

texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex

raw
1 % Copyright 2019 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{pgfmoduleshapes.code.tex}
11
12
13
14 \newbox\pgfnodeparttextbox
15
16
17 % Creates a node
18 %
19 % #1 = shape type
20 % #2 = anchor
21 % #3 = name for later reference
22 % #4 = path usage command
23 %
24 % Description:
25 %
26 % This command draws a shape that has previously been defined using
27 % \pgfdeclareshape. The shape is shifted such that the anchor is at
28 % the origin. In order to transform the whole shape, you should setup
29 % pgf's transformation matrix prior to calling this command.
30 %
31 % When this command is called, the shape-specific TeX boxes of the
32 % node must have been setup correctly.
33 %
34 % Example:
35 %
36 % \pgftransformshift{\pgfpoint{1cm}{1cm}}
37 % \pgfmultipartnode{rectangle}{center}{hellonode}{\pgfusepath{stroke}}
38
39 \def\pgfmultipartnode#1#2#3#4{%
40 \pgfutil@ifundefined{pgf@sh@s@#1}%
41 {\pgferror{Unknown shape ``#1''}}%
42 {%
43 {%
44 \ifpgflatenodepositioning%
45 \pgfsys@beginscope%
46 \fi%
47 \pgf@outer@adjust@hook%
48 \let\pgf@sh@savedmacros=\pgfutil@empty% MW
49 \let\pgf@sh@savedpoints=\pgfutil@empty%
50 \def\pgf@sm@shape@name{#1}% CJ % TT added prefix!
51 \csname pgf@sh@s@#1\endcsname%
52 \pgf@sh@savedpoints%
53 \pgf@sh@savedmacros% MW
54 \pgftransformshift{%
55 \pgf@sh@reanchor{#1}{#2}%
56 \pgf@x=-\pgf@x%
57 \pgf@y=-\pgf@y%
58 }%
59 \expandafter\pgfsavepgf@process\csname pgf@sh@sa@#3\endcsname{%
60 \pgf@sh@reanchor{#1}{#2}% FIXME : this is double work!
61 }%
62 % Save the saved points and the transformation matrix
63 \edef\pgf@node@name{#3}%
64 \ifpgflatenodepositioning%
65 \pgf@shapes@late@pos@begin%
66 \fi%
67 \ifx\pgf@node@name\pgfutil@empty%
68 \else%
69 \expandafter\xdef\csname pgf@sh@ns@\pgf@node@name\endcsname{#1}%
70 \edef\pgf@sh@@temp{\noexpand\gdef\expandafter\noexpand\csname pgf@sh@np@\pgf@node@name\endcsname}%
71 \expandafter\pgf@sh@@temp\expandafter{\pgf@sh@savedpoints}%
72 \edef\pgf@sh@@temp{\noexpand\gdef\expandafter\noexpand\csname pgf@sh@ma@\pgf@node@name\endcsname}% MW
73 \expandafter\pgf@sh@@temp\expandafter{\pgf@sh@savedmacros}% MW
74 \pgfgettransform\pgf@temp%
75 \expandafter\xdef\csname pgf@sh@nt@\pgf@node@name\endcsname{\pgf@temp}%
76 \expandafter\xdef\csname pgf@sh@pi@\pgf@node@name\endcsname{\pgfpictureid}%
77 \fi%
78 \pgfutil@ifundefined{pgf@sh@bbg@#1}{}
79 {{\pgfusetype{.behind background}\pgfidscope\pgfscope\csname pgf@sh@bbg@#1\endcsname\endpgfscope\endpgfidscope}}%
80 \pgfutil@ifundefined{pgf@sh@bg@#1}{%
81 \global\let\pgfpositionnodelaterpath\pgfutil@empty%
82 }%
83 {\pgfpushtype%
84 \pgfusetype{.background}\csname pgf@sh@bg@#1\endcsname%
85 \ifpgflatenodepositioning%
86 \pgfsyssoftpath@getcurrentpath\pgfpositionnodelaterpath%
87 \pgfprocessround{\pgfpositionnodelaterpath}{\pgfpositionnodelaterpath}%
88 \global\let\pgfpositionnodelaterpath\pgfpositionnodelaterpath%
89 \fi%
90 #4\pgfpoptype}%
91 \pgfutil@ifundefined{pgf@sh@fbg@#1}{}
92 {{\pgfusetype{.before background}\pgfidscope\pgfscope\csname pgf@sh@fbg@#1\endcsname\endpgfscope\endpgfidscope}}%
93 {%
94 \expandafter\pgfutil@for\expandafter\pgf@shape@com\expandafter:\expandafter=\csname pgf@sh@boxes@#1\endcsname\do{%
95 {%
96 \pgfusetype{.\pgf@shape@com}%
97 \pgftransformshift{\pgf@sh@reanchor{#1}{\pgf@shape@com}}%
98 \pgfapproximatenonlineartransformation%
99 \expandafter\pgfqboxsynced\expandafter{\csname pgfnodepart\pgf@shape@com box\endcsname}%
100 }%
101 }%
102 }%
103 \pgfutil@ifundefined{pgf@sh@bfg@#1}{}%
104 {{\pgfusetype{.behind foreground}\pgfidscope\pgfscope\csname pgf@sh@bfg@#1\endcsname\endpgfscope\endpgfidscope}}%
105 \pgfutil@ifundefined{pgf@sh@fg@#1}{}%
106 {\pgfpushtype\pgfusetype{.foreground}\csname pgf@sh@fg@#1\endcsname#4\pgfpoptype}%
107 \pgfutil@ifundefined{pgf@sh@ffg@#1}{}%
108 {{\pgfusetype{.before foreground}\pgfidscope\pgfscope\csname pgf@sh@ffg@#1\endcsname\endpgfscope\endpgfidscope}}%
109 \ifpgflatenodepositioning%
110 \pgf@shapes@late@pos@end%
111 \pgfsys@endscope%
112 \else%
113 \expandafter\pgf@nodecallback\expandafter{\pgf@node@name}%
114 \fi%
115 }%
116 }%
117 }%
118 \let\pgf@outer@adjust@hook\relax
119
120 \def\pgf@shapes@late@pos@begin{%
121 % Rename node
122 \edef\pgf@node@name{not yet positionedPGFINTERNAL\pgf@node@name}%
123 % Interrupt bounding box!
124 \pgfinterruptboundingbox%
125 % Put everything in our box:
126 \pgf@relevantforpicturesizetrue%
127 \setbox\pgfpositionnodelaterbox=\hbox%
128 \bgroup%
129 \pgfsys@beginscope%
130 }%
131
132 \def\pgf@shapes@late@pos@end{%
133 \pgfsys@endscope%
134 \egroup% Close box
135 \ifdim\pgf@picminx>\pgf@picmaxx\relax% happens for empty nodes
136 \def\pgfpositionnodelaterminx{0.0pt}%
137 \let\pgfpositionnodelaterminy\pgfpositionnodelaterminx%
138 \let\pgfpositionnodelatermaxx\pgfpositionnodelaterminx%
139 \let\pgfpositionnodelatermaxy\pgfpositionnodelaterminx%
140 \else%
141 \edef\pgfpositionnodelaterminx{\the\pgf@picminx}%
142 \edef\pgfpositionnodelaterminy{\the\pgf@picminy}%
143 \edef\pgfpositionnodelatermaxx{\the\pgf@picmaxx}%
144 \edef\pgfpositionnodelatermaxy{\the\pgf@picmaxy}%
145 \fi%
146 \let\pgfpositionnodelatername=\pgf@node@name%
147 \pgf@positionnodelater@macro%
148 \endpgfinterruptboundingbox%
149 }%
150
151 \def\pgf@shift@node#1#2{%
152 % This internal command shifts the recorded coordinates for node #1
153 % by the vector #2. It is used to
154 % correct the position of the node if the recorded coordinate
155 % happens to be wrong
156 {%
157 \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
158 \pgf@process{#2}%
159 \advance\pgf@pt@x by\pgf@x%
160 \advance\pgf@pt@y by\pgf@y%
161 \pgfgettransform{\pgf@temp}%
162 \expandafter\xdef\csname pgf@sh@nt@#1\endcsname{\pgf@temp}%
163 }%
164 }%
165
166
167
168 % Creates a node
169 %
170 % #1 = shape type
171 % #2 = anchor
172 % #3 = normal TeX text
173 % #4 = name for later reference
174 % #5 = path usage command
175 %
176 % Description:
177 %
178 % This command draws a shape that has previously been defined using
179 % \pgfdeclareshape. The shape is shifted such that the anchor is at
180 % the origin. In order to transform the whole shape, you should setup
181 % pgf's transformation matrix prior to calling this command.
182 %
183 % Example:
184 %
185 % \pgftransformshift{\pgfpoint{1cm}{1cm}}
186 % \pgfnode{rectangle}{center}{Hello}{hellonode}{\pgfusepath{stroke}}
187
188 \def\pgfnode#1#2#3#4#5{%
189 {%
190 \setbox\pgfnodeparttextbox=\hbox%
191 {%
192 \pgfinterruptpicture%
193 {#3}%
194 \endpgfinterruptpicture%
195 }%
196 \pgfmultipartnode{#1}{#2}{#4}{#5}%
197 }
198 }%
199
200
201
202 % Create a node that is positioned later
203 %
204 % #1 = macro to be called after the next node has been created
205 %
206 % Description:
207 %
208 % You can use this command to create a node that is "positioned
209 % later". The idea is the following: Normally, when a node is created
210 % using a command like \pgfnode, the node is immediately inserted into
211 % the current picture. In particular, you have no chance to change the
212 % position of a created node after it has been create.
213 %
214 % Using \pgfpositionnodelater, you can change the default
215 % behaviour. This command is not a replacement for \pgfnode, but is
216 % called before such a command and will cause the following to happen:
217 % The node is created, but not inserted into the picture. Instead, it
218 % is stored in the box \pgfpositionnodelaterbox. Furthermore, the node
219 % is not relevant for the picture's bounding box, but a bounding box
220 % for the node is computed and stored in the macros
221 % \pgfpositionnodelaterboundboxminx to
222 % \pgfpositionnodelaterboundboxmaxy. Finally, the
223 % macro #1 is called with the following macros setup:
224 %
225 % \pgfpositionnodelaterbox
226 % A box register (box 0 by default) that stores the node's paths and
227 % texts. You should move the contents of this box to a box of your
228 % choice.
229 %
230 % \pgfpositionnodelatername
231 % The name of the just-created-node. This name will be the
232 % originally "desired" name of the box plus the prefix "not yet
233 % positioned boxPGFINTERNAL".
234 %
235 % \pgfpositionnodelaterminx
236 % \pgfpositionnodelatermaxx
237 % \pgfpositionnodelaterminy
238 % \pgfpositionnodelatermaxy
239 % These four macros store the bounding box as dimensions that are
240 % guaranteed to end with "pt".
241 %
242 % By setting #1 to \relax (which is the default), you can switch off
243 % the whole mechanism
244 %
245 % Once a late node has been created, you can add arbitrary code in the
246 % same picture. Then, at some later point, you call
247 % \pgfpositionnodenow to finally position the node at a given position.
248 %
249 % When \pgfpositionnodenow is called, the macros mentioned above
250 % should have the exact same values they had when #1 is called.
251
252 \def\pgfpositionnodelater#1{%
253 \let\pgf@positionnodelater@macro=#1%
254 \ifx\pgf@positionnodelater@macro\relax%
255 \pgflatenodepositioningfalse%
256 \else%
257 \pgflatenodepositioningtrue%
258 \fi%
259 }%
260 \newif\ifpgflatenodepositioning
261 \pgfpositionnodelater{\relax}%
262 \def\pgfpositionnodelaterbox{0}%
263
264
265
266
267 % Position a node that has been scheduled for later insertion
268 %
269 % #1 = position in the picture, where the original anchor should go,
270 % now
271 %
272 % Description:
273 %
274 % This command works in concert with \pgfpositionnodelater, see the
275 % description there. When \pgfpositionnodenow is called, the macros
276 % \pgfpositionnodelaterbox and so on should be set to the values they
277 % had when the macro given to \pgfpositionnodelater was called. Then,
278 % the box described by these macros will be inserted into the picture
279 % at the position given #1. More precisely, the original node will
280 % have been positioned such that the anchor given upon invocation is
281 % at (0,0) and the node is now shifted by #1 before being inserted
282 % into the actual picture.
283
284 \def\pgfpositionnodenow#1{%
285 \pgfinterruptpath%
286 {%
287 \pgfpointtransformed{#1}%
288 \edef\pgf@temp@shift{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}
289 \pgftransformreset%
290 \pgftransformshift{\pgf@temp@shift}%
291 \pgfsys@pictureboxsynced\pgfpositionnodelaterbox%
292 \pgf@shift@node{\pgfpositionnodelatername}{\pgf@temp@shift}%
293 % Bounding box update...
294 \pgfpointtransformed{\pgfqpoint{\pgfpositionnodelaterminx}{\pgfpositionnodelaterminy}}%
295 \pgf@protocolsizes{\pgf@x}{\pgf@y}
296 \pgfpointtransformed{\pgfqpoint{\pgfpositionnodelatermaxx}{\pgfpositionnodelatermaxy}}%
297 \pgf@protocolsizes{\pgf@x}{\pgf@y}
298 % Naming and callbacks
299 \expandafter\pgfpositionnodenow@rename\pgfpositionnodelatername\relax%
300 }%
301 % Late setup%
302 {%
303 \csname pgf@lns@\pgfpositionnodelatername\endcsname%
304 \expandafter\global\expandafter\let\csname pgf@lns@\pgfpositionnodelatername\endcsname\relax%
305 }%
306 \endpgfinterruptpath%
307 }%
308
309 \def\pgfpositionnodenow@rename not yet positionedPGFINTERNAL#1\relax{%
310 \pgfnoderename{#1}{not yet positionedPGFINTERNAL#1}
311 }%
312
313
314
315 % "Fake" a node
316 %
317 % #1 = node name
318 %
319 % Description:
320 %
321 % This command will setup things so that it "looks like" a node named
322 % #1 has been created, but, in reality, no node is created. The idea
323 % is that a node created in this way can be referenced by systems
324 % using the late positioning, which will only create the node later
325 % on.
326 %
327 \def\pgffakenode#1{%
328 \edef\pgf@temp{\ifpgflatenodepositioning not yet positionedPGFINTERNAL\fi#1}%
329 \expandafter\gdef\csname pgf@sh@ns@\pgf@temp\endcsname{coordinate}%
330 \expandafter\gdef\csname pgf@sh@np@\pgf@temp\endcsname{\def\centerpoint{\pgfpointorigin}}%
331 \expandafter\gdef\csname pgf@sh@nt@\pgf@temp\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
332 \expandafter\global\expandafter\let\csname pgf@sh@ma@\pgf@temp\endcsname\pgfutil@empty%
333 \expandafter\xdef\csname pgf@sh@pi@\pgf@temp\endcsname{\pgfpictureid}%
334 }%
335
336
337
338 % Specify code that should be executed after a node has been created
339 %
340 % #1 = node name
341 % #2 = later code
342 %
343 % Description:
344 %
345 % This macro allows you to provide some code #2 that will be executed
346 % right after a node has been positioned using \pgfpositionnodenow. If
347 % the node has already been positioned (if the late positioning is not
348 % switched on), nothing happens.
349
350 \def\pgfnodepostsetupcode#1#2{%
351 \ifpgflatenodepositioning%
352 \expandafter\ifx\csname pgf@lns@not yet positionedPGFINTERNAL#1\endcsname\relax%
353 \expandafter\gdef\csname pgf@lns@not yet positionedPGFINTERNAL#1\endcsname{#2}%
354 \else%
355 \expandafter\pgfutil@g@addto@macro\csname pgf@lns@not yet positionedPGFINTERNAL#1\endcsname{#2}%
356 \fi%
357 \fi%
358 }%
359
360
361
362 % Alias a node
363 %
364 % #1 = new node name
365 % #2 = existing node name
366 %
367 % Description:
368 %
369 % This command allows you to subsequently access the node #2 using the
370 % name #1.
371 %
372 % Example:
373 %
374 % \pgfnode{rectangle}{center}{Hallo}{hellonode}{}
375 % \pgfnodealias{mynode}{hellonode}
376
377 \def\pgfnodealias#1#2{%
378 \pgf@node@gnamelet{pgf@sh@ns@#1}{pgf@sh@ns@#2}%
379 \pgf@node@gnamelet{pgf@sh@np@#1}{pgf@sh@np@#2}%
380 \pgf@node@gnamelet{pgf@sh@nt@#1}{pgf@sh@nt@#2}%
381 \pgf@node@gnamelet{pgf@sh@pi@#1}{pgf@sh@pi@#2}%
382 \pgf@node@gnamelet{pgf@sh@ma@#1}{pgf@sh@ma@#2}%
383 \pgf@nodecallback{#1}%
384 }%
385 \def\pgf@node@gnamelet#1#2{%
386 \expandafter\let\expandafter\pgf@temp\csname #2\endcsname%
387 \expandafter\global\expandafter\let\csname #1\endcsname=\pgf@temp%
388 }%
389
390 % Rename a node
391 %
392 % #1 = new name
393 % #2 = old name
394 %
395 % Description:
396 %
397 % Renames a node. This is like an alias, only the memory used for the
398 % old name is freed.
399
400 \def\pgfnoderename#1#2{%
401 \pgfnodealias{#1}{#2}%
402 \expandafter\global\expandafter\let\csname pgf@sh@ns@#2\endcsname\relax
403 \expandafter\global\expandafter\let\csname pgf@sh@np@#2\endcsname\relax
404 \expandafter\global\expandafter\let\csname pgf@sh@nt@#2\endcsname\relax
405 \expandafter\global\expandafter\let\csname pgf@sh@pi@#2\endcsname\relax
406 \expandafter\global\expandafter\let\csname pgf@sh@ma@#2\endcsname\relax
407 }%
408
409
410
411
412 % Quickly create a coordinate node
413 %
414 % #1 = name
415 % #2 = coordinate
416 %
417 % Description:
418 %
419 % Creates a node of shape coordinate. The following have the same
420 % effect, only the second is much faster:
421 %
422 % { \pgftransformshift{\pgfpoint{1cm}{2cm} \pgfnode{coordinate}{center}{}{foo}{} }
423 % \pgfcoordinate{foo}{\pgfpoint{1cm}{2cm}}
424
425 \def\pgfcoordinate#1#2{%
426 \edef\pgf@temp{#1}%
427 \ifx\pgf@temp\pgfutil@empty% do nothing
428 \else%
429 \ifpgflatenodepositioning%
430 {\pgftransformshift{#2}\pgfnode{coordinate}{center}{}{#1}{}}%
431 \else%
432 \pgf@process{\pgfpointtransformed{#2}}%
433 \expandafter\gdef\csname pgf@sh@ns@#1\endcsname{coordinate}%
434 \expandafter\xdef\csname pgf@sh@np@#1\endcsname{%
435 \noexpand\def\noexpand\centerpoint{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
436 }
437 \expandafter\gdef\csname pgf@sh@nt@#1\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
438 \expandafter\global\expandafter\let\csname pgf@sh@ma@#1\endcsname\pgfutil@empty%
439 \expandafter\xdef\csname pgf@sh@pi@#1\endcsname{\pgfpictureid}%
440 \fi%
441 \fi%
442 }%
443
444 \def\pgf@sh@redeferredanchor#1#2{% CJ
445 \expandafter\gdef\csname pgf@anchor@\pgf@sm@shape@name @#1\endcsname{#2}}% CJ
446
447
448
449
450
451
452 \def\pgf@sh@resavedanchor#1#2{%
453 \pgf@process{#2}%
454 \edef\pgf@sh@marshal{%
455 \noexpand\pgfutil@g@addto@macro\noexpand\pgf@sh@savedpoints{%
456 \noexpand\def\noexpand#1{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
457 }}%
458 \pgf@sh@marshal%
459 }%
460
461
462 \def\pgf@sh@resaveddimen#1#2{%
463 {#2\global\pgf@x=\pgf@x}%
464 \edef\pgf@sh@marshal{%
465 \noexpand\pgfutil@g@addto@macro\noexpand\pgf@sh@savedpoints{%
466 \noexpand\def\noexpand#1{\the\pgf@x}%
467 }}%
468 \pgf@sh@marshal%
469 }%
470
471 \def\pgf@sh@resavedmacro#1#2{%
472 \let#1\pgfutil@empty%
473 \def\addtosavedmacro##1{%
474 \expandafter\def\expandafter\pgf@sh@addtomacro@temp\expandafter{#1\noexpand\def\noexpand##1{##1}}%
475 {\expandafter\pgfutil@toks@\expandafter{\pgf@sh@addtomacro@temp}\expandafter}%
476 \expandafter\def\expandafter#1\expandafter{\the\pgfutil@toks@}%
477 }%
478 #2\relax%
479 \edef\pgf@sh@marshal{%
480 \noexpand\pgfutil@g@addto@macro\noexpand\pgf@sh@savedmacros{%
481 \noexpand\def\noexpand#1{#1}%
482 }}%
483 \pgf@sh@marshal%
484 }%
485
486 % Invoke an anchor
487 \def\pgf@sh@reanchor#1#2{%
488 \pgfutil@ifundefined{pgf@anchor@#1@#2}%
489 {%
490 \pgfutil@ifundefined{pgf@anchor@generic@#2}{%
491 \pgfmathsetcounter{pgf@counta}{#2}%
492 \csname pgf@anchor@#1@border\endcsname{\pgfqpointpolar{\the\c@pgf@counta}{1pt}}%
493 }{%
494 \csname pgf@anchor@generic@#2\endcsname{#1}%
495 }%
496 }%
497 {\csname pgf@anchor@#1@#2\endcsname}%
498 }%
499
500 % Defines a generic anchor, i.e. one which gets the associated shape
501 % as first argument.
502 %
503 % #1: the anchor name.
504 % #2: the code of the anchor. It may depend upon '##1', the shape's
505 % name.
506 %
507 % The anchor will be defined locally in the current TeX scope.
508 %
509 % If the anchor will be referenced later by \pgfpointanchor, the macro \pgfreferencednodename
510 % can be used to query the referenced node's name.
511 % This macro is not defined during node creation.
512 \def\pgfdeclaregenericanchor#1#2{%
513 \expandafter\def\csname pgf@anchor@generic@#1\endcsname##1{#2}%
514 }%
515
516
517 % Retrieves an anchor of a shape
518 %
519 % #1 = name
520 % #2 = anchor or a number (corresponding to a degree)
521 %
522 % Description:
523 %
524 % This command yields a point at the anchor of the given named shape.
525 %
526 % Example:
527 %
528 % \pgfshape{rectangle}{center}{Hello}{hellonode}{\pgfusepath[stroke]}
529 % \pgfpathmoveto{\pgfpointanchor{hellonode}{center}}
530
531 \def\pgfpointanchor#1#2{%
532 % Ok, check whether #1 is known!
533 \pgfutil@ifundefined{pgf@sh@ns@#1}
534 {\pgfutil@ifundefined{pgf@sh@ns@not yet positionedPGFINTERNAL#1}{%
535 \pgferror{No shape named `#1' is known}}{
536 % else, fail silently
537 }%
538 \pgfpointorigin}%
539 {%
540 \pgf@process{%
541 \edef\pgfreferencednodename{#1}% for use inside of anchors.
542 % MW install special macros
543 \csname pgf@sh@ma@#1\endcsname% MW
544 % install special coordinates
545 \csname pgf@sh@np@#1\endcsname
546 \pgf@sh@reanchor{\csname pgf@sh@ns@#1\endcsname}{#2}%
547 {%
548 \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
549 \pgf@pos@transform@glob%
550 }%
551 % Add inter picture transformation
552 \pgf@shape@interpictureshift{#1}%
553 % Undo current transformation
554 \pgftransforminvert%
555 \pgf@pos@transform@glob%
556 }%
557 }%
558 }%
559
560 \def\pgf@shape@interpictureshift#1{%
561 \expandafter\ifx\csname pgf@sh@pi@#1\endcsname\pgfpictureid%
562 \else%
563 \pgfsys@getposition{\csname pgf@sh@pi@#1\endcsname}\pgf@shape@original@pos%
564 \pgfsys@getposition{\pgfpictureid}\pgf@shape@current@pos%
565 \pgf@xa=\pgf@x%
566 \pgf@ya=\pgf@y%
567 \pgf@process{\pgfpointorigin\pgf@shape@current@pos}%
568 \advance\pgf@xa by-\pgf@x%
569 \advance\pgf@ya by-\pgf@y%
570 \pgf@process{\pgfpointorigin\pgf@shape@original@pos}%
571 \advance\pgf@xa by\pgf@x%
572 \advance\pgf@ya by\pgf@y%
573 \pgf@x=\pgf@xa%
574 \pgf@y=\pgf@ya%
575 \fi%
576 }%
577
578
579
580 % Retrieves a border point of a shape
581 %
582 % #1 = name
583 % #2 = another point
584 %
585 % Description:
586 %
587 % This command yields a point on the border of the shape that is on a
588 % straight line from the center to the point #2.
589 %
590 % Example:
591 %
592 % \pgfshape{rectangle}{center}{Hello}{hellonode}{\pgfusepath[stroke]}
593 % \pgfpathmoveto{\pgfpointshapeborder{hellonode}{\pgfpoint{2cm}{1cm}}
594 % \pgfpathlineto{\pgfpoint{2cm}{1cm}}
595 % \pgfusepath{stroke}
596
597 \def\pgfpointshapeborder#1#2{%
598 % Ok, check whether #1 is known!
599 \pgfutil@ifundefined{pgf@sh@ns@#1}
600 {\pgferror{No shape named `#1' is known}%
601 \pgfpointorigin}%
602 {%
603 \pgf@process{%
604 \edef\pgfreferencednodename{#1}% for use inside of anchors.
605 % MW install special macros
606 \csname pgf@sh@ma@#1\endcsname% MW
607 % install special coordinates
608 \csname pgf@sh@np@#1\endcsname%
609 {%
610 \pgf@process{\pgfpointtransformed{#2}}%
611 \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
612 \pgftransforminvert%
613 \pgf@pos@transform@glob%
614 \pgf@xa=\pgf@x%
615 \pgf@ya=\pgf@y%
616 \pgf@process{\csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @center\endcsname}%
617 \pgf@process{\pgf@shape@interpictureshift{#1}}%%
618 \advance\pgf@xa by-\pgf@x%
619 \advance\pgf@ya by-\pgf@y%
620 % Now (\pgf@xa, \pgf@ya) is a coord in shape's coord system, and
621 % relative to the anchor "center". If (xa, ya) is almost identical to
622 % the node center, which is determined by sqrt(xa^2+ya^2) < 0.02pt,
623 % just return the node center.
624 %
625 % \pgf@xb = 10*\pgf@xa if -1pt<\pgf@xa<1pt else 10pt
626 % - "10*\pgf@xa": reduce ruonding errors when \pgf@xa is small
627 % - "-1pt<\pgf@xa<1pt": guard against error "Dimension too large"
628 \pgf@xb=10pt
629 \ifdim\pgf@xa<1pt\ifdim\pgf@xa>-1pt
630 \pgf@xb=10\pgf@xa
631 \fi\fi
632 % \pgf@yb = 10*\pgf@ya if -1pt<\pgf@ya<1pt else 10pt
633 \pgf@yb=10pt
634 \ifdim\pgf@ya<1pt\ifdim\pgf@ya>-1pt
635 \pgf@yb=10\pgf@ya
636 \fi\fi
637 % if xb^2+yb^2 < 0.04pt, which means sqrt(xa^2+ya^2) < 0.02pt,
638 % return node center
639 \ifdim\dimexpr\expandafter\Pgf@geT\the\pgf@xb\pgf@xb
640 +\expandafter\Pgf@geT\the\pgf@yb\pgf@yb\relax<0.04pt
641 \expandafter\pgfutil@firstoftwo
642 \else
643 \expandafter\pgfutil@secondoftwo
644 \fi
645 {% return coord of "center"
646 \pgfwarning
647 {Returning node center instead of a point on node border. Did you
648 specify a point identical to the center of node
649 ``\pgfreferencednodename''?}%
650 \pgf@sh@reanchor{\csname pgf@sh@ns@#1\endcsname}{center}%
651 }
652 {% this calls the corresponding \anchorborder in shape declaration
653 \csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @border\endcsname
654 {\pgfqpoint{\pgf@xa}{\pgf@ya}}%
655 }%
656 \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
657 \pgf@pos@transform@glob%
658 \global\pgf@x=\pgf@x%
659 \global\pgf@y=\pgf@y%
660 }%
661 % Add inter picture transformation
662 \pgf@shape@interpictureshift{#1}%
663 % Undo current transformation
664 \pgftransforminvert%
665 \pgf@pos@transform@glob%
666 }%
667 }%
668 }%
669
670
671 % Retrieve the list of node parts of a shape
672 %
673 % #1 = a macro
674 % #2 = a shape name
675 %
676 % Description:
677 %
678 % Stores the list of node parts of a shape #2 in the macro #1.
679 %
680 % Example:
681 %
682 % \pgfgetnodeparts\mylist{circle split}
683 %
684 % This will set \mylist\ to "text,lower"
685
686 \def\pgfgetnodeparts#1#2{%
687 \expandafter\let\expandafter#1\csname pgf@sh@boxes@#2\endcsname%
688 }%
689
690
691 % Declares a shape type
692 %
693 % #1 = shape type
694 % #2 = shape specification
695 %
696 % Description:
697 %
698 % This command declares a new shape type. The shape specification
699 % should contain the following commands:
700 %
701 % - \savedanchor
702 % This command takes two arguments: a name and some code. The point
703 % specified by the code (the \pgf@x and \pgf@y values resulting from
704 % executing the code, to be precise), will be stored under the given
705 % name. Whenever, later on, an anchor is invoked these stored points
706 % will be available. The \saveddimen works like \savedanchor, only a
707 % single dimension is stored (taken from \pgf@x).
708 % When a savedanchor is calculated, the height/width/depth of the
709 % boxes mentioned in \nodeparts can be used.
710 %
711 % - \anchor
712 % Specifies an anchor. This command takes two arguments: an anchor
713 % name and some code for computing the anchor. When the anchor
714 % computation starts, all shape points and shape dimension will be
715 % setup.
716 %
717 % - \anchorborder
718 % This command should compute a point on the border of the
719 % shape. When the code is called, \pgf@x and \pgf@y will have been
720 % preinitialised with a direction.
721 %
722 % - \behindbackgroundpath
723 % Some things to be draw behind everything.
724 %
725 % - \backgroundpath
726 % A path that is drawn behind the main box. How this path is used
727 % depends on how \pgfshape is called.
728 %
729 % - \beforebackgroundpath
730 % Some things to be draw before the background path, but behind the
731 % main box.
732 %
733 % - \behindforegroundpath
734 % Some things to be draw on top of the main box.
735 %
736 % - \foregroundpath
737 % A path that is drawn on top of all of the above. How this path is
738 % used depends on how \pgfshape is called.
739 %
740 % - \beforeforegroundpath
741 % Some things to be draw before everything.
742 %
743 % - \nodeparts
744 % List of node parts that make up the shape. For each entry XYZ in
745 % the list there must be a box named \pgfnodepartXYZbox (possibly
746 % ``redirected'' to some different box using \let). Each such box
747 % will be placed at the anchor XYZ.
748 % By default, \nodeparts is just {text}. Thus, there will be one
749 % node part box named \pgfnodeparttextbox and this node will be
750 % placed at the anchor text.
751 %
752 %
753 % Example:
754 %
755 % See the definition of rectangle, below.
756
757 \long\def\pgfdeclareshape#1#2{%
758 {%
759 \def\pgf@sm@shape@name{#1}%
760 \let\savedanchor=\pgf@sh@savedanchor
761 \let\saveddimen=\pgf@sh@saveddimen
762 \let\savedmacro=\pgf@sh@savedmacro% MW
763 \let\deferredanchor=\pgf@sh@deferredanchor% CJ
764 \let\anchor=\pgf@sh@anchor
765 \let\anchorborder=\pgf@sh@anchorborder
766 \let\behindbackgroundpath=\pgf@sh@behindbgpath
767 \let\backgroundpath=\pgf@sh@bgpath
768 \let\beforebackgroundpath=\pgf@sh@beforebgpath
769 \let\behindforegroundpath=\pgf@sh@behindfgpath
770 \let\foregroundpath=\pgf@sh@fgpath
771 \let\beforeforegroundpath=\pgf@sh@beforefgpath
772 \let\nodeparts=\pgf@sh@boxes
773 \let\inheritsavedanchors=\pgf@sh@inheritsavedanchors
774 \let\inheritanchor=\pgf@sh@inheritanchor
775 \let\inheritanchorborder=\pgf@sh@inheritanchorborder
776 \let\inheritbehindbackgroundpath=\pgf@sh@inheritbehindbgpath
777 \let\inheritbackgroundpath=\pgf@sh@inheritbgpath
778 \let\inheritbeforebackgroundpath=\pgf@sh@inheritbeforebgpath
779 \let\inheritbehindforegroundpath=\pgf@sh@inheritbehindfgpath
780 \let\inheritforegroundpath=\pgf@sh@inheritfgpath
781 \let\inheritbeforeforegroundpath=\pgf@sh@inheritbeforefgpath
782 \let\inheritnodeparts=\pgf@sh@inheritboxes
783 \anchorborder{\csname pgf@anchor@#1@center\endcsname}%
784 \anchor{text}{\pgfpointorigin}%
785 \nodeparts{text}%
786 \expandafter\global\expandafter\let\csname pgf@sh@s@\pgf@sm@shape@name\endcsname=\pgfutil@empty%
787 #2%
788 }%
789 }%
790
791 \def\pgf@sh@savedanchor#1#2{%
792 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@\pgf@sm@shape@name\endcsname{\pgf@sh@resavedanchor{#1}{#2}}}%
793 \def\pgf@sh@saveddimen#1#2{%
794 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@\pgf@sm@shape@name\endcsname{\pgf@sh@resaveddimen{#1}{#2}}}%
795 \def\pgf@sh@savedmacro#1#2{% MW
796 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@\pgf@sm@shape@name\endcsname{\pgf@sh@resavedmacro{#1}{#2}}}% MW
797 \def\pgf@sh@anchor#1#2{\expandafter\gdef\csname pgf@anchor@\pgf@sm@shape@name @#1\endcsname{#2}}%
798 \def\pgf@sh@deferredanchor#1#2{% CJ
799 \expandafter\pgfutil@g@addto@macro
800 \csname pgf@sh@s@\pgf@sm@shape@name\endcsname{\pgf@sh@redeferredanchor{#1}{#2}}}% CJ
801 \def\pgf@sh@anchorborder#1{\expandafter\gdef\csname pgf@anchor@\pgf@sm@shape@name @border\endcsname##1{\pgf@process{##1}#1}}%
802 \long\def\pgf@sh@behindbgpath#1{\expandafter\gdef\csname pgf@sh@bbg@\pgf@sm@shape@name\endcsname{#1}}%
803 \long\def\pgf@sh@bgpath#1{\expandafter\gdef\csname pgf@sh@bg@\pgf@sm@shape@name\endcsname{#1}}%
804 \long\def\pgf@sh@beforebgpath#1{\expandafter\gdef\csname pgf@sh@fbg@\pgf@sm@shape@name\endcsname{#1}}%
805 \long\def\pgf@sh@behindfgpath#1{\expandafter\gdef\csname pgf@sh@bfg@\pgf@sm@shape@name\endcsname{#1}}%
806 \long\def\pgf@sh@fgpath#1{\expandafter\gdef\csname pgf@sh@fg@\pgf@sm@shape@name\endcsname{#1}}%
807 \long\def\pgf@sh@beforefgpath#1{\expandafter\gdef\csname pgf@sh@ffg@\pgf@sm@shape@name\endcsname{#1}}%
808 \def\pgf@sh@boxes#1{\expandafter\gdef\csname pgf@sh@boxes@\pgf@sm@shape@name\endcsname{#1}}%
809
810 \def\pgf@sh@inheritsavedanchors[from=#1]{%
811 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@\pgf@sm@shape@name\endcsname{\csname pgf@sh@s@#1\endcsname}}%
812
813 \def\pgf@sh@inheritanchor[from=#1]#2{%
814 \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
815 pgf@anchor@\pgf@sm@shape@name @#2\endcsname=\expandafter\noexpand\csname
816 pgf@anchor@#1@#2\endcsname}%
817 \pgf@marshal%
818 }%
819 \def\pgf@sh@inheritanchorborder[from=#1]{%
820 \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
821 pgf@anchor@\pgf@sm@shape@name @border\endcsname=\expandafter\noexpand\csname
822 pgf@anchor@#1@border\endcsname}%
823 \pgf@marshal%
824 }%
825 \def\pgf@sh@inheritor#1#2{%
826 \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
827 pgf@sh@#1@\pgf@sm@shape@name\endcsname=\expandafter\noexpand\csname
828 pgf@sh@#1@#2\endcsname}%
829 \pgf@marshal%
830 }%
831 \def\pgf@sh@inheritbehindbgpath[from=#1]{\pgf@sh@inheritor{bbg}{#1}}%
832 \def\pgf@sh@inheritbgpath[from=#1]{\pgf@sh@inheritor{bg}{#1}}%
833 \def\pgf@sh@inheritbeforebgpath[from=#1]{\pgf@sh@inheritor{fbg}{#1}}%
834 \def\pgf@sh@inheritbehindfgpath[from=#1]{\pgf@sh@inheritor{bfg}{#1}}%
835 \def\pgf@sh@inheritfgpath[from=#1]{\pgf@sh@inheritor{fg}{#1}}%
836 \def\pgf@sh@inheritbeforefgpath[from=#1]{\pgf@sh@inheritor{ffg}{#1}}%
837 \def\pgf@sh@inheritboxes[from=#1]{\pgf@sh@inheritor{boxes}{#1}}%
838
839
840
841 %
842 % Coordinate. This shape is special: It is only used to reference a
843 % point for later usage. Nothing is drawn, all anchors are identical
844 % to the center.
845 %
846
847 \pgfdeclareshape{coordinate}
848 {%
849 \savedanchor\centerpoint{%
850 % x
851 \pgf@x=.5\wd\pgfnodeparttextbox%
852 % y
853 \pgf@y=.5\ht\pgfnodeparttextbox%
854 \advance\pgf@y by -.5\dp\pgfnodeparttextbox%
855 }%
856
857 \anchor{center}{\centerpoint}%
858 \anchor{north}{\centerpoint}%
859 \anchor{north west}{\centerpoint}%
860 \anchor{north east}{\centerpoint}%
861 \anchor{west}{\centerpoint}%
862 \anchor{east}{\centerpoint}%
863 \anchor{mid}{\centerpoint}%
864 \anchor{mid west}{\centerpoint}%
865 \anchor{mid east}{\centerpoint}%
866 \anchor{base}{\centerpoint}%
867 \anchor{base west}{\centerpoint}%
868 \anchor{base east}{\centerpoint}%
869 \anchor{south}{\centerpoint}%
870 \anchor{south west}{\centerpoint}%
871 \anchor{south east}{\centerpoint}%
872 \anchorborder{\centerpoint}%
873
874 \nodeparts{}% no text
875 }%
876
877
878 % Value keys for shapes:
879 %
880 % /pgf/inner xsep : recommended inner x separation
881 % /pgf/inner ysep : recommended inner y separation
882 % /pgf/outer xsep : recommended outer x separation
883 % /pgf/outer ysep : recommended outer y separation
884 % /pgf/minimum width : recommended minimum width
885 % /pgf/minimum height : recommended minimum height
886
887 \pgfset{
888 inner xsep/.initial =.3333em,
889 inner ysep/.initial =.3333em,
890 inner sep/.style ={/pgf/inner xsep={#1},/pgf/inner ysep={#1}},
891 outer xsep/.initial =.5\pgflinewidth,
892 outer ysep/.initial =.5\pgflinewidth,
893 outer sep/.code =\pgf@handle@outer@sep{#1},
894 minimum width/.initial =1pt,
895 minimum height/.initial =1pt,
896 minimum size/.style ={/pgf/minimum width={#1},/pgf/minimum height={#1}},
897 }%
898
899
900
901 \def\pgf@handle@outer@sep#1{%
902 \def\pgf@temp{#1}%
903 \ifx\pgf@temp\pgf@auto@text%
904 \def\pgf@outer@adjust@hook{%
905 \pgftransformationadjustments%
906 \pgfkeyssetvalue{/pgf/outer xsep}{.5\pgflinewidth*\pgfhorizontaltransformationadjustment}%
907 \pgfkeyssetvalue{/pgf/outer ysep}{.5\pgflinewidth*\pgfverticaltransformationadjustment}%
908 \pgf@outer@auto@adjust@hook%
909 }%
910 \else%
911 \pgfkeyssetvalue{/pgf/outer xsep}{#1}%
912 \pgfkeyssetvalue{/pgf/outer ysep}{#1}%
913 \fi%
914 }%
915 \def\pgf@auto@text{auto}%
916
917 \let\pgf@outer@auto@adjust@hook\relax
918
919
920 % Keys for rotating the shape border.
921 % (may not be supported by all shapes)
922 %
923 % /pgf/shape border uses incircle : Calculate the shape border using the incircle
924 % around the node contents (+inner sep).
925 %
926 % /pgf/shape border rotate : Angle of independent border rotation.
927
928 \newif\ifpgfshapeborderusesincircle
929 \pgfkeys{/pgf/shape border uses incircle/.is if=pgfshapeborderusesincircle}%
930 \pgfkeys{/pgf/shape border rotate/.initial=0}%
931
932 %
933 % Rectangle
934 %
935
936 \pgfdeclareshape{rectangle}
937 {%
938 \savedanchor\northeast{%
939 % Calculate x
940 %
941 % First, is width < minimum width?
942 \pgf@x=\the\wd\pgfnodeparttextbox%
943 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}%
944 \advance\pgf@x by 2\pgf@xc%
945 \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
946 \ifdim\pgf@x<\pgf@xb%
947 % yes, too small. Enlarge...
948 \pgf@x=\pgf@xb%
949 \fi%
950 % Now, calculate right border: .5\wd\pgfnodeparttextbox + .5 \pgf@x + outer sep
951 \pgf@x=.5\pgf@x%
952 \advance\pgf@x by.5\wd\pgfnodeparttextbox%
953 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
954 \advance\pgf@x by\pgf@xa%
955 % Calculate y
956 %
957 % First, is height+depth < minimum height?
958 \pgf@y=\ht\pgfnodeparttextbox%
959 \advance\pgf@y by\dp\pgfnodeparttextbox%
960 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}%
961 \advance\pgf@y by 2\pgf@yc%
962 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
963 \ifdim\pgf@y<\pgf@yb%
964 % yes, too small. Enlarge...
965 \pgf@y=\pgf@yb%
966 \fi%
967 % Now, calculate upper border: .5\ht-.5\dp + .5 \pgf@y + outer sep
968 \pgf@y=.5\pgf@y%
969 \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
970 \advance\pgf@y by.5\ht\pgfnodeparttextbox%
971 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
972 \advance\pgf@y by\pgf@ya%
973 }%
974
975 \savedanchor\southwest{%
976 % Calculate x
977 %
978 % First, is width < minimum width?
979 \pgf@x=\wd\pgfnodeparttextbox%
980 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}%
981 \advance\pgf@x by 2\pgf@xc%
982 \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
983 \ifdim\pgf@x<\pgf@xb%
984 % yes, too small. Enlarge...
985 \pgf@x=\pgf@xb%
986 \fi%
987 % Now, calculate left border: .5\wd\pgfnodeparttextbox - .5 \pgf@x - outer sep
988 \pgf@x=-.5\pgf@x%
989 \advance\pgf@x by.5\wd\pgfnodeparttextbox%
990 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
991 \advance\pgf@x by-\pgf@xa%
992 % Calculate y
993 %
994 % First, is height+depth < minimum height?
995 \pgf@y=\ht\pgfnodeparttextbox%
996 \advance\pgf@y by\dp\pgfnodeparttextbox%
997 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}%
998 \advance\pgf@y by 2\pgf@yc%
999 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
1000 \ifdim\pgf@y<\pgf@yb%
1001 % yes, too small. Enlarge...
1002 \pgf@y=\pgf@yb%
1003 \fi%
1004 % Now, calculate upper border: .5\ht-.5\dp - .5 \pgf@y - outer sep
1005 \pgf@y=-.5\pgf@y%
1006 \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
1007 \advance\pgf@y by.5\ht\pgfnodeparttextbox%
1008 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
1009 \advance\pgf@y by-\pgf@ya%
1010 }%
1011
1012 %
1013 % Anchors
1014 %
1015 \anchor{center}{
1016 \pgf@process{\northeast}%
1017 \pgf@xa=.5\pgf@x%
1018 \pgf@ya=.5\pgf@y%
1019 \pgf@process{\southwest}%
1020 \pgf@x=.5\pgf@x%
1021 \pgf@y=.5\pgf@y%
1022 \advance\pgf@x by \pgf@xa%
1023 \advance\pgf@y by \pgf@ya%
1024 }%
1025 \anchor{mid}{\pgf@anchor@rectangle@center\pgfmathsetlength\pgf@y{.5ex}}%
1026 \anchor{base}{\pgf@anchor@rectangle@center\pgf@y=0pt}%
1027 \anchor{north}{
1028 \pgf@process{\southwest}%
1029 \pgf@xa=.5\pgf@x%
1030 \pgf@process{\northeast}%
1031 \pgf@x=.5\pgf@x%
1032 \advance\pgf@x by \pgf@xa%
1033 }%
1034 \anchor{south}{
1035 \pgf@process{\northeast}%
1036 \pgf@xa=.5\pgf@x%
1037 \pgf@process{\southwest}%
1038 \pgf@x=.5\pgf@x%
1039 \advance\pgf@x by \pgf@xa%
1040 }%
1041 \anchor{west}{
1042 \pgf@process{\northeast}%
1043 \pgf@ya=.5\pgf@y%
1044 \pgf@process{\southwest}%
1045 \pgf@y=.5\pgf@y%
1046 \advance\pgf@y by \pgf@ya%
1047 }%
1048 \anchor{mid west}{\southwest\pgfmathsetlength\pgf@y{.5ex}}%
1049 \anchor{base west}{\southwest\pgf@y=0pt}%
1050 \anchor{north west}{
1051 \southwest
1052 \pgf@xa=\pgf@x
1053 \northeast
1054 \pgf@x=\pgf@xa}%
1055 \anchor{south west}{\southwest}%
1056 \anchor{east}{%
1057 \pgf@process{\southwest}%
1058 \pgf@ya=.5\pgf@y%
1059 \pgf@process{\northeast}%
1060 \pgf@y=.5\pgf@y%
1061 \advance\pgf@y by \pgf@ya%
1062 }%
1063 \anchor{mid east}{\northeast\pgfmathsetlength\pgf@y{.5ex}}%
1064 \anchor{base east}{\northeast\pgf@y=0pt}%
1065 \anchor{north east}{\northeast}%
1066 \anchor{south east}{
1067 \northeast
1068 \pgf@xa=\pgf@x
1069 \southwest
1070 \pgf@x=\pgf@xa
1071 }%
1072 \anchorborder{%
1073 \pgf@xb=\pgf@x% xb/yb is target
1074 \pgf@yb=\pgf@y%
1075 \southwest%
1076 \pgf@xa=\pgf@x% xa/ya is se
1077 \pgf@ya=\pgf@y%
1078 \northeast%
1079 \advance\pgf@x by-\pgf@xa%
1080 \advance\pgf@y by-\pgf@ya%
1081 \pgf@xc=.5\pgf@x% x/y is half width/height
1082 \pgf@yc=.5\pgf@y%
1083 \advance\pgf@xa by\pgf@xc% xa/ya becomes center
1084 \advance\pgf@ya by\pgf@yc%
1085 \edef\pgf@marshal{%
1086 \noexpand\pgfpointborderrectangle
1087 {\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}
1088 {\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
1089 }%
1090 \pgf@process{\pgf@marshal}%
1091 \advance\pgf@x by\pgf@xa%
1092 \advance\pgf@y by\pgf@ya%
1093 }%
1094
1095 %
1096 % Background path
1097 %
1098 \backgroundpath{
1099 \pgfpathrectanglecorners
1100 {\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
1101 {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
1102 }%
1103 }%
1104
1105
1106 % Special current path start coordinate:
1107 \expandafter\def\csname pgf@sh@ns@current subpath start\endcsname{coordinate}%
1108 \expandafter\def\csname pgf@sh@np@current subpath start\endcsname{%
1109 \def\centerpoint{\expandafter\pgfqpoint\pgfsyssoftpath@lastmoveto}%
1110 }%
1111 \expandafter\def\csname pgf@sh@nt@current subpath start\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
1112 \expandafter\def\csname pgf@sh@pi@current subpath start\endcsname{\pgfpictureid}%
1113
1114
1115
1116 % Special current bounding box rectangle:
1117 \expandafter\def\csname pgf@sh@ns@current bounding box\endcsname{rectangle}%
1118 \expandafter\def\csname pgf@sh@np@current bounding box\endcsname{%
1119 \def\southwest{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
1120 \def\northeast{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
1121 }%
1122 \expandafter\def\csname pgf@sh@nt@current bounding box\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
1123 \expandafter\def\csname pgf@sh@pi@current bounding box\endcsname{\pgfpictureid}%
1124
1125
1126 % Special current path bounding box rectangle:
1127 \expandafter\def\csname pgf@sh@ns@current path bounding box\endcsname{rectangle}%
1128 \expandafter\def\csname pgf@sh@np@current path bounding box\endcsname{%
1129 \def\southwest{\pgfqpoint{\pgf@pathminx}{\pgf@pathminy}}%
1130 \def\northeast{\pgfqpoint{\pgf@pathmaxx}{\pgf@pathmaxy}}%
1131 }%
1132 \expandafter\def\csname pgf@sh@nt@current path bounding box\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
1133 \expandafter\def\csname pgf@sh@pi@current path bounding box\endcsname{\pgfpictureid}%
1134
1135
1136 % Special current page bounding box rectangle:
1137 \expandafter\def\csname pgf@sh@ns@current page\endcsname{rectangle}%
1138 \expandafter\def\csname pgf@sh@np@current page\endcsname{%
1139 \def\southwest{\pgfpointorigin}%
1140 \def\northeast{\pgfpoint{\pgfsys@thepagewidth}{\pgfsys@thepageheight}}%
1141 }%
1142 \expandafter\def\csname pgf@sh@nt@current page\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
1143 \expandafter\def\csname pgf@sh@pi@current page\endcsname{pgfpageorigin}%
1144
1145
1146 % Special scope bounding box rectangle:
1147 \pgfkeys{/pgf/local bounding box/.code={%
1148 \expandafter\gdef\csname pgf@sh@ns@#1\endcsname{rectangle}
1149 \expandafter\gdef\csname pgf@sh@np@#1\endcsname{%
1150 \def\southwest{\pgfqpoint{\csname pgf@lbb@minx@#1\endcsname}{\csname pgf@lbb@miny@#1\endcsname}}%
1151 \def\northeast{\pgfqpoint{\csname pgf@lbb@maxx@#1\endcsname}{\csname pgf@lbb@maxy@#1\endcsname}}%
1152 }
1153 \expandafter\gdef\csname pgf@sh@nt@#1\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
1154 \expandafter\gdef\csname pgf@sh@pi@#1\endcsname{\pgfpictureid}
1155 \expandafter\gdef\csname pgf@lbb@maxx@#1\endcsname{-16000pt}%
1156 \expandafter\gdef\csname pgf@lbb@minx@#1\endcsname{16000pt}%
1157 \expandafter\gdef\csname pgf@lbb@maxy@#1\endcsname{-16000pt}%
1158 \expandafter\gdef\csname pgf@lbb@miny@#1\endcsname{16000pt}%
1159 \pgf@size@hookedtrue%
1160 \expandafter\def\expandafter\pgf@path@size@hook\expandafter{\pgf@path@size@hook\pgf@lbb@do{#1}}
1161 },
1162 /pgf/freeze local bounding box/.code={%
1163 {%
1164 \csname pgf@sh@np@#1\endcsname%
1165 \southwest%
1166 \pgf@xa=\pgf@x%
1167 \pgf@ya=\pgf@y%
1168 \northeast%
1169 \expandafter\xdef\csname pgf@sh@np@#1\endcsname{%
1170 \noexpand\def\noexpand\southwest{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
1171 \noexpand\def\noexpand\northeast{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
1172 }%
1173 }%
1174 },
1175 }%
1176 \def\pgf@lbb@do#1{%
1177 \ifdim\pgf@size@hook@x<\csname pgf@lbb@minx@#1\endcsname\expandafter\xdef\csname pgf@lbb@minx@#1\endcsname{\the\pgf@size@hook@x}\fi%
1178 \ifdim\pgf@size@hook@x>\csname pgf@lbb@maxx@#1\endcsname\expandafter\xdef\csname pgf@lbb@maxx@#1\endcsname{\the\pgf@size@hook@x}\fi%
1179 \ifdim\pgf@size@hook@y<\csname pgf@lbb@miny@#1\endcsname\expandafter\xdef\csname pgf@lbb@miny@#1\endcsname{\the\pgf@size@hook@y}\fi%
1180 \ifdim\pgf@size@hook@y>\csname pgf@lbb@maxy@#1\endcsname\expandafter\xdef\csname pgf@lbb@maxy@#1\endcsname{\the\pgf@size@hook@y}\fi%
1181 }%
1182
1183 %
1184 % Circle
1185 %
1186
1187 \pgfdeclareshape{circle}
1188 %
1189 % Draws a circle around the text
1190 %
1191 {%
1192 \savedanchor\centerpoint{%
1193 \pgf@x=.5\wd\pgfnodeparttextbox%
1194 \pgf@y=.5\ht\pgfnodeparttextbox%
1195 \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
1196 }%
1197
1198 \saveddimen\radius{%
1199 %
1200 % Calculate ``height radius''
1201 %
1202 \pgf@ya=.5\ht\pgfnodeparttextbox%
1203 \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
1204 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/inner ysep}}%
1205 \advance\pgf@ya by\pgf@yb%
1206 %
1207 % Calculate ``width radius''
1208 %
1209 \pgf@xa=.5\wd\pgfnodeparttextbox%
1210 \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/inner xsep}}%
1211 \advance\pgf@xa by\pgf@xb%
1212 %
1213 % Calculate length of radius vector:
1214 %
1215 \pgf@process{\pgfpointnormalised{\pgfqpoint{\pgf@xa}{\pgf@ya}}}%
1216 \ifdim\pgf@x>\pgf@y%
1217 \c@pgf@counta=\pgf@x%
1218 \ifnum\c@pgf@counta=0\relax%
1219 \else%
1220 \divide\c@pgf@counta by 255\relax%
1221 \pgf@xa=16\pgf@xa\relax%
1222 \divide\pgf@xa by\c@pgf@counta%
1223 \pgf@xa=16\pgf@xa\relax%
1224 \fi%
1225 \else%
1226 \c@pgf@counta=\pgf@y%
1227 \ifnum\c@pgf@counta=0\relax%
1228 \else%
1229 \divide\c@pgf@counta by 255\relax%
1230 \pgf@ya=16\pgf@ya\relax%
1231 \divide\pgf@ya by\c@pgf@counta%
1232 \pgf@xa=16\pgf@ya\relax%
1233 \fi%
1234 \fi%
1235 \pgf@x=\pgf@xa%
1236 %
1237 % If necessary, adjust radius so that the size requirements are
1238 % met:
1239 %
1240 \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/minimum width}}%
1241 \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/minimum height}}%
1242 \ifdim\pgf@x<.5\pgf@xb%
1243 \pgf@x=.5\pgf@xb%
1244 \fi%
1245 \ifdim\pgf@x<.5\pgf@yb%
1246 \pgf@x=.5\pgf@yb%
1247 \fi%
1248 %
1249 % Now, add larger of outer separations.
1250 %
1251 \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
1252 \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
1253 \ifdim\pgf@xb<\pgf@yb%
1254 \advance\pgf@x by\pgf@yb%
1255 \else%
1256 \advance\pgf@x by\pgf@xb%
1257 \fi%
1258 }%
1259
1260 %
1261 % Anchors
1262 %
1263 \anchor{center}{\centerpoint}%
1264 \anchor{mid}{\centerpoint\pgfmathsetlength\pgf@y{.5ex}}%
1265 \anchor{base}{\centerpoint\pgf@y=0pt}%
1266 \anchor{north}{\centerpoint\advance\pgf@y by\radius}%
1267 \anchor{south}{\centerpoint\advance\pgf@y by-\radius}%
1268 \anchor{west}{\centerpoint\advance\pgf@x by-\radius}%
1269 \anchor{east}{\centerpoint\advance\pgf@x by\radius}%
1270 \anchor{mid west}{\centerpoint\advance\pgf@x by-\radius\pgfmathsetlength\pgf@y{.5ex}}%
1271 \anchor{mid east}{\centerpoint\advance\pgf@x by\radius\pgfmathsetlength\pgf@y{.5ex}}%
1272 \anchor{base west}{\centerpoint\advance\pgf@x by-\radius\pgf@y=0pt}%
1273 \anchor{base east}{\centerpoint\advance\pgf@x by\radius\pgf@y=0pt}%
1274 \anchor{north west}{
1275 \centerpoint
1276 \pgf@xa=\radius
1277 \advance\pgf@x by-0.707107\pgf@xa
1278 \advance\pgf@y by0.707107\pgf@xa
1279 }%
1280 \anchor{south west}{
1281 \centerpoint
1282 \pgf@xa=\radius
1283 \advance\pgf@x by-0.707107\pgf@xa
1284 \advance\pgf@y by-0.707107\pgf@xa
1285 }%
1286 \anchor{north east}{
1287 \centerpoint
1288 \pgf@xa=\radius
1289 \advance\pgf@x by0.707107\pgf@xa
1290 \advance\pgf@y by0.707107\pgf@xa
1291 }%
1292 \anchor{south east}{
1293 \centerpoint
1294 \pgf@xa=\radius
1295 \advance\pgf@x by0.707107\pgf@xa
1296 \advance\pgf@y by-0.707107\pgf@xa
1297 }%
1298 \anchorborder{%
1299 \pgf@xa=\pgf@x%
1300 \pgf@ya=\pgf@y%
1301 \edef\pgf@marshal{%
1302 \noexpand\pgfpointborderellipse
1303 {\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}
1304 {\noexpand\pgfqpoint{\radius}{\radius}}%
1305 }%
1306 \pgf@marshal%
1307 \pgf@xa=\pgf@x%
1308 \pgf@ya=\pgf@y%
1309 \centerpoint%
1310 \advance\pgf@x by\pgf@xa%
1311 \advance\pgf@y by\pgf@ya%
1312 }%
1313
1314 %
1315 % Background path
1316 %
1317 \backgroundpath{%
1318 \pgfutil@tempdima=\radius%
1319 \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
1320 \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
1321 \ifdim\pgf@xb<\pgf@yb%
1322 \advance\pgfutil@tempdima by-\pgf@yb%
1323 \else%
1324 \advance\pgfutil@tempdima by-\pgf@xb%
1325 \fi%
1326 \pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
1327 }%
1328 }%
1329
1330
1331
1332
1333
1334 \endinput