Skip to content

Commit ce8d3cd

Browse files
authored
Fixes #414 - Do not convert explicit M/m path operators to L/l (#416)
Thanks!
1 parent ed1ab7f commit ce8d3cd

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
ChangeLog
44
=========
55

6+
Unreleased
7+
----------
8+
- Fixed a SVG path interpretation bug with two successive M or m commands
9+
(#414).
10+
611
1.6.0 (2025-09-25)
712
------------------
813
- Replace setup.py with pyproject.toml, rework GitHub workflows (#405).

src/svglib/utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def normalise_svg_path(attr: str) -> List[Union[str, List[float]]]:
128128
['m', [100.0, 200.0], 'l', [300.0, 400.0]]
129129
130130
Note:
131-
- Converts sequences of M/m commands to M/m followed by L/l commands
132131
- Handles all SVG path commands: M, L, H, V, C, c, S, s, Q, q, T, t, A, a, Z, z
133132
- Supports various whitespace and comma separators
134133
- All coordinates are converted to float values
@@ -159,22 +158,14 @@ def normalise_svg_path(attr: str) -> List[Union[str, List[float]]]:
159158
}
160159
op_keys = ops.keys()
161160

162-
# do some preprocessing
163161
result: List[Union[str, List[float]]] = []
164162
groups = re.split("([achlmqstvz])", attr.strip(), flags=re.I)
165163
op = ""
166164
for item in groups:
167165
if item.strip() == "":
168166
continue
169167
if item in op_keys:
170-
# fix sequences of M to one M plus a sequence of L operators,
171-
# same for m and l.
172-
if item == "M" and op == "M":
173-
op = "L"
174-
elif item == "m" and op == "m":
175-
op = "l"
176-
else:
177-
op = item
168+
op = item
178169
if ops[op] == 0: # Z, z
179170
result.extend([op, []])
180171
else:

tests/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_path_normalisation(self):
128128
[
129129
"M",
130130
[10, 20],
131-
"L",
131+
"M",
132132
[30, 40],
133133
"L",
134134
[40, 40],
@@ -144,7 +144,7 @@ def test_path_normalisation(self):
144144
),
145145
(
146146
" m 10 20, m 30 40, l 40 40, z",
147-
["m", [10, 20], "l", [30, 40], "l", [40, 40], "z", []],
147+
["m", [10, 20], "m", [30, 40], "l", [40, 40], "z", []],
148148
),
149149
(
150150
" m 10,20 30,40, l 40 40, z ",

0 commit comments

Comments
 (0)