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 #ifndef INCLUDED_VCL_INC_IMPGRAPH_HXX
21 #define INCLUDED_VCL_INC_IMPGRAPH_HXX
22 
24 #include <vcl/gdimtf.hxx>
25 #include <vcl/graph.hxx>
26 #include "graphic/Manager.hxx"
27 
29 {
33 
35  bool mbIsEPS;
37  bool mbIsAlpha;
38 
40 };
41 
42 class OutputDevice;
43 class GfxLink;
44 struct ImpSwapFile;
46 class ImpGraphic;
47 
48 class GraphicID
49 {
50 private:
51  sal_uInt32 mnID1;
52  sal_uInt32 mnID2;
53  sal_uInt32 mnID3;
55 
56 public:
57  GraphicID(ImpGraphic const & rGraphic);
58 
59  bool operator==(const GraphicID& rID) const
60  {
61  return rID.mnID1 == mnID1 && rID.mnID2 == mnID2 &&
62  rID.mnID3 == mnID3 && rID.mnID4 == mnID4;
63  }
64 
65  OString getIDString() const;
66 };
67 
68 class ImpGraphic final
69 {
70  friend class Graphic;
71  friend class GraphicID;
72  friend class vcl::graphic::Manager;
73 
74 private:
75 
79  std::unique_ptr<Animation> mpAnimation;
80  std::shared_ptr<GraphicReader> mpContext;
81  std::shared_ptr<ImpSwapFile> mpSwapFile;
82  std::shared_ptr<GfxLink> mpGfxLink;
85  bool mbSwapOut;
88  // cache checksum computation
90 
94  std::shared_ptr<std::vector<sal_Int8>> mpPdfData;
95  std::unique_ptr<GraphicID> mpGraphicID;
97 
98  std::chrono::high_resolution_clock::time_point maLastUsed;
99  bool mbPrepared;
100 
104  sal_Int32 mnPageNumber;
105 
106 public:
107  ImpGraphic();
108  ImpGraphic( const ImpGraphic& rImpGraphic );
109  ImpGraphic( ImpGraphic&& rImpGraphic ) noexcept;
110  ImpGraphic( const GraphicExternalLink& rExternalLink);
111  ImpGraphic( const Bitmap& rBmp );
112  ImpGraphic( const BitmapEx& rBmpEx );
113  ImpGraphic(const VectorGraphicDataPtr& rVectorGraphicDataPtr);
114  ImpGraphic( const Animation& rAnimation );
115  ImpGraphic( const GDIMetaFile& rMtf );
116  ~ImpGraphic();
117 
118  void ImplSetPrepared(bool bAnimated, const Size* pSizeHint);
119 
120 private:
121 
122  ImpGraphic& operator=( const ImpGraphic& rImpGraphic );
123  ImpGraphic& operator=( ImpGraphic&& rImpGraphic );
124  bool operator==( const ImpGraphic& rImpGraphic ) const;
125  bool operator!=( const ImpGraphic& rImpGraphic ) const { return !( *this == rImpGraphic ); }
126 
127  OUString const & getOriginURL() const
128  {
129  return maGraphicExternalLink.msURL;
130  }
131 
132  void setOriginURL(OUString const & rOriginURL)
133  {
134  maGraphicExternalLink.msURL = rOriginURL;
135  }
136 
137  OString getUniqueID()
138  {
139  if (!mpGraphicID)
140  mpGraphicID.reset(new GraphicID(*this));
141  return mpGraphicID->getIDString();
142  }
143 
144  bool hasPdfData() const
145  {
146  return mpPdfData && !mpPdfData->empty();
147  }
148 
149  void ImplCreateSwapInfo();
150  void ImplClearGraphics();
151  void ImplClear();
152 
153  GraphicType ImplGetType() const { return meType;}
154  void ImplSetDefaultType();
155  bool ImplIsSupportedGraphic() const;
156 
157  bool ImplIsTransparent() const;
158  bool ImplIsAlpha() const;
159  bool ImplIsAnimated() const;
160  bool ImplIsEPS() const;
161 
162  bool isAvailable() const;
163  bool makeAvailable();
164 
165  Bitmap ImplGetBitmap(const GraphicConversionParameters& rParameters) const;
166  BitmapEx ImplGetBitmapEx(const GraphicConversionParameters& rParameters) const;
168  const BitmapEx& ImplGetBitmapExRef() const;
169  Animation ImplGetAnimation() const;
170  const GDIMetaFile& ImplGetGDIMetaFile() const;
171 
172  Size ImplGetSizePixel() const;
173 
174  Size ImplGetPrefSize() const;
175  void ImplSetPrefSize( const Size& rPrefSize );
176 
177  MapMode ImplGetPrefMapMode() const;
178  void ImplSetPrefMapMode( const MapMode& rPrefMapMode );
179 
180  sal_uLong ImplGetSizeBytes() const;
181 
182  void ImplDraw( OutputDevice* pOutDev,
183  const Point& rDestPt ) const;
184  void ImplDraw( OutputDevice* pOutDev,
185  const Point& rDestPt,
186  const Size& rDestSize ) const;
187 
188  void ImplStartAnimation( OutputDevice* pOutDev,
189  const Point& rDestPt,
190  const Size& rDestSize,
191  long nExtraData,
192  OutputDevice* pFirstFrameOutDev );
193  void ImplStopAnimation( OutputDevice* pOutputDevice,
194  long nExtraData );
195 
198 
199  sal_uInt32 ImplGetAnimationLoopCount() const;
200 
201 private:
202 
203  std::shared_ptr<GraphicReader>& ImplGetContext() { return mpContext;}
204  void ImplSetContext( const std::shared_ptr<GraphicReader>& pReader );
205  void ImplSetDummyContext( bool value ) { mbDummyContext = value; }
206  bool ImplReadEmbedded( SvStream& rIStream );
207  bool ImplWriteEmbedded( SvStream& rOStream );
208 
209  bool ImplSwapIn();
210  bool ImplSwapIn( SvStream* pIStm );
211 
212  bool ImplSwapOut();
213  bool ImplSwapOut( SvStream* pOStm );
214 
215  bool ImplIsSwapOut() const { return mbSwapOut;}
216  bool ImplIsDummyContext() const { return mbDummyContext; }
217  void ImplSetLink( const std::shared_ptr<GfxLink>& );
218  std::shared_ptr<GfxLink> ImplGetSharedGfxLink() const;
220  bool ImplIsLink() const;
221 
223 
224  bool ImplExportNative( SvStream& rOStm ) const;
225 
226  friend void WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic);
227  friend void ReadImpGraphic(SvStream& rIStm, ImpGraphic& rImpGraphic);
228 
230 
231  const std::shared_ptr<std::vector<sal_Int8>> & getPdfData() const;
232 
233  void setPdfData(const std::shared_ptr<std::vector<sal_Int8>>& rPdfData);
234 
235  bool ensureAvailable () const;
236 
237  bool loadPrepared();
238 };
239 
240 #endif // INCLUDED_VCL_INC_IMPGRAPH_HXX
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapEx maEx
Definition: impgraph.hxx:77
bool mbDummyContext
Definition: impgraph.hxx:86
const GDIMetaFile & ImplGetGDIMetaFile() const
Definition: impgraph.cxx:837
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
std::shared_ptr< GraphicReader > mpContext
Definition: impgraph.hxx:80
bool operator==(const GraphicID &rID) const
Definition: impgraph.hxx:59
Bitmap ImplGetBitmap(const GraphicConversionParameters &rParameters) const
Definition: impgraph.cxx:671
MapMode ImplGetPrefMapMode() const
Definition: impgraph.cxx:1003
const BitmapEx & ImplGetBitmapExRef() const
Gives direct access to the contained BitmapEx.
Definition: impgraph.cxx:831
bool mbIsTransparent
Definition: impgraph.hxx:36
sal_uInt32 mnID1
Definition: impgraph.hxx:51
sal_uIntPtr sal_uLong
bool ImplSwapOut()
Definition: impgraph.cxx:1461
void ImplSetPrefMapMode(const MapMode &rPrefMapMode)
Definition: impgraph.cxx:1048
GraphicID(ImpGraphic const &rGraphic)
Definition: impgraph.cxx:107
GraphicType
Definition: graph.hxx:36
BitmapChecksum mnID4
Definition: impgraph.hxx:54
bool mbIsAlpha
Definition: impgraph.hxx:37
bool ImplWriteEmbedded(SvStream &rOStream)
Definition: impgraph.cxx:1383
bool ensureAvailable() const
Definition: impgraph.cxx:1554
sal_uInt32 mnID2
Definition: impgraph.hxx:52
bool mbSwapOut
Definition: impgraph.hxx:85
std::shared_ptr< GfxLink > ImplGetSharedGfxLink() const
Definition: impgraph.cxx:1684
OUString const & getOriginURL() const
Definition: impgraph.hxx:127
bool ImplReadEmbedded(SvStream &rIStream)
Definition: impgraph.cxx:1249
sal_uInt32 mnAnimationLoopCount
Definition: impgraph.hxx:39
void ImplStartAnimation(OutputDevice *pOutDev, const Point &rDestPt, const Size &rDestSize, long nExtraData, OutputDevice *pFirstFrameOutDev)
Definition: impgraph.cxx:1197
sal_uInt32 ImplGetAnimationLoopCount() const
Definition: impgraph.cxx:1235
GraphicType meType
Definition: impgraph.hxx:83
BitmapChecksum ImplGetChecksum() const
Definition: impgraph.cxx:1701
bool ImplIsTransparent() const
Definition: impgraph.cxx:610
Size maPrefSize
Definition: impgraph.hxx:31
const std::shared_ptr< std::vector< sal_Int8 > > & getPdfData() const
Definition: impgraph.cxx:481
bool makeAvailable()
Definition: impgraph.cxx:666
std::unique_ptr< Animation > mpAnimation
Definition: impgraph.hxx:79
std::shared_ptr< ImpSwapFile > mpSwapFile
Definition: impgraph.hxx:81
void setOriginURL(OUString const &rOriginURL)
Definition: impgraph.hxx:132
OString getIDString() const
Definition: impgraph.cxx:166
bool loadPrepared()
Definition: impgraph.cxx:1565
std::shared_ptr< std::vector< sal_Int8 > > mpPdfData
The PDF stream from which this Graphic is rendered, as converted (version downgraded) from the origin...
Definition: impgraph.hxx:94
GDIMetaFile maMetaFile
Definition: impgraph.hxx:76
void ImplClear()
Definition: impgraph.cxx:584
BitmapEx ImplGetBitmapEx(const GraphicConversionParameters &rParameters) const
Definition: impgraph.cxx:781
std::shared_ptr< GraphicReader > & ImplGetContext()
Definition: impgraph.hxx:203
void ImplSetPrepared(bool bAnimated, const Size *pSizeHint)
Definition: impgraph.cxx:536
void ImplSetAnimationNotifyHdl(const Link< Animation *, void > &rLink)
Definition: impgraph.cxx:1215
BitmapChecksum mnChecksum
Definition: impgraph.hxx:89
friend void WriteImpGraphic(SvStream &rOStm, const ImpGraphic &rImpGraphic)
Definition: impgraph.cxx:1948
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
bool ImplExportNative(SvStream &rOStm) const
Definition: impgraph.cxx:1742
sal_uLong mnSizeBytes
Definition: impgraph.hxx:84
GraphicType ImplGetType() const
Definition: impgraph.hxx:153
OString getUniqueID()
Definition: impgraph.hxx:137
bool ImplIsAnimated() const
Definition: impgraph.cxx:646
Link< Animation *, void > ImplGetAnimationNotifyHdl() const
Definition: impgraph.cxx:1223
bool ImplIsEPS() const
Definition: impgraph.cxx:651
bool mbPrepared
Definition: impgraph.hxx:99
std::shared_ptr< GfxLink > mpGfxLink
Definition: impgraph.hxx:82
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
Size ImplGetPrefSize() const
Definition: impgraph.cxx:914
std::chrono::high_resolution_clock::time_point maLastUsed
Definition: impgraph.hxx:98
const VectorGraphicDataPtr & getVectorGraphicData() const
Definition: impgraph.cxx:467
void ImplSetLink(const std::shared_ptr< GfxLink > &)
Definition: impgraph.cxx:1677
sal_Int32 mnPageNumber
Used with GfxLink and/or PdfData when they store original media which might be multi-page (PDF...
Definition: impgraph.hxx:104
void ImplDraw(OutputDevice *pOutDev, const Point &rDestPt) const
Definition: impgraph.cxx:1120
void ImplClearGraphics()
Definition: impgraph.cxx:502
std::unique_ptr< GraphicID > mpGraphicID
Definition: impgraph.hxx:95
bool ImplIsDummyContext() const
Definition: impgraph.hxx:216
sal_uLong ImplGetSizeBytes() const
Definition: impgraph.cxx:1088
void ImplSetDummyContext(bool value)
Definition: impgraph.hxx:205
ImpSwapInfo maSwapInfo
Definition: impgraph.hxx:78
bool mbIsAnimated
Definition: impgraph.hxx:34
bool ImplIsSwapOut() const
Definition: impgraph.hxx:215
Size ImplGetSizePixel() const
Definition: impgraph.cxx:902
Animation ImplGetAnimation() const
Definition: impgraph.cxx:820
void ImplStopAnimation(OutputDevice *pOutputDevice, long nExtraData)
Definition: impgraph.cxx:1207
void ImplCreateSwapInfo()
Definition: impgraph.cxx:488
sal_uInt32 mnID3
Definition: impgraph.hxx:53
void ImplSetDefaultType()
Definition: impgraph.cxx:599
bool isAvailable() const
Definition: impgraph.cxx:661
friend class GraphicID
Definition: impgraph.hxx:71
bool ImplIsLink() const
Definition: impgraph.cxx:1696
bool mbIsEPS
Definition: impgraph.hxx:35
void ImplSetContext(const std::shared_ptr< GraphicReader > &pReader)
Definition: impgraph.cxx:1243
bool hasPdfData() const
Definition: impgraph.hxx:144
void ImplSetPrefSize(const Size &rPrefSize)
Definition: impgraph.cxx:963
GraphicExternalLink maGraphicExternalLink
Definition: impgraph.hxx:96
GfxLink ImplGetLink()
Definition: impgraph.cxx:1689
MapMode maPrefMapMode
Definition: impgraph.hxx:30
bool ImplIsSupportedGraphic() const
Definition: impgraph.cxx:605
void setPdfData(const std::shared_ptr< std::vector< sal_Int8 >> &rPdfData)
Definition: impgraph.cxx:474
VectorGraphicDataPtr maVectorGraphicData
Definition: impgraph.hxx:87
friend void ReadImpGraphic(SvStream &rIStm, ImpGraphic &rImpGraphic)
Definition: impgraph.cxx:1769
bool ImplIsAlpha() const
Definition: impgraph.cxx:626
Size maSizePixel
Definition: impgraph.hxx:32
bool ImplSwapIn()
Definition: impgraph.cxx:1587