summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-10-27 17:42:36 +0200
committerTomaž Vajngerl <quikee@gmail.com>2016-10-29 18:14:01 +0000
commit5bb5463efefc4d65e3434b37618cb74a1fe2a598 (patch)
treec55623858d6691778c8b046b5fc6600e5f55ed77 /include
parentc857e5ef42266485619587198dcf4599cf995935 (diff)
tdf#51733 support SVG icon theme, disk cache and scaling / darken
Also resolves tdf#92248 This extends icon name resolving so that is in addition tries to find an icon with the "svg" extension and load that instead of stated (mostly "png") extension. If the filename extension is "svg" we load the icon with the SVG filter instead. This also adds icon scaling and conversion for HiDPI or when a dark theme is wanted. If the SVG icon is available, we render it at a higher resolution instead of scaling As loading of SVG icons can be computatunally expensive, a icon disk cache was added. This saves the rendered SVG as a PNG image into the "cache" folder. The same caching is also used for HiDPI and dark theme converted icons so we don't always scale or convert the icons. In addition some style changes and DRY fixes were made to the ImplImageTree source code. Change-Id: I9e421395a342ffe8da9facea7ea06e5db2778b26 Reviewed-on: https://gerrit.libreoffice.org/30339 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/vcl/BitmapTools.hxx10
-rw-r--r--include/vcl/implimagetree.hxx56
2 files changed, 48 insertions, 18 deletions
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index d12e9e13b2cd..c67bbb81f4f3 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -16,12 +16,12 @@
namespace vcl
{
-class VCL_DLLPUBLIC BitmapTools
+namespace bitmap
{
-public:
- static void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx,
- double fScaleFactor = 1.0);
-};
+
+void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScaleFactor = 1.0);
+
+}
}
diff --git a/include/vcl/implimagetree.hxx b/include/vcl/implimagetree.hxx
index a76442f93a64..3064e578999a 100644
--- a/include/vcl/implimagetree.hxx
+++ b/include/vcl/implimagetree.hxx
@@ -31,11 +31,26 @@
#include <rtl/ustring.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/dllapi.h>
+#include <i18nlangtag/languagetag.hxx>
namespace com { namespace sun { namespace star { namespace container {
class XNameAccess;
} } } }
+enum class ImageLoadFlags : sal_uInt16
+{
+ NONE = 0,
+ IgnoreScalingFactor = 1,
+ IgnoreDarkTheme = 2,
+};
+
+namespace o3tl {
+
+template<> struct typed_flags<ImageLoadFlags>: is_typed_flags<ImageLoadFlags, 0x3> {};
+
+}
+
+
class ImplImageTree {
public:
VCL_DLLPUBLIC static ImplImageTree & get();
@@ -45,11 +60,13 @@ public:
bool loadImage(
OUString const & name, OUString const & style,
- BitmapEx & bitmap, bool localized );
+ BitmapEx & bitmap, bool localized,
+ const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
bool loadDefaultImage(
OUString const & style,
- BitmapEx& bitmap);
+ BitmapEx& bitmap,
+ const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
/** a crude form of life cycle control (called from DeInitVCL; otherwise,
* if the ImplImageTree singleton were destroyed during exit that would
@@ -69,51 +86,64 @@ private:
typedef std::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache;
typedef std::unordered_map<OUString, OUString, OUStringHash> IconLinkHash;
- struct IconSet {
+ struct IconSet
+ {
OUString maURL;
css::uno::Reference<css::container::XNameAccess> maNameAccess;
IconCache maIconCache;
IconLinkHash maLinkHash;
- IconSet() {}
- IconSet(const OUString &aURL) : maURL(aURL) {}
+ IconSet()
+ {}
+
+ IconSet(const OUString & rURL)
+ : maURL(rURL)
+ {}
};
/// Map between the theme name(s) and the content.
typedef std::unordered_map<OUString, IconSet, OUStringHash> StyleIconSet;
/// Remember all the (used) icon styles and individual icons in them.
- StyleIconSet maIconSet;
+ StyleIconSet maIconSets;
/// Style used for the current operations; switches switch several times during fallback search.
OUString maCurrentStyle;
+ IconSet& getCurrentIconSet()
+ {
+ return maIconSets[maCurrentStyle];
+ }
+
bool doLoadImage(
OUString const & name, OUString const & style,
- BitmapEx & bitmap, bool localized);
+ BitmapEx & bitmap, bool localized, const ImageLoadFlags eFlags);
+
+ std::vector<OUString> getPaths(OUString const & name, LanguageTag& rLanguageTag);
bool checkPathAccess();
- void setStyle(OUString const & style );
+ void setStyle(OUString const & rStyle);
void createStyle();
- bool iconCacheLookup( OUString const & name, bool localized, BitmapEx & bitmap );
+ bool iconCacheLookup(OUString const & rName, bool bLocalized, const ImageLoadFlags eFlags, BitmapEx & rBitmap);
- bool findImage(std::vector< OUString > const & paths, BitmapEx & bitmap );
+ bool findImage(std::vector<OUString> const & rPaths, BitmapEx & rBitmap, const ImageLoadFlags eFlags);
void loadImageLinks();
- void parseLinkFile(std::shared_ptr<SvStream> const & stream);
+ void parseLinkFile(std::shared_ptr<SvStream> const & aStream);
/// Return name of a real .png according to links.txt.
- OUString const & getRealImageName(OUString const & name);
+ OUString const & getRealImageName(OUString const & rName);
+
/** Return name of the fallback style for the provided one.
Must not be cyclic :-) The last theme in the chain returns an empty string.
*/
- static OUString fallbackStyle(const OUString &style);
+ static OUString fallbackStyle(const OUString &rStyle);
};
#endif