diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2018-11-26 14:45:50 +0000 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-12-06 10:51:23 +0100 |
commit | 190fad517d66be7891d54d0731cecb148aff357d (patch) | |
tree | b4721ca55ef8d2e4814f2b633aa80d7e59cb6114 | |
parent | 6dca7a2411c96f955c768b425bc4ac62bafacd0b (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
(cherry picked from commit 1799b122ef79432c9ce4e419bce660797c01efa4)
-rw-r--r-- | vcl/source/image/Image.cxx | 4 | ||||
-rw-r--r-- | vcl/source/image/ImplImage.cxx | 39 |
2 files changed, 36 insertions, 7 deletions
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index fdda197f2654..4232173f80d6 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -119,7 +119,7 @@ void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(aBitmapSizePixel); - BitmapEx aRenderBmp = mpImplData->getBitmapEx(!!(nStyle & DrawImageFlags::Disable)); + BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(!!(nStyle & DrawImageFlags::Disable)); if (!(nStyle & DrawImageFlags::Disable) && (nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight | @@ -156,7 +156,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 e9024229f482..5f75c82845a1 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> @@ -26,7 +27,8 @@ #include <vcl/virdev.hxx> #include <vcl/image.hxx> #include <vcl/settings.hxx> -#include <vcl/imagerepository.hxx> +#include <vcl/ImageTree.hxx> +#include <comphelper/lok.hxx> #include <BitmapProcessor.hxx> #include <image.h> @@ -46,6 +48,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; @@ -53,13 +70,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 @@ -98,4 +113,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: */ |