关于将 SVG 转换为 PSTRICKS 再转换为 TIKZ

关于将 SVG 转换为 PSTRICKS 再转换为 TIKZ

我将通过我在pgfornaments(最后几节)包中找到的方法转换我在互联网上找到的 SVG 图像,我需要知道是否存在任何缺点:

一、首先我抓取一个 SVG 图像,它可以是这个:https://publicdomainvectors.org/photos/town-hall-15.png

II. 然后我在 Inkscape 上打开此 SVG 图像并将其保存为 PSTRICKS:

%LaTeX with PSTricks extensions
%%Creator: Inkscape 1.2.1 (0b8a7e5fb6, 2022-09-14, custom)
%%Please note this file requires PSTricks extensions
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(15,15)
{
\newrgbcolor{curcolor}{0 0 0}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
{
\newpath
\moveto(7.5,15)
\lineto(1,11.5547)
\lineto(1,11)
\lineto(14,11)
\lineto(14,11.5547)
\closepath
\moveto(2,10)
\lineto(2,5)
\lineto(1,3.4453)
\lineto(1,2)
\lineto(14,2)
\lineto(14,3.4453)
\lineto(13,5)
\lineto(13,10)
\closepath
\moveto(4,9)
\lineto(5,9)
\lineto(5,3.5)
\lineto(4,3.5)
\closepath
\moveto(7,9)
\lineto(8,9)
\lineto(8,3.5)
\lineto(7,3.5)
\closepath
\moveto(10,9)
\lineto(11,9)
\lineto(11,3.5)
\lineto(10,3.5)
\closepath
}
}
\end{pspicture}

III. 接下来我定义以下命令:

\def\i{\pgfusepath{clip}}%
\def\k{\pgfusepath{stroke}}%
\let\o\pgfpathclose
\let\s\pgfusepathqfillstroke
\def\p #1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}%
\def\r #1 #2 #3 #4 {\pgfpathrectangle{\p{#1}{#2}}{%
\p{#3}{#4}}}%
\def\l #1 #2 {\pgfpathlineto{\p{#1}{#2}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%

IV. 之后我把这部分代码放到了 TikzPicture 上:

\begin{tikzpicture}
\newpath
\moveto(7.5,15)
\lineto(1,11.5547)
\lineto(1,11)
\lineto(14,11)
\lineto(14,11.5547)
\closepath
\moveto(2,10)
\lineto(2,5)
\lineto(1,3.4453)
\lineto(1,2)
\lineto(14,2)
\lineto(14,3.4453)
\lineto(13,5)
\lineto(13,10)
\closepath
\moveto(4,9)
\lineto(5,9)
\lineto(5,3.5)
\lineto(4,3.5)
\closepath
\moveto(7,9)
\lineto(8,9)
\lineto(8,3.5)
\lineto(7,3.5)
\closepath
\moveto(10,9)
\lineto(11,9)
\lineto(11,3.5)
\lineto(10,3.5)
\closepath
\end{tikzpicture}

V.最后,使用定义的命令,我使用任何具有正则表达式的文本编辑器进行以下更改:

 - "(" -> " "
 - ")" -> " "
 - "," -> " "
 - "\lineto" -> "\l"
 - "\moveto" -> "\m"
 - "\newpath", "\closepath" -> "\o" or "\s"

据我了解,\o关闭路径而不填充它,并\s在填充它的同时关闭路径,因此在我们的图中中间的三条线将需要“\o”。

在我确定了哪条路径是这三条线之后,我得到了如下代码:

\begin{tikzpicture}
\pgftransformscale{1}
\s
\m 7.5 15 
\l 1 11.5547 
\l 1 11 
\l 14 11 
\l 14 11.5547 
\s
\m 2 10 
\l 2 5 
\l 1 3.4453 
\l 1 2 
\l 14 2 
\l 14 3.4453 
\l 13 5 
\l 13 10 
\o
\m 4 9 
\l 5 9 
\l 5 3.5 
\l 4 3.5 
\o
\m 7 9 
\l 8 9 
\l 8 3.5 
\l 7 3.5 
\o
\m 10 9 
\l 11 9 
\l 11 3.5 
\l 10 3.5 
\s
\end{tikzpicture}

这实际上呈现出了一幅相当不错的画面:

在此处输入图片描述

以下是 MWE:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgf}
\usepackage{lipsum}


\begin{document}

\begingroup
\def\i{\pgfusepath{clip}}%
\def\k{\pgfusepath{stroke}}%
\let\o\pgfpathclose
\let\s\pgfusepathqfillstroke
\def\p #1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}%
\def\r #1 #2 #3 #4 {\pgfpathrectangle{\p{#1}{#2}}{%
\p{#3}{#4}}}%
\def\l #1 #2 {\pgfpathlineto{\p{#1}{#2}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\begin{tikzpicture}
\pgftransformscale{3}
\s
\m 7.5 15 
\l 1 11.5547 
\l 1 11 
\l 14 11 
\l 14 11.5547 
\s
\m 2 10 
\l 2 5 
\l 1 3.4453 
\l 1 2 
\l 14 2 
\l 14 3.4453 
\l 13 5 
\l 13 10 
\o
\m 4 9 
\l 5 9 
\l 5 3.5 
\l 4 3.5 
\o
\m 7 9 
\l 8 9 
\l 8 3.5 
\l 7 3.5 
\o
\m 10 9 
\l 11 9 
\l 11 3.5 
\l 10 3.5 
\s
\end{tikzpicture}
\endgroup

\vspace{10pt}

\lipsum[1-2]

\vspace{10pt}

\begingroup
\def\i{\pgfusepath{clip}}%
\def\k{\pgfusepath{stroke}}%
\let\o\pgfpathclose
\let\s\pgfusepathqfillstroke
\def\p #1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}%
\def\r #1 #2 #3 #4 {\pgfpathrectangle{\p{#1}{#2}}{%
\p{#3}{#4}}}%
\def\l #1 #2 {\pgfpathlineto{\p{#1}{#2}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\def\c #1 #2 #3 #4 #5 #6 {%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\begin{tikzpicture}[anchor = center, align =center, color = green]
\pgftransformscale{.15}
\m 2172.19445438 97.79985074 
\l 2120.608589 97.79985074 
\l 2159.84298802 59.73198503 
\l 2211.4284534 59.73198503 
\l 2172.19445438 97.79985074 
\s
\m 2263.02005211 97.79985074 
\l 2211.4284534 97.79985074 
\l 2250.66858575 59.73198503 
\l 2302.25431779 59.73198503 
\l 2263.02005211 97.79985074 
\s
\m 2353.84004984 97.79985074 
\l 2302.25431779 97.79985074 
\l 2341.48845014 59.73198503 
\l 2393.07418219 59.73198503 
\l 2353.84004984 97.79985074 
\s
\m 2782.40683912 59.73198503 
\l 2452.39338071 59.73198503 
\l 2491.62751306 21.67465264 
\l 2821.64097147 21.67465264 
\l 2782.40683912 59.73198503 
\s
\m 2075.28592347 97.79985074 
\l 1087.3832815 97.79985074 
\l 1126.61728052 59.73198503 
\l 2114.51992249 59.73198503 
\l 2075.28592347 97.79985074 
\s
\m 1024.65194973 97.79985074 
\l 976.69908426 97.79985074 
\l 1015.93341662 59.73198503 
\l 1063.88634875 59.73198503 
\l 1024.65194973 97.79985074 
\s
\m 884.84743323 97.79985074 
\l 836.88003443 97.79985074 
\l 876.11430011 59.73198503 
\l 924.08168558 59.73198503 
\l 884.84743323 97.79985074 
\m 745.02843672 97.79985074 
\l 697.07549125 97.79985074 
\l 736.30974361 59.73198503 
\l 784.26268908 59.73198503 
\l 745.02843672 97.79985074 
\s
\m 605.22386688 97.79985074 
\l 557.25636142 97.79985074 
\l 596.49061377 59.73198503 
\l 644.45813257 59.73198503 
\l 605.22386688 97.79985074 
\s
\m 465.40472371 97.79985074 
\l 417.45203158 97.79985074 
\l 456.6860306 59.73198503 
\l 504.63897607 59.73198503 
\l 465.40472371 97.79985074 
\s
\m 325.58570054 97.79985074 
\l 277.63288841 97.79985074 
\l 316.86703409 59.73198503 
\l 364.81996623 59.73198503 
\l 325.58570054 97.79985074 
\s
\m 185.78126404 97.79985074 
\l 137.81375857 97.79985074 
\l 177.04801092 59.73198503 
\l 225.01539639 59.73198503 
\l 185.78126404 97.79985074 
\s
\m 2463.91231375 76.13558462 
\l 3019.68069986 76.13558462 
\l 3019.68069986 81.40678448 
\l 2467.54951366 81.40678448 
\l 2428.31524797 119.46398353 
\l 0.00000202 119.46398353 
\l 0.00000202 114.192917 
\l 2424.67644806 114.192917 
\l 2463.91231375 76.13558462 
\s
\m 2463.91231375 -0.00001348 
\l 2653.07924235 -0.00001348 
\l 2653.07924235 5.28158639 
\l 2467.54951366 5.28158639 
\l 2428.31524797 43.33878544 
\l 323.21724727 43.33878544 
\l 323.21724727 38.06785223 
\l 2424.67804806 38.06785223 
\l 2463.91231375 -0.00001348 
\s
\m 238.47124939 19.03918604 
\l 2230.58071958 19.03918604 
\l 2230.58071958 24.31025258 
\l 238.47124939 24.31025258 
\l 238.47124939 19.03918604 
\end{tikzpicture}
\endgroup

\end{document}

如果你们需要看其他示例,我添加了另一种形状。

所以我的问题是,这种方法的缺点是什么?我将其用于其他图片(标题、徽标),看起来很棒,我甚至不需要在我的项目中保存文件。

相关内容