sw/qa/extras/uiwriter/uiwriter2.cxx | 25 +++++++++++++++++++++++++ sw/source/uibase/uno/unotxdoc.cxx | 22 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-)
New commits: commit 1f23e5dc4f5697e748ee5caad4142e01e5ffa3ef Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Jul 16 16:22:29 2019 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jul 17 13:06:17 2019 +0200 sw comments on frames: no overlay in the LOK API, either So that the Online and the desktop rendering result match. (cherry picked from commit 28fcb7d86765194b4015e7023449333f43aba0c5) Conflicts: sw/qa/extras/uiwriter/uiwriter2.cxx [ cp-6.2 backport note: added explicit IsEmpty() check, otherwise we would expose negative width/height for empty rectangles via LOK, which doesn't happen on master. ] Change-Id: Iabc62e74f5ce5880b663b4d7217c81729592a356 Reviewed-on: https://gerrit.libreoffice.org/75760 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index ddaa4894af2e..04265e0644e7 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -9,6 +9,11 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/awt/FontSlant.hpp> + +#include <sstream> + +#include <boost/property_tree/json_parser.hpp> + #include <com/sun/star/frame/DispatchHelper.hpp> #include <comphelper/propertysequence.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -1186,6 +1191,26 @@ void SwUiWriterTest2::testImageComment() const SwRect& rAnchor = pItem->pPostIt->GetAnchorRect(); CPPUNIT_ASSERT_LESSEQUAL(static_cast<long>(1418), rAnchor.Left()); } + + // Test the comment anchor we expose via the LOK API. + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1418, 1418, 0, 0 + // - Actual : 1418, 1418, 1024, 1024 + // I.e. the anchor position had a non-empty size, which meant different rendering via tiled + // rendering and on the desktop. + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + OUString aPostits = pTextDoc->getPostIts(); + std::stringstream aStream(aPostits.toUtf8().getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments")) + { + const boost::property_tree::ptree& rComment = rValue.second; + OString aAnchorPos(rComment.get<std::string>("anchorPos").c_str()); + CPPUNIT_ASSERT_EQUAL(OString("1418, 1418, 0, 0"), aAnchorPos); + } + #endif // Now delete the image. diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 10720bf3b334..423b88647402 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3345,10 +3345,17 @@ OUString SwXTextDocument::getPostIts() const SwPostItField* pField = pWin->GetPostItField(); const SwRect& aRect = pWin->GetAnchorRect(); - const tools::Rectangle aSVRect(aRect.Pos().getX(), + tools::Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height()); + + if (!sidebarItem->maLayoutInfo.mPositionFromCommentAnchor) + { + // Comments on frames: anchor position is the corner position, not the whole frame. + aSVRect.SetSize(Size(0, 0)); + } + std::vector<OString> aRects; for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges()) { @@ -3363,7 +3370,18 @@ OUString SwXTextDocument::getPostIts() aAnnotation.put("author", pField->GetPar1().toUtf8().getStr()); aAnnotation.put("text", pField->GetPar2().toUtf8().getStr()); aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime())); - aAnnotation.put("anchorPos", aSVRect.toString()); + { + std::stringstream ss; + if (aSVRect.IsEmpty()) + { + ss << aSVRect.getX() << ", " << aSVRect.getY() << ", 0, 0"; + } + else + { + ss << aSVRect.getX() << ", " << aSVRect.getY() << ", " << aSVRect.getWidth() << ", " << aSVRect.getHeight(); + } + aAnnotation.put("anchorPos", ss.str()); + } aAnnotation.put("textRange", sRects.getStr()); aAnnotations.push_back(std::make_pair("", aAnnotation)); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits