framework/source/uielement/popuptoolbarcontroller.cxx | 22 +++++----------- include/svtools/imagemgr.hxx | 5 ++- include/vcl/image.hxx | 4 +-- svtools/source/misc/imagemgr.cxx | 14 +++++----- vcl/inc/image.h | 24 +++++++++++++----- vcl/source/image/Image.cxx | 6 ++-- vcl/source/image/ImplImage.cxx | 13 +++++++-- 7 files changed, 50 insertions(+), 38 deletions(-)
New commits: commit 812f0a83d223cddf00b121db40ca7ff91c22ccfa Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Apr 12 11:11:13 2019 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Apr 12 13:56:53 2019 +0200 internally resize image instead of scaling bitmaps outside When we want a different size Image, we can now set that as a parameter at construction of the Image. Previously we needed to create an Image, forcefully take the bitmap out, resize the bitmap and create a new Image out of that. Doing it internally gives us the benefit to have a more control over the scaling process, especially when dealing with HiDPI images. Change-Id: I104118f4d863d519cc7aad1a17ca0289c01ed9ff Reviewed-on: https://gerrit.libreoffice.org/70617 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx index 94d056daf60d..6d325ff4f452 100644 --- a/framework/source/uielement/popuptoolbarcontroller.cxx +++ b/framework/source/uielement/popuptoolbarcontroller.cxx @@ -785,25 +785,17 @@ void NewToolbarController::setItemImage( const OUString &rCommand ) bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge(); INetURLObject aURLObj( aURL ); - Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig ); - if ( !aImage ) - aImage = !!aMenuImage ? - aMenuImage : - SvFileInformationManager::GetImage( aURLObj, bBig ); - + Size aPreferredSize(bBig ? pToolBox->GetDefaultImageSize() : Size()); + Image aImage = SvFileInformationManager::GetImageNoDefault(aURLObj, bBig, aPreferredSize); + if (!aImage) + { + aImage = !!aMenuImage ? aMenuImage : SvFileInformationManager::GetImage(aURLObj, bBig, aPreferredSize); + } // if everything failed, just use the image associated with the toolbar item command if ( !aImage ) return; - Size aBigSize( pToolBox->GetDefaultImageSize() ); - if ( bBig && aImage.GetSizePixel() != aBigSize ) - { - BitmapEx aScaleBmpEx( aImage.GetBitmapEx() ); - aScaleBmpEx.Scale( aBigSize, BmpScaleFlag::Interpolate ); - pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) ); - } - else - pToolBox->SetItemImage( m_nToolBoxId, aImage ); + pToolBox->SetItemImage( m_nToolBoxId, aImage ); m_aLastURL = aURL; } diff --git a/include/svtools/imagemgr.hxx b/include/svtools/imagemgr.hxx index 45212829b5c6..697ab8aeb41c 100644 --- a/include/svtools/imagemgr.hxx +++ b/include/svtools/imagemgr.hxx @@ -22,6 +22,7 @@ #include <rtl/ustring.hxx> #include <svtools/svtdllapi.h> +#include <tools/gen.hxx> enum class SvImageId { NONE = 0, @@ -119,10 +120,10 @@ private: public: SVT_DLLPUBLIC static OUString GetImageId( const INetURLObject& rURL, bool bBig = false ); - SVT_DLLPUBLIC static Image GetImage( const INetURLObject& rURL, bool bBig = false ); + SVT_DLLPUBLIC static Image GetImage( const INetURLObject& rURL, bool bBig = false, Size const & rPreferredSize = Size()); SVT_DLLPUBLIC static OUString GetFileImageId( const INetURLObject& rURL ); SVT_DLLPUBLIC static Image GetFileImage( const INetURLObject& rURL ); - SVT_DLLPUBLIC static Image GetImageNoDefault( const INetURLObject& rURL, bool bBig = false ); + SVT_DLLPUBLIC static Image GetImageNoDefault(const INetURLObject& rURL, bool bBig = false, Size const & rPreferredSize = Size()); SVT_DLLPUBLIC static Image GetFolderImage( const svtools::VolumeInfo& rInfo ); SVT_DLLPUBLIC static OUString GetDescription( const INetURLObject& rObject ); diff --git a/include/vcl/image.hxx b/include/vcl/image.hxx index b2f64c138bac..4c5047518bf3 100644 --- a/include/vcl/image.hxx +++ b/include/vcl/image.hxx @@ -27,7 +27,7 @@ #include <memory> -struct ImplImage; +class ImplImage; namespace com::sun::star::graphic { class XGraphic; } namespace com::sun::star::uno { template <class interface_type> class Reference; } @@ -57,7 +57,7 @@ public: explicit Image(BitmapEx const & rBitmapEx); explicit Image(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); explicit Image(OUString const & rPNGFileUrl); - explicit Image(StockImage , OUString const & rPNGFilePath); + explicit Image(StockImage, OUString const & rPNGFilePath, Size aSpecificSize = Size()); Size GetSizePixel() const; BitmapEx GetBitmapEx() const; diff --git a/svtools/source/misc/imagemgr.cxx b/svtools/source/misc/imagemgr.cxx index fdb556d6184c..5e688394e4dd 100644 --- a/svtools/source/misc/imagemgr.cxx +++ b/svtools/source/misc/imagemgr.cxx @@ -686,11 +686,11 @@ static OUString GetImageNameFromList_Impl( SvImageId nImageId, bool bBig ) return OUString(); } -static Image GetImageFromList_Impl( SvImageId nImageId, bool bBig ) +static Image GetImageFromList_Impl( SvImageId nImageId, bool bBig, Size aSize = Size()) { OUString sImageName(GetImageNameFromList_Impl(nImageId, bBig)); if (!sImageName.isEmpty()) - return Image(StockImage::Yes, sImageName); + return Image(StockImage::Yes, sImageName, aSize); return Image(); } @@ -766,11 +766,11 @@ OUString SvFileInformationManager::GetImageId(const INetURLObject& rObject, bool return GetImageNameFromList_Impl(nImage, bBig); } -Image SvFileInformationManager::GetImage( const INetURLObject& rObject, bool bBig ) +Image SvFileInformationManager::GetImage(const INetURLObject& rObject, bool bBig, Size const & rPreferredSize) { SvImageId nImage = GetImageId_Impl( rObject, true ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); - return GetImageFromList_Impl( nImage, bBig ); + return GetImageFromList_Impl(nImage, bBig, rPreferredSize); } OUString SvFileInformationManager::GetFileImageId(const INetURLObject& rObject) @@ -787,15 +787,15 @@ Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject ) return GetImageFromList_Impl( nImage, false/*bBig*/ ); } -Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, bool bBig ) +Image SvFileInformationManager::GetImageNoDefault(const INetURLObject& rObject, bool bBig, Size const & rPreferredSize) { - SvImageId nImage = GetImageId_Impl( rObject, true ); + SvImageId nImage = GetImageId_Impl(rObject, true); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); if ( nImage == SvImageId::File ) return Image(); - return GetImageFromList_Impl( nImage, bBig ); + return GetImageFromList_Impl(nImage, bBig, rPreferredSize); } Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo ) diff --git a/vcl/inc/image.h b/vcl/inc/image.h index c9fb5393191a..c5acc06f782a 100644 --- a/vcl/inc/image.h +++ b/vcl/inc/image.h @@ -25,22 +25,31 @@ #include <unordered_map> #include <vector> -struct ImplImage +class ImplImage { +private: BitmapChecksum maBitmapChecksum; /// if non-empty: cached original size of maStockName else Size of maBitmap - Size maSizePixel; + Size maSizePixel; + Size maPreferedSizePixel; /// If set - defines the bitmap via images.zip* OUString maStockName; + /// Original bitmap - or cache of a potentially scaled bitmap BitmapEx maBitmapEx; BitmapEx maDisabledBitmapEx; + bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx); + +public: ImplImage(const BitmapEx& rBitmapEx); - ImplImage(const OUString &aStockName); + ImplImage(const OUString &aStockName, Size const & rPreferedSize); - bool isStock() const { return maStockName.getLength() > 0; } + bool isStock() const + { + return maStockName.getLength() > 0; + } /// get size in co-ordinates not scaled for HiDPI Size getSizePixel(); @@ -48,9 +57,12 @@ struct ImplImage 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); + bool isSizeEmpty() const + { + return maSizePixel == Size(); + } }; #endif // INCLUDED_VCL_INC_IMAGE_H diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index e52583b99bd9..4316f9145a16 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -60,7 +60,7 @@ Image::Image(const OUString & rFileUrl) OUString sImageName; if (rFileUrl.startsWith("private:graphicrepository/", &sImageName)) { - mpImplData = std::make_shared<ImplImage>(sImageName); + mpImplData = std::make_shared<ImplImage>(sImageName, Size()); } else { @@ -72,8 +72,8 @@ Image::Image(const OUString & rFileUrl) } } -Image::Image(StockImage, const OUString & rFileUrl) - : mpImplData(std::make_shared<ImplImage>(rFileUrl)) +Image::Image(StockImage, const OUString & rFileUrl, Size aSpecificSize) + : mpImplData(std::make_shared<ImplImage>(rFileUrl, aSpecificSize)) { } diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx index 95d605e47173..7605f88d9767 100644 --- a/vcl/source/image/ImplImage.cxx +++ b/vcl/source/image/ImplImage.cxx @@ -39,14 +39,16 @@ ImplImage::ImplImage(const BitmapEx &rBitmapEx) : maBitmapChecksum(0) , maSizePixel(rBitmapEx.GetSizePixel()) + , maPreferedSizePixel() , maBitmapEx(rBitmapEx) { } -ImplImage::ImplImage(const OUString &aStockName) +ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize) : maBitmapChecksum(0) - , maSizePixel(0,0) // defer size lookup - , maStockName( aStockName ) + , maSizePixel() // defer size lookup + , maPreferedSizePixel(rPreferedSize) + , maStockName(aStockName) { } @@ -61,6 +63,11 @@ bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx) SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale); return false; } + if (maPreferedSizePixel != Size()) + { + Size aScaleSize(maPreferedSizePixel.Width() * fScale, maPreferedSizePixel.Height() * fScale); + aBitmapEx.Scale(aScaleSize); + } rBitmapEx = aBitmapEx; return true; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
