filter/source/msfilter/escherex.cxx             |    1 
 include/filter/msfilter/escherex.hxx            |    3 
 sw/inc/IDocumentDrawModelAccess.hxx             |    1 
 sw/inc/IDocumentSettingAccess.hxx               |    2 
 sw/qa/extras/layout/layout2.cxx                 |   18 ++---
 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx      |    2 
 sw/source/core/doc/DocumentDrawModelManager.cxx |   13 +++-
 sw/source/core/doc/DocumentSettingManager.cxx   |   13 +++-
 sw/source/core/doc/notxtfrm.cxx                 |    2 
 sw/source/core/inc/DocumentDrawModelManager.hxx |    3 
 sw/source/core/inc/DocumentSettingManager.hxx   |    1 
 sw/source/core/inc/cellfrm.hxx                  |    2 
 sw/source/core/inc/flyfrm.hxx                   |    4 -
 sw/source/core/inc/frame.hxx                    |   10 ++-
 sw/source/core/inc/layfrm.hxx                   |    2 
 sw/source/core/inc/notxtfrm.hxx                 |    2 
 sw/source/core/inc/rootfrm.hxx                  |    2 
 sw/source/core/inc/tabfrm.hxx                   |    2 
 sw/source/core/inc/txtfrm.hxx                   |    2 
 sw/source/core/layout/fly.cxx                   |   26 ++++++--
 sw/source/core/layout/paintfrm.cxx              |   74 +++++++++++++++++++-----
 sw/source/core/layout/unusedf.cxx               |    2 
 sw/source/core/text/frmpaint.cxx                |    2 
 sw/source/core/unocore/unodraw.cxx              |    7 +-
 sw/source/core/unocore/unoframe.cxx             |   10 ++-
 sw/source/filter/ww8/docxsdrexport.cxx          |   11 +--
 sw/source/filter/ww8/wrtw8esh.cxx               |    2 
 sw/source/uibase/uno/SwXDocumentSettings.cxx    |   16 +++++
 sw/source/writerfilter/dmapper/DomainMapper.cxx |    2 
 sw/source/writerfilter/filter/WriterFilter.cxx  |    2 
 30 files changed, 186 insertions(+), 53 deletions(-)

New commits:
commit b860aea9d6f8ac46f6d2575ead25337495ec9a88
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Wed Mar 13 13:04:18 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue May 28 00:45:20 2024 +0200

    tdf#160198 Compatibility in background shapes/pictures
    
    Paint Word background shapes/pictures (wrapped through) above
    header and footer if the anchor is in the document body.
    
    Change-Id: Ic32ba8d64f82c64e502788007e49a9dce4c4c76f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164802
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/filter/source/msfilter/escherex.cxx 
b/filter/source/msfilter/escherex.cxx
index 319be56e6269..17543714ca29 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -4867,6 +4867,7 @@ EscherEx::EscherEx(std::shared_ptr<EscherExGlobal> 
xGlobal, SvStream* pOutStrm,
     , mnCountOfs(0)
     , mnGroupLevel(0)
     , mnHellLayerId(SDRLAYER_NOTFOUND)
+    , mnHeaderFooterHellLayerId(SDRLAYER_NOTFOUND)
     , mbEscherSpgr(false)
     , mbEscherDg(false)
     , mbOOXML(bOOXML)
diff --git a/include/filter/msfilter/escherex.hxx 
b/include/filter/msfilter/escherex.hxx
index b8845ae240a5..196dc7918f6e 100644
--- a/include/filter/msfilter/escherex.hxx
+++ b/include/filter/msfilter/escherex.hxx
@@ -1062,6 +1062,7 @@ class MSFILTER_DLLPUBLIC EscherEx : public 
EscherPersistTable
 
         sal_uInt32                  mnGroupLevel;
         SdrLayerID                  mnHellLayerId;
+        SdrLayerID                  mnHeaderFooterHellLayerId;
 
         bool                        mbEscherSpgr;
         bool                        mbEscherDg;
@@ -1211,6 +1212,8 @@ public:
 
     void SetHellLayerId( SdrLayerID nId )       { mnHellLayerId = nId; }
     SdrLayerID GetHellLayerId() const           { return mnHellLayerId; }
+    void SetHeaderFooterHellLayerId( SdrLayerID nId )       { 
mnHeaderFooterHellLayerId = nId; }
+    SdrLayerID GetHeaderFooterHellLayerId() const           { return 
mnHeaderFooterHellLayerId; }
 
 private:
                         EscherEx( const EscherEx& ) = delete;
diff --git a/sw/inc/IDocumentDrawModelAccess.hxx 
b/sw/inc/IDocumentDrawModelAccess.hxx
index 3c1113cfe882..3a40da7881ec 100644
--- a/sw/inc/IDocumentDrawModelAccess.hxx
+++ b/sw/inc/IDocumentDrawModelAccess.hxx
@@ -37,6 +37,7 @@ public:
     virtual SwDrawModel* GetOrCreateDrawModel() = 0;
     virtual SdrLayerID GetHeavenId() const = 0;
     virtual SdrLayerID GetHellId() const = 0;
+    virtual SdrLayerID GetHeaderFooterHellId() const = 0;
     virtual SdrLayerID GetControlsId() const = 0;
     virtual SdrLayerID GetInvisibleHeavenId() const = 0;
     virtual SdrLayerID GetInvisibleHellId() const = 0;
diff --git a/sw/inc/IDocumentSettingAccess.hxx 
b/sw/inc/IDocumentSettingAccess.hxx
index 264860b854c4..39bcd7efcbeb 100644
--- a/sw/inc/IDocumentSettingAccess.hxx
+++ b/sw/inc/IDocumentSettingAccess.hxx
@@ -133,6 +133,8 @@ enum class DocumentSettingId
     DROP_CAP_PUNCTUATION,
     // render NBSP as standard-space-width (prettier when justified)
     USE_VARIABLE_WIDTH_NBSP,
+    // overlap background shapes if anchored in body
+    PAINT_HELL_OVER_HEADER_FOOTER,
 };
 
 /** Provides access to settings of a document
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index a393f06d4306..56c6991fce5e 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -1288,11 +1288,11 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf125300)
 
     // Keep line spacing before bottom cell border (it was 1892)
     sal_Int32 y1
-        = getXPath(pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[5]/polyline/point[1]"_ostr,
+        = getXPath(pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[7]/polyline/point[1]"_ostr,
                    "y"_ostr)
               .toInt32();
     sal_Int32 y2
-        = getXPath(pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[5]/polyline/point[2]"_ostr,
+        = getXPath(pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[7]/polyline/point[2]"_ostr,
                    "y"_ostr)
               .toInt32();
     CPPUNIT_ASSERT_DOUBLES_EQUAL(2092, y1, 7);
@@ -1545,13 +1545,13 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf115630)
     sal_Int32 nXRight
         = getXPath(
               pXmlDoc,
-              
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/polyline[1]/point[1]"_ostr,
+              
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[3]/polyline[1]/point[1]"_ostr,
               "x"_ostr)
               .toInt32();
     sal_Int32 nXLeft
         = getXPath(
               pXmlDoc,
-              
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/polyline[1]/point[2]"_ostr,
+              
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[3]/polyline[1]/point[2]"_ostr,
               "x"_ostr)
               .toInt32();
     CPPUNIT_ASSERT_DOUBLES_EQUAL(2895, nXRight - nXLeft, 50);
@@ -1931,13 +1931,13 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf129054)
     sal_Int32 nYTop
         = getXPath(
               pXmlDoc,
-              
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[4]/polyline[1]/point[1]"_ostr,
+              
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[4]/polyline[1]/point[1]"_ostr,
               "y"_ostr)
               .toInt32();
     sal_Int32 nYBottom
         = getXPath(
               pXmlDoc,
-              
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[4]/polyline[1]/point[31]"_ostr,
+              
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[4]/polyline[1]/point[31]"_ostr,
               "y"_ostr)
               .toInt32();
     CPPUNIT_ASSERT_DOUBLES_EQUAL(4615, nYTop - nYBottom, 5);
@@ -2134,7 +2134,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf130380)
     xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
     CPPUNIT_ASSERT(pXmlDoc);
     sal_Int32 nY = getXPath(pXmlDoc,
-                            
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[1]/polypolygon/"
+                            
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[1]/polypolygon/"
                             "polygon/point[1]"_ostr,
                             "y"_ostr)
                        .toInt32();
@@ -2322,12 +2322,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf116925)
     CPPUNIT_ASSERT(pXmlDoc);
 
     assertXPathContent(
-        pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/textarray/text"_ostr,
+        pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[3]/textarray/text"_ostr,
         "hello");
     // This failed, text color was #000000.
     assertXPath(
         pXmlDoc,
-        
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/textcolor[@color='#ffffff']"_ostr,
+        
"/metafile/push[1]/push[1]/push[1]/push[6]/push[1]/push[3]/textcolor[@color='#ffffff']"_ostr,
         1);
 }
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index d6193305e96c..06b806a0f555 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -754,7 +754,7 @@ CPPUNIT_TEST_FIXTURE(Test, TestPuzzleExport)
     CPPUNIT_ASSERT(pMetaXml);
     // After parsing check that node...
     auto pXNode = getXPathNode(
-        pMetaXml, 
"/metafile/push/push/push/push[4]/push/push/polypolygon/polygon"_ostr);
+        pMetaXml, 
"/metafile/push/push/push/push[6]/push/push/polypolygon/polygon"_ostr);
     CPPUNIT_ASSERT(pXNode);
     auto pNode = pXNode->nodesetval->nodeTab[0];
     CPPUNIT_ASSERT(pNode);
diff --git a/sw/source/core/doc/DocumentDrawModelManager.cxx 
b/sw/source/core/doc/DocumentDrawModelManager.cxx
index 672c8abffb75..0db1d576fc80 100644
--- a/sw/source/core/doc/DocumentDrawModelManager.cxx
+++ b/sw/source/core/doc/DocumentDrawModelManager.cxx
@@ -56,6 +56,7 @@ DocumentDrawModelManager::DocumentDrawModelManager(SwDoc& 
i_rSwdoc)
     : m_rDoc(i_rSwdoc)
     , mnHeaven(0)
     , mnHell(0)
+    , mnHeaderFooterHell(0)
     , mnControls(0)
     , mnInvisibleHeaven(0)
     , mnInvisibleHell(0)
@@ -86,6 +87,9 @@ void DocumentDrawModelManager::InitDrawModel()
     sLayerNm = "Hell";
     mnHell   = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
 
+    sLayerNm = "HeaderFooterHell";
+    mnHeaderFooterHell = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm 
)->GetID();
+
     sLayerNm = "Heaven";
     mnHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
 
@@ -204,6 +208,11 @@ SdrLayerID DocumentDrawModelManager::GetHellId() const
     return mnHell;
 }
 
+SdrLayerID DocumentDrawModelManager::GetHeaderFooterHellId() const
+{
+    return mnHeaderFooterHell;
+}
+
 SdrLayerID DocumentDrawModelManager::GetControlsId() const
 {
     return mnControls;
@@ -242,6 +251,7 @@ bool DocumentDrawModelManager::IsVisibleLayerId( SdrLayerID 
_nLayerId ) const
     bool bRetVal;
 
     if ( _nLayerId == GetHeavenId() ||
+         _nLayerId == GetHeaderFooterHellId() ||
          _nLayerId == GetHellId() ||
          _nLayerId == GetControlsId() )
     {
@@ -270,7 +280,8 @@ SdrLayerID 
DocumentDrawModelManager::GetInvisibleLayerIdByVisibleOne( SdrLayerID
     {
         nInvisibleLayerId = GetInvisibleHeavenId();
     }
-    else if ( _nVisibleLayerId == GetHellId() )
+    //TODO: do we need an InvisbleHeaderFooterHell?
+    else if ( _nVisibleLayerId == GetHellId() || _nVisibleLayerId == 
GetHeaderFooterHellId())
     {
         nInvisibleLayerId = GetInvisibleHellId();
     }
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx 
b/sw/source/core/doc/DocumentSettingManager.cxx
index 501344ca8108..0a02eb5cb72f 100644
--- a/sw/source/core/doc/DocumentSettingManager.cxx
+++ b/sw/source/core/doc/DocumentSettingManager.cxx
@@ -107,7 +107,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc 
&rDoc)
     mbAutoFirstLineIndentDisregardLineSpace(true),
     mbNoNumberingShowFollowBy(false),
     mbDropCapPunctuation(true),
-    mbUseVariableWidthNBSP(false)
+    mbUseVariableWidthNBSP(false),
+    mbPaintHellOverHeaderFooter(false)
 
     // COMPATIBILITY FLAGS END
 {
@@ -265,6 +266,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ 
DocumentSettingId id) const
         case DocumentSettingId::NO_NUMBERING_SHOW_FOLLOWBY: return 
mbNoNumberingShowFollowBy;
         case DocumentSettingId::DROP_CAP_PUNCTUATION: return 
mbDropCapPunctuation;
         case DocumentSettingId::USE_VARIABLE_WIDTH_NBSP: return 
mbUseVariableWidthNBSP;
+        case DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER: return 
mbPaintHellOverHeaderFooter;
         default:
             OSL_FAIL("Invalid setting id");
     }
@@ -482,6 +484,10 @@ void sw::DocumentSettingManager::set(/*[in]*/ 
DocumentSettingId id, /*[in]*/ boo
             mbUseVariableWidthNBSP = value;
             break;
 
+        case DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER:
+            mbPaintHellOverHeaderFooter = value;
+            break;
+
         // COMPATIBILITY FLAGS END
 
         case DocumentSettingId::BROWSE_MODE: //can be used temporary 
(load/save) when no SwViewShell is available
@@ -1057,6 +1063,11 @@ void 
sw::DocumentSettingManager::dumpAsXml(xmlTextWriterPtr pWriter) const
                                 
BAD_CAST(OString::boolean(mbUseVariableWidthNBSP).getStr()));
     (void)xmlTextWriterEndElement(pWriter);
 
+    (void)xmlTextWriterStartElement(pWriter, 
BAD_CAST("mbPaintHellOverHeaderFooter"));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
+                                
BAD_CAST(OString::boolean(mbPaintHellOverHeaderFooter).getStr()));
+    (void)xmlTextWriterEndElement(pWriter);
+
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("mbContinuousEndnotes"));
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
                                 
BAD_CAST(OString::boolean(mbContinuousEndnotes).getStr()));
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index e7720afea697..5083ad7aded8 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -214,7 +214,7 @@ static void lcl_ClearArea( const SwFrame &rFrame,
     }
 }
 
-void SwNoTextFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwNoTextFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     if ( getFrameArea().IsEmpty() )
         return;
diff --git a/sw/source/core/inc/DocumentDrawModelManager.hxx 
b/sw/source/core/inc/DocumentDrawModelManager.hxx
index 26fd603a67e9..36f03d1a22cb 100644
--- a/sw/source/core/inc/DocumentDrawModelManager.hxx
+++ b/sw/source/core/inc/DocumentDrawModelManager.hxx
@@ -46,6 +46,7 @@ public:
     virtual SwDrawModel* GetOrCreateDrawModel() override;
     virtual SdrLayerID GetHeavenId() const override;
     virtual SdrLayerID GetHellId() const override;
+    virtual SdrLayerID GetHeaderFooterHellId() const override;
     virtual SdrLayerID GetControlsId() const override;
     virtual SdrLayerID GetInvisibleHeavenId() const override;
     virtual SdrLayerID GetInvisibleHellId() const override;
@@ -70,10 +71,12 @@ private:
     /** Draw Model Layer IDs
      * LayerIds, Heaven == above document
      *           Hell   == below document
+     *           HeaderFooterHell = below document but above header/footer
      *         Controls == at the very top
      */
     SdrLayerID mnHeaven;
     SdrLayerID mnHell;
+    SdrLayerID mnHeaderFooterHell;
     SdrLayerID mnControls;
     SdrLayerID mnInvisibleHeaven;
     SdrLayerID mnInvisibleHell;
diff --git a/sw/source/core/inc/DocumentSettingManager.hxx 
b/sw/source/core/inc/DocumentSettingManager.hxx
index 6cfda277ade1..4006fa51dbbe 100644
--- a/sw/source/core/inc/DocumentSettingManager.hxx
+++ b/sw/source/core/inc/DocumentSettingManager.hxx
@@ -184,6 +184,7 @@ class DocumentSettingManager final :
     bool mbNoNumberingShowFollowBy;
     bool mbDropCapPunctuation; // tdf#150200, tdf#150438
     bool mbUseVariableWidthNBSP : 1; // tdf#41652
+    bool mbPaintHellOverHeaderFooter : 1; // tdf#160198
 
 public:
 
diff --git a/sw/source/core/inc/cellfrm.hxx b/sw/source/core/inc/cellfrm.hxx
index f2be099e381f..3fad18e7fcec 100644
--- a/sw/source/core/inc/cellfrm.hxx
+++ b/sw/source/core/inc/cellfrm.hxx
@@ -42,7 +42,7 @@ public:
     SwCellFrame( const SwTableBox &, SwFrame*, bool bInsertContent );
 
     virtual bool GetModelPositionForViewPoint( SwPosition *, Point&, 
SwCursorMoveState* = nullptr, bool bTestBackground = false ) const override;
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
     virtual void CheckDirection( bool bVert ) override;
 
     // #i103961#
diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx
index 821be741fc70..a9db68182fd8 100644
--- a/sw/source/core/inc/flyfrm.hxx
+++ b/sw/source/core/inc/flyfrm.hxx
@@ -83,7 +83,7 @@ class SAL_DLLPUBLIC_RTTI SwFlyFrame : public SwLayoutFrame, 
public SwAnchoredObj
     friend void Notify( SwFlyFrame *, SwPageFrame *pOld, const SwRect &rOld,
                         const SwRect* pOldPrt );
 
-    void InitDrawObj(SwFrame const&); // these to methods are called in the
+    void InitDrawObj(SwFrame&); // these to methods are called in the
     void FinitDrawObj();    // constructors
 
     void UpdateAttr_( const SfxPoolItem*, const SfxPoolItem*, 
SwFlyFrameInvFlags &,
@@ -170,7 +170,7 @@ protected:
 
 public:
     // #i26791#
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
     virtual Size ChgSize( const Size& aNewSize ) override;
     virtual bool GetModelPositionForViewPoint( SwPosition *, Point&,
                               SwCursorMoveState* = nullptr, bool 
bTestBackground = false ) const override;
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index d878bebf8f11..4f0df45e2d30 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -577,13 +577,17 @@ public:
         const SwRect&,
         const SwPageFrame* pPage,
         const SwBorderAttrs&) const;
+    enum PaintFrameMode { PAINT_ALL, PAINT_HEADER_FOOTER, 
PAINT_NON_HEADER_FOOTER };
+    static const SwFrame* SkipFrame(const SwFrame* pFrame, PaintFrameMode 
ePaintFrameMode );
     void PaintBaBo( const SwRect&, const SwPageFrame *pPage,
-                    const bool bOnlyTextBackground = false) const;
+                    const bool bOnlyTextBackground = false,
+                   PaintFrameMode eMode = PAINT_ALL ) const;
     void PaintSwFrameBackground( const SwRect&, const SwPageFrame *pPage,
                           const SwBorderAttrs &,
                           const bool bLowerMode = false,
                           const bool bLowerBorder = false,
-                          const bool bOnlyTextBackground = false ) const;
+                          const bool bOnlyTextBackground = false,
+                          PaintFrameMode eMode = PAINT_ALL ) const;
     void PaintBorderLine( const SwRect&, const SwRect&, const SwPageFrame*,
                           const Color *pColor,
                           const SvxBorderLineStyle = SvxBorderLineStyle::SOLID 
) const;
@@ -849,7 +853,7 @@ public:
                                  SwCursorMoveState* = nullptr, bool 
bTestBackground = false ) const;
     virtual bool    GetCharRect( SwRect &, const SwPosition&,
                                  SwCursorMoveState* = nullptr, bool 
bAllowFarAway = true ) const;
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode eMode = PAINT_ALL ) const;
 
     // HACK: shortcut between frame and formatting
     // It's your own fault if you cast void* incorrectly! In any case check
diff --git a/sw/source/core/inc/layfrm.hxx b/sw/source/core/inc/layfrm.hxx
index bd2c446125b8..a73bf34477d2 100644
--- a/sw/source/core/inc/layfrm.hxx
+++ b/sw/source/core/inc/layfrm.hxx
@@ -96,7 +96,7 @@ public:
 
     SwLayoutFrame( SwFrameFormat*, SwFrame* );
 
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
     const SwFrame *Lower() const { return m_pLower; }
           SwFrame *Lower()       { return m_pLower; }
     bool ContainsDeleteForbiddenLayFrame() const;
diff --git a/sw/source/core/inc/notxtfrm.hxx b/sw/source/core/inc/notxtfrm.hxx
index a7648b6ba5cb..dbd2d3cae1f6 100644
--- a/sw/source/core/inc/notxtfrm.hxx
+++ b/sw/source/core/inc/notxtfrm.hxx
@@ -82,7 +82,7 @@ public:
     virtual bool LeftMargin(SwPaM *) const override;
     virtual bool RightMargin(SwPaM *, bool bAPI = false) const override;
 
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
     virtual bool GetCharRect( SwRect &, const SwPosition&,
                               SwCursorMoveState* = nullptr, bool bAllowFarAway 
= true ) const override;
     virtual bool GetModelPositionForViewPoint(SwPosition* pPos, Point& aPoint,
diff --git a/sw/source/core/inc/rootfrm.hxx b/sw/source/core/inc/rootfrm.hxx
index 96c5d0843f57..82b5743a5a6a 100644
--- a/sw/source/core/inc/rootfrm.hxx
+++ b/sw/source/core/inc/rootfrm.hxx
@@ -240,7 +240,7 @@ public:
     SW_DLLPUBLIC virtual bool GetModelPositionForViewPoint( SwPosition *, 
Point&,
                                SwCursorMoveState* = nullptr, bool 
bTestBackground = false ) const override;
 
-    SW_DLLPUBLIC virtual void PaintSwFrame( vcl::RenderContext& 
rRenderContext, SwRect const& ) const override;
+    SW_DLLPUBLIC virtual void PaintSwFrame( vcl::RenderContext& 
rRenderContext, SwRect const&, PaintFrameMode mode = PAINT_ALL ) const override;
     virtual SwTwips ShrinkFrame( SwTwips, bool bTst = false, bool bInfo = 
false ) override;
     virtual SwTwips GrowFrame  ( SwTwips, bool bTst = false, bool bInfo = 
false ) override;
 #ifdef DBG_UTIL
diff --git a/sw/source/core/inc/tabfrm.hxx b/sw/source/core/inc/tabfrm.hxx
index 80bbcd2b3d2f..f6520b7996d8 100644
--- a/sw/source/core/inc/tabfrm.hxx
+++ b/sw/source/core/inc/tabfrm.hxx
@@ -144,7 +144,7 @@ public:
     inline       SwTabFrame *GetFollow();
     SwTabFrame* FindMaster( bool bFirstMaster = false ) const;
 
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
     virtual void CheckDirection( bool bVert ) override;
 
     virtual void Cut() override;
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index e4b568996b66..768cb6e1c70f 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -419,7 +419,7 @@ public:
 
     void   PaintExtraData( const SwRect & rRect ) const; /// Page number etc.
     SwRect GetPaintSwRect();
-    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const& ) const override;
+    virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect 
const&, PaintFrameMode mode = PAINT_ALL ) const override;
 
     /**
      * Layout oriented cursor travelling:
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index a3c9ac84e7c2..9722a741b2f8 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -427,17 +427,24 @@ void SwFlyFrame::DeleteCnt()
     InvalidatePage();
 }
 
-void SwFlyFrame::InitDrawObj(SwFrame const& rAnchorFrame)
+void SwFlyFrame::InitDrawObj(SwFrame& rAnchorFrame)
 {
     SetDrawObj(*SwFlyDrawContact::CreateNewRef(this, GetFormat(), 
rAnchorFrame));
 
     // Set the right Layer
+    const IDocumentSettingAccess& rIDSA = 
GetFormat()->getIDocumentSettingAccess();
+    bool isPaintHellOverHF = 
rIDSA.get(DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER);
     IDocumentDrawModelAccess& rIDDMA = 
GetFormat()->getIDocumentDrawModelAccess();
     SdrLayerID nHeavenId = rIDDMA.GetHeavenId();
     SdrLayerID nHellId = rIDDMA.GetHellId();
-    GetVirtDrawObj()->SetLayer( GetFormat()->GetOpaque().GetValue()
-                                ? nHeavenId
-                                : nHellId );
+    bool isOpaque = GetFormat()->GetOpaque().GetValue();
+    if (!isOpaque && isPaintHellOverHF)
+    {
+        if (!rAnchorFrame.FindFooterOrHeader())
+            nHellId = rIDDMA.GetHeaderFooterHellId();
+    }
+
+    GetVirtDrawObj()->SetLayer( isOpaque ? nHeavenId :nHellId );
 }
 
 static SwPosition ResolveFlyAnchor(SwFrameFormat const& rFlyFrame)
@@ -1035,9 +1042,18 @@ void SwFlyFrame::UpdateAttr_( const SfxPoolItem *pOld, 
const SfxPoolItem *pNew,
             if ( pSh )
                 pSh->InvalidateWindows( getFrameArea() );
             const IDocumentDrawModelAccess& rIDDMA = 
GetFormat()->getIDocumentDrawModelAccess();
+            const IDocumentSettingAccess& rIDSA = 
GetFormat()->getIDocumentSettingAccess();
+            bool isPaintHellOverHF = 
rIDSA.get(DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER);
+            SdrLayerID nHellId = rIDDMA.GetHellId();
+
+            if (isPaintHellOverHF && !GetAnchorFrame()->FindFooterOrHeader())
+            {
+                nHellId = rIDDMA.GetHeaderFooterHellId();
+            }
+
             const SdrLayerID nId = GetFormat()->GetOpaque().GetValue() ?
                              rIDDMA.GetHeavenId() :
-                             rIDDMA.GetHellId();
+                             nHellId;
             GetVirtDrawObj()->SetLayer( nId );
 
             if ( Lower() )
diff --git a/sw/source/core/layout/paintfrm.cxx 
b/sw/source/core/layout/paintfrm.cxx
index a0d5f0d8a629..47c9b105e10a 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -3269,7 +3269,7 @@ namespace
  * 3. Paint the document content (text)
  * 4. Paint the draw layer that is above the document
 |*/
-void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     OSL_ENSURE( Lower() && Lower()->IsPageFrame(), "Lower of root is no page." 
);
 
@@ -3293,6 +3293,8 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
     else
         SwRootFrame::s_isInPaint = bResetRootPaint = true;
 
+    const IDocumentSettingAccess& rIDSA = 
pSh->GetDoc()->getIDocumentSettingAccess();
+    bool isPaintHellOverHF = 
rIDSA.get(DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER) && 
pSh->Imp()->HasDrawView();
     std::unique_ptr<SwSavePaintStatics> pStatics;
     if ( gProp.pSGlobalShell )
         pStatics.reset(new SwSavePaintStatics());
@@ -3486,9 +3488,24 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
                     gProp.pSLines->LockLines( false );
                 }
 
-                if ( pSh->GetDoc()->GetDocumentSettingManager().get( 
DocumentSettingId::BACKGROUND_PARA_OVER_DRAWINGS ) )
-                    pPage->PaintBaBo( aPaintRect, pPage, 
/*bOnlyTextBackground=*/true );
+                if (isPaintHellOverHF)
+                {
+                    if ( pSh->GetDoc()->GetDocumentSettingManager().get( 
DocumentSettingId::BACKGROUND_PARA_OVER_DRAWINGS ) )
+                        pPage->PaintBaBo( aPaintRect, pPage, 
/*bOnlyTextBackground=*/true, PAINT_HEADER_FOOTER );
+                    pPage->PaintSwFrame(rRenderContext, aPaintRect, 
PAINT_HEADER_FOOTER);
+                    gProp.pSLines->LockLines( true );
+                    const IDocumentDrawModelAccess& rIDDMA = 
pSh->getIDocumentDrawModelAccess();
+                    pSh->Imp()->PaintLayer( rIDDMA.GetHeaderFooterHellId(),
+                                            *pPage, pPage->getFrameArea(),
+                                            &aPageBackgrdColor,
+                                            pPage->IsRightToLeft(),
+                                            &aSwRedirector );
+                    gProp.pSLines->PaintLines( pSh->GetOut(), gProp );
+                    gProp.pSLines->LockLines( false );
+                }
 
+                if ( pSh->GetDoc()->GetDocumentSettingManager().get( 
DocumentSettingId::BACKGROUND_PARA_OVER_DRAWINGS ) )
+                    pPage->PaintBaBo( aPaintRect, pPage, 
/*bOnlyTextBackground=*/true, isPaintHellOverHF ? PAINT_NON_HEADER_FOOTER : 
PAINT_ALL );
                 if( pSh->GetWin() )
                 {
                     // collect sub-lines
@@ -3496,8 +3513,7 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
                     // paint special sub-lines
                     gProp.pSSpecSubsLines->PaintSubsidiary( pSh->GetOut(), 
nullptr, gProp );
                 }
-
-                pPage->PaintSwFrame( rRenderContext, aPaintRect );
+                pPage->PaintSwFrame( rRenderContext, aPaintRect, 
isPaintHellOverHF ? PAINT_NON_HEADER_FOOTER : PAINT_ALL);
 
                 // no paint of page border and shadow, if writer is in place 
mode.
                 if( pSh->GetWin() && pSh->GetDoc()->GetDocShell() &&
@@ -3698,11 +3714,13 @@ SwShortCut::SwShortCut( const SwFrame& rFrame, const 
SwRect& rRect )
     }
 }
 
-void SwLayoutFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwLayoutFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode ePaintFrameMode) const
 {
     // #i16816# tagged pdf support
     Frame_Info aFrameInfo(*this, false);
-    SwTaggedPDFHelper aTaggedPDFHelper( nullptr, &aFrameInfo, nullptr, 
rRenderContext );
+    SwTaggedPDFHelper aTaggedPDFHelper( nullptr,
+        PAINT_HEADER_FOOTER == ePaintFrameMode ? nullptr : &aFrameInfo,
+        nullptr, rRenderContext );
     ::std::optional<SwTaggedPDFHelper> oTaggedLink;
     if (IsFlyFrame())
     {
@@ -3719,6 +3737,10 @@ void SwLayoutFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect cons
     if ( !pFrame )
         return;
 
+    pFrame = SkipFrame(pFrame, ePaintFrameMode);
+    if (!pFrame)
+        return;
+
     SwFrameDeleteGuard g(const_cast<SwLayoutFrame*>(this)); // lock because 
Calc() and recursion
     SwShortCut aShortCut( *pFrame, rRect );
     bool bCnt = pFrame->IsContentFrame();
@@ -3825,6 +3847,7 @@ void SwLayoutFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect cons
             ::lcl_EmergencyFormatFootnoteCont( 
const_cast<SwFootnoteContFrame*>(static_cast<const 
SwFootnoteContFrame*>(pFrame->GetNext())) );
 
         pFrame = pFrame->GetNext();
+        pFrame = SkipFrame(pFrame, ePaintFrameMode);
 
         if ( pFrame )
         {
@@ -4224,7 +4247,7 @@ bool SwFlyFrame::IsPaint( SdrObject *pObj, const 
SwViewShell *pSh )
     return bPaint;
 }
 
-void SwCellFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwCellFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     if ( GetLayoutRowSpan() >= 1 )
         SwLayoutFrame::PaintSwFrame( rRenderContext, rRect );
@@ -4263,7 +4286,7 @@ void SwFrame::SetDrawObjsAsDeleted( bool bDeleted )
     }
 }
 
-void SwFlyFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwFlyFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     //optimize thumbnail generation and store procedure to improve odt saving 
performance, #i120030#
     SwViewShell *pShell = getRootFrame()->GetCurrShell();
@@ -4640,7 +4663,7 @@ void SwTextFrame::PaintOutlineContentVisibilityButton() 
const
         UpdateOutlineContentVisibilityButton(pWrtSh);
 }
 
-void SwTabFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwTabFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     const SwViewOption* pViewOption = gProp.pSGlobalShell->GetViewOptions();
     if (pViewOption->IsTable())
@@ -6667,8 +6690,26 @@ SwRect SwPageFrame::GetBoundRect(OutputDevice const * 
pOutputDevice) const
     return nRet;
 }
 
+const SwFrame* SwFrame::SkipFrame(const SwFrame* pFrame, PaintFrameMode 
ePaintFrameMode )
+{
+    if (ePaintFrameMode != PAINT_ALL)
+    {
+        if (ePaintFrameMode == PAINT_NON_HEADER_FOOTER)
+        {
+            while (pFrame && (pFrame->IsHeaderFrame() || 
pFrame->IsFooterFrame()))
+                pFrame = pFrame->GetNext();
+        }
+        else
+        {
+            while ( pFrame && !pFrame->IsHeaderFrame() && 
!pFrame->IsFooterFrame())
+                pFrame = pFrame->GetNext();
+        }
+    }
+    return pFrame;
+}
+
 void SwFrame::PaintBaBo( const SwRect& rRect, const SwPageFrame *pPage,
-                         const bool bOnlyTextBackground ) const
+                         const bool bOnlyTextBackground, PaintFrameMode 
ePaintFrameMode ) const
 {
     if ( !pPage )
         pPage = FindPageFrame();
@@ -6694,7 +6735,7 @@ void SwFrame::PaintBaBo( const SwRect& rRect, const 
SwPageFrame *pPage,
 
     // paint background
     {
-        PaintSwFrameBackground( rRect, pPage, rAttrs, false, 
true/*bLowerBorder*/, bOnlyTextBackground );
+        PaintSwFrameBackground( rRect, pPage, rAttrs, false, 
true/*bLowerBorder*/, bOnlyTextBackground, ePaintFrameMode );
     }
 
     // paint border before painting background
@@ -6729,7 +6770,8 @@ void SwFrame::PaintSwFrameBackground( const SwRect 
&rRect, const SwPageFrame *pP
                              const SwBorderAttrs & rAttrs,
                              const bool bLowerMode,
                              const bool bLowerBorder,
-                             const bool bOnlyTextBackground ) const
+                             const bool bOnlyTextBackground,
+                             PaintFrameMode ePaintFrameMode) const
 {
     // #i1837# - no paint of table background, if corresponding option is 
*not* set.
     SwViewShell *pSh = gProp.pSGlobalShell;
@@ -6964,6 +7006,11 @@ void SwFrame::PaintSwFrameBackground( const SwRect 
&rRect, const SwPageFrame *pP
     SwRect aRect( GetPaintArea() );
     aRect.Intersection_( rRect );
     SwRect aBorderRect( aRect );
+
+    pFrame = SkipFrame(pFrame, ePaintFrameMode);
+    if (!pFrame)
+        return;
+
     SwShortCut aShortCut( *pFrame, aBorderRect );
     do
     {   if ( gProp.pSProgress )
@@ -6986,6 +7033,7 @@ void SwFrame::PaintSwFrameBackground( const SwRect 
&rRect, const SwPageFrame *pP
             }
         }
         pFrame = pFrame->GetNext();
+        pFrame = SkipFrame(pFrame, ePaintFrameMode);
     } while ( pFrame && pFrame->GetUpper() == this &&
               !aShortCut.Stop( aFrameRect ) );
 }
diff --git a/sw/source/core/layout/unusedf.cxx 
b/sw/source/core/layout/unusedf.cxx
index e26e3a923ab0..d36498b18452 100644
--- a/sw/source/core/layout/unusedf.cxx
+++ b/sw/source/core/layout/unusedf.cxx
@@ -27,7 +27,7 @@ void SwFrame::Format( vcl::RenderContext* /*pRenderContext*/, 
const SwBorderAttr
     OSL_FAIL( "Format() of the base class called." );
 }
 
-void SwFrame::PaintSwFrame(vcl::RenderContext&, SwRect const&) const
+void SwFrame::PaintSwFrame(vcl::RenderContext&, SwRect const&, PaintFrameMode) 
const
 {
     OSL_FAIL( "PaintSwFrame() of the base class called." );
 }
diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx
index 8d20a4bf168b..702f4f048e71 100644
--- a/sw/source/core/text/frmpaint.cxx
+++ b/sw/source/core/text/frmpaint.cxx
@@ -642,7 +642,7 @@ bool SwTextFrame::PaintEmpty( const SwRect &rRect, bool 
bCheck ) const
     return false;
 }
 
-void SwTextFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect) const
+void SwTextFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect 
const& rRect, PaintFrameMode) const
 {
     ResetRepaint();
 
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index 6d679499342d..7b5b8f392630 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1500,9 +1500,12 @@ uno::Any SwXShape::getPropertyValue(const OUString& 
rPropertyName)
                     {
                         SdrObject* pObj = pSvxShape->GetSdrObject();
                         // consider invisible layers
+                        SdrLayerID nLayerId = pObj->GetLayer();
+                        const IDocumentDrawModelAccess& rIDMA = 
pFormat->GetDoc()->getIDocumentDrawModelAccess();
                         aRet <<=
-                            ( pObj->GetLayer() != 
pFormat->GetDoc()->getIDocumentDrawModelAccess().GetHellId() &&
-                              pObj->GetLayer() != 
pFormat->GetDoc()->getIDocumentDrawModelAccess().GetInvisibleHellId() );
+                            ( nLayerId != rIDMA.GetHellId() &&
+                              nLayerId != rIDMA.GetHeaderFooterHellId() &&
+                              nLayerId != rIDMA.GetInvisibleHellId() );
                     }
                 }
                 else if(FN_ANCHOR_POSITION == pEntry->nWID)
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index 524431d21e6c..85d1eee41ece 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -46,6 +46,7 @@
 #include <IDocumentDrawModelAccess.hxx>
 #include <IDocumentLayoutAccess.hxx>
 #include <IDocumentStylePoolAccess.hxx>
+#include <IDocumentSettingAccess.hxx>
 #include <UndoAttribute.hxx>
 #include <docsh.hxx>
 #include <editsh.hxx>
@@ -1376,9 +1377,16 @@ SdrObject 
*SwXFrame::GetOrCreateSdrObject(SwFlyFrameFormat &rFormat)
         pObject = pContactObject->GetMaster();
 
         const ::SwFormatSurround& rSurround = rFormat.GetSurround();
+        const IDocumentSettingAccess& rIDSA = 
pDoc->getIDocumentSettingAccess();
+        bool isPaintHellOverHF = 
rIDSA.get(DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER);
+
+        //TODO: HeaderFooterHellId only appropriate if object is anchored in 
body
         pObject->SetLayer(
             ( css::text::WrapTextMode_THROUGH == rSurround.GetSurround() &&
-              !rFormat.GetOpaque().GetValue() ) ? 
pDoc->getIDocumentDrawModelAccess().GetHellId()
+              !rFormat.GetOpaque().GetValue() )
+                              ? isPaintHellOverHF
+                                    ? 
pDoc->getIDocumentDrawModelAccess().GetHeaderFooterHellId()
+                                    : 
pDoc->getIDocumentDrawModelAccess().GetHellId()
                                              : 
pDoc->getIDocumentDrawModelAccess().GetHeavenId() );
         SwDrawModel* pDrawModel = 
pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
         pDrawModel->GetPage(0)->InsertObject( pObject );
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx 
b/sw/source/filter/ww8/docxsdrexport.cxx
index 4722e7ce4079..70281e4eac7b 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -846,12 +846,11 @@ void DocxSdrExport::startDMLAnchorInline(const 
SwFrameFormat* pFrameFormat, cons
         if (pObj)
         {
             // SdrObjects know their layer, consider that instead of the frame 
format.
-            bOpaque = pObj->GetLayer()
-                          != 
pFrameFormat->GetDoc()->getIDocumentDrawModelAccess().GetHellId()
-                      && pObj->GetLayer()
-                             != pFrameFormat->GetDoc()
-                                    ->getIDocumentDrawModelAccess()
-                                    .GetInvisibleHellId();
+            const IDocumentDrawModelAccess& iDocumentDrawModelAccess
+                = pFrameFormat->GetDoc()->getIDocumentDrawModelAccess();
+            bOpaque = pObj->GetLayer() != iDocumentDrawModelAccess.GetHellId()
+                      && pObj->GetLayer() != 
iDocumentDrawModelAccess.GetHeaderFooterHellId()
+                      && pObj->GetLayer() != 
iDocumentDrawModelAccess.GetInvisibleHellId();
         }
         attrList->add(XML_behindDoc, bOpaque ? "0" : "1");
 
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx 
b/sw/source/filter/ww8/wrtw8esh.cxx
index 21afd78cce1d..5040c190be2a 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2044,6 +2044,7 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat,
     const SdrObject* pObj = rFormat.FindRealSdrObject();
 
     if( pObj && (pObj->GetLayer() == GetHellLayerId() ||
+        pObj->GetLayer() == GetHeaderFooterHellLayerId() ||
         pObj->GetLayer() == GetInvisibleHellId() ) && !(bIsInHeader && 
bIsThrough))
     {
         rPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x200020 );
@@ -2135,6 +2136,7 @@ void SwBasicEscherEx::Init()
     mnEmuDiv = aFact.GetDenominator();
 
     SetHellLayerId(mrWrt.m_rDoc.getIDocumentDrawModelAccess().GetHellId());
+    
SetHeaderFooterHellLayerId(mrWrt.m_rDoc.getIDocumentDrawModelAccess().GetHeaderFooterHellId());
 }
 
 sal_Int32 SwBasicEscherEx::ToFract16(sal_Int32 nVal, sal_uInt32 nMax)
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx 
b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index d4d5e223e602..b46c9c4316ed 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -161,6 +161,7 @@ enum SwDocumentSettingsPropertyHandles
     HANDLE_USE_VARIABLE_WIDTH_NBSP,
     HANDLE_APPLY_TEXT_ATTR_TO_EMPTY_LINE_AT_END_OF_PARAGRAPH,
     HANDLE_DO_NOT_MIRROR_RTL_DRAW_OBJS,
+    HANDLE_PAINT_HELL_OVER_HEADER_FOOTER
 };
 
 }
@@ -268,6 +269,7 @@ static rtl::Reference<MasterPropertySetInfo> 
lcl_createSettingsInfo()
         { OUString("UseVariableWidthNBSP"), HANDLE_USE_VARIABLE_WIDTH_NBSP, 
cppu::UnoType<bool>::get(), 0 },
         { OUString("ApplyTextAttrToEmptyLineAtEndOfParagraph"), 
HANDLE_APPLY_TEXT_ATTR_TO_EMPTY_LINE_AT_END_OF_PARAGRAPH, 
cppu::UnoType<bool>::get(), 0 },
         { OUString("DoNotMirrorRtlDrawObjs"), 
HANDLE_DO_NOT_MIRROR_RTL_DRAW_OBJS, cppu::UnoType<bool>::get(), 0 },
+        { OUString("PaintHellOverHeaderFooter"), 
HANDLE_PAINT_HELL_OVER_HEADER_FOOTER, cppu::UnoType<bool>::get(), 0 },
 
 /*
  * As OS said, we don't have a view when we need to set this, so I have to
@@ -1152,6 +1154,14 @@ void SwXDocumentSettings::_setSingleValue( const 
comphelper::PropertyInfo & rInf
                     DocumentSettingId::USE_VARIABLE_WIDTH_NBSP, bTmp);
         }
         break;
+        case HANDLE_PAINT_HELL_OVER_HEADER_FOOTER:
+        {
+            bool bTmp;
+            if (rValue >>= bTmp)
+                mpDoc->getIDocumentSettingAccess().set(
+                    DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER, bTmp);
+        }
+        break;
         default:
             throw UnknownPropertyException(OUString::number(rInfo.mnHandle));
     }
@@ -1728,6 +1738,12 @@ void SwXDocumentSettings::_getSingleValue( const 
comphelper::PropertyInfo & rInf
                 DocumentSettingId::USE_VARIABLE_WIDTH_NBSP);
         }
         break;
+        case HANDLE_PAINT_HELL_OVER_HEADER_FOOTER:
+        {
+            rValue <<= mpDoc->getIDocumentSettingAccess().get(
+                DocumentSettingId::PAINT_HELL_OVER_HEADER_FOOTER);
+        }
+        break;
         default:
             throw UnknownPropertyException(OUString::number(rInfo.mnHandle));
     }
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index 2912f403234c..25c262b10ad9 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -147,6 +147,8 @@ DomainMapper::DomainMapper( const uno::Reference< 
uno::XComponentContext >& xCon
 
         // Enable only for new documents, since pasting from clipboard can 
influence existing doc
         m_pImpl->SetDocumentSettingsProperty("NoNumberingShowFollowBy", 
uno::Any(true));
+        //paint backgound frames after header/footer when anchored in body
+        
m_pImpl->SetDocumentSettingsProperty("PaintHellOverHeaderFooter",uno::Any(true));
     }
 
     // Initialize RDF metadata, to be able to add statements during the import.
diff --git a/sw/source/writerfilter/filter/WriterFilter.cxx 
b/sw/source/writerfilter/filter/WriterFilter.cxx
index ee8131f95ae3..5faeab2badd5 100644
--- a/sw/source/writerfilter/filter/WriterFilter.cxx
+++ b/sw/source/writerfilter/filter/WriterFilter.cxx
@@ -330,6 +330,8 @@ void WriterFilter::setTargetDocument(const 
uno::Reference<lang::XComponent>& xDo
     xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::Any(true));
     xSettings->setPropertyValue("DisableOffPagePositioning", uno::Any(true));
     xSettings->setPropertyValue("DropCapPunctuation", uno::Any(true));
+    xSettings->setPropertyValue("PaintHellOverHeaderFooter", uno::Any(true));
+
     // rely on default for HyphenateURLs=false
     // rely on default for 
APPLY_TEXT_ATTR_TO_EMPTY_LINE_AT_END_OF_PARAGRAPH=true
     xSettings->setPropertyValue("DoNotMirrorRtlDrawObjs", uno::Any(true));

Reply via email to