[Libreoffice-commits] core.git: 4 commits - oox/Library_oox.mk oox/source sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Nov 13 06:43:16 PST 2013


 oox/Library_oox.mk                            |    1 
 oox/source/shape/ShapeContextHandler.cxx      |   37 ++++++++++++++++
 oox/source/shape/ShapeContextHandler.hxx      |    2 
 oox/source/shape/WpsContext.cxx               |   58 ++++++++++++++++++++++++++
 oox/source/shape/WpsContext.hxx               |   38 +++++++++++++++++
 oox/source/token/namespaces.hxx.tail          |    1 
 oox/source/token/namespaces.txt               |    1 
 oox/source/token/tokens.txt                   |    1 
 sw/qa/extras/ooxmlimport/data/wps-only.docx   |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx      |    7 +++
 writerfilter/source/dmapper/GraphicImport.cxx |   11 ++++
 writerfilter/source/ooxml/model.xml           |   23 ++++++++++
 12 files changed, 179 insertions(+), 1 deletion(-)

New commits:
commit 903bbf3865809ddd03e181eee1c6297c91021743
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Nov 13 13:41:17 2013 +0100

    writerfilter: fix anchoring of anchored wps (drawingML) shapes
    
    Previous code assumed that either we're dealing with VML shapes (where
    the shape knows its position, anchoring, etc.) or with Wrtier pictures.
    drawingML shapes are a third category: they don't know their anchoring
    (and similar properties), still they are not Writer pictures.
    
    For now just fix the anchoring, other properties should be handled in a
    later follow-up commit.
    
    Change-Id: I2fede3b11cfbd423cd50cfc0c032d424c81c6c4a

diff --git a/sw/qa/extras/ooxmlimport/data/wps-only.docx b/sw/qa/extras/ooxmlimport/data/wps-only.docx
new file mode 100644
index 0000000..5b563b0
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/wps-only.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index f2c3b70..91f49c0 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1505,6 +1505,13 @@ DECLARE_OOXMLIMPORT_TEST(testFdo69548, "fdo69548.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("#this is a bookmark"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
 }
 
+DECLARE_OOXMLIMPORT_TEST(testWpsOnly, "wps-only.docx")
+{
+    // Document has wp:anchor, not wp:inline, so handle it accordingly.
+    text::TextContentAnchorType eValue = getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType");
+    CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, eValue);
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index ba8aab2..ff3409c 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -986,6 +986,16 @@ void GraphicImport::lcl_attribute(Id nName, Value & val)
 
                         m_pImpl->bIsGraphic = true;
                     }
+
+                    if (bUseShape && m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
+                    {
+                        // If we are here, this is a drawingML shape. For those, only dmapper (and not oox) knows the anchoring infos (just like for Writer pictures).
+                        // But they aren't Writer pictures, either (which are already handled above).
+                        uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW);
+                        xShapeProps->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+
+                        // TODO handle more properties here like HoriOrientPosition, etc.
+                    }
                 }
             }
         break;
commit 400d5d8a90f1f2737f87b7011294cddb8071768f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Nov 13 10:35:36 2013 +0100

    oox: initial import of wps:wsp
    
    We import something that's visible, but the shape is always inline, even
    when it has to be anchored.
    
    Change-Id: I6e20aa1a208f06731098ad21bb51c1ca840213d0

diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index dd30e70..7bd3710 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -277,6 +277,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
     oox/source/shape/ShapeContextHandler \
     oox/source/shape/ShapeDrawingFragmentHandler \
     oox/source/shape/ShapeFilterBase \
+    oox/source/shape/WpsContext \
     oox/source/token/namespacemap \
     oox/source/token/propertynames \
     oox/source/token/tokenmap \
diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index dbbd41d..8286def 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -22,6 +22,7 @@
 #include "ShapeContextHandler.hxx"
 #include "ShapeDrawingFragmentHandler.hxx"
 #include "LockedCanvasContext.hxx"
+#include "WpsContext.hxx"
 #include "oox/vml/vmldrawingfragment.hxx"
 #include "oox/vml/vmlshape.hxx"
 #include "oox/drawingml/themefragmenthandler.hxx"
@@ -115,6 +116,26 @@ uno::Reference<xml::sax::XFastContextHandler> ShapeContextHandler::getChartShape
     return mxChartShapeContext;
 }
 
+uno::Reference<xml::sax::XFastContextHandler> ShapeContextHandler::getWpsContext(sal_Int32 nElement)
+{
+    if (!mxWpsContext.is())
+    {
+        FragmentHandler2Ref rFragmentHandler(new ShapeFragmentHandler(*mxFilterBase, msRelationFragmentPath));
+        ShapePtr pMasterShape;
+
+        switch (getBaseToken(nElement))
+        {
+            case XML_wsp:
+                mxWpsContext.set(new WpsContext(*rFragmentHandler));
+                break;
+            default:
+                break;
+        }
+    }
+
+    return mxWpsContext;
+}
+
 uno::Reference<xml::sax::XFastContextHandler>
 ShapeContextHandler::getGraphicShapeContext(::sal_Int32 Element )
 {
@@ -192,6 +213,9 @@ ShapeContextHandler::getContextHandler()
         case NMSP_dmlChart:
             xResult.set(getChartShapeContext(mnStartToken));
             break;
+        case NMSP_wps:
+            xResult.set(getWpsContext(mnStartToken));
+            break;
         default:
             xResult.set(getGraphicShapeContext(mnStartToken));
             break;
@@ -216,7 +240,7 @@ void SAL_CALL ShapeContextHandler::startFastElement
 
     mpThemePtr.reset(new Theme());
 
-    if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) )
+    if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp))
     {
         // Parse the theme relation, if available; the diagram won't have colors without it.
         if (!msRelationFragmentPath.isEmpty())
@@ -396,6 +420,17 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
             xResult = pShapePtr->getXShape();
             mxChartShapeContext.clear();
         }
+        else if (mxWpsContext.is())
+        {
+            ShapePtr pShape = dynamic_cast<WpsContext*>(mxWpsContext.get())->getShape();
+            if (pShape)
+            {
+                basegfx::B2DHomMatrix aMatrix;
+                pShape->addShape(*mxFilterBase, mpThemePtr.get(), xShapes, aMatrix, pShape->getFillProperties());
+                xResult = pShape->getXShape();
+                mxWpsContext.clear();
+            }
+        }
         else if (mpShape.get() != NULL)
         {
             basegfx::B2DHomMatrix aTransformation;
diff --git a/oox/source/shape/ShapeContextHandler.hxx b/oox/source/shape/ShapeContextHandler.hxx
index d7a49a1..11fdc0b 100644
--- a/oox/source/shape/ShapeContextHandler.hxx
+++ b/oox/source/shape/ShapeContextHandler.hxx
@@ -150,6 +150,7 @@ private:
     css::uno::Reference<XFastContextHandler> mxGraphicShapeContext;
     css::uno::Reference<XFastContextHandler> mxDiagramShapeContext;
     css::uno::Reference<XFastContextHandler> mxLockedCanvasContext;
+    css::uno::Reference<XFastContextHandler> mxWpsContext;
     css::uno::Reference<XFastContextHandler> mxChartShapeContext;
 
     core::XmlFilterRef mxFilterBase;
@@ -163,6 +164,7 @@ private:
     css::uno::Reference<XFastContextHandler> getDrawingShapeContext();
     css::uno::Reference<XFastContextHandler> getDiagramShapeContext();
     css::uno::Reference<XFastContextHandler> getLockedCanvasContext(sal_Int32 nElement);
+    css::uno::Reference<XFastContextHandler> getWpsContext(sal_Int32 nElement);
     css::uno::Reference<XFastContextHandler> getContextHandler();
 };
 
diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx
new file mode 100644
index 0000000..7b90770
--- /dev/null
+++ b/oox/source/shape/WpsContext.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "WpsContext.hxx"
+#include <oox/drawingml/shapepropertiescontext.hxx>
+#include <oox/drawingml/shapestylecontext.hxx>
+
+using namespace com::sun::star;
+
+namespace oox { namespace shape {
+
+WpsContext::WpsContext(ContextHandler2Helper& rParent)
+: ContextHandler2(rParent)
+{
+    mpShape.reset(new oox::drawingml::Shape("com.sun.star.drawing.CustomShape"));
+}
+
+WpsContext::~WpsContext()
+{
+}
+
+oox::drawingml::ShapePtr WpsContext::getShape()
+{
+    return mpShape;
+}
+
+oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& /*rAttribs*/)
+{
+    switch (getBaseToken(nElementToken))
+    {
+        case XML_wsp:
+            break;
+        case XML_cNvSpPr:
+            break;
+        case XML_spPr:
+            return new oox::drawingml::ShapePropertiesContext(*this, *mpShape);
+            break;
+        case XML_style:
+            return new oox::drawingml::ShapeStyleContext(*this, *mpShape);
+            break;
+        case XML_bodyPr:
+            break;
+        default:
+            SAL_WARN("oox", "WpsContext::createFastChildContext: unhandled element:" << getBaseToken(nElementToken));
+            break;
+    }
+    return 0;
+}
+
+} }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/shape/WpsContext.hxx b/oox/source/shape/WpsContext.hxx
new file mode 100644
index 0000000..cb05de8
--- /dev/null
+++ b/oox/source/shape/WpsContext.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_OOX_SOURCE_SHAPE_WPSCONTEXT_HXX
+#define INCLUDED_OOX_SOURCE_SHAPE_WPSCONTEXT_HXX
+
+#include "oox/core/contexthandler2.hxx"
+#include "oox/drawingml/shape.hxx"
+
+namespace oox { namespace shape {
+
+/// Wps is the drawingML equivalent of v:shape.
+class WpsContext : public oox::core::ContextHandler2
+{
+public:
+    WpsContext(oox::core::ContextHandler2Helper& rParent);
+    virtual ~WpsContext();
+
+    virtual oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs) SAL_OVERRIDE;
+
+    oox::drawingml::ShapePtr getShape();
+
+protected:
+    oox::drawingml::ShapePtr mpShape;
+};
+
+
+} }
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit cd29a30fcf0bf6c66762e4872bf1b8ced5b0262d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Nov 13 10:33:39 2013 +0100

    writerfilter: tokenize wps:wsp
    
    These are just the minimal changes, so that writerfilter calls into
    oox::shape::ShapeContextHandler, which does the real work.
    
    Change-Id: I4f44a508736d780ff090bca0d12526160ddd167f

diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index f147d6c..ba8aab2 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1209,6 +1209,7 @@ void GraphicImport::lcl_sprm(Sprm & rSprm)
         case NS_ooxml::LN_dgm_relIds:
         case NS_ooxml::LN_lc_lockedCanvas:
         case NS_ooxml::LN_c_chart:
+        case NS_ooxml::LN_wps_wsp:
         {
             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
             if( pProperties.get())
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 0efa12a..2e0a300 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -27,6 +27,7 @@
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/picture" alias="picture" id="dmlPicture"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/diagram" alias="diagram" id="dmlDiagram"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" alias="lockedCanvas" id="dmlLockedCanvas"/>
+  <namespace-alias name="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" alias="wps" id="wps"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/chart" alias="chart" id="dmlChart"/>
   <namespace-alias name="urn:schemas-microsoft-com:office:word" alias="vml_wordprocessingDrawing" id="vmlWord"/>
   <namespace-alias name="http://schemas.openxmlformats.org/wordprocessingml/2006/main" alias="wordprocessingml" id="doc"/>
@@ -5171,6 +5172,7 @@
           <ref name="relIds"/>
           <ref name="lockedCanvas"/>
           <ref name="chart"/>
+          <ref name="wsp"/>
           <element>
             <anyName/>
             <ref name="BUILT_IN_ANY_TYPE"/>
@@ -5199,6 +5201,7 @@
       <element name="relIds" tokenid="ooxml:CT_GraphicalObjectData_relIds"/>
       <element name="lockedCanvas" tokenid="ooxml:CT_GraphicalObjectData_lockedCanvas"/>
       <element name="chart" tokenid="ooxml:CT_GraphicalObjectData_chart"/>
+      <element name="wsp" tokenid="ooxml:CT_GraphicalObjectData_wsp"/>
       <attribute name="uri" tokenid="ooxml:CT_GraphicalObjectData_uri"/>
     </resource>
     <resource name="CT_GraphicalObject" resource="Properties" tag="shape">
@@ -8485,6 +8488,19 @@
             <ref name="CT_Chart"/>
         </element>
       </define>
+      <define name="CT_WordprocessingShape">
+        <element name="cNvSpPr">
+          <ref name="CT_NonVisualDrawingShapeProps"/>
+        </element>
+        <element name="spPr">
+          <ref name="CT_ShapeProperties"/>
+        </element>
+      </define>
+      <define name="wsp">
+        <element xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" name="wps:wsp">
+          <ref name="CT_WordprocessingShape"/>
+        </element>
+      </define>
     </grammar>
     <resource name="CT_PictureNonVisual" resource="Properties" tag="shape">
       <element name="cNvPr" tokenid="ooxml:CT_PictureNonVisual_cNvPr"/>
@@ -8520,6 +8536,13 @@
     <resource name="chart" resource="Shape" tag="shape">
         <element xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" name="c:chart" tokenid="ooxml:c_chart"/>
     </resource>
+    <resource xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" name="CT_WordprocessingShape" resource="Shape" tag="shape">
+      <element name="wps:cNvSpPr" tokenid="ooxml:CT_WordprocessingShape_cNvSpPr"/>
+      <element name="wps:spPr" tokenid="ooxml:CT_WordprocessingShape_spPr"/>
+    </resource>
+    <resource name="wsp" resource="Shape" tag="shape">
+      <element xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" name="wps:wsp" tokenid="ooxml:wps_wsp"/>
+    </resource>
 
   </namespace>
   <namespace name="vml-main" file="vml-main.rng" todo="ignore">
commit 1d4db60ab3c1947c096370d043b1f673e92dbc8c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Nov 13 10:32:55 2013 +0100

    oox: add support for the wps namespace
    
    The plan is that once these are here, the writerfilter ooxml tokenizer
    can refer to them. And then the writerfilter will call back to oox to do
    the real drawingml import.
    
    Change-Id: I1f860d1ade21cde767ad259d46b8d38ff167662f

diff --git a/oox/source/token/namespaces.hxx.tail b/oox/source/token/namespaces.hxx.tail
index b684ea5..a0489fe 100644
--- a/oox/source/token/namespaces.hxx.tail
+++ b/oox/source/token/namespaces.hxx.tail
@@ -52,6 +52,7 @@ inline sal_Int32 getNamespace( sal_Int32 nToken ) { return nToken & NMSP_MASK; }
 #define VMLPPT_TOKEN( token )   OOX_TOKEN( vmlPowerpoint, token )
 #define DSP_TOKEN( token )      OOX_TOKEN( dsp, token )
 #define LC_TOKEN( token )       OOX_TOKEN( dmlLockedCanvas, token )
+#define WPS_TOKEN( token )      OOX_TOKEN( wps, token )
 
 // ============================================================================
 
diff --git a/oox/source/token/namespaces.txt b/oox/source/token/namespaces.txt
index 78ba6ba..0083bca 100644
--- a/oox/source/token/namespaces.txt
+++ b/oox/source/token/namespaces.txt
@@ -71,6 +71,7 @@ xm                      http://schemas.microsoft.com/office/excel/2006/main
 sprm                    http://sprm
 mce                     http://schemas.openxmlformats.org/markup-compatibility/2006
 mceTest                 http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2
+wps                     http://schemas.microsoft.com/office/word/2010/wordprocessingShape
 
 # extlst namespaces
 
diff --git a/oox/source/token/tokens.txt b/oox/source/token/tokens.txt
index 94644b4..952520f 100644
--- a/oox/source/token/tokens.txt
+++ b/oox/source/token/tokens.txt
@@ -5660,6 +5660,7 @@ wrapTopAndBottom
 wrapTrailSpaces
 wrapcoords
 writeProtection
+wsp
 wsDr
 x
 x14


More information about the Libreoffice-commits mailing list