1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <rtl/logfile.hxx>
22 #include <com/sun/star/rendering/XBitmap.hpp>
23 #include <com/sun/star/rendering/RepaintResult.hpp>
24 #include <com/sun/star/rendering/XCachedPrimitive.hpp>
25 #include <vcl/bitmapex.hxx>
26 #include <tools/gen.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <canvas/canvastools.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/vector/b2dsize.hxx>
31 #include <basegfx/point/b2dpoint.hxx>
32 #include <basegfx/range/b2drange.hxx>
33 #include <basegfx/tools/canvastools.hxx>
34 #include <boost/utility.hpp>
35 #include "cachedprimitivebase.hxx"
36 #include "bitmapaction.hxx"
37 #include "outdevstate.hxx"
38 #include "mtftools.hxx"
39 #include <basegfx/matrix/b2dhommatrixtools.hxx>
42 using namespace ::com::sun::star
;
51 class BitmapAction
: public CachedPrimitiveBase
54 BitmapAction( const ::BitmapEx
&,
55 const ::basegfx::B2DPoint
& rDstPoint
,
56 const CanvasSharedPtr
&,
58 BitmapAction( const ::BitmapEx
&,
59 const ::basegfx::B2DPoint
& rDstPoint
,
60 const ::basegfx::B2DVector
& rDstSize
,
61 const CanvasSharedPtr
&,
64 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
65 const Subset
& rSubset
) const;
67 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
68 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
69 const Subset
& rSubset
) const;
71 virtual sal_Int32
getActionCount() const;
75 virtual bool renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
76 const ::basegfx::B2DHomMatrix
& rTransformation
) const;
78 uno::Reference
< rendering::XBitmap
> mxBitmap
;
79 CanvasSharedPtr mpCanvas
;
80 rendering::RenderState maState
;
84 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
85 const ::basegfx::B2DPoint
& rDstPoint
,
86 const CanvasSharedPtr
& rCanvas
,
87 const OutDevState
& rState
) :
88 CachedPrimitiveBase( rCanvas
, true ),
89 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
94 tools::initRenderState(maState
,rState
);
96 // Setup transformation such that the next render call is
98 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createTranslateB2DHomMatrix(rDstPoint
));
99 ::canvas::tools::appendToRenderState( maState
,
100 aLocalTransformation
);
102 // correct clip (which is relative to original transform)
103 tools::modifyClip( maState
,
111 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
112 const ::basegfx::B2DPoint
& rDstPoint
,
113 const ::basegfx::B2DVector
& rDstSize
,
114 const CanvasSharedPtr
& rCanvas
,
115 const OutDevState
& rState
) :
116 CachedPrimitiveBase( rCanvas
, true ),
117 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
122 tools::initRenderState(maState
,rState
);
124 // Setup transformation such that the next render call is
125 // moved rPoint away, and scaled according to the ratio
126 // given by src and dst size.
127 const ::Size
aBmpSize( rBmpEx
.GetSizePixel() );
129 const ::basegfx::B2DVector
aScale( rDstSize
.getX() / aBmpSize
.Width(),
130 rDstSize
.getY() / aBmpSize
.Height() );
131 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createScaleTranslateB2DHomMatrix(
133 ::canvas::tools::appendToRenderState( maState
, aLocalTransformation
);
135 // correct clip (which is relative to original transform)
136 tools::modifyClip( maState
,
144 bool BitmapAction::renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
145 const ::basegfx::B2DHomMatrix
& rTransformation
) const
147 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction::renderPrimitive()" );
148 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction: 0x" << std::hex
<< this );
150 rendering::RenderState
aLocalState( maState
);
151 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
153 rCachedPrimitive
= mpCanvas
->getUNOCanvas()->drawBitmap( mxBitmap
,
154 mpCanvas
->getViewState(),
160 bool BitmapAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
161 const Subset
& rSubset
) const
163 // bitmap only contains a single action, fail if subset
164 // requests different range
165 if( rSubset
.mnSubsetBegin
!= 0 ||
166 rSubset
.mnSubsetEnd
!= 1 )
169 return CachedPrimitiveBase::render( rTransformation
);
172 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
174 rendering::RenderState
aLocalState( maState
);
175 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
177 const geometry::IntegerSize2D
aSize( mxBitmap
->getSize() );
179 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0,0,
182 mpCanvas
->getViewState(),
186 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
187 const Subset
& rSubset
) const
189 // bitmap only contains a single action, empty bounds
190 // if subset requests different range
191 if( rSubset
.mnSubsetBegin
!= 0 ||
192 rSubset
.mnSubsetEnd
!= 1 )
193 return ::basegfx::B2DRange();
195 return getBounds( rTransformation
);
198 sal_Int32
BitmapAction::getActionCount() const
204 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
205 const ::basegfx::B2DPoint
& rDstPoint
,
206 const CanvasSharedPtr
& rCanvas
,
207 const OutDevState
& rState
)
209 return ActionSharedPtr( new BitmapAction(rBmpEx
,
215 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
216 const ::basegfx::B2DPoint
& rDstPoint
,
217 const ::basegfx::B2DVector
& rDstSize
,
218 const CanvasSharedPtr
& rCanvas
,
219 const OutDevState
& rState
)
221 return ActionSharedPtr( new BitmapAction(rBmpEx
,
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */