office-gobmx/vcl/source/outdev/clipping.cxx
Jan-Marek Glogowski e021901b6c tdf#128337 clip the metafile Gradient drawing
This basically reverts the patches for tdf#125670. Instead this
just checks the mpGraphics in InitClipRegion() before using it,
to prevent the crash from the tdf#125670 bug report.

Additionally it drops the early mbOutputClipped return, as the
output device doesn't matter for the metafile drawing and the
preview of the tdf#125670 bugdoc and the Impress full screen
view otherwise don't show the gradients.

This patch works for me in the following tested scenarios:
1. Bugdoc tdf#125670 doesn't crash
2. Bugdoc tdf#125670 draws gradients in Impress full screen
3. Correct thumbnail pictures for both bug documents

With all these side effects, I have no idea, if this is finally
the correct fix and doesn't break anything else...

Change-Id: I8c48210d4255e50339710fc14819d15686417c9c
Reviewed-on: https://gerrit.libreoffice.org/83722
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
2019-11-27 21:52:08 +01:00

226 lines
5.9 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <osl/diagnose.h>
#include <tools/debug.hxx>
#include <vcl/metaact.hxx>
#include <vcl/virdev.hxx>
#include <vcl/gdimtf.hxx>
#include <vcl/outdev.hxx>
#include <salgdi.hxx>
void OutputDevice::SaveBackground(VirtualDevice& rSaveDevice,
const Point& rPos, const Size& rSize, const Size& rBackgroundSize) const
{
rSaveDevice.DrawOutDev(Point(), rBackgroundSize, rPos, rSize, *this);
}
vcl::Region OutputDevice::GetClipRegion() const
{
return PixelToLogic( maRegion );
}
void OutputDevice::SetClipRegion()
{
if ( mpMetaFile )
mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
SetDeviceClipRegion( nullptr );
if( mpAlphaVDev )
mpAlphaVDev->SetClipRegion();
}
void OutputDevice::SetClipRegion( const vcl::Region& rRegion )
{
if ( mpMetaFile )
mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
if ( rRegion.IsNull() )
{
SetDeviceClipRegion( nullptr );
}
else
{
vcl::Region aRegion = LogicToPixel( rRegion );
SetDeviceClipRegion( &aRegion );
}
if( mpAlphaVDev )
mpAlphaVDev->SetClipRegion( rRegion );
}
bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
{
DBG_TESTSOLARMUTEX();
if( !pGraphics )
{
if( !mpGraphics && !AcquireGraphics() )
return false;
pGraphics = mpGraphics;
}
bool bClipRegion = pGraphics->SetClipRegion( rRegion, this );
OSL_ENSURE( bClipRegion, "OutputDevice::SelectClipRegion() - can't create region" );
return bClipRegion;
}
void OutputDevice::MoveClipRegion( long nHorzMove, long nVertMove )
{
if ( mbClipRegion )
{
if( mpMetaFile )
mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) );
maRegion.Move( ImplLogicWidthToDevicePixel( nHorzMove ),
ImplLogicHeightToDevicePixel( nVertMove ) );
mbInitClipRegion = true;
}
if( mpAlphaVDev )
mpAlphaVDev->MoveClipRegion( nHorzMove, nVertMove );
}
void OutputDevice::IntersectClipRegion( const tools::Rectangle& rRect )
{
if ( mpMetaFile )
mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) );
tools::Rectangle aRect = LogicToPixel( rRect );
maRegion.Intersect( aRect );
mbClipRegion = true;
mbInitClipRegion = true;
if( mpAlphaVDev )
mpAlphaVDev->IntersectClipRegion( rRect );
}
void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion )
{
if(!rRegion.IsNull())
{
if ( mpMetaFile )
mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) );
vcl::Region aRegion = LogicToPixel( rRegion );
maRegion.Intersect( aRegion );
mbClipRegion = true;
mbInitClipRegion = true;
}
if( mpAlphaVDev )
mpAlphaVDev->IntersectClipRegion( rRegion );
}
void OutputDevice::InitClipRegion()
{
DBG_TESTSOLARMUTEX();
if ( mbClipRegion )
{
if ( maRegion.IsEmpty() )
mbOutputClipped = true;
else
{
mbOutputClipped = false;
// #102532# Respect output offset also for clip region
vcl::Region aRegion = ClipToDeviceBounds(ImplPixelToDevicePixel(maRegion));
if ( aRegion.IsEmpty() )
{
mbOutputClipped = true;
}
else
{
mbOutputClipped = false;
SelectClipRegion( aRegion );
}
}
mbClipRegionSet = true;
}
else
{
if ( mbClipRegionSet )
{
if (mpGraphics)
mpGraphics->ResetClipRegion();
mbClipRegionSet = false;
}
mbOutputClipped = false;
}
mbInitClipRegion = false;
}
vcl::Region OutputDevice::ClipToDeviceBounds(vcl::Region aRegion) const
{
aRegion.Intersect(tools::Rectangle{mnOutOffX,
mnOutOffY,
mnOutOffX + GetOutputWidthPixel() - 1,
mnOutOffY + GetOutputHeightPixel() - 1
});
return aRegion;
}
vcl::Region OutputDevice::GetActiveClipRegion() const
{
return GetClipRegion();
}
void OutputDevice::ClipToPaintRegion(tools::Rectangle& /*rDstRect*/)
{
// this is only used in Window, but we still need it as it's called
// on in other clipping functions
}
void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion )
{
DBG_TESTSOLARMUTEX();
if ( !pRegion )
{
if ( mbClipRegion )
{
maRegion = vcl::Region(true);
mbClipRegion = false;
mbInitClipRegion = true;
}
}
else
{
maRegion = *pRegion;
mbClipRegion = true;
mbInitClipRegion = true;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */