svx/source/svdraw/svdmrkv.cxx |    3 ++-
 svx/source/svdraw/svdpage.cxx |   24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 10 deletions(-)

New commits:
commit 81780168e35dce08e3d30d95eb3b9e65849d5a14
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Wed Aug 7 17:41:21 2024 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Sep 10 08:40:00 2024 +0200

    Simplify GetObjectRectangles function with JSonWriter.
    
    This is a follow up for:
    * https://gerrit.libreoffice.org/c/core/+/171374
    
    Change-Id: I66bf8c100053907a0e2999730a6ef19e1144ae58
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172883
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 8526e7e51f17..d63556a50d3d 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -1228,7 +1228,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 1cff663e1f08..7618c51c825a 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -29,6 +29,7 @@
 #include <string.h>
 
 #include <tools/debug.hxx>
+#include <tools/json_writer.hxx>
 #include <comphelper/diagnose_ex.hxx>
 
 #include <sfx2/viewsh.hxx>
@@ -130,21 +131,26 @@ SdrObject* SdrObjList::getSdrObjectFromSdrObjList() const
 
 OString SdrObjList::GetObjectRectangles(const SdrObjList& rSrcList)
 {
-    OStringBuffer aBuffer("[");
+    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();
-            aBuffer.append("["_ostr + rectangle.toString() + ", "_ostr + 
OString::number(item->GetOrdNum()) + "]"_ostr);
+            if (item->IsPrintable() && item->IsVisible())
+            {
+                tools::Rectangle rectangle = item->GetCurrentBoundRect();
+                OStringBuffer value(OString::number(item->GetOrdNum()));
+                value = rectangle.toString() + ", "_ostr + value;
+
+                auto subArray = jsWriter.startAnonArray();
+                jsWriter.putRaw(value.makeStringAndClear());
+            }
         }
     }
 
-    OString aResult = aBuffer.makeStringAndClear();
-    aResult = aResult.replaceAll("]["_ostr, "],["_ostr);
-
-    return aResult + "]"_ostr;
+    return jsWriter.finishAndGetAsOString();
 }
 
 void SdrObjList::CopyObjects(const SdrObjList& rSrcList)

Reply via email to