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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\ProvidesFileRCS{pgfcorelayers.code.tex}
% Creates a new pgf layer
%
% #1 = layer name
%
% Declares a new layer for pgf.
%
% Example:
%
% \pgfdeclarelayer{background}
\def\pgfdeclarelayer#1{%
\pgfutil@ifundefined{pgf@layerbox@#1}{%
\expandafter\expandafter\csname pgf@newbox\endcsname\csname pgf@layerbox@#1\endcsname%
\expandafter\expandafter\csname pgf@newbox\endcsname\csname pgf@layerboxsaved@#1\endcsname%
}{}%
}
\let\pgf@newbox=\newbox % avoid plain TeX outer problem
% Sets the layers that compose the picture
%
% #1 = List of layers
%
% Description:
%
% Sets the list of layers that make up the picture. The layers will be
% put on top of each other in the order given.
%
% This command can also be given inside of a picture in which case it
% applies only to that very picture.
%
% Example:
%
% \pgfsetlayers{background,main}
\def\pgfsetlayers#1{%
\let\pgf@layerlist\pgfutil@empty%
\pgf@dosetlayer#1,,\relax%
}
\def\pgf@dosetlayer#1,#2,\relax{%
\ifx\pgf@layerlist\pgfutil@empty%
\edef\pgf@layerlist{\pgfutil@trimspaces{#1}}%
\else
\edef\pgf@layerlist{\pgf@layerlist,\pgfutil@trimspaces{#1}}%
\fi
\def\pgf@test{#2}%
\ifx\pgf@test\pgfutil@empty%
\else%
\pgf@dosetlayer#2,\relax%
\fi%
}
\pgfsetlayers{main}
% Adds code to a layer
%
% #1 = layer name
%
% Note:
%
% You cannot add anything to the ``main'' layer using this command.
%
% Example:
%
% \begin{pgfonlayer}{background}
% \fill[red] (0,0) -- (1,1);
% \end{pgfonlayer}
\def\pgfonlayer@name{main}
\def\pgfonlayer#1{%
\pgfutil@ifundefined{pgf@layerbox@#1}{%
\pgferror{Sorry, the requested layer '#1' could not be found. Maybe you misspelled it?}%
\bgroup
\begingroup
}{%
\begingroup
\edef\pgf@temp{#1}%
\ifx\pgf@temp\pgfonlayer@name
% we are already on this layer.
\def\pgf@temp{%
\bgroup
\begingroup
}%
\else
\let\pgfonlayer@name=\pgf@temp
\pgfonlayer@assert@is@active
\def\pgf@temp{%
\expandafter\global\expandafter%
\setbox\csname pgf@layerbox@#1\endcsname=\hbox to 0pt%
\bgroup%
\expandafter\box\csname pgf@layerbox@#1\endcsname%
\begingroup%
}%
\fi
\pgfsetlinewidth{0.4pt}% always reset the line width
\pgf@temp
}%
}
\def\endpgfonlayer{%
\endgroup%
\hss
\egroup%
\endgroup
}
\let\startpgfonlayer=\pgfonlayer
\let\stoppgfonlayer=\endpgfonlayer
\def\pgfdiscardlayername{discard}
\def\pgfonlayer@assert@is@active{%
\ifx\pgfonlayer@name\pgfdiscardlayername
% this special layer name can be used as /dev/null without
% warning.
\else
\begingroup
\def\pgfonlayer@isactive{0}%
\expandafter\pgf@assert@layer@is@active@loop\pgf@layerlist,,\relax%
\if0\pgfonlayer@isactive
\pgfonlayer@assert@fail
\fi
\endgroup
\fi
}%
\def\pgfonlayer@assert@fail{%
\pgferror{Sorry, the requested layer '\pgfonlayer@name' is not
part of the layer list. Please verify that you provided
\string\pgfsetlayers\space and that '\pgfonlayer@name' is part of this list}%
}%
\def\pgf@assert@layer@is@active@loop#1,#2,\relax{%
\edef\pgf@test{#1}%
\ifx\pgf@test\pgfonlayer@name
\def\pgfonlayer@isactive{1}%
\else
\def\pgf@test{#2}%
\ifx\pgf@test\pgfutil@empty%
\else%
\pgf@assert@layer@is@active@loop#2,\relax%
\fi%
\fi
}
% Hooks into the scoping:
\def\pgf@insertlayers{%
\expandafter\pgf@dolayer\pgf@layerlist,,\relax%
}
\def\pgf@maintext{main}%
\def\pgf@dolayer#1,#2,\relax{%
\def\pgf@test{#1}%
\ifx\pgf@test\pgf@maintext%
\box\pgf@layerbox@main%
\else%
\pgfsys@beginscope%
\expandafter\box\csname pgf@layerbox@#1\endcsname%
\pgfsys@endscope%
\fi%
\def\pgf@test{#2}%
\ifx\pgf@test\pgfutil@empty%
\else%
\pgf@dolayer#2,\relax%
\fi%
}
\def\pgf@savelayers{%
\expandafter\pgf@dosavelayer\pgf@layerlist,,\relax%
}
\def\pgf@dosavelayer#1,#2,\relax{%
\def\pgf@test{#1}%
\ifx\pgf@test\pgf@maintext%
\else%
\setbox\csname pgf@layerboxsaved@#1\endcsname=\box\csname pgf@layerbox@#1\endcsname%
\fi%
\def\pgf@test{#2}%
\ifx\pgf@test\pgfutil@empty%
\else%
\pgf@dosavelayer#2,\relax%
\fi%
}
\def\pgf@restorelayers{%
\expandafter\pgf@dorestorelayer\pgf@layerlist,,\relax%
}
\def\pgf@dorestorelayer#1,#2,\relax{%
\def\pgf@test{#1}%
\ifx\pgf@test\pgf@maintext%
\else%
\global\setbox\csname pgf@layerbox@#1\endcsname=\box\csname pgf@layerboxsaved@#1\endcsname%
\fi%
\def\pgf@test{#2}%
\ifx\pgf@test\pgfutil@empty%
\else%
\pgf@dorestorelayer#2,\relax%
\fi%
}
\endinput
|