tikz 库中 \curveto 的替代品 - Inkscape 将 svg 导出到 tikz

tikz 库中 \curveto 的替代品 - Inkscape 将 svg 导出到 tikz

我需要绘制一条复杂的曲线,我想借助矢量程序 Inkscape。第一步,我尝试使用 Inkscape 到 TikZ 导出器 (http://code.google.com/p/inkscape2tikz/) 将曲线转换为 tikz,但未成功(启动插件后出现错误 - Inkscape 0.48.2 r9819/Extension/Export/Export 到 Tikz 路径)。不太可能有人能帮我解决这个错误:

    Traceback (most recent call last):

  File "tikz_export.py", line 1391, in <module>

    main_inkscape()

  File "tikz_export.py", line 1379, in main_inkscape

    effect.affect()

  File "C:\Program Files (x86)\Inkscape\share\extensions\inkex.py", line 216, in affect

    if output: self.output()

  File "tikz_export.py", line 1322, in output

    f = codecs.open(self.options.outputfile, 'w', 'utf8')

  File "C:\Program Files (x86)\Inkscape\python\Lib\codecs.py", line 870, in open

    file = __builtin__.open(filename, mode, buffering)

IOError: [Errno 13] Permission denied: 'none'

所以我想问一下如何\curveto用原生 tikz 命令替换命令。因为我能够将 Inkscape 曲线转换为 PSTricks... 我更熟悉 pakcage tikz。

%LaTeX with PSTricks extensions
%%Creator: 0.48.2
%%Please note this file requires PSTricks extensions
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(272,129)
{
\newrgbcolor{curcolor}{0 0 0}
\pscustom[linewidth=1,linecolor=curcolor]
{
\newpath
\moveto(1.410771,63.47461)
\curveto(6.288991,93.43519)(6.900971,94.37507)(27.182131,102.49149)
\curveto(41.727261,108.31238)(35.032981,125.42937)(51.364001,125.36952)
\curveto(67.695031,125.30962)(67.928601,83.44326)(69.419751,64.22647)
\curveto(70.630951,48.61748)(74.370481,32.72818)(94.65164,24.61178)
\curveto(109.19677,18.79088)(101.39868,1.81368)(117.97023,1.87438)
\curveto(134.06073,1.93338)(134.11602,42.07748)(136.03504,63.349)
\curveto(136.94551,73.44118)(139.86205,86.13389)(143.15997,91.12848)
\curveto(146.45789,96.12308)(151.68117,98.38715)(161.82175,102.44536)
\curveto(176.36688,108.26625)(169.6726,125.38324)(186.00362,125.32339)
\curveto(202.33465,125.26349)(199.36351,96.7115)(204.05937,64.18034)
\curveto(208.75523,31.64918)(209.0101,32.68208)(229.29126,24.56568)
\curveto(243.83639,18.74478)(236.0383,1.76758)(252.60985,1.82828)
\curveto(268.70035,1.88728)(256.58629,30.46878)(270.65931,63.2234)
}
}
\end{pspicture}

我猜想它可以解决命令control,但我仍然没有成功。

谢谢。

答案1

(看起来 Inkscape 无法打开文件进行写入。)

以下代码适用于您的示例。如果您生成的所有代码都是这样,那么它可能适用于该示例,但这不是完整的解决方案。

的直接替换\curveto\pgfpathcurveto。因此,您可以将 PSTricks 宏重新定义为其 PGF 等效项(如果存在),如下所示:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/82308/86}
\usepackage{tikz}

\def\moveto(#1,#2){%
  \pgfpathmoveto{\pgfpoint{#1 pt}{#2 pt}}}

\def\curveto(#1,#2)(#3,#4)(#5,#6){%
  \pgfpathcurveto{\pgfpoint{#1 pt}{#2 pt}}{\pgfpoint{#3 pt}{#4 pt}}{\pgfpoint{#5 pt}{#6 pt}}}

\let\psset=\tikzset
\def\pscustom[#1]{\tikzset{#1}}
\tikzset{
  xunit/.style={x={(#1,0)}},
  yunit/.style={y={(0,#1)}},
  runit/.style={},
  linecolor/.style={color=#1},
  linewidth/.style={line width=#1},
}

\def\newrgbcolor#1#2{\definecolor{#1}{RGB}{#2}}
\def\pspicture(#1,#2){\tikzpicture}
\def\endpspicture{%
\pgfusepath{stroke}
\endtikzpicture}
\let\newpath=\relax


\begin{document}

%LaTeX with PSTricks extensions
%%Creator: 0.48.2
%%Please note this file requires PSTricks extensions
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(272,129)
{
\newrgbcolor{curcolor}{0 0 0}
\pscustom[linewidth=1,linecolor=curcolor]
{
\newpath
\moveto(1.410771,63.47461)
\curveto(6.288991,93.43519)(6.900971,94.37507)(27.182131,102.49149)
\curveto(41.727261,108.31238)(35.032981,125.42937)(51.364001,125.36952)
\curveto(67.695031,125.30962)(67.928601,83.44326)(69.419751,64.22647)
\curveto(70.630951,48.61748)(74.370481,32.72818)(94.65164,24.61178)
\curveto(109.19677,18.79088)(101.39868,1.81368)(117.97023,1.87438)
\curveto(134.06073,1.93338)(134.11602,42.07748)(136.03504,63.349)
\curveto(136.94551,73.44118)(139.86205,86.13389)(143.15997,91.12848)
\curveto(146.45789,96.12308)(151.68117,98.38715)(161.82175,102.44536)
\curveto(176.36688,108.26625)(169.6726,125.38324)(186.00362,125.32339)
\curveto(202.33465,125.26349)(199.36351,96.7115)(204.05937,64.18034)
\curveto(208.75523,31.64918)(209.0101,32.68208)(229.29126,24.56568)
\curveto(243.83639,18.74478)(236.0383,1.76758)(252.60985,1.82828)
\curveto(268.70035,1.88728)(256.58629,30.46878)(270.65931,63.2234)
}
}
\end{pspicture}

\end{document}

PGF 路径

在这种情况下,我实际上会使用类似上述内容来生成 pgf 软路径,然后将其剪切并粘贴到我的真实文档中。我不会在正确的文档中使用类似上述的黑客手段。

答案2

如果有人来这里寻找 inkscape2tikz 错误,问题在于 inkscape 没有权限写入导出文件,导出文件会在扩展目录中写入,而不会询问保存位置。因此,如果执行 inkscape 的用户没有权限写入扩展文件夹,它就会崩溃,这就是给出的错误。

Inkscape 至 TikZ 导出器 (http://code.google.com/p/inkscape2tikz/

相关内容