1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <vcl/dllapi.h>
23 #include <vcl/GraphicExternalLink.hxx>
24 #include <vcl/gdimtf.hxx>
25 #include <vcl/graph.hxx>
26 #include "graphic/Manager.hxx"
27 #include "graphic/GraphicID.hxx"
32 MapMode maPrefMapMode
;
41 sal_uInt32 mnAnimationLoopCount
;
42 sal_Int32 mnPageIndex
;
48 class GraphicConversionParameters
;
50 namespace rtl
{ class OStringBuffer
; }
52 enum class GraphicContentType
: sal_Int32
59 class VCL_DLLPUBLIC ImpGraphic final
62 friend class GraphicID
;
63 friend class vcl::graphic::Manager
;
67 GDIMetaFile maMetaFile
;
69 /// If maBitmapEx is empty, this preferred size will be set on it when it gets initialized.
71 ImpSwapInfo maSwapInfo
;
72 std::unique_ptr
<Animation
> mpAnimation
;
73 std::shared_ptr
<GraphicReader
> mpContext
;
74 std::shared_ptr
<ImpSwapFile
> mpSwapFile
;
75 std::shared_ptr
<GfxLink
> mpGfxLink
;
77 mutable sal_uLong mnSizeBytes
;
80 std::shared_ptr
<VectorGraphicData
> maVectorGraphicData
;
81 // cache checksum computation
82 mutable BitmapChecksum mnChecksum
= 0;
84 std::optional
<GraphicID
> mxGraphicID
;
85 GraphicExternalLink maGraphicExternalLink
;
87 std::chrono::high_resolution_clock::time_point maLastUsed
;
92 ImpGraphic( const ImpGraphic
& rImpGraphic
);
93 ImpGraphic( ImpGraphic
&& rImpGraphic
) noexcept
;
94 ImpGraphic( GraphicExternalLink aExternalLink
);
95 ImpGraphic(std::shared_ptr
<GfxLink
> xGfxLink
, sal_Int32 nPageIndex
= 0);
96 ImpGraphic( const BitmapEx
& rBmpEx
);
97 ImpGraphic(const std::shared_ptr
<VectorGraphicData
>& rVectorGraphicDataPtr
);
98 ImpGraphic( const Animation
& rAnimation
);
99 ImpGraphic( const GDIMetaFile
& rMtf
);
102 void setPrepared(bool bAnimated
, const Size
* pSizeHint
);
106 ImpGraphic
& operator=( const ImpGraphic
& rImpGraphic
);
107 ImpGraphic
& operator=( ImpGraphic
&& rImpGraphic
);
108 bool operator==( const ImpGraphic
& rImpGraphic
) const;
109 bool operator!=( const ImpGraphic
& rImpGraphic
) const { return !( *this == rImpGraphic
); }
111 OUString
const & getOriginURL() const
113 return maGraphicExternalLink
.msURL
;
116 void setOriginURL(OUString
const & rOriginURL
)
118 maGraphicExternalLink
.msURL
= rOriginURL
;
121 OString
getUniqueID()
124 mxGraphicID
.emplace(*this);
125 return mxGraphicID
->getIDString();
128 void createSwapInfo();
129 void restoreFromSwapInfo();
131 void clearGraphics();
134 GraphicType
getType() const { return meType
;}
135 void setDefaultType();
136 bool isSupportedGraphic() const;
138 bool isTransparent() const;
139 bool isAlpha() const;
140 bool isAnimated() const;
143 bool isAvailable() const;
144 bool makeAvailable();
146 Bitmap
getBitmap(const GraphicConversionParameters
& rParameters
) const;
147 BitmapEx
getBitmapEx(const GraphicConversionParameters
& rParameters
) const;
148 /// Gives direct access to the contained BitmapEx.
149 const BitmapEx
& getBitmapExRef() const;
150 Animation
getAnimation() const;
151 const GDIMetaFile
& getGDIMetaFile() const;
153 Size
getSizePixel() const;
155 Size
getPrefSize() const;
156 void setPrefSize( const Size
& rPrefSize
);
158 MapMode
getPrefMapMode() const;
159 void setPrefMapMode( const MapMode
& rPrefMapMode
);
161 sal_uLong
getSizeBytes() const;
163 void draw(OutputDevice
& rOutDev
, const Point
& rDestPt
) const;
164 void draw(OutputDevice
& rOutDev
, const Point
& rDestPt
,
165 const Size
& rDestSize
) const;
167 void startAnimation(OutputDevice
& rOutDev
,
168 const Point
& rDestPt
,
169 const Size
& rDestSize
,
170 tools::Long nRendererId
,
171 OutputDevice
* pFirstFrameOutDev
);
172 void stopAnimation( const OutputDevice
* pOutputDevice
,
173 tools::Long nRendererId
);
175 void setAnimationNotifyHdl( const Link
<Animation
*,void>& rLink
);
176 Link
<Animation
*,void> getAnimationNotifyHdl() const;
178 sal_uInt32
getAnimationLoopCount() const;
182 bool swapInFromStream(SvStream
& rStream
);
183 bool swapInGraphic(SvStream
& rStream
);
185 bool swapInContent(SvStream
& rStream
);
186 bool swapOutContent(SvStream
& rStream
);
187 bool swapOutGraphic(SvStream
& rStream
);
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() const;
197 bool isGfxLink() const;
199 BitmapChecksum
getChecksum() const;
201 const std::shared_ptr
<VectorGraphicData
>& getVectorGraphicData() const;
203 /// Gets the bitmap replacement for a vector graphic.
204 BitmapEx
getVectorGraphicReplacement() const;
206 bool ensureAvailable () const;
208 sal_Int32
getPageNumber() const;
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
);
216 void resetChecksum() { mnChecksum
= 0; }
219 bool isSwappedOut() const { return mbSwapOut
; }
220 SvStream
* getSwapFileStream() const;
221 // public only because of use in GraphicFilter
222 void updateFromLoadedGraphic(const ImpGraphic
* graphic
);
223 void dumpState(rtl::OStringBuffer
&rState
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */