Skip to content

Commit 8c82767

Browse files
committed
Do not double the pattern length
1 parent ee6769a commit 8c82767

2 files changed

Lines changed: 1 addition & 22 deletions

File tree

Tests/test_imagedraw.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,20 +1783,6 @@ def test_line_dash_multi_segment() -> None:
17831783
assert im.getbbox() is not None
17841784

17851785

1786-
def test_line_dash_odd_pattern() -> None:
1787-
# An odd-length dash pattern should be doubled per SVG spec
1788-
im = Image.new("RGB", (W, H))
1789-
draw = ImageDraw.Draw(im)
1790-
draw.line([(10, 50), (90, 50)], "yellow", 2, dash=(10,))
1791-
1792-
expected = Image.new("RGB", (W, H))
1793-
draw2 = ImageDraw.Draw(expected)
1794-
draw2.line([(10, 50), (90, 50)], "yellow", 2, dash=(10, 10))
1795-
1796-
# odd pattern (10,) becomes (10, 10)
1797-
assert_image_equal(im, expected)
1798-
1799-
18001786
def test_line_dash_empty() -> None:
18011787
im = Image.new("RGB", (W, H))
18021788
draw = ImageDraw.Draw(im)

src/PIL/ImageDraw.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ def line(
315315
if len(dash) == 0:
316316
msg = "dash must be a non-empty tuple of ints"
317317
raise ValueError(msg)
318-
# If odd number of elements, double the pattern per SVG spec
319-
if len(dash) % 2 != 0:
320-
dash *= 2
321318
points = self._normalize_points(xy)
322319
dash_offset = 0
323320
for i in range(len(points) - 1):
@@ -440,8 +437,6 @@ def polygon(
440437
if len(dash) == 0:
441438
msg = "dash must be a non-empty tuple of ints"
442439
raise ValueError(msg)
443-
if len(dash) % 2 != 0:
444-
dash *= 2
445440
points = self._normalize_points(xy)
446441
# Close the polygon by connecting last point to first
447442
if points[0] != points[-1]:
@@ -503,10 +498,8 @@ def rectangle(
503498
(x0, y1),
504499
(x0, y0),
505500
]
506-
if len(dash) % 2 != 0:
507-
dash *= 2
508501
dash_offset = 0
509-
for i in range(len(rect_points) - 1):
502+
for i in range(4):
510503
dash_offset = self._draw_dashed_line(
511504
rect_points[i],
512505
rect_points[i + 1],

0 commit comments

Comments
 (0)