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

Miklos Vajna vmiklos at collabora.co.uk
Tue Oct 7 09:05:10 PDT 2014


 sw/qa/extras/ooxmlexport/data/multi-page-toc.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx          |   12 ++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   18 ++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |   18 ++++++++++++++++++
 4 files changed, 48 insertions(+)

New commits:
commit 153af84762f98d6c86c4c060b01402f40b2b0c24
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 7 17:53:29 2014 +0200

    DOCX import: handle section break right after a ToC field
    
    The symptom was that during the handling of the XE field, we tried to
    access the top of the text append stack, but the stack was empty.
    
    The situation is the following:
    
    1) There is a multi-page TOC field.
    2) The page break inside the field is described using a section break,
    featuring headers, and the header contains a field that we map to a
    fieldmark.
    3) There is an XE field after all this.
    
    The root cause was that during parsing of the header, some of the state
    should be stashed away and restored when we're done. The new
    HeaderFooterContext does exactly this, and now the number of push/pop
    calls on the text append context match again.
    
    Change-Id: I10f259fd9edb8bd719ae5bc8a43ed5ef8c708071

diff --git a/sw/qa/extras/ooxmlexport/data/multi-page-toc.docx b/sw/qa/extras/ooxmlexport/data/multi-page-toc.docx
new file mode 100644
index 0000000..5b5b594
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/multi-page-toc.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 487728d..9b49339 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -412,6 +412,18 @@ DECLARE_OOXMLEXPORT_TEST(testAnchorPosition, "anchor-position.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(getRun(getParagraph(1), 3), "TextPortionType"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testMultiPageToc, "multi-page-toc.docx")
+{
+    // Import of this document triggered an STL assertion.
+
+    // Document has a ToC from its second paragraph.
+    uno::Reference<container::XNamed> xTextSection = getProperty< uno::Reference<container::XNamed> >(getParagraph(2), "TextSection");
+    CPPUNIT_ASSERT_EQUAL(OUString("Table of Contents1"), xTextSection->getName());
+    // There should be a field in the header as well.
+    uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText");
+    CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(getRun(getParagraphOfText(1, xHeaderText), 1), "TextPortionType"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b396866..fbfae7c 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1452,6 +1452,9 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
 
 void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType)
 {
+    m_aHeaderFooterStack.push(HeaderFooterContext(m_bTextInserted));
+    m_bTextInserted = false;
+
     const PropertyIds ePropIsOn = bHeader? PROP_HEADER_IS_ON: PROP_FOOTER_IS_ON;
     const PropertyIds ePropShared = bHeader? PROP_HEADER_IS_SHARED: PROP_FOOTER_IS_SHARED;
     const PropertyIds ePropTextLeft = bHeader? PROP_HEADER_TEXT_LEFT: PROP_FOOTER_TEXT_LEFT;
@@ -1532,6 +1535,12 @@ void DomainMapper_Impl::PopPageHeaderFooter()
         m_bDiscardHeaderFooter = false;
     }
     m_bInHeaderFooterImport = false;
+
+    if (!m_aHeaderFooterStack.empty())
+    {
+        m_bTextInserted = m_aHeaderFooterStack.top().getTextInserted();
+        m_aHeaderFooterStack.pop();
+    }
 }
 
 
@@ -2567,6 +2576,15 @@ bool DomainMapper_Impl::IsOpenField() const
     return !m_aFieldStack.empty();
 }
 
+HeaderFooterContext::HeaderFooterContext(bool bTextInserted)
+    : m_bTextInserted(bTextInserted)
+{
+}
+
+bool HeaderFooterContext::getTextInserted()
+{
+    return m_bTextInserted;
+}
 
 FieldContext::FieldContext(uno::Reference< text::XTextRange > const& xStart)
     : m_bFieldCommandCompleted(false)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 76d6c57..4072349 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -113,6 +113,22 @@ enum BreakType
     PAGE_BREAK,
     COLUMN_BREAK
 };
+
+/**
+ * Storage for state that is relevant outside a header/footer, but not inside it.
+ *
+ * In case some state of DomainMapper_Impl should be reset before handling the
+ * header/footer and should be restored once handling of header/footer is done,
+ * then you can use this class to do so.
+ */
+class HeaderFooterContext
+{
+    bool m_bTextInserted;
+public:
+    HeaderFooterContext(bool bTextInserted);
+    bool getTextInserted();
+};
+
 /*--------------------------------------------------
    field stack element
  * --------------------------------------------------*/
@@ -206,6 +222,7 @@ typedef boost::shared_ptr<FieldContext>  FieldContextPtr;
 typedef std::stack<ContextType>                 ContextStack;
 typedef std::stack<PropertyMapPtr>              PropertyStack;
 typedef std::stack< TextAppendContext >         TextAppendStack;
+typedef std::stack<HeaderFooterContext> HeaderFooterStack;
 typedef std::stack<FieldContextPtr>                FieldStack;
 typedef std::stack< AnchoredContext >           TextContentStack;
 
@@ -311,6 +328,7 @@ private:
 
     TextContentStack                                                                m_aAnchoredStack;
 
+    HeaderFooterStack m_aHeaderFooterStack;
     FieldStack                                                                      m_aFieldStack;
     bool                                                                            m_bSetUserFieldContent;
     bool                                                                            m_bSetCitation;


More information about the Libreoffice-commits mailing list