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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 17 15:19:20 UTC 2020


 sw/qa/extras/htmlexport/htmlexport.cxx |   83 +++++++++++++++++++++++++++++++--
 sw/source/filter/html/css1atr.cxx      |    2 
 sw/source/filter/html/htmlatr.cxx      |   10 +++
 sw/source/filter/html/htmlfldw.cxx     |    2 
 sw/source/filter/html/wrthtml.hxx      |    1 
 5 files changed, 93 insertions(+), 5 deletions(-)

New commits:
commit ec855fe33351d482b6d60fd92cf531757fccee83
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 17 10:48:20 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 17 16:18:37 2020 +0100

    sw reqif-xhtml export: fix not needed font name/size
    
    The only reason commit 4cd3c436923bfba281b1bf16d9785208a2119cea (sw
    reqif-xhtml export: limit values of the style attribute, 2018-04-11)
    missed these is because they write their css properties directly, not
    going via SwHTMLWriter::OutCSS1_Property().
    
    Also adapt testReqIfWellFormed: its intention was to make sure that in
    case these properties are written, then inline CSS is used: that is true
    for XHTML, but not for ReqIF-XHTML.
    
    (cherry picked from commit 1655819c8914efad28f218f56d8d89d4e4bd9488)
    
    Change-Id: I4ceb2bb09187101baa6f4a74d65aaa4dc955511f

diff --git a/sw/qa/extras/htmlexport/data/reqif.odt b/sw/qa/extras/htmlexport/data/xhtml-css.odt
similarity index 100%
rename from sw/qa/extras/htmlexport/data/reqif.odt
rename to sw/qa/extras/htmlexport/data/xhtml-css.odt
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index faf86c966159..7d707888dea5 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -535,7 +535,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable2, "reqif-table2.odt")
     CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:td>") != -1);
 }
 
-DECLARE_HTMLEXPORT_TEST(testReqIfWellFormed, "reqif.odt")
+DECLARE_HTMLEXPORT_TEST(testXHTMLUseCSS, "xhtml-css.odt")
 {
     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
     CPPUNIT_ASSERT(pStream);
@@ -544,9 +544,9 @@ DECLARE_HTMLEXPORT_TEST(testReqIfWellFormed, "reqif.odt")
     pStream->Seek(0);
     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
     // This failed, <font face="..."> was written.
-    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"font-family:") != -1);
+    CPPUNIT_ASSERT(aStream.indexOf("<span style=\"font-family:") != -1);
     // This failed, <font size="..."> was written.
-    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"font-size:") != -1);
+    CPPUNIT_ASSERT(aStream.indexOf("<span style=\"font-size:") != -1);
 }
 
 DECLARE_HTMLEXPORT_TEST(testReqIfList, "reqif-list.xhtml")
@@ -847,6 +847,39 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifComment)
     CPPUNIT_ASSERT(pDoc);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifFontNameSize)
+{
+    // Create a document with a custom font name and size in it.
+    loadURL("private:factory/swriter", nullptr);
+    uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), uno::UNO_QUERY);
+    xParagraph->setPropertyValue("CharFontName", uno::makeAny(OUString("Liberation Serif")));
+    float fCharHeight = 14.0;
+    xParagraph->setPropertyValue("CharHeight", uno::makeAny(fCharHeight));
+    sal_Int32 nCharColor = 0xff0000;
+    xParagraph->setPropertyValue("CharColor", uno::makeAny(nCharColor));
+    uno::Reference<text::XTextRange> xTextRange(xParagraph, uno::UNO_QUERY);
+    xTextRange->setString("x");
+
+    // Export it.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreProperties = {
+        comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+        comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+    SvMemoryStream aStream;
+    HtmlExportTest::wrapFragment(maTempFile, aStream);
+    xmlDocPtr pDoc = parseXmlStream(&aStream);
+
+    // Make sure the output is well-formed.
+    CPPUNIT_ASSERT(pDoc);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 3
+    // i.e. font name and size was written, even if that's not relevant for ReqIF.
+    assertXPath(pDoc, "//reqif-xhtml:span", 1);
+}
+
 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 94dd953bd221..e98134fdc5ce 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -185,6 +185,7 @@ OString lclConvToHex(sal_uInt16 nHex)
 
     return OString(aNToABuf, 2);
 }
+}
 
 /// Determines if rProperty has to be suppressed due to ReqIF mode.
 bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
@@ -201,7 +202,6 @@ bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty)
 
     return true;
 }
-}
 
 OString GetCSS1_Color(const Color& rColor)
 {
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 807396ace498..f34d978e9806 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -2696,6 +2696,11 @@ static Writer& OutHTML_SvxFont( Writer& rWrt, const SfxPoolItem& rHt )
     if( rHTMLWrt.m_bOutOpts )
         return rWrt;
 
+    if (IgnorePropertyForReqIF(rHTMLWrt.mbReqIF, "font-family"))
+    {
+        return rWrt;
+    }
+
     if( rHTMLWrt.m_bTagOn )
     {
         OUString aNames;
@@ -2737,6 +2742,11 @@ static Writer& OutHTML_SvxFontHeight( Writer& rWrt, const SfxPoolItem& rHt )
     if( rHTMLWrt.m_bOutOpts )
         return rWrt;
 
+    if (IgnorePropertyForReqIF(rHTMLWrt.mbReqIF, "font-size"))
+    {
+        return rWrt;
+    }
+
     if( rHTMLWrt.m_bTagOn )
     {
         if (rHTMLWrt.mbXHTML)
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index a3fc7a115b34..3617bcdeed27 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -697,6 +697,7 @@ Writer& OutHTML_NumBulListEnd( SwHTMLWriter& rWrt,
 Writer& OutCSS1_SvxBox( Writer& rWrt, const SfxPoolItem& rHt );
 
 OString GetCSS1_Color(const Color& rColor);
+bool IgnorePropertyForReqIF(bool bReqIF, const OString& rProperty);
 
 #endif // INCLUDED_SW_SOURCE_FILTER_HTML_WRTHTML_HXX
 
commit ec17da9c7867e0e0667c6479f16021abb3008f24
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 17 09:16:21 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 17 11:59:48 2020 +0100

    sw reqif-xhtml export: fix not needed namespace for comments
    
    In general, all "foo" elements should be started as "<reqif-xhtml:foo"
    in the reqif case, but not for comments, which stay as "<!--".
    
    (cherry picked from commit a73483817faac173b2b9d4e970d2a05bfedc6798)
    
    Conflicts:
            sw/qa/extras/htmlexport/htmlexport.cxx
            sw/source/filter/html/htmlfldw.cxx
    
    Change-Id: I841c0d8e448f670b9b42cb915154e6264f7f150a

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 47288ae65ced..faf86c966159 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -17,6 +17,8 @@
 #include <com/sun/star/io/XActiveDataStreamer.hpp>
 #include <com/sun/star/io/XSeekable.hpp>
 #include <rtl/byteseq.hxx>
+#include <com/sun/star/frame/XDispatchHelper.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
 
 #include <swmodule.hxx>
 #include <swdll.hxx>
@@ -26,6 +28,7 @@
 #include <tools/urlobj.hxx>
 #include <svtools/rtfkeywd.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <comphelper/propertysequence.hxx>
 
 class HtmlExportTest : public SwModelTestBase, public HtmlTestTools
 {
@@ -803,6 +806,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testChinese)
     CPPUNIT_ASSERT(pDoc);
 }
 
+static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, const OUString& rCommand, const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+    uno::Reference<frame::XController> xController = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
+    CPPUNIT_ASSERT(xController.is());
+    uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xFrame.is());
+
+    uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+    uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+    CPPUNIT_ASSERT(xDispatchHelper.is());
+
+    xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifComment)
+{
+    // Create a document with a comment in it.
+    loadURL("private:factory/swriter", nullptr);
+    uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence(
+    {
+        {"Text", uno::makeAny(OUString("some text"))},
+        {"Author", uno::makeAny(OUString("me"))},
+    });
+    lcl_dispatchCommand(mxComponent, ".uno:InsertAnnotation", aPropertyValues);
+
+    // Export it.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreProperties = {
+        comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+        comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+    SvMemoryStream aStream;
+    HtmlExportTest::wrapFragment(maTempFile, aStream);
+    xmlDocPtr pDoc = parseXmlStream(&aStream);
+
+    // Without the accompanying fix in place, this test would have failed as the output was not
+    // well-formed.
+    CPPUNIT_ASSERT(pDoc);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlfldw.cxx b/sw/source/filter/html/htmlfldw.cxx
index 68527d90807a..eaa6e5e57510 100644
--- a/sw/source/filter/html/htmlfldw.cxx
+++ b/sw/source/filter/html/htmlfldw.cxx
@@ -511,7 +511,7 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
             OUString sComment(convertLineEnd(rComment, GetSystemLineEnd()));
             OStringBuffer sOut;
             // TODO: ???
-            sOut.append('<').append(rHTMLWrt.GetNamespace()).append(OOO_STRING_SVTOOLS_HTML_comment)
+            sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_comment)
                 .append(' ').append(OUStringToOString(sComment,
                     static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc)).append(" -->");
             rWrt.Strm().WriteCharPtr( sOut.getStr() );


More information about the Libreoffice-commits mailing list