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 "lineaction.hxx"
22 #include <outdevstate.hxx>
24 #include <com/sun/star/rendering/XCanvas.hpp>
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>
32 #include <cppcanvas/canvas.hxx>
35 #include "mtftools.hxx"
38 using namespace ::com::sun::star
;
40 namespace cppcanvas::internal
44 class LineAction
: public Action
47 LineAction( const ::basegfx::B2DPoint
&,
48 const ::basegfx::B2DPoint
&,
52 LineAction(const LineAction
&) = delete;
53 const LineAction
& operator=(const LineAction
&) = delete;
55 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
) const override
;
56 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
57 const Subset
& rSubset
) const override
;
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
;
63 virtual sal_Int32
getActionCount() const override
;
66 ::basegfx::B2DPoint maStartPoint
;
67 ::basegfx::B2DPoint maEndPoint
;
68 CanvasSharedPtr mpCanvas
;
69 rendering::RenderState maState
;
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
))
80 tools::initRenderState(maState
,rState
);
81 maState
.DeviceColor
= rState
.lineColor
;
84 bool LineAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
86 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
87 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex
<< this );
89 rendering::RenderState
aLocalState( maState
);
90 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
92 mpCanvas
->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint
),
93 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint
),
94 mpCanvas
->getViewState(),
100 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
101 const Subset
& rSubset
) const
103 // line only contains a single action, fail if subset
104 // requests different range
105 if( rSubset
.mnSubsetBegin
!= 0 ||
106 rSubset
.mnSubsetEnd
!= 1 )
109 return render( rTransformation
);
112 ::basegfx::B2DRange
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
114 rendering::RenderState
aLocalState( maState
);
115 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
117 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint
,
119 mpCanvas
->getViewState(),
123 ::basegfx::B2DRange
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
124 const Subset
& rSubset
) const
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();
132 return getBounds( rTransformation
);
135 sal_Int32
LineAction::getActionCount() const
141 std::shared_ptr
<Action
> LineActionFactory::createLineAction( const ::basegfx::B2DPoint
& rStartPoint
,
142 const ::basegfx::B2DPoint
& rEndPoint
,
143 const CanvasSharedPtr
& rCanvas
,
144 const OutDevState
& rState
)
146 return std::make_shared
<LineAction
>( rStartPoint
,
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */