Skip to content

Commit

Permalink
fix: drop redundant final h to recognize rectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Nov 25, 2024
1 parent 1a8bd2f commit 28463f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def paint_path(
for o, p in zip(operators, transformed_points)
]

# Drop redundant final "h" on an already closed path
if len(shape) > 3 and shape[-1] == "h" and pts[-2] == pts[0]:
shape = shape[:-1]
pts.pop()

if shape in {"mlh", "ml"}:
# single line segment
#
Expand Down
12 changes: 12 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ def get_types(path):
],
) == [LTRect]

# Same but mllllh variation
assert get_types(
[
("m", 10, 90),
("l", 90, 90),
("l", 90, 10),
("l", 10, 10),
("l", 10, 90),
('h',)
],
) == [LTRect]

# Bowtie shape
assert get_types(
[
Expand Down

0 comments on commit 28463f2

Please sign in to comment.