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
QWindowsFontDatabase Class Reference

Font database for Windows. More...

#include <qwindowsfontdatabase_p.h>

+ Inheritance diagram for QWindowsFontDatabase:
+ Collaboration diagram for QWindowsFontDatabase:

Classes

struct  FontHandle
 

Public Types

enum  FontOptions { DontUseDirectWriteFonts = 0x40 , DontUseColorFonts = 0x80 }
 

Public Member Functions

 QWindowsFontDatabase ()
 
 ~QWindowsFontDatabase () override
 
void ensureFamilyPopulated (const QString &familyName)
 
void populateFontDatabase () override
 This function is called once at startup by Qt's internal font database.
 
void invalidate () override
 This function is called whenever the font database is invalidated.
 
void removeApplicationFonts ()
 
void populateFamily (const QString &familyName) override
 This function is called whenever a lazily populated family, populated through registerFontFamily(), needs full population.
 
bool populateFamilyAliases (const QString &missingFamily) override
 
QFontEnginefontEngine (const QFontDef &fontDef, void *handle) override
 Returns the font engine that can be used to render the font described by the font definition, fontDef, in the specified script.
 
QFontEnginefontEngine (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override
 Returns the font engine that will be used to back a QRawFont, based on the given \fontData, pixelSize, and hintingPreference.
 
QStringList fallbacksForFamily (const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const override
 Returns a list of alternative fonts for the specified family and style and script using the styleHint given.
 
QStringList addApplicationFont (const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont=nullptr) override
 Adds an application font described by the font contained supplied fontData or using the font contained in the file referenced by fileName.
 
void releaseHandle (void *handle) override
 Releases the specified font handle.
 
QString fontDir () const override
 Returns the directory containing the fonts used by the database.
 
QFont defaultFont () const override
 Returns the default system font.
 
bool fontsAlwaysScalable () const override
 Return true if all fonts are considered scalable when using this font database.
 
void derefUniqueFont (const QString &uniqueFont)
 
void refUniqueFont (const QString &uniqueFont)
 
bool isPrivateFontFamily (const QString &family) const override
 Returns true if the font family is private.
 
- Public Member Functions inherited from QWindowsFontDatabaseBase
 QWindowsFontDatabaseBase ()
 
 ~QWindowsFontDatabaseBase () override
 
QFontEnginefontEngine (const QFontDef &fontDef, void *handle) override
 Returns the font engine that can be used to render the font described by the font definition, fontDef, in the specified script.
 
QFontEnginefontEngine (const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override
 Returns the font engine that will be used to back a QRawFont, based on the given \fontData, pixelSize, and hintingPreference.
 
void invalidate () override
 This function is called whenever the font database is invalidated.
 
QFontDef sanitizeRequest (QFontDef request) const
 
- Public Member Functions inherited from QPlatformFontDatabase
virtual ~QPlatformFontDatabase ()
 
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 QString resolveFontFamilyAlias (const QString &family) const
 Resolve alias to actual font family names.
 
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 QFontEnginecreateEngine (const QFontDef &request, const QString &faceName, int dpi, const QSharedPointer< QWindowsFontEngineData > &data)
 
static qreal fontSmoothingGamma ()
 
static void setFontOptions (unsigned options)
 
static unsigned fontOptions ()
 
static void debugFormat (QDebug &d, const LOGFONT &lf)
 
- Static Public Member Functions inherited from QWindowsFontDatabaseBase
static int defaultVerticalDPI ()
 
static QSharedPointer< QWindowsFontEngineDatadata ()
 
static QFont systemDefaultFont ()
 
static HFONT systemFont ()
 
static LOGFONT fontDefToLOGFONT (const QFontDef &fontDef, const QString &faceName)
 
static QFont LOGFONT_to_QFont (const LOGFONT &lf, int verticalDPI=0)
 
static QString familyForStyleHint (QFont::StyleHint styleHint)
 
static QStringList extraTryFontsForFamily (const QString &family)
 
- Static Public Member Functions inherited from QPlatformFontDatabase
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

Font database for Windows.

Note
The Qt 4.8 WIndows font database employed a mechanism of delayed population of the database again passing a font name to EnumFontFamiliesEx(), working around the fact that EnumFontFamiliesEx() does not list all fonts by default. This should be introduced to QPA as well?

Definition at line 31 of file qwindowsfontdatabase_p.h.

Member Enumeration Documentation

◆ FontOptions

Enumerator
DontUseDirectWriteFonts 
DontUseColorFonts 

Definition at line 35 of file qwindowsfontdatabase_p.h.

Constructor & Destructor Documentation

◆ QWindowsFontDatabase()

QWindowsFontDatabase::QWindowsFontDatabase ( )

Definition at line 720 of file qwindowsfontdatabase.cpp.

References d, QWindowsFontDatabaseBase::data(), Q_UNUSED, and qCDebug.

+ Here is the call graph for this function:

◆ ~QWindowsFontDatabase()

QWindowsFontDatabase::~QWindowsFontDatabase ( )
override

Definition at line 735 of file qwindowsfontdatabase.cpp.

References removeApplicationFonts().

+ Here is the call graph for this function:

Member Function Documentation

◆ addApplicationFont()

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

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 from QPlatformFontDatabase.

Definition at line 992 of file qwindowsfontdatabase.cpp.

References addFontToDatabase(), QString::append(), QString::data(), fileName, font, getFamiliesAndSignatures(), j, populateFamily(), properties, qMin(), QIODeviceBase::ReadOnly, QString::size(), QFont::StyleItalic, and QFont::StyleNormal.

+ Here is the call graph for this function:

◆ createEngine()

QFontEngine * QWindowsFontDatabase::createEngine ( const QFontDef & request,
const QString & faceName,
int dpi,
const QSharedPointer< QWindowsFontEngineData > & data )
static

Definition at line 1179 of file qwindowsfontdatabase.cpp.

References CLEARTYPE_QUALITY, QFontDef::families, QWindowsFontDatabaseBase::fontDefToLOGFONT(), QWindowsFontEngineDirectWrite::fontNameSubstitute(), QFontEngine::Format_A32, QString::fromWCharArray(), qCDebug, qErrnoWarning(), qMin(), qt_error_string(), qWarning, request, and QWindowsFontDatabaseBase::systemFont().

Referenced by QWindowsFontEngine::cloneWithSize(), fontEngine(), and fontEngine().

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

◆ debugFormat()

void QWindowsFontDatabase::debugFormat ( QDebug & d,
const LOGFONT & lf )
static

Definition at line 141 of file qwindowsfontdatabase.cpp.

References d, and QString::fromWCharArray().

Referenced by operator<<(), and operator<<().

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

◆ defaultFont()

QFont QWindowsFontDatabase::defaultFont ( ) const
inlineoverridevirtual

Returns the default system font.

See also
QGuiApplication::font()
Since
5.0

Reimplemented from QPlatformFontDatabase.

Definition at line 59 of file qwindowsfontdatabase_p.h.

◆ derefUniqueFont()

void QWindowsFontDatabase::derefUniqueFont ( const QString & uniqueFont)

Definition at line 1145 of file qwindowsfontdatabase.cpp.

References QMap< Key, T >::end(), QMap< Key, T >::erase(), QMap< Key, T >::find(), it, and lock.

+ Here is the call graph for this function:

◆ ensureFamilyPopulated()

void QWindowsFontDatabase::ensureFamilyPopulated ( const QString & familyName)

◆ fallbacksForFamily()

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

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 from QPlatformFontDatabase.

Definition at line 1165 of file qwindowsfontdatabase.cpp.

References QWindowsFontDatabaseBase::extraTryFontsForFamily(), QPlatformFontDatabase::fallbacksForFamily(), QWindowsFontDatabaseBase::familyForStyleHint(), and qCDebug.

+ Here is the call graph for this function:

◆ fontDir()

QString QWindowsFontDatabase::fontDir ( ) const
overridevirtual

Returns the directory containing the fonts used by the database.

Reimplemented from QPlatformFontDatabase.

Definition at line 1133 of file qwindowsfontdatabase.cpp.

References QPlatformFontDatabase::fontDir(), and qCDebug.

+ Here is the call graph for this function:

◆ fontEngine() [1/2]

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

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 from QPlatformFontDatabase.

Definition at line 751 of file qwindowsfontdatabase.cpp.

References createEngine(), QWindowsFontDatabaseBase::data(), QWindowsFontDatabaseBase::defaultVerticalDPI(), QFontEngine::DirectWrite, QFontDef::families, font, QFontEngine::fontDef, fontEngine(), QWindowsFontDatabaseBase::fontEngine(), QBasicAtomicInteger< T >::loadRelaxed(), lock, QString::number(), QFont::PreferMatch, Q_ASSERT, Q_ASSERT_X, Q_FUNC_INFO, qCDebug, qPrintable, QT_WARNING_DISABLE_GCC, QT_WARNING_POP, QT_WARNING_PUSH, qWarning, QFontEngine::ref, request, QFontEngine::type(), QFont::Unstretched, and QFontEngine::Win.

+ Here is the call graph for this function:

◆ fontEngine() [2/2]

QFontEngine * QWindowsFontDatabase::fontEngine ( const QFontDef & fontDef,
void * handle )
overridevirtual

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 from QPlatformFontDatabase.

Definition at line 740 of file qwindowsfontdatabase.cpp.

References createEngine(), QWindowsFontDatabaseBase::data(), QWindowsFontDatabaseBase::defaultVerticalDPI(), QString::left(), and qCDebug.

Referenced by fontEngine(), and QWindowsDirectWriteFontDatabase::fontEngine().

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

◆ fontOptions()

unsigned QWindowsFontDatabase::fontOptions ( )
static

Definition at line 94 of file qwindowsfontdatabase.cpp.

◆ fontsAlwaysScalable()

bool QWindowsFontDatabase::fontsAlwaysScalable ( ) const
overridevirtual

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

Defaults to false.

Since
5.0

Reimplemented from QPlatformFontDatabase.

Definition at line 1140 of file qwindowsfontdatabase.cpp.

◆ fontSmoothingGamma()

qreal QWindowsFontDatabase::fontSmoothingGamma ( )
static

Definition at line 99 of file qwindowsfontdatabase.cpp.

Referenced by QWindowsIntegration::styleHint().

+ Here is the caller graph for this function:

◆ invalidate()

void QWindowsFontDatabase::invalidate ( )
overridevirtual

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 from QPlatformFontDatabase.

Definition at line 714 of file qwindowsfontdatabase.cpp.

References QWindowsFontDatabaseBase::invalidate(), and removeApplicationFonts().

+ Here is the call graph for this function:

◆ isPrivateFontFamily()

bool QWindowsFontDatabase::isPrivateFontFamily ( const QString & family) const
overridevirtual

Returns true if the font family is private.

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

Reimplemented from QPlatformFontDatabase.

Definition at line 1286 of file qwindowsfontdatabase.cpp.

References QPlatformFontDatabase::isPrivateFontFamily().

+ Here is the call graph for this function:

◆ populateFamily()

void QWindowsFontDatabase::populateFamily ( const QString & familyName)
overridevirtual

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 from QPlatformFontDatabase.

Definition at line 620 of file qwindowsfontdatabase.cpp.

References qCDebug, QString::size(), storeFont(), and QString::toWCharArray().

Referenced by addApplicationFont(), addFontToDatabase(), QWindowsDirectWriteFontDatabase::populateFamily(), and populateFamilyAliases().

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

◆ populateFamilyAliases()

bool QWindowsFontDatabase::populateFamilyAliases ( const QString & missingFamily)
overridevirtual

Reimplemented from QPlatformFontDatabase.

Definition at line 605 of file qwindowsfontdatabase.cpp.

References QFontDatabase::families(), populateFamily(), and Q_UNUSED.

+ Here is the call graph for this function:

◆ populateFontDatabase()

void QWindowsFontDatabase::populateFontDatabase ( )
overridevirtual

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 from QPlatformFontDatabase.

Definition at line 698 of file qwindowsfontdatabase.cpp.

References populateFontFamilies(), QPlatformFontDatabase::registerFontFamily(), QPlatformFontDatabase::resolveFontFamilyAlias(), and QWindowsFontDatabaseBase::systemDefaultFont().

+ Here is the call graph for this function:

◆ refUniqueFont()

void QWindowsFontDatabase::refUniqueFont ( const QString & uniqueFont)

Definition at line 1157 of file qwindowsfontdatabase.cpp.

References QMap< Key, T >::end(), QMap< Key, T >::find(), it, and lock.

+ Here is the call graph for this function:

◆ releaseHandle()

void QWindowsFontDatabase::releaseHandle ( void * handle)
overridevirtual

Releases the specified font handle.

Reimplemented from QPlatformFontDatabase.

Definition at line 1128 of file qwindowsfontdatabase.cpp.

◆ removeApplicationFonts()

void QWindowsFontDatabase::removeApplicationFonts ( )

Definition at line 1101 of file qwindowsfontdatabase.cpp.

References QList< T >::clear(), and font.

Referenced by ~QWindowsFontDatabase(), and invalidate().

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

◆ setFontOptions()

void QWindowsFontDatabase::setFontOptions ( unsigned options)
static

Definition at line 88 of file qwindowsfontdatabase.cpp.

References DontUseColorFonts, and DontUseDirectWriteFonts.

Referenced by QWindowsIntegrationPrivate::parseOptions().

+ Here is the caller graph for this function:

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