diff options
Diffstat (limited to 'emfio/source')
-rw-r--r-- | emfio/source/emfuno/emfuno.cxx | 46 | ||||
-rw-r--r-- | emfio/source/emfuno/xemfparser.cxx | 210 | ||||
-rw-r--r-- | emfio/source/emfuno/xemfparser.hxx | 50 |
3 files changed, 306 insertions, 0 deletions
diff --git a/emfio/source/emfuno/emfuno.cxx b/emfio/source/emfuno/emfuno.cxx new file mode 100644 index 000000000000..b027c5fe3cc2 --- /dev/null +++ b/emfio/source/emfuno/emfuno.cxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implementationentry.hxx> +#include <sal/types.h> + +#include "xemfparser.hxx" + +namespace { + +static cppu::ImplementationEntry const services[] = { + { &emfio::emfreader::XEmfParser_createInstance, + &emfio::emfreader::XEmfParser_getImplementationName, + &emfio::emfreader::XEmfParser_getSupportedServiceNames, + &cppu::createSingleComponentFactory, nullptr, 0 }, + { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } }; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL emfio_component_getFactory( + char const * pImplName, void * pServiceManager, void * pRegistryKey) +{ + return cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, services); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/emfio/source/emfuno/xemfparser.cxx b/emfio/source/emfuno/xemfparser.cxx new file mode 100644 index 000000000000..ce18d4be3a3a --- /dev/null +++ b/emfio/source/emfuno/xemfparser.cxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <com/sun/star/graphic/XEmfParser.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/sequence.hxx> +#include <drawinglayer/primitive2d/baseprimitive2d.hxx> +#include <basegfx/color/bcolor.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> + +//#include <com/sun/star/xml/sax/XParser.hpp> +//#include <com/sun/star/xml/sax/Parser.hpp> +//#include <com/sun/star/xml/sax/InputSource.hpp> +//#include <drawinglayer/geometry/viewinformation2d.hxx> +//#include <svgdocumenthandler.hxx> + +#include "xemfparser.hxx" + +using namespace ::com::sun::star; + +namespace emfio +{ + namespace emfreader + { + class XEmfParser : public ::cppu::WeakAggImplHelper2< graphic::XEmfParser, lang::XServiceInfo > + { + private: + uno::Reference< uno::XComponentContext > context_; + + protected: + public: + explicit XEmfParser( + uno::Reference< uno::XComponentContext > const & context); + XEmfParser(const XEmfParser&) = delete; + XEmfParser& operator=(const XEmfParser&) = delete; + + // XEmfParser + virtual uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > SAL_CALL getDecomposition( + const uno::Reference< ::io::XInputStream >& xEmfStream, + const OUString& aAbsolutePath) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString&) override; + virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + }; + } // end of namespace emfreader +} // end of namespace emfio + +// uno functions +namespace emfio +{ + namespace emfreader + { + uno::Sequence< OUString > XEmfParser_getSupportedServiceNames() + { + return uno::Sequence< OUString > { "com.sun.star.graphic.EmfTools" }; + } + + OUString XEmfParser_getImplementationName() + { + return OUString( "emfio::emfreader::XEmfParser" ); + } + + uno::Reference< uno::XInterface > SAL_CALL XEmfParser_createInstance(const uno::Reference< uno::XComponentContext >& context) + { + return static_cast< ::cppu::OWeakObject* >(new XEmfParser(context)); + } + } // end of namespace emfreader +} // end of namespace emfio + +namespace emfio +{ + namespace emfreader + { + XEmfParser::XEmfParser( + uno::Reference< uno::XComponentContext > const & context): + context_(context) + { + } + + uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > XEmfParser::getDecomposition( + const uno::Reference< ::io::XInputStream >& xEmfStream, + const OUString& aAbsolutePath ) + { + drawinglayer::primitive2d::Primitive2DContainer aRetval; + + if (xEmfStream.is()) + { + static bool bTestCode(true); + + if (bTestCode) + { + // for test, just create some graphic data + const basegfx::B2DRange aRange(1000, 1000, 5000, 5000); + const basegfx::BColor aColor(1.0, 0.0, 0.0); + const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange)); + + aRetval.push_back(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline), aColor)); + } + else + { + // new parser here + bool bBla = true; + + + + + // // local document handler + // SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath); + // uno::Reference< xml::sax::XDocumentHandler > xSvgDocHdl(pSvgDocHdl); + // + // try + // { + // // prepare ParserInputSrouce + // xml::sax::InputSource myInputSource; + // myInputSource.aInputStream = xEmfStream; + // + // // get parser + // uno::Reference< xml::sax::XParser > xParser( + // xml::sax::Parser::create(context_)); + // // fdo#60471 need to enable internal entities because + // // certain ... popular proprietary products write SVG files + // // that use entities to define XML namespaces. + // uno::Reference<lang::XInitialization> const xInit(xParser, + // uno::UNO_QUERY_THROW); + // uno::Sequence<uno::Any> args(1); + // args[0] <<= OUString("DoSmeplease"); + // xInit->initialize(args); + // + // // connect parser and filter + // xParser->setDocumentHandler(xSvgDocHdl); + // + // // finally, parse the stream to a hierarchy of + // // SVGGraphicPrimitive2D which will be embedded to the + // // primitive sequence. Their decompositions will in the + // // end create local low-level primitives, thus SVG will + // // be processable from all our processors + // xParser->parseStream(myInputSource); + // } + // catch(const uno::Exception& e) + // { + // SAL_WARN( "svg", "Parse error! : " << e.Message); + // } + // + // // decompose to primitives + // const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector(); + // const sal_uInt32 nCount(rResults.size()); + // + // for(sal_uInt32 a(0); a < nCount; a++) + // { + // SvgNode* pCandidate = rResults[a]; + // + // if(Display_none != pCandidate->getDisplay()) + // { + // pCandidate->decomposeSvgNode(aRetval, false); + // } + // } + } + } + else + { + OSL_ENSURE(false, "Invalid stream (!)"); + } + + return comphelper::containerToSequence(aRetval); + } + + OUString SAL_CALL XEmfParser::getImplementationName() + { + return(XEmfParser_getImplementationName()); + } + + sal_Bool SAL_CALL XEmfParser::supportsService(const OUString& rServiceName) + { + return cppu::supportsService(this, rServiceName); + } + + uno::Sequence< OUString > SAL_CALL XEmfParser::getSupportedServiceNames() + { + return XEmfParser_getSupportedServiceNames(); + } + + } // end of namespace emfreader +} // end of namespace emfio + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/emfio/source/emfuno/xemfparser.hxx b/emfio/source/emfuno/xemfparser.hxx new file mode 100644 index 000000000000..da78322028dc --- /dev/null +++ b/emfio/source/emfuno/xemfparser.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_EMFIO_SOURCE_EMFUNO_XEMFARSER_HXX +#define INCLUDED_EMFIO_SOURCE_EMFUNO_XEMFARSER_HXX + +#include <sal/config.h> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <sal/types.h> + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + class XInterface; + } +} } } + +namespace emfio { namespace emfreader { + +css::uno::Reference< css::uno::XInterface > SAL_CALL +XEmfParser_createInstance( css::uno::Reference< css::uno::XComponentContext > const &); + +OUString SAL_CALL XEmfParser_getImplementationName(); + +css::uno::Sequence< OUString > SAL_CALL +XEmfParser_getSupportedServiceNames(); + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |