1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _CAIROCANVAS_CANVASHELPER_HXX_
21 #define _CAIROCANVAS_CANVASHELPER_HXX_
23 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
26 #include <basegfx/vector/b2isize.hxx>
27 #include <basegfx/vector/b2dsize.hxx>
28 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
30 #include <boost/utility.hpp>
32 #include "cairo_cairo.hxx"
33 #include "cairo_surfaceprovider.hxx"
51 class CanvasHelper
: private ::boost::noncopyable
56 /// Release all references
59 /** Initialize canvas helper
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!
70 Size of the output surface in pixel.
73 Reference device this canvas is associated with
76 void init( const ::basegfx::B2ISize
& rSizePixel
,
77 SurfaceProvider
& rSurfaceProvider
,
78 ::com::sun::star::rendering::XGraphicDevice
* pDevice
);
80 void setSize( const ::basegfx::B2ISize
& rSize
);
81 void setSurface( const ::cairo::SurfaceSharedPtr
& pSurface
, bool bHasAlpha
);
83 // CanvasHelper functionality
84 // ==========================
86 // XCanvas (only providing, not implementing the
87 // interface. Also note subtle method parameter differences)
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
);
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
);
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
);
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
);
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
);
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
>
212 // BitmapCanvasHelper functionality
213 // ================================
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
);
225 ::com::sun::star::geometry::IntegerSize2D
getSize();
227 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBitmap
>
228 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D
& newSize
,
231 ::com::sun::star::uno::Sequence
< sal_Int8
>
232 getData( ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
233 const ::com::sun::star::geometry::IntegerRectangle2D
& rect
);
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
);
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
);
243 ::com::sun::star::uno::Sequence
< sal_Int8
>
244 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
245 const ::com::sun::star::geometry::IntegerPoint2D
& pos
);
247 ::com::sun::star::rendering::IntegerBitmapLayout
getMemoryLayout();
249 /** Called from XCanvas base classes, to notify that content
254 bool hasAlpha() const;
258 LINE_COLOR
, FILL_COLOR
, TEXT_COLOR
, IGNORE_COLOR
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;
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
,
276 bool repaint( const ::cairo::SurfaceSharedPtr
& pSurface
,
277 const ::com::sun::star::rendering::ViewState
& viewState
,
278 const ::com::sun::star::rendering::RenderState
& renderState
);
283 Deliberately not a refcounted reference, because of
284 potential circular references for canvas. Provides us with
285 our output surface and associated functionality.
287 SurfaceProvider
* mpSurfaceProvider
;
289 /** Phyical output device
291 Deliberately not a refcounted reference, because of
292 potential circular references for spritecanvas.
294 ::com::sun::star::rendering::XGraphicDevice
* mpDevice
;
298 boost::shared_ptr
<VirtualDevice
> mpVirtualDevice
;
300 void useStates( const ::com::sun::star::rendering::ViewState
& viewState
,
301 const ::com::sun::star::rendering::RenderState
& renderState
,
304 com::sun::star::rendering::IntegerBitmapLayout
impl_getMemoryLayout( sal_Int32 nWidth
, sal_Int32 nHeight
);
306 /// When true, content is able to represent alpha
309 CairoSharedPtr mpCairo
;
310 SurfaceSharedPtr mpSurface
;
311 ::basegfx::B2ISize maSize
;
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
);
323 #endif /* _CAIROCANVAS_CANVASHELPER_HXX_ */
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */