diff --git a/CHANGELOG.md b/CHANGELOG.md index 671a050..4e86788 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## [0.7.2] - [unreleased] + +### Fixed + +- Fix bug in `LayoutEngine.calculate(...)` when processing char objects with len>1 representations, such as ligatures. ([#683](https://github.com/jsvine/pdfplumber/issues/683)) + ## [0.7.1] - 2022-05-31 ### Fixed diff --git a/pdfplumber/utils.py b/pdfplumber/utils.py index 7d20d16..c6d6159 100644 --- a/pdfplumber/utils.py +++ b/pdfplumber/utils.py @@ -450,7 +450,8 @@ class LayoutEngine: num_spaces_prepend = max(min(1, line_len), round(x_dist) - line_len) rendered += [(" ", None)] * num_spaces_prepend for c in chars: - rendered.append((c["text"], c)) + for letter in c["text"]: + rendered.append((letter, c)) line_len += num_spaces_prepend + len(word["text"]) return rendered diff --git a/tests/test_issues.py b/tests/test_issues.py index decf563..10c1571 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -198,3 +198,19 @@ class Test(unittest.TestCase): with pdfplumber.open(path) as pdf: annots = pdf.annots annots[0]["contents"] == "日本語" + + def test_issue_683(self): + """ + Page.search ValueError: min() arg is an empty sequence + + This ultimately stemmed from a mistaken assumption in + LayoutEngine.calculate(...) that len(char["text"]) would always equal + 1, which is not true for ligatures. Issue 683 does not provide a PDF, + but the test PDF triggers the same error, which should now be fixed. + + Thank you to @samkit-jain for identifying and writing this test. + """ + path = os.path.join(HERE, "pdfs/issue-71-duplicate-chars-2.pdf") + with pdfplumber.open(path) as pdf: + page = pdf.pages[0] + page.search(r"\d+", regex=True)