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>
30#include <comphelper/lok.hxx>
31
32#include <image.h>
33#include <salgdi.hxx>
34
36 : maBitmapChecksum(0)
37 , maSizePixel(rBitmapEx.GetSizePixel())
38 , maBitmapEx(rBitmapEx)
39{
40}
41
42ImplImage::ImplImage(OUString aStockName)
43 : maBitmapChecksum(0)
44 , maStockName(std::move(aStockName))
45{
46}
47
49 : maBitmapChecksum(0)
50 , maSizePixel(rMetaFile.GetPrefSize())
51 , mxMetaFile(new GDIMetaFile(rMetaFile))
52{
53}
54
56{
57 BitmapEx aBitmapEx;
58
60 sal_Int32 nScalePercentage = -1;
61
62 double fScale(1.0);
63 if (pGraphics && pGraphics->ShouldDownscaleIconsAtSurface(&fScale)) // scale at the surface
64 {
65 nScalePercentage = fScale * 100.0;
67 }
68
70 if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
71 nScalePercentage, eScalingFlags))
72 {
73 /* If the uno command has parameters, passed in from a toolbar,
74 * recover from failure by removing the parameters from the file name
75 */
76 if (maStockName.indexOf("%3f") > 0)
77 {
78 sal_Int32 nStart = maStockName.indexOf("%3f");
79 sal_Int32 nEnd = maStockName.lastIndexOf(".");
80
81 OUString aFileName = maStockName.replaceAt(nStart, nEnd - nStart, u"");
82 if (!ImageTree::get().loadImage(aFileName, aIconTheme, aBitmapEx, true,
83 nScalePercentage, eScalingFlags))
84 {
85 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
86 " and " << aFileName << " at " << fScale);
87 return false;
88 }
89 }
90 else
91 {
92 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
93 " at " << fScale);
94 return false;
95 }
96 }
97 rBitmapEx = aBitmapEx;
98 return true;
99}
100
102{
103 Size aRet;
104 if (!isSizeEmpty())
105 aRet = maSizePixel;
106 else if (isStock())
107 {
108 if (loadStockAtScale(nullptr, maBitmapEx))
109 {
110 assert(maDisabledBitmapEx.IsEmpty());
111 assert(maBitmapChecksum == 0);
113 aRet = maSizePixel;
114 }
115 else
116 SAL_WARN("vcl", "Failed to load stock icon " << maStockName);
117 }
118 return aRet;
119}
120
122BitmapEx const & ImplImage::getBitmapEx(bool bDisabled)
123{
124 getSizePixel(); // force load, and at unity scale.
125 if (bDisabled)
126 {
127 // Changed since we last generated this.
129 if (maBitmapChecksum != aChecksum ||
131 {
134 maBitmapChecksum = aChecksum;
135 }
136 return maDisabledBitmapEx;
137 }
138
139 return maBitmapEx;
140}
141
142bool ImplImage::isEqual(const ImplImage &ref) const
143{
144 if (isStock() != ref.isStock())
145 return false;
146 if (isStock())
147 return maStockName == ref.maStockName;
148 else
149 return maBitmapEx == ref.maBitmapEx;
150}
151
152BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled, SalGraphics* pGraphics)
153{
154 if ((isStock() || mxMetaFile) && pGraphics)
155 { // check we have the right bitmap cached.
156 double fScale = 1.0;
157 pGraphics->ShouldDownscaleIconsAtSurface(&fScale);
158 Size aTarget(maSizePixel.Width()*fScale,
159 maSizePixel.Height()*fScale);
160 if (maBitmapEx.GetSizePixel() != aTarget)
161 {
162 if (isStock())
163 loadStockAtScale(pGraphics, maBitmapEx);
164 else // if (mxMetaFile)
165 {
167 aVDev->SetOutputSizePixel(aTarget);
168 mxMetaFile->WindStart();
169 mxMetaFile->Play(*aVDev, Point(), aTarget);
170 maBitmapEx = aVDev->GetBitmapEx(Point(), aTarget);
171 }
172 }
173 }
174 return getBitmapEx(bDisabled);
175}
176
177/* 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:767
BitmapChecksum GetChecksum() const
Definition: BitmapEx.cxx:225
bool IsEmpty() const
Definition: BitmapEx.cxx:177
const Size & GetSizePixel() const
Definition: bitmapex.hxx:72
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:122
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:101
bool loadStockAtScale(SalGraphics *pGraphics, BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:55
BitmapEx const & getBitmapExForHiDPI(bool bDisabled, SalGraphics *pGraphics)
Taking account of HiDPI scaling.
Definition: ImplImage.cxx:152
ImplImage(const BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:35
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:142
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)