diff --git a/src/page_object_image.rs b/src/page_object_image.rs index af4fde9..5e18c81 100644 --- a/src/page_object_image.rs +++ b/src/page_object_image.rs @@ -231,12 +231,11 @@ impl<'a> PdfPageImageObject<'a> { // We attempt to work around two separate problems in Pdfium's // FPDFImageObj_GetRenderedBitmap() function. - // First, the call to FPDFImageObj_GetRenderedBitmap() can fail, - // returning a null FPDF_BITMAP handle, if the image object's transformation matrix - // includes negative values for either the matrix.a or matrix.d values. - // We flip those values in the transformation matrix if they are negative, - // and we make sure we return them to their original values before we return to - // the caller. + // First, the call to FPDFImageObj_GetRenderedBitmap() can fail, returning + // a null FPDF_BITMAP handle, if the image object's transformation matrix includes + // negative values for either the matrix.a or matrix.d values. We flip those values + // in the transformation matrix if they are negative, and we make sure we return them + // to their original values before we return to the caller. // Second, Pdfium seems to often return a rendered bitmap that is much smaller // than the image object's metadata suggests. We look at the dimensions of the bitmap @@ -249,7 +248,7 @@ impl<'a> PdfPageImageObject<'a> { let original_matrix = matrix; // We'll reset the matrix to this before we return. - // Flip the matrix.a and/or matrix.d values if they are negative. + // Ensure the matrix.a and matrix.d values are not negative. if matrix.a < 0f32 { matrix.a = -matrix.a; @@ -284,7 +283,7 @@ impl<'a> PdfPageImageObject<'a> { let result = result.unwrap(); - return if width as u32 == result.width() && height as u32 == result.height() { + if width as u32 == result.width() && height as u32 == result.height() { // The bitmap generated by Pdfium is already at the caller's requested dimensions. // Restore the original transformation matrix values before we return to the caller. @@ -293,8 +292,8 @@ impl<'a> PdfPageImageObject<'a> { Ok(result) } else { // The bitmap generated by Pdfium is not at the caller's requested dimensions. - // We apply a scale transform to the page object to coerce Pdfium into generating - // a bitmap at the caller's requested dimensions. + // We apply a scale transform to the page object to encourage Pdfium to generate + // a bitmap matching the caller's requested dimensions. self.transform_impl( width as f64 / result.width() as f64, @@ -325,7 +324,7 @@ impl<'a> PdfPageImageObject<'a> { self.set_matrix(original_matrix)?; result - }; + } } pub(crate) fn get_image_from_bitmap_handle( diff --git a/test/attachments-test.pdf b/test/attachments-test.pdf index 25bdfe7..0d853a6 100644 Binary files a/test/attachments-test.pdf and b/test/attachments-test.pdf differ