Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / wrapper / basegfxfactory.cxx
blob96020de28a95659cd1d4a64b9385628ee96b5ae4
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 .
21 #include <rtl/instance.hxx>
22 #include <osl/getglobalmutex.hxx>
23 #include <osl/diagnose.h>
25 #include <com/sun/star/rendering/InterpolationMode.hpp>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <basegfx/tools/canvastools.hxx>
31 #include <cppcanvas/basegfxfactory.hxx>
33 #include <com/sun/star/rendering/RenderState.hpp>
34 #include <com/sun/star/rendering/StringContext.hpp>
35 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <com/sun/star/rendering/XCanvasFont.hpp>
38 #include <cppcanvas/text.hxx>
39 #include <canvasgraphichelper.hxx>
41 #include "implpolypolygon.hxx"
42 #include "implbitmap.hxx"
44 using namespace ::com::sun::star;
46 namespace cppcanvas
48 /* Singleton handling */
49 struct InitInstance2
51 BaseGfxFactory* operator()()
53 return new BaseGfxFactory();
57 BaseGfxFactory& BaseGfxFactory::getInstance()
59 return *rtl_Instance< BaseGfxFactory, InitInstance2, ::osl::MutexGuard,
60 ::osl::GetGlobalMutex >::create(
61 InitInstance2(), ::osl::GetGlobalMutex());
64 BaseGfxFactory::BaseGfxFactory()
68 PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& rCanvas,
69 const ::basegfx::B2DPolygon& rPoly ) const
71 OSL_ENSURE( rCanvas.get() != NULL &&
72 rCanvas->getUNOCanvas().is(),
73 "BaseGfxFactory::createPolyPolygon(): Invalid canvas" );
75 if( rCanvas.get() == NULL )
76 return PolyPolygonSharedPtr();
78 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
79 if( !xCanvas.is() )
80 return PolyPolygonSharedPtr();
82 return PolyPolygonSharedPtr(
83 new internal::ImplPolyPolygon( rCanvas,
84 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
85 xCanvas->getDevice(),
86 rPoly) ) );
89 BitmapSharedPtr BaseGfxFactory::createBitmap( const CanvasSharedPtr& rCanvas,
90 const ::basegfx::B2ISize& rSize ) const
92 OSL_ENSURE( rCanvas.get() != NULL &&
93 rCanvas->getUNOCanvas().is(),
94 "BaseGfxFactory::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(
104 new internal::ImplBitmap( rCanvas,
105 xCanvas->getDevice()->createCompatibleBitmap(
106 ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) );
109 BitmapSharedPtr BaseGfxFactory::createAlphaBitmap( const CanvasSharedPtr& rCanvas,
110 const ::basegfx::B2ISize& rSize ) const
112 OSL_ENSURE( rCanvas.get() != NULL &&
113 rCanvas->getUNOCanvas().is(),
114 "BaseGfxFactory::createBitmap(): Invalid canvas" );
116 if( rCanvas.get() == NULL )
117 return BitmapSharedPtr();
119 uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
120 if( !xCanvas.is() )
121 return BitmapSharedPtr();
123 return BitmapSharedPtr(
124 new internal::ImplBitmap( rCanvas,
125 xCanvas->getDevice()->createCompatibleAlphaBitmap(
126 ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) );
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */