Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / cairo / cairo_canvashelper.hxx
blobed6f702a53aad0ad3bd3522427f6719910e75bf5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_CANVAS_SOURCE_CAIRO_CAIRO_CANVASHELPER_HXX
21 #define INCLUDED_CANVAS_SOURCE_CAIRO_CAIRO_CANVASHELPER_HXX
23 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
25 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
27 #include <basegfx/vector/b2isize.hxx>
28 #include <basegfx/vector/b2dsize.hxx>
29 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
31 #include <vcl/vclptr.hxx>
32 #include <vcl/virdev.hxx>
33 #include <boost/utility.hpp>
35 #include <vcl/cairo.hxx>
36 #include "cairo_surfaceprovider.hxx"
38 class VirtualDevice;
40 namespace basegfx {
41 class B2DPolyPolygon;
44 namespace cairocanvas
46 class SpriteCanvas;
48 enum Operation {
49 Stroke,
50 Fill,
51 Clip
54 class CanvasHelper : private ::boost::noncopyable
56 public:
57 CanvasHelper();
59 /// Release all references
60 void disposing();
62 /** Initialize canvas helper
64 This method late-initializes the canvas helper, providing
65 it with the necessary device and size. Note that the
66 CanvasHelper does <em>not</em> take ownership of the
67 passed rDevice reference, nor does it perform any
68 reference counting. Thus, to prevent the reference counted
69 SpriteCanvas object from deletion, the user of this class
70 is responsible for holding ref-counted references itself!
72 @param rSizePixel
73 Size of the output surface in pixel.
75 @param rDevice
76 Reference device this canvas is associated with
79 void init( const ::basegfx::B2ISize& rSizePixel,
80 SurfaceProvider& rSurfaceProvider,
81 ::com::sun::star::rendering::XGraphicDevice* pDevice );
83 void setSize( const ::basegfx::B2ISize& rSize );
84 void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha );
86 // CanvasHelper functionality
87 // ==========================
89 // XCanvas (only providing, not implementing the
90 // interface. Also note subtle method parameter differences)
91 void clear();
92 void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas,
93 const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
94 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
95 const ::com::sun::star::rendering::ViewState& viewState,
96 const ::com::sun::star::rendering::RenderState& renderState );
97 void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas,
98 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
99 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
100 const ::com::sun::star::rendering::ViewState& viewState,
101 const ::com::sun::star::rendering::RenderState& renderState );
102 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
103 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
104 const ::com::sun::star::uno::Reference<
105 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
106 const ::com::sun::star::rendering::ViewState& viewState,
107 const ::com::sun::star::rendering::RenderState& renderState );
108 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
109 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
110 const ::com::sun::star::uno::Reference<
111 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
112 const ::com::sun::star::rendering::ViewState& viewState,
113 const ::com::sun::star::rendering::RenderState& renderState,
114 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
115 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
116 strokeTexturedPolyPolygon( 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 const ::com::sun::star::uno::Sequence<
122 ::com::sun::star::rendering::Texture >& textures,
123 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
124 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
125 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
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::uno::Sequence<
131 ::com::sun::star::rendering::Texture >& textures,
132 const ::com::sun::star::uno::Reference<
133 ::com::sun::star::geometry::XMapping2D >& xMapping,
134 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
135 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
136 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas,
137 const ::com::sun::star::uno::Reference<
138 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
139 const ::com::sun::star::rendering::ViewState& viewState,
140 const ::com::sun::star::rendering::RenderState& renderState,
141 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
142 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
143 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
144 const ::com::sun::star::uno::Reference<
145 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
146 const ::com::sun::star::rendering::ViewState& viewState,
147 const ::com::sun::star::rendering::RenderState& renderState );
148 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
149 fillTexturedPolyPolygon( 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::uno::Sequence<
155 ::com::sun::star::rendering::Texture >& textures );
156 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
157 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas,
158 const ::com::sun::star::uno::Reference<
159 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
160 const ::com::sun::star::rendering::ViewState& viewState,
161 const ::com::sun::star::rendering::RenderState& renderState,
162 const ::com::sun::star::uno::Sequence<
163 ::com::sun::star::rendering::Texture >& textures,
164 const ::com::sun::star::uno::Reference<
165 ::com::sun::star::geometry::XMapping2D >& xMapping );
167 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
168 createFont( const ::com::sun::star::rendering::XCanvas* pCanvas,
169 const ::com::sun::star::rendering::FontRequest& fontRequest,
170 const ::com::sun::star::uno::Sequence<
171 ::com::sun::star::beans::PropertyValue >& extraFontProperties,
172 const ::com::sun::star::geometry::Matrix2D& fontMatrix );
174 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
175 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas,
176 const ::com::sun::star::rendering::FontInfo& aFilter,
177 const ::com::sun::star::uno::Sequence<
178 ::com::sun::star::beans::PropertyValue >& aFontProperties );
180 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
181 drawText( const ::com::sun::star::rendering::XCanvas* pCanvas,
182 const ::com::sun::star::rendering::StringContext& text,
183 const ::com::sun::star::uno::Reference<
184 ::com::sun::star::rendering::XCanvasFont >& xFont,
185 const ::com::sun::star::rendering::ViewState& viewState,
186 const ::com::sun::star::rendering::RenderState& renderState,
187 sal_Int8 textDirection );
189 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
190 drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas,
191 const ::com::sun::star::uno::Reference<
192 ::com::sun::star::rendering::XTextLayout >& laidOutText,
193 const ::com::sun::star::rendering::ViewState& viewState,
194 const ::com::sun::star::rendering::RenderState& renderState );
196 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
197 drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas,
198 const ::com::sun::star::uno::Reference<
199 ::com::sun::star::rendering::XBitmap >& xBitmap,
200 const ::com::sun::star::rendering::ViewState& viewState,
201 const ::com::sun::star::rendering::RenderState& renderState );
202 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
203 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas,
204 const ::com::sun::star::uno::Reference<
205 ::com::sun::star::rendering::XBitmap >& xBitmap,
206 const ::com::sun::star::rendering::ViewState& viewState,
207 const ::com::sun::star::rendering::RenderState& renderState );
208 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
209 getDevice() { return css::uno::Reference< css::rendering::XGraphicDevice >(mpDevice); }
211 // BitmapCanvasHelper functionality
212 // ================================
214 ::com::sun::star::geometry::IntegerSize2D getSize();
216 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
217 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
218 bool beFast );
220 ::com::sun::star::uno::Sequence< sal_Int8 >
221 getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
222 const ::com::sun::star::geometry::IntegerRectangle2D& rect );
224 ::com::sun::star::uno::Sequence< sal_Int8 >
225 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
226 const ::com::sun::star::geometry::IntegerPoint2D& pos );
228 ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
230 bool hasAlpha() const { return mbHaveAlpha; }
232 enum ColorType
234 LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
237 void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
238 Operation aOperation,
239 bool bNoLineJoin = false,
240 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL,
241 cairo_t* pCairo=NULL ) const;
243 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > implDrawBitmapSurface(
244 const ::com::sun::star::rendering::XCanvas* pCanvas,
245 const ::cairo::SurfaceSharedPtr& pSurface,
246 const ::com::sun::star::rendering::ViewState& viewState,
247 const ::com::sun::star::rendering::RenderState& renderState,
248 const ::com::sun::star::geometry::IntegerSize2D& rSize,
249 bool bModulateColors,
250 bool bHasAlpha );
252 bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
253 const ::com::sun::star::rendering::ViewState& viewState,
254 const ::com::sun::star::rendering::RenderState& renderState );
256 protected:
257 /** Surface provider
259 Deliberately not a refcounted reference, because of
260 potential circular references for canvas. Provides us with
261 our output surface and associated functionality.
263 SurfaceProvider* mpSurfaceProvider;
265 /** Phyical output device
267 Deliberately not a refcounted reference, because of
268 potential circular references for spritecanvas.
270 ::com::sun::star::rendering::XGraphicDevice* mpDevice;
272 private:
274 VclPtr<VirtualDevice> mpVirtualDevice;
276 void useStates( const ::com::sun::star::rendering::ViewState& viewState,
277 const ::com::sun::star::rendering::RenderState& renderState,
278 bool setColor );
280 com::sun::star::rendering::IntegerBitmapLayout impl_getMemoryLayout( sal_Int32 nWidth, sal_Int32 nHeight );
282 /// When true, content is able to represent alpha
283 bool mbHaveAlpha;
285 ::cairo::CairoSharedPtr mpCairo;
286 ::cairo::SurfaceSharedPtr mpSurface;
287 ::basegfx::B2ISize maSize;
289 void clip_cairo_from_dev(::OutputDevice& rOutDev);
293 /// also needed from SpriteHelper
294 void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon,
295 Operation aOperation,
296 cairo_t* pCairo,
297 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures,
298 const SurfaceProviderRef& pDevice,
299 ::com::sun::star::rendering::FillRule eFillrule );
302 #endif // INCLUDED_CANVAS_SOURCE_CAIRO_CAIRO_CANVASHELPER_HXX
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */