diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9a704..e372fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,13 @@ ### Added - Adding info about the dependencies and how to contribute in the README +- Adding test for the arc direction ### Changed ### Deprecated ### Removed ### Fixed - Fixing the latex build of the docs +- Fixing some arc were not rendered correctly by tikz ### Security ## v3.1.0 - 19/05/2024 diff --git a/svg2tikz/tikz_export.py b/svg2tikz/tikz_export.py index 33b71bb..354b8be 100644 --- a/svg2tikz/tikz_export.py +++ b/svg2tikz/tikz_export.py @@ -607,6 +607,23 @@ def _add_booloption(self, parser, *args, **kwargs): kwargs["action"] = "store_true" parser.add_argument(*args, **kwargs) + def sanitize_angles(self, start_raw: float, end_raw: float): + """ + Sanitizes angles from arc to put them in [-360, 360] range + + start_raw: start angle of the arc + end_raw: end angle of the arc + """ + + start_ang = self.round_value(start_raw % 360) + end_ang = self.round_value(end_raw % 360) + # # Does not to seem a problem anymore + if start_raw < end_raw and not start_ang < end_ang: + start_ang -= 360 + elif start_raw > end_raw and not start_ang > end_ang: + end_ang -= 360 + return start_ang, end_ang + def convert_unit(self, value: float) -> float: """Convert value from the user unit to the output unit which is an option""" ret = self.svg.unit_to_viewport(value, self.options.output_unit) @@ -1152,15 +1169,8 @@ def convert_path_to_tikz(self, path): if not self.options.noreversey: r.y *= -1 - # pgf 2.0 does not like angles larger than 360 - # make sure it is in the +- 360 range - start_ang = self.round_value(start_ang_o % 360) - end_ang = self.round_value(end_ang_o % 360) - # # Does not to seem a problem anymore - # if start_ang_o < end_ang_o and not start_ang < end_ang: - # start_ang -= 360 - # elif start_ang_o > end_ang_o and not start_ang > end_ang: - # end_ang -= 360 + # For Pgf 2.0 + start_ang, end_ang = self.sanitize_angles(start_ang_o, end_ang_o) if not self.options.noreversey: command.x_axis_rotation *= -1 diff --git a/tests/test_complete_files.py b/tests/test_complete_files.py index d216c99..3167756 100644 --- a/tests/test_complete_files.py +++ b/tests/test_complete_files.py @@ -164,6 +164,12 @@ def test_attribute_texmode(self): filename, self, texmode="attribute", texmode_attribute="data-texmode" ) + def test_arc_direction(self): + """Test per SVG object texmode with attribute""" + # Exemple taken from svg of the flag of the state of California + filename = "R_letter_with_arc" + create_test_from_filename(filename, self) + if __name__ == "__main__": unittest.main() diff --git a/tests/testfiles/R_letter_with_arc.svg b/tests/testfiles/R_letter_with_arc.svg new file mode 100644 index 0000000..63a961e --- /dev/null +++ b/tests/testfiles/R_letter_with_arc.svg @@ -0,0 +1,47 @@ + + + + + + + + + + diff --git a/tests/testfiles/R_letter_with_arc.tex b/tests/testfiles/R_letter_with_arc.tex new file mode 100644 index 0000000..933a996 --- /dev/null +++ b/tests/testfiles/R_letter_with_arc.tex @@ -0,0 +1,18 @@ + +\documentclass{article} +\usepackage[utf8]{inputenc} +\usepackage{tikz} + +\begin{document} +\definecolor{c584528}{RGB}{88,69,40} + + +\def \globalscale {1.000000} +\begin{tikzpicture}[y=1cm, x=1cm, yscale=\globalscale,xscale=\globalscale, every node/.append style={scale=\globalscale}, inner sep=0pt, outer sep=0pt] + \path[fill=c584528,line width=0.0265cm] (1.139, 27.7421) -- (0.8996, 27.7421) -- (0.8996, 29.065) -- (1.412, 29.065)arc(269.0684:315.4369:0.1347 and -0.1347)arc(-46.43000000000001:0.8173:0.1311 and -0.1311) -- (1.5509, 28.4461)arc(-1.6533999999999764:58.4445:0.1287 and -0.1287)arc(-58.43090000000001:1.6398:0.1288 and -0.1288) -- (1.5509, 27.8781)arc(182.0888:115.7033:0.127 and -0.127) .. controls (1.6278, 27.7559) and (1.6304, 27.7528) .. (1.6304, 27.7497)arc(-8.094499999999982:98.4931:0.0067 and -0.0067) -- (1.459, 27.7421)arc(88.9159:135.3056:0.1339 and -0.1339)arc(133.7122:180.9811:0.1302 and -0.1302) -- (1.3211, 28.2335) -- (1.1391, 28.2335) -- cycle(1.139, 28.4413) -- (1.321, 28.4413) -- (1.321, 28.8288) -- (1.139, 28.8288) -- cycle; + + + + +\end{tikzpicture} +\end{document}