Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / mtfrenderer / lineaction.cxx
blob6553f34657a19a455379da12d1c34ea54057bd26
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <lineaction.hxx>
22 #include <outdevstate.hxx>
24 #include <com/sun/star/rendering/XCanvas.hpp>
26 #include <tools/gen.hxx>
27 #include <vcl/canvastools.hxx>
29 #include <basegfx/range/b2drange.hxx>
30 #include <basegfx/point/b2dpoint.hxx>
31 #include <basegfx/tools/canvastools.hxx>
32 #include <canvas/canvastools.hxx>
34 #include <boost/utility.hpp>
36 #include <cppcanvas/canvas.hxx>
38 #include <mtftools.hxx>
41 using namespace ::com::sun::star;
43 namespace cppcanvas
45 namespace internal
47 namespace
49 class LineAction : public Action, private ::boost::noncopyable
51 public:
52 LineAction( const ::basegfx::B2DPoint&,
53 const ::basegfx::B2DPoint&,
54 const CanvasSharedPtr&,
55 const OutDevState& );
57 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
58 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
59 const Subset& rSubset ) const;
61 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const;
62 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
63 const Subset& rSubset ) const;
65 virtual sal_Int32 getActionCount() const;
67 private:
68 ::basegfx::B2DPoint maStartPoint;
69 ::basegfx::B2DPoint maEndPoint;
70 CanvasSharedPtr mpCanvas;
71 rendering::RenderState maState;
74 LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
75 const ::basegfx::B2DPoint& rEndPoint,
76 const CanvasSharedPtr& rCanvas,
77 const OutDevState& rState ) :
78 maStartPoint( rStartPoint ),
79 maEndPoint( rEndPoint ),
80 mpCanvas( rCanvas ),
81 maState()
83 tools::initRenderState(maState,rState);
84 maState.DeviceColor = rState.lineColor;
87 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
89 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
90 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this );
92 rendering::RenderState aLocalState( maState );
93 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
95 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
96 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
97 mpCanvas->getViewState(),
98 aLocalState );
100 return true;
103 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
104 const Subset& rSubset ) const
106 // line only contains a single action, fail if subset
107 // requests different range
108 if( rSubset.mnSubsetBegin != 0 ||
109 rSubset.mnSubsetEnd != 1 )
110 return false;
112 return render( rTransformation );
115 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
117 rendering::RenderState aLocalState( maState );
118 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
120 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
121 maEndPoint ),
122 mpCanvas->getViewState(),
123 aLocalState );
126 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
127 const Subset& rSubset ) const
129 // line only contains a single action, empty bounds
130 // if subset requests different range
131 if( rSubset.mnSubsetBegin != 0 ||
132 rSubset.mnSubsetEnd != 1 )
133 return ::basegfx::B2DRange();
135 return getBounds( rTransformation );
138 sal_Int32 LineAction::getActionCount() const
140 return 1;
144 ActionSharedPtr LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
145 const ::basegfx::B2DPoint& rEndPoint,
146 const CanvasSharedPtr& rCanvas,
147 const OutDevState& rState )
149 return ActionSharedPtr( new LineAction( rStartPoint,
150 rEndPoint,
151 rCanvas,
152 rState) );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */