Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
None
-
None
Description
Overview
Qt can access local fonts using the Local font access API (https://wicg.github.io/local-font-access/).
Currently this is is done by loading each font file in to memory, and then use FreeType's memory font support to access the font data. However this does not scale to loading all fonts, since a system can have several gigabytes of font data.
The technical reason for this limitation is that Qt does not have access to the font files through a POSIX file API, only through the async Web File API, which is not directly compatible and can't be used by FreeType.
We can improve on this in a couple of different ways:
- Load a subset of the fonts, and provide an API to specify the font set
- Stream fonts from disk on-demand
Font Loading API
Merged (6.8): https://codereview.qt-project.org/c/qt/qtbase/+/523922
This makes Qt recognize the following qtloader.js configuration keys:
qt.requestLocalFontsPermission (bool)
Set to true to make Qt request local font access permission on startup
qt.localFontFamiliesCollection (string)
Specify which set of font families to load (None/WebSafe/All) ("All" fonts will use 2GB+ of memory and is not recommended)
qt.extraLocalFontFamilies (array-of-string)
Specify extra font families (e.g. ["Helvetica Neue", "Comic Sans"])
Font Streaming
We'd like to:
- Avoid reading all font data on startup
- Avoid holding all font data in memory
FreeType supports custom IO via the FT_Stream API: use this to implement partial / on demand reading of font data.
The JS Font/Blob API is async, so we need one of:
- Use asyncify
- Run the font indexing code on a secondary thread (which can block and wait)
- "Park" the main thread when it returns control to the event loop at startup, and then scan for fonts? (does not require asyncify)
Local font access API documentation: https://wicg.github.io/local-font-access/
Implementation:
Streaming font data requires the following:
- QFreeTypeFontDatabase support for loading fonts by FT_Stream: WIP: wasm: investigate use of freetype streaming API
- FT_Stream wrapper for QIODevice: WIP: wasm: investigate use of freetype streaming API
- QIODevice wrapper for JS Blob
Attachments
Issue Links
- is required for
-
QTBUG-110988 Qt 6.6 WebAssembly Dev Roadmap
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-114469 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
467888,3 | WIP: wasm: investigate use of freetype streaming API | dev | qt/qtbase | Status: NEW | -2 | 0 |