Skip to content

Commit

Permalink
fix: screen space origin is *top* of mediabox not height!
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Nov 24, 2024
1 parent ea3a319 commit e7a5a2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion playa/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def __init__(
#
# "screen" device space: origin is top left of MediaBox
if page.space == "screen":
ctm = (1.0, 0.0, 0.0, -1.0, -x0, height)
ctm = (1.0, 0.0, 0.0, -1.0, -x0, y1)
# "page" device space: origin is bottom left of MediaBox
elif page.space == "page":
ctm = (1.0, 0.0, 0.0, 1.0, -x0, -y0)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@ def test_write_csv() -> None:

def test_spaces() -> None:
"""Test different coordinate spaces."""
with playa.open(TESTDIR / "pdfplumber" / "issue-1181.pdf") as doc:
page = doc.pages[0]
screen_box = next(page.objects).bbox
with playa.open(TESTDIR / "pdfplumber" / "issue-1181.pdf", space="page") as doc:
page = doc.pages[0]
page_box = next(page.objects).bbox
with playa.open(TESTDIR / "pdfplumber" / "issue-1181.pdf", space="user") as doc:
page = doc.pages[0]
user_box = next(page.objects).bbox
print(screen_box)
print(page_box)
print(user_box)
assert page_box[1] == pytest.approx(user_box[1] - page.mediabox[1])
with playa.open(TESTDIR / "pdfplumber" / "issue-1181.pdf", space="screen") as doc:
page = doc.pages[0]
screen_box = next(page.objects).bbox
# BBoxes are normalied, so top is 1 for screen and 3 for page
assert screen_box[3] == pytest.approx(page.height - page_box[1])
assert screen_box[3] == pytest.approx(page.height - page_box[1])


if __name__ == "__main__":
Expand Down

0 comments on commit e7a5a2a

Please sign in to comment.