sw/qa/extras/htmlexport/data/reqif-table.xhtml | 9 +++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 21 ++++++++++++++++++++- sw/source/filter/html/css1atr.cxx | 15 +++++++++++---- sw/source/filter/html/htmltabw.cxx | 15 +++++++++++---- sw/source/filter/html/wrthtml.cxx | 6 ++++++ sw/source/filter/html/wrthtml.hxx | 4 ++-- 6 files changed, 59 insertions(+), 11 deletions(-)
New commits: commit 1b444e839c62ade6d5f4177cbee87fe50b71c547 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Mar 20 17:48:58 2018 +0100 sw XHTML export: write only CSS markup for table background At least in the ReqIF case the bgcolor attribute is not only redundant but is also invalid. Reviewed-on: https://gerrit.libreoffice.org/51657 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> (cherry picked from commit e2076f48aef4aff9a90ae8581d3bde7c26c69ef1) Conflicts: sw/source/filter/html/htmltabw.cxx Change-Id: I9b5f00a4885d0671668b6bab986c4aee00f3597b diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index ba2fafbc5876..0cac2dad965c 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -471,6 +471,9 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable, "reqif-table.xhtml") // 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); + + // The attribute was present, which is not valid in reqif-xhtml. + assertXPathNoAttribute(pDoc, "/html/body/div/table/tr/th", "bgcolor"); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx index 853bf8ce7d24..89aacba1ad31 100644 --- a/sw/source/filter/html/htmltabw.cxx +++ b/sw/source/filter/html/htmltabw.cxx @@ -420,7 +420,9 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt, if( pBrushItem ) { // Hintergrund ausgeben - rWrt.OutBackground( pBrushItem, false ); + if (!rWrt.mbReqIF) + // Avoid non-CSS version in the ReqIF case. + rWrt.OutBackground( pBrushItem, false ); if( rWrt.m_bCfgOutStyles ) OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem, /*bClose=*/false ); commit 4b8888909600d25ef4ce3485b49546a9d259d939 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Mar 20 14:58:19 2018 +0100 sw XHTML import: write <div> wrapper in ReqIF mode ReqIF says the XHTML fragment must be of type xhtml.BlkStruct.class, which is either a <p> or a <div> element (a single one). Just write this wrapper unconditionally, as we ignore it on import anyway, and it could be skipped only in the single-paragraph-doc case. Change-Id: I3051008866c4a28ce54413c73071bd4a5ced8b87 Reviewed-on: https://gerrit.libreoffice.org/51646 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> (cherry picked from commit f74d9ba2190426b974ca3d56da58919ac233a5d3) diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index f13946edc65f..ba2fafbc5876 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -341,7 +341,8 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml") sal_uInt64 nLength = pStream->Tell(); pStream->Seek(0); - OString aExpected("<reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb</reqif-xhtml:p>" SAL_NEWLINE_STRING); + OString aExpected("<reqif-xhtml:div><reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb" + "</reqif-xhtml:p>" SAL_NEWLINE_STRING); // This was '<table' instead. aExpected += "<reqif-xhtml:table"; @@ -462,8 +463,10 @@ 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"); + // <div> was missing, so the XHTML fragment wasn't a valid + // xhtml.BlkStruct.class type anymore. + assertXPath(pDoc, "/html/body/div/table/tr/th", 1); + OUString aStyle = getXPath(pDoc, "/html/body/div/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. diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 9169c403ada7..42ec9956ef9e 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -452,6 +452,9 @@ sal_uLong SwHTMLWriter::WriteStream() OutNewLine(); HTMLOutFuncs::Out_AsciiTag( Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_html, false ); } + else if (mbReqIF) + // ReqIF: end xhtml.BlkStruct.class. + HTMLOutFuncs::Out_AsciiTag(Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_division, false); // delete the table with floating frames OSL_ENSURE( !m_pHTMLPosFlyFrames, "Were not all frames output?" ); @@ -1078,6 +1081,9 @@ const SwPageDesc *SwHTMLWriter::MakeHeader( sal_uInt16 &rHeaderAttrs ) Strm().WriteChar( '>' ); } + else if (mbReqIF) + // ReqIF: start xhtml.BlkStruct.class. + HTMLOutFuncs::Out_AsciiTag(Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_division); return pPageDesc; } commit d594ff2b59c9782d25a7cc573d8642eac9b08fde 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> (cherry picked from commit c0149b1c028450411d36457593f4af3406541b00) 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 8f031d7346ce..f13946edc65f 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 fc83048a3697..d02f3e05deb6 100644 --- a/sw/source/filter/html/css1atr.cxx +++ b/sw/source/filter/html/css1atr.cxx @@ -1824,7 +1824,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); @@ -1833,7 +1833,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; @@ -2091,12 +2091,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) { this->Strm().WriteChar( cCSS1_style_opt_end ); } diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx index cd9fba58722d..853bf8ce7d24 100644 --- a/sw/source/filter/html/htmltabw.cxx +++ b/sw/source/filter/html/htmltabw.cxx @@ -416,16 +416,21 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt, if( !pBrushItem ) pBrushItem = pCell->GetBackground(); + // Start writing the style attribute. if( pBrushItem ) { // Hintergrund ausgeben 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; @@ -530,7 +535,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 ec74dcf414dd..e92cf9673cee 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -477,7 +477,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, @@ -676,7 +676,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