[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - 25 commits - framework/source include/svtools sfx2/source svtools/qa svtools/source sw/inc sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Mar 14 20:35:59 UTC 2018


 framework/source/classes/taskcreator.cxx          |    4 
 framework/source/services/taskcreatorsrv.cxx      |    2 
 include/svtools/HtmlWriter.hxx                    |    8 
 include/svtools/htmlout.hxx                       |    2 
 include/svtools/parhtml.hxx                       |    5 
 sfx2/source/doc/docfile.cxx                       |   34 +++
 svtools/qa/unit/testHtmlWriter.cxx                |   33 +++
 svtools/source/svhtml/HtmlWriter.cxx              |   25 ++
 svtools/source/svhtml/htmlout.cxx                 |    4 
 svtools/source/svhtml/parhtml.cxx                 |   10 +
 sw/inc/shellio.hxx                                |    4 
 sw/qa/extras/htmlexport/data/reqif-jpg-img.xhtml  |    4 
 sw/qa/extras/htmlexport/data/reqif-ole-data.ole   |    1 
 sw/qa/extras/htmlexport/data/reqif-ole-data.xhtml |    3 
 sw/qa/extras/htmlexport/data/reqif-ole-img.jpg    |binary
 sw/qa/extras/htmlexport/data/reqif-ole-img.png    |binary
 sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml  |    6 
 sw/qa/extras/htmlexport/data/reqif-p.xhtml        |    5 
 sw/qa/extras/htmlexport/data/reqif-png-img.xhtml  |    4 
 sw/qa/extras/htmlexport/htmlexport.cxx            |  119 +++++++++++++
 sw/qa/extras/htmlimport/data/outline-level.html   |    5 
 sw/qa/extras/htmlimport/data/reqif-br.xhtml       |    1 
 sw/qa/extras/htmlimport/htmlimport.cxx            |   28 +++
 sw/qa/extras/inc/swmodeltestbase.hxx              |   45 +++++
 sw/source/filter/basflt/shellio.cxx               |   10 -
 sw/source/filter/html/css1atr.cxx                 |   18 +-
 sw/source/filter/html/htmlatr.cxx                 |   74 ++++----
 sw/source/filter/html/htmldrawwriter.cxx          |    2 
 sw/source/filter/html/htmlfldw.cxx                |    2 
 sw/source/filter/html/htmlflywriter.cxx           |  110 ++++++++----
 sw/source/filter/html/htmlforw.cxx                |    8 
 sw/source/filter/html/htmlftn.cxx                 |   16 -
 sw/source/filter/html/htmlgrin.cxx                |   13 +
 sw/source/filter/html/htmlnumwriter.cxx           |    8 
 sw/source/filter/html/htmlplug.cxx                |  197 +++++++++++++++++++---
 sw/source/filter/html/htmltabw.cxx                |   63 +++----
 sw/source/filter/html/swhtml.cxx                  |   61 ++++++
 sw/source/filter/html/swhtml.hxx                  |   14 +
 sw/source/filter/html/wrthtml.cxx                 |   50 ++++-
 sw/source/filter/html/wrthtml.hxx                 |   14 +
 sw/source/filter/inc/fltini.hxx                   |    2 
 41 files changed, 826 insertions(+), 188 deletions(-)

New commits:
commit be27eb46318071127d4dd24e974819df5e32c750
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 14 12:00:19 2018 +0100

    sw XHTML export: fix handling of character styles
    
    Namespace prefix was missing here.
    
    Change-Id: Id746d47713b22e2efd5d679c2325b32a0bee8a09
    Reviewed-on: https://gerrit.libreoffice.org/51270
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 0efb6a1a3525a402ab28083181fc39b75f7ef556)

diff --git a/sw/qa/extras/htmlexport/data/reqif-p.xhtml b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
index e5484ee79483..315a4db80918 100644
--- a/sw/qa/extras/htmlexport/data/reqif-p.xhtml
+++ b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
@@ -2,3 +2,4 @@
 <reqif-xhtml:table><reqif-xhtml:tr><reqif-xhtml:td>in table</reqif-xhtml:tr></reqif-xhtml:tr></reqif-xhtml:table>
 <reqif-xhtml:a href="http://libreoffice.org/">http://libreoffice.org</reqif-xhtml:a>
 <reqif-xhtml:span style="text-decoration: underline">u</reqif-xhtml:span>
+<reqif-xhtml:strong>s</reqif-xhtml:strong>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 144572463922..6816853351c1 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -357,6 +357,9 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
 
     // This was "<u>" instead of CSS.
     CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"text-decoration: underline\"") != -1);
+
+    // This was <strong>, namespace prefix was missing.
+    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:strong>") != -1);
 }
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index d1fd33326f1c..b08e1ee3f1ee 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -3056,7 +3056,7 @@ static Writer& OutHTML_SwTextCharFormat( Writer& rWrt, const SfxPoolItem& rHt )
 
     if( rHTMLWrt.m_bTagOn )
     {
-        OString sOut = "<";
+        OString sOut = "<" + rHTMLWrt.GetNamespace();
         if( !pFormatInfo->aToken.isEmpty() )
             sOut += pFormatInfo->aToken;
         else
commit 51fec471b5c8122594ea5c86c0168232b5852227
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Mar 12 17:54:34 2018 +0100

    sw XHTML export: avoid <u> for underline in ReqIF mode
    
    The spec insists on the CSS equivalent (while <b> and <i> is OK).
    
    Change-Id: Ied3ebc896403ab85f544b0071e841e35eafdeb64
    Reviewed-on: https://gerrit.libreoffice.org/51158
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 3a4b0b4a86258f56e699c324fb2282c49319f92f)

diff --git a/sw/qa/extras/htmlexport/data/reqif-p.xhtml b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
index 3db2325467a2..e5484ee79483 100644
--- a/sw/qa/extras/htmlexport/data/reqif-p.xhtml
+++ b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
@@ -1,3 +1,4 @@
 <reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
 <reqif-xhtml:table><reqif-xhtml:tr><reqif-xhtml:td>in table</reqif-xhtml:tr></reqif-xhtml:tr></reqif-xhtml:table>
 <reqif-xhtml:a href="http://libreoffice.org/">http://libreoffice.org</reqif-xhtml:a>
+<reqif-xhtml:span style="text-decoration: underline">u</reqif-xhtml:span>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 35ca3cef64ea..144572463922 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -354,6 +354,9 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
 
     // This was "<a", was not found.
     CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:a") != -1);
+
+    // This was "<u>" instead of CSS.
+    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"text-decoration: underline\"") != -1);
 }
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index 1bcb687ccc85..9fc4a02bcf77 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -284,7 +284,7 @@ void SwHTMLWriter::OutCSS1_Property( const sal_Char *pProp,
         case CSS1_OUTMODE_SPAN_TAG1_ON:
             if( m_bTagOn )
             {
-                sOut.append("<" OOO_STRING_SVTOOLS_HTML_span
+                sOut.append("<" + GetNamespace() + OOO_STRING_SVTOOLS_HTML_span
                             " " OOO_STRING_SVTOOLS_HTML_O_style "=\"");
             }
             else
@@ -2249,7 +2249,7 @@ static Writer& OutCSS1_SvxTextLn_SvxCrOut_SvxBlink( Writer& rWrt,
             {
                 // this also works in HTML does not need to be written as
                 // a STYLE-Options, and must not be written as Hint
-                OSL_ENSURE( !rHTMLWrt.IsCSS1Source(CSS1_OUTMODE_HINT),
+                OSL_ENSURE( !rHTMLWrt.IsCSS1Source(CSS1_OUTMODE_HINT) || rHTMLWrt.mbReqIF,
                         "write underline as Hint?" );
                 pUStr = sCSS1_PV_underline;
             }
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 48f1458bad43..d1fd33326f1c 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -2815,7 +2815,7 @@ static Writer& OutHTML_SwUnderline( Writer& rWrt, const SfxPoolItem& rHt )
         return rWrt;
 
     const FontLineStyle eUnder = static_cast<const SvxUnderlineItem&>(rHt).GetLineStyle();
-    if( LINESTYLE_NONE != eUnder )
+    if( LINESTYLE_NONE != eUnder && !rHTMLWrt.mbReqIF )
     {
         HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_underline, rHTMLWrt.m_bTagOn );
     }
commit 23a5907950f6edb47a2bdd5011eb1e0427d978b4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Mar 12 16:30:55 2018 +0100

    sw XHTML export: always write images as PNG in ReqIF mode
    
    JPG image would have to be JPG + PNG fallback, at which point it's
    easier to just write PNG.
    
    Reviewed-on: https://gerrit.libreoffice.org/51151
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 9034207b3019e395390e5aa9eaa1a11ca81c63b5)
    
    Conflicts:
            sw/source/filter/html/htmlflywriter.cxx
    
    Change-Id: I6e4f0759244d29735fdcda8e050d198f118c737d

diff --git a/sw/qa/extras/htmlexport/data/reqif-jpg-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-jpg-img.xhtml
new file mode 100644
index 000000000000..da7276192a31
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-jpg-img.xhtml
@@ -0,0 +1,4 @@
+<reqif-xhtml:div><reqif-xhtml:br/>
+    <reqif-xhtml:img data="reqif-ole-img.jpg" type="image/jpeg">OLE Object</reqif-xhtml:img>
+</reqif-xhtml:div>
+
diff --git a/sw/qa/extras/htmlexport/data/reqif-ole-img.jpg b/sw/qa/extras/htmlexport/data/reqif-ole-img.jpg
new file mode 100644
index 000000000000..ca9183e9d308
Binary files /dev/null and b/sw/qa/extras/htmlexport/data/reqif-ole-img.jpg differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index c77097db4d66..35ca3cef64ea 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -424,6 +424,18 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml")
     CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:object") != -1);
 }
 
+DECLARE_HTMLEXPORT_TEST(testReqIfJpgImg, "reqif-jpg-img.xhtml")
+{
+    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));
+    // This was image/jpeg, JPG was not converted to PNG in ReqIF mode.
+    CPPUNIT_ASSERT(aStream.indexOf("type=\"image/png\"") != -1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 00c3404daaa9..3885b87866b2 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1202,7 +1202,8 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
                        Graphic& rGraphic, const OUString& rAlternateText,
                        const Size &rRealSize, HtmlFrmOpts nFrameOpts,
                        const sal_Char *pMarkType,
-                       const ImageMap *pAltImgMap )
+                       const ImageMap *pAltImgMap,
+                       const OUString& rMimeType )
 {
     SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
     // <object data="..."> instead of <img src="...">
@@ -1390,13 +1391,8 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
     if (bReplacement)
     {
         // Handle XHTML type attribute for OLE replacement images.
-        uno::Reference<beans::XPropertySet> xGraphic(rGraphic.GetXGraphic(), uno::UNO_QUERY);
-        if (xGraphic.is())
-        {
-            OUString aMimeType;
-            xGraphic->getPropertyValue("MimeType") >>= aMimeType;
-            aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_type, aMimeType.toUtf8());
-        }
+        if (!rMimeType.isEmpty())
+            aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_type, rMimeType.toUtf8());
     }
 
     // Events
@@ -1795,6 +1791,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
 
     Graphic aGraphic = pGrfNd->GetGraphic();
     OUString aGraphicURL;
+    OUString aMimeType;
     if(!rHTMLWrt.mbEmbedImages)
     {
         const SwMirrorGrf& rMirror = pGrfNd->GetSwAttrSet().GetMirrorGrf();
@@ -1823,8 +1820,19 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
             aMM100Size = OutputDevice::LogicToLogic( rSize.GetSize(),
                             MapMode( MapUnit::MapTwip ), MapMode( MapUnit::Map100thMM ));
 
+            OUString aFilterName("JPG");
+
+            if (rHTMLWrt.mbReqIF)
+            {
+                // Writing image without fallback PNG in ReqIF mode: force PNG
+                // output.
+                aFilterName = "PNG";
+                nFlags &= ~XOutFlags::UseNativeIfPossible;
+                aMimeType = "image/png";
+            }
+
             sal_uInt16 nErr = XOutBitmap::WriteGraphic( pGrfNd->GetGrf(), aGraphicURL,
-                    "JPG", nFlags, &aMM100Size );
+                    aFilterName, nFlags, &aMM100Size );
             if( nErr )
             {
                 rHTMLWrt.m_nWarn = WARN_SWG_POOR_LOAD | WARN_SW_WRITE_BASE;
@@ -1842,8 +1850,11 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
         }
 
     }
+    uno::Reference<beans::XPropertySet> xGraphic(aGraphic.GetXGraphic(), uno::UNO_QUERY);
+    if (xGraphic.is() && aMimeType.isEmpty())
+        xGraphic->getPropertyValue("MimeType") >>= aMimeType;
     OutHTML_Image( rWrt, rFrameFormat, aGraphicURL, aGraphic, pGrfNd->GetTitle(),
-                  pGrfNd->GetTwipSize(), nFrameFlags, "graphic" );
+                  pGrfNd->GetTwipSize(), nFrameFlags, "graphic", nullptr, aMimeType );
 
     return rWrt;
 }
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index a2e9380a15c7..ec74dcf414dd 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -659,7 +659,8 @@ Writer& OutHTML_Image( Writer&, const SwFrameFormat& rFormat,
                        Graphic& rGraphic, const OUString& rAlternateText,
                        const Size& rRealSize, HtmlFrmOpts nFrameOpts,
                        const sal_Char *pMarkType,
-                       const ImageMap *pGenImgMap = nullptr );
+                       const ImageMap *pGenImgMap = nullptr,
+                       const OUString& rMimeType = OUString() );
 
 Writer& OutHTML_BulletImage( Writer& rWrt, const sal_Char *pTag,
                              const SvxBrushItem* pBrush,
commit 3d55e4dd93d4cea29d7d9ee2ab2c003417581ee3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Mar 12 21:24:09 2018 +0100

    tdf#116117 sfx2 store: don't inherit temp file permissions when renaming
    
    This has to be handled explicitly, otherwise the tempfile permissions
    (which intentionally don't respect umask()) would be preserved on
    rename().
    
    Reviewed-on: https://gerrit.libreoffice.org/51169
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit fb04780cf8523ad4e900ae8b9cecbe7a2697a12a)
    
    Conflicts:
            sfx2/qa/cppunit/test_misc.cxx
    
    Change-Id: I0a2681dbf06986e73f6e12d294e35e87b93b4f8a

diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 1838af974842..384178f756c6 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -158,6 +158,32 @@ bool IsLockingUsed()
 
 #endif
 
+/// Gets default attributes of a file:// URL.
+sal_uInt64 GetDefaultFileAttributes(const OUString& rURL)
+{
+    sal_uInt64 nRet = 0;
+
+    if (!comphelper::isFileUrl(rURL))
+        return nRet;
+
+    osl::File aFile(rURL);
+    if (aFile.open(osl_File_OpenFlag_Create) != osl::File::E_None)
+        return nRet;
+
+    aFile.close();
+
+    osl::DirectoryItem aItem;
+    if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
+        return nRet;
+
+    osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
+    if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
+        return nRet;
+
+    nRet = aStatus.getAttributes();
+    return nRet;
+}
+
 } // anonymous namespace
 
 class SfxMedium_Impl
@@ -1690,8 +1716,16 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
             {
                 OUString aSourceMainURL = aSource.GetMainURL(INetURLObject::DecodeMechanism::NONE);
                 OUString aDestMainURL = aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+                sal_uInt64 nAttributes = GetDefaultFileAttributes(aDestMainURL);
                 if (comphelper::isFileUrl(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
+                {
+                    if (nAttributes)
+                        // Adjust attributes, source might be created with
+                        // the osl_File_OpenFlag_Private flag.
+                        osl::File::setAttributes(aDestMainURL, nAttributes);
                     bResult = true;
+                }
                 else
                 {
                     if (bOverWrite && ::utl::UCBContentHelper::IsDocument(aDestMainURL))
commit 548df632e3e4f0d572a857a9258188391b624562
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>
    (cherry picked from commit 7a644e363a8c2156b7e1202c0a2ff518ec11b027)

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 3f4ac8201837..c77097db4d66 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 b85f61146236..00c3404daaa9 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -802,12 +802,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());
@@ -822,7 +823,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);
     }
@@ -831,7 +832,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) ||
@@ -862,7 +863,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);
     }
@@ -1204,6 +1205,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;
@@ -1356,7 +1359,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);
@@ -1379,12 +1382,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);
@@ -1411,7 +1414,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);
     }
@@ -1426,7 +1429,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 b190607c3c72..9169c403ada7 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -194,8 +194,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 c8a6dd3a7f4b..a2e9380a15c7 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -394,6 +394,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
commit e5eddfa414fb82330e97fa7eafd020739e9174a9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 9 15:14:36 2018 +0100

    sw XHTML import: PNG <object> is an image
    
    The previous scheme was:
    
    <object data="..." type="...">
        <object data="..." type="image/png">alternate text</object>
    </object>
    
    Support also the case when the inner <object> is standalone, like:
    
    <object data="..." type="image/png">alternate text</object>
    
    Reviewed-on: https://gerrit.libreoffice.org/51003
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 68c542cfa888f1aa03a08bfc13163c0f2f0c3a75)
    
    Conflicts:
            sw/source/filter/html/htmlgrin.cxx
    
    Change-Id: I2dec2770ee3c1c538bcf26f6ff12c6e8f5969563

diff --git a/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml
new file mode 100644
index 000000000000..f31795e35224
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml
@@ -0,0 +1,4 @@
+<reqif-xhtml:div><reqif-xhtml:br/>
+    <reqif-xhtml:object data="reqif-ole-img.png" type="image/png">OLE Object</reqif-xhtml:object>
+</reqif-xhtml:div>
+
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 2d3e5a47f633..3f4ac8201837 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -402,6 +402,15 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
 }
 
+DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml")
+{
+    uno::Reference<container::XNamed> xShape(getShape(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xShape.is());
+
+    // This was Object1, PNG without fallback was imported as OLE object.
+    CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xShape->getName());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 153d1e31e346..122f639dd4f6 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -298,6 +298,7 @@ void SwHTMLParser::InsertImage()
     // and now analyze
     OUString sAltNm, aId, aClass, aStyle, aMap, sHTMLGrfName;
     OUString sGrfNm;
+    OUString aGraphicData;
     sal_Int16 eVertOri = text::VertOrientation::TOP;
     sal_Int16 eHoriOri = text::HoriOrientation::NONE;
     bool bWidthProvided=false, bHeightProvided=false;
@@ -336,6 +337,11 @@ void SwHTMLParser::InsertImage()
                 if( !InternalImgToPrivateURL(sGrfNm) )
                     sGrfNm = INetURLObject::GetAbsURL( m_sBaseURL, sGrfNm );
                 break;
+            case HtmlOptionId::DATA:
+                aGraphicData = rOption.GetString();
+                if (!InternalImgToPrivateURL(aGraphicData))
+                    aGraphicData = INetURLObject::GetAbsURL(m_sBaseURL, aGraphicData);
+                break;
             case HtmlOptionId::ALIGN:
                 eVertOri =
                     rOption.GetEnum( aHTMLImgVAlignTable,
@@ -419,6 +425,9 @@ IMAGE_SETEVENT:
         }
     }
 
+    if (sGrfNm.isEmpty() && !aGraphicData.isEmpty())
+        sGrfNm = aGraphicData;
+
     if( sGrfNm.isEmpty() )
         return;
 
@@ -461,8 +470,10 @@ IMAGE_SETEVENT:
                 sGrfNm.clear();
         }
     }
-    else if (m_sBaseURL.isEmpty()) // sBaseURL is empty if the source is clipboard
+    else if (m_sBaseURL.isEmpty() || !aGraphicData.isEmpty())
     {
+        // sBaseURL is empty if the source is clipboard
+        // aGraphicData is non-empty for <object data="..."> -> not a linked graphic.
         if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL))
             sGrfNm.clear();
     }
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 3bcf4d63ce3c..cc2b6709b6df 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -294,7 +294,7 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace,
     }
 }
 
-void SwHTMLParser::InsertEmbed()
+bool SwHTMLParser::InsertEmbed()
 {
     OUString aURL, aType, aName, aAlt, aId, aStyle, aClass;
     OUString aData;
@@ -384,6 +384,10 @@ void SwHTMLParser::InsertEmbed()
         aCmdLst.Append( rOption.GetTokenString(), rOption.GetString() );
     }
 
+    if (aType == "image/png" && m_aEmbeds.empty())
+        // Toplevel <object> for PNG -> that's an image, not an OLE object.
+        return false;
+
     SfxItemSet aItemSet( m_xDoc->GetAttrPool(), m_pCSS1Parser->GetWhichMap() );
     SvxCSS1PropertyInfo aPropInfo;
     if( HasStyleOptions( aStyle, aId, aClass ) )
@@ -425,7 +429,7 @@ void SwHTMLParser::InsertEmbed()
     // do not insert plugin if it has neither URL nor type
     bool bHasType = !aType.isEmpty();
     if( !bHasURL && !bHasType && !bHasData )
-        return;
+        return true;
 
     if (!m_aEmbeds.empty())
     {
@@ -434,7 +438,7 @@ void SwHTMLParser::InsertEmbed()
         svt::EmbeddedObjectRef& rObj = pOLENode->GetOLEObj().GetObject();
         Graphic aGraphic;
         if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
-            return;
+            return true;
 
         rObj.SetGraphic(aGraphic, aType);
 
@@ -451,7 +455,7 @@ void SwHTMLParser::InsertEmbed()
 
         SwFrameFormat* pFormat = pOLENode->GetFlyFormat();
         if (!pFormat)
-            return;
+            return true;
 
         SwAttrSet aAttrSet(pFormat->GetAttrSet());
         aAttrSet.ClearItem(RES_CNTNT);
@@ -459,7 +463,7 @@ void SwHTMLParser::InsertEmbed()
         SwFormatFrameSize aFrameSize(ATT_FIX_SIZE, aTwipSize.Width(), aTwipSize.Height());
         aAttrSet.Put(aFrameSize);
         pOLENode->GetDoc()->SetFlyFrameAttr(*pFormat, aAttrSet);
-        return;
+        return true;
     }
 
     // das Plugin anlegen
@@ -563,13 +567,15 @@ void SwHTMLParser::InsertEmbed()
     }
 
     if (!bHasData)
-        return;
+        return true;
 
     SwOLENode* pOLENode = pNoTextNd->GetOLENode();
     if (!pOLENode)
-        return;
+        return true;
 
     m_aEmbeds.push(pOLENode);
+
+    return true;
 }
 
 #if HAVE_FEATURE_JAVA
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 5c5c9f0ae810..434ff5d82d2e 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -1388,7 +1388,8 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
     case HtmlTokenId::OBJECT_ON:
         if (m_bXHTML)
         {
-            InsertEmbed();
+            if (!InsertEmbed())
+                InsertImage();
             break;
         }
 #if HAVE_FEATURE_JAVA
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 6cae2022e1bc..27dfd2965360 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -705,7 +705,7 @@ private:
 
     // the actual insert methods for <IMG>, <EMBED>, <APPLET> and <PARAM>
     void InsertImage();     // htmlgrin.cxx
-    void InsertEmbed();     // htmlplug.cxx
+    bool InsertEmbed();     // htmlplug.cxx
 
 #if HAVE_FEATURE_JAVA
     void NewObject();   // htmlplug.cxx
commit ee5558fdf057c857ea5d8d34e3091b78434be10d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 9 12:32:39 2018 +0100

    sw XHTML export: fix OutHTML_INetFormat()
    
    <a> missed the namespace prefix, </a> did not.
    
    Change-Id: I8f50249170c6323d35bbeb856e10a2c93038cdbf
    Reviewed-on: https://gerrit.libreoffice.org/50993
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 3af025f0fe0daa1de24eb3ac80797cd618d06ec3)

diff --git a/sw/qa/extras/htmlexport/data/reqif-p.xhtml b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
index 2f069d78e0eb..3db2325467a2 100644
--- a/sw/qa/extras/htmlexport/data/reqif-p.xhtml
+++ b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
@@ -1,2 +1,3 @@
 <reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
 <reqif-xhtml:table><reqif-xhtml:tr><reqif-xhtml:td>in table</reqif-xhtml:tr></reqif-xhtml:tr></reqif-xhtml:table>
+<reqif-xhtml:a href="http://libreoffice.org/">http://libreoffice.org</reqif-xhtml:a>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 994edfeaf620..2d3e5a47f633 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -337,15 +337,23 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
 {
     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
     CPPUNIT_ASSERT(pStream);
+    pStream->Seek(STREAM_SEEK_TO_END);
+    sal_uInt64 nLength = pStream->Tell();
+    pStream->Seek(0);
 
     OString aExpected("<reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb</reqif-xhtml:p>" SAL_NEWLINE_STRING);
 
     // This was '<table' instead.
     aExpected += "<reqif-xhtml:table";
 
+    OString aStream(read_uInt8s_ToOString(*pStream, nLength));
+    pStream->Seek(0);
     OString aActual(read_uInt8s_ToOString(*pStream, aExpected.getLength()));
     // This was a HTML header, like '<!DOCTYPE html ...'.
     CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
+
+    // This was "<a", was not found.
+    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:a") != -1);
 }
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 199c8a45c57e..48f1458bad43 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -2883,7 +2883,7 @@ Writer& OutHTML_INetFormat( Writer& rWrt, const SwFormatINetFormat& rINetFormat,
         return rWrt;
     }
 
-    OString sOut = "<" OOO_STRING_SVTOOLS_HTML_anchor;
+    OString sOut("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_anchor);
 
     bool bScriptDependent = false;
     {
commit fb546119af9b09b37dcc5b9f2cf8bc01a4dee522
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 8 17:25:10 2018 +0100

    sw XHTML export: handle alt text for OLE objects
    
    The XHTML export is now on par with the import wrt OLE objects.
    
    Change-Id: I736c1f03b0e3d8b84b8ebe08eb1b1cfa247cefbd
    Reviewed-on: https://gerrit.libreoffice.org/50966
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit b288fdf89386446854debea35f8b8d013fec671d)

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 8ab0b5803512..994edfeaf620 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -390,11 +390,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     // This was empty when either import or export handling was missing.
     CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
 
-    if (mbExported)
-        // The below is not yet working for export.
-        return;
-
-    // Check alternate text (it was empty).
+    // Check alternate text (it was empty, for export the 'alt' attribute was used).
     CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
 }
 
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 99894b91698c..b85f61146236 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1426,6 +1426,11 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
         aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_usemap, "#" + aIMapName);
     }
 
+    if ((nFrameOpts & HtmlFrmOpts::Replacement) && !rAlternateText.isEmpty())
+        // XHTML object replacement image's alternate text doesn't use the
+        // "alt" attribute.
+        aHtml.characters(rAlternateText.toUtf8());
+
     aHtml.flushStack();
 
     if( !rHTMLWrt.m_aINetFormats.empty() )
commit 99c4e32f55bbdc273abb82b922bad81da8ddb0d0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 8 15:56:08 2018 +0100

    svtools: allow writing characters with HtmlWriter
    
    The sw HTML image export already uses HtmlWriter, so need to extend this
    to support XHTML alternate text, writing the character data directly is
    not an option.
    
    Change-Id: Iac3f2b9a3828175a5f1d0fb14ab505f8de389e52
    Reviewed-on: https://gerrit.libreoffice.org/50965
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit a8ca72cbcd2c6ea0baa5e3569224c2f08d358f3e)

diff --git a/include/svtools/HtmlWriter.hxx b/include/svtools/HtmlWriter.hxx
index a842df4870a9..25030f6dffe8 100644
--- a/include/svtools/HtmlWriter.hxx
+++ b/include/svtools/HtmlWriter.hxx
@@ -27,6 +27,7 @@ private:
 
     bool mbElementOpen;
     bool mbContentWritten;
+    bool mbCharactersWritten;
     bool mbPrettyPrint;
     /// XML namespace, in case of XHTML.
     OString maNamespace;
@@ -52,6 +53,9 @@ public:
 
     void single(const OString& aContent);
     void endAttribute();
+
+    /// Writes character data.
+    void characters(const OString& rChars);
 };
 
 #endif
diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx
index 02acfd253603..1feff4dfc6ad 100644
--- a/svtools/qa/unit/testHtmlWriter.cxx
+++ b/svtools/qa/unit/testHtmlWriter.cxx
@@ -41,6 +41,7 @@ public:
     void testNested();
     void testNamespace();
     void testAttributeValues();
+    void testCharacters();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testSingleElement);
@@ -50,6 +51,7 @@ public:
     CPPUNIT_TEST(testNested);
     CPPUNIT_TEST(testNamespace);
     CPPUNIT_TEST(testAttributeValues);
+    CPPUNIT_TEST(testCharacters);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -190,6 +192,21 @@ void Test::testAttributeValues()
     CPPUNIT_ASSERT_EQUAL(OString("<abc one=\"one\" two=\"two\" three=\"12\"/>"), aString);
 }
 
+void Test::testCharacters()
+{
+    SvMemoryStream aStream;
+
+    HtmlWriter aHtml(aStream);
+    aHtml.prettyPrint(false);
+    aHtml.start("abc");
+    aHtml.characters("hello");
+    aHtml.end();
+
+    OString aString = extractFromStream(aStream);
+
+    CPPUNIT_ASSERT_EQUAL(OString("<abc>hello</abc>"), aString);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/svtools/source/svhtml/HtmlWriter.cxx b/svtools/source/svhtml/HtmlWriter.cxx
index 499aa7ed8ab0..631a56e3e1f1 100644
--- a/svtools/source/svhtml/HtmlWriter.cxx
+++ b/svtools/source/svhtml/HtmlWriter.cxx
@@ -15,6 +15,7 @@ HtmlWriter::HtmlWriter(SvStream& rStream, const OString& rNamespace) :
     mrStream(rStream),
     mbElementOpen(false),
     mbContentWritten(false),
+    mbCharactersWritten(false),
     mbPrettyPrint(true)
 {
     if (!rNamespace.isEmpty())
@@ -83,7 +84,7 @@ void HtmlWriter::flushStack()
 
 void HtmlWriter::end()
 {
-    if (mbElementOpen)
+    if (mbElementOpen && !mbCharactersWritten)
     {
         mrStream.WriteCharPtr("/>");
         if (mbPrettyPrint)
@@ -107,6 +108,7 @@ void HtmlWriter::end()
     maElementStack.pop_back();
     mbElementOpen = false;
     mbContentWritten = false;
+    mbCharactersWritten = false;
 }
 
 void HtmlWriter::attribute(const OString &aAttribute, const OString& aValue)
@@ -146,5 +148,12 @@ void HtmlWriter::attribute(const OString& aAttribute)
     }
 }
 
+void HtmlWriter::characters(const OString& rChars)
+{
+    if (!mbCharactersWritten)
+        mrStream.WriteCharPtr(">");
+    mrStream.WriteOString(rChars);
+    mbCharactersWritten = true;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit c91275a49b9fb85036c19ab8998035684f4fb734
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 8 14:58:01 2018 +0100

    sw XHTML export: handle media type for OLE objects
    
    Both native data and replacement graphic.
    
    Change-Id: I2f89493e56e9d22a54aa3e4175d8b750c33d98f0
    Reviewed-on: https://gerrit.libreoffice.org/50964
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit ad628045f62b0656c58d2e195e33186c055c2196)

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index e5984565fe63..8ab0b5803512 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -379,10 +379,6 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     // This was only 1247, size was not set explicitly.
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
 
-    if (mbExported)
-        // The below is not yet working for export.
-        return;
-
     // Check mime/media types.
     CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty<OUString>(xGraphic, "MimeType"));
 
@@ -391,9 +387,13 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     auto aStreamName = getProperty<OUString>(xObject, "StreamName");
     uno::Reference<io::XStream> xStream
         = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
-    // This was empty.
+    // This was empty when either import or export handling was missing.
     CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
 
+    if (mbExported)
+        // The below is not yet working for export.
+        return;
+
     // Check alternate text (it was empty).
     CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
 }
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 928ea665b17d..99894b91698c 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1384,6 +1384,18 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
         aHtml.attribute(aAttribute, sBuffer.makeStringAndClear().getStr());
     }
 
+    if (nFrameOpts & HtmlFrmOpts::Replacement)
+    {
+        // Handle XHTML type attribute for OLE replacement images.
+        uno::Reference<beans::XPropertySet> xGraphic(rGraphic.GetXGraphic(), uno::UNO_QUERY);
+        if (xGraphic.is())
+        {
+            OUString aMimeType;
+            xGraphic->getPropertyValue("MimeType") >>= aMimeType;
+            aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_type, aMimeType.toUtf8());
+        }
+    }
+
     // Events
     if (SfxItemState::SET == rItemSet.GetItemState(RES_FRMMACRO, true, &pItem))
     {
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index ee8cf06efa36..3bcf4d63ce3c 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -1432,12 +1432,19 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
         comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(),
                                                       xOutStream->getOutputStream());
         aFileName = URIHelper::simpleNormalizedMakeRelative(rWrt.GetBaseURL(), aFileName);
+        uno::Reference<beans::XPropertySet> xOutStreamProps(xInStream, uno::UNO_QUERY);
+        OUString aFileType;
+        if (xOutStreamProps.is())
+            xOutStreamProps->getPropertyValue("MediaType") >>= aFileType;
 
         // Refer to this data.
         if (rHTMLWrt.m_bLFPossible)
             rHTMLWrt.OutNewLine();
         rWrt.Strm().WriteOString("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object);
-        rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\">");
+        rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\"");
+        if (!aFileType.isEmpty())
+            rWrt.Strm().WriteOString(" type=\"" + aFileType.toUtf8() + "\"");
+        rWrt.Strm().WriteOString(">");
         bObjectOpened = true;
         rHTMLWrt.m_bLFPossible = true;
     }
commit d528a27165819fd2a9d6f54babc76ee97bfc439c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 8 14:44:51 2018 +0100

    sw XHTML export: handle replacement graphic of OLE objects
    
    Replacement image of OLE object in XHTML is <object data="...">, not
    <img src="...">.
    
    Change-Id: I244000099037869590a71bf49dd94fbf34a71e50
    Reviewed-on: https://gerrit.libreoffice.org/50955
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 97d44109949a45e5022aa8ca1e51f6b54562a002)

diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.png b/sw/qa/extras/htmlexport/data/reqif-ole-img.png
similarity index 100%
rename from sw/qa/extras/htmlimport/data/reqif-ole-img.png
rename to sw/qa/extras/htmlexport/data/reqif-ole-img.png
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml
similarity index 100%
rename from sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
rename to sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 634bc9e4e802..e5984565fe63 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -12,6 +12,8 @@
 
 #include <com/sun/star/awt/Gradient.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
 #include <rtl/byteseq.hxx>
 
 #include <swmodule.hxx>
@@ -356,6 +358,45 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
 }
 
+DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
+{
+    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
+                                                     uno::UNO_QUERY);
+    uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0),
+                                                               uno::UNO_QUERY);
+    // This failed, OLE object had no replacement image.
+    // And then it also failed when the export lost the replacement image.
+    uno::Reference<graphic::XGraphic> xGraphic = xObject->getReplacementGraphic();
+    CPPUNIT_ASSERT(xGraphic.is());
+
+    uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
+    OutputDevice* pDevice = Application::GetDefaultDevice();
+    Size aPixel(64, 64);
+    // Expected to be 1693.
+    Size aLogic(pDevice->PixelToLogic(aPixel, MapMode(MapUnit::Map100thMM)));
+    awt::Size aSize = xShape->getSize();
+    // This was only 1247, size was not set explicitly.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
+
+    if (mbExported)
+        // The below is not yet working for export.
+        return;
+
+    // Check mime/media types.
+    CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty<OUString>(xGraphic, "MimeType"));
+
+    uno::Reference<document::XStorageBasedDocument> xStorageProvider(mxComponent, uno::UNO_QUERY);
+    uno::Reference<embed::XStorage> xStorage = xStorageProvider->getDocumentStorage();
+    auto aStreamName = getProperty<OUString>(xObject, "StreamName");
+    uno::Reference<io::XStream> xStream
+        = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
+    // This was empty.
+    CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
+
+    // Check alternate text (it was empty).
+    CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
+}
 
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.ole b/sw/qa/extras/htmlimport/data/reqif-ole-data.ole
deleted file mode 100644
index d3dc23d793e2..000000000000
--- a/sw/qa/extras/htmlimport/data/reqif-ole-data.ole
+++ /dev/null
@@ -1 +0,0 @@
-{\pict}
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 944e60b971dc..08de9411650b 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -249,41 +249,6 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
     CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
 }
 
-DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
-{
-    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
-                                                     uno::UNO_QUERY);
-    uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0),
-                                                               uno::UNO_QUERY);
-    // This failed, OLE object had no replacement image.
-    uno::Reference<graphic::XGraphic> xGraphic = xObject->getReplacementGraphic();
-    CPPUNIT_ASSERT(xGraphic.is());
-
-    uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
-    OutputDevice* pDevice = Application::GetDefaultDevice();
-    Size aPixel(64, 64);
-    // Expected to be 1693.
-    Size aLogic(pDevice->PixelToLogic(aPixel, MapMode(MapUnit::Map100thMM)));
-    awt::Size aSize = xShape->getSize();
-    // This was only 1247, size was not set explicitly.
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
-
-    // Check mime/media types.
-    CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty<OUString>(xGraphic, "MimeType"));
-
-    uno::Reference<document::XStorageBasedDocument> xStorageProvider(mxComponent, uno::UNO_QUERY);
-    uno::Reference<embed::XStorage> xStorage = xStorageProvider->getDocumentStorage();
-    auto aStreamName = getProperty<OUString>(xObject, "StreamName");
-    uno::Reference<io::XStream> xStream
-        = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
-    // This was empty.
-    CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
-
-    // Check alternate text (it was empty).
-    CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index acb6524a856f..928ea665b17d 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -807,7 +807,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
 
     // Name
     if( (nFrameOptions & (HtmlFrmOpts::Id|HtmlFrmOpts::Name)) &&
-        !rFrameFormat.GetName().isEmpty() )
+        !rFrameFormat.GetName().isEmpty() && !(nFrameOptions & HtmlFrmOpts::Replacement))
     {
         const sal_Char* pAttributeName = (nFrameOptions & HtmlFrmOpts::Id) ? OOO_STRING_SVTOOLS_HTML_O_id : OOO_STRING_SVTOOLS_HTML_O_name;
         aHtml.attribute(pAttributeName, rFrameFormat.GetName());
@@ -822,7 +822,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
     }
 
     // alt
-    if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.isEmpty() )
+    if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.isEmpty() && !(nFrameOptions & HtmlFrmOpts::Replacement) )
     {
         aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_alt, rAlternateText);
     }
@@ -831,7 +831,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)) )
+        ((RndStdIds::FLY_AT_PARA == eAnchorId) || (RndStdIds::FLY_AT_CHAR == eAnchorId)) && !(nFrameOptions & HtmlFrmOpts::Replacement))
     {
         const SwFormatHoriOrient& rHoriOri = rFrameFormat.GetHoriOrient();
         if( !(nFrameOptions & HtmlFrmOpts::SAlign) ||
@@ -862,7 +862,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
         case text::VertOrientation::NONE:     break;
         }
     }
-    if (pAlignString)
+    if (pAlignString && !(nFrameOptions & HtmlFrmOpts::Replacement))
     {
         aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_align, pAlignString);
     }
@@ -1355,7 +1355,11 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
         }
     }
 
-    aHtml.start(OOO_STRING_SVTOOLS_HTML_image);
+    OString aTag(OOO_STRING_SVTOOLS_HTML_image);
+    if (nFrameOpts & HtmlFrmOpts::Replacement)
+        // Write replacement graphic of OLE object as <object>.
+        aTag = OOO_STRING_SVTOOLS_HTML_object;
+    aHtml.start(aTag);
 
     OStringBuffer sBuffer;
     if(rHTMLWrt.mbEmbedImages)
@@ -1374,7 +1378,10 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat,
     else
     {
         sBuffer.append(OUStringToOString(aGraphicURL, RTL_TEXTENCODING_UTF8));
-        aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_src, sBuffer.makeStringAndClear().getStr());
+        OString aAttribute(OOO_STRING_SVTOOLS_HTML_O_src);
+        if (nFrameOpts & HtmlFrmOpts::Replacement)
+            aAttribute = OOO_STRING_SVTOOLS_HTML_O_data;
+        aHtml.attribute(aAttribute, sBuffer.makeStringAndClear().getStr());
     }
 
     // Events
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 5eb86b23da7b..ee8cf06efa36 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -1465,6 +1465,8 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
     }
     HtmlFrmOpts nFlags = bInCntnr ? HtmlFrmOpts::GenImgAllMask
         : HtmlFrmOpts::GenImgMask;
+    if (bObjectOpened)
+        nFlags |= HtmlFrmOpts::Replacement;
     OutHTML_Image( rWrt, rFrameFormat, aGraphicURL, aGraphic,
             pOLENd->GetTitle(), pOLENd->GetTwipSize(),
             nFlags, "ole" );
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index 3564a9942c1d..c8a6dd3a7f4b 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -99,12 +99,14 @@ enum class HtmlFrmOpts {
     SPixSize    = 1<<18,
     Id          = 1<<19,
     Dir         = 1<<20,
+    /// The graphic frame is a replacement image of an OLE object.
+    Replacement = 1<<21,
 
     GenImgAllMask = Alt | Size | AbsSize | Name,
     GenImgMask    = GenImgAllMask | Align | Space | BrClear
 };
 namespace o3tl {
-    template<> struct typed_flags<HtmlFrmOpts> : is_typed_flags<HtmlFrmOpts, ((1<<21)-1)> {};
+    template<> struct typed_flags<HtmlFrmOpts> : is_typed_flags<HtmlFrmOpts, ((1<<22)-1)> {};
 }
 
 #define HTMLMODE_BLOCK_SPACER       0x00010000
commit da0948e42c531c54dac29b99b83f231b8c593701
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 8 12:10:14 2018 +0100

    sw XHTML export: handle native data of OLE objects
    
    Write the native data and refer it from the XHTML stream.
    
    Change-Id: I8952ed07108ddc92b1d136bd9af6f21d3ed604f0
    Reviewed-on: https://gerrit.libreoffice.org/50941
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit ae510e67cdc644c541ffa26b2f91bba71a9856d2)

diff --git a/sw/qa/extras/htmlexport/data/reqif-ole-data.ole b/sw/qa/extras/htmlexport/data/reqif-ole-data.ole
new file mode 100644
index 000000000000..d3dc23d793e2
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-ole-data.ole
@@ -0,0 +1 @@
+{\pict}
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml b/sw/qa/extras/htmlexport/data/reqif-ole-data.xhtml
similarity index 100%
rename from sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml
rename to sw/qa/extras/htmlexport/data/reqif-ole-data.xhtml
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 00327893fa5e..634bc9e4e802 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -346,6 +346,17 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
     CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
 }
 
+DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
+{
+    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
+                                                     uno::UNO_QUERY);
+    // This was 0, <object> without URL was ignored.
+    // Then this was 0 on export, as data of OLE nodes was ignored.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
+}
+
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index cddda2bc6d1b..944e60b971dc 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -249,15 +249,6 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
     CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
 }
 
-DECLARE_HTMLIMPORT_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
-{
-    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
-                                                     uno::UNO_QUERY);
-    // This was 0, <object> without URL was ignored.
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
-}
-
 DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
 {
     uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index bdbbe0f2500a..6757f6d8b961 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -711,6 +711,23 @@ protected:
         {
             setTestInteractionHandler(pPassword, aFilterOptions);
         }
+
+        if (!maImportFilterOptions.isEmpty())
+        {
+            beans::PropertyValue aValue;
+            aValue.Name = "FilterOptions";
+            aValue.Value <<= maImportFilterOptions;
+            aFilterOptions.push_back(aValue);
+        }
+
+        if (!maImportFilterName.isEmpty())
+        {
+            beans::PropertyValue aValue;
+            aValue.Name = "FilterName";
+            aValue.Value <<= maImportFilterName;
+            aFilterOptions.push_back(aValue);
+        }
+
         mxComponent = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument", comphelper::containerToSequence(aFilterOptions));
         if (pPassword)
         {
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index a543e9df4bb6..5eb86b23da7b 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -1400,6 +1400,48 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
     }
 
     Graphic aGraphic( *pOLENd->GetGraphic() );
+
+    SwDocShell* pDocSh = rHTMLWrt.pDoc->GetDocShell();
+    bool bObjectOpened = false;
+    if (rHTMLWrt.mbXHTML && pDocSh)
+    {
+        // Map native data to an outer <object> element.
+
+        // Calculate the file name, which is meant to be the same as the
+        // replacement image, just with a .ole extension.
+        OUString aFileName;
+        if (rHTMLWrt.GetOrigFileName())
+            aFileName = *rHTMLWrt.GetOrigFileName();
+        INetURLObject aURL(aFileName);
+        OUString aName(aURL.getBase());
+        aName += "_";
+        aName += aURL.getExtension();
+        aName += "_";
+        aName += OUString::number(aGraphic.GetChecksum(), 16);
+        aURL.setBase(aName);
+        aURL.setExtension("ole");
+        aFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+        // Write the data.
+        OUString aStreamName = pOLENd->GetOLEObj().GetCurrentPersistName();
+        uno::Reference<embed::XStorage> xStorage = pDocSh->GetStorage();
+        uno::Reference<io::XStream> xInStream
+            = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
+        SvFileStream aOutStream(aFileName, StreamMode::WRITE);
+        uno::Reference<io::XStream> xOutStream(new utl::OStreamWrapper(aOutStream));
+        comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(),
+                                                      xOutStream->getOutputStream());
+        aFileName = URIHelper::simpleNormalizedMakeRelative(rWrt.GetBaseURL(), aFileName);
+
+        // Refer to this data.
+        if (rHTMLWrt.m_bLFPossible)
+            rHTMLWrt.OutNewLine();
+        rWrt.Strm().WriteOString("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object);
+        rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\">");
+        bObjectOpened = true;
+        rHTMLWrt.m_bLFPossible = true;
+    }
+
     OUString aGraphicURL;
     if(!rHTMLWrt.mbEmbedImages)
     {
@@ -1427,6 +1469,11 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
             pOLENd->GetTitle(), pOLENd->GetTwipSize(),
             nFlags, "ole" );
 
+    if (bObjectOpened)
+        // Close native data.
+        rWrt.Strm().WriteOString("</" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object
+                                 ">");
+
     return rWrt;
 }
 
commit dbf9728327564df7737cec83c1e97bbf049e64ca
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 7 17:50:00 2018 +0100

    sw XHTML export: let reqif-xhtml= imply XHTML
    
    An XML namespace for non-XHTML makes little sense.
    
    Change-Id: I0ae1b2886a8d81be3c932c9e74aa91cd2e2fa447
    Reviewed-on: https://gerrit.libreoffice.org/50905
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit a1aa7cfe28c80296d160528a62da33cc031101b0)

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index c0ccd6212077..00327893fa5e 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -55,8 +55,8 @@ private:
             setImportFilterOptions("xhtmlns=reqif-xhtml");
             // Bypass filter detect.
             setImportFilterName("HTML (StarWriter)");
-            // Export options.
-            setFilterOptions("XHTML,xhtmlns=reqif-xhtml");
+            // Export options (implies XHTML).
+            setFilterOptions("xhtmlns=reqif-xhtml");
         }
         else
             setFilterOptions("");
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index fa9e5fec8c7f..b190607c3c72 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -196,6 +196,8 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
             if (maNamespace == "reqif-xhtml")
                 // XHTML is always just a fragment inside ReqIF.
                 mbSkipHeaderFooter = true;
+            // XHTML namespace implies XHTML.
+            mbXHTML = true;
         }
     }
 }
commit 0485730bbd4d5c2b296eede549e10f9c89364200
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 7 14:38:02 2018 +0100

    sw XHTML import: handle alt text of OLE objects
    
    That ended up in the body text instead previously, which is unexpected.
    
    Reviewed-on: https://gerrit.libreoffice.org/50897
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit b9086ccff6325bdfaf0cf03715fd8be7e2628169)
    
    Conflicts:
            sw/source/filter/html/swhtml.cxx
    
    Change-Id: Ia40d83b3243c313462dce2617404a0670a7debb2

diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
index 05abc7721d24..b552783068ae 100644
--- a/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
+++ b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
@@ -1,6 +1,6 @@
 <reqif-xhtml:div><reqif-xhtml:br/>
     <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf">
-        <reqif-xhtml:object data="reqif-ole-img.png" type="image/png"/>
+        <reqif-xhtml:object data="reqif-ole-img.png" type="image/png">OLE Object</reqif-xhtml:object>
     </reqif-xhtml:object>
 </reqif-xhtml:div>
 
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 742d570d2bd8..cddda2bc6d1b 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -288,6 +288,9 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
         = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
     // This was empty.
     CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
+
+    // Check alternate text (it was empty).
+    CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index f3932e89b91f..5c5c9f0ae810 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -109,9 +109,12 @@
 #include <SwAppletImpl.hxx>
 
 #include <sfx2/viewfrm.hxx>
+#include <svx/svdobj.hxx>
 
 #include <statstr.hrc>
 #include <swerror.h>
+#include <ndole.hxx>
+#include <unoframe.hxx>
 #include <css1atr.hxx>
 
 #define FONTSIZE_MASK           7
@@ -1483,6 +1486,23 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
         {
             if( !m_bDocInitalized )
                 DocumentDetected();
+
+            if (!m_aEmbeds.empty())
+            {
+                // The text token is inside an OLE object, which means
+                // alternate text.
+                SwOLENode* pOLENode = m_aEmbeds.top();
+                if (SwFlyFrameFormat* pFormat
+                    = dynamic_cast<SwFlyFrameFormat*>(pOLENode->GetFlyFormat()))
+                {
+                    if (SdrObject* pObject = SwXFrame::GetOrCreateSdrObject(*pFormat))
+                    {
+                        pObject->SetTitle(pObject->GetTitle() + aToken);
+                        break;
+                    }
+                }
+            }
+
             m_xDoc->getIDocumentContentOperations().InsertString( *m_pPam, aToken );
 
             // if there are temporary paragraph attributes and the
commit 195a684fcfa9876b56ed02cbe122f995d76c0fdf
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Mar 7 11:35:12 2018 +0100

    sw XHTML import: handle media type of OLE object data
    
    For both the native data and the replacement image.
    
    Change-Id: I590fa037f78fe1a4dca41ec4173670f554bb9c6c
    Reviewed-on: https://gerrit.libreoffice.org/50876
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 16605d0cdc2c15ab4ae175531ba52824bf52bc70)

diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 6fed482c0eeb..742d570d2bd8 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -14,6 +14,7 @@
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/BitmapMode.hpp>
 #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
 #include <tools/datetime.hxx>
 #include <unotools/datetime.hxx>
 #include <vcl/GraphicNativeTransform.hxx>
@@ -265,7 +266,8 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0),
                                                                uno::UNO_QUERY);
     // This failed, OLE object had no replacement image.
-    CPPUNIT_ASSERT(xObject->getReplacementGraphic().is());
+    uno::Reference<graphic::XGraphic> xGraphic = xObject->getReplacementGraphic();
+    CPPUNIT_ASSERT(xGraphic.is());
 
     uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
     OutputDevice* pDevice = Application::GetDefaultDevice();
@@ -275,6 +277,17 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
     awt::Size aSize = xShape->getSize();
     // This was only 1247, size was not set explicitly.
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
+
+    // Check mime/media types.
+    CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty<OUString>(xGraphic, "MimeType"));
+
+    uno::Reference<document::XStorageBasedDocument> xStorageProvider(mxComponent, uno::UNO_QUERY);
+    uno::Reference<embed::XStorage> xStorage = xStorageProvider->getDocumentStorage();
+    auto aStreamName = getProperty<OUString>(xObject, "StreamName");
+    uno::Reference<io::XStream> xStream
+        = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
+    // This was empty.
+    CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 80db528cb683..a543e9df4bb6 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -436,7 +436,7 @@ void SwHTMLParser::InsertEmbed()
         if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
             return;
 
-        rObj.SetGraphic(aGraphic, OUString());
+        rObj.SetGraphic(aGraphic, aType);
 
         // Set the size of the OLE frame to the size of the graphic.
         OutputDevice* pDevice = Application::GetDefaultDevice();
@@ -499,6 +499,14 @@ void SwHTMLParser::InsertEmbed()
             uno::Reference<io::XStream> xOutStream
                 = xStorage->openStreamElement(aObjName, embed::ElementModes::READWRITE);
             comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream->getOutputStream());
+
+            if (!aType.isEmpty())
+            {
+                // Set media type of the native data.
+                uno::Reference<beans::XPropertySet> xOutStreamProps(xOutStream, uno::UNO_QUERY);
+                if (xOutStreamProps.is())
+                    xOutStreamProps->setPropertyValue("MediaType", uno::makeAny(aType));
+            }
         }
         xObj = aCnt.GetEmbeddedObject(aObjName);
     }
commit c5ff3f26080f136fa2893172ed3462e864dad7b7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Mar 6 13:45:19 2018 +0100

    sw XHTML import: handle size of replacement graphic of <object>
    
    Similar to how <img src="..."> defaults to the pixel size.
    
    Change-Id: I2c55522366e8635c491b322ca70fc3e2d79617fc
    Reviewed-on: https://gerrit.libreoffice.org/50836
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 970d20a3abd187d5a14f0af3639f116e47d15179)

diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 1c14836c7dac..6fed482c0eeb 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -266,6 +266,15 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
                                                                uno::UNO_QUERY);
     // This failed, OLE object had no replacement image.
     CPPUNIT_ASSERT(xObject->getReplacementGraphic().is());
+
+    uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
+    OutputDevice* pDevice = Application::GetDefaultDevice();
+    Size aPixel(64, 64);
+    // Expected to be 1693.
+    Size aLogic(pDevice->PixelToLogic(aPixel, MapMode(MapUnit::Map100thMM)));
+    awt::Size aSize = xShape->getSize();
+    // This was only 1247, size was not set explicitly.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index e60a20cf3117..80db528cb683 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -437,6 +437,28 @@ void SwHTMLParser::InsertEmbed()
             return;
 
         rObj.SetGraphic(aGraphic, OUString());
+
+        // Set the size of the OLE frame to the size of the graphic.
+        OutputDevice* pDevice = Application::GetDefaultDevice();
+        if (aSize.getHeight() == USHRT_MAX || aSize.getWidth() == USHRT_MAX)
+        {
+            Size aPixelSize = aGraphic.GetSizePixel(pDevice);
+            if (aSize.getWidth() == USHRT_MAX)
+                aSize.setWidth(aPixelSize.getWidth());
+            if (aSize.getHeight() == USHRT_MAX)
+                aSize.setHeight(aPixelSize.getHeight());
+        }
+
+        SwFrameFormat* pFormat = pOLENode->GetFlyFormat();
+        if (!pFormat)
+            return;
+
+        SwAttrSet aAttrSet(pFormat->GetAttrSet());
+        aAttrSet.ClearItem(RES_CNTNT);
+        Size aTwipSize(pDevice->PixelToLogic(aSize, MapMode(MapUnit::MapTwip)));
+        SwFormatFrameSize aFrameSize(ATT_FIX_SIZE, aTwipSize.Width(), aTwipSize.Height());
+        aAttrSet.Put(aFrameSize);
+        pOLENode->GetDoc()->SetFlyFrameAttr(*pFormat, aAttrSet);
         return;
     }
 
commit 52af287dac3d6deef5db942d1851ea74bf357078
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Mar 6 11:01:52 2018 +0100

    sw XHTML import: map nested <object> to replacement graphic
    
    Handle the case when the native data is the outer element and the
    replacement image is the inner one.
    
    Reviewed-on: https://gerrit.libreoffice.org/50812
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 62eb6d3f964e78fa210bba4af81ebf63ba8a16a9)
    
    Conflicts:
            sw/source/filter/html/htmlplug.cxx
    
    Change-Id: Ifc3c8b8bc8c0903562a4dab1f0bf15e9de5c98ac

diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.png b/sw/qa/extras/htmlimport/data/reqif-ole-img.png
new file mode 100644
index 000000000000..fdad35484e7c
Binary files /dev/null and b/sw/qa/extras/htmlimport/data/reqif-ole-img.png differ
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
new file mode 100644
index 000000000000..05abc7721d24
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml
@@ -0,0 +1,6 @@
+<reqif-xhtml:div><reqif-xhtml:br/>
+    <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf">
+        <reqif-xhtml:object data="reqif-ole-img.png" type="image/png"/>
+    </reqif-xhtml:object>
+</reqif-xhtml:div>
+
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 81b733072f8a..1c14836c7dac 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/graphic/GraphicType.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/BitmapMode.hpp>
+#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
 #include <tools/datetime.hxx>
 #include <unotools/datetime.hxx>
 #include <vcl/GraphicNativeTransform.hxx>
@@ -256,6 +257,17 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
 }
 
+DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
+{
+    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
+                                                     uno::UNO_QUERY);
+    uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0),
+                                                               uno::UNO_QUERY);
+    // This failed, OLE object had no replacement image.
+    CPPUNIT_ASSERT(xObject->getReplacementGraphic().is());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 9edae9befc83..e60a20cf3117 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -65,6 +65,7 @@
 #include <comphelper/classids.hxx>
 #include <rtl/uri.hxx>
 #include <comphelper/storagehelper.hxx>
+#include <vcl/graphicfilter.hxx>
 
 using namespace com::sun::star;
 
@@ -426,6 +427,19 @@ void SwHTMLParser::InsertEmbed()
     if( !bHasURL && !bHasType && !bHasData )
         return;
 
+    if (!m_aEmbeds.empty())
+    {
+        // Nested XHTML <object> element: points to replacement graphic.
+        SwOLENode* pOLENode = m_aEmbeds.top();
+        svt::EmbeddedObjectRef& rObj = pOLENode->GetOLEObj().GetObject();
+        Graphic aGraphic;
+        if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
+            return;
+
+        rObj.SetGraphic(aGraphic, OUString());
+        return;
+    }
+
     // das Plugin anlegen
     comphelper::EmbeddedObjectContainer aCnt;
     OUString aObjName;
@@ -517,6 +531,15 @@ void SwHTMLParser::InsertEmbed()
         // Rahmen umwandelt, muessen die Frames hier von Hand angelegt werden.
         RegisterFlyFrame( pFlyFormat );
     }
+
+    if (!bHasData)
+        return;
+
+    SwOLENode* pOLENode = pNoTextNd->GetOLENode();
+    if (!pOLENode)
+        return;
+
+    m_aEmbeds.push(pOLENode);
 }
 
 #if HAVE_FEATURE_JAVA
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 2b412ec142ab..f3932e89b91f 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -1394,6 +1394,11 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
 #endif
         break;
 
+    case HtmlTokenId::OBJECT_OFF:
+        if (!m_aEmbeds.empty())
+            m_aEmbeds.pop();
+        break;
+
     case HtmlTokenId::APPLET_ON:
 #if HAVE_FEATURE_JAVA
         InsertApplet();
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index bf6be7febbb4..6cae2022e1bc 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -35,6 +35,7 @@
 #include <memory>
 #include <vector>
 #include <deque>
+#include <stack>
 
 class SfxMedium;
 class SfxViewFrame;
@@ -483,6 +484,12 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
 
     bool m_bXHTML = false;
 
+    /**
+     * Non-owning pointers to already inserted OLE nodes, matching opened
+     * <object> XHTML elements.
+     */
+    std::stack<SwOLENode*> m_aEmbeds;
+
     void DeleteFormImpl();
 
     void DocumentDetected();
commit f575344b6d840c963763ac543e75fc26224721ff
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Mar 5 17:29:51 2018 +0100

    sw XHTML import: map <object> to OLE objects
    
    This handles native data only so far, replacement image still needs
    doing.
    
    Reviewed-on: https://gerrit.libreoffice.org/50778
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit c40afac8a39403f1c785151c9066becccf79078b)
    
    Conflicts:
            sw/source/filter/html/htmlplug.cxx
    
    Change-Id: I5f51bc7d837309fa0b88b277c1b754e435cb4208

diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.ole b/sw/qa/extras/htmlimport/data/reqif-ole-data.ole
new file mode 100644
index 000000000000..d3dc23d793e2
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-ole-data.ole
@@ -0,0 +1 @@
+{\pict}
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml b/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml
new file mode 100644
index 000000000000..9e0cfaa378b4
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml
@@ -0,0 +1,3 @@
+<reqif-xhtml:div>
+    <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf"/>
+</reqif-xhtml:div>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index f1e6bb235909..81b733072f8a 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -247,6 +247,15 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
     CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
 }
 
+DECLARE_HTMLIMPORT_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
+{
+    uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
+                                                     uno::UNO_QUERY);
+    // This was 0, <object> without URL was ignored.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 524e23b9ce64..9edae9befc83 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -49,6 +49,7 @@
 #include "swerror.h"
 #include "ndole.hxx"
 #include "swtable.hxx"
+#include <docsh.hxx>
 #include "swhtml.hxx"
 #include "wrthtml.hxx"
 #include "htmlfly.hxx"
@@ -58,9 +59,12 @@
 #include <com/sun/star/embed/Aspects.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
 
 #include <comphelper/embeddedobjectcontainer.hxx>
 #include <comphelper/classids.hxx>
+#include <rtl/uri.hxx>
+#include <comphelper/storagehelper.hxx>
 
 using namespace com::sun::star;
 
@@ -292,6 +296,7 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace,
 void SwHTMLParser::InsertEmbed()
 {
     OUString aURL, aType, aName, aAlt, aId, aStyle, aClass;
+    OUString aData;
     Size aSize( USHRT_MAX, USHRT_MAX );
     Size aSpace( USHRT_MAX, USHRT_MAX );
     bool bPrcWidth = false, bPrcHeight = false, bHidden = false;
@@ -359,6 +364,10 @@ void SwHTMLParser::InsertEmbed()
             if( USHRT_MAX==aSpace.Height() )
                 aSpace.Height() = (long)rOption.GetNumber();
             break;
+        case HtmlOptionId::DATA:
+            if (m_bXHTML && aURL.isEmpty())
+                aData = rOption.GetString();
+            break;
         case HtmlOptionId::UNKNOWN:
             if (rOption.GetTokenString().equalsIgnoreAsciiCase(
                         OOO_STRING_SW_HTML_O_Hidden))
@@ -402,31 +411,60 @@ void SwHTMLParser::InsertEmbed()
                        URIHelper::SmartRel2Abs(
                            INetURLObject(m_sBaseURL), aURL,
                            URIHelper::GetMaybeFileHdl()) );
+    bool bHasData = !aData.isEmpty();
+    try
+    {
+        aURLObj.SetURL(rtl::Uri::convertRelToAbs(m_sBaseURL, aData));
+    }
+    catch (const rtl::MalformedUriException& /*rException*/)
+    {
+        bHasData = false;
+    }
 
     // do not insert plugin if it has neither URL nor type
     bool bHasType = !aType.isEmpty();
-    if( !bHasURL && !bHasType )
+    if( !bHasURL && !bHasType && !bHasData )
         return;
 
     // das Plugin anlegen
     comphelper::EmbeddedObjectContainer aCnt;
     OUString aObjName;
-    uno::Reference < embed::XEmbeddedObject > xObj = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aObjName );
-    if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
+    uno::Reference < embed::XEmbeddedObject > xObj;
+    if (!bHasData)
     {
-        uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
-        if ( xSet.is() )
+        xObj = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aObjName );
+        if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
         {
-            if( bHasURL )
-                xSet->setPropertyValue("PluginURL", uno::makeAny( aURL ) );
-            if( bHasType )
-                xSet->setPropertyValue("PluginMimeType", uno::makeAny( aType ) );
+            uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
+            if ( xSet.is() )
+            {
+                if( bHasURL )
+                    xSet->setPropertyValue("PluginURL", uno::makeAny( aURL ) );
+                if( bHasType )
+                    xSet->setPropertyValue("PluginMimeType", uno::makeAny( aType ) );
 
-            uno::Sequence < beans::PropertyValue > aProps;
-            aCmdLst.FillSequence( aProps );
-            xSet->setPropertyValue("PluginCommands", uno::makeAny( aProps ) );
+                uno::Sequence < beans::PropertyValue > aProps;
+                aCmdLst.FillSequence( aProps );
+                xSet->setPropertyValue("PluginCommands", uno::makeAny( aProps ) );
 
+            }
+        }
+    }
+    else if (SwDocShell* pDocSh = m_xDoc->GetDocShell())
+    {
+        // Has non-empty data attribute in XHTML: map that to an OLE object.
+        uno::Reference<embed::XStorage> xStorage = pDocSh->GetStorage();
+        aCnt.SwitchPersistence(xStorage);
+        aObjName = aCnt.CreateUniqueObjectName();
+        {
+            SvFileStream aFileStream(aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE),
+                                     StreamMode::READ);
+            uno::Reference<io::XInputStream> xInStream(new utl::OStreamWrapper(aFileStream));
+            uno::Reference<io::XStream> xOutStream
+                = xStorage->openStreamElement(aObjName, embed::ElementModes::READWRITE);
+            comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream->getOutputStream());
         }
+        xObj = aCnt.GetEmbeddedObject(aObjName);
     }
 
     SfxItemSet aFrameSet( m_xDoc->GetAttrPool(),
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index a629667a4e14..2b412ec142ab 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -1383,6 +1383,11 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
         break;
 
     case HtmlTokenId::OBJECT_ON:
+        if (m_bXHTML)
+        {
+            InsertEmbed();
+            break;
+        }
 #if HAVE_FEATURE_JAVA
         NewObject();
         m_bCallNextToken = m_pAppletImpl!=nullptr && m_pTable!=nullptr;
@@ -5549,7 +5554,10 @@ void SwHTMLParser::SetupFilterOptions()
     OUString aFilterOptions = pItem->GetValue();
     const OUString aXhtmlNsKey("xhtmlns=");
     if (aFilterOptions.startsWith(aXhtmlNsKey))
+    {
         SetNamespace(aFilterOptions.copy(aXhtmlNsKey.getLength()));
+        m_bXHTML = true;
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 8bed120d3060..bf6be7febbb4 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -481,6 +481,8 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
 
     SfxViewFrame* m_pTempViewFrame;
 
+    bool m_bXHTML = false;
+
     void DeleteFormImpl();
 
     void DocumentDetected();
commit 63618e669e8c33cf0b3431eaadd6332ab3e19433
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 1 17:50:52 2018 +0100

    sw HTML export: XHTML ns alias for table markup
    
    This was forgotten from the previous mass-conversion of adding namespace
    aliases to written elements.
    
    Reviewed-on: https://gerrit.libreoffice.org/50595
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 12c3ab8c341ff6482ce380ca4010bb7b97e35bf7)
    
    Conflicts:
            sw/source/filter/html/htmltabw.cxx
    
    Change-Id: Id9b7e961c941ec3b3614e3694963c3f9ef9e46eb

diff --git a/sw/qa/extras/htmlexport/data/reqif-p.xhtml b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
index 36f5aa11768b..2f069d78e0eb 100644
--- a/sw/qa/extras/htmlexport/data/reqif-p.xhtml
+++ b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
@@ -1 +1,2 @@
 <reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
+<reqif-xhtml:table><reqif-xhtml:tr><reqif-xhtml:td>in table</reqif-xhtml:tr></reqif-xhtml:tr></reqif-xhtml:table>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 4632498e302e..c0ccd6212077 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -337,6 +337,10 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
     CPPUNIT_ASSERT(pStream);
 
     OString aExpected("<reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb</reqif-xhtml:p>" SAL_NEWLINE_STRING);
+
+    // This was '<table' instead.
+    aExpected += "<reqif-xhtml:table";
+
     OString aActual(read_uInt8s_ToOString(*pStream, aExpected.getLength()));
     // This was a HTML header, like '<!DOCTYPE html ...'.
     CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx
index e8d1924d5156..cd9fba58722d 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -303,7 +303,8 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
     rWrt.OutNewLine();  // <TH>/<TD> in neue Zeile
     OStringBuffer sOut;
     sOut.append('<');
-    sOut.append(bHead ? OOO_STRING_SVTOOLS_HTML_tableheader : OOO_STRING_SVTOOLS_HTML_tabledata);
+    OString aTag(bHead ? OOO_STRING_SVTOOLS_HTML_tableheader : OOO_STRING_SVTOOLS_HTML_tabledata);
+    sOut.append(rWrt.GetNamespace() + aTag);
 
     // ROW- und COLSPAN ausgeben
     if( nRowSpan>1 )
@@ -489,7 +490,7 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
 
     if( rWrt.m_bLFPossible )
         rWrt.OutNewLine();
-    OString aTag = bHead ? OOO_STRING_SVTOOLS_HTML_tableheader : OOO_STRING_SVTOOLS_HTML_tabledata;
+    aTag = bHead ? OOO_STRING_SVTOOLS_HTML_tableheader : OOO_STRING_SVTOOLS_HTML_tabledata;
     HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), rWrt.GetNamespace() + aTag, false);
     rWrt.m_bLFPossible = true;
 }
@@ -521,7 +522,7 @@ void SwHTMLWrtTable::OutTableCells( SwHTMLWriter& rWrt,
     }
 
     rWrt.OutNewLine();  // <TR> in neuer Zeile
-    rWrt.Strm().WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tablerow );
+    rWrt.Strm().WriteChar( '<' ).WriteOString( rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_tablerow );
     if( pBrushItem )
     {
         rWrt.OutBackground( pBrushItem, false );
@@ -605,7 +606,7 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 eAlign,
     if( rWrt.m_bLFPossible )
         rWrt.OutNewLine();  // <TABLE> in neue Zeile
     OStringBuffer sOut;
-    sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_table);
+    sOut.append('<').append(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_table);
 
     const SvxFrameDirection nOldDirection = rWrt.m_nDirection;
     if( pFrameFormat )
@@ -739,7 +740,7 @@ void SwHTMLWrtTable::Write( SwHTMLWriter& rWrt, sal_Int16 eAlign,
             const SwWriteTableCol *pColumn = m_aCols[nCol];
 
             OStringBuffer sOutStr;
-            sOutStr.append('<').append(OOO_STRING_SVTOOLS_HTML_col);
+            sOutStr.append('<').append(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_col);
 
             sal_uInt32 nWidth;
             bool bRel;
commit 7ba8ec01a86c4415dbdcba777cec2fd580e51a03
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 28 12:00:38 2018 +0100

    sw HTML export: ReqIf implies we write a fragment
    
    Test that for a very simple input we roundtrip perfectly (not counting
    whitespace changes).
    
    Change-Id: I89cfbe1da594f8a5343444ca20a107021d6a1a37
    Reviewed-on: https://gerrit.libreoffice.org/50522
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit eb1049597bd92d61a2ad319bc9a2c3f9a08dd259)

diff --git a/sw/qa/extras/htmlexport/data/reqif-p.xhtml b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
new file mode 100644
index 000000000000..36f5aa11768b
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-p.xhtml
@@ -0,0 +1 @@
+<reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 8afe67449fa4..4632498e302e 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -50,6 +50,14 @@ private:
             setFilterOptions("EmbedImages");
         else if (getTestName().indexOf("XHTML") != -1)
             setFilterOptions("XHTML");
+        else if (getTestName().indexOf("ReqIf") != -1)
+        {
+            setImportFilterOptions("xhtmlns=reqif-xhtml");
+            // Bypass filter detect.
+            setImportFilterName("HTML (StarWriter)");
+            // Export options.
+            setFilterOptions("XHTML,xhtmlns=reqif-xhtml");
+        }
         else
             setFilterOptions("");
 
@@ -323,6 +331,17 @@ DECLARE_HTMLEXPORT_TEST(testXHTML, "hello.html")
     assertXPath(pDoc, "/html/body", "xml:lang", "en-US");
 }
 
+DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
+{
+    SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
+    CPPUNIT_ASSERT(pStream);
+
+    OString aExpected("<reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb</reqif-xhtml:p>" SAL_NEWLINE_STRING);
+    OString aActual(read_uInt8s_ToOString(*pStream, aExpected.getLength()));
+    // This was a HTML header, like '<!DOCTYPE html ...'.
+    CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
+}
+
 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 33c990176524..1bcb687ccc85 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -3068,6 +3068,10 @@ static Writer& OutCSS1_SvxFormatBreak_SwFormatPDesc_SvxFormatKeep( Writer& rWrt,
         }
     }
 
+    if (rHTMLWrt.mbSkipHeaderFooter)
+        // No page break when writing only a fragment.
+        return rWrt;
+
     if( pBreakBefore )
         rHTMLWrt.OutCSS1_PropertyAscii( sCSS1_P_page_break_before,
                                         pBreakBefore );
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 286b9196f951..199c8a45c57e 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -740,7 +740,7 @@ void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat,
             (rHWrt.m_nDefListLvl-1) * rHWrt.m_nDefListMargin;
     }
 
-    if( rHWrt.m_bLFPossible )
+    if( rHWrt.m_bLFPossible && !rHWrt.m_bFirstLine )
         rHWrt.OutNewLine(); // paragraph tag on a new line
     rInfo.bOutPara = false;
 
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index 1019ad306d9a..fa9e5fec8c7f 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -191,7 +191,12 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
         if (rOption == "XHTML")
             mbXHTML = true;
         else if (rOption.startsWith(aXhtmlNsKey))
+        {
             maNamespace = rOption.copy(aXhtmlNsKey.getLength()).toUtf8();
+            if (maNamespace == "reqif-xhtml")
+                // XHTML is always just a fragment inside ReqIF.
+                mbSkipHeaderFooter = true;
+        }
     }
 }
 
commit 787ba6e234d32fb54a819865fbc9f1447ce5c3d2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 27 15:30:25 2018 +0100

    sw HTML export: handle XHTML ns alias even with HTMLOutFuncs::Out_AsciiTag()
    
    This is meant to be mechanical, full conversion to HtmlWriter has to be
    done step by step in follow-up commits.
    
    Reviewed-on: https://gerrit.libreoffice.org/50449
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit b4f3af91d344d5f8c18e060615360e2a6633b63f)
    
    Conflicts:
            include/svtools/htmlout.hxx
            svtools/source/svhtml/htmlout.cxx
            sw/source/filter/html/htmlatr.cxx
            sw/source/filter/html/htmlplug.cxx
            sw/source/filter/html/htmltabw.cxx
    
    Change-Id: Ieab096f8c9936f0ecad029fbdfb51da7412ad83e

diff --git a/include/svtools/htmlout.hxx b/include/svtools/htmlout.hxx
index 979741af0f85..a906fed1f566 100644
--- a/include/svtools/htmlout.hxx
+++ b/include/svtools/htmlout.hxx
@@ -57,7 +57,7 @@ struct HTMLOutFuncs
                         rtl_TextEncoding eDestEnc,
                         OUString *pNonConvertableChars );
 
-    SVT_DLLPUBLIC static SvStream& Out_AsciiTag( SvStream&, const sal_Char* pStr,
+    SVT_DLLPUBLIC static SvStream& Out_AsciiTag( SvStream&, const OString& rStr,
                                    bool bOn = true,
                                    rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_MS_1252);
     SVT_DLLPUBLIC static SvStream& Out_Char( SvStream&, sal_uInt32 cChar,
diff --git a/svtools/source/svhtml/htmlout.cxx b/svtools/source/svhtml/htmlout.cxx
index c52207e10f32..66d4206c430d 100644
--- a/svtools/source/svhtml/htmlout.cxx
+++ b/svtools/source/svhtml/htmlout.cxx
@@ -513,7 +513,7 @@ OString HTMLOutFuncs::ConvertStringToHTML( const OUString& rSrc,
     return aDest.makeStringAndClear();
 }
 
-SvStream& HTMLOutFuncs::Out_AsciiTag( SvStream& rStream, const sal_Char *pStr,
+SvStream& HTMLOutFuncs::Out_AsciiTag( SvStream& rStream, const OString& rStr,
                                       bool bOn, rtl_TextEncoding )
 {
     if(bOn)
@@ -521,7 +521,7 @@ SvStream& HTMLOutFuncs::Out_AsciiTag( SvStream& rStream, const sal_Char *pStr,
     else
         rStream.WriteCharPtr("</");
 
-    rStream.WriteCharPtr(pStr).WriteChar('>');
+    rStream.WriteOString(rStr).WriteChar('>');
 
     return rStream;
 }
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index bb80e234df7d..33c990176524 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -227,7 +227,7 @@ void SwHTMLWriter::OutCSS1_Property( const sal_Char *pProp,
     {
         m_bFirstCSS1Rule = false;
         OutNewLine();
-        sOut.append("<" OOO_STRING_SVTOOLS_HTML_style " "
+        sOut.append("<" + GetNamespace() + OOO_STRING_SVTOOLS_HTML_style " "
                     OOO_STRING_SVTOOLS_HTML_O_type "=\"text/css\">");
     //  Optional CSS2 code for dot leaders (dotted line between the Table of Contents titles and page numbers):
     //  (More information: http://www.w3.org/Style/Examples/007/leaders.en.html)
@@ -289,7 +289,7 @@ void SwHTMLWriter::OutCSS1_Property( const sal_Char *pProp,
             }
             else
             {
-                HTMLOutFuncs::Out_AsciiTag( Strm(), OOO_STRING_SVTOOLS_HTML_span, false );
+                HTMLOutFuncs::Out_AsciiTag( Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false );
                 return;
             }
             break;
@@ -591,7 +591,7 @@ void SwHTMLWriter::OutStyleSheet( const SwPageDesc& rPageDesc )
         DecIndentLevel();
 
         OutNewLine();
-        HTMLOutFuncs::Out_AsciiTag( Strm(), OOO_STRING_SVTOOLS_HTML_style, false );
+        HTMLOutFuncs::Out_AsciiTag( Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_style, false );
     }
     else
     {
@@ -2828,7 +2828,7 @@ static Writer& OutCSS1_SwFormatDrop( Writer& rWrt, const SfxPoolItem& rHt )
     }
     else
     {
-        HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_span, false );
+        HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false );
     }
 
     return rWrt;
@@ -3391,7 +3391,7 @@ Writer& OutCSS1_SvxBox( Writer& rWrt, const SfxPoolItem& rHt )
         }
         else
         {
-            HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_span, false );
+            HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false );
             return rWrt;
         }
     }
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 354f52c38a8f..286b9196f951 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -136,7 +136,7 @@ void SwHTMLWriter::OutAndSetDefList( sal_uInt16 nNewLvl )
         {
             if( m_bLFPossible )
                 OutNewLine();
-            HTMLOutFuncs::Out_AsciiTag( Strm(), OOO_STRING_SVTOOLS_HTML_deflist );

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list