[Libreoffice-commits] core.git: chart2/qa include/oox oox/source

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 1 08:32:31 UTC 2021


 chart2/qa/extras/chart2export2.cxx        |   61 ++++++++++++++++++++++++
 chart2/qa/extras/data/docx/tdf143130.docx |binary
 chart2/qa/extras/data/xlsx/tdf143127.xlsx |binary
 include/oox/export/shapes.hxx             |    4 +
 oox/source/export/chartexport.cxx         |    5 +-
 oox/source/export/shapes.cxx              |   75 +++++++++++++++---------------
 6 files changed, 105 insertions(+), 40 deletions(-)

New commits:
commit 9fbe0a171ece07da0d5c1e16eae23a167cb81114
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Wed Aug 25 14:40:24 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Wed Sep 1 10:31:54 2021 +0200

    tdf#143127 tdf#143130 ooxml export: fix lost image/shape in chart
    
    tdf#143127: Add officeRel namespace to XML_userShapes
    to fix invalid file error in MSO.
    
    tdf#143130: Add mbUserShapes variable to ShapeExport class
    to fix export of embedded shapes of charts in DOCX.
    
    Change-Id: I10c1dbf905af96d6a63a9243514b32a6440e63f1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121035
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2export2.cxx b/chart2/qa/extras/chart2export2.cxx
index 3a1afef91bd6..d7862946fd4d 100644
--- a/chart2/qa/extras/chart2export2.cxx
+++ b/chart2/qa/extras/chart2export2.cxx
@@ -21,6 +21,7 @@
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/chart2/DataPointLabel.hpp>
 #include <com/sun/star/chart/DataLabelPlacement.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
 
 #include <libxml/xpathInternals.h>
 
@@ -97,6 +98,8 @@ public:
     void testTdf138181();
     void testCustomShapeText();
     void testuserShapesXLSX();
+    void testuserShapesDOCX();
+    void testGraphicBlipXLSX();
     void testNameRangeXLSX();
     void testTdf143942();
 
@@ -159,6 +162,8 @@ public:
     CPPUNIT_TEST(testTdf138181);
     CPPUNIT_TEST(testCustomShapeText);
     CPPUNIT_TEST(testuserShapesXLSX);
+    CPPUNIT_TEST(testuserShapesDOCX);
+    CPPUNIT_TEST(testGraphicBlipXLSX);
     CPPUNIT_TEST(testNameRangeXLSX);
     CPPUNIT_TEST(testTdf143942);
     CPPUNIT_TEST_SUITE_END();
@@ -1462,6 +1467,62 @@ void Chart2ExportTest2::testuserShapesXLSX()
     CPPUNIT_ASSERT(!xRange->getString().isEmpty());
 }
 
+void Chart2ExportTest2::testuserShapesDOCX()
+{
+    load(u"/chart2/qa/extras/data/docx/", "tdf143130.docx");
+    reload("Office Open XML Text");
+
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    // test that the custom shape exists
+    Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
+    Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
+    Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xCustomShape.is());
+    // test type of shape
+    CPPUNIT_ASSERT(xCustomShape->getShapeType().endsWith("CustomShape"));
+    // test custom shape position
+    awt::Point aPosition = xCustomShape->getPosition();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(9824, aPosition.X, 300);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(547, aPosition.Y, 300);
+    // test custom shape size
+    awt::Size aSize = xCustomShape->getSize();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1848, aSize.Width, 300);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1003, aSize.Height, 300);
+    // test custom shape text
+    Reference<text::XText> xRange(xCustomShape, uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(!xRange->getString().isEmpty());
+}
+
+void Chart2ExportTest2::testGraphicBlipXLSX()
+{
+    load(u"/chart2/qa/extras/data/xlsx/", "tdf143127.xlsx");
+    reload("Calc Office Open XML");
+
+    Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    // test that the Graphic shape exists
+    Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
+    Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
+    Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xCustomShape.is());
+    // test type of shape
+    CPPUNIT_ASSERT(xCustomShape->getShapeType().endsWith("GraphicObjectShape"));
+    Reference<XPropertySet> xShapeProps(xCustomShape, UNO_QUERY);
+
+    uno::Reference<graphic::XGraphic> xGraphic;
+    CPPUNIT_ASSERT(xShapeProps->getPropertyValue("Graphic") >>= xGraphic);
+
+    Graphic aGraphic(xGraphic);
+    GfxLink aLink = aGraphic.GetGfxLink();
+    std::size_t nDataSize = aLink.GetDataSize();
+
+    // test the image size is bigger then 0.
+    CPPUNIT_ASSERT_GREATER(size_t(0), nDataSize);
+}
+
 void Chart2ExportTest2::testNameRangeXLSX()
 {
     load(u"/chart2/qa/extras/data/xlsx/", "chart_with_name_range.xlsx");
diff --git a/chart2/qa/extras/data/docx/tdf143130.docx b/chart2/qa/extras/data/docx/tdf143130.docx
new file mode 100644
index 000000000000..a364f4811a9f
Binary files /dev/null and b/chart2/qa/extras/data/docx/tdf143130.docx differ
diff --git a/chart2/qa/extras/data/xlsx/tdf143127.xlsx b/chart2/qa/extras/data/xlsx/tdf143127.xlsx
new file mode 100644
index 000000000000..116a00b60c35
Binary files /dev/null and b/chart2/qa/extras/data/xlsx/tdf143127.xlsx differ
diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index 3e9bf364d400..0f4e264fb1b6 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -87,6 +87,7 @@ public:
 
 protected:
     sal_Int32           mnShapeIdMax;
+    bool                mbUserShapes; // for chart's embedded usershapes
 
     void WriteGraphicObjectShapePart( const css::uno::Reference< css::drawing::XShape >& xShape, const Graphic *pGraphic=nullptr );
 
@@ -107,7 +108,8 @@ public:
     ShapeExport( sal_Int32 nXmlNamespace, ::sax_fastparser::FSHelperPtr pFS,
                  ShapeHashMap* pShapeMap, ::oox::core::XmlFilterBase* pFB,
                  DocumentType eDocumentType = DOCUMENT_PPTX,
-                 DMLTextExport* pTextExport = nullptr );
+                 DMLTextExport* pTextExport = nullptr,
+                 bool bUserShapes = false );
     virtual ~ShapeExport() {}
 
     void SetURLTranslator(const std::shared_ptr<URLTransformer>& pTransformer);
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 2e13b40288bb..c39f2f146681 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -1088,7 +1088,8 @@ void ChartExport::exportAdditionalShapes( const Reference< css::chart::XChartDoc
             pDrawing->startElement(FSNS(XML_c, XML_userShapes),
                 FSNS(XML_xmlns, XML_cdr), pFB->getNamespaceURL(OOX_NS(dmlChartDr)),
                 FSNS(XML_xmlns, XML_a), pFB->getNamespaceURL(OOX_NS(dml)),
-                FSNS(XML_xmlns, XML_c), pFB->getNamespaceURL(OOX_NS(dmlChart)));
+                FSNS(XML_xmlns, XML_c), pFB->getNamespaceURL(OOX_NS(dmlChart)),
+                FSNS(XML_xmlns, XML_r), pFB->getNamespaceURL(OOX_NS(officeRel)));
 
             const sal_Int32 nShapeCount(mxAdditionalShapes->getCount());
             for (sal_Int32 nShapeId = 0; nShapeId < nShapeCount; nShapeId++)
@@ -1108,7 +1109,7 @@ void ChartExport::exportAdditionalShapes( const Reference< css::chart::XChartDoc
                     awt::Size aPageSize = xVisObject->getVisualAreaSize(embed::Aspects::MSOLE_CONTENT);
                     WriteFromTo( xShape, aPageSize, pDrawing );
 
-                    ShapeExport aExport(XML_cdr, pDrawing, nullptr, GetFB(), GetDocumentType());
+                    ShapeExport aExport(XML_cdr, pDrawing, nullptr, GetFB(), GetDocumentType(), nullptr, true);
                     aExport.WriteShape(xShape);
                 }
                 pDrawing->endElement(FSNS(XML_cdr, XML_relSizeAnchor));
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 3d03af800a13..c7c47aa00059 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -321,10 +321,11 @@ namespace oox::drawingml {
     if ( GETA(propName) ) \
         mAny >>= variable;
 
-ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ShapeHashMap* pShapeMap, XmlFilterBase* pFB, DocumentType eDocumentType, DMLTextExport* pTextExport )
+ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ShapeHashMap* pShapeMap, XmlFilterBase* pFB, DocumentType eDocumentType, DMLTextExport* pTextExport, bool bUserShapes )
     : DrawingML( std::move(pFS), pFB, eDocumentType, pTextExport )
     , m_nEmbeddedObjects(0)
     , mnShapeIdMax( 1 )
+    , mbUserShapes( bUserShapes )
     , mnXmlNamespace( nXmlNamespace )
     , maMapModeSrc( MapUnit::Map100thMM )
     , maMapModeDest( MapUnit::MapInch, Point(), Fraction( 1, 576 ), Fraction( 1, 576 ) )
@@ -398,11 +399,11 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
     SAL_INFO("oox.shape", "write polypolygon shape");
 
     FSHelperPtr pFS = GetFS();
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     awt::Point aPos = xShape->getPosition();
     // Position is relative to group for child elements in Word, but absolute in API.
-    if (GetDocumentType() == DOCUMENT_DOCX && m_xParent.is())
+    if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes && m_xParent.is())
     {
         awt::Point aParentPos = m_xParent->getPosition();
         aPos.X -= aParentPos.X;
@@ -419,7 +420,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
 #endif
 
     // non visual shape properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         pFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
         pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
@@ -427,7 +428,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
                               XML_name, GetShapeName(xShape));
     }
     pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr);
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         WriteNonVisualProperties( xShape );
         pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
@@ -449,7 +450,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
     // write text
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }
@@ -469,7 +470,7 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>&
     FSHelperPtr pFS = GetFS();
 
     sal_Int32 nGroupShapeToken = XML_grpSp;
-    if (GetDocumentType() == DOCUMENT_DOCX)
+    if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes)
     {
         if (!m_xParent.is())
             nGroupShapeToken = XML_wgp; // toplevel
@@ -480,7 +481,7 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>&
     pFS->startElementNS(mnXmlNamespace, nGroupShapeToken);
 
     // non visual properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         pFS->startElementNS(mnXmlNamespace, XML_nvGrpSpPr);
         pFS->singleElementNS(mnXmlNamespace, XML_cNvPr,
@@ -507,7 +508,7 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>&
         sal_Int32 nSavedNamespace = mnXmlNamespace;
 
         uno::Reference<lang::XServiceInfo> xServiceInfo(xChild, uno::UNO_QUERY_THROW);
-        if (GetDocumentType() == DOCUMENT_DOCX)
+        if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes)
         {
             // tdf#128820: WriteGraphicObjectShapePart calls WriteTextShape for non-empty simple
             // text objects, which needs writing into wps::wsp element, so make sure to use wps
@@ -775,10 +776,10 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape )
     }
 
     FSHelperPtr pFS = GetFS();
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     // non visual shape properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         bool isVisible = true ;
         if( GETA (Visible))
@@ -844,7 +845,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape )
     // Let the custom shapes what has name and preset information in OOXML, to be written
     // as preset ones with parameters. Try that with this converter class.
     if (!sShapeType.startsWith("ooxml") && sShapeType != "non-primitive"
-        && GetDocumentType() == DOCUMENT_DOCX
+        && GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes
         && xShape->getShapeType() == "com.sun.star.drawing.CustomShape")
     {
         DMLPresetShapeExporter aCustomShapeConverter(this, xShape);
@@ -1038,7 +1039,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape )
     // write text
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }
@@ -1049,12 +1050,12 @@ ShapeExport& ShapeExport::WriteEllipseShape( const Reference< XShape >& xShape )
 
     FSHelperPtr pFS = GetFS();
 
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     // TODO: connector ?
 
     // non visual shape properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         pFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
         pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
@@ -1133,7 +1134,7 @@ ShapeExport& ShapeExport::WriteEllipseShape( const Reference< XShape >& xShape )
     // write text
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }
@@ -1185,7 +1186,7 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
     FSHelperPtr pFS = GetFS();
     XmlFilterBase* pFB = GetFB();
 
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
         pFS->startElementNS(mnXmlNamespace, XML_pic);
     else
         pFS->startElementNS(mnXmlNamespace, XML_pic,
@@ -1236,7 +1237,7 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
 
     if (xGraphic.is())
     {
-        WriteXGraphicBlip(xShapeProps, xGraphic, false);
+        WriteXGraphicBlip(xShapeProps, xGraphic, mbUserShapes);
     }
     else if (bHasMediaURL)
     {
@@ -1244,7 +1245,7 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
         if (xShapeProps->getPropertySetInfo()->hasPropertyByName("FallbackGraphic"))
             xShapeProps->getPropertyValue("FallbackGraphic") >>= xFallbackGraphic;
 
-        WriteXGraphicBlip(xShapeProps, xFallbackGraphic, false);
+        WriteXGraphicBlip(xShapeProps, xFallbackGraphic, mbUserShapes);
     }
 
     if (xGraphic.is())
@@ -1335,7 +1336,7 @@ ShapeExport& ShapeExport::WriteConnectorShape( const Reference< XShape >& xShape
         GET( rXShapeB, EdgeEndConnection );
     }
     // Position is relative to group in Word, but relative to anchor of group in API.
-    if (GetDocumentType() == DOCUMENT_DOCX && m_xParent.is())
+    if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes && m_xParent.is())
     {
         awt::Point aParentPos = m_xParent->getPosition();
         aStartPoint.X -= aParentPos.X;
@@ -1408,7 +1409,7 @@ ShapeExport& ShapeExport::WriteLineShape( const Reference< XShape >& xShape )
 
     FSHelperPtr pFS = GetFS();
 
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     tools::PolyPolygon aPolyPolygon = EscherPropertyContainer::GetPolyPolygon( xShape );
     if( aPolyPolygon.Count() == 1 && aPolyPolygon[ 0 ].GetSize() == 2)
@@ -1420,7 +1421,7 @@ ShapeExport& ShapeExport::WriteLineShape( const Reference< XShape >& xShape )
     }
 
     // non visual shape properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         pFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
         pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
@@ -1428,7 +1429,7 @@ ShapeExport& ShapeExport::WriteLineShape( const Reference< XShape >& xShape )
                               XML_name, GetShapeName(xShape));
     }
     pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr );
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         WriteNonVisualProperties( xShape );
         pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
@@ -1451,7 +1452,7 @@ ShapeExport& ShapeExport::WriteLineShape( const Reference< XShape >& xShape )
     // write text
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }
@@ -1477,7 +1478,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape
 
     FSHelperPtr pFS = GetFS();
 
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     sal_Int32 nRadius = 0;
 
@@ -1495,7 +1496,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape
     // "rect" or "roundRect" preset shape below
 
     // non visual shape properties
-    if (GetDocumentType() == DOCUMENT_DOCX)
+    if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes)
         pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr);
     pFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
     pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
@@ -1520,7 +1521,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape
     // write text
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }
@@ -1584,7 +1585,7 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
 ShapeExport& ShapeExport::WriteTextBox( const Reference< XInterface >& xIface, sal_Int32 nXmlNamespace, bool bWritePropertiesAsLstStyles )
 {
     // In case this shape has an associated textbox, then export that, and we're done.
-    if (GetDocumentType() == DOCUMENT_DOCX && GetTextExport())
+    if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes && GetTextExport())
     {
         uno::Reference<beans::XPropertySet> xPropertySet(xIface, uno::UNO_QUERY);
         if (xPropertySet.is())
@@ -1605,14 +1606,14 @@ ShapeExport& ShapeExport::WriteTextBox( const Reference< XInterface >& xIface, s
         FSHelperPtr pFS = GetFS();
 
         pFS->startElementNS(nXmlNamespace,
-                            (GetDocumentType() != DOCUMENT_DOCX ? XML_txBody : XML_txbx));
-        WriteText(xIface, /*bBodyPr=*/(GetDocumentType() != DOCUMENT_DOCX), /*bText=*/true,
+                            (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_txBody : XML_txbx));
+        WriteText(xIface, /*bBodyPr=*/(GetDocumentType() != DOCUMENT_DOCX || mbUserShapes), /*bText=*/true,
                   /*nXmlNamespace=*/0, /*bWritePropertiesAsLstStyles=*/bWritePropertiesAsLstStyles);
-        pFS->endElementNS( nXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_txBody : XML_txbx) );
-        if (GetDocumentType() == DOCUMENT_DOCX)
+        pFS->endElementNS( nXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_txBody : XML_txbx) );
+        if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes)
             WriteText( xIface, /*bBodyPr=*/true, /*bText=*/false, /*nXmlNamespace=*/nXmlNamespace );
     }
-    else if (GetDocumentType() == DOCUMENT_DOCX)
+    else if (GetDocumentType() == DOCUMENT_DOCX && !mbUserShapes)
         mpFS->singleElementNS(nXmlNamespace, XML_bodyPr);
 
     return *this;
@@ -1908,10 +1909,10 @@ ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape )
     FSHelperPtr pFS = GetFS();
     Reference<XPropertySet> xShapeProps(xShape, UNO_QUERY);
 
-    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
+    pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp));
 
     // non visual shape properties
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         pFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
         pFS->startElementNS(mnXmlNamespace, XML_cNvPr,
@@ -1933,7 +1934,7 @@ ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape )
         pFS->endElementNS(mnXmlNamespace, XML_cNvPr);
     }
     pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1");
-    if (GetDocumentType() != DOCUMENT_DOCX)
+    if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes)
     {
         WriteNonVisualProperties( xShape );
         pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
@@ -1954,7 +1955,7 @@ ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape )
 
     WriteTextBox( xShape, mnXmlNamespace );
 
-    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp) );
+    pFS->endElementNS( mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes ? XML_sp : XML_wsp) );
 
     return *this;
 }


More information about the Libreoffice-commits mailing list