Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsgopenvgfontglyphcache.cpp
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
#
include
"qsgopenvgfontglyphcache.h"
5
#
include
"qsgopenvghelpers.h"
6
#
include
<
private
/
qfontengine_p
.
h
>
7
#
include
<
private
/
qrawfont_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
QSGOpenVGFontGlyphCacheManager::QSGOpenVGFontGlyphCacheManager()
12
{
13
14
}
15
16
QSGOpenVGFontGlyphCacheManager
::~
QSGOpenVGFontGlyphCacheManager
()
17
{
18
qDeleteAll(m_caches);
19
}
20
21
QSGOpenVGFontGlyphCache
*
QSGOpenVGFontGlyphCacheManager
::
cache
(
const
QRawFont &font)
22
{
23
return
m_caches.value(font,
nullptr
);
24
}
25
26
void
QSGOpenVGFontGlyphCacheManager
::
insertCache
(
const
QRawFont &font,
QSGOpenVGFontGlyphCache
*cache)
27
{
28
m_caches.insert(font, cache);
29
}
30
31
QSGOpenVGFontGlyphCache
::
QSGOpenVGFontGlyphCache
(
QSGOpenVGFontGlyphCacheManager
*manager,
const
QRawFont &font)
32
: m_manager(manager)
33
{
34
m_referenceFont = font;
35
QRawFontPrivate *fontD = QRawFontPrivate::get(font);
36
m_glyphCount = fontD->fontEngine->glyphCount();
37
m_font = vgCreateFont(0);
38
}
39
40
QSGOpenVGFontGlyphCache
::~
QSGOpenVGFontGlyphCache
()
41
{
42
if
(m_font != VG_INVALID_HANDLE)
43
vgDestroyFont(m_font);
44
}
45
46
void
QSGOpenVGFontGlyphCache
::
populate
(
const
QList<quint32> &glyphs)
47
{
48
QSet<quint32> referencedGlyphs;
49
QSet<quint32> newGlyphs;
50
int
count = glyphs.count();
51
for
(
int
i = 0; i < count; ++i) {
52
quint32 glyphIndex = glyphs.at(i);
53
if
((
int
) glyphIndex >=
glyphCount
(
)
) {
54
qWarning(
"Warning: glyph is not available with index %d"
, glyphIndex);
55
continue
;
56
}
57
58
referencedGlyphs.insert(glyphIndex);
59
60
61
if
(!m_glyphReferences.contains(glyphIndex)) {
62
newGlyphs.insert(glyphIndex);
63
}
64
}
65
66
referenceGlyphs(referencedGlyphs);
67
if
(!newGlyphs.isEmpty())
68
requestGlyphs(newGlyphs);
69
}
70
71
void
QSGOpenVGFontGlyphCache
::
release
(
const
QList<quint32> &glyphs)
72
{
73
QSet<quint32> unusedGlyphs;
74
int
count = glyphs.count();
75
for
(
int
i = 0; i < count; ++i) {
76
quint32 glyphIndex = glyphs.at(i);
77
unusedGlyphs.insert(glyphIndex);
78
}
79
releaseGlyphs(unusedGlyphs);
80
}
81
82
void
QSGOpenVGFontGlyphCache
::requestGlyphs(
const
QSet<quint32> &glyphs)
83
{
84
VGfloat origin[2];
85
VGfloat escapement[2];
86
QRawFont rawFont = m_referenceFont;
87
88
for
(
auto
glyph : glyphs) {
89
// Calculate the path for the glyph and cache it.
90
QPainterPath path = rawFont.pathForGlyph(glyph);
91
VGPath vgPath;
92
if
(!path.isEmpty()) {
93
vgPath = QSGOpenVGHelpers::qPainterPathToVGPath(path);
94
}
else
{
95
// Probably a "space" character with no visible outline.
96
vgPath = VG_INVALID_HANDLE;
97
}
98
origin[0] = 0;
99
origin[1] = 0;
100
escapement[0] = 0;
101
escapement[1] = 0;
102
vgSetGlyphToPath(m_font, glyph, vgPath, VG_FALSE, origin, escapement);
103
vgDestroyPath(vgPath);
// Reduce reference count.
104
}
105
106
}
107
108
void
QSGOpenVGFontGlyphCache
::referenceGlyphs(
const
QSet<quint32> &glyphs)
109
{
110
for
(
auto
glyph : glyphs) {
111
if
(m_glyphReferences.contains(glyph))
112
m_glyphReferences[glyph] += 1;
113
else
114
m_glyphReferences.insert(glyph, 1);
115
}
116
}
117
118
void
QSGOpenVGFontGlyphCache
::releaseGlyphs(
const
QSet<quint32> &glyphs)
119
{
120
for
(
auto
glyph : glyphs) {
121
int
references = m_glyphReferences[glyph] -= 1;
122
if
(references == 0) {
123
vgClearGlyph(m_font, glyph);
124
m_glyphReferences.remove(glyph);
125
}
126
}
127
}
128
129
QT_END_NAMESPACE
QSGOpenVGFontGlyphCacheManager
Definition
qsgopenvgfontglyphcache.h:16
QSGOpenVGFontGlyphCacheManager::cache
QSGOpenVGFontGlyphCache * cache(const QRawFont &font)
Definition
qsgopenvgfontglyphcache.cpp:21
QSGOpenVGFontGlyphCacheManager::insertCache
void insertCache(const QRawFont &font, QSGOpenVGFontGlyphCache *cache)
Definition
qsgopenvgfontglyphcache.cpp:26
QSGOpenVGFontGlyphCacheManager::~QSGOpenVGFontGlyphCacheManager
~QSGOpenVGFontGlyphCacheManager()
Definition
qsgopenvgfontglyphcache.cpp:16
QSGOpenVGFontGlyphCache
Definition
qsgopenvgfontglyphcache.h:29
QSGOpenVGFontGlyphCache::release
void release(const QList< quint32 > &glyphs)
Definition
qsgopenvgfontglyphcache.cpp:71
QSGOpenVGFontGlyphCache::glyphCount
int glyphCount() const
Definition
qsgopenvgfontglyphcache.h:36
QSGOpenVGFontGlyphCache::populate
void populate(const QList< quint32 > &glyphs)
Definition
qsgopenvgfontglyphcache.cpp:46
QSGOpenVGFontGlyphCache::QSGOpenVGFontGlyphCache
QSGOpenVGFontGlyphCache(QSGOpenVGFontGlyphCacheManager *manager, const QRawFont &font)
Definition
qsgopenvgfontglyphcache.cpp:31
QSGOpenVGFontGlyphCache::~QSGOpenVGFontGlyphCache
~QSGOpenVGFontGlyphCache()
Definition
qsgopenvgfontglyphcache.cpp:40
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
plugins
scenegraph
openvg
qsgopenvgfontglyphcache.cpp
Generated on
for Qt by
1.18.0