diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2018-11-26 13:24:03 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-11-27 13:16:38 +0100 |
commit | bc8e23fc946380751447ab24587b1631eb56ef19 (patch) | |
tree | 90334349e2696111af048bab4436d790fb68b96d /vcl/source/image/ImplImageTree.cxx | |
parent | a71ea5cefffc4169237310d72f2d6e96c8bbf63d (diff) |
Add explicit API scaling via ImageTree API.
Also add image scale to in-memory cache lookup.
Change-Id: I1e84b922d4a9ab2f1723c5cb8a72f295c6940504
Reviewed-on: https://gerrit.libreoffice.org/64043
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'vcl/source/image/ImplImageTree.cxx')
-rw-r--r-- | vcl/source/image/ImplImageTree.cxx | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx index 1fed00908365..22fd194b3a8d 100644 --- a/vcl/source/image/ImplImageTree.cxx +++ b/vcl/source/image/ImplImageTree.cxx @@ -69,6 +69,8 @@ sal_Int32 ImageRequestParameters::scalePercentage() sal_Int32 aScalePercentage = 100; if (!(meFlags & ImageLoadFlags::IgnoreScalingFactor)) aScalePercentage = Application::GetDefaultDevice()->GetDPIScalePercentage(); + else if (mnScalePercentage > 0) + aScalePercentage = mnScalePercentage; return aScalePercentage; } @@ -96,17 +98,17 @@ OUString createPath(OUString const & name, sal_Int32 pos, OUString const & local return name.copy(0, pos + 1) + locale + name.copy(pos); } -OUString getIconCacheUrl(OUString const & sStyle, OUString const & sVariant, OUString const & sName) +OUString getIconCacheUrl(OUString const & sVariant, ImageRequestParameters const & rParameters) { OUString sUrl("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/cache/"); - sUrl += sStyle + "/" + sVariant + "/" + sName; + sUrl += rParameters.msStyle + "/" + sVariant + "/" + rParameters.msName; rtl::Bootstrap::expandMacros(sUrl); return sUrl; } -OUString createIconCacheUrl(OUString const & sStyle, OUString const & sVariant, OUString const & sName) +OUString createIconCacheUrl(OUString const & sVariant, ImageRequestParameters const & rParameters) { - OUString sUrl(getIconCacheUrl(sStyle, sVariant, sName)); + OUString sUrl(getIconCacheUrl(sVariant, rParameters)); OUString sDir = sUrl.copy(0, sUrl.lastIndexOf('/')); osl::Directory::createPath(sDir); return sUrl; @@ -315,14 +317,15 @@ OUString ImplImageTree::fallbackStyle(const OUString& rsStyle) return sResult; } -bool ImplImageTree::loadImage(OUString const & rName, OUString const & rStyle, BitmapEx & rBitmap, bool localized, const ImageLoadFlags eFlags) +bool ImplImageTree::loadImage(OUString const & rName, OUString const & rStyle, BitmapEx & rBitmap, bool localized, + const ImageLoadFlags eFlags, sal_Int32 nScalePercentage) { OUString aCurrentStyle(rStyle); while (!aCurrentStyle.isEmpty()) { try { - ImageRequestParameters aParameters(rName, aCurrentStyle, rBitmap, localized, eFlags); + ImageRequestParameters aParameters(rName, aCurrentStyle, rBitmap, localized, eFlags, nScalePercentage); if (doLoadImage(aParameters)) return true; } @@ -349,7 +352,7 @@ static OUString createVariant(ImageRequestParameters& rParameters) static bool loadDiskCachedVersion(OUString const & sVariant, ImageRequestParameters& rParameters) { - OUString sUrl(getIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName)); + OUString sUrl(getIconCacheUrl(sVariant, rParameters)); if (!urlExists(sUrl)) return false; SvFileStream aFileStream(sUrl, StreamMode::READ); @@ -361,7 +364,7 @@ static bool loadDiskCachedVersion(OUString const & sVariant, ImageRequestParamet static void cacheBitmapToDisk(OUString const & sVariant, ImageRequestParameters const & rParameters) { - OUString sUrl(createIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName)); + OUString sUrl(createIconCacheUrl(sVariant, rParameters)); vcl::PNGWriter aWriter(rParameters.mrBitmap); try { @@ -382,9 +385,7 @@ bool ImplImageTree::doLoadImage(ImageRequestParameters& rParameters) OUString aVariant = createVariant(rParameters); if (loadDiskCachedVersion(aVariant, rParameters)) - { return true; - } if (!rParameters.mrBitmap.IsEmpty()) rParameters.mrBitmap.SetEmpty(); @@ -414,7 +415,7 @@ bool ImplImageTree::doLoadImage(ImageRequestParameters& rParameters) { cacheBitmapToDisk(aVariant, rParameters); } - getCurrentIconSet().maIconCache[rParameters.msName] = std::make_pair(rParameters.mbLocalized, rParameters.mrBitmap); + getIconCache(rParameters)[rParameters.msName] = std::make_pair(rParameters.mbLocalized, rParameters.mrBitmap); } return bFound; @@ -482,9 +483,20 @@ void ImplImageTree::createStyle() loadImageLinks(); } +/// Find an icon cache for the right scale factor +ImplImageTree::IconCache &ImplImageTree::getIconCache(ImageRequestParameters& rParameters) +{ + IconSet &rSet = getCurrentIconSet(); + auto it = rSet.maScaledIconCaches.find(rParameters.mnScalePercentage); + if ( it != rSet.maScaledIconCaches.end() ) + return *it->second.get(); + rSet.maScaledIconCaches[rParameters.mnScalePercentage] = std::unique_ptr<IconCache>(new IconCache); + return *rSet.maScaledIconCaches[rParameters.mnScalePercentage].get(); +} + bool ImplImageTree::iconCacheLookup(ImageRequestParameters& rParameters) { - IconCache& rIconCache = getCurrentIconSet().maIconCache; + IconCache& rIconCache = getIconCache(rParameters); IconCache::iterator i(rIconCache.find(getRealImageName(rParameters.msName))); if (i != rIconCache.end() && i->second.first == rParameters.mbLocalized) @@ -513,6 +525,7 @@ bool ImplImageTree::findImage(std::vector<OUString> const & rPaths, ImageRequest (void)ok; // prevent unused warning in release build loadImageFromStream(wrapStream(aStream), rPath, rParameters); + return true; } } |