diff options
author | Tibor Nagy <nagy.tibor2@nisz.hu> | 2021-04-29 17:26:59 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-05-04 17:53:22 +0200 |
commit | 3a24211a1d49f33ca52e4fb2c927d50304f005df (patch) | |
tree | 864ba876ab7e2d10ac158f58e8f40bee6f06a759 /oox | |
parent | cfa672013a1a75ff53993084ae5e69fcd985d010 (diff) |
tdf#54037 PPTX export: fix internal hyperlinks
exported as external by accident: after reloading the bad
export, clicking on the hyperlink opened the same file
in another document, because the exported link contained
also the full file name reference instead of the slide name,
according to the OOXML Relationship TargetMode="External".
Change-Id: I08cf1537cd307b0b6f51ba1c3f61d89e220d44fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114891
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/drawingml.cxx | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index bfe44e32b098..b84a77f085a0 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -93,6 +93,10 @@ #include <com/sun/star/xml/dom/XNodeList.hpp> #include <com/sun/star/xml/sax/Writer.hpp> #include <com/sun/star/xml/sax/XSAXSerializable.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/frame/XModel.hpp> #include <comphelper/random.hxx> #include <comphelper/seqstream.hxx> @@ -156,9 +160,12 @@ OUString URLTransformer::getTransformedString(const OUString& rString) const return rString; } -bool URLTransformer::isExternalURL(const OUString& /*rURL*/) const +bool URLTransformer::isExternalURL(const OUString& rURL) const { - return true; + bool bExternal = true; + if (rURL.startsWith("#")) + bExternal = false; + return bExternal; } static css::uno::Any getLineDash( const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rDashName ) @@ -1842,6 +1849,29 @@ void DrawingML::WriteShapeTransformation( const Reference< XShape >& rXShape, sa bFlipHWrite, bFlipVWrite, ExportRotateClockwisify(nRotation + nCameraRotation), IsGroupShape( rXShape )); } +static OUString lcl_GetTarget(const css::uno::Reference<css::frame::XModel>& xModel, OUString& rURL) +{ + Reference<drawing::XDrawPagesSupplier> xDPS(xModel, uno::UNO_QUERY_THROW); + Reference<drawing::XDrawPages> xDrawPages(xDPS->getDrawPages(), uno::UNO_SET_THROW); + sal_uInt32 nPageCount = xDrawPages->getCount(); + OUString sTarget; + + for (sal_uInt32 i = 0; i < nPageCount; ++i) + { + Reference<XDrawPage> xDrawPage; + xDrawPages->getByIndex(i) >>= xDrawPage; + Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY_THROW); + OUString sSlideName = "#" + xNamed->getName(); + if (rURL == sSlideName) + { + sTarget = "slide" + OUString::number(i + 1) + ".xml"; + break; + } + } + + return sTarget; +} + void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect,bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, sal_Int16 nScriptType, const Reference< XPropertySet >& rXShapePropSet) @@ -2177,15 +2207,34 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool OUString sURL; mAny >>= sURL; - if( !sURL.isEmpty() ) { - OUString sRelId = mpFB->addRelation( mpFS->getOutputStream(), - oox::getRelationship(Relationship::HYPERLINK), - sURL, true ); + if (!sURL.isEmpty()) + { + if (!sURL.match("#action?jump=")) + { + bool bExtURL = URLTransformer().isExternalURL(sURL); + sURL = bExtURL ? sURL : lcl_GetTarget(GetFB()->getModel(), sURL); + + OUString sRelId + = mpFB->addRelation(mpFS->getOutputStream(), + bExtURL ? oox::getRelationship(Relationship::HYPERLINK) + : oox::getRelationship(Relationship::SLIDE), + sURL, bExtURL); - mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId); + if (bExtURL) + mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId); + else + mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId, + XML_action, "ppaction://hlinksldjump"); + } + else + { + sal_Int32 nIndex = sURL.indexOf('='); + OUString aDestination(sURL.copy(nIndex + 1)); + mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), "", XML_action, + "ppaction://hlinkshowjump?jump=" + aDestination); + } } } - mpFS->endElementNS( XML_a, nElement ); } |