svx/source/svdraw/svdmrkv.cxx |    3 ++-
 svx/source/svdraw/svdpage.cxx |   24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 10 deletions(-)
New commits:
commit 7f259891ed8d7f20466280df7a2ddbc2dfab9ad8
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Wed Aug 7 17:41:21 2024 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Aug 9 08:45:11 2024 +0200

    Simplify GetObjectRectangles function with JSonWriter.
    
    This is a follow up for:
    * https://gerrit.libreoffice.org/c/core/+/171374
    
    Signed-off-by: Gökay Şatır <gokaysa...@collabora.com>
    Change-Id: I66bf8c100053907a0e2999730a6ef19e1144ae58
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171598
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 1c78c9dab9e9..67df22bd05ad 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -1223,7 +1223,8 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
                 {
                     // Send all objects' rectangles along with the selected 
object's information.
                     // Other rectangles can be used for aligning the selected 
object referencing the others.
-                    OString objectRectangles = 
SdrObjList::GetObjectRectangles(*pPage);
+                    // Replace curly braces with empty string in order to 
merge it with the resulting string.
+                    OString objectRectangles = 
SdrObjList::GetObjectRectangles(*pPage).replaceAll("{"_ostr, 
""_ostr).replaceAll("}"_ostr, ""_ostr);
                     aExtraInfo.append(", \"ObjectRectangles\": "_ostr + 
objectRectangles);
                 }
 
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index cbf15673b12c..eefed8094632 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -30,6 +30,7 @@
 #include <string.h>
 
 #include <tools/debug.hxx>
+#include <tools/json_writer.hxx>
 #include <comphelper/diagnose_ex.hxx>
 #include <comphelper/lok.hxx>
 
@@ -136,21 +137,26 @@ SdrObject* SdrObjList::getSdrObjectFromSdrObjList() const
 
 OString SdrObjList::GetObjectRectangles(const SdrObjList& rSrcList)
 {
-    OString result = "["_ostr;
+    tools::JsonWriter jsWriter;
 
-    for (const rtl::Reference<SdrObject>& item: rSrcList)
     {
-        if (item->IsPrintable() && item->IsVisible())
+        auto array = jsWriter.startAnonArray();
+
+        for (const rtl::Reference<SdrObject>& item: rSrcList)
         {
-            tools::Rectangle rectangle = item->GetCurrentBoundRect();
-            OString ordNum(std::to_string(item->GetOrdNum()));
-            result += "["_ostr + rectangle.toString() + ", "_ostr + ordNum + 
"]"_ostr;
+            if (item->IsPrintable() && item->IsVisible())
+            {
+                tools::Rectangle rectangle = item->GetCurrentBoundRect();
+                OString value(std::to_string(item->GetOrdNum()));
+                value = rectangle.toString() + ", "_ostr + value;
+
+                auto subArray = jsWriter.startAnonArray();
+                jsWriter.putRaw(value);
+            }
         }
     }
 
-    result = result.replaceAll("]["_ostr, "],["_ostr);
-
-    return result + "]"_ostr;
+    return jsWriter.finishAndGetAsOString();
 }
 
 void SdrObjList::CopyObjects(const SdrObjList& rSrcList)

Reply via email to