summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2024-02-06 13:48:48 +0100
committerMorten Sørvig <morten.sorvig@qt.io>2024-02-08 14:37:50 +0100
commitb33b85cc46998133cddb18683402b6f0aaac754e (patch)
tree2dc8aeed1d315cc225b42ab9a9ad6848a4c99c64 /src/gui/text
parentef5ab6e00664caf0af23b21593f809d718c9dfc7 (diff)
qfreetype: Fix caching of memory fonts
Make QFreetypeFace::getFace() not return the same font face for all memory fonts. QtFreetypeData has a cache which maps QFontEngine::FaceId to QFreetypeFace instances. Each FaceId should then have a unique hash value, which is accomplished by by hashing the font file name and a stored uuid. However, we were not setting the uuid in all cases, which means that in-memory fonts (which do not have a file name) would hash identically. Fix this by setting the uuid to a value based on the address of the FontFile, which should be unique. Pick-to: 6.7 Change-Id: I45de37b512fb666c26490551c831c0db824b5f35 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/freetype/qfreetypefontdatabase.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/text/freetype/qfreetypefontdatabase.cpp b/src/gui/text/freetype/qfreetypefontdatabase.cpp
index 772485471f..018e590ac2 100644
--- a/src/gui/text/freetype/qfreetypefontdatabase.cpp
+++ b/src/gui/text/freetype/qfreetypefontdatabase.cpp
@@ -11,6 +11,7 @@
#include <QtCore/QDir>
#include <QtCore/QtEndian>
#include <QtCore/QLoggingCategory>
+#include <QtCore/QUuid>
#undef QT_NO_FREETYPE
#include "qfontengine_ft_p.h"
@@ -64,6 +65,14 @@ QFontEngine *QFreeTypeFontDatabase::fontEngine(const QFontDef &fontDef, void *us
faceId.instanceIndex = fontfile->instanceIndex;
faceId.variableAxes = fontDef.variableAxisValues;
+ // Make sure the FaceId compares uniquely in cases where a
+ // file name is not provided.
+ if (faceId.filename.isEmpty()) {
+ QUuid::Id128Bytes id{};
+ memcpy(&id, &usrPtr, sizeof(usrPtr));
+ faceId.uuid = QUuid(id).toByteArray();
+ }
+
return QFontEngineFT::create(fontDef, faceId, fontfile->data);
}