[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - sd/CppunitTest_sd_pdf_import_test.mk sd/Module_sd.mk sd/qa svx/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon May 4 06:52:07 UTC 2020


 sd/CppunitTest_sd_pdf_import_test.mk |   73 +++++++++++++++++++
 sd/Module_sd.mk                      |    1 
 sd/qa/unit/SdrPdfImportTest.cxx      |  128 +++++++++++++++++++++++++++++++++++
 sd/qa/unit/data/SimplePDF.pdf        |binary
 svx/source/inc/svdpdf.hxx            |    4 -
 svx/source/svdraw/svdpdf.cxx         |    2 
 6 files changed, 205 insertions(+), 3 deletions(-)

New commits:
commit 5ee8ac37222ddc2bcb460e6e8d250113223752d0
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon May 4 08:49:36 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon May 4 08:49:36 2020 +0200

    SdrPdfImport: add a test class to sd and write a simple test
    
    Open a simple PDF document, run the "break" action, check that
    we get the expected text as a text object.
    
    Change-Id: Iadb458f06b437689202eb013cb900edaabf17673

diff --git a/sd/CppunitTest_sd_pdf_import_test.mk b/sd/CppunitTest_sd_pdf_import_test.mk
new file mode 100644
index 000000000000..4326c9cdede0
--- /dev/null
+++ b/sd/CppunitTest_sd_pdf_import_test.mk
@@ -0,0 +1,73 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sd_pdf_import_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sd_pdf_import_test, \
+    sd/qa/unit/SdrPdfImportTest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sd_pdf_import_test, \
+    boost_headers \
+    $(if $(filter PDFIUM,$(BUILD_TYPE)),pdfium) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sd_pdf_import_test,\
+    -I$(SRCDIR)/sd/inc \
+    -I$(SRCDIR)/sd/source/ui/inc \
+    -I$(SRCDIR)/sd/source/ui/slidesorter/inc \
+    -I$(SRCDIR)/svx/source/inc \
+    -I$(SRCDIR)/svx/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sd_pdf_import_test, \
+    $(call gb_Helper_optional,AVMEDIA,avmedia) \
+    basegfx \
+    canvastools \
+    comphelper \
+    cppcanvas \
+    cppu \
+    cppuhelper \
+    drawinglayer \
+    editeng \
+    for \
+    forui \
+    i18nlangtag \
+    i18nutil \
+    msfilter \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sb \
+    sd \
+    sfx \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+    test \
+    tl \
+    tk \
+    ucbhelper \
+    unotest \
+    utl \
+    vcl \
+    xo \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sd_pdf_import_test))
+$(eval $(call gb_CppunitTest_use_ure,sd_pdf_import_test))
+$(eval $(call gb_CppunitTest_use_vcl,sd_pdf_import_test))
+$(eval $(call gb_CppunitTest_use_rdb,sd_pdf_import_test,services))
+$(eval $(call gb_CppunitTest_use_configuration,sd_pdf_import_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sd/Module_sd.mk b/sd/Module_sd.mk
index a7edda76cbe4..d5c6b2ecab23 100644
--- a/sd/Module_sd.mk
+++ b/sd/Module_sd.mk
@@ -39,6 +39,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sd,\
     CppunitTest_sd_uiimpress \
     CppunitTest_sd_html_export_tests \
     CppunitTest_sd_activex_controls_tests \
+    CppunitTest_sd_pdf_import_test \
 ))
 endif
 
diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx
new file mode 100644
index 000000000000..f7215360ec7e
--- /dev/null
+++ b/sd/qa/unit/SdrPdfImportTest.cxx
@@ -0,0 +1,128 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <svdpdf.hxx>
+
+#include <config_features.h>
+
+#include <comphelper/scopeguard.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <svx/svdograf.hxx>
+#include <editeng/outlobj.hxx>
+#include <editeng/editobj.hxx>
+
+#include <DrawDocShell.hxx>
+#include <DrawController.hxx>
+#include <ViewShell.hxx>
+#include <drawdoc.hxx>
+#include <sdpage.hxx>
+#include <unomodel.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+
+using namespace css;
+
+class SdrPdfImportTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+protected:
+    uno::Reference<lang::XComponent> mxComponent;
+
+public:
+    virtual void setUp() override;
+    virtual void tearDown() override;
+};
+
+void SdrPdfImportTest::setUp()
+{
+    test::BootstrapFixture::setUp();
+
+    mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void SdrPdfImportTest::tearDown()
+{
+    if (mxComponent.is())
+        mxComponent->dispose();
+
+    test::BootstrapFixture::tearDown();
+}
+
+// Load the PDF in Draw, which will load the PDF as an Graphic, then
+// mark the graphic object and trigger "break" funcition. This should
+// convert the PDF content into objects/shapes.
+CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText)
+{
+#if HAVE_FEATURE_PDFIUM
+    // We need to enable PDFium import (and make sure to disable after the test)
+    bool bResetEnvVar = false;
+    if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+    {
+        bResetEnvVar = true;
+        setenv("LO_IMPORT_USE_PDFIUM", "1", false);
+    }
+    comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+        if (bResetEnvVar)
+            unsetenv("LO_IMPORT_USE_PDFIUM");
+    });
+
+    mxComponent = loadFromDesktop(m_directories.getURLFromSrc("sd/qa/unit/data/SimplePDF.pdf"));
+    auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+    sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
+    CPPUNIT_ASSERT(pViewShell);
+
+    // Get the first page - there should be only one.
+    SdPage* pPage = pViewShell->GetActualPage();
+    CPPUNIT_ASSERT(pPage);
+
+    // Get the first object - there should be only one.
+    SdrObject* pObject = pPage->GetObj(0);
+    CPPUNIT_ASSERT(pObject);
+
+    // Check the object is a graphic object
+    SdrGrafObj* pGraphicObject = dynamic_cast<SdrGrafObj*>(pObject);
+    CPPUNIT_ASSERT(pGraphicObject);
+    // Check the graphic is a vector graphic and that it is PDF
+    Graphic aGraphic = pGraphicObject->GetGraphic();
+    auto const& pVectorGraphicData = aGraphic.getVectorGraphicData();
+    CPPUNIT_ASSERT(pVectorGraphicData);
+    CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
+                         pVectorGraphicData->getVectorGraphicDataType());
+
+    // Mark the object
+    SdrView* pView = pViewShell->GetView();
+    pView->MarkObj(pObject, pView->GetSdrPageView());
+
+    // Execute the break operation - to turn the PDF into shapes/objects
+    pViewShell->GetDrawView()->DoImportMarkedMtf();
+
+    // Check Objects after import
+
+    SdrObject* pImportedObject = pPage->GetObj(0);
+    CPPUNIT_ASSERT(pImportedObject);
+
+    // Object should be a text object containing one paragraph with
+    // content "This is PDF!"
+
+    SdrTextObj* pTextObject = dynamic_cast<SdrTextObj*>(pImportedObject);
+    CPPUNIT_ASSERT(pTextObject);
+    OutlinerParaObject* pOutlinerParagraphObject = pTextObject->GetOutlinerParaObject();
+    const EditTextObject& aEdit = pOutlinerParagraphObject->GetTextObject();
+    OUString sText = aEdit.GetText(0);
+    CPPUNIT_ASSERT_EQUAL(OUString("This is PDF!"), sText);
+
+#endif // HAVE_FEATURE_PDFIUM
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/data/SimplePDF.pdf b/sd/qa/unit/data/SimplePDF.pdf
new file mode 100644
index 000000000000..5d6fdb191544
Binary files /dev/null and b/sd/qa/unit/data/SimplePDF.pdf differ
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
similarity index 98%
rename from svx/source/svdraw/svdpdf.hxx
rename to svx/source/inc/svdpdf.hxx
index d9d35fe0c80c..9b48eb1d30c5 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -24,9 +24,9 @@
 
 #if HAVE_FEATURE_PDFIUM
 #include <sal/config.h>
+#include <svx/svxdllapi.h>
 
 #include <memory>
-#include <sstream>
 
 #include <tools/fract.hxx>
 #include <vcl/virdev.hxx>
@@ -52,7 +52,7 @@ class SdrObject;
 class SvdProgressInfo;
 
 // Helper Class to import PDF
-class ImpSdrPdfImport final
+class SVXCORE_DLLPUBLIC ImpSdrPdfImport final
 {
     std::vector<SdrObject*> maTmpList;
     ScopedVclPtr<VirtualDevice> mpVD;
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 0560b99ebe54..1c037bc8e497 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "svdpdf.hxx"
+#include <svdpdf.hxx>
 
 #include <config_features.h>
 


More information about the Libreoffice-commits mailing list