| 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 "lineaction.hxx" |
| 22 |
#include <outdevstate.hxx> |
| 23 |
|
| 24 |
#include <com/sun/star/rendering/XCanvas.hpp> |
| 25 |
|
| 26 |
#include <basegfx/range/b2drange.hxx> |
| 27 |
#include <basegfx/point/b2dpoint.hxx> |
| 28 |
#include <basegfx/utils/canvastools.hxx> |
| 29 |
#include <canvas/canvastools.hxx> |
| 30 |
#include <sal/log.hxx> |
| 31 |
|
| 32 |
#include <cppcanvas/canvas.hxx> |
| 33 |
#include <utility> |
| 34 |
|
| 35 |
#include "mtftools.hxx" |
| 36 |
|
| 37 |
|
| 38 |
using namespace ::com::sun::star; |
| 39 |
|
| 40 |
namespace cppcanvas::internal |
| 41 |
{ |
| 42 |
namespace |
| 43 |
{ |
| 44 |
class LineAction : public Action |
| 45 |
{ |
| 46 |
public: |
| 47 |
LineAction( const ::basegfx::B2DPoint&, |
| 48 |
const ::basegfx::B2DPoint&, |
| 49 |
CanvasSharedPtr, |
| 50 |
const OutDevState& ); |
| 51 |
|
| 52 |
LineAction(const LineAction&) = delete; |
| 53 |
const LineAction& operator=(const LineAction&) = delete; |
| 54 |
|
| 55 |
virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override; |
| 56 |
virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
| 57 |
const Subset& rSubset ) const override; |
| 58 |
|
| 59 |
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override; |
| 60 |
virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, |
| 61 |
const Subset& rSubset ) const override; |
| 62 |
|
| 63 |
virtual sal_Int32 getActionCount() const override; |
| 64 |
|
| 65 |
private: |
| 66 |
::basegfx::B2DPoint maStartPoint; |
| 67 |
::basegfx::B2DPoint maEndPoint; |
| 68 |
CanvasSharedPtr mpCanvas; |
| 69 |
rendering::RenderState maState; |
| 70 |
}; |
| 71 |
|
| 72 |
LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint, |
| 73 |
const ::basegfx::B2DPoint& rEndPoint, |
| 74 |
CanvasSharedPtr xCanvas, |
| 75 |
const OutDevState& rState ) : |
| 76 |
maStartPoint( rStartPoint ), |
| 77 |
maEndPoint( rEndPoint ), |
| 78 |
mpCanvas(std::move( xCanvas )) |
| 79 |
{ |
| 80 |
cppcanvastools::initRenderState(maState,rState); |
| 81 |
maState.DeviceColor = rState.lineColor; |
| 82 |
} |
| 83 |
|
| 84 |
bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const |
| 85 |
{ |
| 86 |
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" ); |
| 87 |
SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this ); |
| 88 |
|
| 89 |
rendering::RenderState aLocalState( maState ); |
| 90 |
::canvastools::prependToRenderState(aLocalState, rTransformation); |
| 91 |
|
| 92 |
mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint), |
| 93 |
::basegfx::unotools::point2DFromB2DPoint(maEndPoint), |
| 94 |
mpCanvas->getViewState(), |
| 95 |
aLocalState ); |
| 96 |
|
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
| 101 |
const Subset& rSubset ) const |
| 102 |
{ |
| 103 |
// line only contains a single action, fail if subset |
| 104 |
// requests different range |
| 105 |
if( rSubset.mnSubsetBegin != 0 || |
| 106 |
rSubset.mnSubsetEnd != 1 ) |
| 107 |
return false; |
| 108 |
|
| 109 |
return render( rTransformation ); |
| 110 |
} |
| 111 |
|
| 112 |
::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const |
| 113 |
{ |
| 114 |
rendering::RenderState aLocalState( maState ); |
| 115 |
::canvastools::prependToRenderState(aLocalState, rTransformation); |
| 116 |
|
| 117 |
return cppcanvastools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint, |
| 118 |
maEndPoint ), |
| 119 |
mpCanvas->getViewState(), |
| 120 |
aLocalState ); |
| 121 |
} |
| 122 |
|
| 123 |
::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, |
| 124 |
const Subset& rSubset ) const |
| 125 |
{ |
| 126 |
// line only contains a single action, empty bounds |
| 127 |
// if subset requests different range |
| 128 |
if( rSubset.mnSubsetBegin != 0 || |
| 129 |
rSubset.mnSubsetEnd != 1 ) |
| 130 |
return ::basegfx::B2DRange(); |
| 131 |
|
| 132 |
return getBounds( rTransformation ); |
| 133 |
} |
| 134 |
|
| 135 |
sal_Int32 LineAction::getActionCount() const |
| 136 |
{ |
| 137 |
return 1; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
std::shared_ptr<Action> LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint, |
| 142 |
const ::basegfx::B2DPoint& rEndPoint, |
| 143 |
const CanvasSharedPtr& rCanvas, |
| 144 |
const OutDevState& rState ) |
| 145 |
{ |
| 146 |
return std::make_shared<LineAction>( rStartPoint, |
| 147 |
rEndPoint, |
| 148 |
rCanvas, |
| 149 |
rState); |
| 150 |
} |
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |