diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-03-18 12:57:01 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-04-08 07:48:57 +0200 |
commit | 2fb43a35dfa08bb0746913e3363f1fcf21815e72 (patch) | |
tree | f21107060994df759deb2ba8cfebb55113e4f5dc /src/quick/items/qquicktextinput.cpp | |
parent | 54a71e8c83de9b0312c920bc52378efcf20d537b (diff) |
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextinput.cpp')
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 2a136bf8d4..b209fabf14 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -136,6 +136,13 @@ QString QQuickTextInput::text() const return (res.isNull() ? QString::fromLatin1("") : res); } +void QQuickTextInput::invalidate() +{ + Q_D(QQuickTextInput); + d->updateLayout(); + invalidateFontCaches(); +} + void QQuickTextInput::setText(const QString &s) { Q_D(QQuickTextInput); |