From 69c2dd1306189890c6113b0e054a0461a8d1dafb Mon Sep 17 00:00:00 2001 From: ldevillez Date: Tue, 10 Oct 2023 19:01:36 +0200 Subject: [PATCH] Fix: wrapping line --- CHANGELOG.md | 1 + svg2tikz/tikz_export.py | 28 ++++----- tests/test_complete_files.py | 5 ++ tests/testfiles/rectangle_wrap.svg | 91 ++++++++++++++++++++++++++++++ tests/testfiles/rectangle_wrap.tex | 35 ++++++++++++ 5 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 tests/testfiles/rectangle_wrap.svg create mode 100644 tests/testfiles/rectangle_wrap.tex diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8935b..d7091b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ ### Fixed - Transform working with --noreversey - Fixing the installation of svg2tikz as command line tool +- Wrapping line now respect newline ### Security ## v2.1.0 - 2023/06/28 diff --git a/svg2tikz/tikz_export.py b/svg2tikz/tikz_export.py index bc5e2d0..7307216 100644 --- a/svg2tikz/tikz_export.py +++ b/svg2tikz/tikz_export.py @@ -1237,7 +1237,6 @@ def _output_group(self, group): The group is processed recursively if it contains sub groups. """ string = "" - # transform = [] for node in group: if not filter_tag(node): continue @@ -1258,12 +1257,10 @@ def _output_group(self, group): attr = msg.args[0].split("attribute")[1].split(".")[0] logging.warning("%s attribute cannot be represented", attr) - cmd = [] - pathcode = "" if self.options.verbose: - cmd.append(f"%{node.get_id()}\n") + string += self.text_indent + f"%{node.get_id()}\n" if node.TAG == "path": optionscode = f"[{','.join(goptions)}]" if len(goptions) > 0 else "" @@ -1307,16 +1304,21 @@ def _output_group(self, group): logging.debug("Unhandled element %s", node.tag) continue - if pathcode != "": - cmd.append(pathcode) - - cmd = [self.text_indent + c for c in cmd] - string += "\n".join(cmd) + ";\n\n\n\n" + if self.options.wrap: + string += "\n".join( + wrap( + self.text_indent + pathcode, + 80, + subsequent_indent=" ", + break_long_words=False, + drop_whitespace=False, + replace_whitespace=False, + ) + ) + else: + string += self.text_indent + pathcode - if self.options.wrap: - string = "\n".join( - wrap(string, 80, subsequent_indent=" ", break_long_words=False) - ) + string += ";\n\n\n\n" return string diff --git a/tests/test_complete_files.py b/tests/test_complete_files.py index 2601239..6e0ad4b 100644 --- a/tests/test_complete_files.py +++ b/tests/test_complete_files.py @@ -112,6 +112,11 @@ def test_text_fill_color(self): filename = "text_fill_color" create_test_from_filename(filename, self) + def test_wrap(self): + """Test complete convert wrap option""" + filename = "rectangle_wrap" + create_test_from_filename(filename, self, wrap=True) + if __name__ == "__main__": unittest.main() diff --git a/tests/testfiles/rectangle_wrap.svg b/tests/testfiles/rectangle_wrap.svg new file mode 100644 index 0000000..94b47b7 --- /dev/null +++ b/tests/testfiles/rectangle_wrap.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + diff --git a/tests/testfiles/rectangle_wrap.tex b/tests/testfiles/rectangle_wrap.tex new file mode 100644 index 0000000..44805b8 --- /dev/null +++ b/tests/testfiles/rectangle_wrap.tex @@ -0,0 +1,35 @@ + +\documentclass{article} +\usepackage[utf8]{inputenc} +\usepackage{tikz} + +\begin{document} +\definecolor{cc2a2f2}{RGB}{194,162,242} +\definecolor{ccdf4c8}{RGB}{205,244,200} + + +\def \globalscale {1.000000} +\begin{tikzpicture}[y=1cm, x=1cm, yscale=\globalscale,xscale=\globalscale, inner sep=0pt, outer sep=0pt] + \path[draw=black,line cap=,line width=0.2cm] (0.7985, 28.9408) rectangle + (5.0753, 27.1111); + + + + \path[draw=black,line cap=,line width=0.2cm,rounded corners=1.4343cm] (0.7985, + 25.8962) rectangle (5.0753, 24.0665); + + + + \path[draw=black,line cap=,line width=0.2cm,rounded corners=0.644cm] (7.5137, + 28.9408) rectangle (11.7905, 27.1111); + + + + \path[draw=cc2a2f2,fill=ccdf4c8,line cap=,line width=0.2cm] (7.5137, 25.8962) + rectangle (11.7905, 24.0665); + + + + +\end{tikzpicture} +\end{document}