[Libreoffice-commits] core.git: sw/qa sw/source

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


 sw/qa/extras/htmlexport/htmlexport.cxx |   39 ++++++++++++++++++++++++++++++---
 sw/source/filter/html/css1atr.cxx      |    2 -
 sw/source/filter/html/htmlatr.cxx      |   10 ++++++++
 sw/source/filter/html/wrthtml.hxx      |    1 
 4 files changed, 48 insertions(+), 4 deletions(-)

New commits:
commit 1655819c8914efad28f218f56d8d89d4e4bd9488
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 12:18:35 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.
    
    Change-Id: I4ceb2bb09187101baa6f4a74d65aaa4dc955511f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86962
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

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 b87d1bde173a..b5f50f1106aa 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -521,16 +521,16 @@ 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);
     sal_uInt64 nLength = pStream->TellEnd();
     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")
@@ -827,6 +827,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 709da0fbc878..0a48de57e35c 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -183,6 +183,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)
@@ -199,7 +200,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 8b501b0e894f..9e41f0da2289 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -2692,6 +2692,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;
@@ -2733,6 +2738,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 0f773901aa33..5d17081fdfd4 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -696,6 +696,7 @@ Writer& OutHTML_NumberBulletListEnd( 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
 


More information about the Libreoffice-commits mailing list