QFontDatabase Class Reference

#include <qfontdatabase.h>

Collaboration diagram for QFontDatabase:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

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, e.g. "Helvetica [Adobe]" and "Helvetica [Cronyx]". When you specify a family you can either use the old hyphenated Qt 2.x "foundry-family" format, e.g. "Cronyx-Helvetica", or the new bracketed Qt 3.x "family [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a foundry it is always returned, e.g. by families(), using the bracketed format.

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:

snippets/qfontdatabase/main.cpp QFontDatabase database; } }

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 46 of file qfontdatabase.h.

Public Types

enum  WritingSystem

Public Member Functions

 QFontDatabase ()
QList< WritingSystemwritingSystems () const
QList< WritingSystemwritingSystems (const QString &family) const
QStringList families (WritingSystem writingSystem=Any) const
QStringList styles (const QString &family) const
QList< int > pointSizes (const QString &family, const QString &style=QString())
QList< int > smoothSizes (const QString &family, const QString &style)
QString styleString (const QFont &font)
QString styleString (const QFontInfo &fontInfo)
QFont font (const QString &family, const QString &style, int pointSize) const
bool isBitmapScalable (const QString &family, const QString &style=QString()) const
bool isSmoothlyScalable (const QString &family, const QString &style=QString()) const
bool isScalable (const QString &family, const QString &style=QString()) const
bool isFixedPitch (const QString &family, const QString &style=QString()) const
bool italic (const QString &family, const QString &style) const
bool bold (const QString &family, const QString &style) const
int weight (const QString &family, const QString &style) const

Static Public Member Functions

static QList< int > standardSizes ()
static QString writingSystemName (WritingSystem writingSystem)
static QString writingSystemSample (WritingSystem writingSystem)
static int addApplicationFont (const QString &fileName)
static int addApplicationFontFromData (const QByteArray &fontData)
static QStringList applicationFontFamilies (int id)
static bool removeApplicationFont (int id)
static bool removeAllApplicationFonts ()

Static Private Member Functions

static void createDatabase ()
static void parseFontName (const QString &name, QString &foundry, QString &family)
static QFontEnginefindFont (int script, const QFontPrivate *fp, const QFontDef &request, int force_encoding_id=-1)

Private Attributes

QFontDatabasePrivated

Friends

struct QFontDef
class QFontPrivate
class QFontDialog
class QFontEngineMultiXLFD


Member Enumeration Documentation

enum QFontDatabase::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

WritingSystemsCount

Definition at line 51 of file qfontdatabase.h.

00051                        {
00052         Any,
00053 
00054         Latin,
00055         Greek,
00056         Cyrillic,
00057         Armenian,
00058         Hebrew,
00059         Arabic,
00060         Syriac,
00061         Thaana,
00062         Devanagari,
00063         Bengali,
00064         Gurmukhi,
00065         Gujarati,
00066         Oriya,
00067         Tamil,
00068         Telugu,
00069         Kannada,
00070         Malayalam,
00071         Sinhala,
00072         Thai,
00073         Lao,
00074         Tibetan,
00075         Myanmar,
00076         Georgian,
00077         Khmer,
00078         SimplifiedChinese,
00079         TraditionalChinese,
00080         Japanese,
00081         Korean,
00082         Vietnamese,
00083 
00084         Symbol,
00085         Other = Symbol,
00086 
00087         Ogham,
00088         Runic,
00089 
00090         WritingSystemsCount
00091     };


Constructor & Destructor Documentation

QFontDatabase::QFontDatabase (  ) 

Creates a font database object.

Definition at line 1359 of file qfontdatabase.cpp.

References createDatabase(), and d.

01360 {
01361     createDatabase();
01362 
01363     d = privateDb();
01364 }

Here is the call graph for this function:


Member Function Documentation

QList< int > QFontDatabase::standardSizes (  )  [static]

Returns a list of standard font sizes.

See also:
smoothSizes(), pointSizes()

Definition at line 1835 of file qfontdatabase.cpp.

Referenced by MainWindow::findSizes(), pointSizes(), TextEdit::setupTextActions(), and smoothSizes().

01836 {
01837     QList<int> ret;
01838     static const unsigned short standard[] =
01839         { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 };
01840     const unsigned short *sizes = standard;
01841     while (*sizes) ret << *sizes++;
01842     return ret;
01843 }

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 1414 of file qfontdatabase.cpp.

References checkSymbolFonts(), QFontDatabasePrivate::count, d, QFontDatabasePrivate::families, i, Latin, load(), qSort(), QtFontFamily::Supported, WritingSystemsCount, and x.

01415 {
01416     ::load();
01417 #ifdef Q_WS_X11
01418     ::checkSymbolFonts();
01419 #endif
01420 
01421     QList<WritingSystem> list;
01422     for (int i = 0; i < d->count; ++i) {
01423         QtFontFamily *family = d->families[i];
01424         if (family->count == 0)
01425             continue;
01426         for (int x = Latin; x < WritingSystemsCount; ++x) {
01427             const WritingSystem writingSystem = WritingSystem(x);
01428             if (!(family->writingSystems[writingSystem] & QtFontFamily::Supported))
01429                 continue;
01430             if (!list.contains(writingSystem))
01431                 list.append(writingSystem);
01432         }
01433     }
01434     qSort(list);
01435     return list;
01436 }

Here is the call graph for this function:

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 1445 of file qfontdatabase.cpp.

References checkSymbolFonts(), QtFontFamily::count, d, QFontDatabasePrivate::family(), Latin, load(), parseFontName(), QtFontFamily::Supported, QtFontFamily::writingSystems, WritingSystemsCount, and x.

01446 {
01447     QString familyName, foundryName;
01448     parseFontName(family, foundryName, familyName);
01449 
01450     ::load();
01451 #ifdef Q_WS_X11
01452     ::checkSymbolFonts(familyName);
01453 #endif
01454 
01455     QList<WritingSystem> list;
01456     QtFontFamily *f = d->family(familyName);
01457     if (!f || f->count == 0)
01458         return list;
01459 
01460     for (int x = Latin; x < WritingSystemsCount; ++x) {
01461         const WritingSystem writingSystem = WritingSystem(x);
01462         if (f->writingSystems[writingSystem] & QtFontFamily::Supported)
01463             list.append(writingSystem);
01464     }
01465     return list;
01466 }

Here is the call graph for this function:

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 1479 of file qfontdatabase.cpp.

References Any, QList< T >::append(), checkSymbolFonts(), QFontDatabasePrivate::count, QtFontFamily::count, d, QFontDatabasePrivate::families, QtFontFamily::foundries, i, j, load(), QtFontFoundry::name, QtFontFamily::name, QtFontFamily::Supported, and QtFontFamily::writingSystems.

Referenced by QFontComboBoxPrivate::_q_updateModel(), and MainWindow::setupFontTree().

01480 {
01481     ::load();
01482 #ifdef Q_WS_X11
01483     if (writingSystem != Any)
01484         ::checkSymbolFonts();
01485 #endif
01486 
01487     QStringList flist;
01488     for (int i = 0; i < d->count; i++) {
01489         QtFontFamily *f = d->families[i];
01490         if (f->count == 0)
01491             continue;
01492         if (writingSystem != Any && (f->writingSystems[writingSystem] != QtFontFamily::Supported))
01493             continue;
01494         if (f->count == 1) {
01495             flist.append(f->name);
01496         } else {
01497             for (int j = 0; j < f->count; j++) {
01498                 QString str = f->name;
01499                 QString foundry = f->foundries[j]->name;
01500                 if (!foundry.isEmpty()) {
01501                     str += QLatin1String(" [");
01502                     str += foundry;
01503                     str += QLatin1String("]");
01504                 }
01505                 flist.append(str);
01506             }
01507         }
01508     }
01509     return flist;
01510 }

Here is the call graph for this function:

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 1519 of file qfontdatabase.cpp.

References QtFontFoundry::count, QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, i, QString::isEmpty(), j, QtFontStyle::key, l, load(), parseFontName(), QtFontFoundry::style(), QtFontFoundry::styles, styleString(), and ucstricmp().

Referenced by MainWindow::familySelected(), MainWindow::findStyles(), and MainWindow::setupFontTree().

01520 {
01521     QString familyName, foundryName;
01522     parseFontName(family, foundryName, familyName);
01523 
01524     ::load(familyName);
01525 
01526     QStringList l;
01527     QtFontFamily *f = d->family(familyName);
01528     if (!f)
01529         return l;
01530 
01531     QtFontFoundry allStyles(foundryName);
01532     for (int j = 0; j < f->count; j++) {
01533         QtFontFoundry *foundry = f->foundries[j];
01534         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01535             for (int k = 0; k < foundry->count; k++) {
01536                 QtFontStyle::Key ke(foundry->styles[k]->key);
01537                 ke.stretch = 0;
01538                 allStyles.style(ke, true);
01539             }
01540         }
01541     }
01542 
01543     for (int i = 0; i < allStyles.count; i++)
01544         l.append(::styleString(allStyles.styles[i]->key.weight, (QFont::Style)allStyles.styles[i]->key.style));
01545     return l;
01546 }

Here is the call graph for this function:

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

Returns a list of the point sizes available for the font that has family family and style style. The list may be empty.

See also:
smoothSizes(), standardSizes()

Definition at line 1667 of file qfontdatabase.cpp.

References QX11Info::appDpiY(), QList< T >::append(), QList< T >::contains(), QString::count(), QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, l, load(), parseFontName(), qRound(), size, standardSizes(), and ucstricmp().

01669 {
01670 #if defined(Q_WS_WIN)
01671     // windows and macosx are always smoothly scalable
01672     Q_UNUSED(family);
01673     Q_UNUSED(style);
01674     return standardSizes();
01675 #else
01676     bool smoothScalable = false;
01677     QString familyName, foundryName;
01678     parseFontName(family, foundryName, familyName);
01679 
01680     ::load(familyName);
01681 
01682     QtFontStyle::Key styleKey(style);
01683 
01684     QList<int> sizes;
01685 
01686     QtFontFamily *fam = d->family(familyName);
01687     if (!fam) return sizes;
01688 
01689 
01690 #ifdef Q_WS_X11
01691     int dpi = QX11Info::appDpiY();
01692 #else
01693     const int dpi = 72; // embedded
01694 #endif
01695 
01696     for (int j = 0; j < fam->count; j++) {
01697         QtFontFoundry *foundry = fam->foundries[j];
01698         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01699             QtFontStyle *style = foundry->style(styleKey);
01700             if (!style) continue;
01701 
01702             if (style->smoothScalable) {
01703                 smoothScalable = true;
01704                 goto end;
01705             }
01706             for (int l = 0; l < style->count; l++) {
01707                 const QtFontSize *size = style->pixelSizes + l;
01708 
01709                 if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
01710                     const uint pointSize = qRound(size->pixelSize * dpi / 72.);
01711                     if (! sizes.contains(pointSize))
01712                         sizes.append(pointSize);
01713                 }
01714             }
01715         }
01716     }
01717  end:
01718     if (smoothScalable)
01719         return standardSizes();
01720 
01721     qSort(sizes);
01722     return sizes;
01723 #endif
01724 }

Here is the call graph for this function:

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

Returns the point sizes of a font that has family family and style 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 1771 of file qfontdatabase.cpp.

References QX11Info::appDpiY(), QList< T >::append(), QList< T >::contains(), QString::count(), QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, l, load(), parseFontName(), qRound(), size, standardSizes(), and ucstricmp().

Referenced by MainWindow::findSizes().

01773 {
01774 #ifdef Q_WS_WIN
01775     Q_UNUSED(family);
01776     Q_UNUSED(style);
01777     return QFontDatabase::standardSizes();
01778 #else
01779     bool smoothScalable = false;
01780     QString familyName, foundryName;
01781     parseFontName(family, foundryName, familyName);
01782 
01783     ::load(familyName);
01784 
01785     QtFontStyle::Key styleKey(style);
01786 
01787     QList<int> sizes;
01788 
01789     QtFontFamily *fam = d->family(familyName);
01790     if (!fam)
01791         return sizes;
01792 
01793 #ifdef Q_WS_X11
01794     int dpi = QX11Info::appDpiY();
01795 #else
01796     const int dpi = 72; // embedded
01797 #endif
01798     for (int j = 0; j < fam->count; j++) {
01799         QtFontFoundry *foundry = fam->foundries[j];
01800         if (foundryName.isEmpty() ||
01801              ucstricmp(foundry->name, foundryName) == 0) {
01802             QtFontStyle *style = foundry->style(styleKey);
01803             if (!style) continue;
01804 
01805             if (style->smoothScalable) {
01806                 smoothScalable = true;
01807                 goto end;
01808             }
01809             for (int l = 0; l < style->count; l++) {
01810                 const QtFontSize *size = style->pixelSizes + l;
01811 
01812                 if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
01813                     const uint pointSize = qRound(size->pixelSize * dpi / 72.);
01814                     if (! sizes.contains(pointSize))
01815                         sizes.append(pointSize);
01816                 }
01817             }
01818         }
01819     }
01820  end:
01821     if (smoothScalable)
01822         return QFontDatabase::standardSizes();
01823 
01824     qSort(sizes);
01825     return sizes;
01826 #endif
01827 }

Here is the call graph for this function:

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 1287 of file qfontdatabase.cpp.

References font(), QFont::style(), styleString(), and QFont::weight().

Referenced by MainWindow::findSizes(), and styles().

01288 {
01289     return ::styleString(font.weight(), font.style());
01290 }

Here is the call graph for this function:

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 1297 of file qfontdatabase.cpp.

References QFontInfo::style(), styleString(), and QFontInfo::weight().

01298 {
01299     return ::styleString(fontInfo.weight(), fontInfo.style());
01300 }

Here is the call graph for this function:

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 1732 of file qfontdatabase.cpp.

References bestStyle(), QtFontFamily::count, d, QFontDatabasePrivate::family(), QApplication::font(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), s, QFont::setStyle(), QtFontFoundry::style(), and ucstricmp().

Referenced by MainWindow::buildFont(), MainWindow::fileSave(), styleString(), and CharacterWidget::updateStyle().

01734 {
01735     QString familyName, foundryName;
01736     parseFontName(family, foundryName, familyName);
01737 
01738     ::load(familyName);
01739 
01740     QtFontFoundry allStyles(foundryName);
01741     QtFontFamily *f = d->family(familyName);
01742     if (!f) return QApplication::font();
01743 
01744     for (int j = 0; j < f->count; j++) {
01745         QtFontFoundry *foundry = f->foundries[j];
01746         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01747             for (int k = 0; k < foundry->count; k++)
01748                 allStyles.style(foundry->styles[k]->key, true);
01749         }
01750     }
01751 
01752     QtFontStyle::Key styleKey(style);
01753     QtFontStyle *s = bestStyle(&allStyles, styleKey);
01754 
01755     if (!s) // no styles found?
01756         return QApplication::font();
01757     QFont fnt(family, pointSize, s->key.weight);
01758     fnt.setStyle((QFont::Style)s->key.style);
01759     return fnt;
01760 }

Here is the call graph for this function:

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 1580 of file qfontdatabase.cpp.

References QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), and ucstricmp().

Referenced by isScalable().

01582 {
01583     bool bitmapScalable = false;
01584     QString familyName, foundryName;
01585     parseFontName(family, foundryName, familyName);
01586 
01587     ::load(familyName);
01588 
01589     QtFontStyle::Key styleKey(style);
01590 
01591     QtFontFamily *f = d->family(familyName);
01592     if (!f) return bitmapScalable;
01593 
01594     for (int j = 0; j < f->count; j++) {
01595         QtFontFoundry *foundry = f->foundries[j];
01596         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01597             for (int k = 0; k < foundry->count; k++)
01598                 if ((style.isEmpty() || foundry->styles[k]->key == styleKey)
01599                     && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) {
01600                     bitmapScalable = true;
01601                     goto end;
01602                 }
01603         }
01604     }
01605  end:
01606     return bitmapScalable;
01607 }

Here is the call graph for this function:

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 1618 of file qfontdatabase.cpp.

References QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), and ucstricmp().

Referenced by QFontComboBoxPrivate::_q_updateModel(), MainWindow::findSizes(), and isScalable().

01619 {
01620     bool smoothScalable = false;
01621     QString familyName, foundryName;
01622     parseFontName(family, foundryName, familyName);
01623 
01624     ::load(familyName);
01625 
01626     QtFontStyle::Key styleKey(style);
01627 
01628     QtFontFamily *f = d->family(familyName);
01629     if (!f) return smoothScalable;
01630 
01631     for (int j = 0; j < f->count; j++) {
01632         QtFontFoundry *foundry = f->foundries[j];
01633         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01634             for (int k = 0; k < foundry->count; k++)
01635                 if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
01636                     smoothScalable = true;
01637                     goto end;
01638                 }
01639         }
01640     }
01641  end:
01642     return smoothScalable;
01643 }

Here is the call graph for this function:

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 1651 of file qfontdatabase.cpp.

References isBitmapScalable(), and isSmoothlyScalable().

01653 {
01654     if (isSmoothlyScalable(family, style))
01655         return true;
01656 
01657     return isBitmapScalable(family, style);
01658 }

Here is the call graph for this function:

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 1553 of file qfontdatabase.cpp.

References d, QFontDatabasePrivate::family(), QtFontFamily::fixedPitch, load(), and parseFontName().

Referenced by QFontComboBoxPrivate::_q_updateModel().

01555 {
01556     Q_UNUSED(style);
01557 
01558     QString familyName, foundryName;
01559     parseFontName(family, foundryName, familyName);
01560 
01561     ::load(familyName);
01562 
01563     QtFontFamily *f = d->family(familyName);
01564 #if !defined(QWS) && defined(Q_OS_MAC)
01565     qt_mac_get_fixed_pitch(f);
01566 #endif
01567     return (f && f->fixedPitch);
01568 }

Here is the call graph for this function:

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 1852 of file qfontdatabase.cpp.

References QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), s, QtFontFoundry::style(), QFont::StyleItalic, and ucstricmp().

Referenced by MainWindow::setupFontTree().

01853 {
01854     QString familyName, foundryName;
01855     parseFontName(family, foundryName, familyName);
01856 
01857     ::load(familyName);
01858 
01859     QtFontFoundry allStyles(foundryName);
01860     QtFontFamily *f = d->family(familyName);
01861     if (!f) return false;
01862 
01863     for (int j = 0; j < f->count; j++) {
01864         QtFontFoundry *foundry = f->foundries[j];
01865         if (foundryName.isEmpty() || ucstricmp(foundry->name, foundryName) == 0) {
01866             for (int k = 0; k < foundry->count; k++)
01867                 allStyles.style(foundry->styles[k]->key, true);
01868         }
01869     }
01870 
01871     QtFontStyle::Key styleKey(style);
01872     QtFontStyle *s = allStyles.style(styleKey);
01873     return s && s->key.style == QFont::StyleItalic;
01874 }

Here is the call graph for this function:

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 1883 of file qfontdatabase.cpp.

References QFont::Bold, QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), s, QtFontFoundry::style(), and ucstricmp().

01885 {
01886     QString familyName, foundryName;
01887     parseFontName(family, foundryName, familyName);
01888 
01889     ::load(familyName);
01890 
01891     QtFontFoundry allStyles(foundryName);
01892     QtFontFamily *f = d->family(familyName);
01893     if (!f) return false;
01894 
01895     for (int j = 0; j < f->count; j++) {
01896         QtFontFoundry *foundry = f->foundries[j];
01897         if (foundryName.isEmpty() ||
01898              ucstricmp(foundry->name, foundryName) == 0) {
01899             for (int k = 0; k < foundry->count; k++)
01900                 allStyles.style(foundry->styles[k]->key, true);
01901         }
01902     }
01903 
01904     QtFontStyle::Key styleKey(style);
01905     QtFontStyle *s = allStyles.style(styleKey);
01906     return s && s->key.weight >= QFont::Bold;
01907 }

Here is the call graph for this function:

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 1917 of file qfontdatabase.cpp.

References QtFontFamily::count, d, QFontDatabasePrivate::family(), QtFontFamily::foundries, QString::isEmpty(), j, load(), parseFontName(), s, QtFontFoundry::style(), and ucstricmp().

Referenced by MainWindow::setupFontTree().

01919 {
01920     QString familyName, foundryName;
01921     parseFontName(family, foundryName, familyName);
01922 
01923     ::load(familyName);
01924 
01925     QtFontFoundry allStyles(foundryName);
01926     QtFontFamily *f = d->family(familyName);
01927     if (!f) return -1;
01928 
01929     for (int j = 0; j < f->count; j++) {
01930         QtFontFoundry *foundry = f->foundries[j];
01931         if (foundryName.isEmpty() ||
01932              ucstricmp(foundry->name, foundryName) == 0) {
01933             for (int k = 0; k < foundry->count; k++)
01934                 allStyles.style(foundry->styles[k]->key, true);
01935         }
01936     }
01937 
01938     QtFontStyle::Key styleKey(style);
01939     QtFontStyle *s = allStyles.style(styleKey);
01940     return s ? s->key.weight : -1;
01941 }

Here is the call graph for this function:

QString QFontDatabase::writingSystemName ( WritingSystem  writingSystem  )  [static]

Returns the names the writingSystem (e.g. for displaying to the user in a dialog).

Definition at line 1948 of file qfontdatabase.cpp.

References Any, Arabic, Armenian, Bengali, Cyrillic, Devanagari, QString::fromLatin1(), Georgian, Greek, Gujarati, Gurmukhi, Hebrew, Japanese, Kannada, Khmer, Korean, Lao, Latin, Malayalam, Myanmar, name, Ogham, Oriya, qApp, Runic, SimplifiedChinese, Sinhala, Syriac, Tamil, Telugu, Thaana, Thai, Tibetan, TraditionalChinese, and Vietnamese.

Referenced by initializeDb(), and QFontDialog::QFontDialog().

