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 99b3e159726b51537563790e8f73b43a88970e13
Author: Miklos Vajna <vmik...@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.
    
    (cherry picked from commit 153af84762f98d6c86c4c060b01402f40b2b0c24)
    
    Conflicts:
        sw/qa/extras/ooxmlexport/ooxmlexport.cxx
    
    Change-Id: I10f259fd9edb8bd719ae5bc8a43ed5ef8c708071
    Reviewed-on: https://gerrit.libreoffice.org/13524
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

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 2fe437b..a443d58 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3706,6 +3706,18 @@ DECLARE_OOXMLEXPORT_TEST(testMsoPosition, 
"bnc884615-mso-position.docx")
     }
 }
 
+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"));
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index bc4ff52..3779aa3 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1496,6 +1496,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;
@@ -1576,6 +1579,12 @@ void DomainMapper_Impl::PopPageHeaderFooter()
         m_bDiscardHeaderFooter = false;
     }
     m_bInHeaderFooterImport = false;
+
+    if (!m_aHeaderFooterStack.empty())
+    {
+        m_bTextInserted = m_aHeaderFooterStack.top().getTextInserted();
+        m_aHeaderFooterStack.pop();
+    }
 }
 
 
@@ -2523,6 +2532,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 > xStart) :
     m_bFieldCommandCompleted( false )
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index f72c866..68e1af7 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
  * --------------------------------------------------*/
@@ -200,6 +216,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;
 
@@ -301,6 +318,7 @@ private:
 
     TextContentStack                                                           
     m_aAnchoredStack;
 
+    HeaderFooterStack m_aHeaderFooterStack;
     FieldStack                                                                 
     m_aFieldStack;
     bool                                                                       
     m_bSetUserFieldContent;
     bool                                                                       
     m_bSetCitation;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to