svx/qa/unit/data/page-view-draw-layer-clip.docx |binary
 svx/qa/unit/svdraw.cxx                          |   37 ++++++++++++++++++++++++
 svx/source/svdraw/svdpagv.cxx                   |    2 -
 3 files changed, 38 insertions(+), 1 deletion(-)

New commits:
commit 475e698826e2103bdc78ac286e1fc8970363638e
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Oct 10 20:38:40 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Oct 25 21:08:12 2022 +0200

    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 <vmik...@collabora.com>
    (cherry picked from commit bab44a97d21d0ac8a8a06678e71024c1a830943f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141180
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

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 dacf558c5f7f..564998bcf9a9 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>
 
@@ -512,6 +515,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 0e35d09b080e..60cd8cfe8ca0 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
         {

Reply via email to