01949 {
01950     const char *name = 0;
01951     switch (writingSystem) {
01952     case Any:
01953         name = "Any";
01954         break;
01955     case Latin:
01956         name = "Latin";
01957         break;
01958     case Greek:
01959         name = "Greek";
01960         break;
01961     case Cyrillic:
01962         name = "Cyrillic";
01963         break;
01964     case Armenian:
01965         name = "Armenian";
01966         break;
01967     case Hebrew:
01968         name = "Hebrew";
01969         break;
01970     case Arabic:
01971         name = "Arabic";
01972         break;
01973     case Syriac:
01974         name = "Syriac";
01975         break;
01976     case Thaana:
01977         name = "Thaana";
01978         break;
01979     case Devanagari:
01980         name = "Devanagari";
01981         break;
01982     case Bengali:
01983         name = "Bengali";
01984         break;
01985     case Gurmukhi:
01986         name = "Gurmukhi";
01987         break;
01988     case Gujarati:
01989         name = "Gujarati";
01990         break;
01991     case Oriya:
01992         name = "Oriya";
01993         break;
01994     case Tamil:
01995         name = "Tamil";
01996         break;
01997     case Telugu:
01998         name = "Telugu";
01999         break;
02000     case Kannada:
02001         name = "Kannada";
02002         break;
02003     case Malayalam:
02004         name = "Malayalam";
02005         break;
02006     case Sinhala:
02007         name = "Sinhala";
02008         break;
02009     case Thai:
02010         name = "Thai";
02011         break;
02012     case Lao:
02013         name = "Lao";
02014         break;
02015     case Tibetan:
02016         name = "Tibetan";
02017         break;
02018     case Myanmar:
02019         name = "Myanmar";
02020         break;
02021     case Georgian:
02022         name = "Georgian";
02023         break;
02024     case Khmer:
02025         name = "Khmer";
02026         break;
02027     case SimplifiedChinese:
02028         name = "Simplified Chinese";
02029         break;
02030     case TraditionalChinese:
02031         name = "Traditional Chinese";
02032         break;
02033     case Japanese:
02034         name = "Japanese";
02035         break;
02036     case Korean:
02037         name = "Korean";
02038         break;
02039     case Vietnamese:
02040         name = "Vietnamese";
02041         break;
02042     case Symbol:
02043         name = "Symbol";
02044         break;
02045     case Ogham:
02046         name = "Ogham";
02047         break;
02048     case Runic:
02049         name = "Runic";
02050         break;
02051     default:
02052         Q_ASSERT_X(false, "QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter");
02053         break;
02054     }
02055     return qApp ? qApp->translate("QFont", name) : QString::fromLatin1(name);
02056 }

Here is the call graph for this function:

QString QFontDatabase::writingSystemSample ( WritingSystem  writingSystem  )  [static]

Returns a string with sample characters from writingSystem.

Definition at line 2062 of file qfontdatabase.cpp.

References Any, Arabic, Armenian, Bengali, Cyrillic, Devanagari, Georgian, Greek, Gujarati, Gurmukhi, Hebrew, Japanese, Kannada, Khmer, Korean, Lao, Latin, Malayalam, Myanmar, Ogham, Oriya, Runic, SimplifiedChinese, Sinhala, Syriac, Tamil, Telugu, Thaana, Thai, Tibetan, TraditionalChinese, and Vietnamese.

Referenced by QFontDialogPrivate::_q_writingSystemHighlighted().

02063 {
02064     QString sample;
02065     switch (writingSystem) {
02066     case Any:
02067     case Symbol:
02068         // show only ascii characters
02069         sample += QLatin1String("AaBbzZ");
02070         break;
02071     case Latin:
02072         // This is cheating... we only show latin-1 characters so that we don't
02073         // end up loading lots of fonts - at least on X11...
02074         sample = QLatin1String("Aa");
02075         sample += QChar(0x00C3);
02076         sample += QChar(0x00E1);
02077         sample += QLatin1String("Zz");
02078         break;
02079     case Greek:
02080         sample += QChar(0x0393);
02081         sample += QChar(0x03B1);
02082         sample += QChar(0x03A9);
02083         sample += QChar(0x03C9);
02084         break;
02085     case Cyrillic:
02086         sample += QChar(0x0414);
02087         sample += QChar(0x0434);
02088         sample += QChar(0x0436);
02089         sample += QChar(0x0402);
02090         break;
02091     case Armenian:
02092         sample += QChar(0x053f);
02093         sample += QChar(0x054f);
02094         sample += QChar(0x056f);
02095         sample += QChar(0x057f);
02096         break;
02097     case Hebrew:
02098         sample += QChar(0x05D0);
02099         sample += QChar(0x05D1);
02100         sample += QChar(0x05D2);
02101         sample += QChar(0x05D3);
02102         break;
02103     case Arabic:
02104         sample += QChar(0x0628);
02105         sample += QChar(0x0629);
02106         sample += QChar(0x062A);
02107         sample += QChar(0x063A);
02108         break;
02109     case Syriac:
02110         sample += QChar(0x0715);
02111         sample += QChar(0x0725);
02112         sample += QChar(0x0716);
02113         sample += QChar(0x0726);
02114         break;
02115     case Thaana:
02116         sample += QChar(0x0784);
02117         sample += QChar(0x0794);
02118         sample += QChar(0x078c);
02119         sample += QChar(0x078d);
02120         break;
02121     case Devanagari:
02122         sample += QChar(0x0905);
02123         sample += QChar(0x0915);
02124         sample += QChar(0x0925);
02125         sample += QChar(0x0935);
02126         break;
02127     case Bengali:
02128         sample += QChar(0x0986);
02129         sample += QChar(0x0996);
02130         sample += QChar(0x09a6);
02131         sample += QChar(0x09b6);
02132         break;
02133     case Gurmukhi:
02134         sample += QChar(0x0a05);
02135         sample += QChar(0x0a15);
02136         sample += QChar(0x0a25);
02137         sample += QChar(0x0a35);
02138         break;
02139     case Gujarati:
02140         sample += QChar(0x0a85);
02141         sample += QChar(0x0a95);
02142         sample += QChar(0x0aa5);
02143         sample += QChar(0x0ab5);
02144         break;
02145     case Oriya:
02146         sample += QChar(0x0b06);
02147         sample += QChar(0x0b16);
02148         sample += QChar(0x0b2b);
02149         sample += QChar(0x0b36);
02150         break;
02151     case Tamil:
02152         sample += QChar(0x0b89);
02153         sample += QChar(0x0b99);
02154         sample += QChar(0x0ba9);
02155         sample += QChar(0x0bb9);
02156         break;
02157     case Telugu:
02158         sample += QChar(0x0c05);
02159         sample += QChar(0x0c15);
02160         sample += QChar(0x0c25);
02161         sample += QChar(0x0c35);
02162         break;
02163     case Kannada:
02164         sample += QChar(0x0c85);
02165         sample += QChar(0x0c95);
02166         sample += QChar(0x0ca5);
02167         sample += QChar(0x0cb5);
02168         break;
02169     case Malayalam:
02170         sample += QChar(0x0d05);
02171         sample += QChar(0x0d15);
02172         sample += QChar(0x0d25);
02173         sample += QChar(0x0d35);
02174         break;
02175     case Sinhala:
02176         sample += QChar(0x0d90);
02177         sample += QChar(0x0da0);
02178         sample += QChar(0x0db0);
02179         sample += QChar(0x0dc0);
02180         break;
02181     case Thai:
02182         sample += QChar(0x0e02);
02183         sample += QChar(0x0e12);
02184         sample += QChar(0x0e22);
02185         sample += QChar(0x0e32);
02186         break;
02187     case Lao:
02188         sample += QChar(0x0e8d);
02189         sample += QChar(0x0e9d);
02190         sample += QChar(0x0ead);
02191         sample += QChar(0x0ebd);
02192         break;
02193     case Tibetan:
02194         sample += QChar(0x0f00);
02195         sample += QChar(0x0f01);
02196         sample += QChar(0x0f02);
02197         sample += QChar(0x0f03);
02198         break;
02199     case Myanmar:
02200         sample += QChar(0x1000);
02201         sample += QChar(0x1001);
02202         sample += QChar(0x1002);
02203         sample += QChar(0x1003);
02204         break;
02205     case Georgian:
02206         sample += QChar(0x10a0);
02207         sample += QChar(0x10b0);
02208         sample += QChar(0x10c0);
02209         sample += QChar(0x10d0);
02210         break;
02211     case Khmer:
02212         sample += QChar(0x1780);
02213         sample += QChar(0x1790);
02214         sample += QChar(0x17b0);
02215         sample += QChar(0x17c0);
02216         break;
02217     case SimplifiedChinese:
02218         sample += QChar(0x4e2d);
02219         sample += QChar(0x6587);
02220         sample += QChar(0x8303);
02221         sample += QChar(0x4f8b);
02222         break;
02223     case TraditionalChinese:
02224         sample += QChar(0x4e2d);
02225         sample += QChar(0x6587);
02226         sample += QChar(0x7bc4);
02227         sample += QChar(0x4f8b);
02228         break;
02229     case Japanese:
02230         sample += QChar(0x3050);
02231         sample += QChar(0x3060);
02232         sample += QChar(0x30b0);
02233         sample += QChar(0x30c0);
02234         break;
02235     case Korean:
02236         sample += QChar(0xac00);
02237         sample += QChar(0xac11);
02238         sample += QChar(0xac1a);
02239         sample += QChar(0xac2f);
02240         break;
02241     case Vietnamese:
02242         break;
02243     case Ogham:
02244         sample += QChar(0x1681);
02245         sample += QChar(0x1682);
02246         sample += QChar(0x1683);
02247         sample += QChar(0x1684);
02248         break;
02249     case Runic:
02250         sample += QChar(0x16a0);
02251         sample += QChar(0x16a1);
02252         sample += QChar(0x16a2);
02253         sample += QChar(0x16a3);
02254         break;
02255     default:
02256         break;
02257     }
02258     return sample;
02259 }

int QFontDatabase::addApplicationFont ( const QString fileName  )  [static]

Since:
4.2
Loads the font from the file specified by fileName and makes it available to the application. 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.

See also:
addApplicationFontFromData(), applicationFontFamilies(), removeApplicationFont()

Definition at line 2315 of file qfontdatabase.cpp.

References data, QFile::fileEngine(), QAbstractFileEngine::fileFlags(), QAbstractFileEngine::FlagsMask, QAbstractFileEngine::LocalDiskFlag, QFile::open(), QIODevice::readAll(), and QIODevice::ReadOnly.

02316 {
02317     QByteArray data;
02318     QFile f(fileName);
02319     if (!(f.fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)) {
02320         if (!f.open(QIODevice::ReadOnly))
02321             return -1;
02322         data = f.readAll();
02323     }
02324     return privateDb()->addAppFont(data, fileName);
02325 }

Here is the call graph for this function:

int QFontDatabase::addApplicationFontFromData ( const QByteArray fontData  )  [static]

Since:
4.2
Loads the font from binary data specified by fontData and makes it available to the application. 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.

See also:
addApplicationFont(), applicationFontFamilies(), removeApplicationFont()

Definition at line 2344 of file qfontdatabase.cpp.

02345 {
02346     return privateDb()->addAppFont(fontData, QString() /* fileName */);
02347 }

QStringList QFontDatabase::applicationFontFamilies ( int  id  )  [static]

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

See also:
addApplicationFont(), addApplicationFontFromData()

Definition at line 2357 of file qfontdatabase.cpp.

References QList< T >::value().

02358 {
02359     return privateDb()->applicationFonts.value(id).families;
02360 }

Here is the call graph for this function:

bool QFontDatabase::removeApplicationFont ( int  id  )  [static]

Since:
4.2
Removes the previously loaded application font identified by id. Returns true if unloading of the font succeeded; otherwise returns false.

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

Definition at line 1950 of file qfontdatabase_x11.cpp.

References QFontDatabasePrivate::applicationFonts, QFontDatabasePrivate::invalidate(), and QFontDatabasePrivate::reregisterAppFonts.

01951 {
01952 #if defined(QT_NO_FONTCONFIG)
01953     return false;
01954 #else
01955     QFontDatabasePrivate *db = privateDb();
01956     if (handle < 0 || handle >= db->applicationFonts.count())
01957         return false;
01958 
01959     FcConfigAppFontClear(0);
01960 
01961     db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont();
01962 
01963     db->reregisterAppFonts = true;
01964     db->invalidate();
01965     return true;
01966 #endif
01967 }

Here is the call graph for this function:

bool QFontDatabase::removeAllApplicationFonts (  )  [static]

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

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

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

Definition at line 1969 of file qfontdatabase_x11.cpp.

References QFontDatabasePrivate::applicationFonts, and QFontDatabasePrivate::invalidate().

01970 {
01971 #if defined(QT_NO_FONTCONFIG)
01972     return false;
01973 #else
01974     QFontDatabasePrivate *db = privateDb();
01975     if (db->applicationFonts.isEmpty())
01976         return false;
01977 
01978     FcConfigAppFontClear(0);
01979     db->applicationFonts.clear();
01980     db->invalidate();
01981     return true;
01982 #endif
01983 }

Here is the call graph for this function:

void QFontDatabase::createDatabase (  )  [static, private]

Definition at line 2267 of file qfontdatabase.cpp.

References initializeDb().

Referenced by QFontDatabase().

02268 { initializeDb(); }

Here is the call graph for this function:

void QFontDatabase::parseFontName ( const QString name,
QString foundry,
QString family 
) [static, private]

Definition at line 2262 of file qfontdatabase.cpp.

References name.

Referenced by bold(), QFontDef::exactMatch(), font(), isBitmapScalable(), isFixedPitch(), isSmoothlyScalable(), italic(), pointSizes(), smoothSizes(), styles(), QFontDialog::updateFamilies(), weight(), and writingSystems().

02263 {
02264     ::parseFontName(name, foundry, family);
02265 }

static QFontEngine* QFontDatabase::findFont ( int  script,
const QFontPrivate fp,
const QFontDef request,
int  force_encoding_id = -1 
) [static, private]


Friends And Related Function Documentation

friend struct QFontDef [friend]

Definition at line 140 of file qfontdatabase.h.

friend class QFontPrivate [friend]

Definition at line 141 of file qfontdatabase.h.

friend class QFontDialog [friend]

Definition at line 142 of file qfontdatabase.h.

friend class QFontEngineMultiXLFD [friend]

Definition at line 143 of file qfontdatabase.h.


Member Data Documentation

QFontDatabasePrivate* QFontDatabase::d [private]

Definition at line 145 of file qfontdatabase.h.

Referenced by bold(), families(), font(), isBitmapScalable(), isFixedPitch(), isSmoothlyScalable(), italic(), pointSizes(), QFontDatabase(), smoothSizes(), styles(), weight(), and writingSystems().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:36:43 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1