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>
25 #include <vcl/canvastools.hxx>
27 #include <basegfx/range/b2drange.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
29 #include <basegfx/utils/canvastools.hxx>
30 #include <canvas/canvastools.hxx>
32 #include "pointaction.hxx"
33 #include <outdevstate.hxx>
34 #include <cppcanvas/canvas.hxx>
35 #include "mtftools.hxx"
38 using namespace ::com::sun::star
;
40 namespace cppcanvas::internal
44 class PointAction
: public Action
47 PointAction( const ::basegfx::B2DPoint
&,
48 const CanvasSharedPtr
&,
50 PointAction( const ::basegfx::B2DPoint
&,
51 const CanvasSharedPtr
&,
55 PointAction(const PointAction
&) = delete;
56 const PointAction
& operator=(const PointAction
&) = delete;
58 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
) const override
;
59 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
60 const Subset
& rSubset
) const override
;
62 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const override
;
63 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
64 const Subset
& rSubset
) const override
;
66 virtual sal_Int32
getActionCount() const override
;
69 ::basegfx::B2DPoint maPoint
;
70 CanvasSharedPtr mpCanvas
;
71 css::rendering::RenderState maState
;
74 PointAction::PointAction( const ::basegfx::B2DPoint
& rPoint
,
75 const CanvasSharedPtr
& rCanvas
,
76 const OutDevState
& rState
) :
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
) :
93 tools::initRenderState(maState
,rState
);
94 maState
.DeviceColor
= vcl::unotools::colorToDoubleSequence(
96 rCanvas
->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
99 bool PointAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
101 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction::render()" );
102 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction: 0x" << std::hex
<< this );
104 rendering::RenderState
aLocalState( maState
);
105 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
107 mpCanvas
->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint
),
108 mpCanvas
->getViewState(),
114 bool PointAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
115 const Subset
& rSubset
) const
117 // point only contains a single action, fail if subset
118 // requests different range
119 if( rSubset
.mnSubsetBegin
!= 0 ||
120 rSubset
.mnSubsetEnd
!= 1 )
123 return render( rTransformation
);
126 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
128 rendering::RenderState
aLocalState( maState
);
129 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
131 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint
.getX()-1,
135 mpCanvas
->getViewState(),
139 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
140 const Subset
& rSubset
) const
142 // point only contains a single action, empty bounds
143 // if subset requests different range
144 if( rSubset
.mnSubsetBegin
!= 0 ||
145 rSubset
.mnSubsetEnd
!= 1 )
146 return ::basegfx::B2DRange();
148 return getBounds( rTransformation
);
151 sal_Int32
PointAction::getActionCount() const
157 std::shared_ptr
<Action
> PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
158 const CanvasSharedPtr
& rCanvas
,
159 const OutDevState
& rState
)
161 return std::make_shared
<PointAction
>( rPoint
, rCanvas
, rState
);
164 std::shared_ptr
<Action
> PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
165 const CanvasSharedPtr
& rCanvas
,
166 const OutDevState
& rState
,
167 const ::Color
& rColor
)
169 return std::make_shared
<PointAction
>( rPoint
, rCanvas
, rState
, rColor
);
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */