/src/libreoffice/cppcanvas/source/mtfrenderer/pointaction.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include <com/sun/star/rendering/XCanvas.hpp> |
22 | | |
23 | | #include <sal/types.h> |
24 | | #include <sal/log.hxx> |
25 | | #include <utility> |
26 | | #include <vcl/canvastools.hxx> |
27 | | |
28 | | #include <basegfx/range/b2drange.hxx> |
29 | | #include <basegfx/point/b2dpoint.hxx> |
30 | | #include <basegfx/utils/canvastools.hxx> |
31 | | #include <canvas/canvastools.hxx> |
32 | | |
33 | | #include "pointaction.hxx" |
34 | | #include <outdevstate.hxx> |
35 | | #include <cppcanvas/canvas.hxx> |
36 | | #include "mtftools.hxx" |
37 | | |
38 | | |
39 | | using namespace ::com::sun::star; |
40 | | |
41 | | namespace cppcanvas::internal |
42 | | { |
43 | | namespace |
44 | | { |
45 | | class PointAction : public Action |
46 | | { |
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& ); |
55 | | |
56 | | PointAction(const PointAction&) = delete; |
57 | | const PointAction& operator=(const PointAction&) = delete; |
58 | | |
59 | | virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override; |
60 | | virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
61 | | const Subset& rSubset ) const override; |
62 | | |
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; |
66 | | |
67 | | virtual sal_Int32 getActionCount() const override; |
68 | | |
69 | | private: |
70 | | ::basegfx::B2DPoint maPoint; |
71 | | CanvasSharedPtr mpCanvas; |
72 | | css::rendering::RenderState maState; |
73 | | }; |
74 | | |
75 | | PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, |
76 | | CanvasSharedPtr xCanvas, |
77 | | const OutDevState& rState ) : |
78 | 0 | maPoint( rPoint ), |
79 | 0 | mpCanvas(std::move( xCanvas )) |
80 | 0 | { |
81 | 0 | tools::initRenderState(maState,rState); |
82 | 0 | maState.DeviceColor = rState.lineColor; |
83 | 0 | } |
84 | | |
85 | | PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, |
86 | | const CanvasSharedPtr& rCanvas, |
87 | | const OutDevState& rState, |
88 | | const ::Color& rAltColor ) : |
89 | 0 | maPoint( rPoint ), |
90 | 0 | mpCanvas( rCanvas ) |
91 | 0 | { |
92 | 0 | tools::initRenderState(maState,rState); |
93 | 0 | maState.DeviceColor = vcl::unotools::colorToDoubleSequence( |
94 | 0 | rAltColor, |
95 | 0 | rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() ); |
96 | 0 | } |
97 | | |
98 | | bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const |
99 | 0 | { |
100 | 0 | SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction::render()" ); |
101 | 0 | SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction: 0x" << std::hex << this ); |
102 | | |
103 | 0 | rendering::RenderState aLocalState( maState ); |
104 | 0 | ::canvas::tools::prependToRenderState(aLocalState, rTransformation); |
105 | |
|
106 | 0 | mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint), |
107 | 0 | mpCanvas->getViewState(), |
108 | 0 | aLocalState ); |
109 | |
|
110 | 0 | return true; |
111 | 0 | } |
112 | | |
113 | | bool PointAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
114 | | const Subset& rSubset ) const |
115 | 0 | { |
116 | | // point only contains a single action, fail if subset |
117 | | // requests different range |
118 | 0 | if( rSubset.mnSubsetBegin != 0 || |
119 | 0 | rSubset.mnSubsetEnd != 1 ) |
120 | 0 | return false; |
121 | | |
122 | 0 | return render( rTransformation ); |
123 | 0 | } |
124 | | |
125 | | ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const |
126 | 0 | { |
127 | 0 | rendering::RenderState aLocalState( maState ); |
128 | 0 | ::canvas::tools::prependToRenderState(aLocalState, rTransformation); |
129 | |
|
130 | 0 | return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1, |
131 | 0 | maPoint.getY()-1, |
132 | 0 | maPoint.getX()+1, |
133 | 0 | maPoint.getY()+1 ), |
134 | 0 | mpCanvas->getViewState(), |
135 | 0 | aLocalState ); |
136 | 0 | } |
137 | | |
138 | | ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, |
139 | | const Subset& rSubset ) const |
140 | 0 | { |
141 | | // point only contains a single action, empty bounds |
142 | | // if subset requests different range |
143 | 0 | if( rSubset.mnSubsetBegin != 0 || |
144 | 0 | rSubset.mnSubsetEnd != 1 ) |
145 | 0 | return ::basegfx::B2DRange(); |
146 | | |
147 | 0 | return getBounds( rTransformation ); |
148 | 0 | } |
149 | | |
150 | | sal_Int32 PointAction::getActionCount() const |
151 | 0 | { |
152 | 0 | return 1; |
153 | 0 | } |
154 | | } |
155 | | |
156 | | std::shared_ptr<Action> PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, |
157 | | const CanvasSharedPtr& rCanvas, |
158 | | const OutDevState& rState ) |
159 | 0 | { |
160 | 0 | return std::make_shared<PointAction>( rPoint, rCanvas, rState ); |
161 | 0 | } |
162 | | |
163 | | std::shared_ptr<Action> PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, |
164 | | const CanvasSharedPtr& rCanvas, |
165 | | const OutDevState& rState, |
166 | | const ::Color& rColor ) |
167 | 0 | { |
168 | 0 | return std::make_shared<PointAction>( rPoint, rCanvas, rState, rColor ); |
169 | 0 | } |
170 | | } |
171 | | |
172 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |