Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtextureglyphcache_p.h
Go to the documentation of this file.
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 QTEXTUREGLYPHCACHE_P_H
5#define QTEXTUREGLYPHCACHE_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 for the convenience
12// of other Qt classes. 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 <QtGui/private/qtguiglobal_p.h>
19#include <qhash.h>
20#include <qimage.h>
21#include <qobject.h>
22#include <qtransform.h>
23
24#include <private/qfontengineglyphcache_p.h>
25
26#ifndef QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH
27#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH 256
28#endif
29
30struct glyph_metrics_t;
31typedef unsigned int glyph_t;
32
33
35
36class QTextItemInt;
37
38class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache
39{
40public:
42 : QFontEngineGlyphCache(format, matrix, color), m_current_fontengine(nullptr),
43 m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0)
44 { }
45
47
49 {
51 : glyph(g), subPixelPosition(spp) {}
52
54 {
55 return glyph == other.glyph && subPixelPosition == other.subPixelPosition;
56 }
57
60 };
61
62 struct Coord {
63 int x;
64 int y;
65 int w;
66 int h;
67
70
71 bool isNull() const
72 {
73 return w == 0 || h == 0;
74 }
75 };
76
77 bool populate(QFontEngine *fontEngine,
79 const glyph_t *glyphs,
81 QPainter::RenderHints renderHints = QPainter::RenderHints(),
82 bool includeGlyphCacheScale = false);
83 bool hasPendingGlyphs() const { return !m_pendingGlyphs.isEmpty(); }
84 void fillInPendingGlyphs();
85
86 virtual void createTextureData(int width, int height) = 0;
87 virtual void resizeTextureData(int width, int height) = 0;
88 virtual int glyphPadding() const { return 0; }
89
90 virtual void beginFillTexture() { }
91 virtual void fillTexture(const Coord &coord,
92 glyph_t glyph,
93 const QFixedPoint &subPixelPosition) = 0;
94 virtual void endFillTexture() { }
95
96 inline void createCache(int width, int height) {
97 m_w = width;
98 m_h = height;
99 createTextureData(width, height);
100 }
101
102 inline void resizeCache(int width, int height)
103 {
104 resizeTextureData(width, height);
105 m_w = width;
106 m_h = height;
107 }
108
109 inline bool isNull() const { return m_h == 0; }
110
111 QHash<GlyphAndSubPixelPosition, Coord> coords;
113 virtual int maxTextureHeight() const { return -1; }
114
115 QImage textureMapForGlyph(glyph_t g, const QFixedPoint &subPixelPosition) const;
116
117protected:
118 int calculateSubPixelPositionCount(glyph_t) const;
119
121 QHash<GlyphAndSubPixelPosition, Coord> m_pendingGlyphs;
122
123 int m_w; // image width
124 int m_h; // image height
125 int m_cx; // current x
126 int m_cy; // current y
127 int m_currentRowHeight; // Height of last row
128};
129
131{
132 return qHashMulti(seed,
133 g.glyph,
134 g.subPixelPosition.x.value(),
135 g.subPixelPosition.y.value());
136}
137
138
140{
141public:
145
146 virtual void createTextureData(int width, int height) override;
147 virtual void resizeTextureData(int width, int height) override;
148 virtual void fillTexture(const Coord &c,
149 glyph_t glyph,
150 const QFixedPoint &subPixelPosition) override;
151
152 inline const QImage &image() const { return m_image; }
153
154private:
155 QImage m_image;
156};
157
159
160#endif
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color=QColor())
const QImage & image() const
\inmodule QtGui
Definition qimage.h:37
Internal QTextItem.
QHash< GlyphAndSubPixelPosition, Coord > coords
QFontEngine * m_current_fontengine
virtual int maxTextureHeight() const
void resizeCache(int width, int height)
virtual void endFillTexture()
virtual void fillTexture(const Coord &coord, glyph_t glyph, const QFixedPoint &subPixelPosition)=0
virtual void resizeTextureData(int width, int height)=0
virtual void beginFillTexture()
void createCache(int width, int height)
QHash< GlyphAndSubPixelPosition, Coord > m_pendingGlyphs
virtual void createTextureData(int width, int height)=0
virtual int maxTextureWidth() const
QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color=QColor())
virtual int glyphPadding() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
Combined button and popup list for selecting options.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum const void GLbitfield GLsizei numGlyphs
GLint GLsizei width
GLuint color
[2]
GLboolean GLboolean g
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
const GLubyte * c
GLuint coord
GLuint GLenum matrix
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned int glyph_t
size_t qHash(const QTextureGlyphCache::GlyphAndSubPixelPosition &g, size_t seed=0)
#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH
ptrdiff_t qsizetype
Definition qtypes.h:165
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
bool operator==(const GlyphAndSubPixelPosition &other) const
GlyphAndSubPixelPosition(glyph_t g, const QFixedPoint &spp)