summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper
diff options
context:
space:
mode:
Diffstat (limited to 'writerfilter/source/dmapper')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx58
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx1
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx33
3 files changed, 91 insertions, 1 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 946befddd2f9..f3e15a69afaf 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -32,6 +32,8 @@
#include <ooxml/resourceids.hxx>
#include <oox/token/tokens.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
+
+#include <com/sun/star/awt/Gradient2.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
@@ -1474,7 +1476,63 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
switch (rSprm.getId())
{
case NS_ooxml::LN_background_background:
+ {
+ // if a VML background has been defined, it was imported into a shape to hold the properties
+ uno::Reference<drawing::XShape> xFill(m_pImpl->PopPendingShape());
+ if (xFill.is())
+ {
+ assert(!m_pImpl->GetTopContext());
+ assert(m_pImpl->GetIsFirstParagraphInShape());
+ assert(mbWasShapeInPara);
+ assert(m_pImpl->GetIsFirstParagraphInSection());
+ assert(m_pImpl->IsOutsideAParagraph());
+ if (m_pImpl->GetSettingsTable()->GetDisplayBackgroundShape())
+ {
+ // apply the XATTR_FILL attributes to the default page style
+ const uno::Reference<beans::XPropertySet> xFillPropertySet(xFill, uno::UNO_QUERY);
+ const uno::Reference<beans::XPropertySetInfo> xFillInfo
+ = xFillPropertySet->getPropertySetInfo();
+ uno::Reference<beans::XPropertySet> xPS(
+ m_pImpl->GetPageStyles()->getByName("Standard"), uno::UNO_QUERY_THROW);
+ for (const beans::Property& rProp : xPS->getPropertySetInfo()->getProperties())
+ {
+ if (rProp.Name == "FillComplexColor" || rProp.Name == "FillGradientName"
+ || rProp.Name == "FillGradientStepCount"
+ || rProp.Name == "FillTransparenceGradientName"
+ || rProp.Name == "FillBitmapURL" || rProp.Name == "FillColor2")
+ {
+ // silence exceptions for unsupported stuff when appling to page style
+ continue;
+ }
+ if (!rProp.Name.startsWith("Fill"))
+ continue;
+
+ if (!xFillInfo->hasPropertyByName(rProp.Name))
+ continue;
+
+ try
+ {
+ const uno::Any aFillValue = xFillPropertySet->getPropertyValue(rProp.Name);
+ xPS->setPropertyValue(rProp.Name, aFillValue);
+ }
+ catch (uno::Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION("writerfilter", "Exception setting page background fill");
+ }
+ }
+
+ m_pImpl->m_bCopyStandardPageStyleFill = true;
+ }
+
+ // The background was unhelpfully imported into the text body: remove it
+ uno::Reference<lang::XComponent> xComponent(xFill, uno::UNO_QUERY_THROW);
+ xComponent->dispose();
+
+ m_pImpl->SetIsFirstParagraphInShape(false);
+ mbWasShapeInPara = false;
+ }
return;
+ }
default:
break;
}
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index bd6358a6a7e1..9d1a3aaa3b75 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -1149,6 +1149,7 @@ public:
/// Document background color, applied to every page style.
std::optional<sal_Int32> m_oBackgroundColor;
+ bool m_bCopyStandardPageStyleFill = false;
/// If the current section has a footnote separator.
bool m_bHasFtnSep;
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 96bec18a14fa..79ee185ad17d 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -39,6 +39,7 @@
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/style/BreakType.hpp>
#include <com/sun/star/style/PageStyleLayout.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
@@ -1137,7 +1138,37 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl)
Insert( PROP_RIGHT_MARGIN, uno::Any( m_nRightMargin ) );
Insert(PROP_GUTTER_MARGIN, uno::Any(m_nGutterMargin));
- if ( rDM_Impl.m_oBackgroundColor )
+ // w:background is applied to every page in the document
+ if (!rDM_Impl.m_oBackgroundColor.has_value() && !rDM_Impl.IsRTFImport())
+ {
+ // DOCX has an interesting quirk, where if the fallback background color is not defined,
+ // then the fill is not applied either.
+
+ // Disable the imported fill from the default style
+ if (rDM_Impl.m_bCopyStandardPageStyleFill && m_sPageStyleName == "Standard")
+ {
+ rDM_Impl.m_bCopyStandardPageStyleFill = false;
+ m_aPageStyle->setPropertyValue("FillStyle", uno::Any(drawing::FillStyle_NONE));
+ }
+ }
+ else if (rDM_Impl.m_bCopyStandardPageStyleFill) // complex fill: graphics/gradients/patterns
+ {
+ uno::Reference<beans::XPropertySet> xDefaultPageStyle(
+ rDM_Impl.GetPageStyles()->getByName("Standard"), uno::UNO_QUERY_THROW);
+ for (const beans::Property& rProp : m_aPageStyle->getPropertySetInfo()->getProperties())
+ {
+ try
+ {
+ const uno::Any aFillValue = xDefaultPageStyle->getPropertyValue(rProp.Name);
+ m_aPageStyle->setPropertyValue(rProp.Name, aFillValue);
+ }
+ catch (uno::Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION("writerfilter", "Exception setting page background fill");
+ }
+ }
+ }
+ else if (rDM_Impl.m_oBackgroundColor) // simple, solid color
Insert( PROP_BACK_COLOR, uno::Any( *rDM_Impl.m_oBackgroundColor ) );
// Check for missing footnote separator only in case there is at least