chart2/source/view/main/ChartView.cxx   |   10 +++++++++-
 chart2/source/view/main/VTitle.cxx      |   15 ++++++++++++---
 chart2/source/view/main/VTitle.hxx      |    3 ++-
 sw/qa/extras/layout/data/tdf134146.docx |binary
 sw/qa/extras/layout/layout.cxx          |   17 +++++++++++++++++
 5 files changed, 40 insertions(+), 5 deletions(-)

New commits:
commit 23b73bc02536455df75438e19b5c70bacc9aa700
Author:     Tünde Tóth <tund...@gmail.com>
AuthorDate: Wed Jul 1 15:48:19 2020 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Jul 7 10:13:38 2020 +0200

    tdf#134146 Chart OOXML import: break long horizontal Y axis title
    
    Workaround to handle long (near) horizontal Y axis titles,
    like MSO does.
    
    See commit 17f131fcb3f534792a3b2ec6048d03fb54b55eb1
    (tdf#134235 Chart OOXML import: fix long chart title).
    
    Change-Id: I215aaa8e2ca18920e2b7ca5761c5bed7e8d19663
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97631
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/chart2/source/view/main/ChartView.cxx 
b/chart2/source/view/main/ChartView.cxx
index faa7fbe3511a..a6c09be30b1d 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -2139,15 +2139,23 @@ std::shared_ptr<VTitle> lcl_createTitle( 
TitleHelper::eTitleType eType
 
     //create title
     awt::Size aTextMaxWidth(rPageSize.Width, rPageSize.Height);
+    bool bYAxisTitle = false;
     if (eType == TitleHelper::MAIN_TITLE || eType == TitleHelper::SUB_TITLE)
     {
         aTextMaxWidth.Width = static_cast<sal_Int32>(rPageSize.Width * 0.8);
         aTextMaxWidth.Height = static_cast<sal_Int32>(rPageSize.Height * 0.5);
     }
+    else if (eType == TitleHelper::Y_AXIS_TITLE || eType == 
TitleHelper::SECONDARY_Y_AXIS_TITLE
+             || eType == TitleHelper::TITLE_AT_STANDARD_Y_AXIS_POSITION)
+    {
+        aTextMaxWidth.Width = static_cast<sal_Int32>(rPageSize.Width * 0.2);
+        aTextMaxWidth.Height = static_cast<sal_Int32>(rPageSize.Height * 0.8);
+        bYAxisTitle = true;
+    }
     apVTitle = std::make_shared<VTitle>(xTitle);
     OUString aCID = 
ObjectIdentifier::createClassifiedIdentifierForObject(xTitle, rModel);
     apVTitle->init(xPageShapes, xShapeFactory, aCID);
-    apVTitle->createShapes(awt::Point(0, 0), rPageSize, aTextMaxWidth);
+    apVTitle->createShapes(awt::Point(0, 0), rPageSize, aTextMaxWidth, 
bYAxisTitle);
     awt::Size aTitleUnrotatedSize = apVTitle->getUnrotatedSize();
     awt::Size aTitleSize = apVTitle->getFinalSize();
 
diff --git a/chart2/source/view/main/VTitle.cxx 
b/chart2/source/view/main/VTitle.cxx
index 53e214f76999..f0befe954659 100644
--- a/chart2/source/view/main/VTitle.cxx
+++ b/chart2/source/view/main/VTitle.cxx
@@ -100,7 +100,8 @@ void VTitle::changePosition( const awt::Point& rPos )
 void VTitle::createShapes(
       const awt::Point& rPos
     , const awt::Size& rReferenceSize
-    , const awt::Size& rTextMaxWidth )
+    , const awt::Size& rTextMaxWidth
+    , bool bYAxisTitle )
 {
     if(!m_xTitle.is())
         return;
@@ -126,8 +127,16 @@ void VTitle::createShapes(
     }
 
     sal_Int32 nTextMaxWidth;
-    if (m_fRotationAngleDegree <= 15.0 || m_fRotationAngleDegree >= 345.0
-        || (m_fRotationAngleDegree >= 165.0 && m_fRotationAngleDegree <= 
195.0))
+    if (bYAxisTitle)
+    {
+        if (m_fRotationAngleDegree < 75.0 || m_fRotationAngleDegree > 285.0
+            || (m_fRotationAngleDegree > 105.0 && m_fRotationAngleDegree < 
255.0))
+            nTextMaxWidth = rTextMaxWidth.Width;
+        else
+            nTextMaxWidth = rTextMaxWidth.Height;
+    }
+    else if (m_fRotationAngleDegree <= 15.0 || m_fRotationAngleDegree >= 345.0
+             || (m_fRotationAngleDegree >= 165.0 && m_fRotationAngleDegree <= 
195.0))
         nTextMaxWidth = rTextMaxWidth.Width;
     else
         nTextMaxWidth = rTextMaxWidth.Height;
diff --git a/chart2/source/view/main/VTitle.hxx 
b/chart2/source/view/main/VTitle.hxx
index 261458025956..9fb0e905fa8a 100644
--- a/chart2/source/view/main/VTitle.hxx
+++ b/chart2/source/view/main/VTitle.hxx
@@ -45,7 +45,8 @@ public:
 
     void    createShapes( const css::awt::Point& rPos
                           , const css::awt::Size& rReferenceSize
-                          , const css::awt::Size& nTextMaxWidth );
+                          , const css::awt::Size& nTextMaxWidth
+                          , bool bYAxisTitle );
 
     double getRotationAnglePi() const;
     css::awt::Size getUnrotatedSize() const;
diff --git a/sw/qa/extras/layout/data/tdf134146.docx 
b/sw/qa/extras/layout/data/tdf134146.docx
new file mode 100644
index 000000000000..9fe1bc06196f
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf134146.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index a4c46a3d69de..94cd82d26782 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -2840,6 +2840,23 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf134235)
     assertXPath(pXmlDoc, "//textarray", 14);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf134146)
+{
+    SwDoc* pDoc = createDoc("tdf134146.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: 14
+    // - Actual  : 13
+    // i.e. the Y axis title didn't break to multilple lines.
+    assertXPath(pXmlDoc, "//textarray", 14);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf116925)
 {
     SwDoc* pDoc = createDoc("tdf116925.docx");
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to