Skip to content

Commit 507ac9b

Browse files
committed
sw HTML export: handle field shadings view option
Regardless of the value of the View -> Field Shadings option, shadings were always lost when saving to HTML. Implement handling of this in the HTML conditionally, so in case that UI option is on, then shadings are preserved in the HTML result; disabling that option results in the old behavior, though. Change-Id: I1bd19f4c6e22aff2f84fac25f0a506ad0127cc3c Reviewed-on: https://gerrit.libreoffice.org/69081 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
1 parent 2f7c3cc commit 507ac9b

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed
8.06 KB
Binary file not shown.

sw/qa/extras/htmlexport/htmlexport.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,16 @@ DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt")
670670
assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:h1", "lang");
671671
}
672672

673+
DECLARE_HTMLEXPORT_TEST(testFieldShade, "field-shade.odt")
674+
{
675+
htmlDocPtr pDoc = parseHtml(maTempFile);
676+
CPPUNIT_ASSERT(pDoc);
677+
678+
// Without the accompanying fix in place, this test would have failed with 'Expected: 1; Actual:
679+
// 0', i.e. shading for the field was lost.
680+
assertXPath(pDoc, "/html/body/p[1]/span", "style", "background: #c0c0c0");
681+
}
682+
673683
CPPUNIT_PLUGIN_IMPLEMENT();
674684

675685
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

sw/source/filter/html/css1atr.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ OString lclConvToHex(sal_uInt16 nHex)
184184
return OString(aNToABuf, 2);
185185
}
186186

187-
OString lclGetCSS1Color(const Color& rColor)
188-
{
189-
return "#" + lclConvToHex(rColor.GetRed()) + lclConvToHex(rColor.GetGreen()) + lclConvToHex(rColor.GetBlue());
190-
}
191-
192187
/// Determines if rProperty has to be suppressed due to ReqIF mode.
193188
bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
194189
{
@@ -206,6 +201,11 @@ bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
206201
}
207202
}
208203

204+
OString GetCSS1_Color(const Color& rColor)
205+
{
206+
return "#" + lclConvToHex(rColor.GetRed()) + lclConvToHex(rColor.GetGreen()) + lclConvToHex(rColor.GetBlue());
207+
}
208+
209209
class SwCSS1OutMode
210210
{
211211
SwHTMLWriter& rWrt;
@@ -2232,7 +2232,7 @@ void SwHTMLWriter::OutCSS1_FrameFormatBackground( const SwFrameFormat& rFrameFor
22322232
aColor = pVSh->GetViewOptions()->GetRetoucheColor();
22332233
}
22342234

2235-
OutCSS1_PropertyAscii(sCSS1_P_background, lclGetCSS1Color(aColor));
2235+
OutCSS1_PropertyAscii(sCSS1_P_background, GetCSS1_Color(aColor));
22362236
}
22372237
}
22382238

@@ -2407,7 +2407,7 @@ static Writer& OutCSS1_SvxColor( Writer& rWrt, const SfxPoolItem& rHt )
24072407
if( COL_AUTO == aColor )
24082408
aColor = COL_BLACK;
24092409

2410-
rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, lclGetCSS1Color(aColor));
2410+
rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, GetCSS1_Color(aColor));
24112411

24122412
return rWrt;
24132413
}
@@ -3264,7 +3264,7 @@ static Writer& OutCSS1_SvxBrush( Writer& rWrt, const SfxPoolItem& rHt,
32643264
{
32653265
if( bColor )
32663266
{
3267-
OString sTmp(lclGetCSS1Color(aColor));
3267+
OString sTmp(GetCSS1_Color(aColor));
32683268
sOut += OStringToOUString(sTmp, RTL_TEXTENCODING_ASCII_US);
32693269
}
32703270

@@ -3379,7 +3379,7 @@ static void OutCSS1_SvxBorderLine( SwHTMLWriter& rHTMLWrt,
33793379
sOut.append(' ');
33803380

33813381
// and also the color
3382-
sOut.append(lclGetCSS1Color(pLine->GetColor()));
3382+
sOut.append(GetCSS1_Color(pLine->GetColor()));
33833383

33843384
rHTMLWrt.OutCSS1_PropertyAscii(pProperty, sOut.makeStringAndClear());
33853385
}

sw/source/filter/html/htmlfldw.cxx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
#include <fldbas.hxx>
3333
#include <docufld.hxx>
3434
#include <flddat.hxx>
35+
#include <viewopt.hxx>
3536
#include "htmlfld.hxx"
3637
#include "wrthtml.hxx"
3738
#include <rtl/strbuf.hxx>
3839
#include "css1atr.hxx"
40+
#include "css1kywd.hxx"
3941

4042
using namespace nsSwDocInfoSubType;
4143

@@ -535,8 +537,29 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
535537
const SwTextField *pTextField = rField.GetTextField();
536538
OSL_ENSURE( pTextField, "Where is the txt fld?" );
537539
if( pTextField )
540+
{
541+
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
542+
if (SwViewOption::IsFieldShadings())
543+
{
544+
OStringBuffer sOut;
545+
sOut.append("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span);
546+
sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_style "=\"");
547+
sOut.append(sCSS1_P_background);
548+
sOut.append(": ");
549+
550+
Color& rColor = SwViewOption::GetFieldShadingsColor();
551+
sOut.append(GetCSS1_Color(rColor));
552+
sOut.append("\">");
553+
rWrt.Strm().WriteCharPtr(sOut.getStr());
554+
}
555+
538556
OutHTML_SwField( rWrt, pField, pTextField->GetTextNode(),
539557
pTextField->GetStart() );
558+
559+
if (SwViewOption::IsFieldShadings())
560+
HTMLOutFuncs::Out_AsciiTag(
561+
rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false);
562+
}
540563
}
541564
return rWrt;
542565
}

sw/source/filter/html/wrthtml.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ Writer& OutHTML_NumBulListEnd( SwHTMLWriter& rWrt,
683683

684684
Writer& OutCSS1_SvxBox( Writer& rWrt, const SfxPoolItem& rHt );
685685

686+
OString GetCSS1_Color(const Color& rColor);
687+
686688
#endif // INCLUDED_SW_SOURCE_FILTER_HTML_WRTHTML_HXX
687689

688690
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

0 commit comments

Comments
 (0)