Line data Source code
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/virdev.hxx>
21 : #include <vcl/window.hxx>
22 : #include <vcl/gdimtf.hxx>
23 : #include <vcl/print.hxx>
24 : #include <vcl/outdev.hxx>
25 :
26 : #include <salgdi.hxx>
27 : #include <salframe.hxx>
28 : #include <salvd.hxx>
29 : #include <salprn.hxx>
30 : #include <window.h>
31 :
32 : #include <numeric>
33 :
34 53109 : vcl::Region OutputDevice::GetClipRegion() const
35 : {
36 :
37 53109 : return PixelToLogic( maRegion );
38 : }
39 :
40 45842 : void OutputDevice::SetClipRegion()
41 : {
42 :
43 45842 : if ( mpMetaFile )
44 345 : mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
45 :
46 45842 : SetDeviceClipRegion( NULL );
47 :
48 45842 : if( mpAlphaVDev )
49 21 : mpAlphaVDev->SetClipRegion();
50 45842 : }
51 :
52 63824 : void OutputDevice::SetClipRegion( const vcl::Region& rRegion )
53 : {
54 :
55 63824 : if ( mpMetaFile )
56 7113 : mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
57 :
58 63824 : if ( rRegion.IsNull() )
59 : {
60 3685 : SetDeviceClipRegion( NULL );
61 : }
62 : else
63 : {
64 60139 : vcl::Region aRegion = LogicToPixel( rRegion );
65 60139 : SetDeviceClipRegion( &aRegion );
66 : }
67 :
68 63824 : if( mpAlphaVDev )
69 6671 : mpAlphaVDev->SetClipRegion( rRegion );
70 63824 : }
71 :
72 1005100 : bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
73 : {
74 : DBG_TESTSOLARMUTEX();
75 :
76 1005100 : if( !pGraphics )
77 : {
78 1003503 : if( !mpGraphics )
79 0 : if( !AcquireGraphics() )
80 0 : return false;
81 1003503 : pGraphics = mpGraphics;
82 : }
83 :
84 1005100 : bool bClipRegion = pGraphics->SetClipRegion( rRegion, this );
85 : OSL_ENSURE( bClipRegion, "OutputDevice::SelectClipRegion() - can't create region" );
86 1005100 : return bClipRegion;
87 : }
88 :
89 0 : void OutputDevice::MoveClipRegion( long nHorzMove, long nVertMove )
90 : {
91 :
92 0 : if ( mbClipRegion )
93 : {
94 0 : if( mpMetaFile )
95 0 : mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) );
96 :
97 : maRegion.Move( ImplLogicWidthToDevicePixel( nHorzMove ),
98 0 : ImplLogicHeightToDevicePixel( nVertMove ) );
99 0 : mbInitClipRegion = true;
100 : }
101 :
102 0 : if( mpAlphaVDev )
103 0 : mpAlphaVDev->MoveClipRegion( nHorzMove, nVertMove );
104 0 : }
105 :
106 300826 : void OutputDevice::IntersectClipRegion( const Rectangle& rRect )
107 : {
108 :
109 300826 : if ( mpMetaFile )
110 10582 : mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) );
111 :
112 300826 : Rectangle aRect = LogicToPixel( rRect );
113 300826 : maRegion.Intersect( aRect );
114 300826 : mbClipRegion = true;
115 300826 : mbInitClipRegion = true;
116 :
117 300826 : if( mpAlphaVDev )
118 1045 : mpAlphaVDev->IntersectClipRegion( rRect );
119 300826 : }
120 :
121 274141 : void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion )
122 : {
123 :
124 274141 : if(!rRegion.IsNull())
125 : {
126 274141 : if ( mpMetaFile )
127 2398 : mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) );
128 :
129 274141 : vcl::Region aRegion = LogicToPixel( rRegion );
130 274141 : maRegion.Intersect( aRegion );
131 274141 : mbClipRegion = true;
132 274141 : mbInitClipRegion = true;
133 : }
134 :
135 274141 : if( mpAlphaVDev )
136 264 : mpAlphaVDev->IntersectClipRegion( rRegion );
137 274141 : }
138 :
139 267816 : void OutputDevice::InitClipRegion()
140 : {
141 : DBG_TESTSOLARMUTEX();
142 :
143 267816 : if ( mbClipRegion )
144 : {
145 29077 : if ( maRegion.IsEmpty() )
146 85 : mbOutputClipped = true;
147 : else
148 : {
149 28992 : mbOutputClipped = false;
150 :
151 : // #102532# Respect output offset also for clip region
152 28992 : vcl::Region aRegion( ImplPixelToDevicePixel( maRegion ) );
153 28992 : const bool bClipDeviceBounds( ! GetPDFWriter()
154 28992 : && GetOutDevType() != OUTDEV_PRINTER );
155 28992 : if( bClipDeviceBounds )
156 : {
157 : // Perform actual rect clip against outdev
158 : // dimensions, to generate empty clips whenever one of the
159 : // values is completely off the device.
160 : Rectangle aDeviceBounds( mnOutOffX, mnOutOffY,
161 28992 : mnOutOffX+GetOutputWidthPixel()-1,
162 57984 : mnOutOffY+GetOutputHeightPixel()-1 );
163 28992 : aRegion.Intersect( aDeviceBounds );
164 : }
165 :
166 28992 : if ( aRegion.IsEmpty() )
167 : {
168 64 : mbOutputClipped = true;
169 : }
170 : else
171 : {
172 28928 : mbOutputClipped = false;
173 28928 : SelectClipRegion( aRegion );
174 28992 : }
175 : }
176 :
177 29077 : mbClipRegionSet = true;
178 : }
179 : else
180 : {
181 238739 : if ( mbClipRegionSet )
182 : {
183 9254 : mpGraphics->ResetClipRegion();
184 9254 : mbClipRegionSet = false;
185 : }
186 :
187 238739 : mbOutputClipped = false;
188 : }
189 :
190 267816 : mbInitClipRegion = false;
191 267816 : }
192 :
193 0 : vcl::Region OutputDevice::GetActiveClipRegion() const
194 : {
195 0 : return GetClipRegion();
196 : }
197 :
198 123832 : void OutputDevice::ClipToPaintRegion(Rectangle& /*rDstRect*/)
199 : {
200 : // this is only used in Window, but we still need it as it's called
201 : // on in other clipping functions
202 123832 : }
203 :
204 726543 : void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion )
205 : {
206 : DBG_TESTSOLARMUTEX();
207 :
208 726543 : if ( !pRegion )
209 : {
210 399662 : if ( mbClipRegion )
211 : {
212 369819 : maRegion = vcl::Region(true);
213 369819 : mbClipRegion = false;
214 369819 : mbInitClipRegion = true;
215 : }
216 : }
217 : else
218 : {
219 326881 : maRegion = *pRegion;
220 326881 : mbClipRegion = true;
221 326881 : mbInitClipRegion = true;
222 : }
223 727776 : }
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|