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 <com/sun/star/rendering/XCanvas.hpp>
23 #include <sal/types.h>
24 #include <sal/log.hxx>
26 #include <vcl/canvastools.hxx>
28 #include <basegfx/range/b2drange.hxx>
29 #include <basegfx/point/b2dpoint.hxx>
30 #include <basegfx/utils/canvastools.hxx>
31 #include <canvas/canvastools.hxx>
33 #include "pointaction.hxx"
34 #include <outdevstate.hxx>
35 #include <cppcanvas/canvas.hxx>
36 #include "mtftools.hxx"
39 using namespace ::com::sun::star
;
41 namespace cppcanvas::internal
45 class PointAction
: public Action
48 PointAction( const ::basegfx::B2DPoint
&,
51 PointAction( const ::basegfx::B2DPoint
&,
52 const CanvasSharedPtr
&,
56 PointAction(const PointAction
&) = delete;
57 const PointAction
& operator=(const PointAction
&) = 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 maPoint
;
71 CanvasSharedPtr mpCanvas
;
72 css::rendering::RenderState maState
;
75 PointAction::PointAction( const ::basegfx::B2DPoint
& rPoint
,
76 CanvasSharedPtr xCanvas
,
77 const OutDevState
& rState
) :
79 mpCanvas(std::move( xCanvas
))
81 tools::initRenderState(maState
,rState
);
82 maState
.DeviceColor
= rState
.lineColor
;
85 PointAction::PointAction( const ::basegfx::B2DPoint
& rPoint
,
86 const CanvasSharedPtr
& rCanvas
,
87 const OutDevState
& rState
,
88 const ::Color
& rAltColor
) :
92 tools::initRenderState(maState
,rState
);
93 maState
.DeviceColor
= vcl::unotools::colorToDoubleSequence(
95 rCanvas
->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
98 bool PointAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
100 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction::render()" );
101 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction: 0x" << std::hex
<< this );
103 rendering::RenderState
aLocalState( maState
);
104 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
106 mpCanvas
->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint
),
107 mpCanvas
->getViewState(),
113 bool PointAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
114 const Subset
& rSubset
) const
116 // point only contains a single action, fail if subset
117 // requests different range
118 if( rSubset
.mnSubsetBegin
!= 0 ||
119 rSubset
.mnSubsetEnd
!= 1 )
122 return render( rTransformation
);
125 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
127 rendering::RenderState
aLocalState( maState
);
128 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
130 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint
.getX()-1,
134 mpCanvas
->getViewState(),
138 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
139 const Subset
& rSubset
) const
141 // point only contains a single action, empty bounds
142 // if subset requests different range
143 if( rSubset
.mnSubsetBegin
!= 0 ||
144 rSubset
.mnSubsetEnd
!= 1 )
145 return ::basegfx::B2DRange();
147 return getBounds( rTransformation
);
150 sal_Int32
PointAction::getActionCount() const
156 std::shared_ptr
<Action
> PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
157 const CanvasSharedPtr
& rCanvas
,
158 const OutDevState
& rState
)
160 return std::make_shared
<PointAction
>( rPoint
, rCanvas
, rState
);
163 std::shared_ptr
<Action
> PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
164 const CanvasSharedPtr
& rCanvas
,
165 const OutDevState
& rState
,
166 const ::Color
& rColor
)
168 return std::make_shared
<PointAction
>( rPoint
, rCanvas
, rState
, rColor
);
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */