diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-10-10 20:38:40 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-01-24 20:40:04 +0000 |
commit | 870c39cc6a4c16f135ebaf990011a7705649efb9 (patch) | |
tree | 3658e687df9c360f70ff00b29ff3fdbe81752cc4 | |
parent | 2d118d98f48be1d3dd550af3ca4964800703115c (diff) |
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 <vmiklos@collabora.com>
(cherry picked from commit bab44a97d21d0ac8a8a06678e71024c1a830943f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141180
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
(cherry picked from commit 475e698826e2103bdc78ac286e1fc8970363638e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146050
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | svx/qa/unit/data/page-view-draw-layer-clip.docx | bin | 0 -> 20764 bytes | |||
-rw-r--r-- | svx/qa/unit/svdraw.cxx | 37 | ||||
-rw-r--r-- | svx/source/svdraw/svdpagv.cxx | 2 |
3 files changed, 38 insertions, 1 deletions
diff --git a/svx/qa/unit/data/page-view-draw-layer-clip.docx b/svx/qa/unit/data/page-view-draw-layer-clip.docx Binary files differnew file mode 100644 index 000000000000..7136a800f01f --- /dev/null +++ b/svx/qa/unit/data/page-view-draw-layer-clip.docx diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 58d01e7f8905..04cdb43f0584 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -15,6 +15,7 @@ #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/LineStyle.hpp> @@ -37,6 +38,8 @@ #include <sfx2/viewsh.hxx> #include <svl/itempool.hxx> #include <svx/svdomedia.hxx> +#include <unotools/mediadescriptor.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> #include <sdr/contact/objectcontactofobjlistpainter.hxx> @@ -500,6 +503,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<tools::Long>(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::TempFile aTempFile; + uno::Reference<frame::XStorable> 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<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return; + } + std::unique_ptr<vcl::pdf::PDFiumDocument> pDoc + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr<vcl::pdf::PDFiumPage> pPage1 = pDoc->openPage(0); + CPPUNIT_ASSERT_EQUAL(3, pPage1->getObjectCount()); + std::unique_ptr<vcl::pdf::PDFiumPage> 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: */ diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx index 791a1fc30e70..496e57382322 100644 --- a/svx/source/svdraw/svdpagv.cxx +++ b/svx/source/svdraw/svdpagv.cxx @@ -262,7 +262,7 @@ void SdrPageView::DrawLayer(SdrLayerID nID, OutputDevice* pGivenTarget, if(pKnownTarget) { // paint known target - pKnownTarget->RedrawLayer(&nID, pRedirector, nullptr); + pKnownTarget->RedrawLayer(&nID, pRedirector, pPageFrame); } else { |