1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSGDEFAULTGLYPHNODE_P_P_H
41#define QSGDEFAULTGLYPHNODE_P_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <qcolor.h>
55#include <QtGui/private/qopengltextureglyphcache_p.h>
56#include <QtQuick/qsgmaterial.h>
57#include <QtQuick/qsgtexture.h>
58#include <QtQuick/qsggeometry.h>
59#include <qshareddata.h>
60#include <QtQuick/private/qsgplaintexture_p.h>
61#include <QtQuick/private/qsgrhitextureglyphcache_p.h>
62#include <qrawfont.h>
63#include <qmargins.h>
64
65QT_BEGIN_NAMESPACE
66
67class QFontEngine;
68class Geometry;
69class QSGRenderContext;
70class QSGDefaultRenderContext;
71
72class QSGTextMaskMaterial: public QSGMaterial
73{
74public:
75 QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None);
76 virtual ~QSGTextMaskMaterial();
77
78 QSGMaterialType *type() const override;
79 QSGMaterialShader *createShader() const override;
80 int compare(const QSGMaterial *other) const override;
81
82 void setColor(const QColor &c) { setColor(QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF())); }
83 void setColor(const QVector4D &color);
84 const QVector4D &color() const { return m_color; }
85
86 QSGTexture *texture() const { return m_texture; }
87
88 bool ensureUpToDate();
89
90 QTextureGlyphCache *glyphCache() const;
91 QOpenGLTextureGlyphCache *openglGlyphCache() const;
92 QSGRhiTextureGlyphCache *rhiGlyphCache() const;
93
94 void populate(const QPointF &position,
95 const QVector<quint32> &glyphIndexes, const QVector<QPointF> &glyphPositions,
96 QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine,
97 const QMargins &margins = QMargins(0, 0, 0, 0));
98
99private:
100 void init(QFontEngine::GlyphFormat glyphFormat);
101 void updateCache(QFontEngine::GlyphFormat glyphFormat);
102
103 QSGDefaultRenderContext *m_rc;
104 QSGPlainTexture *m_texture;
105 QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
106 QRawFont m_font;
107 QRhi *m_rhi;
108 QVector4D m_color;
109 QSize m_size;
110};
111
112class QSGStyledTextMaterial : public QSGTextMaskMaterial
113{
114public:
115 QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font);
116 virtual ~QSGStyledTextMaterial() { }
117
118 void setStyleShift(const QVector2D &shift) { m_styleShift = shift; }
119 const QVector2D &styleShift() const { return m_styleShift; }
120
121 void setStyleColor(const QColor &c) { m_styleColor = QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF()); }
122 void setStyleColor(const QVector4D &color) { m_styleColor = color; }
123 const QVector4D &styleColor() const { return m_styleColor; }
124
125 QSGMaterialType *type() const override;
126 QSGMaterialShader *createShader() const override;
127 int compare(const QSGMaterial *other) const override;
128
129private:
130 QVector2D m_styleShift;
131 QVector4D m_styleColor;
132};
133
134class QSGOutlinedTextMaterial : public QSGStyledTextMaterial
135{
136public:
137 QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font);
138 ~QSGOutlinedTextMaterial() { }
139
140 QSGMaterialType *type() const override;
141 QSGMaterialShader *createShader() const override;
142};
143
144QT_END_NAMESPACE
145
146#endif
147