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 <tools/gen.hxx>
27 #include <vcl/canvastools.hxx>
29 #include <basegfx/range/b2drange.hxx>
30 #include <basegfx/point/b2dpoint.hxx>
31 #include <basegfx/utils/canvastools.hxx>
32 #include <canvas/canvastools.hxx>
33 #include <sal/log.hxx>
35 #include <cppcanvas/canvas.hxx>
37 #include "mtftools.hxx"
40 using namespace ::com::sun::star
;
48 class LineAction
: public Action
51 LineAction( const ::basegfx::B2DPoint
&,
52 const ::basegfx::B2DPoint
&,
53 const CanvasSharedPtr
&,
56 LineAction(const LineAction
&) = delete;
57 const LineAction
& operator=(const LineAction
&) = delete;
59 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
) const override
;
60 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
61 const Subset
& rSubset
) const override
;
63 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const override
;
64 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
65 const Subset
& rSubset
) const override
;
67 virtual sal_Int32
getActionCount() const override
;
70 ::basegfx::B2DPoint maStartPoint
;
71 ::basegfx::B2DPoint maEndPoint
;
72 CanvasSharedPtr mpCanvas
;
73 rendering::RenderState maState
;
76 LineAction::LineAction( const ::basegfx::B2DPoint
& rStartPoint
,
77 const ::basegfx::B2DPoint
& rEndPoint
,
78 const CanvasSharedPtr
& rCanvas
,
79 const OutDevState
& rState
) :
80 maStartPoint( rStartPoint
),
81 maEndPoint( rEndPoint
),
85 tools::initRenderState(maState
,rState
);
86 maState
.DeviceColor
= rState
.lineColor
;
89 bool LineAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
91 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
92 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex
<< this );
94 rendering::RenderState
aLocalState( maState
);
95 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
97 mpCanvas
->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint
),
98 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint
),
99 mpCanvas
->getViewState(),
105 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
106 const Subset
& rSubset
) const
108 // line only contains a single action, fail if subset
109 // requests different range
110 if( rSubset
.mnSubsetBegin
!= 0 ||
111 rSubset
.mnSubsetEnd
!= 1 )
114 return render( rTransformation
);
117 ::basegfx::B2DRange
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
119 rendering::RenderState
aLocalState( maState
);
120 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
122 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint
,
124 mpCanvas
->getViewState(),
128 ::basegfx::B2DRange
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
129 const Subset
& rSubset
) const
131 // line only contains a single action, empty bounds
132 // if subset requests different range
133 if( rSubset
.mnSubsetBegin
!= 0 ||
134 rSubset
.mnSubsetEnd
!= 1 )
135 return ::basegfx::B2DRange();
137 return getBounds( rTransformation
);
140 sal_Int32
LineAction::getActionCount() const
146 std::shared_ptr
<Action
> LineActionFactory::createLineAction( const ::basegfx::B2DPoint
& rStartPoint
,
147 const ::basegfx::B2DPoint
& rEndPoint
,
148 const CanvasSharedPtr
& rCanvas
,
149 const OutDevState
& rState
)
151 return std::shared_ptr
<Action
>( new LineAction( rStartPoint
,
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */