Files
libreoffice/canvas/source/vcl/devicehelper.cxx

222 lines
7.6 KiB
C++
Raw Normal View History

/* -*- 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 <basegfx/tools/canvastools.hxx>
#include <basegfx/tools/unopolypolygon.hxx>
#include <canvas/canvastools.hxx>
#include <rtl/instance.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/canvastools.hxx>
Resolves: #i121504# Support for alpha channel in clipboard for all systems (cherry picked from commit ef3931ff410117e1237b3bef7bc090e8b83b9519) Conflicts: automation/source/server/statemnt.cxx basic/source/runtime/methods.cxx canvas/source/vcl/devicehelper.cxx canvas/source/vcl/spritedevicehelper.cxx drawinglayer/source/processor2d/vclhelperbufferdevice.cxx drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx drawinglayer/source/tools/converters.cxx dtrans/source/win32/dtobj/FmtFilter.cxx editeng/source/items/bulitem.cxx extensions/source/scanner/sanedlg.cxx external/gcc3_specific/makefile.mk filter/source/graphicfilter/eos2met/eos2met.cxx filter/source/graphicfilter/ios2met/ios2met.cxx filter/source/msfilter/msdffimp.cxx fpicker/source/office/iodlg.cxx framework/source/fwe/classes/addonsoptions.cxx framework/source/fwe/helper/actiontriggerhelper.cxx sc/source/filter/excel/xiescher.cxx sc/source/ui/docshell/docsh.cxx sc/source/ui/inc/viewfunc.hxx sd/source/ui/app/sdxfer.cxx sd/source/ui/unoidl/unopage.cxx sd/source/ui/view/sdview3.cxx sfx2/source/appl/fileobj.cxx sfx2/source/appl/linkmgr2.cxx sfx2/source/dialog/filedlghelper.cxx sfx2/source/dialog/intro.cxx sfx2/source/doc/docinf.cxx sot/inc/sot/formats.hxx sot/source/base/formats.cxx svtools/bmpmaker/bmpcore.cxx svtools/bmpmaker/bmpsum.cxx svtools/inc/svtools/transfer.hxx svtools/source/filter/filter.cxx svtools/source/filter/wmf/emfwr.cxx svtools/source/filter/wmf/enhwmf.cxx svtools/source/filter/wmf/winwmf.cxx svtools/source/filter/wmf/wmfwr.cxx svtools/source/graphic/graphic.cxx svtools/source/graphic/provider.cxx svtools/source/misc/transfer.cxx svx/inc/svx/xoutbmp.hxx svx/source/sdr/overlay/overlaymanagerbuffered.cxx svx/source/xoutdev/_xoutbmp.cxx sw/source/core/view/viewsh.cxx sw/source/filter/ww1/w1filter.cxx sw/source/filter/ww8/ww8par.hxx sw/source/ui/dochdl/swdtflvr.cxx toolkit/source/awt/vclxbitmap.cxx toolkit/source/helper/vclunohelper.cxx vcl/Library_vcl.mk vcl/Package_inc.mk vcl/aqua/source/dtrans/DataFlavorMapping.cxx vcl/aqua/source/dtrans/OSXTransferable.cxx vcl/aqua/source/dtrans/PictToBmpFlt.cxx vcl/aqua/source/dtrans/PictToBmpFlt.hxx vcl/inc/vcl/alpha.hxx vcl/inc/vcl/bitmap.hxx vcl/inc/vcl/bitmapex.hxx vcl/inc/vcl/pngwrite.hxx vcl/inc/vcl/salbtype.hxx vcl/inc/vcl/wall.hxx vcl/source/gdi/animate.cxx vcl/source/gdi/bitmap2.cxx vcl/source/gdi/bitmapex.cxx vcl/source/gdi/bmpconv.cxx vcl/source/gdi/cvtsvm.cxx vcl/source/gdi/impgraph.cxx vcl/source/gdi/impimagetree.cxx vcl/source/gdi/metaact.cxx vcl/source/gdi/wall.cxx Change-Id: I79938bc412c048c3d4e64f430f216e73bec16167
2013-01-10 16:28:40 +00:00
#include <vcl/dibtools.hxx>
#include "canvasbitmap.hxx"
#include "devicehelper.hxx"
#include "spritecanvas.hxx"
#include "spritecanvashelper.hxx"
using namespace ::com::sun::star;
namespace vclcanvas
{
DeviceHelper::DeviceHelper() :
mpOutDev()
{}
void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev )
{
mpOutDev = rOutDev;
}
geometry::RealSize2D DeviceHelper::getPhysicalResolution()
{
if( !mpOutDev )
return ::canvas::tools::createInfiniteSize2D(); // we're disposed
// Map a one-by-one millimeter box to pixel
OutputDevice& rOutDev = mpOutDev->getOutDev();
const MapMode aOldMapMode( rOutDev.GetMapMode() );
rOutDev.SetMapMode( MapMode(MAP_MM) );
const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
rOutDev.SetMapMode( aOldMapMode );
return vcl::unotools::size2DFromSize( aPixelSize );
}
geometry::RealSize2D DeviceHelper::getPhysicalSize()
{
if( !mpOutDev )
return ::canvas::tools::createInfiniteSize2D(); // we're disposed
// Map the pixel dimensions of the output window to millimeter
OutputDevice& rOutDev = mpOutDev->getOutDev();
const MapMode aOldMapMode( rOutDev.GetMapMode() );
rOutDev.SetMapMode( MapMode(MAP_MM) );
const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
rOutDev.SetMapMode( aOldMapMode );
return vcl::unotools::size2DFromSize( aLogSize );
}
uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
const uno::Reference< rendering::XGraphicDevice >& ,
const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
{
uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
if( !mpOutDev )
return xPoly; // we're disposed
xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
// vcl only handles even_odd polygons
xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
return xPoly;
}
uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
const uno::Reference< rendering::XGraphicDevice >& ,
const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
{
uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
if( !mpOutDev )
return xPoly; // we're disposed
xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
// vcl only handles even_odd polygons
xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
return xPoly;
}
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
const uno::Reference< rendering::XGraphicDevice >& rDevice,
const geometry::IntegerSize2D& size )
{
if( !mpOutDev )
return uno::Reference< rendering::XBitmap >(); // we're disposed
return uno::Reference< rendering::XBitmap >(
new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
false,
*rDevice.get(),
mpOutDev ) );
}
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
const uno::Reference< rendering::XGraphicDevice >& ,
const geometry::IntegerSize2D& )
{
return uno::Reference< rendering::XVolatileBitmap >();
}
uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
const uno::Reference< rendering::XGraphicDevice >& rDevice,
const geometry::IntegerSize2D& size )
{
if( !mpOutDev )
return uno::Reference< rendering::XBitmap >(); // we're disposed
return uno::Reference< rendering::XBitmap >(
new CanvasBitmap( vcl::unotools::sizeFromIntegerSize2D(size),
true,
*rDevice.get(),
mpOutDev ) );
}
uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
const uno::Reference< rendering::XGraphicDevice >& ,
const geometry::IntegerSize2D& )
{
return uno::Reference< rendering::XVolatileBitmap >();
}
void DeviceHelper::disposing()
{
// release all references
mpOutDev.reset();
}
uno::Any DeviceHelper::isAccelerated() const
{
return css::uno::makeAny(false);
}
uno::Any DeviceHelper::getDeviceHandle() const
{
if( !mpOutDev )
return uno::Any();
return uno::makeAny(
reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
}
uno::Any DeviceHelper::getSurfaceHandle() const
{
return getDeviceHandle();
}
namespace
{
struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
DeviceColorSpace>
{
uno::Reference<rendering::XColorSpace> operator()()
{
uno::Reference< rendering::XColorSpace > xColorSpace( canvas::tools::getStdColorSpace(), uno::UNO_QUERY );
assert( xColorSpace.is() );
return xColorSpace;
}
};
}
uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
{
// always the same
return DeviceColorSpace::get();
}
void DeviceHelper::dumpScreenContent() const
{
static sal_Int32 nFilePostfixCount(0);
if( mpOutDev )
{
OUString aFilename = "dbg_frontbuffer" + OUString::number(nFilePostfixCount) + ".bmp";
SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
const ::Point aEmptyPoint;
OutputDevice& rOutDev = mpOutDev->getOutDev();
bool bOldMap( rOutDev.IsMapModeEnabled() );
rOutDev.EnableMapMode( false );
Resolves: #i121504# Support for alpha channel in clipboard for all systems (cherry picked from commit ef3931ff410117e1237b3bef7bc090e8b83b9519) Conflicts: automation/source/server/statemnt.cxx basic/source/runtime/methods.cxx canvas/source/vcl/devicehelper.cxx canvas/source/vcl/spritedevicehelper.cxx drawinglayer/source/processor2d/vclhelperbufferdevice.cxx drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx drawinglayer/source/tools/converters.cxx dtrans/source/win32/dtobj/FmtFilter.cxx editeng/source/items/bulitem.cxx extensions/source/scanner/sanedlg.cxx external/gcc3_specific/makefile.mk filter/source/graphicfilter/eos2met/eos2met.cxx filter/source/graphicfilter/ios2met/ios2met.cxx filter/source/msfilter/msdffimp.cxx fpicker/source/office/iodlg.cxx framework/source/fwe/classes/addonsoptions.cxx framework/source/fwe/helper/actiontriggerhelper.cxx sc/source/filter/excel/xiescher.cxx sc/source/ui/docshell/docsh.cxx sc/source/ui/inc/viewfunc.hxx sd/source/ui/app/sdxfer.cxx sd/source/ui/unoidl/unopage.cxx sd/source/ui/view/sdview3.cxx sfx2/source/appl/fileobj.cxx sfx2/source/appl/linkmgr2.cxx sfx2/source/dialog/filedlghelper.cxx sfx2/source/dialog/intro.cxx sfx2/source/doc/docinf.cxx sot/inc/sot/formats.hxx sot/source/base/formats.cxx svtools/bmpmaker/bmpcore.cxx svtools/bmpmaker/bmpsum.cxx svtools/inc/svtools/transfer.hxx svtools/source/filter/filter.cxx svtools/source/filter/wmf/emfwr.cxx svtools/source/filter/wmf/enhwmf.cxx svtools/source/filter/wmf/winwmf.cxx svtools/source/filter/wmf/wmfwr.cxx svtools/source/graphic/graphic.cxx svtools/source/graphic/provider.cxx svtools/source/misc/transfer.cxx svx/inc/svx/xoutbmp.hxx svx/source/sdr/overlay/overlaymanagerbuffered.cxx svx/source/xoutdev/_xoutbmp.cxx sw/source/core/view/viewsh.cxx sw/source/filter/ww1/w1filter.cxx sw/source/filter/ww8/ww8par.hxx sw/source/ui/dochdl/swdtflvr.cxx toolkit/source/awt/vclxbitmap.cxx toolkit/source/helper/vclunohelper.cxx vcl/Library_vcl.mk vcl/Package_inc.mk vcl/aqua/source/dtrans/DataFlavorMapping.cxx vcl/aqua/source/dtrans/OSXTransferable.cxx vcl/aqua/source/dtrans/PictToBmpFlt.cxx vcl/aqua/source/dtrans/PictToBmpFlt.hxx vcl/inc/vcl/alpha.hxx vcl/inc/vcl/bitmap.hxx vcl/inc/vcl/bitmapex.hxx vcl/inc/vcl/pngwrite.hxx vcl/inc/vcl/salbtype.hxx vcl/inc/vcl/wall.hxx vcl/source/gdi/animate.cxx vcl/source/gdi/bitmap2.cxx vcl/source/gdi/bitmapex.cxx vcl/source/gdi/bmpconv.cxx vcl/source/gdi/cvtsvm.cxx vcl/source/gdi/impgraph.cxx vcl/source/gdi/impimagetree.cxx vcl/source/gdi/metaact.cxx vcl/source/gdi/wall.cxx Change-Id: I79938bc412c048c3d4e64f430f216e73bec16167
2013-01-10 16:28:40 +00:00
WriteDIB(rOutDev.GetBitmap(aEmptyPoint, rOutDev.GetOutputSizePixel()), aStream, false, true);
rOutDev.EnableMapMode( bOldMap );
++nFilePostfixCount;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */