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

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 30 11:00:15 UTC 2019


 sw/qa/extras/ooxmlexport/data/internal_hyperlink_frame.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx                 |   11 +++++++
 sw/source/filter/ww8/docxattributeoutput.cxx               |    2 -
 sw/source/filter/ww8/wrtw8nds.cxx                          |    5 +--
 sw/source/filter/ww8/wrtww8.cxx                            |   20 +++++++++----
 5 files changed, 29 insertions(+), 9 deletions(-)

New commits:
commit a0f46953883aadab1ae7cae5641d3fc1a6089f81
Author:     Tünde Tóth <tundeth at gmail.com>
AuthorDate: Tue Sep 24 11:53:46 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Mon Sep 30 12:59:21 2019 +0200

    tdf#127732 DOCX export: fix internal hyperlinks to frame target
    
    Hyperlinks to internal frame targets didn't work in Word.
    
    Change-Id: Ia402bbdd2e77d8d3bb68ed2ed3a6bde1a913617c
    Reviewed-on: https://gerrit.libreoffice.org/79448
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/internal_hyperlink_frame.odt b/sw/qa/extras/ooxmlexport/data/internal_hyperlink_frame.odt
new file mode 100644
index 000000000000..2497d5926a26
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/internal_hyperlink_frame.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 7d94913e9449..33d767e0bd81 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -771,6 +771,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf127605, "tdf127605.odt")
     CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf127732, "internal_hyperlink_frame.odt")
+{
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    if (!pXmlDoc)
+        return;
+
+    OUString bookmarkName = getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/mc:AlternateContent/mc:Fallback/w:pict/v:rect/v:textbox/w:txbxContent/w:p/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 f183bada73b1..b6f83787b673 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("|ole") && !sMark.endsWith("|region"))
+            if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table") && !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 eb81d0105db3..528cd498017b 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -917,12 +917,11 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT
                                 OUString());
 
         // #i21465# Only interested in outline references
-        if ( sRefType == "outline" || sRefType == "graphic" )
+        if ( !sRefType.isEmpty() && (sRefType == "outline" || sRefType == "graphic" || sRefType == "frame") )
         {
-            OUString sLink = sMark.copy(0, nPos);
             for ( const auto& rBookmarkPair : GetExport().m_aImplicitBookmarks )
             {
-                if ( rBookmarkPair.first == sLink )
+                if ( rBookmarkPair.first == sMark )
                 {
                     sMark = "_toc" + OUString::number( rBookmarkPair.second );
                     break;
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 763038abcb4d..222466d8eb1e 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3066,14 +3066,13 @@ 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() );
-        aName = BookmarkToWriter(aURL.copy(0, nPos));
+        SwPosition aPos(*m_pCurPam->GetPoint());
+        OUString 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
@@ -3086,7 +3085,7 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL)
     else if( sCmp == "graphic" )
     {
         SwNodeIndex* pIdx;
-        aName = BookmarkToWriter(aURL.copy( 0, nPos ));
+        OUString 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())))
         {
@@ -3094,10 +3093,21 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL)
             noBookmark = true;
         }
     }
+    else if( sCmp == "frame" )
+    {
+        SwNodeIndex* pIdx;
+        OUString aName(BookmarkToWriter(aURL.copy(0, nPos)));
+        const SwFlyFrameFormat* pFormat = m_pDoc->FindFlyByName(aName, SwNodeType::Text);
+        if (pFormat && nullptr != (pIdx = const_cast<SwNodeIndex*>(pFormat->GetContent().GetContentIdx())))
+        {
+            nIdx = pIdx->GetIndex() + 1;
+            noBookmark = true;
+        }
+    }
     if (noBookmark)
     {
         aBookmarkPair aImplicitBookmark;
-        aImplicitBookmark.first = aName;
+        aImplicitBookmark.first = aURL;
         aImplicitBookmark.second = nIdx;
         m_aImplicitBookmarks.push_back(aImplicitBookmark);
     }


More information about the Libreoffice-commits mailing list