1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
% pgfsubpic.tex
% Version 1, 22 Dec 2009
% Copyright 2009 by David Chiang
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\newdimen\pgf@subpicminx
\newdimen\pgf@subpicminy
\newdimen\pgf@subpicmaxx
\newdimen\pgf@subpicmaxy
% Special virtual node for current subpicture's bounding box
\expandafter\def\csname pgf@sh@ns@current subpicture\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@current subpicture\endcsname{%
\def\southwest{\pgfqpoint{\pgf@subpicminx}{\pgf@subpicminy}}%
\def\northeast{\pgfqpoint{\pgf@subpicmaxx}{\pgf@subpicmaxy}}%
}
\expandafter\def\csname pgf@sh@nt@current subpicture\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@current subpicture\endcsname{\pgfpictureid}
% Create a pgfpicture inside an hbox for delayed placement
\def\pgfsubpicture{%
\global\setbox\pgf@hbox=\hbox\bgroup
\pgfinterruptpicture%
\pgfpicture%
}
\def\endpgfsubpicture{
\global\pgf@subpicminx=\pgf@picminx
\global\pgf@subpicminy=\pgf@picminy
\global\pgf@subpicmaxx=\pgf@picmaxx
\global\pgf@subpicmaxy=\pgf@picmaxy
\global\edef\subpictureid{\pgfpictureid}%
\pgfsetbaseline{\pgf@picminy}%
\endpgfpicture%
\endpgfinterruptpicture%
\egroup
}
% Place a previously-created subpicture, lining up its origin with the current origin
\def\pgfplacesubpicture{
\pgfscope
% expand current bounding box to accommodate subpicture
\pgfpathmoveto{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}%
\pgfpathlineto{\pgfpoint{\the\pgf@subpicmaxx}{\the\pgf@subpicmaxy}}%
\pgfusepath{use as bounding box}%
% save relative position of subpicture inside containing picture
\pgfpointorigin
\pgf@pos@transform{\pgf@x}{\pgf@y}%
\expandafter\xdef\csname pgf@subpic@\subpictureid @x\endcsname{\the\pgf@x}%
\expandafter\xdef\csname pgf@subpic@\subpictureid @y\endcsname{\the\pgf@y}%
\expandafter\xdef\csname pgf@subpic@\subpictureid @p\endcsname{\pgfpictureid}%
% align origin of subpicture with origin
\pgftransformshift{\pgfpoint{\the\pgf@subpicminx}{\the\pgf@subpicminy}}%
\pgfqboxsynced{\pgf@hbox}%
\endpgfscope
}
% Hook onto existing macro \pgf@shape@interpictureshift.
% This is called whenever we look up an anchor of a node.
% This hook recursively checks to see if the node's picture
% is a subpicture of another, and if so, adjusts its position accordingly.
\let\orig@pgf@shape@interpictureshift\pgf@shape@interpictureshift
\def\unwind@subpic#1{%
% is #1 the current picture?
\edef\subpicid{#1}%
\ifx\subpicid\pgfpictureid
% yes, we're done
\else
% does #1 have a parent picture?
\expandafter\ifx\csname pgf@subpic@#1@p\endcsname\relax
% no, the original node was not inside the current picture
\fallback
\else
% yes, apply shift and move up to parent picture
\global\advance\pgf@x by \csname pgf@subpic@#1@x\endcsname
\global\advance\pgf@y by \csname pgf@subpic@#1@y\endcsname
\unwind@subpic{\csname pgf@subpic@#1@p\endcsname}%
\fi
\fi
}
\def\pgf@shape@interpictureshift#1{%
\edef\fallback{\pgf@x=\the\pgf@x\pgf@y=\the\pgf@y\noexpand\orig@pgf@shape@interpictureshift{#1}}%
\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}%
}
\def\pgfnodedelete#1{%
\expandafter\global\expandafter\let\csname pgf@sh@ns@#1\endcsname\relax
\expandafter\global\expandafter\let\csname pgf@sh@np@#1\endcsname\relax
\expandafter\global\expandafter\let\csname pgf@sh@nt@#1\endcsname\relax
\expandafter\global\expandafter\let\csname pgf@sh@pi@#1\endcsname\relax
\expandafter\global\expandafter\let\csname pgf@sh@ma@#1\endcsname\relax
}
\def\pgfnodeifexists#1#2#3{%
\expandafter\ifx\csname pgf@sh@ns@#1\endcsname\relax#3\else#2\fi
}
|