[Libreoffice-commits] core.git: sw/qa writerfilter/source

drazil abcdefghi236 at gmail.com
Fri Sep 2 14:59:05 UTC 2016


 sw/qa/extras/ooxmlimport/data/image-hyperlink.docx    |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx              |    6 +++
 writerfilter/source/dmapper/GraphicImport.cxx         |   14 ++++++++
 writerfilter/source/ooxml/Handler.cxx                 |   31 ++++++++++++++++++
 writerfilter/source/ooxml/Handler.hxx                 |   13 +++++++
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx |    6 ++-
 writerfilter/source/ooxml/OOXMLFastContextHandler.hxx |    1 
 writerfilter/source/ooxml/factoryimpl_ns.py           |    2 -
 writerfilter/source/ooxml/model.xml                   |   11 +++++-
 9 files changed, 81 insertions(+), 3 deletions(-)

New commits:
commit 8e375369206606c541cff5f46ea6a87db2c808b4
Author: drazil <abcdefghi236 at gmail.com>
Date:   Sun Aug 28 14:22:57 2016 +0800

    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 at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlimport/data/image-hyperlink.docx b/sw/qa/extras/ooxmlimport/data/image-hyperlink.docx
new file mode 100644
index 0000000..ab0b53b
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/image-hyperlink.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 19266ef..1187770 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -159,6 +159,12 @@ public:
     }
 };
 
+DECLARE_OOXMLIMPORT_TEST(testImageHyperlink, "image-hyperlink.docx")
+{
+    OUString URL = getProperty<OUString>(getShape(1), "HyperLinkURL");
+    CPPUNIT_ASSERT_EQUAL(OUString("http://www.libreoffice.org/"), URL);
+}
+
 #if !defined(_WIN32)
 
 DECLARE_SW_IMPORT_TEST(testMathMalformedXml, "math-malformed_xml.docx", FailTest)
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 168d83a..006c91c 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 7915f8b..0600b5b 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 e2d5907..80254d5 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 c6730eb..50fcef3 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 47f363f..a8ad379 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 d9baaa1..60437ba 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 61438c3..89c8af8 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"/>


More information about the Libreoffice-commits mailing list