Skip to content
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

Drop a redundant final 'l' operator to recognize rectangles #1066

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Using absolute instead of relative imports ([[#995](https://github.com/pdfminer/pdfminer.six/pull/995)])
- Remove redundant line to be able to recognize rectangles ([#1066](https://github.com/pdfminer/pdfminer.six/pull/1066))

### Deprecated

Expand Down
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 a redundant "l" on a path closed with "h"
if len(shape) > 3 and shape[-2:] == "lh" and pts[-2] == pts[0]:
shape = shape[:-2] + "h"
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
Loading