1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewbackgroundshape.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
38 #include "viewbackgroundshape.hxx"
41 #include <rtl/logfile.hxx>
42 #include <rtl/math.hxx>
44 #include <comphelper/anytostring.hxx>
45 #include <cppuhelper/exc_hlp.hxx>
47 #include <basegfx/polygon/b2dpolygontools.hxx>
48 #include <basegfx/polygon/b2dpolygon.hxx>
49 #include <basegfx/numeric/ftools.hxx>
50 #include <basegfx/matrix/b2dhommatrix.hxx>
52 #include <com/sun/star/rendering/XCanvas.hpp>
54 #include <canvas/verbosetrace.hxx>
55 #include <canvas/canvastools.hxx>
56 #include <cppcanvas/vclfactory.hxx>
57 #include <cppcanvas/basegfxfactory.hxx>
58 #include <cppcanvas/renderer.hxx>
59 #include <cppcanvas/bitmap.hxx>
61 using namespace ::com::sun::star
;
69 bool ViewBackgroundShape::prefetch( const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
,
70 const GDIMetaFileSharedPtr
& rMtf
) const
72 RTL_LOGFILE_CONTEXT( aLog
, "::presentation::internal::ViewBackgroundShape::prefetch()" );
73 ENSURE_OR_RETURN( rMtf
,
74 "ViewBackgroundShape::prefetch(): no valid metafile!" );
76 const ::basegfx::B2DHomMatrix
& rCanvasTransform(
77 mpViewLayer
->getTransformation() );
81 rCanvasTransform
!= maLastTransformation
)
83 // buffered bitmap is invalid, re-create
85 // determine transformed page bounds
86 ::basegfx::B2DRectangle aTmpRect
;
87 ::canvas::tools::calcTransformedRectBounds( aTmpRect
,
91 // determine pixel size of bitmap (choose it one pixel
92 // larger, as polygon rendering takes one pixel more
93 // to the right and to the bottom)
94 const ::basegfx::B2ISize
aBmpSizePixel(
95 ::basegfx::fround( aTmpRect
.getRange().getX() + 1),
96 ::basegfx::fround( aTmpRect
.getRange().getY() + 1) );
98 // create a bitmap of appropriate size
99 ::cppcanvas::BitmapSharedPtr
pBitmap(
100 ::cppcanvas::BaseGfxFactory::getInstance().createBitmap(
104 ENSURE_OR_THROW( pBitmap
,
105 "ViewBackgroundShape::prefetch(): Cannot create background bitmap" );
107 ::cppcanvas::BitmapCanvasSharedPtr
pBitmapCanvas( pBitmap
->getBitmapCanvas() );
109 ENSURE_OR_THROW( pBitmapCanvas
,
110 "ViewBackgroundShape::prefetch(): Cannot create background bitmap canvas" );
113 initSlideBackground( pBitmapCanvas
,
116 // apply linear part of destination canvas transformation (linear means in this context:
117 // transformation without any translational components)
118 ::basegfx::B2DHomMatrix
aLinearTransform( rCanvasTransform
);
119 aLinearTransform
.set( 0, 2, 0.0 );
120 aLinearTransform
.set( 1, 2, 0.0 );
121 pBitmapCanvas
->setTransformation( aLinearTransform
);
123 ::basegfx::B2DHomMatrix aShapeTransform
;
125 aShapeTransform
.scale( maBounds
.getWidth(), maBounds
.getHeight() );
126 aShapeTransform
.translate( maBounds
.getMinX(), maBounds
.getMinY() );
128 ::cppcanvas::RendererSharedPtr
pRenderer(
129 ::cppcanvas::VCLFactory::getInstance().createRenderer(
132 ::cppcanvas::Renderer::Parameters() ) );
134 ENSURE_OR_RETURN( pRenderer
,
135 "ViewBackgroundShape::prefetch(): Could not create Renderer" );
137 pRenderer
->setTransformation( aShapeTransform
);
140 mxBitmap
= pBitmap
->getUNOBitmap();
144 maLastTransformation
= rCanvasTransform
;
146 return mxBitmap
.is();
149 ViewBackgroundShape::ViewBackgroundShape( const ViewLayerSharedPtr
& rViewLayer
,
150 const ::basegfx::B2DRectangle
& rShapeBounds
) :
151 mpViewLayer( rViewLayer
),
154 maLastTransformation(),
155 maBounds( rShapeBounds
)
157 ENSURE_OR_THROW( mpViewLayer
, "ViewBackgroundShape::ViewBackgroundShape(): Invalid View" );
158 ENSURE_OR_THROW( mpViewLayer
->getCanvas(), "ViewBackgroundShape::ViewBackgroundShape(): Invalid ViewLayer canvas" );
161 ViewLayerSharedPtr
ViewBackgroundShape::getViewLayer() const
166 bool ViewBackgroundShape::render( const GDIMetaFileSharedPtr
& rMtf
) const
168 RTL_LOGFILE_CONTEXT( aLog
, "::presentation::internal::ViewBackgroundShape::draw()" );
170 const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas( mpViewLayer
->getCanvas() );
172 if( !prefetch( rDestinationCanvas
, rMtf
) )
175 ENSURE_OR_RETURN( mxBitmap
.is(),
176 "ViewBackgroundShape::draw(): Invalid background bitmap" );
178 ::basegfx::B2DHomMatrix
aTransform( mpViewLayer
->getTransformation() );
180 // invert the linear part of the view transformation
181 // (i.e. the view transformation without translational
182 // components), to be able to leave the canvas
183 // transformation intact (would otherwise destroy possible
184 // clippings, as the clip polygon is relative to the view
185 // coordinate system).
186 aTransform
.set(0,2, 0.0 );
187 aTransform
.set(1,2, 0.0 );
190 rendering::RenderState aRenderState
;
191 ::canvas::tools::initRenderState( aRenderState
);
193 ::canvas::tools::setRenderStateTransform( aRenderState
, aTransform
);
197 rDestinationCanvas
->getUNOCanvas()->drawBitmap( mxBitmap
,
198 rDestinationCanvas
->getViewState(),
201 catch( uno::Exception
& )
204 rtl::OUStringToOString(
205 comphelper::anyToString( cppu::getCaughtException() ),
206 RTL_TEXTENCODING_UTF8
).getStr() );