1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <rtl/logfile.hxx>
31 #include <com/sun/star/rendering/XBitmap.hpp>
32 #include <com/sun/star/rendering/RepaintResult.hpp>
33 #include <com/sun/star/rendering/XCachedPrimitive.hpp>
34 #include <vcl/rendergraphicrasterizer.hxx>
35 #include <tools/gen.hxx>
36 #include <vcl/canvastools.hxx>
37 #include <canvas/canvastools.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/vector/b2dsize.hxx>
40 #include <basegfx/point/b2dpoint.hxx>
41 #include <basegfx/range/b2drange.hxx>
42 #include <basegfx/tools/canvastools.hxx>
43 #include <boost/utility.hpp>
44 #include "cachedprimitivebase.hxx"
45 #include "rendergraphicaction.hxx"
46 #include "outdevstate.hxx"
47 #include "mtftools.hxx"
48 #include <basegfx/matrix/b2dhommatrixtools.hxx>
51 using namespace ::com::sun::star
;
60 class RenderGraphicAction
: public CachedPrimitiveBase
63 RenderGraphicAction( const ::vcl::RenderGraphic
& rRenderGraphic
,
64 const ::basegfx::B2DPoint
& rDstPoint
,
65 const ::basegfx::B2DVector
& rDstSize
,
66 const CanvasSharedPtr
&,
69 virtual bool renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
70 const Subset
& rSubset
) const;
72 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const;
73 virtual ::basegfx::B2DRange
getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
74 const Subset
& rSubset
) const;
76 virtual sal_Int32
getActionCount() const;
80 virtual bool renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
81 const ::basegfx::B2DHomMatrix
& rTransformation
) const;
83 ::vcl::RenderGraphic maRenderGraphic
;
84 uno::Reference
< rendering::XBitmap
> mxBitmap
;
85 CanvasSharedPtr mpCanvas
;
86 rendering::RenderState maState
;
89 RenderGraphicAction::RenderGraphicAction( const ::vcl::RenderGraphic
& rRenderGraphic
,
90 const ::basegfx::B2DPoint
& rDstPoint
,
91 const ::basegfx::B2DVector
& rDstSize
,
92 const CanvasSharedPtr
& rCanvas
,
93 const OutDevState
& rState
) :
94 CachedPrimitiveBase( rCanvas
, true ),
95 maRenderGraphic( rRenderGraphic
),
98 tools::initRenderState( maState
,rState
);
100 const ::vcl::RenderGraphicRasterizer
aRasterizer( rRenderGraphic
);
101 const BitmapEx
aBmpEx( aRasterizer
.Rasterize( ::vcl::unotools::sizeFromB2DSize( rDstSize
) ) );
102 const Size
aRasteredSizePixel( aBmpEx
.GetSizePixel() );
104 if( aRasteredSizePixel
.Width() && aRasteredSizePixel
.Height() )
106 const ::basegfx::B2DVector
aScale( rDstSize
.getX() / aRasteredSizePixel
.Width(),
107 rDstSize
.getY() / aRasteredSizePixel
.Height() );
108 const basegfx::B2DHomMatrix
aLocalTransformation(
109 basegfx::tools::createScaleTranslateB2DHomMatrix( aScale
, rDstPoint
)) ;
111 ::canvas::tools::appendToRenderState( maState
, aLocalTransformation
);
113 // correct clip (which is relative to original transform)
114 tools::modifyClip( maState
, rState
, rCanvas
, rDstPoint
, &aScale
, NULL
);
116 mxBitmap
= ::vcl::unotools::xBitmapFromBitmapEx( rCanvas
->getUNOCanvas()->getDevice(), aBmpEx
);
120 bool RenderGraphicAction::renderPrimitive( uno::Reference
< rendering::XCachedPrimitive
>& rCachedPrimitive
,
121 const ::basegfx::B2DHomMatrix
& rTransformation
) const
123 RTL_LOGFILE_CONTEXT( aLog
, "::cppcanvas::internal::RenderGraphicAction::renderPrimitive()" );
124 RTL_LOGFILE_CONTEXT_TRACE1( aLog
, "::cppcanvas::internal::RenderGraphicAction: 0x%X", this );
128 rendering::RenderState
aLocalState( maState
);
129 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
131 rCachedPrimitive
= mpCanvas
->getUNOCanvas()->drawBitmap( mxBitmap
,
132 mpCanvas
->getViewState(),
139 bool RenderGraphicAction::renderSubset( const ::basegfx::B2DHomMatrix
& rTransformation
,
140 const Subset
& rSubset
) const
142 // rendergraphic only contains a single action, fail if subset
143 // requests different range
144 if( rSubset
.mnSubsetBegin
!= 0 ||
145 rSubset
.mnSubsetEnd
!= 1 )
148 return CachedPrimitiveBase::render( rTransformation
);
151 ::basegfx::B2DRange
RenderGraphicAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
) const
153 ::basegfx::B2DRange aRet
;
157 rendering::RenderState
aLocalState( maState
);
158 ::canvas::tools::prependToRenderState(aLocalState
, rTransformation
);
160 geometry::IntegerSize2D
aSize( mxBitmap
->getSize() );
162 aRet
= tools::calcDevicePixelBounds( ::basegfx::B2DRange( 0, 0, aSize
.Width
, aSize
.Height
),
163 mpCanvas
->getViewState(), aLocalState
);
169 ::basegfx::B2DRange
RenderGraphicAction::getBounds( const ::basegfx::B2DHomMatrix
& rTransformation
,
170 const Subset
& rSubset
) const
172 // rendergraphic only contains a single action, empty bounds
173 // if subset requests different range
174 if( rSubset
.mnSubsetBegin
!= 0 ||
175 rSubset
.mnSubsetEnd
!= 1 )
176 return ::basegfx::B2DRange();
178 return getBounds( rTransformation
);
181 sal_Int32
RenderGraphicAction::getActionCount() const
187 ActionSharedPtr
RenderGraphicActionFactory::createRenderGraphicAction( const ::vcl::RenderGraphic
& rRenderGraphic
,
188 const ::basegfx::B2DPoint
& rDstPoint
,
189 const ::basegfx::B2DVector
& rDstSize
,
190 const CanvasSharedPtr
& rCanvas
,
191 const OutDevState
& rState
)
193 return ActionSharedPtr( new RenderGraphicAction(rRenderGraphic
,
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */