Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QTEXTUREGLYPHCACHE_P_H
6#define QTEXTUREGLYPHCACHE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <qhash.h>
21#include <qimage.h>
22#include <qobject.h>
23#include <qtransform.h>
24
25#include <private/qfontengineglyphcache_p.h>
26
27#ifndef QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH
28#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH 256
29#endif
30
31struct glyph_metrics_t;
32typedef unsigned int glyph_t;
33
34
35QT_BEGIN_NAMESPACE
36
37class QTextItemInt;
38
39class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache
40{
41public:
42 QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
43 : QFontEngineGlyphCache(format, matrix, color), m_current_fontengine(nullptr),
44 m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0)
45 { }
46
47 ~QTextureGlyphCache();
48
49 struct GlyphAndSubPixelPosition
50 {
51 GlyphAndSubPixelPosition(glyph_t g, const QFixedPoint &spp)
52 : glyph(g), subPixelPosition(spp) {}
53
54 bool operator==(const GlyphAndSubPixelPosition &other) const
55 {
56 return glyph == other.glyph && subPixelPosition == other.subPixelPosition;
57 }
58
59 glyph_t glyph;
60 QFixedPoint subPixelPosition;
61 };
62
63 struct Coord {
64 int x;
65 int y;
66 int w;
67 int h;
68
69 int baseLineX;
70 int baseLineY;
71
72 bool isNull() const
73 {
74 return w == 0 || h == 0;
75 }
76 };
77
78 bool populate(QFontEngine *fontEngine,
79 qsizetype numGlyphs,
80 const glyph_t *glyphs,
81 const QFixedPoint *positions,
82 QPainter::RenderHints renderHints = QPainter::RenderHints(),
83 bool includeGlyphCacheScale = false);
84 bool hasPendingGlyphs() const { return !m_pendingGlyphs.isEmpty(); }
85 void fillInPendingGlyphs();
86
87 virtual void createTextureData(int width, int height) = 0;
88 virtual void resizeTextureData(int width, int height) = 0;
89 virtual int glyphPadding() const { return 0; }
90
91 virtual void beginFillTexture() { }
92 virtual void fillTexture(const Coord &coord,
93 glyph_t glyph,
94 const QFixedPoint &subPixelPosition) = 0;
95 virtual void endFillTexture() { }
96
97 inline void createCache(int width, int height) {
98 m_w = width;
99 m_h = height;
100 createTextureData(width, height);
101 }
102
103 inline void resizeCache(int width, int height)
104 {
105 resizeTextureData(width, height);
106 m_w = width;
107 m_h = height;
108 }
109
110 inline bool isNull() const { return m_h == 0; }
111
112 QHash<GlyphAndSubPixelPosition, Coord> coords;
113 virtual int maxTextureWidth() const { return QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH; }
114 virtual int maxTextureHeight() const { return -1; }
115
116 QImage textureMapForGlyph(glyph_t g, const QFixedPoint &subPixelPosition) const;
117
118protected:
119 int calculateSubPixelPositionCount(glyph_t) const;
120
121 QFontEngine *m_current_fontengine;
122 QHash<GlyphAndSubPixelPosition, Coord> m_pendingGlyphs;
123
124 int m_w; // image width
125 int m_h; // image height
126 int m_cx; // current x
127 int m_cy; // current y
128 int m_currentRowHeight; // Height of last row
129};
130
131inline size_t qHash(const QTextureGlyphCache::GlyphAndSubPixelPosition &g, size_t seed = 0)
132{
133 return qHashMulti(seed,
134 g.glyph,
135 g.subPixelPosition.x.value(),
136 g.subPixelPosition.y.value());
137}
138
139
140class Q_GUI_EXPORT QImageTextureGlyphCache : public QTextureGlyphCache
141{
142public:
143 QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
144 : QTextureGlyphCache(format, matrix, color) { }
145 ~QImageTextureGlyphCache();
146
147 virtual void createTextureData(int width, int height) override;
148 virtual void resizeTextureData(int width, int height) override;
149 virtual void fillTexture(const Coord &c,
150 glyph_t glyph,
151 const QFixedPoint &subPixelPosition) override;
152
153 inline const QImage &image() const { return m_image; }
154
155private:
156 QImage m_image;
157};
158
159QT_END_NAMESPACE
160
161#endif
Combined button and popup list for selecting options.
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192
unsigned int glyph_t
#define QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH