Prefer pikepdf's newer Page.mediabox accessor over .MediaBox
This commit is contained in:
@@ -248,10 +248,10 @@ class OcrGrafter:
|
||||
# content may have a rotation applied. Wrap the text stream with a rotation
|
||||
# so it will be oriented the same way as the rest of the page content.
|
||||
# (Previous versions OCRmyPDF rotated the content layer to match the text.)
|
||||
mediabox = [float(pdf_text.pages[0].MediaBox[v]) for v in range(4)]
|
||||
mediabox = pdf_text.pages[0].mediabox
|
||||
wt, ht = mediabox[2] - mediabox[0], mediabox[3] - mediabox[1]
|
||||
|
||||
mediabox = [float(base_page.MediaBox[v]) for v in range(4)]
|
||||
mediabox = base_page.mediabox
|
||||
wp, hp = mediabox[2] - mediabox[0], mediabox[3] - mediabox[1]
|
||||
|
||||
translate = PdfMatrix().translated(-wt / 2, -ht / 2)
|
||||
|
||||
@@ -828,7 +828,7 @@ class PageInfo:
|
||||
detailed_analysis: bool,
|
||||
):
|
||||
page: Page = pdf.pages[pageno]
|
||||
mediabox = [Decimal(d) for d in page.MediaBox.as_list()]
|
||||
mediabox = [Decimal(d) for d in page.mediabox.as_list()]
|
||||
width_pt = mediabox[2] - mediabox[0]
|
||||
height_pt = mediabox[3] - mediabox[1]
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ def francais(resources):
|
||||
|
||||
def test_rasterize_size(francais, outdir):
|
||||
path, pdf = francais
|
||||
page_size_pts = (pdf.pages[0].MediaBox[2], pdf.pages[0].MediaBox[3])
|
||||
assert pdf.pages[0].MediaBox[0] == pdf.pages[0].MediaBox[1] == 0
|
||||
page_size_pts = (pdf.pages[0].mediabox[2], pdf.pages[0].mediabox[3])
|
||||
assert pdf.pages[0].mediabox[0] == pdf.pages[0].mediabox[1] == 0
|
||||
page_size = (page_size_pts[0] / Decimal(72), page_size_pts[1] / Decimal(72))
|
||||
target_size = Decimal('50.0'), Decimal('30.0')
|
||||
forced_dpi = Resolution(42.0, 4242.0)
|
||||
@@ -52,8 +52,8 @@ def test_rasterize_size(francais, outdir):
|
||||
|
||||
def test_rasterize_rotated(francais, outdir, caplog):
|
||||
path, pdf = francais
|
||||
page_size_pts = (pdf.pages[0].MediaBox[2], pdf.pages[0].MediaBox[3])
|
||||
assert pdf.pages[0].MediaBox[0] == pdf.pages[0].MediaBox[1] == 0
|
||||
page_size_pts = (pdf.pages[0].mediabox[2], pdf.pages[0].mediabox[3])
|
||||
assert pdf.pages[0].mediabox[0] == pdf.pages[0].mediabox[1] == 0
|
||||
page_size = (page_size_pts[0] / Decimal(72), page_size_pts[1] / Decimal(72))
|
||||
target_size = Decimal('50.0'), Decimal('30.0')
|
||||
forced_dpi = Resolution(42.0, 4242.0)
|
||||
|
||||
@@ -321,15 +321,15 @@ def test_simulated_scan(outdir):
|
||||
|
||||
with pikepdf.open(outdir / 'out.pdf') as pdf:
|
||||
assert (
|
||||
pdf.pages[1].MediaBox[2] > pdf.pages[1].MediaBox[3]
|
||||
pdf.pages[1].mediabox[2] > pdf.pages[1].mediabox[3]
|
||||
), "Wrong orientation: not landscape"
|
||||
assert (
|
||||
pdf.pages[3].MediaBox[2] > pdf.pages[3].MediaBox[3]
|
||||
pdf.pages[3].mediabox[2] > pdf.pages[3].mediabox[3]
|
||||
), "Wrong orientation: Not landscape"
|
||||
|
||||
assert (
|
||||
pdf.pages[0].MediaBox[2] < pdf.pages[0].MediaBox[3]
|
||||
pdf.pages[0].mediabox[2] < pdf.pages[0].mediabox[3]
|
||||
), "Wrong orientation: Not portrait"
|
||||
assert (
|
||||
pdf.pages[2].MediaBox[2] < pdf.pages[2].MediaBox[3]
|
||||
pdf.pages[2].mediabox[2] < pdf.pages[2].mediabox[3]
|
||||
), "Wrong orientation: Not portrait"
|
||||
|
||||
Reference in New Issue
Block a user