From 5ddaaa0c86a9c7851d2277d56b379a3412b1fff3 Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Thu, 9 May 2019 11:00:36 +0200 Subject: tdf#125173 fix hyperlink inserted to text box MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hyperlink inserted to text box lost after export. Change-Id: I796e54339292cb4a5e98de1ead6558d66587d353 Reviewed-on: https://gerrit.libreoffice.org/72033 Tested-by: Jenkins Reviewed-by: László Németh --- oox/source/export/shapes.cxx | 20 ++++++++++++++++++-- sc/qa/unit/data/ods/text_box_hyperlink.ods | Bin 0 -> 8538 bytes sc/qa/unit/subsequent_export-test.cxx | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 sc/qa/unit/data/ods/text_box_hyperlink.ods diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 7302682b02b0..3cb71aeacf8c 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -1793,14 +1793,30 @@ ShapeExport& ShapeExport::WriteTableShape( const Reference< XShape >& xShape ) ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape ) { FSHelperPtr pFS = GetFS(); - + Reference xShapeProps(xShape, UNO_QUERY); pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp)); // non visual shape properties if (GetDocumentType() != DOCUMENT_DOCX) { pFS->startElementNS(mnXmlNamespace, XML_nvSpPr); - WriteNonVisualDrawingProperties( xShape, IDS( TextShape ) ); + pFS->startElementNS(mnXmlNamespace, XML_cNvPr, + XML_id, OString::number(GetNewShapeID(xShape)), + XML_name, IDS(TextShape)); + OUString sURL; + if (GetProperty(xShapeProps, "URL")) + mAny >>= sURL; + + if (!sURL.isEmpty()) + { + OUString sRelId = mpFB->addRelation(mpFS->getOutputStream(), + oox::getRelationship(Relationship::HYPERLINK), + mpURLTransformer->getTransformedString(sURL), + mpURLTransformer->isExternalURL(sURL)); + + mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId.toUtf8()); + } + pFS->endElementNS(mnXmlNamespace, XML_cNvPr); } pFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1"); if (GetDocumentType() != DOCUMENT_DOCX) diff --git a/sc/qa/unit/data/ods/text_box_hyperlink.ods b/sc/qa/unit/data/ods/text_box_hyperlink.ods new file mode 100644 index 000000000000..77778e99818b Binary files /dev/null and b/sc/qa/unit/data/ods/text_box_hyperlink.ods differ diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index bc8545ca182e..1879924d705a 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -221,6 +221,7 @@ public: void testTdf115159(); void testTdf112567(); void testTdf123645XLSX(); + void testTdf125173XLSX(); void testXltxExport(); @@ -347,6 +348,7 @@ public: CPPUNIT_TEST(testTdf115159); CPPUNIT_TEST(testTdf112567); CPPUNIT_TEST(testTdf123645XLSX); + CPPUNIT_TEST(testTdf125173XLSX); CPPUNIT_TEST(testXltxExport); @@ -4352,6 +4354,22 @@ void ScExportTest::testTdf123645XLSX() assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId5']", "Target", "https://bugs.documentfoundation.org/show_bug.cgi?id=123645"); } +void ScExportTest::testTdf125173XLSX() +{ + ScDocShellRef xDocSh = loadDoc("text_box_hyperlink.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocPtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr/a:hlinkClick", 1); + + xmlDocPtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", "http://www.google.com/"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit