Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114469

Improve font Loading on WebAssembly

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • 6.8
    • None
    • GUI: Font handling
    • 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:

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-114469
          # Subject Branch Project Status CR V

          Activity

            People

              sorvig Morten Sørvig
              sorvig Morten Sørvig
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change