LibreOffice Module canvas (master)  1
canvashelper.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_CANVAS_SOURCE_VCL_CANVASHELPER_HXX
21 #define INCLUDED_CANVAS_SOURCE_VCL_CANVASHELPER_HXX
22 
23 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
24 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
25 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
26 #include <com/sun/star/rendering/XCanvas.hpp>
27 
28 #include "cachedbitmap.hxx"
29 #include "outdevprovider.hxx"
30 
31 
32 namespace vclcanvas
33 {
34  class SpriteCanvas;
35 
41  {
42  public:
45  CanvasHelper();
46 
48  CanvasHelper(const CanvasHelper&) = delete;
49  const CanvasHelper& operator=(const CanvasHelper&) = delete;
50 
52  void disposing();
53 
78  void init( css::rendering::XGraphicDevice& rDevice,
79  const OutDevProviderSharedPtr& rOutDev,
80  bool bProtect,
81  bool bHaveAlpha );
82 
88  void setOutDev( const OutDevProviderSharedPtr& rOutDev,
89  bool bProtect);
90 
95  void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
96 
97 
98  // CanvasHelper functionality
99  // ==========================
100 
101  // XCanvas (only providing, not implementing the
102  // interface. Also note subtle method parameter differences)
103  void clear();
104  void drawLine( const css::rendering::XCanvas* rCanvas,
105  const css::geometry::RealPoint2D& aStartPoint,
106  const css::geometry::RealPoint2D& aEndPoint,
107  const css::rendering::ViewState& viewState,
108  const css::rendering::RenderState& renderState );
109  void drawBezier( const css::rendering::XCanvas* rCanvas,
110  const css::geometry::RealBezierSegment2D& aBezierSegment,
111  const css::geometry::RealPoint2D& aEndPoint,
112  const css::rendering::ViewState& viewState,
113  const css::rendering::RenderState& renderState );
114  css::uno::Reference< css::rendering::XCachedPrimitive >
115  drawPolyPolygon( const css::rendering::XCanvas* rCanvas,
116  const css::uno::Reference<
117  css::rendering::XPolyPolygon2D >& xPolyPolygon,
118  const css::rendering::ViewState& viewState,
119  const css::rendering::RenderState& renderState );
120  css::uno::Reference< css::rendering::XCachedPrimitive >
121  strokePolyPolygon( const css::rendering::XCanvas* rCanvas,
122  const css::uno::Reference<
123  css::rendering::XPolyPolygon2D >& xPolyPolygon,
124  const css::rendering::ViewState& viewState,
125  const css::rendering::RenderState& renderState,
126  const css::rendering::StrokeAttributes& strokeAttributes );
127  css::uno::Reference< css::rendering::XCachedPrimitive >
128  strokeTexturedPolyPolygon( const css::rendering::XCanvas* rCanvas,
129  const css::uno::Reference<
130  css::rendering::XPolyPolygon2D >& xPolyPolygon,
131  const css::rendering::ViewState& viewState,
132  const css::rendering::RenderState& renderState,
133  const css::uno::Sequence<
134  css::rendering::Texture >& textures,
135  const css::rendering::StrokeAttributes& strokeAttributes );
136  css::uno::Reference< css::rendering::XCachedPrimitive >
137  strokeTextureMappedPolyPolygon( const css::rendering::XCanvas* rCanvas,
138  const css::uno::Reference<
139  css::rendering::XPolyPolygon2D >& xPolyPolygon,
140  const css::rendering::ViewState& viewState,
141  const css::rendering::RenderState& renderState,
142  const css::uno::Sequence<
143  css::rendering::Texture >& textures,
144  const css::uno::Reference<
145  css::geometry::XMapping2D >& xMapping,
146  const css::rendering::StrokeAttributes& strokeAttributes );
147  css::uno::Reference< css::rendering::XPolyPolygon2D >
148  queryStrokeShapes( const css::rendering::XCanvas* rCanvas,
149  const css::uno::Reference<
150  css::rendering::XPolyPolygon2D >& xPolyPolygon,
151  const css::rendering::ViewState& viewState,
152  const css::rendering::RenderState& renderState,
153  const css::rendering::StrokeAttributes& strokeAttributes );
154  css::uno::Reference< css::rendering::XCachedPrimitive >
155  fillPolyPolygon( const css::rendering::XCanvas* rCanvas,
156  const css::uno::Reference<
157  css::rendering::XPolyPolygon2D >& xPolyPolygon,
158  const css::rendering::ViewState& viewState,
159  const css::rendering::RenderState& renderState );
160  css::uno::Reference< css::rendering::XCachedPrimitive >
161  fillTexturedPolyPolygon( const css::rendering::XCanvas* rCanvas,
162  const css::uno::Reference<
163  css::rendering::XPolyPolygon2D >& xPolyPolygon,
164  const css::rendering::ViewState& viewState,
165  const css::rendering::RenderState& renderState,
166  const css::uno::Sequence<
167  css::rendering::Texture >& textures );
168  css::uno::Reference< css::rendering::XCachedPrimitive >
169  fillTextureMappedPolyPolygon( const css::rendering::XCanvas* rCanvas,
170  const css::uno::Reference<
171  css::rendering::XPolyPolygon2D >& xPolyPolygon,
172  const css::rendering::ViewState& viewState,
173  const css::rendering::RenderState& renderState,
174  const css::uno::Sequence<
175  css::rendering::Texture >& textures,
176  const css::uno::Reference<
177  css::geometry::XMapping2D >& xMapping );
178 
179  css::uno::Reference< css::rendering::XCanvasFont >
180  createFont( const css::rendering::XCanvas* rCanvas,
181  const css::rendering::FontRequest& fontRequest,
182  const css::uno::Sequence<
183  css::beans::PropertyValue >& extraFontProperties,
184  const css::geometry::Matrix2D& fontMatrix );
185 
186  css::uno::Sequence< css::rendering::FontInfo >
187  queryAvailableFonts( const css::rendering::XCanvas* rCanvas,
188  const css::rendering::FontInfo& aFilter,
189  const css::uno::Sequence<
190  css::beans::PropertyValue >& aFontProperties );
191 
192  css::uno::Reference< css::rendering::XCachedPrimitive >
193  drawText( const css::rendering::XCanvas* rCanvas,
194  const css::rendering::StringContext& text,
195  const css::uno::Reference<
196  css::rendering::XCanvasFont >& xFont,
197  const css::rendering::ViewState& viewState,
198  const css::rendering::RenderState& renderState,
199  sal_Int8 textDirection );
200 
201  css::uno::Reference< css::rendering::XCachedPrimitive >
202  drawTextLayout( const css::rendering::XCanvas* rCanvas,
203  const css::uno::Reference<
204  css::rendering::XTextLayout >& laidOutText,
205  const css::rendering::ViewState& viewState,
206  const css::rendering::RenderState& renderState );
207 
208  css::uno::Reference< css::rendering::XCachedPrimitive >
209  drawBitmap( const css::rendering::XCanvas* rCanvas,
210  const css::uno::Reference<
211  css::rendering::XBitmap >& xBitmap,
212  const css::rendering::ViewState& viewState,
213  const css::rendering::RenderState& renderState );
214  css::uno::Reference< css::rendering::XCachedPrimitive >
215  drawBitmapModulated( const css::rendering::XCanvas* rCanvas,
216  const css::uno::Reference<
217  css::rendering::XBitmap >& xBitmap,
218  const css::rendering::ViewState& viewState,
219  const css::rendering::RenderState& renderState );
220  // cast away const, need to change refcount (as this is
221  // ~invisible to client code, still logically const)
222  css::uno::Reference< css::rendering::XGraphicDevice >
223  getDevice() { return css::uno::Reference< css::rendering::XGraphicDevice >(mpDevice); }
224 
225 
226  // BitmapCanvasHelper functionality
227  // ================================
228 
229  css::geometry::IntegerSize2D getSize();
230 
231  css::uno::Reference< css::rendering::XBitmap >
232  getScaledBitmap( const css::geometry::RealSize2D& newSize,
233  bool beFast );
234 
235  css::uno::Sequence< sal_Int8 >
236  getData( css::rendering::IntegerBitmapLayout& bitmapLayout,
237  const css::geometry::IntegerRectangle2D& rect );
238 
239  css::uno::Sequence< sal_Int8 >
240  getPixel( css::rendering::IntegerBitmapLayout& bitmapLayout,
241  const css::geometry::IntegerPoint2D& pos );
242 
243  css::rendering::IntegerBitmapLayout getMemoryLayout();
244 
246  bool repaint( const GraphicObjectSharedPtr& rGrf,
247  const css::rendering::ViewState& viewState,
248  const css::rendering::RenderState& renderState,
249  const ::Point& rPt,
250  const ::Size& rSz,
251  const GraphicAttr& rAttr ) const;
252 
259  void flush() const;
260 
262  {
264  };
265 
266  // returns transparency of color
267  int setupOutDevState( const css::rendering::ViewState& viewState,
268  const css::rendering::RenderState& renderState,
269  ColorType eColorType ) const;
270 
271  bool hasAlpha() const { return mbHaveAlpha; }
272 
273  protected:
279  css::rendering::XGraphicDevice* mpDevice;
280 
283 
286 
289 
292 
293  private:
294  css::uno::Reference< css::rendering::XCachedPrimitive >
295  implDrawBitmap( const css::rendering::XCanvas* rCanvas,
296  const css::uno::Reference<
297  css::rendering::XBitmap >& xBitmap,
298  const css::rendering::ViewState& viewState,
299  const css::rendering::RenderState& renderState,
300  bool bModulateColors );
301 
302  bool setupTextOutput( ::Point& o_rOutPos,
303  const css::rendering::ViewState& viewState,
304  const css::rendering::RenderState& renderState,
305  const css::uno::Reference< css::rendering::XCanvasFont >& xFont ) const;
306 
307  };
308 }
309 
310 #endif // INCLUDED_CANVAS_SOURCE_VCL_CANVASHELPER_HXX
311 
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::rendering::XCachedPrimitive > fillTexturedPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::uno::Sequence< css::rendering::Texture > &textures)
css::uno::Reference< css::rendering::XCachedPrimitive > drawBitmapModulated(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Sequence< sal_Int8 > getData(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
bool mbHaveAlpha
When true, content is able to represent alpha.
css::uno::Sequence< css::rendering::FontInfo > queryAvailableFonts(const css::rendering::XCanvas *rCanvas, const css::rendering::FontInfo &aFilter, const css::uno::Sequence< css::beans::PropertyValue > &aFontProperties)
signed char sal_Int8
css::uno::Reference< css::rendering::XCanvasFont > createFont(const css::rendering::XCanvas *rCanvas, const css::rendering::FontRequest &fontRequest, const css::uno::Sequence< css::beans::PropertyValue > &extraFontProperties, const css::geometry::Matrix2D &fontMatrix)
void drawLine(const css::rendering::XCanvas *rCanvas, const css::geometry::RealPoint2D &aStartPoint, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XCachedPrimitive > fillTextureMappedPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::uno::Sequence< css::rendering::Texture > &textures, const css::uno::Reference< css::geometry::XMapping2D > &xMapping)
void init(css::rendering::XGraphicDevice &rDevice, const OutDevProviderSharedPtr &rOutDev, bool bProtect, bool bHaveAlpha)
Initialize canvas helper.
Helper class for basic canvas functionality.
css::uno::Reference< css::rendering::XCachedPrimitive > strokeTextureMappedPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::uno::Sequence< css::rendering::Texture > &textures, const css::uno::Reference< css::geometry::XMapping2D > &xMapping, const css::rendering::StrokeAttributes &strokeAttributes)
void disposing()
Release all references.
OutDevProviderSharedPtr mpOutDevProvider
Rendering to this outdev does not preserve its state.
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
void drawBezier(const css::rendering::XCanvas *rCanvas, const css::geometry::RealBezierSegment2D &aBezierSegment, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XCachedPrimitive > strokePolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::rendering::StrokeAttributes &strokeAttributes)
css::uno::Reference< css::rendering::XCachedPrimitive > drawTextLayout(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XTextLayout > &laidOutText, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
std::shared_ptr< GraphicObject > GraphicObjectSharedPtr
bool setupTextOutput(::Point &o_rOutPos, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::uno::Reference< css::rendering::XCanvasFont > &xFont) const
css::uno::Reference< css::rendering::XPolyPolygon2D > queryStrokeShapes(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::rendering::StrokeAttributes &strokeAttributes)
css::geometry::IntegerSize2D getSize()
css::rendering::IntegerBitmapLayout getMemoryLayout()
void setOutDev(const OutDevProviderSharedPtr &rOutDev, bool bProtect)
Set primary output device.
css::uno::Sequence< sal_Int8 > getPixel(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
css::uno::Reference< css::rendering::XCachedPrimitive > implDrawBitmap(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, bool bModulateColors)
css::uno::Reference< css::rendering::XCachedPrimitive > drawText(const css::rendering::XCanvas *rCanvas, const css::rendering::StringContext &text, const css::uno::Reference< css::rendering::XCanvasFont > &xFont, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, sal_Int8 textDirection)
OutDevProviderSharedPtr mp2ndOutDevProvider
Rendering to this outdev does not preserve its state.
css::uno::Reference< css::rendering::XCachedPrimitive > strokeTexturedPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::uno::Sequence< css::rendering::Texture > &textures, const css::rendering::StrokeAttributes &strokeAttributes)
const CanvasHelper & operator=(const CanvasHelper &)=delete
void flush() const
Flush drawing queue.
css::uno::Reference< css::rendering::XCachedPrimitive > drawPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XGraphicDevice > getDevice()
css::uno::Reference< css::rendering::XCachedPrimitive > drawBitmap(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XCachedPrimitive > fillPolyPolygon(const css::rendering::XCanvas *rCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
def text(shape, st)
css::uno::Reference< css::rendering::XBitmap > getScaledBitmap(const css::geometry::RealSize2D &newSize, bool beFast)
int setupOutDevState(const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, ColorType eColorType) const
OutDevProviderSharedPtr mpProtectedOutDevProvider
Rendering to this outdev preserves its state.
CanvasHelper()
Create canvas helper.
bool repaint(const GraphicObjectSharedPtr &rGrf, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const ::Point &rPt, const ::Size &rSz, const GraphicAttr &rAttr) const
Repaint a cached bitmap.
void setBackgroundOutDev(const OutDevProviderSharedPtr &rOutDev)
Set secondary output device.