summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2021-08-25 14:40:24 +0200
committerLászló Németh <nemeth@numbertext.org>2021-09-01 10:31:54 +0200
commit9fbe0a171ece07da0d5c1e16eae23a167cb81114 (patch)
tree4ee35708516fbc1cb8489182a2139e78f338b023 /oox
parent504d78acb866495fd954fcd6db22ea68f174a5ab (diff)
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@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/chartexport.cxx5
-rw-r--r--oox/source/export/shapes.cxx75
2 files changed, 41 insertions, 39 deletions
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;
}