From 1979e340e630af941ddc07230f50a318d0cf67c9 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 16 Nov 2022 10:55:35 +0000 Subject: [PATCH] fitz/utils.py: fix #2051, added `dpi` arg in get_page_pixmap() 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. --- fitz/utils.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fitz/utils.py b/fitz/utils.py index 3c9aebf85..154ca9e33 100644 --- a/fitz/utils.py +++ b/fitz/utils.py @@ -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: @@ -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": @@ -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, @@ -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 )