diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2013-12-17 13:19:16 +0100 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2013-12-17 19:51:18 +0100 |
commit | 3d126bcf1febe68919eab42c5cd2cd0d7db2f66b (patch) | |
tree | 88cd02dbb06a9a18428139becd1288c74001be0b /sw | |
parent | 79aecccf048f98a187065fdfabbc911b0e499cdc (diff) |
ooxml: preserve font theme color property
The property is called w:themeColor and it belongs to the w:color tag
inside run properties.
On import, the themeColor prop is stored in the character interop
grab bag together with the val prop.
On export, the current color of a text run is compared with the
stored val prop to know if the color has been changed during the
document edition. If it hasn't changed, the themeColor property
must be written to the document; if it has, it must not be written to
avoid overwriting the new color.
Also added a unit test for this property.
Change-Id: Icc95ee023aecc741adcba23d23206aadd6c30e1f
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 36 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 |
3 files changed, 38 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 8759f618f743..9cbaaf638e5c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -2060,6 +2060,9 @@ DECLARE_OOXMLEXPORT_TEST(testThemePreservation, "theme-preservation.docx") assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:r[1]/w:rPr/w:rFonts", "hAnsiTheme", "majorHAnsi"); assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:r[1]/w:rPr/w:rFonts", "asciiTheme", "majorHAnsi"); + // check theme font color value has been preserved + assertXPath(pXmlDocument, "/w:document/w:body/w:p[4]/w:r[1]/w:rPr/w:color", "themeColor", "accent3"); + // check the themeFontLang values in settings file xmlDocPtr pXmlSettings = parseExport("word/settings.xml"); if (!pXmlSettings) diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 8e5ebbbfbb8d..7d32238467a6 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1234,6 +1234,14 @@ void DocxAttributeOutput::WriteCollectedRunProperties() m_pSerializer->singleElementNS( XML_w, XML_rFonts, xAttrList ); } + if ( m_pColorAttrList ) + { + XFastAttributeListRef xAttrList( m_pColorAttrList ); + m_pColorAttrList = NULL; + + m_pSerializer->singleElementNS( XML_w, XML_color, xAttrList ); + } + if ( m_pEastAsianLayoutAttrList ) { XFastAttributeListRef xAttrList( m_pEastAsianLayoutAttrList ); @@ -3490,6 +3498,7 @@ void DocxAttributeOutput::WriteOutliner(const OutlinerParaObject& rParaObj) // Write run properties. m_pSerializer->startElementNS(XML_w, XML_rPr, FSEND); aAttrIter.OutAttr(nAktPos); + WriteCollectedRunProperties(); m_pSerializer->endElementNS(XML_w, XML_rPr); bool bTxtAtr = aAttrIter.IsTxtAttr( nAktPos ); @@ -4342,8 +4351,10 @@ void DocxAttributeOutput::CharColor( const SvxColorItem& rColor ) aColorString = msfilter::util::ConvertColor( aColor ); - m_pSerializer->singleElementNS( XML_w, XML_color, - FSNS( XML_w, XML_val ), aColorString.getStr(), FSEND ); + if( !m_pColorAttrList ) + m_pColorAttrList = m_pSerializer->createAttrList(); + + m_pColorAttrList->add( FSNS( XML_w, XML_val ), aColorString.getStr() ); } void DocxAttributeOutput::CharContour( const SvxContourItem& rContour ) @@ -6128,6 +6139,7 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) sal_Bool bWriteCSTheme = sal_True; sal_Bool bWriteAsciiTheme = sal_True; sal_Bool bWriteEastAsiaTheme = sal_True; + sal_Bool bWriteThemeFontColor = sal_True; OUString sOriginalValue; for ( std::map< OUString, com::sun::star::uno::Any >::const_iterator i = rMap.begin(); i != rMap.end(); i++ ) { @@ -6149,6 +6161,12 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) bWriteEastAsiaTheme = ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, XML_eastAsia ) ) == sOriginalValue ); } + else if ( m_pColorAttrList && i->first == "CharThemeOriginalColor" ) + { + if ( i->second >>= sOriginalValue ) + bWriteThemeFontColor = + ( m_pColorAttrList->getOptionalValue( FSNS( XML_w, XML_val ) ) == sOriginalValue ); + } } // save theme attributes back to the run properties @@ -6189,9 +6207,19 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) m_pFontsAttrList->add( FSNS( XML_w, XML_hAnsiTheme ), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) ); } + else if ( i->first == "CharThemeColor" && bWriteThemeFontColor ) + { + i->second >>= str; + if( !m_pColorAttrList ) + m_pColorAttrList = m_pSerializer->createAttrList(); + + m_pColorAttrList->add( FSNS( XML_w, XML_themeColor ), + OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) ); + } else if( i->first == "CharThemeFontNameCs" || i->first == "CharThemeFontNameAscii" || - i->first == "CharThemeFontNameEastAsia" ) + i->first == "CharThemeFontNameEastAsia" || + i->first == "CharThemeOriginalColor" ) { // just skip these, they were processed before } @@ -6214,6 +6242,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri m_pFlyFillAttrList( NULL ), m_pFlyWrapAttrList( NULL ), m_pTextboxAttrList( NULL ), + m_pColorAttrList( NULL ), m_pFlyFrameSize(0), m_pFootnotesList( new ::docx::FootnotesList() ), m_pEndnotesList( new ::docx::FootnotesList() ), @@ -6269,6 +6298,7 @@ DocxAttributeOutput::~DocxAttributeOutput() delete m_pHyperlinkAttrList, m_pHyperlinkAttrList = NULL; delete m_pFlyAttrList, m_pFlyAttrList = NULL; delete m_pTextboxAttrList, m_pTextboxAttrList = NULL; + delete m_pColorAttrList, m_pColorAttrList = 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 08ff82c47674..99bb35ca4ea3 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -682,6 +682,8 @@ private: ::sax_fastparser::FastAttributeList *m_pFlyWrapAttrList; /// Attributes of the next v:textbox element. ::sax_fastparser::FastAttributeList *m_pTextboxAttrList; + /// Attributes of the run color + ::sax_fastparser::FastAttributeList *m_pColorAttrList; /// When exporting fly frames, this holds the real size of the frame. const Size* m_pFlyFrameSize; |