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