diff options
author | Justin Luth <justin.luth@collabora.com> | 2024-01-30 09:08:13 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-01-31 10:46:34 +0100 |
commit | 9833ac64c43b140233eca4ebb98e445a462425fc (patch) | |
tree | a5b656f9945ffdcd54eab1a9913fc531dd5262a5 /chart2/source | |
parent | b39c6082aa975ed8e5696c3dc24c3025ed07bbb6 (diff) |
tdf#146756 pie chart2 import: use consistent outside-label max text len
This is a followup to commit 85f4395b6f40c0295a190cca09ecd51858fc3b31.
Although there is no pressing need for this patch in my opinion,
it DOES fix a 7.1 regression in importing MSO charts with long labels.
MSO wraps text at 1/5 the width of the chart.
7.1 Regression commit 75a8b367f2a06e0d485fc2b9f4472e8bb29d71e3
Author: Balazs Varga on Tue Aug 25 12:32:02 2020 +0200
tdf#136105 tdf#134883 pie chart: improve data label position
Before Balazs' commit, the text width for everything was simply
fTextMaximumFrameWidth = 0.8 * fPieRadius.
I personally think Balazs' no wrapping looks better
(for outside labels, when there is enough space)
but in order to be consistent with how we handle
wrapping for bestFit-that-didn't-fit labels,
and to have our charts be as interoperable with OOXML as possible,
it makes good sense to use the same logic as the previous patch here.
Interestingly, Balazs broke some unit tests that specifically
were testing to make sure that text wrapping existed.
Fixed: // text wrap: wrap all text labels except Yellow one
make CppunitTest_chart2_xshape CPPUNIT_TEST_NAME=testPieChartLabels2
Fixed: // text wrap: wrap no text label except Yellow one
make CppunitTest_chart2_xshape CPPUNIT_TEST_NAME=testPieChartLabels3
Interestingly, I couldn't just copy/paste Ctrl-F12 dump to fix
make CppunitTest_chart2_xshape CPPUNIT_TEST_NAME=testPieChartLabels4
so I instead did a copy/paste of SAL_WARN("DUH",getXShapeDumpString());
Change-Id: I19f2ce2ce9c7653ae92dd596f0aaca1ed83f41bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162764
Tested-by: Justin Luth <jluth@mail.com>
Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'chart2/source')
-rw-r--r-- | chart2/source/view/charttypes/PieChart.cxx | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index 2d72da5f5886..ba87e8ce0cbe 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -417,12 +417,14 @@ void PieChart::createTextLabelShape( } else if (nLabelPlacement == css::chart::DataLabelPlacement::OUTSIDE) { - if ((fAngleDegree >= 67.5 && fAngleDegree <= 112.5) - || (fAngleDegree >= 247.5 && fAngleDegree <= 292.5)) - fTextMaximumFrameWidth = m_aAvailableOuterRect.getWidth() / 3.0; - else - fTextMaximumFrameWidth = 0.85 * (m_aAvailableOuterRect.getWidth() / 2.0 - fPieRadius); - } + const sal_Int32 nOuterX = aPieLabelInfo.aOuterPosition.getX(); + if (fAngleDegree < 90 || fAngleDegree > 270) // label is placed on the right side + fTextMaximumFrameWidth = 0.8 * abs(m_aAvailableOuterRect.getWidth() - nOuterX); + else // label is placed on the left side + fTextMaximumFrameWidth = 0.8 * nOuterX; + + fTextMaximumFrameWidth = std::min(fTextMaximumFrameWidth, fCompatMaxTextLen); + } } sal_Int32 nTextMaximumFrameWidth = ceil(fTextMaximumFrameWidth); @@ -473,9 +475,9 @@ void PieChart::createTextLabelShape( * so in that bizarre case just try the positive value of the result... */ const sal_Int32 nOuterX = aPieLabelInfo.aOuterPosition.getX(); - if (fAngleDegree < 90 || fAngleDegree > 270) // label is placed on the right half + if (fAngleDegree < 90 || fAngleDegree > 270) // label is placed on the right side fTextMaximumFrameWidth = 0.8 * abs(m_aAvailableOuterRect.getWidth() - nOuterX); - else // label is placed on the left half + else // label is placed on the left side fTextMaximumFrameWidth = 0.8 * nOuterX; nTextMaximumFrameWidth = ceil(std::min(fTextMaximumFrameWidth, fCompatMaxTextLen)); |