sw/qa/filter/ww8/ww8.cxx                             |    7 ++++++-
 sw/source/core/inc/frame.hxx                         |    3 +++
 sw/source/core/layout/findfrm.cxx                    |   11 +++++++++++
 sw/source/filter/ww8/ww8par.cxx                      |    7 -------
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   16 +++++++++++++++-
 5 files changed, 35 insertions(+), 9 deletions(-)

New commits:
commit 5ae1379fcdd00228e683ae90991e275f570cd92d
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed May 15 17:45:16 2024 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu May 16 10:13:55 2024 +0200

    writerfilter: fix parsing of invalid STYLEREF field
    
    forum-mso-en-3309.docx contains a funny field that doesn't follow
    the grammar in the OOXML spec:
    
    STYLEREF     "Heading 1" \* MERGEFORMAT
    
    Word can evaluate it and find the paragraph, so make the parser a bit
    more flexible, by adding known switches that don't have arguments, so
    that any argument following these becomes a field argument,
    for now only for STYLEREF.
    
    (regression from commit d4fdafa103bfea94a279d7069ddc50ba92f67d01)
    
    Change-Id: Ic42cd2be58fd65a817946e21a9661d357b02a99a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167697
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index bdf05bee33a5..0d6570997e82 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -5457,13 +5457,27 @@ std::tuple<OUString, std::vector<OUString>, 
std::vector<OUString> > splitFieldCo
         OUString const token =
             lcl_ExtractToken(rCommand, nStartIndex, bHaveToken, bIsSwitch);
         assert(nStartIndex <= rCommand.size());
+        static std::map<OUString, std::set<OUString>> const noArgumentSwitches 
= {
+            { u"STYLEREF"_ustr,
+              { u"\l"_ustr, u"\n"_ustr, u"\p"_ustr, u"\r"_ustr, u"\t"_ustr, 
u"\w"_ustr } }
+        };
         if (bHaveToken)
         {
             if (sType.isEmpty())
             {
                 sType = token.toAsciiUpperCase();
             }
-            else if (bIsSwitch || !switches.empty())
+            else if (bIsSwitch)
+            {
+                switches.push_back(token);
+            }
+            // evidently Word evaluates 'STYLEREF       "Heading 1" \* 
MERGEFORMAT'
+            // despite the grammar specifying that the style name must
+            // precede switches like ' '; try to approximate that here
+            // by checking for known switches that don't expect arguments
+            else if (auto const it = noArgumentSwitches.find(sType);
+                !switches.empty() && (it == noArgumentSwitches.end()
+                                    || 
it->second.find(switches.back().toAsciiLowerCase()) == it->second.end()))
             {
                 switches.push_back(token);
             }
commit d74fb6b571304b41c13b7a6dcdd2b853bfca7210
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu May 16 08:46:36 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu May 16 10:13:43 2024 +0200

    tdf#160984 sw continuous endnotes, DOC import: enable this unconditionally
    
    DOC files with <= 2 endnotes were imported fine, but not if they had
    more endnotes.
    
    This was added in commit dc11f5b151e1a2ea2623fc8cf806a400763955d9
    (tdf#143445 DOC import: limit the usage of the CONTINUOUS_ENDNOTES
    compat flag, 2023-05-23), because mapping endnotes to footnotes was a
    dead-end.
    
    The limitation can be dropped: I checked that the tdf#143445 bugdoc with
    all its 72 endnotes is laid out reasonably.
    
    Also add a new SwFrame::DynCastColumnFrame() to easily get a column
    frame from a frame using our own RTTI, if we have it anyway.
    
    Change-Id: If7fd856f5dc5f1feb1366fca69a2ad6b3602044d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167722
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index af19051a03e5..4cbbfe5fbf31 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -30,6 +30,8 @@
 #include <fmtwrapinfluenceonobjpos.hxx>
 #include <ftnidx.hxx>
 #include <tabfrm.hxx>
+#include <cntfrm.hxx>
+#include <colfrm.hxx>
 
 namespace
 {
@@ -298,7 +300,10 @@ CPPUNIT_TEST_FIXTURE(Test, test3Endnotes)
     SwDoc* pDoc = getSwDoc();
     SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
     SwPageFrame* pPage = pLayout->GetLastPage();
-    SwFootnoteContFrame* pFootnoteCont = pPage->FindFootnoteCont();
+    SwContentFrame* pLastContent = pPage->FindLastBodyContent();
+    SwFrame* pSectionFrame = pLastContent->GetNext();
+    auto pColumnFrame = pSectionFrame->GetLower()->DynCastColumnFrame();
+    SwFootnoteContFrame* pFootnoteCont = pColumnFrame->FindFootnoteCont();
     int nEndnotes = 0;
     for (SwFrame* pLower = pFootnoteCont->GetLower(); pLower; pLower = 
pLower->GetNext())
     {
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index f0b7439bd283..399ab4d0b448 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -40,6 +40,7 @@ namespace drawinglayer::processor2d { class BaseProcessor2D; }
 class SwLayoutFrame;
 class SwRootFrame;
 class SwPageFrame;
+class SwColumnFrame;
 class SwBodyFrame;
 class SwFlyFrame;
 class SwSectionFrame;
@@ -879,6 +880,8 @@ public:
     const SwTextFrame* DynCastTextFrame() const;
     SW_DLLPUBLIC SwPageFrame* DynCastPageFrame();
     const SwPageFrame* DynCastPageFrame() const;
+    SW_DLLPUBLIC SwColumnFrame* DynCastColumnFrame();
+    const SwColumnFrame* DynCastColumnFrame() const;
     inline bool IsNoTextFrame() const;
     // Frames where its PrtArea depends on their neighbors and that are
     // positioned in the content flow
diff --git a/sw/source/core/layout/findfrm.cxx 
b/sw/source/core/layout/findfrm.cxx
index 60ca1fe7d326..e83f4f8414a0 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <pagefrm.hxx>
+#include <colfrm.hxx>
 #include <rootfrm.hxx>
 #include <cellfrm.hxx>
 #include <rowfrm.hxx>
@@ -1990,4 +1991,14 @@ const SwPageFrame* SwFrame::DynCastPageFrame() const
     return IsPageFrame() ? static_cast<const SwPageFrame*>(this) : nullptr;
 }
 
+SwColumnFrame* SwFrame::DynCastColumnFrame()
+{
+    return IsColumnFrame() ? static_cast<SwColumnFrame*>(this) : nullptr;
+}
+
+const SwColumnFrame* SwFrame::DynCastColumnFrame() const
+{
+    return IsColumnFrame() ? static_cast<const SwColumnFrame*>(this) : nullptr;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 45eef231ab27..6d1666359eec 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -5196,13 +5196,6 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const 
*pGloss)
         if( m_xWDop->nEdn )
             aInfo.m_nFootnoteOffset = m_xWDop->nEdn - 1;
         m_rDoc.SetEndNoteInfo( aInfo );
-
-        if (m_xSBase->GetEndnoteCount() > 2)
-        {
-            // This compatibility flag only works in easy cases, disable it 
for anything non-trivial
-            // for now.
-            
m_rDoc.getIDocumentSettingAccess().set(DocumentSettingId::CONTINUOUS_ENDNOTES, 
false);
-        }
     }
 
     if (m_xWwFib->m_lcbPlcfhdd)

Reply via email to