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 <com/sun/star/rendering/XBitmap.hpp>
22 #include <com/sun/star/rendering/RepaintResult.hpp>
23 #include <com/sun/star/rendering/XCachedPrimitive.hpp>
24 #include <vcl/bitmapex.hxx>
25 #include <tools/gen.hxx>
26 #include <vcl/canvastools.hxx>
27 #include <canvas/canvastools.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <basegfx/vector/b2dsize.hxx>
30 #include <basegfx/point/b2dpoint.hxx>
31 #include <basegfx/range/b2drange.hxx>
32 #include <basegfx/tools/canvastools.hxx>
33 #include <boost/utility.hpp>
34 #include "cachedprimitivebase.hxx"
35 #include "bitmapaction.hxx"
36 #include "outdevstate.hxx"
37 #include "mtftools.hxx"
38 #include <basegfx/matrix/b2dhommatrixtools.hxx>
41 using namespace ::com::sun::star
;
50 class BitmapAction
: public CachedPrimitiveBase
53 BitmapAction( const ::BitmapEx
&,
54 const ::basegfx::B2DPoint
& rDstPoint
,
55 const CanvasSharedPtr
&,
57 BitmapAction( const ::BitmapEx
&,
58 const ::basegfx::B2DPoint
& rDstPoint
,
59 const ::basegfx::B2DVector
& rDstSize
,
60 const CanvasSharedPtr
&,
63 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
64 const Subset
& rSubset
) const;
66 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
67 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
68 const Subset
& rSubset
) const;
70 virtual sal_Int32
getActionCount() const;
74 virtual bool renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
75 const ::basegfx::B2DHomMatrix
& rTransformation
) const;
77 uno::Reference
< rendering::XBitmap
> mxBitmap
;
78 CanvasSharedPtr mpCanvas
;
79 rendering::RenderState maState
;
83 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
84 const ::basegfx::B2DPoint
& rDstPoint
,
85 const CanvasSharedPtr
& rCanvas
,
86 const OutDevState
& rState
) :
87 CachedPrimitiveBase( rCanvas
, true ),
88 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
93 tools::initRenderState(maState
,rState
);
95 // Setup transformation such that the next render call is
97 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createTranslateB2DHomMatrix(rDstPoint
));
98 ::canvas::tools::appendToRenderState( maState
,
99 aLocalTransformation
);
101 // correct clip (which is relative to original transform)
102 tools::modifyClip( maState
,
110 BitmapAction::BitmapAction( const ::BitmapEx
& rBmpEx
,
111 const ::basegfx::B2DPoint
& rDstPoint
,
112 const ::basegfx::B2DVector
& rDstSize
,
113 const CanvasSharedPtr
& rCanvas
,
114 const OutDevState
& rState
) :
115 CachedPrimitiveBase( rCanvas
, true ),
116 mxBitmap( ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(),
121 tools::initRenderState(maState
,rState
);
123 // Setup transformation such that the next render call is
124 // moved rPoint away, and scaled according to the ratio
125 // given by src and dst size.
126 const ::Size
aBmpSize( rBmpEx
.GetSizePixel() );
128 const ::basegfx::B2DVector
aScale( rDstSize
.getX() / aBmpSize
.Width(),
129 rDstSize
.getY() / aBmpSize
.Height() );
130 const basegfx::B2DHomMatrix
aLocalTransformation(basegfx::tools::createScaleTranslateB2DHomMatrix(
132 ::canvas::tools::appendToRenderState( maState
, aLocalTransformation
);
134 // correct clip (which is relative to original transform)
135 tools::modifyClip( maState
,
143 bool BitmapAction::renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
144 const ::basegfx::B2DHomMatrix
& rTransformation
) const
146 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction::renderPrimitive()" );
147 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction: 0x" << std::hex
<< this );
149 rendering::RenderState
aLocalState( maState
);
150 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
152 rCachedPrimitive
= mpCanvas
->getUNOCanvas()->drawBitmap( mxBitmap
,
153 mpCanvas
->getViewState(),
159 bool BitmapAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
160 const Subset
& rSubset
) const
162 // bitmap only contains a single action, fail if subset
163 // requests different range
164 if( rSubset
.mnSubsetBegin
!= 0 ||
165 rSubset
.mnSubsetEnd
!= 1 )
168 return CachedPrimitiveBase::render( rTransformation
);
171 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
173 rendering::RenderState
aLocalState( maState
);
174 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
176 const geometry::IntegerSize2D
aSize( mxBitmap
->getSize() );
178 return tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0,0,
181 mpCanvas
->getViewState(),
185 ::basegfx::B2DRange
BitmapAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
186 const Subset
& rSubset
) const
188 // bitmap only contains a single action, empty bounds
189 // if subset requests different range
190 if( rSubset
.mnSubsetBegin
!= 0 ||
191 rSubset
.mnSubsetEnd
!= 1 )
192 return ::basegfx::B2DRange();
194 return getBounds( rTransformation
);
197 sal_Int32
BitmapAction::getActionCount() const
203 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
204 const ::basegfx::B2DPoint
& rDstPoint
,
205 const CanvasSharedPtr
& rCanvas
,
206 const OutDevState
& rState
)
208 return ActionSharedPtr( new BitmapAction(rBmpEx
,
214 ActionSharedPtr
BitmapActionFactory::createBitmapAction( const ::BitmapEx
& rBmpEx
,
215 const ::basegfx::B2DPoint
& rDstPoint
,
216 const ::basegfx::B2DVector
& rDstSize
,
217 const CanvasSharedPtr
& rCanvas
,
218 const OutDevState
& rState
)
220 return ActionSharedPtr( new BitmapAction(rBmpEx
,
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */