Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / cppcanvas / source / mtfrenderer / lineaction.cxx
blob5d9acd23ef057bdeaa412c554a3aff85c86526ba
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 <cppcanvas/canvas.hxx>
36 #include <mtftools.hxx>
39 using namespace ::com::sun::star;
41 namespace cppcanvas
43 namespace internal
45 namespace
47 class LineAction : public Action
49 public:
50 LineAction( const ::basegfx::B2DPoint&,
51 const ::basegfx::B2DPoint&,
52 const CanvasSharedPtr&,
53 const OutDevState& );
55 LineAction(const LineAction&) = delete;
56 const LineAction& operator=(const LineAction&) = delete;
58 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
59 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
60 const Subset& rSubset ) const override;
62 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
63 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
64 const Subset& rSubset ) const override;
66 virtual sal_Int32 getActionCount() const override;
68 private:
69 ::basegfx::B2DPoint maStartPoint;
70 ::basegfx::B2DPoint maEndPoint;
71 CanvasSharedPtr mpCanvas;
72 rendering::RenderState maState;
75 LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
76 const ::basegfx::B2DPoint& rEndPoint,
77 const CanvasSharedPtr& rCanvas,
78 const OutDevState& rState ) :
79 maStartPoint( rStartPoint ),
80 maEndPoint( rEndPoint ),
81 mpCanvas( rCanvas ),
82 maState()
84 tools::initRenderState(maState,rState);
85 maState.DeviceColor = rState.lineColor;
88 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
90 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
91 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this );
93 rendering::RenderState aLocalState( maState );
94 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
96 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
97 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
98 mpCanvas->getViewState(),
99 aLocalState );
101 return true;
104 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
105 const Subset& rSubset ) const
107 // line only contains a single action, fail if subset
108 // requests different range
109 if( rSubset.mnSubsetBegin != 0 ||
110 rSubset.mnSubsetEnd != 1 )
111 return false;
113 return render( rTransformation );
116 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
118 rendering::RenderState aLocalState( maState );
119 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
121 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
122 maEndPoint ),
123 mpCanvas->getViewState(),
124 aLocalState );
127 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
128 const Subset& rSubset ) const
130 // line only contains a single action, empty bounds
131 // if subset requests different range
132 if( rSubset.mnSubsetBegin != 0 ||
133 rSubset.mnSubsetEnd != 1 )
134 return ::basegfx::B2DRange();
136 return getBounds( rTransformation );
139 sal_Int32 LineAction::getActionCount() const
141 return 1;
145 ActionSharedPtr LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
146 const ::basegfx::B2DPoint& rEndPoint,
147 const CanvasSharedPtr& rCanvas,
148 const OutDevState& rState )
150 return ActionSharedPtr( new LineAction( rStartPoint,
151 rEndPoint,
152 rCanvas,
153 rState) );
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */