From 47f5876b94d6c2d12df4fd08a92ba21320ca4fba Mon Sep 17 00:00:00 2001 From: merttumer Date: Fri, 2 Apr 2021 16:14:55 +0300 Subject: Improve dumpGluePointsAsJSON added gridoffset for the shape for calc changed the logic, now the ordnum would be enough Change-Id: Iebe7d29c569a4cb968fe2e5ef1692b59f0c4b2d8 Signed-off-by: merttumer Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113516 --- svx/source/svdraw/svdmrkv.cxx | 62 ++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index c2d4c09282e3..875d0dfc3993 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -712,37 +712,51 @@ bool SdrMarkView::dumpGluePointsToJSON(boost::property_tree::ptree& rTree) if (rOutDev->GetMapMode().GetMapUnit() == MapUnit::Map100thMM) bConvertUnit = true; const SdrObjList* pOL = mpMarkedPV->GetObjList(); + if (!pOL) + return false; const size_t nObjCount = pOL->GetObjCount(); boost::property_tree::ptree elements; for (size_t nObjNum = 0; nObjNum < nObjCount; ++nObjNum) { - const SdrObject* pObj = pOL->GetObj(nObjNum); + SdrObject* pObj = pOL->GetObj(nObjNum); + if (!pObj) + continue; + if (pObj == GetMarkedObjectByIndex(0)) + continue; const SdrGluePointList* pGPL = pObj->GetGluePointList(); - if (pGPL != nullptr && pGPL->GetCount()) + bool VertexObject = !(pGPL && pGPL->GetCount()); + const size_t count = !VertexObject ? pGPL->GetCount() : 4; + boost::property_tree::ptree object; + boost::property_tree::ptree points; + for (size_t i = 0; i < count; ++i) { - boost::property_tree::ptree object; - boost::property_tree::ptree points; - for (size_t i = 0; i < pGPL->GetCount(); ++i) - { - boost::property_tree::ptree node; - boost::property_tree::ptree point; - const SdrGluePoint& rGP = (*pGPL)[i]; - // coordinates are relative to the OBJ snap rect - Point rPoint = pObj->GetSnapRect().TopLeft(); - rPoint.Move(rGP.GetPos().getX(), rGP.GetPos().getY()); - if (bConvertUnit) - rPoint = OutputDevice::LogicToLogic(rPoint, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); - point.put("x", rPoint.getX()); - point.put("y", rPoint.getY()); - node.put("glueId", rGP.GetId()); - node.add_child("point", point); - points.push_back(std::make_pair("", node)); - } - object.put("id", reinterpret_cast(pObj)); - object.add_child("gluepoints", points); - elements.push_back(std::make_pair("", object)); - result = true; + boost::property_tree::ptree node; + boost::property_tree::ptree point; + const SdrGluePoint& rGP = !VertexObject ? (*pGPL)[i] : pObj->GetVertexGluePoint(i); + Point rPoint = rGP.GetAbsolutePos(*pObj); + if (bConvertUnit) + rPoint = OutputDevice::LogicToLogic(rPoint, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + point.put("x", rPoint.getX()); + point.put("y", rPoint.getY()); + node.add_child("point", point); + points.push_back(std::make_pair("", node)); + } + basegfx::B2DVector aGridOffset(0.0, 0.0); + Point objLogicRectTopLeft = pObj->GetLogicRect().TopLeft(); + if(getPossibleGridOffsetForPosition(aGridOffset, basegfx::B2DPoint(objLogicRectTopLeft.X(), objLogicRectTopLeft.Y()), GetSdrPageView())) + { + Point p(aGridOffset.getX(), aGridOffset.getY()); + if (bConvertUnit) + p = OutputDevice::LogicToLogic(p, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + boost::property_tree::ptree gridOffset; + gridOffset.put("x", p.getX()); + gridOffset.put("y", p.getY()); + object.add_child("gridoffset", gridOffset); } + object.put("ordnum", pObj->GetOrdNum()); + object.add_child("gluepoints", points); + elements.push_back(std::make_pair("", object)); + result = true; } rTree.add_child("shapes", elements); } -- cgit