tdf#126746 Fix exporting closed Polylines to PPTX

In previous implementation the closed shapes was
imported as a polylines without closing joint.
As a result the joint style was not applied.

This patch fixes that, and allow proper PPTX export.

TODO The same issue needs to be fixed for PPT export

Change-Id: I557daac1ba02330d8923f7eda3476e67d8711384
Reviewed-on: https://gerrit.libreoffice.org/77179
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 55279e2..c11664b 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -265,7 +265,7 @@ public:
    static sal_Int32 GetCustomGeometryPointValue(
        const css::drawing::EnhancedCustomShapeParameter& rParam,
        const SdrObjCustomShape& rSdrObjCustomShape);
    void WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon );
    void WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon, const bool bClosed );
    void WriteFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
    void WriteShapeStyle( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
    void WriteShapeEffects( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index e810188..58e7db5 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3199,7 +3199,7 @@ sal_Int32 DrawingML::GetCustomGeometryPointValue(
    return nValue;
}

void DrawingML::WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon )
void DrawingML::WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon, const bool bClosed )
{
    // In case of Writer, the parent element is <wps:spPr>, and there the
    // <a:custGeom> element is not optional.
@@ -3269,6 +3269,8 @@ void DrawingML::WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon )
            }
        }
    }
    if (bClosed)
        mpFS->singleElementNS( XML_a, XML_close);
    mpFS->endElementNS( XML_a, XML_path );

    mpFS->endElementNS( XML_a, XML_pathLst );
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 2c0fb16..ebdac12 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -420,7 +420,7 @@ bool ShapeExport::NonEmptyText( const Reference< XInterface >& xIface )
    return false;
}

ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xShape, bool bClosed )
ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xShape, const bool bClosed )
{
    SAL_INFO("oox.shape", "write polypolygon shape");

@@ -454,7 +454,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
    // visual shape properties
    pFS->startElementNS(mnXmlNamespace, XML_spPr);
    WriteTransformation( aRect, XML_a );
    WritePolyPolygon( aPolyPolygon );
    WritePolyPolygon( aPolyPolygon, bClosed );
    Reference< XPropertySet > xProps( xShape, UNO_QUERY );
    if( xProps.is() ) {
        if( bClosed )
@@ -882,7 +882,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape )
        bool bInvertRotation = bFlipH != bFlipV;
        if (nRotation != 0)
            aPolyPolygon.Rotate(Point(0,0), static_cast<sal_uInt16>(bInvertRotation ? nRotation/10 : 3600-nRotation/10));
        WritePolyPolygon( aPolyPolygon );
        WritePolyPolygon( aPolyPolygon, false );
    }
    else if (bCustGeom)
    {
@@ -1477,7 +1477,7 @@ static const NameToConvertMapType& lcl_GetConverters()
        { "com.sun.star.drawing.LineShape"                 , &ShapeExport::WriteLineShape },
        { "com.sun.star.drawing.OpenBezierShape"           , &ShapeExport::WriteOpenPolyPolygonShape },
        { "com.sun.star.drawing.PolyPolygonShape"          , &ShapeExport::WriteClosedPolyPolygonShape },
        { "com.sun.star.drawing.PolyLineShape"             , &ShapeExport::WriteClosedPolyPolygonShape },
        { "com.sun.star.drawing.PolyLineShape"             , &ShapeExport::WriteOpenPolyPolygonShape },
        { "com.sun.star.drawing.RectangleShape"            , &ShapeExport::WriteRectangleShape },
        { "com.sun.star.drawing.OLE2Shape"                 , &ShapeExport::WriteOLE2Shape },
        { "com.sun.star.drawing.TableShape"                , &ShapeExport::WriteTableShape },
diff --git a/sd/qa/unit/data/odp/closed-shapes.odp b/sd/qa/unit/data/odp/closed-shapes.odp
new file mode 100644
index 0000000..23460c7
--- /dev/null
+++ b/sd/qa/unit/data/odp/closed-shapes.odp
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index ac274d6..031156c 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -152,6 +152,7 @@ public:
    void testTdf111863();
    void testTdf111518();
    void testTdf100387();
    void testClosingShapes();
    void testRotateFlip();
    void testTdf106867();
    void testTdf112280();
@@ -245,6 +246,7 @@ public:
    CPPUNIT_TEST(testTdf111863);
    CPPUNIT_TEST(testTdf111518);
    CPPUNIT_TEST(testTdf100387);
    CPPUNIT_TEST(testClosingShapes);
    CPPUNIT_TEST(testRotateFlip);
    CPPUNIT_TEST(testTdf106867);
    CPPUNIT_TEST(testTdf112280);
@@ -1133,6 +1135,17 @@ void SdOOXMLExportTest2::testTdf100387()
                             "/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl/p:spTgt/p:txEl/p:pRg", "end", "2");
}

void SdOOXMLExportTest2::testClosingShapes()
{
    sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odp/closed-shapes.odp"), ODP);
    utl::TempFile tempFile;
    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
    xDocShRef->DoClose();
    xmlDocPtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml");
    assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/a:close", 1);
    assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/a:close", 0);
}

void SdOOXMLExportTest2::testRotateFlip()
{
    sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odp/rotate_flip.odp"), ODP);
@@ -1175,6 +1188,7 @@ void SdOOXMLExportTest2::testRotateFlip()
            assertXPath(pXmlDocContent, sPt, "x", points[nPointIndex][0]);
            assertXPath(pXmlDocContent, sPt, "y", points[nPointIndex][1]);
        }
        assertXPath(pXmlDocContent, sSpPr + "/a:custGeom/a:pathLst/a:path/a:close", 1);
    }
}