Skip to content

More marker fixes #307

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions cairosvg/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ def preserve_ratio(surface, node, width=None, height=None):
return scale_x, scale_y, translate_x, translate_y


def bezier_angles(*points):
"""Return the tangent angles of a Bezier curve of any degree."""
if len(points) < 2:
# zero-length segment
return (0, 0)
# Control points that coincide with vertices can be removed
elif points[0] == points[1]:
return bezier_angles(*points[1:])
elif points[-2] == points[-1]:
return bezier_angles(*points[:-1])
else:
return (point_angle(*points[0], *points[1]), point_angle(*points[-2], *points[-1]))


def clip_marker_box(surface, node, scale_x, scale_y):
"""Get the clip ``(x, y, width, height)`` of the marker box."""
width = size(surface, node.get('markerWidth', '3'), 'x')
Expand Down
Loading