[Libreoffice-commits] .: oox/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Jun 5 02:05:33 PDT 2012


 oox/source/shape/ShapeContextHandler.cxx |   83 ++++++++++++++++++++++++++++++-
 oox/source/shape/ShapeFilterBase.cxx     |   44 ++++++++++++++++
 oox/source/shape/ShapeFilterBase.hxx     |    7 ++
 3 files changed, 131 insertions(+), 3 deletions(-)

New commits:
commit 110c8df2d80bd09c2848eba0091d8a1f7b51bcc9
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jun 4 12:46:17 2012 +0200

    oox: import prerendered smartart into writer
    
    Change-Id: I1c76c1bb2098c42727ae4e605e20746d0bb09463

diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index 0643603..77223c0 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -26,11 +26,17 @@
  *
  ************************************************************************/
 
+#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
+
 #include "ShapeContextHandler.hxx"
 #include "oox/vml/vmldrawingfragment.hxx"
 #include "oox/vml/vmlshape.hxx"
 #include "oox/vml/vmlshapecontainer.hxx"
 #include "oox/drawingml/diagram/diagram.hxx"
+#include "oox/drawingml/shapegroupcontext.hxx"
+#include "oox/drawingml/shapestylecontext.hxx"
+#include "oox/drawingml/textbodycontext.hxx"
+#include "oox/drawingml/themefragmenthandler.hxx"
 
 namespace oox { namespace shape {
 
@@ -172,7 +178,21 @@ void SAL_CALL ShapeContextHandler::startFastElement
     mpThemePtr.reset(new Theme());
 
     if (Element == DGM_TOKEN(relIds))
+    {
+        // Parse the theme relation, if available; the diagram won't have colors without it.
+        if (!msRelationFragmentPath.isEmpty())
+        {
+            FragmentHandlerRef rFragmentHandler(new ShapeFragmentHandler(*mxFilterBase, msRelationFragmentPath));
+            rtl::OUString aThemeFragmentPath = rFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "theme" ) );
+            uno::Reference<xml::sax::XFastSAXSerializable> xDoc(mxFilterBase->importFragment(aThemeFragmentPath), uno::UNO_QUERY_THROW);
+            mxFilterBase->importFragment(new ThemeFragmentHandler(*mxFilterBase, aThemeFragmentPath, *mpThemePtr ), xDoc);
+            ShapeFilterBase* pShapeFilterBase(dynamic_cast<ShapeFilterBase*>(mxFilterBase.get()));
+            if (pShapeFilterBase)
+                pShapeFilterBase->setCurrentTheme(mpThemePtr);
+        }
+
         createFastChildContext(Element, Attribs);
+    }
 
     uno::Reference<XFastContextHandler> xContextHandler(getContextHandler());
 
@@ -252,6 +272,48 @@ void SAL_CALL ShapeContextHandler::characters(const ::rtl::OUString & aChars)
         xContextHandler->characters(aChars);
 }
 
+/// Generic (i.e. not specific to PPTX) handler for the prerendered diagram parsing.
+class ShapeExtDrawingFragmentHandler : public ::oox::core::FragmentHandler
+{
+public:
+    ShapeExtDrawingFragmentHandler( oox::core::XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath,
+        oox::drawingml::ShapePtr pGroupShapePtr ) throw()
+        : FragmentHandler( rFilter, rFragmentPath ),
+        mpGroupShapePtr( pGroupShapePtr )
+    {
+    }
+
+    virtual ~ShapeExtDrawingFragmentHandler() throw()
+    {
+    }
+
+    virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
+    {
+    }
+
+    virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& /*Attribs*/ ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
+    {
+        uno::Reference< XFastContextHandler > xRet;
+
+        switch( Element )
+        {
+            case DSP_TOKEN( spTree ):
+                xRet.set( new ShapeGroupContext(*this, ShapePtr((Shape*)0), mpGroupShapePtr));
+                break;
+            default:
+                break;
+        }
+
+        if( !xRet.is() )
+            xRet = getFastContextHandler();
+
+        return xRet;
+    }
+
+private:
+        oox::drawingml::ShapePtr        mpGroupShapePtr;
+};
+
 // ::com::sun::star::xml::sax::XFastShapeContextHandler:
 uno::Reference< drawing::XShape > SAL_CALL
 ShapeContextHandler::getShape() throw (uno::RuntimeException)
@@ -270,8 +332,25 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
         else if (mxDiagramShapeContext.is())
         {
             basegfx::B2DHomMatrix aMatrix;
-            mpShape->addShape( *mxFilterBase, mpThemePtr.get(), xShapes, aMatrix );
-            xResult = mpShape->getXShape();
+            if (mpShape->getExtDrawings().size() == 0)
+            {
+                xResult = mpShape->getXShape();
+                mpShape->addShape( *mxFilterBase, mpThemePtr.get(), xShapes, aMatrix );
+            }
+            else
+            {
+                // Prerendered diagram output is available, then use that, and throw away the original result.
+                for (std::vector<rtl::OUString>::const_iterator aIt = mpShape->getExtDrawings().begin(); aIt != mpShape->getExtDrawings().end(); ++aIt)
+                {
+                    DiagramGraphicDataContext* pDiagramGraphicDataContext = dynamic_cast<DiagramGraphicDataContext*>(mxDiagramShapeContext.get());
+                    rtl::OUString aFragmentPath(pDiagramGraphicDataContext->getFragmentPathFromRelId(*aIt));
+                    oox::drawingml::ShapePtr pShapePtr( new Shape( "com.sun.star.drawing.GroupShape" ) );
+                    mxFilterBase->importFragment(new ShapeExtDrawingFragmentHandler(*mxFilterBase, aFragmentPath, pShapePtr));
+                    pShapePtr->addShape( *mxFilterBase, mpThemePtr.get(), xShapes, aMatrix );
+                    xResult = pShapePtr->getXShape();
+                }
+                mpShape.reset((Shape*)0);
+            }
         }
         else if (mpShape.get() != NULL)
         {
diff --git a/oox/source/shape/ShapeFilterBase.cxx b/oox/source/shape/ShapeFilterBase.cxx
index ac010d4..e06f834 100644
--- a/oox/source/shape/ShapeFilterBase.cxx
+++ b/oox/source/shape/ShapeFilterBase.cxx
@@ -29,6 +29,7 @@
 #include "ShapeFilterBase.hxx"
 #include "oox/drawingml/chart/chartconverter.hxx"
 #include "oox/ole/vbaproject.hxx"
+#include "oox/drawingml/theme.hxx"
 
 namespace oox {
 namespace shape {
@@ -47,7 +48,12 @@ ShapeFilterBase::~ShapeFilterBase()
 
 const ::oox::drawingml::Theme* ShapeFilterBase::getCurrentTheme() const
 {
-    return 0;
+    return mpTheme.get();
+}
+
+void ShapeFilterBase::setCurrentTheme(::oox::drawingml::ThemePtr pTheme)
+{
+    mpTheme = pTheme;
 }
 
 ::oox::vml::Drawing* ShapeFilterBase::getVmlDrawing()
@@ -75,6 +81,42 @@ const ::oox::drawingml::table::TableStyleListPtr ShapeFilterBase::getTableStyles
     return ::rtl::OUString();
 }
 
+/// Graphic helper for shapes, that can manage color schemes.
+class ShapeGraphicHelper : public GraphicHelper
+{
+public:
+    explicit            ShapeGraphicHelper( const ShapeFilterBase& rFilter );
+    virtual sal_Int32   getSchemeColor( sal_Int32 nToken ) const;
+private:
+    const ShapeFilterBase& mrFilter;
+};
+
+ShapeGraphicHelper::ShapeGraphicHelper( const ShapeFilterBase& rFilter ) :
+    GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
+    mrFilter( rFilter )
+{
+}
+
+sal_Int32 ShapeGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
+{
+    return mrFilter.getSchemeColor( nToken );
+}
+
+GraphicHelper* ShapeFilterBase::implCreateGraphicHelper() const
+{
+    return new ShapeGraphicHelper( *this );
+}
+
+sal_Int32 ShapeFilterBase::getSchemeColor( sal_Int32 nToken ) const
+{
+    sal_Int32 nColor = 0;
+
+    if (mpTheme.get())
+        mpTheme->getClrScheme().getColor( nToken, nColor );
+
+    return nColor;
+}
+
 }
 }
 
diff --git a/oox/source/shape/ShapeFilterBase.hxx b/oox/source/shape/ShapeFilterBase.hxx
index 360e810..03846d8 100644
--- a/oox/source/shape/ShapeFilterBase.hxx
+++ b/oox/source/shape/ShapeFilterBase.hxx
@@ -34,6 +34,7 @@
 #include "oox/vml/vmldrawing.hxx"
 #include "oox/drawingml/table/tablestylelist.hxx"
 #include "oox/core/xmlfilterbase.hxx"
+#include "oox/drawingml/drawingmltypes.hxx"
 
 namespace oox {
 namespace shape {
@@ -54,6 +55,8 @@ public:
     /** Has to be implemented by each filter, returns the current theme. */
     virtual const ::oox::drawingml::Theme* getCurrentTheme() const;
 
+    void setCurrentTheme(::oox::drawingml::ThemePtr pTheme);
+
     /** Has to be implemented by each filter to return the collection of VML shapes. */
     virtual ::oox::vml::Drawing* getVmlDrawing();
 
@@ -65,11 +68,15 @@ public:
     virtual bool importDocument() { return true; }
     virtual bool exportDocument() { return true; }
 
+    sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
+
 private:
     virtual ::oox::ole::VbaProject* implCreateVbaProject() const;
     virtual rtl::OUString implGetImplementationName() const;
+    virtual GraphicHelper* implCreateGraphicHelper() const;
 
     ::boost::shared_ptr< ::oox::drawingml::chart::ChartConverter > mxChartConv;
+    ::oox::drawingml::ThemePtr mpTheme;
 };
 
 // ============================================================================


More information about the Libreoffice-commits mailing list