1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pointaction.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppcanvas.hxx"
34 #include <rtl/logfile.hxx>
35 #include <com/sun/star/rendering/XCanvas.hpp>
37 #include <tools/gen.hxx>
38 #include <vcl/canvastools.hxx>
40 #include <basegfx/range/b2drange.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
42 #include <basegfx/tools/canvastools.hxx>
43 #include <canvas/canvastools.hxx>
45 #include <boost/utility.hpp>
47 #include "pointaction.hxx"
48 #include "outdevstate.hxx"
49 #include "cppcanvas/canvas.hxx"
50 #include "mtftools.hxx"
53 using namespace ::com::sun::star
;
61 class PointAction
: public Action
, private ::boost::noncopyable
64 PointAction( const ::basegfx::B2DPoint
&,
65 const CanvasSharedPtr
&,
67 PointAction( const ::basegfx::B2DPoint
&,
68 const CanvasSharedPtr
&,
72 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
73 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
,
74 const Subset
& rSubset
) const;
76 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
77 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
78 const Subset
& rSubset
) const;
80 virtual sal_Int32
getActionCount() const;
83 // default: disabled copy/assignment
84 PointAction(const PointAction
&);
85 PointAction
& operator = ( const PointAction
& );
87 ::basegfx::B2DPoint maPoint
;
88 CanvasSharedPtr mpCanvas
;
89 ::com::sun::star::rendering::RenderState maState
;
92 PointAction::PointAction( const ::basegfx::B2DPoint
& rPoint
,
93 const CanvasSharedPtr
& rCanvas
,
94 const OutDevState
& rState
) :
99 tools::initRenderState(maState
,rState
);
100 maState
.DeviceColor
= rState
.lineColor
;
103 PointAction::PointAction( const ::basegfx::B2DPoint
& rPoint
,
104 const CanvasSharedPtr
& rCanvas
,
105 const OutDevState
& rState
,
106 const ::Color
& rAltColor
) :
111 tools::initRenderState(maState
,rState
);
112 maState
.DeviceColor
= ::vcl::unotools::colorToDoubleSequence(
114 rCanvas
->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
117 bool PointAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
119 RTL_LOGFILE_CONTEXT( aLog
, "::cppcanvas::internal::PointAction::render()" );
120 RTL_LOGFILE_CONTEXT_TRACE1( aLog
, "::cppcanvas::internal::PointAction: 0x%X", this );
122 rendering::RenderState
aLocalState( maState
);
123 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
125 mpCanvas
->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint
),
126 mpCanvas
->getViewState(),
132 bool PointAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
,
133 const Subset
& rSubset
) const
135 // point only contains a single action, fail if subset
136 // requests different range
137 if( rSubset
.mnSubsetBegin
!= 0 ||
138 rSubset
.mnSubsetEnd
!= 1 )
141 return render( rTransformation
);
144 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
146 rendering::RenderState
aLocalState( maState
);
147 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
149 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint
.getX()-1,
153 mpCanvas
->getViewState(),
157 ::basegfx::B2DRange
PointAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
158 const Subset
& rSubset
) const
160 // point only contains a single action, empty bounds
161 // if subset requests different range
162 if( rSubset
.mnSubsetBegin
!= 0 ||
163 rSubset
.mnSubsetEnd
!= 1 )
164 return ::basegfx::B2DRange();
166 return getBounds( rTransformation
);
169 sal_Int32
PointAction::getActionCount() const
175 ActionSharedPtr
PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
176 const CanvasSharedPtr
& rCanvas
,
177 const OutDevState
& rState
)
179 return ActionSharedPtr( new PointAction( rPoint
, rCanvas
, rState
) );
182 ActionSharedPtr
PointActionFactory::createPointAction( const ::basegfx::B2DPoint
& rPoint
,
183 const CanvasSharedPtr
& rCanvas
,
184 const OutDevState
& rState
,
185 const ::Color
& rColor
)
187 return ActionSharedPtr( new PointAction( rPoint
, rCanvas
, rState
, rColor
) );