[Libreoffice-commits] core.git: desktop/qa desktop/source include/LibreOfficeKit include/vcl sw/inc sw/source

2021-07-30 Thread Tomaž Vajngerl (via logerrit)
 desktop/qa/data/SearchIndexResultTest.odt   |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   49 +++-
 desktop/source/lib/init.cxx |   57 
 include/LibreOfficeKit/LibreOfficeKit.h |6 ++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   16 +++
 include/vcl/ITiledRenderable.hxx|9 
 sw/inc/unotxdoc.hxx |3 +
 sw/source/uibase/uno/unotxdoc.cxx   |   25 
 8 files changed, 164 insertions(+), 1 deletion(-)

New commits:
commit e1511ce551f27a5560600029193f076fd65ece17
Author: Tomaž Vajngerl 
AuthorDate: Fri Jul 9 14:41:21 2021 +0900
Commit: Tomaž Vajngerl 
CommitDate: Fri Jul 30 08:22:19 2021 +0200

indexing: add LOKit API to render the search result into a bitmap

This adds a new LOKit API to render the search result into a bitmap
buffer. It combines the SearchResultLocator to get the location
inside the document of the search result (a series of rectangles)
and the existing LOKit paintTile API to render the result into
a bitmap (byte) buffer.

It also adds a LOKit test to show how the API is used and to render
a search result of a example document.

Change-Id: I4284d90188777fd28158d029daa04151e71022bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118670
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/desktop/qa/data/SearchIndexResultTest.odt 
b/desktop/qa/data/SearchIndexResultTest.odt
new file mode 100644
index ..58ed3a0f5447
Binary files /dev/null and b/desktop/qa/data/SearchIndexResultTest.odt differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 2a26b04dcfa0..dfbee77167b8 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -59,6 +59,8 @@
 #include 
 
 #include 
+#include 
+#include 
 
 #if USE_TLS_NSS
 #include 
@@ -205,6 +207,7 @@ public:
 void testMetricField();
 void testMultiDocuments();
 void testJumpCursor();
+void testRenderSearchResult();
 void testABI();
 
 CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -268,6 +271,7 @@ public:
 CPPUNIT_TEST(testMetricField);
 CPPUNIT_TEST(testMultiDocuments);
 CPPUNIT_TEST(testJumpCursor);
+CPPUNIT_TEST(testRenderSearchResult);
 CPPUNIT_TEST(testABI);
 CPPUNIT_TEST_SUITE_END();
 
@@ -3103,6 +3107,48 @@ void DesktopLOKTest::testJumpCursor()
 comphelper::LibreOfficeKit::setTiledAnnotations(true);
 }
 
+void DesktopLOKTest::testRenderSearchResult()
+{
+constexpr const bool bDumpBitmap = false;
+
+LibLODocument_Impl* pDocument = loadDoc("SearchIndexResultTest.odt");
+pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+
+Scheduler::ProcessEventsToIdle();
+
+unsigned char* pBuffer = nullptr;
+OString aJSON = "{ \"node_index\" : 19 }";
+
+int nWidth = 0;
+int nHeight = 0;
+size_t nByteSize = 0;
+
+bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, 
aJSON.getStr(), , , , );
+
+CPPUNIT_ASSERT(bResult);
+CPPUNIT_ASSERT(pBuffer);
+
+Scheduler::ProcessEventsToIdle();
+
+CPPUNIT_ASSERT_EQUAL(642, nWidth);
+CPPUNIT_ASSERT_EQUAL(561, nHeight);
+CPPUNIT_ASSERT_EQUAL(size_t(1440648), nByteSize);
+
+const sal_uInt8* pD = reinterpret_cast(pBuffer);
+BitmapEx aBitmap = vcl::bitmap::CreateFromData(pD, nWidth, nHeight, nWidth 
* 4, vcl::PixelFormat::N32_BPP, true, true);
+
+if (bDumpBitmap)
+{
+SvFileStream aStream("~/SearchResultBitmap.png", StreamMode::WRITE | 
StreamMode::TRUNC);
+vcl::PNGWriter aPNGWriter(aBitmap);
+aPNGWriter.Write(aStream);
+}
+CPPUNIT_ASSERT_EQUAL(tools::Long(642), aBitmap.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL(tools::Long(561), aBitmap.GetSizePixel().Height());
+
+std::free(pBuffer);
+}
+
 namespace {
 
 constexpr size_t classOffset(int i)
@@ -3200,10 +3246,11 @@ void DesktopLOKTest::testABI()
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct 
_LibreOfficeKitDocumentClass, completeFunction));
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), offsetof(struct 
_LibreOfficeKitDocumentClass, setWindowTextSelection));
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct 
_LibreOfficeKitDocumentClass, sendFormFieldEvent));
+CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), offsetof(struct 
_LibreOfficeKitDocumentClass, renderSearchResult));
 
 // Extending is fine, update this, and add new assert for the offsetof the
 // new method
-CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), sizeof(struct 
_LibreOfficeKitDocumentClass));
+CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), sizeof(struct 
_LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 

[Libreoffice-commits] core.git: desktop/qa desktop/source include/LibreOfficeKit include/vcl sw/inc sw/source

2020-05-08 Thread Tamás Zolnai (via logerrit)
 desktop/qa/desktop_lib/test_desktop_lib.cxx |3 +-
 desktop/source/lib/init.cxx |   33 +
 include/LibreOfficeKit/LibreOfficeKit.h |4 +++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   10 +++
 include/vcl/ITiledRenderable.hxx|   11 
 sw/inc/unotxdoc.hxx |3 ++
 sw/source/uibase/uno/unotxdoc.cxx   |   36 
 7 files changed, 99 insertions(+), 1 deletion(-)

New commits:
commit 36508d0110248f6683757602cd1668547dbfb253
Author: Tamás Zolnai 
AuthorDate: Wed May 6 14:33:10 2020 +0200
Commit: Tamás Zolnai 
CommitDate: Fri May 8 22:42:35 2020 +0200

lok: MSForms: Handle event about item selection of a drop-down field.

Change-Id: I095013097348c98361b6614e4ddf1e9029923c7f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93659
Tested-by: Tamás Zolnai 
Reviewed-by: Tamás Zolnai 

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 3344279f1a78..30dd2c60dc3c 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2923,10 +2923,11 @@ void DesktopLOKTest::testABI()
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(58), offsetof(struct 
_LibreOfficeKitDocumentClass, paintWindowForView));
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct 
_LibreOfficeKitDocumentClass, completeFunction));
 CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), offsetof(struct 
_LibreOfficeKitDocumentClass, setWindowTextSelection));
+CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct 
_LibreOfficeKitDocumentClass, sendFormFieldEvent));
 
 // Extending is fine, update this, and add new assert for the offsetof the
 // new method
-CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), sizeof(struct 
_LibreOfficeKitDocumentClass));
+CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), sizeof(struct 
_LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ccd32a035ff5..c7763b608a28 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1137,6 +1137,10 @@ static void doc_resizeWindow(LibreOfficeKitDocument* 
pThis, unsigned nLOKWindowI
  const int nWidth, const int nHeight);
 
 static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex);
+
+
+static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis,
+   const char* pArguments);
 } // extern "C"
 
 namespace {
@@ -1252,6 +1256,8 @@ LibLODocument_Impl::LibLODocument_Impl(const 
uno::Reference createViewWithOptions = doc_createViewWithOptions;
 m_pDocumentClass->completeFunction = doc_completeFunction;
 
+m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent;
+
 gDocumentClass = m_pDocumentClass;
 }
 pClass = m_pDocumentClass.get();
@@ -5412,6 +5418,33 @@ static void doc_completeFunction(LibreOfficeKitDocument* 
pThis, int nIndex)
 pDoc->completeFunction(nIndex);
 }
 
+
+static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, const char* 
pArguments)
+{
+SolarMutexGuard aGuard;
+
+// Supported in Writer only
+if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT)
+return;
+
+StringMap aMap(jsonToStringMap(pArguments));
+ITiledRenderable* pDoc = getTiledRenderable(pThis);
+if (!pDoc)
+{
+SetLastExceptionMsg("Document doesn't support tiled rendering!");
+return;
+}
+
+// Sanity check
+if (aMap.find("type") == aMap.end() || aMap.find("cmd") == aMap.end())
+{
+SetLastExceptionMsg("Wrong arguments for sendFormFieldEvent!");
+return;
+}
+
+pDoc->executeFromFieldEvent(aMap);
+}
+
 static char* lo_getError (LibreOfficeKit *pThis)
 {
 comphelper::ProfileZone aZone("lo_getError");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index 6203c11fb044..309744522004 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -446,6 +446,10 @@ struct _LibreOfficeKitDocumentClass
 int nX,
 int nY);
 
+/// @see lok::Document::sendFormFieldEvent
+void (*sendFormFieldEvent) (LibreOfficeKitDocument* pThis,
+const char* pArguments);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx 
b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 4076637863fd..37eacdfb3649 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -779,6 +779,16 @@ public:
 mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY);
 }
 

[Libreoffice-commits] core.git: desktop/qa desktop/source include/LibreOfficeKit include/vcl sw/inc sw/source

2015-09-29 Thread Miklos Vajna
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   25 +
 desktop/source/lib/init.cxx |   19 +++
 include/LibreOfficeKit/LibreOfficeKit.h |3 +++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |   14 ++
 include/vcl/ITiledRenderable.hxx|8 
 sw/inc/crsrsh.hxx   |2 ++
 sw/inc/unotxdoc.hxx |2 ++
 sw/source/core/crsr/crsrsh.cxx  |   14 ++
 sw/source/uibase/uno/unotxdoc.cxx   |   11 +++
 9 files changed, 98 insertions(+)

New commits:
commit d355207b45755cfe1eef0147bc25ead931741684
Author: Miklos Vajna 
Date:   Tue Sep 29 10:47:31 2015 +0200

lok: add Document::getPartPageRectangles()

Change-Id: I20acd44f7a81471982ba96ad3894a9124e035c5f

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index d7b9347..a7696d8 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -52,12 +52,14 @@ public:
 void testGetFonts();
 void testCreateView();
 void testGetFilterTypes();
+void testGetPartPageRectangles();
 
 CPPUNIT_TEST_SUITE(DesktopLOKTest);
 CPPUNIT_TEST(testGetStyles);
 CPPUNIT_TEST(testGetFonts);
 CPPUNIT_TEST(testCreateView);
 CPPUNIT_TEST(testGetFilterTypes);
+CPPUNIT_TEST(testGetPartPageRectangles);
 CPPUNIT_TEST_SUITE_END();
 
 uno::Reference mxComponent;
@@ -152,6 +154,29 @@ void DesktopLOKTest::testCreateView()
 closeDoc();
 }
 
+void DesktopLOKTest::testGetPartPageRectangles()
+{
+// Test that we get as many page rectangles as expected: blank document is
+// one page.
+LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+char* pRectangles = pDocument->pClass->getPartPageRectangles(pDocument);
+OUString sRectangles = OUString::fromUtf8(pRectangles);
+
+std::vector aRectangles;
+sal_Int32 nIndex = 0;
+do
+{
+OUString aRectangle = sRectangles.getToken(0, ';', nIndex);
+if (!aRectangle.isEmpty())
+aRectangles.push_back(aRectangle);
+}
+while (nIndex >= 0);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aRectangles.size());
+
+free(pRectangles);
+closeDoc();
+}
+
 void DesktopLOKTest::testGetFilterTypes()
 {
 LibLibreOffice_Impl aOffice;
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b581bca..509983c 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -204,6 +204,7 @@ static void doc_destroy(LibreOfficeKitDocument* pThis);
 static int  doc_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const 
char* pFormat, const char* pFilterOptions);
 static int doc_getDocumentType(LibreOfficeKitDocument* pThis);
 static int doc_getParts(LibreOfficeKitDocument* pThis);
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis);
 static int doc_getPart(LibreOfficeKitDocument* pThis);
 static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
@@ -266,6 +267,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
saveAs = doc_saveAs;
 m_pDocumentClass->getDocumentType = doc_getDocumentType;
 m_pDocumentClass->getParts = doc_getParts;
+m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles;
 m_pDocumentClass->getPart = doc_getPart;
 m_pDocumentClass->setPart = doc_setPart;
 m_pDocumentClass->getPartName = doc_getPartName;
@@ -659,6 +661,23 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int 
nPart)
 pDoc->setPart( nPart );
 }
 
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
+{
+ITiledRenderable* pDoc = getTiledRenderable(pThis);
+if (!pDoc)
+{
+gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+return 0;
+}
+
+OUString sRectangles = pDoc->getPartPageRectangles();
+OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8);
+char* pMemory = static_cast(malloc(aString.getLength() + 1));
+strcpy(pMemory, aString.getStr());
+return pMemory;
+
+}
+
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
 {
 ITiledRenderable* pDoc = getTiledRenderable(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index d5094bd..d83dd49 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -85,6 +85,9 @@ struct _LibreOfficeKitDocumentClass
 /// @see lok::Document::getParts().
 int (*getParts) (LibreOfficeKitDocument* pThis);
 
+/// @see lok::Document::getPartPageRectangles().
+char* (*getPartPageRectangles) (LibreOfficeKitDocument* pThis);
+
 /// @see lok::Document::getPart().
 int