-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Is there already, or in the future, can there be a convenience/helper function for calculation 'clip' Rect in getPixmap ?
GetPixmap(Matrix matrix: Identity, int dpi: 0, string colorSpace: "RGB", Rect clip: null, bool alpha: false, bool annots: true)
From
https://mupdfnet.readthedocs.io/en/latest/classes/Page.html#Page.GetPixmap
- clip (IRect) – restrict rendering to the intersection of this area with the page’s rectangle
I searched the docs and utils at https://mupdfnet.readthedocs.io/en/latest/glossary/Utils.html
The cliprectangle must be in the page coordinate space - makes sense.
However that coordinate space can be nasty for humans, with non-normalized rectangles, negative cropbox origins, and page rotation (0,90,180,270).
If someone wants to extract a partial corner image (as pixmap) from any pdf, the way it is displayed in a viewer, calculating the proper clip coordinate Rect is quite an effort. For every possible page rotation the page cropbox x0,y0 and x1,y1 coordinates need to be related to the clipsize (width/heigth) depending on rotation.
Could there be a convenience function on the Page object like
Rect cornerclip = Page.GetCornerClip(CornerEnum C, SizeF Cornersize);
CornerEnum: NE, NW, SE, SW, C (the 4 corners as shown in a any viewer plus 'C' for Center)
Cornersize: desired clip region, width (horizontal) and heigth (vertical)
Returns: cornerclip Rect with proper coordinates calculated based on Page cropbox and rotation.
and even better, with an overload to offset that clip on viewer X,Y axis coordinate space.
If cropbox origin is at 0,0 and page rotation = 0 it is easy...anything else gets tricky
Rect clip = Rect(cropbox.X1 - clipsize.Width, cropbox.Y1 - clipsize.Height, cropbox.X1, cropbox.Y1);
Working in Page coordinate space is of course mandatory for the low level library, but humans work better with coordinate systems that they can see visually.
Best Regards