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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 25 14:47:45 UTC 2018


 sw/qa/extras/htmlimport/data/reqif-page-style.xhtml |    1 
 sw/qa/extras/htmlimport/htmlimport.cxx              |    8 +++++
 sw/source/filter/html/swhtml.cxx                    |   31 ++++++++++++--------
 sw/source/filter/html/swhtml.hxx                    |    6 +--
 sw/source/filter/inc/fltini.hxx                     |    5 +++
 5 files changed, 36 insertions(+), 15 deletions(-)

New commits:
commit 094e7b6a1028620c2b1503de8b51dc6a2482e290
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Oct 25 14:22:02 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Oct 25 16:47:19 2018 +0200

    sw HTML import: avoid custom default page style in reqif mode
    
    Would be "HTML" by default, but reqif-html is mostly very simple
    documents and the custom page styles is unexpected.
    
    Change-Id: I3f1b293bcd074305cf5cc87f03248e934d5fac4d
    Reviewed-on: https://gerrit.libreoffice.org/62317
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml b/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml
new file mode 100644
index 000000000000..36f5aa11768b
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml
@@ -0,0 +1 @@
+<reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index ad404d7e4f3a..52a6a7145bc4 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -349,6 +349,14 @@ DECLARE_HTMLIMPORT_TEST(testImageSize, "image-size.html")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aExpected.getHeight()), aSize.Height);
 }
 
+DECLARE_HTMLIMPORT_TEST(testReqIfPageStyle, "reqif-page-style.xhtml")
+{
+    // Without the accompanying fix in place, this test would have failed with
+    // 'Expected: Standard, Actual  : HTML'.
+    CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
+                         getProperty<OUString>(getParagraph(1), "PageStyleName"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 2e11911b7ece..879a95e0db9b 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -204,6 +204,8 @@ bool HTMLReader::SetStrmStgPtr()
 // Call for the general Reader-Interface
 ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, const OUString & rName )
 {
+    SetupFilterOptions();
+
     if( !m_pStream )
     {
         OSL_ENSURE( m_pStream, "HTML-Read without stream" );
@@ -216,7 +218,7 @@ ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, co
 
         // Set the HTML page style, when it isn't a HTML document,
         // otherwise it's already set.
-        if( !rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) )
+        if( !rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && m_aNamespace != "reqif-xhtml" )
         {
             rDoc.getIDocumentContentOperations().InsertPoolItem( rPam, SwFormatPageDesc(
                 rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( RES_POOLPAGE_HTML, false )) );
@@ -229,7 +231,7 @@ ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, co
     tools::SvRef<SwHTMLParser> xParser = new SwHTMLParser( &rDoc, rPam, *m_pStream,
                                             rName, rBaseURL, !m_bInsertMode, m_pMedium,
                                             IsReadUTF8(),
-                                            m_bIgnoreHTMLComments );
+                                            m_bIgnoreHTMLComments, m_aNamespace );
 
     SvParserState eState = xParser->CallParser();
 
@@ -253,7 +255,8 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
                             const OUString& rBaseURL,
                             bool bReadNewDoc,
                             SfxMedium* pMed, bool bReadUTF8,
-                            bool bNoHTMLComments )
+                            bool bNoHTMLComments,
+                            const OUString& rNamespace )
     : SfxHTMLParser( rIn, bReadNewDoc, pMed ),
     SwClient( nullptr ),
     m_aPathToFile( rPath ),
@@ -417,7 +420,13 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
         }
     }
 
-    SetupFilterOptions();
+    if (!rNamespace.isEmpty())
+    {
+        SetNamespace(rNamespace);
+        m_bXHTML = true;
+        if (rNamespace == "reqif-xhtml")
+            m_bReqIF = true;
+    }
 }
 
 SwHTMLParser::~SwHTMLParser()
@@ -5539,12 +5548,15 @@ void SwHTMLParser::AddMetaUserDefined( OUString const & i_rMetaName )
     }
 }
 
-void SwHTMLParser::SetupFilterOptions()
+void HTMLReader::SetupFilterOptions()
 {
-    if (!GetMedium())
+    // Reset state from previous Read() invocation.
+    m_aNamespace.clear();
+
+    if (!m_pMedium)
         return;
 
-    const SfxItemSet* pItemSet = GetMedium()->GetItemSet();
+    const SfxItemSet* pItemSet = m_pMedium->GetItemSet();
     if (!pItemSet)
         return;
 
@@ -5557,10 +5569,7 @@ void SwHTMLParser::SetupFilterOptions()
     if (aFilterOptions.startsWith(aXhtmlNsKey))
     {
         OUString aNamespace = aFilterOptions.copy(aXhtmlNsKey.getLength());
-        SetNamespace(aNamespace);
-        m_bXHTML = true;
-        if (aNamespace == "reqif-xhtml")
-            m_bReqIF = true;
+        m_aNamespace = aNamespace;
     }
 }
 
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 12d4dbe416e9..2f9a633a3cd9 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -856,9 +856,6 @@ private:
 
     bool PendingObjectsInPaM(SwPaM& rPam) const;
 
-    /// Parse FilterOptions passed to the importer.
-    void SetupFilterOptions();
-
     class TableDepthGuard
     {
     private:
@@ -902,7 +899,8 @@ public:
                     const OUString& rBaseURL,
                     bool bReadNewDoc,
                     SfxMedium* pMed, bool bReadUTF8,
-                    bool bIgnoreHTMLComments );
+                    bool bIgnoreHTMLComments,
+                    const OUString& rNamespace);
 
     virtual SvParserState CallParser() override;
 
diff --git a/sw/source/filter/inc/fltini.hxx b/sw/source/filter/inc/fltini.hxx
index ca3f9e347e7f..81b0809c2040 100644
--- a/sw/source/filter/inc/fltini.hxx
+++ b/sw/source/filter/inc/fltini.hxx
@@ -35,6 +35,11 @@ class HTMLReader: public Reader
     virtual bool SetStrmStgPtr() override;
     virtual ErrCode Read(SwDoc &, const OUString& rBaseURL, SwPaM &, const OUString &) override;
     virtual OUString GetTemplateName(SwDoc& rDoc) const override;
+
+    /// Parse FilterOptions passed to the importer.
+    void SetupFilterOptions();
+
+    OUString m_aNamespace;
 public:
     HTMLReader();
 };


More information about the Libreoffice-commits mailing list