LibreOffice Module slideshow (master) 1
viewbackgroundshape.cxx
Go to the documentation of this file.
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// must be first
23#include <sal/log.hxx>
24
26#include <tools.hxx>
27
31
32#include <com/sun/star/rendering/XCanvas.hpp>
33
38#include <cppcanvas/bitmap.hxx>
39#include <utility>
40
41using namespace ::com::sun::star;
42
43
44namespace slideshow::internal
45{
46
47 bool ViewBackgroundShape::prefetch( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
48 const GDIMetaFileSharedPtr& rMtf ) const
49 {
50 SAL_INFO( "slideshow", "::presentation::internal::ViewBackgroundShape::prefetch()" );
52 "ViewBackgroundShape::prefetch(): no valid metafile!" );
53
54 const ::basegfx::B2DHomMatrix& rCanvasTransform(
55 mpViewLayer->getTransformation() );
56
57 if( !mxBitmap.is() ||
58 rMtf != mpLastMtf ||
59 rCanvasTransform != maLastTransformation )
60 {
61 // buffered bitmap is invalid, re-create
62
63 // determine transformed page bounds
65 ::canvas::tools::calcTransformedRectBounds( aTmpRect,
67 rCanvasTransform );
68
69 // determine pixel size of bitmap (choose it one pixel
70 // larger, as polygon rendering takes one pixel more
71 // to the right and to the bottom)
72 const ::basegfx::B2ISize aBmpSizePixel(
73 ::basegfx::fround( aTmpRect.getRange().getX() + 1),
74 ::basegfx::fround( aTmpRect.getRange().getY() + 1) );
75
76 // create a bitmap of appropriate size
79 rDestinationCanvas,
80 aBmpSizePixel ) );
81
82 ENSURE_OR_THROW( pBitmap,
83 "ViewBackgroundShape::prefetch(): Cannot create background bitmap" );
84
85 ::cppcanvas::BitmapCanvasSharedPtr pBitmapCanvas( pBitmap->getBitmapCanvas() );
86
87 ENSURE_OR_THROW( pBitmapCanvas,
88 "ViewBackgroundShape::prefetch(): Cannot create background bitmap canvas" );
89
90 // clear bitmap
91 initSlideBackground( pBitmapCanvas,
92 aBmpSizePixel );
93
94 // apply linear part of destination canvas transformation (linear means in this context:
95 // transformation without any translational components)
96 ::basegfx::B2DHomMatrix aLinearTransform( rCanvasTransform );
97 aLinearTransform.set( 0, 2, 0.0 );
98 aLinearTransform.set( 1, 2, 0.0 );
99 pBitmapCanvas->setTransformation( aLinearTransform );
100
104
107 pBitmapCanvas,
108 *rMtf,
110
111 ENSURE_OR_RETURN_FALSE( pRenderer,
112 "ViewBackgroundShape::prefetch(): Could not create Renderer" );
113
114 pRenderer->setTransformation( aShapeTransform );
115 pRenderer->draw();
116
117 mxBitmap = pBitmap->getUNOBitmap();
118 }
119
120 mpLastMtf = rMtf;
121 maLastTransformation = rCanvasTransform;
122
123 return mxBitmap.is();
124 }
125
127 const ::basegfx::B2DRectangle& rShapeBounds ) :
128 mpViewLayer(std::move( xViewLayer )),
129 mxBitmap(),
130 mpLastMtf(),
132 maBounds( rShapeBounds )
133 {
134 ENSURE_OR_THROW( mpViewLayer, "ViewBackgroundShape::ViewBackgroundShape(): Invalid View" );
135 ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewBackgroundShape::ViewBackgroundShape(): Invalid ViewLayer canvas" );
136 }
137
139 {
140 return mpViewLayer;
141 }
142
144 {
145 SAL_INFO( "slideshow", "::presentation::internal::ViewBackgroundShape::draw()" );
146
147 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas( mpViewLayer->getCanvas() );
148
149 if( !prefetch( rDestinationCanvas, rMtf ) )
150 return false;
151
153 "ViewBackgroundShape::draw(): Invalid background bitmap" );
154
155 ::basegfx::B2DHomMatrix aTransform( mpViewLayer->getTransformation() );
156
157 // invert the linear part of the view transformation
158 // (i.e. the view transformation without translational
159 // components), to be able to leave the canvas
160 // transformation intact (would otherwise destroy possible
161 // clippings, as the clip polygon is relative to the view
162 // coordinate system).
163 aTransform.set(0,2, 0.0 );
164 aTransform.set(1,2, 0.0 );
165 aTransform.invert();
166
167 rendering::RenderState aRenderState;
168 ::canvas::tools::initRenderState( aRenderState );
169
170 ::canvas::tools::setRenderStateTransform( aRenderState, aTransform );
171
172 try
173 {
174 rDestinationCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
175 rDestinationCanvas->getViewState(),
176 aRenderState );
177 }
178 catch( uno::Exception& )
179 {
180 TOOLS_WARN_EXCEPTION( "slideshow", "" );
181 return false;
182 }
183
184 return true;
185 }
186
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::basegfx::B2DRectangle maBounds
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
B2DVector getRange() const
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
TYPE getX() const
TYPE getY() const
static BitmapSharedPtr createBitmap(const CanvasSharedPtr &, const ::basegfx::B2ISize &rSize)
static RendererSharedPtr createRenderer(const CanvasSharedPtr &rCanvas, const ::GDIMetaFile &rMtf, const Renderer::Parameters &rParms)
ViewLayerSharedPtr mpViewLayer
The view layer this object is part of.
css::uno::Reference< css::rendering::XBitmap > mxBitmap
Generated content bitmap, already with correct output size.
mutable::basegfx::B2DHomMatrix maLastTransformation
The canvas, mpRenderer is associated with.
ViewBackgroundShape(ViewLayerSharedPtr xViewLayer, const ::basegfx::B2DRectangle &rShapeBounds)
Create a ViewBackgroundShape for the given View.
bool render(const GDIMetaFileSharedPtr &rMtf) const
const ViewLayerSharedPtr & getViewLayer() const
Query the associated view layer of this shape.
bool prefetch(const ::cppcanvas::CanvasSharedPtr &rDestinationCanvas, const GDIMetaFileSharedPtr &rMtf) const
Prefetch bitmap for given canvas.
GDIMetaFileSharedPtr mpLastMtf
The last metafile a render object was generated for.
VclPtr< VirtualDevice > mxBitmap
#define TOOLS_WARN_EXCEPTION(area, stream)
#define ENSURE_OR_RETURN_FALSE(c, m)
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
std::shared_ptr< ::cppcanvas::Renderer > RendererSharedPtr
std::shared_ptr< BitmapCanvas > BitmapCanvasSharedPtr
std::shared_ptr< ::cppcanvas::Bitmap > BitmapSharedPtr
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
Definition: viewlayer.hxx:168
std::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr
Definition: tools.hxx:63
void initSlideBackground(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2ISize &rSize)
Definition: tools.cxx:674
mutable::basegfx::B2DHomMatrix maLastTransformation