/src/libreoffice/cppcanvas/source/mtfrenderer/lineaction.cxx
Line | Count | Source |
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 "lineaction.hxx" |
22 | | #include <outdevstate.hxx> |
23 | | |
24 | | #include <com/sun/star/rendering/XCanvas.hpp> |
25 | | |
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> |
31 | | |
32 | | #include <cppcanvas/canvas.hxx> |
33 | | #include <utility> |
34 | | |
35 | | #include "mtftools.hxx" |
36 | | |
37 | | |
38 | | using namespace ::com::sun::star; |
39 | | |
40 | | namespace cppcanvas::internal |
41 | | { |
42 | | namespace |
43 | | { |
44 | | class LineAction : public Action |
45 | | { |
46 | | public: |
47 | | LineAction( const ::basegfx::B2DPoint&, |
48 | | const ::basegfx::B2DPoint&, |
49 | | CanvasSharedPtr, |
50 | | const OutDevState& ); |
51 | | |
52 | | LineAction(const LineAction&) = delete; |
53 | | const LineAction& operator=(const LineAction&) = delete; |
54 | | |
55 | | virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const override; |
56 | | virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
57 | | const Subset& rSubset ) const override; |
58 | | |
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; |
62 | | |
63 | | virtual sal_Int32 getActionCount() const override; |
64 | | |
65 | | private: |
66 | | ::basegfx::B2DPoint maStartPoint; |
67 | | ::basegfx::B2DPoint maEndPoint; |
68 | | CanvasSharedPtr mpCanvas; |
69 | | rendering::RenderState maState; |
70 | | }; |
71 | | |
72 | | LineAction::LineAction( const ::basegfx::B2DPoint& rStartPoint, |
73 | | const ::basegfx::B2DPoint& rEndPoint, |
74 | | CanvasSharedPtr xCanvas, |
75 | | const OutDevState& rState ) : |
76 | 0 | maStartPoint( rStartPoint ), |
77 | 0 | maEndPoint( rEndPoint ), |
78 | 0 | mpCanvas(std::move( xCanvas )) |
79 | 0 | { |
80 | 0 | cppcanvastools::initRenderState(maState,rState); |
81 | 0 | maState.DeviceColor = rState.lineColor; |
82 | 0 | } |
83 | | |
84 | | bool LineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const |
85 | 0 | { |
86 | 0 | SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction::render()" ); |
87 | 0 | SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::LineAction: 0x" << std::hex << this ); |
88 | | |
89 | 0 | rendering::RenderState aLocalState( maState ); |
90 | 0 | ::canvastools::prependToRenderState(aLocalState, rTransformation); |
91 | |
|
92 | 0 | mpCanvas->getUNOCanvas()->drawLine( ::basegfx::unotools::point2DFromB2DPoint(maStartPoint), |
93 | 0 | ::basegfx::unotools::point2DFromB2DPoint(maEndPoint), |
94 | 0 | mpCanvas->getViewState(), |
95 | 0 | aLocalState ); |
96 | |
|
97 | 0 | return true; |
98 | 0 | } |
99 | | |
100 | | bool LineAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, |
101 | | const Subset& rSubset ) const |
102 | 0 | { |
103 | | // line only contains a single action, fail if subset |
104 | | // requests different range |
105 | 0 | if( rSubset.mnSubsetBegin != 0 || |
106 | 0 | rSubset.mnSubsetEnd != 1 ) |
107 | 0 | return false; |
108 | | |
109 | 0 | return render( rTransformation ); |
110 | 0 | } |
111 | | |
112 | | ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const |
113 | 0 | { |
114 | 0 | rendering::RenderState aLocalState( maState ); |
115 | 0 | ::canvastools::prependToRenderState(aLocalState, rTransformation); |
116 | |
|
117 | 0 | return cppcanvastools::calcDevicePixelBounds( ::basegfx::B2DRange( maStartPoint, |
118 | 0 | maEndPoint ), |
119 | 0 | mpCanvas->getViewState(), |
120 | 0 | aLocalState ); |
121 | 0 | } |
122 | | |
123 | | ::basegfx::B2DRange LineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, |
124 | | const Subset& rSubset ) const |
125 | 0 | { |
126 | | // line only contains a single action, empty bounds |
127 | | // if subset requests different range |
128 | 0 | if( rSubset.mnSubsetBegin != 0 || |
129 | 0 | rSubset.mnSubsetEnd != 1 ) |
130 | 0 | return ::basegfx::B2DRange(); |
131 | | |
132 | 0 | return getBounds( rTransformation ); |
133 | 0 | } |
134 | | |
135 | | sal_Int32 LineAction::getActionCount() const |
136 | 0 | { |
137 | 0 | return 1; |
138 | 0 | } |
139 | | } |
140 | | |
141 | | std::shared_ptr<Action> LineActionFactory::createLineAction( const ::basegfx::B2DPoint& rStartPoint, |
142 | | const ::basegfx::B2DPoint& rEndPoint, |
143 | | const CanvasSharedPtr& rCanvas, |
144 | | const OutDevState& rState ) |
145 | 0 | { |
146 | 0 | return std::make_shared<LineAction>( rStartPoint, |
147 | 0 | rEndPoint, |
148 | 0 | rCanvas, |
149 | 0 | rState); |
150 | 0 | } |
151 | | |
152 | | } |
153 | | |
154 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |