Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / wrapper / vclfactory.cxx
blobd27afa18099d1015e66f7b98c76def37ca5234dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/instance.hxx>
21 #include <osl/getglobalmutex.hxx>
22 #include <osl/diagnose.h>
23 #include <com/sun/star/rendering/InterpolationMode.hpp>
24 #include <vcl/window.hxx>
25 #include <vcl/graph.hxx>
26 #include <vcl/canvastools.hxx>
27 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <cppcanvas/vclfactory.hxx>
31 #include <implbitmapcanvas.hxx>
32 #include <implspritecanvas.hxx>
33 #include <implpolypolygon.hxx>
34 #include <implbitmap.hxx>
35 #include <implrenderer.hxx>
36 #include <implsprite.hxx>
38 using namespace ::com::sun::star;
40 namespace cppcanvas
42 /* Singleton handling */
43 struct InitInstance
45 VCLFactory* operator()()
47 return new VCLFactory();
51 VCLFactory& VCLFactory::getInstance()
53 return *rtl_Instance< VCLFactory, InitInstance, ::osl::MutexGuard,
54 ::osl::GetGlobalMutex >::create(
55 InitInstance(), ::osl::GetGlobalMutex());
58 VCLFactory::VCLFactory()
62 CanvasSharedPtr VCLFactory::createCanvas( const uno::Reference< rendering::XCanvas >& xCanvas )
64 return CanvasSharedPtr(
65 new internal::ImplCanvas( xCanvas ) );
68 BitmapCanvasSharedPtr VCLFactory::createBitmapCanvas( const uno::Reference< rendering::XBitmapCanvas >& xCanvas )
70 return BitmapCanvasSharedPtr(
71 new internal::ImplBitmapCanvas( xCanvas ) );
74 SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const ::Window& rVCLWindow ) const
76 return SpriteCanvasSharedPtr(
77 new internal::ImplSpriteCanvas(
78 uno::Reference< rendering::XSpriteCanvas >(
79 rVCLWindow.GetSpriteCanvas(),
80 uno::UNO_QUERY) ) );
83 SpriteCanvasSharedPtr VCLFactory::createSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& xCanvas ) const
85 return SpriteCanvasSharedPtr(
86 new internal::ImplSpriteCanvas( xCanvas ) );
89 BitmapSharedPtr VCLFactory::createBitmap( const CanvasSharedPtr& rCanvas,
90 const ::BitmapEx& rBmpEx ) const
92 OSL_ENSURE( rCanvas.get() != NULL &&
93 rCanvas->getUNOCanvas().is(),
94 "VCLFactory::createBitmap(): Invalid canvas" );
96 if( rCanvas.get() == NULL )
97 return BitmapSharedPtr();
99 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
100 if( !xCanvas.is() )
101 return BitmapSharedPtr();
103 return BitmapSharedPtr( new internal::ImplBitmap( rCanvas,
104 ::vcl::unotools::xBitmapFromBitmapEx(
105 xCanvas->getDevice(),
106 rBmpEx) ) );
109 RendererSharedPtr VCLFactory::createRenderer( const CanvasSharedPtr& rCanvas,
110 const ::GDIMetaFile& rMtf,
111 const Renderer::Parameters& rParms ) const
113 return RendererSharedPtr( new internal::ImplRenderer( rCanvas,
114 rMtf,
115 rParms ) );
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */