From 05c2dde477896f1c3915a7142506ed5e1a89b90c Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Tue, 16 May 2017 19:44:09 +0200 Subject: [PATCH] Also preserve empty path segments if stroke-linecap is square This was implemented for round linecaps in 6c50c78d99c9ac474c5ca29616263eebf87022d4 but applies to square linecaps, too (only butt is not rendered). See https://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes for details. --- scour/scour.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index 29a3bb2..89e6c3f 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -2045,9 +2045,9 @@ def cleanPath(element, options): oldPathStr = element.getAttribute('d') path = svg_parser.parse(oldPathStr) - # This determines whether the stroke has round linecaps. If it does, - # we do not want to collapse empty segments, as they are actually rendered. - withRoundLineCaps = element.getAttribute('stroke-linecap') == 'round' + # This determines whether the stroke has round or square linecaps. If it does, we do not want to collapse empty + # segments, as they are actually rendered (as circles or squares with diameter/dimension matching the path-width). + has_round_or_square_linecaps = element.getAttribute('stroke-linecap') in ['round', 'square'] # This determines whether the stroke has intermediate markers. If it does, we do not want to collapse # straight segments running in the same direction, as markers are rendered on the intermediate nodes. @@ -2162,7 +2162,7 @@ def cleanPath(element, options): # remove empty segments # Reuse the data structure 'path' and the coordinate lists, even if we're # deleting items, because these deletions are relatively cheap. - if not withRoundLineCaps: + if not has_round_or_square_linecaps: for pathIndex in range(0, len(path)): cmd, data = path[pathIndex] i = 0