summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-02-11 14:05:37 +0900
committerMiklos Vajna <vmiklos@collabora.com>2022-02-28 12:48:34 +0100
commit2e8bc09cda424e87a7015147744c9230d4d8e7e0 (patch)
tree8a24a7bba62690b766f928bf8545f89e0455b7de
parentofz#44991 keep within legal ArrowShape range (diff)
downloadcore-2e8bc09cda424e87a7015147744c9230d4d8e7e0.tar.gz
core-2e8bc09cda424e87a7015147744c9230d4d8e7e0.zip
chart2: crop x-axis label if it's too long on fixed size charts
If the label text is too long on a fixed size chart area, crop it as we can't resize the chart area to accomodate for text breaking into multiple lines. The algorithm to determine if cropping is needed has assumed that we need this in case the x-axis label is vertical, so there was no check to actually make sure the text is horizontal or vertical and in case it was horizontal, it has taken height into account and not width, so nothing got cropped. Change-Id: I8e73027fc51722280418c9e0be34ce487c41171e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129813 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 92da88582ae8d5ddbd786f9936e1b2b46eaddf2c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129897 Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
-rw-r--r--chart2/qa/extras/chart2import.cxx73
-rw-r--r--chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odpbin0 -> 13293 bytes
-rw-r--r--chart2/source/view/axes/VCartesianAxis.cxx14
3 files changed, 70 insertions, 17 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 0c142a4e7f97..467bac3a7f62 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -124,20 +124,15 @@ public:
void testTdf90510(); // Pie chart label placement settings(XLS)
void testTdf109858(); // Pie chart label placement settings(XLSX)
void testTdf130105();
-
void testTdf111173();
void testTdf122226();
-
void testInternalDataProvider();
-
void testTdf115107(); // import complex data point labels
void testTdf115107_2(); // import complex data point labels in cobo charts with multiple data series
-
void testTdf116163();
-
void testTdf48041();
-
void testTdf121205();
+ void testFixedSizeBarChartVeryLongLabel();
void testTdf114179();
void testTdf124243();
@@ -251,17 +246,13 @@ public:
CPPUNIT_TEST(testTdf130105);
CPPUNIT_TEST(testTdf111173);
CPPUNIT_TEST(testTdf122226);
-
CPPUNIT_TEST(testInternalDataProvider);
-
CPPUNIT_TEST(testTdf115107);
CPPUNIT_TEST(testTdf115107_2);
-
CPPUNIT_TEST(testTdf116163);
-
CPPUNIT_TEST(testTdf48041);
-
CPPUNIT_TEST(testTdf121205);
+ CPPUNIT_TEST(testFixedSizeBarChartVeryLongLabel);
CPPUNIT_TEST(testTdf114179);
CPPUNIT_TEST(testTdf124243);
@@ -2917,6 +2908,66 @@ void Chart2ImportTest::testTdf139658()
CPPUNIT_ASSERT_EQUAL(OUString("category\"3"), aCategories[2]);
}
+void Chart2ImportTest::testFixedSizeBarChartVeryLongLabel()
+{
+ // Bar chart area size is fixed (not automatic) so we can't resize
+ // the chart area to let the label break into multiple lines. In this
+ // case the best course of action is to just crop the label text. This
+ // test checks that the rendered text is actually cropped.
+
+ load(u"/chart2/qa/extras/data/odp/", "FixedSizeBarChartVeryLongLabel.odp");
+
+ Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ Reference<chart2::XAxis> xHAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
+ CPPUNIT_ASSERT(xHAxis.is());
+
+ chart2::ScaleData aScaleData = xHAxis->getScaleData();
+ CPPUNIT_ASSERT(aScaleData.Categories.is());
+
+ Reference<chart2::data::XLabeledDataSequence> xLabeledDataSequence = aScaleData.Categories;
+ CPPUNIT_ASSERT(xLabeledDataSequence.is());
+
+ Reference<chart2::data::XDataSequence> xDataSequence = xLabeledDataSequence->getValues();
+ CPPUNIT_ASSERT(xDataSequence.is());
+
+ Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xDataSequence, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xTextualDataSequence.is());
+
+ std::vector<OUString> aCategories;
+ const Sequence<OUString> aTextData(xTextualDataSequence->getTextualData());
+ ::std::copy(aTextData.begin(), aTextData.end(),
+ ::std::back_inserter(aCategories));
+
+ // Check that we have a very very long label text
+ CPPUNIT_ASSERT_EQUAL(OUString("Very very very very very very very very very very very loooooooooooong label"), aCategories[0]);
+
+ // Check visible text
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xShapes.is());
+
+ uno::Reference<drawing::XShape> xXAxis = getShapeByName(xShapes, "CID/D=0:CS=0:Axis=0,0",
+ // Axis occurs twice in chart xshape representation so need to get the one related to labels
+ [](const uno::Reference<drawing::XShape>& rXShape) -> bool
+ {
+ uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xAxisShapes.is());
+ uno::Reference<drawing::XShape> xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xChildShape, uno::UNO_QUERY_THROW);
+ return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape");
+ });
+ CPPUNIT_ASSERT(xXAxis.is());
+
+ uno::Reference<container::XIndexAccess> xIndexAccess(xXAxis, UNO_QUERY_THROW);
+
+ // Check text is actually cropped
+ uno::Reference<text::XTextRange> xLabel(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("Very very very very..."), xLabel->getString());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp b/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp
new file mode 100644
index 000000000000..18869b638d1e
--- /dev/null
+++ b/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp
Binary files differ
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx
index fcb3391c693c..eceaf5d95fd4 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -84,14 +84,16 @@ static void lcl_ResizeTextShapeToFitAvailableSpace( Reference< drawing::XShape >
if( !xTextRange.is() )
return;
- const sal_Int32 nFullSize = bIsHorizontalAxis ? rAxisLabelProperties.m_aFontReferenceSize.Height : rAxisLabelProperties.m_aFontReferenceSize.Width;
+ bool bTextHorizontal = rAxisLabelProperties.fRotationAngleDegree != 0.0;
+ bool bIsDirectionVertical = bIsHorizontalAxis && bTextHorizontal;
+ const sal_Int32 nFullSize = bIsDirectionVertical ? rAxisLabelProperties.m_aFontReferenceSize.Height : rAxisLabelProperties.m_aFontReferenceSize.Width;
if( !nFullSize || !rLabel.getLength() )
return;
- sal_Int32 nMaxLabelsSize = bIsHorizontalAxis ? rAxisLabelProperties.m_aMaximumSpaceForLabels.Height : rAxisLabelProperties.m_aMaximumSpaceForLabels.Width;
+ sal_Int32 nMaxLabelsSize = bIsDirectionVertical ? rAxisLabelProperties.m_aMaximumSpaceForLabels.Height : rAxisLabelProperties.m_aMaximumSpaceForLabels.Width;
const sal_Int32 nAvgCharWidth = xShape2DText->getSize().Width / rLabel.getLength();
- const sal_Int32 nTextSize = bIsHorizontalAxis ? ShapeFactory::getSizeAfterRotation(xShape2DText, rAxisLabelProperties.fRotationAngleDegree).Height :
+ const sal_Int32 nTextSize = bIsDirectionVertical ? ShapeFactory::getSizeAfterRotation(xShape2DText, rAxisLabelProperties.fRotationAngleDegree).Height :
ShapeFactory::getSizeAfterRotation(xShape2DText, rAxisLabelProperties.fRotationAngleDegree).Width;
if( !nAvgCharWidth )
@@ -1860,12 +1862,12 @@ void VCartesianAxis::createShapes()
if( !prepareShapeCreation() )
return;
- std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure
- TickFactory2D* pTickFactory2D = apTickFactory2D.get();
-
//create line shapes
if(m_nDimension==2)
{
+ std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure
+ TickFactory2D* pTickFactory2D = apTickFactory2D.get();
+
//create extra long ticks to separate complex categories (create them only there where the labels are)
if( isComplexCategoryAxis() )
{