[Libreoffice-commits] core.git: sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Mar 12 10:25:17 UTC 2019


 sw/qa/extras/htmlexport/data/field-shade.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx       |   10 ++++++++++
 sw/source/filter/html/css1atr.cxx            |   18 +++++++++---------
 sw/source/filter/html/htmlfldw.cxx           |   23 +++++++++++++++++++++++
 sw/source/filter/html/wrthtml.hxx            |    2 ++
 5 files changed, 44 insertions(+), 9 deletions(-)

New commits:
commit 507ac9b8c20926de7479213cf2d890bbb5952a1d
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Mar 12 10:21:36 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Mar 12 11:24:53 2019 +0100

    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 at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/htmlexport/data/field-shade.odt b/sw/qa/extras/htmlexport/data/field-shade.odt
new file mode 100644
index 000000000000..38debcb48d0b
Binary files /dev/null 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 c2d8143b67b9..170213e16699 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -670,6 +670,16 @@ DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt")
     assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:h1", "lang");
 }
 
+DECLARE_HTMLEXPORT_TEST(testFieldShade, "field-shade.odt")
+{
+    htmlDocPtr pDoc = parseHtml(maTempFile);
+    CPPUNIT_ASSERT(pDoc);
+
+    // 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");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index a6599a50705d..dd6f6564a4f6 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -184,11 +184,6 @@ OString lclConvToHex(sal_uInt16 nHex)
     return OString(aNToABuf, 2);
 }
 
-OString lclGetCSS1Color(const Color& rColor)
-{
-    return "#" + lclConvToHex(rColor.GetRed()) + lclConvToHex(rColor.GetGreen()) + lclConvToHex(rColor.GetBlue());
-}
-
 /// Determines if rProperty has to be suppressed due to ReqIF mode.
 bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
 {
@@ -206,6 +201,11 @@ bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
 }
 }
 
+OString GetCSS1_Color(const Color& rColor)
+{
+    return "#" + lclConvToHex(rColor.GetRed()) + lclConvToHex(rColor.GetGreen()) + lclConvToHex(rColor.GetBlue());
+}
+
 class SwCSS1OutMode
 {
     SwHTMLWriter& rWrt;
@@ -2232,7 +2232,7 @@ void SwHTMLWriter::OutCSS1_FrameFormatBackground( const SwFrameFormat& rFrameFor
                 aColor = pVSh->GetViewOptions()->GetRetoucheColor();
         }
 
-        OutCSS1_PropertyAscii(sCSS1_P_background, lclGetCSS1Color(aColor));
+        OutCSS1_PropertyAscii(sCSS1_P_background, GetCSS1_Color(aColor));
     }
 }
 
@@ -2407,7 +2407,7 @@ static Writer& OutCSS1_SvxColor( Writer& rWrt, const SfxPoolItem& rHt )
     if( COL_AUTO == aColor )
         aColor = COL_BLACK;
 
-    rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, lclGetCSS1Color(aColor));
+    rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, GetCSS1_Color(aColor));
 
     return rWrt;
 }
@@ -3264,7 +3264,7 @@ static Writer& OutCSS1_SvxBrush( Writer& rWrt, const SfxPoolItem& rHt,
     {
         if( bColor )
         {
-            OString sTmp(lclGetCSS1Color(aColor));
+            OString sTmp(GetCSS1_Color(aColor));
             sOut += OStringToOUString(sTmp, RTL_TEXTENCODING_ASCII_US);
         }
 
@@ -3379,7 +3379,7 @@ static void OutCSS1_SvxBorderLine( SwHTMLWriter& rHTMLWrt,
     sOut.append(' ');
 
     // and also the color
-    sOut.append(lclGetCSS1Color(pLine->GetColor()));
+    sOut.append(GetCSS1_Color(pLine->GetColor()));
 
     rHTMLWrt.OutCSS1_PropertyAscii(pProperty, sOut.makeStringAndClear());
 }
diff --git a/sw/source/filter/html/htmlfldw.cxx b/sw/source/filter/html/htmlfldw.cxx
index 7100a16b6f28..e70e856bae81 100644
--- a/sw/source/filter/html/htmlfldw.cxx
+++ b/sw/source/filter/html/htmlfldw.cxx
@@ -32,10 +32,12 @@
 #include <fldbas.hxx>
 #include <docufld.hxx>
 #include <flddat.hxx>
+#include <viewopt.hxx>
 #include "htmlfld.hxx"
 #include "wrthtml.hxx"
 #include <rtl/strbuf.hxx>
 #include "css1atr.hxx"
+#include "css1kywd.hxx"
 
 using namespace nsSwDocInfoSubType;
 
@@ -535,8 +537,29 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
         const SwTextField *pTextField = rField.GetTextField();
         OSL_ENSURE( pTextField, "Where is the txt fld?" );
         if( pTextField )
+        {
+            SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
+            if (SwViewOption::IsFieldShadings())
+            {
+                OStringBuffer sOut;
+                sOut.append("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span);
+                sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_style "=\"");
+                sOut.append(sCSS1_P_background);
+                sOut.append(": ");
+
+                Color& rColor = SwViewOption::GetFieldShadingsColor();
+                sOut.append(GetCSS1_Color(rColor));
+                sOut.append("\">");
+                rWrt.Strm().WriteCharPtr(sOut.getStr());
+            }
+
             OutHTML_SwField( rWrt, pField, pTextField->GetTextNode(),
                              pTextField->GetStart()  );
+
+            if (SwViewOption::IsFieldShadings())
+                HTMLOutFuncs::Out_AsciiTag(
+                    rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false);
+        }
     }
     return rWrt;
 }
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index e06c4190aa4d..9c96d8680232 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -683,6 +683,8 @@ Writer& OutHTML_NumBulListEnd( SwHTMLWriter& rWrt,
 
 Writer& OutCSS1_SvxBox( Writer& rWrt, const SfxPoolItem& rHt );
 
+OString GetCSS1_Color(const Color& rColor);
+
 #endif // INCLUDED_SW_SOURCE_FILTER_HTML_WRTHTML_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list