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