include/oox/export/drawingml.hxx | 2 - oox/source/export/drawingml.cxx | 26 ++++++++++++++++++---- sd/qa/unit/data/odp/autofitted-textbox-indent.odp |binary sd/qa/unit/export-tests-ooxml3.cxx | 22 ++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-)
New commits: commit e6a1586ff90125245cf0f898af37bf568abdcddf Author: Sarper Akdemir <sarper.akde...@collabora.com> AuthorDate: Mon Oct 24 14:16:16 2022 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Oct 27 15:15:26 2022 +0200 related tdf#149961 pptx export: scale indents for autofitted textboxes For autofitted textboxes, Impress scales the indents with the text size while PowerPoint doesn't. Try to compensate for this by scaling exported indents proportionally to the font scale on autofitted textboxes. Change-Id: Ib0f967e923d23553b4cdbd1bbe2e137d97b1b2e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141758 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index aeda7fa3a222..3f74f124d767 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -303,7 +303,7 @@ public: @returns true if any paragraph properties were written */ - bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, float fFirstCharHeight, sal_Int32 nElement); + bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet, float fFirstCharHeight, sal_Int32 nElement); void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight, sal_Int16 nLevel ); void WriteParagraphTabStops(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index e0766d0e7a7a..e8d5bef246c4 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -3021,7 +3021,7 @@ void DrawingML::WriteLinespacing(const LineSpacing& rSpacing, float fFirstCharHe } } -bool DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph, float fFirstCharHeight, sal_Int32 nElement) +bool DrawingML::WriteParagraphProperties(const Reference<XTextContent>& rParagraph, const Reference<XPropertySet>& rXShapePropSet, float fFirstCharHeight, sal_Int32 nElement) { Reference< XPropertySet > rXPropSet( rParagraph, UNO_QUERY ); Reference< XPropertyState > rXPropState( rParagraph, UNO_QUERY ); @@ -3111,6 +3111,24 @@ bool DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara return false; } + // for autofitted textboxes, scale the indents + if (GetProperty(rXShapePropSet, "TextFitToSize") && mAny.get<TextFitToSizeType>() == TextFitToSizeType_AUTOFIT) + { + SvxShapeText* pTextShape = dynamic_cast<SvxShapeText*>(rXShapePropSet.get()); + if (pTextShape) + { + SdrTextObj* pTextObject = dynamic_cast<SdrTextObj*>(pTextShape->GetSdrObject()); + if (pTextObject) + { + const auto nFontScaleY = pTextObject->GetFontScaleY(); + nLeftMargin = nLeftMargin * nFontScaleY / 100; + nLineIndentation = nLineIndentation * nFontScaleY / 100; + nParaLeftMargin = nParaLeftMargin * nFontScaleY / 100; + nParaFirstLineIndent = nParaFirstLineIndent * nFontScaleY / 100; + } + } + } + if (nParaLeftMargin) // For Paragraph mpFS->startElementNS( XML_a, nElement, XML_lvl, sax_fastparser::UseIf(OString::number(nLevel), nLevel > 0), @@ -3198,7 +3216,7 @@ void DrawingML::WriteLstStyles(const css::uno::Reference<css::text::XTextContent fFirstCharHeight = xFirstRunPropSet->getPropertyValue("CharHeight").get<float>(); mpFS->startElementNS(XML_a, XML_lstStyle); - if( !WriteParagraphProperties(rParagraph, fFirstCharHeight, XML_lvl1pPr) ) + if( !WriteParagraphProperties(rParagraph, rXShapePropSet, fFirstCharHeight, XML_lvl1pPr) ) mpFS->startElementNS(XML_a, XML_lvl1pPr); WriteRunProperties(xFirstRunPropSet, false, XML_defRPr, true, rbOverridingCharHeight, rnCharHeight, GetScriptType(rRun->getString()), rXShapePropSet); @@ -3240,7 +3258,7 @@ void DrawingML::WriteParagraph( const Reference< XTextContent >& rParagraph, rnCharHeight = 100 * fFirstCharHeight; rbOverridingCharHeight = true; } - WriteParagraphProperties(rParagraph, fFirstCharHeight, XML_pPr); + WriteParagraphProperties(rParagraph, rXShapePropSet, fFirstCharHeight, XML_pPr); bPropertiesWritten = true; } WriteRun( run, rbOverridingCharHeight, rnCharHeight, rXShapePropSet); @@ -3848,7 +3866,7 @@ void DrawingML::WriteText(const Reference<XInterface>& rXIface, bool bBodyPr, bo if( aAny >>= xParagraph ) { mpFS->startElementNS(XML_a, XML_p); - WriteParagraphProperties(xParagraph, nCharHeight, XML_pPr); + WriteParagraphProperties(xParagraph, rXPropSet, nCharHeight, XML_pPr); sal_Int16 nDummy = -1; WriteRunProperties(rXPropSet, false, XML_endParaRPr, false, bOverridingCharHeight, nCharHeight, nDummy, rXPropSet); diff --git a/sd/qa/unit/data/odp/autofitted-textbox-indent.odp b/sd/qa/unit/data/odp/autofitted-textbox-indent.odp new file mode 100644 index 000000000000..298c19903db2 Binary files /dev/null and b/sd/qa/unit/data/odp/autofitted-textbox-indent.odp differ diff --git a/sd/qa/unit/export-tests-ooxml3.cxx b/sd/qa/unit/export-tests-ooxml3.cxx index 4f5460e1c00b..128528f15844 100644 --- a/sd/qa/unit/export-tests-ooxml3.cxx +++ b/sd/qa/unit/export-tests-ooxml3.cxx @@ -123,6 +123,7 @@ public: void testTdf149551_btlr(); void testTdf94122_autoColor(); void testTdf124333(); + void testAutofittedTextboxIndent(); CPPUNIT_TEST_SUITE(SdOOXMLExportTest3); @@ -211,6 +212,7 @@ public: CPPUNIT_TEST(testTdf149551_btlr); CPPUNIT_TEST(testTdf94122_autoColor); CPPUNIT_TEST(testTdf124333); + CPPUNIT_TEST(testAutofittedTextboxIndent); CPPUNIT_TEST_SUITE_END(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override @@ -2281,6 +2283,26 @@ void SdOOXMLExportTest3::testTdf124333() xDocShRef->DoClose(); } +void SdOOXMLExportTest3::testAutofittedTextboxIndent() +{ + ::sd::DrawDocShellRef xDocShRef = loadURL( + m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/autofitted-textbox-indent.odp"), ODP); + + utl::TempFileNamed tempFile; + xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile); + xDocShRef->DoClose(); + + // Without the accompanying fix in place, these tests would have failed with: + // - Expected: 691200 + // - Actual : 1080000 + // i.e. paragraph indent wasn't scaled proportionally to autofitted textbox + // font scale on export + + xmlDocUniquePtr pXmlDocContent1 = parseExport(tempFile, "ppt/slides/slide1.xml"); + assertXPath(pXmlDocContent1, "/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p[1]/a:pPr", "marL", + "691200"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3); CPPUNIT_PLUGIN_IMPLEMENT();