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