drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx | 39 +++++++++++++ vcl/qa/cppunit/pdfexport/data/tdf150076.odt |binary vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 19 ++++++ 3 files changed, 58 insertions(+)
New commits: commit b36d027634952e127d67b8d7392555d3f4f09837 Author: Jaume Pujantell <[email protected]> AuthorDate: Tue Feb 24 08:50:09 2026 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Feb 25 13:34:04 2026 +0100 tdf#150076 embed background pdf When exporting to PDF a document with a background image on the page. The image would always be exported as a bitmap at a fix resolution, even if the original data had vector form (like a pdf or svg). This ensures that the original vector data is also exported as it is done with regularly inserted images. Change-Id: I7f363614ba375e01a4b076c961ce91dae8c2351b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200141 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx index 127f6819492b..be383e030ef2 100644 --- a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx @@ -1078,7 +1078,46 @@ void VclMetafileProcessor2D::processFillGraphicPrimitive2D( } // all other cases: process recursively with original primitive + // If we are in PDF export and have vector data, pass this along + // as is done in processGraphicPrimitive2D + bool bUsingPDFExtOutDevData(false); + basegfx::B2DVector aTranslate, aScale; + static bool bSuppressPDFExtOutDevDataSupport(false); // loplugin:constvars:ignore + + if (mpPDFExtOutDevData && !bSuppressPDFExtOutDevDataSupport) + { + const Graphic& rGraphic = rFillGraphicPrimitive2D.getFillGraphic().getGraphic(); + + if (rGraphic.IsGfxLink()) + { + const basegfx::B2DHomMatrix& rTransform = rFillGraphicPrimitive2D.getTransformation(); + double fRotate, fShearX; + rTransform.decompose(aScale, aTranslate, fRotate, fShearX); + + if (basegfx::fTools::equalZero(fRotate) && (aScale.getX() > 0.0) + && (aScale.getY() > 0.0)) + { + bUsingPDFExtOutDevData = true; + mpPDFExtOutDevData->BeginGroup(); + } + } + } + + // process recursively and add MetaFile comment process(rFillGraphicPrimitive2D); + + if (!bUsingPDFExtOutDevData) + return; + + const basegfx::B2DRange aCurrentRange(aTranslate.getX(), aTranslate.getY(), + aTranslate.getX() + aScale.getX(), + aTranslate.getY() + aScale.getY()); + const tools::Rectangle aCurrentRect( + sal_Int32(floor(aCurrentRange.getMinX())), sal_Int32(floor(aCurrentRange.getMinY())), + sal_Int32(ceil(aCurrentRange.getMaxX())), sal_Int32(ceil(aCurrentRange.getMaxY()))); + + mpPDFExtOutDevData->EndGroup(rFillGraphicPrimitive2D.getFillGraphic().getGraphic(), 0, + aCurrentRect, aCurrentRect); } void VclMetafileProcessor2D::processGraphicPrimitive2D( diff --git a/vcl/qa/cppunit/pdfexport/data/tdf150076.odt b/vcl/qa/cppunit/pdfexport/data/tdf150076.odt new file mode 100644 index 000000000000..e1bd124eac08 Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf150076.odt differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 3c59b4b6d5f9..2c5aeaa67ab2 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -6166,6 +6166,25 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testPDFAttachmentsWithEncryptedFile) CPPUNIT_ASSERT_EQUAL(u"This is a test document."_ustr, xParagraph->getString()); } +CPPUNIT_TEST_FIXTURE(PdfExportTest2, tdf150076BackgroundPdf) +{ + saveAsPDF(u"tdf150076.odt"); + + // Parse the export result. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount()); + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(0); + // Without the fix in place, this fails with: + // equality assertion failed + // - Expected: 5 + // - Actual : 3 + // Where 5 means form (i.e. embedded PDF) and 3 means it's just an image + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, pPageObject->getType()); +} + } // end anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT();
