diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2018-11-26 14:00:08 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-11-27 21:33:35 +0100 |
commit | da3432a0a8ab06c5bbd79a82703bf07e79c692f9 (patch) | |
tree | e1076ed8ba981708ae2dde3542529f4cdadc4c93 | |
parent | 0f25a3c36f27fd51453b9a9115f236b83c143684 (diff) |
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: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | vcl/inc/image.h | 4 | ||||
-rw-r--r-- | vcl/source/image/Image.cxx | 10 | ||||
-rw-r--r-- | vcl/source/image/ImplImage.cxx | 36 |
3 files changed, 39 insertions, 11 deletions
diff --git a/vcl/inc/image.h b/vcl/inc/image.h index f966a8c62c1f..c9fb5393191a 100644 --- a/vcl/inc/image.h +++ b/vcl/inc/image.h @@ -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 diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index 8bce4839a1ea..ecb514c5bbac 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -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: */ diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx index 471dcb091e3d..95d605e47173 100644 --- a/vcl/source/image/ImplImage.cxx +++ b/vcl/source/image/ImplImage.cxx @@ -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: */ |