| 1 |
% Copyright 2018 by Mark Wibrow |
| 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 |
\usepgfmodule{decorations}% |
| 11 |
|
| 12 |
% Define the basic decoration stuff for tikz. Load more libraries to |
| 13 |
% "actually use" decorations |
| 14 |
|
| 15 |
\tikzset{decorate/.is if=tikz@decoratepath, |
| 16 |
/pgf/decoration/name/.store in=\tikz@decoration@name, |
| 17 |
/pgf/decoration/.unknown/.code={% |
| 18 |
\pgfifdecoration{\pgfkeyscurrentname} |
| 19 |
{\edef\tikz@decoration@name{\pgfkeyscurrentname}} |
| 20 |
{\pgfifmetadecoration{\pgfkeyscurrentname} |
| 21 |
{\edef\tikz@decoration@name{\pgfkeyscurrentname}} |
| 22 |
% expand \pgfkeyscurrentname _before_ it's updated by nested \pgfkeys |
| 23 |
{\pgfutil@expanded{\noexpand\pgfkeys{/errors/unknown key= |
| 24 |
{/pgf/decoration/\pgfkeyscurrentname}{\pgfutil@unexpanded{#1}}}}}}% |
| 25 |
}, |
| 26 |
/pgf/decoration/raise/.code={\def\tikz@dec@shift{\pgftransformyshift{#1}}\tikz@dec@trans}, |
| 27 |
/pgf/decoration/mirror/.code={% |
| 28 |
\csname if#1\endcsname |
| 29 |
\def\tikz@dec@mirror{\pgftransformyscale{-1}}% |
| 30 |
\else% |
| 31 |
\let\tikz@dec@mirror=\relax% |
| 32 |
\fi% |
| 33 |
\tikz@dec@trans% |
| 34 |
}, |
| 35 |
/pgf/decoration/mirror/.default=true, |
| 36 |
/pgf/decoration/transform/.code={% |
| 37 |
{% |
| 38 |
\pgftransformreset% |
| 39 |
\def\tikz@transform{}% |
| 40 |
\pgfkeysalso{/tikz/.cd, #1}% |
| 41 |
\expandafter\gdef\expandafter\tikz@g@temptransform\expandafter{\tikz@transform}% |
| 42 |
}% |
| 43 |
\let\tikz@dec@user@transform=\tikz@g@temptransform% |
| 44 |
\tikz@dec@trans% |
| 45 |
},% |
| 46 |
/pgf/decoration/pre/.initial=lineto, |
| 47 |
/pgf/decoration/post/.initial=lineto, |
| 48 |
/pgf/decoration/pre length/.initial=0pt, |
| 49 |
/pgf/decoration/post length/.initial=0pt, |
| 50 |
}% |
| 51 |
|
| 52 |
\let\tikz@decoration@name=\tikz@nonetext |
| 53 |
|
| 54 |
\def\tikz@dec@trans{\pgfsetdecorationsegmenttransformation{\tikz@dec@user@transform\tikz@dec@mirror\tikz@dec@shift}}% |
| 55 |
\let\tikz@dec@user@transform=\relax |
| 56 |
\let\tikz@dec@shift=\relax |
| 57 |
\let\tikz@dec@mirror=\relax |
| 58 |
|
| 59 |
\pgfdeclaremetadecoration{tikz@internal}{pre}{% |
| 60 |
\state{pre}[width=\pgfkeysvalueof{/pgf/decoration/pre length}, next state=main] |
| 61 |
{ |
| 62 |
\tikz@dec@trans |
| 63 |
\decoration{\pgfkeysvalueof{/pgf/decoration/pre}} |
| 64 |
}% |
| 65 |
\state{main}[width=\pgfmetadecoratedremainingdistance-\pgfkeysvalueof{/pgf/decoration/post length}, next state=final] |
| 66 |
{ |
| 67 |
\tikz@dec@trans |
| 68 |
\decoration{\tikz@decoration@name} |
| 69 |
}% |
| 70 |
\state{final} |
| 71 |
{ |
| 72 |
\tikz@dec@trans |
| 73 |
\decoration{\pgfkeysvalueof{/pgf/decoration/post}} |
| 74 |
}% |
| 75 |
}% |
| 76 |
|
| 77 |
|
| 78 |
\newif\iftikz@metadecoration |
| 79 |
|
| 80 |
\def\tikz@lib@dec@addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}% |
| 81 |
|
| 82 |
\def\tikz@lib@decoration[#1]{% |
| 83 |
\begingroup% |
| 84 |
% Just to be on the save side... |
| 85 |
% |
| 86 |
% Now, let's parse the options: |
| 87 |
\tikzset{#1}% |
| 88 |
% |
| 89 |
\ifx\tikz@decoration@name\tikz@nonetext% |
| 90 |
% Ok, let's forget about this decoration stuff... |
| 91 |
\else |
| 92 |
\expandafter\tikz@lib@do@dec% |
| 93 |
\fi% |
| 94 |
% Now, we expect a brace. |
| 95 |
\pgfutil@ifnextchar\bgroup{% |
| 96 |
\begingroup% |
| 97 |
\tikz@auto@end@pathfalse% |
| 98 |
\aftergroup\tikz@enddecoration% |
| 99 |
\afterassignment\tikz@scan@next@command% |
| 100 |
\let\tikz@lib@next% gobble \bgroup% |
| 101 |
}% |
| 102 |
{% |
| 103 |
\tikzerror{A decoration must begin with a brace}% |
| 104 |
\tikz@enddecoration% |
| 105 |
}% |
| 106 |
}% |
| 107 |
\def\tikz@lib@do@dec{% |
| 108 |
% Ok, now what? |
| 109 |
\pgfifmetadecoration{\tikz@decoration@name}% |
| 110 |
{\expandafter\pgfmetadecoration\expandafter{\tikz@decoration@name}}% |
| 111 |
{% |
| 112 |
\pgfifdecoration{\tikz@decoration@name}% |
| 113 |
{\tikz@lib@dec@startdecoration}% |
| 114 |
{\tikzerror{Unknown (meta-)decoration '\tikz@decoration@name'. Perhaps you |
| 115 |
misspelled it?}}% |
| 116 |
}% |
| 117 |
\ifx\pgfdecorateexistingpath\pgfutil@empty% |
| 118 |
\pgfpathmoveto{\pgfqpoint{\the\tikz@lastxsaved}{\the\tikz@lastysaved}}% |
| 119 |
\fi% |
| 120 |
}% |
| 121 |
\newbox\tikz@lib@dec@box |
| 122 |
\def\tikz@enddecoration{% |
| 123 |
\global\setbox\tikz@lib@dec@box=\box\tikz@tempbox% |
| 124 |
\ifx\tikz@decoration@name\tikz@nonetext% |
| 125 |
% ignore this. |
| 126 |
\else |
| 127 |
% Ok, now what? |
| 128 |
\iftikz@metadecoration% |
| 129 |
\endpgfmetadecoration% |
| 130 |
\else% |
| 131 |
\tikz@lib@dec@stopdecoration% |
| 132 |
\fi% |
| 133 |
\fi |
| 134 |
\endgroup% |
| 135 |
\setbox\tikz@tempbox=\box\tikz@lib@dec@box% |
| 136 |
}% |
| 137 |
|
| 138 |
|
| 139 |
\def\tikz@lib@dec@decorate@path{% |
| 140 |
\ifx\tikz@decoration@name\tikz@nonetext% |
| 141 |
\else% |
| 142 |
\pgfgetpath\tikz@lib@dec@currentpath% |
| 143 |
\pgfsetpath\pgfutil@empty% |
| 144 |
\pgfifmetadecoration{\tikz@decoration@name} |
| 145 |
{ |
| 146 |
\expandafter\pgfmetadecoration\expandafter{\tikz@decoration@name}% |
| 147 |
\pgfsetpath\tikz@lib@dec@currentpath% |
| 148 |
\endpgfmetadecoration% |
| 149 |
} |
| 150 |
{ |
| 151 |
\pgfifdecoration{\tikz@decoration@name} |
| 152 |
{ |
| 153 |
\tikz@lib@dec@startdecoration% |
| 154 |
\pgfsetpath\tikz@lib@dec@currentpath% |
| 155 |
\tikz@lib@dec@stopdecoration% |
| 156 |
} |
| 157 |
{ |
| 158 |
\tikzerror{Unknown (meta-)decoration '\tikz@decoration@name'. Perhaps |
| 159 |
you misspelled it?} |
| 160 |
} |
| 161 |
} |
| 162 |
\fi% |
| 163 |
}% |
| 164 |
|
| 165 |
\def\tikz@lib@dec@zpttext{0pt}% |
| 166 |
|
| 167 |
\newif\iftikz@lib@dec@temp |
| 168 |
\def\tikz@lib@dec@startdecoration{% |
| 169 |
\pgfkeysgetvalue{/pgf/decoration/pre length}{\tikz@lib@pre}% |
| 170 |
\pgfkeysgetvalue{/pgf/decoration/post length}{\tikz@lib@post}% |
| 171 |
\tikz@lib@dec@tempfalse% |
| 172 |
\ifx\tikz@lib@pre\tikz@lib@dec@zpttext% |
| 173 |
\ifx\tikz@lib@post\tikz@lib@dec@zpttext% |
| 174 |
\else% |
| 175 |
\tikz@lib@dec@temptrue% |
| 176 |
\fi% |
| 177 |
\else% |
| 178 |
\tikz@lib@dec@temptrue% |
| 179 |
\fi% |
| 180 |
\iftikz@lib@dec@temp% |
| 181 |
\pgfmetadecoration{tikz@internal}% |
| 182 |
\else% |
| 183 |
\expandafter\pgfdecoration\expandafter{\expandafter{\tikz@decoration@name}{\pgfdecoratedpathlength}{}{}}% |
| 184 |
\fi% |
| 185 |
}% |
| 186 |
|
| 187 |
\def\tikz@lib@dec@stopdecoration{% |
| 188 |
\iftikz@lib@dec@temp% |
| 189 |
\endpgfmetadecoration% |
| 190 |
\else% |
| 191 |
\endpgfdecoration% |
| 192 |
\fi% |
| 193 |
}% |
| 194 |
|
| 195 |
|
| 196 |
\endinput |