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_canvas.hxx"
26 
27 #include <canvas/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 
30 #include <rtl/logfile.hxx>
31 #include <rtl/math.hxx>
32 
33 #include <com/sun/star/util/Endianness.hpp>
34 #include <com/sun/star/rendering/TexturingMode.hpp>
35 #include <com/sun/star/rendering/CompositeOperation.hpp>
36 #include <com/sun/star/rendering/RepaintResult.hpp>
37 #include <com/sun/star/rendering/PathCapType.hpp>
38 #include <com/sun/star/rendering/PathJoinType.hpp>
39 
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
42 #include <basegfx/tools/canvastools.hxx>
43 
44 #include <comphelper/sequence.hxx>
45 #include <canvas/canvastools.hxx>
46 
47 #include "null_spritecanvas.hxx"
48 #include "null_canvasfont.hxx"
49 #include "null_textlayout.hxx"
50 #include "null_canvashelper.hxx"
51 
52 #include <algorithm>
53 
54 
55 using namespace ::com::sun::star;
56 
57 namespace nullcanvas
58 {
CanvasHelper()59     CanvasHelper::CanvasHelper() :
60         mpDevice( NULL ),
61         maSize(),
62         mbHaveAlpha()
63     {
64     }
65 
disposing()66     void CanvasHelper::disposing()
67     {
68         mpDevice = NULL;
69     }
70 
init(const::basegfx::B2ISize & rSize,SpriteCanvas & rDevice,bool bHasAlpha)71     void CanvasHelper::init( const ::basegfx::B2ISize& rSize,
72                              SpriteCanvas&             rDevice,
73                              bool                      bHasAlpha )
74     {
75         mpDevice = &rDevice;
76         maSize = rSize;
77         mbHaveAlpha = bHasAlpha;
78     }
79 
clear()80     void CanvasHelper::clear()
81     {
82     }
83 
drawPoint(const rendering::XCanvas *,const geometry::RealPoint2D &,const rendering::ViewState &,const rendering::RenderState &)84     void CanvasHelper::drawPoint( const rendering::XCanvas* 	/*pCanvas*/,
85                                   const geometry::RealPoint2D& 	/*aPoint*/,
86                                   const rendering::ViewState& 	/*viewState*/,
87                                   const rendering::RenderState&	/*renderState*/ )
88     {
89     }
90 
drawLine(const rendering::XCanvas *,const geometry::RealPoint2D &,const geometry::RealPoint2D &,const rendering::ViewState &,const rendering::RenderState &)91     void CanvasHelper::drawLine( const rendering::XCanvas* 	    /*pCanvas*/,
92                                  const geometry::RealPoint2D& 	/*aPoint1*/,
93                                  const geometry::RealPoint2D& 	/*aPoint2*/,
94                                  const rendering::ViewState& 	/*viewState*/,
95                                  const rendering::RenderState&	/*renderState*/ )
96     {
97     }
98 
drawBezier(const rendering::XCanvas *,const geometry::RealBezierSegment2D &,const geometry::RealPoint2D &,const rendering::ViewState &,const rendering::RenderState &)99     void CanvasHelper::drawBezier( const rendering::XCanvas* 			/*pCanvas*/,
100                                    const geometry::RealBezierSegment2D&	/*aBezierSegment*/,
101                                    const geometry::RealPoint2D& 		/*aEndPoint*/,
102                                    const rendering::ViewState& 			/*viewState*/,
103                                    const rendering::RenderState& 		/*renderState*/ )
104     {
105     }
106 
drawPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &)107     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
108                                                                                  const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
109                                                                                  const rendering::ViewState& 						/*viewState*/,
110                                                                                  const rendering::RenderState& 						/*renderState*/ )
111     {
112         // TODO(P1): Provide caching here.
113         return uno::Reference< rendering::XCachedPrimitive >(NULL);
114     }
115 
strokePolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const rendering::StrokeAttributes &)116     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokePolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
117                                                                                    const uno::Reference< rendering::XPolyPolygon2D >& 	/*xPolyPolygon*/,
118                                                                                    const rendering::ViewState& 							/*viewState*/,
119                                                                                    const rendering::RenderState& 						/*renderState*/,
120                                                                                    const rendering::StrokeAttributes& 					/*strokeAttributes*/ )
121     {
122         // TODO(P1): Provide caching here.
123         return uno::Reference< rendering::XCachedPrimitive >(NULL);
124     }
125 
strokeTexturedPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const uno::Sequence<rendering::Texture> &,const rendering::StrokeAttributes &)126     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokeTexturedPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
127                                                                                            const uno::Reference< rendering::XPolyPolygon2D >& 	/*xPolyPolygon*/,
128                                                                                            const rendering::ViewState& 							/*viewState*/,
129                                                                                            const rendering::RenderState& 						/*renderState*/,
130                                                                                            const uno::Sequence< rendering::Texture >& 			/*textures*/,
131                                                                                            const rendering::StrokeAttributes& 					/*strokeAttributes*/ )
132     {
133         // TODO
134         return uno::Reference< rendering::XCachedPrimitive >(NULL);
135     }
136 
strokeTextureMappedPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const uno::Sequence<rendering::Texture> &,const uno::Reference<geometry::XMapping2D> &,const rendering::StrokeAttributes &)137     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokeTextureMappedPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
138                                                                                                 const uno::Reference< rendering::XPolyPolygon2D >&	/*xPolyPolygon*/,
139                                                                                                 const rendering::ViewState& 						/*viewState*/,
140                                                                                                 const rendering::RenderState& 						/*renderState*/,
141                                                                                                 const uno::Sequence< rendering::Texture >& 			/*textures*/,
142                                                                                                 const uno::Reference< geometry::XMapping2D >& 		/*xMapping*/,
143                                                                                                 const rendering::StrokeAttributes& 					/*strokeAttributes*/ )
144     {
145         // TODO
146         return uno::Reference< rendering::XCachedPrimitive >(NULL);
147     }
148 
queryStrokeShapes(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const rendering::StrokeAttributes &)149     uno::Reference< rendering::XPolyPolygon2D >   CanvasHelper::queryStrokeShapes( const rendering::XCanvas* 							/*pCanvas*/,
150                                                                                    const uno::Reference< rendering::XPolyPolygon2D >& 	/*xPolyPolygon*/,
151                                                                                    const rendering::ViewState& 							/*viewState*/,
152                                                                                    const rendering::RenderState& 						/*renderState*/,
153                                                                                    const rendering::StrokeAttributes& 					/*strokeAttributes*/ )
154     {
155         // TODO
156         return uno::Reference< rendering::XPolyPolygon2D >(NULL);
157     }
158 
fillPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &)159     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
160                                                                                  const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
161                                                                                  const rendering::ViewState& 						/*viewState*/,
162                                                                                  const rendering::RenderState& 						/*renderState*/ )
163     {
164         // TODO(P1): Provide caching here.
165         return uno::Reference< rendering::XCachedPrimitive >(NULL);
166     }
167 
fillTexturedPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const uno::Sequence<rendering::Texture> &)168     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTexturedPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
169                                                                                          const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
170                                                                                          const rendering::ViewState& 						/*viewState*/,
171                                                                                          const rendering::RenderState& 						/*renderState*/,
172                                                                                          const uno::Sequence< rendering::Texture >& 		/*textures*/ )
173     {
174         // TODO(P1): Provide caching here.
175         return uno::Reference< rendering::XCachedPrimitive >(NULL);
176     }
177 
fillTextureMappedPolyPolygon(const rendering::XCanvas *,const uno::Reference<rendering::XPolyPolygon2D> &,const rendering::ViewState &,const rendering::RenderState &,const uno::Sequence<rendering::Texture> &,const uno::Reference<geometry::XMapping2D> &)178     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTextureMappedPolyPolygon( const rendering::XCanvas* 							/*pCanvas*/,
179                                                                                               const uno::Reference< rendering::XPolyPolygon2D >& 	/*xPolyPolygon*/,
180                                                                                               const rendering::ViewState& 							/*viewState*/,
181                                                                                               const rendering::RenderState& 						/*renderState*/,
182                                                                                               const uno::Sequence< rendering::Texture >& 			/*textures*/,
183                                                                                               const uno::Reference< geometry::XMapping2D >& 		/*xMapping*/ )
184     {
185         // TODO
186         return uno::Reference< rendering::XCachedPrimitive >(NULL);
187     }
188 
createFont(const rendering::XCanvas *,const rendering::FontRequest & fontRequest,const uno::Sequence<beans::PropertyValue> & extraFontProperties,const geometry::Matrix2D & fontMatrix)189     uno::Reference< rendering::XCanvasFont > CanvasHelper::createFont( const rendering::XCanvas* 					/*pCanvas*/,
190                                                                        const rendering::FontRequest& 				fontRequest,
191                                                                        const uno::Sequence< beans::PropertyValue >& extraFontProperties,
192                                                                        const geometry::Matrix2D& 					fontMatrix )
193     {
194         return uno::Reference< rendering::XCanvasFont >(
195             new CanvasFont(fontRequest, extraFontProperties, fontMatrix ) );
196     }
197 
queryAvailableFonts(const rendering::XCanvas *,const rendering::FontInfo &,const uno::Sequence<beans::PropertyValue> &)198     uno::Sequence< rendering::FontInfo > CanvasHelper::queryAvailableFonts( const rendering::XCanvas* 						/*pCanvas*/,
199                                                                             const rendering::FontInfo& 						/*aFilter*/,
200                                                                             const uno::Sequence< beans::PropertyValue >& 	/*aFontProperties*/ )
201     {
202         // TODO
203         return uno::Sequence< rendering::FontInfo >();
204     }
205 
drawText(const rendering::XCanvas *,const rendering::StringContext &,const uno::Reference<rendering::XCanvasFont> &,const rendering::ViewState &,const rendering::RenderState &,sal_Int8)206     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawText( const rendering::XCanvas* 						/*pCanvas*/,
207                                                                           const rendering::StringContext& 					/*text*/,
208                                                                           const uno::Reference< rendering::XCanvasFont >& 	/*xFont*/,
209                                                                           const rendering::ViewState& 						/*viewState*/,
210                                                                           const rendering::RenderState& 					/*renderState*/,
211                                                                           sal_Int8				 							/*textDirection*/ )
212     {
213         return uno::Reference< rendering::XCachedPrimitive >(NULL);
214     }
215 
drawTextLayout(const rendering::XCanvas *,const uno::Reference<rendering::XTextLayout> & xLayoutetText,const rendering::ViewState & viewState,const rendering::RenderState & renderState)216     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawTextLayout( const rendering::XCanvas* 						/*pCanvas*/,
217                                                                                 const uno::Reference< rendering::XTextLayout >& xLayoutetText,
218                                                                                 const rendering::ViewState& 					viewState,
219                                                                                 const rendering::RenderState& 					renderState )
220     {
221         ENSURE_OR_THROW( xLayoutetText.is(),
222                           "CanvasHelper::drawTextLayout: layout is NULL");
223 
224         TextLayout* pTextLayout =
225             dynamic_cast< TextLayout* >( xLayoutetText.get() );
226 
227         ENSURE_OR_THROW( pTextLayout,
228                           "CanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
229 
230         pTextLayout->draw( viewState,
231                            renderState,
232                            mpDevice );
233 
234         return uno::Reference< rendering::XCachedPrimitive >(NULL);
235     }
236 
drawBitmap(const rendering::XCanvas *,const uno::Reference<rendering::XBitmap> &,const rendering::ViewState &,const rendering::RenderState &)237     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawBitmap( const rendering::XCanvas* 					/*pCanvas*/,
238                                                                             const uno::Reference< rendering::XBitmap >& /*xBitmap*/,
239                                                                             const rendering::ViewState& 				/*viewState*/,
240                                                                             const rendering::RenderState& 				/*renderState*/ )
241     {
242         // TODO(P1): Provide caching here.
243         return uno::Reference< rendering::XCachedPrimitive >(NULL);
244     }
245 
drawBitmapModulated(const rendering::XCanvas *,const uno::Reference<rendering::XBitmap> &,const rendering::ViewState &,const rendering::RenderState &)246     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawBitmapModulated( const rendering::XCanvas* 						/*pCanvas*/,
247                                                                                      const uno::Reference< rendering::XBitmap >& 	/*xBitmap*/,
248                                                                                      const rendering::ViewState& 					/*viewState*/,
249                                                                                      const rendering::RenderState& 					/*renderState*/ )
250     {
251         // TODO(P1): Provide caching here.
252         return uno::Reference< rendering::XCachedPrimitive >(NULL);
253     }
254 
getDevice()255     uno::Reference< rendering::XGraphicDevice > CanvasHelper::getDevice()
256     {
257         return uno::Reference< rendering::XGraphicDevice >(mpDevice);
258     }
259 
copyRect(const rendering::XCanvas *,const uno::Reference<rendering::XBitmapCanvas> &,const geometry::RealRectangle2D &,const rendering::ViewState &,const rendering::RenderState &,const geometry::RealRectangle2D &,const rendering::ViewState &,const rendering::RenderState &)260     void CanvasHelper::copyRect( const rendering::XCanvas* 							/*pCanvas*/,
261                                  const uno::Reference< rendering::XBitmapCanvas >&	/*sourceCanvas*/,
262                                  const geometry::RealRectangle2D& 					/*sourceRect*/,
263                                  const rendering::ViewState& 						/*sourceViewState*/,
264                                  const rendering::RenderState& 						/*sourceRenderState*/,
265                                  const geometry::RealRectangle2D& 					/*destRect*/,
266                                  const rendering::ViewState& 						/*destViewState*/,
267                                  const rendering::RenderState& 						/*destRenderState*/ )
268     {
269         // TODO(F2): copyRect NYI
270     }
271 
getSize()272     geometry::IntegerSize2D CanvasHelper::getSize()
273     {
274         if( !mpDevice )
275             geometry::IntegerSize2D(1, 1); // we're disposed
276 
277         return ::basegfx::unotools::integerSize2DFromB2ISize( maSize );
278     }
279 
getScaledBitmap(const geometry::RealSize2D &,sal_Bool)280     uno::Reference< rendering::XBitmap > CanvasHelper::getScaledBitmap( const geometry::RealSize2D&	/*newSize*/,
281                                                                         sal_Bool 					/*beFast*/ )
282     {
283         // TODO(F1):
284         return uno::Reference< rendering::XBitmap >();
285     }
286 
getData(rendering::IntegerBitmapLayout &,const geometry::IntegerRectangle2D &)287     uno::Sequence< sal_Int8 > CanvasHelper::getData( rendering::IntegerBitmapLayout&     /*bitmapLayout*/,
288                                                      const geometry::IntegerRectangle2D& /*rect*/ )
289     {
290         // TODO
291         return uno::Sequence< sal_Int8 >();
292     }
293 
setData(const uno::Sequence<sal_Int8> &,const rendering::IntegerBitmapLayout &,const geometry::IntegerRectangle2D &)294     void CanvasHelper::setData( const uno::Sequence< sal_Int8 >& 		/*data*/,
295                                 const rendering::IntegerBitmapLayout&   /*bitmapLayout*/,
296                                 const geometry::IntegerRectangle2D& 	/*rect*/ )
297     {
298     }
299 
setPixel(const uno::Sequence<sal_Int8> &,const rendering::IntegerBitmapLayout &,const geometry::IntegerPoint2D &)300     void CanvasHelper::setPixel( const uno::Sequence< sal_Int8 >&       /*color*/,
301                                  const rendering::IntegerBitmapLayout&  /*bitmapLayout*/,
302                                  const geometry::IntegerPoint2D&        /*pos*/ )
303     {
304     }
305 
getPixel(rendering::IntegerBitmapLayout &,const geometry::IntegerPoint2D &)306     uno::Sequence< sal_Int8 > CanvasHelper::getPixel( rendering::IntegerBitmapLayout&   /*bitmapLayout*/,
307                                                       const geometry::IntegerPoint2D&   /*pos*/ )
308     {
309         return uno::Sequence< sal_Int8 >();
310     }
311 
getPalette()312     uno::Reference< rendering::XBitmapPalette > CanvasHelper::getPalette()
313     {
314         // TODO(F1): Palette bitmaps NYI
315         return uno::Reference< rendering::XBitmapPalette >();
316     }
317 
getMemoryLayout()318     rendering::IntegerBitmapLayout CanvasHelper::getMemoryLayout()
319     {
320         return ::canvas::tools::getStdMemoryLayout(getSize());
321     }
322 
flush() const323     void CanvasHelper::flush() const
324     {
325     }
326 
hasAlpha() const327     bool CanvasHelper::hasAlpha() const
328     {
329         return mbHaveAlpha;
330     }
331 
332 }
333