LibreOffice Module vcl (master) 1
ImplImage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/log.hxx>
21#include <utility>
22#include <vcl/svapp.hxx>
23#include <vcl/bitmapex.hxx>
24#include <vcl/gdimtf.hxx>
25#include <vcl/settings.hxx>
26#include <vcl/virdev.hxx>
27#include <vcl/BitmapFilter.hxx>
28#include <vcl/ImageTree.hxx>
31#include <comphelper/lok.hxx>
32
33#include <image.h>
34#include <salgdi.hxx>
35
37 : maBitmapChecksum(0)
38 , maSizePixel(rBitmapEx.GetSizePixel())
39 , maBitmapEx(rBitmapEx)
40{
41}
42
43ImplImage::ImplImage(OUString aStockName)
44 : maBitmapChecksum(0)
45 , maStockName(std::move(aStockName))
46{
47}
48
50 : maBitmapChecksum(0)
51 , maSizePixel(rMetaFile.GetPrefSize())
52 , mxMetaFile(new GDIMetaFile(rMetaFile))
53{
54}
55
57{
58 BitmapEx aBitmapEx;
59
61 sal_Int32 nScalePercentage = -1;
62
63 double fScale(1.0);
64 if (pGraphics && pGraphics->ShouldDownscaleIconsAtSurface(&fScale)) // scale at the surface
65 {
66 nScalePercentage = fScale * 100.0;
68 }
69
71 if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
72 nScalePercentage, eScalingFlags))
73 {
74 /* If the uno command has parameters, passed in from a toolbar,
75 * recover from failure by removing the parameters from the file name
76 */
77 if (maStockName.indexOf("%3f") > 0)
78 {
79 sal_Int32 nStart = maStockName.indexOf("%3f");
80 sal_Int32 nEnd = maStockName.lastIndexOf(".");
81
82 OUString aFileName = maStockName.replaceAt(nStart, nEnd - nStart, u"");
83 if (!ImageTree::get().loadImage(aFileName, aIconTheme, aBitmapEx, true,
84 nScalePercentage, eScalingFlags))
85 {
86 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
87 " and " << aFileName << " at " << fScale);
88 return false;
89 }
90 }
91 else
92 {
93 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
94 " at " << fScale);
95 return false;
96 }
97 }
98 rBitmapEx = aBitmapEx;
99 return true;
100}
101
103{
104 Size aRet;
105 if (!isSizeEmpty())
106 aRet = maSizePixel;
107 else if (isStock())
108 {
109 if (loadStockAtScale(nullptr, maBitmapEx))
110 {
111 assert(maDisabledBitmapEx.IsEmpty());
112 assert(maBitmapChecksum == 0);
114 aRet = maSizePixel;
115 }
116 else
117 SAL_WARN("vcl", "Failed to load stock icon " << maStockName);
118 }
119 return aRet;
120}
121
123BitmapEx const & ImplImage::getBitmapEx(bool bDisabled)
124{
125 getSizePixel(); // force load, and at unity scale.
126 if (bDisabled)
127 {
128 // Changed since we last generated this.
130 if (maBitmapChecksum != aChecksum ||
132 {
135 maBitmapChecksum = aChecksum;
136 }
137 return maDisabledBitmapEx;
138 }
139
140 return maBitmapEx;
141}
142
143bool ImplImage::isEqual(const ImplImage &ref) const
144{
145 if (isStock() != ref.isStock())
146 return false;
147 if (isStock())
148 return maStockName == ref.maStockName;
149 else
150 return maBitmapEx == ref.maBitmapEx;
151}
152
153BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled, SalGraphics* pGraphics)
154{
155 if ((isStock() || mxMetaFile) && pGraphics)
156 { // check we have the right bitmap cached.
157 double fScale = 1.0;
158 pGraphics->ShouldDownscaleIconsAtSurface(&fScale);
159 Size aTarget(maSizePixel.Width()*fScale,
160 maSizePixel.Height()*fScale);
161 if (maBitmapEx.GetSizePixel() != aTarget)
162 {
163 if (isStock())
164 loadStockAtScale(pGraphics, maBitmapEx);
165 else // if (mxMetaFile)
166 {
168
169 // Fix white background in font color and font background color
170 // in the Breeze icons by setting the alpha mask to transparent
171 bool bAlphaMaskTransparent = true;
172#if HAVE_FEATURE_SKIA
174 bAlphaMaskTransparent = false;
175#endif
176 aVDev->SetOutputSizePixel(aTarget, true, bAlphaMaskTransparent);
177 mxMetaFile->WindStart();
178 mxMetaFile->Play(*aVDev, Point(), aTarget);
179 maBitmapEx = aVDev->GetBitmapEx(Point(), aTarget);
180 }
181 }
182 }
183 return getBitmapEx(bDisabled);
184}
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImageLoadFlags
Definition: ImageTree.hxx:32
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:638
BitmapChecksum GetChecksum() const
Definition: BitmapEx.cxx:239
bool IsEmpty() const
Definition: BitmapEx.cxx:186
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
static VCL_DLLPUBLIC ImageTree & get()
Definition: ImageTree.cxx:16
BitmapChecksum maBitmapChecksum
Definition: image.h:31
BitmapEx const & getBitmapEx(bool bDisabled=false)
Legacy - the original bitmap.
Definition: ImplImage.cxx:123
BitmapEx maBitmapEx
Original bitmap - or cache of a potentially scaled bitmap.
Definition: image.h:40
bool isSizeEmpty() const
Definition: image.h:68
bool isStock() const
Definition: image.h:50
BitmapEx maDisabledBitmapEx
Definition: image.h:41
Size maSizePixel
if non-empty: cached original size of maStockName else Size of maBitmap
Definition: image.h:33
Size getSizePixel()
get size in co-ordinates not scaled for HiDPI
Definition: ImplImage.cxx:102
bool loadStockAtScale(SalGraphics *pGraphics, BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:56
BitmapEx const & getBitmapExForHiDPI(bool bDisabled, SalGraphics *pGraphics)
Taking account of HiDPI scaling.
Definition: ImplImage.cxx:153
ImplImage(const BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:36
std::unique_ptr< GDIMetaFile > mxMetaFile
rare case of dynamically created Image contents
Definition: image.h:37
bool isEqual(const ImplImage &ref) const
Definition: ImplImage.cxx:143
OUString maStockName
If set - defines the bitmap via images.zip*.
Definition: image.h:35
virtual bool ShouldDownscaleIconsAtSurface(double *pScaleOut) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
OUString DetermineIconTheme() const
Determine which icon theme should be used.
float u
#define SAL_WARN(area, stream)
VCL_DLLPUBLIC bool isAlphaMaskBlendingEnabled()
VCL_DLLPUBLIC bool isVCLSkiaEnabled()