[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - 2 commits - filter/Configuration_filter.mk filter/source sw/CppunitTest_sw_indexingexport.mk sw/Library_sw.mk sw/qa sw/source sw/util

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 1 03:10:38 UTC 2021


 filter/Configuration_filter.mk                                      |    2 
 filter/source/config/cache/typedetection.cxx                        |    1 
 filter/source/config/fragments/filters/writer_indexing_export.xcu   |   22 +++
 filter/source/config/fragments/types/writer_indexing_export_xml.xcu |   21 ++
 sw/CppunitTest_sw_indexingexport.mk                                 |    1 
 sw/Library_sw.mk                                                    |    2 
 sw/qa/extras/indexing/SearchResultLocatorTest.cxx                   |   72 ++++++++++
 sw/source/core/inc/SearchResultLocator.hxx                          |   45 ++++++
 sw/source/core/model/SearchResultLocator.cxx                        |   47 ++++++
 sw/source/filter/inc/IndexingExportFilter.hxx                       |   68 +++++++++
 sw/source/filter/indexing/IndexingExportFilter.cxx                  |   63 ++++++++
 sw/util/sw.component                                                |    4 
 12 files changed, 348 insertions(+)

New commits:
commit 7094123d6316368df4bb0471ff3e36a842b2211a
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Jul 5 10:57:41 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Sep 1 05:10:16 2021 +0200

    indexing: search result locator to return the rect of the result
    
    Returns the rectangle(s) where the search result is located in the
    document.
    
    Change-Id: Ib2333584fbc460cc16b1bf205fc3d674a1c06957
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118668
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 6e155959de6f46afbe0b68057200c3da822d81f9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121108
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>

diff --git a/sw/CppunitTest_sw_indexingexport.mk b/sw/CppunitTest_sw_indexingexport.mk
index a3884fee8fb6..7210fbe33042 100644
--- a/sw/CppunitTest_sw_indexingexport.mk
+++ b/sw/CppunitTest_sw_indexingexport.mk
@@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_indexingexport))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_indexingexport, \
     sw/qa/extras/indexing/IndexingExportTest \
+    sw/qa/extras/indexing/SearchResultLocatorTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_libraries,sw_indexingexport, \
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 1c5884008c23..20ed5e28f100 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -352,6 +352,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/layout/virtoutp \
     sw/source/core/layout/wsfrm \
     sw/source/core/model/ModelTraverser \
+    sw/source/core/model/SearchResultLocator \
     sw/source/core/objectpositioning/anchoredobjectposition \
     sw/source/core/objectpositioning/ascharanchoredobjectposition \
     sw/source/core/objectpositioning/environmentofanchoredobject \
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
new file mode 100644
index 000000000000..933c96159a51
--- /dev/null
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -0,0 +1,72 @@
+/* -*- 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 <memory>
+#include <string_view>
+#include <swmodeltestbase.hxx>
+#include <docsh.hxx>
+#include <unotxdoc.hxx>
+
+#include <SearchResultLocator.hxx>
+
+namespace
+{
+constexpr OUStringLiteral DATA_DIRECTORY = u"sw/qa/extras/indexing/data/";
+}
+
+class SearchResultLocatorTest : public SwModelTestBase
+{
+private:
+    SwDoc* createDoc(const char* pName = nullptr);
+
+public:
+    void testSearchResultLocator();
+
+    CPPUNIT_TEST_SUITE(SearchResultLocatorTest);
+    CPPUNIT_TEST(testSearchResultLocator);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+SwDoc* SearchResultLocatorTest::createDoc(const char* pName)
+{
+    if (!pName)
+        loadURL("private:factory/swriter", nullptr);
+    else
+        load(DATA_DIRECTORY, pName);
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    return pTextDoc->GetDocShell()->GetDoc();
+}
+
+void SearchResultLocatorTest::testSearchResultLocator()
+{
+#ifndef MACOSX
+    SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt");
+    CPPUNIT_ASSERT(pDoc);
+
+    sw::SearchResultLocator aLocator(pDoc);
+    sw::SearchIndexData aData;
+    aData.nNodeIndex = 14;
+
+    sw::LocationResult aResult = aLocator.find(aData);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
+    auto aRectangle = aResult.maRectangles[0];
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4);
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4);
+#endif
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx
new file mode 100644
index 000000000000..f9e3aab6929b
--- /dev/null
+++ b/sw/source/core/inc/SearchResultLocator.hxx
@@ -0,0 +1,45 @@
+/* -*- 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/.
+ *
+ */
+
+#pragma once
+
+#include <swdllapi.h>
+#include <doc.hxx>
+#include <basegfx/range/b2drange.hxx>
+
+namespace sw
+{
+struct SearchIndexData
+{
+    sal_uInt32 nNodeIndex;
+};
+
+struct LocationResult
+{
+    bool mbFound = false;
+    std::vector<basegfx::B2DRange> maRectangles;
+};
+
+class SW_DLLPUBLIC SearchResultLocator
+{
+    SwDoc* mpDocument;
+
+public:
+    SearchResultLocator(SwDoc* pDoc)
+        : mpDocument(pDoc)
+    {
+    }
+
+    LocationResult find(SearchIndexData const& rSearchIndexData);
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
new file mode 100644
index 000000000000..09aa12ffeb85
--- /dev/null
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -0,0 +1,47 @@
+/* -*- 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 <SearchResultLocator.hxx>
+#include <node.hxx>
+#include <drawdoc.hxx>
+#include <frame.hxx>
+#include <cntfrm.hxx>
+#include <viewsh.hxx>
+#include <IDocumentLayoutAccess.hxx>
+
+namespace sw
+{
+LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData)
+{
+    LocationResult aResult;
+    SwNodes const& rNodes = mpDocument->GetNodes();
+    if (rSearchIndexData.nNodeIndex >= rNodes.Count())
+        return aResult;
+    SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
+
+    auto* pContentNode = pNode->GetContentNode();
+    auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
+
+    if (pContentNode && pShell)
+    {
+        const SwFrame* pFrame = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
+        SwRect const& rArea = pFrame->getFrameArea();
+
+        aResult.mbFound = true;
+        aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), rArea.Left() + rArea.Width(),
+                                          rArea.Top() + rArea.Height());
+    }
+
+    return aResult;
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 551a36a058faea1b66c411bf346772af8be36afd
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Jun 30 16:33:48 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Sep 1 05:10:03 2021 +0200

    indexing: add indexing export as an export filter for Writer
    
    Change-Id: I26157a8ffeee80b03866569d3d3cec2a34fe377d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118144
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 95b06d3aa514ce83f82fd538d1731fc6363e4b8a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121107
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk
index d53afa704fc9..dfeacc6a542c 100644
--- a/filter/Configuration_filter.mk
+++ b/filter/Configuration_filter.mk
@@ -358,6 +358,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu
 	writer_OOXML \
 	writer_OOXML_Template \
 	writer_layout_dump_xml \
+	writer_indexing_export_xml \
 	writer_BroadBand_eBook \
 	writer_FictionBook_2 \
 	writer_PalmDoc \
@@ -407,6 +408,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters
 	OOXML_Text \
 	OOXML_Text_Template \
 	writer_layout_dump \
+	writer_indexing_export \
 	BroadBand_eBook \
 	FictionBook_2 \
 	PalmDoc \
diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index e9e149511cff..64c3fcbb1f24 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -273,6 +273,7 @@ int getFlatTypeRank(const OUString& rType)
 
         // Export only
         "writer_layout_dump_xml",
+        "writer_indexing_export",
         "graphic_HTML",
 
         // Internal use only
diff --git a/filter/source/config/fragments/filters/writer_indexing_export.xcu b/filter/source/config/fragments/filters/writer_indexing_export.xcu
new file mode 100644
index 000000000000..28cbe5b5b055
--- /dev/null
+++ b/filter/source/config/fragments/filters/writer_indexing_export.xcu
@@ -0,0 +1,22 @@
+<!--
+ * 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/.
+ *
+-->
+
+<node oor:name="writer_indexing_export" oor:op="replace">
+    <prop oor:name="Flags"><value>EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+    <prop oor:name="UIComponent"/>
+    <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.IndexingExportFilter</value></prop>
+    <prop oor:name="UserData"><value></value></prop>
+    <prop oor:name="UIName">
+        <value xml:lang="en-US">Writer Indexing Export XML</value>
+    </prop>
+    <prop oor:name="FileFormatVersion"><value>0</value></prop>
+    <prop oor:name="Type"><value>writer_indexing_export_xml</value></prop>
+    <prop oor:name="TemplateName"/>
+    <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
+</node>
diff --git a/filter/source/config/fragments/types/writer_indexing_export_xml.xcu b/filter/source/config/fragments/types/writer_indexing_export_xml.xcu
new file mode 100644
index 000000000000..4cda6e597461
--- /dev/null
+++ b/filter/source/config/fragments/types/writer_indexing_export_xml.xcu
@@ -0,0 +1,21 @@
+<!--
+ * 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/.
+ *
+-->
+
+<node oor:name="writer_indexing_export_xml" oor:op="replace" >
+    <prop oor:name="DetectService"/>
+    <prop oor:name="URLPattern"/>
+    <prop oor:name="Extensions"><value>xml</value></prop>
+    <prop oor:name="MediaType"/>
+    <prop oor:name="Preferred"><value>false</value></prop>
+    <prop oor:name="PreferredFilter"/>
+    <prop oor:name="UIName">
+        <value>Writer Indexing Export XML</value>
+    </prop>
+    <prop oor:name="ClipboardFormat"/>
+</node>
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 616b34f44b41..1c5884008c23 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -570,6 +570,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/filter/xml/xmltexte \
     sw/source/filter/xml/xmltexti \
     sw/source/filter/indexing/IndexingExport \
+    sw/source/filter/indexing/IndexingExportFilter \
     sw/source/uibase/app/appenv \
     sw/source/uibase/app/apphdl \
     sw/source/uibase/app/applab \
diff --git a/sw/source/filter/inc/IndexingExportFilter.hxx b/sw/source/filter/inc/IndexingExportFilter.hxx
new file mode 100644
index 000000000000..82c56dfa9a61
--- /dev/null
+++ b/sw/source/filter/inc/IndexingExportFilter.hxx
@@ -0,0 +1,68 @@
+/* -*- 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/.
+ */
+
+#pragma once
+
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+namespace sw
+{
+class IndexingExportFilter final
+    : public cppu::WeakImplHelper<css::document::XFilter, css::document::XExporter,
+                                  css::lang::XInitialization, css::lang::XServiceInfo>
+{
+private:
+    css::uno::Reference<css::lang::XComponent> m_xSourceDocument;
+
+public:
+    IndexingExportFilter() {}
+
+    // XFilter
+    virtual sal_Bool SAL_CALL
+    filter(const css::uno::Sequence<css::beans::PropertyValue>& aDescriptor) override;
+
+    virtual void SAL_CALL cancel() override {}
+
+    // XExporter
+    virtual void SAL_CALL
+    setSourceDocument(const css::uno::Reference<css::lang::XComponent>& xDocument) override
+    {
+        m_xSourceDocument = xDocument;
+    }
+
+    // XInitialization
+    virtual void SAL_CALL
+    initialize(const css::uno::Sequence<css::uno::Any>& /*aArguments*/) override
+    {
+    }
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override
+    {
+        return "com.sun.star.comp.Writer.IndexingExportFilter";
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(OUString const& rServiceName) override
+    {
+        return cppu::supportsService(this, rServiceName);
+    }
+
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
+    {
+        return { "com.sun.star.document.ExportFilter" };
+    }
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/indexing/IndexingExportFilter.cxx b/sw/source/filter/indexing/IndexingExportFilter.cxx
new file mode 100644
index 000000000000..52488782aaf9
--- /dev/null
+++ b/sw/source/filter/indexing/IndexingExportFilter.cxx
@@ -0,0 +1,63 @@
+/* -*- 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 <IndexingExportFilter.hxx>
+#include <IndexingExport.hxx>
+
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <comphelper/servicehelper.hxx>
+
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <svl/outstrm.hxx>
+
+using namespace css;
+
+namespace sw
+{
+sal_Bool IndexingExportFilter::filter(const uno::Sequence<beans::PropertyValue>& aDescriptor)
+{
+    bool bReturn = false;
+
+    utl::MediaDescriptor aMediaDesc = aDescriptor;
+
+    // Actually get the SwRootFrame to call dumpAsXml
+    auto pXTextDocument
+        = comphelper::getUnoTunnelImplementation<SwXTextDocument>(m_xSourceDocument);
+    if (pXTextDocument)
+    {
+        uno::Reference<io::XOutputStream> xOutputStream = aMediaDesc.getUnpackedValueOrDefault(
+            utl::MediaDescriptor::PROP_OUTPUTSTREAM(), uno::Reference<io::XOutputStream>());
+
+        std::unique_ptr<SvStream> pStream(new SvOutputStream(xOutputStream));
+        SwDocShell* pShell = pXTextDocument->GetDocShell();
+        SwDoc* pDoc = pShell->GetDoc();
+        if (pDoc)
+        {
+            IndexingExport aIndexingExport(*pStream, pDoc);
+            bReturn = aIndexingExport.runExport();
+        }
+    }
+
+    return bReturn;
+}
+
+} // end namespace sw
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_Writer_IndexingExportFilter_get_implementation(
+    css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
+{
+    return cppu::acquire(new sw::IndexingExportFilter());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/util/sw.component b/sw/util/sw.component
index f4ad4f7e3339..e05a865a6471 100644
--- a/sw/util/sw.component
+++ b/sw/util/sw.component
@@ -151,6 +151,10 @@
       constructor="com_sun_star_util_comp_FinalThreadManager_get_implementation">
     <service name="com.sun.star.util.JobManager"/>
   </implementation>
+  <implementation name="com.sun.star.comp.Writer.IndexingExportFilter"
+      constructor="com_sun_star_comp_Writer_IndexingExportFilter_get_implementation">
+    <service name="com.sun.star.comp.Writer.IndexingExportFilter"/>
+  </implementation>
   <implementation name="com.sun.star.comp.Writer.LayoutDump"
       constructor="com_sun_star_comp_Writer_LayoutDump_get_implementation">
     <service name="com.sun.star.comp.Writer.LayoutDump"/>


More information about the Libreoffice-commits mailing list