1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cppcanvas.hxx" 30 31 #include <rtl/logfile.hxx> 32 #include <com/sun/star/rendering/XCanvas.hpp> 33 34 #include <tools/gen.hxx> 35 #include <vcl/canvastools.hxx> 36 37 #include <basegfx/range/b2drange.hxx> 38 #include <basegfx/point/b2dpoint.hxx> 39 #include <basegfx/tools/canvastools.hxx> 40 #include <canvas/canvastools.hxx> 41 42 #include <boost/utility.hpp> 43 44 #include "pointaction.hxx" 45 #include "outdevstate.hxx" 46 #include "cppcanvas/canvas.hxx" 47 #include "mtftools.hxx" 48 49 50 using namespace ::com::sun::star; 51 52 namespace cppcanvas 53 { 54 namespace internal 55 { 56 namespace 57 { 58 class PointAction : public Action, private ::boost::noncopyable 59 { 60 public: 61 PointAction( const ::basegfx::B2DPoint&, 62 const CanvasSharedPtr&, 63 const OutDevState& ); 64 PointAction( const ::basegfx::B2DPoint&, 65 const CanvasSharedPtr&, 66 const OutDevState&, 67 const ::Color& ); 68 69 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 70 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 71 const Subset& rSubset ) const; 72 73 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 74 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 75 const Subset& rSubset ) const; 76 77 virtual sal_Int32 getActionCount() const; 78 79 private: 80 // default: disabled copy/assignment 81 PointAction(const PointAction&); 82 PointAction& operator = ( const PointAction& ); 83 84 ::basegfx::B2DPoint maPoint; 85 CanvasSharedPtr mpCanvas; 86 ::com::sun::star::rendering::RenderState maState; 87 }; 88 89 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 90 const CanvasSharedPtr& rCanvas, 91 const OutDevState& rState ) : 92 maPoint( rPoint ), 93 mpCanvas( rCanvas ), 94 maState() 95 { 96 tools::initRenderState(maState,rState); 97 maState.DeviceColor = rState.lineColor; 98 } 99 100 PointAction::PointAction( const ::basegfx::B2DPoint& rPoint, 101 const CanvasSharedPtr& rCanvas, 102 const OutDevState& rState, 103 const ::Color& rAltColor ) : 104 maPoint( rPoint ), 105 mpCanvas( rCanvas ), 106 maState() 107 { 108 tools::initRenderState(maState,rState); 109 maState.DeviceColor = ::vcl::unotools::colorToDoubleSequence( 110 rAltColor, 111 rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() ); 112 } 113 114 bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 115 { 116 RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PointAction::render()" ); 117 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PointAction: 0x%X", this ); 118 119 rendering::RenderState aLocalState( maState ); 120 ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 121 122 mpCanvas->getUNOCanvas()->drawPoint( ::basegfx::unotools::point2DFromB2DPoint(maPoint), 123 mpCanvas->getViewState(), 124 aLocalState ); 125 126 return true; 127 } 128 129 bool PointAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 130 const Subset& rSubset ) const 131 { 132 // point only contains a single action, fail if subset 133 // requests different range 134 if( rSubset.mnSubsetBegin != 0 || 135 rSubset.mnSubsetEnd != 1 ) 136 return false; 137 138 return render( rTransformation ); 139 } 140 141 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 142 { 143 rendering::RenderState aLocalState( maState ); 144 ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 145 146 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( maPoint.getX()-1, 147 maPoint.getY()-1, 148 maPoint.getX()+1, 149 maPoint.getY()+1 ), 150 mpCanvas->getViewState(), 151 aLocalState ); 152 } 153 154 ::basegfx::B2DRange PointAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 155 const Subset& rSubset ) const 156 { 157 // point only contains a single action, empty bounds 158 // if subset requests different range 159 if( rSubset.mnSubsetBegin != 0 || 160 rSubset.mnSubsetEnd != 1 ) 161 return ::basegfx::B2DRange(); 162 163 return getBounds( rTransformation ); 164 } 165 166 sal_Int32 PointAction::getActionCount() const 167 { 168 return 1; 169 } 170 } 171 172 ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 173 const CanvasSharedPtr& rCanvas, 174 const OutDevState& rState ) 175 { 176 return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState ) ); 177 } 178 179 ActionSharedPtr PointActionFactory::createPointAction( const ::basegfx::B2DPoint& rPoint, 180 const CanvasSharedPtr& rCanvas, 181 const OutDevState& rState, 182 const ::Color& rColor ) 183 { 184 return ActionSharedPtr( new PointAction( rPoint, rCanvas, rState, rColor ) ); 185 } 186 } 187 } 188