summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-02-26 14:24:14 -0500
committerMiklos Vajna <vmiklos@collabora.com>2024-02-27 08:44:16 +0100
commit2e073dc313cb2beaa7e4d2aef8584e7f76e9edee (patch)
tree5554ea8819175003cfe3d9d4d227a09fe3edd7b6
parent38083e4c0b5638d69162593c3fbf599da6cd499f (diff)
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 <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/source/filter/ww8/docxexport.cxx100
-rw-r--r--sw/source/filter/ww8/docxexport.hxx3
2 files changed, 56 insertions, 47 deletions
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();