LibreOffice Module canvas (master) 1
canvasbase.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/uno/Reference.hxx>
23#include <com/sun/star/uno/Sequence.hxx>
24#include <com/sun/star/rendering/TextDirection.hpp>
25#include <osl/mutex.hxx>
26#include <verifyinput.hxx>
27
28namespace com::sun::star::beans { struct PropertyValue; }
29namespace com::sun::star::geometry { class XMapping2D; }
30namespace com::sun::star::rendering { class XBitmap; }
31namespace com::sun::star::rendering { class XCachedPrimitive; }
32namespace com::sun::star::rendering { class XCanvasFont; }
33namespace com::sun::star::rendering { class XGraphicDevice; }
34namespace com::sun::star::rendering { class XPolyPolygon2D; }
35namespace com::sun::star::rendering { class XTextLayout; }
36namespace com::sun::star::rendering { struct FontInfo; }
37namespace com::sun::star::rendering { struct StringContext; }
38
39
40namespace canvas
41{
104 template< class Base,
105 class CanvasHelper,
106 class Mutex=::osl::MutexGuard,
107 class UnambiguousBase=css::uno::XInterface > class CanvasBase :
108 public Base
109 {
110 public:
111 typedef Base BaseType;
112 typedef Mutex MutexType;
113 typedef UnambiguousBase UnambiguousBaseType;
114
119 mbSurfaceDirty( true )
120 {
121 }
122
123 virtual void disposeThis() override
124 {
125 MutexType aGuard( BaseType::m_aMutex );
126
127 maCanvasHelper.disposing();
128
129 // pass on to base class
130 BaseType::disposeThis();
131 }
132
133 // XCanvas
134 virtual void SAL_CALL clear() override
135 {
136 MutexType aGuard( BaseType::m_aMutex );
137
138 mbSurfaceDirty = true;
139
140 maCanvasHelper.clear();
141 }
142
143 virtual void SAL_CALL drawPoint(const css::geometry::RealPoint2D& aPoint,
144 const css::rendering::ViewState& viewState,
145 const css::rendering::RenderState& renderState) override
146 {
147 tools::verifyArgs(aPoint, viewState, renderState,
148 __func__,
149 static_cast< UnambiguousBaseType* >(this));
150
151 MutexType aGuard( BaseType::m_aMutex );
152
153 mbSurfaceDirty = true;
154 }
155
156 virtual void SAL_CALL drawLine(const css::geometry::RealPoint2D& aStartPoint,
157 const css::geometry::RealPoint2D& aEndPoint,
158 const css::rendering::ViewState& viewState,
159 const css::rendering::RenderState& renderState) override
160 {
161 tools::verifyArgs(aStartPoint, aEndPoint, viewState, renderState,
162 __func__,
163 static_cast< UnambiguousBaseType* >(this));
164
165 MutexType aGuard( BaseType::m_aMutex );
166
167 mbSurfaceDirty = true;
168
169 maCanvasHelper.drawLine( this, aStartPoint, aEndPoint, viewState, renderState );
170 }
171
172 virtual void SAL_CALL drawBezier( const css::geometry::RealBezierSegment2D& aBezierSegment,
173 const css::geometry::RealPoint2D& aEndPoint,
174 const css::rendering::ViewState& viewState,
175 const css::rendering::RenderState& renderState ) override
176 {
177 tools::verifyArgs(aBezierSegment, aEndPoint, viewState, renderState,
178 __func__,
179 static_cast< UnambiguousBaseType* >(this));
180
181 MutexType aGuard( BaseType::m_aMutex );
182
183 mbSurfaceDirty = true;
184
185 maCanvasHelper.drawBezier( this, aBezierSegment, aEndPoint, viewState, renderState );
186 }
187
188 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
189 drawPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
190 const css::rendering::ViewState& viewState,
191 const css::rendering::RenderState& renderState) override
192 {
193 tools::verifyArgs(xPolyPolygon, viewState, renderState,
194 __func__,
195 static_cast< UnambiguousBaseType* >(this));
196
197 MutexType aGuard( BaseType::m_aMutex );
198
199 mbSurfaceDirty = true;
200
201 return maCanvasHelper.drawPolyPolygon( this, xPolyPolygon, viewState, renderState );
202 }
203
204 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
205 strokePolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
206 const css::rendering::ViewState& viewState,
207 const css::rendering::RenderState& renderState,
208 const css::rendering::StrokeAttributes& strokeAttributes) override
209 {
210 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
211 __func__,
212 static_cast< UnambiguousBaseType* >(this));
213
214 MutexType aGuard( BaseType::m_aMutex );
215
216 mbSurfaceDirty = true;
217
218 return maCanvasHelper.strokePolyPolygon( this, xPolyPolygon, viewState, renderState, strokeAttributes );
219 }
220
221 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
222 strokeTexturedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
223 const css::rendering::ViewState& viewState,
224 const css::rendering::RenderState& renderState,
225 const css::uno::Sequence< css::rendering::Texture >& textures,
226 const css::rendering::StrokeAttributes& strokeAttributes ) override
227 {
228 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
229 __func__,
230 static_cast< UnambiguousBaseType* >(this));
231
232 MutexType aGuard( BaseType::m_aMutex );
233
234 mbSurfaceDirty = true;
235
236 return maCanvasHelper.strokeTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, strokeAttributes );
237 }
238
239 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
240 strokeTextureMappedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
241 const css::rendering::ViewState& viewState,
242 const css::rendering::RenderState& renderState,
243 const css::uno::Sequence< css::rendering::Texture >& textures,
244 const css::uno::Reference< css::geometry::XMapping2D >& xMapping,
245 const css::rendering::StrokeAttributes& strokeAttributes ) override
246 {
247 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes,
248 __func__,
249 static_cast< UnambiguousBaseType* >(this));
250
251 MutexType aGuard( BaseType::m_aMutex );
252
253 mbSurfaceDirty = true;
254
255 return maCanvasHelper.strokeTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes );
256 }
257
258 virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL
259 queryStrokeShapes( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
260 const css::rendering::ViewState& viewState,
261 const css::rendering::RenderState& renderState,
262 const css::rendering::StrokeAttributes& strokeAttributes ) override
263 {
264 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
265 __func__,
266 static_cast< UnambiguousBaseType* >(this));
267
268 MutexType aGuard( BaseType::m_aMutex );
269
270 mbSurfaceDirty = true;
271
272 return maCanvasHelper.queryStrokeShapes( this, xPolyPolygon, viewState, renderState, strokeAttributes );
273 }
274
275 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
276 fillPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
277 const css::rendering::ViewState& viewState,
278 const css::rendering::RenderState& renderState) override
279 {
280 tools::verifyArgs(xPolyPolygon, viewState, renderState,
281 __func__,
282 static_cast< UnambiguousBaseType* >(this));
283
284 MutexType aGuard( BaseType::m_aMutex );
285
286 mbSurfaceDirty = true;
287
288 return maCanvasHelper.fillPolyPolygon( this, xPolyPolygon, viewState, renderState );
289 }
290
291 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
292 fillTexturedPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
293 const css::rendering::ViewState& viewState,
294 const css::rendering::RenderState& renderState,
295 const css::uno::Sequence< css::rendering::Texture >& textures) override
296 {
297 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures,
298 __func__,
299 static_cast< UnambiguousBaseType* >(this));
300
301 MutexType aGuard( BaseType::m_aMutex );
302
303 mbSurfaceDirty = true;
304
305 return maCanvasHelper.fillTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures );
306 }
307
308 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
309 fillTextureMappedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
310 const css::rendering::ViewState& viewState,
311 const css::rendering::RenderState& renderState,
312 const css::uno::Sequence< css::rendering::Texture >& textures,
313 const css::uno::Reference< css::geometry::XMapping2D >& xMapping ) override
314 {
315 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping,
316 __func__,
317 static_cast< UnambiguousBaseType* >(this));
318
319 MutexType aGuard( BaseType::m_aMutex );
320
321 mbSurfaceDirty = true;
322
323 return maCanvasHelper.fillTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping );
324 }
325
326
327 virtual css::uno::Reference< css::rendering::XCanvasFont > SAL_CALL
328 createFont( const css::rendering::FontRequest& fontRequest,
329 const css::uno::Sequence< css::beans::PropertyValue >& extraFontProperties,
330 const css::geometry::Matrix2D& fontMatrix ) override
331 {
332 tools::verifyArgs(fontRequest,
333 // dummy, to keep argPos in sync
334 fontRequest,
335 fontMatrix,
336 __func__,
337 static_cast< UnambiguousBaseType* >(this));
338
339 MutexType aGuard( BaseType::m_aMutex );
340
341 return maCanvasHelper.createFont( this, fontRequest, extraFontProperties, fontMatrix );
342 }
343
344
345 virtual css::uno::Sequence< css::rendering::FontInfo > SAL_CALL
346 queryAvailableFonts( const css::rendering::FontInfo& aFilter,
347 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties ) override
348 {
349 tools::verifyArgs(aFilter,
350 __func__,
351 static_cast< UnambiguousBaseType* >(this));
352
353 MutexType aGuard( BaseType::m_aMutex );
354
355 return maCanvasHelper.queryAvailableFonts( this, aFilter, aFontProperties );
356 }
357
358
359 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
360 drawText(const css::rendering::StringContext& text,
361 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
362 const css::rendering::ViewState& viewState,
363 const css::rendering::RenderState& renderState,
364 sal_Int8 textDirection) override
365 {
366 tools::verifyArgs(xFont, viewState, renderState,
367 __func__,
368 static_cast< UnambiguousBaseType* >(this));
369 tools::verifyRange( textDirection,
370 css::rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
371 css::rendering::TextDirection::STRONG_RIGHT_TO_LEFT );
372
373 MutexType aGuard( BaseType::m_aMutex );
374
375 mbSurfaceDirty = true;
376
377 return maCanvasHelper.drawText( this, text, xFont, viewState, renderState, textDirection );
378 }
379
380
381 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
382 drawTextLayout(const css::uno::Reference< css::rendering::XTextLayout >& laidOutText,
383 const css::rendering::ViewState& viewState,
384 const css::rendering::RenderState& renderState) override
385 {
386 tools::verifyArgs(laidOutText, viewState, renderState,
387 __func__,
388 static_cast< UnambiguousBaseType* >(this));
389
390 MutexType aGuard( BaseType::m_aMutex );
391
392 mbSurfaceDirty = true;
393
394 return maCanvasHelper.drawTextLayout( this, laidOutText, viewState, renderState );
395 }
396
397
398 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
399 drawBitmap( const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
400 const css::rendering::ViewState& viewState,
401 const css::rendering::RenderState& renderState ) override
402 {
403 tools::verifyArgs(xBitmap, viewState, renderState,
404 __func__,
405 static_cast< UnambiguousBaseType* >(this));
406
407 MutexType aGuard( BaseType::m_aMutex );
408
409 mbSurfaceDirty = true;
410
411 return maCanvasHelper.drawBitmap( this, xBitmap, viewState, renderState );
412 }
413
414 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
415 drawBitmapModulated( const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
416 const css::rendering::ViewState& viewState,
417 const css::rendering::RenderState& renderState ) override
418 {
419 tools::verifyArgs(xBitmap, viewState, renderState,
420 __func__,
421 static_cast< UnambiguousBaseType* >(this));
422
423 MutexType aGuard( BaseType::m_aMutex );
424
425 mbSurfaceDirty = true;
426
427 return maCanvasHelper.drawBitmapModulated( this, xBitmap, viewState, renderState );
428 }
429
430 virtual css::uno::Reference< css::rendering::XGraphicDevice > SAL_CALL
431 getDevice() override
432 {
433 MutexType aGuard( BaseType::m_aMutex );
434
435 return maCanvasHelper.getDevice();
436 }
437
438 protected:
439 ~CanvasBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
440
441 CanvasHelper maCanvasHelper;
442 mutable bool mbSurfaceDirty;
443
444 private:
445 CanvasBase( const CanvasBase& ) = delete;
446 CanvasBase& operator=( const CanvasBase& ) = delete;
447 };
448}
449
450/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper template to handle XCanvas method forwarding to CanvasHelper.
Definition: canvasbase.hxx:109
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL fillTextureMappedPolyPolygon(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) override
Definition: canvasbase.hxx:309
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL strokeTextureMappedPolyPolygon(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) override
Definition: canvasbase.hxx:240
virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL queryStrokeShapes(const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::rendering::StrokeAttributes &strokeAttributes) override
Definition: canvasbase.hxx:259
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL fillPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:276
virtual void disposeThis() override
Definition: canvasbase.hxx:123
CanvasBase()
Create CanvasBase.
Definition: canvasbase.hxx:117
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:441
virtual css::uno::Sequence< css::rendering::FontInfo > SAL_CALL queryAvailableFonts(const css::rendering::FontInfo &aFilter, const css::uno::Sequence< css::beans::PropertyValue > &aFontProperties) override
Definition: canvasbase.hxx:346
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawBitmap(const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:399
CanvasBase & operator=(const CanvasBase &)=delete
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawText(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) override
Definition: canvasbase.hxx:360
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawTextLayout(const css::uno::Reference< css::rendering::XTextLayout > &laidOutText, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:382
virtual void SAL_CALL drawBezier(const css::geometry::RealBezierSegment2D &aBezierSegment, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:172
virtual css::uno::Reference< css::rendering::XCanvasFont > SAL_CALL createFont(const css::rendering::FontRequest &fontRequest, const css::uno::Sequence< css::beans::PropertyValue > &extraFontProperties, const css::geometry::Matrix2D &fontMatrix) override
Definition: canvasbase.hxx:328
virtual void SAL_CALL drawLine(const css::geometry::RealPoint2D &aStartPoint, const css::geometry::RealPoint2D &aEndPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:156
virtual void SAL_CALL clear() override
Definition: canvasbase.hxx:134
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL fillTexturedPolyPolygon(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) override
Definition: canvasbase.hxx:292
virtual void SAL_CALL drawPoint(const css::geometry::RealPoint2D &aPoint, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:143
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL strokeTexturedPolyPolygon(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) override
Definition: canvasbase.hxx:222
virtual css::uno::Reference< css::rendering::XGraphicDevice > SAL_CALL getDevice() override
Definition: canvasbase.hxx:431
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:189
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawBitmapModulated(const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
Definition: canvasbase.hxx:415
CanvasBase(const CanvasBase &)=delete
UnambiguousBase UnambiguousBaseType
Definition: canvasbase.hxx:113
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL strokePolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D > &xPolyPolygon, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const css::rendering::StrokeAttributes &strokeAttributes) override
Definition: canvasbase.hxx:205
def text(shape, orig_st)
void verifyRange(NumType arg, NumType lowerBound, NumType upperBound)
Range checker, which throws css::lang::IllegalArgument exception, when range is violated.
void verifyArgs(const Arg0 &rArg0, const char *pStr, const css::uno::Reference< css::uno::XInterface > &xIf)
signed char sal_Int8
Base