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 <vcl/svapp.hxx>
22 #include <vcl/bitmapex.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/BitmapFilter.hxx>
25 #include <vcl/ImageTree.hxx>
27 #include <comphelper/lok.hxx>
28 
29 #include <image.h>
30 
31 ImplImage::ImplImage(const BitmapEx &rBitmapEx)
32  : maBitmapChecksum(0)
33  , maSizePixel(rBitmapEx.GetSizePixel())
34  , maPreferedSizePixel()
35  , maBitmapEx(rBitmapEx)
36 {
37 }
38 
39 ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize)
40  : maBitmapChecksum(0)
41  , maSizePixel() // defer size lookup
42  , maPreferedSizePixel(rPreferedSize)
43  , maStockName(aStockName)
44 {
45 }
46 
47 bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
48 {
49  BitmapEx aBitmapEx;
51  if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
52  fScale * 100.0,
54  {
55  SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale);
56  return false;
57  }
58  if (maPreferedSizePixel != Size())
59  {
60  Size aScaleSize(maPreferedSizePixel.Width() * fScale, maPreferedSizePixel.Height() * fScale);
61  aBitmapEx.Scale(aScaleSize);
62  }
63  rBitmapEx = aBitmapEx;
64  return true;
65 }
66 
68 {
69  Size aRet;
70  if (!isSizeEmpty())
71  aRet = maSizePixel;
72  else if (isStock())
73  {
74  if (loadStockAtScale(1.0, maBitmapEx))
75  {
76  assert(!maDisabledBitmapEx);
77  assert(maBitmapChecksum == 0);
79  aRet = maSizePixel;
80  }
81  else
82  SAL_WARN("vcl", "Failed to load stock icon " << maStockName);
83  }
84  return aRet;
85 }
86 
88 BitmapEx const & ImplImage::getBitmapEx(bool bDisabled)
89 {
90  getSizePixel(); // force load, and at unity scale.
91  if (bDisabled)
92  {
93  // Changed since we last generated this.
95  if (maBitmapChecksum != aChecksum ||
97  {
100  maBitmapChecksum = aChecksum;
101  }
102  return maDisabledBitmapEx;
103  }
104 
105  return maBitmapEx;
106 }
107 
108 bool ImplImage::isEqual(const ImplImage &ref) const
109 {
110  if (isStock() != ref.isStock())
111  return false;
112  if (isStock())
113  return maStockName == ref.maStockName;
114  else
115  return maBitmapEx == ref.maBitmapEx;
116 }
117 
119 {
120  if (isStock())
121  { // check we have the right bitmap cached.
122  // FIXME: DPI scaling should be tied to the outdev really ...
123  double fScale = comphelper::LibreOfficeKit::getDPIScale();
124  Size aTarget(maSizePixel.Width()*fScale,
125  maSizePixel.Height()*fScale);
126  if (maBitmapEx.GetSizePixel() != aTarget)
127  loadStockAtScale(fScale, maBitmapEx);
128  }
129  return getBitmapEx(bDisabled);
130 }
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
OUString DetermineIconTheme() const
Determine which icon theme should be used.
long Height() const
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
Scale the bitmap.
Definition: bitmapex.cxx:370
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:705
BitmapChecksum GetChecksum() const
Definition: bitmapex.cxx:292
BitmapEx maBitmapEx
Original bitmap - or cache of a potentially scaled bitmap.
Definition: image.h:37
static VCL_DLLPUBLIC ImageTree & get()
Definition: ImageTree.cxx:16
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
bool isEqual(const ImplImage &ref) const
Definition: ImplImage.cxx:108
Size maPreferedSizePixel
Definition: image.h:31
bool isStock() const
Definition: image.h:46
Size maSizePixel
if non-empty: cached original size of maStockName else Size of maBitmap
Definition: image.h:30
BitmapEx const & getBitmapExForHiDPI(bool bDisabled=false)
Taking account of HiDPI scaling.
Definition: ImplImage.cxx:118
OUString maStockName
If set - defines the bitmap via images.zip*.
Definition: image.h:33
BitmapChecksum maBitmapChecksum
Definition: image.h:28
BitmapEx const & getBitmapEx(bool bDisabled=false)
Legacy - the original bitmap.
Definition: ImplImage.cxx:88
bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:47
#define SAL_WARN(area, stream)
bool isSizeEmpty() const
Definition: image.h:59
ImplImage(const BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:31
BitmapEx maDisabledBitmapEx
Definition: image.h:38
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
Size getSizePixel()
get size in co-ordinates not scaled for HiDPI
Definition: ImplImage.cxx:67