LibreOffice Module vcl (master)  1
graph.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_GRAPH_HXX
21 #define INCLUDED_VCL_GRAPH_HXX
22 
23 #include <memory>
24 #include <vcl/dllapi.h>
25 #include <tools/solar.h>
26 #include <rtl/ustring.hxx>
27 #include <vcl/bitmapex.hxx>
29 #include <vcl/gfxlink.hxx>
30 #include <com/sun/star/uno/Reference.hxx>
34 
35 
36 enum class GraphicType
37 {
38  NONE,
39  Bitmap,
41  Default
42 };
43 
44 namespace com { namespace sun { namespace star { namespace graphic { class XGraphic;} } } }
45 namespace vcl { class Font; }
46 
47 class Bitmap;
48 class GDIMetaFile;
49 class SvStream;
50 class ImpGraphic;
51 class OutputDevice;
52 class ReaderData;
53 
55 {
56 public:
57  virtual ~GraphicReader();
58 
59  const OUString& GetUpperFilterName() const { return maUpperName; }
60 
61  // TODO: when incompatible changes are possible again
62  // the preview size hint should be redone
63  void DisablePreviewMode();
64  void SetPreviewSize( const Size& );
65  Size GetPreviewSize() const;
66 
67 protected:
68  OUString maUpperName;
69 
70  GraphicReader();
71 private:
72  std::unique_ptr<ReaderData> mpReaderData;
73 };
74 
76 {
77 private:
78  Size const maSizePixel; // default is (0,0)
79 
80  bool const mbUnlimitedSize : 1; // default is false
81  bool const mbAntiAliase : 1; // default is false
82  bool const mbSnapHorVerLines : 1; // default is false
83 
84 public:
86  const Size& rSizePixel = Size(),
87  bool bUnlimitedSize = false,
88  bool bAntiAliase = false,
89  bool bSnapHorVerLines = false)
90  : maSizePixel(rSizePixel),
91  mbUnlimitedSize(bUnlimitedSize),
92  mbAntiAliase(bAntiAliase),
93  mbSnapHorVerLines(bSnapHorVerLines)
94  {
95  }
96 
97  // data read access
98  const Size& getSizePixel() const { return maSizePixel; }
99  bool getUnlimitedSize() const { return mbUnlimitedSize; }
100  bool getAntiAliase() const { return mbAntiAliase; }
101  bool getSnapHorVerLines() const { return mbSnapHorVerLines; }
102 };
103 
104 class Image;
106 {
107 private:
108 
109  std::shared_ptr<ImpGraphic> mxImpGraphic;
110 
111 public:
112 
113  SAL_DLLPRIVATE void ImplTestRefCount();
114  SAL_DLLPRIVATE ImpGraphic* ImplGetImpGraphic() const { return mxImpGraphic.get(); }
115 
116 public:
117  Graphic();
118  Graphic( const GraphicExternalLink& rGraphicLink );
119  Graphic( const Graphic& rGraphic );
120  Graphic( Graphic&& rGraphic ) noexcept;
121  Graphic( const Bitmap& rBmp );
122  Graphic( const Image& rImage );
123  Graphic( const BitmapEx& rBmpEx );
124  Graphic( const VectorGraphicDataPtr& rVectorGraphicDataPtr );
125  Graphic( const Animation& rAnimation );
126  Graphic( const GDIMetaFile& rMtf );
127  Graphic( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic );
128 
129  Graphic& operator=( const Graphic& rGraphic );
130  Graphic& operator=( Graphic&& rGraphic ) noexcept;
131  bool operator==( const Graphic& rGraphic ) const;
132  bool operator!=( const Graphic& rGraphic ) const;
133 
134  bool IsNone() const;
135 
136  void Clear();
137 
138  GraphicType GetType() const;
139  void SetDefaultType();
140  bool IsSupportedGraphic() const;
141 
142  bool IsTransparent() const;
143  bool IsAlpha() const;
144  bool IsAnimated() const;
145  bool IsEPS() const;
146 
147  bool isAvailable() const;
148  bool makeAvailable();
149 
150  // #i102089# Access of Bitmap potentially will have to rasterconvert the Graphic
151  // if it is a MetaFile. To be able to control this conversion it is necessary to
152  // allow giving parameters which control AntiAliasing and LineSnapping of the
153  // MetaFile when played. Defaults will use a no-AAed, not snapped conversion as
154  // before.
155  BitmapEx GetBitmapEx(const GraphicConversionParameters& rParameters = GraphicConversionParameters()) const;
157  const BitmapEx& GetBitmapExRef() const;
158 
159  Animation GetAnimation() const;
160  const GDIMetaFile& GetGDIMetaFile() const;
161 
162  css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const;
163 
164  Size GetPrefSize() const;
165  void SetPrefSize( const Size& rPrefSize );
166 
167  MapMode GetPrefMapMode() const;
168  void SetPrefMapMode( const MapMode& rPrefMapMode );
169 
170  basegfx::B2DSize GetPPI() const;
171 
172  Size GetSizePixel( const OutputDevice* pRefDevice = nullptr ) const;
173 
174  sal_uLong GetSizeBytes() const;
175 
176  void Draw( OutputDevice* pOutDev,
177  const Point& rDestPt ) const;
178  void Draw( OutputDevice* pOutDev,
179  const Point& rDestPt,
180  const Size& rDestSize ) const;
181  static void DrawEx( OutputDevice* pOutDev, const OUString& rText,
182  vcl::Font& rFont, const BitmapEx& rBitmap,
183  const Point& rDestPt, const Size& rDestSize );
184 
185  void StartAnimation( OutputDevice* pOutDev,
186  const Point& rDestPt,
187  const Size& rDestSize,
188  long nExtraData = 0,
189  OutputDevice* pFirstFrameOutDev = nullptr );
190  void StopAnimation( OutputDevice* pOutputDevice,
191  long nExtraData );
192 
193  void SetAnimationNotifyHdl( const Link<Animation*,void>& rLink );
194  Link<Animation*,void> GetAnimationNotifyHdl() const;
195 
196  sal_uInt32 GetAnimationLoopCount() const;
197 
198  BitmapChecksum GetChecksum() const;
199 
200  OUString getOriginURL() const;
201  void setOriginURL(OUString const & rOriginURL);
202 
203  OString getUniqueID() const;
204 
205 public:
206 
207  std::shared_ptr<GraphicReader>& GetContext();
208  void SetContext( const std::shared_ptr<GraphicReader> &pReader );
209  void SetDummyContext(bool value);
210  bool IsDummyContext() const;
211 private:
212  friend class GraphicObject;
213 
214 public:
215  void SetGfxLink(const std::shared_ptr<GfxLink>& rGfxLink);
216  std::shared_ptr<GfxLink> GetSharedGfxLink() const;
217  GfxLink GetGfxLink() const;
218  bool IsGfxLink() const;
219 
220  bool ExportNative( SvStream& rOStream ) const;
221 
222  friend VCL_DLLPUBLIC void WriteGraphic(SvStream& rOStream, const Graphic& rGraphic);
223  friend VCL_DLLPUBLIC void ReadGraphic(SvStream& rIStream, Graphic& rGraphic);
224 
225 public:
226 
227  const VectorGraphicDataPtr& getVectorGraphicData() const;
228 
229  void setPdfData(const std::shared_ptr<std::vector<sal_Int8>>& rPdfData);
230  const std::shared_ptr<std::vector<sal_Int8>> & getPdfData() const;
231  bool hasPdfData() const;
232 
234  void setPageNumber(sal_Int32 nPageNumber);
236  sal_Int32 getPageNumber() const;
237 
238  static css::uno::Sequence<sal_Int8> getUnoTunnelId();
239 };
240 
241 namespace std {
242 
243 template <>
244 struct hash<Graphic>
245 {
246  std::size_t operator()(Graphic const & rGraphic) const
247  {
248  return static_cast<std::size_t>(rGraphic.GetChecksum());
249  }
250 };
251 
252 } // end namespace std
253 
254 #endif // INCLUDED_VCL_GRAPH_HXX
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
void ReadGraphic(SvStream &rIStream, Graphic &rGraphic)
Definition: graph.cxx:547
std::shared_ptr< ImpGraphic > mxImpGraphic
Definition: graph.hxx:109
signed char sal_Int8
BitmapChecksum GetChecksum() const
Definition: graph.cxx:537
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
GraphicType
Definition: graph.hxx:36
OUString maUpperName
Definition: graph.hxx:68
std::size_t operator()(Graphic const &rGraphic) const
Definition: graph.hxx:246
bool getUnlimitedSize() const
Definition: graph.hxx:99
void DisablePreviewMode()
Definition: impgraph.cxx:86
B2DVector B2DSize
Size GetPreviewSize() const
Definition: impgraph.cxx:99
const Size & getSizePixel() const
Definition: graph.hxx:98
SAL_DLLPRIVATE ImpGraphic * ImplGetImpGraphic() const
Definition: graph.hxx:114
bool getSnapHorVerLines() const
Definition: graph.hxx:101
void WriteGraphic(SvStream &rOStream, const Graphic &rGraphic)
Definition: graph.cxx:553
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
std::unique_ptr< ReaderData > mpReaderData
Definition: graph.hxx:72
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
const OUString & GetUpperFilterName() const
Definition: graph.hxx:59
void SetPreviewSize(const Size &)
Definition: impgraph.cxx:92
Definition: image.hxx:40
GraphicConversionParameters(const Size &rSizePixel=Size(), bool bUnlimitedSize=false, bool bAntiAliase=false, bool bSnapHorVerLines=false)
Definition: graph.hxx:85
virtual ~GraphicReader()
Definition: impgraph.cxx:82
bool getAntiAliase() const
Definition: graph.hxx:100