Coverage Report

Created: 2025-11-16 09:57

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