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

sw reqif-xhtml export: limit values of the style attribute

The ReqIF spec (v1.2, page 56) says that on import only these attributes
should be considered, so it's pointless to write them (even if doing so
is not strictly invalid).

This more general approach also means that the earlier merging that was
specific to tables in commit c0149b1c
(sw XHTML export: fix duplicated style attribute for table
border/background, 2018-03-20) is no longer needed.

Change-Id: I340e6a9f726f42072bf1aaa49ea72162004e5493
Reviewed-on: https://gerrit.libreoffice.org/52725Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst adc10e62
......@@ -468,12 +468,9 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable, "reqif-table.xhtml")
// <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.
CPPUNIT_ASSERT(aStyle.indexOf("border") != -1);
// The attribute was present to contain "background" and "border", which is
// ignored in reqif-xhtml.
assertXPathNoAttribute(pDoc, "/html/body/div/table/tr/th", "style");
// The attribute was present, which is not valid in reqif-xhtml.
assertXPathNoAttribute(pDoc, "/html/body/div/table/tr/th", "bgcolor");
}
......@@ -488,6 +485,10 @@ DECLARE_HTMLEXPORT_TEST(testReqIfList, "reqif-list.xhtml")
OString aStream(read_uInt8s_ToOString(*pStream, nLength));
// This failed, <ul> was written.
CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:ul>") != -1);
// This failed, the 'style' attribute was written, even if the input did
// not had one.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aStream.indexOf(" style=\""));
}
DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOle2, "reqif-ole2.xhtml")
......
......@@ -190,6 +190,21 @@ 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)
{
if (!bReqIF)
return false;
// Only allow these two keys, nothing else in ReqIF mode.
if (rProperty == sCSS1_P_text_decoration)
return false;
if (rProperty == sCSS1_P_color)
return false;
return true;
}
}
class SwCSS1OutMode
......@@ -220,6 +235,9 @@ void SwHTMLWriter::OutCSS1_Property( const sal_Char *pProp,
const sal_Char *pVal,
const OUString *pSVal )
{
if (IgnorePropertyForReqIF(mbReqIF, pProp))
return;
OStringBuffer sOut;
if( m_bFirstCSS1Rule && (m_nCSS1OutMode & CSS1_OUTMODE_RULE_ON)!=0 )
......@@ -1818,7 +1836,7 @@ Writer& OutCSS1_ParaTagStyleOpt( Writer& rWrt, const SfxItemSet& rItemSet )
}
// Wrapper for Table background
Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt, bool bClose )
Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt )
{
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
......@@ -1827,7 +1845,7 @@ Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt, bool bClo
CSS1_OUTMODE_TABLEBOX, nullptr );
OutCSS1_SvxBrush( rWrt, rHt, Css1Background::Table, nullptr );
if( !rHTMLWrt.m_bFirstCSS1Property && bClose )
if( !rHTMLWrt.m_bFirstCSS1Property )
rWrt.Strm().WriteChar( '\"' );
return rWrt;
......@@ -2085,19 +2103,12 @@ void SwHTMLWriter::OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameF
Strm().WriteChar( '\"' );
}
void SwHTMLWriter::OutCSS1_TableCellBorderHack(SwFrameFormat const& rFrameFormat, bool bClose)
void SwHTMLWriter::OutCSS1_TableCellBorderHack(SwFrameFormat const& rFrameFormat)
{
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 && bClose)
if (!m_bFirstCSS1Property)
{
Strm().WriteChar( cCSS1_style_opt_end );
}
......
......@@ -410,7 +410,6 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
if( !pBrushItem )
pBrushItem = pCell->GetBackground();
// Start writing the style attribute.
if( pBrushItem )
{
// output background
......@@ -419,14 +418,10 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
rWrt.OutBackground( pBrushItem, false );
if( rWrt.m_bCfgOutStyles )
OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem, /*bClose=*/false );
OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem );
}
rWrt.OutCSS1_TableCellBorderHack(*pBox->GetFrameFormat(), /*bClose=*/false);
// Now is the time to end the style attribute.
if (!rWrt.m_bFirstCSS1Property)
rWrt.Strm().WriteChar('\"');
rWrt.OutCSS1_TableCellBorderHack(*pBox->GetFrameFormat());
sal_uInt32 nNumFormat = 0;
double nValue = 0.0;
......@@ -530,7 +525,7 @@ void SwHTMLWrtTable::OutTableCells( SwHTMLWriter& rWrt,
rWrt.m_bTextAttr = false;
rWrt.m_bOutOpts = true;
if( rWrt.m_bCfgOutStyles )
OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem, /*bClose=*/true );
OutCSS1_TableBGStyleOpt( rWrt, *pBrushItem );
}
if( text::VertOrientation::TOP==eRowVertOri || text::VertOrientation::BOTTOM==eRowVertOri )
......
......@@ -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, bool bClose);
void OutCSS1_TableCellBorderHack(const SwFrameFormat& rFrameFormat);
void OutCSS1_SectionFormatOptions( const SwFrameFormat& rFrameFormat, const SwFormatCol *pCol );
void OutCSS1_FrameFormatOptions( const SwFrameFormat& rFrameFormat, HtmlFrmOpts nFrameOpts,
const SdrObject *pSdrObj=nullptr,
......@@ -675,7 +675,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, bool bClose );
Writer& OutCSS1_TableBGStyleOpt( Writer& rWrt, const SfxPoolItem& rHt );
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