sw/qa/extras/htmlexport/htmlexport.cxx |    8 ++++++--
 sw/source/core/text/inftxt.cxx         |   16 ++++++++++++++++
 sw/source/core/text/itrpaint.cxx       |   17 +++++++++++++++++
 sw/source/core/text/porfly.hxx         |    1 +
 4 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit 42876f0a99e2ae7cb7529dd7fb4d94c5e9298b21
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Apr 30 22:16:12 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed May 1 06:59:40 2024 +0200

    tdf#160867: export as-char frames' hyperlinks to image map
    
    Change-Id: Idc8d41a27c8ee9cdd12fb5e17a328ec6aa104a16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166935
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 329be9231bb9..1fc731b8b21d 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -3093,13 +3093,17 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testHTML_160867)
     CPPUNIT_ASSERT(pDoc);
     assertXPath(pDoc, "/html/body/p"_ostr, 2);
 
-    // Test export of text hyperlink in the image map. TODO: implement export 
of image hyperlink.
+    // Test export of image and text hyperlinks in the image map.
     // Without the fix, the test would fail with
     // - Expected: 1
     // - Actual  : 0
     // - In <>, XPath '/html/body/p[2]/map' number of nodes is incorrect
     const OUString mapName = getXPath(pDoc, "/html/body/p[2]/map"_ostr, 
"name"_ostr);
-    assertXPath(pDoc, "/html/body/p[2]/map/area"_ostr, "shape"_ostr, 
u"rect"_ustr);
+    assertXPath(pDoc, "/html/body/p[2]/map/area[1]"_ostr, "shape"_ostr, 
u"rect"_ustr);
+    CPPUNIT_ASSERT(
+        getXPath(pDoc, "/html/body/p[2]/map/area[1]"_ostr, 
"href"_ostr).endsWith("foo/bar"));
+    assertXPath(pDoc, "/html/body/p[2]/map/area[2]"_ostr, "shape"_ostr, 
u"rect"_ustr);
+    CPPUNIT_ASSERT(getXPath(pDoc, "/html/body/p[2]/map/area[2]"_ostr, 
"href"_ostr).endsWith("baz"));
     assertXPath(pDoc, "/html/body/p[2]/img"_ostr, "usemap"_ostr, "#" + 
mapName);
 }
 
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index a1a3bb89a87b..ddcca31668db 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -44,6 +44,7 @@
 #include <viewsh.hxx>
 #include <viewopt.hxx>
 #include <frmtool.hxx>
+#include <fmturl.hxx>
 #include <IDocumentSettingAccess.hxx>
 #include <IDocumentDeviceAccess.hxx>
 #include <IDocumentMarkAccess.hxx>
@@ -51,6 +52,7 @@
 #include <rootfrm.hxx>
 #include "inftxt.hxx"
 #include <noteurl.hxx>
+#include "porfly.hxx"
 #include "porftn.hxx"
 #include "porrst.hxx"
 #include "itratr.hxx"
@@ -1479,6 +1481,20 @@ void SwTextPaintInfo::NotifyURL_(const SwLinePortion& 
rPor) const
             const SwFormatINetFormat& rFormat = pAttr->GetINetFormat();
             pNoteURL->InsertURLNote(rFormat.GetValue(), 
rFormat.GetTargetFrame(), aIntersect);
         }
+        else if (rPor.IsFlyCntPortion())
+        {
+            if (auto* pFlyContentPortion = dynamic_cast<const 
sw::FlyContentPortion*>(&rPor))
+            {
+                if (auto* pFlyFtame = pFlyContentPortion->GetFlyFrame())
+                {
+                    if (auto* pFormat = pFlyFtame->GetFormat())
+                    {
+                        auto& url = pFormat->GetURL(); // TODO: url.GetMap() ?
+                        pNoteURL->InsertURLNote(url.GetURL(), 
url.GetTargetFrameName(), aIntersect);
+                    }
+                }
+            }
+        }
     }
 }
 
diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx
index 8fa9ca45f5fd..f02beed8ce5b 100644
--- a/sw/source/core/text/itrpaint.cxx
+++ b/sw/source/core/text/itrpaint.cxx
@@ -33,6 +33,7 @@
 #include <swfont.hxx>
 #include "txtpaint.hxx"
 #include "porfld.hxx"
+#include "porfly.hxx"
 #include "portab.hxx"
 #include <txatbase.hxx>
 #include <charfmt.hxx>
@@ -40,6 +41,7 @@
 #include "porrst.hxx"
 #include "pormulti.hxx"
 #include <doc.hxx>
+#include <fmturl.hxx>
 
 // Returns, if we have an underline breaking situation
 // Adding some more conditions here means you also have to change them
@@ -461,6 +463,21 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, 
SwSaveClip &rClip,
 
         if (GetFnt()->IsURL() && pPor->InTextGrp())
             GetInfo().NotifyURL(*pPor);
+        else if (pPor->IsFlyCntPortion())
+        {
+            if (auto* pFlyContentPortion = 
dynamic_cast<sw::FlyContentPortion*>(pPor))
+            {
+                if (auto* pFlyFrame = pFlyContentPortion->GetFlyFrame())
+                {
+                    if (auto* pFormat = pFlyFrame->GetFormat())
+                    {
+                        auto& url = pFormat->GetURL();
+                        if (!url.GetURL().isEmpty()) // TODO: url.GetMap() ?
+                            GetInfo().NotifyURL(*pPor);
+                    }
+                }
+            }
+        }
 
         bFirst &= !pPor->GetLen();
         if( pNext || !pPor->IsMarginPortion() )
diff --git a/sw/source/core/text/porfly.hxx b/sw/source/core/text/porfly.hxx
index a519c1109c87..2c56563a4436 100644
--- a/sw/source/core/text/porfly.hxx
+++ b/sw/source/core/text/porfly.hxx
@@ -76,6 +76,7 @@ namespace sw
             FlyContentPortion(SwFlyInContentFrame* pFly);
             static FlyContentPortion* Create(const SwTextFrame& rFrame, 
SwFlyInContentFrame* pFly, const Point& rBase, tools::Long nAscent, tools::Long 
nDescent, tools::Long nFlyAsc, tools::Long nFlyDesc, AsCharFlags nFlags);
             SwFlyInContentFrame* GetFlyFrame() { return m_pFly; }
+            const SwFlyInContentFrame* GetFlyFrame() const { return m_pFly; }
             void GetFlyCursorOfst(Point& rPoint, SwPosition& rPos, 
SwCursorMoveState* pCMS) const { m_pFly->GetModelPositionForViewPoint(&rPos, 
rPoint, pCMS); };
             virtual void Paint(const SwTextPaintInfo& rInf) const override;
             virtual ~FlyContentPortion() override;

Reply via email to