vcl/qa/cppunit/pdfexport/data/tdf99680-2.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx       |   48 +++++++++++++++++++++++++++
 vcl/source/gdi/pdfwriter_impl.cxx            |    2 -
 3 files changed, 49 insertions(+), 1 deletion(-)

New commits:
commit cbf371e07fd5dea1ea08a1f299360d1273961ebd
Author: Vasily Melenchuk <vasily.melenc...@cib.de>
Date:   Mon Jun 12 14:14:13 2017 +0300

    tdf#99680 save graphic state even for empty clipping region
    
    Previous fix was causing Adobe Reader errors due to mistmatch of
    save and restore operators.
    
    Corresponding unittest is extended to verify save/restore
    operators count.
    
    Change-Id: I102722140e216cb9ad29107aae3bdaa70472d471
    Reviewed-on: https://gerrit.libreoffice.org/38694
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf99680-2.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf99680-2.odt
new file mode 100644
index 000000000000..47c370004d86
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf99680-2.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 12ceba26b529..d8ef29fe0ba2 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -67,6 +67,7 @@ public:
     void testTdf107018();
     void testTdf107089();
     void testTdf99680();
+    void testTdf99680_2();
 #endif
 
     CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -83,6 +84,7 @@ public:
     CPPUNIT_TEST(testTdf107018);
     CPPUNIT_TEST(testTdf107089);
     CPPUNIT_TEST(testTdf99680);
+    CPPUNIT_TEST(testTdf99680_2);
 #endif
     CPPUNIT_TEST_SUITE_END();
 };
@@ -624,6 +626,52 @@ void PdfExportTest::testTdf99680()
     const char* pEnd = pStart + aUncompressed.GetSize();
     auto it = std::search(pStart, pEnd, aEmptyRegion.getStr(), 
aEmptyRegion.getStr() + aEmptyRegion.getLength());
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Empty clipping region detected!", it, pEnd);
+
+    // Count save graphic state (q) and restore (Q) operators
+    // and ensure their amount is equal
+    size_t nSaveCount = std::count(pStart, pEnd, 'q');
+    size_t nRestoreCount = std::count(pStart, pEnd, 'Q');
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Save/restore graphic state operators count 
mistmatch!", nSaveCount, nRestoreCount);
+}
+
+void PdfExportTest::testTdf99680_2()
+{
+    vcl::filter::PDFDocument aDocument;
+    load("tdf99680-2.odt", aDocument);
+
+    // For each document page
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPages.size());
+    for (size_t nPageNr = 0; nPageNr < aPages.size(); nPageNr++)
+    {
+        // Get page contents and stream.
+        vcl::filter::PDFObjectElement* pContents = 
aPages[nPageNr]->LookupObject("Contents");
+        CPPUNIT_ASSERT(pContents);
+        vcl::filter::PDFStreamElement* pStream = pContents->GetStream();
+        CPPUNIT_ASSERT(pStream);
+        SvMemoryStream& rObjectStream = pStream->GetMemory();
+
+        // Uncompress the stream.
+        SvMemoryStream aUncompressed;
+        ZCodec aZCodec;
+        aZCodec.BeginCompression();
+        rObjectStream.Seek(0);
+        aZCodec.Decompress(rObjectStream, aUncompressed);
+        CPPUNIT_ASSERT(aZCodec.EndCompression());
+
+        // Make sure there are no empty clipping regions.
+        OString aEmptyRegion("0 0 m h W* n");
+        auto pStart = static_cast<const char*>(aUncompressed.GetData());
+        const char* pEnd = pStart + aUncompressed.GetSize();
+        auto it = std::search(pStart, pEnd, aEmptyRegion.getStr(), 
aEmptyRegion.getStr() + aEmptyRegion.getLength());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Empty clipping region detected!", it, 
pEnd);
+
+        // Count save graphic state (q) and restore (Q) operators
+        // and ensure their amount is equal
+        size_t nSaveCount = std::count(pStart, pEnd, 'q');
+        size_t nRestoreCount = std::count(pStart, pEnd, 'Q');
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Save/restore graphic state operators 
count mistmatch!", nSaveCount, nRestoreCount);
+    }
 }
 
 #endif
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index e9042a10ec82..140b4903991f 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -12063,9 +12063,9 @@ void PDFWriterImpl::updateGraphicsState(Mode const mode)
                 getReferenceDevice()->SetMapMode( rNewState.m_aMapMode );
                 m_aCurrentPDFState.m_aMapMode = rNewState.m_aMapMode;
 
+                aLine.append("q ");
                 if ( rNewState.m_aClipRegion.count() )
                 {
-                    aLine.append( "q " );
                     m_aPages.back().appendPolyPolygon( 
rNewState.m_aClipRegion, aLine );
                     aLine.append( "W* n\n" );
                 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to