[Libreoffice-commits] core.git: sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Mar 9 16:41:24 UTC 2018
sw/qa/extras/htmlexport/htmlexport.cxx | 13 +++++++++++++
sw/source/filter/html/htmlflywriter.cxx | 21 ++++++++++++---------
sw/source/filter/html/wrthtml.cxx | 3 +++
sw/source/filter/html/wrthtml.hxx | 2 ++
4 files changed, 30 insertions(+), 9 deletions(-)
New commits:
commit 7a644e363a8c2156b7e1202c0a2ff518ec11b027
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Mar 9 16:40:42 2018 +0100
sw XHTML export: handle image as <object>
At least in ReqIF mode, where <img> is not part of the allowed subset.
(Freeware validator for that subset is at
<https://reqif.academy/library/software/consequent-command-line/>.)
Change-Id: Iecc2645c5fbd35cc52096a25a797df0594b47d4f
Reviewed-on: https://gerrit.libreoffice.org/51009
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 1fcb66d5e4b7..5c8f5cfaf5f1 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -409,6 +409,19 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml")
// This was Object1, PNG without fallback was imported as OLE object.
CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xShape->getName());
+
+ if (!mbExported)
+ return;
+
+ // This was <img>, not <object>, which is not valid in the reqif-xhtml
+ // subset.
+ SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
+ CPPUNIT_ASSERT(pStream);
+ pStream->Seek(STREAM_SEEK_TO_END);
+ sal_uInt64 nLength = pStream->Tell();
+ pStream->Seek(0);
+ OString aStream(read_uInt8s_ToOString(*pStream, nLength));
+ CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:object") != -1);
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 985f8fd11977..30888b2e9d97 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -803,12 +803,13 @@ OString SwHTMLWriter::OutFrameFormatOptions( const SwFrameFormat &rFrameFormat,
void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAlternateText, HtmlFrmOpts nFrameOptions)
{
+ bool bReplacement = (nFrameOptions & HtmlFrmOpts::Replacement) || mbReqIF;
const SfxPoolItem* pItem;
const SfxItemSet& rItemSet = rFrameFormat.GetAttrSet();
// Name
if( (nFrameOptions & (HtmlFrmOpts::Id|HtmlFrmOpts::Name)) &&
- !rFrameFormat.GetName().isEmpty() && !(nFrameOptions & HtmlFrmOpts::Replacement))
+ !rFrameFormat.GetName().isEmpty() && !bReplacement)
{
const sal_Char* pAttributeName = (nFrameOptions & HtmlFrmOpts::Id) ? OOO_STRING_SVTOOLS_HTML_O_id : OOO_STRING_SVTOOLS_HTML_O_name;
aHtml.attribute(pAttributeName, rFrameFormat.GetName());
@@ -823,7 +824,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
}
// alt
- if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.isEmpty() && !(nFrameOptions & HtmlFrmOpts::Replacement) )
+ if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.isEmpty() && !bReplacement )
{
aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_alt, rAlternateText);
}
@@ -832,7 +833,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
const sal_Char* pAlignString = nullptr;
RndStdIds eAnchorId = rFrameFormat.GetAnchor().GetAnchorId();
if( (nFrameOptions & HtmlFrmOpts::Align) &&
- ((RndStdIds::FLY_AT_PARA == eAnchorId) || (RndStdIds::FLY_AT_CHAR == eAnchorId)) && !(nFrameOptions & HtmlFrmOpts::Replacement))
+ ((RndStdIds::FLY_AT_PARA == eAnchorId) || (RndStdIds::FLY_AT_CHAR == eAnchorId)) && !bReplacement)
{
const SwFormatHoriOrient& rHoriOri = rFrameFormat.GetHoriOrient();
if( !(nFrameOptions & HtmlFrmOpts::SAlign) ||
@@ -863,7 +864,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
case text::VertOrientation::NONE: break;
}
}
- if (pAlignString && !(nFrameOptions & HtmlFrmOpts::Replacement))
+ if (pAlignString && !bReplacement)
{
aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_align, pAlignString);
}
@@ -1205,6 +1206,8 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
const ImageMap *pAltImgMap )
{
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
+ // <object data="..."> instead of <img src="...">
+ bool bReplacement = (nFrameOpts & HtmlFrmOpts::Replacement) || rHTMLWrt.mbReqIF;
if (rHTMLWrt.mbSkipImages)
return rHTMLWrt;
@@ -1357,7 +1360,7 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
}
OString aTag(OOO_STRING_SVTOOLS_HTML_image);
- if (nFrameOpts & HtmlFrmOpts::Replacement)
+ if (bReplacement)
// Write replacement graphic of OLE object as <object>.
aTag = OOO_STRING_SVTOOLS_HTML_object;
aHtml.start(aTag);
@@ -1380,12 +1383,12 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
{
sBuffer.append(OUStringToOString(aGraphicURL, RTL_TEXTENCODING_UTF8));
OString aAttribute(OOO_STRING_SVTOOLS_HTML_O_src);
- if (nFrameOpts & HtmlFrmOpts::Replacement)
+ if (bReplacement)
aAttribute = OOO_STRING_SVTOOLS_HTML_O_data;
aHtml.attribute(aAttribute, sBuffer.makeStringAndClear().getStr());
}
- if (nFrameOpts & HtmlFrmOpts::Replacement)
+ if (bReplacement)
{
// Handle XHTML type attribute for OLE replacement images.
uno::Reference<beans::XPropertySet> xGraphic(rGraphic.GetXGraphic(), uno::UNO_QUERY);
@@ -1412,7 +1415,7 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_FLY ) )
rHTMLWrt.OutCSS1_FrameFormatOptions( rFrameFormat, nFrameOpts );
- if( nFrameOpts & HtmlFrmOpts::Border )
+ if ((nFrameOpts & HtmlFrmOpts::Border) && !bReplacement)
{
aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_border, nBorderWidth);
}
@@ -1427,7 +1430,7 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_usemap, "#" + aIMapName);
}
- if ((nFrameOpts & HtmlFrmOpts::Replacement) && !rAlternateText.isEmpty())
+ if (bReplacement && !rAlternateText.isEmpty())
// XHTML object replacement image's alternate text doesn't use the
// "alt" attribute.
aHtml.characters(rAlternateText.toUtf8());
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index c124ae46027f..a2b8a8d811bc 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -195,8 +195,11 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
{
maNamespace = rOption.copy(aXhtmlNsKey.getLength()).toUtf8();
if (maNamespace == "reqif-xhtml")
+ {
+ mbReqIF = true;
// XHTML is always just a fragment inside ReqIF.
mbSkipHeaderFooter = true;
+ }
// XHTML namespace implies XHTML.
mbXHTML = true;
}
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index c29738838cb4..d9f75db90c89 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -391,6 +391,8 @@ public:
bool mbXHTML = false;
/// XML namespace, in case of XHTML.
OString maNamespace;
+ /// If the ReqIF subset of XHTML should be written.
+ bool mbReqIF = false;
#define sCSS2_P_CLASS_leaders "leaders"
bool m_bCfgPrintLayout : 1; // PrintLayout option for TOC dot leaders
More information about the Libreoffice-commits
mailing list