summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-08-03 09:44:03 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-08-03 11:11:15 +0200
commit7c94d7267bc8b5f43185204ab4953c4b188214bf (patch)
treee3e60ec5a6524b768de55b8d4e9183b3c7db89f9 /vcl/qa
parentae434ccb4878ed49f19be578e4935f50196b6b78 (diff)
tdf#149943 vcl: fix pixelated PDF export and print for a rotated image
The bugdoc has a barcode which looks good in Writer, but it's quite blurry in the PDF export result. This is a problem since commit dd4a67084853a030bf4b9f1f85d728620e0604a5 (vcl: avoid downscale && upscale in DrawTransformedBitmapEx(), 2019-10-08), where the motivation was to not downscale a bitmap in case it has a larger amount of pixels but a smaller logic size. This went wrong here and resulted in a blurry bitmap for a not so small image. Fix the problem by mostly reverting the above commit, because it's no longer necessary: 68549e00d5e23aa22bc974a8151d93cd948444b3 (vcl, BitmapEx transformed draw: special-case simple rotations, 2019-10-10) already made sure that the rotation case doesn't use scaling from the transform. testTdf128630 has been adapted to pass again (after manually verifying that the bugdoc export result is still OK), now the bad case there simply produces a smaller bitmap. Change-Id: Ib28881c129a0cf037a96eecd065e5cadede97051 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137737 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odtbin0 -> 13423 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx46
2 files changed, 40 insertions, 6 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt b/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt
new file mode 100644
index 000000000000..da9b167fd9d7
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/bitmap-scaledown.odt
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 03aed3112d64..fb821a7777e4 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1638,7 +1638,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
// The document has one page.
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
- // Assert the aspect ratio of the only bitmap on the page.
+ // Assert the size of the only bitmap on the page.
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
int nPageObjectCount = pPdfPage->getObjectCount();
@@ -1651,12 +1651,13 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630)
std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap();
CPPUNIT_ASSERT(pBitmap);
int nWidth = pBitmap->getWidth();
- int nHeight = pBitmap->getHeight();
// Without the accompanying fix in place, this test would have failed with:
- // assertion failed
- // - Expression: nWidth != nHeight
- // i.e. the bitmap lost its custom aspect ratio during export.
- CPPUNIT_ASSERT(nWidth != nHeight);
+ // - Expected: 466
+ // - Actual : 289
+ // i.e. the rotated + scaled arrow was more thin than it should be.
+ CPPUNIT_ASSERT_EQUAL(466, nWidth);
+ int nHeight = pBitmap->getHeight();
+ CPPUNIT_ASSERT_EQUAL(466, nHeight);
}
}
@@ -3451,6 +3452,39 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageEncryption)
// missing encryption.
CPPUNIT_ASSERT_EQUAL(2, pPageObject->getFormObjectCount());
}
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testBitmapScaledown)
+{
+ // Given a document with an upscaled and rotated barcode bitmap in it:
+ aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+
+ // When saving as PDF:
+ saveAsPDF(u"bitmap-scaledown.odt");
+
+ // Then verify that the bitmap is not downscaled:
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parseExport();
+ CPPUNIT_ASSERT(pPdfDocument);
+ CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
+ CPPUNIT_ASSERT(pPdfPage);
+ int nPageObjectCount = pPdfPage->getObjectCount();
+ for (int i = 0; i < nPageObjectCount; ++i)
+ {
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i);
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Image)
+ continue;
+
+ std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap();
+ CPPUNIT_ASSERT(pBitmap);
+ // In-file sizes: good is 2631x380, bad is 1565x14.
+ int nWidth = pBitmap->getWidth();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 2616
+ // - Actual : 1565
+ // i.e. the bitmap in the pdf result was small enough to be blurry.
+ CPPUNIT_ASSERT_EQUAL(2616, nWidth);
+ }
+}
} // end anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();