LibreOffice Module cppcanvas (master) 1
implcanvas.cxx
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
24
25#include <com/sun/star/rendering/XCanvas.hpp>
26
28#include <utility>
29
30#include "implcanvas.hxx"
31
32
33using namespace ::com::sun::star;
34
35namespace cppcanvas::internal
36{
37
38 ImplCanvas::ImplCanvas( uno::Reference< rendering::XCanvas > xCanvas ) :
39 mxCanvas(std::move( xCanvas ))
40 {
41 OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" );
42
43 ::canvas::tools::initViewState( maViewState );
44 }
45
46 ImplCanvas::~ImplCanvas()
47 {
48 }
49
50 void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
51 {
52 ::canvas::tools::setViewStateTransform( maViewState, rMatrix );
53 }
54
55 ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const
56 {
58 return ::canvas::tools::getViewStateTransform( aMatrix,
59 maViewState );
60 }
61
62 void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
63 {
64 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
65 maClipPolyPolygon = rClipPoly;
66 maViewState.Clip.clear();
67 }
68
69 void ImplCanvas::setClip()
70 {
71 maClipPolyPolygon.reset();
72 maViewState.Clip.clear();
73 }
74
75 ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const
76 {
77 return !maClipPolyPolygon ? nullptr : &(*maClipPolyPolygon);
78 }
79
80 CanvasSharedPtr ImplCanvas::clone() const
81 {
82 return std::make_shared<ImplCanvas>( *this );
83 }
84
85 void ImplCanvas::clear() const
86 {
87 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" );
88 mxCanvas->clear();
89 }
90
91 uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const
92 {
93 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
94
95 return mxCanvas;
96 }
97
98 rendering::ViewState ImplCanvas::getViewState() const
99 {
100 if( maClipPolyPolygon && !maViewState.Clip.is() )
101 {
102 if( !mxCanvas.is() )
103 return maViewState;
104
105 maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
106 mxCanvas->getDevice(),
107 *maClipPolyPolygon );
108 }
109
110 return maViewState;
111 }
112
113}
114
115/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< rendering::XCanvas > mxCanvas
ImplCanvas(css::uno::Reference< css::rendering::XCanvas > xCanvas)
std::shared_ptr< Canvas > CanvasSharedPtr