oox/inc/drawingml/textparagraph.hxx                    |    3 -
 oox/inc/drawingml/textparagraphproperties.hxx          |    1 
 oox/source/drawingml/textbody.cxx                      |    5 +-
 oox/source/drawingml/textparagraph.cxx                 |    5 +-
 oox/source/drawingml/textparagraphproperties.cxx       |   10 +++-
 sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx |binary
 sd/qa/unit/import-tests2.cxx                           |   40 +++++++++++++++++
 7 files changed, 58 insertions(+), 6 deletions(-)

New commits:
commit 08d0c2cd6b6bdf37d6fc5c16359bafc6dddc9d09
Author:     Sarper Akdemir <sarper.akde...@collabora.com>
AuthorDate: Mon Oct 24 01:50:36 2022 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Oct 27 15:13:32 2022 +0200

    tdf#149961 pptx import: fix indents for autofitted texboxes
    
    For autofitted textboxes, Impress scales the indents with the
    text size while PowerPoint doesn't.
    
    Scale the indents inversely propotional to autofit font
    scale so that the visual appearance on import is similar to
    PowerPoint.
    
    Change-Id: I7876b35a1f4221789564fcf23ccbe3fe21db3d48
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141717
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/oox/inc/drawingml/textparagraph.hxx 
b/oox/inc/drawingml/textparagraph.hxx
index 1f43249372a5..4920c99da7c5 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -77,7 +77,8 @@ public:
                                     const TextListStyle& rMasterTextListStyle,
                                     const TextListStyle& rTextListStyle,
                                     bool bFirst,
