Qt 4.8
Public Functions | Properties | List of all members
QFontInfo Class Reference

The QFontInfo class provides general information about fonts. More...

#include <qfontinfo.h>

Public Functions

bool bold () const
 Returns true if weight() would return a value greater than QFont::Normal; otherwise returns false. More...
 
bool exactMatch () const
 Returns true if the matched window system font is exactly the same as the one specified by the font; otherwise returns false. More...
 
QString family () const
 Returns the family name of the matched window system font. More...
 
bool fixedPitch () const
 Returns the fixed pitch value of the matched window system font. More...
 
bool italic () const
 Returns the italic value of the matched window system font. More...
 
QFontInfooperator= (const QFontInfo &)
 Assigns the font info in fi. More...
 
bool overline () const
 Returns the overline value of the matched window system font. More...
 
int pixelSize () const
 Returns the pixel size of the matched window system font. More...
 
int pointSize () const
 Returns the point size of the matched window system font. More...
 
qreal pointSizeF () const
 Returns the point size of the matched window system font. More...
 
 QFontInfo (const QFont &)
 Constructs a font info object for font. More...
 
 QFontInfo (const QFontInfo &)
 Constructs a copy of fi. More...
 
bool rawMode () const
 Returns true if the font is a raw mode font; otherwise returns false. More...
 
bool strikeOut () const
 Returns the strikeout value of the matched window system font. More...
 
QFont::Style style () const
 Returns the style value of the matched window system font. More...
 
QFont::StyleHint styleHint () const
 Returns the style of the matched window system font. More...
 
QString styleName () const
 Returns the style name of the matched window system font on system that supports it. More...
 
bool underline () const
 Returns the underline value of the matched window system font. More...
 
int weight () const
 Returns the weight of the matched window system font. More...
 
 ~QFontInfo ()
 Destroys the font info object. More...
 

Properties

QExplicitlySharedDataPointer< QFontPrivated
 

Detailed Description

The QFontInfo class provides general information about fonts.

Note
This class or function is reentrant.

The QFontInfo class provides the same access functions as QFont, e.g. family(), pointSize(), italic(), weight(), fixedPitch(), styleHint() etc. But whilst the QFont access functions return the values that were set, a QFontInfo object returns the values that apply to the font that will actually be used to draw the text.

For example, when the program asks for a 25pt Courier font on a machine that has a non-scalable 24pt Courier font, QFont will (normally) use the 24pt Courier for rendering. In this case, QFont::pointSize() returns 25 and QFontInfo::pointSize() returns 24.

There are three ways to create a QFontInfo object.

  1. Calling the QFontInfo constructor with a QFont creates a font info object for a screen-compatible font, i.e. the font cannot be a printer font. If the font is changed later, the font info object is not updated.

    (Note: If you use a printer font the values returned may be inaccurate. Printer fonts are not always accessible so the nearest screen font is used if a printer font is supplied.)

  2. QWidget::fontInfo() returns the font info for a widget's font. This is equivalent to calling QFontInfo(widget->font()). If the widget's font is changed later, the font info object is not updated.

  3. QPainter::fontInfo() returns the font info for a painter's current font. If the painter's font is changed later, the font info object is not updated.
See also
QFont QFontMetrics QFontDatabase

Definition at line 54 of file qfontinfo.h.

Constructors and Destructors

◆ QFontInfo() [1/2]

QFontInfo::QFontInfo ( const QFont font)

Constructs a font info object for font.

The font must be screen-compatible, i.e. a font you use when drawing text in widgets or pixmaps, not QPicture or QPrinter.

The font info object holds the information for the font that is passed in the constructor at the time it is created, and is not updated if the font's attributes are changed later.

Use QPainter::fontInfo() to get the font info when painting. This will give correct results also when painting on paint device that is not screen-compatible.

Definition at line 2634 of file qfont.cpp.

2635  : d(font.d.data())
2636 {
2637 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343

◆ QFontInfo() [2/2]

QFontInfo::QFontInfo ( const QFontInfo fi)

Constructs a copy of fi.

Definition at line 2642 of file qfont.cpp.

2643  : d(fi.d.data())
2644 {
2645 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82

◆ ~QFontInfo()

QFontInfo::~QFontInfo ( )

Destroys the font info object.

Definition at line 2650 of file qfont.cpp.

2651 {
2652 }

Functions

◆ bold()

bool QFontInfo::bold ( ) const
inline

Returns true if weight() would return a value greater than QFont::Normal; otherwise returns false.

See also
weight(), QFont::bold()

Definition at line 71 of file qfontinfo.h.

71 { return weight() > QFont::Normal; }
int weight() const
Returns the weight of the matched window system font.
Definition: qfont.cpp:2758

◆ exactMatch()

bool QFontInfo::exactMatch ( ) const

Returns true if the matched window system font is exactly the same as the one specified by the font; otherwise returns false.

See also
QFont::exactMatch()

Definition at line 2878 of file qfont.cpp.

2879 {
2881  Q_ASSERT(engine != 0);
2882  return (d->rawMode
2883  ? engine->type() != QFontEngine::Box
2884  : d->request.exactMatch(engine->fontDef));
2885 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Type type() const =0
uint rawMode
Definition: qfont_p.h:187
QFontDef request
Definition: qfont_p.h:178
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
bool exactMatch(const QFontDef &other) const
Definition: qfont.cpp:102
QFontDef fontDef

◆ family()

QString QFontInfo::family ( ) const

Returns the family name of the matched window system font.

See also
QFont::family()

Definition at line 2668 of file qfont.cpp.

Referenced by QFontComboBoxPrivate::_q_updateModel(), and qt_set_x11_resources().

2669 {
2671  Q_ASSERT(engine != 0);
2672  return engine->fontDef.family;
2673 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef
QString family
Definition: qfont_p.h:82

◆ fixedPitch()

bool QFontInfo::fixedPitch ( ) const

Returns the fixed pitch value of the matched window system font.

See also
QFont::fixedPitch()

Definition at line 2826 of file qfont.cpp.

2827 {
2829  Q_ASSERT(engine != 0);
2830 #ifdef Q_OS_MAC
2831  if (!engine->fontDef.fixedPitchComputed) {
2832  QChar ch[2] = { QLatin1Char('i'), QLatin1Char('m') };
2834  int l = 2;
2835  engine->stringToCMap(ch, 2, &g, &l, 0);
2836  engine->fontDef.fixedPitch = g.advances_x[0] == g.advances_x[1];
2837  engine->fontDef.fixedPitchComputed = true;
2838  }
2839 #endif
2840  return engine->fontDef.fixedPitch;
2841 }
uint fixedPitch
Definition: qfont_p.h:96
uint fixedPitchComputed
Definition: qfont_p.h:102
QFixed * advances_x
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFactoryLoader * l
QFontDef fontDef
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ italic()

bool QFontInfo::italic ( ) const

Returns the italic value of the matched window system font.

See also
QFont::italic()

Definition at line 2734 of file qfont.cpp.

Referenced by qt_set_x11_resources().

2735 {
2737  Q_ASSERT(engine != 0);
2738  return engine->fontDef.style != QFont::StyleNormal;
2739 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
uint style
Definition: qfont_p.h:97
QFontDef fontDef

◆ operator=()

QFontInfo & QFontInfo::operator= ( const QFontInfo fi)

Assigns the font info in fi.

Definition at line 2657 of file qfont.cpp.

2658 {
2659  d = fi.d.data();
2660  return *this;
2661 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82

◆ overline()

bool QFontInfo::overline ( ) const

Returns the overline value of the matched window system font.

See also
QFont::overline()
Warning
This function is not part of the public interface.

Here we read the overline flag directly from the QFont. This is OK for X11 and for Windows because we always get what we want.

Definition at line 2803 of file qfont.cpp.

2804 {
2805  return d->overline;
2806 }
uint overline
Definition: qfont_p.h:189
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82

◆ pixelSize()

int QFontInfo::pixelSize ( ) const

Returns the pixel size of the matched window system font.

See also
QFont::pointSize()

Definition at line 2722 of file qfont.cpp.

Referenced by QVGFontEngineCleaner::fontEngineDestroyed(), and qt_set_x11_resources().

2723 {
2725  Q_ASSERT(engine != 0);
2726  return engine->fontDef.pixelSize;
2727 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal pixelSize
Definition: qfont_p.h:90
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef

◆ pointSize()

int QFontInfo::pointSize ( ) const

Returns the point size of the matched window system font.

See also
pointSizeF() QFont::pointSize()

Definition at line 2698 of file qfont.cpp.

Referenced by QFontDialog::setCurrentFont().

2699 {
2701  Q_ASSERT(engine != 0);
2702  return qRound(engine->fontDef.pointSize);
2703 }
qreal pointSize
Definition: qfont_p.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ pointSizeF()

qreal QFontInfo::pointSizeF ( ) const

Returns the point size of the matched window system font.

See also
QFont::pointSizeF()

Definition at line 2710 of file qfont.cpp.

Referenced by QCleanlooksStyle::drawControl(), and QMacStyle::drawControl().

2711 {
2713  Q_ASSERT(engine != 0);
2714  return engine->fontDef.pointSize;
2715 }
qreal pointSize
Definition: qfont_p.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef

◆ rawMode()

bool QFontInfo::rawMode ( ) const

Returns true if the font is a raw mode font; otherwise returns false.

If it is a raw mode font, all other functions in QFontInfo will return the same values set in the QFont, regardless of the font actually used.

See also
QFont::rawMode()

Definition at line 2867 of file qfont.cpp.

Referenced by qt_set_x11_resources().

2868 {
2869  return d->rawMode;
2870 }
uint rawMode
Definition: qfont_p.h:187
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82

◆ strikeOut()

bool QFontInfo::strikeOut ( ) const

Returns the strikeout value of the matched window system font.

See also
QFont::strikeOut()
Warning
This function is not part of the public interface. Here we read the strikeOut flag directly from the QFont. This is OK for X11 and for Windows because we always get what we want.

Definition at line 2816 of file qfont.cpp.

Referenced by qt_set_x11_resources().

2817 {
2818  return d->strikeOut;
2819 }
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
uint strikeOut
Definition: qfont_p.h:190

◆ style()

QFont::Style QFontInfo::style ( ) const

Returns the style value of the matched window system font.

See also
QFont::style()

Definition at line 2746 of file qfont.cpp.

Referenced by QFontDatabase::styleString().

2747 {
2749  Q_ASSERT(engine != 0);
2750  return (QFont::Style)engine->fontDef.style;
2751 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
uint style
Definition: qfont_p.h:97
QFontDef fontDef

◆ styleHint()

QFont::StyleHint QFontInfo::styleHint ( ) const

Returns the style of the matched window system font.

Currently only returns the style hint set in QFont.

See also
QFont::styleHint() QFont::StyleHint

Definition at line 2850 of file qfont.cpp.

Referenced by qt_set_x11_resources().

2851 {
2853  Q_ASSERT(engine != 0);
2854  return (QFont::StyleHint) engine->fontDef.styleHint;
2855 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
Definition: qfont.h:69
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef
uint styleHint
Definition: qfont_p.h:93

◆ styleName()

QString QFontInfo::styleName ( ) const

Returns the style name of the matched window system font on system that supports it.

Since
4.8
See also
QFont::styleName()

Definition at line 2686 of file qfont.cpp.

Referenced by QFontDatabase::styleString().

2687 {
2689  Q_ASSERT(engine != 0);
2690  return engine->fontDef.styleName;
2691 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QString styleName
Definition: qfont_p.h:83
QFontDef fontDef

◆ underline()

bool QFontInfo::underline ( ) const

Returns the underline value of the matched window system font.

See also
QFont::underline()
Warning
This function is not part of the public interface.

Here we read the underline flag directly from the QFont. This is OK for X11 and for Windows because we always get what we want.

Definition at line 2788 of file qfont.cpp.

Referenced by qt_set_x11_resources().

2789 {
2790  return d->underline;
2791 }
uint underline
Definition: qfont_p.h:188
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82

◆ weight()

int QFontInfo::weight ( ) const

Returns the weight of the matched window system font.

See also
QFont::weight(), bold()

Definition at line 2758 of file qfont.cpp.

Referenced by qt_set_x11_resources(), and QFontDatabase::styleString().

2759 {
2761  Q_ASSERT(engine != 0);
2762  return engine->fontDef.weight;
2763 
2764 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
uint weight
Definition: qfont_p.h:95
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
QFontDef fontDef

Properties

◆ d


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