Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QPlatformFontDatabase Class Reference

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

#include <qplatformfontdatabase.h>

+ Inheritance diagram for QPlatformFontDatabase:
+ Collaboration diagram for QPlatformFontDatabase:

Public Member Functions

virtual ~QPlatformFontDatabase ()
 
virtual void populateFontDatabase ()
 This function is called once at startup by Qt's internal font database.
 
virtual bool populateFamilyAliases (const QString &missingFamily)
 
virtual void populateFamily (const QString &familyName)
 This function is called whenever a lazily populated family, populated through registerFontFamily(), needs full population.
 
virtual void invalidate ()
 This function is called whenever the font database is invalidated.
 
virtual QStringList 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.
 
virtual QStringList addApplicationFont (const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *font=nullptr)
 Adds an application font described by the font contained supplied fontData or using the font contained in the file referenced by fileName.
 
virtual QFontEnginefontEngine (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.
 
virtual QFontEnginefontEngine (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.
 
virtual QFontEngineMultifontEngineMulti (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 void releaseHandle (void *handle)
 Releases the specified font handle.
 
virtual QString fontDir () const
 Returns the directory containing the fonts used by the database.
 
virtual QFont defaultFont () const
 Returns the default system font.
 
virtual bool isPrivateFontFamily (const QString &family) const
 Returns true if the font family is private.
 
virtual QString resolveFontFamilyAlias (const QString &family) const
 Resolve alias to actual font family names.
 
virtual bool fontsAlwaysScalable () const
 Return true if all fonts are considered scalable when using this font database.
 
virtual QList< int > standardSizes () const
 Return list of standard font sizes when using this font database.
 
virtual bool supportsVariableApplicationFonts () const
 Returns true if this font database supports loading named instances from variable application fonts.
 

Static Public Member Functions

static QSupportedWritingSystems writingSystemsFromTrueTypeBits (quint32 unicodeRange[4], quint32 codePageRange[2])
 Helper function that determines the writing systems support by a given unicodeRange and codePageRange.
 
static QSupportedWritingSystems 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.
 
static 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 *handle)
 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.
 
static void registerFontFamily (const QString &familyName)
 Registers a font family with the font database.
 
static void registerAliasToFontFamily (const QString &familyName, const QString &alias)
 Helper function that register the alias for the familyName.
 
static void repopulateFontDatabase ()
 Requests that the platform font database should be repopulated.
 
static bool isFamilyPopulated (const QString &familyName)
 Helper function that returns true if the font family has already been registered and populated.
 

Detailed Description

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

Since
5.0

\preliminary

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

Definition at line 66 of file qplatformfontdatabase.h.

Constructor & Destructor Documentation

◆ ~QPlatformFontDatabase()

QPlatformFontDatabase::~QPlatformFontDatabase ( )
virtual

Definition at line 227 of file qplatformfontdatabase.cpp.

Member Function Documentation

◆ addApplicationFont()

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

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.

Reimplemented in QCoreTextFontDatabase, QFreeTypeFontDatabase, QFontconfigDatabase, QWindowsFontDatabase, and QWindowsDirectWriteFontDatabase.

Definition at line 334 of file qplatformfontdatabase.cpp.

References fileName, Q_UNUSED, and qWarning.

◆ defaultFont()

QFont QPlatformFontDatabase::defaultFont ( ) const
virtual

◆ fallbacksForFamily()

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

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.

Reimplemented in QCoreTextFontDatabase, QFontconfigDatabase, QWindowsDirectWriteFontDatabase, QWindowsFontDatabaseFT, QWindowsFontDatabase, QAndroidPlatformFontDatabase, and QWasmFontDatabase.

Definition at line 623 of file qfontdatabase.cpp.

References QFontDatabase::Any, QString::append(), QtFontFoundry::count, db, familySupportsWritingSystem(), i, QFontDatabasePrivate::instance(), QString::isEmpty(), j, QtFontStyle::key, QtFontFoundry::name, Q_UNUSED, qt_writing_system_for_script(), QtFontStyle::Key::style, QtFontFoundry::styles, and QFontDatabase::WritingSystemsCount.

Referenced by QWindowsDirectWriteFontDatabase::fallbacksForFamily(), QWindowsFontDatabaseFT::fallbacksForFamily(), QWindowsFontDatabase::fallbacksForFamily(), QAndroidPlatformFontDatabase::fallbacksForFamily(), and QWasmFontDatabase::fallbacksForFamily().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fontDir()

QString QPlatformFontDatabase::fontDir ( ) const
virtual

Returns the directory containing the fonts used by the database.

Reimplemented in QWindowsFontDatabaseFT, QWindowsFontDatabase, and QAndroidPlatformFontDatabase.

Definition at line 360 of file qplatformfontdatabase.cpp.

References QString::fromLocal8Bit(), QLibraryInfo::LibrariesPath, QLibraryInfo::path(), and qgetenv().

Referenced by QWindowsFontDatabase::fontDir(), and QFreeTypeFontDatabase::populateFontDatabase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fontEngine() [1/2]

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

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.

Reimplemented in QCoreTextFontDatabaseEngineFactory< T >, QFreeTypeFontDatabase, QFontconfigDatabase, QWindowsDirectWriteFontDatabase, QWindowsFontDatabaseFT, QWindowsFontDatabase, and QWindowsFontDatabaseBase.

Definition at line 309 of file qplatformfontdatabase.cpp.

References Q_UNUSED, and qWarning.

◆ fontEngine() [2/2]

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

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.

Reimplemented in QCoreTextFontDatabaseEngineFactory< T >, QFreeTypeFontDatabase, QFontconfigDatabase, QWindowsDirectWriteFontDatabase, QWindowsFontDatabaseFT, QWindowsFontDatabase, QWindowsFontDatabaseBase, QWasmFontDatabase, QCoreTextFontDatabaseEngineFactory< T >, and QCoreTextFontDatabaseEngineFactory< T >.

Definition at line 294 of file qplatformfontdatabase.cpp.

References Q_UNUSED, and qWarning.

Referenced by QWindowsFontDatabaseBase::fontEngine(), and fontEngineMulti().

+ Here is the caller graph for this function:

◆ fontEngineMulti()

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

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.

Reimplemented in QFontconfigDatabase.

Definition at line 274 of file qplatformfontdatabase.cpp.

References fontEngine().

+ Here is the call graph for this function:

◆ fontsAlwaysScalable()

bool QPlatformFontDatabase::fontsAlwaysScalable ( ) const
virtual

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

Defaults to false.

Since
5.0

Reimplemented in QCoreTextFontDatabase, and QWindowsFontDatabase.

Definition at line 411 of file qplatformfontdatabase.cpp.

◆ invalidate()

void QPlatformFontDatabase::invalidate ( )
virtual

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().

Reimplemented in QCoreTextFontDatabase, QFontconfigDatabase, QWindowsFontDatabase, and QWindowsFontDatabaseBase.

Definition at line 265 of file qplatformfontdatabase.cpp.

◆ isFamilyPopulated()

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

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

Since
5.14

Definition at line 643 of file qplatformfontdatabase.cpp.

References qt_isFontFamilyPopulated().

Referenced by addFontToDatabase(), and QCoreTextFontDatabase::populateFamilyAliases().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPrivateFontFamily()

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

Returns true if the font family is private.

For any given family name, the result is platform dependent.

Reimplemented in QCoreTextFontDatabase, QWindowsDirectWriteFontDatabase, and QWindowsFontDatabase.

Definition at line 373 of file qplatformfontdatabase.cpp.

References Q_UNUSED.

Referenced by QCoreTextFontDatabase::isPrivateFontFamily(), and QWindowsFontDatabase::isPrivateFontFamily().

+ Here is the caller graph for this function:

◆ populateFamily()

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

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.

Reimplemented in QCoreTextFontDatabase, QWindowsDirectWriteFontDatabase, QWindowsFontDatabaseFT, and QWindowsFontDatabase.

Definition at line 254 of file qplatformfontdatabase.cpp.

References Q_UNUSED.

◆ populateFamilyAliases()

virtual bool QPlatformFontDatabase::populateFamilyAliases ( const QString & missingFamily)
inlinevirtual

Reimplemented in QWindowsFontDatabaseFT, QCoreTextFontDatabase, QWindowsDirectWriteFontDatabase, and QWindowsFontDatabase.

Definition at line 71 of file qplatformfontdatabase.h.

References Q_UNUSED.

Referenced by QWindowsDirectWriteFontDatabase::populateFamilyAliases().

+ Here is the caller graph for this function:

◆ populateFontDatabase()

void QPlatformFontDatabase::populateFontDatabase ( )
virtual

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.

Reimplemented in QCoreTextFontDatabase, QFreeTypeFontDatabase, QFontconfigDatabase, QWindowsDirectWriteFontDatabase, QWindowsFontDatabaseFT, QWindowsFontDatabase, QAndroidPlatformFontDatabase, DummyFontDatabase, and QWasmFontDatabase.

Definition at line 243 of file qplatformfontdatabase.cpp.

◆ registerAliasToFontFamily()

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

Helper function that register the alias for the familyName.

Since
5.2

Definition at line 615 of file qplatformfontdatabase.cpp.

References qt_registerAliasToFontFamily().

Referenced by addFontToDatabase(), addFontToDatabase(), QCoreTextFontDatabase::populateFamilyAliases(), populateFontFamilies(), populateFontFamilies(), and populateFromPattern().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerFont()

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 )
static

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()

Definition at line 55 of file qplatformfontdatabase.cpp.

References qt_registerFont().

Referenced by QWindowsDirectWriteFontDatabase::addApplicationFont(), addFontToDatabase(), addFontToDatabase(), QFreeTypeFontDatabase::addNamedInstancesForFace(), QFreeTypeFontDatabase::addTTFile(), QWindowsDirectWriteFontDatabase::populateFamily(), QWindowsDirectWriteFontDatabase::populateFamilyAliases(), QFontconfigDatabase::populateFontDatabase(), and populateFromPattern().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerFontFamily()

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

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(), registerFont()

Definition at line 76 of file qplatformfontdatabase.cpp.

References qt_registerFontFamily().

Referenced by QCoreTextFontDatabase::populateFontDatabase(), QWindowsDirectWriteFontDatabase::populateFontDatabase(), QWindowsFontDatabaseFT::populateFontDatabase(), QWindowsFontDatabase::populateFontDatabase(), populateFontFamilies(), populateFontFamilies(), and QWasmFontDatabase::populateLocalFontFamilies().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releaseHandle()

void QPlatformFontDatabase::releaseHandle ( void * handle)
virtual

Releases the specified font handle.

Reimplemented in QCoreTextFontDatabase, QFreeTypeFontDatabase, QWindowsFontDatabase, and QWasmFontDatabase.

Definition at line 351 of file qplatformfontdatabase.cpp.

◆ repopulateFontDatabase()

void QPlatformFontDatabase::repopulateFontDatabase ( )
static

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.

Since
6.4

Definition at line 633 of file qplatformfontdatabase.cpp.

References QFontDatabasePrivate::instance().

Referenced by QCoreTextFontDatabase::QCoreTextFontDatabase(), and QIOSTheme::QIOSTheme().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveFontFamilyAlias()

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

Resolve alias to actual font family names.

Since
5.0

Reimplemented in QFontconfigDatabase.

Definition at line 399 of file qplatformfontdatabase.cpp.

References qt_resolveFontFamilyAlias().

Referenced by QWindowsFontDatabaseFT::populateFontDatabase(), QWindowsFontDatabase::populateFontDatabase(), and QFontconfigDatabase::resolveFontFamilyAlias().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ standardSizes()

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

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

Since
5.0

Reimplemented in QCoreTextFontDatabase.

Definition at line 422 of file qplatformfontdatabase.cpp.

References ret.

◆ supportsVariableApplicationFonts()

bool QPlatformFontDatabase::supportsVariableApplicationFonts ( ) const
virtual

Returns true if this font database supports loading named instances from variable application fonts.

Since
6.7

Reimplemented in QCoreTextFontDatabase, QFreeTypeFontDatabase, QFontconfigDatabase, and QWindowsDirectWriteFontDatabase.

Definition at line 654 of file qplatformfontdatabase.cpp.

◆ writingSystemsFromOS2Table()

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

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

Since
6.0

Definition at line 496 of file qplatformfontdatabase.cpp.

References writingSystemsFromTrueTypeBits().

Referenced by getFontDescription().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writingSystemsFromTrueTypeBits()

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

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

Since
5.1

Definition at line 522 of file qplatformfontdatabase.cpp.

References QFontDatabase::Arabic, ArabicCsbBit, BalticCsbBit, CentralEuropeCsbBit, QFontDatabase::Cyrillic, CyrillicCsbBit, QFontDatabase::Greek, GreekCsbBit, QFontDatabase::Hebrew, HebrewCsbBit, i, QFontDatabase::Japanese, JapaneseCsbBit, QFontDatabase::Korean, KoreanCsbBit, KoreanJohabCsbBit, QFontDatabase::Latin, Latin1CsbBit, requiredUnicodeBits, QSupportedWritingSystems::setSupported(), QFontDatabase::SimplifiedChinese, SimplifiedChineseCsbBit, QFontDatabase::Symbol, SymbolCsbBit, QFontDatabase::Thai, ThaiCsbBit, QFontDatabase::TraditionalChinese, TraditionalChineseCsbBit, TurkishCsbBit, QFontDatabase::Vietnamese, VietnameseCsbBit, and QFontDatabase::WritingSystemsCount.

Referenced by addFontToDatabase(), addFontToDatabase(), QFreeTypeFontDatabase::addTTFile(), QRawFont::supportedWritingSystems(), and writingSystemsFromOS2Table().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: