Get the style color and number just once
[LibreOffice.git] / cppcanvas / source / mtfrenderer / pointaction.cxx
blob449f4b9b4249d065a43c481190aa5ffa6cb6eb04
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 <com/sun/star/rendering/XCanvas.hpp>
23 #include <sal/types.h>
24 #include <sal/log.hxx>
25 #include <utility>
26 #include <vcl/canvastools.hxx>
28 #include <basegfx/range/b2drange.hxx>
29 #include <basegfx/point/b2dpoint.hxx>
30 #include <basegfx/utils/canvastools.hxx>
31 #include <canvas/canvastools.hxx>
33 #include "pointaction.hxx"
34 #include <outdevstate.hxx>
35 #include <cppcanvas/canvas.hxx>
36 #include "mtftools.hxx"
39 using namespace ::com::sun::star;
41 namespace cppcanvas::internal
43 namespace
45 class PointAction : public Action
47 public:
48 PointAction( const ::basegfx::B2DPoint&,
49 CanvasSharedPtr,
50 const OutDevState& );
51 PointAction( const ::basegfx::B2DPoint&,
52 const CanvasSharedPtr&,
53 const OutDevState&,
54 const ::Color& );
56 PointAction(const PointAction&) = delete;
57 const PointAction& operator=(const PointAction&) = 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 maPoint;
71 CanvasSharedPtr mpCanvas;
72 css::rendering::RenderState maState;
75 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint,
76 CanvasSharedPtr xCanvas,
77 const OutDevState& rState ) :
78 maPoint( rPoint ),
79 mpCanvas(std::move( xCanvas ))
81 tools::initRenderState(maState,rState);
82 maState.DeviceColor = rState.lineColor;
85 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint,
86 const CanvasSharedPtr& rCanvas,
87 const OutDevState& rState,
88 const ::Color& rAltColor ) :
89 maPoint( rPoint ),
90 mpCanvas( rCanvas )
92 tools::initRenderState(maState,rState);
93 maState.DeviceColor = vcl::unotools::colorToDoubleSequence(
94 rAltColor,
95 rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
98 bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
100 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction::render()" );
101 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction: 0x" << std::hex << this );
103 rendering::RenderState aLocalState( maState );
104 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
106 mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint),
107 mpCanvas->getViewState(),
108 aLocalState );
110 return true;
113 bool PointAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
114 const Subset& rSubset ) const
116 // point only contains a single action, fail if subset
117 // requests different range
118 if( rSubset.mnSubsetBegin != 0 ||
119 rSubset.mnSubsetEnd != 1 )
120 return false;
122 return render( rTransformation );
125 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
127 rendering::RenderState aLocalState( maState );
128 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
130 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1,
131 maPoint.getY()-1,
132 maPoint.getX()+1,
133 maPoint.getY()+1 ),
134 mpCanvas->getViewState(),
135 aLocalState );
138 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
139 const Subset& rSubset ) const
141 // point only contains a single action, empty bounds
142 // if subset requests different range
143 if( rSubset.mnSubsetBegin != 0 ||
144 rSubset.mnSubsetEnd != 1 )
145 return ::basegfx::B2DRange();
147 return getBounds( rTransformation );
150 sal_Int32 PointAction::getActionCount() const
152 return 1;
156 std::shared_ptr<Action> PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint,
157 const CanvasSharedPtr& rCanvas,
158 const OutDevState& rState )
160 return std::make_shared<PointAction>( rPoint, rCanvas, rState );
163 std::shared_ptr<Action> PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint,
164 const CanvasSharedPtr& rCanvas,
165 const OutDevState& rState,
166 const ::Color& rColor )
168 return std::make_shared<PointAction>( rPoint, rCanvas, rState, rColor );
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */