Get the style color and number just once
[LibreOffice.git] / cppcanvas / source / mtfrenderer / lineaction.cxx
blob4bc55d9299584a0505c5bf2aded0ae4055999cf7
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 <basegfx/range/b2drange.hxx>
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/utils/canvastools.hxx>
29 #include <canvas/canvastools.hxx>
30 #include <sal/log.hxx>
32 #include <cppcanvas/canvas.hxx>
33 #include <utility>
35 #include "mtftools.hxx"
38 using namespace ::com::sun::star;
40 namespace cppcanvas::internal
42 namespace
44 class LineAction : public Action
46 public:
47 LineAction( const ::basegfx::B2DPoint&,
48 const ::basegfx::B2DPoint&,
49 CanvasSharedPtr,
50 const OutDevState& );
52 LineAction(const LineAction&) = delete;
53 const LineAction& operator=(const LineAction&) = delete;
55 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
56 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
57 const Subset& rSubset ) const override;
59 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
60 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
61 const Subset& rSubset ) const override;
63 virtual sal_Int32 getActionCount() const override;
65 private:
66 ::basegfx::B2DPoint maStartPoint;
67 ::basegfx::B2DPoint maEndPoint;
68 CanvasSharedPtr mpCanvas;
69 rendering::RenderState maState;
72 LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
73 const ::basegfx::B2DPoint& rEndPoint,
74 CanvasSharedPtr xCanvas,
75 const OutDevState& rState ) :
76 maStartPoint( rStartPoint ),
77 maEndPoint( rEndPoint ),
78 mpCanvas(std::move( xCanvas ))
80 tools::initRenderState(maState,rState);
81 maState.DeviceColor = rState.lineColor;
84 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
86 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
87 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this );
89 rendering::RenderState aLocalState( maState );
90 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
92 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
93 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
94 mpCanvas->getViewState(),
95 aLocalState );
97 return true;
100 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
101 const Subset& rSubset ) const
103 // line only contains a single action, fail if subset
104 // requests different range
105 if( rSubset.mnSubsetBegin != 0 ||
106 rSubset.mnSubsetEnd != 1 )
107 return false;
109 return render( rTransformation );
112 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
114 rendering::RenderState aLocalState( maState );
115 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
117 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
118 maEndPoint ),
119 mpCanvas->getViewState(),
120 aLocalState );
123 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
124 const Subset& rSubset ) const
126 // line only contains a single action, empty bounds
127 // if subset requests different range
128 if( rSubset.mnSubsetBegin != 0 ||
129 rSubset.mnSubsetEnd != 1 )
130 return ::basegfx::B2DRange();
132 return getBounds( rTransformation );
135 sal_Int32 LineAction::getActionCount() const
137 return 1;
141 std::shared_ptr<Action> LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
142 const ::basegfx::B2DPoint& rEndPoint,
143 const CanvasSharedPtr& rCanvas,
144 const OutDevState& rState )
146 return std::make_shared<LineAction>( rStartPoint,
147 rEndPoint,
148 rCanvas,
149 rState);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */