[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-6-4' - chart2/source sw/qa

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 27 21:26:42 UTC 2020


 chart2/source/view/main/VLegend.cxx            |   56 ++++++++++++++++++++++---
 sw/qa/extras/layout/data/long_legendentry.docx |binary
 sw/qa/extras/layout/layout.cxx                 |   17 +++++++
 3 files changed, 67 insertions(+), 6 deletions(-)

New commits:
commit 1010aa9b2e064446082a0523aa746a2f9cb7458b
Author:     Tünde Tóth <tundeth at gmail.com>
AuthorDate: Mon Jun 15 16:42:40 2020 +0200
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Mon Jul 27 23:26:07 2020 +0200

    tdf#126425 Chart: fix missing legend with exceeding text
    
    Ellipsize legend box contents, if the custom size of
    the chart legend is too small to contain the text.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96437
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit 72613bd2a04b4b1ba614c0f645e9804ebfe73682)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97503
    Tested-by: Jenkins
    Reviewed-by: Tünde Tóth <tundeth at gmail.com>
    (cherry picked from commit dc219b0fe04d07a1e5c7c4c37bff94c29d4a1171)
    
    Change-Id: I91ef913f509b233912a8bfb878a1c80d577e2a88
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99537
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index f9d836921ebe..9962b3704089 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -407,18 +407,62 @@ awt::Size lcl_placeLegendEntries(
                         DrawModelWrapper::removeShape( aTextShapes[nEntry] );
                         aTextShapes.pop_back();
                     }
-                    if( nEntry < nNumberOfEntries )
+                    if( nEntry < nNumberOfEntries && ( nEntry != 0 || nNumberOfColumns != 1 ) )
                     {
                         DrawModelWrapper::removeShape( rEntries[ nEntry ].aSymbol );
                         rEntries.pop_back();
                         nNumberOfEntries--;
                     }
                 }
-                nSumHeight -= aRowHeights[nRow];
-                aRowHeights.pop_back();
-                nRemainingSpace = rRemainingSpace.Height - nSumHeight;
-                if( nRemainingSpace>=0 )
-                    break;
+                if (nRow == 0 && nNumberOfColumns == 1)
+                {
+                    try
+                    {
+                        OUString aLabelString = rEntries[0].aLabel[0]->getString();
+                        const OUString sDots = "...";
+                        ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(xShapeFactory);
+                        for (sal_Int32 nNewLen = aLabelString.getLength() - sDots.getLength(); nNewLen > 0; nNewLen--)
+                        {
+                            OUString aNewLabel = aLabelString.copy(0, nNewLen) + sDots;
+                            Reference<drawing::XShape> xEntry = pShapeFactory->createText(
+                                xTarget, aNewLabel, rTextProperties.first, rTextProperties.second, uno::Any());
+                            nSumHeight = xEntry->getSize().Height;
+                            nRemainingSpace = rRemainingSpace.Height - nSumHeight;
+                            if (nRemainingSpace >= 0)
+                            {
+                                sal_Int32 nWidth = xEntry->getSize().Width + nSymbolPlusDistanceWidth;
+                                if (rRemainingSpace.Width - nWidth >= 0)
+                                {
+                                    aTextShapes.push_back(xEntry);
+                                    rEntries[0].aLabel[0]->setString(aNewLabel);
+                                    aRowHeights[0] = nSumHeight;
+                                    aColumnWidths[0] = nWidth;
+                                    break;
+                                }
+                            }
+                            DrawModelWrapper::removeShape(xEntry);
+                        }
+                        if (aTextShapes.size() == 0)
+                        {
+                            DrawModelWrapper::removeShape(rEntries[0].aSymbol);
+                            rEntries.pop_back();
+                            nNumberOfEntries--;
+                            aRowHeights.pop_back();
+                        }
+                    }
+                    catch (const uno::Exception&)
+                    {
+                        DBG_UNHANDLED_EXCEPTION("chart2");
+                    }
+                }
+                else
+                {
+                    nSumHeight -= aRowHeights[nRow];
+                    aRowHeights.pop_back();
+                    nRemainingSpace = rRemainingSpace.Height - nSumHeight;
+                    if (nRemainingSpace >= 0)
+                        break;
+                }
             }
             nNumberOfRows = static_cast<sal_Int32>(aRowHeights.size());
         }
diff --git a/sw/qa/extras/layout/data/long_legendentry.docx b/sw/qa/extras/layout/data/long_legendentry.docx
new file mode 100644
index 000000000000..6259438a16e3
Binary files /dev/null and b/sw/qa/extras/layout/data/long_legendentry.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index ee4ecea6be69..c23672f9e562 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -2331,6 +2331,23 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf75659)
     // These failed, if the legend names are empty strings.
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf126425)
+{
+    SwDoc* pDoc = createDoc("long_legendentry.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;
+    xmlDocPtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 14
+    // - Actual  : 12
+    // i.e. the text of the chart legend lost.
+    assertXPath(pXmlDoc, "//textarray", 14);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf123268)
 {
     SwDoc* pDoc = createDoc("tdf123268.odt");


More information about the Libreoffice-commits mailing list