chart2/source/view/charttypes/PieChart.cxx |   38 +++++++++++++++++------------
 sw/qa/extras/layout/data/tdf138018.docx    |binary
 sw/qa/extras/layout/layout2.cxx            |   17 ++++++++++++
 3 files changed, 40 insertions(+), 15 deletions(-)

New commits:
commit 3c7d0c8a32f71d597f33c9219fe8099e5381ca35
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Mon Nov 16 11:57:44 2020 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Nov 17 10:10:04 2020 +0100

    tdf#138018 don't show leader lines inside pie chart
    
    Show leader lines to data labels in custom position
    only outside of pie chart, as intended.
    
    Change-Id: I87dee2d33f4f876ffca208f69a069e1f0bcee688
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105920
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/chart2/source/view/charttypes/PieChart.cxx 
b/chart2/source/view/charttypes/PieChart.cxx
index b3dd54dec86d..7bf2eaa2a89b 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -492,23 +492,31 @@ void PieChart::createTextLabelShape(
         else if (nY1 > aRect.getMaxY())
             nY2 = aRect.getMaxY();
 
-        drawing::PointSequenceSequence aPoints(1);
-        aPoints[0].realloc(2);
-        aPoints[0][0].X = nX1;
-        aPoints[0][0].Y = nY1;
-        aPoints[0][1].X = nX2;
-        aPoints[0][1].Y = nY2;
-
-        uno::Reference<beans::XPropertySet> xProp(aPieLabelInfo.xTextShape, 
uno::UNO_QUERY);
-        VLineProperties aVLineProperties;
-        if (xProp.is())
+        sal_Int32 nSquaredDistanceFromOrigin
+            = (nX2 - aOrigin.X) * (nX2 - aOrigin.X) + (nY2 - aOrigin.Y) * (nY2 
- aOrigin.Y);
+
+        // tdf#138018 Don't show leader line when custom positioned data label 
is inside pie chart
+        if (nSquaredDistanceFromOrigin > fSquaredPieRadius)
         {
-            sal_Int32 nColor = 0;
-            xProp->getPropertyValue("CharColor") >>= nColor;
-            if (nColor != -1) //automatic font color does not work for lines 
-> fallback to black
-                aVLineProperties.Color <<= nColor;
+            drawing::PointSequenceSequence aPoints(1);
+            aPoints[0].realloc(2);
+            aPoints[0][0].X = nX1;
+            aPoints[0][0].Y = nY1;
+            aPoints[0][1].X = nX2;
+            aPoints[0][1].Y = nY2;
+
+            uno::Reference<beans::XPropertySet> 
xProp(aPieLabelInfo.xTextShape, uno::UNO_QUERY);
+            VLineProperties aVLineProperties;
+            if (xProp.is())
+            {
+                sal_Int32 nColor = 0;
+                xProp->getPropertyValue("CharColor") >>= nColor;
+                //automatic font color does not work for lines -> fallback to 
black
+                if (nColor != -1)
+                    aVLineProperties.Color <<= nColor;
+            }
+            m_pShapeFactory->createLine2D(xTextTarget, aPoints, 
&aVLineProperties);
         }
-        m_pShapeFactory->createLine2D(xTextTarget, aPoints, &aVLineProperties);
     }
 
     aPieLabelInfo.fValue = nVal;
diff --git a/sw/qa/extras/layout/data/tdf138018.docx 
b/sw/qa/extras/layout/data/tdf138018.docx
new file mode 100644
index 000000000000..96183f94946f
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf138018.docx differ
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 271087fbbad3..86bc9f43688c 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -893,6 +893,23 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf134121)
     assertXPath(pXmlDoc, "//polyline", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf138018)
+{
+    SwDoc* pDoc = createDoc("tdf138018.docx");
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 2
+    // - Actual  : 3
+    // i.e. the leader line was visible.
+    assertXPath(pXmlDoc, "//polyline", 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf130380)
 {
     SwDoc* pDoc = createDoc("tdf130380.docx");
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to