summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authordrazil <abcdefghi236@gmail.com>2016-08-28 14:22:57 +0800
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-09-02 14:58:40 +0000
commit8e375369206606c541cff5f46ea6a87db2c808b4 (patch)
treea11dbe241612a9ce28d781da9332d7371e9ef327 /writerfilter
parentc6ff9323c11160502b3339cc4bca92630ddcb836 (diff)
tdf#62847 import image hyperlink in docx
The image hyperlink is a resource id in the document and needs to be translated into real URL. First I define a new type CT_Hyperlink_URL in the model and associate it with an action handleHyperlinkURL. In OOXMLFastContextHandlerProperties::handleHyperlinkURL I dispatch it to OOXMLHyperlinkURLHandler to translate resource id to real URL then set the PropertySet with real URL. Then the correct URL will be captured while resolving GraphicImport, which will be stored in GraphicImport_Impl::sHyperlinkURL as an OUString. Finally the property will be set in the GraphicImport::applyName if the length of the sHyperlinkURL is not 0. Also adds a test file image-hyperlink.docx and a test in ooxmlimport.cxx. Change-Id: I6194b9cc6bcc1bfaa033ab05e94836fe96e33f14 Reviewed-on: https://gerrit.libreoffice.org/28432 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx14
-rw-r--r--writerfilter/source/ooxml/Handler.cxx31
-rw-r--r--writerfilter/source/ooxml/Handler.hxx13
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx6
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx1
-rw-r--r--writerfilter/source/ooxml/factoryimpl_ns.py2
-rw-r--r--writerfilter/source/ooxml/model.xml11
7 files changed, 75 insertions, 3 deletions
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 168d83aba0a6..006c91c44489 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -248,6 +248,7 @@ public:
OUString sName;
OUString sAlternativeText;
OUString title;
+ OUString sHyperlinkURL;
std::pair<OUString, OUString>& m_rPositionOffsets;
std::pair<OUString, OUString>& m_rAligns;
std::queue<OUString>& m_rPositivePercentages;
@@ -390,6 +391,9 @@ public:
uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
xNamed->setName(rDomainMapper.GetGraphicNamingHelper().NameGraphic(sName));
+ if ( sHyperlinkURL.getLength() > 0 )
+ xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_HYPER_LINK_U_R_L ),
+ uno::makeAny ( sHyperlinkURL ));
xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_DESCRIPTION ),
uno::makeAny( sAlternativeText ));
xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_TITLE ),
@@ -500,6 +504,9 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
sal_Int32 nIntValue = rValue.getInt();
switch( nName )
{
+ case NS_ooxml::LN_CT_Hyperlink_URL://90682;
+ m_pImpl->sHyperlinkURL = rValue.getString();
+ break;
case NS_ooxml::LN_blip: //the binary graphic data in a shape
{
writerfilter::Reference<Properties>::Pointer_t pProperties = rValue.getProperties();
@@ -1103,6 +1110,13 @@ void GraphicImport::lcl_sprm(Sprm& rSprm)
pProperties->resolve(*this);
}
break;
+ case NS_ooxml::LN_CT_NonVisualDrawingProps_a_hlinkClick: // 90689;
+ {
+ writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
+ if( pProperties.get( ) )
+ pProperties->resolve( *this );
+ }
+ break;
default:
SAL_WARN("writerfilter", "GraphicImport::lcl_sprm: unhandled token: " << nSprmId);
break;
diff --git a/writerfilter/source/ooxml/Handler.cxx b/writerfilter/source/ooxml/Handler.cxx
index 7915f8baef29..0600b5b1853c 100644
--- a/writerfilter/source/ooxml/Handler.cxx
+++ b/writerfilter/source/ooxml/Handler.cxx
@@ -368,6 +368,37 @@ void OOXMLHyperlinkHandler::sprm(Sprm & /*rSprm*/)
{
}
+/**
+ class OOXMLHyperlinkURLHandler
+ */
+
+OOXMLHyperlinkURLHandler::OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pContext)
+: mpFastContext(pContext)
+{
+}
+
+OOXMLHyperlinkURLHandler::~OOXMLHyperlinkURLHandler()
+{
+ mpFastContext->clearProps();
+ mpFastContext->newProperty(NS_ooxml::LN_CT_Hyperlink_URL, OOXMLValue::Pointer_t(new OOXMLStringValue(mURL)));
+}
+
+void OOXMLHyperlinkURLHandler::attribute(Id name, Value & val)
+{
+ switch (name)
+ {
+ case NS_ooxml::LN_CT_Hyperlink_URL:
+ mURL = mpFastContext->getTargetForId(val.getString());
+ break;
+ default:
+ break;
+ }
+}
+
+void OOXMLHyperlinkURLHandler::sprm(Sprm & /*rSprm*/)
+{
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/ooxml/Handler.hxx b/writerfilter/source/ooxml/Handler.hxx
index e2d59070621f..80254d5ee602 100644
--- a/writerfilter/source/ooxml/Handler.hxx
+++ b/writerfilter/source/ooxml/Handler.hxx
@@ -144,6 +144,19 @@ public:
virtual void sprm(Sprm & sprm) override;
};
+class OOXMLHyperlinkURLHandler : public Properties
+{
+ OOXMLFastContextHandler * mpFastContext;
+ OUString mURL;
+
+public:
+ explicit OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pContext);
+ virtual ~OOXMLHyperlinkURLHandler();
+
+ virtual void attribute(Id name, Value & val) override;
+ virtual void sprm(Sprm & sprm) override;
+};
+
}}
#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_HANDLER_HXX
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index c6730eb9a2af..50fcef361ac4 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -862,7 +862,6 @@ void OOXMLFastContextHandler::sendPropertiesToParent()
}
}
-
/*
class OOXMLFastContextHandlerStream
*/
@@ -1056,6 +1055,11 @@ void OOXMLFastContextHandlerProperties::handleFontRel()
getPropertySet()->resolve(handler);
}
+void OOXMLFastContextHandlerProperties::handleHyperlinkURL() {
+ OOXMLHyperlinkURLHandler aHyperlinkURLHandler(this);
+ getPropertySet()->resolve(aHyperlinkURLHandler);
+}
+
void OOXMLFastContextHandlerProperties::setParent
(OOXMLFastContextHandler * pParent)
{
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 47f363fd59ba..a8ad379a7399 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -277,6 +277,7 @@ public:
void handleBreak();
void handleOLE();
void handleFontRel();
+ void handleHyperlinkURL();
virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet) override;
virtual OOXMLPropertySet::Pointer_t getPropertySet() const override;
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
index d9baaa1c3613..60437ba7bfb8 100644
--- a/writerfilter/source/ooxml/factoryimpl_ns.py
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -428,7 +428,7 @@ def factoryChooseAction(actionNode):
ret.append(" {")
extra_space = " "
- if actionNode.getAttribute("action") in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOLE", "handleFontRel"):
+ if actionNode.getAttribute("action") in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOLE", "handleFontRel", "handleHyperlinkURL"):
ret.append(" %sif (OOXMLFastContextHandlerProperties* pProperties = dynamic_cast<OOXMLFastContextHandlerProperties*>(pHandler))" % extra_space)
ret.append(" %s pProperties->%s();" % (extra_space, actionNode.getAttribute("action")))
elif actionNode.getAttribute("action") == "propagateCharacterPropertiesAsSet":
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 61438c3d1f58..89c8af806fef 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -3873,7 +3873,7 @@
</define>
<define name="CT_NonVisualDrawingProps">
<element name="a:hlinkClick">
- <ref name="BUILT_IN_ANY_TYPE"/>
+ <ref name="CT_Hyperlink_URL"/>
</element>
<element name="hlinkHover">
<ref name="CT_Hyperlink"/>
@@ -3897,6 +3897,11 @@
<data type="string"/>
</attribute>
</define>
+ <define name="CT_Hyperlink_URL">
+ <attribute name="r:id">
+ <data type="string"/>
+ </attribute>
+ </define>
<define name="CT_NonVisualDrawingShapeProps">
<element name="spLocks">
<ref name="CT_ShapeLocking"/>
@@ -3950,6 +3955,10 @@
</element>
</define>
</grammar>
+ <resource name="CT_Hyperlink_URL" resource="Properties">
+ <attribute name="r:id" tokenid="ooxml:CT_Hyperlink_URL"/>
+ <action name="start" action="handleHyperlinkURL"/>
+ </resource>
<resource name="CT_GraphicalObjectFrameLocking" resource="Properties">
<element name="extLst" tokenid="ooxml:CT_GraphicalObjectFrameLocking_extLst"/>
<attribute name="noGrp" tokenid="ooxml:CT_GraphicalObjectFrameLocking_noGrp"/>