1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <rtl/logfile.hxx>
31 #include <com/sun/star/rendering/XBitmap.hpp>
32 #include <com/sun/star/rendering/RepaintResult.hpp>
33 #include <com/sun/star/rendering/XCachedPrimitive.hpp>
34 #include <vcl/bitmapex.hxx>
35 #include <tools/gen.hxx>
36 #include <vcl/canvastools.hxx>
37 #include <canvas/canvastools.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/vector/b2dsize.hxx>
40 #include <basegfx/point/b2dpoint.hxx>
41 #include <basegfx/range/b2drange.hxx>
42 #include <basegfx/tools/canvastools.hxx>
43 #include <boost/utility.hpp>
44 #include "cachedprimitivebase.hxx"
45 #include "bitmapaction.hxx"
46 #include "outdevstate.hxx"
47 #include "mtftools.hxx"
48 #include <basegfx/matrix/b2dhommatrixtools.hxx>
51 using namespace ::com::sun::star
;
60 class BitmapAction
: public CachedPrimitiveBase
63 BitmapAction( const ::BitmapEx
&,
64 const ::basegfx::B2DPoint
& rDstPoint
,
65 const CanvasSharedPtr
&,
67 BitmapAction( const ::BitmapEx
&,
68 const ::basegfx::B2DPoint
& rDstPoint
,
69 const ::basegfx::B2DVector
& rDstSize
,
70 const CanvasSharedPtr
&,
73 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
74 const Subset
& rSubset
) const;
76 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
77 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
78 const Subset
& rSubset
) const;
80 virtual sal_Int32
getActionCount() const;
84 virtual bool renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
85 const ::basegfx::B2DHomMatrix
& rTransformation
) const;
87 uno::Reference
< rendering::XBitmap
> mxBitmap
;
88 CanvasSharedPtr mpCanvas
;
89 rendering::RenderState maState
;
93 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
94 const ::basegfx::B2DPoint
& rDstPoint
,
95 const CanvasSharedPtr
& rCanvas
,
96 const OutDevState
& rState
) :
97 CachedPrimitiveBase( rCanvas
, true ),
98 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
103 tools::initRenderState(maState
,rState
);
105 // Setup transformation such that the next render call is
106 // moved rPoint away.
107 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createTranslateB2DHomMatrix(rDstPoint
));
108 ::canvas::tools::appendToRenderState( maState
,
109 aLocalTransformation
);
111 // correct clip (which is relative to original transform)
112 tools::modifyClip( maState
,
120 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
121 const ::basegfx::B2DPoint
& rDstPoint
,
122 const ::basegfx::B2DVector
& rDstSize
,
123 const CanvasSharedPtr
& rCanvas
,
124 const OutDevState
& rState
) :
125 CachedPrimitiveBase( rCanvas
, true ),
126 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
131 tools::initRenderState(maState
,rState
);
133 // Setup transformation such that the next render call is
134 // moved rPoint away, and scaled according to the ratio
135 // given by src and dst size.
136 const ::Size
aBmpSize( rBmpEx
.GetSizePixel() );
138 const ::basegfx::B2DVector
aScale( rDstSize
.getX() / aBmpSize
.Width(),
139 rDstSize
.getY() / aBmpSize
.Height() );
140 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createScaleTranslateB2DHomMatrix(
142 ::canvas::tools::appendToRenderState( maState
, aLocalTransformation
);
144 // correct clip (which is relative to original transform)
145 tools::modifyClip( maState
,
153 bool BitmapAction::renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
154 const ::basegfx::B2DHomMatrix
& rTransformation
) const
156 RTL_LOGFILE_CONTEXT( aLog
, "::cppcanvas::internal::BitmapAction::renderPrimitive()" );
157 RTL_LOGFILE_CONTEXT_TRACE1( aLog
, "::cppcanvas::internal::BitmapAction: 0x%X", this );
159 rendering::RenderState
aLocalState( maState
);
160 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
162 rCachedPrimitive
= mpCanvas
->getUNOCanvas()->drawBitmap( mxBitmap
,
163 mpCanvas
->getViewState(),
169 bool BitmapAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
170 const Subset
& rSubset
) const
172 // bitmap only contains a single action, fail if subset
173 // requests different range
174 if( rSubset
.mnSubsetBegin
!= 0 ||
175 rSubset
.mnSubsetEnd
!= 1 )
178 return CachedPrimitiveBase::render( rTransformation
);
181 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
183 rendering::RenderState
aLocalState( maState
);
184 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
186 const geometry::IntegerSize2D
aSize( mxBitmap
->getSize() );
188 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0,0,
191 mpCanvas
->getViewState(),
195 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
196 const Subset
& rSubset
) const
198 // bitmap only contains a single action, empty bounds
199 // if subset requests different range
200 if( rSubset
.mnSubsetBegin
!= 0 ||
201 rSubset
.mnSubsetEnd
!= 1 )
202 return ::basegfx::B2DRange();
204 return getBounds( rTransformation
);
207 sal_Int32
BitmapAction::getActionCount() const
213 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
214 const ::basegfx::B2DPoint
& rDstPoint
,
215 const CanvasSharedPtr
& rCanvas
,
216 const OutDevState
& rState
)
218 return ActionSharedPtr( new BitmapAction(rBmpEx
,
224 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
225 const ::basegfx::B2DPoint
& rDstPoint
,
226 const ::basegfx::B2DVector
& rDstSize
,
227 const CanvasSharedPtr
& rCanvas
,
228 const OutDevState
& rState
)
230 return ActionSharedPtr( new BitmapAction(rBmpEx
,
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */