Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add simple switch handle #153

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions svg2tikz/tikz_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,53 @@ def _handle_group(self, groupnode):
s = code
return s

def _handle_switch(self, groupnode):
"""
Convert a svg switch to tikzcode
All the elements are returned for now
"""
options = self.trans_to_tz(groupnode)

old_indent = self.text_indent

if len(options) > 0:
self.text_indent += TEXT_INDENT

group_id = groupnode.get_id()
code = self._output_group(groupnode)

self.text_indent = old_indent

if code == "":
return ""

extra = ""
if self.options.verbose and group_id:
extra = f"%% {group_id}"

hide = "none" in options

s = ""
if len(options) > 0 or self.options.verbose:
# Remove it from the list
if hide or self.options.verbose:
options.remove("none")

pstyles = [",".join(options)]

if "opacity" in pstyles[0]:
pstyles.append("transparency group")

s += self.text_indent + "\\begin{scope}"
s += f"[{','.join(pstyles)}]{extra}\n{code}"
s += self.text_indent + "\\end{scope}\n"

if hide:
s = "%" + s.replace("\n", "\n%")[:-1]
else:
s = code
return s

def _handle_image(self, node):
"""Handles the image tag and returns tikz code"""
p = self.convert_unit_coord(Vector2d(node.left, node.top))
Expand Down Expand Up @@ -1188,6 +1235,10 @@ def _output_group(self, group):
if node.TAG == "use":
node = node.unlink()

if node.TAG == "switch":
string += self._handle_switch(node)
continue

if node.TAG == "g":
string += self._handle_group(node)
continue
Expand Down
5 changes: 5 additions & 0 deletions tests/test_complete_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ def test_text(self):
filename = "text"
create_test_from_filename(filename, self)

def test_switch(self):
"""Test complete convert simple switch case"""
filename = "switch_simple"
create_test_from_filename(filename, self)


if __name__ == "__main__":
unittest.main()
89 changes: 89 additions & 0 deletions tests/testfiles/switch_simple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions tests/testfiles/switch_simple.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}


\def \globalscale {1.000000}
\begin{tikzpicture}[y=1cm, x=1cm, yscale=\globalscale,xscale=\globalscale, inner sep=0pt, outer sep=0pt]
\path[draw=black,miter limit=10.0] (3.2015, 5.5298) -- (1.2171, 5.5298) -- (1.2171, 4.3754);



\path[draw=black,fill,miter limit=10.0] (1.2171, 4.2365) -- (1.1245, 4.4217) -- (1.2171, 4.3754) -- (1.3097, 4.4217) -- cycle;



\begin{scope}[shift={(-0.0132, 0.189)}]
\node[anchor=south west] (text2) at (2.249, 5.3975){vrai};



\end{scope}

\end{tikzpicture}
\end{document}