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

Function test_2736

tests/test_general.py:746–774  ·  view source on GitHub ↗

Check handling of CropBox changes vis-a-vis a MediaBox with negative coordinates.

()

Source from the content-addressed store, hash-verified

744
745
746def test_2736():
747 """Check handling of CropBox changes vis-a-vis a MediaBox with
748 negative coordinates."""
749 doc = pymupdf.open()
750 page = doc.new_page()
751
752 # fake a MediaBox for demo purposes
753 doc.xref_set_key(page.xref, "MediaBox", "[-30 -20 595 842]")
754
755 assert page.cropbox == pymupdf.Rect(-30, 0, 595, 862)
756 assert page.rect == pymupdf.Rect(0, 0, 625, 862)
757
758 # change the CropBox: shift by (10, 10) in both dimensions. Please note:
759 # To achieve this, 10 must be subtracted from 862! yo must never be negative!
760 page.set_cropbox(pymupdf.Rect(-20, 0, 595, 852))
761
762 # get CropBox from the page definition
763 assert doc.xref_get_key(page.xref, "CropBox")[1] == "[-20 -10 595 842]"
764 assert page.rect == pymupdf.Rect(0, 0, 615, 852)
765
766 error = False
767 text = ""
768 try: # check error detection
769 page.set_cropbox((-35, -10, 595, 842))
770 except Exception as e:
771 text = str(e)
772 error = True
773 assert error == True
774 assert text == "CropBox not in MediaBox"
775
776
777def test_subset_fonts():

Callers

nothing calls this directly

Calls 4

new_pageMethod · 0.80
xref_set_keyMethod · 0.80
set_cropboxMethod · 0.80
xref_get_keyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…