Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _CAIROCANVAS_CANVASHELPER_HXX_
21 : #define _CAIROCANVAS_CANVASHELPER_HXX_
22 :
23 : #include <com/sun/star/rendering/XCanvas.hpp>
24 : #include <com/sun/star/rendering/XIntegerBitmap.hpp>
25 :
26 : #include <basegfx/vector/b2isize.hxx>
27 : #include <basegfx/vector/b2dsize.hxx>
28 : #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
29 :
30 : #include <boost/utility.hpp>
31 :
32 : #include "cairo_cairo.hxx"
33 : #include "cairo_surfaceprovider.hxx"
34 :
35 : class VirtualDevice;
36 :
37 : namespace basegfx {
38 : class B2DPolyPolygon;
39 : }
40 :
41 : namespace cairocanvas
42 : {
43 : class SpriteCanvas;
44 :
45 : enum Operation {
46 : Stroke,
47 : Fill,
48 : Clip
49 : };
50 :
51 0 : class CanvasHelper : private ::boost::noncopyable
52 : {
53 : public:
54 : CanvasHelper();
55 :
56 : /// Release all references
57 : void disposing();
58 :
59 : /** Initialize canvas helper
60 :
61 : This method late-initializes the canvas helper, providing
62 : it with the necessary device and size. Note that the
63 : CanvasHelper does <em>not</em> take ownership of the
64 : passed rDevice reference, nor does it perform any
65 : reference counting. Thus, to prevent the reference counted
66 : SpriteCanvas object from deletion, the user of this class
67 : is responsible for holding ref-counted references itself!
68 :
69 : @param rSizePixel
70 : Size of the output surface in pixel.
71 :
72 : @param rDevice
73 : Reference device this canvas is associated with
74 :
75 : */
76 : void init( const ::basegfx::B2ISize& rSizePixel,
77 : SurfaceProvider& rSurfaceProvider,
78 : ::com::sun::star::rendering::XGraphicDevice* pDevice );
79 :
80 : void setSize( const ::basegfx::B2ISize& rSize );
81 : void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha );
82 :
83 : // CanvasHelper functionality
84 : // ==========================
85 :
86 : // XCanvas (only providing, not implementing the
87 : // interface. Also note subtle method parameter differences)
88 : void clear();
89 : void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas,
90 : const ::com::sun::star::geometry::RealPoint2D& aPoint,
91 : const ::com::sun::star::rendering::ViewState& viewState,
92 : const ::com::sun::star::rendering::RenderState& renderState );
93 : void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas,
94 : const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
95 : const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
96 : const ::com::sun::star::rendering::ViewState& viewState,
97 : const ::com::sun::star::rendering::RenderState& renderState );
98 : void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas,
99 : const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
100 : const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
101 : const ::com::sun::star::rendering::ViewState& viewState,
102 : const ::com::sun::star::rendering::RenderState& renderState );
103 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
104 : drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
105 : const ::com::sun::star::uno::Reference<
106 : ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
107 : const ::com::sun::star::rendering::ViewState& viewState,
108 : const ::com::sun::star::rendering::RenderState& renderState );
109 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
110 : strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
111 : const ::com::sun::star::uno::Reference<
112 : ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
113 : const ::com::sun::star::rendering::ViewState& viewState,
114 : const ::com::sun::star::rendering::RenderState& renderState,
115 : const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
116 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
117 : strokeTexturedPolyPolygon( 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::rendering::StrokeAttributes& strokeAttributes );
125 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
126 : strokeTextureMappedPolyPolygon( 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::uno::Reference<
134 : ::com::sun::star::geometry::XMapping2D >& xMapping,
135 : const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
136 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
137 : queryStrokeShapes( 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::rendering::StrokeAttributes& strokeAttributes );
143 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
144 : fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
145 : const ::com::sun::star::uno::Reference<
146 : ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
147 : const ::com::sun::star::rendering::ViewState& viewState,
148 : const ::com::sun::star::rendering::RenderState& renderState );
149 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
150 : fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
151 : const ::com::sun::star::uno::Reference<
152 : ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
153 : const ::com::sun::star::rendering::ViewState& viewState,
154 : const ::com::sun::star::rendering::RenderState& renderState,
155 : const ::com::sun::star::uno::Sequence<
156 : ::com::sun::star::rendering::Texture >& textures );
157 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
158 : fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
159 : const ::com::sun::star::uno::Reference<
160 : ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
161 : const ::com::sun::star::rendering::ViewState& viewState,
162 : const ::com::sun::star::rendering::RenderState& renderState,
163 : const ::com::sun::star::uno::Sequence<
164 : ::com::sun::star::rendering::Texture >& textures,
165 : const ::com::sun::star::uno::Reference<
166 : ::com::sun::star::geometry::XMapping2D >& xMapping );
167 :
168 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
169 : createFont( const ::com::sun::star::rendering::XCanvas* pCanvas,
170 : const ::com::sun::star::rendering::FontRequest& fontRequest,
171 : const ::com::sun::star::uno::Sequence<
172 : ::com::sun::star::beans::PropertyValue >& extraFontProperties,
173 : const ::com::sun::star::geometry::Matrix2D& fontMatrix );
174 :
175 : ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
176 : queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas,
177 : const ::com::sun::star::rendering::FontInfo& aFilter,
178 : const ::com::sun::star::uno::Sequence<
179 : ::com::sun::star::beans::PropertyValue >& aFontProperties );
180 :
181 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
182 : drawText( const ::com::sun::star::rendering::XCanvas* pCanvas,
183 : const ::com::sun::star::rendering::StringContext& text,
184 : const ::com::sun::star::uno::Reference<
185 : ::com::sun::star::rendering::XCanvasFont >& xFont,
186 : const ::com::sun::star::rendering::ViewState& viewState,
187 : const ::com::sun::star::rendering::RenderState& renderState,
188 : sal_Int8 textDirection );
189 :
190 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
191 : drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas,
192 : const ::com::sun::star::uno::Reference<
193 : ::com::sun::star::rendering::XTextLayout >& layoutetText,
194 : const ::com::sun::star::rendering::ViewState& viewState,
195 : const ::com::sun::star::rendering::RenderState& renderState );
196 :
197 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
198 : drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas,
199 : const ::com::sun::star::uno::Reference<
200 : ::com::sun::star::rendering::XBitmap >& xBitmap,
201 : const ::com::sun::star::rendering::ViewState& viewState,
202 : const ::com::sun::star::rendering::RenderState& renderState );
203 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
204 : drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas,
205 : const ::com::sun::star::uno::Reference<
206 : ::com::sun::star::rendering::XBitmap >& xBitmap,
207 : const ::com::sun::star::rendering::ViewState& viewState,
208 : const ::com::sun::star::rendering::RenderState& renderState );
209 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
210 : getDevice();
211 :
212 : // BitmapCanvasHelper functionality
213 : // ================================
214 :
215 : void copyRect( const ::com::sun::star::rendering::XCanvas* pCanvas,
216 : const ::com::sun::star::uno::Reference<
217 : ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas,
218 : const ::com::sun::star::geometry::RealRectangle2D& sourceRect,
219 : const ::com::sun::star::rendering::ViewState& sourceViewState,
220 : const ::com::sun::star::rendering::RenderState& sourceRenderState,
221 : const ::com::sun::star::geometry::RealRectangle2D& destRect,
222 : const ::com::sun::star::rendering::ViewState& destViewState,
223 : const ::com::sun::star::rendering::RenderState& destRenderState );
224 :
225 : ::com::sun::star::geometry::IntegerSize2D getSize();
226 :
227 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
228 : getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
229 : sal_Bool beFast );
230 :
231 : ::com::sun::star::uno::Sequence< sal_Int8 >
232 : getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
233 : const ::com::sun::star::geometry::IntegerRectangle2D& rect );
234 :
235 : void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data,
236 : const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
237 : const ::com::sun::star::geometry::IntegerRectangle2D& rect );
238 :
239 : void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color,
240 : const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
241 : const ::com::sun::star::geometry::IntegerPoint2D& pos );
242 :
243 : ::com::sun::star::uno::Sequence< sal_Int8 >
244 : getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
245 : const ::com::sun::star::geometry::IntegerPoint2D& pos );
246 :
247 : ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
248 :
249 : /** Called from XCanvas base classes, to notify that content
250 : is _about_ to change
251 : */
252 0 : void modifying() {}
253 :
254 : bool hasAlpha() const;
255 :
256 : enum ColorType
257 : {
258 : LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
259 : };
260 :
261 : void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
262 : Operation aOperation,
263 : bool bNoLineJoin = false,
264 : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL,
265 : ::cairo::Cairo* pCairo=NULL ) const;
266 :
267 : ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > implDrawBitmapSurface(
268 : const ::com::sun::star::rendering::XCanvas* pCanvas,
269 : const ::cairo::SurfaceSharedPtr& pSurface,
270 : const ::com::sun::star::rendering::ViewState& viewState,
271 : const ::com::sun::star::rendering::RenderState& renderState,
272 : const ::com::sun::star::geometry::IntegerSize2D& rSize,
273 : bool bModulateColors,
274 : bool bHasAlpha );
275 :
276 : bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
277 : const ::com::sun::star::rendering::ViewState& viewState,
278 : const ::com::sun::star::rendering::RenderState& renderState );
279 :
280 : protected:
281 : /** Surface provider
282 :
283 : Deliberately not a refcounted reference, because of
284 : potential circular references for canvas. Provides us with
285 : our output surface and associated functionality.
286 : */
287 : SurfaceProvider* mpSurfaceProvider;
288 :
289 : /** Phyical output device
290 :
291 : Deliberately not a refcounted reference, because of
292 : potential circular references for spritecanvas.
293 : */
294 : ::com::sun::star::rendering::XGraphicDevice* mpDevice;
295 :
296 : private:
297 :
298 : boost::shared_ptr<VirtualDevice> mpVirtualDevice;
299 :
300 : void useStates( const ::com::sun::star::rendering::ViewState& viewState,
301 : const ::com::sun::star::rendering::RenderState& renderState,
302 : bool setColor );
303 :
304 : com::sun::star::rendering::IntegerBitmapLayout impl_getMemoryLayout( sal_Int32 nWidth, sal_Int32 nHeight );
305 :
306 : /// When true, content is able to represent alpha
307 : bool mbHaveAlpha;
308 :
309 : CairoSharedPtr mpCairo;
310 : SurfaceSharedPtr mpSurface;
311 : ::basegfx::B2ISize maSize;
312 : };
313 :
314 : /// also needed from SpriteHelper
315 : void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon,
316 : Operation aOperation,
317 : ::cairo::Cairo* pCairo,
318 : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures,
319 : const SurfaceProviderRef& pDevice,
320 : ::com::sun::star::rendering::FillRule eFillrule );
321 : }
322 :
323 : #endif /* _CAIROCANVAS_CANVASHELPER_HXX_ */
324 :
325 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|