diff options
author | Tünde Tóth <tundeth@gmail.com> | 2020-06-25 10:43:58 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-06-29 12:52:44 +0200 |
commit | 17f131fcb3f534792a3b2ec6048d03fb54b55eb1 (patch) | |
tree | fba5ac3d4f57c353fe89f157133e1da12a1cae9d | |
parent | 51a4c85bf9228a3750b61cb54e64c8134314a35e (diff) |
tdf#134235 Chart OOXML import: fix long chart title
Workaround to handle long (sub)titles which resulted
broken charts.
See commit 96a29c12a9d8734c9d2a812f38fc6654b5df9c48
(tdf#101322 Chart OOXML Export: fix missing subtitle).
Change-Id: I22bb4699bdda8dea5f31c715cc1f439085a0718f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97092
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | chart2/source/view/inc/ShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 8 | ||||
-rw-r--r-- | chart2/source/view/main/ShapeFactory.cxx | 4 | ||||
-rw-r--r-- | chart2/source/view/main/VTitle.cxx | 14 | ||||
-rw-r--r-- | chart2/source/view/main/VTitle.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/layout/data/tdf134235.docx | bin | 0 -> 27348 bytes | |||
-rw-r--r-- | sw/qa/extras/layout/layout.cxx | 17 |
7 files changed, 40 insertions, 8 deletions
diff --git a/chart2/source/view/inc/ShapeFactory.hxx b/chart2/source/view/inc/ShapeFactory.hxx index 02faf45b8716..7a698e4b9d87 100644 --- a/chart2/source/view/inc/ShapeFactory.hxx +++ b/chart2/source/view/inc/ShapeFactory.hxx @@ -247,7 +247,7 @@ public: const css::awt::Point& rPosition, css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >& xFormattedString, const css::uno::Reference< css::beans::XPropertySet > & xTextProperties, - double nRotation, const OUString& aName ); + double nRotation, const OUString& aName, sal_Int32 nTextMaxWidth ); css::uno::Reference< css::drawing::XShape > createInvisibleRectangle( diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index a5e0ab5da984..4b6b1fa9b48f 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -2137,10 +2137,16 @@ std::shared_ptr<VTitle> lcl_createTitle( TitleHelper::eTitleType eType return apVTitle; //create title + awt::Size aTextMaxWidth(rPageSize.Width, rPageSize.Height); + 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); + } apVTitle = std::make_shared<VTitle>(xTitle); OUString aCID = ObjectIdentifier::createClassifiedIdentifierForObject(xTitle, rModel); apVTitle->init(xPageShapes, xShapeFactory, aCID); - apVTitle->createShapes(awt::Point(0,0), rPageSize); + apVTitle->createShapes(awt::Point(0, 0), rPageSize, aTextMaxWidth); awt::Size aTitleUnrotatedSize = apVTitle->getUnrotatedSize(); awt::Size aTitleSize = apVTitle->getFinalSize(); diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index 26a598931c29..23953def50d7 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -2374,7 +2374,7 @@ uno::Reference< drawing::XShape > uno::Sequence< uno::Reference< chart2::XFormattedString > >& xFormattedString, const uno::Reference< beans::XPropertySet > & xTextProperties, - double nRotation, const OUString& aName ) + double nRotation, const OUString& aName, sal_Int32 nTextMaxWidth ) { //create shape and add to page uno::Reference< drawing::XShape > xShape( @@ -2407,7 +2407,7 @@ uno::Reference< drawing::XShape > aValueMap.insert( { "TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_CENTER) } ); //drawing::TextVerticalAdjust aValueMap.insert( { "TextAutoGrowHeight", uno::Any(true) } ); // sal_Bool aValueMap.insert( { "TextAutoGrowWidth", uno::Any(true) } ); // sal_Bool - aValueMap.insert( { "TextMaximumFrameWidth", uno::Any(rSize.Width) } ); // sal_Int32 + aValueMap.insert({ "TextMaximumFrameWidth", uno::Any(nTextMaxWidth) }); // sal_Int32 //set name/classified ObjectID (CID) if( !aName.isEmpty() ) diff --git a/chart2/source/view/main/VTitle.cxx b/chart2/source/view/main/VTitle.cxx index 39989f191aa0..53e214f76999 100644 --- a/chart2/source/view/main/VTitle.cxx +++ b/chart2/source/view/main/VTitle.cxx @@ -99,7 +99,8 @@ void VTitle::changePosition( const awt::Point& rPos ) void VTitle::createShapes( const awt::Point& rPos - , const awt::Size& rReferenceSize ) + , const awt::Size& rReferenceSize + , const awt::Size& rTextMaxWidth ) { if(!m_xTitle.is()) return; @@ -124,9 +125,16 @@ void VTitle::createShapes( TOOLS_WARN_EXCEPTION("chart2", "" ); } + sal_Int32 nTextMaxWidth; + if (m_fRotationAngleDegree <= 15.0 || m_fRotationAngleDegree >= 345.0 + || (m_fRotationAngleDegree >= 165.0 && m_fRotationAngleDegree <= 195.0)) + nTextMaxWidth = rTextMaxWidth.Width; + else + nTextMaxWidth = rTextMaxWidth.Height; + ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory); - m_xShape =pShapeFactory->createText( m_xTarget, rReferenceSize, rPos, aStringList, - xTitleProperties, m_fRotationAngleDegree, m_aCID ); + m_xShape =pShapeFactory->createText( m_xTarget, rReferenceSize, rPos, aStringList, xTitleProperties, + m_fRotationAngleDegree, m_aCID, nTextMaxWidth ); } } //namespace chart diff --git a/chart2/source/view/main/VTitle.hxx b/chart2/source/view/main/VTitle.hxx index 45b9a5421324..261458025956 100644 --- a/chart2/source/view/main/VTitle.hxx +++ b/chart2/source/view/main/VTitle.hxx @@ -44,7 +44,8 @@ public: , const OUString& rCID ); void createShapes( const css::awt::Point& rPos - , const css::awt::Size& rReferenceSize ); + , const css::awt::Size& rReferenceSize + , const css::awt::Size& nTextMaxWidth ); double getRotationAnglePi() const; css::awt::Size getUnrotatedSize() const; diff --git a/sw/qa/extras/layout/data/tdf134235.docx b/sw/qa/extras/layout/data/tdf134235.docx Binary files differnew file mode 100644 index 000000000000..af0cb0d3de43 --- /dev/null +++ b/sw/qa/extras/layout/data/tdf134235.docx diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index a44d0396cf3d..e5c2784c17cb 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -2776,6 +2776,23 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf132956) "Category 1"); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf134235) +{ + SwDoc* pDoc = createDoc("tdf134235.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 chart title flowed out of chart area. + assertXPath(pXmlDoc, "//textarray", 14); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf116925) { SwDoc* pDoc = createDoc("tdf116925.docx"); |