[Libreoffice-commits] core.git: svtools/CppunitTest_svtools_graphic.mk svtools/qa vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Jun 29 10:36:50 UTC 2016


 svtools/CppunitTest_svtools_graphic.mk |   31 ----------------------------
 svtools/qa/unit/GraphicObjectTest.cxx  |   34 +++++++++++++++++++++++++++++++
 svtools/qa/unit/data/pdf.odt           |binary
 vcl/source/gdi/impgraph.cxx            |   36 +++++++++++++++++++++++++++------
 4 files changed, 65 insertions(+), 36 deletions(-)

New commits:
commit 71b2dc0de9514d9972211f03641f64b7ed9ed8f3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jun 29 11:07:23 2016 +0200

    vcl: handle PDF data in Read/WriteImpGraphic()
    
    Initially I wrote the test to cover
    f7d6f3e4e3fda3cd4936880918e2831246634a3e (svtools: survive swapout/in of
    graphic with embedded pdf, 2016-06-28), but as it turns out the actual
    swapin/out code is in vcl, so extend that as well to support pdf data.
    
    Change-Id: I320ea729dce9440b84a5089607807322ea7b0b04
    Reviewed-on: https://gerrit.libreoffice.org/26755
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/svtools/CppunitTest_svtools_graphic.mk b/svtools/CppunitTest_svtools_graphic.mk
index 9636c7d..17056e5 100644
--- a/svtools/CppunitTest_svtools_graphic.mk
+++ b/svtools/CppunitTest_svtools_graphic.mk
@@ -45,36 +45,7 @@ $(eval $(call gb_CppunitTest_use_custom_headers,svtools_graphic,\
 
 $(eval $(call gb_CppunitTest_use_configuration,svtools_graphic))
 
-$(eval $(call gb_CppunitTest_use_components,svtools_graphic,\
-    basic/util/sb \
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-    embeddedobj/util/embobj \
-    filter/source/config/cache/filterconfig1 \
-    filter/source/storagefilterdetect/storagefd \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-    linguistic/source/lng \
-    oox/util/oox \
-    package/source/xstor/xstor \
-    package/util/package2 \
-    sax/source/expatwrap/expwrap \
-    sfx2/util/sfx \
-    starmath/util/sm \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    sw/util/sw \
-    sw/util/swd \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/file/ucpfile1 \
-    unotools/util/utl \
-    unoxml/source/service/unoxml \
-    uui/util/uui \
-    writerfilter/util/writerfilter \
-    $(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \
-    xmloff/util/xo \
-))
+$(eval $(call gb_CppunitTest_use_rdb,svtools_graphic,services))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,svtools_graphic, \
     svtools/qa/unit/GraphicObjectTest \
diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx
index 2266442..c785fad 100644
--- a/svtools/qa/unit/GraphicObjectTest.cxx
+++ b/svtools/qa/unit/GraphicObjectTest.cxx
@@ -41,6 +41,7 @@ public:
     void testSizeBasedAutoSwap();
     void testTdf88836();
     void testTdf88935();
+    void testPdf();
 
 
     virtual void setUp() override
@@ -59,6 +60,7 @@ private:
     CPPUNIT_TEST(testSizeBasedAutoSwap);
     CPPUNIT_TEST(testTdf88836);
     CPPUNIT_TEST(testTdf88935);
+    CPPUNIT_TEST(testPdf);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -307,6 +309,38 @@ void GraphicObjectTest::testTdf88935()
     xComponent->dispose();
 }
 
+void GraphicObjectTest::testPdf()
+{
+    uno::Reference<lang::XComponent> xComponent = loadFromDesktop(m_directories.getURLFromSrc("svtools/qa/unit/data/pdf.odt"), "com.sun.star.text.TextDocument");
+    SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument*>(xComponent.get());
+    CPPUNIT_ASSERT(pTxtDoc);
+    SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+    SwNodes& aNodes = pDoc->GetNodes();
+
+    // Find images
+    GraphicObject* pGraphicObject = nullptr;
+    for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
+    {
+        if( aNodes[nIndex]->IsGrfNode() )
+        {
+            SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
+            CPPUNIT_ASSERT(pGrfNode);
+            pGraphicObject = const_cast<GraphicObject*>(&pGrfNode->GetGrfObj());
+            break;
+        }
+    }
+    CPPUNIT_ASSERT_MESSAGE("Missing image", pGraphicObject);
+
+    CPPUNIT_ASSERT(pGraphicObject->GetGraphic().getPdfData().hasElements());
+    pGraphicObject->SwapOut();
+    pGraphicObject->SwapIn();
+    // This failed, swap out + swap in lost the PDF data.
+    CPPUNIT_ASSERT(pGraphicObject->GetGraphic().getPdfData().hasElements());
+
+    xComponent->dispose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(GraphicObjectTest);
 
 }
diff --git a/svtools/qa/unit/data/pdf.odt b/svtools/qa/unit/data/pdf.odt
new file mode 100644
index 0000000..f20b389
Binary files /dev/null and b/svtools/qa/unit/data/pdf.odt differ
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 25d82d8..82e6b74 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -51,6 +51,8 @@
 #define GRAPHIC_FORMAT_50           static_cast<sal_uInt32>(COMPAT_FORMAT( 'G', 'R', 'F', '5' ))
 #define NATIVE_FORMAT_50            static_cast<sal_uInt32>(COMPAT_FORMAT( 'N', 'A', 'T', '5' ))
 
+const sal_uInt32 nPdfMagic((sal_uInt32('p') << 24) | (sal_uInt32('d') << 16) | (sal_uInt32('f') << 8) | sal_uInt32('0'));
+
 using namespace com::sun::star;
 
 struct ImpSwapFile
@@ -1553,11 +1555,7 @@ SvStream& ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
                         rIStm.ResetError();
                         rIStm.ReadUInt32( nMagic );
 
-                        if (nSvgMagic != nMagic)
-                        {
-                            rIStm.SetError(nOrigError);
-                        }
-                        else
+                        if (nSvgMagic == nMagic)
                         {
                             sal_uInt32 nSvgDataArrayLength(0);
                             rIStm.ReadUInt32(nSvgDataArrayLength);
@@ -1580,6 +1578,24 @@ SvStream& ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
                                 }
                             }
                         }
+                        else if (nMagic == nPdfMagic)
+                        {
+                            // Stream in PDF data.
+                            sal_uInt32 nPdfDataLength = 0;
+                            rIStm.ReadUInt32(nPdfDataLength);
+
+                            if (nPdfDataLength)
+                            {
+                                uno::Sequence<sal_Int8> aPdfData(nPdfDataLength);
+                                rIStm.ReadBytes(aPdfData.getArray(), nPdfDataLength);
+                                if (!rIStm.GetError())
+                                    rImpGraphic.maPdfData = aPdfData;
+                            }
+                        }
+                        else
+                        {
+                            rIStm.SetError(nOrigError);
+                        }
 
                         rIStm.Seek(nStmPos1);
                     }
@@ -1601,7 +1617,8 @@ SvStream& WriteImpGraphic( SvStream& rOStm, const ImpGraphic& rImpGraphic )
         {
             if( ( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 ) &&
                 ( rOStm.GetCompressMode() & SvStreamCompressFlags::NATIVE ) &&
-                rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() )
+                rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() &&
+                !rImpGraphic.maPdfData.hasElements())
             {
                 // native format
                 rOStm.WriteUInt32( NATIVE_FORMAT_50 );
@@ -1656,6 +1673,13 @@ SvStream& WriteImpGraphic( SvStream& rOStm, const ImpGraphic& rImpGraphic )
 
                     default:
                     {
+                        if (rImpGraphic.maPdfData.hasElements())
+                        {
+                            // Stream out PDF data.
+                            rOStm.WriteUInt32(nPdfMagic);
+                            rOStm.WriteUInt32(rImpGraphic.maPdfData.getLength());
+                            rOStm.WriteBytes(rImpGraphic.maPdfData.getConstArray(), rImpGraphic.maPdfData.getLength());
+                        }
                         if( rImpGraphic.ImplIsSupportedGraphic() )
                             WriteGDIMetaFile( rOStm, rImpGraphic.maMetaFile );
                     }


More information about the Libreoffice-commits mailing list