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 9e623d8d0a1896e679a48b84459dc3b316636aba Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Fri Feb 9 15:43:32 2024 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Feb 26 08:42:51 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163862 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.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 ca0cc5438ee6..d4bc37d5f700 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -83,6 +83,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 e7c1972ce9c0..46e66a4a42a0 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 6063eb343248..87a8a2e8e262 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 74e9d27c09ea..d79876eb5524 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;