summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-04 08:49:36 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-05-05 12:12:07 +0200
commit342d98b8aae6dcea0a5eec9ad97214fa17409437 (patch)
tree46431b4696d77f2b81a96b2fadc8aeb339b2ac2b
parent8e53551db00d325dd638d45e50b32984dc778f17 (diff)
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 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93395 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sd/CppunitTest_sd_pdf_import_test.mk73
-rw-r--r--sd/Module_sd.mk1
-rw-r--r--sd/qa/unit/SdrPdfImportTest.cxx128
-rw-r--r--sd/qa/unit/data/SimplePDF.pdfbin0 -> 8136 bytes
-rw-r--r--svx/source/inc/svdpdf.hxx (renamed from svx/source/svdraw/svdpdf.hxx)4
-rw-r--r--svx/source/svdraw/svdedtv2.cxx2
-rw-r--r--svx/source/svdraw/svdpdf.cxx2
7 files changed, 206 insertions, 4 deletions
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..d17bb2b6dae5
--- /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 && !defined(_WIN32)
+ // 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
--- /dev/null
+++ b/sd/qa/unit/data/SimplePDF.pdf
Binary files differ
diff --git a/svx/source/svdraw/svdpdf.hxx b/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/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx
index c7f5dfebeec0..fa36984bb4ec 100644
--- a/svx/source/svdraw/svdedtv2.cxx
+++ b/svx/source/svdraw/svdedtv2.cxx
@@ -34,7 +34,7 @@
#include <svx/xlineit0.hxx>
#include <svx/xtextit0.hxx>
#include "svdfmtf.hxx"
-#include "svdpdf.hxx"
+#include <svdpdf.hxx>
#include <svx/svdetc.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/eeitem.hxx>
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 5394c3c261d1..5cd0c0765a29 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>