/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 | 219 | { |
37 | | |
38 | 219 | return PixelToLogic( maRegion ); |
39 | 219 | } |
40 | | |
41 | | void OutputDevice::SetClipRegion() |
42 | 29.8k | { |
43 | | |
44 | 29.8k | if ( mpMetaFile ) |
45 | 22.9k | mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) ); |
46 | | |
47 | 29.8k | SetDeviceClipRegion( nullptr ); |
48 | 29.8k | } |
49 | | |
50 | | void OutputDevice::SetClipRegion( const vcl::Region& rRegion ) |
51 | 17.7k | { |
52 | | |
53 | 17.7k | if ( mpMetaFile ) |
54 | 13.6k | mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) ); |
55 | | |
56 | 17.7k | if ( rRegion.IsNull() ) |
57 | 964 | { |
58 | 964 | SetDeviceClipRegion( nullptr ); |
59 | 964 | } |
60 | 16.7k | else |
61 | 16.7k | { |
62 | 16.7k | vcl::Region aRegion = LogicToPixel( rRegion ); |
63 | 16.7k | SetDeviceClipRegion( &aRegion ); |
64 | 16.7k | } |
65 | 17.7k | } |
66 | | |
67 | | bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics ) |
68 | 17.2k | { |
69 | 17.2k | DBG_TESTSOLARMUTEX(); |
70 | | |
71 | 17.2k | if( !pGraphics ) |
72 | 17.2k | { |
73 | 17.2k | if( !mpGraphics && !AcquireGraphics() ) |
74 | 0 | return false; |
75 | 17.2k | assert(mpGraphics); |
76 | 17.2k | pGraphics = mpGraphics; |
77 | 17.2k | } |
78 | | |
79 | 17.2k | pGraphics->SetClipRegion( rRegion, *this ); |
80 | 17.2k | return true; |
81 | 17.2k | } |
82 | | |
83 | | void OutputDevice::MoveClipRegion( tools::Long nHorzMove, tools::Long nVertMove ) |
84 | 10.7k | { |
85 | 10.7k | if ( mbClipRegion ) |
86 | 4.01k | { |
87 | 4.01k | if( mpMetaFile ) |
88 | 0 | mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) ); |
89 | | |
90 | 4.01k | maRegion.Move( ImplLogicWidthToDevicePixel( nHorzMove ), |
91 | 4.01k | ImplLogicHeightToDevicePixel( nVertMove ) ); |
92 | 4.01k | mbInitClipRegion = true; |
93 | 4.01k | } |
94 | 10.7k | } |
95 | | |
96 | | void OutputDevice::IntersectClipRegion( const tools::Rectangle& rRect ) |
97 | 51.3k | { |
98 | 51.3k | if ( mpMetaFile ) |
99 | 13.5k | mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) ); |
100 | | |
101 | 51.3k | tools::Rectangle aRect = LogicToPixel( rRect ); |
102 | 51.3k | maRegion.Intersect( aRect ); |
103 | 51.3k | mbClipRegion = true; |
104 | 51.3k | mbInitClipRegion = true; |
105 | 51.3k | } |
106 | | |
107 | | void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion ) |
108 | 165k | { |
109 | 165k | if(!rRegion.IsNull()) |
110 | 160k | { |
111 | 160k | if ( mpMetaFile ) |
112 | 157k | mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) ); |
113 | | |
114 | 160k | vcl::Region aRegion = LogicToPixel( rRegion ); |
115 | 160k | maRegion.Intersect( aRegion ); |
116 | 160k | mbClipRegion = true; |
117 | 160k | mbInitClipRegion = true; |
118 | 160k | } |
119 | 165k | } |
120 | | |
121 | | void OutputDevice::InitClipRegion() |
122 | 71.7k | { |
123 | 71.7k | DBG_TESTSOLARMUTEX(); |
124 | | |
125 | 71.7k | if ( mbClipRegion ) |
126 | 40.2k | { |
127 | 40.2k | if ( maRegion.IsEmpty() ) |
128 | 3.37k | mbOutputClipped = true; |
129 | 36.8k | else |
130 | 36.8k | { |
131 | 36.8k | mbOutputClipped = false; |
132 | | |
133 | | // #102532# Respect output offset also for clip region |
134 | 36.8k | vcl::Region aRegion = ClipToDeviceBounds(ImplPixelToDevicePixel(maRegion)); |
135 | | |
136 | 36.8k | if ( aRegion.IsEmpty() ) |
137 | 19.6k | { |
138 | 19.6k | mbOutputClipped = true; |
139 | 19.6k | } |
140 | 17.2k | else |
141 | 17.2k | { |
142 | 17.2k | mbOutputClipped = false; |
143 | 17.2k | SelectClipRegion( aRegion ); |
144 | 17.2k | } |
145 | 36.8k | } |
146 | | |
147 | 40.2k | mbClipRegionSet = true; |
148 | 40.2k | } |
149 | 31.5k | else |
150 | 31.5k | { |
151 | 31.5k | if ( mbClipRegionSet ) |
152 | 10.1k | { |
153 | 10.1k | if (mpGraphics) |
154 | 10.1k | mpGraphics->ResetClipRegion(); |
155 | 10.1k | mbClipRegionSet = false; |
156 | 10.1k | } |
157 | | |
158 | 31.5k | mbOutputClipped = false; |
159 | 31.5k | } |
160 | | |
161 | 71.7k | mbInitClipRegion = false; |
162 | 71.7k | } |
163 | | |
164 | | vcl::Region OutputDevice::ClipToDeviceBounds(vcl::Region aRegion) const |
165 | 36.8k | { |
166 | 36.8k | aRegion.Intersect(tools::Rectangle{mnOutOffX, |
167 | 36.8k | mnOutOffY, |
168 | 36.8k | mnOutOffX + GetOutputWidthPixel() - 1, |
169 | 36.8k | mnOutOffY + GetOutputHeightPixel() - 1 |
170 | 36.8k | }); |
171 | 36.8k | return aRegion; |
172 | 36.8k | } |
173 | | |
174 | | vcl::Region OutputDevice::GetActiveClipRegion() const |
175 | 0 | { |
176 | 0 | return GetClipRegion(); |
177 | 0 | } |
178 | | |
179 | | void OutputDevice::ClipToPaintRegion(tools::Rectangle& /*rDstRect*/) |
180 | 561 | { |
181 | | // this is only used in Window, but we still need it as it's called |
182 | | // on in other clipping functions |
183 | 561 | } |
184 | | |
185 | | void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion ) |
186 | 866k | { |
187 | 866k | DBG_TESTSOLARMUTEX(); |
188 | | |
189 | 866k | if ( !pRegion ) |
190 | 841k | { |
191 | 841k | if ( mbClipRegion ) |
192 | 184k | { |
193 | 184k | maRegion = vcl::Region(true); |
194 | 184k | mbClipRegion = false; |
195 | 184k | mbInitClipRegion = true; |
196 | 184k | } |
197 | 841k | } |
198 | 24.2k | else |
199 | 24.2k | { |
200 | 24.2k | maRegion = *pRegion; |
201 | 24.2k | mbClipRegion = true; |
202 | 24.2k | mbInitClipRegion = true; |
203 | 24.2k | } |
204 | 866k | } |
205 | | |
206 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |