diff --git a/sw/qa/extras/htmlexport/data/field-shade.odt b/sw/qa/extras/htmlexport/data/field-shade.odt index 38debcb48d0b7..2533be68c49e3 100644 Binary files a/sw/qa/extras/htmlexport/data/field-shade.odt and b/sw/qa/extras/htmlexport/data/field-shade.odt differ diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 170213e166996..1f016f52409aa 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -678,6 +678,12 @@ DECLARE_HTMLEXPORT_TEST(testFieldShade, "field-shade.odt") // Without the accompanying fix in place, this test would have failed with 'Expected: 1; Actual: // 0', i.e. shading for the field was lost. assertXPath(pDoc, "/html/body/p[1]/span", "style", "background: #c0c0c0"); + + // Check that field shading is written only in case there is no user-defined span background. + assertXPath(pDoc, "/html/body/p[2]/span", "style", "background: #ff0000"); + // Without the accompanying fix in place, this test would have failed with 'Expected: 0; Actual: + // 1', i.e there was an inner span hiding the wanted background color. + assertXPath(pDoc, "/html/body/p[2]/span/span", 0); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 50a7562cb8585..d73f915725134 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -1931,6 +1931,7 @@ void HTMLEndPosLst::OutStartAttrs( SwHTMLWriter& rHWrt, sal_Int32 nPos, pContext = nullptr; // one time only } Out( aHTMLAttrFnTab, *pPos->GetItem(), rHWrt ); + rHWrt.maStartedAttributes[pPos->GetItem()->Which()]++; rHWrt.m_nCSS1Script = nCSS1Script; } } @@ -1981,6 +1982,7 @@ void HTMLEndPosLst::OutEndAttrs( SwHTMLWriter& rHWrt, sal_Int32 nPos, if( !bSkipOut ) { Out( aHTMLAttrFnTab, *pPos->GetItem(), rHWrt ); + rHWrt.maStartedAttributes[pPos->GetItem()->Which()]--; } RemoveItem_( i ); } diff --git a/sw/source/filter/html/htmlfldw.cxx b/sw/source/filter/html/htmlfldw.cxx index e70e856bae819..0ad1b55d5db7a 100644 --- a/sw/source/filter/html/htmlfldw.cxx +++ b/sw/source/filter/html/htmlfldw.cxx @@ -539,7 +539,16 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt ) if( pTextField ) { SwHTMLWriter& rHTMLWrt = static_cast(rWrt); - if (SwViewOption::IsFieldShadings()) + bool bFieldShadings = SwViewOption::IsFieldShadings(); + if (bFieldShadings) + { + // If there is a text portion background started already, that should have priority. + auto it = rHTMLWrt.maStartedAttributes.find(RES_CHRATR_BACKGROUND); + if (it != rHTMLWrt.maStartedAttributes.end()) + bFieldShadings = it->second <= 0; + } + + if (bFieldShadings) { OStringBuffer sOut; sOut.append("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span); @@ -556,7 +565,7 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt ) OutHTML_SwField( rWrt, pField, pTextField->GetTextNode(), pTextField->GetStart() ); - if (SwViewOption::IsFieldShadings()) + if (bFieldShadings) HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false); } diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 9c96d8680232e..b92b95f70e27c 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -398,6 +399,9 @@ public: bool m_bParaDotLeaders : 1; // for TOC dot leaders // 25 + /// Tracks which text portion attributes are currently open: a which id -> open count map. + std::map maStartedAttributes; + explicit SwHTMLWriter( const OUString& rBaseURL ); virtual ~SwHTMLWriter() override;