xref: /aoo41x/main/canvas/source/vcl/canvashelper.hxx (revision cdf0e10c)
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 #ifndef _VCLCANVAS_CANVASHELPER_HXX_
29 #define _VCLCANVAS_CANVASHELPER_HXX_
30 
31 #include <com/sun/star/rendering/XCanvas.hpp>
32 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
33 
34 #include <vcl/outdev.hxx>
35 
36 #include <canvas/vclwrapper.hxx>
37 
38 #include "cachedbitmap.hxx"
39 #include "outdevprovider.hxx"
40 
41 #include <boost/utility.hpp>
42 
43 
44 namespace vclcanvas
45 {
46     class SpriteCanvas;
47 
48     /** Helper class for basic canvas functionality. Also offers
49         optional backbuffer painting, when providing it with a second
50         OutputDevice to render into.
51      */
52     class CanvasHelper : private ::boost::noncopyable
53     {
54     public:
55 		/** Create canvas helper
56          */
57         CanvasHelper();
58 
59         /// Release all references
60         void disposing();
61 
62 		/** Initialize canvas helper
63 
64         	This method late-initializes the canvas helper, providing
65         	it with the necessary device and output objects. Note that
66         	the CanvasHelper does <em>not</em> take ownership of the
67         	passed rDevice reference, nor does it perform any
68         	reference counting. Thus, to prevent the reference counted
69         	SpriteCanvas object from deletion, the user of this class
70         	is responsible for holding ref-counted references itself!
71 
72         	@param rDevice
73             Reference device this canvas is associated with
74 
75             @param rOutDev
76             Set primary output device for this canvas. That's where
77             all content is output to.
78 
79         	@param bProtect
80             When true, all output operations preserve outdev
81             state. When false, outdev state might change at any time.
82 
83         	@param bHaveAlpha
84             When true, hasAlpha() will always return true, otherwise, false.
85          */
86         void init( ::com::sun::star::rendering::XGraphicDevice& rDevice,
87                    const OutDevProviderSharedPtr&               rOutDev,
88                    bool                                         bProtect,
89                    bool                                         bHaveAlpha );
90 
91         /** Set primary output device
92 
93         	This changes the primary output device, where rendering is
94         	sent to.
95          */
96         void setOutDev( const OutDevProviderSharedPtr&	rOutDev,
97                         bool							bProtect);
98 
99         /** Set secondary output device
100 
101         	Used for sprites, to generate mask bitmap.
102          */
103         void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
104 
105 
106         // CanvasHelper functionality
107         // ==========================
108 
109         // XCanvas (only providing, not implementing the
110         // interface. Also note subtle method parameter differences)
111         void clear();
112         void drawPoint( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
113                         const ::com::sun::star::geometry::RealPoint2D& 		aPoint,
114                         const ::com::sun::star::rendering::ViewState& 		viewState,
115                         const ::com::sun::star::rendering::RenderState& 	renderState );
116         void drawLine( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
117                        const ::com::sun::star::geometry::RealPoint2D& 	aStartPoint,
118                        const ::com::sun::star::geometry::RealPoint2D& 	aEndPoint,
119                        const ::com::sun::star::rendering::ViewState& 	viewState,
120                        const ::com::sun::star::rendering::RenderState& 	renderState	);
121         void drawBezier( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
122                          const ::com::sun::star::geometry::RealBezierSegment2D&	aBezierSegment,
123                          const ::com::sun::star::geometry::RealPoint2D& 		aEndPoint,
124                          const ::com::sun::star::rendering::ViewState& 			viewState,
125                          const ::com::sun::star::rendering::RenderState& 		renderState );
126         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
127         	drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
128                              const ::com::sun::star::uno::Reference<
129                              	::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
130                              const ::com::sun::star::rendering::ViewState& 		viewState,
131                              const ::com::sun::star::rendering::RenderState& 	renderState );
132         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
133         	strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
134                                const ::com::sun::star::uno::Reference<
135                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
136                                const ::com::sun::star::rendering::ViewState& 		viewState,
137                                const ::com::sun::star::rendering::RenderState& 		renderState,
138                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
139         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
140         	strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
141                                        const ::com::sun::star::uno::Reference<
142                                        		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
143                                        const ::com::sun::star::rendering::ViewState& 		viewState,
144                                        const ::com::sun::star::rendering::RenderState& 		renderState,
145                                        const ::com::sun::star::uno::Sequence<
146                                        		::com::sun::star::rendering::Texture >& 		textures,
147                                        const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
148         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
149         	strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
150                                             const ::com::sun::star::uno::Reference<
151                                             		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
152                                             const ::com::sun::star::rendering::ViewState& 			viewState,
153                                             const ::com::sun::star::rendering::RenderState& 		renderState,
154                                             const ::com::sun::star::uno::Sequence<
155                                             		::com::sun::star::rendering::Texture >& 		textures,
156                                             const ::com::sun::star::uno::Reference<
157                                             		::com::sun::star::geometry::XMapping2D >& 		xMapping,
158                                             const ::com::sun::star::rendering::StrokeAttributes& 	strokeAttributes );
159         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
160         	queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
161                                const ::com::sun::star::uno::Reference<
162                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
163                                const ::com::sun::star::rendering::ViewState& 		viewState,
164                                const ::com::sun::star::rendering::RenderState& 		renderState,
165                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
166         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
167         	fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
168                              const ::com::sun::star::uno::Reference<
169                              		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
170                              const ::com::sun::star::rendering::ViewState& 			viewState,
171                              const ::com::sun::star::rendering::RenderState& 		renderState );
172         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
173         	fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
174                                      const ::com::sun::star::uno::Reference<
175                                      		::com::sun::star::rendering::XPolyPolygon2D >&	xPolyPolygon,
176                                      const ::com::sun::star::rendering::ViewState& 			viewState,
177                                      const ::com::sun::star::rendering::RenderState& 		renderState,
178                                      const ::com::sun::star::uno::Sequence<
179                                      		::com::sun::star::rendering::Texture >& 		textures );
180         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
181         	fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
182                                           const ::com::sun::star::uno::Reference<
183                                           		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
184                                           const ::com::sun::star::rendering::ViewState& 		viewState,
185                                           const ::com::sun::star::rendering::RenderState& 		renderState,
186                                           const ::com::sun::star::uno::Sequence<
187                                           		::com::sun::star::rendering::Texture >& 		textures,
188                                           const ::com::sun::star::uno::Reference<
189                                           		::com::sun::star::geometry::XMapping2D >& 		xMapping );
190 
191         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >
192 	        createFont( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
193                         const ::com::sun::star::rendering::FontRequest& 	fontRequest,
194                         const ::com::sun::star::uno::Sequence<
195                         	::com::sun::star::beans::PropertyValue >& 		extraFontProperties,
196                         const ::com::sun::star::geometry::Matrix2D& 		fontMatrix );
197 
198         ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
199         	queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
200                                  const ::com::sun::star::rendering::FontInfo& 		aFilter,
201                                  const ::com::sun::star::uno::Sequence<
202                                  		::com::sun::star::beans::PropertyValue >& 	aFontProperties );
203 
204         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
205         	drawText( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
206                       const ::com::sun::star::rendering::StringContext& text,
207                       const ::com::sun::star::uno::Reference<
208                       		::com::sun::star::rendering::XCanvasFont >& xFont,
209                       const ::com::sun::star::rendering::ViewState& 	viewState,
210                       const ::com::sun::star::rendering::RenderState& 	renderState,
211                       sal_Int8 											textDirection );
212 
213         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
214         	drawTextLayout( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
215                             const ::com::sun::star::uno::Reference<
216                             		::com::sun::star::rendering::XTextLayout >& layoutetText,
217                             const ::com::sun::star::rendering::ViewState& 		viewState,
218                             const ::com::sun::star::rendering::RenderState& 	renderState );
219 
220         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
221         	drawBitmap( const ::com::sun::star::rendering::XCanvas* 	rCanvas,
222                         const ::com::sun::star::uno::Reference<
223                         		::com::sun::star::rendering::XBitmap >& xBitmap,
224                         const ::com::sun::star::rendering::ViewState& 	viewState,
225                         const ::com::sun::star::rendering::RenderState& renderState );
226         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
227         	drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* 		rCanvas,
228                                  const ::com::sun::star::uno::Reference<
229                                  		::com::sun::star::rendering::XBitmap >&		xBitmap,
230                                  const ::com::sun::star::rendering::ViewState& 		viewState,
231                                  const ::com::sun::star::rendering::RenderState&	renderState );
232         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
233         	getDevice();
234 
235         // BitmapCanvasHelper functionality
236         // ================================
237 
238         void copyRect( const ::com::sun::star::rendering::XCanvas* 			rCanvas,
239                        const ::com::sun::star::uno::Reference<
240                        		::com::sun::star::rendering::XBitmapCanvas >& 	sourceCanvas,
241                        const ::com::sun::star::geometry::RealRectangle2D& 	sourceRect,
242                        const ::com::sun::star::rendering::ViewState& 		sourceViewState,
243                        const ::com::sun::star::rendering::RenderState& 		sourceRenderState,
244                        const ::com::sun::star::geometry::RealRectangle2D& 	destRect,
245                        const ::com::sun::star::rendering::ViewState& 		destViewState,
246                        const ::com::sun::star::rendering::RenderState& 		destRenderState );
247 
248         ::com::sun::star::geometry::IntegerSize2D getSize();
249 
250         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > queryBitmapCanvas();
251 
252         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
253         	getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& 	newSize,
254                              sal_Bool 												beFast );
255 
256         ::com::sun::star::uno::Sequence< sal_Int8 >
257 	        getData( ::com::sun::star::rendering::IntegerBitmapLayout& 		bitmapLayout,
258                      const ::com::sun::star::geometry::IntegerRectangle2D&	rect );
259 
260         void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& 		data,
261                       const ::com::sun::star::rendering::IntegerBitmapLayout& 	bitmapLayout,
262                       const ::com::sun::star::geometry::IntegerRectangle2D& 	rect );
263 
264         void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& 		color,
265                        const ::com::sun::star::rendering::IntegerBitmapLayout&	bitmapLayout,
266                        const ::com::sun::star::geometry::IntegerPoint2D& 		pos );
267 
268         ::com::sun::star::uno::Sequence< sal_Int8 >
269 	        getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
270                       const ::com::sun::star::geometry::IntegerPoint2D& pos );
271 
272         ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
273 
274         /// Repaint a cached bitmap
275         bool repaint( const GraphicObjectSharedPtr&                   rGrf,
276                       const ::com::sun::star::rendering::ViewState&   viewState,
277                       const ::com::sun::star::rendering::RenderState& renderState,
278                       const ::Point&                                  rPt,
279                       const ::Size&                                   rSz,
280                       const GraphicAttr&                              rAttr ) const;
281 
282         /** Flush drawing queue.
283 
284             This only works for Window canvases, and ensures that all
285             pending render operations are flushed to the
286             driver/hardware.
287          */
288         void flush() const;
289 
290         enum ColorType
291         {
292             LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
293         };
294 
295         // returns transparency of color
296         int setupOutDevState( const ::com::sun::star::rendering::ViewState& 	viewState,
297                               const ::com::sun::star::rendering::RenderState& 	renderState,
298                               ColorType											eColorType ) const;
299 
300         /** Called from XCanvas base classes, to notify that content
301             is _about_ to change
302         */
303         void modifying() {}
304 
305         bool hasAlpha() const { return mbHaveAlpha; }
306 
307     protected:
308         /** Phyical output device
309 
310             Deliberately not a refcounted reference, because of
311             potential circular references for spritecanvas.
312          */
313         ::com::sun::star::rendering::XGraphicDevice* mpDevice;
314 
315         /// Rendering to this outdev preserves its state
316         OutDevProviderSharedPtr                      mpProtectedOutDev;
317 
318         /// Rendering to this outdev does not preserve its state
319         OutDevProviderSharedPtr                      mpOutDev;
320 
321         /// Rendering to this outdev does not preserve its state
322         OutDevProviderSharedPtr                      mp2ndOutDev;
323 
324         /// When true, content is able to represent alpha
325         bool                                         mbHaveAlpha;
326 
327     private:
328         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
329         	implDrawBitmap( const ::com::sun::star::rendering::XCanvas* 	rCanvas,
330                             const ::com::sun::star::uno::Reference<
331                   		          ::com::sun::star::rendering::XBitmap >& 	xBitmap,
332                             const ::com::sun::star::rendering::ViewState& 	viewState,
333                             const ::com::sun::star::rendering::RenderState& renderState,
334                             bool 											bModulateColors );
335 
336         bool setupTextOutput( ::Point&																				o_rOutPos,
337                               const ::com::sun::star::rendering::ViewState& 										viewState,
338                               const ::com::sun::star::rendering::RenderState& 										renderState,
339                               const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >&	xFont ) const;
340 
341     };
342 }
343 
344 #endif /* _VCLCANVAS_CANVASHELPER_HXX_ */
345