Kaydet (Commit) 78776388 authored tarafından Miklos Vajna's avatar Miklos Vajna

n#792778 oox: implement import of v:line inside v:group

The problem was that in ShapeBase::convertAndInsert(), the rectangle
calculated for a line was zero, that's why it wasn't imported. Fix this
by overriding the get*Rectangle() methods in LineShape, instead of doing
so with implConvertAndInsert().

Change-Id: Ie4bb2f7964b438cb56e4f5ee7a4ebe9f8f8eb734
üst 1e33b3dc
......@@ -128,12 +128,10 @@ protected:
::com::sun::star::awt::Rectangle getCoordSystem() const;
/** Returns the absolute shape rectangle according to the passed anchor. */
::com::sun::star::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
private:
/** Returns the absolute shape rectangle. */
::com::sun::star::awt::Rectangle getAbsRectangle() const;
virtual ::com::sun::star::awt::Rectangle getAbsRectangle() const;
/** Returns the rectangle relative to the parent coordinate system. */
::com::sun::star::awt::Rectangle getRelRectangle() const;
virtual ::com::sun::star::awt::Rectangle getRelRectangle() const;
protected:
Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
......@@ -341,11 +339,10 @@ public:
explicit LineShape( Drawing& rDrawing );
protected:
/** Creates the corresponding XShape and inserts it into the passed container. */
virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
implConvertAndInsert(
const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
/** Returns the absolute shape rectangle. */
virtual ::com::sun::star::awt::Rectangle getAbsRectangle() const;
/** Returns the rectangle relative to the parent coordinate system. */
virtual ::com::sun::star::awt::Rectangle getRelRectangle() const;
};
/** Bezier shape object that supports to, from, control1 and control2
......
......@@ -297,7 +297,6 @@ Reference< XShape > ShapeBase::convertAndInsert( const Reference< XShapes >& rxS
according to some imported shape client data (e.g. Excel cell anchor). */
awt::Rectangle aShapeRect = calcShapeRectangle( pParentAnchor );
// convert the shape, if the calculated rectangle is not empty
if( ((aShapeRect.Width > 0) || (aShapeRect.Height > 0)) && rxShapes.is() )
{
xShape = implConvertAndInsert( rxShapes, aShapeRect );
......@@ -320,6 +319,8 @@ Reference< XShape > ShapeBase::convertAndInsert( const Reference< XShapes >& rxS
mrDrawing.notifyXShapeInserted( xShape, aShapeRect, *this, bGroupChild );
}
}
else
SAL_WARN("oox", "not converting shape, as calculated rectangle is empty");
}
return xShape;
}
......@@ -637,10 +638,10 @@ LineShape::LineShape(Drawing& rDrawing)
{
}
Reference<XShape> LineShape::implConvertAndInsert(const Reference<XShapes>& rxShapes, const awt::Rectangle& rShapeRect) const
awt::Rectangle LineShape::getAbsRectangle() const
{
const GraphicHelper& rGraphicHelper = mrDrawing.getFilter().getGraphicHelper();
awt::Rectangle aShapeRect(rShapeRect);
awt::Rectangle aShapeRect;
sal_Int32 nIndex = 0;
aShapeRect.X = ConversionHelper::decodeMeasureToHmm(rGraphicHelper, maShapeModel.maFrom.getToken(0, ',', nIndex), 0, true, true);
......@@ -648,8 +649,20 @@ Reference<XShape> LineShape::implConvertAndInsert(const Reference<XShapes>& rxSh
nIndex = 0;
aShapeRect.Width = ConversionHelper::decodeMeasureToHmm(rGraphicHelper, maShapeModel.maTo.getToken(0, ',', nIndex), 0, true, true) - aShapeRect.X;
aShapeRect.Height = ConversionHelper::decodeMeasureToHmm(rGraphicHelper, maShapeModel.maTo.getToken(0, ',', nIndex), 0, false, true) - aShapeRect.Y;
return aShapeRect;
}
return SimpleShape::implConvertAndInsert(rxShapes, aShapeRect);
awt::Rectangle LineShape::getRelRectangle() const
{
awt::Rectangle aShapeRect;
sal_Int32 nIndex = 0;
aShapeRect.X = maShapeModel.maFrom.getToken(0, ',', nIndex).toInt32();
aShapeRect.Y = maShapeModel.maFrom.getToken(0, ',', nIndex).toInt32();
nIndex = 0;
aShapeRect.Width = maShapeModel.maTo.getToken(0, ',', nIndex).toInt32() - aShapeRect.X;
aShapeRect.Height = maShapeModel.maTo.getToken(0, ',', nIndex).toInt32() - aShapeRect.Y;
return aShapeRect;
}
// ============================================================================
......@@ -887,9 +900,9 @@ Reference< XShape > GroupShape::implConvertAndInsert( const Reference< XShapes >
xGroupShape = mrDrawing.createAndInsertXShape( "com.sun.star.drawing.GroupShape", rxShapes, rShapeRect );
Reference< XShapes > xChildShapes( xGroupShape, UNO_QUERY_THROW );
mxChildren->convertAndInsert( xChildShapes, &aParentAnchor );
// no child shape has been created - delete the group shape
if( !xChildShapes->hasElements() )
{
SAL_WARN("oox", "no child shape has been created - deleting the group shape");
rxShapes->remove( xGroupShape );
xGroupShape.clear();
}
......
......@@ -113,6 +113,7 @@ public:
void testN792778();
void testN793262();
void testN793998();
void testGroupshapeLine();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
......@@ -178,6 +179,7 @@ void Test::run()
{"n792778.docx", &Test::testN792778},
{"n793262.docx", &Test::testN793262},
{"n793998.docx", &Test::testN793998},
{"groupshape-line.docx", &Test::testGroupshapeLine},
};
header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
......@@ -1101,6 +1103,37 @@ void Test::testN792778()
CPPUNIT_ASSERT_EQUAL(sal_Int32(11684), xInnerShape->getPosition().Y);
}
void Test::testGroupshapeLine()
{
/*
* Another fallout from n#792778, this time first the lines inside a
* groupshape wasn't imported, then the fix broke the size/position of
* non-groupshape lines. Test both here.
*
* xray ThisComponent.DrawPage.Count ' 2 shapes
* xray ThisComponent.DrawPage(0).Position 'x: 2656, y: 339
* xray ThisComponent.DrawPage(0).Size ' width: 3270, height: 1392
* xray ThisComponent.DrawPage(1).getByIndex(0).Position 'x: 1272, y: 2286
* xray ThisComponent.DrawPage(1).getByIndex(0).Size 'width: 10160, height: 0
*/
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xDrawPage(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDrawPage->getCount());
uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2656), xShape->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(339), xShape->getPosition().Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(3270), xShape->getSize().Width);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1392), xShape->getSize().Height);
uno::Reference<drawing::XShapes> xGroupShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
xShape.set(xGroupShape->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1272), xShape->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2286), xShape->getPosition().Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(10160), xShape->getSize().Width);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xShape->getSize().Height);
}
void Test::testN793262()
{
uno::Reference<container::XEnumerationAccess> xHeaderText = getProperty< uno::Reference<container::XEnumerationAccess> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment