| 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 <canvasgraphichelper.hxx> |
| 22 |
|
| 23 |
#include <com/sun/star/rendering/XCanvas.hpp> |
| 24 |
|
| 25 |
#include <canvas/canvastools.hxx> |
| 26 |
#include <basegfx/utils/canvastools.hxx> |
| 27 |
#include <osl/diagnose.h> |
| 28 |
#include <utility> |
| 29 |
|
| 30 |
|
| 31 |
using namespace ::com::sun::star; |
| 32 |
|
| 33 |
/* Implementation of CanvasGraphicHelper class */ |
| 34 |
|
| 35 |
namespace cppcanvas::internal |
| 36 |
{ |
| 37 |
CanvasGraphicHelper::CanvasGraphicHelper( CanvasSharedPtr xParentCanvas ) : |
| 38 |
mpCanvas(std::move( xParentCanvas )) |
| 39 |
{ |
| 40 |
OSL_ENSURE( mpCanvas && mpCanvas->getUNOCanvas().is(), |
| 41 |
"CanvasGraphicHelper::CanvasGraphicHelper: no valid canvas" ); |
| 42 |
|
| 43 |
::canvastools::initRenderState( maRenderState ); |
| 44 |
} |
| 45 |
|
| 46 |
void CanvasGraphicHelper::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) |
| 47 |
{ |
| 48 |
::canvastools::setRenderStateTransform( maRenderState, rMatrix ); |
| 49 |
} |
| 50 |
|
| 51 |
void CanvasGraphicHelper::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) |
| 52 |
{ |
| 53 |
// TODO(T3): not thread-safe. B2DPolyPolygon employs copy-on-write |
| 54 |
maClipPolyPolygon = rClipPoly; |
| 55 |
maRenderState.Clip.clear(); |
| 56 |
} |
| 57 |
|
| 58 |
void CanvasGraphicHelper::setClip() |
| 59 |
{ |
| 60 |
maClipPolyPolygon.reset(); |
| 61 |
maRenderState.Clip.clear(); |
| 62 |
} |
| 63 |
|
| 64 |
const rendering::RenderState& CanvasGraphicHelper::getRenderState() const |
| 65 |
{ |
| 66 |
if( maClipPolyPolygon && !maRenderState.Clip.is() ) |
| 67 |
{ |
| 68 |
uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() ); |
| 69 |
if( !xCanvas.is() ) |
| 70 |
return maRenderState; |
| 71 |
|
| 72 |
maRenderState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( |
| 73 |
xCanvas->getDevice(), |
| 74 |
*maClipPolyPolygon ); |
| 75 |
} |
| 76 |
|
| 77 |
return maRenderState; |
| 78 |
} |
| 79 |
|
| 80 |
void CanvasGraphicHelper::setCompositeOp( sal_Int8 aOp ) |
| 81 |
{ |
| 82 |
maRenderState.CompositeOperation = aOp; |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |