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

Fix regression in page layout that sometimes returned text lines out of order #659

Merged
merged 10 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `PermissionError` when creating temporary filepaths on windows when running tests ([#469](https://github.com/pdfminer/pdfminer.six/issues/469))
- Detecting trailer correctly when surrounded with needless whitespace ([#535](https://github.com/pdfminer/pdfminer.six/pull/535))
- Fix `.paint_path` logic for handling single line segments and extracting point-on-curve positions of Beziér path commands ([#530](https://github.com/pdfminer/pdfminer.six/pull/530))
- Fix regression in `LTLayoutContainer.group_textboxes` (introduced in 20191107) that sometimes returned text lines out of order ([#659](https://github.com/pdfminer/pdfminer.six/pull/659))

## Removed
- Support for Python 3.4 and 3.5 ([#522](https://github.com/pdfminer/pdfminer.six/pull/522))
Expand Down
2 changes: 1 addition & 1 deletion pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def isany(obj1, obj2):
(skip_isany, d, id1, id2, obj1, obj2) = heapq.heappop(dists)
# Skip objects that are already merged
if (id1 not in done) and (id2 not in done):
if skip_isany and isany(obj1, obj2):
if not skip_isany and isany(obj1, obj2):
heapq.heappush(dists, (True, d, id1, id2, obj1, obj2))
continue
if isinstance(obj1, (LTTextBoxVertical, LTTextGroupTBRL)) or \
Expand Down
Binary file added samples/simple5.pdf
Binary file not shown.
16 changes: 15 additions & 1 deletion tests/test_highlevel_extracttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def run_with_file(sample_path):
"simple2.pdf": "\f",
"simple3.pdf": "Hello\n\nHello\nあ\nい\nう\nえ\nお\nあ\nい\nう\nえ\nお\n"
"World\n\nWorld\n\n\f",
"simple4.pdf": "Text1\nText2\nText3\n\n\f"
"simple4.pdf": "Text1\nText2\nText3\n\n\f",
"simple5.pdf": "Heading\n\n"
"Link to heading that is working with vim-pandoc.\n\n"
"Link to heading “that is” not working with vim-pandoc.\n\n"
"Subheading\n\nSome “more text”\n\n1\n\n\f"
}


Expand Down Expand Up @@ -60,6 +64,11 @@ def test_simple4_with_string(self):
s = run_with_string(test_file)
self.assertEqual(s, test_strings[test_file])

def test_simple5_with_string(self):
test_file = "simple5.pdf"
s = run_with_string(test_file)
self.assertEqual(s, test_strings[test_file])

def test_simple1_with_file(self):
test_file = "simple1.pdf"
s = run_with_file(test_file)
Expand All @@ -80,6 +89,11 @@ def test_simple4_with_file(self):
s = run_with_file(test_file)
self.assertEqual(s, test_strings[test_file])

def test_simple5_with_file(self):
test_file = "simple5.pdf"
s = run_with_file(test_file)
self.assertEqual(s, test_strings[test_file])


class TestExtractPages(unittest.TestCase):
def _get_test_file_path(self):
Expand Down