diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-09-08 16:34:42 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-09-08 15:18:52 +0200 |
commit | 160b6db92cc94f2ec2447ae0e9c60c8c9dcf3bad (patch) | |
tree | e29cdddaf23e4c85878b3fab10105301b460c8ef | |
parent | 11622c2eb319bb096d4d587ea06a932ba5fceafb (diff) |
indexing: fix correct size and pos. for shapes + more tests
Determining the position and size of the shapes (SdrObjects) was
wrong as the assumption was the values are in Hmm but were in
twips. Added some more tests that check rendering of SdrObjects.
Change-Id: I6ef9287892d1774a1243118a5c97f58384bcfd68
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121801
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | desktop/qa/data/SearchIndexResultShapeTest.odt | bin | 0 -> 9046 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 53 | ||||
-rw-r--r-- | sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/model/SearchResultLocator.cxx | 3 |
4 files changed, 59 insertions, 13 deletions
diff --git a/desktop/qa/data/SearchIndexResultShapeTest.odt b/desktop/qa/data/SearchIndexResultShapeTest.odt Binary files differnew file mode 100644 index 000000000000..4298eb8ad06e --- /dev/null +++ b/desktop/qa/data/SearchIndexResultShapeTest.odt diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 28a5e76a6e1e..c593eca12562 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -207,7 +207,8 @@ public: void testMetricField(); void testMultiDocuments(); void testJumpCursor(); - void testRenderSearchResult(); + void testRenderSearchResult_WriterNode(); + void testRenderSearchResult_CommonNode(); void testABI(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -271,7 +272,8 @@ public: CPPUNIT_TEST(testMetricField); CPPUNIT_TEST(testMultiDocuments); CPPUNIT_TEST(testJumpCursor); - CPPUNIT_TEST(testRenderSearchResult); + CPPUNIT_TEST(testRenderSearchResult_WriterNode); + CPPUNIT_TEST(testRenderSearchResult_CommonNode); CPPUNIT_TEST(testABI); CPPUNIT_TEST_SUITE_END(); @@ -3107,7 +3109,7 @@ void DesktopLOKTest::testJumpCursor() comphelper::LibreOfficeKit::setTiledAnnotations(true); } -void DesktopLOKTest::testRenderSearchResult() +void DesktopLOKTest::testRenderSearchResult_WriterNode() { constexpr const bool bDumpBitmap = false; @@ -3152,6 +3154,51 @@ void DesktopLOKTest::testRenderSearchResult() std::free(pBuffer); } +void DesktopLOKTest::testRenderSearchResult_CommonNode() +{ + constexpr const bool bDumpBitmap = false; + + LibLODocument_Impl* pDocument = loadDoc("SearchIndexResultShapeTest.odt"); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + + Scheduler::ProcessEventsToIdle(); + + unsigned char* pBuffer = nullptr; + OString aPayload = + "<indexing>" + "<paragraph node_type=\"common\" index=\"0\" object_name=\"Shape 1\" />" + "</indexing>"; + + int nWidth = 0; + int nHeight = 0; + size_t nByteSize = 0; + + bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aPayload.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize); + + CPPUNIT_ASSERT(bResult); + CPPUNIT_ASSERT(pBuffer); + + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(192, nWidth); + CPPUNIT_ASSERT_EQUAL(96, nHeight); + CPPUNIT_ASSERT_EQUAL(size_t(73728), nByteSize); + + const sal_uInt8* pD = reinterpret_cast<const sal_uInt8*>(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(192), aBitmap.GetSizePixel().Width()); + CPPUNIT_ASSERT_EQUAL(tools::Long(96), aBitmap.GetSizePixel().Height()); + + std::free(pBuffer); +} + namespace { constexpr size_t classOffset(int i) diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx index 08d074bb86f8..586c07b1e534 100644 --- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -155,11 +155,11 @@ void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects() // inconsistent results #if !defined(_WIN32) && !defined(MACOSX) auto aRectangle = aResult.maRectangles[0]; - CPPUNIT_ASSERT_DOUBLES_EQUAL(1478.0, aRectangle.getMinX(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(3223.0, aRectangle.getMinY(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getWidth(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getHeight(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4); #endif } @@ -183,11 +183,11 @@ void SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPaylo // inconsistent results #if !defined(_WIN32) && !defined(MACOSX) auto aRectangle = aResult.maRectangles[0]; - CPPUNIT_ASSERT_DOUBLES_EQUAL(1478.0, aRectangle.getMinX(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(3223.0, aRectangle.getMinY(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getWidth(), 1e-4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getHeight(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4); #endif } diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx index dd488780981e..435f0110aedf 100644 --- a/sw/source/core/model/SearchResultLocator.cxx +++ b/sw/source/core/model/SearchResultLocator.cxx @@ -65,8 +65,7 @@ void SearchResultLocator::findOne(LocationResult& rResult, SearchIndexData const { if (pObject->GetName() == rSearchIndexData.maObjectName) { - auto aRect = o3tl::convert(pObject->GetLogicRect(), o3tl::Length::mm100, - o3tl::Length::twip); + auto aRect = pObject->GetLogicRect(); rResult.mbFound = true; rResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(), aRect.Left() + aRect.GetWidth(), |