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