Skip to content

Commit

Permalink
fitz/utils.py: fix pymupdf#2051, added dpi arg in get_page_pixmap()…
Browse files Browse the repository at this point in the history
… and require keyword-only args.

In `get_pixmap()`, use Python's special `*` arg to force args to be
keyword-only instead of enforcing this in the code.

In `get_page_pixmap()`, also use Python's special `*` arg to force args
to be keyword-only. This makes the fn conform to the documentation in
docs/document.rst, but could break code that used to use non-keyword args.
  • Loading branch information
julian-smith-artifex-com committed Nov 16, 2022
1 parent 824be2e commit 1979e34
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions fitz/utils.py
Expand Up @@ -809,7 +809,16 @@ def get_page_text(
return doc[pno].get_text(option, clip=clip, flags=flags, sort=sort)


def get_pixmap(page: Page, *args, **kw) -> Pixmap:
def get_pixmap(
page: Page,
*,
matrix: matrix_like=Identity,
dpi=None,
colorspace: Colorspace=csRGB,
clip: rect_like=None,
alpha: bool=False,
annots: bool=True,
) -> Pixmap:
"""Create pixmap of page.
Keyword args:
Expand All @@ -820,18 +829,10 @@ def get_pixmap(page: Page, *args, **kw) -> Pixmap:
alpha: (bool) whether to include alpha channel
annots: (bool) whether to also render annotations
"""
if args:
raise ValueError("method accepts keywords only")
CheckParent(page)
matrix = kw.get("matrix", Identity)
dpi = kw.get("dpi", None)
if dpi:
zoom = dpi / 72
matrix = Matrix(zoom, zoom)
colorspace = kw.get("colorspace", csRGB)
clip = kw.get("clip")
alpha = bool(kw.get("alpha", False))
annots = bool(kw.get("annots", True))

if type(colorspace) is str:
if colorspace.upper() == "GRAY":
Expand All @@ -854,7 +855,9 @@ def get_pixmap(page: Page, *args, **kw) -> Pixmap:
def get_page_pixmap(
doc: Document,
pno: int,
*,
matrix: matrix_like = Identity,
dpi=None,
colorspace: Colorspace = csRGB,
clip: rect_like = None,
alpha: bool = False,
Expand All @@ -873,7 +876,7 @@ def get_page_pixmap(
annots: (bool) also render annotations
"""
return doc[pno].get_pixmap(
matrix=matrix, colorspace=colorspace, clip=clip, alpha=alpha, annots=annots
matrix=matrix, dpi=dpi, colorspace=colorspace, clip=clip, alpha=alpha, annots=annots
)


Expand Down

0 comments on commit 1979e34

Please sign in to comment.