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