[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 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 Jun 8 11:43:29 UTC 2020
sd/CppunitTest_sd_pdf_import_test.mk | 73 +++++++++++++++++++
sd/Module_sd.mk | 1
sd/qa/unit/SdrPdfImportTest.cxx | 129 +++++++++++++++++++++++++++++++++++
sd/qa/unit/data/SimplePDF.pdf |binary
svx/source/inc/svdpdf.hxx | 4 -
svx/source/svdraw/svdedtv2.cxx | 2
svx/source/svdraw/svdpdf.cxx | 2
7 files changed, 207 insertions(+), 4 deletions(-)
New commits:
commit ab95f37716c031e4824ed9ff622ea2a613a56ad3
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon May 4 08:49:36 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Jun 8 13:42:56 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
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93395
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95702
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
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..a22579d67526
--- /dev/null
+++ b/sd/qa/unit/SdrPdfImportTest.cxx
@@ -0,0 +1,129 @@
+/* -*- 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(
+ css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
+}
+
+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
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 9dd6626d3318..60894542fb8f 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/contnr.hxx>
#include <tools/fract.hxx>
@@ -55,7 +55,7 @@ class SdrObject;
class SvdProgressInfo;
// Helper Class to import PDF
-class ImpSdrPdfImport final
+class SVXCORE_DLLPUBLIC ImpSdrPdfImport final
{
Graphic const& mrGraphic;
std::vector<SdrObject*> maTmpList;
diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx
index 7eab69f7bb5b..4fd92b1e30ca 100644
--- a/svx/source/svdraw/svdedtv2.cxx
+++ b/svx/source/svdraw/svdedtv2.cxx
@@ -36,7 +36,7 @@
#include <svx/xlineit0.hxx>
#include <svx/xtextit0.hxx>
#include "svdfmtf.hxx"
-#include "svdpdf.hxx"
+#include <svdpdf.hxx>
#include <svx/svdetc.hxx>
#include <sfx2/basedlgs.hxx>
#include <editeng/outlobj.hxx>
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 820832265aa0..a41caaeaba14 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