Kaydet (Commit) da3432a0 authored tarafından Michael Meeks's avatar Michael Meeks

Use HiDPI scaling to load scaled images.

We render these at apparently the same pixel size as normal images,
but the underlying canvas is larger so these then end up pixel-matching
the true underlying grid.

Change-Id: Ic4b749127e9c81da78d06b34d9f88c5635dc64b9
Reviewed-on: https://gerrit.libreoffice.org/64044
Tested-by: Jenkins
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 0f25a3c3
......@@ -44,9 +44,13 @@ struct ImplImage
/// get size in co-ordinates not scaled for HiDPI
Size getSizePixel();
/// Legacy - the original bitmap
BitmapEx getBitmapEx(bool bDisabled = false);
/// Taking account of HiDPI scaling
BitmapEx getBitmapExForHiDPI(bool bDisabled = false);
bool isEqual(const ImplImage &ref) const;
bool isSizeEmpty() const { return maSizePixel == Size(0, 0); }
bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx);
};
#endif // INCLUDED_VCL_INC_IMAGE_H
......
......@@ -111,13 +111,9 @@ void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle
if (!mpImplData || (!pOutDev->IsDeviceOutputNecessary() && pOutDev->GetConnectMetaFile() == nullptr))
return;
const Point aSrcPos(0, 0);
Size aBitmapSizePixel = mpImplData->getSizePixel();
Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(mpImplData->getSizePixel());
Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(aBitmapSizePixel);
// FIXME: do the HiDPI scaling fun here [!] =)
BitmapEx aRenderBmp = mpImplData->getBitmapEx(!!(nStyle & DrawImageFlags::Disable));
BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(!!(nStyle & DrawImageFlags::Disable));
if (!(nStyle & DrawImageFlags::Disable) &&
(nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight |
......@@ -154,7 +150,7 @@ void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle
aRenderBmp = aTempBitmapEx;
}
pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aBitmapSizePixel, aRenderBmp);
pOutDev->DrawBitmapEx(rPos, aOutSize, aRenderBmp);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -18,6 +18,7 @@
*/
#include <sal/log.hxx>
#include <vcl/svapp.hxx>
#include <vcl/outdev.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/alpha.hxx>
......@@ -49,6 +50,21 @@ ImplImage::ImplImage(const OUString &aStockName)
{
}
bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
{
BitmapEx aBitmapEx;
OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
fScale * 100.0,
ImageLoadFlags::IgnoreScalingFactor))
{
SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale);
return false;
}
rBitmapEx = aBitmapEx;
return true;
}
Size ImplImage::getSizePixel()
{
Size aRet;
......@@ -56,13 +72,11 @@ Size ImplImage::getSizePixel()
aRet = maSizePixel;
else if (isStock())
{
BitmapEx aBitmapEx;
if (vcl::ImageRepository::loadImage(maStockName, aBitmapEx))
if (loadStockAtScale(1.0, maBitmapEx))
{
assert(!maDisabledBitmapEx);
assert(maBitmapChecksum == 0);
maBitmapEx = aBitmapEx;
maSizePixel = aBitmapEx.GetSizePixel();
maSizePixel = maBitmapEx.GetSizePixel();
aRet = maSizePixel;
}
else
......@@ -102,4 +116,18 @@ bool ImplImage::isEqual(const ImplImage &ref) const
return maBitmapEx == ref.maBitmapEx;
}
BitmapEx ImplImage::getBitmapExForHiDPI(bool bDisabled)
{
if (isStock())
{ // check we have the right bitmap cached.
// FIXME: DPI scaling should be tied to the outdev really ...
double fScale = comphelper::LibreOfficeKit::getDPIScale();
Size aTarget(maSizePixel.Width()*fScale,
maSizePixel.Height()*fScale);
if (maBitmapEx.GetSizePixel() != aTarget)
loadStockAtScale(fScale, maBitmapEx);
}
return getBitmapEx(bDisabled);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment