| 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 | |
| 4 | #ifndef QSVGFONT_P_H |
| 5 | #define QSVGFONT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qpainterpath.h" |
| 19 | #include "qhash.h" |
| 20 | #include "qstring.h" |
| 21 | #include "qsvgstyle_p.h" |
| 22 | #include "qtsvgglobal_p.h" |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class Q_SVG_EXPORT QSvgGlyph |
| 27 | { |
| 28 | public: |
| 29 | QSvgGlyph(QChar unicode, const QPainterPath &path, qreal horizAdvX); |
| 30 | QSvgGlyph() : m_unicode(0), m_horizAdvX(0) {} |
| 31 | |
| 32 | QChar m_unicode; |
| 33 | QPainterPath m_path; |
| 34 | qreal m_horizAdvX; |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | class Q_SVG_EXPORT QSvgFont : public QSvgRefCounted |
| 39 | { |
| 40 | public: |
| 41 | static constexpr qreal DEFAULT_UNITS_PER_EM = 1000; |
| 42 | QSvgFont(qreal horizAdvX); |
| 43 | |
| 44 | void setFamilyName(const QString &name); |
| 45 | QString familyName() const; |
| 46 | |
| 47 | void setUnitsPerEm(qreal upem); |
| 48 | |
| 49 | void addGlyph(QChar unicode, const QPainterPath &path, qreal horizAdvX = -1); |
| 50 | |
| 51 | void draw(QPainter *p, const QPointF &point, const QString &str, |
| 52 | qreal pixelSize, Qt::Alignment alignment) const; |
| 53 | QRectF boundingRect(QPainter *p, const QPointF &point, const QString &str, |
| 54 | qreal pixelSize, Qt::Alignment alignment) const; |
| 55 | |
| 56 | public: |
| 57 | QString m_familyName; |
| 58 | qreal m_unitsPerEm = DEFAULT_UNITS_PER_EM; |
| 59 | qreal m_horizAdvX; |
| 60 | QHash<QChar, QSvgGlyph> m_glyphs; |
| 61 | |
| 62 | private: |
| 63 | void draw_helper(QPainter *p, const QPointF &point, const QString &str, qreal pixelSize, |
| 64 | Qt::Alignment alignment, QRectF *boundingRect = nullptr) const; |
| 65 | }; |
| 66 | |
| 67 | QT_END_NAMESPACE |
| 68 | |
| 69 | #endif // QSVGFONT_P_H |
| 70 | |