Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/outdev/mask.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
#include <vcl/metaact.hxx>
21
#include <vcl/metaactiontypes.hxx>
22
#include <vcl/virdev.hxx>
23
24
#include <salgdi.hxx>
25
#include <salbmp.hxx>
26
27
#include <cassert>
28
29
void OutputDevice::DrawMask( const Point& rDestPt,
30
                             const Bitmap& rBitmap, const Color& rMaskColor )
31
874
{
32
874
    assert(!is_double_buffered_window());
33
34
874
    const Size aSizePix( rBitmap.GetSizePixel() );
35
874
    DrawMask( rDestPt, PixelToLogic( aSizePix ), Point(), aSizePix, rBitmap, rMaskColor, MetaActionType::MASK );
36
874
}
37
38
void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
39
                             const Bitmap& rBitmap, const Color& rMaskColor )
40
1.41k
{
41
1.41k
    assert(!is_double_buffered_window());
42
43
1.41k
    DrawMask( rDestPt, rDestSize, Point(), rBitmap.GetSizePixel(), rBitmap, rMaskColor, MetaActionType::MASKSCALE );
44
1.41k
}
45
46
void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
47
                             const Point& rSrcPtPixel, const Size& rSrcSizePixel,
48
                             const Bitmap& rBitmap, const Color& rMaskColor)
49
0
{
50
51
0
    assert(!is_double_buffered_window());
52
53
0
    DrawMask( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor, MetaActionType::MASKSCALEPART );
54
0
}
55
56
void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
57
                             const Point& rSrcPtPixel, const Size& rSrcSizePixel,
58
                             const Bitmap& rBitmap, const Color& rMaskColor,
59
                             const MetaActionType nAction )
60
4.12k
{
61
4.12k
    assert(!is_double_buffered_window());
62
63
4.12k
    if( ImplIsRecordLayout() )
64
0
        return;
65
66
4.12k
    if( RasterOp::Invert == meRasterOp )
67
174
    {
68
174
        DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
69
174
        return;
70
174
    }
71
72
3.95k
    if ( mpMetaFile )
73
0
    {
74
0
        switch( nAction )
75
0
        {
76
0
            case MetaActionType::MASK:
77
0
                mpMetaFile->AddAction( new MetaMaskAction( rDestPt,
78
0
                    rBitmap, rMaskColor ) );
79
0
            break;
80
81
0
            case MetaActionType::MASKSCALE:
82
0
                mpMetaFile->AddAction( new MetaMaskScaleAction( rDestPt,
83
0
                    rDestSize, rBitmap, rMaskColor ) );
84
0
            break;
85
86
0
            case MetaActionType::MASKSCALEPART:
87
0
                mpMetaFile->AddAction( new MetaMaskScalePartAction( rDestPt, rDestSize,
88
0
                    rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor ) );
89
0
            break;
90
91
0
            default: break;
92
0
        }
93
0
    }
94
95
3.95k
    if ( !IsDeviceOutputNecessary() )
96
0
        return;
97
98
3.95k
    if ( !mpGraphics && !AcquireGraphics() )
99
0
        return;
100
101
3.95k
    if ( mbInitClipRegion )
102
279
        InitClipRegion();
103
104
3.95k
    if ( mbOutputClipped )
105
229
        return;
106
107
3.72k
    DrawDeviceMask( rBitmap, rMaskColor, rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel );
108
109
3.72k
}
110
111
void OutputDevice::DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor,
112
                              const Point& rDestPt, const Size& rDestSize,
113
                              const Point& rSrcPtPixel, const Size& rSrcSizePixel )
114
3.72k
{
115
3.72k
    assert(!is_double_buffered_window());
116
117
3.72k
    const std::shared_ptr<SalBitmap>& xImpBmp = rMask.ImplGetSalBitmap();
118
3.72k
    if (xImpBmp)
119
3.72k
    {
120
3.72k
        SalTwoRect aPosAry(rSrcPtPixel.X(), rSrcPtPixel.Y(), rSrcSizePixel.Width(), rSrcSizePixel.Height(),
121
3.72k
                           ImplLogicXToDevicePixel(rDestPt.X()), ImplLogicYToDevicePixel(rDestPt.Y()),
122
3.72k
                           ImplLogicWidthToDevicePixel(rDestSize.Width()),
123
3.72k
                           ImplLogicHeightToDevicePixel(rDestSize.Height()));
124
125
        // we don't want to mirror via coordinates
126
3.72k
        const BmpMirrorFlags nMirrFlags = AdjustTwoRect( aPosAry, xImpBmp->GetSize() );
127
128
        // check if output is necessary
129
3.72k
        if( aPosAry.mnSrcWidth && aPosAry.mnSrcHeight && aPosAry.mnDestWidth && aPosAry.mnDestHeight )
130
1.50k
        {
131
132
1.50k
            if( nMirrFlags != BmpMirrorFlags::NONE )
133
0
            {
134
0
                Bitmap aTmp( rMask );
135
0
                aTmp.Mirror( nMirrFlags );
136
0
                mpGraphics->DrawMask( aPosAry, *aTmp.ImplGetSalBitmap(),
137
0
                                      rMaskColor, *this);
138
0
            }
139
1.50k
            else
140
1.50k
                mpGraphics->DrawMask( aPosAry, *xImpBmp, rMaskColor, *this );
141
142
1.50k
        }
143
3.72k
    }
144
3.72k
}
145
146
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */