Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/graph.hxx
Line
Count
Source
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 <memory>
23
#include <vcl/dllapi.h>
24
#include <tools/solar.h>
25
#include <tools/gen.hxx>
26
#include <tools/long.hxx>
27
#include <rtl/ustring.hxx>
28
#include <vcl/checksum.hxx>
29
30
enum class GraphicType
31
{
32
    NONE,
33
    Bitmap,
34
    GdiMetafile,
35
    Default
36
};
37
38
namespace com::sun::star::graphic { class XGraphic; }
39
namespace vcl { class Font; }
40
namespace basegfx { class B2DSize; }
41
namespace com::sun::star::uno { template <class interface_type> class Reference; }
42
template <typename Arg, typename Ret> class Link;
43
44
class Animation;
45
class Bitmap;
46
class GDIMetaFile;
47
class GfxLink;
48
class GraphicExternalLink;
49
class ImpGraphic;
50
class MapMode;
51
class OutputDevice;
52
class VectorGraphicData;
53
54
class SAL_WARN_UNUSED VCL_DLLPUBLIC GraphicConversionParameters
55
{
56
private:
57
    Size            maSizePixel;            // default is (0,0)
58
59
    bool            mbUnlimitedSize : 1;    // default is false
60
    bool            mbAntiAliase : 1;       // default is false
61
    bool            mbSnapHorVerLines : 1;  // default is false
62
63
public:
64
    GraphicConversionParameters(
65
        const Size& rSizePixel = Size(),
66
        bool bUnlimitedSize = false,
67
        bool bAntiAliase = false,
68
        bool bSnapHorVerLines = false)
69
104k
    :   maSizePixel(rSizePixel),
70
104k
        mbUnlimitedSize(bUnlimitedSize),
71
104k
        mbAntiAliase(bAntiAliase),
72
104k
        mbSnapHorVerLines(bSnapHorVerLines)
73
104k
    {
74
104k
    }
75
76
    // data read access
77
60.4k
    const Size&     getSizePixel() const { return maSizePixel; }
78
0
    bool            getUnlimitedSize() const { return mbUnlimitedSize; }
79
0
    bool            getAntiAliase() const { return mbAntiAliase; }
80
0
    bool            getSnapHorVerLines() const { return mbSnapHorVerLines; }
81
};
82
83
class Image;
84
class VCL_DLLPUBLIC Graphic
85
{
86
private:
87
    std::shared_ptr<ImpGraphic> mxImpGraphic;
88
    SAL_DLLPRIVATE void ImplTestRefCount();
89
    basegfx::B2DSize GetPPUnit(const MapMode& unit) const;
90
91
public:
92
50.7k
    SAL_DLLPRIVATE ImpGraphic* ImplGetImpGraphic() const { return mxImpGraphic.get(); }
93
0
    SAL_DLLPRIVATE std::shared_ptr<ImpGraphic> ImplGetSharedImpGraphic() const { return mxImpGraphic; }
94
95
                    Graphic();
96
    SAL_DLLPRIVATE  Graphic(std::shared_ptr<GfxLink> const & rGfxLink, sal_Int32 nPageIndex = 0);
97
                    Graphic( const GraphicExternalLink& rGraphicLink );
98
                    Graphic( const Graphic& rGraphic );
99
                    Graphic( Graphic&& rGraphic ) noexcept;
100
                    Graphic( const Image& rImage );
101
                    Graphic( const Bitmap& rBmp );
102
                    Graphic( const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr );
103
                    Graphic( const Animation& rAnimation );
104
                    Graphic( const GDIMetaFile& rMtf );
105
                    Graphic( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic );
106
107
    Graphic&        operator=( const Graphic& rGraphic );
108
    Graphic&        operator=( Graphic&& rGraphic ) noexcept;
109
    bool            operator==( const Graphic& rGraphic ) const;
110
    bool            operator!=( const Graphic& rGraphic ) const;
111
112
    bool            IsNone() const;
113
114
    void            Clear();
115
116
    GraphicType     GetType() const;
117
    void            SetDefaultType();
118
    bool            IsSupportedGraphic() const;
119
120
    bool            IsTransparent() const;
121
    bool            IsAlpha() const;
122
    bool            IsAnimated() const;
123
    SAL_DLLPRIVATE bool IsEPS() const;
124
125
    bool isAvailable() const;
126
    bool makeAvailable();
127
128
    // #i102089# Access of Bitmap potentially will have to rasterconvert the Graphic
129
    // if it is a MetaFile. To be able to control this conversion it is necessary to
130
    // allow giving parameters which control AntiAliasing and LineSnapping of the
131
    // MetaFile when played. Defaults will use a no-AAed, not snapped conversion as
132
    // before.
133
    Bitmap          GetBitmap(const GraphicConversionParameters& rParameters = GraphicConversionParameters()) const;
134
    /// Gives direct access to the contained Bitmap.
135
    const Bitmap&   GetBitmapRef() const;
136
137
    Animation       GetAnimation() const;
138
    const GDIMetaFile& GetGDIMetaFile() const;
139
140
    css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const;
141
142
    Size            GetPrefSize() const;
143
    void            SetPrefSize( const Size& rPrefSize );
144
145
    MapMode         GetPrefMapMode() const;
146
    void            SetPrefMapMode( const MapMode& rPrefMapMode );
147
148
    /** pixels per inch i.e. DPI */
149
    basegfx::B2DSize GetPPI() const;
150
    /** pixels per meter */
151
    basegfx::B2DSize GetPPM() const;
152
153
    Size            GetSizePixel( const OutputDevice* pRefDevice = nullptr ) const;
154
155
    sal_uLong       GetSizeBytes() const;
156
157
    void            Draw(OutputDevice& rOutDev, const Point& rDestPt,
158
                         const Size& rDestSize) const;
159
    static void     DrawEx(OutputDevice& rOutDev, const OUString& rText,
160
                           vcl::Font& rFont, const Bitmap& rBitmap,
161
                           const Point& rDestPt, const Size& rDestSize);
162
163
    void            StartAnimation(OutputDevice& rOutDev,
164
                                   const Point& rDestPt,
165
                                   const Size& rDestSize,
166
                                   tools::Long nExtraData = 0,
167
                                   OutputDevice* pFirstFrameOutDev = nullptr);
168
    void            StopAnimation( const OutputDevice* pOutputDevice,
169
                          tools::Long nExtraData );
170
171
    SAL_DLLPRIVATE void SetAnimationNotifyHdl( const Link<Animation*,void>& rLink );
172
    SAL_DLLPRIVATE Link<Animation*,void> GetAnimationNotifyHdl() const;
173
174
    SAL_DLLPRIVATE sal_uInt32 GetAnimationLoopCount() const;
175
176
    BitmapChecksum  GetChecksum() const;
177
178
    const OUString & getOriginURL() const;
179
    void setOriginURL(OUString const & rOriginURL);
180
181
    SAL_DLLPRIVATE OString getUniqueID() const;
182
183
    SAL_DLLPRIVATE void             SetDummyContext(bool value);
184
    SAL_DLLPRIVATE bool             IsDummyContext() const;
185
186
    void            SetGfxLink(const std::shared_ptr<GfxLink>& rGfxLink);
187
    const std::shared_ptr<GfxLink> & GetSharedGfxLink() const;
188
    GfxLink         GetGfxLink() const;
189
    bool            IsGfxLink() const;
190
191
    const std::shared_ptr<VectorGraphicData>& getVectorGraphicData() const;
192
193
    /// Get the page number of the multi-page source this Graphic is rendered from.
194
    sal_Int32 getPageNumber() const;
195
};
196
197
namespace std {
198
199
template <>
200
struct hash<Graphic>
201
{
202
    std::size_t operator()(Graphic const & rGraphic) const
203
0
    {
204
0
        return static_cast<std::size_t>(rGraphic.GetChecksum());
205
0
    }
206
};
207
208
} // end namespace std
209
210
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */