sw/qa/extras/htmlexport/data/reqif-table.xhtml | 9 +++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 13 +++++++++++++ sw/source/filter/html/css1atr.cxx | 15 +++++++++++---- sw/source/filter/html/htmltabw.cxx | 11 ++++++++--- sw/source/filter/html/wrthtml.hxx | 4 ++-- 5 files changed, 43 insertions(+), 9 deletions(-)
New commits: commit c0149b1c028450411d36457593f4af3406541b00 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Mar 20 12:19:27 2018 +0100 sw XHTML export: fix duplicated style attribute for table border/background By making sure only border starts the style attribute, neither of them closes it, and then closing it manually after both finished. It seems that HtmlTestTools::parseHtml() is flexible enough that it can take a HTML fragment that has multiple root elements, so no need to wrap the fragment in some <html><body>...</body><html> template for test purposes. Change-Id: I32622b17da0fc8ac02a045b3569e34a41419927d Reviewed-on: https://gerrit.libreoffice.org/51631 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/sw/qa/extras/htmlexport/data/reqif-table.xhtml b/sw/qa/extras/htmlexport/data/reqif-table.xhtml new file mode 100644 index 000000000000..1bf1f0d93707 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/reqif-table.xhtml @@ -0,0 +1,9 @@ +<reqif-xhtml:div><table border="1" style="width:100%"> + <tr> + <th bgcolor="#888888">A1</th> + </tr> + <tr> + <td>A2</td> + </tr> +</table> +</reqif-xhtml:div> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 4777e8945b8a..fcb073cbcd8b 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -457,6 +457,19 @@ DECLARE_HTMLEXPORT_TEST(testReqIfJpgImg, "reqif-jpg-img.xhtml") CPPUNIT_ASSERT(aStream.indexOf("type=\"image/png\"") != -1); } +DECLARE_HTMLEXPORT_TEST(testReqIfTable, "reqif-table.xhtml") +{ + htmlDocPtr pDoc = parseHtml(maTempFile); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/html/body/table/tr/th", 1); + OUString aStyle = getXPath(pDoc, "/html/body/table/tr/th", "style"); + CPPUNIT_ASSERT(aStyle.indexOf("background") != -1); + // This failed, there were 2 style attributes, so as a best effort the + // parser took the value of the first. + CPPUNIT_ASSERT(aStyle.indexOf("border") != -1); +} + 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 9a8acd083eac..b3125aff5e75 100644 --- a/sw/source/filter/html/css1atr.cxx +++ b/sw/source/filter/html/css1atr.cxx @@ -1818,7 +1818,7 @@ Writer& OutCSS1_ParaTagStyleOpt( Writer& rWrt, const SfxItemSet& rItemSet ) } // Wrapper for Table background -Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt ) +Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt, bool bClose ) { SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt); @@ -1827,7 +1827,7 @@ Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt ) CSS1_OUTMODE_TABLEBOX, nullptr ); OutCSS1_SvxBrush( rWrt, rHt, Css1Background::Table, nullptr ); - if( !rHTMLWrt.m_bFirstCSS1Property ) + if( !rHTMLWrt.m_bFirstCSS1Property && bClose ) rWrt.Strm().WriteChar( '\"' ); return rWrt; @@ -2085,12 +2085,19 @@ void SwHTMLWriter::OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameF Strm().WriteChar( '\"' ); } -void SwHTMLWriter::OutCSS1_TableCellBorderHack(SwFrameFormat const& rFrameFormat) +void SwHTMLWriter::OutCSS1_TableCellBorderHack(SwFrameFormat const& rFrameFormat, bool bClose) { + bool bFirstCSS1Property = m_bFirstCSS1Property; + SwCSS1OutMode const aMode( *this, CSS1_OUTMODE_STYLE_OPT_ON|CSS1_OUTMODE_ENCODE|CSS1_OUTMODE_TABLEBOX, nullptr ); + + if (!bFirstCSS1Property) + // Don't start the style attribute again if it was started already. + m_bFirstCSS1Property = bFirstCSS1Property; + OutCSS1_SvxBox(*this, rFrameFormat.GetBox()); - if (!m_bFirstCSS1Property) + if (!m_bFirstCSS1Property && bClose) { Strm().WriteChar( cCSS1_style_opt_end ); } diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx index f856af17eac4..ba95d41dbf15 100644 --- a/sw/source/filter/html/htmltabw.cxx +++ b/sw/source/filter/html/htmltabw.cxx @@ -410,16 +410,21 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt, if( !pBrushItem ) pBrushItem = pCell->GetBackground(); + // Start writing the style attribute. if( pBrushItem ) { // output background rWrt.OutBackground( pBrushItem, false ); if( rWrt.m_bCfgOutStyles ) - OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem ); + OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem, /*bClose=*/false ); } - rWrt.OutCSS1_TableCellBorderHack(*pBox->GetFrameFormat()); + rWrt.OutCSS1_TableCellBorderHack(*pBox->GetFrameFormat(), /*bClose=*/false); + + // Now is the time to end the style attribute. + if (!rWrt.m_bFirstCSS1Property) + rWrt.Strm().WriteChar('\"'); sal_uInt32 nNumFormat = 0; double nValue = 0.0; @@ -523,7 +528,7 @@ void SwHTMLWrtTable::OutTableCells( SwHTMLWriter& rWrt, rWrt.m_bTextAttr = false; rWrt.m_bOutOpts = true; if( rWrt.m_bCfgOutStyles ) - OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem ); + OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem, /*bClose=*/true ); } if( text::VertOrientation::TOP==eRowVertOri || text::VertOrientation::BOTTOM==eRowVertOri ) diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 6251405bef52..639f07103ccd 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -474,7 +474,7 @@ public: void writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAltText, HtmlFrmOpts nFrameOpts); void OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameFormat ); - void OutCSS1_TableCellBorderHack(const SwFrameFormat& rFrameFormat); + void OutCSS1_TableCellBorderHack(const SwFrameFormat& rFrameFormat, bool bClose); void OutCSS1_SectionFormatOptions( const SwFrameFormat& rFrameFormat, const SwFormatCol *pCol ); void OutCSS1_FrameFormatOptions( const SwFrameFormat& rFrameFormat, HtmlFrmOpts nFrameOpts, const SdrObject *pSdrObj=nullptr, @@ -672,7 +672,7 @@ Writer& OutCSS1_ParaTagStyleOpt( Writer& rWrt, const SfxItemSet& rItemSet ); Writer& OutCSS1_HintSpanTag( Writer& rWrt, const SfxPoolItem& rHt ); Writer& OutCSS1_HintStyleOpt( Writer& rWrt, const SfxPoolItem& rHt ); -Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt ); +Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt, bool bClose ); Writer& OutCSS1_NumBulListStyleOpt( Writer& rWrt, const SwNumRule& rNumRule, sal_uInt8 nLevel ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits