summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/pgflibrarydecorations.pathreplacing.code.tex
blob: f028ec6c375a50a4ef1f11e26425187ea851cb79 (plain)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
% Copyright 2018 by Mark Wibrow and 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.

\usepgfmodule{decorations}%


%
% Path replacing decorations
%
% These decorations change the path by replacing it by another path.
% For instance, a line in the path might be replaced by small
% ticks or unconnected curves or crosses. Applying a chopping
% decoration to a path means that the path can no longer be used for
% filling in the original manner.
%



%
%
% Kind 1: Path chopping with open subpaths
%
%


% ticks decoration
%
% Parameters: \pgfdecorationsegmentlength, \pgfdecorationsegmentamplitude

\pgfdeclaredecoration{ticks}{ticks}
{%
  \state{ticks}[width=+\pgfdecorationsegmentlength]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfdecorationsegmentamplitude}}
  }%
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfdecorationsegmentamplitude}}
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }%
}%



% expanding waves decoration
%
% Parameters: \pgfdecorationsegmentangle, \pgfdecorationsegmentlength

\pgfdeclaredecoration{expanding waves}{initial}
{%
  \state{initial}[width=+\pgfdecorationsegmentlength,next state=wave]
  {}%

  \state{wave}[switch if less than=+\pgfdecorationsegmentlength to last,
               width=+\pgfdecorationsegmentlength]
  {
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfdecoratedcompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfdecorationsegmentangle}{+\pgfdecoratedcompleteddistance}}}%
    \pgfpatharc{\pgfdecorationsegmentangle}{-\pgfdecorationsegmentangle}{+\pgfdecoratedcompleteddistance}%
  }%
  \state{last}[width=+0pt,next state=final]
  {
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfdecoratedcompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfdecorationsegmentangle}{+\pgfdecoratedcompleteddistance}}}%
    \pgfpatharc{\pgfdecorationsegmentangle}{-\pgfdecorationsegmentangle}{+\pgfdecoratedcompleteddistance}%
  }%
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }%
}%



% waves decoration

\pgfdeclaredecoration{waves}{wave}
{%
  \state{wave}[width=\pgfdecorationsegmentlength]
  {
    \pgftransformxshift{+\pgfdecorationsegmentlength}
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfkeysvalueof{/pgf/decoration/start radius}}{0pt}}%
      {\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}}}%
    \pgfpatharc{\pgfdecorationsegmentangle}{-\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}%
  }%
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }%
}%



% border decoration
%
% Parameters: \pgfdecorationsegmentlength, \pgfdecorationsegmentamplitude, \pgfdecorationsegmentangle

\pgfdeclaredecoration{border}{tick}
{%
  \state{tick}[switch if less than=+\pgfdecorationsegmentlength to last,
               width=+\pgfdecorationsegmentlength]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpointpolar{\pgfdecorationsegmentangle}{+\pgfdecorationsegmentamplitude}}
  }%
  \state{last}[width=+\pgfdecorationsegmentamplitude,next state=final]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpointpolar{\pgfdecorationsegmentangle}{+\pgfdecorationsegmentamplitude}}
  }%
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }%
}%






% brace decorations
%
% Parameters: \pgfdecorationsegmentamplitude

\pgfdeclaredecoration{brace}{brace}
{%
  \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
  {
    \pgf@yc=\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance
    \ifdim2\pgfdecorationsegmentamplitude>\pgf@yc
      \pgf@yc=0.5\pgf@yc
    \else
      \pgf@yc=\pgfdecorationsegmentamplitude
    \fi
    \pgf@xc=\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance
    \advance\pgf@xc-\pgfdecoratedremainingdistance
    \ifdim-2\pgfdecorationsegmentamplitude<\pgf@xc
      \pgf@xc=-0.5\pgf@xc
    \else
      \pgf@xc=\pgfdecorationsegmentamplitude
    \fi
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathcurveto
    {\pgfqpoint{.15\pgf@yc}{.3\pgfdecorationsegmentamplitude}}
    {\pgfqpoint{.5\pgf@yc}{.5\pgfdecorationsegmentamplitude}}
    {\pgfqpoint{\pgf@yc}{.5\pgfdecorationsegmentamplitude}}
    {
      \pgftransformxshift{+\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance}
      \pgfpathlineto{\pgfqpoint{-\pgf@yc}{.5\pgfdecorationsegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{-.5\pgf@yc}{.5\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{-.15\pgf@yc}{.7\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{0\pgf@yc}{1\pgfdecorationsegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{.15\pgf@xc}{.7\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{.5\pgf@xc}{.5\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{\pgf@xc}{.5\pgfdecorationsegmentamplitude}}
    }
    {
      \pgftransformxshift{+\pgfdecoratedremainingdistance}
      \pgfpathlineto{\pgfqpoint{-\pgf@xc}{.5\pgfdecorationsegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{-.5\pgf@xc}{.5\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{-.15\pgf@xc}{.3\pgfdecorationsegmentamplitude}}
      {\pgfqpoint{0pt}{0pt}}
    }
  }%
  \state{final}
  {}%
}%




% show path construction decoration
%
\pgfdeclaredecoration{show path construction}{check for moveto}{%
    \state{check for moveto}[width=0pt, next state=segment,
      persistent precomputation={%
        \begingroup%
            \pgf@lib@decoraions@installinputsegmentpoints%
              \ifx\pgfdecorationpreviousinputsegment\pgfdecorationinputsegmentmoveto%
                  \pgfdecoratedinputsegmentmovetocode%
              \fi%
            \endgroup%
        }]{}%
    \state{segment}[width=\pgfdecoratedinputsegmentremainingdistance, next state=check for moveto,
      persistent precomputation={%
        \begingroup%
            \pgf@lib@decoraions@installinputsegmentpoints%
                \csname pgfdecoratedinputsegment\pgfdecorationcurrentinputsegment code\endcsname%
            \endgroup%
        }]{}%
    \state{final}{%
        \egroup%
        \begingroup%
        \pgf@lib@decoraions@installinputsegmentpoints%
            \csname pgfdecoratedinputsegment\pgfdecorationcurrentinputsegment code\endcsname%
        \endgroup%
        \bgroup%
    }%
}%

\pgfkeys{
    /pgf/decoration/.cd,
        moveto code/.code=\def\pgfdecoratedinputsegmentmovetocode{#1},
        lineto code/.code=\def\pgfdecoratedinputsegmentlinetocode{#1},
        curveto code/.code=\def\pgfdecoratedinputsegmentcurvetocode{#1},
      closepath code/.code=\def\pgfdecoratedinputsegmentclosepathcode{#1}
}%

\let\pgfdecoratedinputsegmentmovetocode\pgfutil@empty%
\let\pgfdecoratedinputsegmentlinetocode\pgfutil@empty%
\let\pgfdecoratedinputsegmentcurvetocode\pgfutil@empty%
\let\pgfdecoratedinputsegmentclosepathcode\pgfutil@empty%

\def\pgf@lib@decoraions@installinputsegmentpoints{%
    \let\pgfpointdecoratedinputsegmentfirst\pgf@decorate@inputsegment@first%
    \let\pgfpointdecoratedinputsegmentlast\pgf@decorate@inputsegment@last%
    \let\pgfpointdecoratedinputsegmentsupporta\pgf@decorate@inputsegment@supporta%
    \let\pgfpointdecoratedinputsegmentsupportb\pgf@decorate@inputsegment@supportb%
}%


\endinput