1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppcanvas.hxx"
26 
27 #include <rtl/instance.hxx>
28 #include <osl/getglobalmutex.hxx>
29 #include <osl/diagnose.h>
30 
31 #include <com/sun/star/rendering/InterpolationMode.hpp>
32 
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/polygon/b2dpolypolygon.hxx>
35 #include <basegfx/tools/canvastools.hxx>
36 
37 #include <cppcanvas/basegfxfactory.hxx>
38 
39 #include "implpolypolygon.hxx"
40 #include "implbitmap.hxx"
41 #include "impltext.hxx"
42 
43 
44 using namespace ::com::sun::star;
45 
46 namespace cppcanvas
47 {
48 	/* Singleton handling */
49     struct InitInstance2
50     {
operator ()cppcanvas::InitInstance251         BaseGfxFactory* operator()()
52         {
53             return new BaseGfxFactory();
54         }
55     };
56 
getInstance()57     BaseGfxFactory& BaseGfxFactory::getInstance()
58     {
59         return *rtl_Instance< BaseGfxFactory, InitInstance2, ::osl::MutexGuard,
60             ::osl::GetGlobalMutex >::create(
61                 InitInstance2(), ::osl::GetGlobalMutex());
62     }
63 
BaseGfxFactory()64     BaseGfxFactory::BaseGfxFactory()
65     {
66     }
67 
~BaseGfxFactory()68     BaseGfxFactory::~BaseGfxFactory()
69     {
70     }
71 
createPolyPolygon(const CanvasSharedPtr & rCanvas,const::basegfx::B2DPolygon & rPoly) const72     PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& 			rCanvas,
73                                                             const ::basegfx::B2DPolygon& 	rPoly ) const
74     {
75         OSL_ENSURE( rCanvas.get() != NULL &&
76                     rCanvas->getUNOCanvas().is(),
77                     "BaseGfxFactory::createPolyPolygon(): Invalid canvas" );
78 
79         if( rCanvas.get() == NULL )
80             return PolyPolygonSharedPtr();
81 
82         uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
83         if( !xCanvas.is() )
84             return PolyPolygonSharedPtr();
85 
86         return PolyPolygonSharedPtr(
87             new internal::ImplPolyPolygon( rCanvas,
88                                            ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
89                                                xCanvas->getDevice(),
90                                                rPoly) ) );
91     }
92 
createPolyPolygon(const CanvasSharedPtr & rCanvas,const::basegfx::B2DPolyPolygon & rPolyPoly) const93     PolyPolygonSharedPtr BaseGfxFactory::createPolyPolygon( const CanvasSharedPtr& 				rCanvas,
94                                                             const ::basegfx::B2DPolyPolygon& 	rPolyPoly ) const
95     {
96         OSL_ENSURE( rCanvas.get() != NULL &&
97                     rCanvas->getUNOCanvas().is(),
98                     "BaseGfxFactory::createPolyPolygon(): Invalid canvas" );
99 
100         if( rCanvas.get() == NULL )
101             return PolyPolygonSharedPtr();
102 
103         uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
104         if( !xCanvas.is() )
105             return PolyPolygonSharedPtr();
106 
107         return PolyPolygonSharedPtr(
108             new internal::ImplPolyPolygon( rCanvas,
109                                            ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
110                                                xCanvas->getDevice(),
111                                                rPolyPoly) ) );
112     }
113 
createBitmap(const CanvasSharedPtr & rCanvas,const::basegfx::B2ISize & rSize) const114     BitmapSharedPtr BaseGfxFactory::createBitmap( const CanvasSharedPtr&	rCanvas,
115                                                   const ::basegfx::B2ISize& rSize ) const
116     {
117         OSL_ENSURE( rCanvas.get() != NULL &&
118                     rCanvas->getUNOCanvas().is(),
119                     "BaseGfxFactory::createBitmap(): Invalid canvas" );
120 
121         if( rCanvas.get() == NULL )
122             return BitmapSharedPtr();
123 
124         uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
125         if( !xCanvas.is() )
126             return BitmapSharedPtr();
127 
128         return BitmapSharedPtr(
129             new internal::ImplBitmap( rCanvas,
130                                       xCanvas->getDevice()->createCompatibleBitmap(
131                                           ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) );
132     }
133 
createAlphaBitmap(const CanvasSharedPtr & rCanvas,const::basegfx::B2ISize & rSize) const134     BitmapSharedPtr BaseGfxFactory::createAlphaBitmap( const CanvasSharedPtr&	rCanvas,
135                                                        const ::basegfx::B2ISize& rSize ) const
136     {
137         OSL_ENSURE( rCanvas.get() != NULL &&
138                     rCanvas->getUNOCanvas().is(),
139                     "BaseGfxFactory::createBitmap(): Invalid canvas" );
140 
141         if( rCanvas.get() == NULL )
142             return BitmapSharedPtr();
143 
144         uno::Reference< rendering::XCanvas > xCanvas( rCanvas->getUNOCanvas() );
145         if( !xCanvas.is() )
146             return BitmapSharedPtr();
147 
148         return BitmapSharedPtr(
149             new internal::ImplBitmap( rCanvas,
150                                       xCanvas->getDevice()->createCompatibleAlphaBitmap(
151                                           ::basegfx::unotools::integerSize2DFromB2ISize(rSize) ) ) );
152     }
153 
createText(const CanvasSharedPtr & rCanvas,const::rtl::OUString & rText) const154     TextSharedPtr BaseGfxFactory::createText( const CanvasSharedPtr& rCanvas, const ::rtl::OUString& rText ) const
155     {
156         return TextSharedPtr( new internal::ImplText( rCanvas,
157                                                       rText ) );
158     }
159 
160 }
161