Get the style color and number just once
[LibreOffice.git] / cppcanvas / source / wrapper / implcanvas.cxx
blob6f13f7452e65451fa434f84b2debbcff736e37b8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <osl/diagnose.h>
26 #include <com/sun/star/rendering/XCanvas.hpp>
28 #include <canvas/canvastools.hxx>
29 #include <utility>
31 #include "implcanvas.hxx"
34 using namespace ::com::sun::star;
36 namespace cppcanvas::internal
39 ImplCanvas::ImplCanvas( uno::Reference< rendering::XCanvas > xCanvas ) :
40 mxCanvas(std::move( xCanvas ))
42 OSL_ENSURE( mxCanvas.is(), "Canvas::Canvas() invalid XCanvas" );
44 ::canvas::tools::initViewState( maViewState );
47 ImplCanvas::~ImplCanvas()
51 void ImplCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
53 ::canvas::tools::setViewStateTransform( maViewState, rMatrix );
56 ::basegfx::B2DHomMatrix ImplCanvas::getTransformation() const
58 return ::canvas::tools::getViewStateTransform( maViewState );
61 void ImplCanvas::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
63 // TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write
64 maClipPolyPolygon = rClipPoly;
65 maViewState.Clip.clear();
68 void ImplCanvas::setClip()
70 maClipPolyPolygon.reset();
71 maViewState.Clip.clear();
74 ::basegfx::B2DPolyPolygon const* ImplCanvas::getClip() const
76 return !maClipPolyPolygon ? nullptr : &(*maClipPolyPolygon);
79 CanvasSharedPtr ImplCanvas::clone() const
81 return std::make_shared<ImplCanvas>( *this );
84 void ImplCanvas::clear() const
86 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::clear(): Invalid XCanvas" );
87 mxCanvas->clear();
90 uno::Reference< rendering::XCanvas > ImplCanvas::getUNOCanvas() const
92 OSL_ENSURE( mxCanvas.is(), "ImplCanvas::getUNOCanvas(): Invalid XCanvas" );
94 return mxCanvas;
97 rendering::ViewState ImplCanvas::getViewState() const
99 if( maClipPolyPolygon && !maViewState.Clip.is() )
101 if( !mxCanvas.is() )
102 return maViewState;
104 maViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
105 mxCanvas->getDevice(),
106 *maClipPolyPolygon );
109 return maViewState;
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */