tdf#127908 tdf#128193 Chart OOXML: Fix Custom Y axis title position

Import part: set the anchor position to the TOP_LEFT corner of the rectangle
during the import, if the textbox is rotated with 90 or 270 degree. Because
the OOXML files always contains the TOP_LEFT coordinates of a textbox, even if
they are rotated.

Note: Unfortunatelly we do not know the shape size, so this fix
cannot handle rotations different than 0, 90 or 270 degrees.

Export part: export the top left corner coordinates of axis title shape
as the OOXML Standerd requires.

Change-Id: Id0875d65884f6bfef8726135a7c03418d2ce3f23
Reviewed-on: https://gerrit.libreoffice.org/80939
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
Balazs Varga
2019-10-22 14:33:46 +02:00
committed by László Németh
parent 6fff5e07f6
commit 9ff954d5f7
4 changed files with 60 additions and 11 deletions
+25
View File
@@ -123,6 +123,7 @@ public:
void testCrossBetweenXLSX();
void testCrossBetweenODS();
void testAxisTitleRotationXLSX();
void testAxisTitlePositionDOCX();
void testAxisCrossBetweenXSLX();
void testPieChartDataPointExplosionXLSX();
void testCustomDataLabel();
@@ -228,6 +229,7 @@ public:
CPPUNIT_TEST(testCrossBetweenXLSX);
CPPUNIT_TEST(testCrossBetweenODS);
CPPUNIT_TEST(testAxisTitleRotationXLSX);
CPPUNIT_TEST(testAxisTitlePositionDOCX);
CPPUNIT_TEST(testAxisCrossBetweenXSLX);
CPPUNIT_TEST(testPieChartDataPointExplosionXLSX);
CPPUNIT_TEST(testCustomDataLabel);
@@ -1932,6 +1934,29 @@ void Chart2ExportTest::testAxisTitleRotationXLSX()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:tx/c:rich/a:bodyPr", "rot", "0");
}
void Chart2ExportTest::testAxisTitlePositionDOCX()
{
load("/chart2/qa/extras/data/docx/", "testAxisTitlePosition.docx");
xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
CPPUNIT_ASSERT(pXmlDoc);
// test X Axis title position
OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:layout/c:manualLayout/c:x", "val");
double nX = aXVal.toDouble();
CPPUNIT_ASSERT(nX > 0.698208 && nX < 0.698209);
OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:layout/c:manualLayout/c:y", "val");
double nY = aYVal.toDouble();
CPPUNIT_ASSERT(nY > 0.805152 && nY < 0.805153);
// test Y Axis title position
aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:layout/c:manualLayout/c:x", "val");
nX = aXVal.toDouble();
CPPUNIT_ASSERT(nX > 0.025395 && nX < 0.025396);
aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:layout/c:manualLayout/c:y", "val");
nY = aYVal.toDouble();
CPPUNIT_ASSERT(nY > 0.384407 && nY < 0.384408);
}
void Chart2ExportTest::testAxisCrossBetweenXSLX()
{
load("/chart2/qa/extras/data/odt/", "axis-position.odt");
+1 -2
View File
@@ -1539,8 +1539,7 @@ void Chart2ImportTest::testAxisTitlePositionDOCX()
aPos = xAxisTitle->getPosition();
CPPUNIT_ASSERT_EQUAL(sal_Int32(387), static_cast<sal_Int32>(aPos.X));
// y coordinate is still wrong because of another older bug!
/*CPPUNIT_ASSERT_EQUAL(sal_Int32(1535), static_cast<sal_Int32>(aPos.Y));*/
CPPUNIT_ASSERT_EQUAL(sal_Int32(6378), static_cast<sal_Int32>(aPos.Y));
}
void Chart2ImportTest::testCombinedChartAttachedAxisXLSX()
+24 -8
View File
@@ -405,18 +405,34 @@ void LayoutConverter::convertFromModel( const Reference< XShape >& rxShape, doub
lclCalcPosition( aChartSize.Height, mrModel.mfY, mrModel.mnYMode ) );
if( (aShapePos.X >= 0) && (aShapePos.Y >= 0) )
{
bool bPropSet = false;
// the call to XShape.getSize() may recalc the chart view
awt::Size aShapeSize = rxShape->getSize();
// rotated shapes need special handling...
double fSin = fabs( sin( basegfx::deg2rad(fRotationAngle) ) );
// add part of height to X direction, if title is rotated down
if( fRotationAngle > 180.0 )
aShapePos.X += static_cast< sal_Int32 >( fSin * aShapeSize.Height + 0.5 );
// add part of width to Y direction, if title is rotated up
else if( fRotationAngle > 0.0 )
aShapePos.Y += static_cast< sal_Int32 >( fSin * aShapeSize.Width + 0.5 );
if( aShapeSize.Height > 0 || aShapeSize.Width > 0 )
{
double fSin = fabs(sin(basegfx::deg2rad(fRotationAngle)));
// add part of height to X direction, if title is rotated down
if( fRotationAngle > 180.0 )
aShapePos.X += static_cast<sal_Int32>(fSin * aShapeSize.Height + 0.5);
// add part of width to Y direction, if title is rotated up
else if( fRotationAngle > 0.0 )
aShapePos.Y += static_cast<sal_Int32>(fSin * aShapeSize.Width + 0.5);
}
else if( fRotationAngle == 90.0 || fRotationAngle == 270.0 )
{
PropertySet aShapeProp( rxShape );
RelativePosition aPos(
getLimitedValue< double, double >(mrModel.mfX, 0.0, 1.0),
getLimitedValue< double, double >(mrModel.mfY, 0.0, 1.0),
fRotationAngle == 90.0 ? Alignment_TOP_RIGHT : Alignment_BOTTOM_LEFT );
// set the resulting position at the shape
if( aShapeProp.setProperty(PROP_RelativePosition, aPos) )
bPropSet = true;
}
// set the resulting position at the shape
rxShape->setPosition( aShapePos );
if( !bPropSet )
rxShape->setPosition( aShapePos );
}
}
}
+10 -1
View File
@@ -1213,8 +1213,17 @@ void ChartExport::exportTitle( const Reference< XShape >& xShape, const OUString
Reference<embed::XVisualObject> xVisObject(mxChartModel, uno::UNO_QUERY);
awt::Size aPageSize = xVisObject->getVisualAreaSize(embed::Aspects::MSOLE_CONTENT);
// awt::Size aSize = xShape->getSize();
awt::Size aSize = xShape->getSize();
awt::Point aPos2 = xShape->getPosition();
// rotated shapes need special handling...
double fSin = fabs(sin(basegfx::deg2rad(nRotation*0.01)));
// remove part of height from X direction, if title is rotated down
if( nRotation*0.01 > 180.0 )
aPos2.X -= static_cast<sal_Int32>(fSin * aSize.Height + 0.5);
// remove part of width from Y direction, if title is rotated up
else if( nRotation*0.01 > 0.0 )
aPos2.Y -= static_cast<sal_Int32>(fSin * aSize.Width + 0.5);
double x = static_cast<double>(aPos2.X) / static_cast<double>(aPageSize.Width);
double y = static_cast<double>(aPos2.Y) / static_cast<double>(aPageSize.Height);
/*