bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cppcanvas / source / mtfrenderer / lineaction.cxx
blobe1eafbc82cf80d771411fdd8e9a310b51bbdc509
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/utils/canvastools.hxx>
32 #include <canvas/canvastools.hxx>
33 #include <sal/log.hxx>
35 #include <cppcanvas/canvas.hxx>
37 #include "mtftools.hxx"
40 using namespace ::com::sun::star;
42 namespace cppcanvas
44 namespace internal
46 namespace
48 class LineAction : public Action
50 public:
51 LineAction( const ::basegfx::B2DPoint&,
52 const ::basegfx::B2DPoint&,
53 const CanvasSharedPtr&,
54 const OutDevState& );
56 LineAction(const LineAction&) = delete;
57 const LineAction& operator=(const LineAction&) = delete;
59 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
60 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
61 const Subset& rSubset ) const override;
63 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
64 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
65 const Subset& rSubset ) const override;
67 virtual sal_Int32 getActionCount() const override;
69 private:
70 ::basegfx::B2DPoint maStartPoint;
71 ::basegfx::B2DPoint maEndPoint;
72 CanvasSharedPtr mpCanvas;
73 rendering::RenderState maState;
76 LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint,
77 const ::basegfx::B2DPoint& rEndPoint,
78 const CanvasSharedPtr& rCanvas,
79 const OutDevState& rState ) :
80 maStartPoint( rStartPoint ),
81 maEndPoint( rEndPoint ),
82 mpCanvas( rCanvas ),
83 maState()
85 tools::initRenderState(maState,rState);
86 maState.DeviceColor = rState.lineColor;
89 bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
91 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" );
92 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this );
94 rendering::RenderState aLocalState( maState );
95 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
97 mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint),
98 ::basegfx::unotools::point2DFromB2DPoint(maEndPoint),
99 mpCanvas->getViewState(),
100 aLocalState );
102 return true;
105 bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
106 const Subset& rSubset ) const
108 // line only contains a single action, fail if subset
109 // requests different range
110 if( rSubset.mnSubsetBegin != 0 ||
111 rSubset.mnSubsetEnd != 1 )
112 return false;
114 return render( rTransformation );
117 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
119 rendering::RenderState aLocalState( maState );
120 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
122 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint,
123 maEndPoint ),
124 mpCanvas->getViewState(),
125 aLocalState );
128 ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
129 const Subset& rSubset ) const
131 // line only contains a single action, empty bounds
132 // if subset requests different range
133 if( rSubset.mnSubsetBegin != 0 ||
134 rSubset.mnSubsetEnd != 1 )
135 return ::basegfx::B2DRange();
137 return getBounds( rTransformation );
140 sal_Int32 LineAction::getActionCount() const
142 return 1;
146 std::shared_ptr<Action> LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint,
147 const ::basegfx::B2DPoint& rEndPoint,
148 const CanvasSharedPtr& rCanvas,
149 const OutDevState& rState )
151 return std::shared_ptr<Action>( new LineAction( rStartPoint,
152 rEndPoint,
153 rCanvas,
154 rState) );
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */