Coverage Report

Created: 2026-06-30 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qt/qtsvg/src/svg/qsvgfont_p.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#ifndef QSVGFONT_P_H
7
#define QSVGFONT_P_H
8
9
//
10
//  W A R N I N G
11
//  -------------
12
//
13
// This file is not part of the Qt API.  It exists purely as an
14
// implementation detail.  This header file may change from version to
15
// version without notice, or even be removed.
16
//
17
// We mean it.
18
//
19
20
#include <QtCore/qhash.h>
21
#include "qpainterpath.h"
22
#include "qlist.h"
23
#include "qstring.h"
24
25
#include "qsvgstyle_p.h"
26
27
#include <memory>
28
29
QT_BEGIN_NAMESPACE
30
31
class Q_SVG_EXPORT QSvgGlyph
32
{
33
public:
34
    QSvgGlyph(const QString &unicode, const QPainterPath &path, qreal horizAdvX);
35
0
    QSvgGlyph() : m_horizAdvX(0) {}
36
37
    QString m_unicode;
38
    QPainterPath m_path;
39
    qreal m_horizAdvX;
40
};
41
42
43
class Q_SVG_EXPORT QSvgFont : public QSvgRefCounted
44
{
45
public:
46
    QSvgFont(qreal horizAdvX);
47
    ~QSvgFont() override;
48
49
    void setFamilyName(const QString &name);
50
    QString familyName() const;
51
52
    void setUnitsPerEm(qreal upem);
53
54
    void addGlyph(const QString &unicode, const QPainterPath &path, qreal horizAdvX = -1);
55
    bool addMissingGlyph(const QPainterPath &path, qreal horizAdvX);
56
57
    void draw(QPainter *p, const QPointF &point, const QList<const QSvgGlyph *> &glyphs,
58
              qreal pixelSize, Qt::Alignment alignment) const;
59
    QRectF boundingRect(QPainter *p, const QPointF &point, const QList<const QSvgGlyph *> &glyphs,
60
                        qreal pixelSize, Qt::Alignment alignment) const;
61
    const QSvgGlyph *findFirstGlyphFor(QStringView text) const;
62
    QList<const QSvgGlyph *> toGlyphs(QStringView text) const;
63
64
public:
65
    QString m_familyName;
66
    qreal m_unitsPerEm{1000};
67
    qreal m_horizAdvX;
68
    // not about a missing <glyph> element, but the font's <missing-glyph> element:
69
    std::unique_ptr<const QSvgGlyph> m_missingGlyph;
70
    // The following needs to preserve the order of glyphs because
71
    // "17.6 Glyph selection rules" in SVG Tiny 1.2 reads:
72
    // "the 'font' element must be searched from its first
73
    // 'glyph' element to its last in logical order"
74
    QList<QSvgGlyph> m_glyphs;
75
76
private:
77
    // to speed up finding glyphs
78
    mutable QHash<char32_t, QList<qsizetype>> m_possibleGlyphIndicesForChar;
79
    mutable qsizetype m_firstUnscannedGlyphIdx = 0;
80
81
    void draw_helper(QPainter *p, const QPointF &point,
82
                     const QList<const QSvgGlyph *> &glyphs, qreal pixelSize,
83
                     Qt::Alignment alignment, QRectF *boundingRect = nullptr) const;
84
};
85
86
QT_END_NAMESPACE
87
88
#endif // QSVGFONT_P_H