tdf#103602 xmloff: ODF export: draw:background-size attribute

... on drawing-page style; no import because Writer doesn't have the
property anyway.

It looks like Writer paints color, gradient, hatch and bitmap with
"repeat" on the entire page, and bitmap "scaled" or "no-repeat" within
the borders.

Change-Id: Ia32c800a6cb537bf9df57c6a6a77a5c1dcf52aa8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95040
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
diff --git a/include/xmloff/xmltypes.hxx b/include/xmloff/xmltypes.hxx
index d3ffd80..38c4b61 100644
--- a/include/xmloff/xmltypes.hxx
+++ b/include/xmloff/xmltypes.hxx
@@ -291,6 +291,7 @@

#define XML_TYPE_TEXT_RUBY_IS_ABOVE     (XML_TEXT_TYPES_START + 126)
#define XML_TYPE_GRAPHIC                (XML_TEXT_TYPES_START + 127)
#define XML_SW_TYPE_PRESPAGE_BACKSIZE   (XML_TEXT_TYPES_START + 128)

#endif // INCLUDED_XMLOFF_XMLTYPES_HXX

diff --git a/xmloff/inc/PageMasterStyleMap.hxx b/xmloff/inc/PageMasterStyleMap.hxx
index a57acde..f27d4ce 100644
--- a/xmloff/inc/PageMasterStyleMap.hxx
+++ b/xmloff/inc/PageMasterStyleMap.hxx
@@ -96,6 +96,8 @@
#define CTF_PM_FILLBITMAPNAME           (XML_PM_CTF_START + 0x0041)
#define CTF_PM_FILLTRANSNAME            (XML_PM_CTF_START + 0x0042)
#define CTF_PM_FILLBITMAPMODE           (XML_PM_CTF_START + 0x0043)
#define CTF_PM_FILL                     (XML_PM_CTF_START + 0x0044)
#define CTF_PM_BACKGROUNDSIZE           (XML_PM_CTF_START + 0x0045)

#define CTF_PM_SCALETO                  (XML_PM_CTF_START + 0x0051) // calc specific
#define CTF_PM_SCALETOPAGES             (XML_PM_CTF_START + 0x0052)
diff --git a/xmloff/source/style/PageMasterExportPropMapper.cxx b/xmloff/source/style/PageMasterExportPropMapper.cxx
index 3581c9d..d4c6abb 100644
--- a/xmloff/source/style/PageMasterExportPropMapper.cxx
+++ b/xmloff/source/style/PageMasterExportPropMapper.cxx
@@ -23,6 +23,8 @@
#include <comphelper/types.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
#include <PageMasterStyleMap.hxx>
#include <rtl/ref.hxx>
#include <comphelper/extract.hxx>
@@ -328,6 +330,9 @@ void XMLPageMasterExportPropMapper::ContextFilter(
    XMLPropertyState* pFooterRepeatOffsetX = nullptr;
    XMLPropertyState* pFooterRepeatOffsetY = nullptr;

    XMLPropertyState* pFill = nullptr;
    XMLPropertyState* pFillBitmapMode = nullptr;

    rtl::Reference < XMLPropertySetMapper > aPropMapper(getPropertySetMapper());

    for( auto& rProp : rPropState )
@@ -348,6 +353,20 @@ void XMLPageMasterExportPropMapper::ContextFilter(

        switch( nSimpleId )
        {
            case CTF_PM_FILL: // tdf#103602: add background-size attribute to ODT
                if (nFlag != CTF_PM_HEADERFLAG && nFlag != CTF_PM_FOOTERFLAG
                    && rProp.maValue.hasValue())
                {
                    pFill = &rProp;
                }
                break;
            case CTF_PM_FILLBITMAPMODE:
                if (nFlag != CTF_PM_HEADERFLAG && nFlag != CTF_PM_FOOTERFLAG
                    && rProp.maValue.hasValue())
                {
                    pFillBitmapMode = &rProp;
                }
                break;
            case CTF_PM_MARGINALL:          pBuffer->pPMMarginAll           = pProp;    break;
            case CTF_PM_BORDERALL:          pBuffer->pPMBorderAll           = pProp;    break;
            case CTF_PM_BORDERTOP:          pBuffer->pPMBorderTop           = pProp;    break;
@@ -544,6 +563,45 @@ void XMLPageMasterExportPropMapper::ContextFilter(
        lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ZEROVALUES), "PrintZeroValues", rPropSet);
    }

    if (pFill)
    {   // note: only drawing-page export should write this, because CTF_PM_FILL
        uno::Any backgroundSize;
        switch (pFill->maValue.get<drawing::FillStyle>())
        {
            case drawing::FillStyle_NONE:
                break;
            case drawing::FillStyle_SOLID:
            case drawing::FillStyle_GRADIENT:
            case drawing::FillStyle_HATCH:
                backgroundSize <<= true;
                break;
            case drawing::FillStyle_BITMAP:
                assert(pFillBitmapMode);
                switch (pFillBitmapMode->maValue.get<drawing::BitmapMode>())
                {
                    case drawing::BitmapMode_REPEAT:
                        backgroundSize <<= true;
                        break;
                    case drawing::BitmapMode_STRETCH:
                    case drawing::BitmapMode_NO_REPEAT:
                        backgroundSize <<= false;
                        break;
                    default:
                        assert(false);
                }
                break;
            default:
                assert(false);
        }

        if (backgroundSize.hasValue())
        {
            auto const nIndex(aPropMapper->FindEntryIndex(CTF_PM_BACKGROUNDSIZE));
            assert(0 <= nIndex);
            rPropState.emplace_back(nIndex, backgroundSize);
        }
    }

    SvXMLExportPropertyMapper::ContextFilter(bEnableFoFontFamily, rPropState, rPropSet);
}

diff --git a/xmloff/source/style/PageMasterPropHdlFactory.cxx b/xmloff/source/style/PageMasterPropHdlFactory.cxx
index ae61a30..5be8cbf 100644
--- a/xmloff/source/style/PageMasterPropHdlFactory.cxx
+++ b/xmloff/source/style/PageMasterPropHdlFactory.cxx
@@ -131,6 +131,9 @@ const XMLPropertyHandler* XMLPageMasterPropHdlFactory::GetPropertyHandler( sal_I
            case XML_SW_TYPE_FILLSTYLE:
                pHdl = new XMLEnumPropertyHdl( aXML_FillStyle_EnumMap );
                break;
            case XML_SW_TYPE_PRESPAGE_BACKSIZE:
                pHdl = new XMLNamedBoolPropertyHdl(GetXMLToken(XML_FULL), GetXMLToken(XML_BORDER));
                break;
            case XML_SW_TYPE_FILLBITMAPSIZE:
                pHdl = new XMLFillBitmapSizePropertyHandler();
                break;
diff --git a/xmloff/source/style/PageMasterStyleMap.cxx b/xmloff/source/style/PageMasterStyleMap.cxx
index 7ab1b46..3e4b035 100644
--- a/xmloff/source/style/PageMasterStyleMap.cxx
+++ b/xmloff/source/style/PageMasterStyleMap.cxx
@@ -273,7 +273,9 @@ XMLPropertyMapEntry const g_XMLPageMasterDrawingPageStyleMap[] =
{
    // ODF 1.3 OFFICE-3937 style of family "drawing-page" referenced from style:master-page
    // duplication of relevant part of aXMLPageMasterStyleMap but as DP type
    DPMAP("FillStyle",                    XML_NAMESPACE_DRAW,     XML_FILL,                   XML_SW_TYPE_FILLSTYLE,                                0),
    DPMAP("FillStyle",                    XML_NAMESPACE_DRAW,     XML_FILL,                   XML_SW_TYPE_FILLSTYLE,                                CTF_PM_FILL),
    // this does not exist yet!
    DPMAP("BackgroundFullSize",           XML_NAMESPACE_DRAW,     XML_BACKGROUND_SIZE,        XML_SW_TYPE_PRESPAGE_BACKSIZE|MID_FLAG_NO_PROPERTY,   CTF_PM_BACKGROUNDSIZE),
    DPMAP("FillColor",                    XML_NAMESPACE_DRAW,     XML_FILL_COLOR,             XML_TYPE_COLOR,                                       0),
    DPMAP("FillColor2",                   XML_NAMESPACE_DRAW,     XML_SECONDARY_FILL_COLOR,   XML_TYPE_COLOR,                                       0),
    DPMAP("FillGradientName",             XML_NAMESPACE_DRAW,     XML_FILL_GRADIENT_NAME,     XML_TYPE_STYLENAME|MID_FLAG_NO_PROPERTY_IMPORT,       CTF_PM_FILLGRADIENTNAME),