QString QSGDistanceFieldGlyphCacheManager::fontKey(const QRawFont &font) { QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine; if (!fe->faceId().filename.isEmpty()) { QByteArray keyName = fe->faceId().filename; if (font.style() != QFont::StyleNormal) keyName += QByteArray(" I"); if (font.weight() != QFont::Normal) keyName += ' ' + QByteArray::number(font.weight()); keyName += QByteArray(" DF"); return QString::fromUtf8(keyName); } else { return QString::fromLatin1("%1_%2_%3_%4") .arg(font.familyName()) .arg(font.styleName()) .arg(font.weight()) .arg(font.style()); } }
/*! Factory function for scene graph backends of the distance-field glyph cache. */ QSGDistanceFieldGlyphCache *QSGContext::distanceFieldGlyphCache(const QRawFont &font) { Q_D(QSGContext); if (!d->distanceFieldCacheManager) d->distanceFieldCacheManager = new QSGDistanceFieldGlyphCacheManager; QSGDistanceFieldGlyphCache *cache = d->distanceFieldCacheManager->cache(font); if (!cache) { QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration(); if (platformIntegration != 0 && platformIntegration->hasCapability(QPlatformIntegration::SharedGraphicsCache)) { QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine; if (!fe->faceId().filename.isEmpty()) { QByteArray keyName = fe->faceId().filename; if (font.style() != QFont::StyleNormal) keyName += QByteArray(" I"); if (font.weight() != QFont::Normal) keyName += ' ' + QByteArray::number(font.weight()); keyName += QByteArray(" DF"); QPlatformSharedGraphicsCache *sharedGraphicsCache = platformIntegration->createPlatformSharedGraphicsCache(keyName); if (sharedGraphicsCache != 0) { sharedGraphicsCache->ensureCacheInitialized(keyName, QPlatformSharedGraphicsCache::OpenGLTexture, QPlatformSharedGraphicsCache::Alpha8); cache = new QSGSharedDistanceFieldGlyphCache(keyName, sharedGraphicsCache, d->distanceFieldCacheManager, glContext(), font); } } } if (!cache) cache = new QSGDefaultDistanceFieldGlyphCache(d->distanceFieldCacheManager, glContext(), font); d->distanceFieldCacheManager->insertCache(font, cache); } return cache; }
QByteArray QPF::generate(const QFont &font, int options, const QList<CharacterRange> &ranges, QString *originalFontFile) { QTextEngine engine("Test", font); engine.itemize(); engine.shape(0); QFontEngine *fontEngine = engine.fontEngine(engine.layoutData->items[0]); if (fontEngine->type() == QFontEngine::Multi) fontEngine = static_cast<QFontEngineMulti *>(fontEngine)->engine(0); if (originalFontFile) *originalFontFile = QFile::decodeName(fontEngine->faceId().filename); return generate(fontEngine, options, ranges); }