Bump version to 5.0-14
[LibreOffice.git] / cppcanvas / source / mtfrenderer / bitmapaction.cxx
blobfb0eb33ffec970bba647b13c45f4d485ce629010
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
43 namespace cppcanvas
45 namespace internal
47 namespace
50 class BitmapAction : public CachedPrimitiveBase
52 public:
53 BitmapAction( const ::BitmapEx&,
54 const ::basegfx::B2DPoint& rDstPoint,
55 const CanvasSharedPtr&,
56 const OutDevState& );
57 BitmapAction( const ::BitmapEx&,
58 const ::basegfx::B2DPoint& rDstPoint,
59 const ::basegfx::B2DVector& rDstSize,
60 const CanvasSharedPtr&,
61 const OutDevState& );
63 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
64 const Subset& rSubset ) const SAL_OVERRIDE;
66 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const SAL_OVERRIDE;
67 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
68 const Subset& rSubset ) const SAL_OVERRIDE;
70 virtual sal_Int32 getActionCount() const SAL_OVERRIDE;
72 private:
73 using Action::render;
74 virtual bool renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
75 const ::basegfx::B2DHomMatrix& rTransformation ) const SAL_OVERRIDE;
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(),
89 rBmpEx ) ),
90 mpCanvas( rCanvas ),
91 maState()
93 tools::initRenderState(maState,rState);
95 // Setup transformation such that the next render call is
96 // moved rPoint away.
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,
103 rState,
104 rCanvas,
105 rDstPoint,
106 NULL,
107 NULL );
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(),
117 rBmpEx ) ),
118 mpCanvas( rCanvas ),
119 maState()
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(
131 aScale, rDstPoint));
132 ::canvas::tools::appendToRenderState( maState, aLocalTransformation );
134 // correct clip (which is relative to original transform)
135 tools::modifyClip( maState,
136 rState,
137 rCanvas,
138 rDstPoint,
139 &aScale,
140 NULL );
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(),
154 aLocalState );
156 return true;
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 )
166 return false;
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,
179 aSize.Width,
180 aSize.Height ),
181 mpCanvas->getViewState(),
182 aLocalState );
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
199 return 1;
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,
209 rDstPoint,
210 rCanvas,
211 rState ) );
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,
221 rDstPoint,
222 rDstSize,
223 rCanvas,
224 rState ) );
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */