diff options
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 5 | ||||
-rw-r--r-- | drawinglayer/Library_drawinglayer.mk | 2 | ||||
-rw-r--r-- | drawinglayer/Package_inc.mk | 1 | ||||
-rw-r--r-- | drawinglayer/inc/drawinglayer/ChartViewDumper.hxx | 50 | ||||
-rw-r--r-- | drawinglayer/source/dumper/ChartViewDumper.cxx | 159 |
5 files changed, 216 insertions, 1 deletions
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 8714040fed9d..0b1f19d53e16 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -3023,6 +3023,9 @@ uno::Sequence< ::rtl::OUString > ChartView::getAvailableServiceNames() throw (un return aServiceNames; } +/* ---------------------- + goes to drawinglayer/ + ---------------------- namespace { #define DEBUG_DUMPER 0 @@ -3118,7 +3121,7 @@ void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr x } } - +*/ rtl::OUString ChartView::dump() throw (uno::RuntimeException) { impl_updateView(); diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk index 94ab023682ea..37e0cdd9e7b6 100644 --- a/drawinglayer/Library_drawinglayer.mk +++ b/drawinglayer/Library_drawinglayer.mk @@ -31,6 +31,7 @@ $(eval $(call gb_Library_use_package,drawinglayer,drawinglayer_inc)) $(eval $(call gb_Library_set_include,drawinglayer,\ $$(INCLUDE) \ + -I$(SRCDIR)/drawinglayer/inc \ )) $(eval $(call gb_Library_add_defs,drawinglayer,\ @@ -171,6 +172,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\ drawinglayer/source/processor3d/zbufferprocessor3d \ drawinglayer/source/texture/texture3d \ drawinglayer/source/texture/texture \ + drawinglayer/source/dumper/ChartViewDumper \ )) # vim: set noet sw=4 ts=4: diff --git a/drawinglayer/Package_inc.mk b/drawinglayer/Package_inc.mk index 4cc1d34c530d..51c52ce838ea 100644 --- a/drawinglayer/Package_inc.mk +++ b/drawinglayer/Package_inc.mk @@ -137,5 +137,6 @@ $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor3d/ $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/processor3d/zbufferprocessor3d.hxx,drawinglayer/processor3d/zbufferprocessor3d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/texture/texture3d.hxx,drawinglayer/texture/texture3d.hxx)) $(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/texture/texture.hxx,drawinglayer/texture/texture.hxx)) +$(eval $(call gb_Package_add_file,drawinglayer_inc,inc/drawinglayer/ChartViewDumper.hxx,drawinglayer/ChartViewDumper.hxx)) # vim: set noet sw=4 ts=4: diff --git a/drawinglayer/inc/drawinglayer/ChartViewDumper.hxx b/drawinglayer/inc/drawinglayer/ChartViewDumper.hxx new file mode 100644 index 000000000000..b7f355213a28 --- /dev/null +++ b/drawinglayer/inc/drawinglayer/ChartViewDumper.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Artur Dorda <artur.dorda+libo@gmail.com> (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <libxml/xmlwriter.h> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/drawing/XShape.hpp> + +#ifndef ChartViewDumper_hxx +#define ChartViewDumper_hxx + +class ChartViewDumper +{ + +public: + ChartViewDumper(); + int writeCallback(void* pContext, const char* sBuffer, int nLen); + void dumpPositionAsAttribute(const com::sun::star::awt::Point& rPoint, xmlTextWriterPtr xmlWriter); + void dumpSizeAsAttribute(const com::sun::star::awt::Size& rSize, xmlTextWriterPtr xmlWriter); + void dumpShapeDescriptorAsAttribute( com::sun::star::uno::Reference< com::sun::star::drawing::XShapeDescriptor > xDescr, xmlTextWriterPtr xmlWriter ); + void dumpXShape(com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape, xmlTextWriterPtr xmlWriter); + void dumpXShapes( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter ); + rtl::OUString dump(); + +}; +#endif diff --git a/drawinglayer/source/dumper/ChartViewDumper.cxx b/drawinglayer/source/dumper/ChartViewDumper.cxx new file mode 100644 index 000000000000..5d3c03761242 --- /dev/null +++ b/drawinglayer/source/dumper/ChartViewDumper.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Artur Dorda <artur.dorda+libo@gmail.com> (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <drawinglayer/ChartViewDumper.hxx> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XText.hpp> +#include <rtl/strbuf.hxx> + + +#define DEBUG_DUMPER 0 + +using namespace com::sun::star; +//class ChartViewDumper +namespace +{ + void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter ); + + int writeCallback(void* pContext, const char* sBuffer, int nLen) + { + rtl::OStringBuffer* pBuffer = static_cast<rtl::OStringBuffer*>(pContext); + pBuffer->append(sBuffer); + return nLen; + } + + int closeCallback(void* ) + { + return 0; + } + + void dumpPositionAsAttribute(const awt::Point& rPoint, xmlTextWriterPtr xmlWriter) + { + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("positionX"), "%" SAL_PRIdINT32, rPoint.X); + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("positionY"), "%" SAL_PRIdINT32, rPoint.Y); + } + + void dumpSizeAsAttribute(const awt::Size& rSize, xmlTextWriterPtr xmlWriter) + { + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("sizeX"), "%" SAL_PRIdINT32, rSize.Width); + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("sizeY"), "%" SAL_PRIdINT32, rSize.Height); + } + + void dumpShapeDescriptorAsAttribute( uno::Reference< drawing::XShapeDescriptor > xDescr, xmlTextWriterPtr xmlWriter ) + { + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("type"), "%s", rtl::OUStringToOString(xDescr->getShapeType(), RTL_TEXTENCODING_UTF8).getStr()); + } + + void dumpXShape(uno::Reference< drawing::XShape > xShape, xmlTextWriterPtr xmlWriter) + { + xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShape" ) ); + + dumpPositionAsAttribute(xShape->getPosition(), xmlWriter); + dumpSizeAsAttribute(xShape->getSize(), xmlWriter); + uno::Reference< drawing::XShapeDescriptor > xDescr(xShape, uno::UNO_QUERY_THROW); + dumpShapeDescriptorAsAttribute(xDescr, xmlWriter); + + uno::Reference< lang::XServiceInfo > xServiceInfo( xShape, uno::UNO_QUERY_THROW ); + uno::Sequence< rtl::OUString > aServiceNames = xServiceInfo->getSupportedServiceNames(); + + uno::Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY_THROW); + uno::Any aAny = xPropSet->getPropertyValue("Name"); + rtl::OUString aName; + if (aAny >>= aName) + { + if (!aName.isEmpty()) + xmlTextWriterWriteFormatAttribute( xmlWriter, BAD_CAST("name"), "%s", rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr()); + } + if (xServiceInfo->supportsService("com.sun.star.drawing.Text")) + { + uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY_THROW); + rtl::OUString aText = xText->getString(); + if(!aText.isEmpty()) + xmlTextWriterWriteFormatAttribute( xmlWriter, BAD_CAST("text"), "%s", rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr()); + } + else if(xServiceInfo->supportsService("com.sun.star.drawing.GroupShape")) + { + uno::Reference< drawing::XShapes > xShapes(xShape, uno::UNO_QUERY_THROW); + dumpXShapes(xShapes, xmlWriter); + } + + #if DEBUG_DUMPER + sal_Int32 nServices = aServiceNames.getLength(); + for (sal_Int32 i = 0; i < nServices; ++i) + { + xmlTextWriterStartElement(xmlWriter, BAD_CAST( "ServiceName" )); + xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST( "name" ), "%s", rtl::OUStringToOString(aServiceNames[i], RTL_TEXTENCODING_UTF8).getStr()); + xmlTextWriterEndElement( xmlWriter ); + } + #endif + + xmlTextWriterEndElement( xmlWriter ); + } + + void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter ) + { + xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShapes" ) ); + uno::Reference< container::XIndexAccess > xIA( xShapes, uno::UNO_QUERY_THROW); + sal_Int32 nLength = xIA->getCount(); + for (sal_Int32 i = 0; i < nLength; ++i) + { + uno::Reference< drawing::XShape > xShape( xIA->getByIndex( i ), uno::UNO_QUERY_THROW ); + dumpXShape( xShape, xmlWriter ); + } + + xmlTextWriterEndElement( xmlWriter ); + } + + rtl::OUString dump() throw (uno::RuntimeException) + { + impl_updateView(); + uno::Reference<drawing::XShapes> xPageShapes( ShapeFactory(m_xShapeFactory) + .getOrCreateChartRootShape( m_xDrawPage ) ); + + if (!xPageShapes.is()) + return rtl::OUString(); + + rtl::OStringBuffer aString; + xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO( writeCallback, closeCallback, &aString, NULL ); + xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); + xmlTextWriterSetIndent( xmlWriter, 1 ); + + xmlTextWriterStartDocument( xmlWriter, NULL, NULL, NULL ); + + dumpXShapes( xPageShapes, xmlWriter ); + + xmlTextWriterEndDocument( xmlWriter ); + xmlFreeTextWriter( xmlWriter ); + + return OStringToOUString(aString.makeStringAndClear(), RTL_TEXTENCODING_UTF8); + } + +} //end of namespace |