[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - sw/CppunitTest_sw_rtfexport.mk sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Wed May 27 02:31:03 PDT 2015


 sw/CppunitTest_sw_rtfexport.mk              |   31 -----------
 sw/qa/extras/inc/swmodeltestbase.hxx        |    6 ++
 sw/qa/extras/rtfexport/data/tdf90421.fodt   |    8 +++
 sw/qa/extras/rtfexport/rtfexport.cxx        |   23 ++++++++
 sw/source/filter/ww8/rtfattributeoutput.cxx |   74 +++++++++++++++-------------
 sw/source/filter/ww8/rtfattributeoutput.hxx |    3 +
 6 files changed, 81 insertions(+), 64 deletions(-)

New commits:
commit dbf24ea9aa010fe51da8d580a1403c8ecd9f0b04
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Apr 21 17:00:57 2015 +0200

    tdf#90421 RTF export: ignore hyperlinks without an URL
    
    Commit fe444d1f74abe417962be0bcd3340f40f2446b58 (fdo#62536: sw: fix
    AutoCorrect bold/underline on existing AUTOFMT, 2013-06-20) adds an
    empty inet format hint on the text node during autocorrection, on export
    we can safely ignore that to provide well-formed output.
    
    (cherry picked from commit 7d42346ba77c9c4df241ea40eaf550993ca18783)
    
    Change-Id: Iafae941a13e29dcc7d8b4bade5ce94a486b59638
    Reviewed-on: https://gerrit.libreoffice.org/15906
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/CppunitTest_sw_rtfexport.mk b/sw/CppunitTest_sw_rtfexport.mk
index 88f371b..b47c906 100644
--- a/sw/CppunitTest_sw_rtfexport.mk
+++ b/sw/CppunitTest_sw_rtfexport.mk
@@ -48,36 +48,7 @@ $(eval $(call gb_CppunitTest_use_api,sw_rtfexport,\
 $(eval $(call gb_CppunitTest_use_ure,sw_rtfexport))
 $(eval $(call gb_CppunitTest_use_vcl,sw_rtfexport))
 
-$(eval $(call gb_CppunitTest_use_components,sw_rtfexport,\
-	basic/util/sb \
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-    embeddedobj/util/embobj \
-    filter/source/config/cache/filterconfig1 \
-    filter/source/storagefilterdetect/storagefd \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-    linguistic/source/lng \
-    package/source/xstor/xstor \
-    package/util/package2 \
-    sax/source/expatwrap/expwrap \
-    sfx2/util/sfx \
-    starmath/util/sm \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    sw/util/msword \
-    sw/util/sw \
-    sw/util/swd \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/file/ucpfile1 \
-    unotools/util/utl \
-    unoxml/source/service/unoxml \
-	uui/util/uui \
-    writerfilter/util/writerfilter \
-    xmloff/util/xo \
-	oox/util/oox \
-))
+$(eval $(call gb_CppunitTest_use_rdb,sw_rtfexport,services))
 
 $(eval $(call gb_CppunitTest_use_configuration,sw_rtfexport))
 
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 760afc2..4cd9919 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -264,6 +264,7 @@ protected:
         header();
         preTest(filename);
         load(mpTestDocumentPath, filename);
+        postLoad(filename);
         reload(mpFilter, filename);
         postTest(filename);
         verify();
@@ -313,6 +314,11 @@ protected:
     {
     }
 
+    /// Override this function if some special file-specific setup is needed during export test: after load, but before save.
+    virtual void postLoad(const char* /*pFilename*/)
+    {
+    }
+
     /**
      * Override this function if some special filename-specific teardown is needed
      */
diff --git a/sw/qa/extras/rtfexport/data/tdf90421.fodt b/sw/qa/extras/rtfexport/data/tdf90421.fodt
new file mode 100644
index 0000000..a0da4b8
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf90421.fodt
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1">A <text:a xlink:type="simple" xlink:href="http://s/" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">http://s/</text:a> B</text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 2a13b4b..9bc57d5 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -76,6 +76,16 @@ public:
         return false;
 
     }
+
+    virtual void postLoad(const char* pFilename) SAL_OVERRIDE
+    {
+        if (OString(pFilename) == "tdf90421.fodt")
+        {
+            // Change the hyperlink, so its URL is empty.
+            uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 2), uno::UNO_QUERY);
+            xRun->setPropertyValue("HyperLinkURL", uno::makeAny(OUString()));
+        }
+    }
 };
 
 DECLARE_RTFEXPORT_TEST(testZoom, "zoom.rtf")
@@ -869,6 +879,19 @@ DECLARE_RTFEXPORT_TEST(testTdf80708, "tdf80708.rtf")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf90421, "tdf90421.fodt")
+{
+    if (mbExported)
+    {
+        SvMemoryStream aMemoryStream;
+        SvFileStream aStream(maTempFile.GetURL(), STREAM_READ);
+        aStream.ReadStream(aMemoryStream);
+        OString aData(static_cast<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
+        // This was some positive number, i.e. we exported a hyperlink with an empty URL.
+        CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aData.indexOf("HYPERLINK"));
+    }
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 7071e7b..da8f01f 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -437,52 +437,58 @@ void RtfAttributeOutput::EndRuby()
 
 bool RtfAttributeOutput::StartURL(const OUString& rUrl, const OUString& rTarget)
 {
-    m_aStyles.append('{');
-    m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FIELD);
-    m_aStyles.append('{');
-    m_aStyles.append(OOO_STRING_SVTOOLS_RTF_IGNORE);
-    m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FLDINST);
-    m_aStyles.append(" HYPERLINK ");
-
-    OUString sURL(rUrl);
-    if (!sURL.isEmpty())
+    m_sURL = rUrl;
+    // Ignore hyperlink without an URL.
+    if (!rUrl.isEmpty())
     {
+        m_aStyles.append('{');
+        m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FIELD);
+        m_aStyles.append('{');
+        m_aStyles.append(OOO_STRING_SVTOOLS_RTF_IGNORE);
+        m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FLDINST);
+        m_aStyles.append(" HYPERLINK ");
+
+        OUString sURL(rUrl);
         m_aStyles.append("\"");
         m_aStyles.append(msfilter::rtfutil::OutString(sURL, m_rExport.eCurrentEncoding));
         m_aStyles.append("\" ");
-    }
 
-    if (!rTarget.isEmpty())
-    {
-        m_aStyles.append("\\\\t \"");
-        m_aStyles.append(msfilter::rtfutil::OutString(rTarget, m_rExport.eCurrentEncoding));
-        m_aStyles.append("\" ");
-    }
+        if (!rTarget.isEmpty())
+        {
+            m_aStyles.append("\\\\t \"");
+            m_aStyles.append(msfilter::rtfutil::OutString(rTarget, m_rExport.eCurrentEncoding));
+            m_aStyles.append("\" ");
+        }
 
-    m_aStyles.append("}");
-    m_aStyles.append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+        m_aStyles.append("}");
+        m_aStyles.append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+    }
     return true;
 }
 
 bool RtfAttributeOutput::EndURL(bool const isAtEndOfParagraph)
 {
-    // UGLY: usually EndRun is called earlier, but there is an extra
-    // call to OutAttrWithRange() when at the end of the paragraph,
-    // so in that special case the output needs to be appended to the
-    // new run's text instead of the previous run
-    if (isAtEndOfParagraph)
+    if (!m_sURL.isEmpty())
     {
-        // close the fldrslt group
-        m_aRunText->append("}}");
-        // close the field group
-        m_aRunText->append('}');
-    }
-    else
-    {
-        // close the fldrslt group
-        m_aRun->append("}}");
-        // close the field group
-        m_aRun->append('}');
+        // UGLY: usually EndRun is called earlier, but there is an extra
+        // call to OutAttrWithRange() when at the end of the paragraph,
+        // so in that special case the output needs to be appended to the
+        // new run's text instead of the previous run
+        if (isAtEndOfParagraph)
+        {
+            // close the fldrslt group
+            m_aRunText->append("}}");
+            // close the field group
+            m_aRunText->append('}');
+        }
+        else
+        {
+            // close the fldrslt group
+            m_aRun->append("}}");
+            // close the field group
+            m_aRun->append('}');
+        }
+        m_sURL.clear();
     }
     return true;
 }
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index a056849..72d07cc 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -596,6 +596,9 @@ private:
 
     boost::optional<css::drawing::FillStyle> m_oFillStyle;
 
+    /// If we're in the process of exporting a hyperlink, then its URL.
+    OUString m_sURL;
+
 public:
     RtfAttributeOutput(RtfExport& rExport);
 


More information about the Libreoffice-commits mailing list