Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _CAIROCANVAS_CANVASHELPER_HXX_
30 : : #define _CAIROCANVAS_CANVASHELPER_HXX_
31 : :
32 : : #include <com/sun/star/rendering/XCanvas.hpp>
33 : : #include <com/sun/star/rendering/XIntegerBitmap.hpp>
34 : :
35 : : #include <basegfx/vector/b2isize.hxx>
36 : : #include <basegfx/vector/b2dsize.hxx>
37 : : #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
38 : :
39 : : #include <boost/utility.hpp>
40 : :
41 : : #include "cairo_cairo.hxx"
42 : : #include "cairo_surfaceprovider.hxx"
43 : :
44 : : class VirtualDevice;
45 : :
46 : : namespace basegfx {
47 : : class B2DPolyPolygon;
48 : : }
49 : :
50 : : namespace cairocanvas
51 : : {
52 : : class SpriteCanvas;
53 : :
54 : : enum Operation {
55 : : Stroke,
56 : : Fill,
57 : : Clip
58 : : };
59 : :
60 : 0 : class CanvasHelper : private ::boost::noncopyable
61 : : {
62 : : public:
63 : : CanvasHelper();
64 : :
65 : : /// Release all references
66 : : void disposing();
67 : :
68 : : /** Initialize canvas helper
69 : :
70 : : This method late-initializes the canvas helper, providing
71 : : it with the necessary device and size. Note that the
72 : : CanvasHelper does <em>not</em> take ownership of the
73 : : passed rDevice reference, nor does it perform any
74 : : reference counting. Thus, to prevent the reference counted
75 : : SpriteCanvas object from deletion, the user of this class
76 : : is responsible for holding ref-counted references itself!
77 : :
78 : : @param rSizePixel
79 : : Size of the output surface in pixel.
80 : :
81 : : @param rDevice
82 : : Reference device this canvas is associated with
83 : :
84 : : */
85 : : void init( const ::basegfx::B2ISize& rSizePixel,
86 : : SurfaceProvider& rSurfaceProvider,
87 : : ::com::sun::star::rendering::XGraphicDevice* pDevice );
88 : :
89 : : void setSize( const ::basegfx::B2ISize& rSize );
90 : : void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha );
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 : : // BitmapCanvasHelper functionality
222 : : // ================================
223 : :
224 : : void copyRect( const ::com::sun::star::rendering::XCanvas* pCanvas,
225 : : const ::com::sun::star::uno::Reference<
226 : : ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas,
227 : : const ::com::sun::star::geometry::RealRectangle2D& sourceRect,
228 : : const ::com::sun::star::rendering::ViewState& sourceViewState,
229 : : const ::com::sun::star::rendering::RenderState& sourceRenderState,
230 : : const ::com::sun::star::geometry::RealRectangle2D& destRect,
231 : : const ::com::sun::star::rendering::ViewState& destViewState,
232 : : const ::com::sun::star::rendering::RenderState& destRenderState );
233 : :
234 : : ::com::sun::star::geometry::IntegerSize2D getSize();
235 : :
236 : : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
237 : : getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
238 : : sal_Bool beFast );
239 : :
240 : : ::com::sun::star::uno::Sequence< sal_Int8 >
241 : : getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
242 : : const ::com::sun::star::geometry::IntegerRectangle2D& rect );
243 : :
244 : : void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data,
245 : : const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
246 : : const ::com::sun::star::geometry::IntegerRectangle2D& rect );
247 : :
248 : : void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color,
249 : : const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
250 : : const ::com::sun::star::geometry::IntegerPoint2D& pos );
251 : :
252 : : ::com::sun::star::uno::Sequence< sal_Int8 >
253 : : getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
254 : : const ::com::sun::star::geometry::IntegerPoint2D& pos );
255 : :
256 : : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapPalette > getPalette();
257 : :
258 : : ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
259 : :
260 : : // Flush drawing queue to screen
261 : : void flush() const;
262 : :
263 : : /** Called from XCanvas base classes, to notify that content
264 : : is _about_ to change
265 : : */
266 : 0 : void modifying() {}
267 : :
268 : : bool hasAlpha() const;
269 : :
270 : : enum ColorType
271 : : {
272 : : LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
273 : : };
274 : :
275 : : void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
276 : : Operation aOperation,
277 : : bool bNoLineJoin = false,
278 : : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL,
279 : : ::cairo::Cairo* pCairo=NULL ) const;
280 : :
281 : : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > implDrawBitmapSurface(
282 : : const ::com::sun::star::rendering::XCanvas* pCanvas,
283 : : const ::cairo::SurfaceSharedPtr& pSurface,
284 : : const ::com::sun::star::rendering::ViewState& viewState,
285 : : const ::com::sun::star::rendering::RenderState& renderState,
286 : : const ::com::sun::star::geometry::IntegerSize2D& rSize,
287 : : bool bModulateColors,
288 : : bool bHasAlpha );
289 : :
290 : : bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
291 : : const ::com::sun::star::rendering::ViewState& viewState,
292 : : const ::com::sun::star::rendering::RenderState& renderState );
293 : :
294 : : protected:
295 : : /** Surface provider
296 : :
297 : : Deliberately not a refcounted reference, because of
298 : : potential circular references for canvas. Provides us with
299 : : our output surface and associated functionality.
300 : : */
301 : : SurfaceProvider* mpSurfaceProvider;
302 : :
303 : : /** Phyical output device
304 : :
305 : : Deliberately not a refcounted reference, because of
306 : : potential circular references for spritecanvas.
307 : : */
308 : : ::com::sun::star::rendering::XGraphicDevice* mpDevice;
309 : :
310 : : private:
311 : :
312 : : boost::shared_ptr<VirtualDevice> mpVirtualDevice;
313 : :
314 : : void useStates( const ::com::sun::star::rendering::ViewState& viewState,
315 : : const ::com::sun::star::rendering::RenderState& renderState,
316 : : bool setColor );
317 : :
318 : : /// When true, content is able to represent alpha
319 : : bool mbHaveAlpha;
320 : :
321 : : CairoSharedPtr mpCairo;
322 : : SurfaceSharedPtr mpSurface;
323 : : ::basegfx::B2ISize maSize;
324 : : };
325 : :
326 : : /// also needed from SpriteHelper
327 : : void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon,
328 : : Operation aOperation,
329 : : ::cairo::Cairo* pCairo,
330 : : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures,
331 : : const SurfaceProviderRef& pDevice,
332 : : ::com::sun::star::rendering::FillRule eFillrule );
333 : : }
334 : :
335 : : #endif /* _CAIROCANVAS_CANVASHELPER_HXX_ */
336 : :
337 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|