1

I'm going to convert a SVG image that I found on internet through a method that I found on the pgfornaments (on the last sections) package and I need to know if there is any downside:

I. First I grab an SVG image, it can be this one: https://publicdomainvectors.org/photos/town-hall-15.png

II. Then I open this SVG image on Inkscape and save it as 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. Next I define the following commands:

\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. After that I put this part of the code on a 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. Finally, using the commands that were defined, I do the following changes using any text editor that has regex:

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

From what I understand \o closes the path without filling it, and \s closes the path while filling it, so in our figure the three lines in the middle will need "\o".

After I identified which of the paths were the three lines, I got the code like this:

\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}

That actually renders a pretty good picture:

enter image description here

Here's a 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}

I added another shape if any of you need to see other examples.

So my question is, what is the downside of this method? I'm using it for other pictures (headers, logos) and it looks great, I don't even need to be holding files on my project.

3
  • Related: Q370876, TikZ also has a svgpath library (which I've used recently in another answer). Sep 19 at 17:45
  • 1
    if it works it's fine, but tikz can read svg paths directly, also you could just include the svg (auto converted to pdf in the background) the main disadvantage of going via pstricks is that limits the tex engines and dvi drivers you can use Sep 19 at 17:45
  • In addition to the comment of @DavidCarlisle I would like to mention that the svg package is needed to automatically convert from SVG to PDF.
    – mrpiggi
    Sep 19 at 21:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.