1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_cppcanvas.hxx" 26 27 #include <rtl/logfile.hxx> 28 #include <com/sun/star/rendering/XCanvas.hpp> 29 30 #include <tools/gen.hxx> 31 #include <vcl/canvastools.hxx> 32 33 #include <basegfx/range/b2drange.hxx> 34 #include <basegfx/point/b2dpoint.hxx> 35 #include <basegfx/tools/canvastools.hxx> 36 #include <canvas/canvastools.hxx> 37 38 #include <boost/utility.hpp> 39 40 #include "pointaction.hxx" 41 #include "outdevstate.hxx" 42 #include "cppcanvas/canvas.hxx" 43 #include "mtftools.hxx" 44 45 46 using namespace ::com::sun::star; 47 48 namespace cppcanvas 49 { 50 namespace internal 51 { 52 namespace 53 { 54 class PointAction : public Action, private ::boost::noncopyable 55 { 56 public: 57 PointAction( const ::basegfx::B2DPoint&, 58 const CanvasSharedPtr&, 59 const OutDevState& ); 60 PointAction( const ::basegfx::B2DPoint&, 61 const CanvasSharedPtr&, 62 const OutDevState&, 63 const ::Color& ); 64 65 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 66 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 67 const Subset& rSubset ) const; 68 69 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 70 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 71 const Subset& rSubset ) const; 72 73 virtual sal_Int32 getActionCount() const; 74 75 private: 76 // default: disabled copy/assignment 77 PointAction(const PointAction&); 78 PointAction& operator = ( const PointAction& ); 79 80 ::basegfx::B2DPoint maPoint; 81 CanvasSharedPtr mpCanvas; 82 ::com::sun::star::rendering::RenderState maState; 83 }; 84 PointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)85 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 86 const CanvasSharedPtr& rCanvas, 87 const OutDevState& rState ) : 88 maPoint( rPoint ), 89 mpCanvas( rCanvas ), 90 maState() 91 { 92 tools::initRenderState(maState,rState); 93 maState.DeviceColor = rState.lineColor; 94 } 95 PointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::Color & rAltColor)96 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 97 const CanvasSharedPtr& rCanvas, 98 const OutDevState& rState, 99 const ::Color& rAltColor ) : 100 maPoint( rPoint ), 101 mpCanvas( rCanvas ), 102 maState() 103 { 104 tools::initRenderState(maState,rState); 105 maState.DeviceColor = ::vcl::unotools::colorToDoubleSequence( 106 rAltColor, 107 rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() ); 108 } 109 render(const::basegfx::B2DHomMatrix & rTransformation) const110 bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 111 { 112 RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PointAction::render()" ); 113 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PointAction: 0x%X", this ); 114 115 rendering::RenderState aLocalState( maState ); 116 ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 117 118 mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint), 119 mpCanvas->getViewState(), 120 aLocalState ); 121 122 return true; 123 } 124 render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const125 bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 126 const Subset& rSubset ) const 127 { 128 // point only contains a single action, fail if subset 129 // requests different range 130 if( rSubset.mnSubsetBegin != 0 || 131 rSubset.mnSubsetEnd != 1 ) 132 return false; 133 134 return render( rTransformation ); 135 } 136 getBounds(const::basegfx::B2DHomMatrix & rTransformation) const137 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 138 { 139 rendering::RenderState aLocalState( maState ); 140 ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 141 142 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1, 143 maPoint.getY()-1, 144 maPoint.getX()+1, 145 maPoint.getY()+1 ), 146 mpCanvas->getViewState(), 147 aLocalState ); 148 } 149 getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const150 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 151 const Subset& rSubset ) const 152 { 153 // point only contains a single action, empty bounds 154 // if subset requests different range 155 if( rSubset.mnSubsetBegin != 0 || 156 rSubset.mnSubsetEnd != 1 ) 157 return ::basegfx::B2DRange(); 158 159 return getBounds( rTransformation ); 160 } 161 getActionCount() const162 sal_Int32 PointAction::getActionCount() const 163 { 164 return 1; 165 } 166 } 167 createPointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState)168 ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 169 const CanvasSharedPtr& rCanvas, 170 const OutDevState& rState ) 171 { 172 return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState ) ); 173 } 174 createPointAction(const::basegfx::B2DPoint & rPoint,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::Color & rColor)175 ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 176 const CanvasSharedPtr& rCanvas, 177 const OutDevState& rState, 178 const ::Color& rColor ) 179 { 180 return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState, rColor ) ); 181 } 182 } 183 } 184