1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _DXCANVAS_CANVASHELPER_HXX_ 25 #define _DXCANVAS_CANVASHELPER_HXX_ 26 27 #include <com/sun/star/rendering/XCanvas.hpp> 28 29 #include <basegfx/vector/b2isize.hxx> 30 #include <basegfx/vector/b2dsize.hxx> 31 32 #include "dx_graphicsprovider.hxx" 33 #include "dx_gdiplususer.hxx" 34 #include "dx_impltools.hxx" 35 36 #include <boost/utility.hpp> 37 38 39 namespace dxcanvas 40 { 41 /** Helper class for basic canvas functionality. Also offers 42 optional backbuffer painting, when providing it with a second 43 HDC to render into. 44 */ 45 class CanvasHelper : private ::boost::noncopyable 46 { 47 public: 48 CanvasHelper(); 49 50 /// Release all references 51 void disposing(); 52 53 /** Initialize canvas helper 54 55 This method late-initializes the canvas helper, providing 56 it with the necessary device and output objects. Note that 57 the CanvasHelper does <em>not</em> take ownership of the 58 passed rDevice reference, nor does it perform any 59 reference counting. Thus, to prevent the reference counted 60 SpriteCanvas object from deletion, the user of this class 61 is responsible for holding ref-counted references itself! 62 63 @param rDevice 64 Reference device this canvas is associated with 65 66 */ 67 void setDevice( com::sun::star::rendering::XGraphicDevice& rDevice ); 68 69 /** Set the target for rendering operations 70 71 @param rTarget 72 Render target 73 */ 74 void setTarget( const GraphicsProviderSharedPtr& rTarget ); 75 76 /** Set the target for rendering operations 77 78 @param rTarget 79 Render target 80 81 @param rOutputOffset 82 Output offset in pixel 83 */ 84 void setTarget( const GraphicsProviderSharedPtr& rTarget, 85 const ::basegfx::B2ISize& rOutputOffset ); 86 87 88 // CanvasHelper functionality 89 // ========================== 90 91 // XCanvas (only providing, not implementing the 92 // interface. Also note subtle method parameter differences) 93 void clear(); 94 void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, 95 const ::com::sun::star::geometry::RealPoint2D& aPoint, 96 const ::com::sun::star::rendering::ViewState& viewState, 97 const ::com::sun::star::rendering::RenderState& renderState ); 98 void drawLine( const ::com::sun::star::rendering::XCanvas* pCanvas, 99 const ::com::sun::star::geometry::RealPoint2D& aStartPoint, 100 const ::com::sun::star::geometry::RealPoint2D& aEndPoint, 101 const ::com::sun::star::rendering::ViewState& viewState, 102 const ::com::sun::star::rendering::RenderState& renderState ); 103 void drawBezier( const ::com::sun::star::rendering::XCanvas* pCanvas, 104 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment, 105 const ::com::sun::star::geometry::RealPoint2D& aEndPoint, 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 drawPolyPolygon( 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 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 115 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 116 const ::com::sun::star::uno::Reference< 117 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 118 const ::com::sun::star::rendering::ViewState& viewState, 119 const ::com::sun::star::rendering::RenderState& renderState, 120 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 121 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 122 strokeTexturedPolyPolygon( 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::uno::Sequence< 128 ::com::sun::star::rendering::Texture >& textures, 129 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 130 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 131 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 132 const ::com::sun::star::uno::Reference< 133 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 134 const ::com::sun::star::rendering::ViewState& viewState, 135 const ::com::sun::star::rendering::RenderState& renderState, 136 const ::com::sun::star::uno::Sequence< 137 ::com::sun::star::rendering::Texture >& textures, 138 const ::com::sun::star::uno::Reference< 139 ::com::sun::star::geometry::XMapping2D >& xMapping, 140 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 141 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > 142 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* pCanvas, 143 const ::com::sun::star::uno::Reference< 144 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 145 const ::com::sun::star::rendering::ViewState& viewState, 146 const ::com::sun::star::rendering::RenderState& renderState, 147 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ); 148 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 149 fillPolyPolygon( 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 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 155 fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 156 const ::com::sun::star::uno::Reference< 157 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 158 const ::com::sun::star::rendering::ViewState& viewState, 159 const ::com::sun::star::rendering::RenderState& renderState, 160 const ::com::sun::star::uno::Sequence< 161 ::com::sun::star::rendering::Texture >& textures ); 162 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 163 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, 164 const ::com::sun::star::uno::Reference< 165 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, 166 const ::com::sun::star::rendering::ViewState& viewState, 167 const ::com::sun::star::rendering::RenderState& renderState, 168 const ::com::sun::star::uno::Sequence< 169 ::com::sun::star::rendering::Texture >& textures, 170 const ::com::sun::star::uno::Reference< 171 ::com::sun::star::geometry::XMapping2D >& xMapping ); 172 173 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL 174 createFont( const ::com::sun::star::rendering::XCanvas* pCanvas, 175 const ::com::sun::star::rendering::FontRequest& fontRequest, 176 const ::com::sun::star::uno::Sequence< 177 ::com::sun::star::beans::PropertyValue >& extraFontProperties, 178 const ::com::sun::star::geometry::Matrix2D& fontMatrix ); 179 180 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo > 181 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* pCanvas, 182 const ::com::sun::star::rendering::FontInfo& aFilter, 183 const ::com::sun::star::uno::Sequence< 184 ::com::sun::star::beans::PropertyValue >& aFontProperties ); 185 186 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 187 drawText( const ::com::sun::star::rendering::XCanvas* pCanvas, 188 const ::com::sun::star::rendering::StringContext& text, 189 const ::com::sun::star::uno::Reference< 190 ::com::sun::star::rendering::XCanvasFont >& xFont, 191 const ::com::sun::star::rendering::ViewState& viewState, 192 const ::com::sun::star::rendering::RenderState& renderState, 193 sal_Int8 textDirection ); 194 195 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 196 drawTextLayout( const ::com::sun::star::rendering::XCanvas* pCanvas, 197 const ::com::sun::star::uno::Reference< 198 ::com::sun::star::rendering::XTextLayout >& layoutetText, 199 const ::com::sun::star::rendering::ViewState& viewState, 200 const ::com::sun::star::rendering::RenderState& renderState ); 201 202 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > 203 drawBitmap( 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::XCachedPrimitive > 209 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas, 210 const ::com::sun::star::uno::Reference< 211 ::com::sun::star::rendering::XBitmap >& xBitmap, 212 const ::com::sun::star::rendering::ViewState& viewState, 213 const ::com::sun::star::rendering::RenderState& renderState ); 214 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > 215 getDevice(); 216 217 // Flush drawing queue to screen 218 void flush() const; 219 220 /** Called from XCanvas base classes, to notify that content 221 is _about_ to change 222 */ modifying()223 void modifying() {} 224 225 protected: 226 /// Refcounted global GDI+ state container 227 GDIPlusUserSharedPtr mpGdiPlusUser; 228 229 /** Phyical output device 230 231 Deliberately not a refcounted reference, because of 232 potential circular references for spritecanvas. 233 */ 234 com::sun::star::rendering::XGraphicDevice* mpDevice; 235 236 /// Provides the Gdiplus::Graphics to render into 237 GraphicsProviderSharedPtr mpGraphicsProvider; 238 needOutput() const239 bool needOutput() const { return mpGraphicsProvider.get() != NULL; }; 240 241 // returns transparency of color 242 void setupGraphicsState( GraphicsSharedPtr& rGraphics, 243 const ::com::sun::star::rendering::ViewState& viewState, 244 const ::com::sun::star::rendering::RenderState& renderState ); 245 246 Gdiplus::CompositingMode calcCompositingMode( sal_Int8 nMode ); 247 248 /// Current (transformation-independent) output buffer offset 249 ::basegfx::B2ISize maOutputOffset; 250 }; 251 } 252 253 #endif /* _DXCANVAS_CANVASHELPER_HXX_ */ 254