[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - 2 commits - sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Aug 31 08:21:06 UTC 2018


 sw/qa/extras/htmlexport/data/reqif-no-lang.odt    |binary
 sw/qa/extras/htmlexport/data/reqif-ole-nodata.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx            |   47 ++++++++++++--
 sw/source/filter/html/htmlplug.cxx                |   72 ++++++++++++++++------
 sw/source/filter/html/wrthtml.cxx                 |    3 
 5 files changed, 99 insertions(+), 23 deletions(-)

New commits:
commit 4f5103235d2e6769231f8acde792df12d1dd6e55
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Aug 30 15:08:36 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Fri Aug 31 10:13:01 2018 +0200

    sw XHTML export: xml:lang is not relevant for ReqIF
    
    I suppose if language is set, that happens in the wrapping ReqIF
    document, not in the XHTML fragments.
    
    Reviewed-on: https://gerrit.libreoffice.org/59810
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 81fac013cb365d711ad78a566ee1b5b13480b013)
    
    Change-Id: I970c3810b7f02bbafc37dd85e095b254cc651330

diff --git a/sw/qa/extras/htmlexport/data/reqif-no-lang.odt b/sw/qa/extras/htmlexport/data/reqif-no-lang.odt
new file mode 100644
index 000000000000..c831921a42a4
Binary files /dev/null and b/sw/qa/extras/htmlexport/data/reqif-no-lang.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index a2f133ea5615..884cbbd02d2e 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -646,6 +646,17 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt")
     CPPUNIT_ASSERT(!aSource.isEmpty());
 }
 
+DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt")
+{
+    SvMemoryStream aStream;
+    wrapFragment(aStream);
+    xmlDocPtr pDoc = parseXmlStream(&aStream);
+    CPPUNIT_ASSERT(pDoc);
+
+    // Make sure that xml:lang is not written in ReqIF mode.
+    assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:h1", "lang");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index 20b96a248045..730b7a1ebd58 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -1347,7 +1347,8 @@ sal_uInt16 SwHTMLWriter::GetLangWhichIdFromScript( sal_uInt16 nScript )
 
 void SwHTMLWriter::OutLanguage( LanguageType nLang )
 {
-    if( LANGUAGE_DONTKNOW != nLang )
+    // ReqIF mode: consumers would ignore language anyway.
+    if (LANGUAGE_DONTKNOW != nLang && !mbReqIF)
     {
         OStringBuffer sOut;
         sOut.append(' ');
commit e296a0a6b09e06e073209cc3ba0770dbee6a0a59
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Aug 30 14:14:11 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Fri Aug 31 10:12:51 2018 +0200

    sw XHTML export: improve dummy OLE object handling
    
    It is possible that we not only have a dummy OLE object, but both the
    replacement image and the native data is missing. Handle these enough so
    that we don't give up exporting the document and also produce valid
    output.
    
    Reviewed-on: https://gerrit.libreoffice.org/59806
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins
    (cherry picked from commit 5d997c029e53c31a3651a08f5012645097cec48f)
    
    Change-Id: Ia973ecfbfb7e8fdecdc831b29d3a82c988ed7ea5

diff --git a/sw/qa/extras/htmlexport/data/reqif-ole-nodata.odt b/sw/qa/extras/htmlexport/data/reqif-ole-nodata.odt
new file mode 100644
index 000000000000..a4d3243a8bf3
Binary files /dev/null and b/sw/qa/extras/htmlexport/data/reqif-ole-nodata.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index ac4a7e825de9..a2f133ea5615 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -35,6 +35,20 @@ public:
         m_eUnit(FUNIT_NONE)
     {}
 
+    /**
+     * Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can
+     * parse it.
+     */
+    void wrapFragment(SvMemoryStream& rStream)
+    {
+        rStream.WriteCharPtr(
+            "<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n");
+        SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
+        rStream.WriteStream(aFileStream);
+        rStream.WriteCharPtr("</reqif-xhtml:html>\n");
+        rStream.Seek(0);
+    }
+
 private:
     bool mustCalcLayoutOf(const char* filename) override
     {
@@ -603,11 +617,7 @@ DECLARE_HTMLEXPORT_TEST(testTransparentImage, "transparent-image.odt")
 DECLARE_HTMLEXPORT_TEST(testTransparentImageReqIf, "transparent-image.odt")
 {
     SvMemoryStream aStream;
-    aStream.WriteCharPtr("<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n");
-    SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
-    aStream.WriteStream(aFileStream);
-    aStream.WriteCharPtr("</reqif-xhtml:html>\n");
-    aStream.Seek(0);
+    wrapFragment(aStream);
     xmlDocPtr pDoc = parseXmlStream(&aStream);
     CPPUNIT_ASSERT(pDoc);
 
@@ -620,6 +630,22 @@ DECLARE_HTMLEXPORT_TEST(testTransparentImageReqIf, "transparent-image.odt")
     CPPUNIT_ASSERT_MESSAGE(aMessage.toUtf8().getStr(), aSource.endsWith(".png"));
 }
 
+DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt")
+{
+    // This failed, io::IOException was thrown during the filter() call.
+    SvMemoryStream aStream;
+    wrapFragment(aStream);
+    xmlDocPtr pDoc = parseXmlStream(&aStream);
+    CPPUNIT_ASSERT(pDoc);
+
+    // Make sure the native <object> element has the required data attribute.
+    OUString aSource = getXPath(
+        pDoc,
+        "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p/reqif-xhtml:object/reqif-xhtml:object",
+        "data");
+    CPPUNIT_ASSERT(!aSource.isEmpty());
+}
+
 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 70456390f54c..3565bf58952f 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -62,6 +62,7 @@
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/io/XActiveDataStreamer.hpp>
+#include <com/sun/star/io/IOException.hpp>
 #include <com/sun/star/embed/XEmbedPersist2.hpp>
 
 #include <comphelper/embeddedobjectcontainer.hxx>
@@ -73,6 +74,7 @@
 #include <comphelper/propertysequence.hxx>
 #include <filter/msfilter/msoleexp.hxx>
 #include <comphelper/fileurl.hxx>
+#include <osl/file.hxx>
 
 using namespace com::sun::star;
 
@@ -129,6 +131,33 @@ const HtmlFrmOpts HTML_FRMOPTS_OLE_CSS1       =
     HtmlFrmOpts::SAlign |
     HtmlFrmOpts::SSpace;
 
+namespace
+{
+/**
+ * Calculates a filename for an image, provided the HTML file name, the image
+ * itself and a wanted extension.
+ */
+OUString lcl_CalculateFileName(const OUString* pOrigFileName, const Graphic& rGraphic,
+                               const OUString& rExtension)
+{
+    OUString aFileName;
+
+    if (pOrigFileName)
+        aFileName = *pOrigFileName;
+    INetURLObject aURL(aFileName);
+    OUString aName(aURL.getBase());
+    aName += "_";
+    aName += aURL.getExtension();
+    aName += "_";
+    aName += OUString::number(rGraphic.GetChecksum(), 16);
+    aURL.setBase(aName);
+    aURL.setExtension(rExtension);
+    aFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+    return aFileName;
+}
+}
+
 void SwHTMLParser::SetFixSize( const Size& rPixSize,
                                const Size& rTwipDfltSize,
                                bool bPrcWidth, bool bPrcHeight,
@@ -1479,18 +1508,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
 
         // 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);
+        OUString aFileName = lcl_CalculateFileName(rHTMLWrt.GetOrigFileName(), aGraphic, "ole");
 
         // Write the data.
         SwOLEObj& rOLEObj = pOLENd->GetOLEObj();
@@ -1541,11 +1559,22 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
             // Otherwise the native data is just a grab-bag: ODummyEmbeddedObject.
             OUString aStreamName = rOLEObj.GetCurrentPersistName();
             uno::Reference<embed::XStorage> xStorage = pDocSh->GetStorage();
-            uno::Reference<io::XStream> xInStream
-                = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
-            uno::Reference<io::XStream> xOutStream(new utl::OStreamWrapper(aOutStream));
-            comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(),
-                                                          xOutStream->getOutputStream());
+            uno::Reference<io::XStream> xInStream;
+            try
+            {
+                // Even the native data may be missing.
+                xInStream = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
+            } catch (const uno::Exception& rException)
+            {
+                SAL_WARN("sw.html", "OutHTML_FrameFormatOLENodeGrf: failed to open stream element: " << rException.Message);
+            }
+            if (xInStream.is())
+            {
+                uno::Reference<io::XStream> xOutStream(new utl::OStreamWrapper(aOutStream));
+                comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(),
+                                                              xOutStream->getOutputStream());
+            }
+
             uno::Reference<beans::XPropertySet> xOutStreamProps(xInStream, uno::UNO_QUERY);
             if (xOutStreamProps.is())
                 xOutStreamProps->getPropertyValue("MediaType") >>= aFileType;
@@ -1580,6 +1609,15 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
             aFilterName = "PNG";
             nFlags = XOutFlags::NONE;
             aMimeType = "image/png";
+
+            if (aGraphic.GetType() == GraphicType::NONE)
+            {
+                // The OLE Object has no replacement image, write a stub.
+                aGraphicURL = lcl_CalculateFileName(rHTMLWrt.GetOrigFileName(), aGraphic, "png");
+                osl::File aFile(aGraphicURL);
+                aFile.open(osl_File_OpenFlag_Create);
+                aFile.close();
+            }
         }
 
         sal_uInt16 nErr = XOutBitmap::WriteGraphic( aGraphic, aGraphicURL,


More information about the Libreoffice-commits mailing list