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