LCOV - code coverage report
Current view: top level - libreoffice/svgio/source/svguno - xsvgparser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 40 0.0 %
Date: 2012-12-27 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10