| 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 |
|
| 13 |
% A marking decoration is used to add markings (which are just pgf |
| 14 |
% scopes, essentially) at certain positions of a path. |
| 15 |
|
| 16 |
\pgfkeys{ |
| 17 |
/pgf/decoration/reset marks/.code=\let\pgf@lib@dec@mark@marks\pgfutil@empty, |
| 18 |
/pgf/decoration/mark/.code=\pgf@lib@dec@parsemark#1\pgf@lib@dec@stop, |
| 19 |
}% |
| 20 |
|
| 21 |
\let\pgf@lib@dec@mark@marks=\pgfutil@empty |
| 22 |
|
| 23 |
\def\pgf@lib@dec@parsemark{\pgfutil@ifnextchar b{\pgf@lib@dec@parsebetween}{\pgf@lib@dec@parseat}}% |
| 24 |
\def\pgf@lib@dec@parseat at position#1with#2\pgf@lib@dec@stop{% |
| 25 |
\expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@lib@dec@mark@marks% |
| 26 |
\pgf@lib@dec@domark{#1}{#2}% |
| 27 |
}% |
| 28 |
}% |
| 29 |
\def\pgf@lib@dec@parsebetween between positions#1and#2step#3with#4\pgf@lib@dec@stop{% |
| 30 |
\expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@lib@dec@mark@marks% |
| 31 |
\pgf@lib@dec@dobetweenmark{#1}{#2}{#3}{#4}% |
| 32 |
}% |
| 33 |
}% |
| 34 |
|
| 35 |
\def\pgf@lib@dec@arrowhead#1#2{% |
| 36 |
\pgftransformxscale{#1} |
| 37 |
\pgfarrowdraw{#2}% |
| 38 |
}% |
| 39 |
|
| 40 |
\def\pgf@lib@dec@doarrowhead#1{% |
| 41 |
\pgf@lib@dec@arrowhead{1}{#1}% |
| 42 |
}% |
| 43 |
\def\pgf@lib@dec@doarrowheadrev#1{% |
| 44 |
\pgf@lib@dec@arrowhead{-1}{#1}% |
| 45 |
}% |
| 46 |
|
| 47 |
|
| 48 |
\pgfdeclaredecoration{markings}{init} |
| 49 |
{% |
| 50 |
\state{init} |
| 51 |
[ |
| 52 |
width=0pt, |
| 53 |
persistent precomputation={% |
| 54 |
\pgfkeys{/pgf/decoration/mark info/sequence number/.initial=0}% |
| 55 |
\pgfkeys{/pgf/decoration/mark info/distance from start/.initial=}% |
| 56 |
}, |
| 57 |
next state=pre |
| 58 |
] |
| 59 |
{}% |
| 60 |
|
| 61 |
\state{pre} |
| 62 |
[ |
| 63 |
width=0pt, |
| 64 |
persistent precomputation={% |
| 65 |
\def\pgf@lib@dec@computed@width{0pt}% |
| 66 |
\pgf@lib@dec@mark@marks\pgf@lib@dec@mark@last% |
| 67 |
\let\arrow=\pgf@lib@dec@doarrowhead% |
| 68 |
\let\arrowreversed=\pgf@lib@dec@doarrowheadrev% |
| 69 |
}, |
| 70 |
next state=skipper |
| 71 |
] |
| 72 |
{}% |
| 73 |
|
| 74 |
\state{skipper}[width=\pgf@lib@dec@computed@width-\pgfdecoratedcompleteddistance-1sp, |
| 75 |
next state=\pgf@lib@dec@next@state]{}% |
| 76 |
|
| 77 |
\state{main} |
| 78 |
[ |
| 79 |
width=1sp, |
| 80 |
next state=pre, |
| 81 |
persistent precomputation={% |
| 82 |
\pgfutil@tempcnta=\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}\relax% |
| 83 |
\advance\pgfutil@tempcnta by1\relax% |
| 84 |
\pgfkeys{/pgf/decoration/mark info/sequence number/.expanded=\the\pgfutil@tempcnta}% |
| 85 |
\pgfkeys{/pgf/decoration/mark info/distance from start/.expanded=\pgf@lib@dec@computed@width}% |
| 86 |
}% |
| 87 |
] |
| 88 |
{% |
| 89 |
\pgfinterruptpath% |
| 90 |
\pgfscope% |
| 91 |
\let\pgf@lib@dec@mark@marks=\pgfutil@empty% |
| 92 |
\pgfslopedattimefalse |
| 93 |
\pgf@lib@dec@computed@action% |
| 94 |
\endpgfscope% |
| 95 |
\endpgfinterruptpath% |
| 96 |
\ifx\pgf@lib@mark@node\pgfutil@empty% |
| 97 |
\else% |
| 98 |
\pgf@lib@mark@connect@node% |
| 99 |
\fi% |
| 100 |
}% |
| 101 |
|
| 102 |
\state{final}[width=\pgfdecoratedremainingdistance]{ |
| 103 |
\ifx\pgf@lib@mark@node\pgfutil@empty% |
| 104 |
\pgfpathmoveto{\pgfpointdecoratedpathlast} |
| 105 |
\else% |
| 106 |
\pgfpathlineto{\pgfpointdecoratedpathlast} |
| 107 |
\fi% |
| 108 |
}% |
| 109 |
}% |
| 110 |
|
| 111 |
\def\pgf@lib@dec@domark#1#2#3\pgf@lib@dec@mark@last{% |
| 112 |
\def\pgf@lib@dec@mark@marks{#3}% |
| 113 |
\pgf@lib@dec@parsenum{#1}% |
| 114 |
\def\pgf@lib@dec@computed@action{#2}% |
| 115 |
\def\pgf@lib@dec@next@state{main}% |
| 116 |
}% |
| 117 |
|
| 118 |
|
| 119 |
\def\pgf@lib@dec@dobetweenmark#1#2#3#4#5\pgf@lib@dec@mark@last{% |
| 120 |
\pgf@lib@dec@parsenum{#1}% |
| 121 |
\let\pgf@lib@dec@mark@start=\pgf@lib@dec@computed@width% |
| 122 |
\pgf@lib@dec@parsenum{#2}% |
| 123 |
\let\pgf@lib@dec@mark@end=\pgf@lib@dec@computed@width% |
| 124 |
\ifdim\pgf@lib@dec@mark@end<\pgf@lib@dec@mark@start\relax% |
| 125 |
% Skip! |
| 126 |
#5\pgf@lib@dec@mark@last% |
| 127 |
\else% |
| 128 |
% |
| 129 |
\pgf@lib@dec@parsenum{#3}% |
| 130 |
\pgfmathparse{\pgf@lib@dec@mark@start+\pgf@lib@dec@computed@width}% |
| 131 |
% Update entry in mark list |
| 132 |
\edef\pgf@temp{\noexpand\pgf@lib@dec@dobetweenmark{\pgfmathresult pt}{\pgf@lib@dec@mark@end}{\pgf@lib@dec@computed@width}}% |
| 133 |
\expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@temp{#4}#5}% |
| 134 |
\let\pgf@lib@dec@computed@width\pgf@lib@dec@mark@start% |
| 135 |
\def\pgf@lib@dec@computed@action{#4}% |
| 136 |
\def\pgf@lib@dec@next@state{main}% |
| 137 |
\fi% |
| 138 |
}% |
| 139 |
|
| 140 |
|
| 141 |
\def\pgf@lib@dec@parsenum#1{% |
| 142 |
\pgfmathparse{#1}% |
| 143 |
\ifpgfmathunitsdeclared% |
| 144 |
\ifdim\pgfmathresult pt<0pt\relax% |
| 145 |
\pgfmathparse{\pgfdecoratedpathlength\pgfmathresult pt}% |
| 146 |
\else% |
| 147 |
\pgfmathparse{\pgfmathresult pt}% |
| 148 |
\fi% |
| 149 |
\else% |
| 150 |
\ifdim\pgfmathresult pt<0pt\relax% |
| 151 |
\pgfmathparse{\pgfdecoratedpathlength\pgfmathresult*\pgfdecoratedpathlength}% |
| 152 |
\else% |
| 153 |
\pgfmathparse{\pgfmathresult*\pgfdecoratedpathlength}% |
| 154 |
\fi% |
| 155 |
\fi% |
| 156 |
\edef\pgf@lib@dec@computed@width{\pgfmathresult pt}% |
| 157 |
}% |
| 158 |
|
| 159 |
\def\pgf@lib@dec@mark@last{% |
| 160 |
\def\pgf@lib@dec@next@state{final}% |
| 161 |
}% |
| 162 |
|
| 163 |
|
| 164 |
% |
| 165 |
% If you set the mark connection node inside a mark picture, the |
| 166 |
% output path will contain a line to this node |
| 167 |
% |
| 168 |
|
| 169 |
\pgfkeys{/pgf/decoration/mark connection node/.store in=\pgf@lib@mark@node, |
| 170 |
/pgf/decoration/mark connection node=}% |
| 171 |
\def\pgf@lib@mark@connect@node{% |
| 172 |
% Line to "left" end of the node |
| 173 |
\pgfpathlineto{\pgfpointshapeborder{\pgf@lib@mark@node}{\pgfqpoint{-1pt}{0pt}}} |
| 174 |
% Move to "right" end of the node |
| 175 |
\pgfpathmoveto{\pgfpointshapeborder{\pgf@lib@mark@node}{\pgfqpoint{1pt}{0pt}}} |
| 176 |
}% |
| 177 |
|
| 178 |
|
| 179 |
\endinput |