Coverage Report

Created: 2025-07-07 10:01

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