QPlatformFontDatabase Class

The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they are rendered. More...

Header: #include <QPlatformFontDatabase>

Public Functions

virtual ~QPlatformFontDatabase()
virtual QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr)
virtual QFont defaultFont() const
virtual QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const
virtual QString fontDir() const
virtual QFontEngine *fontEngine(const QFontDef &fontDef, void *handle)
virtual QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)
virtual QFontEngineMulti *fontEngineMulti(QFontEngine *fontEngine, QChar::Script script)
virtual bool fontsAlwaysScalable() const
virtual void invalidate()
virtual bool isPrivateFontFamily(const QString &family) const
virtual void populateFamily(const QString &familyName)
virtual void populateFontDatabase()
virtual void releaseHandle(void *handle)
virtual QString resolveFontFamilyAlias(const QString &family) const
virtual QList<int> standardSizes() const

Static Public Members

bool isFamilyPopulated(const QString &familyName)
void registerAliasToFontFamily(const QString &familyName, const QString &alias)
void registerFont(const QString &familyname, const QString &stylename, const QString &foundryname, QFont::Weight weight, QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, bool fixedPitch, const QSupportedWritingSystems &writingSystems, void *usrPtr)
void registerFontFamily(const QString &familyName)
void repopulateFontDatabase()
QSupportedWritingSystems writingSystemsFromOS2Table(const char *os2Table, size_t length)
QSupportedWritingSystems writingSystemsFromTrueTypeBits(quint32[4] unicodeRange = 4, quint32[2] codePageRange = 2)

Detailed Description

\since5.0 \internal \preliminary \ingroup qpa \ingroup painting

QPlatformFontDatabase is the superclass which is intended to let platform implementations use native font handling.

Qt has its internal font database which it uses to discover available fonts on the user's system. To be able to populate this database subclass this class, and reimplement populateFontDatabase().

Use the function registerFont() to populate the internal font database.

Sometimes a specified font does not have the required glyphs; in such a case, the fallbackForFamily() function is called automatically to find alternative font families that can supply alternatives to the missing glyphs.

See also QSupportedWritingSystems.

Member Function Documentation

[virtual noexcept] QPlatformFontDatabase::~QPlatformFontDatabase()

\internal

[virtual] QStringList QPlatformFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr)

Adds an application font described by the font contained supplied fontData or using the font contained in the file referenced by fileName. Returns a list of family names, or an empty list if the font could not be added.

If applicationFont is non-null, its properties list should be filled with information from the loaded fonts. This is exposed through FontLoader in Qt Quick where it is needed for disambiguating fonts in the same family. When the function exits, the applicationFont should contain an entry of properties per font in the file, or it should be empty if no font was loaded.

Note: The default implementation of this function does not add an application font. Subclasses should reimplement this function to perform the necessary loading and registration of fonts.

[virtual] QFont QPlatformFontDatabase::defaultFont() const

Returns the default system font.

\since5.0

See also QGuiApplication::font().

[virtual] QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const

Returns a list of alternative fonts for the specified family and style and script using the styleHint given.

Default implementation returns a list of fonts for which style and script support has been reported during the font database population.

[virtual] QString QPlatformFontDatabase::fontDir() const

Returns the directory containing the fonts used by the database.

[virtual] QFontEngine *QPlatformFontDatabase::fontEngine(const QFontDef &fontDef, void *handle)

Returns the font engine that can be used to render the font described by the font definition, fontDef, in the specified script.

This function is called by QFontDatabase both for system fonts provided by the platform font database, as well as for application fonts added by the application developer.

The handle is the QPlatformFontDatabase specific handle passed when registering the font family via QPlatformFontDatabase::registerFont.

The function is called for both fonts added via a filename as well as fonts added from QByteArray data. Subclasses will need to handle both cases via its platform specific handle.

[virtual] QFontEngine *QPlatformFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference)

Returns the font engine that will be used to back a QRawFont, based on the given fontData, pixelSize, and hintingPreference.

This function is called by QRawFont, and does not play a part in the normal operations of QFontDatabase.

[virtual] QFontEngineMulti *QPlatformFontDatabase::fontEngineMulti(QFontEngine *fontEngine, QChar::Script script)

Returns a multi font engine in the specified script to encapsulate fontEngine with the option to fall back to the fonts given by fallbacks if fontEngine does not support a certain character.

[virtual] bool QPlatformFontDatabase::fontsAlwaysScalable() const

Return true if all fonts are considered scalable when using this font database. Defaults to false.

\since5.0

[virtual] void QPlatformFontDatabase::invalidate()

This function is called whenever the font database is invalidated.

Reimplement this function to clear any internal data structures that will need to be rebuilt at the next call to populateFontDatabase().

[static] bool QPlatformFontDatabase::isFamilyPopulated(const QString &familyName)

Helper function that returns true if the font family has already been registered and populated.

\since5.14

[virtual] bool QPlatformFontDatabase::isPrivateFontFamily(const QString &family) const

Returns true if the font family is private. For any given family name, the result is platform dependent.

[virtual] void QPlatformFontDatabase::populateFamily(const QString &familyName)

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.

[virtual] void QPlatformFontDatabase::populateFontDatabase()

This function is called once at startup by Qt's internal font database. 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 does nothing.

[static] void QPlatformFontDatabase::registerAliasToFontFamily(const QString &familyName, const QString &alias)

Helper function that register the alias for the familyName.

\since5.2

[static] void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename, const QString &foundryname, QFont::Weight weight, QFont::Style style, QFont::Stretch stretch, bool antialiased, bool scalable, int pixelSize, bool fixedPitch, const QSupportedWritingSystems &writingSystems, void *usrPtr)

Registers a font with the given set of attributes describing the font's foundry, family name, style and stretch information, pixel size, and supported writing systems. Additional information about whether the font can be scaled and antialiased can also be provided.

The foundry name and font family are described by foundryName and familyName. The font weight (light, normal, bold, etc.), style (normal, oblique, italic) and stretch information (condensed, expanded, unstretched, etc.) are specified by weight, style and stretch.

Some fonts can be antialiased and scaled; scalable and antialiased can be set to true for fonts with these attributes. The intended pixel size of non-scalable fonts is specified by pixelSize; this value will be ignored for scalable fonts.

The writing systems supported by the font are specified by the writingSystems argument.

See also registerFontFamily().

[static] void QPlatformFontDatabase::registerFontFamily(const QString &familyName)

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.

See also populateFamily() and registerFont().

[virtual] void QPlatformFontDatabase::releaseHandle(void *handle)

Releases the specified font handle.

[static] void QPlatformFontDatabase::repopulateFontDatabase()

Requests that the platform font database should be repopulated.

This will result in invalidating the entire font database.

The next time the font database is accessed it will be repopulated via a call to QPlatformFontDatabase::populate().

Application fonts will not be removed, and will be automatically populated when the font database is repopulated.

\since6.4

[virtual] QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const

Resolve alias to actual font family names.

\since5.0

[virtual] QList<int> QPlatformFontDatabase::standardSizes() const

Return list of standard font sizes when using this font database.

\since5.0

[static] QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromOS2Table(const char *os2Table, size_t length)

Helper function that determines the writing system support based on the contents of the OS/2 table in the font.

\since6.0

[static] QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(quint32[4] unicodeRange = 4, quint32[2] codePageRange = 2)

Helper function that determines the writing systems support by a given unicodeRange and codePageRange.

\since5.1