LibreOffice Module canvas (master)  1
cairo_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 #pragma once
21 
22 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
23 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
24 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
25 #include <com/sun/star/rendering/XCanvas.hpp>
26 
27 #include <vcl/vclptr.hxx>
28 #include <vcl/virdev.hxx>
29 
30 #include <vcl/cairo.hxx>
32 
33 class VirtualDevice;
34 
35 namespace basegfx {
36  class B2DPolyPolygon;
37 }
38 
39 namespace cairocanvas
40 {
41  class SpriteCanvas;
42 
43  enum Operation {
47  };
48 
50  {
51  public:
53  CanvasHelper(const CanvasHelper&) = delete;
54  const CanvasHelper& operator=(const CanvasHelper&) = delete;
55 
56  CanvasHelper();
57 
59  void disposing();
60 
78  void init( const ::basegfx::B2ISize& rSizePixel,
79  SurfaceProvider& rSurfaceProvider,
80  css::rendering::XGraphicDevice* pDevice );
81 
82  void setSize( const ::basegfx::B2ISize& rSize );
83  void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha );
84 
85  // CanvasHelper functionality
86  // ==========================
87 
88  // XCanvas (only providing, not implementing the
89  // interface. Also note subtle method parameter differences)
90  void clear();
91  void drawLine( const css::rendering::XCanvas* pCanvas,
92  const css::geometry::RealPoint2D& aStartPoint,
93  const css::geometry::RealPoint2D& aEndPoint,
94  const css::rendering::ViewState& viewState,
95  const css::rendering::RenderState& renderState );
96  void drawBezier( const css::rendering::XCanvas* pCanvas,
97  const css::geometry::RealBezierSegment2D& aBezierSegment,
98  const css::geometry::RealPoint2D& aEndPoint,
99  const css::rendering::ViewState& viewState,
100  const css::rendering::RenderState& renderState );
101  css::uno::Reference< css::rendering::XCachedPrimitive >
102  drawPolyPolygon( const css::rendering::XCanvas* pCanvas,
103  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
104  const css::rendering::ViewState& viewState,
105  const css::rendering::RenderState& renderState );
106  css::uno::Reference< css::rendering::XCachedPrimitive >
107  strokePolyPolygon( const css::rendering::XCanvas* pCanvas,
108  const css::uno::Reference<
109  css::rendering::XPolyPolygon2D >& xPolyPolygon,
110  const css::rendering::ViewState& viewState,
111  const css::rendering::RenderState& renderState,
112  const css::rendering::StrokeAttributes& strokeAttributes );
113  css::uno::Reference< css::rendering::XCachedPrimitive >
114  strokeTexturedPolyPolygon( const css::rendering::XCanvas* pCanvas,
115  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
116  const css::rendering::ViewState& viewState,
117  const css::rendering::RenderState& renderState,
118  const css::uno::Sequence< css::rendering::Texture >& textures,
119  const css::rendering::StrokeAttributes& strokeAttributes );
120  css::uno::Reference< css::rendering::XCachedPrimitive >
121  strokeTextureMappedPolyPolygon( const css::rendering::XCanvas* pCanvas,
122  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
123  const css::rendering::ViewState& viewState,
124  const css::rendering::RenderState& renderState,
125  const css::uno::Sequence< css::rendering::Texture >& textures,
126  const css::uno::Reference< css::geometry::XMapping2D >& xMapping,
127  const css::rendering::StrokeAttributes& strokeAttributes );
128  css::uno::Reference< css::rendering::XPolyPolygon2D >
129  queryStrokeShapes( const css::rendering::XCanvas* pCanvas,
130  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
131  const css::rendering::ViewState& viewState,
132  const css::rendering::RenderState& renderState,
133  const css::rendering::StrokeAttributes& strokeAttributes );
134  css::uno::Reference< css::rendering::XCachedPrimitive >
135  fillPolyPolygon( const css::rendering::XCanvas* pCanvas,
136  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
137  const css::rendering::ViewState& viewState,
138  const css::rendering::RenderState& renderState );
139  css::uno::Reference< css::rendering::XCachedPrimitive >
140  fillTexturedPolyPolygon( const css::rendering::XCanvas* pCanvas,
141  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
142  const css::rendering::ViewState& viewState,
143  const css::rendering::RenderState& renderState,
144  const css::uno::Sequence< css::rendering::Texture >& textures );
145  css::uno::Reference< css::rendering::XCachedPrimitive >
146  fillTextureMappedPolyPolygon( const css::rendering::XCanvas* pCanvas,
147  const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
148  const css::rendering::ViewState& viewState,
149  const css::rendering::RenderState& renderState,
150  const css::uno::Sequence< css::rendering::Texture >& textures,
151  const css::uno::Reference< css::geometry::XMapping2D >& xMapping );
152 
153  css::uno::Reference< css::rendering::XCanvasFont >
154  createFont( const css::rendering::XCanvas* pCanvas,
155  const css::rendering::FontRequest& fontRequest,
156  const css::uno::Sequence< css::beans::PropertyValue >& extraFontProperties,
157  const css::geometry::Matrix2D& fontMatrix );
158 
159  css::uno::Sequence< css::rendering::FontInfo >
160  queryAvailableFonts( const css::rendering::XCanvas* pCanvas,
161  const css::rendering::FontInfo& aFilter,
162  const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties );
163 
164  css::uno::Reference< css::rendering::XCachedPrimitive >
165  drawText( const css::rendering::XCanvas* pCanvas,
166  const css::rendering::StringContext& text,
167  const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
168  const css::rendering::ViewState& viewState,
169  const css::rendering::RenderState& renderState,
170  sal_Int8 textDirection );
171 
172  css::uno::Reference< css::rendering::XCachedPrimitive >
173  drawTextLayout( const css::rendering::XCanvas* pCanvas,
174  const css::uno::Reference< css::rendering::XTextLayout >& laidOutText,
175  const css::rendering::ViewState& viewState,
176  const css::rendering::RenderState& renderState );
177 
178  css::uno::Reference< css::rendering::XCachedPrimitive >
179  drawBitmap( const css::rendering::XCanvas* pCanvas,
180  const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
181  const css::rendering::ViewState& viewState,
182  const css::rendering::RenderState& renderState );
183  css::uno::Reference< css::rendering::XCachedPrimitive >
184  drawBitmapModulated( const css::rendering::XCanvas* pCanvas,
185  const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
186  const css::rendering::ViewState& viewState,
187  const css::rendering::RenderState& renderState );
188  css::uno::Reference< css::rendering::XGraphicDevice >
189  getDevice() { return css::uno::Reference< css::rendering::XGraphicDevice >(mpDevice); }
190 
191  // BitmapCanvasHelper functionality
192  // ================================
193 
194  css::geometry::IntegerSize2D getSize() const;
195 
196  css::uno::Reference< css::rendering::XBitmap >
197  getScaledBitmap( const css::geometry::RealSize2D& newSize,
198  bool beFast );
199 
200  css::uno::Sequence< sal_Int8 >
201  getData( css::rendering::IntegerBitmapLayout& bitmapLayout,
202  const css::geometry::IntegerRectangle2D& rect );
203 
204  css::uno::Sequence< sal_Int8 >
205  getPixel( css::rendering::IntegerBitmapLayout& bitmapLayout,
206  const css::geometry::IntegerPoint2D& pos );
207 
208  css::rendering::IntegerBitmapLayout getMemoryLayout();
209 
210  void doPolyPolygonPath( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
211  Operation aOperation,
212  bool bNoLineJoin = false,
213  const css::uno::Sequence< css::rendering::Texture >* pTextures=nullptr ) const;
214 
215  css::uno::Reference< css::rendering::XCachedPrimitive > implDrawBitmapSurface(
216  const css::rendering::XCanvas* pCanvas,
217  const ::cairo::SurfaceSharedPtr& pSurface,
218  const css::rendering::ViewState& viewState,
219  const css::rendering::RenderState& renderState,
220  const css::geometry::IntegerSize2D& rSize,
221  bool bModulateColors,
222  bool bHasAlpha );
223 
224  bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
225  const css::rendering::ViewState& viewState,
226  const css::rendering::RenderState& renderState );
227 
228  protected:
236 
242  css::rendering::XGraphicDevice* mpDevice;
243 
244  private:
245 
247 
248  void useStates( const css::rendering::ViewState& viewState,
249  const css::rendering::RenderState& renderState,
250  bool setColor );
251 
252  css::rendering::IntegerBitmapLayout impl_getMemoryLayout( sal_Int32 nWidth, sal_Int32 nHeight );
253 
256 
260  };
261 
263  void doPolyPolygonImplementation( const ::basegfx::B2DPolyPolygon& aPolyPolygon,
264  Operation aOperation,
265  cairo_t* pCairo,
266  const css::uno::Sequence< css::rendering::Texture >* pTextures,
267  const SurfaceProviderRef& pDevice,
268  css::rendering::FillRule eFillrule );
269 }
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::rendering::IntegerBitmapLayout impl_getMemoryLayout(sal_Int32 nWidth, sal_Int32 nHeight)
css::uno::Reference< css::rendering::XCachedPrimitive > implDrawBitmapSurface(const css::rendering::XCanvas *pCanvas, const ::cairo::SurfaceSharedPtr &pSurface, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::geometry::IntegerSize2D &rSize, bool bModulateColors, bool bHasAlpha)
Target interface for XCachedPrimitive implementations.
css::uno::Reference< css::rendering::XCachedPrimitive > strokeTexturedPolyPolygon(const css::rendering::XCanvas *pCanvas, 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)
::cairo::CairoSharedPtr mpCairo
signed char sal_Int8
void setSize(const ::basegfx::B2ISize &rSize)
css::uno::Sequence< sal_Int8 > getPixel(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerPoint2D &pos)
void disposing()
Release all references.
css::uno::Reference< css::rendering::XGraphicDevice > getDevice()
std::shared_ptr< cairo_t > CairoSharedPtr
css::uno::Reference< css::rendering::XCachedPrimitive > drawTextLayout(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XTextLayout > &laidOutText, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XCachedPrimitive > fillPolyPolygon(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
void drawBezier(const css::rendering::XCanvas *pCanvas, const css::geometry::RealBezierSegment2D &aBezierSegment, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
exports com.sun.star. text
std::shared_ptr< Surface > SurfaceSharedPtr
css::uno::Sequence< css::rendering::FontInfo > queryAvailableFonts(const css::rendering::XCanvas *pCanvas, const css::rendering::FontInfo &aFilter, const css::uno::Sequence< css::beans::PropertyValue > &aFontProperties)
css::uno::Reference< css::rendering::XCachedPrimitive > strokePolyPolygon(const css::rendering::XCanvas *pCanvas, 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 > drawBitmap(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
void doPolyPolygonImplementation(const ::basegfx::B2DPolyPolygon &aPolyPolygon, Operation aOperation, cairo_t *pCairo, const uno::Sequence< rendering::Texture > *pTextures, const SurfaceProviderRef &pDevice, rendering::FillRule eFillrule)
css::uno::Reference< css::rendering::XPolyPolygon2D > queryStrokeShapes(const css::rendering::XCanvas *pCanvas, 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 > fillTextureMappedPolyPolygon(const css::rendering::XCanvas *pCanvas, 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)
css::uno::Reference< css::rendering::XCanvasFont > createFont(const css::rendering::XCanvas *pCanvas, const css::rendering::FontRequest &fontRequest, const css::uno::Sequence< css::beans::PropertyValue > &extraFontProperties, const css::geometry::Matrix2D &fontMatrix)
css::uno::Sequence< sal_Int8 > getData(css::rendering::IntegerBitmapLayout &bitmapLayout, const css::geometry::IntegerRectangle2D &rect)
css::uno::Reference< css::rendering::XCachedPrimitive > drawPolyPolygon(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
void useStates(const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, bool setColor)
struct _cairo cairo_t
bool mbHaveAlpha
When true, content is able to represent alpha.
const CanvasHelper & operator=(const CanvasHelper &)=delete
css::rendering::IntegerBitmapLayout getMemoryLayout()
::cairo::SurfaceSharedPtr mpSurface
css::geometry::IntegerSize2D getSize() const
SurfaceProvider * mpSurfaceProvider
Surface provider.
void setSurface(const ::cairo::SurfaceSharedPtr &pSurface, bool bHasAlpha)
void init(const ::basegfx::B2ISize &rSizePixel, SurfaceProvider &rSurfaceProvider, css::rendering::XGraphicDevice *pDevice)
Initialize canvas helper.
css::uno::Reference< css::rendering::XCachedPrimitive > drawBitmapModulated(const css::rendering::XCanvas *pCanvas, const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
void doPolyPolygonPath(const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, Operation aOperation, bool bNoLineJoin=false, const css::uno::Sequence< css::rendering::Texture > *pTextures=nullptr) const
css::rendering::XGraphicDevice * mpDevice
Phyical output device.
void drawLine(const css::rendering::XCanvas *pCanvas, const css::geometry::RealPoint2D &aStartPoint, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
static void setColor(cairo_t *pCairo, const uno::Sequence< double > &rColor)
css::uno::Reference< css::rendering::XCachedPrimitive > fillTexturedPolyPolygon(const css::rendering::XCanvas *pCanvas, 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)
bool repaint(const ::cairo::SurfaceSharedPtr &pSurface, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState)
css::uno::Reference< css::rendering::XBitmap > getScaledBitmap(const css::geometry::RealSize2D &newSize, bool beFast)
css::uno::Reference< css::rendering::XCachedPrimitive > strokeTextureMappedPolyPolygon(const css::rendering::XCanvas *pCanvas, 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)
VclPtr< VirtualDevice > mpVirtualDevice
css::uno::Reference< css::rendering::XCachedPrimitive > drawText(const css::rendering::XCanvas *pCanvas, 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)