1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _CAIROCANVAS_CANVASHELPER_HXX_ 29 #define _CAIROCANVAS_CANVASHELPER_HXX_ 30 31 #include <com/sun/star/rendering/XCanvas.hpp> 32 #include <com/sun/star/rendering/XIntegerBitmap.hpp> 33 34 #include <basegfx/vector/b2isize.hxx> 35 #include <basegfx/vector/b2dsize.hxx> 36 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp> 37 38 #include <boost/utility.hpp> 39 40 #include "cairo_cairo.hxx" 41 #include "cairo_surfaceprovider.hxx" 42 43 class VirtualDevice; 44 45 namespace basegfx { 46 class B2DPolyPolygon; 47 } 48 49 namespace cairocanvas 50 { 51 class SpriteCanvas; 52 53 enum Operation { 54 Stroke, 55 Fill, 56 Clip 57 }; 58 59 class CanvasHelper : private ::boost::noncopyable 60 { 61 public: 62 CanvasHelper(); 63 64 /// Release all references 65 void disposing(); 66 67 /** Initialize canvas helper 68 69 This method late-initializes the canvas helper, providing 70 it with the necessary device and size. Note that the 71 CanvasHelper does <em>not</em> take ownership of the 72 passed rDevice reference, nor does it perform any 73 reference counting. Thus, to prevent the reference counted 74 SpriteCanvas object from deletion, the user of this class 75 is responsible for holding ref-counted references itself! 76 77 @param rSizePixel 78 Size of the output surface in pixel. 79 80 @param rDevice 81 Reference device this canvas is associated with 82 83 */ 84 void init( const ::basegfx::B2ISize& rSizePixel, 85 SurfaceProvider& rSurfaceProvider, 86 ::com::sun::star::rendering::XGraphicDevice* pDevice ); 87 88 void setSize( const ::basegfx::B2ISize& rSize ); 89 void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha ); 90 91 // CanvasHelper functionality 92 // ========================== 93 94 // XCanvas (only providing, not implementing the 95 // interface. Also note subtle method parameter differences) 96 void clear(); 97 void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, 98 const ::com::sun::star::geometry::RealPoint2D& aPoint, 99 const ::com::sun::star::rendering::ViewState& viewState, 100 const ::com::sun::star::rendering::RenderState& renderState ); 101 void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas, 102 const ::com::sun::star::geometry::RealPoint2D& aStartPoint, 103 const ::com::sun::star::geometry::RealPoint2D& aEndPoint, 104 const ::com::sun::star::rendering::ViewState& viewState, 105 const ::com::sun::star::rendering::RenderState& renderState ); 106 void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas, 107 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, 108 const ::com::sun::star::geometry::RealPoint2D& aEndPoint, 109 const ::com::sun::star::rendering::ViewState& viewState, 110 const ::com::sun::star::rendering::RenderState& renderState ); 111 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 112 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 113 const ::com::sun::star::uno::Reference< 114 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 115 const ::com::sun::star::rendering::ViewState& viewState, 116 const ::com::sun::star::rendering::RenderState& renderState ); 117 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 118 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 119 const ::com::sun::star::uno::Reference< 120 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 121 const ::com::sun::star::rendering::ViewState& viewState, 122 const ::com::sun::star::rendering::RenderState& renderState, 123 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 124 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 125 strokeTexturedPolyPolygon( 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::rendering::StrokeAttributes& strokeAttributes ); 133 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 134 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 135 const ::com::sun::star::uno::Reference< 136 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 137 const ::com::sun::star::rendering::ViewState& viewState, 138 const ::com::sun::star::rendering::RenderState& renderState, 139 const ::com::sun::star::uno::Sequence< 140 ::com::sun::star::rendering::Texture >& textures, 141 const ::com::sun::star::uno::Reference< 142 ::com::sun::star::geometry::XMapping2D >& xMapping, 143 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 144 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > 145 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas, 146 const ::com::sun::star::uno::Reference< 147 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 148 const ::com::sun::star::rendering::ViewState& viewState, 149 const ::com::sun::star::rendering::RenderState& renderState, 150 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 151 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 152 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 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 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 158 fillTexturedPolyPolygon( 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 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 166 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 167 const ::com::sun::star::uno::Reference< 168 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 169 const ::com::sun::star::rendering::ViewState& viewState, 170 const ::com::sun::star::rendering::RenderState& renderState, 171 const ::com::sun::star::uno::Sequence< 172 ::com::sun::star::rendering::Texture >& textures, 173 const ::com::sun::star::uno::Reference< 174 ::com::sun::star::geometry::XMapping2D >& xMapping ); 175 176 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL 177 createFont( const ::com::sun::star::rendering::XCanvas* pCanvas, 178 const ::com::sun::star::rendering::FontRequest& fontRequest, 179 const ::com::sun::star::uno::Sequence< 180 ::com::sun::star::beans::PropertyValue >& extraFontProperties, 181 const ::com::sun::star::geometry::Matrix2D& fontMatrix ); 182 183 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo > 184 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas, 185 const ::com::sun::star::rendering::FontInfo& aFilter, 186 const ::com::sun::star::uno::Sequence< 187 ::com::sun::star::beans::PropertyValue >& aFontProperties ); 188 189 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 190 drawText( const ::com::sun::star::rendering::XCanvas* pCanvas, 191 const ::com::sun::star::rendering::StringContext& text, 192 const ::com::sun::star::uno::Reference< 193 ::com::sun::star::rendering::XCanvasFont >& xFont, 194 const ::com::sun::star::rendering::ViewState& viewState, 195 const ::com::sun::star::rendering::RenderState& renderState, 196 sal_Int8 textDirection ); 197 198 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 199 drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas, 200 const ::com::sun::star::uno::Reference< 201 ::com::sun::star::rendering::XTextLayout >& layoutetText, 202 const ::com::sun::star::rendering::ViewState& viewState, 203 const ::com::sun::star::rendering::RenderState& renderState ); 204 205 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 206 drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas, 207 const ::com::sun::star::uno::Reference< 208 ::com::sun::star::rendering::XBitmap >& xBitmap, 209 const ::com::sun::star::rendering::ViewState& viewState, 210 const ::com::sun::star::rendering::RenderState& renderState ); 211 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 212 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas, 213 const ::com::sun::star::uno::Reference< 214 ::com::sun::star::rendering::XBitmap >& xBitmap, 215 const ::com::sun::star::rendering::ViewState& viewState, 216 const ::com::sun::star::rendering::RenderState& renderState ); 217 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > 218 getDevice(); 219 220 // BitmapCanvasHelper functionality 221 // ================================ 222 223 void copyRect( const ::com::sun::star::rendering::XCanvas* pCanvas, 224 const ::com::sun::star::uno::Reference< 225 ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, 226 const ::com::sun::star::geometry::RealRectangle2D& sourceRect, 227 const ::com::sun::star::rendering::ViewState& sourceViewState, 228 const ::com::sun::star::rendering::RenderState& sourceRenderState, 229 const ::com::sun::star::geometry::RealRectangle2D& destRect, 230 const ::com::sun::star::rendering::ViewState& destViewState, 231 const ::com::sun::star::rendering::RenderState& destRenderState ); 232 233 ::com::sun::star::geometry::IntegerSize2D getSize(); 234 235 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > 236 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize, 237 sal_Bool beFast ); 238 239 ::com::sun::star::uno::Sequence< sal_Int8 > 240 getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 241 const ::com::sun::star::geometry::IntegerRectangle2D& rect ); 242 243 void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data, 244 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 245 const ::com::sun::star::geometry::IntegerRectangle2D& rect ); 246 247 void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color, 248 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 249 const ::com::sun::star::geometry::IntegerPoint2D& pos ); 250 251 ::com::sun::star::uno::Sequence< sal_Int8 > 252 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 253 const ::com::sun::star::geometry::IntegerPoint2D& pos ); 254 255 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapPalette > getPalette(); 256 257 ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout(); 258 259 // Flush drawing queue to screen 260 void flush() const; 261 262 /** Called from XCanvas base classes, to notify that content 263 is _about_ to change 264 */ 265 void modifying() {} 266 267 bool hasAlpha() const; 268 269 enum ColorType 270 { 271 LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR 272 }; 273 274 void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 275 Operation aOperation, 276 bool bNoLineJoin = false, 277 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL, 278 ::cairo::Cairo* pCairo=NULL ) const; 279 280 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 281 implDrawBitmapSurface( 282 const ::com::sun::star::rendering::XCanvas* pCanvas, 283 const ::cairo::SurfaceSharedPtr& pSurface, 284 const ::com::sun::star::rendering::ViewState& viewState, 285 const ::com::sun::star::rendering::RenderState& renderState, 286 const ::com::sun::star::geometry::IntegerSize2D& rSize, 287 bool bModulateColors, 288 bool bHasAlpha ); 289 290 bool repaint( const ::cairo::SurfaceSharedPtr& pSurface, 291 const ::com::sun::star::rendering::ViewState& viewState, 292 const ::com::sun::star::rendering::RenderState& renderState ); 293 294 protected: 295 /** Surface provider 296 297 Deliberately not a refcounted reference, because of 298 potential circular references for canvas. Provides us with 299 our output surface and associated functionality. 300 */ 301 SurfaceProvider* mpSurfaceProvider; 302 303 /** Phyical output device 304 305 Deliberately not a refcounted reference, because of 306 potential circular references for spritecanvas. 307 */ 308 ::com::sun::star::rendering::XGraphicDevice* mpDevice; 309 310 private: 311 312 boost::shared_ptr<VirtualDevice> mpVirtualDevice; 313 314 void useStates( const ::com::sun::star::rendering::ViewState& viewState, 315 const ::com::sun::star::rendering::RenderState& renderState, 316 bool setColor ); 317 318 /// When true, content is able to represent alpha 319 bool mbHaveAlpha; 320 321 CairoSharedPtr mpCairo; 322 SurfaceSharedPtr mpSurface; 323 ::basegfx::B2ISize maSize; 324 }; 325 326 /// also needed from SpriteHelper 327 void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon, 328 Operation aOperation, 329 ::cairo::Cairo* pCairo, 330 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures, 331 const SurfaceProviderRef& pDevice, 332 ::com::sun::star::rendering::FillRule eFillrule ); 333 } 334 335 #endif /* _CAIROCANVAS_CANVASHELPER_HXX_ */ 336