1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_canvashelper.hxx,v $
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 _DXCANVAS_CANVASHELPER_HXX_
32 #define _DXCANVAS_CANVASHELPER_HXX_
34 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <basegfx/vector/b2isize.hxx>
37 #include <basegfx/vector/b2dsize.hxx>
39 #include "dx_graphicsprovider.hxx"
40 #include "dx_gdiplususer.hxx"
41 #include "dx_impltools.hxx"
43 #include <boost/utility.hpp>
48 /** Helper class for basic canvas functionality. Also offers
49 optional backbuffer painting, when providing it with a second
52 class CanvasHelper
: private ::boost::noncopyable
57 /// Release all references
60 /** Initialize canvas helper
62 This method late-initializes the canvas helper, providing
63 it with the necessary device and output objects. Note that
64 the CanvasHelper does <em>not</em> take ownership of the
65 passed rDevice reference, nor does it perform any
66 reference counting. Thus, to prevent the reference counted
67 SpriteCanvas object from deletion, the user of this class
68 is responsible for holding ref-counted references itself!
71 Reference device this canvas is associated with
74 void setDevice( com::sun::star::rendering::XGraphicDevice
& rDevice
);
76 /** Set the target for rendering operations
81 void setTarget( const GraphicsProviderSharedPtr
& rTarget
);
83 /** Set the target for rendering operations
89 Output offset in pixel
91 void setTarget( const GraphicsProviderSharedPtr
& rTarget
,
92 const ::basegfx::B2ISize
& rOutputOffset
);
95 // CanvasHelper functionality
96 // ==========================
98 // XCanvas (only providing, not implementing the
99 // interface. Also note subtle method parameter differences)
101 void drawPoint( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
102 const ::com::sun::star::geometry::RealPoint2D
& aPoint
,
103 const ::com::sun::star::rendering::ViewState
& viewState
,
104 const ::com::sun::star::rendering::RenderState
& renderState
);
105 void drawLine( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
106 const ::com::sun::star::geometry::RealPoint2D
& aStartPoint
,
107 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
108 const ::com::sun::star::rendering::ViewState
& viewState
,
109 const ::com::sun::star::rendering::RenderState
& renderState
);
110 void drawBezier( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
111 const ::com::sun::star::geometry::RealBezierSegment2D
& aBezierSegment
,
112 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
113 const ::com::sun::star::rendering::ViewState
& viewState
,
114 const ::com::sun::star::rendering::RenderState
& renderState
);
115 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
116 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
117 const ::com::sun::star::uno::Reference
<
118 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
119 const ::com::sun::star::rendering::ViewState
& viewState
,
120 const ::com::sun::star::rendering::RenderState
& renderState
);
121 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
122 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
123 const ::com::sun::star::uno::Reference
<
124 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
125 const ::com::sun::star::rendering::ViewState
& viewState
,
126 const ::com::sun::star::rendering::RenderState
& renderState
,
127 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
128 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
129 strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
130 const ::com::sun::star::uno::Reference
<
131 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
132 const ::com::sun::star::rendering::ViewState
& viewState
,
133 const ::com::sun::star::rendering::RenderState
& renderState
,
134 const ::com::sun::star::uno::Sequence
<
135 ::com::sun::star::rendering::Texture
>& textures
,
136 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
137 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
138 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
139 const ::com::sun::star::uno::Reference
<
140 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
141 const ::com::sun::star::rendering::ViewState
& viewState
,
142 const ::com::sun::star::rendering::RenderState
& renderState
,
143 const ::com::sun::star::uno::Sequence
<
144 ::com::sun::star::rendering::Texture
>& textures
,
145 const ::com::sun::star::uno::Reference
<
146 ::com::sun::star::geometry::XMapping2D
>& xMapping
,
147 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
148 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XPolyPolygon2D
>
149 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
150 const ::com::sun::star::uno::Reference
<
151 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
152 const ::com::sun::star::rendering::ViewState
& viewState
,
153 const ::com::sun::star::rendering::RenderState
& renderState
,
154 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
155 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
156 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
157 const ::com::sun::star::uno::Reference
<
158 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
159 const ::com::sun::star::rendering::ViewState
& viewState
,
160 const ::com::sun::star::rendering::RenderState
& renderState
);
161 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
162 fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
163 const ::com::sun::star::uno::Reference
<
164 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
165 const ::com::sun::star::rendering::ViewState
& viewState
,
166 const ::com::sun::star::rendering::RenderState
& renderState
,
167 const ::com::sun::star::uno::Sequence
<
168 ::com::sun::star::rendering::Texture
>& textures
);
169 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
170 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
171 const ::com::sun::star::uno::Reference
<
172 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
173 const ::com::sun::star::rendering::ViewState
& viewState
,
174 const ::com::sun::star::rendering::RenderState
& renderState
,
175 const ::com::sun::star::uno::Sequence
<
176 ::com::sun::star::rendering::Texture
>& textures
,
177 const ::com::sun::star::uno::Reference
<
178 ::com::sun::star::geometry::XMapping2D
>& xMapping
);
180 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCanvasFont
> SAL_CALL
181 createFont( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
182 const ::com::sun::star::rendering::FontRequest
& fontRequest
,
183 const ::com::sun::star::uno::Sequence
<
184 ::com::sun::star::beans::PropertyValue
>& extraFontProperties
,
185 const ::com::sun::star::geometry::Matrix2D
& fontMatrix
);
187 ::com::sun::star::uno::Sequence
< ::com::sun::star::rendering::FontInfo
>
188 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
189 const ::com::sun::star::rendering::FontInfo
& aFilter
,
190 const ::com::sun::star::uno::Sequence
<
191 ::com::sun::star::beans::PropertyValue
>& aFontProperties
);
193 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
194 drawText( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
195 const ::com::sun::star::rendering::StringContext
& text
,
196 const ::com::sun::star::uno::Reference
<
197 ::com::sun::star::rendering::XCanvasFont
>& xFont
,
198 const ::com::sun::star::rendering::ViewState
& viewState
,
199 const ::com::sun::star::rendering::RenderState
& renderState
,
200 sal_Int8 textDirection
);
202 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
203 drawTextLayout( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
204 const ::com::sun::star::uno::Reference
<
205 ::com::sun::star::rendering::XTextLayout
>& layoutetText
,
206 const ::com::sun::star::rendering::ViewState
& viewState
,
207 const ::com::sun::star::rendering::RenderState
& renderState
);
209 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
210 drawBitmap( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
211 const ::com::sun::star::uno::Reference
<
212 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
213 const ::com::sun::star::rendering::ViewState
& viewState
,
214 const ::com::sun::star::rendering::RenderState
& renderState
);
215 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
>
216 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas
* pCanvas
,
217 const ::com::sun::star::uno::Reference
<
218 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
219 const ::com::sun::star::rendering::ViewState
& viewState
,
220 const ::com::sun::star::rendering::RenderState
& renderState
);
221 ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XGraphicDevice
>
224 // Flush drawing queue to screen
227 /** Called from XCanvas base classes, to notify that content
233 /// Refcounted global GDI+ state container
234 GDIPlusUserSharedPtr mpGdiPlusUser
;
236 /** Phyical output device
238 Deliberately not a refcounted reference, because of
239 potential circular references for spritecanvas.
241 com::sun::star::rendering::XGraphicDevice
* mpDevice
;
243 /// Provides the Gdiplus::Graphics to render into
244 GraphicsProviderSharedPtr mpGraphicsProvider
;
246 bool needOutput() const { return mpGraphicsProvider
.get() != NULL
; };
248 // returns transparency of color
249 void setupGraphicsState( GraphicsSharedPtr
& rGraphics
,
250 const ::com::sun::star::rendering::ViewState
& viewState
,
251 const ::com::sun::star::rendering::RenderState
& renderState
);
253 Gdiplus::CompositingMode
calcCompositingMode( sal_Int8 nMode
);
255 /// Current (transformation-independent) output buffer offset
256 ::basegfx::B2ISize maOutputOffset
;
260 #endif /* _DXCANVAS_CANVASHELPER_HXX_ */