update dev300-m58
[ooovba.git] / cppcanvas / source / mtfrenderer / bitmapaction.cxx
blob169b15393ab4813195d1e6fb9dc3476d403cf1fa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bitmapaction.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppcanvas.hxx"
34 #include <rtl/logfile.hxx>
35 #include <com/sun/star/rendering/XBitmap.hpp>
36 #include <com/sun/star/rendering/RepaintResult.hpp>
37 #include <com/sun/star/rendering/XCachedPrimitive.hpp>
39 #include <vcl/bitmapex.hxx>
40 #include <tools/gen.hxx>
41 #include <vcl/canvastools.hxx>
43 #include <canvas/canvastools.hxx>
45 #include <basegfx/matrix/b2dhommatrix.hxx>
46 #include <basegfx/vector/b2dsize.hxx>
47 #include <basegfx/point/b2dpoint.hxx>
48 #include <basegfx/range/b2drange.hxx>
49 #include <basegfx/tools/canvastools.hxx>
51 #include <boost/utility.hpp>
53 #include "cachedprimitivebase.hxx"
54 #include "bitmapaction.hxx"
55 #include "outdevstate.hxx"
56 #include "mtftools.hxx"
59 using namespace ::com::sun::star;
61 namespace cppcanvas
63 namespace internal
65 namespace
68 class BitmapAction : public CachedPrimitiveBase
70 public:
71 BitmapAction( const ::BitmapEx&,
72 const ::basegfx::B2DPoint& rDstPoint,
73 const CanvasSharedPtr&,
74 const OutDevState& );
75 BitmapAction( const ::BitmapEx&,
76 const ::basegfx::B2DPoint& rDstPoint,
77 const ::basegfx::B2DVector& rDstSize,
78 const CanvasSharedPtr&,
79 const OutDevState& );
81 virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation,
82 const Subset& rSubset ) const;
84 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const;
85 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
86 const Subset& rSubset ) const;
88 virtual sal_Int32 getActionCount() const;
90 private:
91 using Action::render;
92 virtual bool render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
93 const ::basegfx::B2DHomMatrix& rTransformation ) const;
95 uno::Reference< rendering::XBitmap > mxBitmap;
96 CanvasSharedPtr mpCanvas;
97 rendering::RenderState maState;
101 BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx,
102 const ::basegfx::B2DPoint& rDstPoint,
103 const CanvasSharedPtr& rCanvas,
104 const OutDevState& rState ) :
105 CachedPrimitiveBase( rCanvas, true ),
106 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas->getUNOCanvas()->getDevice(),
107 rBmpEx ) ),
108 mpCanvas( rCanvas ),
109 maState()
111 tools::initRenderState(maState,rState);
113 // Setup transformation such that the next render call is
114 // moved rPoint away.
115 ::basegfx::B2DHomMatrix aLocalTransformation;
116 aLocalTransformation.translate( rDstPoint.getX(),
117 rDstPoint.getY() );
118 ::canvas::tools::appendToRenderState( maState,
119 aLocalTransformation );
121 // correct clip (which is relative to original transform)
122 tools::modifyClip( maState,
123 rState,
124 rCanvas,
125 rDstPoint,
126 NULL,
127 NULL );
130 BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx,
131 const ::basegfx::B2DPoint& rDstPoint,
132 const ::basegfx::B2DVector& rDstSize,
133 const CanvasSharedPtr& rCanvas,
134 const OutDevState& rState ) :
135 CachedPrimitiveBase( rCanvas, true ),
136 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas->getUNOCanvas()->getDevice(),
137 rBmpEx ) ),
138 mpCanvas( rCanvas ),
139 maState()
141 tools::initRenderState(maState,rState);
143 // Setup transformation such that the next render call is
144 // moved rPoint away, and scaled according to the ratio
145 // given by src and dst size.
146 const ::Size aBmpSize( rBmpEx.GetSizePixel() );
147 ::basegfx::B2DHomMatrix aLocalTransformation;
149 const ::basegfx::B2DVector aScale( rDstSize.getX() / aBmpSize.Width(),
150 rDstSize.getY() / aBmpSize.Height() );
151 aLocalTransformation.scale( aScale.getX(), aScale.getY() );
152 aLocalTransformation.translate( rDstPoint.getX(),
153 rDstPoint.getY() );
154 ::canvas::tools::appendToRenderState( maState,
155 aLocalTransformation );
157 // correct clip (which is relative to original transform)
158 tools::modifyClip( maState,
159 rState,
160 rCanvas,
161 rDstPoint,
162 &aScale,
163 NULL );
166 bool BitmapAction::render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
167 const ::basegfx::B2DHomMatrix& rTransformation ) const
169 RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::BitmapAction::render()" );
170 RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::BitmapAction: 0x%X", this );
172 rendering::RenderState aLocalState( maState );
173 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
175 rCachedPrimitive = mpCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
176 mpCanvas->getViewState(),
177 aLocalState );
179 return true;
182 bool BitmapAction::render( const ::basegfx::B2DHomMatrix& rTransformation,
183 const Subset& rSubset ) const
185 // bitmap only contains a single action, fail if subset
186 // requests different range
187 if( rSubset.mnSubsetBegin != 0 ||
188 rSubset.mnSubsetEnd != 1 )
189 return false;
191 return CachedPrimitiveBase::render( rTransformation );
194 ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
196 rendering::RenderState aLocalState( maState );
197 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
199 const geometry::IntegerSize2D aSize( mxBitmap->getSize() );
201 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0,0,
202 aSize.Width,
203 aSize.Height ),
204 mpCanvas->getViewState(),
205 aLocalState );
208 ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
209 const Subset& rSubset ) const
211 // bitmap only contains a single action, empty bounds
212 // if subset requests different range
213 if( rSubset.mnSubsetBegin != 0 ||
214 rSubset.mnSubsetEnd != 1 )
215 return ::basegfx::B2DRange();
217 return getBounds( rTransformation );
220 sal_Int32 BitmapAction::getActionCount() const
222 return 1;
226 ActionSharedPtr BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
227 const ::basegfx::B2DPoint& rDstPoint,
228 const CanvasSharedPtr& rCanvas,
229 const OutDevState& rState )
231 return ActionSharedPtr( new BitmapAction(rBmpEx,
232 rDstPoint,
233 rCanvas,
234 rState ) );
237 ActionSharedPtr BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
238 const ::basegfx::B2DPoint& rDstPoint,
239 const ::basegfx::B2DVector& rDstSize,
240 const CanvasSharedPtr& rCanvas,
241 const OutDevState& rState )
243 return ActionSharedPtr( new BitmapAction(rBmpEx,
244 rDstPoint,
245 rDstSize,
246 rCanvas,
247 rState ) );