bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / image / ImplImage.cxx
blob965b0e360b62986e59046564131a17ff645dd4f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/log.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/bitmapex.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/BitmapFilter.hxx>
25 #include <vcl/ImageTree.hxx>
26 #include <BitmapDisabledImageFilter.hxx>
27 #include <comphelper/lok.hxx>
29 #include <image.h>
31 ImplImage::ImplImage(const BitmapEx &rBitmapEx)
32 : maBitmapChecksum(0)
33 , maSizePixel(rBitmapEx.GetSizePixel())
34 , maPreferedSizePixel()
35 , maBitmapEx(rBitmapEx)
39 ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize)
40 : maBitmapChecksum(0)
41 , maSizePixel() // defer size lookup
42 , maPreferedSizePixel(rPreferedSize)
43 , maStockName(aStockName)
47 bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
49 BitmapEx aBitmapEx;
51 ImageLoadFlags eScalingFlags = ImageLoadFlags::NONE;
52 sal_Int32 nScalePercentage = -1;
54 if (comphelper::LibreOfficeKit::isActive()) // scale at the surface
56 nScalePercentage = fScale * 100.0;
57 eScalingFlags = ImageLoadFlags::IgnoreScalingFactor;
60 OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
61 if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
62 nScalePercentage, eScalingFlags))
64 /* If the uno command has parameters, passed in from a toolbar,
65 * recover from failure by removing the parameters from the file name
67 if (maStockName.indexOf("%3f") > 0)
69 sal_Int32 nStart = maStockName.indexOf("%3f");
70 sal_Int32 nEnd = maStockName.lastIndexOf(".");
72 OUString aFileName = maStockName.replaceAt(nStart, nEnd - nStart, "");
73 if (!ImageTree::get().loadImage(aFileName, aIconTheme, aBitmapEx, true,
74 nScalePercentage, eScalingFlags))
76 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
77 " and " << aFileName << " at " << fScale);
78 return false;
82 if (maPreferedSizePixel != Size())
84 Size aScaleSize(maPreferedSizePixel.Width() * fScale, maPreferedSizePixel.Height() * fScale);
85 aBitmapEx.Scale(aScaleSize);
87 rBitmapEx = aBitmapEx;
88 return true;
91 Size ImplImage::getSizePixel()
93 Size aRet;
94 if (!isSizeEmpty())
95 aRet = maSizePixel;
96 else if (isStock())
98 if (loadStockAtScale(1.0, maBitmapEx))
100 assert(!maDisabledBitmapEx);
101 assert(maBitmapChecksum == 0);
102 maSizePixel = maBitmapEx.GetSizePixel();
103 aRet = maSizePixel;
105 else
106 SAL_WARN("vcl", "Failed to load stock icon " << maStockName);
108 return aRet;
111 /// non-HiDPI compatibility method.
112 BitmapEx const & ImplImage::getBitmapEx(bool bDisabled)
114 getSizePixel(); // force load, and at unity scale.
115 if (bDisabled)
117 // Changed since we last generated this.
118 BitmapChecksum aChecksum = maBitmapEx.GetChecksum();
119 if (maBitmapChecksum != aChecksum ||
120 maDisabledBitmapEx.GetSizePixel() != maBitmapEx.GetSizePixel())
122 maDisabledBitmapEx = maBitmapEx;
123 BitmapFilter::Filter(maDisabledBitmapEx, BitmapDisabledImageFilter());
124 maBitmapChecksum = aChecksum;
126 return maDisabledBitmapEx;
129 return maBitmapEx;
132 bool ImplImage::isEqual(const ImplImage &ref) const
134 if (isStock() != ref.isStock())
135 return false;
136 if (isStock())
137 return maStockName == ref.maStockName;
138 else
139 return maBitmapEx == ref.maBitmapEx;
142 BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled)
144 if (isStock())
145 { // check we have the right bitmap cached.
146 // FIXME: DPI scaling should be tied to the outdev really ...
147 double fScale = comphelper::LibreOfficeKit::getDPIScale();
148 Size aTarget(maSizePixel.Width()*fScale,
149 maSizePixel.Height()*fScale);
150 if (maBitmapEx.GetSizePixel() != aTarget)
151 loadStockAtScale(fScale, maBitmapEx);
153 return getBitmapEx(bDisabled);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */