LibreOffice Module cppcanvas (master) 1
bitmapaction.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#include <com/sun/star/rendering/XBitmap.hpp>
22#include <com/sun/star/rendering/XCanvas.hpp>
23#include <com/sun/star/rendering/XCachedPrimitive.hpp>
24#include <vcl/bitmapex.hxx>
25#include <tools/gen.hxx>
26#include <vcl/canvastools.hxx>
31#include <sal/log.hxx>
33#include "bitmapaction.hxx"
34#include <outdevstate.hxx>
35#include "mtftools.hxx"
37
38
39using namespace ::com::sun::star;
40
41namespace cppcanvas::internal
42{
43 namespace
44 {
45
46 class BitmapAction : public CachedPrimitiveBase
47 {
48 public:
49 BitmapAction( const ::BitmapEx&,
50 const ::basegfx::B2DPoint& rDstPoint,
51 const CanvasSharedPtr&,
52 const OutDevState& );
53 BitmapAction( const ::BitmapEx&,
54 const ::basegfx::B2DPoint& rDstPoint,
55 const ::basegfx::B2DVector& rDstSize,
56 const CanvasSharedPtr&,
57 const OutDevState& );
58
59 virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
60 const Subset& rSubset ) const override;
61
62 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const override;
63 virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
64 const Subset& rSubset ) const override;
65
66 virtual sal_Int32 getActionCount() const override;
67
68 private:
69 using Action::render;
70 virtual bool renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
71 const ::basegfx::B2DHomMatrix& rTransformation ) const override;
72
73 uno::Reference< rendering::XBitmap > mxBitmap;
75 rendering::RenderState maState;
76 };
77
78
79 BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx,
80 const ::basegfx::B2DPoint& rDstPoint,
81 const CanvasSharedPtr& rCanvas,
82 const OutDevState& rState ) :
83 CachedPrimitiveBase( rCanvas, true ),
85 mpCanvas( rCanvas )
86 {
88
89 // Setup transformation such that the next render call is
90 // moved rPoint away.
91 const basegfx::B2DHomMatrix aLocalTransformation(basegfx::utils::createTranslateB2DHomMatrix(rDstPoint));
92 ::canvas::tools::appendToRenderState( maState,
93 aLocalTransformation );
94
95 // correct clip (which is relative to original transform)
97 rState,
98 rCanvas,
99 rDstPoint,
100 nullptr,
101 nullptr );
102 }
103
104 BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx,
105 const ::basegfx::B2DPoint& rDstPoint,
106 const ::basegfx::B2DVector& rDstSize,
107 const CanvasSharedPtr& rCanvas,
108 const OutDevState& rState ) :
109 CachedPrimitiveBase( rCanvas, true ),
111 mpCanvas( rCanvas )
112 {
114
115 // Setup transformation such that the next render call is
116 // moved rPoint away, and scaled according to the ratio
117 // given by src and dst size.
118 const ::Size aBmpSize( rBmpEx.GetSizePixel() );
119
120 const ::basegfx::B2DVector aScale( rDstSize.getX() / aBmpSize.Width(),
121 rDstSize.getY() / aBmpSize.Height() );
123 aScale, rDstPoint));
124 ::canvas::tools::appendToRenderState( maState, aLocalTransformation );
125
126 // correct clip (which is relative to original transform)
128 rState,
129 rCanvas,
130 rDstPoint,
131 &aScale,
132 nullptr );
133 }
134
135 bool BitmapAction::renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive,
136 const ::basegfx::B2DHomMatrix& rTransformation ) const
137 {
138 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction::renderPrimitive()" );
139 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::BitmapAction: 0x" << std::hex << this );
140
141 rendering::RenderState aLocalState( maState );
142 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
143
144 rCachedPrimitive = mpCanvas->getUNOCanvas()->drawBitmap( mxBitmap,
145 mpCanvas->getViewState(),
146 aLocalState );
147
148 return true;
149 }
150
151 bool BitmapAction::renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
152 const Subset& rSubset ) const
153 {
154 // bitmap only contains a single action, fail if subset
155 // requests different range
156 if( rSubset.mnSubsetBegin != 0 ||
157 rSubset.mnSubsetEnd != 1 )
158 return false;
159
160 return CachedPrimitiveBase::render( rTransformation );
161 }
162
163 ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const
164 {
165 rendering::RenderState aLocalState( maState );
166 ::canvas::tools::prependToRenderState(aLocalState, rTransformation);
167
168 const geometry::IntegerSize2D aSize( mxBitmap->getSize() );
169
171 aSize.Width,
172 aSize.Height ),
173 mpCanvas->getViewState(),
174 aLocalState );
175 }
176
177 ::basegfx::B2DRange BitmapAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
178 const Subset& rSubset ) const
179 {
180 // bitmap only contains a single action, empty bounds
181 // if subset requests different range
182 if( rSubset.mnSubsetBegin != 0 ||
183 rSubset.mnSubsetEnd != 1 )
184 return ::basegfx::B2DRange();
185
186 return getBounds( rTransformation );
187 }
188
189 sal_Int32 BitmapAction::getActionCount() const
190 {
191 return 1;
192 }
193 }
194
195 std::shared_ptr<Action> BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
196 const ::basegfx::B2DPoint& rDstPoint,
197 const CanvasSharedPtr& rCanvas,
198 const OutDevState& rState )
199 {
200 return std::make_shared<BitmapAction>(rBmpEx, rDstPoint, rCanvas, rState );
201 }
202
203 std::shared_ptr<Action> BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx,
204 const ::basegfx::B2DPoint& rDstPoint,
205 const ::basegfx::B2DVector& rDstSize,
206 const CanvasSharedPtr& rCanvas,
207 const OutDevState& rState )
208 {
209 return std::make_shared<BitmapAction>(rBmpEx,
210 rDstPoint,
211 rDstSize,
212 rCanvas,
213 rState );
214 }
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< rendering::XBitmap > mxBitmap
rendering::RenderState maState
CanvasSharedPtr mpCanvas
virtual bool render(const ::basegfx::B2DHomMatrix &rTransformation) const =0
Render this action to the associated canvas.
#define SAL_INFO(area, stream)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
std::shared_ptr< Action > createBitmapAction(const ::BitmapEx &, const ::basegfx::B2DPoint &rDstPoint, const CanvasSharedPtr &, const OutDevState &)
Unscaled bitmap action, only references destination point.
bool modifyClip(rendering::RenderState &o_rRenderState, const struct ::cppcanvas::internal::OutDevState &rOutdevState, const CanvasSharedPtr &rCanvas, const ::basegfx::B2DPoint &rOffset, const ::basegfx::B2DVector *pScaling, const double *pRotation)
Definition: mtftools.cxx:112
void initRenderState(rendering::RenderState &renderState, const ::cppcanvas::internal::OutDevState &outdevState)
Definition: mtftools.cxx:42
::basegfx::B2DRange calcDevicePixelBounds(const ::basegfx::B2DRange &rBounds, const rendering::ViewState &viewState, const rendering::RenderState &renderState)
Definition: mtftools.cxx:628
std::shared_ptr< Canvas > CanvasSharedPtr
uno::Reference< rendering::XBitmap > xBitmapFromBitmapEx(const ::BitmapEx &inputBitmap)