summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/libraries/decorations/pgflibrarydecorations.markings.code.tex
blob: 546301c4d072b100c66135472f7cf69e54a63de4 (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
% Copyright 2008 by Mark Wibrow
%
% 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}


% A marking decoration is used to add markings (which are just pgf
% scopes, essentially) at certain positions of a path.

\pgfkeys{
  /pgf/decoration/reset marks/.code=\let\pgf@lib@dec@mark@marks\pgfutil@empty,
  /pgf/decoration/mark/.code=\pgf@lib@dec@parsemark#1\pgf@lib@dec@stop,
}

\let\pgf@lib@dec@mark@marks=\pgfutil@empty

\def\pgf@lib@dec@parsemark{\pgfutil@ifnextchar b{\pgf@lib@dec@parsebetween}{\pgf@lib@dec@parseat}}
\def\pgf@lib@dec@parseat at position#1with#2\pgf@lib@dec@stop{%
  \expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@lib@dec@mark@marks%
    \pgf@lib@dec@domark{#1}{#2}%
  }%
}
\def\pgf@lib@dec@parsebetween between positions#1and#2step#3with#4\pgf@lib@dec@stop{%
  \expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@lib@dec@mark@marks%
    \pgf@lib@dec@dobetweenmark{#1}{#2}{#3}{#4}%
  }%
}

\def\pgf@lib@dec@arrowhead#1#2{%
  \pgftransformxscale{#1}
  \pgfarrowdraw{#2}%
}

\def\pgf@lib@dec@doarrowhead#1{%
  \pgf@lib@dec@arrowhead{1}{#1}%
}
\def\pgf@lib@dec@doarrowheadrev#1{%
  \pgf@lib@dec@arrowhead{-1}{#1}%
}


\pgfdeclaredecoration{markings}{init}
{
  \state{init}
  [
    width=0pt,
    persistent precomputation={%
      \pgfkeys{/pgf/decoration/mark info/sequence number/.initial=0}%
      \pgfkeys{/pgf/decoration/mark info/distance from start/.initial=}%
    },
    next state=pre
  ]
  {}
  
  \state{pre}
  [
    width=0pt,
    persistent precomputation={%
      \def\pgf@lib@dec@computed@width{0pt}%
      \pgf@lib@dec@mark@marks\pgf@lib@dec@mark@last%
      \let\arrow=\pgf@lib@dec@doarrowhead%
      \let\arrowreversed=\pgf@lib@dec@doarrowheadrev%
    },
    next state=skipper
  ]
  {}

  \state{skipper}[width=\pgf@lib@dec@computed@width-\pgfdecoratedcompleteddistance-1sp,
                  next state=\pgf@lib@dec@next@state]{}
  
  \state{main}
  [
    width=1sp,
    next state=pre,
    persistent precomputation={%
      \pgfutil@tempcnta=\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}\relax%
      \advance\pgfutil@tempcnta by1\relax%
      \pgfkeys{/pgf/decoration/mark info/sequence number/.expanded=\the\pgfutil@tempcnta}%
      \pgfkeys{/pgf/decoration/mark info/distance from start/.expanded=\pgf@lib@dec@computed@width}%
    }%
  ]
  {%
    \pgfinterruptpath%
      \pgfscope%
        \let\pgf@lib@dec@mark@marks=\pgfutil@empty%
        \pgf@lib@dec@computed@action%
      \endpgfscope%
    \endpgfinterruptpath%
    \ifx\pgf@lib@mark@node\pgfutil@empty%
    \else%
      \pgf@lib@mark@connect@node%
    \fi%
  }%

  \state{final}[width=\pgfdecoratedremainingdistance]{
    \ifx\pgf@lib@mark@node\pgfutil@empty%
      \pgfpathmoveto{\pgfpointdecoratedpathlast}
    \else%
      \pgfpathlineto{\pgfpointdecoratedpathlast}
    \fi%
  }
}

\def\pgf@lib@dec@domark#1#2#3\pgf@lib@dec@mark@last{%
  \def\pgf@lib@dec@mark@marks{#3}%
  \pgf@lib@dec@parsenum{#1}%
  \def\pgf@lib@dec@computed@action{#2}%
  \def\pgf@lib@dec@next@state{main}%
}


\def\pgf@lib@dec@dobetweenmark#1#2#3#4#5\pgf@lib@dec@mark@last{%
  \pgf@lib@dec@parsenum{#1}%
  \let\pgf@lib@dec@mark@start=\pgf@lib@dec@computed@width%
  \pgf@lib@dec@parsenum{#2}%
  \let\pgf@lib@dec@mark@end=\pgf@lib@dec@computed@width%
  \ifdim\pgf@lib@dec@mark@end<\pgf@lib@dec@mark@start\relax%
    % Skip!
    #5\pgf@lib@dec@mark@last%
  \else%
    % 
    \pgf@lib@dec@parsenum{#3}%
    \pgfmathparse{\pgf@lib@dec@mark@start+\pgf@lib@dec@computed@width}%
    % Update entry in mark list
    \edef\pgf@temp{\noexpand\pgf@lib@dec@dobetweenmark{\pgfmathresult pt}{\pgf@lib@dec@mark@end}{\pgf@lib@dec@computed@width}}%
    \expandafter\def\expandafter\pgf@lib@dec@mark@marks\expandafter{\pgf@temp{#4}#5}%
    \let\pgf@lib@dec@computed@width\pgf@lib@dec@mark@start%
    \def\pgf@lib@dec@computed@action{#4}%
    \def\pgf@lib@dec@next@state{main}%
  \fi%
}


\def\pgf@lib@dec@parsenum#1{%
  \pgfmathparse{#1}%
  \ifpgfmathunitsdeclared%
    \ifdim\pgfmathresult pt<0pt\relax%
      \pgfmathparse{\pgfdecoratedpathlength\pgfmathresult pt}%
    \else%
      \pgfmathparse{\pgfmathresult pt}%
    \fi%
  \else%  
    \ifdim\pgfmathresult pt<0pt\relax%
      \pgfmathparse{\pgfdecoratedpathlength\pgfmathresult*\pgfdecoratedpathlength}%
    \else%
      \pgfmathparse{\pgfmathresult*\pgfdecoratedpathlength}%
    \fi%
  \fi%
  \edef\pgf@lib@dec@computed@width{\pgfmathresult pt}%  
}

\def\pgf@lib@dec@mark@last{%
  \def\pgf@lib@dec@next@state{final}%
}


%
% If you set the mark connection node inside a mark picture, the
% output path will contain a line to this node  
%

\pgfkeys{/pgf/decoration/mark connection node/.store in=\pgf@lib@mark@node,
  /pgf/decoration/mark connection node=}
\def\pgf@lib@mark@connect@node{%
  % Line to "left" end of the node
  \pgfpathlineto{\pgfpointshapeborder{\pgf@lib@mark@node}{\pgfqpoint{-1pt}{0pt}}}
  % Move to "right" end of the node
  \pgfpathmoveto{\pgfpointshapeborder{\pgf@lib@mark@node}{\pgfqpoint{1pt}{0pt}}}
}%


\endinput