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 f2aba4e0f9bd11962739fed69bd5c99a56a6f5ed
Author:     Sarper Akdemir <sarper.akde...@collabora.com>
AuthorDate: Mon Oct 24 14:16:16 2022 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Fri Oct 28 12:06:44 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>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141940
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index c80024ea1fdd..674457b3c6e4 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -302,7 +302,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 0ab497a4fed3..5ee48ff6e338 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3020,7 +3020,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 );
@@ -3110,6 +3110,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),
@@ -3197,7 +3215,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);
@@ -3239,7 +3257,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);
@@ -3733,7 +3751,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 c897fecebaf2..45453f8e2b42 100644
--- a/sd/qa/unit/export-tests-ooxml3.cxx
+++ b/sd/qa/unit/export-tests-ooxml3.cxx
@@ -119,6 +119,7 @@ public:
     void testTdf109169_DiamondBevel();
     void testTdf144092_emptyShapeTextProps();
     void testTdf94122_autoColor();
+    void testAutofittedTextboxIndent();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest3);
 
@@ -204,6 +205,7 @@ public:
     CPPUNIT_TEST(testTdf109169_DiamondBevel);
     CPPUNIT_TEST(testTdf144092_emptyShapeTextProps);
     CPPUNIT_TEST(testTdf94122_autoColor);
+    CPPUNIT_TEST(testAutofittedTextboxIndent);
     CPPUNIT_TEST_SUITE_END();
 
     virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -2177,6 +2179,26 @@ void SdOOXMLExportTest3::testTdf94122_autoColor()
                 "val", "000000");
 }
 
+void SdOOXMLExportTest3::testAutofittedTextboxIndent()
+{
+    ::sd::DrawDocShellRef xDocShRef = loadURL(
+        
m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/autofitted-textbox-indent.odp"),
 ODP);
+
+    utl::TempFile 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();

Reply via email to