#include <qglfunctions.h>
#include <qglyphrun.h>
#include <qrawfont.h>
+#include <qdir.h>
QT_BEGIN_NAMESPACE
resizeTexture((requiredWidth), (requiredHeight));
glBindTexture(GL_TEXTURE_2D, m_textureData->texture);
+ // ### Remove before final release
+ static bool cacheDistanceFields = QApplication::arguments().contains("--cache-distance-fields");
+
+ QString tmpPath = QString::fromLatin1("%1/.qt/").arg(QDir::tempPath());
+ QString keyBase = QString::fromLatin1("%1%2%3_%4_%5_%6.fontblob")
+ .arg(tmpPath)
+ .arg(m_font.familyName())
+ .arg(m_font.styleName())
+ .arg(m_font.weight())
+ .arg(m_font.style());
+
+ if (cacheDistanceFields && !QFile::exists(tmpPath))
+ QDir(tmpPath).mkpath(tmpPath);
+
for (int i = 0; i < m_textureData->pendingGlyphs.size(); ++i) {
glyph_t glyphIndex = m_textureData->pendingGlyphs.at(i);
- QImage glyph = renderDistanceFieldGlyph(glyphIndex);
TexCoord c = m_textureData->texCoords.value(glyphIndex);
+ if (cacheDistanceFields) {
+ QString key = keyBase.arg(glyphIndex);
+ QFile file(key);
+ if (file.open(QFile::ReadOnly)) {
+ int fileSize = file.size();
+ int dim = sqrt(fileSize);
+ QByteArray blob = file.readAll();
+ glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, dim, dim, GL_ALPHA, GL_UNSIGNED_BYTE, blob.constData());
+ continue;
+ }
+ }
+
+ QImage glyph = renderDistanceFieldGlyph(glyphIndex);
+
if (ctx->d_ptr->workaround_brokenFBOReadBack) {
QPainter p(&m_textureData->image);
p.setCompositionMode(QPainter::CompositionMode_Source);
convert_to_Format_Alpha(&glyph);
glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, glyph.width(), glyph.height(), GL_ALPHA, GL_UNSIGNED_BYTE, glyph.constBits());
+
+ if (cacheDistanceFields) {
+ QString key = keyBase.arg(glyphIndex);
+ QFile file(key);
+ file.open(QFile::WriteOnly);
+ file.write((const char *) glyph.constBits(), glyph.width() * glyph.height());
+ }
}
m_textureData->pendingGlyphs.reset();
}