Skip to content

Commit

Permalink
sw HTML export, field shadings: give text portion background priority
Browse files Browse the repository at this point in the history
If the user explicitly gives a background color to the field portion,
then respect that, don't overwrite with the field shading (the UI does
the same).

Change-Id: I7c35618f82a37ef1dd16c03b82651268767813af
Reviewed-on: https://gerrit.libreoffice.org/69127
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
  • Loading branch information
vmiklos committed Mar 12, 2019
1 parent bdbe84b commit ce01727
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Binary file modified sw/qa/extras/htmlexport/data/field-shade.odt
Binary file not shown.
6 changes: 6 additions & 0 deletions sw/qa/extras/htmlexport/htmlexport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions sw/source/filter/html/htmlatr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 );
}
Expand Down
13 changes: 11 additions & 2 deletions sw/source/filter/html/htmlfldw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,16 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
if( pTextField )
{
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(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);
Expand All @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions sw/source/filter/html/wrthtml.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <memory>
#include <vector>
#include <set>
#include <map>

#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/form/XForm.hpp>
Expand Down Expand Up @@ -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<sal_uInt16, int> maStartedAttributes;

explicit SwHTMLWriter( const OUString& rBaseURL );
virtual ~SwHTMLWriter() override;

Expand Down

0 comments on commit ce01727

Please sign in to comment.