1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <basegfx/matrix/b2dhommatrix.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <basegfx/utils/canvastools.hxx>
25 #include <com/sun/star/rendering/XCanvas.hpp>
27 #include <canvas/canvastools.hxx>
30 #include "implcanvas.hxx"
33 using namespace ::com::sun::star
;
35 namespace cppcanvas::internal
38 ImplCanvas::ImplCanvas( uno::Reference
< rendering::XCanvas
> xCanvas
) :
39 mxCanvas(std::move( xCanvas
))
41 OSL_ENSURE( mxCanvas
.is(), "Canvas::Canvas() invalid XCanvas" );
43 ::canvas::tools::initViewState( maViewState
);
46 ImplCanvas::~ImplCanvas()
50 void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix
& rMatrix
)
52 ::canvas::tools::setViewStateTransform( maViewState
, rMatrix
);
55 ::basegfx::B2DHomMatrix
ImplCanvas::getTransformation() const
57 ::basegfx::B2DHomMatrix aMatrix
;
58 return ::canvas::tools::getViewStateTransform( aMatrix
,
62 void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
64 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
65 maClipPolyPolygon
= rClipPoly
;
66 maViewState
.Clip
.clear();
69 void ImplCanvas::setClip()
71 maClipPolyPolygon
.reset();
72 maViewState
.Clip
.clear();
75 ::basegfx::B2DPolyPolygon
const* ImplCanvas::getClip() const
77 return !maClipPolyPolygon
? nullptr : &(*maClipPolyPolygon
);
80 CanvasSharedPtr
ImplCanvas::clone() const
82 return std::make_shared
<ImplCanvas
>( *this );
85 void ImplCanvas::clear() const
87 OSL_ENSURE( mxCanvas
.is(), "ImplCanvas::clear(): Invalid XCanvas" );
91 uno::Reference
< rendering::XCanvas
> ImplCanvas::getUNOCanvas() const
93 OSL_ENSURE( mxCanvas
.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
98 rendering::ViewState
ImplCanvas::getViewState() const
100 if( maClipPolyPolygon
&& !maViewState
.Clip
.is() )
105 maViewState
.Clip
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
106 mxCanvas
->getDevice(),
107 *maClipPolyPolygon
);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */