MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_remove_rotation

Function test_remove_rotation

tests/test_remove-rotation.py:8–30  ·  view source on GitHub ↗

Remove rotation verifying identical appearance and text.

()

Source from the content-addressed store, hash-verified

6
7
8def test_remove_rotation():
9 """Remove rotation verifying identical appearance and text."""
10 filename = os.path.join(scriptdir, "resources", "test-2812.pdf")
11 doc = pymupdf.open(filename)
12
13 # We always create fresh pages to avoid false positives from cache content.
14 # Text on these pages consists of pairwise different strings, sorting by
15 # these strings must therefore yield identical bounding boxes.
16 for i in range(1, doc.page_count):
17 assert doc[i].rotation # must be a rotated page
18 pix0 = doc[i].get_pixmap() # make image
19 words0 = []
20 for w in doc[i].get_text("words"):
21 words0.append(list(pymupdf.Rect(w[:4]) * doc[i].rotation_matrix) + [w[4]])
22 words0.sort(key=lambda w: w[4]) # sort by word strings
23 # derotate page and confirm nothing else has changed
24 doc[i].remove_rotation()
25 assert doc[i].rotation == 0
26 pix1 = doc[i].get_pixmap()
27 words1 = doc[i].get_text("words")
28 words1.sort(key=lambda w: w[4]) # sort by word strings
29 assert pix1.digest == pix0.digest, f"{pix1.digest}/{pix0.digest}"
30 assert gentle_compare(words0, words1)

Callers

nothing calls this directly

Calls 5

gentle_compareFunction · 0.90
remove_rotationMethod · 0.80
get_pixmapMethod · 0.45
get_textMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…