1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <lineaction.hxx>
31 #include <outdevstate.hxx>
33 #include <rtl/logfile.hxx>
34 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <tools/gen.hxx>
37 #include <vcl/canvastools.hxx>
39 #include <basegfx/range/b2drange.hxx>
40 #include <basegfx/point/b2dpoint.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 #include <canvas/canvastools.hxx>
44 #include <boost/utility.hpp>
46 #include <cppcanvas/canvas.hxx>
48 #include <mtftools.hxx>
51 using namespace ::com::sun::star
;
59 class LineAction
: public Action
, private ::boost::noncopyable
62 LineAction( const ::basegfx::B2DPoint
&,
63 const ::basegfx::B2DPoint
&,
64 const CanvasSharedPtr
&,
67 virtual bool render( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
68 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
69 const Subset
& rSubset
) const;
71 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
72 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
73 const Subset
& rSubset
) const;
75 virtual sal_Int32
getActionCount() const;
78 ::basegfx::B2DPoint maStartPoint
;
79 ::basegfx::B2DPoint maEndPoint
;
80 CanvasSharedPtr mpCanvas
;
81 rendering::RenderState maState
;
84 LineAction::LineAction( const ::basegfx::B2DPoint
& rStartPoint
,
85 const ::basegfx::B2DPoint
& rEndPoint
,
86 const CanvasSharedPtr
& rCanvas
,
87 const OutDevState
& rState
) :
88 maStartPoint( rStartPoint
),
89 maEndPoint( rEndPoint
),
93 tools::initRenderState(maState
,rState
);
94 maState
.DeviceColor
= rState
.lineColor
;
97 bool LineAction::render( const ::basegfx::B2DHomMatrix
& rTransformation
) const
99 RTL_LOGFILE_CONTEXT( aLog
, "::cppcanvas::internal::LineAction::render()" );
100 RTL_LOGFILE_CONTEXT_TRACE1( aLog
, "::cppcanvas::internal::LineAction: 0x%X", this );
102 rendering::RenderState
aLocalState( maState
);
103 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
105 mpCanvas
->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint
),
106 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint
),
107 mpCanvas
->getViewState(),
113 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
114 const Subset
& rSubset
) const
116 // line 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
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
127 rendering::RenderState
aLocalState( maState
);
128 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
130 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint
,
132 mpCanvas
->getViewState(),
136 ::basegfx::B2DRange
LineAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
137 const Subset
& rSubset
) const
139 // line only contains a single action, empty bounds
140 // if subset requests different range
141 if( rSubset
.mnSubsetBegin
!= 0 ||
142 rSubset
.mnSubsetEnd
!= 1 )
143 return ::basegfx::B2DRange();
145 return getBounds( rTransformation
);
148 sal_Int32
LineAction::getActionCount() const
154 ActionSharedPtr
LineActionFactory::createLineAction( const ::basegfx::B2DPoint
& rStartPoint
,
155 const ::basegfx::B2DPoint
& rEndPoint
,
156 const CanvasSharedPtr
& rCanvas
,
157 const OutDevState
& rState
)
159 return ActionSharedPtr( new LineAction( rStartPoint
,
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */