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

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 23 11:13:35 UTC 2019


 sw/inc/ndindex.hxx                           |    1 
 sw/qa/extras/ooxmlexport/data/tdf127605.odt  |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx   |   11 +++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |    2 -
 sw/source/filter/ww8/wrtw8nds.cxx            |    3 +-
 sw/source/filter/ww8/wrtww8.cxx              |   32 +++++++++++++++++++++------
 6 files changed, 40 insertions(+), 9 deletions(-)

New commits:
commit 89ffe6149a0e14bcde89d7981362aa1556849ab0
Author:     Tünde Tóth <tundeth at gmail.com>
AuthorDate: Wed Sep 18 10:13:50 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Mon Sep 23 13:12:41 2019 +0200

    tdf#127605 DOCX export: fix internal hyperlinks to image target
    
    jumping to the paragraph anchored by the image as a workaround.
    
    Change-Id: Iff4feacca0cc9c790028d72fb834e8cf066c95e1
    Reviewed-on: https://gerrit.libreoffice.org/79081
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 95f1f7354ac5..274bc4b2014c 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -115,6 +115,7 @@ public:
     inline const SwNodes& GetNodes() const;
     inline       SwNodes& GetNodes();
 
+    SwNodeIndex* GetNext() { return GetNextInRing(); }
     SwNode& GetNode() const { return *m_pNode; }
 };
 
diff --git a/sw/qa/extras/ooxmlexport/data/tdf127605.odt b/sw/qa/extras/ooxmlexport/data/tdf127605.odt
new file mode 100644
index 000000000000..583f7fdeeb42
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf127605.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index ad5aec4e6d39..dc237f18ac4d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -753,6 +753,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf127362, "tdf127362.odt")
     CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf127605, "tdf127605.odt")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    if (!pXmlDoc)
+        return;
+
+    OUString bookmarkName = getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:bookmarkStart", "name");
+    OUString anchor = getXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink", "anchor");
+    CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 77f12ac20a7c..f4812c4613ec 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2914,7 +2914,7 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge
                     }
                 }
             }
-            if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table") && !sMark.endsWith("|frame") && !sMark.endsWith("|graphic") && !sMark.endsWith("|ole") && !sMark.endsWith("|region"))
+            if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table") && !sMark.endsWith("|frame") && !sMark.endsWith("|ole") && !sMark.endsWith("|region"))
             {
                 // Spaces are prohibited in bookmark name.
                 sMark = sMark.replace(' ', '_');
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index da3726c980e3..eb81d0105db3 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -917,7 +917,7 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT
                                 OUString());
 
         // #i21465# Only interested in outline references
-        if ( sRefType == "outline" )
+        if ( sRefType == "outline" || sRefType == "graphic" )
         {
             OUString sLink = sMark.copy(0, nPos);
             for ( const auto& rBookmarkPair : GetExport().m_aImplicitBookmarks )
@@ -925,6 +925,7 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT
                 if ( rBookmarkPair.first == sLink )
                 {
                     sMark = "_toc" + OUString::number( rBookmarkPair.second );
+                    break;
                 }
             }
         }
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 42f7b7e4f29f..763038abcb4d 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3066,23 +3066,41 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL)
         return;
 
     sCmp = sCmp.toAsciiLowerCase();
+    OUString aName;
+    sal_uLong nIdx = 0;
+    bool noBookmark = false;
 
     if( sCmp == "outline" )
     {
         SwPosition aPos( *m_pCurPam->GetPoint() );
-        OUString aOutline( BookmarkToWriter(aURL.copy( 0, nPos )) );
+        aName = BookmarkToWriter(aURL.copy(0, nPos));
         // If we can find the outline this bookmark refers to
         // save the name of the bookmark and the
         // node index number of where it points to
-        if( m_pDoc->GotoOutline( aPos, aOutline ) )
+        if( m_pDoc->GotoOutline( aPos, aName ) )
         {
-            sal_uLong nIdx = aPos.nNode.GetIndex();
-            aBookmarkPair aImplicitBookmark;
-            aImplicitBookmark.first = aOutline;
-            aImplicitBookmark.second = nIdx;
-            m_aImplicitBookmarks.push_back(aImplicitBookmark);
+            nIdx = aPos.nNode.GetIndex();
+            noBookmark = true;
         }
     }
+    else if( sCmp == "graphic" )
+    {
+        SwNodeIndex* pIdx;
+        aName = BookmarkToWriter(aURL.copy( 0, nPos ));
+        const SwFlyFrameFormat* pFormat = m_pDoc->FindFlyByName(aName, SwNodeType::Grf);
+        if (pFormat && nullptr != (pIdx = const_cast<SwNodeIndex*>(pFormat->GetContent().GetContentIdx())))
+        {
+            nIdx = pIdx->GetNext()->GetIndex();
+            noBookmark = true;
+        }
+    }
+    if (noBookmark)
+    {
+        aBookmarkPair aImplicitBookmark;
+        aImplicitBookmark.first = aName;
+        aImplicitBookmark.second = nIdx;
+        m_aImplicitBookmarks.push_back(aImplicitBookmark);
+    }
 }
 
 void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc)


More information about the Libreoffice-commits mailing list