sw/qa/extras/htmlexport/htmlexport.cxx | 15 +++++++++++++++ sw/source/filter/html/htmlflywriter.cxx | 31 +++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-)
New commits: commit 96eabc69e9c3c6e9c944a4e83adddea44d48c621 Author: Mike Kaganski <[email protected]> AuthorDate: Wed May 1 12:10:23 2024 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Wed May 1 12:12:59 2024 +0200 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 <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 1fc731b8b21d..282ce035b3a6 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -3107,6 +3107,21 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_160867) assertXPath(pDoc, "/html/body/p[2]/img"_ostr, "usemap"_ostr, "#" + 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. + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); + assertXPath(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a/reqif-xhtml:object"_ostr); + CPPUNIT_ASSERT(getXPath(pXmlDoc, "//reqif-xhtml:p[2]/reqif-xhtml:a"_ostr, "href"_ostr) + .endsWith("foo/bar")); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index ea421f3cbc72..80b4abf5eade 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1080,17 +1080,17 @@ OUString lclWriteOutImap(SwHTMLWriter& rWrt, const SfxItemSet& rItemSet, const S 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 && !rWrt.mbReqIF) { // make the name unique aIMapName = pIMap->GetName(); @@ -1098,10 +1098,10 @@ OUString lclWriteOutImap(SwHTMLWriter& rWrt, const SfxItemSet& rItemSet, const S if (!aIMapName.isEmpty()) aNameBase = aIMapName; else + { aNameBase = OOO_STRING_SVTOOLS_HTML_map; - - if (aIMapName.isEmpty()) aIMapName = aNameBase + OUString::number(rWrt.m_nImgMapCnt); + } bool bFound; do @@ -1271,7 +1271,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S // URL -> <a>...<img ... >...</a> const SvxMacroItem *pMacItem = rItemSet.GetItemIfSet(RES_FRMMACRO); - if (pURLItem || pMacItem) + if (pURLItem || pMacItem || (rWrt.mbReqIF && pAltImgMap)) { OUString aMapURL; OUString aName; @@ -1283,6 +1283,21 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S aName = pURLItem->GetName(); aTarget = pURLItem->GetTargetFrameName(); } + else if (rWrt.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();
