sd/source/core/annotations/Annotation.cxx | 55 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 28 deletions(-)
New commits: commit 94d59b6227bf6818b191ee37d28b6fa64b67c9cf Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Thu Mar 24 11:29:59 2022 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Mon Apr 11 20:59:31 2022 +0200 lok: use JsonWriter for annotations notification This will unify received objects in LOK. boost::property_tree used "string" for number values we expect them to be a "number" type. Change-Id: Ie90d7e2dd98bb371fc09878dcc6e96f4cdf73f3b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132054 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132808 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index 1d1ca39fc9dd..991412f063d5 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -22,8 +22,6 @@ #include <Annotation.hxx> #include <drawdoc.hxx> -#include <boost/property_tree/json_parser.hpp> - #include <com/sun/star/drawing/XDrawPage.hpp> #include <comphelper/processfactory.hxx> @@ -38,6 +36,8 @@ #include <notifydocumentevent.hxx> +#include <tools/json_writer.hxx> + using namespace css; namespace com::sun::star::uno { class XComponentContext; } @@ -342,34 +342,33 @@ namespace { std::string lcl_LOKGetCommentPayload(CommentNotificationType nType, uno::Reference<office::XAnnotation> const & rxAnnotation) { - boost::property_tree::ptree aAnnotation; - aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" : - (nType == CommentNotificationType::Remove ? "Remove" : - (nType == CommentNotificationType::Modify ? "Modify" : "???")))); - aAnnotation.put("id", sd::getAnnotationId(rxAnnotation)); - if (nType != CommentNotificationType::Remove && rxAnnotation.is()) + ::tools::JsonWriter aJsonWriter; { - aAnnotation.put("id", sd::getAnnotationId(rxAnnotation)); - aAnnotation.put("author", rxAnnotation->getAuthor()); - aAnnotation.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime())); - uno::Reference<text::XText> xText(rxAnnotation->getTextRange()); - aAnnotation.put("text", xText->getString()); - const SdPage* pPage = sd::getAnnotationPage(rxAnnotation); - aAnnotation.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString()); - geometry::RealPoint2D const & rPoint = rxAnnotation->getPosition(); - geometry::RealSize2D const & rSize = rxAnnotation->getSize(); - ::tools::Rectangle aRectangle(Point(rPoint.X * 100.0, rPoint.Y * 100.0), Size(rSize.Width * 100.0, rSize.Height * 100.0)); - aRectangle = o3tl::convert(aRectangle, o3tl::Length::mm100, o3tl::Length::twip); - OString sRectangle = aRectangle.toString(); - aAnnotation.put("rectangle", sRectangle.getStr()); + auto aCommentNode = aJsonWriter.startNode("comment"); + + aJsonWriter.put("action", (nType == CommentNotificationType::Add ? "Add" : + (nType == CommentNotificationType::Remove ? "Remove" : + (nType == CommentNotificationType::Modify ? "Modify" : "???")))); + aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation)); + + if (nType != CommentNotificationType::Remove && rxAnnotation.is()) + { + aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation)); + aJsonWriter.put("author", rxAnnotation->getAuthor()); + aJsonWriter.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime())); + uno::Reference<text::XText> xText(rxAnnotation->getTextRange()); + aJsonWriter.put("text", xText->getString()); + const SdPage* pPage = sd::getAnnotationPage(rxAnnotation); + aJsonWriter.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString()); + geometry::RealPoint2D const & rPoint = rxAnnotation->getPosition(); + geometry::RealSize2D const & rSize = rxAnnotation->getSize(); + ::tools::Rectangle aRectangle(Point(rPoint.X * 100.0, rPoint.Y * 100.0), Size(rSize.Width * 100.0, rSize.Height * 100.0)); + aRectangle = OutputDevice::LogicToLogic(aRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + OString sRectangle = aRectangle.toString(); + aJsonWriter.put("rectangle", sRectangle.getStr()); + } } - - boost::property_tree::ptree aTree; - aTree.add_child("comment", aAnnotation); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - - return aStream.str(); + return aJsonWriter.extractData(); } } // anonymous ns