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 #ifndef _NULLCANVAS_CANVASHELPER_HXX_
25 #define _NULLCANVAS_CANVASHELPER_HXX_
26 
27 #include <com/sun/star/rendering/XCanvas.hpp>
28 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
29 
30 #include <basegfx/vector/b2isize.hxx>
31 #include <basegfx/vector/b2dsize.hxx>
32 
33 #include <boost/utility.hpp>
34 
35 
36 namespace nullcanvas
37 {
38     class SpriteCanvas;
39 
40     /** Helper class for basic canvas functionality. Also offers
41         optional backbuffer painting, when providing it with a second
42         HDC to render into.
43      */
44     class CanvasHelper : private ::boost::noncopyable
45     {
46     public:
47         CanvasHelper();
48 
49         /// Release all references
50         void disposing();
51 
52 		/** Initialize canvas helper
53 
54         	This method late-initializes the canvas helper, providing
55         	it with the necessary device and size. Note that the
56         	CanvasHelper does <em>not</em> take ownership of the
57         	passed rDevice reference, nor does it perform any
58         	reference counting. Thus, to prevent the reference counted
59         	SpriteCanvas object from deletion, the user of this class
60         	is responsible for holding ref-counted references itself!
61 
62             @param rSizePixel
63             Size of the output surface in pixel.
64 
65         	@param rDevice
66             Reference device this canvas is associated with
67 
68          */
69         void init( const ::basegfx::B2ISize& rSizePixel,
70                    SpriteCanvas&             rDevice,
71                    bool                      bHasAlpha );
72 
73 
74         // CanvasHelper functionality
75         // ==========================
76 
77         // XCanvas (only providing, not implementing the
78         // interface. Also note subtle method parameter differences)
79         void clear();
80         void drawPoint( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
81                         const ::com::sun::star::geometry::RealPoint2D& 	aPoint,
82                         const ::com::sun::star::rendering::ViewState& 	viewState,
83                         const ::com::sun::star::rendering::RenderState& renderState );
84         void drawLine( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
85                        const ::com::sun::star::geometry::RealPoint2D& 	aStartPoint,
86                        const ::com::sun::star::geometry::RealPoint2D& 	aEndPoint,
87                        const ::com::sun::star::rendering::ViewState& 	viewState,
88                        const ::com::sun::star::rendering::RenderState& 	renderState	);
89         void drawBezier( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
90                          const ::com::sun::star::geometry::RealBezierSegment2D&	aBezierSegment,
91                          const ::com::sun::star::geometry::RealPoint2D& 		aEndPoint,
92                          const ::com::sun::star::rendering::ViewState& 			viewState,
93                          const ::com::sun::star::rendering::RenderState& 		renderState );
94         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
95         	drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
96                              const ::com::sun::star::uno::Reference<
97                              		::com::sun::star::rendering::XPolyPolygon2D >&	xPolyPolygon,
98                              const ::com::sun::star::rendering::ViewState& 			viewState,
99                              const ::com::sun::star::rendering::RenderState& 		renderState );
100         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
101         	strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
102                                const ::com::sun::star::uno::Reference<
103                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
104                                const ::com::sun::star::rendering::ViewState& 		viewState,
105                                const ::com::sun::star::rendering::RenderState& 		renderState,
106                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
107         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
108         	strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
109                                        const ::com::sun::star::uno::Reference<
110                                        		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
111                                        const ::com::sun::star::rendering::ViewState& 		viewState,
112                                        const ::com::sun::star::rendering::RenderState& 		renderState,
113                                        const ::com::sun::star::uno::Sequence<
114                                        		::com::sun::star::rendering::Texture >& 		textures,
115                                        const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
116         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
117         	strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
118                                             const ::com::sun::star::uno::Reference<
119                                             		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
120                                             const ::com::sun::star::rendering::ViewState& 			viewState,
121                                             const ::com::sun::star::rendering::RenderState& 		renderState,
122                                             const ::com::sun::star::uno::Sequence<
123                                             		::com::sun::star::rendering::Texture >& 		textures,
124                                             const ::com::sun::star::uno::Reference<
125                                             		::com::sun::star::geometry::XMapping2D >& 		xMapping,
126                                             const ::com::sun::star::rendering::StrokeAttributes& 	strokeAttributes );
127         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
128         	queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
129                                const ::com::sun::star::uno::Reference<
130                                		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
131                                const ::com::sun::star::rendering::ViewState& 		viewState,
132                                const ::com::sun::star::rendering::RenderState& 		renderState,
133                                const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
134         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
135         	fillPolyPolygon( 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         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
141         	fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
142                                      const ::com::sun::star::uno::Reference<
143                                      		::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
144                                      const ::com::sun::star::rendering::ViewState& 			viewState,
145                                      const ::com::sun::star::rendering::RenderState& 		renderState,
146                                      const ::com::sun::star::uno::Sequence<
147                                      		::com::sun::star::rendering::Texture >& 		textures );
148         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
149         	fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
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 
159         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
160         	createFont( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
161                         const ::com::sun::star::rendering::FontRequest& 		fontRequest,
162                         const ::com::sun::star::uno::Sequence<
163                         		::com::sun::star::beans::PropertyValue >& 		extraFontProperties,
164                         const ::com::sun::star::geometry::Matrix2D& 			fontMatrix );
165 
166         ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
167         	queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
168                                  const ::com::sun::star::rendering::FontInfo& 		aFilter,
169                                  const ::com::sun::star::uno::Sequence<
170                                  		::com::sun::star::beans::PropertyValue >& 	aFontProperties );
171 
172         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
173         	drawText( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
174                       const ::com::sun::star::rendering::StringContext& 	text,
175                       const ::com::sun::star::uno::Reference<
176                       		::com::sun::star::rendering::XCanvasFont >& 	xFont,
177                       const ::com::sun::star::rendering::ViewState& 		viewState,
178                       const ::com::sun::star::rendering::RenderState& 		renderState,
179                       sal_Int8 												textDirection );
180 
181         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
182         	drawTextLayout( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
183                             const ::com::sun::star::uno::Reference<
184                             	::com::sun::star::rendering::XTextLayout >& layoutetText,
185                             const ::com::sun::star::rendering::ViewState& 	viewState,
186                             const ::com::sun::star::rendering::RenderState& renderState );
187 
188         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
189         	drawBitmap( const ::com::sun::star::rendering::XCanvas* 	pCanvas,
190                         const ::com::sun::star::uno::Reference<
191                         		::com::sun::star::rendering::XBitmap >& xBitmap,
192                         const ::com::sun::star::rendering::ViewState& 	viewState,
193                         const ::com::sun::star::rendering::RenderState& renderState );
194         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
195         	drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* 		pCanvas,
196                                  const ::com::sun::star::uno::Reference<
197                                  		::com::sun::star::rendering::XBitmap >&		xBitmap,
198                                  const ::com::sun::star::rendering::ViewState& 		viewState,
199                                  const ::com::sun::star::rendering::RenderState& 	renderState );
200         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
201         	getDevice();
202 
203         // BitmapCanvasHelper functionality
204         // ================================
205 
206         void copyRect( const ::com::sun::star::rendering::XCanvas* 			pCanvas,
207                        const ::com::sun::star::uno::Reference<
208                        		::com::sun::star::rendering::XBitmapCanvas >& 	sourceCanvas,
209                        const ::com::sun::star::geometry::RealRectangle2D& 	sourceRect,
210                        const ::com::sun::star::rendering::ViewState& 		sourceViewState,
211                        const ::com::sun::star::rendering::RenderState& 		sourceRenderState,
212                        const ::com::sun::star::geometry::RealRectangle2D& 	destRect,
213                        const ::com::sun::star::rendering::ViewState& 		destViewState,
214                        const ::com::sun::star::rendering::RenderState& 		destRenderState );
215 
216         ::com::sun::star::geometry::IntegerSize2D getSize();
217 
218         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
219         	getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& 	newSize,
220                              sal_Bool 										beFast );
221 
222         ::com::sun::star::uno::Sequence< sal_Int8 >
223 	        getData( ::com::sun::star::rendering::IntegerBitmapLayout& 		bitmapLayout,
224                      const ::com::sun::star::geometry::IntegerRectangle2D&  rect );
225 
226         void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >&         data,
227                       const ::com::sun::star::rendering::IntegerBitmapLayout&    bitmapLayout,
228                       const ::com::sun::star::geometry::IntegerRectangle2D&      rect );
229 
230         void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >&        color,
231                        const ::com::sun::star::rendering::IntegerBitmapLayout&   bitmapLayout,
232                        const ::com::sun::star::geometry::IntegerPoint2D&         pos );
233 
234         ::com::sun::star::uno::Sequence< sal_Int8 >
235 	        getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
236                       const ::com::sun::star::geometry::IntegerPoint2D& pos );
237 
238         ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapPalette > getPalette();
239 
240         ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
241 
242         // Flush drawing queue to screen
243         void					flush() const;
244 
245         /** Called from XCanvas base classes, to notify that content
246             is _about_ to change
247         */
modifying()248         void modifying() {}
249 
250         bool hasAlpha() const;
251 
252     protected:
253         /** Phyical output device
254 
255             Deliberately not a refcounted reference, because of
256             potential circular references for spritecanvas.
257          */
258         SpriteCanvas*                   mpDevice;
259 
260     private:
261         /// Current size of the output surface in pixel
262         ::basegfx::B2ISize				maSize;
263 
264         /// When true, content is able to represent alpha
265         bool                            mbHaveAlpha;
266     };
267 }
268 
269 #endif /* _NULLCANVAS_CANVASHELPER_HXX_ */
270