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