1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppcanvas.hxx"
26 
27 #include <lineaction.hxx>
28 #include <outdevstate.hxx>
29 
30 #include <rtl/logfile.hxx>
31 #include <com/sun/star/rendering/XCanvas.hpp>
32 
33 #include <tools/gen.hxx>
34 #include <vcl/canvastools.hxx>
35 
36 #include <basegfx/range/b2drange.hxx>
37 #include <basegfx/point/b2dpoint.hxx>
38 #include <basegfx/tools/canvastools.hxx>
39 #include <canvas/canvastools.hxx>
40 
41 #include <boost/utility.hpp>
42 
43 #include <cppcanvas/canvas.hxx>
44 
45 #include <mtftools.hxx>
46 
47 
48 using namespace ::com::sun::star;
49 
50 namespace cppcanvas
51 {
52     namespace internal
53     {
54         namespace
55         {
56             class LineAction : public Action, private ::boost::noncopyable
57             {
58             public:
59                 LineAction( const ::basegfx::B2DPoint&,
60                             const ::basegfx::B2DPoint&,
61                             const CanvasSharedPtr&,
62                             const OutDevState& );
63 
64                 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
65                 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation,
66                                      const Subset&					rSubset ) const;
67 
68                 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const;
69                 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix&	rTransformation,
70                                                        const Subset&					rSubset ) const;
71 
72                 virtual sal_Int32 getActionCount() const;
73 
74             private:
75                 ::basegfx::B2DPoint     maStartPoint;
76                 ::basegfx::B2DPoint     maEndPoint;
77                 CanvasSharedPtr			mpCanvas;
78                 rendering::RenderState	maState;
79             };
80 
LineAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DPoint & rEndPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)81             LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
82                                     const ::basegfx::B2DPoint& rEndPoint,
83                                     const CanvasSharedPtr&     rCanvas,
84                                     const OutDevState&         rState ) :
85                 maStartPoint( rStartPoint ),
86                 maEndPoint( rEndPoint ),
87                 mpCanvas( rCanvas ),
88                 maState()
89             {
90                 tools::initRenderState(maState,rState);
91                 maState.DeviceColor = rState.lineColor;
92             }
93 
render(const::basegfx::B2DHomMatrix & rTransformation) const94             bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
95             {
96                 RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::LineAction::render()" );
97                 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::LineAction: 0x%X", this );
98 
99                 rendering::RenderState aLocalState( maState );
100                 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
101 
102                 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
103                                                     ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
104                                                     mpCanvas->getViewState(),
105                                                     aLocalState );
106 
107                 return true;
108             }
109 
render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const110             bool LineAction::render( const ::basegfx::B2DHomMatrix&	rTransformation,
111                                      const Subset&					rSubset ) const
112             {
113                 // line only contains a single action, fail if subset
114                 // requests different range
115                 if( rSubset.mnSubsetBegin != 0 ||
116                     rSubset.mnSubsetEnd != 1 )
117                     return false;
118 
119                 return render( rTransformation );
120             }
121 
getBounds(const::basegfx::B2DHomMatrix & rTransformation) const122             ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
123             {
124                 rendering::RenderState aLocalState( maState );
125                 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
126 
127                 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
128                                                                           maEndPoint ),
129                                                      mpCanvas->getViewState(),
130                                                      aLocalState );
131             }
132 
getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const133             ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix&	rTransformation,
134                                                        const Subset&					rSubset ) const
135             {
136                 // line only contains a single action, empty bounds
137                 // if subset requests different range
138                 if( rSubset.mnSubsetBegin != 0 ||
139                     rSubset.mnSubsetEnd != 1 )
140                     return ::basegfx::B2DRange();
141 
142                 return getBounds( rTransformation );
143             }
144 
getActionCount() const145             sal_Int32 LineAction::getActionCount() const
146             {
147                 return 1;
148             }
149         }
150 
createLineAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DPoint & rEndPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)151         ActionSharedPtr LineActionFactory::createLineAction( const ::basegfx::B2DPoint&	rStartPoint,
152                                                              const ::basegfx::B2DPoint&	rEndPoint,
153                                                              const CanvasSharedPtr&     rCanvas,
154                                                              const OutDevState&         rState	)
155         {
156             return ActionSharedPtr( new LineAction( rStartPoint,
157                                                     rEndPoint,
158                                                     rCanvas,
159                                                     rState) );
160         }
161 
162     }
163 }
164