summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qplatformfontdatabase.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2014-03-10 15:16:47 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-20 19:01:53 +0100
commit2bc7a40048ada41c59ddac0988bb2e04c227a18d (patch)
tree549092659e1e2c9e29c16eee3f850c809408fb44 /src/gui/text/qplatformfontdatabase.cpp
parent7a08f714a582b2dd1dbdcbc4c20cebc3d7536fe1 (diff)
Teach font database to populate families lazily
Instead of requiring that QPlatformFontDatabase::populateFontDatabase() populates every single font in the system by calling registerFont(), we now allow the platform database to call registerFontFamily() instead, and then keep track of which families we've yet to fully populate in the font database. Once a property of a family is requested (such as its writing system, style, etc), the family is lazily populated by calling back to the platform database through QPlatformFontDatabase::populateFamily(), which in turn does the final call to registerFont() as before. This cuts application startup on OS X and iOS (of which the font population used to be a major limiting factor) from roughly one second to about 350ms. Task-number: QTBUG-37165 Change-Id: Ic2fc3447beb818ffe23635a5b7816ed7e70c93a7 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com> Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/gui/text/qplatformfontdatabase.cpp')
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index 5f277c878a..33301005c6 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -53,6 +53,7 @@ void qt_registerFont(const QString &familyname, const QString &stylename,
bool scalable, int pixelSize, bool fixedPitch,
const QSupportedWritingSystems &writingSystems, void *hanlde);
+void qt_registerFontFamily(const QString &familyName);
void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias);
/*!
@@ -118,7 +119,7 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *
The writing systems supported by the font are specified by the
\a writingSystems argument.
- \sa registerQPF2Font()
+ \sa registerQPF2Font(), registerFontFamily()
*/
void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename,
const QString &foundryname, QFont::Weight weight,
@@ -134,6 +135,18 @@ void QPlatformFontDatabase::registerFont(const QString &familyname, const QStrin
fixedPitch, writingSystems, usrPtr);
}
+/*!
+ Registers a font family with the font database. The font will be
+ lazily populated by a callback to populateFamily() when the font
+ database determines that the family needs population.
+
+ \sa populateFamily(), registerFont()
+*/
+void QPlatformFontDatabase::registerFontFamily(const QString &familyName)
+{
+ qt_registerFontFamily(familyName);
+}
+
class QWritingSystemsPrivate
{
public:
@@ -249,6 +262,11 @@ QPlatformFontDatabase::~QPlatformFontDatabase()
Reimplement this function in a subclass for a convenient place to initialize
the internal font database.
+ You may lazily populate the database by calling registerFontFamily() instead
+ of registerFont(), in which case you'll get a callback to populateFamily()
+ when the required family needs population. You then call registerFont() to
+ finish population of the family.
+
The default implementation looks in the fontDir() location and registers all
QPF2 fonts.
*/
@@ -276,6 +294,18 @@ void QPlatformFontDatabase::populateFontDatabase()
}
/*!
+ This function is called whenever a lazily populated family, populated
+ through registerFontFamily(), needs full population.
+
+ You are expected to fully populate the family by calling registerFont()
+ for each font that matches the family name.
+*/
+void QPlatformFontDatabase::populateFamily(const QString &familyName)
+{
+ Q_UNUSED(familyName);
+}
+
+/*!
This function is called whenever the font database is invalidated.
Reimplement this function to clear any internal data structures that