Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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>
39 :
40 :
41 : using namespace ::com::sun::star;
42 :
43 : namespace cppcanvas
44 : {
45 : namespace internal
46 : {
47 : namespace
48 : {
49 :
50 4 : class BitmapAction : public CachedPrimitiveBase
51 : {
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& );
62 :
63 : virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
64 : const Subset& rSubset ) const SAL_OVERRIDE;
65 :
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;
69 :
70 : virtual sal_Int32 getActionCount() const SAL_OVERRIDE;
71 :
72 : private:
73 : using Action::render;
74 : virtual bool renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
75 : const ::basegfx::B2DHomMatrix& rTransformation ) const SAL_OVERRIDE;
76 :
77 : uno::Reference< rendering::XBitmap > mxBitmap;
78 : CanvasSharedPtr mpCanvas;
79 : rendering::RenderState maState;
80 : };
81 :
82 :
83 0 : BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx,
84 : const ::basegfx::B2DPoint& rDstPoint,
85 : const CanvasSharedPtr& rCanvas,
86 : const OutDevState& rState ) :
87 : CachedPrimitiveBase( rCanvas, true ),
88 0 : mxBitmap( vcl::unotools::xBitmapFromBitmapEx( rCanvas->getUNOCanvas()->getDevice(),
89 : rBmpEx ) ),
90 : mpCanvas( rCanvas ),
91 0 : maState()
92 : {
93 0 : tools::initRenderState(maState,rState);
94 :
95 : // Setup transformation such that the next render call is
96 : // moved rPoint away.
97 0 : const basegfx::B2DHomMatrix aLocalTransformation(basegfx::tools::createTranslateB2DHomMatrix(rDstPoint));
98 : ::canvas::tools::appendToRenderState( maState,
99 0 : aLocalTransformation );
100 :
101 : // correct clip (which is relative to original transform)
102 : tools::modifyClip( maState,
103 : rState,
104 : rCanvas,
105 : rDstPoint,
106 : NULL,
107 0 : NULL );
108 0 : }
109 :
110 2 : 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 4 : mxBitmap( vcl::unotools::xBitmapFromBitmapEx( rCanvas->getUNOCanvas()->getDevice(),
117 : rBmpEx ) ),
118 : mpCanvas( rCanvas ),
119 6 : maState()
120 : {
121 2 : tools::initRenderState(maState,rState);
122 :
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 2 : const ::Size aBmpSize( rBmpEx.GetSizePixel() );
127 :
128 2 : const ::basegfx::B2DVector aScale( rDstSize.getX() / aBmpSize.Width(),
129 4 : rDstSize.getY() / aBmpSize.Height() );
130 : const basegfx::B2DHomMatrix aLocalTransformation(basegfx::tools::createScaleTranslateB2DHomMatrix(
131 4 : aScale, rDstPoint));
132 2 : ::canvas::tools::appendToRenderState( maState, aLocalTransformation );
133 :
134 : // correct clip (which is relative to original transform)
135 : tools::modifyClip( maState,
136 : rState,
137 : rCanvas,
138 : rDstPoint,
139 : &aScale,
140 4 : NULL );
141 2 : }
142 :
143 2 : bool BitmapAction::renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
144 : const ::basegfx::B2DHomMatrix& rTransformation ) const
145 : {
146 : SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction::renderPrimitive()" );
147 : SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction: 0x" << std::hex << this );
148 :
149 2 : rendering::RenderState aLocalState( maState );
150 2 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
151 :
152 6 : rCachedPrimitive = mpCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
153 2 : mpCanvas->getViewState(),
154 4 : aLocalState );
155 :
156 2 : return true;
157 : }
158 :
159 0 : bool BitmapAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
160 : const Subset& rSubset ) const
161 : {
162 : // bitmap only contains a single action, fail if subset
163 : // requests different range
164 0 : if( rSubset.mnSubsetBegin != 0 ||
165 0 : rSubset.mnSubsetEnd != 1 )
166 0 : return false;
167 :
168 0 : return CachedPrimitiveBase::render( rTransformation );
169 : }
170 :
171 0 : ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
172 : {
173 0 : rendering::RenderState aLocalState( maState );
174 0 : ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
175 :
176 0 : const geometry::IntegerSize2D aSize( mxBitmap->getSize() );
177 :
178 : return tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0,0,
179 : aSize.Width,
180 : aSize.Height ),
181 0 : mpCanvas->getViewState(),
182 0 : aLocalState );
183 : }
184 :
185 0 : ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
186 : const Subset& rSubset ) const
187 : {
188 : // bitmap only contains a single action, empty bounds
189 : // if subset requests different range
190 0 : if( rSubset.mnSubsetBegin != 0 ||
191 0 : rSubset.mnSubsetEnd != 1 )
192 0 : return ::basegfx::B2DRange();
193 :
194 0 : return getBounds( rTransformation );
195 : }
196 :
197 2 : sal_Int32 BitmapAction::getActionCount() const
198 : {
199 2 : return 1;
200 : }
201 : }
202 :
203 0 : ActionSharedPtr BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
204 : const ::basegfx::B2DPoint& rDstPoint,
205 : const CanvasSharedPtr& rCanvas,
206 : const OutDevState& rState )
207 : {
208 : return ActionSharedPtr( new BitmapAction(rBmpEx,
209 : rDstPoint,
210 : rCanvas,
211 0 : rState ) );
212 : }
213 :
214 2 : ActionSharedPtr BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
215 : const ::basegfx::B2DPoint& rDstPoint,
216 : const ::basegfx::B2DVector& rDstSize,
217 : const CanvasSharedPtr& rCanvas,
218 : const OutDevState& rState )
219 : {
220 : return ActionSharedPtr( new BitmapAction(rBmpEx,
221 : rDstPoint,
222 : rDstSize,
223 : rCanvas,
224 2 : rState ) );
225 : }
226 : }
227 : }
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|