diff options
-rw-r--r-- | oox/inc/drawingml/textparagraph.hxx | 3 | ||||
-rw-r--r-- | oox/inc/drawingml/textparagraphproperties.hxx | 1 | ||||
-rw-r--r-- | oox/source/drawingml/textbody.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraph.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraphproperties.cxx | 10 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx | bin | 0 -> 34123 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests2.cxx | 40 |
7 files changed, 58 insertions, 6 deletions
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 Binary files differnew file mode 100644 index 000000000000..25513df7c9e8 --- /dev/null +++ b/sd/qa/unit/data/pptx/tdf149961-autofitIndentation.pptx 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(); |