[PATCH] fdo#65257 : DOCX not exporting background color

Adam CloudOn (via Code Review) gerrit at gerrit.libreoffice.org
Sun Jun 2 01:22:04 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/4130

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/30/4130/1

fdo#65257 : DOCX not exporting background color

Change-Id: Ida3f66d5adb063400494e1da589a463b4d7c2a86
---
A sw/qa/extras/ooxmlexport/data/page-background.docx
M sw/qa/extras/ooxmlexport/ooxmlexport.cxx
M sw/source/filter/ww8/docxexport.cxx
3 files changed, 34 insertions(+), 0 deletions(-)



diff --git a/sw/qa/extras/ooxmlexport/data/page-background.docx b/sw/qa/extras/ooxmlexport/data/page-background.docx
new file mode 100644
index 0000000..8c1f2ebd
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/page-background.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 8dc69f2..a816854 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -69,6 +69,7 @@
     void testMathLiteral();
     void testFdo48557();
     void testI120928();
+    void testPageBackground();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -116,6 +117,7 @@
         {"math-literal.docx", &Test::testMathLiteral},
         {"fdo48557.odt", &Test::testFdo48557},
         {"i120928.docx", &Test::testI120928},
+        {"page-background.docx", &Test::testPageBackground},
     };
     // Don't test the first import of these, for some reason those tests fail
     const char* aBlacklist[] = {
@@ -672,6 +674,13 @@
     CPPUNIT_ASSERT_EQUAL(true, bIsGraphic);
 }
 
+void Test::testPageBackground()
+{
+    // 'Document Background' wasn't exported.
+    uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty<sal_Int32>(xPageStyle, "BackColor"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index ca46cae..5de892e 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -44,6 +44,7 @@
 #include <frmfmt.hxx>
 #include <section.hxx>
 #include <ftninfo.hxx>
+#include <pagedesc.hxx>
 
 #include <editeng/editobj.hxx>
 #include <editeng/outlobj.hxx>
@@ -687,6 +688,16 @@
     OString aZoom(OString::valueOf(sal_Int32(pViewShell->GetViewOptions()->GetZoom())));
     pFS->singleElementNS(XML_w, XML_zoom, FSNS(XML_w, XML_percent), aZoom.getStr(), FSEND);
 
+    // Display Background Shape
+    const SwFrmFmt &rFmt = pDoc->GetPageDesc(0).GetMaster();
+    const SfxPoolItem* pItem = 0;
+    SfxItemState eState = rFmt.GetItemState(RES_BACKGROUND, true, &pItem);
+    if (SFX_ITEM_SET == eState && pItem)
+    {
+        // Turn on the 'displayBackgroundShape'
+        pFS->singleElementNS( XML_w, XML_displayBackgroundShape, FSEND );
+    }
+
     // Track Changes
     if ( settings.trackRevisions )
         pFS->singleElementNS( XML_w, XML_trackRevisions, FSEND );
@@ -729,6 +740,20 @@
     // setup the namespaces
     m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces( m_pDocumentFS ));
 
+    // Write background page color
+    const SwFrmFmt &rFmt = pDoc->GetPageDesc(0).GetMaster();
+    const SfxPoolItem* pItem = 0;
+    SfxItemState eState = rFmt.GetItemState(RES_BACKGROUND, true, &pItem);
+    if (SFX_ITEM_SET == eState && pItem)
+    {
+        // The 'color' is set for the first page style - take it and use it as the background color of the entire DOCX
+        const SvxBrushItem* pBrush = (const SvxBrushItem*)pItem;
+        Color backgroundColor = pBrush->GetColor();
+        OString aBackgroundColorStr = msfilter::util::ConvertColor(backgroundColor);
+
+        m_pDocumentFS->singleElementNS( XML_w, XML_background, FSNS( XML_w, XML_color ), aBackgroundColorStr, FSEND );
+    }
+
     // body
     m_pDocumentFS->startElementNS( XML_w, XML_body, FSEND );
 

-- 
To view, visit https://gerrit.libreoffice.org/4130
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida3f66d5adb063400494e1da589a463b4d7c2a86
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Adam CloudOn <rattles2013 at gmail.com>



More information about the LibreOffice mailing list