From bab44a97d21d0ac8a8a06678e71024c1a830943f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 10 Oct 2022 20:38:40 +0200 Subject: tdf#151060 sw PDF export: don't paint off-page part of drawing object Reported to be a regression from c12358166a9bd88fe10feabca45a6ad3f65dff8e (DOCX import: fix lost objects anchored to an empty linked header, 2020-01-10), the 3rd page of the PDF export result contains an unexpected line shape. This was "working" before as all objects anchored to the empty header were lost. Fix the problem by clipping the rendering to the page frame when handling shapes, similar to what 689cead9e0837dc932e3a4cd765f7d319b529018 (tdf#91260 svx, sw: don't paint off-page part of drawing object, 2016-12-06) did to fix the normal rendering of the document. The testcase document just has 2 pages, so there the unexpected shape was on the 2nd page. Change-Id: Ica24cd15717a1ee97dff448d385a10536671103e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141167 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- svx/qa/unit/data/page-view-draw-layer-clip.docx | Bin 0 -> 20764 bytes svx/qa/unit/svdraw.cxx | 37 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 svx/qa/unit/data/page-view-draw-layer-clip.docx (limited to 'svx/qa/unit') diff --git a/svx/qa/unit/data/page-view-draw-layer-clip.docx b/svx/qa/unit/data/page-view-draw-layer-clip.docx new file mode 100644 index 000000000000..7136a800f01f Binary files /dev/null and b/svx/qa/unit/data/page-view-draw-layer-clip.docx differ diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index f6ca7fd4b09e..90030296e1c8 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,8 @@ #include #include #include +#include +#include #include @@ -509,6 +512,40 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testVideoSnapshot) // i.e. ~25% crop from left and right should result in half width, but it was not reduced. CPPUNIT_ASSERT_EQUAL(static_cast(321), rBitmap.GetSizePixel().getWidth()); } + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testPageViewDrawLayerClip) +{ + // Given a document with 2 pages, first page footer has an off-page line shape: + OUString aURL = m_directories.getURLFromSrc(u"svx/qa/unit/data/page-view-draw-layer-clip.docx"); + mxComponent = loadFromDesktop(aURL); + + // When saving that document to PDF: + utl::TempFileNamed aTempFile; + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Then make sure that line shape gets clipped: + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + std::unique_ptr pDoc + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr pPage1 = pDoc->openPage(0); + CPPUNIT_ASSERT_EQUAL(3, pPage1->getObjectCount()); + std::unique_ptr pPage2 = pDoc->openPage(1); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 3 + // i.e. the 2nd page had a line shape from the first page's footer. + CPPUNIT_ASSERT_EQUAL(2, pPage2->getObjectCount()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit