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 _DXCANVAS_CANVASHELPER_HXX_
29 #define _DXCANVAS_CANVASHELPER_HXX_
30 
31 #include <com/sun/star/rendering/XCanvas.hpp>
32 
33 #include <basegfx/vector/b2isize.hxx>
34 #include <basegfx/vector/b2dsize.hxx>
35 
36 #include "dx_graphicsprovider.hxx"
37 #include "dx_gdiplususer.hxx"
38 #include "dx_impltools.hxx"
39 
40 #include <boost/utility.hpp>
41 
42 
43 namespace dxcanvas
44 {
45     /** Helper class for basic canvas functionality. Also offers
46         optional backbuffer painting, when providing it with a second
47         HDC to render into.
48      */
49     class CanvasHelper : private ::boost::noncopyable
50     {
51     public:
52         CanvasHelper();
53 
54         /// Release all references
55         void disposing();
56 
57 		/** Initialize canvas helper
58 
59         	This method late-initializes the canvas helper, providing
60         	it with the necessary device and output objects. Note that
61         	the CanvasHelper does <em>not</em> take ownership of the
62         	passed rDevice reference, nor does it perform any
63         	reference counting. Thus, to prevent the reference counted
64         	SpriteCanvas object from deletion, the user of this class
65         	is responsible for holding ref-counted references itself!
66 
67         	@param rDevice
68             Reference device this canvas is associated with
69 
70          */
71         void setDevice( com::sun::star::rendering::XGraphicDevice& rDevice );
72 
73         /** Set the target for rendering operations
74 
75             @param rTarget
76             Render target
77          */
78         void setTarget( const GraphicsProviderSharedPtr& rTarget );
79 
80         /** Set the target for rendering operations
81 
82             @param rTarget
83             Render target
84 
85             @param rOutputOffset
86             Output offset in pixel
87          */
88         void setTarget( const GraphicsProviderSharedPtr& rTarget,
89                         const ::basegfx::B2ISize& 		 rOutputOffset );
90 
91 
92         // CanvasHelper functionality
93         // ==========================
94 
95         // XCanvas (only providing, not implementing the
96         // interface. Also note subtle method parameter differences)
97         void clear();
98         void drawPoint( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
99                         const ::com::sun::star::geometry::RealPoint2D& 	aPoint,
100                         const ::com::sun::star::rendering::ViewState& 	viewState,
101                         const ::com::sun::star::rendering::RenderState& renderState );
102         void drawLine( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
103                        const ::com::sun::star::geometry::RealPoint2D& 	aStartPoint,
104                        const ::com::sun::star::geometry::RealPoint2D& 	aEndPoint,
105                        const ::com::sun::star::rendering::ViewState& 	viewState,
106                        const ::com::sun::star::rendering::RenderState& 	renderState	);
107         void drawBezier( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
108                          const ::com::sun::star::geometry::RealBezierSegment2D&	aBezierSegment,
109                          const ::com::sun::star::geometry::RealPoint2D& 		aEndPoint,
110                          const ::com::sun::star::rendering::ViewState& 			viewState,
111                          const ::com::sun::star::rendering::RenderState& 		renderState );
112         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
113         	drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
114                              const ::com::sun::star::uno::Reference<
115                              		::com::sun::star::rendering::XPolyPolygon2D >&	xPolyPolygon,
116                              const ::com::sun::star::rendering::ViewState& 			viewState,
117                              const ::com::sun::star::rendering::RenderState& 		renderState );
118         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
119         	strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
120                                const ::com::sun::star::uno::Reference<
121                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
122                                const ::com::sun::star::rendering::ViewState& 		viewState,
123                                const ::com::sun::star::rendering::RenderState& 		renderState,
124                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
125         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
126         	strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
127                                        const ::com::sun::star::uno::Reference<
128                                        		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
129                                        const ::com::sun::star::rendering::ViewState& 		viewState,
130                                        const ::com::sun::star::rendering::RenderState& 		renderState,
131                                        const ::com::sun::star::uno::Sequence<
132                                        		::com::sun::star::rendering::Texture >& 		textures,
133                                        const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
134         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
135         	strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
136                                             const ::com::sun::star::uno::Reference<
137                                             		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
138                                             const ::com::sun::star::rendering::ViewState& 			viewState,
139                                             const ::com::sun::star::rendering::RenderState& 		renderState,
140                                             const ::com::sun::star::uno::Sequence<
141                                             		::com::sun::star::rendering::Texture >& 		textures,
142                                             const ::com::sun::star::uno::Reference<
143                                             		::com::sun::star::geometry::XMapping2D >& 		xMapping,
144                                             const ::com::sun::star::rendering::StrokeAttributes& 	strokeAttributes );
145         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
146         	queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
147                                const ::com::sun::star::uno::Reference<
148                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
149                                const ::com::sun::star::rendering::ViewState& 		viewState,
150                                const ::com::sun::star::rendering::RenderState& 		renderState,
151                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
152         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
153         	fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
154                              const ::com::sun::star::uno::Reference<
155                              		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
156                              const ::com::sun::star::rendering::ViewState& 			viewState,
157                              const ::com::sun::star::rendering::RenderState& 		renderState );
158         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
159         	fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
160                                      const ::com::sun::star::uno::Reference<
161                                      		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
162                                      const ::com::sun::star::rendering::ViewState& 			viewState,
163                                      const ::com::sun::star::rendering::RenderState& 		renderState,
164                                      const ::com::sun::star::uno::Sequence<
165                                      		::com::sun::star::rendering::Texture >& 		textures );
166         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
167         	fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
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                                           const ::com::sun::star::uno::Sequence<
173                                           		::com::sun::star::rendering::Texture >& 		textures,
174                                           const ::com::sun::star::uno::Reference<
175                                           		::com::sun::star::geometry::XMapping2D >& 		xMapping );
176 
177         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
178         	createFont( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
179                         const ::com::sun::star::rendering::FontRequest& 		fontRequest,
180                         const ::com::sun::star::uno::Sequence<
181                         		::com::sun::star::beans::PropertyValue >& 		extraFontProperties,
182                         const ::com::sun::star::geometry::Matrix2D& 			fontMatrix );
183 
184         ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
185         	queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
186                                  const ::com::sun::star::rendering::FontInfo& 		aFilter,
187                                  const ::com::sun::star::uno::Sequence<
188                                  		::com::sun::star::beans::PropertyValue >& 	aFontProperties );
189 
190         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
191         	drawText( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
192                       const ::com::sun::star::rendering::StringContext& 	text,
193                       const ::com::sun::star::uno::Reference<
194                       		::com::sun::star::rendering::XCanvasFont >& 	xFont,
195                       const ::com::sun::star::rendering::ViewState& 		viewState,
196                       const ::com::sun::star::rendering::RenderState& 		renderState,
197                       sal_Int8 												textDirection );
198 
199         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
200         	drawTextLayout( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
201                             const ::com::sun::star::uno::Reference<
202                             	::com::sun::star::rendering::XTextLayout >& layoutetText,
203                             const ::com::sun::star::rendering::ViewState& 	viewState,
204                             const ::com::sun::star::rendering::RenderState& renderState );
205 
206         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
207         	drawBitmap( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
208                         const ::com::sun::star::uno::Reference<
209                         		::com::sun::star::rendering::XBitmap >& xBitmap,
210                         const ::com::sun::star::rendering::ViewState& 	viewState,
211                         const ::com::sun::star::rendering::RenderState& renderState );
212         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
213         	drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
214                                  const ::com::sun::star::uno::Reference<
215                                  		::com::sun::star::rendering::XBitmap >&		xBitmap,
216                                  const ::com::sun::star::rendering::ViewState& 		viewState,
217                                  const ::com::sun::star::rendering::RenderState& 	renderState );
218         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
219         	getDevice();
220 
221         // Flush drawing queue to screen
222         void					flush() const;
223 
224         /** Called from XCanvas base classes, to notify that content
225             is _about_ to change
226         */
227         void modifying() {}
228 
229     protected:
230         /// Refcounted global GDI+ state container
231         GDIPlusUserSharedPtr			mpGdiPlusUser;
232 
233         /** Phyical output device
234 
235             Deliberately not a refcounted reference, because of
236             potential circular references for spritecanvas.
237          */
238         com::sun::star::rendering::XGraphicDevice* mpDevice;
239 
240         /// Provides the Gdiplus::Graphics to render into
241         GraphicsProviderSharedPtr                  mpGraphicsProvider;
242 
243         bool needOutput() const { return mpGraphicsProvider.get() != NULL; };
244 
245         // returns transparency of color
246         void setupGraphicsState( GraphicsSharedPtr&                              rGraphics,
247                                  const ::com::sun::star::rendering::ViewState& 	 viewState,
248                                  const ::com::sun::star::rendering::RenderState& renderState );
249 
250         Gdiplus::CompositingMode 	calcCompositingMode( sal_Int8 nMode );
251 
252         /// Current (transformation-independent) output buffer offset
253         ::basegfx::B2ISize				maOutputOffset;
254     };
255 }
256 
257 #endif /* _DXCANVAS_CANVASHELPER_HXX_ */
258