sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx              |   16 +++++++++++
 sw/source/filter/ww8/docxexport.cxx                     |   22 +++++++++++++---
 sw/source/filter/ww8/rtfexport.cxx                      |    3 +-
 sw/source/filter/ww8/wrtww8.cxx                         |    2 -
 5 files changed, 37 insertions(+), 6 deletions(-)

New commits:
commit ed91971c9312e4b8a33c03c28d339bff6c5accc7
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Feb 9 15:43:32 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Feb 21 08:42:31 2024 +0100

    tdf#126533 docx export: page background vml fill: basic image
    
    This is the absolute minimal possible combination
    to export an image to page background.
    
    However, none of the other properties
    that I see strike me as particularly important
    or connected to our image properties.
    
    Plus MSO ignores things like "frame" and tiles anyway.
    
    Import is also pretty basic, so any improvement to imports
    can also add the corresponding export component.
    
    For example: it seems like MSO tiles all images
    based on somewhat magical sizing (they do always export
    o:targetscreensize="999<w>,999<h>" which we ignore).
    But note that MSO does pixel display and not logical display
    for page background - something we do NOT want to emulate,
    so any importing of properties needs to be done intelligently.
    
    But MSO's UI only allows for basic image insertion,
    so very few files will have complex settings.
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf126533_pageBitmap
    
    Change-Id: Ib410594d1e3377aefb8ee94f209a1a1155154b17
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163203
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docx 
b/sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docx
new file mode 100644
index 000000000000..67131acd2fd8
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index e455467a74ef..224f8f2aa27d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -387,6 +387,22 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf126533_pageGradient)
                          getProperty<drawing::FillStyle>(xPageStyle, 
"FillStyle"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf126533_pageBitmap, "tdf126533_pageBitmap.docx")
+{
+    // given a document with a page background image
+    uno::Reference<beans::XPropertySet> 
xPageStyle(getStyles("PageStyles")->getByName("Standard"),
+                                                   uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP,
+                         getProperty<drawing::FillStyle>(xPageStyle, 
"FillStyle"));
+
+    if (!isExported())
+        return;
+
+    xmlDocUniquePtr pXmlDocRels = parseExport("word/_rels/document.xml.rels");
+    assertXPath(pXmlDocRels,
+                
"/rels:Relationships/rels:Relationship[@Target='media/image1.jpeg']"_ostr, 1);
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index 869862909678..fcb55e19c314 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1911,11 +1911,25 @@ void DocxExport::WriteMainText()
     // Write background page color
     if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
     {
-        Color backgroundColor = oBrush->GetColor();
-        OString aBackgroundColorStr = 
msfilter::util::ConvertColor(backgroundColor);
+        m_pDocumentFS->startElementNS(XML_w, XML_background, FSNS(XML_w, 
XML_color),
+                                      
msfilter::util::ConvertColor(oBrush->GetColor()));
 
-        m_pDocumentFS->singleElementNS(XML_w, XML_background, FSNS(XML_w, 
XML_color),
-                                       aBackgroundColorStr);
+        const GraphicObject* pGraphicObj = oBrush->GetGraphicObject();
+        if (pGraphicObj) // image/pattern/texture
+        {
+            const OUString aRelId = 
m_pDrawingML->writeGraphicToStorage(pGraphicObj->GetGraphic());
+            if (!aRelId.isEmpty())
+            {
+                m_pDocumentFS->startElementNS(XML_v, XML_background);
+
+                m_pDocumentFS->singleElementNS(XML_v, XML_fill, FSNS(XML_r, 
XML_id), aRelId,
+                                            XML_type, "frame");
+
+                m_pDocumentFS->endElementNS(XML_v, XML_background);
+            }
+        }
+
+        m_pDocumentFS->endElementNS(XML_w, XML_background);
     }
 
     // body
diff --git a/sw/source/filter/ww8/rtfexport.cxx 
b/sw/source/filter/ww8/rtfexport.cxx
index 135a84da36a5..7dbe10221ef1 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -471,7 +471,8 @@ void RtfExport::WriteMainText()
 {
     SAL_INFO("sw.rtf", __func__ << " start");
 
-    if (std::unique_ptr<SvxBrushItem> oBrush = getBackground(); oBrush)
+    const std::unique_ptr<SvxBrushItem> oBrush = getBackground();
+    if (oBrush && oBrush->GetColor() != COL_AUTO)
     {
         Strm().WriteOString(LO_STRING_SVTOOLS_RTF_VIEWBKSP).WriteChar('1');
         Strm().WriteOString("{" OOO_STRING_SVTOOLS_RTF_IGNORE 
OOO_STRING_SVTOOLS_RTF_BACKGROUND);
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index e471f64a0afa..3b8abbc0bc7b 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -1517,7 +1517,7 @@ std::unique_ptr<SvxBrushItem> 
MSWordExportBase::getBackground()
     if (SfxItemState::SET == eState)
     {
         // The 'color' is set for the first page style - take it and use it as 
the background color of the entire DOCX
-        if (aBrush->GetColor() != COL_AUTO)
+        if (aBrush->GetColor() != COL_AUTO || aBrush->GetGraphicObject())
             return aBrush;
     }
     return nullptr;

Reply via email to