diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-10-10 20:38:40 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-10-11 08:29:34 +0200 |
commit | bab44a97d21d0ac8a8a06678e71024c1a830943f (patch) | |
tree | 05649f0bd9305f2a83ca8d967c0bee07f350651c /svx/qa/unit | |
parent | f486d2220d5b51f422c8feca21c831e1c1d143d7 (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>
Diffstat (limited to 'svx/qa/unit')
-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 |
2 files changed, 37 insertions, 0 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 f6ca7fd4b09e..90030296e1c8 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> @@ -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<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::TempFileNamed 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: */ |