[Libreoffice-commits] core.git: include/oox oox/source sd/qa
Jan Holesovsky
kendy at collabora.com
Fri Sep 1 12:30:39 UTC 2017
include/oox/export/drawingml.hxx | 4 +-
oox/source/export/drawingml.cxx | 18 +++++++++---
oox/source/export/shapes.cxx | 55 +++++++++++++++++++++++++------------
sd/qa/unit/export-tests-ooxml1.cxx | 26 ++++++++++++-----
4 files changed, 72 insertions(+), 31 deletions(-)
New commits:
commit e06ef6f42e47780b26f6f3424bb2053e0490d8e3
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Aug 31 18:32:58 2017 +0200
tdf#111884: Implement export of group shapes in pptx.
Change-Id: If12984c0670db6396cbfd0dcb8ae1f5a9b591705
Reviewed-on: https://gerrit.libreoffice.org/41766
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index ecdad5b99b6a..866689fa5e21 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -191,8 +191,8 @@ public:
void WriteShapeTransformation(const css::uno::Reference< css::drawing::XShape >& rXShape,
sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, bool bSuppressRotation = false, bool bSuppressFlipping = false );
- void WriteTransformation( const tools::Rectangle& rRectangle,
- sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0 );
+ void WriteTransformation(const tools::Rectangle& rRectangle,
+ sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0, bool bIsGroupShape = false);
void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, const OUString& presetWarp, bool bBodyPr = true, bool bText = true, sal_Int32 nXmlNamespace = 0);
void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph,
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 3d5a7ace8262..3e66a504aa14 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1154,8 +1154,8 @@ void DrawingML::WriteStretch( const css::uno::Reference< css::beans::XPropertySe
mpFS->endElementNS( XML_a, XML_stretch );
}
-void DrawingML::WriteTransformation( const tools::Rectangle& rRect,
- sal_Int32 nXmlNamespace, bool bFlipH, bool bFlipV, sal_Int32 nRotation )
+void DrawingML::WriteTransformation(const tools::Rectangle& rRect,
+ sal_Int32 nXmlNamespace, bool bFlipH, bool bFlipV, sal_Int32 nRotation, bool bIsGroupShape)
{
mpFS->startElementNS( nXmlNamespace, XML_xfrm,
@@ -1175,6 +1175,12 @@ void DrawingML::WriteTransformation( const tools::Rectangle& rRect,
mpFS->singleElementNS( XML_a, XML_off, XML_x, IS( oox::drawingml::convertHmmToEmu( nLeft ) ), XML_y, IS( oox::drawingml::convertHmmToEmu( nTop ) ), FSEND );
mpFS->singleElementNS( XML_a, XML_ext, XML_cx, IS( oox::drawingml::convertHmmToEmu( rRect.GetWidth() ) ), XML_cy, IS( oox::drawingml::convertHmmToEmu( rRect.GetHeight() ) ), FSEND );
+ if (GetDocumentType() != DOCUMENT_DOCX && bIsGroupShape)
+ {
+ mpFS->singleElementNS(XML_a, XML_chOff, XML_x, IS(oox::drawingml::convertHmmToEmu(nLeft)), XML_y, IS(oox::drawingml::convertHmmToEmu(nTop)), FSEND);
+ mpFS->singleElementNS(XML_a, XML_chExt, XML_cx, IS(oox::drawingml::convertHmmToEmu(rRect.GetWidth())), XML_cy, IS(oox::drawingml::convertHmmToEmu(rRect.GetHeight())), FSEND);
+ }
+
mpFS->endElementNS( nXmlNamespace, XML_xfrm );
}
@@ -1186,7 +1192,7 @@ void DrawingML::WriteShapeTransformation( const Reference< XShape >& rXShape, sa
awt::Point aPos = rXShape->getPosition();
awt::Size aSize = rXShape->getSize();
- if (m_xParent.is())
+ if (GetDocumentType() == DOCUMENT_DOCX && m_xParent.is())
{
awt::Point aParentPos = m_xParent->getPosition();
aPos.X -= aParentPos.X;
@@ -1223,7 +1229,11 @@ void DrawingML::WriteShapeTransformation( const Reference< XShape >& rXShape, sa
if(bSuppressFlipping)
bFlipH = bFlipV = false;
- WriteTransformation( tools::Rectangle( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) ), nXmlNamespace, bFlipH, bFlipV, OOX_DRAWINGML_EXPORT_ROTATE_CLOCKWISIFY(nRotation) );
+ uno::Reference<lang::XServiceInfo> xServiceInfo(rXShape, uno::UNO_QUERY_THROW);
+ bool bIsGroupShape = (xServiceInfo.is() && xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"));
+
+ WriteTransformation(tools::Rectangle(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height)), nXmlNamespace,
+ bFlipH, bFlipV, OOX_DRAWINGML_EXPORT_ROTATE_CLOCKWISIFY(nRotation), bIsGroupShape);
}
void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect,
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index df34231a225b..60bd7d0a80cf 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -497,13 +497,32 @@ ShapeExport& ShapeExport::WriteOpenPolyPolygonShape( const Reference< XShape >&
ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>& xShape)
{
FSHelperPtr pFS = GetFS();
- bool bToplevel = !m_xParent.is();
- if (!bToplevel)
- mnXmlNamespace = XML_wpg;
- pFS->startElementNS(mnXmlNamespace, (bToplevel ? XML_wgp : XML_grpSp), FSEND);
+
+ sal_Int32 nGroupShapeToken = XML_grpSp;
+ if (GetDocumentType() == DOCUMENT_DOCX)
+ {
+ if (!m_xParent.is())
+ nGroupShapeToken = XML_wgp; // toplevel
+ else
+ mnXmlNamespace = XML_wpg;
+ }
+
+ pFS->startElementNS(mnXmlNamespace, nGroupShapeToken, FSEND);
// non visual properties
- pFS->singleElementNS(mnXmlNamespace, XML_cNvGrpSpPr, FSEND);
+ if (GetDocumentType() != DOCUMENT_DOCX)
+ {
+ pFS->startElementNS(mnXmlNamespace, XML_nvGrpSpPr, FSEND);
+ pFS->singleElementNS(mnXmlNamespace, XML_cNvPr,
+ XML_id, I32S(GetNewShapeID(xShape)),
+ XML_name, IDS(Group),
+ FSEND);
+ pFS->singleElementNS(mnXmlNamespace, XML_cNvGrpSpPr, FSEND);
+ WriteNonVisualProperties(xShape );
+ pFS->endElementNS(mnXmlNamespace, XML_nvGrpSpPr);
+ }
+ else
+ pFS->singleElementNS(mnXmlNamespace, XML_cNvGrpSpPr, FSEND);
// visual properties
pFS->startElementNS(mnXmlNamespace, XML_grpSpPr, FSEND);
@@ -519,17 +538,20 @@ ShapeExport& ShapeExport::WriteGroupShape(const uno::Reference<drawing::XShape>&
sal_Int32 nSavedNamespace = mnXmlNamespace;
uno::Reference<lang::XServiceInfo> xServiceInfo(xChild, uno::UNO_QUERY_THROW);
- if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
- mnXmlNamespace = XML_pic;
- else
- mnXmlNamespace = XML_wps;
+ if (GetDocumentType() == DOCUMENT_DOCX)
+ {
+ if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
+ mnXmlNamespace = XML_pic;
+ else
+ mnXmlNamespace = XML_wps;
+ }
WriteShape(xChild);
mnXmlNamespace = nSavedNamespace;
}
m_xParent = xParent;
- pFS->endElementNS(mnXmlNamespace, (bToplevel ? XML_wgp : XML_grpSp));
+ pFS->endElementNS(mnXmlNamespace, nGroupShapeToken);
return *this;
}
@@ -1371,7 +1393,7 @@ ShapeExport& ShapeExport::WriteRectangleShape( const Reference< XShape >& xShape
typedef ShapeExport& (ShapeExport::*ShapeConverter)( const Reference< XShape >& );
typedef std::unordered_map< const char*, ShapeConverter, rtl::CStringHash, rtl::CStringEqual> NameToConvertMapType;
-static const NameToConvertMapType& lcl_GetConverters(DocumentType eDocumentType)
+static const NameToConvertMapType& lcl_GetConverters()
{
static bool shape_map_inited = false;
static NameToConvertMapType shape_converters;
@@ -1387,12 +1409,13 @@ static const NameToConvertMapType& lcl_GetConverters(DocumentType eDocumentType)
shape_converters[ "com.sun.star.drawing.GraphicObjectShape" ] = &ShapeExport::WriteGraphicObjectShape;
shape_converters[ "com.sun.star.drawing.LineShape" ] = &ShapeExport::WriteLineShape;
shape_converters[ "com.sun.star.drawing.OpenBezierShape" ] = &ShapeExport::WriteOpenPolyPolygonShape;
- shape_converters[ "com.sun.star.drawing.PolyPolygonShape" ] = &ShapeExport::WriteClosedPolyPolygonShape;
- shape_converters[ "com.sun.star.drawing.PolyLineShape" ] = &ShapeExport::WriteClosedPolyPolygonShape;
+ shape_converters[ "com.sun.star.drawing.PolyPolygonShape" ] = &ShapeExport::WriteClosedPolyPolygonShape;
+ shape_converters[ "com.sun.star.drawing.PolyLineShape" ] = &ShapeExport::WriteClosedPolyPolygonShape;
shape_converters[ "com.sun.star.drawing.RectangleShape" ] = &ShapeExport::WriteRectangleShape;
shape_converters[ "com.sun.star.drawing.OLE2Shape" ] = &ShapeExport::WriteOLE2Shape;
shape_converters[ "com.sun.star.drawing.TableShape" ] = &ShapeExport::WriteTableShape;
shape_converters[ "com.sun.star.drawing.TextShape" ] = &ShapeExport::WriteTextShape;
+ shape_converters[ "com.sun.star.drawing.GroupShape" ] = &ShapeExport::WriteGroupShape;
shape_converters[ "com.sun.star.presentation.GraphicObjectShape" ] = &ShapeExport::WriteGraphicObjectShape;
shape_converters[ "com.sun.star.presentation.OLE2Shape" ] = &ShapeExport::WriteOLE2Shape;
@@ -1406,8 +1429,6 @@ static const NameToConvertMapType& lcl_GetConverters(DocumentType eDocumentType)
shape_converters[ "com.sun.star.presentation.OutlinerShape" ] = &ShapeExport::WriteTextShape;
shape_converters[ "com.sun.star.presentation.SlideNumberShape" ] = &ShapeExport::WriteTextShape;
shape_converters[ "com.sun.star.presentation.TitleTextShape" ] = &ShapeExport::WriteTextShape;
- if (eDocumentType == DOCUMENT_DOCX)
- shape_converters[ "com.sun.star.drawing.GroupShape" ] = &ShapeExport::WriteGroupShape;
shape_map_inited = true;
return shape_converters;
@@ -1417,8 +1438,8 @@ ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape )
{
OUString sShapeType = xShape->getShapeType();
SAL_INFO("oox.shape", "write shape: " << sShapeType);
- NameToConvertMapType::const_iterator aConverter = lcl_GetConverters(GetDocumentType()).find( USS( sShapeType ) );
- if( aConverter == lcl_GetConverters(GetDocumentType()).end() )
+ NameToConvertMapType::const_iterator aConverter = lcl_GetConverters().find(USS(sShapeType));
+ if (aConverter == lcl_GetConverters().end())
{
SAL_INFO("oox.shape", "unknown shape");
return WriteUnknownShape( xShape );
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx
index a847352d2bb6..ef3186660f92 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -216,20 +216,26 @@ void SdOOXMLExportTest1::testBnc870233_2()
// First smart art has blue font color (direct formatting)
{
- const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
- checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x0000ff) );
+ const SdrObjGroup *pObjGroup = dynamic_cast<SdrObjGroup *>(pPage->GetObj(0));
+ CPPUNIT_ASSERT(pObjGroup);
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>(pObjGroup->GetSubList()->GetObj(0));
+ checkFontAttributes<Color, SvxColorItem>(pObj, Color(0x0000ff));
}
// Second smart art has "dk2" font color (style)
{
- const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
+ const SdrObjGroup *pObjGroup = dynamic_cast<SdrObjGroup *>(pPage->GetObj(2)); // FIXME should be 1, smartart import creates an additional empty group for some reason
+ CPPUNIT_ASSERT(pObjGroup);
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>(pObjGroup->GetSubList()->GetObj(0));
checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x1F497D) );
}
// Third smart art has white font color (style)
{
- const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 2 ) );
- checkFontAttributes<Color, SvxColorItem>( pObj, Color(0xffffff) );
+ const SdrObjGroup *pObjGroup = dynamic_cast<SdrObjGroup *>(pPage->GetObj(4)); // FIXME should be 2, smartart import creates an additional empty group for some reason
+ CPPUNIT_ASSERT(pObjGroup);
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>(pObjGroup->GetSubList()->GetObj(0));
+ checkFontAttributes<Color, SvxColorItem>(pObj, Color(0xffffff));
}
xDocShRef->DoClose();
@@ -361,12 +367,14 @@ void SdOOXMLExportTest1::testBnc880763()
// Check z-order of the two shapes, use background color to identify them
// First object in the background has blue background color
- const SdrObject *pObj = dynamic_cast<SdrObject *>( pPage->GetObj( 0 ) );
+ const SdrObjGroup *pObjGroup = dynamic_cast<SdrObjGroup *>(pPage->GetObj(0));
+ CPPUNIT_ASSERT(pObjGroup);
+ const SdrObject *pObj = dynamic_cast<SdrObject *>(pObjGroup->GetSubList()->GetObj(0));
CPPUNIT_ASSERT_MESSAGE( "no object", pObj != nullptr);
CPPUNIT_ASSERT_EQUAL( sal_uInt32(0x0000ff),(static_cast< const XColorItem& >(pObj->GetMergedItem(XATTR_FILLCOLOR))).GetColorValue().GetColor());
// Second object at the front has green background color
- pObj = dynamic_cast<SdrObject *>( pPage->GetObj( 1 ) );
+ pObj = dynamic_cast<SdrObject *>(pPage->GetObj(2)); // FIXME should be 1, smartart import creates an additional empty group for some reason
CPPUNIT_ASSERT_MESSAGE( "no object", pObj != nullptr);
CPPUNIT_ASSERT_EQUAL( sal_uInt32(0x00ff00),(static_cast< const XColorItem& >(pObj->GetMergedItem(XATTR_FILLCOLOR))).GetColorValue().GetColor());
@@ -381,7 +389,9 @@ void SdOOXMLExportTest1::testBnc862510_5()
const SdrPage *pPage = GetPage( 1, xDocShRef );
// Same as testBnc870237, but here we check the horizontal spacing
- const SdrObject* pObj = dynamic_cast<SdrObject*>( pPage->GetObj( 1 ) );
+ const SdrObjGroup *pObjGroup = dynamic_cast<SdrObjGroup *>(pPage->GetObj(0));
+ CPPUNIT_ASSERT(pObjGroup);
+ const SdrObject* pObj = dynamic_cast<SdrObject*>(pObjGroup->GetSubList()->GetObj(1));
CPPUNIT_ASSERT_MESSAGE( "no object", pObj != nullptr);
CPPUNIT_ASSERT_EQUAL( sal_Int32(0), (static_cast< const SdrMetricItem& >(pObj->GetMergedItem(SDRATTR_TEXT_UPPERDIST))).GetValue());
CPPUNIT_ASSERT_EQUAL( sal_Int32(0), (static_cast< const SdrMetricItem& >(pObj->GetMergedItem(SDRATTR_TEXT_LOWERDIST))).GetValue());
More information about the Libreoffice-commits
mailing list