xmloff/source/draw/shapeexport.cxx |   42 +++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

New commits:
commit 470201f392a019ef6f2b9e70377e66e47e839494
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Thu Oct 27 15:08:50 2022 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Fri Oct 28 10:47:36 2022 +0200

    tdf#145240 add flexibility to receiving PolyPolygons over UNO API
    
    Make XMLShapeExport aware and use that PolyPolygons can be not
    only in Bezier format, but also a sequence of Points
    
    Change-Id: Ie00e87d35d4f8aa9d481b2800585c5a770bbbc0a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141935
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/xmloff/source/draw/shapeexport.cxx 
b/xmloff/source/draw/shapeexport.cxx
index f975e4d1d1b2..f12958a9f650 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -2321,37 +2321,35 @@ void XMLShapeExport::ImpExportPolygonShape(
     // prepare name (with most used)
     enum ::xmloff::token::XMLTokenEnum eName(XML_PATH);
 
-    if(bBezier)
+    uno::Any aAny( xPropSet->getPropertyValue("Geometry") );
+    basegfx::B2DPolyPolygon aPolyPolygon;
+
+    // tdf#145240 the Any can contain PolyPolygonBezierCoords or 
PointSequenceSequence
+    // (see OWN_ATTR_BASE_GEOMETRY in 
SvxShapePolyPolygon::getPropertyValueImpl),
+    // so be more flexible in interpreting it. Try to access bezier first:
     {
-        // get PolygonBezier
-        uno::Any aAny( xPropSet->getPropertyValue("Geometry") );
         auto pSourcePolyPolygon = 
o3tl::tryAccess<drawing::PolyPolygonBezierCoords>(aAny);
+
         if(pSourcePolyPolygon && pSourcePolyPolygon->Coordinates.getLength())
         {
-            const basegfx::B2DPolyPolygon aPolyPolygon(
-                basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
-                    *pSourcePolyPolygon));
+            aPolyPolygon = 
basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(*pSourcePolyPolygon);
+        }
+    }
 
-            // complex polygon shape, write as svg:d
-            const OUString aPolygonString(
-                basegfx::utils::exportToSvgD(
-                    aPolyPolygon,
-                    true,       // bUseRelativeCoordinates
-                    false,      // bDetectQuadraticBeziers: not used in old, 
but maybe activated now
-                    true));     // bHandleRelativeNextPointCompatible
+    // if received no data, try to access point sequence second:
+    if(0 == aPolyPolygon.count())
+    {
+        auto pSourcePolyPolygon = 
o3tl::tryAccess<drawing::PointSequenceSequence>(aAny);
 
-            // write point array
-            mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString);
+        if(pSourcePolyPolygon)
+        {
+            aPolyPolygon = 
basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(*pSourcePolyPolygon);
         }
     }
-    else
-    {
-        // get non-bezier polygon
-        uno::Any aAny( xPropSet->getPropertyValue("Geometry") );
-        const basegfx::B2DPolyPolygon aPolyPolygon(
-            
basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(*o3tl::doAccess<drawing::PointSequenceSequence>(aAny)));
 
-        if(!aPolyPolygon.areControlPointsUsed() && 1 == aPolyPolygon.count())
+    if(aPolyPolygon.count())
+    {
+        if(!bBezier && !aPolyPolygon.areControlPointsUsed() && 1 == 
aPolyPolygon.count())
         {
             // simple polygon shape, can be written as svg:points sequence
             const basegfx::B2DPolygon& aPolygon(aPolyPolygon.getB2DPolygon(0));

Reply via email to