sw/qa/extras/htmlexport/data/field-shade.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx       |   16 +++++++++++++
 sw/source/core/txtnode/txatbase.cxx          |   18 +++++++++++++--
 sw/source/filter/html/css1atr.cxx            |   18 +++++++--------
 sw/source/filter/html/htmlatr.cxx            |    2 +
 sw/source/filter/html/htmlfldw.cxx           |   32 +++++++++++++++++++++++++++
 sw/source/filter/html/wrthtml.hxx            |    6 +++++
 7 files changed, 81 insertions(+), 11 deletions(-)

New commits:
commit b2151cd207dac9a1bd48265160fde8d53fe3ac3f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Mar 12 18:43:43 2019 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 13 11:11:49 2019 +0100

    sw HTML export, field shadings: give text portion background priority
    
    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 <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit ce01727e4d6779ea128aa1be09f4af8cad4e1854)

diff --git a/sw/qa/extras/htmlexport/data/field-shade.odt 
b/sw/qa/extras/htmlexport/data/field-shade.odt
index 38debcb48d0b..2533be68c49e 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 6d577c9ea4b2..6944a8991c07 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -694,6 +694,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 137febd1d86a..b765e4967f0a 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 a4921bd0ec93..e2ac83f39df9 100644
--- a/sw/source/filter/html/htmlfldw.cxx
+++ b/sw/source/filter/html/htmlfldw.cxx
@@ -538,7 +538,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);
@@ -555,7 +564,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 c6979959d3c7..e1097cb23b25 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -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>
@@ -405,6 +406,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;
 
commit ce4ce51fb86ef3a4f0debaa5ef33ee956f7ef5bf
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Mar 12 10:21:36 2019 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 13 11:10:42 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.
    
    Reviewed-on: https://gerrit.libreoffice.org/69081
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 507ac9b8c20926de7479213cf2d890bbb5952a1d)
    
    Conflicts:
            sw/source/filter/html/htmlfldw.cxx
    
    Change-Id: I1bd19f4c6e22aff2f84fac25f0a506ad0127cc3c

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 95ed4ba88a2a..6d577c9ea4b2 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -686,6 +686,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 71af340d119b..94dd953bd221 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -186,11 +186,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)
 {
@@ -208,6 +203,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;
@@ -2239,7 +2239,7 @@ void SwHTMLWriter::OutCSS1_FrameFormatBackground( const 
SwFrameFormat& rFrameFor
                 aColor = pVSh->GetViewOptions()->GetRetoucheColor().GetColor();
         }
 
-        OutCSS1_PropertyAscii(sCSS1_P_background, lclGetCSS1Color(aColor));
+        OutCSS1_PropertyAscii(sCSS1_P_background, GetCSS1_Color(aColor));
     }
 }
 
@@ -2414,7 +2414,7 @@ static Writer& OutCSS1_SvxColor( Writer& rWrt, const 
SfxPoolItem& rHt )
     if( COL_AUTO == aColor.GetColor() )
         aColor.SetColor( COL_BLACK );
 
-    rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, lclGetCSS1Color(aColor));
+    rHTMLWrt.OutCSS1_PropertyAscii(sCSS1_P_color, GetCSS1_Color(aColor));
 
     return rWrt;
 }
@@ -3275,7 +3275,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);
         }
 
@@ -3390,7 +3390,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 788b8f202bf4..a4921bd0ec93 100644
--- a/sw/source/filter/html/htmlfldw.cxx
+++ b/sw/source/filter/html/htmlfldw.cxx
@@ -30,10 +30,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;
 
@@ -534,8 +536,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 7ce840b34d7e..c6979959d3c7 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -690,6 +690,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: */
commit 24cdbc6736940fef43d90671301615dba06d2f8c
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Mar 11 16:11:03 2019 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 13 11:08:18 2019 +0100

    sw doc model xml dump: show text node's field hints
    
    Change-Id: I17927231da389ce54d2fb8ade0091c7e7033a808
    Reviewed-on: https://gerrit.libreoffice.org/69049
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 99f25bc344e931e66366e20664a23dc263fe3113)

diff --git a/sw/source/core/txtnode/txatbase.cxx 
b/sw/source/core/txtnode/txatbase.cxx
index 41179576cadf..842ce5d67777 100644
--- a/sw/source/core/txtnode/txatbase.cxx
+++ b/sw/source/core/txtnode/txatbase.cxx
@@ -122,6 +122,11 @@ void SwTextAttr::dumpAsXml(xmlTextWriterPtr pWriter) const
             pWhich = "meta";
             break;
         }
+    case RES_TXTATR_FIELD:
+        {
+            pWhich = "field";
+            break;
+        }
     default:
         break;
     }
@@ -129,8 +134,17 @@ void SwTextAttr::dumpAsXml(xmlTextWriterPtr pWriter) const
         xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), 
BAD_CAST(pWhich));
     if (oValue)
         xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), 
BAD_CAST(oValue->getStr()));
-    if (Which() == RES_TXTATR_AUTOFMT)
-        GetAutoFormat().dumpAsXml(pWriter);
+    switch (Which())
+    {
+        case RES_TXTATR_AUTOFMT:
+            GetAutoFormat().dumpAsXml(pWriter);
+            break;
+        case RES_TXTATR_FIELD:
+            GetFormatField().dumpAsXml(pWriter);
+            break;
+        default:
+            break;
+    }
 
     xmlTextWriterEndElement(pWriter);
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to