6#include <private/qfontengine_p.h>
7#include <private/qrawfont_p.h>
11QSGOpenVGFontGlyphCacheManager::QSGOpenVGFontGlyphCacheManager()
23 return m_caches.value(font,
nullptr);
28 m_caches.insert(font, cache);
34 m_referenceFont = font;
35 QRawFontPrivate *fontD = QRawFontPrivate::get(font);
36 m_glyphCount = fontD->fontEngine->glyphCount();
37 m_font = vgCreateFont(0);
42 if (m_font != VG_INVALID_HANDLE)
43 vgDestroyFont(m_font);
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);
54 qWarning(
"Warning: glyph is not available with index %d", glyphIndex);
58 referencedGlyphs.insert(glyphIndex);
61 if (!m_glyphReferences.contains(glyphIndex)) {
62 newGlyphs.insert(glyphIndex);
66 referenceGlyphs(referencedGlyphs);
67 if (!newGlyphs.isEmpty())
68 requestGlyphs(newGlyphs);
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);
79 releaseGlyphs(unusedGlyphs);
85 VGfloat escapement[2];
86 QRawFont rawFont = m_referenceFont;
88 for (
auto glyph : glyphs) {
90 QPainterPath path = rawFont.pathForGlyph(glyph);
92 if (!path.isEmpty()) {
93 vgPath = QSGOpenVGHelpers::qPainterPathToVGPath(path);
96 vgPath = VG_INVALID_HANDLE;
102 vgSetGlyphToPath(m_font, glyph, vgPath, VG_FALSE, origin, escapement);
103 vgDestroyPath(vgPath);
110 for (
auto glyph : glyphs) {
111 if (m_glyphReferences.contains(glyph))
112 m_glyphReferences[glyph] += 1;
114 m_glyphReferences.insert(glyph, 1);
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);
QSGOpenVGFontGlyphCache * cache(const QRawFont &font)
void insertCache(const QRawFont &font, QSGOpenVGFontGlyphCache *cache)
~QSGOpenVGFontGlyphCacheManager()
void populate(const QVector< quint32 > &glyphs)
void release(const QVector< quint32 > &glyphs)
QSGOpenVGFontGlyphCache(QSGOpenVGFontGlyphCacheManager *manager, const QRawFont &font)
~QSGOpenVGFontGlyphCache()