Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/vectorgraphicdata.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
#ifndef INCLUDED_VCL_VECTORGRAPHICDATA_HXX
21
#define INCLUDED_VCL_VECTORGRAPHICDATA_HXX
22
23
#include <basegfx/range/b2drange.hxx>
24
#include <vcl/bitmap.hxx>
25
#include <vcl/BinaryDataContainer.hxx>
26
#include <deque>
27
#include <algorithm>
28
#include <optional>
29
30
#include <com/sun/star/graphic/XPrimitive2D.hpp>
31
32
// helper to convert any Primitive2DSequence to a good quality Bitmap,
33
// using default parameters and graphic::XPrimitive2DRenderer
34
35
Bitmap VCL_DLLPUBLIC convertPrimitive2DSequenceToBitmap(
36
    const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
37
    const basegfx::B2DRange& rTargetRange,
38
    const sal_uInt32 nMaximumQuadraticPixels = 500000,
39
    const o3tl::Length eTargetUnit = o3tl::Length::mm100,
40
    const std::optional<Size>& rTargetDPI = std::nullopt);
41
42
43
enum class VectorGraphicDataType
44
{
45
    Svg = 0,
46
    Emf = 1,
47
    Wmf = 2,
48
    Pdf = 3
49
};
50
51
class VCL_DLLPUBLIC VectorGraphicData
52
{
53
private:
54
    // the file and length
55
    BinaryDataContainer maDataContainer;
56
57
    // on demand created content
58
    bool                        mbSequenceCreated;
59
    basegfx::B2DRange           maRange;
60
    std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > maSequence;
61
    Bitmap                      maReplacement;
62
    size_t                      mNestedBitmapSize;
63
    VectorGraphicDataType meType;
64
65
    /// If the vector format has more pages this denotes which page to render
66
    sal_Int32 mnPageIndex;
67
68
    /// Useful for PDF, which is vector-based, but still rendered to a bitmap.
69
    basegfx::B2DTuple maSizeHint;
70
71
    bool mbEnableEMFPlus = true;
72
73
    // on demand creators
74
    void ensurePdfReplacement();
75
    void ensureReplacement();
76
    void ensureSequenceAndRange();
77
78
    VectorGraphicData(const VectorGraphicData&) = delete;
79
    VectorGraphicData& operator=(const VectorGraphicData&) = delete;
80
81
public:
82
    VectorGraphicData(
83
        BinaryDataContainer aDataContainer,
84
        VectorGraphicDataType eVectorDataType,
85
        sal_Int32 nPageIndex = -1);
86
    ~VectorGraphicData();
87
88
    /// compare op
89
    bool operator==(const VectorGraphicData& rCandidate) const;
90
91
    /// data read
92
    const BinaryDataContainer& getBinaryDataContainer() const
93
56
    {
94
56
        return maDataContainer;
95
56
    }
96
97
    enum class State { UNPARSED, PARSED };
98
    std::pair<State, size_t> getSizeBytes() const;
99
100
82.8k
    const VectorGraphicDataType& getType() const { return meType; }
101
102
    /// data read and evtl. on demand creation
103
    const basegfx::B2DRange& getRange() const;
104
    const std::deque<css::uno::Reference<css::graphic::XPrimitive2D>>& getPrimitive2DSequence() const;
105
    Bitmap getBitmap(const Size& pixelSize) const;
106
    const Bitmap& getReplacement() const;
107
    BitmapChecksum GetChecksum() const;
108
109
    sal_Int32 getPageIndex() const
110
56
    {
111
56
        return std::max(sal_Int32(0), mnPageIndex);
112
56
    }
113
114
    void setPageIndex(sal_Int32 nPageIndex)
115
28
    {
116
28
        mnPageIndex = nPageIndex;
117
28
    }
118
119
    void setSizeHint(const basegfx::B2DTuple& rSizeHint)
120
5.47k
    {
121
5.47k
        maSizeHint = rSizeHint;
122
5.47k
    }
123
124
0
    const basegfx::B2DTuple& getSizeHint() const { return maSizeHint; }
125
126
0
    void setEnableEMFPlus(bool bEnableEMFPlus) { mbEnableEMFPlus = bEnableEMFPlus; }
127
128
0
    bool isPrimitiveSequenceCreated() const { return mbSequenceCreated; }
129
};
130
131
#endif // INCLUDED_VCL_VECTORGRAPHICDATA_HXX
132
133
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */