Parece haber un error o error al utilizar comandos relativos. En mi caso, encontré un caso en el que dibujar una curva suave dibujaría la curva incorrectamente.
Verifique los siguientes casos (el primero es completamente relativo y el último es completamente absoluto), donde el uso relativo de los comandos dibuja erróneamente, mientras que los absolutos funcionan como se esperaba.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}
\begin{document}
% Original
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 s 111 248 248 248 s 248 -111 248 -248 S 393 8 256 8 z";
\end{tikzpicture}
% Mix of relative
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 s 111 248 248 248 S 504 393 504 256 S 393 8 256 8 z";
\end{tikzpicture}
% Mix of relative
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 S 119 504 256 504 s 248 -111 248 -248 S 393 8 256 8 z";
\end{tikzpicture}
% Full absolute
\begin{tikzpicture}
\draw svg "M256 8 C 119 8 8 119 8 256 S 119 504 256 504 S 504 393 504 256 S 393 8 256 8 z";
\end{tikzpicture}
\end{document}
Respuesta1
En la definición de s
operador.
\pgfparserdef{svgpath}{all}{the letter s} { \pgf@lib@svg@finish@prev \pgf@lib@svg@read@nums{4}{\pgf@lib@svg@curveto@rel@smooth} } \def\pgf@lib@svg@curveto@rel@smooth{% \ifnum\pgf@lib@svg@count=0\relax% nothing read \else% % Draw curve % Compute first control point \ifx\pgf@lib@svg@bezier@last\pgfutil@empty% \def\pgf@lib@svg@first@cp{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}} \else \def\pgf@lib@svg@first@cp{ \pgfpointadd {\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}} {\pgfpointdiff {\pgf@lib@svg@bezier@last} {\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}} } } \fi \pgfpathcurveto {\pgf@lib@svg@first@cp} {\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{0}pt}{\pgf@lib@svg@get@num{1}pt}}}% {\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{2}pt}{\pgf@lib@svg@get@num{3}pt}}}% % Clear quadratic last point and save new last control point: \let\pgf@lib@svg@quad@last=\pgfutil@empty% \pgf@process{\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{2}pt}{\pgf@lib@svg@get@num{3}pt}}} \edef\pgf@lib@svg@bezier@last{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% % update \advance\pgf@lib@svg@last@x by\pgf@lib@svg@get@num{2}pt% \advance\pgf@lib@svg@last@y by\pgf@lib@svg@get@num{3}pt% % Go on \pgf@lib@svg@read@nums{4}{\pgf@lib@svg@curveto@rel@smooth} \fi }
La siguiente línea (actualmente la línea 386 depgflibrarysvg.path.code.tex
\pgf@process{\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{2}pt}{\pgf@lib@svg@get@num{3}pt}}} \edef\pgf@lib@svg@bezier@last{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
Está Mal. Esto se debe a que \pgf@lib@svg@get@num{2}
y {3}
es el punto final de la curva anterior. Pero la norma dice que se debe recordar el segundo punto de control de la curva anterior. Si cambia los números a {0}
y {1}
funcionará como se esperaba.
(Sospecho que esa línea se copia de la línea 300, mientras que en el C
operador {2}
y {3}
significa el segundo punto de control).
Aquí está el MWE
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}
\makeatletter
\def\pgf@lib@svg@curveto@rel@smooth{%
\ifnum\pgf@lib@svg@count=0\relax% nothing read
\else%
% Draw curve
% Compute first control point
\ifx\pgf@lib@svg@bezier@last\pgfutil@empty%
\def\pgf@lib@svg@first@cp{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}
\else
\def\pgf@lib@svg@first@cp{
\pgfpointadd
{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}
{\pgfpointdiff
{\pgf@lib@svg@bezier@last}
{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}
}
}
\fi
\pgfpathcurveto
{\pgf@lib@svg@first@cp}
{\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{0}pt}{\pgf@lib@svg@get@num{1}pt}}}%
{\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{2}pt}{\pgf@lib@svg@get@num{3}pt}}}%
% Clear quadratic last point and save new last control point:
\let\pgf@lib@svg@quad@last=\pgfutil@empty%
\pgf@process{\pgfpointadd{\pgfqpoint{\pgf@lib@svg@last@x}{\pgf@lib@svg@last@y}}{\pgfqpoint{\pgf@lib@svg@get@num{0}pt}{\pgf@lib@svg@get@num{1}pt}}} %%%%%% fixing this line
\edef\pgf@lib@svg@bezier@last{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
% update
\advance\pgf@lib@svg@last@x by\pgf@lib@svg@get@num{2}pt%
\advance\pgf@lib@svg@last@y by\pgf@lib@svg@get@num{3}pt%
% Go on
\pgf@lib@svg@read@nums{4}{\pgf@lib@svg@curveto@rel@smooth}
\fi
}
\begin{document}
% Original
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 s 111 248 248 248 s 248 -111 248 -248 S 393 8 256 8 z";
\end{tikzpicture}
% Mix of relative
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 s 111 248 248 248 S 504 393 504 256 S 393 8 256 8 z";
\end{tikzpicture}
% Mix of relative
\begin{tikzpicture}
\draw svg "M 256 8 C 119 8 8 119 8 256 S 119 504 256 504 s 248 -111 248 -248 S 393 8 256 8 z";
\end{tikzpicture}
% Full absolute
\begin{tikzpicture}
\draw svg "M256 8 C 119 8 8 119 8 256 S 119 504 256 504 S 504 393 504 256 S 393 8 256 8 z";
\end{tikzpicture}
\end{document}