Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <lineaction.hxx>
31 : : #include <outdevstate.hxx>
32 : :
33 : : #include <rtl/logfile.hxx>
34 : : #include <com/sun/star/rendering/XCanvas.hpp>
35 : :
36 : : #include <tools/gen.hxx>
37 : : #include <vcl/canvastools.hxx>
38 : :
39 : : #include <basegfx/range/b2drange.hxx>
40 : : #include <basegfx/point/b2dpoint.hxx>
41 : : #include <basegfx/tools/canvastools.hxx>
42 : : #include <canvas/canvastools.hxx>
43 : :
44 : : #include <boost/utility.hpp>
45 : :
46 : : #include <cppcanvas/canvas.hxx>
47 : :
48 : : #include <mtftools.hxx>
49 : :
50 : :
51 : : using namespace ::com::sun::star;
52 : :
53 : : namespace cppcanvas
54 : : {
55 : : namespace internal
56 : : {
57 : : namespace
58 : : {
59 [ # # ][ # # ]: 0 : class LineAction : public Action, private ::boost::noncopyable
[ # # ]
60 : : {
61 : : public:
62 : : LineAction( const ::basegfx::B2DPoint&,
63 : : const ::basegfx::B2DPoint&,
64 : : const CanvasSharedPtr&,
65 : : const OutDevState& );
66 : :
67 : : virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
68 : : virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
69 : : const Subset& rSubset ) const;
70 : :
71 : : virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const;
72 : : virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
73 : : const Subset& rSubset ) const;
74 : :
75 : : virtual sal_Int32 getActionCount() const;
76 : :
77 : : private:
78 : : ::basegfx::B2DPoint maStartPoint;
79 : : ::basegfx::B2DPoint maEndPoint;
80 : : CanvasSharedPtr mpCanvas;
81 : : rendering::RenderState maState;
82 : : };
83 : :
84 : 0 : 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 ),
90 : : mpCanvas( rCanvas ),
91 [ # # ][ # # ]: 0 : maState()
92 : : {
93 [ # # ]: 0 : tools::initRenderState(maState,rState);
94 [ # # ]: 0 : maState.DeviceColor = rState.lineColor;
95 : 0 : }
96 : :
97 : 0 : bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
98 : : {
99 : : RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::LineAction::render()" );
100 : : RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::LineAction: 0x%X", this );
101 : :
102 [ # # ]: 0 : rendering::RenderState aLocalState( maState );
103 [ # # ]: 0 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
104 : :
105 [ # # ][ # # ]: 0 : mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
106 : 0 : ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
107 : 0 : mpCanvas->getViewState(),
108 [ # # ][ # # ]: 0 : aLocalState );
[ # # ][ # # ]
[ # # ]
109 : :
110 [ # # ]: 0 : return true;
111 : : }
112 : :
113 : 0 : bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
114 : : const Subset& rSubset ) const
115 : : {
116 : : // line only contains a single action, fail if subset
117 : : // requests different range
118 [ # # ][ # # ]: 0 : if( rSubset.mnSubsetBegin != 0 ||
119 : : rSubset.mnSubsetEnd != 1 )
120 : 0 : return false;
121 : :
122 : 0 : return render( rTransformation );
123 : : }
124 : :
125 : 0 : ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
126 : : {
127 [ # # ]: 0 : rendering::RenderState aLocalState( maState );
128 [ # # ]: 0 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
129 : :
130 : : return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
131 : : maEndPoint ),
132 : 0 : mpCanvas->getViewState(),
133 [ # # ][ # # ]: 0 : aLocalState );
[ # # ][ # # ]
[ # # ]
134 : : }
135 : :
136 : 0 : ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
137 : : const Subset& rSubset ) const
138 : : {
139 : : // line only contains a single action, empty bounds
140 : : // if subset requests different range
141 [ # # ][ # # ]: 0 : if( rSubset.mnSubsetBegin != 0 ||
142 : : rSubset.mnSubsetEnd != 1 )
143 : 0 : return ::basegfx::B2DRange();
144 : :
145 : 0 : return getBounds( rTransformation );
146 : : }
147 : :
148 : 0 : sal_Int32 LineAction::getActionCount() const
149 : : {
150 : 0 : return 1;
151 : : }
152 : : }
153 : :
154 : 0 : ActionSharedPtr LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
155 : : const ::basegfx::B2DPoint& rEndPoint,
156 : : const CanvasSharedPtr& rCanvas,
157 : : const OutDevState& rState )
158 : : {
159 : : return ActionSharedPtr( new LineAction( rStartPoint,
160 : : rEndPoint,
161 : : rCanvas,
162 [ # # ]: 0 : rState) );
163 : : }
164 : :
165 : : }
166 : : }
167 : :
168 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|