tdf#74702 - vcl: introduce OutputDevice::GetDeviceInfo()

Change-Id: I02c9cc83fea330ed0ba1539b2682f75d33ba80fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108132
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Chris Sherlock 2020-12-22 10:54:27 +11:00 committed by Mike Kaganski
parent dd91d3389c
commit ab2d3462f4
7 changed files with 68 additions and 43 deletions

View File

@ -48,6 +48,7 @@
#include <com/sun/star/drawing/LineCap.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/awt/DeviceInfo.hpp>
#include <memory>
#include <vector>
@ -2017,6 +2018,13 @@ public:
const Point& rPt, const Size& rSz,
const GfxLink& rGfxLink, GDIMetaFile* pSubst = nullptr );
///@}
public:
virtual css::awt::DeviceInfo GetDeviceInfo() const;
protected:
css::awt::DeviceInfo GetCommonDeviceInfo(Size const& aDevSize) const;
};
#endif // INCLUDED_VCL_OUTDEV_HXX

View File

@ -221,6 +221,8 @@ public:
DrawRect(aBorderRect);
}
css::awt::DeviceInfo GetDeviceInfo() const override;
protected:
virtual void DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor,
const Point& rDestPt, const Size& rDestSize,

View File

@ -1550,6 +1550,8 @@ public:
void SetMnemonicActivateHdl(const Link<vcl::Window&, bool>& rLink);
void SetModalHierarchyHdl(const Link<bool, void>& rLink);
void SetDumpAsPropertyTreeHdl(const Link<tools::JsonWriter&, void>& rLink);
css::awt::DeviceInfo GetDeviceInfo() const override;
};
}

View File

@ -17,8 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/awt/DeviceCapability.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
@ -87,47 +85,8 @@ css::awt::DeviceInfo VCLXDevice::getInfo()
css::awt::DeviceInfo aInfo;
if( mpOutputDevice )
{
Size aDevSz;
OutDevType eDevType = mpOutputDevice->GetOutDevType();
if ( eDevType == OUTDEV_WINDOW )
{
aDevSz = static_cast<vcl::Window*>(mpOutputDevice.get())->GetSizePixel();
static_cast<vcl::Window*>(mpOutputDevice.get())->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset );
}
else if ( eDevType == OUTDEV_PRINTER )
{
aDevSz = static_cast<Printer*>(mpOutputDevice.get())->GetPaperSizePixel();
Size aOutSz = mpOutputDevice->GetOutputSizePixel();
Point aOffset = static_cast<Printer*>(mpOutputDevice.get())->GetPageOffset();
aInfo.LeftInset = aOffset.X();
aInfo.TopInset = aOffset.Y();
aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
}
else // VirtualDevice
{
aDevSz = mpOutputDevice->GetOutputSizePixel();
aInfo.LeftInset = 0;
aInfo.TopInset = 0;
aInfo.RightInset = 0;
aInfo.BottomInset = 0;
}
aInfo.Width = aDevSz.Width();
aInfo.Height = aDevSz.Height();
Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MapUnit::MapCM ) );
aInfo.PixelPerMeterX = aTmpSz.Width()/10;
aInfo.PixelPerMeterY = aTmpSz.Height()/10;
aInfo.BitsPerPixel = mpOutputDevice->GetBitCount();
aInfo.Capabilities = 0;
if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER )
aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS|css::awt::DeviceCapability::GETBITS;
}
if (mpOutputDevice)
aInfo = mpOutputDevice->GetDeviceInfo();
return aInfo;
}

View File

@ -1644,4 +1644,19 @@ Bitmap Printer::GetBitmap( const Point& rSrcPt, const Size& rSize ) const
return OutputDevice::GetBitmap( rSrcPt, rSize );
}
css::awt::DeviceInfo Printer::GetDeviceInfo() const
{
Size aDevSz = GetPaperSizePixel();
css::awt::DeviceInfo aInfo = GetCommonDeviceInfo(aDevSz);
Size aOutSz = GetOutputSizePixel();
Point aOffset = GetPageOffset();
aInfo.LeftInset = aOffset.X();
aInfo.TopInset = aOffset.Y();
aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X();
aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y();
aInfo.Capabilities = 0;
return aInfo;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -34,6 +34,8 @@
#include <window.h>
#include <outdev.h>
#include <com/sun/star/awt/DeviceCapability.hpp>
#ifdef DISABLE_DYNLOADING
// Linking all needed LO code into one .so/executable, these already
// exist in the tools library, so put them in the anonymous namespace
@ -701,4 +703,34 @@ bool OutputDevice::DrawEPS( const Point& rPoint, const Size& rSize,
return bDrawn;
}
css::awt::DeviceInfo OutputDevice::GetCommonDeviceInfo(Size const& rDevSz) const
{
css::awt::DeviceInfo aInfo;
aInfo.Width = rDevSz.Width();
aInfo.Height = rDevSz.Height();
Size aTmpSz = LogicToPixel(Size(1000, 1000), MapMode(MapUnit::MapCM));
aInfo.PixelPerMeterX = aTmpSz.Width() / 10;
aInfo.PixelPerMeterY = aTmpSz.Height() / 10;
aInfo.BitsPerPixel = GetBitCount();
aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS |
css::awt::DeviceCapability::GETBITS;
return aInfo;
}
css::awt::DeviceInfo OutputDevice::GetDeviceInfo() const
{
css::awt::DeviceInfo aInfo = GetCommonDeviceInfo(GetOutputSizePixel());
aInfo.LeftInset = 0;
aInfo.TopInset = 0;
aInfo.RightInset = 0;
aInfo.BottomInset = 0;
return aInfo;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -3963,6 +3963,13 @@ FactoryFunction Window::GetUITestFactory() const
return WindowUIObject::create;
}
css::awt::DeviceInfo Window::GetDeviceInfo() const
{
css::awt::DeviceInfo aInfo = GetCommonDeviceInfo(GetSizePixel());
GetBorder(aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset);
return aInfo;
}
} /* namespace vcl */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */