summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2018-11-26 16:59:42 +0000
committerMichael Meeks <michael.meeks@collabora.com>2019-09-24 14:53:40 +0200
commitac6fe36ac6ccebf3bf891b891bd47c8e3744a056 (patch)
tree3676e69f33602592aec30b1998c978cb1b4fd778 /vcl
parent6b82bbd9e7c3aab343c5e7e9e3fb0bcfc70e2cb7 (diff)
Use lazy-loading stock Image to simplify framework image lists.
Project stock names through XGraphic via origin URL. (cherry picked from commit 77b88eebaadebb626108172e4f2de36c60960051) Change-Id: Ib445694f7c142a163ef7e7bc0beea39b88b99e14 Reviewed-on: https://gerrit.libreoffice.org/79420 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/image.h5
-rw-r--r--vcl/source/gdi/graph.cxx14
-rw-r--r--vcl/source/helper/commandinfoprovider.cxx11
-rw-r--r--vcl/source/image/Image.cxx23
-rw-r--r--vcl/source/image/ImplImage.cxx34
5 files changed, 66 insertions, 21 deletions
diff --git a/vcl/inc/image.h b/vcl/inc/image.h
index e37ada46ef15..c25015624ec4 100644
--- a/vcl/inc/image.h
+++ b/vcl/inc/image.h
@@ -48,6 +48,11 @@ public:
return maStockName.getLength() > 0;
}
+ OUString getStock() const
+ {
+ return maStockName;
+ }
+
/// get size in co-ordinates not scaled for HiDPI
Size getSizePixel();
/// Legacy - the original bitmap
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index e8b377cb222e..5625ac8d8efc 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -21,6 +21,8 @@
#include <vcl/outdev.hxx>
#include <vcl/svapp.hxx>
#include <vcl/graph.hxx>
+#include <vcl/image.hxx>
+#include <vcl/metaact.hxx>
#include <impgraph.hxx>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
@@ -29,6 +31,7 @@
#include <graphic/UnoGraphic.hxx>
#include <vcl/GraphicExternalLink.hxx>
+#include <image.h>
using namespace ::com::sun::star;
@@ -212,6 +215,17 @@ Graphic::Graphic(const BitmapEx& rBmpEx)
{
}
+// We use XGraphic for passing toolbar images across app UNO aps
+// and we need to be able to see and preserve 'stock' images too.
+Graphic::Graphic(const Image& rImage)
+ // FIXME: should really defer the BitmapEx load.
+ : mxImpGraphic(new ImpGraphic(rImage.GetBitmapEx()))
+{
+ OUString aStock = rImage.GetStock();
+ if (aStock.getLength())
+ mxImpGraphic->setOriginURL("private:graphicrepository/" + aStock);
+}
+
Graphic::Graphic(const VectorGraphicDataPtr& rVectorGraphicDataPtr)
: mxImpGraphic(vcl::graphic::Manager::get().newInstance(rVectorGraphicDataPtr))
{
diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx
index f14ee9dd0efb..d6fdc61715e8 100644
--- a/vcl/source/helper/commandinfoprovider.cxx
+++ b/vcl/source/helper/commandinfoprovider.cxx
@@ -350,20 +350,11 @@ Reference<graphic::XGraphic> GetXGraphicForCommand(const OUString& rsCommandName
return nullptr;
}
-static BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
- const Reference<frame::XFrame>& rxFrame,
- vcl::ImageType eImageType)
-{
- const Graphic aGraphic(GetXGraphicForCommand(rsCommandName, rxFrame, eImageType));
- BitmapEx aBitmap(aGraphic.GetBitmapEx());
- return aBitmap;
-}
-
Image GetImageForCommand(const OUString& rsCommandName,
const Reference<frame::XFrame>& rxFrame,
vcl::ImageType eImageType)
{
- return Image(GetBitmapForCommand(rsCommandName, rxFrame, eImageType));
+ return Image(GetXGraphicForCommand(rsCommandName, rxFrame, eImageType));
}
sal_Int32 GetPropertiesForCommand (
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx
index 01bce0514116..0cb7c5d44949 100644
--- a/vcl/source/image/Image.cxx
+++ b/vcl/source/image/Image.cxx
@@ -40,24 +40,28 @@ Image::Image(const BitmapEx& rBitmapEx)
Image::Image(uno::Reference<graphic::XGraphic> const & rxGraphic)
{
- const Graphic aGraphic(rxGraphic);
- ImplInit(aGraphic.GetBitmapEx());
+ if (rxGraphic.is())
+ {
+ const Graphic aGraphic(rxGraphic);
+
+ OUString aPath;
+ if (aGraphic.getOriginURL().startsWith("private:graphicrepository/", &aPath))
+ mpImplData = std::make_shared<ImplImage>(aPath, Size());
+ else
+ ImplInit(aGraphic.GetBitmapEx());
+ }
}
Image::Image(const OUString & rFileUrl)
{
OUString sImageName;
if (rFileUrl.startsWith("private:graphicrepository/", &sImageName))
- {
mpImplData = std::make_shared<ImplImage>(sImageName, Size());
- }
else
{
Graphic aGraphic;
if (ERRCODE_NONE == GraphicFilter::LoadGraphic(rFileUrl, IMP_PNG, aGraphic))
- {
ImplInit(aGraphic.GetBitmapEx());
- }
}
}
@@ -72,6 +76,13 @@ void Image::ImplInit(const BitmapEx& rBitmapEx)
mpImplData = std::make_shared<ImplImage>(rBitmapEx);
}
+OUString Image::GetStock() const
+{
+ if (mpImplData)
+ return mpImplData->getStock();
+ return OUString();
+}
+
Size Image::GetSizePixel() const
{
if (mpImplData)
diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx
index 702426270cf3..965b0e360b62 100644
--- a/vcl/source/image/ImplImage.cxx
+++ b/vcl/source/image/ImplImage.cxx
@@ -47,13 +47,37 @@ ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize)
bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
{
BitmapEx aBitmapEx;
+
+ ImageLoadFlags eScalingFlags = ImageLoadFlags::NONE;
+ sal_Int32 nScalePercentage = -1;
+
+ if (comphelper::LibreOfficeKit::isActive()) // scale at the surface
+ {
+ nScalePercentage = fScale * 100.0;
+ eScalingFlags = ImageLoadFlags::IgnoreScalingFactor;
+ }
+
OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
- fScale * 100.0,
- ImageLoadFlags::IgnoreScalingFactor))
+ nScalePercentage, eScalingFlags))
{
- SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale);
- return false;
+ /* If the uno command has parameters, passed in from a toolbar,
+ * recover from failure by removing the parameters from the file name
+ */
+ if (maStockName.indexOf("%3f") > 0)
+ {
+ sal_Int32 nStart = maStockName.indexOf("%3f");
+ sal_Int32 nEnd = maStockName.lastIndexOf(".");
+
+ OUString aFileName = maStockName.replaceAt(nStart, nEnd - nStart, "");
+ if (!ImageTree::get().loadImage(aFileName, aIconTheme, aBitmapEx, true,
+ nScalePercentage, eScalingFlags))
+ {
+ SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
+ " and " << aFileName << " at " << fScale);
+ return false;
+ }
+ }
}
if (maPreferedSizePixel != Size())
{
@@ -122,7 +146,7 @@ BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled)
// FIXME: DPI scaling should be tied to the outdev really ...
double fScale = comphelper::LibreOfficeKit::getDPIScale();
Size aTarget(maSizePixel.Width()*fScale,
- maSizePixel.Height()*fScale);
+ maSizePixel.Height()*fScale);
if (maBitmapEx.GetSizePixel() != aTarget)
loadStockAtScale(fScale, maBitmapEx);
}