Coverage Report

Created: 2026-04-09 11:41

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