Kaydet (Commit) c0149b1c authored tarafından Miklos Vajna's avatar Miklos Vajna

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/51631Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 4b785097
<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>
......@@ -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: */
......@@ -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 );
}
......
......@@ -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 )
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment