sw/source/filter/ww8/docxexport.cxx |  100 +++++++++++++++++++-----------------
 sw/source/filter/ww8/docxexport.hxx |    3 +
 2 files changed, 56 insertions(+), 47 deletions(-)

New commits:
commit 2e073dc313cb2beaa7e4d2aef8584e7f76e9edee
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Mon Feb 26 14:24:14 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 27 08:44:16 2024 +0100

    address nit: create separate WriteDocumentBackgroundFill function
    
    Change-Id: I4e204dfee51987112f1a4a4a052a11349ae3f373
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163966
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index 787c90e32b12..f1331ce4141e 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1901,63 +1901,69 @@ bool DocxExport::isMirroredMargin()
     return bMirroredMargins;
 }
 
-void DocxExport::WriteMainText()
+void DocxExport::WriteDocumentBackgroundFill()
 {
-    // setup the namespaces
-    m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces());
+    const std::unique_ptr<SvxBrushItem> pBrush = getBackground();
+    if (!pBrush)
+        return;
 
-    // reset the incrementing linked-textboxes chain ID before re-saving.
-    m_nLinkedTextboxesChainId=0;
-    m_aLinkedTextboxesHelper.clear();
+    m_pDocumentFS->startElementNS(XML_w, XML_background, FSNS(XML_w, 
XML_color),
+                                  
msfilter::util::ConvertColor(pBrush->GetColor()));
 
-    // Write background page color
-    if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
+    const SwAttrSet& rPageStyleAttrSet = 
m_rDoc.GetPageDesc(0).GetMaster().GetAttrSet();
+    const drawing::FillStyle eFillType = 
rPageStyleAttrSet.Get(XATTR_FILLSTYLE).GetValue();
+    const GraphicObject* pGraphicObj = pBrush->GetGraphicObject();
+    if (pGraphicObj) // image/pattern/texture
     {
-        m_pDocumentFS->startElementNS(XML_w, XML_background, FSNS(XML_w, 
XML_color),
-                                      
msfilter::util::ConvertColor(oBrush->GetColor()));
-
-        const SwAttrSet& rPageStyleAttrSet = 
m_rDoc.GetPageDesc(0).GetMaster().GetAttrSet();
-        const drawing::FillStyle eFillType = 
rPageStyleAttrSet.Get(XATTR_FILLSTYLE).GetValue();
-        const GraphicObject* pGraphicObj = oBrush->GetGraphicObject();
-        if (pGraphicObj) // image/pattern/texture
+        const OUString aRelId = 
m_pDrawingML->writeGraphicToStorage(pGraphicObj->GetGraphic());
+        if (!aRelId.isEmpty())
         {
-            const OUString aRelId = 
m_pDrawingML->writeGraphicToStorage(pGraphicObj->GetGraphic());
-            if (!aRelId.isEmpty())
-            {
-                m_pDocumentFS->startElementNS(XML_v, XML_background);
+            m_pDocumentFS->startElementNS(XML_v, XML_background);
 
-                // Although MSO treats everything as tile, it is better for LO 
to not always tile
-                OString sType = "frame"_ostr; // single image
-                if (rPageStyleAttrSet.Get(XATTR_FILLBMP_TILE).GetValue())
-                    sType = "tile"_ostr; // primarily for patterns / textures
-                m_pDocumentFS->singleElementNS(XML_v, XML_fill, FSNS(XML_r, 
XML_id), aRelId,
-                                            XML_type, sType);
+            // Although MSO treats everything as tile, it is better for LO to 
not always tile
+            OString sType = "frame"_ostr; // single image
+            if (rPageStyleAttrSet.Get(XATTR_FILLBMP_TILE).GetValue())
+                sType = "tile"_ostr; // primarily for patterns / textures
+            m_pDocumentFS->singleElementNS(XML_v, XML_fill, FSNS(XML_r, 
XML_id), aRelId, XML_type,
+                                           sType);
 
-                m_pDocumentFS->endElementNS(XML_v, XML_background);
-            }
-        }
-        else if (eFillType == drawing::FillStyle_GRADIENT)
-        {
-            SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> 
aSet(m_rDoc.GetAttrPool());
-            aSet.Set(rPageStyleAttrSet);
-
-            // Collect all of the gradient attributes into SdrExporter() 
AttrLists
-            m_pAttrOutput->OutputStyleItemSet(aSet, /*TestForDefault=*/true);
-            assert(SdrExporter().getFlyAttrList().is() && "type and fillcolor 
are always provided");
-            assert(SdrExporter().getFlyFillAttrList().is() && "color2 is 
always provided");
-
-            rtl::Reference<FastAttributeList> 
xFlyAttrList(SdrExporter().getFlyAttrList());
-            rtl::Reference<FastAttributeList> 
xFillAttrList(SdrExporter().getFlyFillAttrList());
-            m_pDocumentFS->startElementNS(XML_v, XML_background, xFlyAttrList);
-            m_pDocumentFS->singleElementNS(XML_v, XML_fill, xFillAttrList);
             m_pDocumentFS->endElementNS(XML_v, XML_background);
-
-            SdrExporter().getFlyAttrList().clear();
-            SdrExporter().getFlyFillAttrList().clear();
         }
-
-        m_pDocumentFS->endElementNS(XML_w, XML_background);
     }
+    else if (eFillType == drawing::FillStyle_GRADIENT)
+    {
+        SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> 
aSet(m_rDoc.GetAttrPool());
+        aSet.Set(rPageStyleAttrSet);
+
+        // Collect all of the gradient attributes into SdrExporter() AttrLists
+        m_pAttrOutput->OutputStyleItemSet(aSet, /*TestForDefault=*/true);
+        assert(SdrExporter().getFlyAttrList().is() && "type and fillcolor are 
always provided");
+        assert(SdrExporter().getFlyFillAttrList().is() && "color2 is always 
provided");
+
+        rtl::Reference<FastAttributeList> 
xFlyAttrList(SdrExporter().getFlyAttrList());
+        rtl::Reference<FastAttributeList> 
xFillAttrList(SdrExporter().getFlyFillAttrList());
+        m_pDocumentFS->startElementNS(XML_v, XML_background, xFlyAttrList);
+        m_pDocumentFS->singleElementNS(XML_v, XML_fill, xFillAttrList);
+        m_pDocumentFS->endElementNS(XML_v, XML_background);
+
+        SdrExporter().getFlyAttrList().clear();
+        SdrExporter().getFlyFillAttrList().clear();
+    }
+
+    m_pDocumentFS->endElementNS(XML_w, XML_background);
+}
+
+void DocxExport::WriteMainText()
+{
+    // setup the namespaces
+    m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces());
+
+    // reset the incrementing linked-textboxes chain ID before re-saving.
+    m_nLinkedTextboxesChainId=0;
+    m_aLinkedTextboxesHelper.clear();
+
+    // Write background page color
+    WriteDocumentBackgroundFill();
 
     // body
     m_pDocumentFS->startElementNS(XML_w, XML_body);
diff --git a/sw/source/filter/ww8/docxexport.hxx 
b/sw/source/filter/ww8/docxexport.hxx
index 95da64d24408..722e3b571291 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -244,6 +244,9 @@ private:
     /// Setup pStyles and write styles.xml
     void InitStyles();
 
+    /// write optional w:background before the w:body of word/document.xml
+    void WriteDocumentBackgroundFill();
+
     /// Write footnotes.xml and endnotes.xml.
     void WriteFootnotesEndnotes();
 

Reply via email to