From acab24042d34dd439e1d074820d1da2fa1d591cd Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Thu, 4 Apr 2019 20:55:44 +0000
Subject: pgf (4apr19)

git-svn-id: svn://tug.org/texlive/trunk@50758 c570f23f-e606-0410-a88d-b1316a301751
---
 .../generic/pgf/basiclayer/pgfcoreshade.code.tex   | 173 +++++++++++++--------
 1 file changed, 110 insertions(+), 63 deletions(-)

(limited to 'Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex')

diff --git a/Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex b/Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex
index 971752304a7..93079024f6e 100644
--- a/Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex
+++ b/Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex
@@ -157,6 +157,12 @@
 
 
 
+\newcount\pgf@shadingcount
+\pgf@shadingcount=0
+{
+  \catcode`\%=12
+  \gdef\pgf@shadingnum{%\the\pgf@shadingcount%}
+}
 
 % Declares a horizontal shading for later use. The shading is a
 % horizontal bar that changes its color.
@@ -196,8 +202,11 @@
 \def\pgf@declarehorizontalshading[#1]#2#3#4{%
   \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
   \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty%
+    \expandafter\let\csname pgf@num@pgfshading#2!\endcsname\pgfutil@empty
     \pgfsys@horishading{#2}{#3}{#4}%
   \else%
+    \global\advance\pgf@shadingcount 1\relax
+    \expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}%
     \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@horishading}%
     \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
     \expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty%
@@ -226,8 +235,11 @@
 \def\pgf@declareverticalshading[#1]#2#3#4{%
   \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
   \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty%
+    \expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty
     \pgfsys@vertshading{#2}{#3}{#4}%
   \else%
+    \global\advance\pgf@shadingcount 1\relax
+    \expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}%
     \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@vertshading}%
     \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
     \expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty%
@@ -269,8 +281,11 @@
 \def\pgf@declareradialshading[#1]#2#3#4{%
   \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
   \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty%
+    \expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty
     \pgfsys@radialshading{#2}{#3}{#4}%
   \else%
+    \global\advance\pgf@shadingcount 1\relax
+    \expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}%
     \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@radialshading}%
     \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
     \expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty%
@@ -317,7 +332,7 @@
 % evaluated for each pixel independently.
 %
 % Because of the rather difficult PostScript syntax, use this macro
-% only *if you know what you are doing* (or if you are advanterous, of
+% only *if you know what you are doing* (or if you are adventurous, of
 % course).
 %
 % As for other shadings, the optional dependencies argument is used to
@@ -376,17 +391,21 @@
 \def\pgf@declarefunctionalshading[#1]#2#3#4#5#6{%
   \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
   \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty%
+    \expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty
     \pgfshade@functionaldo{#2}{#3}{#4}{#5}{#6}%
   \else%
+    \global\advance\pgf@shadingcount 1\relax
+    \expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}%
     \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfshade@functionaldo}%
     \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}{#5}{#6}}%
     \expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty%
   \fi}
 \def\pgfshade@functionaldo#1#2#3#4#5{%
-  {%
+  \begingroup
     #4%
     \pgfsys@functionalshading{#1}{#2}{#3}{#5}%
-  }%
+    \expandafter\pgfmath@smuggleone\csname @pgfshading#1!\endcsname
+  \endgroup
 }
 
 \def\pgfshadecolortorgb#1#2{%
@@ -426,38 +445,38 @@
   \expandafter\pgfutil@ifundefined\expandafter{\pgf@shadingname}%
   {\pgferror{Undefined shading "#1"}}%
   {%
+    \edef\pgf@shade@adds{\csname pgf@num\pgf@shadingname\endcsname}%
+    \pgfutil@ifundefined{pgf@deps\pgf@shadingname}%
+    {}%
     {%
-      \pgfutil@globalcolorsfalse%
-      \def\pgf@shade@adds{}%
-      \pgfutil@ifundefined{pgf@deps\pgf@shadingname}%
-      {}%
-      {%
+      \begingroup
+        \pgfutil@globalcolorsfalse
         \edef\@list{\csname pgf@deps\pgf@shadingname\endcsname}%
         \pgfutil@for\@temp:=\@list\do{%
-          {%
-            \pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{\@temp}}%
-            \pgfutil@extractcolorspec{\@temp}{\pgf@tempcolor}%
-            \expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}%
-            \xdef\pgf@shade@adds{\pgf@shade@adds,\pgf@rgbcolor}%
-          }%
+          \pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{\@temp}}%
+          \pgfutil@extractcolorspec{\@temp}{\pgf@tempcolor}%
+          \expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}%
+          \edef\pgf@shade@adds{\pgf@shade@adds,\pgf@rgbcolor}%
         }%
-      }%
-      \expandafter\pgf@strip@shadename\pgf@shadingname!!%
-      \pgfutil@ifundefined{@pgfshading\pgf@basename\pgf@shade@adds!}%
-      {%
-        {%
-          \expandafter\def\expandafter\@temp\expandafter{\csname pgf@func\pgf@shadingname\endcsname}%
-          \edef\@args{{\pgf@basename\pgf@shade@adds}}%
-          \expandafter\expandafter\expandafter\def%
-          \expandafter\expandafter\expandafter\@@args%
-          \expandafter\expandafter\expandafter{\csname pgf@args\pgf@shadingname\endcsname}%
-          \expandafter\expandafter\expandafter\@temp\expandafter\@args\@@args%
-          %
-        }%
-      }%
-      {}%
-      \pgf@invokeshading{\csname @pgfshading\pgf@basename\pgf@shade@adds!\endcsname}%
+        \pgfmath@smuggleone\pgf@shade@adds
+      \endgroup
+    }%
+    \expandafter\pgf@strip@shadename\pgf@shadingname!!%
+    \edef\pgf@shadingxname{@pgfshading\pgf@basename\pgf@shade@adds!}%
+    \pgfutil@ifundefined{\pgf@shadingxname}%
+    {%
+      \begingroup
+        \edef\@temp{\expandafter\noexpand\csname pgf@func\pgf@shadingname\endcsname}%
+        \edef\@args{{\pgf@basename\pgf@shade@adds}}%
+        \expandafter\expandafter\expandafter\def
+        \expandafter\expandafter\expandafter\@@args
+        \expandafter\expandafter\expandafter{\csname pgf@args\pgf@shadingname\endcsname}%
+        \expandafter\expandafter\expandafter\@temp\expandafter\@args\@@args
+        \expandafter\pgfmath@smuggleone\csname\pgf@shadingxname\endcsname
+      \endgroup
     }%
+    {}%
+    \pgf@invokeshading{\csname\pgf@shadingxname\endcsname}%
   }%
 }
 
@@ -484,6 +503,8 @@
 \def\pgfaliasshading#1#2{%
   \expandafter\let\expandafter\pgf@temp\expandafter=\csname @pgfshading#2!\endcsname%
   \expandafter\let\csname @pgfshading#1!\endcsname=\pgf@temp%
+  \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@num@pgfshading#2!\endcsname%
+  \expandafter\let\csname pgf@num@pgfshading#1!\endcsname=\pgf@temp%
   \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@deps@pgfshading#2!\endcsname%
   \expandafter\let\csname pgf@deps@pgfshading#1!\endcsname=\pgf@temp%
   \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@func@pgfshading#2!\endcsname%
@@ -539,40 +560,66 @@
       \advance\pgf@xb by.5\pgf@pathminx%
       \pgf@yb=.5\pgf@pathmaxy%
       \advance\pgf@yb by.5\pgf@pathminy%
+      % Calculate rotation:
+      \pgfmathparse{#2}%
+      \let\pgfshade@angle=\pgfmathresult
+      \pgfmathsin@\pgfshade@angle
+      \let\pgfshade@sin=\pgfmathresult
+      \pgfmathcos@\pgfshade@angle
+      \let\pgfshade@cos=\pgfmathresult
+      % width and height of the bounding box
+      \pgf@xa=\pgf@pathmaxx
+      \advance\pgf@xa by-\pgf@pathminx
+      \pgf@ya=\pgf@pathmaxy
+      \advance\pgf@ya by-\pgf@pathminy
       % Calculate scaling:
-      \pgf@xc=\pgf@pathmaxx%
-      \advance\pgf@xc by-\pgf@pathminx%
-      \pgf@yc=\pgf@pathmaxy%
-      \advance\pgf@yc by-\pgf@pathminy%
-      \pgf@xc=.01992528\pgf@xc%
-      \pgf@yc=.01992528\pgf@yc%
-      \ifdim\pgf@xc<0.0001pt\relax\ifdim\pgf@xc>-0.0001pt\relax\pgf@no@shadetrue\fi\fi%
-      \ifdim\pgf@yc<0.0001pt\relax\ifdim\pgf@yc>-0.0001pt\relax\pgf@no@shadetrue\fi\fi%
-      \ifpgf@no@shade\else%
-      \pgfsys@beginscope%
-        \pgfsyssoftpath@invokecurrentpath%
-        \pgfsys@clipnext%
-        \pgfsys@discardpath%
-        % Compute new transformation matrix:
-        \pgfsys@transformcm{1}{0}{0}{1}{\pgf@xb}{\pgf@yb}%
-        \pgfsys@transformcm%
-        {\pgf@sys@tonumber{\pgf@xc}}{0}%
-        {0}{\pgf@sys@tonumber{\pgf@yc}}{0pt}{0pt}%
-        \pgfmathparse{#2}%
-        \let\pgfshade@angle=\pgfmathresult%
-        \pgfmathsin@{\pgfshade@angle}%
-        \let\pgfshade@sin=\pgfmathresult%
-        \pgfmathcos@{\pgfshade@angle}%
-        \let\pgfshade@cos=\pgfmathresult%
-        \pgf@x=\pgfshade@sin pt%
-        \pgf@xa=-\pgf@x%
-        \pgfsys@transformcm{\pgfshade@cos}{\pgfshade@sin}{\pgf@sys@tonumber{\pgf@xa}}{\pgfshade@cos}{0pt}{0pt}%
-        \ifx\pgf@shade@extra@transform\pgfutil@empty%
-        \else%
-          \pgflowlevel{\pgf@shade@extra@transform}%
-        \fi%
-        \pgfuseshading{#1}%
-      \pgfsys@endscope%
+      % xscale = 1pt/50bp * (w*|cos(a)|+h*|sin(a)|)/(|cos(a)|+|sin(a)|)
+      % yscale = 1pt/50bp * (w*|sin(a)|+h*|cos(a)|)/(|cos(a)|+|sin(a)|)
+      % 1pt/50bp = .01992528
+      \pgfmathabs@\pgfshade@sin
+      \let\pgfshade@abssin=\pgfmathresult
+      \pgfmathabs@\pgfshade@cos
+      \let\pgfshade@abscos=\pgfmathresult
+      \pgf@xc=\pgfshade@abscos\pgf@xa
+      \advance\pgf@xc by\pgfshade@abssin\pgf@ya
+      \pgf@yc=\pgfshade@abssin\pgf@xa
+      \advance\pgf@yc by\pgfshade@abscos\pgf@ya
+      \pgfmathadd@\pgfshade@abscos\pgfshade@abssin
+      \pgfmathdivide@{.01992528}{\pgfmathresult}%
+      \pgf@xc=\pgfmathresult\pgf@xc
+      \pgf@yc=\pgfmathresult\pgf@yc
+      \ifdim\pgf@xc<0.0001pt
+        \ifdim\pgf@xc>-0.0001pt
+          \pgf@no@shadetrue
+        \fi
+      \fi
+      \ifdim\pgf@yc<0.0001pt
+        \ifdim\pgf@yc>-0.0001pt
+          \pgf@no@shadetrue
+        \fi
+      \fi
+      \ifpgf@no@shade\else
+        \pgfsys@beginscope
+          \pgfsyssoftpath@invokecurrentpath
+          \pgfsys@clipnext
+          \pgfsys@discardpath
+          % Compute new transformation matrix:
+          % shift
+          \pgfsys@transformcm{1}{0}{0}{1}{\the\pgf@xb}{\the\pgf@yb}%
+          % rotation
+          \pgf@x=\pgfshade@sin pt%
+          \pgf@xa=-\pgf@x%
+          \pgfsys@transformcm{\pgfshade@cos}{\pgfshade@sin}{\pgf@sys@tonumber{\pgf@xa}}{\pgfshade@cos}{0pt}{0pt}%
+          % scaling
+          \pgfsys@transformcm{\pgf@sys@tonumber{\pgf@xc}}{0}{0}{\pgf@sys@tonumber{\pgf@yc}}{0pt}{0pt}%
+          % This will actually be the first transformation of the shading.
+          % Should it be applied first so that it becomes the last one?
+          \ifx\pgf@shade@extra@transform\pgfutil@empty%
+          \else%
+            \pgflowlevel{\pgf@shade@extra@transform}%
+          \fi%
+          \pgfuseshading{#1}%
+        \pgfsys@endscope%
       \fi%
     \endgroup%
   \fi%
-- 
cgit v1.2.3

