Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/outdev/clipping.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 <sal/config.h>
21
#include <osl/diagnose.h>
22
#include <tools/debug.hxx>
23
24
#include <vcl/metaact.hxx>
25
#include <vcl/virdev.hxx>
26
27
#include <salgdi.hxx>
28
29
void OutputDevice::SaveBackground(VirtualDevice& rSaveDevice,
30
                                  const Point& rPos, const Size& rSize, const Size& rBackgroundSize) const
31
0
{
32
0
   rSaveDevice.DrawOutDev(Point(), rBackgroundSize, rPos, rSize, *this);
33
0
}
34
35
vcl::Region OutputDevice::GetClipRegion() const
36
452
{
37
38
452
    return PixelToLogic( maRegion );
39
452
}
40
41
void OutputDevice::SetClipRegion()
42
21.1k
{
43
44
21.1k
    if ( mpMetaFile )
45
16.9k
        mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
46
47
21.1k
    SetDeviceClipRegion( nullptr );
48
21.1k
}
49
50
void OutputDevice::SetClipRegion( const vcl::Region& rRegion )
51
15.6k
{
52
53
15.6k
    if ( mpMetaFile )
54
14.7k
        mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
55
56
15.6k
    if ( rRegion.IsNull() )
57
266
    {
58
266
        SetDeviceClipRegion( nullptr );
59
266
    }
60
15.3k
    else
61
15.3k
    {
62
15.3k
        vcl::Region aRegion = LogicToPixel( rRegion );
63
15.3k
        SetDeviceClipRegion( &aRegion );
64
15.3k
    }
65
15.6k
}
66
67
bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
68
10.8k
{
69
10.8k
    DBG_TESTSOLARMUTEX();
70
71
10.8k
    if( !pGraphics )
72
10.8k
    {
73
10.8k
        if( !mpGraphics && !AcquireGraphics() )
74
0
            return false;
75
10.8k
        assert(mpGraphics);
76
10.8k
        pGraphics = mpGraphics;
77
10.8k
    }
78
79
10.8k
    pGraphics->SetClipRegion( rRegion, *this );
80
10.8k
    return true;
81
10.8k
}
82
83
void OutputDevice::MoveClipRegion( tools::Long nHorzMove, tools::Long nVertMove )
84
7.01k
{
85
7.01k
    if ( mbClipRegion )
86
1.73k
    {
87
1.73k
        if( mpMetaFile )
88
0
            mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) );
89
90
1.73k
        maRegion.Move(LogicWidthToDevicePixel(nHorzMove),
91
1.73k
                      LogicHeightToDevicePixel(nVertMove));
92
1.73k
        mbInitClipRegion = true;
93
1.73k
    }
94
7.01k
}
95
96
void OutputDevice::IntersectClipRegion( const tools::Rectangle& rRect )
97
35.2k
{
98
35.2k
    if ( mpMetaFile )
99
15.6k
        mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) );
100
101
35.2k
    tools::Rectangle aRect = LogicToPixel( rRect );
102
35.2k
    maRegion.Intersect( aRect );
103
35.2k
    mbClipRegion        = true;
104
35.2k
    mbInitClipRegion    = true;
105
35.2k
}
106
107
void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion )
108
194k
{
109
194k
    if(!rRegion.IsNull())
110
190k
    {
111
190k
        if ( mpMetaFile )
112
188k
            mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) );
113
114
190k
        vcl::Region aRegion = LogicToPixel( rRegion );
115
190k
        maRegion.Intersect( aRegion );
116
190k
        mbClipRegion        = true;
117
190k
        mbInitClipRegion    = true;
118
190k
    }
119
194k
}
120
121
void OutputDevice::InitClipRegion()
122
42.0k
{
123
42.0k
    DBG_TESTSOLARMUTEX();
124
125
42.0k
    if ( mbClipRegion )
126
20.1k
    {
127
20.1k
        if ( maRegion.IsEmpty() )
128
1.06k
            mbOutputClipped = true;
129
19.0k
        else
130
19.0k
        {
131
19.0k
            mbOutputClipped = false;
132
133
            // #102532# Respect output offset also for clip region
134
19.0k
            vcl::Region aRegion = ClipToDeviceBounds(ImplPixelToDevicePixel(maRegion));
135
136
19.0k
            if ( aRegion.IsEmpty() )
137
8.26k
            {
138
8.26k
                mbOutputClipped = true;
139
8.26k
            }
140
10.8k
            else
141
10.8k
            {
142
10.8k
                mbOutputClipped = false;
143
10.8k
                SelectClipRegion( aRegion );
144
10.8k
            }
145
19.0k
        }
146
147
20.1k
        mbClipRegionSet = true;
148
20.1k
    }
149
21.9k
    else
150
21.9k
    {
151
21.9k
        if ( mbClipRegionSet )
152
6.71k
        {
153
6.71k
            if (mpGraphics)
154
6.71k
                mpGraphics->ResetClipRegion();
155
6.71k
            mbClipRegionSet = false;
156
6.71k
        }
157
158
21.9k
        mbOutputClipped = false;
159
21.9k
    }
160
161
42.0k
    mbInitClipRegion = false;
162
42.0k
}
163
164
vcl::Region OutputDevice::ClipToDeviceBounds(vcl::Region aRegion) const
165
19.0k
{
166
19.0k
    aRegion.Intersect(tools::Rectangle{GetDeviceOriginX(),
167
19.0k
                                       GetDeviceOriginY(),
168
19.0k
                                       GetDeviceOriginX() + GetOutputWidthPixel() - 1,
169
19.0k
                                       GetDeviceOriginY() + GetOutputHeightPixel() - 1
170
19.0k
                                      });
171
19.0k
    return aRegion;
172
19.0k
}
173
174
vcl::Region OutputDevice::GetActiveClipRegion() const
175
0
{
176
0
    return GetClipRegion();
177
0
}
178
179
void OutputDevice::ClipToPaintRegion(tools::Rectangle& /*rDstRect*/)
180
226
{
181
    // this is only used in Window, but we still need it as it's called
182
    // on in other clipping functions
183
226
}
184
185
void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion )
186
963k
{
187
963k
    DBG_TESTSOLARMUTEX();
188
189
963k
    if ( !pRegion )
190
944k
    {
191
944k
        if ( mbClipRegion )
192
205k
        {
193
205k
            maRegion            = vcl::Region(true);
194
205k
            mbClipRegion        = false;
195
205k
            mbInitClipRegion    = true;
196
205k
        }
197
944k
    }
198
19.1k
    else
199
19.1k
    {
200
19.1k
        maRegion            = *pRegion;
201
19.1k
        mbClipRegion        = true;
202
19.1k
        mbInitClipRegion    = true;
203
19.1k
    }
204
963k
}
205
206
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */