Line data Source code
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 <vcl/canvastools.hxx>
25 :
26 : #include <basegfx/range/b2drange.hxx>
27 : #include <basegfx/point/b2dpoint.hxx>
28 : #include <basegfx/tools/canvastools.hxx>
29 : #include <canvas/canvastools.hxx>
30 :
31 : #include <boost/utility.hpp>
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
42 : {
43 : namespace internal
44 : {
45 : namespace
46 : {
47 0 : class PointAction : public Action, private ::boost::noncopyable
48 : {
49 : public:
50 : PointAction( const ::basegfx::B2DPoint&,
51 : const CanvasSharedPtr&,
52 : const OutDevState& );
53 : PointAction( const ::basegfx::B2DPoint&,
54 : const CanvasSharedPtr&,
55 : const OutDevState&,
56 : const ::Color& );
57 :
58 : virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const SAL_OVERRIDE;
59 : virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
60 : const Subset& rSubset ) const SAL_OVERRIDE;
61 :
62 : virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const SAL_OVERRIDE;
63 : virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
64 : const Subset& rSubset ) const SAL_OVERRIDE;
65 :
66 : virtual sal_Int32 getActionCount() const SAL_OVERRIDE;
67 :
68 : private:
69 : ::basegfx::B2DPoint maPoint;
70 : CanvasSharedPtr mpCanvas;
71 : ::com::sun::star::rendering::RenderState maState;
72 : };
73 :
74 0 : PointAction::PointAction( const ::basegfx::B2DPoint& rPoint,
75 : const CanvasSharedPtr& rCanvas,
76 : const OutDevState& rState ) :
77 : maPoint( rPoint ),
78 : mpCanvas( rCanvas ),
79 0 : maState()
80 : {
81 0 : tools::initRenderState(maState,rState);
82 0 : maState.DeviceColor = rState.lineColor;
83 0 : }
84 :
85 0 : PointAction::PointAction( const ::basegfx::B2DPoint& rPoint,
86 : const CanvasSharedPtr& rCanvas,
87 : const OutDevState& rState,
88 : const ::Color& rAltColor ) :
89 : maPoint( rPoint ),
90 : mpCanvas( rCanvas ),
91 0 : maState()
92 : {
93 0 : tools::initRenderState(maState,rState);
94 0 : maState.DeviceColor = ::vcl::unotools::colorToDoubleSequence(
95 : rAltColor,
96 0 : rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() );
97 0 : }
98 :
99 0 : bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
100 : {
101 : SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction::render()" );
102 : SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::PointAction: 0x" << std::hex << this );
103 :
104 0 : rendering::RenderState aLocalState( maState );
105 0 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
106 :
107 0 : mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint),
108 0 : mpCanvas->getViewState(),
109 0 : aLocalState );
110 :
111 0 : return true;
112 : }
113 :
114 0 : bool PointAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
115 : const Subset& rSubset ) const
116 : {
117 : // point only contains a single action, fail if subset
118 : // requests different range
119 0 : if( rSubset.mnSubsetBegin != 0 ||
120 0 : rSubset.mnSubsetEnd != 1 )
121 0 : return false;
122 :
123 0 : return render( rTransformation );
124 : }
125 :
126 0 : ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
127 : {
128 0 : rendering::RenderState aLocalState( maState );
129 0 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
130 :
131 0 : return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1,
132 0 : maPoint.getY()-1,
133 0 : maPoint.getX()+1,
134 0 : maPoint.getY()+1 ),
135 0 : mpCanvas->getViewState(),
136 0 : aLocalState );
137 : }
138 :
139 0 : ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
140 : const Subset& rSubset ) const
141 : {
142 : // point only contains a single action, empty bounds
143 : // if subset requests different range
144 0 : if( rSubset.mnSubsetBegin != 0 ||
145 0 : rSubset.mnSubsetEnd != 1 )
146 0 : return ::basegfx::B2DRange();
147 :
148 0 : return getBounds( rTransformation );
149 : }
150 :
151 0 : sal_Int32 PointAction::getActionCount() const
152 : {
153 0 : return 1;
154 : }
155 : }
156 :
157 0 : ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint,
158 : const CanvasSharedPtr& rCanvas,
159 : const OutDevState& rState )
160 : {
161 0 : return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState ) );
162 : }
163 :
164 0 : ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint,
165 : const CanvasSharedPtr& rCanvas,
166 : const OutDevState& rState,
167 : const ::Color& rColor )
168 : {
169 0 : return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState, rColor ) );
170 : }
171 : }
172 1143 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|