Skip to content

Commit

Permalink
test 2957
Browse files Browse the repository at this point in the history
Test fix of 2957.

We are using the problem file of issue 2957 and confirm in a hardcoded way that the left over strings in the line do not change positions when applying the redactions.
  • Loading branch information
JorjMcKie authored and julian-smith-artifex-com committed Jan 10, 2024
1 parent a23bf69 commit 64e253c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Binary file added tests/resources/pre-redacted.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,30 @@ def test_subset_fonts():
found = True
break
assert found is True


def test_2957():
# test file with redactions
doc = fitz.open(os.path.join(scriptdir, "resources", "pre-redacted.pdf"))
page = doc[0]
# search for string that must not move by redactions
rects0 = page.search_for("6e9f73dfb4384a2b8af6ebba")
# sort rectangles vertically
rects0 = sorted(rects0, key=lambda r: r.y1)
assert len(rects0) == 2 # must be 2 redactions
page.apply_redactions()

# reload page to finalize updates
page = doc.reload_page(page)

# the two string must retain their positions (except rounding errors)
rects1 = page.search_for("6e9f73dfb4384a2b8af6ebba")
rects1 = sorted(rects1, key=lambda r: r.y1)

assert page.first_annot is None # make sure annotations have disappeared
for i in range(2):
r0 = rects0[i].irect # take rounded rects
r1 = rects1[i].irect
assert r0 == r1


0 comments on commit 64e253c

Please sign in to comment.