LCOV - code coverage report
Current view: top level - vcl/source/outdev - clipping.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 82 95 86.3 %
Date: 2015-06-13 12:38:46 Functions: 11 13 84.6 %
Legend: Lines: hit not hit

          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       27549 : vcl::Region OutputDevice::GetClipRegion() const
      35             : {
      36             : 
      37       27549 :     return PixelToLogic( maRegion );
      38             : }
      39             : 
      40       26107 : void OutputDevice::SetClipRegion()
      41             : {
      42             : 
      43       26107 :     if ( mpMetaFile )
      44         266 :         mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
      45             : 
      46       26107 :     SetDeviceClipRegion( NULL );
      47             : 
      48       26107 :     if( mpAlphaVDev )
      49          57 :         mpAlphaVDev->SetClipRegion();
      50       26107 : }
      51             : 
      52       52293 : void OutputDevice::SetClipRegion( const vcl::Region& rRegion )
      53             : {
      54             : 
      55       52293 :     if ( mpMetaFile )
      56       13226 :         mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
      57             : 
      58       52293 :     if ( rRegion.IsNull() )
      59             :     {
      60         371 :         SetDeviceClipRegion( NULL );
      61             :     }
      62             :     else
      63             :     {
      64       51922 :         vcl::Region aRegion = LogicToPixel( rRegion );
      65       51922 :         SetDeviceClipRegion( &aRegion );
      66             :     }
      67             : 
      68       52293 :     if( mpAlphaVDev )
      69       12991 :         mpAlphaVDev->SetClipRegion( rRegion );
      70       52293 : }
      71             : 
      72      513440 : bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
      73             : {
      74             :     DBG_TESTSOLARMUTEX();
      75             : 
      76      513440 :     if( !pGraphics )
      77             :     {
      78      513129 :         if( !mpGraphics )
      79           0 :             if( !AcquireGraphics() )
      80           0 :                 return false;
      81      513129 :         pGraphics = mpGraphics;
      82             :     }
      83             : 
      84      513440 :     bool bClipRegion = pGraphics->SetClipRegion( rRegion, this );
      85             :     OSL_ENSURE( bClipRegion, "OutputDevice::SelectClipRegion() - can't create region" );
      86      513440 :     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      174986 : void OutputDevice::IntersectClipRegion( const Rectangle& rRect )
     107             : {
     108             : 
     109      174986 :     if ( mpMetaFile )
     110        6257 :         mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) );
     111             : 
     112      174986 :     Rectangle aRect = LogicToPixel( rRect );
     113      174986 :     maRegion.Intersect( aRect );
     114      174986 :     mbClipRegion        = true;
     115      174986 :     mbInitClipRegion    = true;
     116             : 
     117      174986 :     if( mpAlphaVDev )
     118        1766 :         mpAlphaVDev->IntersectClipRegion( rRect );
     119      174986 : }
     120             : 
     121      129458 : void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion )
     122             : {
     123             : 
     124      129458 :     if(!rRegion.IsNull())
     125             :     {
     126      129458 :         if ( mpMetaFile )
     127        1908 :             mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) );
     128             : 
     129      129458 :         vcl::Region aRegion = LogicToPixel( rRegion );
     130      129458 :         maRegion.Intersect( aRegion );
     131      129458 :         mbClipRegion        = true;
     132      129458 :         mbInitClipRegion    = true;
     133             :     }
     134             : 
     135      129458 :     if( mpAlphaVDev )
     136         700 :         mpAlphaVDev->IntersectClipRegion( rRegion );
     137      129458 : }
     138             : 
     139      226080 : void OutputDevice::InitClipRegion()
     140             : {
     141             :     DBG_TESTSOLARMUTEX();
     142             : 
     143      226080 :     if ( mbClipRegion )
     144             :     {
     145       41066 :         if ( maRegion.IsEmpty() )
     146         360 :             mbOutputClipped = true;
     147             :         else
     148             :         {
     149       40706 :             mbOutputClipped = false;
     150             : 
     151             :             // #102532# Respect output offset also for clip region
     152       40706 :             vcl::Region aRegion( ImplPixelToDevicePixel( maRegion ) );
     153       40706 :             const bool bClipDeviceBounds( ! GetPDFWriter()
     154       40706 :                                           && GetOutDevType() != OUTDEV_PRINTER );
     155       40706 :             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       40706 :                                          mnOutOffX+GetOutputWidthPixel()-1,
     162       81412 :                                          mnOutOffY+GetOutputHeightPixel()-1 );
     163       40706 :                 aRegion.Intersect( aDeviceBounds );
     164             :             }
     165             : 
     166       40706 :             if ( aRegion.IsEmpty() )
     167             :             {
     168          15 :                 mbOutputClipped = true;
     169             :             }
     170             :             else
     171             :             {
     172       40691 :                 mbOutputClipped = false;
     173       40691 :                 SelectClipRegion( aRegion );
     174       40706 :             }
     175             :         }
     176             : 
     177       41066 :         mbClipRegionSet = true;
     178             :     }
     179             :     else
     180             :     {
     181      185014 :         if ( mbClipRegionSet )
     182             :         {
     183        7019 :             mpGraphics->ResetClipRegion();
     184        7019 :             mbClipRegionSet = false;
     185             :         }
     186             : 
     187      185014 :         mbOutputClipped = false;
     188             :     }
     189             : 
     190      226080 :     mbInitClipRegion = false;
     191      226080 : }
     192             : 
     193           0 : vcl::Region OutputDevice::GetActiveClipRegion() const
     194             : {
     195           0 :     return GetClipRegion();
     196             : }
     197             : 
     198      125509 : 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      125509 : }
     203             : 
     204      453790 : void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion )
     205             : {
     206             :     DBG_TESTSOLARMUTEX();
     207             : 
     208      453790 :     if ( !pRegion )
     209             :     {
     210      235604 :         if ( mbClipRegion )
     211             :         {
     212      191001 :             maRegion            = vcl::Region(true);
     213      191001 :             mbClipRegion        = false;
     214      191001 :             mbInitClipRegion    = true;
     215             :         }
     216             :     }
     217             :     else
     218             :     {
     219      218186 :         maRegion            = *pRegion;
     220      218186 :         mbClipRegion        = true;
     221      218186 :         mbInitClipRegion    = true;
     222             :     }
     223      454591 : }
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11