[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/source

Michael Stahl mstahl at redhat.com
Mon Jul 20 13:01:59 PDT 2015


 sw/source/filter/ww8/writerhelper.cxx |   22 +++++++++++++++++++++-
 sw/source/filter/ww8/writerhelper.hxx |    4 ++++
 sw/source/filter/ww8/wrtww8.cxx       |    3 +++
 3 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 2acb668ad89a9e023561f39df7891be1ee454391
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Jun 5 15:32:32 2015 +0200

    sw: WW8 export: avoid invalidated positions in sw::Frames
    
    When exporting ooo67907-1.doc we get ~SwIndexReg assert because there's
    a frame anchored in a redline, and the SwPosition in the sw::Frame for
    it is invalidated during SetRedlineMode because the node it points to is
    deleted.  Add another horrible workaround to the redline trainwreck.
    
    Change-Id: Ia9b2393c77f42502862daaa30fd54eb3b040a214
    (cherry picked from commit ab706f85bb777ba160712c072c9d2a08ebcddcc6)
    Reviewed-on: https://gerrit.libreoffice.org/17231
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx
index 9a08466..cf762a6 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -126,7 +126,11 @@ namespace
 
             if (const SwPosition* pAnchor = rEntry.GetAnchor().GetContentAnchor())
             {
-                aRet.push_back(sw::Frame(rEntry, *pAnchor));
+                // the anchor position will be invalidated by SetRedlineMode
+                // so set a dummy position and fix it in UpdateFramePositions
+                SwPosition const dummy(SwNodeIndex(
+                            const_cast<SwNodes&>(pAnchor->nNode.GetNodes())));
+                aRet.push_back(sw::Frame(rEntry, dummy));
             }
             else
             {
@@ -522,6 +526,22 @@ namespace sw
             return aRet;
         }
 
+        void UpdateFramePositions(Frames & rFrames)
+        {
+            for (Frame & rFrame : rFrames)
+            {
+                SwFormatAnchor const& rAnchor = rFrame.GetFrameFormat().GetAnchor();
+                if (SwPosition const*const pAnchor = rAnchor.GetContentAnchor())
+                {
+                    rFrame.SetPosition(*pAnchor);
+                }
+                else
+                {   // these don't need to be corrected, they're not in redlines
+                    assert(FLY_AT_PAGE == rAnchor.GetAnchorId());
+                }
+            }
+        }
+
         Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode)
         {
             Frames aRet;
diff --git a/sw/source/filter/ww8/writerhelper.hxx b/sw/source/filter/ww8/writerhelper.hxx
index dbd033e..bbef363 100644
--- a/sw/source/filter/ww8/writerhelper.hxx
+++ b/sw/source/filter/ww8/writerhelper.hxx
@@ -126,6 +126,7 @@ namespace sw
             The anchor position of this frame
         */
         const SwPosition &GetPosition() const { return maPos; }
+        void SetPosition(SwPosition const& rPos) { maPos = rPos; }
 
         /** Get the node this frame is anchored into
 
@@ -633,6 +634,9 @@ namespace sw
         */
         Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
 
+        /** fix up frame positions, must be called after SetRedlineMode */
+        void UpdateFramePositions(Frames & rFrames);
+
         /** Get the Frames anchored to a given node
 
             Given a container of frames, find the ones anchored to a given node
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 611559e..9dad99d 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3107,6 +3107,9 @@ void MSWordExportBase::ExportDocument( bool bWriteAll )
                                                          nsRedlineMode_t::REDLINE_SHOW_INSERT);
     }
 
+    // fix the SwPositions in m_aFrames after SetRedlineMode
+    UpdateFramePositions(m_aFrames);
+
     m_aFontHelper.InitFontTable( SupportsUnicode(), *m_pDoc );
     GatherChapterFields();
 


More information about the Libreoffice-commits mailing list