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 _VCLCANVAS_CANVASHELPER_HXX_
21 #define _VCLCANVAS_CANVASHELPER_HXX_
23 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
26 #include <vcl/outdev.hxx>
28 #include <canvas/vclwrapper.hxx>
30 #include "cachedbitmap.hxx"
31 #include "outdevprovider.hxx"
33 #include <boost/utility.hpp>
40 /** Helper class for basic canvas functionality. Also offers
41 optional backbuffer painting, when providing it with a second
42 OutputDevice to render into.
44 class CanvasHelper
: private ::boost::noncopyable
47 /** Create canvas helper
51 /// Release all references
54 /** Initialize canvas helper
56 This method late-initializes the canvas helper, providing
57 it with the necessary device and output objects. Note that
58 the CanvasHelper does <em>not</em> take ownership of the
59 passed rDevice reference, nor does it perform any
60 reference counting. Thus, to prevent the reference counted
61 SpriteCanvas object from deletion, the user of this class
62 is responsible for holding ref-counted references itself!
65 Reference device this canvas is associated with
68 Set primary output device for this canvas. That's where
69 all content is output to.
72 When true, all output operations preserve outdev
73 state. When false, outdev state might change at any time.
76 When true, hasAlpha() will always return true, otherwise, false.
78 void init( ::com::sun::star::rendering::XGraphicDevice
& rDevice
,
79 const OutDevProviderSharedPtr
& rOutDev
,
83 /** Set primary output device
85 This changes the primary output device, where rendering is
88 void setOutDev( const OutDevProviderSharedPtr
& rOutDev
,
91 /** Set secondary output device
93 Used for sprites, to generate mask bitmap.
95 void setBackgroundOutDev( const OutDevProviderSharedPtr
& rOutDev
);
98 // CanvasHelper functionality
99 // ==========================
101 // XCanvas (only providing, not implementing the
102 // interface. Also note subtle method parameter differences)
104 void drawPoint( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
105 const ::com::sun::star::geometry::RealPoint2D
& aPoint
,
106 const ::com::sun::star::rendering::ViewState
& viewState
,
107 const ::com::sun::star::rendering::RenderState
& renderState
);
108 void drawLine( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
109 const ::com::sun::star::geometry::RealPoint2D
& aStartPoint
,
110 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
111 const ::com::sun::star::rendering::ViewState
& viewState
,
112 const ::com::sun::star::rendering::RenderState
& renderState
);
113 void drawBezier( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
114 const ::com::sun::star::geometry::RealBezierSegment2D
& aBezierSegment
,
115 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
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 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
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 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
125 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
126 const ::com::sun::star::uno::Reference
<
127 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
128 const ::com::sun::star::rendering::ViewState
& viewState
,
129 const ::com::sun::star::rendering::RenderState
& renderState
,
130 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
131 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
132 strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
133 const ::com::sun::star::uno::Reference
<
134 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
135 const ::com::sun::star::rendering::ViewState
& viewState
,
136 const ::com::sun::star::rendering::RenderState
& renderState
,
137 const ::com::sun::star::uno::Sequence
<
138 ::com::sun::star::rendering::Texture
>& textures
,
139 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
140 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
141 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
142 const ::com::sun::star::uno::Reference
<
143 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
144 const ::com::sun::star::rendering::ViewState
& viewState
,
145 const ::com::sun::star::rendering::RenderState
& renderState
,
146 const ::com::sun::star::uno::Sequence
<
147 ::com::sun::star::rendering::Texture
>& textures
,
148 const ::com::sun::star::uno::Reference
<
149 ::com::sun::star::geometry::XMapping2D
>& xMapping
,
150 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
151 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XPolyPolygon2D
>
152 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
153 const ::com::sun::star::uno::Reference
<
154 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
155 const ::com::sun::star::rendering::ViewState
& viewState
,
156 const ::com::sun::star::rendering::RenderState
& renderState
,
157 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
158 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
159 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
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 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
165 fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
166 const ::com::sun::star::uno::Reference
<
167 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
168 const ::com::sun::star::rendering::ViewState
& viewState
,
169 const ::com::sun::star::rendering::RenderState
& renderState
,
170 const ::com::sun::star::uno::Sequence
<
171 ::com::sun::star::rendering::Texture
>& textures
);
172 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
173 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
174 const ::com::sun::star::uno::Reference
<
175 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
176 const ::com::sun::star::rendering::ViewState
& viewState
,
177 const ::com::sun::star::rendering::RenderState
& renderState
,
178 const ::com::sun::star::uno::Sequence
<
179 ::com::sun::star::rendering::Texture
>& textures
,
180 const ::com::sun::star::uno::Reference
<
181 ::com::sun::star::geometry::XMapping2D
>& xMapping
);
183 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCanvasFont
>
184 createFont( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
185 const ::com::sun::star::rendering::FontRequest
& fontRequest
,
186 const ::com::sun::star::uno::Sequence
<
187 ::com::sun::star::beans::PropertyValue
>& extraFontProperties
,
188 const ::com::sun::star::geometry::Matrix2D
& fontMatrix
);
190 ::com::sun::star::uno::Sequence
< ::com::sun::star::rendering::FontInfo
>
191 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
192 const ::com::sun::star::rendering::FontInfo
& aFilter
,
193 const ::com::sun::star::uno::Sequence
<
194 ::com::sun::star::beans::PropertyValue
>& aFontProperties
);
196 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
197 drawText( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
198 const ::com::sun::star::rendering::StringContext
& text
,
199 const ::com::sun::star::uno::Reference
<
200 ::com::sun::star::rendering::XCanvasFont
>& xFont
,
201 const ::com::sun::star::rendering::ViewState
& viewState
,
202 const ::com::sun::star::rendering::RenderState
& renderState
,
203 sal_Int8 textDirection
);
205 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
206 drawTextLayout( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
207 const ::com::sun::star::uno::Reference
<
208 ::com::sun::star::rendering::XTextLayout
>& layoutetText
,
209 const ::com::sun::star::rendering::ViewState
& viewState
,
210 const ::com::sun::star::rendering::RenderState
& renderState
);
212 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
213 drawBitmap( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
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::XCachedPrimitive
>
219 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
220 const ::com::sun::star::uno::Reference
<
221 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
222 const ::com::sun::star::rendering::ViewState
& viewState
,
223 const ::com::sun::star::rendering::RenderState
& renderState
);
224 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XGraphicDevice
>
227 // BitmapCanvasHelper functionality
228 // ================================
230 void copyRect( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
231 const ::com::sun::star::uno::Reference
<
232 ::com::sun::star::rendering::XBitmapCanvas
>& sourceCanvas
,
233 const ::com::sun::star::geometry::RealRectangle2D
& sourceRect
,
234 const ::com::sun::star::rendering::ViewState
& sourceViewState
,
235 const ::com::sun::star::rendering::RenderState
& sourceRenderState
,
236 const ::com::sun::star::geometry::RealRectangle2D
& destRect
,
237 const ::com::sun::star::rendering::ViewState
& destViewState
,
238 const ::com::sun::star::rendering::RenderState
& destRenderState
);
240 ::com::sun::star::geometry::IntegerSize2D
getSize();
242 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBitmapCanvas
> queryBitmapCanvas();
244 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBitmap
>
245 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D
& newSize
,
248 ::com::sun::star::uno::Sequence
< sal_Int8
>
249 getData( ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
250 const ::com::sun::star::geometry::IntegerRectangle2D
& rect
);
252 void setData( const ::com::sun::star::uno::Sequence
< sal_Int8
>& data
,
253 const ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
254 const ::com::sun::star::geometry::IntegerRectangle2D
& rect
);
256 void setPixel( const ::com::sun::star::uno::Sequence
< sal_Int8
>& color
,
257 const ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
258 const ::com::sun::star::geometry::IntegerPoint2D
& pos
);
260 ::com::sun::star::uno::Sequence
< sal_Int8
>
261 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout
& bitmapLayout
,
262 const ::com::sun::star::geometry::IntegerPoint2D
& pos
);
264 ::com::sun::star::rendering::IntegerBitmapLayout
getMemoryLayout();
266 /// Repaint a cached bitmap
267 bool repaint( const GraphicObjectSharedPtr
& rGrf
,
268 const ::com::sun::star::rendering::ViewState
& viewState
,
269 const ::com::sun::star::rendering::RenderState
& renderState
,
272 const GraphicAttr
& rAttr
) const;
274 /** Flush drawing queue.
276 This only works for Window canvases, and ensures that all
277 pending render operations are flushed to the
284 LINE_COLOR
, FILL_COLOR
, TEXT_COLOR
, IGNORE_COLOR
287 // returns transparency of color
288 int setupOutDevState( const ::com::sun::star::rendering::ViewState
& viewState
,
289 const ::com::sun::star::rendering::RenderState
& renderState
,
290 ColorType eColorType
) const;
292 /** Called from XCanvas base classes, to notify that content
297 bool hasAlpha() const { return mbHaveAlpha
; }
300 /** Phyical output device
302 Deliberately not a refcounted reference, because of
303 potential circular references for spritecanvas.
305 ::com::sun::star::rendering::XGraphicDevice
* mpDevice
;
307 /// Rendering to this outdev preserves its state
308 OutDevProviderSharedPtr mpProtectedOutDev
;
310 /// Rendering to this outdev does not preserve its state
311 OutDevProviderSharedPtr mpOutDev
;
313 /// Rendering to this outdev does not preserve its state
314 OutDevProviderSharedPtr mp2ndOutDev
;
316 /// When true, content is able to represent alpha
320 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
321 implDrawBitmap( const ::com::sun::star::rendering::XCanvas
* rCanvas
,
322 const ::com::sun::star::uno::Reference
<
323 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
324 const ::com::sun::star::rendering::ViewState
& viewState
,
325 const ::com::sun::star::rendering::RenderState
& renderState
,
326 bool bModulateColors
);
328 bool setupTextOutput( ::Point
& o_rOutPos
,
329 const ::com::sun::star::rendering::ViewState
& viewState
,
330 const ::com::sun::star::rendering::RenderState
& renderState
,
331 const ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCanvasFont
>& xFont
) const;
336 #endif /* _VCLCANVAS_CANVASHELPER_HXX_ */
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */