chart2/source/view/axes/VCartesianAxis.cxx | 25 ++++++++++++++++++------- chart2/source/view/axes/VCartesianAxis.hxx | 2 +- sw/qa/extras/layout/data/tdf125334.odt |binary sw/qa/extras/layout/layout.cxx | 20 +++++++++++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-)
New commits: commit 75ef0e41ea8a9096ac619356d2b837c5333b47e6 Author: Balazs Varga <[email protected]> AuthorDate: Fri May 17 11:40:27 2019 +0200 Commit: László Németh <[email protected]> CommitDate: Sat May 18 00:06:28 2019 +0200 tdf#125334 Chart: allow text break in bar chart axis labels Now vertical category axis labels support text breaking. Change-Id: I8b1c6eff921ea999bc4f745aa5f85bae278e735b Reviewed-on: https://gerrit.libreoffice.org/72457 Tested-by: Jenkins Reviewed-by: László Németh <[email protected]> diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 234e1000140a..4fac1f83b72e 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -510,7 +510,7 @@ TickInfo* MaxLabelTickIter::nextInfo() } bool VCartesianAxis::isBreakOfLabelsAllowed( - const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis ) const + const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis, bool bIsVerticalAxis) const { if( m_aTextLabels.getLength() > 100 ) return false; @@ -525,8 +525,10 @@ bool VCartesianAxis::isBreakOfLabelsAllowed( rAxisLabelProperties.fRotationAngleDegree == 90.0 || rAxisLabelProperties.fRotationAngleDegree == 270.0 ) ) return false; - //break only for horizontal axis - return bIsHorizontalAxis; + if ( !m_aAxisProperties.m_bSwapXAndY ) + return bIsHorizontalAxis; + else + return bIsVerticalAxis; } namespace{ @@ -702,7 +704,7 @@ bool VCartesianAxis::createTextShapes( const bool bIsHorizontalAxis = pTickFactory->isHorizontalAxis(); const bool bIsVerticalAxis = pTickFactory->isVerticalAxis(); - if (!isBreakOfLabelsAllowed(rAxisLabelProperties, bIsHorizontalAxis) && + if (!isBreakOfLabelsAllowed(rAxisLabelProperties, bIsHorizontalAxis, bIsVerticalAxis) && !isAutoStaggeringOfLabelsAllowed(rAxisLabelProperties, bIsHorizontalAxis, bIsVerticalAxis) && !rAxisLabelProperties.isStaggered()) return createTextShapesSimple(xTarget, rTickIter, rAxisLabelProperties, pTickFactory); @@ -714,7 +716,7 @@ bool VCartesianAxis::createTextShapes( B2DVector aTextToTickDistance = pTickFactory->getDistanceAxisTickToText(m_aAxisProperties, true); sal_Int32 nLimitedSpaceForText = -1; - if( isBreakOfLabelsAllowed( rAxisLabelProperties, bIsHorizontalAxis ) ) + if( isBreakOfLabelsAllowed( rAxisLabelProperties, bIsHorizontalAxis, bIsVerticalAxis ) ) { nLimitedSpaceForText = nScreenDistanceBetweenTicks; if( bIsStaggered ) @@ -742,6 +744,12 @@ bool VCartesianAxis::createTextShapes( nLimitedSpaceForText = -1; } } + + // recalculate the nLimitedSpaceForText in case of vertical category axis if the text break is true + if ( m_aAxisProperties.m_bSwapXAndY && bIsVerticalAxis && rAxisLabelProperties.fRotationAngleDegree == 0.0 ) + { + nLimitedSpaceForText = rAxisLabelProperties.m_aMaximumSpaceForLabels.X; + } } // Stores an array of text label strings in case of a normal @@ -750,8 +758,11 @@ bool VCartesianAxis::createTextShapes( if( m_bUseTextLabels && !m_aAxisProperties.m_bComplexCategories ) pCategories = &m_aTextLabels; - bool bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY()); - + bool bLimitedHeight; + if( !m_aAxisProperties.m_bSwapXAndY ) + bLimitedHeight = fabs(aTextToTickDistance.getX()) > fabs(aTextToTickDistance.getY()); + else + bLimitedHeight = fabs(aTextToTickDistance.getX()) < fabs(aTextToTickDistance.getY()); //prepare properties for multipropertyset-interface of shape tNameSequence aPropNames; tAnySequence aPropValues; diff --git a/chart2/source/view/axes/VCartesianAxis.hxx b/chart2/source/view/axes/VCartesianAxis.hxx index df15e4896198..1c020bc4174c 100644 --- a/chart2/source/view/axes/VCartesianAxis.hxx +++ b/chart2/source/view/axes/VCartesianAxis.hxx @@ -150,7 +150,7 @@ private: //methods * @return true if we can break a single line label text into multiple * lines for better fitting, otherwise false. */ - bool isBreakOfLabelsAllowed( const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis ) const; + bool isBreakOfLabelsAllowed( const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis, bool bIsVerticalAxis ) const; ::basegfx::B2DVector getScreenPosition( double fLogicX, double fLogicY, double fLogicZ ) const; ScreenPosAndLogicPos getScreenPosAndLogicPos( double fLogicX, double fLogicY, double fLogicZ ) const; diff --git a/sw/qa/extras/layout/data/tdf125334.odt b/sw/qa/extras/layout/data/tdf125334.odt new file mode 100644 index 000000000000..70ea914aa48a Binary files /dev/null and b/sw/qa/extras/layout/data/tdf125334.odt differ diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 9c3650e7107b..93cd45e1f429 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -2324,7 +2324,25 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf108021) pXmlDoc, "/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/textarray[@length='22']", 8); - // This failed, if the textarray length of the first axis label not 17. + // This failed, if the textarray length of the first axis label not 22. +} + +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf125334) +{ + SwDoc* pDoc = createDoc("tdf125334.odt"); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + xmlDocPtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath( + pXmlDoc, + "/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/textarray[@length='17']", + 4); + // This failed, if the textarray length of the category axis label not 17. } CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf122800) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
