1ddde725dSArmin Le Grand /************************************************************** 2ddde725dSArmin Le Grand * 3ddde725dSArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4ddde725dSArmin Le Grand * or more contributor license agreements. See the NOTICE file 5ddde725dSArmin Le Grand * distributed with this work for additional information 6ddde725dSArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7ddde725dSArmin Le Grand * to you under the Apache License, Version 2.0 (the 8ddde725dSArmin Le Grand * "License"); you may not use this file except in compliance 9ddde725dSArmin Le Grand * with the License. You may obtain a copy of the License at 10ddde725dSArmin Le Grand * 11ddde725dSArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12ddde725dSArmin Le Grand * 13ddde725dSArmin Le Grand * Unless required by applicable law or agreed to in writing, 14ddde725dSArmin Le Grand * software distributed under the License is distributed on an 15ddde725dSArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ddde725dSArmin Le Grand * KIND, either express or implied. See the License for the 17ddde725dSArmin Le Grand * specific language governing permissions and limitations 18ddde725dSArmin Le Grand * under the License. 19ddde725dSArmin Le Grand * 20ddde725dSArmin Le Grand *************************************************************/ 21ddde725dSArmin Le Grand 22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 23ddde725dSArmin Le Grand #include "precompiled_svgio.hxx" 24ddde725dSArmin Le Grand 25ddde725dSArmin Le Grand #include <com/sun/star/graphic/XSvgParser.hpp> 26ddde725dSArmin Le Grand #include <com/sun/star/lang/XServiceInfo.hpp> 27ddde725dSArmin Le Grand #include <cppuhelper/implbase2.hxx> 28ddde725dSArmin Le Grand #include <svgio/svgreader/svgdocumenthandler.hxx> 29ddde725dSArmin Le Grand #include <com/sun/star/xml/sax/XParser.hpp> 30ddde725dSArmin Le Grand #include <com/sun/star/xml/sax/InputSource.hpp> 31ddde725dSArmin Le Grand #include <comphelper/processfactory.hxx> 32ddde725dSArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx> 33ddde725dSArmin Le Grand 34ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 35ddde725dSArmin Le Grand 36ddde725dSArmin Le Grand using namespace ::com::sun::star; 37ddde725dSArmin Le Grand 38ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 39ddde725dSArmin Le Grand 40ddde725dSArmin Le Grand namespace svgio 41ddde725dSArmin Le Grand { 42ddde725dSArmin Le Grand namespace svgreader 43ddde725dSArmin Le Grand { 44ddde725dSArmin Le Grand class XSvgParser : public ::cppu::WeakAggImplHelper2< graphic::XSvgParser, lang::XServiceInfo > 45ddde725dSArmin Le Grand { 46ddde725dSArmin Le Grand private: 47ddde725dSArmin Le Grand XSvgParser(const XSvgParser&); 48ddde725dSArmin Le Grand XSvgParser& operator=(const XSvgParser&); 49ddde725dSArmin Le Grand 50ddde725dSArmin Le Grand protected: 51ddde725dSArmin Le Grand public: 52ddde725dSArmin Le Grand XSvgParser(); 53ddde725dSArmin Le Grand virtual ~XSvgParser(); 54ddde725dSArmin Le Grand 55ddde725dSArmin Le Grand // XSvgParser 56ddde725dSArmin Le Grand virtual uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > SAL_CALL getDecomposition( 57ddde725dSArmin Le Grand const uno::Reference< ::io::XInputStream >& xSVGStream, 58ddde725dSArmin Le Grand const ::rtl::OUString& aAbsolutePath) throw (uno::RuntimeException); 59ddde725dSArmin Le Grand 60ddde725dSArmin Le Grand // XServiceInfo 61ddde725dSArmin Le Grand virtual rtl::OUString SAL_CALL getImplementationName() throw(uno::RuntimeException); 62ddde725dSArmin Le Grand virtual ::sal_Bool SAL_CALL supportsService(const rtl::OUString&) throw(uno::RuntimeException); 63ddde725dSArmin Le Grand virtual uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException); 64ddde725dSArmin Le Grand }; 65ddde725dSArmin Le Grand } // end of namespace svgreader 66ddde725dSArmin Le Grand } // end of namespace svgio 67ddde725dSArmin Le Grand 68ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 69ddde725dSArmin Le Grand // uno functions 70ddde725dSArmin Le Grand 71ddde725dSArmin Le Grand namespace svgio 72ddde725dSArmin Le Grand { 73ddde725dSArmin Le Grand namespace svgreader 74ddde725dSArmin Le Grand { XSvgParser_getSupportedServiceNames()75ddde725dSArmin Le Grand uno::Sequence< rtl::OUString > XSvgParser_getSupportedServiceNames() 76ddde725dSArmin Le Grand { 77ddde725dSArmin Le Grand static rtl::OUString aServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.SvgTools" ) ); 78ddde725dSArmin Le Grand static uno::Sequence< rtl::OUString > aServiceNames( &aServiceName, 1 ); 79ddde725dSArmin Le Grand 80ddde725dSArmin Le Grand return( aServiceNames ); 81ddde725dSArmin Le Grand } 82ddde725dSArmin Le Grand XSvgParser_getImplementationName()83ddde725dSArmin Le Grand rtl::OUString XSvgParser_getImplementationName() 84ddde725dSArmin Le Grand { 85ddde725dSArmin Le Grand return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "svgio::svgreader::XSvgParser" ) ); 86ddde725dSArmin Le Grand } 87ddde725dSArmin Le Grand XSvgParser_createInstance(const uno::Reference<lang::XMultiServiceFactory> &)88ddde725dSArmin Le Grand uno::Reference< uno::XInterface > SAL_CALL XSvgParser_createInstance(const uno::Reference< lang::XMultiServiceFactory >&) 89ddde725dSArmin Le Grand { 90ddde725dSArmin Le Grand return static_cast< ::cppu::OWeakObject* >(new XSvgParser); 91ddde725dSArmin Le Grand } 92ddde725dSArmin Le Grand } // end of namespace svgreader 93ddde725dSArmin Le Grand } // end of namespace svgio 94ddde725dSArmin Le Grand 95ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 96ddde725dSArmin Le Grand 97ddde725dSArmin Le Grand namespace svgio 98ddde725dSArmin Le Grand { 99ddde725dSArmin Le Grand namespace svgreader 100ddde725dSArmin Le Grand { XSvgParser()101ddde725dSArmin Le Grand XSvgParser::XSvgParser() 102ddde725dSArmin Le Grand { 103ddde725dSArmin Le Grand } 104ddde725dSArmin Le Grand ~XSvgParser()105ddde725dSArmin Le Grand XSvgParser::~XSvgParser() 106ddde725dSArmin Le Grand { 107ddde725dSArmin Le Grand } 108ddde725dSArmin Le Grand getDecomposition(const uno::Reference<::io::XInputStream> & xSVGStream,const::rtl::OUString & aAbsolutePath)109ddde725dSArmin Le Grand uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > XSvgParser::getDecomposition( 110ddde725dSArmin Le Grand const uno::Reference< ::io::XInputStream >& xSVGStream, 111ddde725dSArmin Le Grand const ::rtl::OUString& aAbsolutePath ) throw (uno::RuntimeException) 112ddde725dSArmin Le Grand { 113ddde725dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aRetval; 114ddde725dSArmin Le Grand 115ddde725dSArmin Le Grand if(xSVGStream.is()) 116ddde725dSArmin Le Grand { 117ddde725dSArmin Le Grand // local document handler 118ddde725dSArmin Le Grand SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath); 119ddde725dSArmin Le Grand uno::Reference< xml::sax::XDocumentHandler > xSvgDocHdl(pSvgDocHdl); 120ddde725dSArmin Le Grand 121ddde725dSArmin Le Grand try 122ddde725dSArmin Le Grand { 123ddde725dSArmin Le Grand // prepare ParserInputSrouce 124ddde725dSArmin Le Grand xml::sax::InputSource myInputSource; 125ddde725dSArmin Le Grand myInputSource.aInputStream = xSVGStream; 126ddde725dSArmin Le Grand 127ddde725dSArmin Le Grand // get parser 128ddde725dSArmin Le Grand uno::Reference< xml::sax::XParser > xParser( 129ddde725dSArmin Le Grand comphelper::getProcessServiceFactory()->createInstance( 130ddde725dSArmin Le Grand rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ), 131ddde725dSArmin Le Grand uno::UNO_QUERY_THROW ); 132ddde725dSArmin Le Grand 133ddde725dSArmin Le Grand // connect parser and filter 134ddde725dSArmin Le Grand xParser->setDocumentHandler(xSvgDocHdl); 135ddde725dSArmin Le Grand 136ddde725dSArmin Le Grand // finally, parse the stream to a hierarchy of 137ddde725dSArmin Le Grand // SVGGraphicPrimitive2D which will be embedded to the 138ddde725dSArmin Le Grand // primitive sequence. Their decompositions will in the 139ddde725dSArmin Le Grand // end create local low-level primitives, thus SVG will 140ddde725dSArmin Le Grand // be processable from all our processors 141ddde725dSArmin Le Grand xParser->parseStream(myInputSource); 142ddde725dSArmin Le Grand } 143ddde725dSArmin Le Grand catch(uno::Exception&) 144ddde725dSArmin Le Grand { 145ddde725dSArmin Le Grand OSL_ENSURE(false, "Parse error (!)"); 146ddde725dSArmin Le Grand } 147ddde725dSArmin Le Grand 148ddde725dSArmin Le Grand // decompose to primitives 149ddde725dSArmin Le Grand const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector(); 150ddde725dSArmin Le Grand const sal_uInt32 nCount(rResults.size()); 151ddde725dSArmin Le Grand 152ddde725dSArmin Le Grand for(sal_uInt32 a(0); a < nCount; a++) 153ddde725dSArmin Le Grand { 154*a275c134SArmin Le Grand SvgNode* pCandidate = rResults[a]; 155*a275c134SArmin Le Grand 156*a275c134SArmin Le Grand if(Display_none != pCandidate->getDisplay()) 157*a275c134SArmin Le Grand { 158*a275c134SArmin Le Grand pCandidate->decomposeSvgNode(aRetval, false); 159*a275c134SArmin Le Grand } 160ddde725dSArmin Le Grand } 161ddde725dSArmin Le Grand } 162ddde725dSArmin Le Grand else 163ddde725dSArmin Le Grand { 164ddde725dSArmin Le Grand OSL_ENSURE(false, "Invalid stream (!)"); 165ddde725dSArmin Le Grand } 166ddde725dSArmin Le Grand 167ddde725dSArmin Le Grand return aRetval; 168ddde725dSArmin Le Grand } 169ddde725dSArmin Le Grand getImplementationName()170ddde725dSArmin Le Grand rtl::OUString SAL_CALL XSvgParser::getImplementationName() throw(uno::RuntimeException) 171ddde725dSArmin Le Grand { 172ddde725dSArmin Le Grand return(XSvgParser_getImplementationName()); 173ddde725dSArmin Le Grand } 174ddde725dSArmin Le Grand supportsService(const rtl::OUString & rServiceName)175ddde725dSArmin Le Grand sal_Bool SAL_CALL XSvgParser::supportsService(const rtl::OUString& rServiceName) throw(uno::RuntimeException) 176ddde725dSArmin Le Grand { 177ddde725dSArmin Le Grand const uno::Sequence< rtl::OUString > aServices(XSvgParser_getSupportedServiceNames()); 178ddde725dSArmin Le Grand 179ddde725dSArmin Le Grand for(sal_Int32 nService(0); nService < aServices.getLength(); nService++) 180ddde725dSArmin Le Grand { 181ddde725dSArmin Le Grand if(rServiceName == aServices[nService]) 182ddde725dSArmin Le Grand { 183ddde725dSArmin Le Grand return sal_True; 184ddde725dSArmin Le Grand } 185ddde725dSArmin Le Grand } 186ddde725dSArmin Le Grand 187ddde725dSArmin Le Grand return sal_False; 188ddde725dSArmin Le Grand } 189ddde725dSArmin Le Grand getSupportedServiceNames()190ddde725dSArmin Le Grand uno::Sequence< rtl::OUString > SAL_CALL XSvgParser::getSupportedServiceNames() throw(uno::RuntimeException) 191ddde725dSArmin Le Grand { 192ddde725dSArmin Le Grand return XSvgParser_getSupportedServiceNames(); 193ddde725dSArmin Le Grand } 194ddde725dSArmin Le Grand 195ddde725dSArmin Le Grand } // end of namespace svgreader 196ddde725dSArmin Le Grand } // end of namespace svgio 197ddde725dSArmin Le Grand 198ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 199ddde725dSArmin Le Grand // eof 200