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
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
5#include "qsgopenvghelpers.h"
6#include <private/qfontengine_p.h>
7#include <private/qrawfont_p.h>
8
10
15
20
25
30
32 : m_manager(manager)
33{
34 m_referenceFont = font;
36 m_glyphCount = fontD->fontEngine->glyphCount();
37 m_font = vgCreateFont(0);
38}
39
41{
42 if (m_font != VG_INVALID_HANDLE)
43 vgDestroyFont(m_font);
44}
45
46void QSGOpenVGFontGlyphCache::populate(const QVector<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
71void QSGOpenVGFontGlyphCache::release(const QVector<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
82void 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()) {
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
108void 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
118void 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
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
T value(const Key &key) const noexcept
Definition qhash.h:1054
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
\inmodule QtGui
static QRawFontPrivate * get(const QRawFont &font)
Definition qrawfont_p.h:104
The QRawFont class provides access to a single physical instance of a font.
Definition qrawfont.h:24
QPainterPath pathForGlyph(quint32 glyphIndex) const
This function returns the shape of the glyph at a given glyphIndex in the underlying font if the QRaw...
Definition qrawfont.cpp:264
QSGOpenVGFontGlyphCache * cache(const QRawFont &font)
void insertCache(const QRawFont &font, QSGOpenVGFontGlyphCache *cache)
void populate(const QVector< quint32 > &glyphs)
void release(const QVector< quint32 > &glyphs)
QSGOpenVGFontGlyphCache(QSGOpenVGFontGlyphCacheManager *manager, const QRawFont &font)
qDeleteAll(list.begin(), list.end())
QCache< int, Employee > cache
[0]
VGPath qPainterPathToVGPath(const QPainterPath &path)
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLenum GLenum GLsizei count
GLsizei const GLchar *const * path
unsigned int quint32
Definition qtypes.h:50
QNetworkAccessManager manager