update dev300-m58
[ooovba.git] / cppcanvas / source / mtfrenderer / lineaction.cxx
blob55ee258e7ac555aee5b727723a408cbaa9ecf209
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lineaction.cxx,v $
10 * $Revision: 1.11 $
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 <lineaction.hxx>
35 #include <outdevstate.hxx>
37 #include <rtl/logfile.hxx>
38 #include <com/sun/star/rendering/XCanvas.hpp>
40 #include <tools/gen.hxx>
41 #include <vcl/canvastools.hxx>
43 #include <basegfx/range/b2drange.hxx>
44 #include <basegfx/point/b2dpoint.hxx>
45 #include <basegfx/tools/canvastools.hxx>
46 #include <canvas/canvastools.hxx>
48 #include <boost/utility.hpp>
50 #include <cppcanvas/canvas.hxx>
52 #include <mtftools.hxx>
55 using namespace ::com::sun::star;
57 namespace cppcanvas
59 namespace internal
61 namespace
63 class LineAction : public Action, private ::boost::noncopyable
65 public:
66 LineAction( const ::basegfx::B2DPoint&,
67 const ::basegfx::B2DPoint&,
68 const CanvasSharedPtr&,
69 const OutDevState& );
71 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
72 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation,
73 const Subset& rSubset ) const;
75 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const;
76 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
77 const Subset& rSubset ) const;
79 virtual sal_Int32 getActionCount() const;
81 private:
82 ::basegfx::B2DPoint maStartPoint;
83 ::basegfx::B2DPoint maEndPoint;
84 CanvasSharedPtr mpCanvas;
85 rendering::RenderState maState;
88 LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
89 const ::basegfx::B2DPoint& rEndPoint,
90 const CanvasSharedPtr& rCanvas,
91 const OutDevState& rState ) :
92 maStartPoint( rStartPoint ),
93 maEndPoint( rEndPoint ),
94 mpCanvas( rCanvas ),
95 maState()
97 tools::initRenderState(maState,rState);
98 maState.DeviceColor = rState.lineColor;
101 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
103 RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::LineAction::render()" );
104 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::LineAction: 0x%X", this );
106 rendering::RenderState aLocalState( maState );
107 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
109 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
110 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
111 mpCanvas->getViewState(),
112 aLocalState );
114 return true;
117 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation,
118 const Subset& rSubset ) const
120 // line only contains a single action, fail if subset
121 // requests different range
122 if( rSubset.mnSubsetBegin != 0 ||
123 rSubset.mnSubsetEnd != 1 )
124 return false;
126 return render( rTransformation );
129 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
131 rendering::RenderState aLocalState( maState );
132 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
134 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
135 maEndPoint ),
136 mpCanvas->getViewState(),
137 aLocalState );
140 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
141 const Subset& rSubset ) const
143 // line only contains a single action, empty bounds
144 // if subset requests different range
145 if( rSubset.mnSubsetBegin != 0 ||
146 rSubset.mnSubsetEnd != 1 )
147 return ::basegfx::B2DRange();
149 return getBounds( rTransformation );
152 sal_Int32 LineAction::getActionCount() const
154 return 1;
158 ActionSharedPtr LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
159 const ::basegfx::B2DPoint& rEndPoint,
160 const CanvasSharedPtr& rCanvas,
161 const OutDevState& rState )
163 return ActionSharedPtr( new LineAction( rStartPoint,
164 rEndPoint,
165 rCanvas,
166 rState) );