LibreOffice Module vcl (master)  1
impgraph.hxx
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 #pragma once
21 
22 #include <vcl/dllapi.h>
24 #include <vcl/gdimtf.hxx>
25 #include <vcl/graph.hxx>
26 #include "graphic/Manager.hxx"
27 #include "graphic/GraphicID.hxx"
28 #include <optional>
29 
31 {
35 
37  bool mbIsEPS;
39  bool mbIsAlpha;
40 
42  sal_Int32 mnPageIndex;
43 };
44 
45 class OutputDevice;
46 class GfxLink;
47 class ImpSwapFile;
49 class ImpGraphic;
50 
51 enum class GraphicContentType : sal_Int32
52 {
53  Bitmap,
54  Animation,
55  Vector
56 };
57 
59 {
60  friend class Graphic;
61  friend class GraphicID;
62  friend class vcl::graphic::Manager;
63 
64 private:
65 
71  std::unique_ptr<Animation> mpAnimation;
72  std::shared_ptr<GraphicReader> mpContext;
73  std::shared_ptr<ImpSwapFile> mpSwapFile;
74  std::shared_ptr<GfxLink> mpGfxLink;
77  bool mbSwapOut;
79  std::shared_ptr<VectorGraphicData> maVectorGraphicData;
80  // cache checksum computation
81  mutable BitmapChecksum mnChecksum = 0;
82 
83  std::optional<GraphicID> mxGraphicID;
85 
86  std::chrono::high_resolution_clock::time_point maLastUsed;
87  bool mbPrepared;
88 
89 public:
90  ImpGraphic();
91  ImpGraphic( const ImpGraphic& rImpGraphic );
92  ImpGraphic( ImpGraphic&& rImpGraphic ) noexcept;
93  ImpGraphic( const GraphicExternalLink& rExternalLink);
94  ImpGraphic(std::shared_ptr<GfxLink> const& rGfxLink, sal_Int32 nPageIndex = 0);
95  ImpGraphic( const BitmapEx& rBmpEx );
96  ImpGraphic(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
97  ImpGraphic( const Animation& rAnimation );
98  ImpGraphic( const GDIMetaFile& rMtf );
99  ~ImpGraphic();
100 
101  void setPrepared(bool bAnimated, const Size* pSizeHint);
102 
103 private:
104 
105  ImpGraphic& operator=( const ImpGraphic& rImpGraphic );
106  ImpGraphic& operator=( ImpGraphic&& rImpGraphic );
107  bool operator==( const ImpGraphic& rImpGraphic ) const;
108  bool operator!=( const ImpGraphic& rImpGraphic ) const { return !( *this == rImpGraphic ); }
109 
110  OUString const & getOriginURL() const
111  {
112  return maGraphicExternalLink.msURL;
113  }
114 
115  void setOriginURL(OUString const & rOriginURL)
116  {
117  maGraphicExternalLink.msURL = rOriginURL;
118  }
119 
120  OString getUniqueID()
121  {
122  if (!mxGraphicID)
123  mxGraphicID.emplace(*this);
124  return mxGraphicID->getIDString();
125  }
126 
127  void createSwapInfo();
128  void restoreFromSwapInfo();
129 
130  void clearGraphics();
131  void clear();
132 
133  GraphicType getType() const { return meType;}
134  void setDefaultType();
135  bool isSupportedGraphic() const;
136 
137  bool isTransparent() const;
138  bool isAlpha() const;
139  bool isAnimated() const;
140  bool isEPS() const;
141 
142  bool isAvailable() const;
143  bool makeAvailable();
144 
145  Bitmap getBitmap(const GraphicConversionParameters& rParameters) const;
146  BitmapEx getBitmapEx(const GraphicConversionParameters& rParameters) const;
148  const BitmapEx& getBitmapExRef() const;
149  Animation getAnimation() const;
150  const GDIMetaFile& getGDIMetaFile() const;
151 
152  Size getSizePixel() const;
153 
154  Size getPrefSize() const;
155  void setPrefSize( const Size& rPrefSize );
156 
157  MapMode getPrefMapMode() const;
158  void setPrefMapMode( const MapMode& rPrefMapMode );
159 
160  sal_uLong getSizeBytes() const;
161 
162  void draw(OutputDevice& rOutDev, const Point& rDestPt) const;
163  void draw(OutputDevice& rOutDev, const Point& rDestPt,
164  const Size& rDestSize) const;
165 
166  void startAnimation(OutputDevice& rOutDev,
167  const Point& rDestPt,
168  const Size& rDestSize,
169  tools::Long nExtraData,
170  OutputDevice* pFirstFrameOutDev);
171  void stopAnimation( const OutputDevice* pOutputDevice,
172  tools::Long nExtraData );
173 
174  void setAnimationNotifyHdl( const Link<Animation*,void>& rLink );
175  Link<Animation*,void> getAnimationNotifyHdl() const;
176 
177  sal_uInt32 getAnimationLoopCount() const;
178 
179 private:
180  // swapping methods
181  bool swapInFromStream(SvStream& rStream);
182  bool swapInGraphic(SvStream& rStream);
183 
184  bool swapInContent(SvStream& rStream);
185  bool swapOutContent(SvStream& rStream);
186  bool swapOutGraphic(SvStream& rStream);
187  // end swapping
188 
189  std::shared_ptr<GraphicReader>& getContext() { return mpContext;}
190  void setContext( const std::shared_ptr<GraphicReader>& pReader );
191  void setDummyContext( bool value ) { mbDummyContext = value; }
192  bool isDummyContext() const { return mbDummyContext; }
193  void setGfxLink( const std::shared_ptr<GfxLink>& );
194  const std::shared_ptr<GfxLink> & getSharedGfxLink() const;
195  GfxLink getGfxLink() const;
196  bool isGfxLink() const;
197 
198  BitmapChecksum getChecksum() const;
199 
200  const std::shared_ptr<VectorGraphicData>& getVectorGraphicData() const;
201 
203  BitmapEx getVectorGraphicReplacement() const;
204 
205  bool ensureAvailable () const;
206 
207  sal_Int32 getPageNumber() const;
208 
209  // Set the pref size, but don't force swap-in
210  void setValuesForPrefSize(const Size& rPrefSize);
211  // Set the pref map mode, but don't force swap-in
212  void setValuesForPrefMapMod(const MapMode& rPrefMapMode);
213 
214 public:
215  void resetChecksum() { mnChecksum = 0; }
216  bool swapIn();
217  bool swapOut();
218  bool isSwappedOut() const { return mbSwapOut; }
219  OUString getSwapFileURL() const;
220  // public only because of use in GraphicFilter
221  void updateFromLoadedGraphic(const ImpGraphic* graphic);
222 };
223 
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbDummyContext
Definition: impgraph.hxx:78
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
std::shared_ptr< GraphicReader > mpContext
Definition: impgraph.hxx:72
void resetChecksum()
Definition: impgraph.hxx:215
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
bool mbIsTransparent
Definition: impgraph.hxx:38
sal_uIntPtr sal_uLong
long Long
GraphicType
Definition: graph.hxx:34
bool mbIsAlpha
Definition: impgraph.hxx:39
bool mbSwapOut
Definition: impgraph.hxx:77
GraphicContentType
Definition: impgraph.hxx:51
std::optional< GraphicID > mxGraphicID
Definition: impgraph.hxx:83
OUString const & getOriginURL() const
Definition: impgraph.hxx:110
sal_uInt32 mnAnimationLoopCount
Definition: impgraph.hxx:41
bool isDummyContext() const
Definition: impgraph.hxx:192
GraphicType meType
Definition: impgraph.hxx:75
Size maPrefSize
Definition: impgraph.hxx:33
std::unique_ptr< Animation > mpAnimation
Definition: impgraph.hxx:71
BitmapEx maBitmapEx
Definition: impgraph.hxx:67
bool isSwappedOut() const
Definition: impgraph.hxx:218
std::shared_ptr< ImpSwapFile > mpSwapFile
Definition: impgraph.hxx:73
sal_Int32 mnPageIndex
Definition: impgraph.hxx:42
void setOriginURL(OUString const &rOriginURL)
Definition: impgraph.hxx:115
bool isAlpha(sal_Unicode c, bool bCompatible)
GDIMetaFile maMetaFile
Definition: impgraph.hxx:66
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
sal_uLong mnSizeBytes
Definition: impgraph.hxx:76
void setDummyContext(bool value)
Definition: impgraph.hxx:191
OString getUniqueID()
Definition: impgraph.hxx:120
bool mbPrepared
Definition: impgraph.hxx:87
Size maExPrefSize
If maBitmapEx is empty, this preferred size will be set on it when it gets initialized.
Definition: impgraph.hxx:69
std::shared_ptr< GfxLink > mpGfxLink
Definition: impgraph.hxx:74
std::chrono::high_resolution_clock::time_point maLastUsed
Definition: impgraph.hxx:86
std::shared_ptr< VectorGraphicData > maVectorGraphicData
Definition: impgraph.hxx:79
GraphicType getType() const
Definition: impgraph.hxx:133
ImpSwapInfo maSwapInfo
Definition: impgraph.hxx:70
std::shared_ptr< GraphicReader > & getContext()
Definition: impgraph.hxx:189
bool mbIsAnimated
Definition: impgraph.hxx:36
bool mbIsEPS
Definition: impgraph.hxx:37
GraphicExternalLink maGraphicExternalLink
Definition: impgraph.hxx:84
MapMode maPrefMapMode
Definition: impgraph.hxx:32
Size maSizePixel
Definition: impgraph.hxx:34