use new snake_case naming for pymupdf 1.19.0 and later

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-06-26 22:59:11 +01:00 committed by Johannes Schauer Marin Rodrigues
parent 9bf02315aa
commit c50b44a3a0

View file

@ -326,15 +326,22 @@ class Plakativ:
return len(self.doc) return len(self.doc)
def get_input_page_size(self): def get_input_page_size(self):
width = self.doc[self.pagenr].getDisplayList().rect.width # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
height = self.doc[self.pagenr].getDisplayList().rect.height if hasattr(self.doc[self.pagenr], "get_displaylist"):
return (width, height) gdl = self.doc[self.pagenr].get_displaylist
else:
gdl = self.doc[self.pagenr].getDisplayList
rect = gdl().rect
return (rect.width, rect.height)
def get_image(self, zoom): def get_image(self, zoom):
mat_0 = fitz.Matrix(zoom, zoom) mat_0 = fitz.Matrix(zoom, zoom)
pix = ( # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
self.doc[self.pagenr].getDisplayList().getPixmap(matrix=mat_0, alpha=False) if hasattr(self.doc[self.pagenr], "get_displaylist"):
) gdl = self.doc[self.pagenr].get_displaylist
else:
gdl = self.doc[self.pagenr].getDisplayList
pix = gdl().getPixmap(matrix=mat_0, alpha=False)
# the getImageData() function was only introduced in pymupdf 1.14.5 # the getImageData() function was only introduced in pymupdf 1.14.5
if hasattr(pix, "getImageData"): if hasattr(pix, "getImageData"):
return pix.getImageData("ppm") return pix.getImageData("ppm")
@ -369,8 +376,14 @@ class Plakativ:
printable_height = self.layout["output_pagesize"][1] - ( printable_height = self.layout["output_pagesize"][1] - (
border_top + border_bottom border_top + border_bottom
) )
inpage_width = pt_to_mm(self.doc[self.pagenr].getDisplayList().rect.width) # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
inpage_height = pt_to_mm(self.doc[self.pagenr].getDisplayList().rect.height) if hasattr(self.doc[self.pagenr], "get_displaylist"):
gdl = self.doc[self.pagenr].get_displaylist
else:
gdl = self.doc[self.pagenr].getDisplayList
rect = gdl().rect
inpage_width = pt_to_mm(rect.width)
inpage_height = pt_to_mm(rect.height)
if mode in ["size", "mult"]: if mode in ["size", "mult"]:
if mode == "size": if mode == "size":
@ -625,7 +638,12 @@ class Plakativ:
if not hasattr(self, "layout"): if not hasattr(self, "layout"):
raise LayoutNotComputedException() raise LayoutNotComputedException()
inpage_width = pt_to_mm(self.doc[self.pagenr].getDisplayList().rect.width) # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
if hasattr(self.doc[self.pagenr], "get_displaylist"):
gdl = self.doc[self.pagenr].get_displaylist
else:
gdl = self.doc[self.pagenr].getDisplayList
inpage_width = pt_to_mm(gdl().rect.width)
outdoc = fitz.open() outdoc = fitz.open()
@ -644,7 +662,13 @@ class Plakativ:
) )
/ (self.layout["overallsize"][1]), / (self.layout["overallsize"][1]),
) )
page = outdoc.newPage( # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
if hasattr(outdoc, "new_page"):
np = outdoc.new_page
else:
np = outdoc.newPage
page = np(
-1, # insert after last page -1, # insert after last page
width=mm_to_pt(self.layout["output_pagesize"][0]), width=mm_to_pt(self.layout["output_pagesize"][0]),
height=mm_to_pt(self.layout["output_pagesize"][1]), height=mm_to_pt(self.layout["output_pagesize"][1]),
@ -674,6 +698,9 @@ class Plakativ:
bottom = self.layout["border_right"] * zoom_1 bottom = self.layout["border_right"] * zoom_1
left = self.layout["border_bottom"] * zoom_1 left = self.layout["border_bottom"] * zoom_1
# inner rectangle # inner rectangle
if hasattr(page, "new_shape"):
shape = page.new_shape()
else:
shape = page.newShape() shape = page.newShape()
shape.drawRect( shape.drawRect(
fitz.Rect( fitz.Rect(
@ -714,7 +741,12 @@ class Plakativ:
else: else:
page_width = mm_to_pt(self.layout["output_pagesize"][1]) page_width = mm_to_pt(self.layout["output_pagesize"][1])
page_height = mm_to_pt(self.layout["output_pagesize"][0]) page_height = mm_to_pt(self.layout["output_pagesize"][0])
page = outdoc.newPage( # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
if hasattr(outdoc, "new_page"):
np = outdoc.new_page
else:
np = outdoc.newPage
page = np(
-1, width=page_width, height=page_height # insert after last page -1, width=page_width, height=page_height # insert after last page
) )
@ -758,13 +790,21 @@ class Plakativ:
mm_to_pt(factor * (target_y + target_height)), mm_to_pt(factor * (target_y + target_height)),
) )
page.showPDFpage( # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used
if hasattr(page, "show_pdf_page"):
spp = page.show_pdf_page
else:
spp = page.showPDFpage
spp(
targetrect, # fill the whole page targetrect, # fill the whole page
self.doc, # input document self.doc, # input document
self.pagenr, # input page number self.pagenr, # input page number
clip=sourcerect, # part of the input page to use clip=sourcerect, # part of the input page to use
) )
if hasattr(page, "new_shape"):
shape = page.new_shape()
else:
shape = page.newShape() shape = page.newShape()
if guides: if guides:
if portrait: if portrait: