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 _NULLCANVAS_CANVASHELPER_HXX_ 29 #define _NULLCANVAS_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 37 #include <boost/utility.hpp> 38 39 40 namespace nullcanvas 41 { 42 class SpriteCanvas; 43 44 /** Helper class for basic canvas functionality. Also offers 45 optional backbuffer painting, when providing it with a second 46 HDC to render into. 47 */ 48 class CanvasHelper : private ::boost::noncopyable 49 { 50 public: 51 CanvasHelper(); 52 53 /// Release all references 54 void disposing(); 55 56 /** Initialize canvas helper 57 58 This method late-initializes the canvas helper, providing 59 it with the necessary device and size. Note that the 60 CanvasHelper does <em>not</em> take ownership of the 61 passed rDevice reference, nor does it perform any 62 reference counting. Thus, to prevent the reference counted 63 SpriteCanvas object from deletion, the user of this class 64 is responsible for holding ref-counted references itself! 65 66 @param rSizePixel 67 Size of the output surface in pixel. 68 69 @param rDevice 70 Reference device this canvas is associated with 71 72 */ 73 void init( const ::basegfx::B2ISize& rSizePixel, 74 SpriteCanvas& rDevice, 75 bool bHasAlpha ); 76 77 78 // CanvasHelper functionality 79 // ========================== 80 81 // XCanvas (only providing, not implementing the 82 // interface. Also note subtle method parameter differences) 83 void clear(); 84 void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, 85 const ::com::sun::star::geometry::RealPoint2D& aPoint, 86 const ::com::sun::star::rendering::ViewState& viewState, 87 const ::com::sun::star::rendering::RenderState& renderState ); 88 void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas, 89 const ::com::sun::star::geometry::RealPoint2D& aStartPoint, 90 const ::com::sun::star::geometry::RealPoint2D& aEndPoint, 91 const ::com::sun::star::rendering::ViewState& viewState, 92 const ::com::sun::star::rendering::RenderState& renderState ); 93 void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas, 94 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, 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 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 99 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 100 const ::com::sun::star::uno::Reference< 101 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 102 const ::com::sun::star::rendering::ViewState& viewState, 103 const ::com::sun::star::rendering::RenderState& renderState ); 104 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 105 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 106 const ::com::sun::star::uno::Reference< 107 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 108 const ::com::sun::star::rendering::ViewState& viewState, 109 const ::com::sun::star::rendering::RenderState& renderState, 110 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 111 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 112 strokeTexturedPolyPolygon( 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 const ::com::sun::star::uno::Sequence< 118 ::com::sun::star::rendering::Texture >& textures, 119 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 120 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 121 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 122 const ::com::sun::star::uno::Reference< 123 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 124 const ::com::sun::star::rendering::ViewState& viewState, 125 const ::com::sun::star::rendering::RenderState& renderState, 126 const ::com::sun::star::uno::Sequence< 127 ::com::sun::star::rendering::Texture >& textures, 128 const ::com::sun::star::uno::Reference< 129 ::com::sun::star::geometry::XMapping2D >& xMapping, 130 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 131 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > 132 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas, 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::rendering::StrokeAttributes& strokeAttributes ); 138 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 139 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 140 const ::com::sun::star::uno::Reference< 141 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 142 const ::com::sun::star::rendering::ViewState& viewState, 143 const ::com::sun::star::rendering::RenderState& renderState ); 144 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 145 fillTexturedPolyPolygon( 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::uno::Sequence< 151 ::com::sun::star::rendering::Texture >& textures ); 152 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 153 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 154 const ::com::sun::star::uno::Reference< 155 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 156 const ::com::sun::star::rendering::ViewState& viewState, 157 const ::com::sun::star::rendering::RenderState& renderState, 158 const ::com::sun::star::uno::Sequence< 159 ::com::sun::star::rendering::Texture >& textures, 160 const ::com::sun::star::uno::Reference< 161 ::com::sun::star::geometry::XMapping2D >& xMapping ); 162 163 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL 164 createFont( const ::com::sun::star::rendering::XCanvas* pCanvas, 165 const ::com::sun::star::rendering::FontRequest& fontRequest, 166 const ::com::sun::star::uno::Sequence< 167 ::com::sun::star::beans::PropertyValue >& extraFontProperties, 168 const ::com::sun::star::geometry::Matrix2D& fontMatrix ); 169 170 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo > 171 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas, 172 const ::com::sun::star::rendering::FontInfo& aFilter, 173 const ::com::sun::star::uno::Sequence< 174 ::com::sun::star::beans::PropertyValue >& aFontProperties ); 175 176 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 177 drawText( const ::com::sun::star::rendering::XCanvas* pCanvas, 178 const ::com::sun::star::rendering::StringContext& text, 179 const ::com::sun::star::uno::Reference< 180 ::com::sun::star::rendering::XCanvasFont >& xFont, 181 const ::com::sun::star::rendering::ViewState& viewState, 182 const ::com::sun::star::rendering::RenderState& renderState, 183 sal_Int8 textDirection ); 184 185 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 186 drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas, 187 const ::com::sun::star::uno::Reference< 188 ::com::sun::star::rendering::XTextLayout >& layoutetText, 189 const ::com::sun::star::rendering::ViewState& viewState, 190 const ::com::sun::star::rendering::RenderState& renderState ); 191 192 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 193 drawBitmap( const ::com::sun::star::rendering::XCanvas* pCanvas, 194 const ::com::sun::star::uno::Reference< 195 ::com::sun::star::rendering::XBitmap >& xBitmap, 196 const ::com::sun::star::rendering::ViewState& viewState, 197 const ::com::sun::star::rendering::RenderState& renderState ); 198 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 199 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas, 200 const ::com::sun::star::uno::Reference< 201 ::com::sun::star::rendering::XBitmap >& xBitmap, 202 const ::com::sun::star::rendering::ViewState& viewState, 203 const ::com::sun::star::rendering::RenderState& renderState ); 204 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > 205 getDevice(); 206 207 // BitmapCanvasHelper functionality 208 // ================================ 209 210 void copyRect( const ::com::sun::star::rendering::XCanvas* pCanvas, 211 const ::com::sun::star::uno::Reference< 212 ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas, 213 const ::com::sun::star::geometry::RealRectangle2D& sourceRect, 214 const ::com::sun::star::rendering::ViewState& sourceViewState, 215 const ::com::sun::star::rendering::RenderState& sourceRenderState, 216 const ::com::sun::star::geometry::RealRectangle2D& destRect, 217 const ::com::sun::star::rendering::ViewState& destViewState, 218 const ::com::sun::star::rendering::RenderState& destRenderState ); 219 220 ::com::sun::star::geometry::IntegerSize2D getSize(); 221 222 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > 223 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize, 224 sal_Bool beFast ); 225 226 ::com::sun::star::uno::Sequence< sal_Int8 > 227 getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 228 const ::com::sun::star::geometry::IntegerRectangle2D& rect ); 229 230 void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data, 231 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 232 const ::com::sun::star::geometry::IntegerRectangle2D& rect ); 233 234 void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color, 235 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 236 const ::com::sun::star::geometry::IntegerPoint2D& pos ); 237 238 ::com::sun::star::uno::Sequence< sal_Int8 > 239 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout, 240 const ::com::sun::star::geometry::IntegerPoint2D& pos ); 241 242 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapPalette > getPalette(); 243 244 ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout(); 245 246 // Flush drawing queue to screen 247 void flush() const; 248 249 /** Called from XCanvas base classes, to notify that content 250 is _about_ to change 251 */ 252 void modifying() {} 253 254 bool hasAlpha() const; 255 256 protected: 257 /** Phyical output device 258 259 Deliberately not a refcounted reference, because of 260 potential circular references for spritecanvas. 261 */ 262 SpriteCanvas* mpDevice; 263 264 private: 265 /// Current size of the output surface in pixel 266 ::basegfx::B2ISize maSize; 267 268 /// When true, content is able to represent alpha 269 bool mbHaveAlpha; 270 }; 271 } 272 273 #endif /* _NULLCANVAS_CANVASHELPER_HXX_ */ 274