From 6a8d502f6063d1e03f46b7852876aacbdbc9658b Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sat, 8 Sep 2018 21:41:57 +0000
Subject: svg (8sep18)

git-svn-id: svn://tug.org/texlive/trunk@48626 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/svg/svg-extract.sty | 153 +++++++++++++++++-------
 1 file changed, 108 insertions(+), 45 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/svg/svg-extract.sty')

diff --git a/Master/texmf-dist/tex/latex/svg/svg-extract.sty b/Master/texmf-dist/tex/latex/svg/svg-extract.sty
index f7472d3a063..e4be74acca3 100644
--- a/Master/texmf-dist/tex/latex/svg/svg-extract.sty
+++ b/Master/texmf-dist/tex/latex/svg/svg-extract.sty
@@ -33,7 +33,7 @@
 %% 
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{svg-extract}[%
-  2017/11/29 v2.01\space%
+  2018/09/08 v2.02\space%
   (extract independent graphics from SVG pictures)%
 ]
 \RequirePackage{svg}[2017/03/27]
@@ -81,7 +81,7 @@
       }%
       \svg@deprecated@key{pdf}{extractformat={\svgx@format}}%
     \else%
-      \FamilyKeyStateUnknownValue
+      \FamilyKeyStateUnknownValue%
     \fi%
   \fi%
 }
@@ -94,7 +94,7 @@
       }%
       \svg@deprecated@key{eps}{extractformat={\svgx@format}}%
     \else%
-      \FamilyKeyStateUnknownValue
+      \FamilyKeyStateUnknownValue%
     \fi%
   \fi%
 }
@@ -196,7 +196,7 @@
     `pdftopsopt' instead. See the manual for\MessageBreak%
     more. Nothing was done%
   }%
-  \FamilyKeyStateProcessed
+  \FamilyKeyStateProcessed%
 }
 \newif\if@svgx@cnv@run
 \newcommand*\svgx@cnv@cmd{}
@@ -286,7 +286,7 @@
       }%
       \svg@deprecated@key{png}{convertformat={\svgx@cnv@format}}%
     \else%
-      \FamilyKeyStateUnknownValue
+      \FamilyKeyStateUnknownValue%
     \fi%
   \fi%
 }
@@ -341,12 +341,13 @@
 }
 \newcommand*\svgx@out@path{}
 \DefineFamilyKey{SVG}{extractpath}{%
+  \svg@sanitize@dq\svg@tempb{#1}%
   \FamilySetNumerical{SVG}{extractpath}{svg@tempa}{%
     {svgpath}{0},{svgdir}{0},%
     {svgsubpath}{1},{svgsubdir}{1},%
     {basepath}{2},{basedir}{2},{jobpath}{2},{jobdir}{2},%
     {basesubpath}{3},{basesubdir}{3},{jobsubpath}{3},{jobsubdir}{3}%
-  }{#1}%
+  }{\svg@tempb}%
   \ifx\FamilyKeyState\FamilyKeyStateProcessed%
     \ifcase\svg@tempa\relax% svgpath
       \renewcommand*\svgx@out@path{\svg@file@path}%
@@ -358,7 +359,7 @@
       \renewcommand*\svgx@out@path{./svg-extract/}%
     \fi%
   \else%
-    \renewcommand*\svgx@out@path{#1}%
+    \edef\svgx@out@path{\svg@tempb}%
     \svg@normalize@path{\svgx@out@path}%
     \FamilyKeyStateProcessed%
   \fi%
@@ -370,12 +371,13 @@
 \newcommand*\svgx@out@name{}
 \newif\if@svgx@out@sec
 \DefineFamilyKey{SVG}{extractname}{%
+  \svg@quotes@remove[{#1}]{\svg@tempb}%
   \FamilySetNumerical{SVG}{extractname}{svg@tempa}{%
     {filename}{0},{name}{0},%
     {filenamenumbered}{1},{namenumbered}{1},%
     {numberedfilename}{1},{numberedname}{1},%
     {numbered}{2},{section}{2},{numberedsection}{2},{sectionnumbered}{2}%
-  }{#1}%
+  }{\svg@tempb}%
   \@svgx@out@secfalse%
   \ifx\FamilyKeyState\FamilyKeyStateProcessed%
     \ifcase\svg@tempa\relax% filename
@@ -387,10 +389,11 @@
       \@svgx@out@sectrue%
     \fi%
   \else%
-    \def\svg@tempa##1.##2\@nil{%
-      \IfArgIsEmpty{##1}{}{\renewcommand*\svgx@out@name{##1}}%
-    }%
-    \svg@tempa#1.\@nil%
+    \if@svg@quotes@found%
+      \edef\svgx@out@name{"\svg@tempb"}%
+    \else%
+      \edef\svgx@out@name{\svg@tempb}%
+    \fi%
     \FamilyKeyStateProcessed%
   \fi%
 }
@@ -409,8 +412,10 @@
       \FamilyKeyStateProcessed%
     }{%
       \FamilySetLengthMacro{SVG}{extractwidth}{\svgx@param@width}{#1}%
-      \ifdim\svgx@param@width<\z@\relax%
-        \FamilyKeyStateUnknownValue%
+      \ifx\FamilyKeyState\FamilyKeyStateProcessed%
+        \ifdim\svgx@param@width<\z@\relax%
+          \FamilyKeyStateUnknownValue%
+        \fi%
       \fi%
     }%
   }%
@@ -427,12 +432,41 @@
       \FamilyKeyStateProcessed%
     }{%
       \FamilySetLengthMacro{SVG}{extractheight}{\svgx@param@height}{#1}%
-      \ifdim\svgx@param@height<\z@\relax%
-        \FamilyKeyStateUnknownValue%
+      \ifx\FamilyKeyState\FamilyKeyStateProcessed%
+        \ifdim\svgx@param@height<\z@\relax%
+          \FamilyKeyStateUnknownValue%
+        \fi%
       \fi%
     }%
   }%
 }
+\newif\if@svgx@param@distort
+\DefineFamilyKey{SVG}{extractdistort}[true]{%
+  \FamilyKeyStateUnknownValue%
+  \svg@ifvalueisrelax{#1}{%
+    \@svgx@param@distortfalse%
+    \FamilyKeyStateProcessed%
+  }{%
+    \ifstr{#1}{inherit}{%
+      \renewcommand*\if@svgx@param@distort{\if@svg@param@distort}%
+      \FamilyKeyStateProcessed%
+    }{%
+      \FamilySetBool{SVG}{extractdistort}{@svgx@param@distort}{#1}%
+    }%
+  }%
+}
+\DefineFamilyKey{SVG}{extractkeepaspectratio}[true]{%
+  \FamilySetBool{SVG}{extractkeepaspectratio}{@svg@tempswa}{#1}%
+  \ifx\FamilyKeyState\FamilyKeyStateProcessed%
+    \if@svg@tempswa%
+      \FamilyOptions{SVG}{extractdistort=false}%
+    \else
+      \FamilyOptions{SVG}{extractdistort=true}%
+    \fi%
+  \else%
+    \FamilyOptions{SVG}{extractdistort=#1}%
+  \fi%
+}
 \newcommand*\svgx@param@scale{\svg@param@scale}
 \DefineFamilyKey{SVG}{extractscale}{%
   \FamilyKeyStateUnknownValue%
@@ -459,9 +493,9 @@
     \let\svgx@param@pretex\relax%
   }{%
     \ifstr{#1}{inherit}{%
-      \def\svgx@param@pretex{\svg@param@pretex}%
+      \renewcommand*\svgx@param@pretex{\svg@param@pretex}%
     }{%
-      \def\svgx@param@pretex{#1}%
+      \renewcommand*\svgx@param@pretex{#1}%
     }%
   }%
   \FamilyKeyStateProcessed%
@@ -472,9 +506,9 @@
     \let\svgx@param@apptex\relax%
   }{%
     \ifstr{#1}{inherit}{%
-      \def\svgx@param@apptex{\svg@param@apptex}%
+      \renewcommand*\svgx@param@apptex{\svg@param@apptex}%
     }{%
-      \def\svgx@param@apptex{#1}%
+      \renewcommand*\svgx@param@apptex{#1}%
     }%
   }%
   \FamilyKeyStateProcessed%
@@ -569,11 +603,11 @@
       \fi%
     }%
     \edef\svg@tempb{%
-      \noexpand\endgroup%
+      \endgroup%
       \ifx\svg@tempa\relax%
-        \noexpand\let\noexpand\svg@tempa\noexpand\relax%
+        \let\noexpand\svg@tempa\noexpand\relax%
       \else%
-        \noexpand\def\noexpand\svg@tempa{\svg@tempa}%
+        \def\noexpand\svg@tempa{\svg@tempa}%
       \fi%
     }%
   \svg@tempb%
@@ -611,21 +645,23 @@
     \fi%
   }%
 }
-\newcommand*\svgxdelayed[1]{
+\newif\if@svgx@standalone
+\newcommand*\svgxsetbox[2][]{%
+  \@svgx@standalonetrue%
+  \svgx@setbox{#1}{#2}%
   \scr@ifundefinedorrelax{AtEndPreamble}{%
-    \AtBeginDocument{#1}%
+    \let\svg@tempa\@firstofone%
   }{%
-    \AtEndPreamble{\AtBeginDocument{#1}}%
+    \def\svg@tempa{\AtEndPreamble}%
   }%
+  \svg@tempa{\AtBeginDocument{\svgx@setbox{#1}{#2}}}%
 }
-\newbox\svgx@box
-\newcommand*\svgxsetbox[2][]{%
-  \csname @tud@x@standalone@croptrue\endcsname%
-  \sbox\svgx@box{\svg@@input[{#1},draft=false]{#2}}%
+\newcommand*\svgx@setbox[2]{%
+  \sbox\svg@box{\svg@@input[{#1},draft=false]{#2}}%
   \svgxsetpapersize%
 }
 \newcommand*\svgxsetpapersize{%
-  \setlength\paperwidth{\the\wd\svgx@box}%
+  \setlength\paperwidth{\the\wd\svg@box}%
   \scr@ifundefinedorrelax{stockwidth}{}{%
     \setlength\stockwidth{\paperwidth}%
   }%
@@ -633,7 +669,7 @@
     \setlength\mediawidth{\paperwidth}%
   }%
   \setlength\textwidth{\paperwidth}%
-  \setlength\paperheight{\the\dimexpr\ht\svgx@box+\dp\svgx@box\relax}%
+  \setlength\paperheight{\the\dimexpr\ht\svg@box+\dp\svg@box\relax}%
   \scr@ifundefinedorrelax{stockheight}{}{%
     \setlength\stockheight{\paperheight}%
   }%
@@ -665,22 +701,44 @@
     \if@svgx@beamer%
       \setbeamertemplate{navigation symbols}{}%
       \begin{frame}[plain]%
-      \usebox\svgx@box%
+      \usebox\svg@box%
       \end{frame}%
     \else%
-      \usebox\svgx@box%
+      \usebox\svg@box%
     \fi%
     \endgraf%
   \endgroup%
 }
 \FamilyExecuteOptions{SVG}{%
-  extract=true,extractpath=basesubdir,extractruns=2,extractname=namenumbered,%
+  extract=true,extractpath=basesubdir,%
+  extractruns=2,extractname=namenumbered,extractdistort=false,%
   convert=magick,convert=false,%
   gsdevice={png=png16m},gsdevice={jpeg=jpeg},gsdevice={jpg=jpeg},%
   gsdevice={tif=tiff48nc},gsdevice={tiff=tiff48nc},%
   gsdevice={eps=eps2write},gsdevice={ps=ps2write}%
 }
 \FamilyProcessOptions{SVG}
+\DefineFamilyMember[.param]{SVG}
+\newcommand*\svgx@param@angle{0}
+\svg@local@param@def{%
+  \DefineFamilyKey[.param]{SVG}{extractangle}{%
+    \FamilyKeyStateUnknownValue%
+    \svg@ifvalueisrelax{#1}{%
+      \renewcommand*\svgx@param@angle{0}%
+      \FamilyKeyStateProcessed%
+    }{%
+      \ifstr{#1}{inherit}{%
+        \renewcommand*\svgx@param@angle{\svg@param@angle}%
+        \FamilyKeyStateProcessed%
+      }{%
+        \ifisdimension{#1\p@}{%
+          \renewcommand*\svgx@param@angle{#1}%
+          \FamilyKeyStateProcessed%
+        }{}%
+      }%
+    }%
+  }%
+}
 \let\svghidepreamblestart\relax
 \let\svghidepreambleend\relax
 \ifnum\pdf@shellescape=\@ne\relax\else%
@@ -692,7 +750,7 @@
         \PackageWarning{svg-extract}{%
           You didn't enable `shell escape' (or `write18')\MessageBreak%
           so it wasn't possible to run the extraction for\MessageBreak%
-          file `\svg@tempa'%
+          file `\svg@tempa'\MessageBreak%
         }%
       \endgroup%
     \fi%
@@ -833,6 +891,9 @@
       \ifdim\svgx@param@height>\z@\relax%
         \svg@tempa{height=\svgx@param@height}%
       \fi%
+      \if@svgx@param@distort%
+        \svg@tempa{distort=true}%
+      \fi%
       \ifdim\dimexpr\svgx@param@scale\p@\relax=\p@\relax\else%
         \svg@tempa{scale=\svgx@param@scale}%
       \fi%
@@ -864,6 +925,11 @@
           \fi%
         }{}%
       \fi%
+      \ifdim\dimexpr\svgx@param@angle\p@\relax=\z@\relax\else%
+        \edef\svg@tempa{%
+          angle=\svgx@param@angle\ifx\svg@tempa\@empty\else,\svg@tempa\fi%
+        }%
+      \fi%
       \ifx\svg@tempa\@empty%
         \def\svg@tempa{\string\svgxsetbox{#1}}%
       \else%
@@ -879,9 +945,6 @@
         }{}%
       \fi%
       \immediate\write\svgx@stream@out{%
-        \string\svgxdelayed{\@percentchar^^J%
-          \space\space\svg@tempa\@percentchar^^J%
-        }^^J^^J%
         \string\begin{document}^^J%
         \string\pagestyle{empty}^^J%
         \string\svgxoutputbox\@percentchar^^J%
@@ -954,7 +1017,7 @@
             \expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svgx@format}{%
               \PackageWarning{svg-extract}{%
                 File type `\svg@tempa' was specified for option\MessageBreak%
-                `extractformat' (\svgx@format) as well as for \MessageBreak
+                `extractformat' (\svgx@format) as well as for \MessageBreak%
                 option `convertformat' (\svgx@cnv@format) so the\MessageBreak%
                 conversion won't be done%
               }%
@@ -1073,8 +1136,8 @@
     }%
     \svg@tempa#1,\@nil%
     \edef\svg@tempa{%
-      \noexpand\endgroup%
-      \noexpand\def\noexpand\svgx@cnv@informat{\svg@tempa}%
+      \endgroup%
+      \def\noexpand\svgx@cnv@informat{\svg@tempa}%
     }%
   \svg@tempa%
   \ifx\svgx@cnv@informat\@empty%
@@ -1133,9 +1196,9 @@
         \edef\svg@tempb{%
           The graphic file \svg@tempb\space failed\MessageBreak%
           for `#1.#2'\MessageBreak%
-          Troubleshooting: Please check the log file how the\MessageBreak%
-          invocation of the extraction took place and try\MessageBreak%
-          to execute it yourself in the terminal%
+          Troubleshooting: Please check the log file how\MessageBreak%
+          the invocation of the extraction took place and\MessageBreak%
+          try to execute it yourself in the terminal%
         }%
       \else%
         \def\svg@tempb{%
-- 
cgit v1.2.3

