sw/qa/extras/ww8export/data/tdf72511_editengLRSpace.doc |binary sw/qa/extras/ww8export/ww8export4.cxx | 23 ++++++ sw/source/filter/ww8/ww8graf.cxx | 61 +++++++++++++++- sw/source/filter/ww8/ww8par.hxx | 2 4 files changed, 82 insertions(+), 4 deletions(-)
New commits: commit 7fcd5ac42086f1374c3bd5eb2be9a59e6f38f2e3 Author: Justin Luth <jl...@mail.com> AuthorDate: Tue May 14 18:12:59 2024 -0400 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Thu May 16 09:54:33 2024 +0200 tdf#72511 tdf#78510 ww8import: recombine into SvxLRSpaceItem for EE This fixes Michael's 7.6 regression, commit db115bec9254417ef7a3faf687478fe5424ab378 which split RES_LR_SPACE into (mainly) three pieces. The regression caused paragraphs in textboxes (and anything else that ends up in EditEng) to lose left and right paragraph indents. Accidentally, that regression fixed indents for comments, since MSO ignores them for DOC format, so I made sure that these properties were not passed to commments. make CppunitTest_sw_ww8export4 \ CPPUNIT_TEST_NAME=testTdf72511_editengLRSpace Change-Id: I95121e4b32193701af3e1d77ba92c36aca7f16cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167651 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/extras/ww8export/data/tdf72511_editengLRSpace.doc b/sw/qa/extras/ww8export/data/tdf72511_editengLRSpace.doc new file mode 100644 index 000000000000..adf12e9f6b58 Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf72511_editengLRSpace.doc differ diff --git a/sw/qa/extras/ww8export/ww8export4.cxx b/sw/qa/extras/ww8export/ww8export4.cxx index 6caffceffa00..b52e2b8f77f1 100644 --- a/sw/qa/extras/ww8export/ww8export4.cxx +++ b/sw/qa/extras/ww8export/ww8export4.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextFrame.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <comphelper/sequenceashashmap.hxx> @@ -54,6 +55,28 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf77964) CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, getProperty<text::TextContentAnchorType>(getShapeByName(u"Image2"), "AnchorType")); } +DECLARE_WW8EXPORT_TEST(testTdf72511_editengLRSpace, "tdf72511_editengLRSpace.doc") +{ + // given a default paragraph style with a left indent of 2 inches, + // the comment should ignore the indent, but the textbox must not. + uno::Reference<beans::XPropertySet> xRun( + getProperty<uno::Reference<beans::XPropertySet>>(getRun(getParagraph(1), 3), "TextField")); + uno::Reference<text::XText> xComment(getProperty<uno::Reference<text::XText>>(xRun, "TextRange")); + uno::Reference<beans::XPropertySet> xParagraph(getParagraphOfText(1, xComment), uno::UNO_QUERY); + // The comment was indented by 4001 (2 inches) instead of nothing + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xParagraph, "ParaLeftMargin")); + + uno::Reference<drawing::XShapes> xGroupShape(getShape(1), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape2(xGroupShape->getByIndex(1), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShape2->getShapeType()); + uno::Reference<text::XTextRange> xTextbox(xShape2, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xTBPara(xTextbox, uno::UNO_QUERY); + // Textbox paragraphs had no indent instead of 5080 (2 inches - the same as normal paragraphs). + CPPUNIT_ASSERT_EQUAL(sal_Int32(5080), getProperty<sal_Int32>(xTBPara, "ParaLeftMargin")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("sanity check: normal paragraph's indent", sal_Int32(5080), + getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin")); +} + DECLARE_WW8EXPORT_TEST(testTdf160049_anchorMargin, "tdf160049_anchorMargin.doc") { // given a document with a LEFT "column/text" anchored image diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index 28b1211683d1..a0209e002d8e 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -68,6 +68,7 @@ #include <editeng/frmdiritem.hxx> #include <svx/xfltrit.hxx> #include <filter/msfilter/msdffimp.hxx> +#include <frmatr.hxx> #include <grfatr.hxx> #include <fmtornt.hxx> #include <fmtcntnt.hxx> @@ -495,7 +496,7 @@ static ESelection GetESelection(EditEngine const &rDrawEditEngine, tools::Long n // Which-IDs are changed according to the aDstTab table so that the // EditEngine will not ignore them. // Both Paragraph and character attributes are stuffed into the ItemSet. -void SwWW8ImplReader::InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl ) +void SwWW8ImplReader::InsertTxbxStyAttrs(SfxItemSet& rS, sal_uInt16 nColl, ManTypes eType) { SwWW8StyInf * pStyInf = GetStyle(nColl); if( !(pStyInf != nullptr && pStyInf->m_pFormat && pStyInf->m_bColl) ) @@ -512,7 +513,30 @@ void SwWW8ImplReader::InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl ) SfxItemPool *pEditPool = rS.GetPool(); sal_uInt16 nWhich = i; sal_uInt16 nSlotId = m_rDoc.GetAttrPool().GetSlotId(nWhich); - if ( + + if (nWhich == RES_MARGIN_FIRSTLINE || nWhich == RES_MARGIN_TEXTLEFT + || nWhich == RES_MARGIN_RIGHT) + { + // MSO ignores paragraph indents for comments in DOC format + if (eType == MAN_AND) + continue; + + if (SfxItemState::SET == rS.GetItemState(EE_PARA_LRSPACE, false)) + continue; + + // LO7.6 split SW RES_LR_SPACE into three pieces, + // but EditEng still uses the combined SvxLRSpaceItem, so recombine + assert(!pEditPool->GetTrueWhichIDFromSlotID(nSlotId) + && "unnecessary when EditEng learns about the separate pieces"); + + SvxLRSpaceItem aLR(rS.Get(EE_PARA_LRSPACE)); + aLR.SetTextFirstLineOffset( + pStyInf->m_pFormat->GetFirstLineIndent().GetTextFirstLineOffset()); + aLR.SetTextLeft(pStyInf->m_pFormat->GetTextLeftMargin().GetTextLeft()); + aLR.SetRight(pStyInf->m_pFormat->GetRightMargin().GetRight()); + rS.Put(aLR); + } + else if ( nSlotId && nWhich != nSlotId && 0 != (nWhich = pEditPool->GetWhichIDFromSlotID(nSlotId)) && nWhich != nSlotId && @@ -739,6 +763,37 @@ void SwWW8ImplReader::InsertAttrsAsDrawingAttrs(WW8_CP nStartCp, WW8_CP nEndCp, Color aColor(static_cast<const SvxBrushItem*>(pItem)->GetColor()); pS->Put(SvxColorItem(aColor, EE_CHAR_BKGCOLOR)); } + else if (nWhich == RES_MARGIN_FIRSTLINE || nWhich == RES_MARGIN_TEXTLEFT + || nWhich == RES_MARGIN_RIGHT) + { + // MSO ignores paragraph indents for comments in DOC format + if (eType == MAN_AND) + continue; + + // LO7.6 split SW RES_LR_SPACE into three pieces, + // but EE still uses the combined SvxLRSpaceItem, so recombine + assert(!pEditPool->GetTrueWhichIDFromSlotID(nSlotId) + && "unnecessary when EditEng learns about the separate pieces"); + + SvxLRSpaceItem aLR(pS->Get(EE_PARA_LRSPACE)); + if (nWhich == RES_MARGIN_FIRSTLINE) + { + aLR.SetTextFirstLineOffset( + static_cast<const SvxFirstLineIndentItem*>(pItem) + ->GetTextFirstLineOffset()); + } + else if (nWhich == RES_MARGIN_TEXTLEFT) + { + aLR.SetTextLeft(static_cast<const SvxTextLeftMarginItem*>(pItem) + ->GetTextLeft()); + } + else + { + aLR.SetRight( + static_cast<const SvxRightMarginItem*>(pItem)->GetRight()); + } + pS->Put(aLR); + } else if ( nSlotId && nWhich != nSlotId && 0 != (nWhich = pEditPool->GetWhichIDFromSlotID(nSlotId)) && @@ -751,7 +806,7 @@ void SwWW8ImplReader::InsertAttrsAsDrawingAttrs(WW8_CP nStartCp, WW8_CP nEndCp, } } // Fill in the remainder from the style - InsertTxbxStyAttrs(*pS, m_nCurrentColl); + InsertTxbxStyAttrs(*pS, m_nCurrentColl, eType); if( pS->Count() ) { diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index 6f0c260f1966..e8cb99c29fea 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1628,7 +1628,7 @@ private: rtl::Reference<SdrObject> ReadEllipse(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet); rtl::Reference<SdrObject> ReadArc(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet); rtl::Reference<SdrObject> ReadPolyLine(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet); - void InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl ); + void InsertTxbxStyAttrs(SfxItemSet& rS, sal_uInt16 nColl, ManTypes eType); void InsertAttrsAsDrawingAttrs(WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType, bool bONLYnPicLocFc=false); bool GetTxbxTextSttEndCp(WW8_CP& rStartCp, WW8_CP& rEndCp, sal_uInt16 nTxBxS,