chart2/qa/extras/chart2import2.cxx | 42 ++++++++++++ chart2/qa/extras/data/xls/testRotatedAxisTitlePositions.xls |binary sc/source/filter/excel/xichart.cxx | 17 ++-- 3 files changed, 50 insertions(+), 9 deletions(-)
New commits: commit 18b40b3964f9fc658abbb6cee1d6401842ffe36c Author: Markus Mohrhard <[email protected]> AuthorDate: Thu Aug 14 05:12:31 2025 +0800 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Aug 14 12:19:59 2025 +0200 tdf#94259: don't use the non-existed chart view during import During the import process the chart view shapes don't exist yet and therefore trying to infer the title size from the chart shape can't work. Luckily for the axis titles we can reuse the title size that was stored in the file. There are still small differences in the positioning of various objects between Calc and Excel but these are unrelated to this problem. Change-Id: Ibe243e24f7bab3eedd06ee26037bcedeac48354e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189538 Tested-by: Jenkins Reviewed-by: Markus Mohrhard <[email protected]> (cherry picked from commit 0bfca02bf492ec917633388aa01421a1e0dad31a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189566 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/chart2/qa/extras/chart2import2.cxx b/chart2/qa/extras/chart2import2.cxx index f8b17a4f9116..7f1a086c7f68 100644 --- a/chart2/qa/extras/chart2import2.cxx +++ b/chart2/qa/extras/chart2import2.cxx @@ -1007,6 +1007,48 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf136754) drawing::FillStyle_SOLID, eStyle); } +CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf94259) +{ + loadFromFile(u"xls/testRotatedAxisTitlePositions.xls"); + { + uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 1, 0); + CPPUNIT_ASSERT(xAxis.is()); + lcl_assertAngles(xAxis, 0, 90); + Reference<chart2::XTitle> xAxisTitle + = css::uno::Reference<chart2::XTitled>(xAxis, UNO_QUERY_THROW)->getTitleObject(); + Reference<beans::XPropertySet> xAxisTitleProps(xAxisTitle, UNO_QUERY_THROW); + + chart2::RelativePosition aRelPos; + CPPUNIT_ASSERT(xAxisTitleProps->getPropertyValue("RelativePosition") >>= aRelPos); + + // old value with my setup 0.0327998, new value: 0.822488 + CPPUNIT_ASSERT_GREATER(0.1, aRelPos.Secondary); + SAL_WARN("chart2", "Primary: " << aRelPos.Primary << ", " << aRelPos.Secondary); + } + { + uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(1); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 1, 0); + CPPUNIT_ASSERT(xAxis.is()); + lcl_assertAngles(xAxis, 0, 270); + + Reference<chart2::XTitle> xAxisTitle + = css::uno::Reference<chart2::XTitled>(xAxis, UNO_QUERY_THROW)->getTitleObject(); + Reference<beans::XPropertySet> xAxisTitleProps(xAxisTitle, UNO_QUERY_THROW); + + chart2::RelativePosition aRelPos; + CPPUNIT_ASSERT(xAxisTitleProps->getPropertyValue("RelativePosition") >>= aRelPos); + + SAL_WARN("chart2", "Primary: " << aRelPos.Primary << ", " << aRelPos.Secondary); + // old value with my setup 0.0330348, new value: 0.0987283 + CPPUNIT_ASSERT_GREATER(0.05, aRelPos.Primary); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/qa/extras/data/xls/testRotatedAxisTitlePositions.xls b/chart2/qa/extras/data/xls/testRotatedAxisTitlePositions.xls new file mode 100644 index 000000000000..c5419d3761c1 Binary files /dev/null and b/chart2/qa/extras/data/xls/testRotatedAxisTitlePositions.xls differ diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index 06505c35fad3..f9a9b84c5652 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -1206,22 +1206,21 @@ void XclImpChText::ConvertTitlePosition( const XclChTextKey& rTitleKey ) const try { Reference< XShape > xTitleShape( GetTitleShape( rTitleKey ), UNO_SET_THROW ); - // the call to XShape.getSize() may recalc the chart view - css::awt::Size aTitleSize = xTitleShape->getSize(); // rotated titles need special handling... Degree100 nScRot = XclTools::GetScRotation( GetRotation(), 0_deg100 ); double fRad = toRadians(nScRot); double fSin = fabs( sin( fRad ) ); // calculate the title position from the values in the CHTEXT record - css::awt::Point aTitlePos( - CalcHmmFromChartX( maData.maRect.mnX ), - CalcHmmFromChartY( maData.maRect.mnY ) ); - // add part of height to X direction, if title is rotated down (clockwise) + css::awt::Rectangle aTitleRect = CalcHmmFromChartRect(maData.maRect); + css::awt::Point aTitlePos(aTitleRect.X, aTitleRect.Y); + // add part of width to X direction, if title is rotated down (clockwise) if( nScRot > 18000_deg100 ) - aTitlePos.X += static_cast< sal_Int32 >( fSin * aTitleSize.Height + 0.5 ); - // add part of width to Y direction, if title is rotated up (counterclockwise) + { + aTitlePos.X += static_cast< sal_Int32 >( fSin * aTitleRect.Width + 0.5 ); + } + // add part of height to Y direction, if title is rotated up (counterclockwise) else if( nScRot > 0_deg100 ) - aTitlePos.Y += static_cast< sal_Int32 >( fSin * aTitleSize.Width + 0.5 ); + aTitlePos.Y += static_cast< sal_Int32 >( fSin * aTitleRect.Height + 0.5 ); // set the resulting position at the title shape xTitleShape->setPosition( aTitlePos ); }
