1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bitmapaction.cxx,v $
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
;
68 class BitmapAction
: public CachedPrimitiveBase
71 BitmapAction( const ::BitmapEx
&,
72 const ::basegfx::B2DPoint
& rDstPoint
,
73 const CanvasSharedPtr
&,
75 BitmapAction( const ::BitmapEx
&,
76 const ::basegfx::B2DPoint
& rDstPoint
,
77 const ::basegfx::B2DVector
& rDstSize
,
78 const CanvasSharedPtr
&,
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;
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(),
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(),
118 ::canvas::tools::appendToRenderState( maState
,
119 aLocalTransformation
);
121 // correct clip (which is relative to original transform)
122 tools::modifyClip( maState
,
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(),
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(),
154 ::canvas::tools::appendToRenderState( maState
,
155 aLocalTransformation
);
157 // correct clip (which is relative to original transform)
158 tools::modifyClip( maState
,
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(),
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 )
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,
204 mpCanvas
->getViewState(),
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
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
,
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
,