summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-02-09 15:43:32 -0500
committerMiklos Vajna <vmiklos@collabora.com>2024-02-21 08:42:31 +0100
commited91971c9312e4b8a33c03c28d339bff6c5accc7 (patch)
treef64b93b80b0bdab001969808d007a20020ee4988
parentbbb0663813d0476b9a654207b7006315cb417c2e (diff)
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 <jluth@mail.com>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docxbin0 -> 76377 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport21.cxx16
-rw-r--r--sw/source/filter/ww8/docxexport.cxx22
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx3
-rw-r--r--sw/source/filter/ww8/wrtww8.cxx2
5 files changed, 37 insertions, 6 deletions
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
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf126533_pageBitmap.docx
Binary files 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;