使用相關命令時似乎存在錯誤或錯誤。就我而言,我發現繪製平滑曲線會錯誤地繪製曲線的實例。
檢查以下情況(第一個是完全相對的,最後一個是完全絕對的),其中命令的相對使用繪製錯誤,而絕對命令按預期工作。
\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}
答案1
s
在運算符的定義中
\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 }
以下行(目前為第 386 行)pgflibrarysvg.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}}%
是錯的。這是因為\pgf@lib@svg@get@num{2}
和{3}
是上一條曲線的端點。但標準說它應該記住上一條曲線的第二個控制點。如果您將數字更改為{0}
,{1}
它將按預期工作。
(我懷疑該行是從第 300 行複製的,而在C
運算符中, {2}
and{3}
確實表示第二個控制點。)
這是 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}