-                                    float nDefaultCharHeight) const;
+                                    float nDefaultCharHeight,
+                                    sal_Int32 nAutofitFontScale) const;
 
     bool HasMathXml() const
     {
diff --git a/oox/inc/drawingml/textparagraphproperties.hxx 
b/oox/inc/drawingml/textparagraphproperties.hxx
index 8ea56a7b0736..083b61e37da7 100644
--- a/oox/inc/drawingml/textparagraphproperties.hxx
+++ b/oox/inc/drawingml/textparagraphproperties.hxx
@@ -103,6 +103,7 @@ public:
                                                 const BulletList* 
pMasterBuList,
                                                 bool bApplyBulletList,
                                                 float fFontSize,
+                                                sal_Int32 nAutofitFontScale = 
100000,
                                                 bool bPushDefaultValues = 
false ) const;
 
     /** Returns the largest character size of this paragraph. If possible the
diff --git a/oox/source/drawingml/textbody.cxx 
b/oox/source/drawingml/textbody.cxx
index 0f053ab6ad74..1be15c4f885d 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -65,7 +65,7 @@ void TextBody::insertAt(
     for (auto const& paragraph : maParagraphs)
     {
         paragraph->insertAt(rFilterBase, xText, xAt, rTextStyleProperties, 
aMasterTextStyle,
-                            maTextListStyle, (nIndex == 0), nCharHeight);
+                            maTextListStyle, (nIndex == 0), nCharHeight, 
getTextProperties().mnFontScale);
         ++nIndex;
     }
 }
@@ -148,7 +148,8 @@ void TextBody::ApplyStyleEmpty(
         float nCharHeight = 
xProps->getPropertyValue("CharHeight").get<float>();
         TextParagraphProperties aParaProp;
         aParaProp.apply(*pTextParagraphStyle);
-        aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, 
&pTextParagraphStyle->getBulletList(), true, nCharHeight, true);
+        aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, 
&pTextParagraphStyle->getBulletList(),
+                                true, nCharHeight, 
getTextProperties().mnFontScale, true);
     }
 }
 
diff --git a/oox/source/drawingml/textparagraph.cxx 
b/oox/source/drawingml/textparagraph.cxx
index 23f051cdd5df..f08efdbff3c3 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -87,7 +87,8 @@ void TextParagraph::insertAt(
         const Reference < XTextCursor > &xAt,
         const TextCharacterProperties& rTextStyleProperties,
         const TextListStyle& rMasterTextListStyle,
-        const TextListStyle& rTextListStyle, bool bFirst, float 
nDefaultCharHeight) const
+        const TextListStyle& rTextListStyle, bool bFirst,
+        float nDefaultCharHeight, sal_Int32 nAutofitFontScale) const
 {
     try {
         sal_Int32 nParagraphSize = 0;
@@ -175,7 +176,7 @@ void TextParagraph::insertAt(
             }
 
             float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( 
nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
-            aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, 
&pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
+            aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, 
&pTextParagraphStyle->getBulletList(), true, fCharacterSize, nAutofitFontScale, 
true );
         }
 
         // empty paragraphs do not have bullets in ppt
diff --git a/oox/source/drawingml/textparagraphproperties.cxx 
b/oox/source/drawingml/textparagraphproperties.cxx
index 23efb301e963..0006b7530a76 100644
--- a/oox/source/drawingml/textparagraphproperties.cxx
+++ b/oox/source/drawingml/textparagraphproperties.cxx
@@ -405,7 +405,7 @@ void TextParagraphProperties::apply( const 
TextParagraphProperties& rSourceProps
 
 void TextParagraphProperties::pushToPropSet( const ::oox::core::XmlFilterBase* 
pFilterBase,
     const Reference < XPropertySet >& xPropSet, PropertyMap& rioBulletMap, 
const BulletList* pMasterBuList, bool bApplyBulletMap, float fCharacterSize,
-    bool bPushDefaultValues ) const
+    sal_Int32 nAutofitFontScale, bool bPushDefaultValues ) const
 {
     PropertySet aPropSet( xPropSet );
     aPropSet.setProperties( maTextParagraphPropertyMap );
@@ -431,6 +431,14 @@ void TextParagraphProperties::pushToPropSet( const 
::oox::core::XmlFilterBase* p
     std::optional< sal_Int32 > noParaLeftMargin( moParaLeftMargin );
     std::optional< sal_Int32 > noFirstLineIndentation( moFirstLineIndentation 
);
 
+    // tdf#149961 Impress scales the indents when text is autofitted while 
Powerpoint doesn't
+    // Try to counteract this by multiplying indents by the inverse of the 
autofit font scale.
+    if ( nAutofitFontScale )
+    {
+        if ( noParaLeftMargin ) noParaLeftMargin = *noParaLeftMargin * 
MAX_PERCENT / nAutofitFontScale;
+        if ( noFirstLineIndentation ) noFirstLineIndentation = 
*noFirstLineIndentation * MAX_PERCENT / nAutofitFontScale;
+    }
+
     if ( nNumberingType != NumberingType::NUMBER_NONE )
     {
         if ( noParaLeftMargin )
diff --git a/sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx 
b/sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx
new file mode 100644
index 000000000000..25513df7c9e8
Binary files /dev/null and 
b/sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx differ
diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx
index b95f2e3197e6..86641bde50ac 100644
--- a/sd/qa/unit/import-tests2.cxx
+++ b/sd/qa/unit/import-tests2.cxx
@@ -143,6 +143,7 @@ public:
     void testTdf144092TableHeight();
     void testTdf89928BlackWhiteThreshold();
     void testTdf151547TransparentWhiteText();
+    void testTdf149961AutofitIndentation();
 
     CPPUNIT_TEST_SUITE(SdImportTest2);
 
@@ -219,6 +220,7 @@ public:
     CPPUNIT_TEST(testTdf144092TableHeight);
     CPPUNIT_TEST(testTdf89928BlackWhiteThreshold);
     CPPUNIT_TEST(testTdf151547TransparentWhiteText);
+    CPPUNIT_TEST(testTdf149961AutofitIndentation);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -2189,6 +2191,44 @@ void SdImportTest2::testTdf151547TransparentWhiteText()
     xDocShRef->DoClose();
 }
 
+void SdImportTest2::testTdf149961AutofitIndentation()
+{
+    sd::DrawDocShellRef xDocShRef = loadURL(
+        
m_directories.getURLFromSrc(u"sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx"),
+        PPTX);
+
+    const SdrPage* pPage = GetPage(1, xDocShRef);
+
+    {
+        SdrTextObj* pTxtObj = dynamic_cast<SdrTextObj*>(pPage->GetObj(0));
+        CPPUNIT_ASSERT_MESSAGE("no text object", pTxtObj != nullptr);
+
+        const EditTextObject& aEdit = 
pTxtObj->GetOutlinerParaObject()->GetTextObject();
+        const SvxNumBulletItem* pNumFmt = 
aEdit.GetParaAttribs(0).GetItem(EE_PARA_NUMBULLET);
+        CPPUNIT_ASSERT(pNumFmt);
+
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(3175), 
pNumFmt->GetNumRule().GetLevel(0).GetAbsLSpace());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(-3175),
+                             
pNumFmt->GetNumRule().GetLevel(0).GetFirstLineOffset());
+    }
+
+    {
+        SdrTextObj* pTxtObj = dynamic_cast<SdrTextObj*>(pPage->GetObj(1));
+        CPPUNIT_ASSERT_MESSAGE("no text object", pTxtObj != nullptr);
+
+        const EditTextObject& aEdit = 
pTxtObj->GetOutlinerParaObject()->GetTextObject();
+        const SvxNumBulletItem* pNumFmt = 
aEdit.GetParaAttribs(0).GetItem(EE_PARA_NUMBULLET);
+        CPPUNIT_ASSERT(pNumFmt);
+
+        // Without the accompanying fix in place, this test would have failed 
with:
+        // - Expected: 12700
+        // - Actual  : 3175
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(12700), 
pNumFmt->GetNumRule().GetLevel(0).GetAbsLSpace());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(-12700),
+                             
pNumFmt->GetNumRule().GetLevel(0).GetFirstLineOffset());
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest2);
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to