summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTünde Tóth <toth.tunde@nisz.hu>2022-07-27 08:58:35 +0200
committerLászló Németh <nemeth@numbertext.org>2022-08-18 13:39:31 +0200
commite59db22b3b57c9e1a5678218cb56fb75bcc84c26 (patch)
treeebebb3ac16caba9876cd136561d534e8509cec64
parentno need to allocate these on the heap (diff)
downloadcore-e59db22b3b57c9e1a5678218cb56fb75bcc84c26.tar.gz
core-e59db22b3b57c9e1a5678218cb56fb75bcc84c26.zip
tdf#150434: chart2, XLSX import: strip long legend labels
Full text of legend labels could overflow the chart area, if the legend text was too long. If it's longer than 520 characters, strip it at the first space from the 500th character (or if there is no space, at the 500th character). This results better XLSX interoperability, too. Change-Id: I23a94f6baaf620b40e9b2819738eba5c5a921722 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137492 Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--chart2/qa/extras/chart2import2.cxx18
-rw-r--r--chart2/qa/extras/data/xlsx/tdf150434.xlsxbin0 -> 14918 bytes
-rw-r--r--chart2/source/view/main/VLegend.cxx8
3 files changed, 26 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import2.cxx b/chart2/qa/extras/chart2import2.cxx
index ee41c37dd48a..eb983f7687f1 100644
--- a/chart2/qa/extras/chart2import2.cxx
+++ b/chart2/qa/extras/chart2import2.cxx
@@ -60,6 +60,7 @@ public:
void testTdf121281();
void testTdf139658();
void testTdf146066();
+ void testTdf150434();
CPPUNIT_TEST_SUITE(Chart2ImportTest2);
@@ -101,6 +102,7 @@ public:
CPPUNIT_TEST(testTdf121281);
CPPUNIT_TEST(testTdf139658);
CPPUNIT_TEST(testTdf146066);
+ CPPUNIT_TEST(testTdf150434);
CPPUNIT_TEST_SUITE_END();
};
@@ -930,6 +932,22 @@ void Chart2ImportTest2::testTdf146066()
CPPUNIT_ASSERT_EQUAL(OUString("35"), xLabel7->getString());
}
+void Chart2ImportTest2::testTdf150434()
+{
+ load(u"/chart2/qa/extras/data/xlsx/", u"tdf150434.xlsx");
+ Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
+ UNO_QUERY_THROW);
+ Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
+ Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
+ Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
+ Reference<drawing::XShape> xLegend = getShapeByName(xShapes, "CID/D=0:Legend=");
+ CPPUNIT_ASSERT(xLegend.is());
+ awt::Point aPosition = xLegend->getPosition();
+
+ // This failed, if the legend flowed out of the chart area.
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), aPosition.Y);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest2);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/xlsx/tdf150434.xlsx b/chart2/qa/extras/data/xlsx/tdf150434.xlsx
new file mode 100644
index 000000000000..309a0c4c25f7
--- /dev/null
+++ b/chart2/qa/extras/data/xlsx/tdf150434.xlsx
Binary files differ
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 7fc92b491ad2..e789baf62a62 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -167,6 +167,14 @@ awt::Size lcl_createTextShapes(
if( i == 1 )
break;
+ // tdf#150034 limit legend label text
+ if (aLabelSeq[i]->getString().getLength() > 520)
+ {
+ sal_Int32 nIndex = aLabelSeq[i]->getString().indexOf(' ', 500);
+ aLabelSeq[i]->setString(
+ aLabelSeq[i]->getString().copy(0, nIndex > 500 ? nIndex : 500));
+ }
+
aLabelString += aLabelSeq[i]->getString();
// workaround for Issue #i67540#
if( aLabelString.isEmpty())