sw/qa/extras/ooxmlexport/data/theme-preservation.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx              |    3 +
 sw/source/filter/ww8/docxattributeoutput.cxx          |   53 ++++++++++++++++--
 sw/source/filter/ww8/docxattributeoutput.hxx          |    2 
 writerfilter/source/dmapper/CellColorHandler.cxx      |   11 +++
 writerfilter/source/dmapper/CellColorHandler.hxx      |    2 
 writerfilter/source/dmapper/DomainMapper.cxx          |    8 ++
 writerfilter/source/dmapper/PropertyIds.cxx           |    1 
 writerfilter/source/dmapper/PropertyIds.hxx           |    1 
 9 files changed, 77 insertions(+), 4 deletions(-)

New commits:
commit 128aeab30eb768ea11d88a24139284b6901cf60c
Author: Jacobo Aragunde Pérez <jaragu...@igalia.com>
Date:   Sun Dec 22 18:55:43 2013 +0100

    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

diff --git a/sw/qa/extras/ooxmlexport/data/theme-preservation.docx 
b/sw/qa/extras/ooxmlexport/data/theme-preservation.docx
index ff7c570..778e106 100644
Binary files a/sw/qa/extras/ooxmlexport/data/theme-preservation.docx and 
b/sw/qa/extras/ooxmlexport/data/theme-preservation.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index fce4547..11d962a 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 7daf788..29a6cd4 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 62ec9f4..a2a3977 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;
 
diff --git a/writerfilter/source/dmapper/CellColorHandler.cxx 
b/writerfilter/source/dmapper/CellColorHandler.cxx
index da8c9cb..4204b5b 100644
--- a/writerfilter/source/dmapper/CellColorHandler.cxx
+++ b/writerfilter/source/dmapper/CellColorHandler.cxx
@@ -359,6 +359,17 @@ beans::PropertyValue CellColorHandler::getInteropGrabBag()
     return aRet;
 }
 
+void CellColorHandler::disableInteropGrabBag()
+{
+    m_aInteropGrabBagName = "";
+    m_aInteropGrabBag.clear();
+}
+
+sal_Bool CellColorHandler::isInteropGrabBagEnabled()
+{
+    return !(m_aInteropGrabBagName.isEmpty());
+}
+
 } //namespace dmapper
 } //namespace writerfilter
 
diff --git a/writerfilter/source/dmapper/CellColorHandler.hxx 
b/writerfilter/source/dmapper/CellColorHandler.hxx
index 7904a9d..e3e1c0b 100644
--- a/writerfilter/source/dmapper/CellColorHandler.hxx
+++ b/writerfilter/source/dmapper/CellColorHandler.hxx
@@ -58,6 +58,8 @@ public:
 
     void enableInteropGrabBag(OUString aName);
     beans::PropertyValue getInteropGrabBag();
+    void disableInteropGrabBag();
+    sal_Bool isInteropGrabBagEnabled();
 };
 typedef boost::shared_ptr< CellColorHandler >          CellColorHandlerPtr;
 }}
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index bc5d2bf..5e151e6 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1961,8 +1961,16 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, 
PropertyMapPtr rContext, SprmType
         {
             CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
             pCellColorHandler->setOutputFormat( CellColorHandler::Paragraph );
+            sal_Bool bEnableTempGrabBag = 
!pCellColorHandler->isInteropGrabBagEnabled();
+            if( bEnableTempGrabBag )
+                pCellColorHandler->enableInteropGrabBag( "TempShdPropsGrabBag" 
);
+
             pProperties->resolve(*pCellColorHandler);
             rContext->InsertProps(pCellColorHandler->getProperties());
+
+            rContext->Insert(PROP_CHAR_THEME_FILL,  
pCellColorHandler->getInteropGrabBag().Value, true, PARA_GRAB_BAG);
+            if(bEnableTempGrabBag)
+                pCellColorHandler->disableInteropGrabBag();
         }
     }
     break;
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx 
b/writerfilter/source/dmapper/PropertyIds.cxx
index a0c9dc4..a05249a 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -358,6 +358,7 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) 
const
             case PROP_CHAR_THEME_COLOR              :   sName = 
"CharThemeColor"; break;
             case PROP_CHAR_THEME_ORIGINAL_COLOR     :   sName = 
"CharThemeOriginalColor"; break;
             case PROP_CHAR_THEME_COLOR_SHADE        :   sName = 
"CharThemeColorShade"; break;
+            case PROP_CHAR_THEME_FILL               :   sName = 
"CharThemeFill"; break;
         }
         ::std::pair<PropertyNameMap_t::iterator,bool> aInsertIt =
                 m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, 
sName ));
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx 
b/writerfilter/source/dmapper/PropertyIds.hxx
index e9ad035..ae3e02a 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -329,6 +329,7 @@ enum PropertyIds
         ,PROP_CHAR_THEME_COLOR
         ,PROP_CHAR_THEME_ORIGINAL_COLOR
         ,PROP_CHAR_THEME_COLOR_SHADE
+        ,PROP_CHAR_THEME_FILL
     };
 struct PropertyNameSupplier_Impl;
 class PropertyNameSupplier
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to