use new snake_case naming for pymupdf 1.19.0 and later
This commit is contained in:
parent
9bf02315aa
commit
c50b44a3a0
1 changed files with 54 additions and 14 deletions
64
plakativ.py
64
plakativ.py
|
@ -326,15 +326,22 @@ class Plakativ:
|
|||
return len(self.doc)
|
||||
|
||||
def get_input_page_size(self):
|
||||
width = self.doc[self.pagenr].getDisplayList().rect.width
|
||||
height = self.doc[self.pagenr].getDisplayList().rect.height
|
||||
return (width, height)
|
||||
# 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
|
||||
rect = gdl().rect
|
||||
return (rect.width, rect.height)
|
||||
|
||||
def get_image(self, zoom):
|
||||
mat_0 = fitz.Matrix(zoom, zoom)
|
||||
pix = (
|
||||
self.doc[self.pagenr].getDisplayList().getPixmap(matrix=mat_0, alpha=False)
|
||||
)
|
||||
# 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
|
||||
pix = gdl().getPixmap(matrix=mat_0, alpha=False)
|
||||
# the getImageData() function was only introduced in pymupdf 1.14.5
|
||||
if hasattr(pix, "getImageData"):
|
||||
return pix.getImageData("ppm")
|
||||
|
@ -369,8 +376,14 @@ class Plakativ:
|
|||
printable_height = self.layout["output_pagesize"][1] - (
|
||||
border_top + border_bottom
|
||||
)
|
||||
inpage_width = pt_to_mm(self.doc[self.pagenr].getDisplayList().rect.width)
|
||||
inpage_height = pt_to_mm(self.doc[self.pagenr].getDisplayList().rect.height)
|
||||
# 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
|
||||
rect = gdl().rect
|
||||
inpage_width = pt_to_mm(rect.width)
|
||||
inpage_height = pt_to_mm(rect.height)
|
||||
|
||||
if mode in ["size", "mult"]:
|
||||
if mode == "size":
|
||||
|
@ -625,7 +638,12 @@ class Plakativ:
|
|||
if not hasattr(self, "layout"):
|
||||
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()
|
||||
|
||||
|
@ -644,7 +662,13 @@ class Plakativ:
|
|||
)
|
||||
/ (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
|
||||
width=mm_to_pt(self.layout["output_pagesize"][0]),
|
||||
height=mm_to_pt(self.layout["output_pagesize"][1]),
|
||||
|
@ -674,6 +698,9 @@ class Plakativ:
|
|||
bottom = self.layout["border_right"] * zoom_1
|
||||
left = self.layout["border_bottom"] * zoom_1
|
||||
# inner rectangle
|
||||
if hasattr(page, "new_shape"):
|
||||
shape = page.new_shape()
|
||||
else:
|
||||
shape = page.newShape()
|
||||
shape.drawRect(
|
||||
fitz.Rect(
|
||||
|
@ -714,7 +741,12 @@ class Plakativ:
|
|||
else:
|
||||
page_width = mm_to_pt(self.layout["output_pagesize"][1])
|
||||
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
|
||||
)
|
||||
|
||||
|
@ -758,13 +790,21 @@ class Plakativ:
|
|||
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
|
||||
self.doc, # input document
|
||||
self.pagenr, # input page number
|
||||
clip=sourcerect, # part of the input page to use
|
||||
)
|
||||
|
||||
if hasattr(page, "new_shape"):
|
||||
shape = page.new_shape()
|
||||
else:
|
||||
shape = page.newShape()
|
||||
if guides:
|
||||
if portrait:
|
||||
|
|
Loading…
Reference in a new issue