diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2013-12-22 18:55:43 +0100 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2013-12-22 19:02:23 +0100 |
commit | 128aeab30eb768ea11d88a24139284b6901cf60c (patch) | |
tree | 75c8c281ed48418a5b70ab6d92d1e67442ce6ab3 /sw | |
parent | 151887a9550efed41c5a2709a4f56d768b441ce4 (diff) |
ooxml: Preserve paragraph theme fill attribute
The theme fill attribute and the original fill color are saved to the
paragraph grab bag during the import.
On export, the original fill color and the current one are compared
to know if the user has changed the fill color during the edition. In
that case, the theme fill attribute and the original color are
dropped.
Some methods related to the grab bag management were added to
CellColorHandler for convenience.
Added a unit test for this attribute.
Change-Id: Ic0514ce1d2f290fb0aef5ed86327c1f03f31f20c
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/theme-preservation.docx | bin | 14739 -> 14798 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 53 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 |
4 files changed, 54 insertions, 4 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/theme-preservation.docx b/sw/qa/extras/ooxmlexport/data/theme-preservation.docx Binary files differindex ff7c5700c965..778e10646ed3 100644 --- a/sw/qa/extras/ooxmlexport/data/theme-preservation.docx +++ b/sw/qa/extras/ooxmlexport/data/theme-preservation.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index fce454751a76..11d962aa97f0 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -2092,6 +2092,9 @@ DECLARE_OOXMLEXPORT_TEST(testThemePreservation, "theme-preservation.docx") getProperty<OUString>(getRun(getParagraph(4, "Direct format font"), 1), "CharFontName")); CPPUNIT_ASSERT_EQUAL(OUString("Trebuchet MS"), getProperty<OUString>(getParagraph(5, "Major theme font"), "CharFontName")); + + // check the paragraph background theme color has been preserved + assertXPath(pXmlDocument, "/w:document/w:body/w:p[6]/w:pPr/w:shd", "themeFill", "text2"); } DECLARE_OOXMLEXPORT_TEST(testcantSplit, "2_table_doc.docx") diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 7daf7888fddc..29a6cd45b84d 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -694,6 +694,14 @@ void DocxAttributeOutput::WriteCollectedParagraphProperties() m_pSerializer->singleElementNS( XML_w, XML_spacing, xAttrList ); } + + if ( m_pBackgroundAttrList ) + { + XFastAttributeListRef xAttrList( m_pBackgroundAttrList ); + m_pBackgroundAttrList = NULL; + + m_pSerializer->singleElementNS( XML_w, XML_shd, xAttrList ); + } } void DocxAttributeOutput::EndParagraphProperties( const SwRedlineData* pRedlineData, const SwRedlineData* pRedlineParagraphMarkerDeleted, const SwRedlineData* pRedlineParagraphMarkerInserted ) @@ -5769,10 +5777,24 @@ void DocxAttributeOutput::FormatBackground( const SvxBrushItem& rBrush ) } else if ( !m_rExport.bOutPageDescs ) { - m_pSerializer->singleElementNS( XML_w, XML_shd, - FSNS( XML_w, XML_fill ), sColor.getStr( ), - FSNS( XML_w, XML_val ), "clear", - FSEND ); + if( !m_pBackgroundAttrList ) + m_pBackgroundAttrList = m_pSerializer->createAttrList(); + + // compare fill color with the original fill color + OString sOriginalFill = rtl::OUStringToOString( + m_pBackgroundAttrList->getOptionalValue( FSNS( XML_w, XML_fill ) ), RTL_TEXTENCODING_UTF8 ); + if( sOriginalFill.isEmpty() ) + { + m_pBackgroundAttrList->add( FSNS( XML_w, XML_fill ), sColor.getStr() ); + } + else if ( sOriginalFill != sColor ) + { + // fill was modified during edition, theme fill attribute must be dropped + delete m_pBackgroundAttrList; + m_pBackgroundAttrList = m_pSerializer->createAttrList(); + m_pBackgroundAttrList->add( FSNS( XML_w, XML_fill ), sColor.getStr() ); + } + m_pBackgroundAttrList->add( FSNS( XML_w, XML_val ), "clear" ); } } @@ -6109,6 +6131,27 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) m_nParaAfterSpacing = MM100_TO_TWIP(m_nParaAfterSpacing); SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: property =" << i->first << " : m_nParaBeforeSpacing= " << m_nParaAfterSpacing); } + else if (i->first == "CharThemeFill") + { + uno::Sequence<beans::PropertyValue> aGrabBagSeq; + i->second >>= aGrabBagSeq; + OUString sThemeFill, sOriginalFill; + for (sal_Int32 j=0; j < aGrabBagSeq.getLength(); ++j) + { + if (aGrabBagSeq[j].Name == "themeFill") + aGrabBagSeq[j].Value >>= sThemeFill; + else if (aGrabBagSeq[j].Name == "fill") + aGrabBagSeq[j].Value >>= sOriginalFill; + } + + if (!m_pBackgroundAttrList) + m_pBackgroundAttrList = m_pSerializer->createAttrList(); + + m_pBackgroundAttrList->add(FSNS(XML_w, XML_themeFill), + OUStringToOString(sThemeFill, RTL_TEXTENCODING_UTF8)); + m_pBackgroundAttrList->add(FSNS(XML_w, XML_fill), + OUStringToOString(sOriginalFill, RTL_TEXTENCODING_UTF8)); + } else SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled grab bag property " << i->first ); } @@ -6236,6 +6279,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri m_pFlyWrapAttrList( NULL ), m_pTextboxAttrList( NULL ), m_pColorAttrList( NULL ), + m_pBackgroundAttrList( NULL ), m_pFlyFrameSize(0), m_pFootnotesList( new ::docx::FootnotesList() ), m_pEndnotesList( new ::docx::FootnotesList() ), @@ -6293,6 +6337,7 @@ DocxAttributeOutput::~DocxAttributeOutput() delete m_pBodyPrAttrList, m_pBodyPrAttrList = NULL; delete m_pTextboxAttrList, m_pTextboxAttrList = NULL; delete m_pColorAttrList, m_pColorAttrList = NULL; + delete m_pBackgroundAttrList, m_pBackgroundAttrList = NULL; delete m_pFootnotesList, m_pFootnotesList = NULL; delete m_pEndnotesList, m_pEndnotesList = NULL; diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 62ec9f4b7c05..a2a39772cfea 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -686,6 +686,8 @@ private: ::sax_fastparser::FastAttributeList *m_pTextboxAttrList; /// Attributes of the run color ::sax_fastparser::FastAttributeList *m_pColorAttrList; + /// Attributes of the paragraph background + ::sax_fastparser::FastAttributeList *m_pBackgroundAttrList; /// When exporting fly frames, this holds the real size of the frame. const Size* m_pFlyFrameSize; |