From f2f2143316acb449baaf29dd5300a6acf8a5c632 Mon Sep 17 00:00:00 2001 From: Serge Krot Date: Fri, 16 Nov 2018 09:53:37 +0100 Subject: tdf#121456: sw: DOCX: tabs export and TABS_RELATIVE_TO_INDENT prop In DOCX, w:pos specifies the position of the current custom tab stop with respect to the current page margins. But in ODT, zero position could be page margins or paragraph indent according to used settings DocumentSettingId::TABS_RELATIVE_TO_INDENT Added new unit test. Change-Id: Ic56a8527380b6562f4239df1edce0c9b4649af24 Reviewed-on: https://gerrit.libreoffice.org/63460 Tested-by: Jenkins Reviewed-by: Thorsten Behrens Tested-by: Thorsten Behrens --- .../extras/ooxmlexport/data/tdf121456_tabsOffset.odt | Bin 0 -> 14208 bytes sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 11 +++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 sw/qa/extras/ooxmlexport/data/tdf121456_tabsOffset.odt diff --git a/sw/qa/extras/ooxmlexport/data/tdf121456_tabsOffset.odt b/sw/qa/extras/ooxmlexport/data/tdf121456_tabsOffset.odt new file mode 100755 index 000000000000..ff8d5400950b Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf121456_tabsOffset.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 40e9fb19c3ca..2728c75b51be 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -120,6 +120,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs2, "tdf63561_clearTabs2.docx") CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty< uno::Sequence >(getParagraph(4), "ParaTabStops").getLength()); } +DECLARE_OOXMLEXPORT_TEST(testTdf121456_tabsOffset, "tdf121456_tabsOffset.odt") +{ + for (int i=2; i<8; i++) + { + uno::Sequence< style::TabStop > stops = getProperty< uno::Sequence >(getParagraph( i ), "ParaTabStops"); + CPPUNIT_ASSERT_EQUAL( sal_Int32(1), stops.getLength()); + CPPUNIT_ASSERT_EQUAL( css::style::TabAlign_RIGHT, stops[ 0 ].Alignment ); + CPPUNIT_ASSERT_EQUAL( sal_Int32(17000), stops[ 0 ].Position ); + } +} + DECLARE_OOXMLEXPORT_TEST(testTdf106174_rtlParaAlign, "tdf106174_rtlParaAlign.docx") { CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER), getProperty(getParagraph(1), "ParaAdjust")); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 241c22221e1b..c576fec3ec09 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -7707,7 +7707,7 @@ void DocxAttributeOutput::ParaWidows( const SvxWidowsItem& rWidows ) } static void impl_WriteTabElement( FSHelperPtr const & pSerializer, - const SvxTabStop& rTab ) + const SvxTabStop& rTab, long tabsOffset ) { FastAttributeList *pTabElementAttrList = FastSerializerHelper::createAttrList(); @@ -7729,9 +7729,11 @@ static void impl_WriteTabElement( FSHelperPtr const & pSerializer, break; } - // Because GetTabPos already includes indent, we don't need to add nCurrentLeft (CurrentLeft is indentation information) - //pTabElementAttrList->add( FSNS( XML_w, XML_pos ), OString::valueOf( rTab.GetTabPos() + nCurrentLeft ) ); - pTabElementAttrList->add( FSNS( XML_w, XML_pos ), OString::number( rTab.GetTabPos() ) ); + // Write position according to used offset of the whole paragraph. + // In DOCX, w:pos specifies the position of the current custom tab stop with respect to the current page margins. + // But in ODT, zero position could be page margins or paragraph indent according to used settings. + // This is handled outside of this method and provided for us in tabsOffset parameter. + pTabElementAttrList->add( FSNS( XML_w, XML_pos ), OString::number( rTab.GetTabPos() + tabsOffset ) ); sal_Unicode cFillChar = rTab.GetFill(); @@ -7770,6 +7772,13 @@ void DocxAttributeOutput::ParaTabStop( const SvxTabStopItem& rTabStop ) m_pSerializer->startElementNS( XML_w, XML_tabs, FSEND ); + // Get offset for tabs + // In DOCX, w:pos specifies the position of the current custom tab stop with respect to the current page margins. + // But in ODT, zero position could be page margins or paragraph indent according to used settings. + long tabsOffset = 0; + if (m_rExport.m_pDoc->getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT)) + tabsOffset = m_rExport.GetItem(RES_LR_SPACE).GetTextLeft(); + // clear unused inherited tabs - otherwise the style will add them back in sal_Int32 nCurrTab = 0; for ( sal_uInt16 i = 0; i < nInheritedTabCount; ++i ) @@ -7789,7 +7798,7 @@ void DocxAttributeOutput::ParaTabStop( const SvxTabStopItem& rTabStop ) for (sal_uInt16 i = 0; i < nCount; i++ ) { if( rTabStop[i].GetAdjustment() != SvxTabAdjust::Default ) - impl_WriteTabElement( m_pSerializer, rTabStop[i] ); + impl_WriteTabElement( m_pSerializer, rTabStop[i], tabsOffset ); else GetExport().setDefaultTabStop( rTabStop[i].GetTabPos()); } -- cgit v1.2.3