Update ooo320-m1
[ooovba.git] / canvas / source / cairo / cairo_canvashelper.hxx
blobb2adbab3f852b650453f4cac45accb99cdb321d7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_canvashelper.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CAIROCANVAS_CANVASHELPER_HXX_
32 #define _CAIROCANVAS_CANVASHELPER_HXX_
34 #include <com/sun/star/rendering/XCanvas.hpp>
35 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
37 #include <basegfx/vector/b2isize.hxx>
38 #include <basegfx/vector/b2dsize.hxx>
39 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
41 #include <boost/utility.hpp>
43 #include "cairo_cairo.hxx"
44 #include "cairo_surfaceprovider.hxx"
46 class VirtualDevice;
48 namespace basegfx {
49 class B2DPolyPolygon;
52 namespace cairocanvas
54 class SpriteCanvas;
56 enum Operation {
57 Stroke,
58 Fill,
59 Clip
62 class CanvasHelper : private ::boost::noncopyable
64 public:
65 CanvasHelper();
67 /// Release all references
68 void disposing();
70 /** Initialize canvas helper
72 This method late-initializes the canvas helper, providing
73 it with the necessary device and size. Note that the
74 CanvasHelper does <em>not</em> take ownership of the
75 passed rDevice reference, nor does it perform any
76 reference counting. Thus, to prevent the reference counted
77 SpriteCanvas object from deletion, the user of this class
78 is responsible for holding ref-counted references itself!
80 @param rSizePixel
81 Size of the output surface in pixel.
83 @param rDevice
84 Reference device this canvas is associated with
87 void init( const ::basegfx::B2ISize& rSizePixel,
88 SurfaceProvider& rSurfaceProvider,
89 ::com::sun::star::rendering::XGraphicDevice* pDevice );
91 void setSize( const ::basegfx::B2ISize& rSize );
92 void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha );
94 // CanvasHelper functionality
95 // ==========================
97 // XCanvas (only providing, not implementing the
98 // interface. Also note subtle method parameter differences)
99 void clear();
100 void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas,
101 const ::com::sun::star::geometry::RealPoint2D& aPoint,
102 const ::com::sun::star::rendering::ViewState& viewState,
103 const ::com::sun::star::rendering::RenderState& renderState );
104 void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas,
105 const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
106 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
107 const ::com::sun::star::rendering::ViewState& viewState,
108 const ::com::sun::star::rendering::RenderState& renderState );
109 void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas,
110 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
111 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
112 const ::com::sun::star::rendering::ViewState& viewState,
113 const ::com::sun::star::rendering::RenderState& renderState );
114 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
115 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
116 const ::com::sun::star::uno::Reference<
117 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
118 const ::com::sun::star::rendering::ViewState& viewState,
119 const ::com::sun::star::rendering::RenderState& renderState );
120 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
121 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
122 const ::com::sun::star::uno::Reference<
123 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
124 const ::com::sun::star::rendering::ViewState& viewState,
125 const ::com::sun::star::rendering::RenderState& renderState,
126 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
127 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
128 strokeTexturedPolyPolygon( 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::uno::Sequence<
134 ::com::sun::star::rendering::Texture >& textures,
135 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
136 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
137 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
138 const ::com::sun::star::uno::Reference<
139 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
140 const ::com::sun::star::rendering::ViewState& viewState,
141 const ::com::sun::star::rendering::RenderState& renderState,
142 const ::com::sun::star::uno::Sequence<
143 ::com::sun::star::rendering::Texture >& textures,
144 const ::com::sun::star::uno::Reference<
145 ::com::sun::star::geometry::XMapping2D >& xMapping,
146 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
147 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
148 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas,
149 const ::com::sun::star::uno::Reference<
150 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
151 const ::com::sun::star::rendering::ViewState& viewState,
152 const ::com::sun::star::rendering::RenderState& renderState,
153 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
154 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
155 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
156 const ::com::sun::star::uno::Reference<
157 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
158 const ::com::sun::star::rendering::ViewState& viewState,
159 const ::com::sun::star::rendering::RenderState& renderState );
160 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
161 fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
162 const ::com::sun::star::uno::Reference<
163 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
164 const ::com::sun::star::rendering::ViewState& viewState,
165 const ::com::sun::star::rendering::RenderState& renderState,
166 const ::com::sun::star::uno::Sequence<
167 ::com::sun::star::rendering::Texture >& textures );
168 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
169 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
170 const ::com::sun::star::uno::Reference<
171 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
172 const ::com::sun::star::rendering::ViewState& viewState,
173 const ::com::sun::star::rendering::RenderState& renderState,
174 const ::com::sun::star::uno::Sequence<
175 ::com::sun::star::rendering::Texture >& textures,
176 const ::com::sun::star::uno::Reference<
177 ::com::sun::star::geometry::XMapping2D >& xMapping );
179 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
180 createFont( const ::com::sun::star::rendering::XCanvas* pCanvas,
181 const ::com::sun::star::rendering::FontRequest& fontRequest,
182 const ::com::sun::star::uno::Sequence<
183 ::com::sun::star::beans::PropertyValue >& extraFontProperties,
184 const ::com::sun::star::geometry::Matrix2D& fontMatrix );
186 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
187 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas,
188 const ::com::sun::star::rendering::FontInfo& aFilter,
189 const ::com::sun::star::uno::Sequence<
190 ::com::sun::star::beans::PropertyValue >& aFontProperties );
192 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
193 drawText( const ::com::sun::star::rendering::XCanvas* pCanvas,
194 const ::com::sun::star::rendering::StringContext& text,
195 const ::com::sun::star::uno::Reference<
196 ::com::sun::star::rendering::XCanvasFont >& xFont,
197 const ::com::sun::star::rendering::ViewState& viewState,
198 const ::com::sun::star::rendering::RenderState& renderState,
199 sal_Int8 textDirection );
201 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
202 drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas,
203 const ::com::sun::star::uno::Reference<
204 ::com::sun::star::rendering::XTextLayout >& layoutetText,
205 const ::com::sun::star::rendering::ViewState& viewState,
206 const ::com::sun::star::rendering::RenderState& renderState );
208 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
209 drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas,
210 const ::com::sun::star::uno::Reference<
211 ::com::sun::star::rendering::XBitmap >& xBitmap,
212 const ::com::sun::star::rendering::ViewState& viewState,
213 const ::com::sun::star::rendering::RenderState& renderState );
214 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
215 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas,
216 const ::com::sun::star::uno::Reference<
217 ::com::sun::star::rendering::XBitmap >& xBitmap,
218 const ::com::sun::star::rendering::ViewState& viewState,
219 const ::com::sun::star::rendering::RenderState& renderState );
220 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
221 getDevice();
223 // BitmapCanvasHelper functionality
224 // ================================
226 void copyRect( const ::com::sun::star::rendering::XCanvas* pCanvas,
227 const ::com::sun::star::uno::Reference<
228 ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas,
229 const ::com::sun::star::geometry::RealRectangle2D& sourceRect,
230 const ::com::sun::star::rendering::ViewState& sourceViewState,
231 const ::com::sun::star::rendering::RenderState& sourceRenderState,
232 const ::com::sun::star::geometry::RealRectangle2D& destRect,
233 const ::com::sun::star::rendering::ViewState& destViewState,
234 const ::com::sun::star::rendering::RenderState& destRenderState );
236 ::com::sun::star::geometry::IntegerSize2D getSize();
238 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
239 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
240 sal_Bool beFast );
242 ::com::sun::star::uno::Sequence< sal_Int8 >
243 getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
244 const ::com::sun::star::geometry::IntegerRectangle2D& rect );
246 void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data,
247 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
248 const ::com::sun::star::geometry::IntegerRectangle2D& rect );
250 void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color,
251 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
252 const ::com::sun::star::geometry::IntegerPoint2D& pos );
254 ::com::sun::star::uno::Sequence< sal_Int8 >
255 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
256 const ::com::sun::star::geometry::IntegerPoint2D& pos );
258 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapPalette > getPalette();
260 ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
262 // Flush drawing queue to screen
263 void flush() const;
265 /** Called from XCanvas base classes, to notify that content
266 is _about_ to change
268 void modifying() {}
270 bool hasAlpha() const;
272 enum ColorType
274 LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
277 void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
278 Operation aOperation,
279 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL,
280 ::cairo::Cairo* pCairo=NULL ) const;
282 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
283 implDrawBitmapSurface(
284 const ::com::sun::star::rendering::XCanvas* pCanvas,
285 const ::cairo::SurfaceSharedPtr& pSurface,
286 const ::com::sun::star::rendering::ViewState& viewState,
287 const ::com::sun::star::rendering::RenderState& renderState,
288 const ::com::sun::star::geometry::IntegerSize2D& rSize,
289 bool bModulateColors,
290 bool bHasAlpha );
292 bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
293 const ::com::sun::star::rendering::ViewState& viewState,
294 const ::com::sun::star::rendering::RenderState& renderState );
296 protected:
297 /** Surface provider
299 Deliberately not a refcounted reference, because of
300 potential circular references for canvas. Provides us with
301 our output surface and associated functionality.
303 SurfaceProvider* mpSurfaceProvider;
305 /** Phyical output device
307 Deliberately not a refcounted reference, because of
308 potential circular references for spritecanvas.
310 ::com::sun::star::rendering::XGraphicDevice* mpDevice;
312 private:
314 boost::shared_ptr<VirtualDevice> mpVirtualDevice;
316 void useStates( const ::com::sun::star::rendering::ViewState& viewState,
317 const ::com::sun::star::rendering::RenderState& renderState,
318 bool setColor );
320 /// When true, content is able to represent alpha
321 bool mbHaveAlpha;
323 CairoSharedPtr mpCairo;
324 SurfaceSharedPtr mpSurface;
325 ::basegfx::B2ISize maSize;
328 /// also needed from SpriteHelper
329 void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon,
330 Operation aOperation,
331 ::cairo::Cairo* pCairo,
332 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures,
333 const SurfaceProviderRef& pDevice,
334 ::com::sun::star::rendering::FillRule eFillrule );
337 #endif /* _CAIROCANVAS_CANVASHELPER_HXX_ */