summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-07-16 16:22:29 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-07-17 13:06:41 +0200
commitf5221894d961cbec0076bf1aac8c0602d3bedf87 (patch)
treec1e909b7e4c287ed1076f4305190dcdbcb47422a
parent555bf69bbe4688db160c8d409153ff85bb6e2434 (diff)
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.0 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/75766 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx25
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx22
2 files changed, 45 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 1365b752e8a4..07f0214c4b40 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 <swdtflvr.hxx>
#include <wrtsh.hxx>
#include <redline.hxx>
@@ -554,6 +559,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 9411a6834971..cd396bcccb81 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3364,10 +3364,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 (!(*i)->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())
{
@@ -3382,7 +3389,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));