mupdf-rs icon indicating copy to clipboard operation
mupdf-rs copied to clipboard

Completeness / clipping

Open newinnovations opened this issue 6 months ago • 4 comments

This is just to check if my observations are correct and I don't start implementing stuff in a fork that is already there.

Basically I have the need for a variant of Page::to_pixmap that allows for a clipping rectangle for zooming into an area. There doesn't seem to be a utility function in mupdf-c that implements that. In py-mupdf it was added in 2016 (https://github.com/pymupdf/PyMuPDF/issues/54).

I set out to implement the functionality in Rust, but could not find references to functions like fz_transform_rect and fz_round_rect.

My question boils down to:

  • is there a variant of to_pixmap available that allows for a clipping rectangle
  • if not, are the basic mupdf functions required to implement it available through mupdf-rs

newinnovations avatar Jun 20 '25 07:06 newinnovations

but could not find references to functions like fz_transform_rect

this? https://github.com/messense/mupdf-rs/blob/168fcb66297c43b4ba738593653f7c10770263e2/src/rect.rs#L188-L190

and https://docs.rs/mupdf-sys/latest/mupdf_sys/fn.fz_round_rect.html

messense avatar Jun 20 '25 09:06 messense

Great. Exactly what I was looking for!

newinnovations avatar Jun 20 '25 09:06 newinnovations

But why do I get

no method named `transform` found for struct `mupdf::Rect` in the current scope
method not found in `Rect`

is it not part of 0.5.0?

newinnovations avatar Jun 20 '25 09:06 newinnovations

yes, it was added recently, if you want to contribute you should work with the current main branch.

messense avatar Jun 20 '25 09:06 messense

I'm using:

let mut pixmap = Pixmap::new_with_rect(&Colorspace::device_rgb(), crop_rect, true)?;
pixmap.clear()?; // should not be necessary

let ctm = Matrix::default();
let device = Device::from_pixmap_with_clip(&pixmap, crop_rect)?;
page.run(&device, &ctm)?;

TobiasGrothmann avatar Jan 03 '26 21:01 TobiasGrothmann