summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex70
1 files changed, 62 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex b/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
index 090155e26d0..5f67167ad37 100644
--- a/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
+++ b/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
@@ -20,6 +20,8 @@
\newdimen\tikz@lasty
\newdimen\tikz@lastxsaved
\newdimen\tikz@lastysaved
+\newdimen\tikz@lastmovetox
+\newdimen\tikz@lastmovetoy
\newdimen\tikzleveldistance
\newdimen\tikzsiblingdistance
@@ -146,6 +148,42 @@
\expandafter\def\expandafter\tikz@dashpattern\expandafter{\tikz@dashpattern{#1}}%
\pgfutil@ifnextchar\@nil{\pgfutil@gobble}{\tikz@scandashon}}%
+% use a decoration to expand the `off' section of a dash pattern.
+% https://tex.stackexchange.com/a/133357
+\tikzset{
+ dash expand off/.code={%
+ \ifcsname tikz@library@decorations@loaded\endcsname\else
+ \tikzerror{You need \string\usetikzlibrary{decorations} for ``dash offexpand''}%
+ \fi
+ \tikz@addoption{%
+ \pgfgetpath\currentpath
+ \pgfprocessround{\currentpath}{\currentpath}%
+ \pgf@decorate@parsesoftpath{\currentpath}{\currentpath}%
+ % Parse \on and \off from the current path
+ \edef\on{\expandafter\pgfutil@firstoftwo\tikz@dashpattern}%
+ \edef\off{\expandafter\pgfutil@secondoftwo\tikz@dashpattern}%
+ % \dashphase = max(\on - \dashphase, 0)
+ \pgfmathsubtract@{\on}{\tikz@dashphase}%
+ \pgfmathmax@{\pgfmathresult}{0}%
+ \edef\dashphase{\the\dimexpr\pgfmathresult pt\relax}%
+ % \rest = \pgf@decorate@totalpathlength - \on
+ \edef\rest{\expandafter\pgf@sys@tonumber\dimexpr\pgf@decorate@totalpathlength - \on + 2\dimexpr\dashphase\relax\relax}%
+ % \onoff = \on + \off
+ \edef\onoff{\expandafter\pgf@sys@tonumber\dimexpr\on+\off\relax}%
+ % \nfullonoff = max(floor(\rest/\onoff), 1)
+ \pgfmathdivide@{\rest}{\onoff}%
+ \pgfmathfloor@{\pgfmathresult}%
+ \pgfmathmax@{\pgfmathresult}{1}%
+ % \offexpand = max(\rest/\nfullonoff - \on, \off)
+ \pgfmathdivide@{\rest}{\pgfmathresult}%
+ \pgfmathsubtract@{\pgfmathresult}{\on}%
+ \pgfmathmax@{\pgfmathresult}{\off}%
+ \edef\tikz@marshal{\noexpand\pgfsetdash{{\on}{\pgfmathresult}}{\dashphase}}%
+ \tikz@marshal
+ }%
+ }
+}
+
\tikzoption{draw opacity}{\tikz@addoption{\pgfsetstrokeopacity{#1}}}%
% Double draw options
@@ -1584,6 +1622,7 @@
% ID callbacks
\newif\iftikz@is@node
+\let\tikz@id@name\pgfutil@empty
\let\tikz@id@hook\pgfutil@empty
\def\tikz@call@id@hook{\ifx\tikz@id@hook\pgfutil@empty\else\tikz@id@hook\pgfuseid{\tikz@id@name}\fi}%
@@ -2673,24 +2712,38 @@
\def\tikz@moveto{%
\tikz@scan@one@point{\tikz@@moveto}}%
\def\tikz@@moveto#1{%
- \tikz@make@last@position{#1}%
+ \tikz@make@last@position{#1}%
\iftikz@shapeborder%
% ok, the moveto will have to wait. flag that we have a moveto in
% waiting:
\edef\tikz@moveto@waiting{\tikz@shapeborder@name}%
\else%
- \pgfpathmoveto{\tikz@last@position}%
+ \tikz@@movetosave{\tikz@last@position}%
\let\tikz@moveto@waiting=\relax%
\fi%
\tikz@scan@next@command%
}%
+ % Wrapper around \pgfpathmoveto that adds a save
+\def\tikz@@movetosave#1{%
+ {\pgftransformreset
+ \pgf@process{#1}%
+ \xdef\tikz@marshal{%
+ \tikz@lastmovetox=\the\pgf@x\relax%
+ \tikz@lastmovetoy=\the\pgf@y\relax%
+ }%
+ }%
+ \tikz@marshal
+ \pgfpathmoveto{#1}%
+}%
+
+
\let\tikz@moveto@waiting=\relax % normally, nothing is waiting...
\def\tikz@flush@moveto{%
\ifx\tikz@moveto@waiting\relax%
\else%
- \pgfpathmoveto{\tikz@last@position}%
+ \tikz@@movetosave{\tikz@last@position}%
\fi%
\let\tikz@moveto@waiting=\relax%
}%
@@ -2707,7 +2760,7 @@
#2=\pgf@x%
#3=\pgf@y%
\edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
- \pgfpathmoveto{\pgfqpoint{\pgf@x}{\pgf@y}}%
+ \tikz@@movetosave{\pgfqpoint{\pgf@x}{\pgf@y}}%
\fi%
\let\tikz@moveto@waiting=\relax%
}%
@@ -2954,7 +3007,8 @@
\tikz@make@last@position{\expandafter\pgfpoint\pgfsyssoftpath@lastmoveto}%
\tikz@path@close{\expandafter\pgfpoint\pgfsyssoftpath@lastmoveto}%
\def\pgfstrokehook{}%
- \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
+ \edef\tikz@timer@end{%\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
+ \noexpand\pgfqpoint{\the\tikz@lastmovetox}{\the\tikz@lastmovetoy}}%
\let\tikz@timer=\tikz@timer@line%
\let\tikz@tangent\tikz@timer@start%
\tikz@scan@next@command%
@@ -3226,7 +3280,7 @@
\else%
\pgf@process{\pgfpointshapeborder{\tikz@moveto@waiting}{\tikz@curve@first}}%
\edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
- \pgfpathmoveto{\pgfqpoint{\pgf@x}{\pgf@y}}%
+ \tikz@@movetosave{\pgfqpoint{\pgf@x}{\pgf@y}}%
\fi%
\let\tikz@timer@cont@one=\tikz@curve@first%
\let\tikz@timer@cont@two=\tikz@curve@second%
@@ -3271,7 +3325,7 @@
\tikz@make@last@position{#1}%
\edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
\let\tikz@timer=\tikz@timer@line%
- \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
+ \tikz@@movetosave{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
\tikz@path@lineto{\pgfqpoint{\pgf@xa}{\tikz@lasty}}%
\tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}%
\tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@ya}}%
@@ -3279,7 +3333,7 @@
\tikz@path@lineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
\fi%
\pgfpathclose%
- \pgfpathmoveto{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}%
+ \tikz@@movetosave{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}%
\def\pgfstrokehook{}%
\let\tikz@tangent\relax%
\tikz@scan@next@command%