LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svgio/source/svguno - xsvgparser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 46 76.1 %
Date: 2013-07-09 Functions: 7 10 70.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 <com/sun/star/lang/XInitialization.hpp>
      25             : #include <cppuhelper/implbase2.hxx>
      26             : #include <svgio/svgreader/svgdocumenthandler.hxx>
      27             : #include <com/sun/star/xml/sax/XParser.hpp>
      28             : #include <com/sun/star/xml/sax/Parser.hpp>
      29             : #include <com/sun/star/xml/sax/InputSource.hpp>
      30             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      31             : 
      32             : #include "xsvgparser.hxx"
      33             : 
      34             : //////////////////////////////////////////////////////////////////////////////
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : //////////////////////////////////////////////////////////////////////////////
      39             : 
      40             : namespace svgio
      41             : {
      42             :     namespace svgreader
      43             :     {
      44             :         class XSvgParser : public ::cppu::WeakAggImplHelper2< graphic::XSvgParser, lang::XServiceInfo >
      45             :         {
      46             :         private:
      47             :             XSvgParser(const XSvgParser&);
      48             :             XSvgParser& operator=(const XSvgParser&);
      49             : 
      50             :             uno::Reference< uno::XComponentContext > context_;
      51             : 
      52             :         protected:
      53             :         public:
      54             :             XSvgParser(
      55             :                 uno::Reference< uno::XComponentContext > const & context);
      56             :             virtual ~XSvgParser();
      57             : 
      58             :             // XSvgParser
      59             :             virtual uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > SAL_CALL getDecomposition(
      60             :                 const uno::Reference< ::io::XInputStream >& xSVGStream,
      61             :                 const OUString& aAbsolutePath) throw (uno::RuntimeException);
      62             : 
      63             :             // XServiceInfo
      64             :             virtual OUString SAL_CALL getImplementationName() throw(uno::RuntimeException);
      65             :             virtual ::sal_Bool SAL_CALL supportsService(const OUString&) throw(uno::RuntimeException);
      66             :             virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException);
      67             :         };
      68             :     } // end of namespace svgreader
      69             : } // end of namespace svgio
      70             : 
      71             : //////////////////////////////////////////////////////////////////////////////
      72             : // uno functions
      73             : 
      74             : namespace svgio
      75             : {
      76             :     namespace svgreader
      77             :     {
      78           4 :         uno::Sequence< OUString > XSvgParser_getSupportedServiceNames()
      79             :         {
      80           4 :             static OUString aServiceName("com.sun.star.graphic.SvgTools" );
      81           4 :             static uno::Sequence< OUString > aServiceNames( &aServiceName, 1 );
      82             : 
      83           4 :             return( aServiceNames );
      84             :         }
      85             : 
      86           4 :         OUString XSvgParser_getImplementationName()
      87             :         {
      88           4 :             return OUString( "svgio::svgreader::XSvgParser" );
      89             :         }
      90             : 
      91         292 :         uno::Reference< uno::XInterface > SAL_CALL XSvgParser_createInstance(const uno::Reference< uno::XComponentContext >& context)
      92             :         {
      93         292 :             return static_cast< ::cppu::OWeakObject* >(new XSvgParser(context));
      94             :         }
      95             :     } // end of namespace svgreader
      96             : } // end of namespace svgio
      97             : 
      98             : //////////////////////////////////////////////////////////////////////////////
      99             : 
     100             : namespace svgio
     101             : {
     102             :     namespace svgreader
     103             :     {
     104         292 :         XSvgParser::XSvgParser(
     105             :             uno::Reference< uno::XComponentContext > const & context):
     106         292 :             context_(context)
     107             :         {
     108         292 :         }
     109             : 
     110         584 :         XSvgParser::~XSvgParser()
     111             :         {
     112         584 :         }
     113             : 
     114         292 :         uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > XSvgParser::getDecomposition(
     115             :             const uno::Reference< ::io::XInputStream >& xSVGStream,
     116             :             const OUString& aAbsolutePath ) throw (uno::RuntimeException)
     117             :         {
     118         292 :             drawinglayer::primitive2d::Primitive2DSequence aRetval;
     119             : 
     120         292 :             if(xSVGStream.is())
     121             :             {
     122             :                 // local document handler
     123         292 :                 SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath);
     124         292 :                 uno::Reference< xml::sax::XDocumentHandler > xSvgDocHdl(pSvgDocHdl);
     125             : 
     126             :                 try
     127             :                 {
     128             :                     // prepare ParserInputSrouce
     129         292 :                     xml::sax::InputSource myInputSource;
     130         292 :                     myInputSource.aInputStream = xSVGStream;
     131             : 
     132             :                     // get parser
     133             :                     uno::Reference< xml::sax::XParser > xParser(
     134         584 :                         xml::sax::Parser::create(context_));
     135             :                     // fdo#60471 need to enable internal entities because
     136             :                     // certain ... popular proprietary products write SVG files
     137             :                     // that use entities to define XML namespaces.
     138             :                     uno::Reference<lang::XInitialization> const xInit(xParser,
     139         584 :                             uno::UNO_QUERY_THROW);
     140         584 :                     uno::Sequence<uno::Any> args(1);
     141         292 :                     args[0] <<= OUString("DoSmeplease");
     142         292 :                     xInit->initialize(args);
     143             : 
     144             :                     // connect parser and filter
     145         292 :                     xParser->setDocumentHandler(xSvgDocHdl);
     146             : 
     147             :                     // finally, parse the stream to a hierarchy of
     148             :                     // SVGGraphicPrimitive2D which will be embedded to the
     149             :                     // primitive sequence. Their decompositions will in the
     150             :                     // end create local low-level primitives, thus SVG will
     151             :                     // be processable from all our processors
     152         584 :                     xParser->parseStream(myInputSource);
     153             :                 }
     154           0 :                 catch(const uno::Exception& e)
     155             :                 {
     156             :                     SAL_WARN( "svg", "Parse error! : " << e.Message);
     157             :                 }
     158             : 
     159             :                 // decompose to primitives
     160         292 :                 const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector();
     161         292 :                 const sal_uInt32 nCount(rResults.size());
     162             : 
     163         584 :                 for(sal_uInt32 a(0); a < nCount; a++)
     164             :                 {
     165         292 :                     SvgNode* pCandidate = rResults[a];
     166             : 
     167         292 :                     if(Display_none != pCandidate->getDisplay())
     168             :                     {
     169         292 :                         pCandidate->decomposeSvgNode(aRetval, false);
     170             :                     }
     171         292 :                 }
     172             :             }
     173             :             else
     174             :             {
     175             :                 OSL_ENSURE(false, "Invalid stream (!)");
     176             :             }
     177             : 
     178         292 :             return aRetval;
     179             :         }
     180             : 
     181           0 :         OUString SAL_CALL XSvgParser::getImplementationName() throw(uno::RuntimeException)
     182             :         {
     183           0 :             return(XSvgParser_getImplementationName());
     184             :         }
     185             : 
     186           0 :         sal_Bool SAL_CALL XSvgParser::supportsService(const OUString& rServiceName) throw(uno::RuntimeException)
     187             :         {
     188           0 :             const uno::Sequence< OUString > aServices(XSvgParser_getSupportedServiceNames());
     189             : 
     190           0 :             for(sal_Int32 nService(0); nService < aServices.getLength(); nService++)
     191             :             {
     192           0 :                 if(rServiceName == aServices[nService])
     193             :                 {
     194           0 :                     return sal_True;
     195             :                 }
     196             :             }
     197             : 
     198           0 :             return sal_False;
     199             :         }
     200             : 
     201           0 :         uno::Sequence< OUString > SAL_CALL XSvgParser::getSupportedServiceNames() throw(uno::RuntimeException)
     202             :         {
     203           0 :             return XSvgParser_getSupportedServiceNames();
     204             :         }
     205             : 
     206             :     } // end of namespace svgreader
     207             : } // end of namespace svgio
     208             : 
     209             : //////////////////////////////////////////////////////////////////////////////
     210             : // eof
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10