fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / viewbackgroundshape.cxx
blobcdef389d59cead2ae998d3f3e09b531037d97c05
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 // must be first
22 #include <canvas/debug.hxx>
23 #include <tools/diagnose_ex.h>
25 #include "viewbackgroundshape.hxx"
26 #include "tools.hxx"
28 #include <rtl/math.hxx>
30 #include <comphelper/anytostring.hxx>
31 #include <cppuhelper/exc_hlp.hxx>
33 #include <basegfx/polygon/b2dpolygontools.hxx>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/numeric/ftools.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/matrix/b2dhommatrixtools.hxx>
39 #include <com/sun/star/rendering/XCanvas.hpp>
41 #include <canvas/verbosetrace.hxx>
42 #include <canvas/canvastools.hxx>
43 #include <cppcanvas/vclfactory.hxx>
44 #include <cppcanvas/basegfxfactory.hxx>
45 #include <cppcanvas/renderer.hxx>
46 #include <cppcanvas/bitmap.hxx>
48 using namespace ::com::sun::star;
51 namespace slideshow
53 namespace internal
56 bool ViewBackgroundShape::prefetch( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
57 const GDIMetaFileSharedPtr& rMtf ) const
59 SAL_INFO( "slideshow", "::presentation::internal::ViewBackgroundShape::prefetch()" );
60 ENSURE_OR_RETURN_FALSE( rMtf,
61 "ViewBackgroundShape::prefetch(): no valid metafile!" );
63 const ::basegfx::B2DHomMatrix& rCanvasTransform(
64 mpViewLayer->getTransformation() );
66 if( !mxBitmap.is() ||
67 rMtf != mpLastMtf ||
68 rCanvasTransform != maLastTransformation )
70 // buffered bitmap is invalid, re-create
72 // determine transformed page bounds
73 ::basegfx::B2DRectangle aTmpRect;
74 ::canvas::tools::calcTransformedRectBounds( aTmpRect,
75 maBounds,
76 rCanvasTransform );
78 // determine pixel size of bitmap (choose it one pixel
79 // larger, as polygon rendering takes one pixel more
80 // to the right and to the bottom)
81 const ::basegfx::B2ISize aBmpSizePixel(
82 ::basegfx::fround( aTmpRect.getRange().getX() + 1),
83 ::basegfx::fround( aTmpRect.getRange().getY() + 1) );
85 // create a bitmap of appropriate size
86 ::cppcanvas::BitmapSharedPtr pBitmap(
87 ::cppcanvas::BaseGfxFactory::createBitmap(
88 rDestinationCanvas,
89 aBmpSizePixel ) );
91 ENSURE_OR_THROW( pBitmap,
92 "ViewBackgroundShape::prefetch(): Cannot create background bitmap" );
94 ::cppcanvas::BitmapCanvasSharedPtr pBitmapCanvas( pBitmap->getBitmapCanvas() );
96 ENSURE_OR_THROW( pBitmapCanvas,
97 "ViewBackgroundShape::prefetch(): Cannot create background bitmap canvas" );
99 // clear bitmap
100 initSlideBackground( pBitmapCanvas,
101 aBmpSizePixel );
103 // apply linear part of destination canvas transformation (linear means in this context:
104 // transformation without any translational components)
105 ::basegfx::B2DHomMatrix aLinearTransform( rCanvasTransform );
106 aLinearTransform.set( 0, 2, 0.0 );
107 aLinearTransform.set( 1, 2, 0.0 );
108 pBitmapCanvas->setTransformation( aLinearTransform );
110 const basegfx::B2DHomMatrix aShapeTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(
111 maBounds.getWidth(), maBounds.getHeight(),
112 maBounds.getMinX(), maBounds.getMinY()));
114 ::cppcanvas::RendererSharedPtr pRenderer(
115 ::cppcanvas::VCLFactory::createRenderer(
116 pBitmapCanvas,
117 *rMtf.get(),
118 ::cppcanvas::Renderer::Parameters() ) );
120 ENSURE_OR_RETURN_FALSE( pRenderer,
121 "ViewBackgroundShape::prefetch(): Could not create Renderer" );
123 pRenderer->setTransformation( aShapeTransform );
124 pRenderer->draw();
126 mxBitmap = pBitmap->getUNOBitmap();
129 mpLastMtf = rMtf;
130 maLastTransformation = rCanvasTransform;
132 return mxBitmap.is();
135 ViewBackgroundShape::ViewBackgroundShape( const ViewLayerSharedPtr& rViewLayer,
136 const ::basegfx::B2DRectangle& rShapeBounds ) :
137 mpViewLayer( rViewLayer ),
138 mxBitmap(),
139 mpLastMtf(),
140 maLastTransformation(),
141 maBounds( rShapeBounds )
143 ENSURE_OR_THROW( mpViewLayer, "ViewBackgroundShape::ViewBackgroundShape(): Invalid View" );
144 ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewBackgroundShape::ViewBackgroundShape(): Invalid ViewLayer canvas" );
147 ViewLayerSharedPtr ViewBackgroundShape::getViewLayer() const
149 return mpViewLayer;
152 bool ViewBackgroundShape::render( const GDIMetaFileSharedPtr& rMtf ) const
154 SAL_INFO( "slideshow", "::presentation::internal::ViewBackgroundShape::draw()" );
156 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas( mpViewLayer->getCanvas() );
158 if( !prefetch( rDestinationCanvas, rMtf ) )
159 return false;
161 ENSURE_OR_RETURN_FALSE( mxBitmap.is(),
162 "ViewBackgroundShape::draw(): Invalid background bitmap" );
164 ::basegfx::B2DHomMatrix aTransform( mpViewLayer->getTransformation() );
166 // invert the linear part of the view transformation
167 // (i.e. the view transformation without translational
168 // components), to be able to leave the canvas
169 // transformation intact (would otherwise destroy possible
170 // clippings, as the clip polygon is relative to the view
171 // coordinate system).
172 aTransform.set(0,2, 0.0 );
173 aTransform.set(1,2, 0.0 );
174 aTransform.invert();
176 rendering::RenderState aRenderState;
177 ::canvas::tools::initRenderState( aRenderState );
179 ::canvas::tools::setRenderStateTransform( aRenderState, aTransform );
183 rDestinationCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
184 rDestinationCanvas->getViewState(),
185 aRenderState );
187 catch( uno::Exception& )
189 OSL_FAIL( OUStringToOString(
190 comphelper::anyToString( cppu::getCaughtException() ),
191 RTL_TEXTENCODING_UTF8 ).getStr() );
193 return false;
196 return true;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */