[Libreoffice-commits] core.git: include/vcl sd/qa vcl/inc vcl/source
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Sun Aug 25 11:45:46 UTC 2019
include/vcl/graph.hxx | 1
sd/qa/unit/data/pdf/multipage.pdf |binary
sd/qa/unit/import-tests.cxx | 73 ++++++++++++++++++++++++++++++++++++--
vcl/inc/impgraph.hxx | 1
vcl/source/gdi/graph.cxx | 5 ++
vcl/source/gdi/impgraph.cxx | 5 ++
6 files changed, 82 insertions(+), 3 deletions(-)
New commits:
commit 5a3f794219dade812ec29ea9971680058b4bade9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Tue Apr 2 11:32:42 2019 -0400
Commit: Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Sun Aug 25 13:44:31 2019 +0200
sd: unit-test to check that PDF stream is shared among Graphic instances
Reviewed-on: https://gerrit.libreoffice.org/70162
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
(cherry picked from commit d3a9bdd982ad1ed17cb6fef91885fc4dcf442fdb)
Change-Id: Iebd85e5e60c76e6d0756d15e1fa6107a3fcc837d
Reviewed-on: https://gerrit.libreoffice.org/77693
Tested-by: Jenkins
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index b7cd1eb10438..3559f9935a81 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -211,6 +211,7 @@ private:
public:
void SetGfxLink(const std::shared_ptr<GfxLink>& rGfxLink);
+ std::shared_ptr<GfxLink> GetSharedGfxLink() const;
GfxLink GetGfxLink() const;
bool IsGfxLink() const;
diff --git a/sd/qa/unit/data/pdf/multipage.pdf b/sd/qa/unit/data/pdf/multipage.pdf
new file mode 100644
index 000000000000..5cd8b4e4e569
Binary files /dev/null and b/sd/qa/unit/data/pdf/multipage.pdf differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 4e23ad69f227..941e27aa2db9 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -92,6 +92,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/graphicmimetype.hxx>
+#include <comphelper/lok.hxx>
#include <vcl/pngread.hxx>
#include <vcl/bitmapaccess.hxx>
#include <vcl/dibtools.hxx>
@@ -149,10 +150,13 @@ public:
void testTableBorderLineStyle();
void testBnc862510_6();
void testBnc862510_7();
-#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
+#if ENABLE_PDFIMPORT
+ void testPDFImportShared();
+#if defined(IMPORT_PDF_ELEMENTS)
void testPDFImport();
void testPDFImportSkipImages();
#endif
+#endif
void testBulletSuffix();
void testBnc910045();
void testRowHeight();
@@ -242,10 +246,13 @@ public:
CPPUNIT_TEST(testTableBorderLineStyle);
CPPUNIT_TEST(testBnc862510_6);
CPPUNIT_TEST(testBnc862510_7);
-#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
+#if ENABLE_PDFIMPORT
+ CPPUNIT_TEST(testPDFImportShared);
+#if defined(IMPORT_PDF_ELEMENTS)
CPPUNIT_TEST(testPDFImport);
CPPUNIT_TEST(testPDFImportSkipImages);
#endif
+#endif
CPPUNIT_TEST(testBulletSuffix);
CPPUNIT_TEST(testBnc910045);
CPPUNIT_TEST(testRowHeight);
@@ -1193,7 +1200,66 @@ void SdImportTest::testBnc862510_7()
xDocShRef->DoClose();
}
-#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS)
+#if ENABLE_PDFIMPORT
+
+void SdImportTest::testPDFImportShared()
+{
+ comphelper::LibreOfficeKit::setActive();
+ sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pdf/multipage.pdf"), PDF);
+ SdDrawDocument *pDoc = xDocShRef->GetDoc();
+ CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != nullptr );
+
+ // This test is to verify that we share the PDF stream linked to each
+ // Graphic instance in the imported document.
+ // Since we import PDFs as images, we support attaching the original
+ // PDF with each image to allow for advanced editing.
+ // Here we iterate over all Graphic instances embedded in the pages
+ // and verify that they all point to the same object in memory.
+ std::vector<std::shared_ptr<std::vector<sal_Int8>>> aPdfSeqSharedPtrs;
+ std::vector<std::shared_ptr<GfxLink>> aGfxLinkSharedPtrs;
+
+ for (int nPageIndex = 0; nPageIndex < pDoc->GetPageCount(); ++nPageIndex)
+ {
+ const SdrPage* pPage = GetPage(nPageIndex, xDocShRef);
+ if (pPage == nullptr)
+ break;
+
+ for (size_t nObjIndex = 0; nObjIndex < pPage->GetObjCount(); ++nObjIndex)
+ {
+ SdrObject* pObject = pPage->GetObj(nObjIndex);
+ if (pObject == nullptr)
+ continue;
+
+ SdrGrafObj* pSdrGrafObj = dynamic_cast<SdrGrafObj*>(pObject);
+ if (pSdrGrafObj == nullptr)
+ continue;
+
+ const GraphicObject& rGraphicObject = pSdrGrafObj->GetGraphicObject().GetGraphic();
+ const Graphic& rGraphic = rGraphicObject.GetGraphic();
+ aPdfSeqSharedPtrs.push_back(rGraphic.getPdfData());
+ aGfxLinkSharedPtrs.push_back(rGraphic.GetSharedGfxLink());
+ }
+ }
+
+ CPPUNIT_ASSERT_MESSAGE("Expected more than one page.", aPdfSeqSharedPtrs.size() > 1);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected as many PDF streams as GfxLinks.",
+ aPdfSeqSharedPtrs.size(), aGfxLinkSharedPtrs.size());
+
+ const std::shared_ptr<std::vector<sal_Int8>> pPdfSeq = aPdfSeqSharedPtrs[0];
+ const std::shared_ptr<GfxLink> pGfxLink = aGfxLinkSharedPtrs[0];
+ for (size_t i = 0; i < aPdfSeqSharedPtrs.size(); ++i)
+ {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all PDF streams to be identical.",
+ aPdfSeqSharedPtrs[i].get(), pPdfSeq.get());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all GfxLinks to be identical.",
+ aGfxLinkSharedPtrs[i].get(), pGfxLink.get());
+ }
+
+ xDocShRef->DoClose();
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
+#if defined(IMPORT_PDF_ELEMENTS)
void SdImportTest::testPDFImport()
{
@@ -1231,6 +1297,7 @@ void SdImportTest::testPDFImportSkipImages()
}
#endif
+#endif
void SdImportTest::testBulletSuffix()
{
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index e34cbedffddc..bd821eb05fb1 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -215,6 +215,7 @@ private:
bool ImplIsSwapOut() const { return mbSwapOut;}
bool ImplIsDummyContext() const { return mbDummyContext; }
void ImplSetLink( const std::shared_ptr<GfxLink>& );
+ std::shared_ptr<GfxLink> ImplGetSharedGfxLink() const;
GfxLink ImplGetLink();
bool ImplIsLink() const;
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index a106eccb2910..01e069eeead3 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -511,6 +511,11 @@ void Graphic::SetGfxLink( const std::shared_ptr<GfxLink>& rGfxLink )
mxImpGraphic->ImplSetLink( rGfxLink );
}
+std::shared_ptr<GfxLink> Graphic::GetSharedGfxLink() const
+{
+ return mxImpGraphic->ImplGetSharedGfxLink();
+}
+
GfxLink Graphic::GetGfxLink() const
{
return mxImpGraphic->ImplGetLink();
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 904ef2677e37..d60da42ebbc7 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1664,6 +1664,11 @@ void ImpGraphic::ImplSetLink(const std::shared_ptr<GfxLink>& rGfxLink)
mpGfxLink = rGfxLink;
}
+std::shared_ptr<GfxLink> ImpGraphic::ImplGetSharedGfxLink() const
+{
+ return mpGfxLink;
+}
+
GfxLink ImpGraphic::ImplGetLink()
{
ensureAvailable();
More information about the Libreoffice-commits
mailing list