diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-05-01 12:10:23 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-05-01 16:13:46 +0500 |
commit | a2cb4a27f2e56d042b1f0dd1eaead49228b98197 (patch) | |
tree | fc918a1e9d74672f561fed1b36b5aa527253a452 | |
parent | 22ce686df6bd8b2cb2e8048206f3dd86c5a98d68 (diff) |
tdf#160867: only output first element of the map in ReqIF case
It should be investigated, how the whole image map can be output in
that case - something to be done separately.
Change-Id: I6543c0d238205fabdb0a688e32a2d08423d7a5d3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166948
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 17 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 31 |
2 files changed, 40 insertions, 8 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 148285680043..f1e32f9d110e 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -3078,6 +3078,23 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_160867) assertXPath(pDoc, "/html/body/p[2]/img", "usemap", "#" + mapName); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_160867) +{ + // Given a document with an image with hyperlink, and text with hyperlink, both in a frame: + createSwDoc("tdf160867_image_with_link.fodt"); + // When exporting to reqif: + ExportToReqif(); + // For now, we don't (yet) output the whole map in ReqIF case. + // Make sure that the first hyperlink from the objects in the frame is output as an <a> element + // around the whole image of the frame. + SvMemoryStream aStream; + WrapReqifFromTempFile(aStream); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + assertXPath(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a/reqif-xhtml:object"); + CPPUNIT_ASSERT( + getXPath(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a", "href").endsWith("foo/bar")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 624d992fb273..32b97fe16bdc 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1117,17 +1117,17 @@ OUString lclWriteOutImap(SwHTMLWriter& rHTMLWrt, const SfxItemSet& rItemSet, con OUString aIMapName; // Only consider the URL attribute if no ImageMap was supplied - if (!pAltImgMap) - pURLItem = rItemSet.GetItemIfSet( RES_URL ); // write ImageMap const ImageMap* pIMap = pAltImgMap; - if( !pIMap && pURLItem ) + if( !pIMap ) { - pIMap = pURLItem->GetMap(); + pURLItem = rItemSet.GetItemIfSet(RES_URL); + if (pURLItem) + pIMap = pURLItem->GetMap(); } - if (pIMap) + if (pIMap && !rHTMLWrt.mbReqIF) { // make the name unique aIMapName = pIMap->GetName(); @@ -1135,10 +1135,10 @@ OUString lclWriteOutImap(SwHTMLWriter& rHTMLWrt, const SfxItemSet& rItemSet, con if (!aIMapName.isEmpty()) aNameBase = aIMapName; else + { aNameBase = OOO_STRING_SVTOOLS_HTML_map; - - if (aIMapName.isEmpty()) aIMapName = aNameBase + OUString::number(rHTMLWrt.m_nImgMapCnt); + } bool bFound; do @@ -1309,7 +1309,7 @@ Writer& OutHTML_ImageStart( HtmlWriter& rHtml, Writer& rWrt, const SwFrameFormat // URL -> <a>...<img ... >...</a> const SvxMacroItem *pMacItem = rItemSet.GetItemIfSet(RES_FRMMACRO); - if (pURLItem || pMacItem) + if (pURLItem || pMacItem || (rHTMLWrt.mbReqIF && pAltImgMap)) { OUString aMapURL; OUString aName; @@ -1321,6 +1321,21 @@ Writer& OutHTML_ImageStart( HtmlWriter& rHtml, Writer& rWrt, const SwFrameFormat aName = pURLItem->GetName(); aTarget = pURLItem->GetTargetFrameName(); } + else if (rHTMLWrt.mbReqIF && pAltImgMap) + { + // Get first non-empty map element + for (size_t i = 0; i < pAltImgMap->GetIMapObjectCount(); ++i) + { + if (auto* pIMapObject = pAltImgMap->GetIMapObject(i)) + { + aMapURL = pIMapObject->GetURL(); + aName = pIMapObject->GetName(); + aTarget = pIMapObject->GetTarget(); + if (!aMapURL.isEmpty() || !aName.isEmpty() || !aTarget.isEmpty()) + break; + } + } + } bool bEvents = pMacItem && !pMacItem->GetMacroTable().empty(); |