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