Qt 4.8
Public Types | Public Functions | Static Public Functions | Static Private Functions | Properties | Friends | List of all members
QFontDatabase Class Reference

The QFontDatabase class provides information about the fonts available in the underlying window system. More...

#include <qfontdatabase.h>

Public Types

enum  WritingSystem {
  Any, Latin, Greek, Cyrillic,
  Armenian, Hebrew, Arabic, Syriac,
  Thaana, Devanagari, Bengali, Gurmukhi,
  Gujarati, Oriya, Tamil, Telugu,
  Kannada, Malayalam, Sinhala, Thai,
  Lao, Tibetan, Myanmar, Georgian,
  Khmer, SimplifiedChinese, TraditionalChinese, Japanese,
  Korean, Vietnamese, Symbol, Other = Symbol,
  Ogham, Runic, Nko, WritingSystemsCount
}
 

Public Functions

bool bold (const QString &family, const QString &style) const
 Returns true if the font that has family family and style style is bold; otherwise returns false. More...
 
QStringList families (WritingSystem writingSystem=Any) const
 Returns a sorted list of the available font families which support the writingSystem. More...
 
QFont font (const QString &family, const QString &style, int pointSize) const
 Returns a QFont object that has family family, style style and point size pointSize. More...
 
bool hasFamily (const QString &family) const
 
bool isBitmapScalable (const QString &family, const QString &style=QString()) const
 Returns true if the font that has family family and style style is a scalable bitmap font; otherwise returns false. More...
 
bool isFixedPitch (const QString &family, const QString &style=QString()) const
 Returns true if the font that has family family and style style is fixed pitch; otherwise returns false. More...
 
bool isScalable (const QString &family, const QString &style=QString()) const
 Returns true if the font that has family family and style style is scalable; otherwise returns false. More...
 
bool isSmoothlyScalable (const QString &family, const QString &style=QString()) const
 Returns true if the font that has family family and style style is smoothly scalable; otherwise returns false. More...
 
bool italic (const QString &family, const QString &style) const
 Returns true if the font that has family family and style style is italic; otherwise returns false. More...
 
QList< int > pointSizes (const QString &family, const QString &style=QString())
 Returns a list of the point sizes available for the font with the given family and style. More...
 
 QFontDatabase ()
 Creates a font database object. More...
 
QList< int > smoothSizes (const QString &family, const QString &style)
 Returns the point sizes of a font with the given family and style that will look attractive. More...
 
QStringList styles (const QString &family) const
 Returns a list of the styles available for the font family family. More...
 
QString styleString (const QFont &font)
 Returns a string that describes the style of the font. More...
 
QString styleString (const QFontInfo &fontInfo)
 Returns a string that describes the style of the fontInfo. More...
 
int weight (const QString &family, const QString &style) const
 Returns the weight of the font that has family family and style style. More...
 
QList< WritingSystemwritingSystems () const
 Returns a sorted list of the available writing systems. More...
 
QList< WritingSystemwritingSystems (const QString &family) const
 Returns a sorted list of the writing systems supported by a given font family. More...
 

Static Public Functions

static int addApplicationFont (const QString &fileName)
 Loads the font from the file specified by fileName and makes it available to the application. More...
 
static int addApplicationFontFromData (const QByteArray &fontData)
 Loads the font from binary data specified by fontData and makes it available to the application. More...
 
static QStringList applicationFontFamilies (int id)
 Returns a list of font families for the given application font identified by id. More...
 
static bool removeAllApplicationFonts ()
 Removes all application-local fonts previously added using addApplicationFont() and addApplicationFontFromData(). More...
 
static bool removeApplicationFont (int id)
 Removes the previously loaded application font identified by id. More...
 
static QList< int > standardSizes ()
 Returns a list of standard font sizes. More...
 
static bool supportsThreadedFontRendering ()
 Returns true if font rendering is supported outside the GUI thread, false otherwise. More...
 
static QString writingSystemName (WritingSystem writingSystem)
 Returns the names the writingSystem (e.g. More...
 
static QString writingSystemSample (WritingSystem writingSystem)
 Returns a string with sample characters from writingSystem. More...
 

Static Private Functions

static void createDatabase ()
 
static QFontEnginefindFont (int script, const QFontPrivate *fp, const QFontDef &request)
 
static void load (const QFontPrivate *d, int script)
 Loads a QFontEngine for the specified script that matches the QFontDef request member variable. More...
 
static QFontEngineloadXlfd (int screen, int script, const QFontDef &request, int force_encoding_id=-1)
 
static void parseFontName (const QString &name, QString &foundry, QString &family)
 
static QString resolveFontFamilyAlias (const QString &family)
 

Properties

QFontDatabasePrivated
 

Friends

struct QFontDef
 
class QFontDialog
 
class QFontDialogPrivate
 
class QFontEngineMultiQPA
 
class QFontEngineMultiQWS
 
class QFontEngineMultiS60
 
class QFontEngineMultiXLFD
 
class QFontPrivate
 

Detailed Description

The QFontDatabase class provides information about the fonts available in the underlying window system.

Note
This class or function is threadsafe.

The most common uses of this class are to query the database for the list of font families() and for the pointSizes() and styles() that are available for each family. An alternative to pointSizes() is smoothSizes() which returns the sizes at which a given family and style will look attractive.

If the font family is available from two or more foundries the foundry name is included in the family name; for example: "Helvetica [Adobe]" and "Helvetica [Cronyx]". When you specify a family, you can either use the old hyphenated "foundry-family" format or the bracketed "family [foundry]" format; for example: "Cronyx-Helvetica" or "Helvetica [Cronyx]". If the family has a foundry it is always returned using the bracketed format, as is the case with the value returned by families().

The font() function returns a QFont given a family, style and point size.

A family and style combination can be checked to see if it is italic() or bold(), and to retrieve its weight(). Similarly we can call isBitmapScalable(), isSmoothlyScalable(), isScalable() and isFixedPitch().

Use the styleString() to obtain a text version of a style.

The QFontDatabase class also supports some static functions, for example, standardSizes(). You can retrieve the description of a writing system using writingSystemName(), and a sample of characters in a writing system with writingSystemSample().

Example:

QFontDatabase database;
QTreeWidget fontTree;
fontTree.setColumnCount(2);
fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");
foreach (const QString &family, database.families()) {
QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
familyItem->setText(0, family);
foreach (const QString &style, database.styles(family)) {
QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
styleItem->setText(0, style);
QString sizes;
foreach (int points, database.smoothSizes(family, style))
sizes += QString::number(points) + " ";
styleItem->setText(1, sizes.trimmed());
}
}

This example gets the list of font families, the list of styles for each family, and the point sizes that are available for each combination of family and style, displaying this information in a tree view.

See also
QFont, QFontInfo, QFontMetrics, QFontComboBox, {Character Map Example}

Definition at line 66 of file qfontdatabase.h.

Enumerations

◆ WritingSystem

  • Any
  • Latin
  • Greek
  • Cyrillic
  • Armenian
  • Hebrew
  • Arabic
  • Syriac
  • Thaana
  • Devanagari
  • Bengali
  • Gurmukhi
  • Gujarati
  • Oriya
  • Tamil
  • Telugu
  • Kannada
  • Malayalam
  • Sinhala
  • Thai
  • Lao
  • Tibetan
  • Myanmar
  • Georgian
  • Khmer
  • SimplifiedChinese
  • TraditionalChinese
  • Japanese
  • Korean
  • Vietnamese
  • Symbol
  • Other (the same as Symbol)
  • Ogham
  • Runic
  • Nko
  • WritingSystemsCount
Enumerator
Any 
Latin 
Greek 
Cyrillic 
Armenian 
Hebrew 
Arabic 
Syriac 
Thaana 
Devanagari 
Bengali 
Gurmukhi 
Gujarati 
Oriya 
Tamil 
Telugu 
Kannada 
Malayalam 
Sinhala 
Thai 
Lao 
Tibetan 
Myanmar 
Georgian 
Khmer 
SimplifiedChinese 
TraditionalChinese 
Japanese 
Korean 
Vietnamese 
Symbol 
Other 
Ogham 
Runic 
Nko 
WritingSystemsCount 

Definition at line 73 of file qfontdatabase.h.

73  {
74  Any,
75 
76  Latin,
77  Greek,
78  Cyrillic,
79  Armenian,
80  Hebrew,
81  Arabic,
82  Syriac,
83  Thaana,
84  Devanagari,
85  Bengali,
86  Gurmukhi,
87  Gujarati,
88  Oriya,
89  Tamil,
90  Telugu,
91  Kannada,
92  Malayalam,
93  Sinhala,
94  Thai,
95  Lao,
96  Tibetan,
97  Myanmar,
98  Georgian,
99  Khmer,
102  Japanese,
103  Korean,
104  Vietnamese,
105 
106  Symbol,
107  Other = Symbol,
108 
109  Ogham,
110  Runic,
111  Nko,
112 
114  };

Constructors and Destructors

◆ QFontDatabase()

QFontDatabase::QFontDatabase ( )

Creates a font database object.

Definition at line 1606 of file qfontdatabase.cpp.

1607 {
1608  QMutexLocker locker(fontDatabaseMutex());
1609  createDatabase();
1610  d = privateDb();
1611 }
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QFontDatabasePrivate * d
static void createDatabase()

Functions

◆ addApplicationFont()

int QFontDatabase::addApplicationFont ( const QString fileName)
static

Loads the font from the file specified by fileName and makes it available to the application.

Since
4.2

An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.

The function returns -1 if the font could not be loaded.

Currently only TrueType fonts, TrueType font collections, and OpenType fonts are supported.

Note
Adding application fonts on Unix/X11 platforms without fontconfig is currently not supported.
On Symbian, the font family names get truncated to a length of 20 characters.
See also
addApplicationFontFromData(), applicationFontFamilies(), removeApplicationFont()

Definition at line 2659 of file qfontdatabase.cpp.

Referenced by QDeclarativeFontLoader::setSource().

2660 {
2661  QByteArray data;
2662  QFile f(fileName);
2663  if (!(f.fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)) {
2664  if (!f.open(QIODevice::ReadOnly))
2665  return -1;
2666  data = f.readAll();
2667  }
2668  QMutexLocker locker(fontDatabaseMutex());
2669  return privateDb()->addAppFont(data, fileName);
2670 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const char * data(const QByteArray &arr)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65

◆ addApplicationFontFromData()

int QFontDatabase::addApplicationFontFromData ( const QByteArray fontData)
static

Loads the font from binary data specified by fontData and makes it available to the application.

Since
4.2

An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.

The function returns -1 if the font could not be loaded.

Currently only TrueType fonts and TrueType font collections are supported.

Note: Adding application fonts on Unix/X11 platforms without fontconfig is currently not supported.

Note
On Symbian, the font family names get truncated to a length of 20 characters.
See also
addApplicationFont(), applicationFontFamilies(), removeApplicationFont()

Definition at line 2694 of file qfontdatabase.cpp.

Referenced by QDeclarativeFontObject::replyFinished().

2695 {
2696  QMutexLocker locker(fontDatabaseMutex());
2697  return privateDb()->addAppFont(fontData, QString() /* fileName */);
2698 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ applicationFontFamilies()

QStringList QFontDatabase::applicationFontFamilies ( int  id)
static

Returns a list of font families for the given application font identified by id.

Since
4.2
See also
addApplicationFont(), addApplicationFontFromData()

Definition at line 2711 of file qfontdatabase.cpp.

Referenced by QDeclarativeFontObject::replyFinished(), and QDeclarativeFontLoader::setSource().

2712 {
2713  QMutexLocker locker(fontDatabaseMutex());
2714  return privateDb()->applicationFonts.value(id).families;
2715 }
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ bold()

bool QFontDatabase::bold ( const QString family,
const QString style 
) const

Returns true if the font that has family family and style style is bold; otherwise returns false.

See also
italic(), weight()

Definition at line 2172 of file qfontdatabase.cpp.

2174 {
2175  QString familyName, foundryName;
2176  parseFontName(family, foundryName, familyName);
2177 
2178  QMutexLocker locker(fontDatabaseMutex());
2179 
2180  QT_PREPEND_NAMESPACE(load)(familyName);
2181 
2182  QtFontFoundry allStyles(foundryName);
2183  QtFontFamily *f = d->family(familyName);
2184  if (!f) return false;
2185 
2186  for (int j = 0; j < f->count; j++) {
2187  QtFontFoundry *foundry = f->foundries[j];
2188  if (foundryName.isEmpty() ||
2189  foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2190  for (int k = 0; k < foundry->count; k++)
2191  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2192  }
2193  }
2194 
2195  QtFontStyle::Key styleKey(style);
2196  QtFontStyle *s = allStyles.style(styleKey, style);
2197  return s && s->key.weight >= QFont::Bold;
2198 }
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFontDatabasePrivate * d
QString styleName

◆ createDatabase()

void QFontDatabase::createDatabase ( )
staticprivate

Definition at line 2590 of file qfontdatabase.cpp.

2591 { initializeDb(); }
static void initializeDb()

◆ families()

QStringList QFontDatabase::families ( WritingSystem  writingSystem = Any) const

Returns a sorted list of the available font families which support the writingSystem.

If a family exists in several foundries, the returned name for that font is in the form "family [foundry]". Examples: "Times [Adobe]", "Times [Cronyx]", "Palatino".

See also
writingSystems()

Definition at line 1731 of file qfontdatabase.cpp.

Referenced by QFontComboBoxPrivate::_q_updateModel(), QDeclarativeEnginePrivate::fontFamilies(), and loadEngine().

1732 {
1733  QMutexLocker locker(fontDatabaseMutex());
1734 
1736 #ifdef Q_WS_X11
1737  if (writingSystem != Any)
1738  checkSymbolFonts();
1739 #endif
1740 
1741  QStringList flist;
1742  for (int i = 0; i < d->count; i++) {
1743  QtFontFamily *f = d->families[i];
1744  if (f->count == 0)
1745  continue;
1746  if (writingSystem != Any && (f->writingSystems[writingSystem] != QtFontFamily::Supported))
1747  continue;
1748  if (f->count == 1) {
1749  flist.append(f->name);
1750  } else {
1751  for (int j = 0; j < f->count; j++) {
1752  QString str = f->name;
1753  QString foundry = f->foundries[j]->name;
1754  if (!foundry.isEmpty()) {
1755  str += QLatin1String(" [");
1756  str += foundry;
1757  str += QLatin1Char(']');
1758  }
1759  flist.append(str);
1760  }
1761  }
1762  }
1763  return flist;
1764 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QtFontFamily ** families
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
static void checkSymbolFonts(const QString &family=QString())
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QFontDatabasePrivate * d
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ findFont()

QFontEngine * QFontDatabase::findFont ( int  script,
const QFontPrivate fp,
const QFontDef request 
)
staticprivate
Warning
This function is not part of the public interface.

Definition at line 255 of file qfontdatabase_qpa.cpp.

Referenced by QFontEngineMultiQPA::loadEngine(), QFontEngineMultiQWS::loadEngine(), and registerFont().

257 {
258  QMutexLocker locker(fontDatabaseMutex());
259 
260  const int force_encoding_id = -1;
261 
262  if (!privateDb()->count)
263  initializeDb();
264 
265  QFontEngine *engine;
266  QFontCache::Key key(request, script);
267  engine = QFontCache::instance()->findEngine(key);
268  if (engine) {
269  qDebug() << "Cache hit level 1";
270  return engine;
271  }
272 
273  QString family_name, foundry_name;
274 
275  parseFontName(request.family, foundry_name, family_name);
276 
277  if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) {
278  engine =new QTestFontEngine(request.pixelSize);
279  engine->fontDef = request;
280  }
281 
282  QtFontDesc desc;
283  match(script, request, family_name, foundry_name, force_encoding_id, &desc);
284  if (desc.family != 0 && desc.foundry != 0 && desc.style != 0) {
285  engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size);
286  } else {
287  FM_DEBUG(" NO MATCH FOUND\n");
288  }
289 
290  if (engine) {
291  initFontDef(desc, request, &engine->fontDef);
292 
293  if (fp) {
294  QFontDef def = request;
295  if (def.family.isEmpty()) {
296  def.family = fp->request.family;
297  def.family = def.family.left(def.family.indexOf(QLatin1Char(',')));
298  }
299  }
300  }
301 
302  if (!engine) {
303  if (!request.family.isEmpty()) {
305  for (int i = 0; i < fallbacks.size(); i++) {
306  QFontDef def = request;
307  def.family = fallbacks.at(i);
309  engine = QFontCache::instance()->findEngine(key);
310  if (!engine) {
311  QtFontDesc desc;
312  match(script, def, def.family, QLatin1String(""), 0, &desc);
313  if (desc.family == 0 && desc.foundry == 0 && desc.style == 0) {
314  continue;
315  }
316  engine = loadEngine(script, def, desc.family, desc.foundry, desc.style, desc.size);
317  if (engine) {
318  initFontDef(desc, def, &engine->fontDef);
319  break;
320  }
321  }
322  }
323  }
324 
325  if (!engine)
326  engine = new QFontEngineBox(request.pixelSize);
327 
328  FM_DEBUG("returning box engine");
329  }
330 
331  if (fp && fp->dpi > 0) {
332  engine->fontDef.pointSize = qreal(double((engine->fontDef.pixelSize * 72) / fp->dpi));
333  } else {
334  engine->fontDef.pointSize = request.pointSize;
335  }
336 
337  return engine;
338 }
double qreal
Definition: qglobal.h:1193
static void initializeDb()
qreal pointSize
Definition: qfont_p.h:89
QtFontSize * size
static bool match(const uchar *found, const char *target, uint len)
QtFontStyle * style
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QFontCache * instance()
Definition: qfont.cpp:2919
QtFontFoundry * foundry
Q_CORE_EXPORT void qDebug(const char *,...)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QFontDef request
Definition: qfont_p.h:178
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QFontEngine * loadEngine(int script, const QFontDef &request, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool qt_enable_test_font
#define FM_DEBUG
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
Definition: qfont.h:69
uint style
Definition: qfont_p.h:97
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QtFontFamily * family
QFontEngine * findEngine(const Key &key)
Definition: qfont.cpp:3054
QFontDef fontDef
QString family
Definition: qfont_p.h:82
uint styleHint
Definition: qfont_p.h:93
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)

◆ font()

QFont QFontDatabase::font ( const QString family,
const QString style,
int  pointSize 
) const

Returns a QFont object that has family family, style style and point size pointSize.

If no matching font could be created, a QFont object that uses the application's default font is returned.

Definition at line 2008 of file qfontdatabase.cpp.

Referenced by getFamiliesAndSignatures(), qfontForCocoaFont(), registerFont(), and resolveFontFamilyAlias().

2010 {
2011  QString familyName, foundryName;
2012  parseFontName(family, foundryName, familyName);
2013 
2014  QMutexLocker locker(fontDatabaseMutex());
2015 
2016  QT_PREPEND_NAMESPACE(load)(familyName);
2017 
2018  QtFontFoundry allStyles(foundryName);
2019  QtFontFamily *f = d->family(familyName);
2020  if (!f) return QApplication::font();
2021 
2022  for (int j = 0; j < f->count; j++) {
2023  QtFontFoundry *foundry = f->foundries[j];
2024  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2025  for (int k = 0; k < foundry->count; k++)
2026  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2027  }
2028  }
2029 
2030  QtFontStyle::Key styleKey(style);
2031  QtFontStyle *s = bestStyle(&allStyles, styleKey, style);
2032 
2033  if (!s) // no styles found?
2034  return QApplication::font();
2035 
2036  QFont fnt(family, pointSize, s->key.weight);
2037  fnt.setStyle((QFont::Style)s->key.style);
2038  if (!s->styleName.isEmpty())
2039  fnt.setStyleName(s->styleName);
2040  return fnt;
2041 }
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
static QFont font()
Returns the default application font.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
static QtFontStyle * bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey, const QString &styleName=QString())
QtFontFoundry ** foundries
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QFontDatabasePrivate * d
QString styleName
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90

◆ hasFamily()

bool QFontDatabase::hasFamily ( const QString family) const
Warning
This function is not part of the public interface.

Definition at line 2238 of file qfontdatabase.cpp.

2239 {
2240  QString parsedFamily, foundry;
2241  parseFontName(family, foundry, parsedFamily);
2242  const QString familyAlias = resolveFontFamilyAlias(parsedFamily);
2243  return families().contains(familyAlias, Qt::CaseInsensitive);
2244 }
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStringList families(WritingSystem writingSystem=Any) const
Returns a sorted list of the available font families which support the writingSystem.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
static QString resolveFontFamilyAlias(const QString &family)

◆ isBitmapScalable()

bool QFontDatabase::isBitmapScalable ( const QString family,
const QString style = QString() 
) const

Returns true if the font that has family family and style style is a scalable bitmap font; otherwise returns false.

Scaling a bitmap font usually produces an unattractive hardly readable result, because the pixels of the font are scaled. If you need to scale a bitmap font it is better to scale it to one of the fixed sizes returned by smoothSizes().

See also
isScalable(), isSmoothlyScalable()

Definition at line 1842 of file qfontdatabase.cpp.

1844 {
1845  bool bitmapScalable = false;
1846  QString familyName, foundryName;
1847  parseFontName(family, foundryName, familyName);
1848 
1849  QMutexLocker locker(fontDatabaseMutex());
1850 
1851  QT_PREPEND_NAMESPACE(load)(familyName);
1852 
1853  QtFontStyle::Key styleKey(style);
1854 
1855  QtFontFamily *f = d->family(familyName);
1856  if (!f) return bitmapScalable;
1857 
1858  for (int j = 0; j < f->count; j++) {
1859  QtFontFoundry *foundry = f->foundries[j];
1860  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1861  for (int k = 0; k < foundry->count; k++)
1862  if ((style.isEmpty() ||
1863  foundry->styles[k]->styleName == style ||
1864  foundry->styles[k]->key == styleKey)
1865  && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) {
1866  bitmapScalable = true;
1867  goto end;
1868  }
1869  }
1870  }
1871  end:
1872  return bitmapScalable;
1873 }
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFontDatabasePrivate * d
QString styleName
static const KeyPair *const end

◆ isFixedPitch()

bool QFontDatabase::isFixedPitch ( const QString family,
const QString style = QString() 
) const

Returns true if the font that has family family and style style is fixed pitch; otherwise returns false.

Definition at line 1813 of file qfontdatabase.cpp.

Referenced by QFontComboBoxPrivate::_q_updateModel().

1815 {
1816  Q_UNUSED(style);
1817 
1818  QString familyName, foundryName;
1819  parseFontName(family, foundryName, familyName);
1820 
1821  QMutexLocker locker(fontDatabaseMutex());
1822 
1823  QT_PREPEND_NAMESPACE(load)(familyName);
1824 
1825  QtFontFamily *f = d->family(familyName);
1826 #if !defined(QWS) && defined(Q_OS_MAC)
1828 #endif
1829  return (f && f->fixedPitch);
1830 }
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
static void qt_mac_get_fixed_pitch(QtFontFamily *f)
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QFontDatabasePrivate * d
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ isScalable()

bool QFontDatabase::isScalable ( const QString family,
const QString style = QString() 
) const

Returns true if the font that has family family and style style is scalable; otherwise returns false.

See also
isBitmapScalable(), isSmoothlyScalable()

Definition at line 1921 of file qfontdatabase.cpp.

1923 {
1924  QMutexLocker locker(fontDatabaseMutex());
1925  if (isSmoothlyScalable(family, style))
1926  return true;
1927  return isBitmapScalable(family, style);
1928 }
bool isBitmapScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is a scalable bitmap font; otherwise ...
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool isSmoothlyScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is smoothly scalable; otherwise retur...

◆ isSmoothlyScalable()

bool QFontDatabase::isSmoothlyScalable ( const QString family,
const QString style = QString() 
) const

Returns true if the font that has family family and style style is smoothly scalable; otherwise returns false.

If this function returns true, it's safe to scale this font to any size, and the result will always look attractive.

See also
isScalable(), isBitmapScalable()

Definition at line 1884 of file qfontdatabase.cpp.

Referenced by QFontComboBoxPrivate::_q_updateModel(), and QFontFamilyDelegate::paint().

1885 {
1886  bool smoothScalable = false;
1887  QString familyName, foundryName;
1888  parseFontName(family, foundryName, familyName);
1889 
1890  QMutexLocker locker(fontDatabaseMutex());
1891 
1892  QT_PREPEND_NAMESPACE(load)(familyName);
1893 
1894  QtFontStyle::Key styleKey(style);
1895 
1896  QtFontFamily *f = d->family(familyName);
1897  if (!f) return smoothScalable;
1898 
1899  for (int j = 0; j < f->count; j++) {
1900  QtFontFoundry *foundry = f->foundries[j];
1901  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1902  for (int k = 0; k < foundry->count; k++)
1903  if ((style.isEmpty() ||
1904  foundry->styles[k]->styleName == style ||
1905  foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
1906  smoothScalable = true;
1907  goto end;
1908  }
1909  }
1910  }
1911  end:
1912  return smoothScalable;
1913 }
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFontDatabasePrivate * d
QString styleName
static const KeyPair *const end

◆ italic()

bool QFontDatabase::italic ( const QString family,
const QString style 
) const

Returns true if the font that has family family and style style is italic; otherwise returns false.

See also
weight(), bold()

Definition at line 2139 of file qfontdatabase.cpp.

2140 {
2141  QString familyName, foundryName;
2142  parseFontName(family, foundryName, familyName);
2143 
2144  QMutexLocker locker(fontDatabaseMutex());
2145 
2146  QT_PREPEND_NAMESPACE(load)(familyName);
2147 
2148  QtFontFoundry allStyles(foundryName);
2149  QtFontFamily *f = d->family(familyName);
2150  if (!f) return false;
2151 
2152  for (int j = 0; j < f->count; j++) {
2153  QtFontFoundry *foundry = f->foundries[j];
2154  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2155  for (int k = 0; k < foundry->count; k++)
2156  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2157  }
2158  }
2159 
2160  QtFontStyle::Key styleKey(style);
2161  QtFontStyle *s = allStyles.style(styleKey, style);
2162  return s && s->key.style == QFont::StyleItalic;
2163 }
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFontDatabasePrivate * d
QString styleName

◆ load()

void QFontDatabase::load ( const QFontPrivate d,
int  script 
)
staticprivate

Loads a QFontEngine for the specified script that matches the QFontDef request member variable.

Warning
This function is not part of the public interface.

Definition at line 366 of file qfontdatabase_mac.cpp.

Referenced by QFontPrivate::engineForScript(), findFont(), loadWin(), loadXlfd(), and registerFont().

367 {
368  // sanity checks
369  if(!qApp)
370  qWarning("QFont: Must construct a QApplication before a QFont");
371 
373  Q_UNUSED(script);
374 
375  QFontDef req = d->request;
376  req.pixelSize = qt_mac_pixelsize(req, d->dpi);
377 
378  // set the point size to 0 to get better caching
379  req.pointSize = 0;
381 
382  if(!(d->engineData = QFontCache::instance()->findEngineData(key))) {
383  d->engineData = new QFontEngineData;
385  } else {
386  d->engineData->ref.ref();
387  }
388  if(d->engineData->engine) // already loaded
389  return;
390 
391  // set it to the actual pointsize, so QFontInfo will do the right thing
393 
395  if(!e && qt_enable_test_font && req.family == QLatin1String("__Qt__Box__Engine__")) {
396  e = new QTestFontEngine(req.pixelSize);
397  e->fontDef = req;
398  }
399 
400  if(e) {
401  e->ref.ref();
402  d->engineData->engine = e;
403  return; // the font info and fontdef should already be filled
404  }
405 
406  QFontEngine *engine = NULL;
407 #if defined(QT_MAC_USE_COCOA)
408  // Shortcut to get the font directly without going through the font database
409  if (!req.family.isEmpty() && !req.styleName.isEmpty()) {
410  QCFString expectedFamily = QCFString(req.family);
411  QCFString expectedStyle = QCFString(req.styleName);
412 
413  QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(NULL, 0,
414  &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
415  CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, expectedFamily);
416  CFDictionaryAddValue(attributes, kCTFontStyleNameAttribute, expectedStyle);
417 
418  QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes(attributes);
419  CGAffineTransform transform = qt_transform_from_fontdef(req);
420  QCFType<CTFontRef> ctFont = CTFontCreateWithFontDescriptor(descriptor, req.pixelSize, &transform);
421  if (ctFont) {
422  QCFString familyName = CTFontCopyFamilyName(ctFont);
423  // Only accept the font if the family name is exactly the same as we specified
424  if (CFEqual(expectedFamily, familyName)) {
425  engine = new QCoreTextFontEngineMulti(ctFont, req, d->kerning);
426  }
427  }
428  }
429 #endif
430  if (!engine)
431  engine = loadFromDatabase(req, d);
432 
433  if (engine) {
434  d->engineData->engine = engine;
435  engine->ref.ref();
436  QFontCache::instance()->insertEngine(key, engine);
437  }
438 }
QAtomicInt ref
qreal pointSize
Definition: qfont_p.h:89
void insertEngine(const Key &key, QFontEngine *engine)
Definition: qfont.cpp:3073
int qt_mac_pixelsize(const QFontDef &def, int dpi)
Definition: qfont_mac.cpp:64
bool ref()
Atomically increments the value of this QAtomicInt.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QFontCache * instance()
Definition: qfont.cpp:2919
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QFontEngine * loadFromDatabase(QFontDef &req, const QFontPrivate *d)
#define qApp
QFontDef request
Definition: qfont_p.h:178
void insertEngineData(const Key &key, QFontEngineData *engineData)
Definition: qfont.cpp:3046
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool qt_enable_test_font
QAtomicInt ref
Definition: qfont_p.h:152
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
int key
QString styleName
Definition: qfont_p.h:83
int qt_mac_pointsize(const QFontDef &def, int dpi)
Definition: qfont_mac.cpp:73
int screen
Definition: qfont_p.h:181
CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef)
QFontEngineData * findEngineData(const Key &key) const
Definition: qfont.cpp:3036
QFontEngine * findEngine(const Key &key)
Definition: qfont.cpp:3054
QFontDef fontDef
QFontEngine * engine
Definition: qfont_p.h:158
uint kerning
Definition: qfont_p.h:191
QString family
Definition: qfont_p.h:82
QFontEngineData * engineData
Definition: qfont_p.h:179
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ loadXlfd()

QFontEngine * QFontDatabase::loadXlfd ( int  screen,
int  script,
const QFontDef request,
int  force_encoding_id = -1 
)
staticprivate

Definition at line 1797 of file qfontdatabase_x11.cpp.

Referenced by QFontEngineMultiXLFD::loadEngine().

1798 {
1799  QMutexLocker locker(fontDatabaseMutex());
1800 
1801  QtFontDesc desc;
1802  FM_DEBUG() << "---> loadXlfd: request is" << request.family;
1803  QStringList families_and_foundries = familyList(request);
1804  const char *stylehint = styleHint(request);
1805  if (stylehint)
1806  families_and_foundries << QString::fromLatin1(stylehint);
1807  families_and_foundries << QString();
1808  FM_DEBUG() << "loadXlfd: list is" << families_and_foundries;
1809  for (int i = 0; i < families_and_foundries.size(); ++i) {
1810  QString family, foundry;
1811  QT_PREPEND_NAMESPACE(parseFontName)(families_and_foundries.at(i), foundry, family);
1812  FM_DEBUG("loadXlfd: >>>>>>>>>>>>>>trying to match '%s' encoding=%d", family.toLatin1().data(), force_encoding_id);
1813  QT_PREPEND_NAMESPACE(match)(script, request, family, foundry, force_encoding_id, &desc, QList<int>(), true);
1814  if (desc.family)
1815  break;
1816  }
1817 
1818  QFontEngine *fe = 0;
1819  if (force_encoding_id != -1
1820  || (request.styleStrategy & QFont::NoFontMerging)
1821  || (desc.family && desc.family->writingSystems[QFontDatabase::Symbol] & QtFontFamily::Supported)) {
1822  if (desc.family) {
1823  int px = desc.size->pixelSize;
1824  if (desc.style->smoothScalable && px == SMOOTH_SCALABLE)
1825  px = request.pixelSize;
1826  else if (desc.style->bitmapScalable && px == 0)
1827  px = request.pixelSize;
1828 
1829  QByteArray xlfd("-");
1830  xlfd += desc.foundry->name.isEmpty() ? QByteArray("*") : desc.foundry->name.toLatin1();
1831  xlfd += '-';
1832  xlfd += desc.family->name.isEmpty() ? QByteArray("*") : desc.family->name.toLatin1();
1833  xlfd += '-';
1834  xlfd += desc.style->weightName ? desc.style->weightName : "*";
1835  xlfd += '-';
1836  xlfd += (desc.style->key.style == QFont::StyleItalic
1837  ? 'i'
1838  : (desc.style->key.style == QFont::StyleOblique ? 'o' : 'r'));
1839  xlfd += '-';
1840  xlfd += desc.style->setwidthName ? desc.style->setwidthName : "*";
1841  // ### handle add-style
1842  xlfd += "-*-";
1843  xlfd += QByteArray::number(px);
1844  xlfd += '-';
1845  xlfd += QByteArray::number(desc.encoding->xpoint);
1846  xlfd += '-';
1847  xlfd += QByteArray::number(desc.encoding->xres);
1848  xlfd += '-';
1849  xlfd += QByteArray::number(desc.encoding->yres);
1850  xlfd += '-';
1851  xlfd += desc.encoding->pitch;
1852  xlfd += '-';
1853  xlfd += QByteArray::number(desc.encoding->avgwidth);
1854  xlfd += '-';
1855  xlfd += xlfd_for_id(desc.encoding->encoding);
1856 
1857  FM_DEBUG(" using XLFD: %s\n", xlfd.data());
1858 
1859  const int mib = xlfd_encoding[desc.encoding->encoding].mib;
1860  XFontStruct *xfs;
1861  if ((xfs = XLoadQueryFont(QX11Info::display(), xlfd))) {
1862  fe = new QFontEngineXLFD(xfs, xlfd, mib);
1863  const int dpi = QX11Info::appDpiY();
1864  if (!qt_fillFontDef(xfs, &fe->fontDef, dpi, &desc)
1865  && !qt_fillFontDef(xlfd, &fe->fontDef, dpi, &desc)) {
1866  initFontDef(desc, request, &fe->fontDef);
1867  }
1868  }
1869  }
1870  if (!fe) {
1871  fe = new QFontEngineBox(request.pixelSize);
1872  fe->fontDef = QFontDef();
1873  }
1874  } else {
1875  QList<int> encodings;
1876  if (desc.encoding) {
1877  if (desc.encoding->encoding >= 0)
1878  encodings.append(int(desc.encoding->encoding));
1879  }
1880 
1881  if (desc.size) {
1882  // append all other encodings for the matched font
1883  for (int i = 0; i < desc.size->count; ++i) {
1884  QtFontEncoding *e = desc.size->encodings + i;
1885  if (e == desc.encoding || e->encoding < 0)
1886  continue;
1887  encodings.append(int(e->encoding));
1888  }
1889  }
1890  // fill in the missing encodings
1891  const XlfdEncoding *enc = xlfd_encoding;
1892  for (; enc->name; ++enc) {
1893  if (!encodings.contains(enc->id) && enc->id >= 0) {
1894  encodings.append(enc->id);
1895  }
1896  }
1897 
1898 #if defined(FONT_MATCH_DEBUG)
1899  FM_DEBUG(" using MultiXLFD, encodings:");
1900  for (int i = 0; i < encodings.size(); ++i) {
1901  const int id = encodings.at(i);
1902  FM_DEBUG(" %2d: %s", xlfd_encoding[id].id, xlfd_encoding[id].name);
1903  }
1904 #endif
1905 
1906  fe = new QFontEngineMultiXLFD(request, encodings, screen);
1907  }
1908  return fe;
1909 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool match(const uchar *found, const char *target, uint len)
friend struct QFontDef
const char * name
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define SMOOTH_SCALABLE
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static QStringList familyList(const QFontDef &req)
static const char * xlfd_for_id(int id)
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
bool qt_fillFontDef(const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc)
int mib
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static const char * styleHint(const QFontDef &request)
#define FM_DEBUG
signed int encoding
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
static const XlfdEncoding xlfd_encoding[]
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
friend class QFontEngineMultiXLFD
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QFontDef fontDef
QString family
Definition: qfont_p.h:82
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
static Display * display()
Returns the default display for the application.
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ parseFontName()

void QFontDatabase::parseFontName ( const QString name,
QString foundry,
QString family 
)
staticprivate

Definition at line 2585 of file qfontdatabase.cpp.

Referenced by QFontDef::exactMatch(), findFont(), and QFontDialogPrivate::updateFamilies().

2586 {
2587  QT_PREPEND_NAMESPACE(parseFontName)(name, foundry, family);
2588 }
static void parseFontName(const QString &name, QString &foundry, QString &family)
const char * name
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87

◆ pointSizes()

QList< int > QFontDatabase::pointSizes ( const QString family,
const QString style = QString() 
)

Returns a list of the point sizes available for the font with the given family and style.

The list may be empty.

See also
smoothSizes(), standardSizes()

Definition at line 1941 of file qfontdatabase.cpp.

1943 {
1944 #if defined(Q_WS_WIN)
1945  // windows and macosx are always smoothly scalable
1946  Q_UNUSED(family);
1947  Q_UNUSED(styleName);
1948  return standardSizes();
1949 #else
1950  bool smoothScalable = false;
1951  QString familyName, foundryName;
1952  parseFontName(family, foundryName, familyName);
1953 
1954  QMutexLocker locker(fontDatabaseMutex());
1955 
1956  QT_PREPEND_NAMESPACE(load)(familyName);
1957 
1958  QtFontStyle::Key styleKey(styleName);
1959 
1960  QList<int> sizes;
1961 
1962  QtFontFamily *fam = d->family(familyName);
1963  if (!fam) return sizes;
1964 
1965 
1966 #ifdef Q_WS_X11
1967  int dpi = QX11Info::appDpiY();
1968 #else
1969  const int dpi = qt_defaultDpiY(); // embedded
1970 #endif
1971 
1972  for (int j = 0; j < fam->count; j++) {
1973  QtFontFoundry *foundry = fam->foundries[j];
1974  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1975  QtFontStyle *style = foundry->style(styleKey, styleName);
1976  if (!style) continue;
1977 
1978  if (style->smoothScalable) {
1979  smoothScalable = true;
1980  goto end;
1981  }
1982  for (int l = 0; l < style->count; l++) {
1983  const QtFontSize *size = style->pixelSizes + l;
1984 
1985  if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
1986  const uint pointSize = qRound(size->pixelSize * qreal(72.0) / dpi);
1987  if (! sizes.contains(pointSize))
1988  sizes.append(pointSize);
1989  }
1990  }
1991  }
1992  }
1993  end:
1994  if (smoothScalable)
1995  return standardSizes();
1996 
1997  qSort(sizes);
1998  return sizes;
1999 #endif
2000 }
static QList< int > standardSizes()
Returns a list of standard font sizes.
unsigned short pixelSize
double qreal
Definition: qglobal.h:1193
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
signed int count
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
unsigned int uint
Definition: qglobal.h:996
QtFontFoundry ** foundries
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFactoryLoader * l
QFontDatabasePrivate * d
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
QtFontSize * pixelSizes
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ removeAllApplicationFonts()

bool QFontDatabase::removeAllApplicationFonts ( )
static

Removes all application-local fonts previously added using addApplicationFont() and addApplicationFontFromData().

Since
4.2

Returns true if unloading of the fonts succeeded; otherwise returns false.

See also
removeApplicationFont(), addApplicationFont(), addApplicationFontFromData()

Definition at line 530 of file qfontdatabase_mac.cpp.

Referenced by registerFont().

531 {
532  QMutexLocker locker(fontDatabaseMutex());
533 
534  QFontDatabasePrivate *db = privateDb();
535  for(int i = 0; i < db->applicationFonts.count(); ++i) {
536  if(!removeApplicationFont(i))
537  return false;
538  }
539  return true;
540 }
static bool removeApplicationFont(int id)
Removes the previously loaded application font identified by id.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QVector< ApplicationFont > applicationFonts

◆ removeApplicationFont()

bool QFontDatabase::removeApplicationFont ( int  id)
static

Removes the previously loaded application font identified by id.

Since
4.2

Returns true if unloading of the font succeeded; otherwise returns false.

See also
removeAllApplicationFonts(), addApplicationFont(), addApplicationFontFromData()

Definition at line 511 of file qfontdatabase_mac.cpp.

Referenced by registerFont(), and removeAllApplicationFonts().

512 {
513  QMutexLocker locker(fontDatabaseMutex());
514 
515  QFontDatabasePrivate *db = privateDb();
516  if(handle < 0 || handle >= db->applicationFonts.count())
517  return false;
518 
519  OSStatus e = ATSFontDeactivate(db->applicationFonts.at(handle).handle,
520  /*iRefCon=*/0, kATSOptionFlagsDefault);
521  if(e != noErr)
522  return false;
523 
525 
526  db->invalidate();
527  return true;
528 }
signed long OSStatus
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QVector< ApplicationFont > applicationFonts

◆ resolveFontFamilyAlias()

QString QFontDatabase::resolveFontFamilyAlias ( const QString family)
staticprivate

Definition at line 547 of file qfontdatabase_mac.cpp.

Referenced by QFontDef::exactMatch(), qt_fontdatabase_mutex(), and registerFont().

548 {
549  QCFString expectedFamily = QCFString(family);
550 
551  QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(NULL, 0,
552  &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
553  CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, expectedFamily);
554  QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes(attributes);
555 
556  QCFType<CFMutableSetRef> mandatoryAttributes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
557  CFSetAddValue(mandatoryAttributes, kCTFontFamilyNameAttribute);
558 
559  QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL);
560  QCFType<CTFontDescriptorRef> matched = CTFontDescriptorCreateMatchingFontDescriptor(descriptor, mandatoryAttributes);
561  if (!matched)
562  return family;
563 
564  QCFString familyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(matched, kCTFontFamilyNameAttribute, NULL);
565  return familyName;
566 }
const struct __CFString * CFStringRef
QFont font(const QString &family, const QString &style, int pointSize) const
Returns a QFont object that has family family, style style and point size pointSize.

◆ smoothSizes()

QList< int > QFontDatabase::smoothSizes ( const QString family,
const QString style 
)

Returns the point sizes of a font with the given family and style that will look attractive.

The list may be empty. For non-scalable fonts and bitmap scalable fonts, this function is equivalent to pointSizes().

See also
pointSizes(), standardSizes()

Definition at line 2056 of file qfontdatabase.cpp.

2058 {
2059 #ifdef Q_WS_WIN
2060  Q_UNUSED(family);
2061  Q_UNUSED(styleName);
2063 #else
2064  bool smoothScalable = false;
2065  QString familyName, foundryName;
2066  parseFontName(family, foundryName, familyName);
2067 
2068  QMutexLocker locker(fontDatabaseMutex());
2069 
2070  QT_PREPEND_NAMESPACE(load)(familyName);
2071 
2072  QtFontStyle::Key styleKey(styleName);
2073 
2074  QList<int> sizes;
2075 
2076  QtFontFamily *fam = d->family(familyName);
2077  if (!fam)
2078  return sizes;
2079 
2080 #ifdef Q_WS_X11
2081  int dpi = QX11Info::appDpiY();
2082 #else
2083  const int dpi = qt_defaultDpiY(); // embedded
2084 #endif
2085 
2086  for (int j = 0; j < fam->count; j++) {
2087  QtFontFoundry *foundry = fam->foundries[j];
2088  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2089  QtFontStyle *style = foundry->style(styleKey, styleName);
2090  if (!style) continue;
2091 
2092  if (style->smoothScalable) {
2093  smoothScalable = true;
2094  goto end;
2095  }
2096  for (int l = 0; l < style->count; l++) {
2097  const QtFontSize *size = style->pixelSizes + l;
2098 
2099  if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
2100  const uint pointSize = qRound(size->pixelSize * qreal(72.0) / dpi);
2101  if (! sizes.contains(pointSize))
2102  sizes.append(pointSize);
2103  }
2104  }
2105  }
2106  }
2107  end:
2108  if (smoothScalable)
2110 
2111  qSort(sizes);
2112  return sizes;
2113 #endif
2114 }
static QList< int > standardSizes()
Returns a list of standard font sizes.
unsigned short pixelSize
double qreal
Definition: qglobal.h:1193
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
signed int count
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
unsigned int uint
Definition: qglobal.h:996
QtFontFoundry ** foundries
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFactoryLoader * l
QFontDatabasePrivate * d
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
QtFontSize * pixelSizes
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ standardSizes()

QList< int > QFontDatabase::standardSizes ( )
static

Returns a list of standard font sizes.

See also
smoothSizes(), pointSizes()

Definition at line 2122 of file qfontdatabase.cpp.

Referenced by smoothSizes().

2123 {
2124  QList<int> ret;
2125  static const unsigned short standard[] =
2126  { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 };
2127  const unsigned short *sizes = standard;
2128  while (*sizes) ret << *sizes++;
2129  return ret;
2130 }

◆ styles()

QStringList QFontDatabase::styles ( const QString family) const

Returns a list of the styles available for the font family family.

Some example styles: "Light", "Light Italic", "Bold", "Oblique", "Demi". The list may be empty.

See also
families()

Definition at line 1773 of file qfontdatabase.cpp.

1774 {
1775  QString familyName, foundryName;
1776  parseFontName(family, foundryName, familyName);
1777 
1778  QMutexLocker locker(fontDatabaseMutex());
1779 
1780  QT_PREPEND_NAMESPACE(load)(familyName);
1781 
1782  QStringList l;
1783  QtFontFamily *f = d->family(familyName);
1784  if (!f)
1785  return l;
1786 
1787  QtFontFoundry allStyles(foundryName);
1788  for (int j = 0; j < f->count; j++) {
1789  QtFontFoundry *foundry = f->foundries[j];
1790  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1791  for (int k = 0; k < foundry->count; k++) {
1792  QtFontStyle::Key ke(foundry->styles[k]->key);
1793  ke.stretch = 0;
1794  allStyles.style(ke, foundry->styles[k]->styleName, true);
1795  }
1796  }
1797  }
1798 
1799  for (int i = 0; i < allStyles.count; i++) {
1800  l.append(allStyles.styles[i]->styleName.isEmpty() ?
1801  styleStringHelper(allStyles.styles[i]->key.weight,
1802  (QFont::Style)allStyles.styles[i]->key.style) :
1803  allStyles.styles[i]->styleName);
1804  }
1805  return l;
1806 }
QStringList styles(const QString &family) const
Returns a list of the styles available for the font family family.
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFactoryLoader * l
static QString styleStringHelper(int weight, QFont::Style style)
QFontDatabasePrivate * d
QString styleName

◆ styleString() [1/2]

QString QFontDatabase::styleString ( const QFont font)

Returns a string that describes the style of the font.

For example, "Bold Italic", "Bold", "Italic" or "Normal". An empty string may be returned.

Definition at line 1531 of file qfontdatabase.cpp.

1532 {
1533  return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style())
1534  : font.styleName();
1535 }
Style style() const
Returns the style of the font.
Definition: qfont.cpp:1223
QString styleName() const
Returns the requested font style name, it will be used to match the font with irregular styles (that ...
Definition: qfont.cpp:950
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int weight() const
Returns the weight of the font which is one of the enumerated values from QFont::Weight.
Definition: qfont.cpp:1248
static QString styleStringHelper(int weight, QFont::Style style)

◆ styleString() [2/2]

QString QFontDatabase::styleString ( const QFontInfo fontInfo)

Returns a string that describes the style of the fontInfo.

For example, "Bold Italic", "Bold", "Italic" or "Normal". An empty string may be returned.

Definition at line 1542 of file qfontdatabase.cpp.

1543 {
1544  return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style())
1545  : fontInfo.styleName();
1546 }
int weight() const
Returns the weight of the matched window system font.
Definition: qfont.cpp:2758
QString styleName() const
Returns the style name of the matched window system font on system that supports it.
Definition: qfont.cpp:2686
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QFont::Style style() const
Returns the style value of the matched window system font.
Definition: qfont.cpp:2746
static QString styleStringHelper(int weight, QFont::Style style)

◆ supportsThreadedFontRendering()

bool QFontDatabase::supportsThreadedFontRendering ( )
static

Returns true if font rendering is supported outside the GUI thread, false otherwise.

Since
4.4

In other words, a return value of false means that all QPainter::drawText() calls outside the GUI thread will not produce readable output.

See also
{Thread-Support in Qt Modules::Painting In Threads}{Painting In Threads}

Definition at line 542 of file qfontdatabase_mac.cpp.

Referenced by QPainter::drawTextItem(), and registerFont().

543 {
544  return true;
545 }

◆ weight()

int QFontDatabase::weight ( const QString family,
const QString style 
) const

Returns the weight of the font that has family family and style style.

If there is no such family and style combination, returns -1.

See also
italic(), bold()

Definition at line 2208 of file qfontdatabase.cpp.

2210 {
2211  QString familyName, foundryName;
2212  parseFontName(family, foundryName, familyName);
2213 
2214  QMutexLocker locker(fontDatabaseMutex());
2215 
2216  QT_PREPEND_NAMESPACE(load)(familyName);
2217 
2218  QtFontFoundry allStyles(foundryName);
2219  QtFontFamily *f = d->family(familyName);
2220  if (!f) return -1;
2221 
2222  for (int j = 0; j < f->count; j++) {
2223  QtFontFoundry *foundry = f->foundries[j];
2224  if (foundryName.isEmpty() ||
2225  foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2226  for (int k = 0; k < foundry->count; k++)
2227  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2228  }
2229  }
2230 
2231  QtFontStyle::Key styleKey(style);
2232  QtFontStyle *s = allStyles.style(styleKey, style);
2233  return s ? s->key.weight : -1;
2234 }
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
QtFontStyle ** styles
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFoundry ** foundries
QtFontFamily * family(const QString &f, bool=false)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
QFontDatabasePrivate * d
QString styleName

◆ writingSystemName()

QString QFontDatabase::writingSystemName ( WritingSystem  writingSystem)
static

Returns the names the writingSystem (e.g.

for displaying to the user in a dialog).

Definition at line 2251 of file qfontdatabase.cpp.

Referenced by QFontDialogPrivate::init(), initializeDb(), and initWritingSystems().

2252 {
2253  const char *name = 0;
2254  switch (writingSystem) {
2255  case Any:
2256  name = QT_TRANSLATE_NOOP("QFontDatabase", "Any");
2257  break;
2258  case Latin:
2259  name = QT_TRANSLATE_NOOP("QFontDatabase", "Latin");
2260  break;
2261  case Greek:
2262  name = QT_TRANSLATE_NOOP("QFontDatabase", "Greek");
2263  break;
2264  case Cyrillic:
2265  name = QT_TRANSLATE_NOOP("QFontDatabase", "Cyrillic");
2266  break;
2267  case Armenian:
2268  name = QT_TRANSLATE_NOOP("QFontDatabase", "Armenian");
2269  break;
2270  case Hebrew:
2271  name = QT_TRANSLATE_NOOP("QFontDatabase", "Hebrew");
2272  break;
2273  case Arabic:
2274  name = QT_TRANSLATE_NOOP("QFontDatabase", "Arabic");
2275  break;
2276  case Syriac:
2277  name = QT_TRANSLATE_NOOP("QFontDatabase", "Syriac");
2278  break;
2279  case Thaana:
2280  name = QT_TRANSLATE_NOOP("QFontDatabase", "Thaana");
2281  break;
2282  case Devanagari:
2283  name = QT_TRANSLATE_NOOP("QFontDatabase", "Devanagari");
2284  break;
2285  case Bengali:
2286  name = QT_TRANSLATE_NOOP("QFontDatabase", "Bengali");
2287  break;
2288  case Gurmukhi:
2289  name = QT_TRANSLATE_NOOP("QFontDatabase", "Gurmukhi");
2290  break;
2291  case Gujarati:
2292  name = QT_TRANSLATE_NOOP("QFontDatabase", "Gujarati");
2293  break;
2294  case Oriya:
2295  name = QT_TRANSLATE_NOOP("QFontDatabase", "Oriya");
2296  break;
2297  case Tamil:
2298  name = QT_TRANSLATE_NOOP("QFontDatabase", "Tamil");
2299  break;
2300  case Telugu:
2301  name = QT_TRANSLATE_NOOP("QFontDatabase", "Telugu");
2302  break;
2303  case Kannada:
2304  name = QT_TRANSLATE_NOOP("QFontDatabase", "Kannada");
2305  break;
2306  case Malayalam:
2307  name = QT_TRANSLATE_NOOP("QFontDatabase", "Malayalam");
2308  break;
2309  case Sinhala:
2310  name = QT_TRANSLATE_NOOP("QFontDatabase", "Sinhala");
2311  break;
2312  case Thai:
2313  name = QT_TRANSLATE_NOOP("QFontDatabase", "Thai");
2314  break;
2315  case Lao:
2316  name = QT_TRANSLATE_NOOP("QFontDatabase", "Lao");
2317  break;
2318  case Tibetan:
2319  name = QT_TRANSLATE_NOOP("QFontDatabase", "Tibetan");
2320  break;
2321  case Myanmar:
2322  name = QT_TRANSLATE_NOOP("QFontDatabase", "Myanmar");
2323  break;
2324  case Georgian:
2325  name = QT_TRANSLATE_NOOP("QFontDatabase", "Georgian");
2326  break;
2327  case Khmer:
2328  name = QT_TRANSLATE_NOOP("QFontDatabase", "Khmer");
2329  break;
2330  case SimplifiedChinese:
2331  name = QT_TRANSLATE_NOOP("QFontDatabase", "Simplified Chinese");
2332  break;
2333  case TraditionalChinese:
2334  name = QT_TRANSLATE_NOOP("QFontDatabase", "Traditional Chinese");
2335  break;
2336  case Japanese:
2337  name = QT_TRANSLATE_NOOP("QFontDatabase", "Japanese");
2338  break;
2339  case Korean:
2340  name = QT_TRANSLATE_NOOP("QFontDatabase", "Korean");
2341  break;
2342  case Vietnamese:
2343  name = QT_TRANSLATE_NOOP("QFontDatabase", "Vietnamese");
2344  break;
2345  case Symbol:
2346  name = QT_TRANSLATE_NOOP("QFontDatabase", "Symbol");
2347  break;
2348  case Ogham:
2349  name = QT_TRANSLATE_NOOP("QFontDatabase", "Ogham");
2350  break;
2351  case Runic:
2352  name = QT_TRANSLATE_NOOP("QFontDatabase", "Runic");
2353  break;
2354  case Nko:
2355  name = QT_TRANSLATE_NOOP("QFontDatabase", "N'Ko");
2356  break;
2357  default:
2358  Q_ASSERT_X(false, "QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter");
2359  break;
2360  }
2361  return QApplication::translate("QFontDatabase", name);
2362 }
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
const char * name
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ writingSystems() [1/2]

QList< QFontDatabase::WritingSystem > QFontDatabase::writingSystems ( ) const

Returns a sorted list of the available writing systems.

This is list generated from information about all installed fonts on the system.

See also
families()

Definition at line 1662 of file qfontdatabase.cpp.

Referenced by writingSystemForFont().

1663 {
1664  QMutexLocker locker(fontDatabaseMutex());
1665 
1667 #ifdef Q_WS_X11
1668  checkSymbolFonts();
1669 #endif
1670 
1671  QList<WritingSystem> list;
1672  for (int i = 0; i < d->count; ++i) {
1673  QtFontFamily *family = d->families[i];
1674  if (family->count == 0)
1675  continue;
1676  for (int x = Latin; x < WritingSystemsCount; ++x) {
1677  const WritingSystem writingSystem = WritingSystem(x);
1678  if (!(family->writingSystems[writingSystem] & QtFontFamily::Supported))
1679  continue;
1680  if (!list.contains(writingSystem))
1681  list.append(writingSystem);
1682  }
1683  }
1684  qSort(list);
1685  return list;
1686 }
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QtFontFamily ** families
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
static void checkSymbolFonts(const QString &family=QString())
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QFontDatabasePrivate * d
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ writingSystems() [2/2]

QList< QFontDatabase::WritingSystem > QFontDatabase::writingSystems ( const QString family) const

Returns a sorted list of the writing systems supported by a given font family.

See also
families()

Definition at line 1695 of file qfontdatabase.cpp.

1696 {
1697  QString familyName, foundryName;
1698  parseFontName(family, foundryName, familyName);
1699 
1700  QMutexLocker locker(fontDatabaseMutex());
1701 
1703 #ifdef Q_WS_X11
1704  checkSymbolFonts(familyName);
1705 #endif
1706 
1707  QList<WritingSystem> list;
1708  QtFontFamily *f = d->family(familyName);
1709  if (!f || f->count == 0)
1710  return list;
1711 
1712  for (int x = Latin; x < WritingSystemsCount; ++x) {
1713  const WritingSystem writingSystem = WritingSystem(x);
1714  if (f->writingSystems[writingSystem] & QtFontFamily::Supported)
1715  list.append(writingSystem);
1716  }
1717  return list;
1718 }
static void parseFontName(const QString &name, QString &foundry, QString &family)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QtFontFamily * family(const QString &f, bool=false)
static void checkSymbolFonts(const QString &family=QString())
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QFontDatabasePrivate * d
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ writingSystemSample()

QString QFontDatabase::writingSystemSample ( WritingSystem  writingSystem)
static

Returns a string with sample characters from writingSystem.

Definition at line 2368 of file qfontdatabase.cpp.

Referenced by QRawFont::fromFont(), and QFontFamilyDelegate::paint().

2369 {
2370  QString sample;
2371  switch (writingSystem) {
2372  case Any:
2373  case Symbol:
2374  // show only ascii characters
2375  sample += QLatin1String("AaBbzZ");
2376  break;
2377  case Latin:
2378  // This is cheating... we only show latin-1 characters so that we don't
2379  // end up loading lots of fonts - at least on X11...
2380  sample = QLatin1String("Aa");
2381  sample += QChar(0x00C3);
2382  sample += QChar(0x00E1);
2383  sample += QLatin1String("Zz");
2384  break;
2385  case Greek:
2386  sample += QChar(0x0393);
2387  sample += QChar(0x03B1);
2388  sample += QChar(0x03A9);
2389  sample += QChar(0x03C9);
2390  break;
2391  case Cyrillic:
2392  sample += QChar(0x0414);
2393  sample += QChar(0x0434);
2394  sample += QChar(0x0436);
2395  sample += QChar(0x044f);
2396  break;
2397  case Armenian:
2398  sample += QChar(0x053f);
2399  sample += QChar(0x054f);
2400  sample += QChar(0x056f);
2401  sample += QChar(0x057f);
2402  break;
2403  case Hebrew:
2404  sample += QChar(0x05D0);
2405  sample += QChar(0x05D1);
2406  sample += QChar(0x05D2);
2407  sample += QChar(0x05D3);
2408  break;
2409  case Arabic:
2410  sample += QChar(0x0628);
2411  sample += QChar(0x0629);
2412  sample += QChar(0x062A);
2413  sample += QChar(0x063A);
2414  break;
2415  case Syriac:
2416  sample += QChar(0x0715);
2417  sample += QChar(0x0725);
2418  sample += QChar(0x0716);
2419  sample += QChar(0x0726);
2420  break;
2421  case Thaana:
2422  sample += QChar(0x0784);
2423  sample += QChar(0x0794);
2424  sample += QChar(0x078c);
2425  sample += QChar(0x078d);
2426  break;
2427  case Devanagari:
2428  sample += QChar(0x0905);
2429  sample += QChar(0x0915);
2430  sample += QChar(0x0925);
2431  sample += QChar(0x0935);
2432  break;
2433  case Bengali:
2434  sample += QChar(0x0986);
2435  sample += QChar(0x0996);
2436  sample += QChar(0x09a6);
2437  sample += QChar(0x09b6);
2438  break;
2439  case Gurmukhi:
2440  sample += QChar(0x0a05);
2441  sample += QChar(0x0a15);
2442  sample += QChar(0x0a25);
2443  sample += QChar(0x0a35);
2444  break;
2445  case Gujarati:
2446  sample += QChar(0x0a85);
2447  sample += QChar(0x0a95);
2448  sample += QChar(0x0aa5);
2449  sample += QChar(0x0ab5);
2450  break;
2451  case Oriya:
2452  sample += QChar(0x0b06);
2453  sample += QChar(0x0b16);
2454  sample += QChar(0x0b2b);
2455  sample += QChar(0x0b36);
2456  break;
2457  case Tamil:
2458  sample += QChar(0x0b89);
2459  sample += QChar(0x0b99);
2460  sample += QChar(0x0ba9);
2461  sample += QChar(0x0bb9);
2462  break;
2463  case Telugu:
2464  sample += QChar(0x0c05);
2465  sample += QChar(0x0c15);
2466  sample += QChar(0x0c25);
2467  sample += QChar(0x0c35);
2468  break;
2469  case Kannada:
2470  sample += QChar(0x0c85);
2471  sample += QChar(0x0c95);
2472  sample += QChar(0x0ca5);
2473  sample += QChar(0x0cb5);
2474  break;
2475  case Malayalam:
2476  sample += QChar(0x0d05);
2477  sample += QChar(0x0d15);
2478  sample += QChar(0x0d25);
2479  sample += QChar(0x0d35);
2480  break;
2481  case Sinhala:
2482  sample += QChar(0x0d90);
2483  sample += QChar(0x0da0);
2484  sample += QChar(0x0db0);
2485  sample += QChar(0x0dc0);
2486  break;
2487  case Thai:
2488  sample += QChar(0x0e02);
2489  sample += QChar(0x0e12);
2490  sample += QChar(0x0e22);
2491  sample += QChar(0x0e32);
2492  break;
2493  case Lao:
2494  sample += QChar(0x0e8d);
2495  sample += QChar(0x0e9d);
2496  sample += QChar(0x0ead);
2497  sample += QChar(0x0ebd);
2498  break;
2499  case Tibetan:
2500  sample += QChar(0x0f00);
2501  sample += QChar(0x0f01);
2502  sample += QChar(0x0f02);
2503  sample += QChar(0x0f03);
2504  break;
2505  case Myanmar:
2506  sample += QChar(0x1000);
2507  sample += QChar(0x1001);
2508  sample += QChar(0x1002);
2509  sample += QChar(0x1003);
2510  break;
2511  case Georgian:
2512  sample += QChar(0x10a0);
2513  sample += QChar(0x10b0);
2514  sample += QChar(0x10c0);
2515  sample += QChar(0x10d0);
2516  break;
2517  case Khmer:
2518  sample += QChar(0x1780);
2519  sample += QChar(0x1790);
2520  sample += QChar(0x17b0);
2521  sample += QChar(0x17c0);
2522  break;
2523  case SimplifiedChinese:
2524  sample += QChar(0x4e2d);
2525  sample += QChar(0x6587);
2526  sample += QChar(0x8303);
2527  sample += QChar(0x4f8b);
2528  break;
2529  case TraditionalChinese:
2530  sample += QChar(0x4e2d);
2531  sample += QChar(0x6587);
2532  sample += QChar(0x7bc4);
2533  sample += QChar(0x4f8b);
2534  break;
2535  case Japanese:
2536  sample += QChar(0x30b5);
2537  sample += QChar(0x30f3);
2538  sample += QChar(0x30d7);
2539  sample += QChar(0x30eb);
2540  sample += QChar(0x3067);
2541  sample += QChar(0x3059);
2542  break;
2543  case Korean:
2544  sample += QChar(0xac00);
2545  sample += QChar(0xac11);
2546  sample += QChar(0xac1a);
2547  sample += QChar(0xac2f);
2548  break;
2549  case Vietnamese:
2550  {
2551  static const char vietnameseUtf8[] = {
2552  char(0xef), char(0xbb), char(0xbf), char(0xe1), char(0xbb), char(0x97),
2553  char(0xe1), char(0xbb), char(0x99),
2554  char(0xe1), char(0xbb), char(0x91),
2555  char(0xe1), char(0xbb), char(0x93),
2556  };
2557  sample += QString::fromUtf8(vietnameseUtf8, sizeof(vietnameseUtf8));
2558  break;
2559  }
2560  case Ogham:
2561  sample += QChar(0x1681);
2562  sample += QChar(0x1682);
2563  sample += QChar(0x1683);
2564  sample += QChar(0x1684);
2565  break;
2566  case Runic:
2567  sample += QChar(0x16a0);
2568  sample += QChar(0x16a1);
2569  sample += QChar(0x16a2);
2570  sample += QChar(0x16a3);
2571  break;
2572  case Nko:
2573  sample += QChar(0x7ca);
2574  sample += QChar(0x7cb);
2575  sample += QChar(0x7cc);
2576  sample += QChar(0x7cd);
2577  break;
2578  default:
2579  break;
2580  }
2581  return sample;
2582 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302

Friends and Related Functions

◆ QFontDef

friend struct QFontDef
friend

Definition at line 166 of file qfontdatabase.h.

Referenced by loadWin().

◆ QFontDialog

friend class QFontDialog
friend

Definition at line 168 of file qfontdatabase.h.

◆ QFontDialogPrivate

friend class QFontDialogPrivate
friend

Definition at line 169 of file qfontdatabase.h.

◆ QFontEngineMultiQPA

friend class QFontEngineMultiQPA
friend

Definition at line 173 of file qfontdatabase.h.

◆ QFontEngineMultiQWS

friend class QFontEngineMultiQWS
friend

Definition at line 171 of file qfontdatabase.h.

◆ QFontEngineMultiS60

friend class QFontEngineMultiS60
friend

Definition at line 172 of file qfontdatabase.h.

◆ QFontEngineMultiXLFD

friend class QFontEngineMultiXLFD
friend

Definition at line 170 of file qfontdatabase.h.

◆ QFontPrivate

friend class QFontPrivate
friend

Definition at line 167 of file qfontdatabase.h.

Properties

◆ d

QFontDatabasePrivate* QFontDatabase::d
private

Definition at line 175 of file qfontdatabase.h.

Referenced by findFont().


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