From d9809c68f62af3b594854b142e1db5171804158d Mon Sep 17 00:00:00 2001 From: Tushar Bende Date: Mon, 3 Feb 2014 16:44:08 +0530 Subject: fdo#74141 :In Right margin gets added even if not present in orig doc. There was a problem that in style.xml and document.xml in tag "right" & "left" margin attributes gets added(w:right=0 & w:left=0),if these attributes are not set in original document. (In this case LO should not write these attributes in ) eg. if original doc has implicit right and left indentation values set(In style.xml) and there is no explicit values provided for some para (In document.xml) still it used to write w:right=0 and w:left=0 in tag of document.xml which overrides an entry from style.xml. XML difference : - Original file: - Roundtrip file Before Fix: - Roundtrip file After Fix: Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Reviewed on: https://gerrit.libreoffice.org/7816 Change-Id: Ifa01bae24d48bb38d5e255356247c46a43beefcc --- editeng/source/items/frmitems.cxx | 12 +++++++++--- include/editeng/lrspitem.hxx | 17 +++++++++++++++++ sw/qa/extras/ooxmlexport/data/test_indentation.docx | Bin 0 -> 12896 bytes sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 12 ++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 12 ++++++++---- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/test_indentation.docx diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index 6eb012ad26e0..7f2cf425d51a 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -420,7 +420,9 @@ SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) : nPropFirstLineOfst( 100 ), nPropLeftMargin( 100 ), nPropRightMargin( 100 ), - bAutoFirst ( 0 ) + bAutoFirst ( 0 ), + bExplicitZeroMarginValRight(sal_False), + bExplicitZeroMarginValLeft(sal_False) { } @@ -439,7 +441,9 @@ SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft, const long nRight, nPropFirstLineOfst( 100 ), nPropLeftMargin( 100 ), nPropRightMargin( 100 ), - bAutoFirst ( 0 ) + bAutoFirst ( 0 ), + bExplicitZeroMarginValRight(sal_False), + bExplicitZeroMarginValLeft(sal_False) { } @@ -574,7 +578,9 @@ bool SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) const nPropFirstLineOfst == rOther.GetPropTxtFirstLineOfst() && nPropLeftMargin == rOther.GetPropLeft() && nPropRightMargin == rOther.GetPropRight() && - bAutoFirst == rOther.IsAutoFirst() ); + bAutoFirst == rOther.IsAutoFirst() && + bExplicitZeroMarginValRight == rOther.IsExplicitZeroMarginValRight() && + bExplicitZeroMarginValLeft == rOther.IsExplicitZeroMarginValLeft() ); } // ----------------------------------------------------------------------- diff --git a/include/editeng/lrspitem.hxx b/include/editeng/lrspitem.hxx index d56b26831bc9..a18b4ea8138f 100644 --- a/include/editeng/lrspitem.hxx +++ b/include/editeng/lrspitem.hxx @@ -57,10 +57,13 @@ class EDITENG_DLLPUBLIC SvxLRSpaceItem : public SfxPoolItem sal_uInt16 nPropFirstLineOfst, nPropLeftMargin, nPropRightMargin; sal_Bool bAutoFirst : 1; // Automatic calculation of the first line indent + sal_Bool bExplicitZeroMarginValRight; + sal_Bool bExplicitZeroMarginValLeft; void AdjustLeft(); // nLeftMargin and nTxtLeft are being adjusted. public: + TYPEINFO(); explicit SvxLRSpaceItem( const sal_uInt16 nId ); @@ -99,6 +102,10 @@ public: inline sal_Bool IsAutoFirst() const { return bAutoFirst; } inline void SetAutoFirst( const sal_Bool bNew ) { bAutoFirst = bNew; } + inline sal_Bool IsExplicitZeroMarginValRight() const { return bExplicitZeroMarginValRight; } + inline sal_Bool IsExplicitZeroMarginValLeft() const { return bExplicitZeroMarginValLeft; } + inline void SetExplicitZeroMarginValRight( const sal_Bool eR ) { bExplicitZeroMarginValRight = eR; } + inline void SetExplicitZeroMarginValLeft( const sal_Bool eL ) { bExplicitZeroMarginValLeft = eL; } // Query/Setting the percentage values inline void SetPropLeft( const sal_uInt16 nProp = 100 ) { nPropLeftMargin = nProp; } @@ -131,6 +138,8 @@ inline SvxLRSpaceItem &SvxLRSpaceItem::operator=( const SvxLRSpaceItem &rCpy ) nPropLeftMargin = rCpy.nPropLeftMargin; nPropRightMargin = rCpy.nPropRightMargin; bAutoFirst = rCpy.bAutoFirst; + bExplicitZeroMarginValRight = rCpy.bExplicitZeroMarginValRight; + bExplicitZeroMarginValLeft = rCpy.bExplicitZeroMarginValLeft; return *this; } @@ -142,6 +151,10 @@ inline void SvxLRSpaceItem::SetLeft( const long nL, const sal_uInt16 nProp ) } inline void SvxLRSpaceItem::SetRight( const long nR, const sal_uInt16 nProp ) { + if (0 == nR) + { + SetExplicitZeroMarginValRight(sal_True); + } nRightMargin = (nR * nProp) / 100; nPropRightMargin = nProp; } @@ -155,6 +168,10 @@ inline void SvxLRSpaceItem::SetTxtFirstLineOfst( const short nF, inline void SvxLRSpaceItem::SetTxtLeft( const long nL, const sal_uInt16 nProp ) { + if (0 == nL) + { + SetExplicitZeroMarginValLeft(sal_True); + } nTxtLeft = (nL * nProp) / 100; nPropLeftMargin = nProp; AdjustLeft(); diff --git a/sw/qa/extras/ooxmlexport/data/test_indentation.docx b/sw/qa/extras/ooxmlexport/data/test_indentation.docx new file mode 100644 index 000000000000..b39e06658416 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/test_indentation.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 4c437bac178a..79e0bacc8bb7 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -3114,6 +3114,18 @@ DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillPattern, "dml-shape-fillpattern.docx") CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aHatch.Distance); CPPUNIT_ASSERT_EQUAL(drawing::HatchStyle_DOUBLE, aHatch.Style); } + +DECLARE_OOXMLEXPORT_TEST(testIndentation, "test_indentation.docx") +{ + // fdo#74141 :There was a problem that in style.xml and document.xml in tag "right" & "left" margin + // attributes gets added(w:right=0 & w:left=0) if these attributes are not set in original document. + // This test is to verify does not contain w:right attribute. + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:ind", "end", ""); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 188429402269..5f6fed317953 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5424,10 +5424,14 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace ) else { FastAttributeList *pLRSpaceAttrList = m_pSerializer->createAttrList(); - - pLRSpaceAttrList->add( FSNS( XML_w, ( bEcma ? XML_left : XML_start ) ), OString::number( rLRSpace.GetTxtLeft() ) ); - pLRSpaceAttrList->add( FSNS( XML_w, ( bEcma ? XML_right : XML_end ) ), OString::number( rLRSpace.GetRight() ) ); - + if((0 != rLRSpace.GetTxtLeft()) || ((0 == rLRSpace.GetTxtLeft()) && (sal_True == rLRSpace.IsExplicitZeroMarginValLeft()))) + { + pLRSpaceAttrList->add( FSNS( XML_w, ( bEcma ? XML_left : XML_start ) ), OString::number( rLRSpace.GetTxtLeft() ) ); + } + if((0 != rLRSpace.GetRight()) || ((0 == rLRSpace.GetRight()) && (sal_True == rLRSpace.IsExplicitZeroMarginValRight()))) + { + pLRSpaceAttrList->add( FSNS( XML_w, ( bEcma ? XML_right : XML_end ) ), OString::number( rLRSpace.GetRight() ) ); + } sal_Int32 nFirstLineAdjustment = rLRSpace.GetTxtFirstLineOfst(); if (nFirstLineAdjustment > 0) pLRSpaceAttrList->add( FSNS( XML_w, XML_firstLine ), OString::number( nFirstLineAdjustment ) ); -- cgit v1.2.3