| 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 QSGDEFAULTGLYPHNODE_P_P_H |
| 5 | #define QSGDEFAULTGLYPHNODE_P_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 <qcolor.h> |
| 19 | #include <QtQuick/qsgmaterial.h> |
| 20 | #include <QtQuick/qsgtexture.h> |
| 21 | #include <QtQuick/qsggeometry.h> |
| 22 | #include <qshareddata.h> |
| 23 | #include <QtQuick/private/qsgplaintexture_p.h> |
| 24 | #include <QtQuick/private/qsgrhitextureglyphcache_p.h> |
| 25 | #include <qrawfont.h> |
| 26 | #include <qmargins.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QFontEngine; |
| 31 | class Geometry; |
| 32 | class QSGRenderContext; |
| 33 | class QSGDefaultRenderContext; |
| 34 | |
| 35 | class QSGTextMaskMaterial: public QSGMaterial |
| 36 | { |
| 37 | public: |
| 38 | QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None); |
| 39 | virtual ~QSGTextMaskMaterial(); |
| 40 | |
| 41 | QSGMaterialType *type() const override; |
| 42 | QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; |
| 43 | int compare(const QSGMaterial *other) const override; |
| 44 | |
| 45 | void setColor(const QColor &c) { |
| 46 | const auto rgbC = c.toRgb(); |
| 47 | setColor(QVector4D(rgbC.redF(), rgbC.greenF(), rgbC.blueF(), rgbC.alphaF())); |
| 48 | } |
| 49 | void setColor(const QVector4D &color); |
| 50 | const QVector4D &color() const { return m_color; } |
| 51 | |
| 52 | QSGTexture *texture() const { return m_texture; } |
| 53 | |
| 54 | bool ensureUpToDate(); |
| 55 | |
| 56 | QTextureGlyphCache *glyphCache() const; |
| 57 | QSGRhiTextureGlyphCache *rhiGlyphCache() const; |
| 58 | |
| 59 | void populate(const QPointF &position, |
| 60 | const QVector<quint32> &glyphIndexes, const QVector<QPointF> &glyphPositions, |
| 61 | QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine, |
| 62 | const QMargins &margins = QMargins(0, 0, 0, 0)); |
| 63 | |
| 64 | private: |
| 65 | void init(QFontEngine::GlyphFormat glyphFormat); |
| 66 | void updateCache(QFontEngine::GlyphFormat glyphFormat); |
| 67 | |
| 68 | QSGDefaultRenderContext *m_rc; |
| 69 | QSGPlainTexture *m_texture; |
| 70 | QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache; |
| 71 | QRawFont m_font; |
| 72 | QFontEngine *m_retainedFontEngine = nullptr; |
| 73 | QRhi *m_rhi; |
| 74 | QVector4D m_color; |
| 75 | QSize m_size; |
| 76 | }; |
| 77 | |
| 78 | class QSGStyledTextMaterial : public QSGTextMaskMaterial |
| 79 | { |
| 80 | public: |
| 81 | QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font); |
| 82 | virtual ~QSGStyledTextMaterial() { } |
| 83 | |
| 84 | void setStyleShift(const QVector2D &shift) { m_styleShift = shift; } |
| 85 | const QVector2D &styleShift() const { return m_styleShift; } |
| 86 | |
| 87 | void setStyleColor(const QColor &c) { |
| 88 | const auto rgbC = c.toRgb(); |
| 89 | m_styleColor = QVector4D(rgbC.redF(), rgbC.greenF(), rgbC.blueF(), rgbC.alphaF()); |
| 90 | } |
| 91 | void setStyleColor(const QVector4D &color) { m_styleColor = color; } |
| 92 | const QVector4D &styleColor() const { return m_styleColor; } |
| 93 | |
| 94 | QSGMaterialType *type() const override; |
| 95 | QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; |
| 96 | int compare(const QSGMaterial *other) const override; |
| 97 | |
| 98 | private: |
| 99 | QVector2D m_styleShift; |
| 100 | QVector4D m_styleColor; |
| 101 | }; |
| 102 | |
| 103 | class QSGOutlinedTextMaterial : public QSGStyledTextMaterial |
| 104 | { |
| 105 | public: |
| 106 | QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font); |
| 107 | ~QSGOutlinedTextMaterial() { } |
| 108 | |
| 109 | QSGMaterialType *type() const override; |
| 110 | QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; |
| 111 | }; |
| 112 | |
| 113 | QT_END_NAMESPACE |
| 114 | |
| 115 | #endif |
| 116 | |