xref: /trunk/main/canvas/source/null/null_canvashelper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 
34 #include <rtl/logfile.hxx>
35 #include <rtl/math.hxx>
36 
37 #include <com/sun/star/util/Endianness.hpp>
38 #include <com/sun/star/rendering/TexturingMode.hpp>
39 #include <com/sun/star/rendering/CompositeOperation.hpp>
40 #include <com/sun/star/rendering/RepaintResult.hpp>
41 #include <com/sun/star/rendering/PathCapType.hpp>
42 #include <com/sun/star/rendering/PathJoinType.hpp>
43 
44 #include <basegfx/matrix/b2dhommatrix.hxx>
45 #include <basegfx/point/b2dpoint.hxx>
46 #include <basegfx/tools/canvastools.hxx>
47 
48 #include <comphelper/sequence.hxx>
49 #include <canvas/canvastools.hxx>
50 
51 #include "null_spritecanvas.hxx"
52 #include "null_canvasfont.hxx"
53 #include "null_textlayout.hxx"
54 #include "null_canvashelper.hxx"
55 
56 #include <algorithm>
57 
58 
59 using namespace ::com::sun::star;
60 
61 namespace nullcanvas
62 {
63     CanvasHelper::CanvasHelper() :
64         mpDevice( NULL ),
65         maSize(),
66         mbHaveAlpha()
67     {
68     }
69 
70     void CanvasHelper::disposing()
71     {
72         mpDevice = NULL;
73     }
74 
75     void CanvasHelper::init( const ::basegfx::B2ISize& rSize,
76                              SpriteCanvas&             rDevice,
77                              bool                      bHasAlpha )
78     {
79         mpDevice = &rDevice;
80         maSize = rSize;
81         mbHaveAlpha = bHasAlpha;
82     }
83 
84     void CanvasHelper::clear()
85     {
86     }
87 
88     void CanvasHelper::drawPoint( const rendering::XCanvas*     /*pCanvas*/,
89                                   const geometry::RealPoint2D&  /*aPoint*/,
90                                   const rendering::ViewState&   /*viewState*/,
91                                   const rendering::RenderState& /*renderState*/ )
92     {
93     }
94 
95     void CanvasHelper::drawLine( const rendering::XCanvas*      /*pCanvas*/,
96                                  const geometry::RealPoint2D&   /*aPoint1*/,
97                                  const geometry::RealPoint2D&   /*aPoint2*/,
98                                  const rendering::ViewState&    /*viewState*/,
99                                  const rendering::RenderState&  /*renderState*/ )
100     {
101     }
102 
103     void CanvasHelper::drawBezier( const rendering::XCanvas*            /*pCanvas*/,
104                                    const geometry::RealBezierSegment2D& /*aBezierSegment*/,
105                                    const geometry::RealPoint2D&         /*aEndPoint*/,
106                                    const rendering::ViewState&          /*viewState*/,
107                                    const rendering::RenderState&        /*renderState*/ )
108     {
109     }
110 
111     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawPolyPolygon( const rendering::XCanvas*                          /*pCanvas*/,
112                                                                                  const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
113                                                                                  const rendering::ViewState&                        /*viewState*/,
114                                                                                  const rendering::RenderState&                      /*renderState*/ )
115     {
116         // TODO(P1): Provide caching here.
117         return uno::Reference< rendering::XCachedPrimitive >(NULL);
118     }
119 
120     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokePolyPolygon( const rendering::XCanvas*                            /*pCanvas*/,
121                                                                                    const uno::Reference< rendering::XPolyPolygon2D >&   /*xPolyPolygon*/,
122                                                                                    const rendering::ViewState&                          /*viewState*/,
123                                                                                    const rendering::RenderState&                        /*renderState*/,
124                                                                                    const rendering::StrokeAttributes&                   /*strokeAttributes*/ )
125     {
126         // TODO(P1): Provide caching here.
127         return uno::Reference< rendering::XCachedPrimitive >(NULL);
128     }
129 
130     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokeTexturedPolyPolygon( const rendering::XCanvas*                            /*pCanvas*/,
131                                                                                            const uno::Reference< rendering::XPolyPolygon2D >&   /*xPolyPolygon*/,
132                                                                                            const rendering::ViewState&                          /*viewState*/,
133                                                                                            const rendering::RenderState&                        /*renderState*/,
134                                                                                            const uno::Sequence< rendering::Texture >&           /*textures*/,
135                                                                                            const rendering::StrokeAttributes&                   /*strokeAttributes*/ )
136     {
137         // TODO
138         return uno::Reference< rendering::XCachedPrimitive >(NULL);
139     }
140 
141     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::strokeTextureMappedPolyPolygon( const rendering::XCanvas*                           /*pCanvas*/,
142                                                                                                 const uno::Reference< rendering::XPolyPolygon2D >&  /*xPolyPolygon*/,
143                                                                                                 const rendering::ViewState&                         /*viewState*/,
144                                                                                                 const rendering::RenderState&                       /*renderState*/,
145                                                                                                 const uno::Sequence< rendering::Texture >&          /*textures*/,
146                                                                                                 const uno::Reference< geometry::XMapping2D >&       /*xMapping*/,
147                                                                                                 const rendering::StrokeAttributes&                  /*strokeAttributes*/ )
148     {
149         // TODO
150         return uno::Reference< rendering::XCachedPrimitive >(NULL);
151     }
152 
153     uno::Reference< rendering::XPolyPolygon2D >   CanvasHelper::queryStrokeShapes( const rendering::XCanvas*                            /*pCanvas*/,
154                                                                                    const uno::Reference< rendering::XPolyPolygon2D >&   /*xPolyPolygon*/,
155                                                                                    const rendering::ViewState&                          /*viewState*/,
156                                                                                    const rendering::RenderState&                        /*renderState*/,
157                                                                                    const rendering::StrokeAttributes&                   /*strokeAttributes*/ )
158     {
159         // TODO
160         return uno::Reference< rendering::XPolyPolygon2D >(NULL);
161     }
162 
163     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillPolyPolygon( const rendering::XCanvas*                          /*pCanvas*/,
164                                                                                  const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
165                                                                                  const rendering::ViewState&                        /*viewState*/,
166                                                                                  const rendering::RenderState&                      /*renderState*/ )
167     {
168         // TODO(P1): Provide caching here.
169         return uno::Reference< rendering::XCachedPrimitive >(NULL);
170     }
171 
172     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTexturedPolyPolygon( const rendering::XCanvas*                          /*pCanvas*/,
173                                                                                          const uno::Reference< rendering::XPolyPolygon2D >& /*xPolyPolygon*/,
174                                                                                          const rendering::ViewState&                        /*viewState*/,
175                                                                                          const rendering::RenderState&                      /*renderState*/,
176                                                                                          const uno::Sequence< rendering::Texture >&         /*textures*/ )
177     {
178         // TODO(P1): Provide caching here.
179         return uno::Reference< rendering::XCachedPrimitive >(NULL);
180     }
181 
182     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::fillTextureMappedPolyPolygon( const rendering::XCanvas*                             /*pCanvas*/,
183                                                                                               const uno::Reference< rendering::XPolyPolygon2D >&    /*xPolyPolygon*/,
184                                                                                               const rendering::ViewState&                           /*viewState*/,
185                                                                                               const rendering::RenderState&                         /*renderState*/,
186                                                                                               const uno::Sequence< rendering::Texture >&            /*textures*/,
187                                                                                               const uno::Reference< geometry::XMapping2D >&         /*xMapping*/ )
188     {
189         // TODO
190         return uno::Reference< rendering::XCachedPrimitive >(NULL);
191     }
192 
193     uno::Reference< rendering::XCanvasFont > CanvasHelper::createFont( const rendering::XCanvas*                    /*pCanvas*/,
194                                                                        const rendering::FontRequest&                fontRequest,
195                                                                        const uno::Sequence< beans::PropertyValue >& extraFontProperties,
196                                                                        const geometry::Matrix2D&                    fontMatrix )
197     {
198         return uno::Reference< rendering::XCanvasFont >(
199             new CanvasFont(fontRequest, extraFontProperties, fontMatrix ) );
200     }
201 
202     uno::Sequence< rendering::FontInfo > CanvasHelper::queryAvailableFonts( const rendering::XCanvas*                       /*pCanvas*/,
203                                                                             const rendering::FontInfo&                      /*aFilter*/,
204                                                                             const uno::Sequence< beans::PropertyValue >&    /*aFontProperties*/ )
205     {
206         // TODO
207         return uno::Sequence< rendering::FontInfo >();
208     }
209 
210     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawText( const rendering::XCanvas*                         /*pCanvas*/,
211                                                                           const rendering::StringContext&                   /*text*/,
212                                                                           const uno::Reference< rendering::XCanvasFont >&   /*xFont*/,
213                                                                           const rendering::ViewState&                       /*viewState*/,
214                                                                           const rendering::RenderState&                     /*renderState*/,
215                                                                           sal_Int8                                          /*textDirection*/ )
216     {
217         return uno::Reference< rendering::XCachedPrimitive >(NULL);
218     }
219 
220     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawTextLayout( const rendering::XCanvas*                       /*pCanvas*/,
221                                                                                 const uno::Reference< rendering::XTextLayout >& xLayoutetText,
222                                                                                 const rendering::ViewState&                     viewState,
223                                                                                 const rendering::RenderState&                   renderState )
224     {
225         ENSURE_OR_THROW( xLayoutetText.is(),
226                           "CanvasHelper::drawTextLayout: layout is NULL");
227 
228         TextLayout* pTextLayout =
229             dynamic_cast< TextLayout* >( xLayoutetText.get() );
230 
231         ENSURE_OR_THROW( pTextLayout,
232                           "CanvasHelper::drawTextLayout(): TextLayout not compatible with this canvas" );
233 
234         pTextLayout->draw( viewState,
235                            renderState,
236                            mpDevice );
237 
238         return uno::Reference< rendering::XCachedPrimitive >(NULL);
239     }
240 
241     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawBitmap( const rendering::XCanvas*                   /*pCanvas*/,
242                                                                             const uno::Reference< rendering::XBitmap >& /*xBitmap*/,
243                                                                             const rendering::ViewState&                 /*viewState*/,
244                                                                             const rendering::RenderState&               /*renderState*/ )
245     {
246         // TODO(P1): Provide caching here.
247         return uno::Reference< rendering::XCachedPrimitive >(NULL);
248     }
249 
250     uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawBitmapModulated( const rendering::XCanvas*                      /*pCanvas*/,
251                                                                                      const uno::Reference< rendering::XBitmap >&    /*xBitmap*/,
252                                                                                      const rendering::ViewState&                    /*viewState*/,
253                                                                                      const rendering::RenderState&                  /*renderState*/ )
254     {
255         // TODO(P1): Provide caching here.
256         return uno::Reference< rendering::XCachedPrimitive >(NULL);
257     }
258 
259     uno::Reference< rendering::XGraphicDevice > CanvasHelper::getDevice()
260     {
261         return uno::Reference< rendering::XGraphicDevice >(mpDevice);
262     }
263 
264     void CanvasHelper::copyRect( const rendering::XCanvas*                          /*pCanvas*/,
265                                  const uno::Reference< rendering::XBitmapCanvas >&  /*sourceCanvas*/,
266                                  const geometry::RealRectangle2D&                   /*sourceRect*/,
267                                  const rendering::ViewState&                        /*sourceViewState*/,
268                                  const rendering::RenderState&                      /*sourceRenderState*/,
269                                  const geometry::RealRectangle2D&                   /*destRect*/,
270                                  const rendering::ViewState&                        /*destViewState*/,
271                                  const rendering::RenderState&                      /*destRenderState*/ )
272     {
273         // TODO(F2): copyRect NYI
274     }
275 
276     geometry::IntegerSize2D CanvasHelper::getSize()
277     {
278         if( !mpDevice )
279             geometry::IntegerSize2D(1, 1); // we're disposed
280 
281         return ::basegfx::unotools::integerSize2DFromB2ISize( maSize );
282     }
283 
284     uno::Reference< rendering::XBitmap > CanvasHelper::getScaledBitmap( const geometry::RealSize2D& /*newSize*/,
285                                                                         sal_Bool                    /*beFast*/ )
286     {
287         // TODO(F1):
288         return uno::Reference< rendering::XBitmap >();
289     }
290 
291     uno::Sequence< sal_Int8 > CanvasHelper::getData( rendering::IntegerBitmapLayout&     /*bitmapLayout*/,
292                                                      const geometry::IntegerRectangle2D& /*rect*/ )
293     {
294         // TODO
295         return uno::Sequence< sal_Int8 >();
296     }
297 
298     void CanvasHelper::setData( const uno::Sequence< sal_Int8 >&        /*data*/,
299                                 const rendering::IntegerBitmapLayout&   /*bitmapLayout*/,
300                                 const geometry::IntegerRectangle2D&     /*rect*/ )
301     {
302     }
303 
304     void CanvasHelper::setPixel( const uno::Sequence< sal_Int8 >&       /*color*/,
305                                  const rendering::IntegerBitmapLayout&  /*bitmapLayout*/,
306                                  const geometry::IntegerPoint2D&        /*pos*/ )
307     {
308     }
309 
310     uno::Sequence< sal_Int8 > CanvasHelper::getPixel( rendering::IntegerBitmapLayout&   /*bitmapLayout*/,
311                                                       const geometry::IntegerPoint2D&   /*pos*/ )
312     {
313         return uno::Sequence< sal_Int8 >();
314     }
315 
316     uno::Reference< rendering::XBitmapPalette > CanvasHelper::getPalette()
317     {
318         // TODO(F1): Palette bitmaps NYI
319         return uno::Reference< rendering::XBitmapPalette >();
320     }
321 
322     rendering::IntegerBitmapLayout CanvasHelper::getMemoryLayout()
323     {
324         return ::canvas::tools::getStdMemoryLayout(getSize());
325     }
326 
327     void CanvasHelper::flush() const
328     {
329     }
330 
331     bool CanvasHelper::hasAlpha() const
332     {
333         return mbHaveAlpha;
334     }
335 
336 }
337