diff --git a/svg2tikz/tikz_export.py b/svg2tikz/tikz_export.py index d98fd27..b03a294 100644 --- a/svg2tikz/tikz_export.py +++ b/svg2tikz/tikz_export.py @@ -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)) @@ -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 diff --git a/tests/test_complete_files.py b/tests/test_complete_files.py index 5c5bf7e..6001353 100644 --- a/tests/test_complete_files.py +++ b/tests/test_complete_files.py @@ -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() diff --git a/tests/testfiles/switch_simple.svg b/tests/testfiles/switch_simple.svg new file mode 100644 index 0000000..4e69e8d --- /dev/null +++ b/tests/testfiles/switch_simple.svg @@ -0,0 +1,89 @@ + + + + + + + + + + + + vrai + + + + vrai + + + diff --git a/tests/testfiles/switch_simple.tex b/tests/testfiles/switch_simple.tex new file mode 100644 index 0000000..1320512 --- /dev/null +++ b/tests/testfiles/switch_simple.tex @@ -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}