From 0151b1fe4ebb62a25dcb885a1b8d8c6540b16ee6 Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Mon, 24 Jun 2019 17:19:30 +0200 Subject: tdf#78657 DOCX export: fix hyperlink inserted to image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hyperlink inserted to image lost after export. tdf78657_picture_hyperlink.docx: Test file from Microsoft Word 2016. Reviewed-on: https://gerrit.libreoffice.org/74653 Tested-by: Jenkins Reviewed-by: László Németh Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport13.cxx Change-Id: I1b2b9fe023aea3f46848a9d616374f7c08598756 Reviewed-on: https://gerrit.libreoffice.org/74841 Tested-by: Jenkins Reviewed-by: Xisco Faulí --- .../data/tdf78657_picture_hyperlink.docx | Bin 0 -> 21039 bytes sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 11 ++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 30 ++++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf78657_picture_hyperlink.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf78657_picture_hyperlink.docx b/sw/qa/extras/ooxmlexport/data/tdf78657_picture_hyperlink.docx new file mode 100644 index 000000000000..bc4759ecc342 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf78657_picture_hyperlink.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index ce6871b45df5..f7d09f590363 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -355,6 +355,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf125324, "tdf125324.docx") assertXPath(pXmlDoc, "/root/page/body/txt[2]/anchored/fly/tab/infos/bounds", "top", "4193"); } +DECLARE_OOXMLEXPORT_TEST(testTdf78657, "tdf78657_picture_hyperlink.docx") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + xmlDocPtr pXmlRels = parseExport("word/_rels/document.xml.rels"); + if (!pXmlDoc || !pXmlRels) + return; + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:inline/wp:docPr/a:hlinkClick", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr/a:hlinkClick", 1); + assertXPath(pXmlRels, "/rels:Relationships/rels:Relationship[@Target='http://www.google.com']", "TargetMode", "External"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf125518, "tdf125518.odt") { xmlDocPtr pXmlDoc = parseExport("word/document.xml"); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index b7316b003745..2bdbc30c7aa1 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4820,10 +4820,25 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size docPrattrList->add( XML_title, OUStringToOString( pGrfNode ? pGrfNode->GetTitle() : pOLEFrameFormat->GetObjTitle(), RTL_TEXTENCODING_UTF8 ).getStr()); XFastAttributeListRef docPrAttrListRef( docPrattrList ); m_pSerializer->startElementNS( XML_wp, XML_docPr, docPrAttrListRef ); - // TODO hyperlink - // m_pSerializer->singleElementNS( XML_a, XML_hlinkClick, - // FSNS( XML_xmlns, XML_a ), "http://schemas.openxmlformats.org/drawingml/2006/main", - // FSNS( XML_r, XML_id ), "rId4"); + + //TODO: internal hyperlink + OUString sURL, sRelId; + if(pSdrObj) + { + uno::Reference< drawing::XShape > xShape( const_cast(pSdrObj)->getUnoShape(), uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY ); + xPropSet->getPropertyValue("HyperLinkURL") >>= sURL; + if(!sURL.isEmpty()) + { + sRelId = GetExport().GetFilter().addRelation( m_pSerializer->getOutputStream(), + oox::getRelationship(Relationship::HYPERLINK), + sURL, true ); + m_pSerializer->singleElementNS( XML_a, XML_hlinkClick, + FSNS( XML_xmlns, XML_a ), "http://schemas.openxmlformats.org/drawingml/2006/main", + FSNS( XML_r, XML_id ), sRelId.toUtf8()); + } + } + m_pSerializer->endElementNS( XML_wp, XML_docPr ); m_pSerializer->startElementNS(XML_wp, XML_cNvGraphicFramePr); @@ -4845,9 +4860,10 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size // It seems pic:cNvpr and wp:docPr are pretty much the same thing with the same attributes m_pSerializer->startElementNS(XML_pic, XML_cNvPr, docPrAttrListRef); - // TODO hyperlink - // m_pSerializer->singleElementNS( XML_a, XML_hlinkClick, - // FSNS( XML_r, XML_id ), "rId4"); + if(!sURL.isEmpty()) + m_pSerializer->singleElementNS( XML_a, XML_hlinkClick, + FSNS( XML_r, XML_id ), sRelId.toUtf8()); + m_pSerializer->endElementNS( XML_pic, XML_cNvPr ); m_pSerializer->startElementNS(XML_pic, XML_cNvPicPr); -- cgit