Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qfont.cpp
index 90dd029..2144930 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtGui module of the Qt Toolkit.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -48,8 +48,9 @@
 #include "qpainter.h"
 #include "qhash.h"
 #include "qdatastream.h"
-#include "qapplication.h"
+#include "qguiapplication.h"
 #include "qstringlist.h"
+#include "qscreen.h"
 
 #include "qthread.h"
 #include "qthreadstorage.h"
 #include <private/qtextengine_p.h>
 #include <limits.h>
 
-#ifdef Q_WS_X11
-#include "qx11info_x11.h"
-#include <private/qt_x11_p.h>
-#endif
-#ifdef Q_WS_QWS
-#include "qscreen_qws.h"
-#if !defined(QT_NO_QWS_QPF2)
-#include <qfile.h>
-#include "qfontengine_qpf_p.h"
-#endif
-#endif
-#ifdef Q_OS_SYMBIAN
-#include <private/qt_s60_p.h>
-#endif
-#ifdef Q_WS_QPA
-#include <QtGui/qplatformscreen_qpa.h>
-#include <QtGui/private/qapplication_p.h>
-#endif
+#include <qpa/qplatformscreen.h>
+#include <QtGui/private/qguiapplication_p.h>
 
-#include <QMutexLocker>
+#include <QtCore/QMutexLocker>
+#include <QtCore/QMutex>
 
 // #define QFONTCACHE_DEBUG
 #ifdef QFONTCACHE_DEBUG
 
 QT_BEGIN_NAMESPACE
 
-#ifdef Q_WS_WIN
-extern HDC shared_dc();
-#endif
 
-#ifdef Q_WS_X11
-extern const QX11Info *qt_x11Info(const QPaintDevice *pd);
-#endif
 
 bool QFontDef::exactMatch(const QFontDef &other) const
 {
@@ -147,12 +127,10 @@ bool QFontDef::exactMatch(const QFontDef &other) const
             && weight        == other.weight
             && style        == other.style
             && this_family   == other_family
+            && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName)
             && (this_foundry.isEmpty()
                 || other_foundry.isEmpty()
                 || this_foundry == other_foundry)
-#ifdef Q_WS_X11
-            && addStyle == other.addStyle
-#endif // Q_WS_X11
        );
 }
 
@@ -160,80 +138,32 @@ extern bool qt_is_gui_used;
 
 Q_GUI_EXPORT int qt_defaultDpiX()
 {
+    if (qApp->testAttribute(Qt::AA_Use96Dpi))
+        return 96;
+
     if (!qt_is_gui_used)
         return 75;
 
-    int dpi;
-#ifdef Q_WS_X11
-    dpi = QX11Info::appDpiX();
-#elif defined(Q_WS_WIN)
-    dpi = GetDeviceCaps(shared_dc(),LOGPIXELSX);
-#elif defined(Q_WS_MAC)
-    extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
-    dpi = qt_mac_defaultDpi_x();
-#elif defined(Q_WS_QWS)
-    if (!qt_screen)
-        return 72;
-    QScreen *screen = qt_screen;
-    const QList<QScreen*> subScreens = qt_screen->subScreens();
-    if (!subScreens.isEmpty())
-        screen = subScreens.at(0);
-    dpi = qRound(screen->width() / (screen->physicalWidth() / qreal(25.4)));
-#elif defined(Q_WS_QPA)
-    QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
-    if (pi) {
-        QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
-        const QSize screenSize = screen->geometry().size();
-        const QSize physicalSize = screen->physicalSize();
-        dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4)));
-    } else {
-        //PI has not been initialised, or it is being initialised. Give a default dpi
-        dpi = 100;
-    }
-#elif defined(Q_OS_SYMBIAN)
-    dpi = S60->defaultDpiX;
-#endif // Q_WS_X11
+    if (const QScreen *screen = QGuiApplication::primaryScreen())
+        return qRound(screen->logicalDotsPerInchX());
 
-    return dpi;
+    //PI has not been initialised, or it is being initialised. Give a default dpi
+    return 100;
 }
 
 Q_GUI_EXPORT int qt_defaultDpiY()
 {
+    if (qApp->testAttribute(Qt::AA_Use96Dpi))
+        return 96;
+
     if (!qt_is_gui_used)
         return 75;
 
-    int dpi;
-#ifdef Q_WS_X11
-    dpi = QX11Info::appDpiY();
-#elif defined(Q_WS_WIN)
-    dpi = GetDeviceCaps(shared_dc(),LOGPIXELSY);
-#elif defined(Q_WS_MAC)
-    extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp
-    dpi = qt_mac_defaultDpi_y();
-#elif defined(Q_WS_QWS)
-    if (!qt_screen)
-        return 72;
-    QScreen *screen = qt_screen;
-    const QList<QScreen*> subScreens = qt_screen->subScreens();
-    if (!subScreens.isEmpty())
-        screen = subScreens.at(0);
-    dpi = qRound(screen->height() / (screen->physicalHeight() / qreal(25.4)));
-#elif defined(Q_WS_QPA)
-    QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
-    if (pi) {
-        QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
-        const QSize screenSize = screen->geometry().size();
-        const QSize physicalSize = screen->physicalSize();
-        dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4)));
-    } else {
-        //PI has not been initialised, or it is being initialised. Give a default dpi
-        dpi = 100;
-    }
-#elif defined(Q_OS_SYMBIAN)
-    dpi = S60->defaultDpiY;
-#endif // Q_WS_X11
+    if (const QScreen *screen = QGuiApplication::primaryScreen())
+        return qRound(screen->logicalDotsPerInchY());
 
-    return dpi;
+    //PI has not been initialised, or it is being initialised. Give a default dpi
+    return 100;
 }
 
 Q_GUI_EXPORT int qt_defaultDpi()
@@ -246,15 +176,6 @@ QFontPrivate::QFontPrivate()
       rawMode(false), underline(false), overline(false), strikeOut(false), kerning(true),
       capital(0), letterSpacingIsAbsolute(false), scFont(0)
 {
-#ifdef Q_WS_X11
-    if (QX11Info::display())
-        screen = QX11Info::appScreen();
-    else
-        screen = 0;
-#endif
-#ifdef Q_WS_WIN
-    hdc = 0;
-#endif
 }
 
 QFontPrivate::QFontPrivate(const QFontPrivate &other)
@@ -265,9 +186,6 @@ QFontPrivate::QFontPrivate(const QFontPrivate &other)
       letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing),
       scFont(other.scFont)
 {
-#ifdef Q_WS_WIN
-    hdc = other.hdc;
-#endif
     if (scFont && scFont != this)
         scFont->ref.ref();
 }
@@ -284,11 +202,7 @@ QFontPrivate::~QFontPrivate()
 
 extern QMutex *qt_fontdatabase_mutex();
 
-#if !defined(Q_WS_MAC)
 #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engines[script]
-#else
-#define QT_FONT_ENGINE_FROM_DATA(data, script) data->engine
-#endif
 
 QFontEngine *QFontPrivate::engineForScript(int script) const
 {
@@ -348,6 +262,9 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
     if (! (mask & QFont::FamilyResolved))
         request.family = other->request.family;
 
+    if (! (mask & QFont::StyleNameResolved))
+        request.styleName = other->request.styleName;
+
     if (! (mask & QFont::SizeResolved)) {
         request.pointSize = other->request.pointSize;
         request.pixelSize = other->request.pixelSize;
@@ -402,26 +319,16 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
 QFontEngineData::QFontEngineData()
     : ref(1), fontCache(QFontCache::instance())
 {
-#if !defined(Q_WS_MAC)
     memset(engines, 0, QUnicodeTables::ScriptCount * sizeof(QFontEngine *));
-#else
-    engine = 0;
-#endif
 }
 
 QFontEngineData::~QFontEngineData()
 {
-#if !defined(Q_WS_MAC)
     for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
         if (engines[i])
             engines[i]->ref.deref();
         engines[i] = 0;
     }
-#else
-    if (engine)
-        engine->ref.deref();
-    engine = 0;
-#endif // Q_WS_X11 || Q_WS_WIN || Q_WS_MAC
 }
 
 
@@ -437,6 +344,7 @@ QFontEngineData::~QFontEngineData()
     \ingroup appearance
     \ingroup shared
     \ingroup richtext-processing
+    \inmodule QtGui
 
 
     When you create a QFont object you specify various attributes that
@@ -448,9 +356,9 @@ QFontEngineData::~QFontEngineData()
     Use QFontMetrics to get measurements, e.g. the pixel length of a
     string using QFontMetrics::width().
 
-    Note that a QApplication instance must exist before a QFont can be
+    Note that a QGuiApplication instance must exist before a QFont can be
     used. You can set the application's default font with
-    QApplication::setFont().
+    QGuiApplication::setFont().
 
     If a chosen font does not include all the characters that
     need to be displayed, QFont will try to find the characters in the
@@ -460,7 +368,7 @@ QFontEngineData::~QFontEngineData()
 
     Create QFonts like this:
 
-    \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 0
+    \snippet code/src_gui_text_qfont.cpp 0
 
     The attributes set in the constructor can also be set later, e.g.
     setFamily(), setPointSize(), setPointSizeFloat(), setWeight() and
@@ -475,7 +383,7 @@ QFontEngineData::~QFontEngineData()
     QFontInfo object.
 
     If the requested font family is unavailable you can influence the
-    \link #fontmatching font matching algorithm\endlink by choosing a
+    \l{#fontmatching}{font matching algorithm} by choosing a
     particular \l{QFont::StyleHint} and \l{QFont::StyleStrategy} with
     setStyleHint(). The default family (corresponding to the current
     style hint) is returned by defaultFamily().
@@ -484,7 +392,7 @@ QFontEngineData::~QFontEngineData()
     lastResortFont() in cases where a suitable match cannot be found.
     You can provide substitutions for font family names using
     insertSubstitution() and insertSubstitutions(). Substitutions can
-    be removed with removeSubstitution(). Use substitute() to retrieve
+    be removed with removeSubstitutions(). Use substitute() to retrieve
     a family's first substitute, or the family name itself if it has
     no substitutes. Use substitutes() to retrieve a list of a family's
     substitutes (which may be empty).
@@ -512,14 +420,14 @@ QFontEngineData::~QFontEngineData()
     \target fontmatching
     The font matching algorithm works as follows:
     \list 1
-    \o The specified font family is searched for.
-    \o If not found, the styleHint() is used to select a replacement
+    \li The specified font family is searched for.
+    \li If not found, the styleHint() is used to select a replacement
        family.
-    \o Each replacement font family is searched for.
-    \o If none of these are found or there was no styleHint(), "helvetica"
+    \li Each replacement font family is searched for.
+    \li If none of these are found or there was no styleHint(), "helvetica"
        will be searched for.
-    \o If "helvetica" isn't found Qt will try the lastResortFamily().
-    \o If the lastResortFamily() isn't found Qt will try the
+    \li If "helvetica" isn't found Qt will try the lastResortFamily().
+    \li If the lastResortFamily() isn't found Qt will try the
        lastResortFont() which will always return a name of some kind.
     \endlist
 
@@ -533,10 +441,10 @@ QFontEngineData::~QFontEngineData()
     Once a font is found, the remaining attributes are matched in order of
     priority:
     \list 1
-    \o fixedPitch()
-    \o pointSize() (see below)
-    \o weight()
-    \o style()
+    \li fixedPitch()
+    \li pointSize() (see below)
+    \li weight()
+    \li style()
     \endlist
 
     If you have a font which matches on family, even if none of the
@@ -557,11 +465,11 @@ QFontEngineData::~QFontEngineData()
 
     Examples:
 
-    \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 1
+    \snippet code/src_gui_text_qfont.cpp 1
     If you had both an Adobe and a Cronyx Helvetica, you might get
     either.
 
-    \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 2
+    \snippet code/src_gui_text_qfont.cpp 2
 
     You can specify the foundry you want in the family name. The font f
     in the above example will be set to "Helvetica
@@ -570,16 +478,16 @@ QFontEngineData::~QFontEngineData()
     To determine the attributes of the font actually used in the window
     system, use a QFontInfo object, e.g.
 
-    \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 3
+    \snippet code/src_gui_text_qfont.cpp 3
 
     To find out font metrics use a QFontMetrics object, e.g.
 
-    \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 4
+    \snippet code/src_gui_text_qfont.cpp 4
 
     For more general information on fonts, see the
-    \link http://nwalsh.com/comp.fonts/FAQ/ comp.fonts FAQ.\endlink
+    \l{comp.fonts FAQ}{comp.fonts FAQ}.
     Information on encodings can be found from
-    \link http://czyborra.com/ Roman Czyborra's\endlink page.
+    \l{Roman Czyborra's} page.
 
     \sa QFontComboBox, QFontMetrics, QFontInfo, QFontDatabase, {Character Map Example}
 */
@@ -626,13 +534,6 @@ QFontEngineData::~QFontEngineData()
 */
 
 /*!
-    \fn Qt::HANDLE QFont::handle() const
-
-    Returns the window system handle to the font, for low-level
-    access. Using this function is \e not portable.
-*/
-
-/*!
     \fn FT_Face QFont::freetypeFace() const
 
     Returns the handle to the primary FreeType face of the font. If font merging is not disabled a
@@ -649,9 +550,7 @@ QFontEngineData::~QFontEngineData()
 
     Returns the name of the font within the underlying window system.
 
-    On X11, this function will return an empty string if Qt is built with
-    FontConfig support; otherwise the XLFD (X Logical Font Description) is
-    returned.
+    On X11, this function will return an empty string.
 
     Using the return value of this function is usually \e not \e
     portable.
@@ -662,11 +561,7 @@ QFontEngineData::~QFontEngineData()
 /*!
     \fn void QFont::setRawName(const QString &name)
 
-    Sets a font by its system specific name. The function is
-    particularly useful under X, where system font settings (for
-    example X resources) are usually available in XLFD (X Logical Font
-    Description) form only. You can pass an XLFD as \a name to this
-    function.
+    Sets a font by its system specific name.
 
     A font set with setRawName() is still a full-featured QFont. It can
     be queried (for example with italic()) or modified (for example with
@@ -675,10 +570,6 @@ QFontEngineData::~QFontEngineData()
     If Qt's internal font database cannot resolve the raw name, the
     font becomes a raw font with \a name as its family.
 
-    Note that the present implementation does not handle wildcards in
-    XLFDs well, and that font aliases (file \c fonts.alias in the font
-    directory on X11) are not supported.
-
     \sa rawName(), setRawMode(), setFamily()
 */
 
@@ -700,7 +591,7 @@ QFontEngineData::~QFontEngineData()
     Returns the family name that corresponds to the current style
     hint.
 
-    \sa StyleHint styleHint() setStyleHint()
+    \sa StyleHint, styleHint(), setStyleHint()
 */
 
 /*!
@@ -719,10 +610,10 @@ QFontEngineData::~QFontEngineData()
     It is theoretically possible that there really isn't a
     lastResortFont() in which case Qt will abort with an error
     message. We have not been able to identify a case where this
-    happens. Please \link bughowto.html report it as a bug\endlink if
+    happens. Please \l{bughowto.html}{report it as a bug} if
     it does, preferably with a list of the fonts you have installed.
 
-    \sa lastResortFamily() rawName()
+    \sa lastResortFamily(), rawName()
 */
 
 /*!
@@ -733,12 +624,7 @@ QFont::QFont(const QFont &font, QPaintDevice *pd)
 {
     Q_ASSERT(pd != 0);
     int dpi = pd->logicalDpiY();
-#ifdef Q_WS_X11
-    const QX11Info *info = qt_x11Info(pd);
-    int screen = info ? info->screen() : 0;
-#else
     const int screen = 0;
-#endif
     if (font.d->dpi != dpi || font.d->screen != screen ) {
         d = new QFontPrivate(*font.d);
         d->dpi = dpi;
@@ -746,10 +632,6 @@ QFont::QFont(const QFont &font, QPaintDevice *pd)
     } else {
         d = font.d.data();
     }
-#ifdef Q_WS_WIN
-    if (pd->devType() == QInternal::Printer && pd->getDC())
-        d->hdc = pd->getDC();
-#endif
 }
 
 /*!
@@ -765,7 +647,7 @@ QFont::QFont(QFontPrivate *data)
 */
 void QFont::detach()
 {
-    if (d->ref == 1) {
+    if (d->ref.load() == 1) {
         if (d->engineData)
             d->engineData->ref.deref();
         d->engineData = 0;
@@ -781,10 +663,10 @@ void QFont::detach()
 /*!
     Constructs a font object that uses the application's default font.
 
-    \sa QApplication::setFont(), QApplication::font()
+    \sa QGuiApplication::setFont(), QGuiApplication::font()
 */
 QFont::QFont()
-    : d(QApplication::font().d.data()), resolve_mask(0)
+    : d(QGuiApplication::font().d.data()), resolve_mask(0)
 {
 }
 
@@ -794,7 +676,7 @@ QFont::QFont()
 
     If \a pointSize is zero or negative, the point size of the font
     is set to a system-dependent default value. Generally, this is
-    12 points, except on Symbian where it is 7 points.
+    12 points.
 
     The \a family name may optionally also include a foundry name,
     e.g. "Helvetica [Cronyx]". If the \a family is
@@ -804,17 +686,13 @@ QFont::QFont()
     algorithm.
 
     \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(),
-    setStyleHint() QApplication::font()
+    setStyleHint(), QGuiApplication::font()
 */
 QFont::QFont(const QString &family, int pointSize, int weight, bool italic)
     : d(new QFontPrivate()), resolve_mask(QFont::FamilyResolved)
 {
     if (pointSize <= 0) {
-#ifdef Q_OS_SYMBIAN
-        pointSize = 7;
-#else
         pointSize = 12;
-#endif
     } else {
         resolve_mask |= QFont::SizeResolved;
     }
@@ -864,7 +742,7 @@ QFont &QFont::operator=(const QFont &font)
     Returns the requested font family name, i.e. the name set in the
     constructor or the last setFont() call.
 
-    \sa setFamily() substitutes() substitute()
+    \sa setFamily(), substitutes(), substitute()
 */
 QString QFont::family() const
 {
@@ -889,18 +767,47 @@ void QFont::setFamily(const QString &family)
     detach();
 
     d->request.family = family;
-#if defined(Q_WS_X11)
-    d->request.addStyle.clear();
-#endif // Q_WS_X11
 
     resolve_mask |= QFont::FamilyResolved;
 }
 
 /*!
+    \since 4.8
+
+    Returns the requested font style name, it will be used to match the
+    font with irregular styles (that can't be normalized in other style
+    properties). It depends on system font support, thus only works for
+    Mac OS X and X11 so far. On Windows irregular styles will be added
+    as separate font families so there is no need for this.
+
+    \sa setFamily(), setStyle()
+*/
+QString QFont::styleName() const
+{
+    return d->request.styleName;
+}
+
+/*!
+    \since 4.8
+
+    Sets the style name of the font. When set, other style properties
+    like \a style() and \a weight() will be ignored for font matching.
+
+    \sa styleName()
+*/
+void QFont::setStyleName(const QString &styleName)
+{
+    detach();
+
+    d->request.styleName = styleName;
+    resolve_mask |= QFont::StyleNameResolved;
+}
+
+/*!
     Returns the point size of the font. Returns -1 if the font size
     was specified in pixels.
 
-    \sa setPointSize() pointSizeF()
+    \sa setPointSize(), pointSizeF()
 */
 int QFont::pointSize() const
 {
@@ -938,35 +845,35 @@ int QFont::pointSize() const
 
     \table
     \header
-    \o
-    \o PreferDefaultHinting
-    \o PreferNoHinting
-    \o PreferVerticalHinting
-    \o PreferFullHinting
+    \li
+    \li PreferDefaultHinting
+    \li PreferNoHinting
+    \li PreferVerticalHinting
+    \li PreferFullHinting
     \row
-    \o Windows Vista (w/o Platform Update) and earlier
-    \o Full hinting
-    \o Full hinting
-    \o Full hinting
-    \o Full hinting
+    \li Windows Vista (w/o Platform Update) and earlier
+    \li Full hinting
+    \li Full hinting
+    \li Full hinting
+    \li Full hinting
     \row
-    \o Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt
-    \o Full hinting
-    \o Vertical hinting
-    \o Vertical hinting
-    \o Full hinting
+    \li Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt
+    \li Full hinting
+    \li Vertical hinting
+    \li Vertical hinting
+    \li Full hinting
     \row
-    \o FreeType
-    \o Operating System setting
-    \o No hinting
-    \o Vertical hinting (light)
-    \o Full hinting
+    \li FreeType
+    \li Operating System setting
+    \li No hinting
+    \li Vertical hinting (light)
+    \li Full hinting
     \row
-    \o Cocoa on Mac OS X
-    \o No hinting
-    \o No hinting
-    \o No hinting
-    \o No hinting
+    \li Cocoa on Mac OS X
+    \li No hinting
+    \li No hinting
+    \li No hinting
+    \li No hinting
     \endtable
 
     \note Please be aware that altering the hinting preference on Windows is available through
@@ -1010,7 +917,7 @@ QFont::HintingPreference QFont::hintingPreference() const
     Sets the point size to \a pointSize. The point size must be
     greater than zero.
 
-    \sa pointSize() setPointSizeF()
+    \sa pointSize(), setPointSizeF()
 */
 void QFont::setPointSize(int pointSize)
 {
@@ -1032,7 +939,7 @@ void QFont::setPointSize(int pointSize)
     greater than zero. The requested precision may not be achieved on
     all platforms.
 
-    \sa pointSizeF() setPointSize() setPixelSize()
+    \sa pointSizeF(), setPointSize(), setPixelSize()
 */
 void QFont::setPointSizeF(qreal pointSize)
 {
@@ -1053,7 +960,7 @@ void QFont::setPointSizeF(qreal pointSize)
     Returns the point size of the font. Returns -1 if the font size was
     specified in pixels.
 
-    \sa pointSize() setPointSizeF() pixelSize() QFontInfo::pointSize() QFontInfo::pixelSize()
+    \sa pointSize(), setPointSizeF(), pixelSize(), QFontInfo::pointSize(), QFontInfo::pixelSize()
 */
 qreal QFont::pointSizeF() const
 {
@@ -1089,31 +996,19 @@ void QFont::setPixelSize(int pixelSize)
     setPixelSize(). Returns -1 if the size was set with setPointSize()
     or setPointSizeF().
 
-    \sa setPixelSize() pointSize() QFontInfo::pointSize() QFontInfo::pixelSize()
+    \sa setPixelSize(), pointSize(), QFontInfo::pointSize(), QFontInfo::pixelSize()
 */
 int QFont::pixelSize() const
 {
     return d->request.pixelSize;
 }
 
-#ifdef QT3_SUPPORT
-/*! \obsolete
-
-  Sets the logical pixel height of font characters when shown on
-  the screen to \a pixelSize.
-*/
-void QFont::setPixelSizeFloat(qreal pixelSize)
-{
-    setPixelSize((int)pixelSize);
-}
-#endif
-
 /*!
   \fn bool QFont::italic() const
 
     Returns true if the style() of the font is not QFont::StyleNormal
 
-    \sa setItalic() style()
+    \sa setItalic(), style()
 */
 
 /*!
@@ -1122,7 +1017,7 @@ void QFont::setPixelSizeFloat(qreal pixelSize)
   Sets the style() of the font to QFont::StyleItalic if \a enable is true;
   otherwise the style is set to QFont::StyleNormal.
 
-  \sa italic() QFontInfo
+  \sa italic(), QFontInfo
 */
 
 /*!
@@ -1195,8 +1090,8 @@ void QFont::setWeight(int weight)
 /*!
     \fn bool QFont::bold() const
 
-    Returns true if weight() is a value greater than \link Weight
-    QFont::Normal \endlink; otherwise returns false.
+    Returns true if weight() is a value greater than
+   \l{Weight}{QFont::Normal}; otherwise returns false.
 
     \sa weight(), setBold(), QFontInfo::bold()
 */
@@ -1204,9 +1099,9 @@ void QFont::setWeight(int weight)
 /*!
     \fn void QFont::setBold(bool enable)
 
-    If \a enable is true sets the font's weight to \link Weight
-    QFont::Bold \endlink; otherwise sets the weight to \link Weight
-    QFont::Normal\endlink.
+    If \a enable is true sets the font's weight to
+    \l{Weight}{QFont::Bold};
+    otherwise sets the weight to \l{Weight}{QFont::Normal}.
 
     For finer boldness control use setWeight().
 
@@ -1343,7 +1238,7 @@ void QFont::setKerning(bool enable)
     The style strategy affects the \l{QFont}{font matching} algorithm.
     See \l QFont::StyleStrategy for the list of available strategies.
 
-    \sa setStyleHint() QFont::StyleHint
+    \sa setStyleHint(), QFont::StyleHint
 */
 QFont::StyleStrategy QFont::styleStrategy() const
 {
@@ -1356,7 +1251,7 @@ QFont::StyleStrategy QFont::styleStrategy() const
     The style hint affects the \l{QFont}{font matching} algorithm.
     See \l QFont::StyleHint for the list of available hints.
 
-    \sa setStyleHint(), QFont::StyleStrategy QFontInfo::styleHint()
+    \sa setStyleHint(), QFont::StyleStrategy, QFontInfo::styleHint()
 */
 QFont::StyleHint QFont::styleHint() const
 {
@@ -1460,9 +1355,6 @@ void QFont::setStyleHint(StyleHint hint, StyleStrategy strategy)
     resolve_mask |= QFont::StyleHintResolved;
     resolve_mask |= QFont::StyleStrategyResolved;
 
-#if defined(Q_WS_X11)
-    d->request.addStyle.clear();
-#endif // Q_WS_X11
 }
 
 /*!
@@ -1499,7 +1391,7 @@ void QFont::setStyleStrategy(StyleStrategy s)
     \value ExtraExpanded 150
     \value UltraExpanded 200
 
-    \sa setStretch() stretch()
+    \sa setStretch(), stretch()
 */
 
 /*!
@@ -1524,11 +1416,7 @@ int QFont::stretch() const
     The stretch factor is only applied to outline fonts.  The stretch
     factor is ignored for bitmap fonts.
 
-    NOTE: QFont cannot stretch XLFD fonts.  When loading XLFD fonts on
-    X11, the stretch factor is matched against a predefined set of
-    values for the SETWIDTH_NAME field of the XLFD.
-
-    \sa stretch() QFont::Stretch
+    \sa stretch(), QFont::Stretch
 */
 void QFont::setStretch(int factor)
 {
@@ -1739,7 +1627,7 @@ bool QFont::exactMatch() const
     equal. If rawMode() is enabled for both fonts, only the family
     fields are compared.
 
-    \sa operator!=() isCopyOf()
+    \sa operator!=(), isCopyOf()
 */
 bool QFont::operator==(const QFont &f) const
 {
@@ -1767,7 +1655,7 @@ bool QFont::operator==(const QFont &f) const
     This function is useful in some circumstances, for example if you
     want to use QFont objects as keys in a QMap.
 
-    \sa operator==() operator!=() isCopyOf()
+    \sa operator==(), operator!=(), isCopyOf()
 */
 bool QFont::operator<(const QFont &f) const
 {
@@ -1783,9 +1671,6 @@ bool QFont::operator<(const QFont &f) const
     if (r1.styleHint != r2.styleHint) return r1.styleHint < r2.styleHint;
     if (r1.styleStrategy != r2.styleStrategy) return r1.styleStrategy < r2.styleStrategy;
     if (r1.family != r2.family) return r1.family < r2.family;
-#ifdef Q_WS_X11
-    if (r1.addStyle != r2.addStyle) return r1.addStyle < r2.addStyle;
-#endif // Q_WS_X11
     if (f.d->capital != d->capital) return f.d->capital < d->capital;
 
     if (f.d->letterSpacingIsAbsolute != d->letterSpacingIsAbsolute) return f.d->letterSpacingIsAbsolute < d->letterSpacingIsAbsolute;
@@ -1826,7 +1711,7 @@ QFont::operator QVariant() const
     one of them was created as a copy of the other and neither has
     been modified since. This is much stricter than equality.
 
-    \sa operator=() operator==()
+    \sa operator=(), operator==()
 */
 bool QFont::isCopyOf(const QFont & f) const
 {
@@ -1837,7 +1722,7 @@ bool QFont::isCopyOf(const QFont & f) const
     Returns true if raw mode is used for font name matching; otherwise
     returns false.
 
-    \sa setRawMode() rawName()
+    \sa setRawMode(), rawName()
 */
 bool QFont::rawMode() const
 {
@@ -1875,43 +1760,6 @@ QFont QFont::resolve(const QFont &other) const
     \internal
 */
 
-#ifdef QT3_SUPPORT
-
-/*! \obsolete
-
-  Please use QApplication::font() instead.
-*/
-QFont QFont::defaultFont()
-{
-    return QApplication::font();
-}
-
-/*! \obsolete
-
-  Please use QApplication::setFont() instead.
-*/
-void QFont::setDefaultFont(const QFont &f)
-{
-    QApplication::setFont(f);
-}
-
-/*!
-    \fn qreal QFont::pointSizeFloat() const
-    \compat
-
-    Use pointSizeF() instead.
-*/
-
-/*!
-    \fn void QFont::setPointSizeFloat(qreal size)
-    \compat
-
-    Use setPointSizeF() instead.
-*/
-#endif
-
-
-
 
 /*****************************************************************************
   QFont substitution management
@@ -1920,42 +1768,6 @@ void QFont::setDefaultFont(const QFont &f)
 typedef QHash<QString, QStringList> QFontSubst;
 Q_GLOBAL_STATIC(QFontSubst, globalFontSubst)
 
-// create substitution dict
-static void initFontSubst()
-{
-    // default substitutions
-    static const char * const initTbl[] = {
-
-#if defined(Q_WS_X11)
-        "arial",        "helvetica",
-        "times new roman", "times",
-        "courier new",  "courier",
-        "sans serif",   "helvetica",
-#elif defined(Q_WS_WIN)
-        "times",        "times new roman",
-        "courier",      "courier new",
-        "helvetica",    "arial",
-        "sans serif",   "arial",
-#endif
-
-        0,              0
-    };
-
-    QFontSubst *fontSubst = globalFontSubst();
-    Q_ASSERT(fontSubst != 0);
-    if (!fontSubst->isEmpty())
-        return;
-#if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)
-    if (X11->has_fontconfig)
-        return;
-#endif
-
-    for (int i=0; initTbl[i] != 0; i += 2) {
-        QStringList &list = (*fontSubst)[QString::fromLatin1(initTbl[i])];
-        list.append(QString::fromLatin1(initTbl[i+1]));
-    }
-}
-
 /*!
     Returns the first family name to be used whenever \a familyName is
     specified. The lookup is case insensitive.
@@ -1965,12 +1777,10 @@ static void initFontSubst()
 
     To obtain a list of substitutions use substitutes().
 
-    \sa setFamily() insertSubstitutions() insertSubstitution() removeSubstitution()
+    \sa setFamily(), insertSubstitutions(), insertSubstitution(), removeSubstitutions()
 */
 QString QFont::substitute(const QString &familyName)
 {
-    initFontSubst();
-
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower());
@@ -1988,12 +1798,10 @@ QString QFont::substitute(const QString &familyName)
     If there is no substitution for \a familyName, an empty list is
     returned.
 
-    \sa substitute() insertSubstitutions() insertSubstitution() removeSubstitution()
+    \sa substitute(), insertSubstitutions(), insertSubstitution(), removeSubstitutions()
  */
 QStringList QFont::substitutes(const QString &familyName)
 {
-    initFontSubst();
-
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     return fontSubst->value(familyName.toLower(), QStringList());
@@ -2004,13 +1812,11 @@ QStringList QFont::substitutes(const QString &familyName)
     Inserts \a substituteName into the substitution
     table for the family \a familyName.
 
-    \sa insertSubstitutions() removeSubstitution() substitutions() substitute() substitutes()
+    \sa insertSubstitutions(), removeSubstitutions(), substitutions(), substitute(), substitutes()
 */
 void QFont::insertSubstitution(const QString &familyName,
                                const QString &substituteName)
 {
-    initFontSubst();
-
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     QStringList &list = (*fontSubst)[familyName.toLower()];
@@ -2024,22 +1830,18 @@ void QFont::insertSubstitution(const QString &familyName,
     Inserts the list of families \a substituteNames into the
     substitution list for \a familyName.
 
-    \sa insertSubstitution(), removeSubstitution(), substitutions(), substitute()
+    \sa insertSubstitution(), removeSubstitutions(), substitutions(), substitute()
 */
 void QFont::insertSubstitutions(const QString &familyName,
                                 const QStringList &substituteNames)
 {
-    initFontSubst();
-
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     QStringList &list = (*fontSubst)[familyName.toLower()];
-    QStringList::ConstIterator it = substituteNames.constBegin();
-    while (it != substituteNames.constEnd()) {
-        QString s = (*it).toLower();
-        if (!list.contains(s))
-            list.append(s);
-        it++;
+    foreach (const QString &substituteName, substituteNames) {
+        const QString lowerSubstituteName = substituteName.toLower();
+        if (!list.contains(lowerSubstituteName))
+            list.append(lowerSubstituteName);
     }
 }
 
@@ -2057,22 +1859,26 @@ void QFont::insertSubstitutions(const QString &familyName,
   Internal function that cleans up the font system.
 */
 
-// ### mark: should be called removeSubstitutions()
 /*!
     Removes all the substitutions for \a familyName.
 
     \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute()
+    \since 5.0
 */
-void QFont::removeSubstitution(const QString &familyName)
-{ // ### function name should be removeSubstitutions() or
-  // ### removeSubstitutionList()
-    initFontSubst();
-
+void QFont::removeSubstitutions(const QString &familyName)
+{
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     fontSubst->remove(familyName.toLower());
 }
 
+/*!
+    \fn void QFont::removeSubstitution(const QString &familyName)
+
+    \obsolete
+
+    This function is deprecated. Use removeSubstitutions() instead.
+*/
 
 /*!
     Returns a sorted list of substituted family names.
@@ -2081,17 +1887,14 @@ void QFont::removeSubstitution(const QString &familyName)
 */
 QStringList QFont::substitutions()
 {
-    initFontSubst();
+    typedef QFontSubst::const_iterator QFontSubstConstIterator;
 
     QFontSubst *fontSubst = globalFontSubst();
     Q_ASSERT(fontSubst != 0);
     QStringList ret;
-    QFontSubst::ConstIterator it = fontSubst->constBegin();
-
-    while (it != fontSubst->constEnd()) {
+    const QFontSubstConstIterator cend = fontSubst->constEnd();
+    for (QFontSubstConstIterator it = fontSubst->constBegin(); it != cend; ++it)
         ret.append(it.key());
-        ++it;
-    }
 
     ret.sort();
     return ret;
@@ -2251,7 +2054,6 @@ bool QFont::fromString(const QString &descrip)
     return true;
 }
 
-#if !defined(Q_WS_QWS)
 /*! \internal
 
   Internal function that dumps font cache statistics.
@@ -2261,7 +2063,6 @@ void QFont::cacheStatistics()
 
 
 }
-#endif // !Q_WS_QWS
 
 
 
@@ -2276,7 +2077,7 @@ void QFont::cacheStatistics()
     Writes the font \a font to the data stream \a s. (toString()
     writes to a text stream.)
 
-    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
+    \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
 */
 QDataStream &operator<<(QDataStream &s, const QFont &font)
 {
@@ -2295,11 +2096,7 @@ QDataStream &operator<<(QDataStream &s, const QFont &font)
     } else if (s.version() <= 3) {
         qint16 pointSize = (qint16) (font.d->request.pointSize * 10);
         if (pointSize < 0) {
-#ifdef Q_WS_X11
-            pointSize = (qint16)(font.d->request.pixelSize*720/QX11Info::appDpiY());
-#else
             pointSize = (qint16)QFontInfo(font).pointSize() * 10;
-#endif
         }
         s << pointSize;
     } else {
@@ -2331,7 +2128,7 @@ QDataStream &operator<<(QDataStream &s, const QFont &font)
     Reads the font \a font from the data stream \a s. (fromString()
     reads from a text stream.)
 
-    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
+    \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
 */
 QDataStream &operator>>(QDataStream &s, QFont &font)
 {
@@ -2412,6 +2209,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
     \reentrant
 
     \brief The QFontInfo class provides general information about fonts.
+    \inmodule QtGui
 
     \ingroup appearance
     \ingroup shared
@@ -2430,7 +2228,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
 
     There are three ways to create a QFontInfo object.
     \list 1
-    \o Calling the QFontInfo constructor with a QFont creates a font
+    \li 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 \e not updated.
@@ -2439,25 +2237,24 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
     inaccurate. Printer fonts are not always accessible so the nearest
     screen font is used if a printer font is supplied.)
 
-    \o QWidget::fontInfo() returns the font info for a widget's font.
+    \li 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 \e not
     updated.
 
-    \o QPainter::fontInfo() returns the font info for a painter's
+    \li 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 \e not updated.
     \endlist
 
-    \sa QFont QFontMetrics QFontDatabase
+    \sa QFont, QFontMetrics, QFontDatabase
 */
 
 /*!
     Constructs a font info object for \a font.
 
     The font must be screen-compatible, i.e. a font you use when
-    drawing text in \link QWidget widgets\endlink or \link QPixmap
-    pixmaps\endlink, not QPicture or QPrinter.
+    drawing text in \l{QWidget}{widgets} or \l{QPixmap}{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
@@ -2509,9 +2306,24 @@ QString QFontInfo::family() const
 }
 
 /*!
+    \since 4.8
+
+    Returns the style name of the matched window system font on
+    system that supports it.
+
+    \sa QFont::styleName()
+*/
+QString QFontInfo::styleName() const
+{
+    QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
+    Q_ASSERT(engine != 0);
+    return engine->fontDef.styleName;
+}
+
+/*!
     Returns the point size of the matched window system font.
 
-    \sa pointSizeF() QFont::pointSize()
+    \sa pointSizeF(), QFont::pointSize()
 */
 int QFontInfo::pointSize() const
 {
@@ -2660,7 +2472,7 @@ bool QFontInfo::fixedPitch() const
 
     Currently only returns the style hint set in QFont.
 
-    \sa QFont::styleHint() QFont::StyleHint
+    \sa QFont::styleHint(), QFont::StyleHint
 */
 QFont::StyleHint QFontInfo::styleHint() const
 {
@@ -2765,11 +2577,11 @@ QFontCache::~QFontCache()
         EngineDataCache::ConstIterator it = engineDataCache.constBegin(),
                                  end = engineDataCache.constEnd();
         while (it != end) {
-            if (it.value()->ref == 0)
+            if (it.value()->ref.load() == 0)
                 delete it.value();
             else
                 FC_DEBUG("QFontCache::~QFontCache: engineData %p still has refcount %d",
-                         it.value(), int(it.value()->ref));
+                         it.value(), it.value()->ref.load());
             ++it;
         }
     }
@@ -2777,7 +2589,7 @@ QFontCache::~QFontCache()
                          end = engineCache.constEnd();
     while (it != end) {
         if (--it.value().data->cache_count == 0) {
-            if (it.value().data->ref == 0) {
+            if (it.value().data->ref.load() == 0) {
                 FC_DEBUG("QFontCache::~QFontCache: deleting engine %p key=(%d / %g %g %d %d %d)",
                          it.value().data, it.key().script, it.key().def.pointSize,
                          it.key().def.pixelSize, it.key().def.weight, it.key().def.style,
@@ -2786,7 +2598,7 @@ QFontCache::~QFontCache()
                 delete it.value().data;
             } else {
                 FC_DEBUG("QFontCache::~QFontCache: engine = %p still has refcount %d",
-                         it.value().data, int(it.value().data->ref));
+                         it.value().data, it.value().data->ref.load());
             }
         }
         ++it;
@@ -2800,26 +2612,19 @@ void QFontCache::clear()
                                  end = engineDataCache.end();
         while (it != end) {
             QFontEngineData *data = it.value();
-#if !defined(Q_WS_MAC)
             for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
                 if (data->engines[i]) {
                     data->engines[i]->ref.deref();
                     data->engines[i] = 0;
                 }
             }
-#else
-            if (data->engine) {
-                data->engine->ref.deref();
-                data->engine = 0;
-            }
-#endif
             ++it;
         }
     }
 
     for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end();
          it != end; ++it) {
-        if (it->data->ref == 0) {
+        if (it->data->ref.load() == 0) {
             delete it->data;
             it->data = 0;
         }
@@ -2827,7 +2632,7 @@ void QFontCache::clear()
 
     for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end();
          it != end; ++it) {
-        if (it->data && it->data->ref == 0) {
+        if (it->data && it->data->ref.load() == 0) {
             delete it->data;
             it->data = 0;
         }
@@ -2836,21 +2641,10 @@ void QFontCache::clear()
     engineCache.clear();
 }
 
-#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
-void QFontCache::removeEngineForFont(const QByteArray &_fontName)
-{
 
-    /* This could be optimized but the code becomes much more complex if we want to handle multi
-     * font engines and it is probably not worth it. Therefore we just clear the entire font cache.
-     */
-    Q_UNUSED(_fontName);
-    clear();
-}
-#endif
-
-QFontEngineData *QFontCache::findEngineData(const Key &key) const
+QFontEngineData *QFontCache::findEngineData(const QFontDef &def) const
 {
-    EngineDataCache::ConstIterator it = engineDataCache.find(key),
+    EngineDataCache::ConstIterator it = engineDataCache.find(def),
                                   end = engineDataCache.end();
     if (it == end) return 0;
 
@@ -2858,11 +2652,11 @@ QFontEngineData *QFontCache::findEngineData(const Key &key) const
     return it.value();
 }
 
-void QFontCache::insertEngineData(const Key &key, QFontEngineData *engineData)
+void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineData)
 {
     FC_DEBUG("QFontCache: inserting new engine data %p", engineData);
 
-    engineDataCache.insert(key, engineData);
+    engineDataCache.insert(def, engineData);
     increaseCost(sizeof(QFontEngineData));
 }
 
@@ -2871,28 +2665,35 @@ QFontEngine *QFontCache::findEngine(const Key &key)
     EngineCache::Iterator it = engineCache.find(key),
                          end = engineCache.end();
     if (it == end) return 0;
-
     // found... update the hitcount and timestamp
-    it.value().hits++;
-    it.value().timestamp = ++current_timestamp;
+    updateHitCountAndTimeStamp(it.value());
+
+    return it.value().data;
+}
+
+void QFontCache::updateHitCountAndTimeStamp(Engine &value)
+{
+    value.hits++;
+    value.timestamp = ++current_timestamp;
 
     FC_DEBUG("QFontCache: found font engine\n"
              "  %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'",
-             it.value().data, it.value().timestamp, it.value().hits,
-             int(it.value().data->ref), it.value().data->cache_count,
-             it.value().data->name());
-
-    return it.value().data;
+             value.data, value.timestamp, value.hits,
+             value.data->ref.load(), value.data->cache_count,
+             value.data->name());
 }
 
-void QFontCache::insertEngine(const Key &key, QFontEngine *engine)
+void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti)
 {
     FC_DEBUG("QFontCache: inserting new engine %p", engine);
 
     Engine data(engine);
     data.timestamp = ++current_timestamp;
 
-    engineCache.insert(key, data);
+    if (insertMulti)
+        engineCache.insertMulti(key, data);
+    else
+        engineCache.insert(key, data);
 
     // only increase the cost if this is the first time we insert the engine
     if (engine->cache_count == 0)
@@ -2934,70 +2735,6 @@ void QFontCache::decreaseCost(uint cost)
             cost, total_cost, max_cost);
 }
 
-#if defined(Q_WS_WIN) || defined (Q_WS_QWS)
-void QFontCache::cleanupPrinterFonts()
-{
-    FC_DEBUG("QFontCache::cleanupPrinterFonts");
-
-    {
-        FC_DEBUG("  CLEAN engine data:");
-
-        // clean out all unused engine data
-        EngineDataCache::Iterator it = engineDataCache.begin(),
-                                 end = engineDataCache.end();
-        while (it != end) {
-            if (it.key().screen == 0) {
-                ++it;
-                continue;
-            }
-
-            if(it.value()->ref != 0) {
-                for(int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
-                    if(it.value()->engines[i]) {
-                        it.value()->engines[i]->ref.deref();
-                        it.value()->engines[i] = 0;
-                    }
-                }
-                ++it;
-            } else {
-
-                EngineDataCache::Iterator rem = it++;
-
-                decreaseCost(sizeof(QFontEngineData));
-
-                FC_DEBUG("    %p", rem.value());
-
-                delete rem.value();
-                engineDataCache.erase(rem);
-            }
-        }
-    }
-
-    EngineCache::Iterator it = engineCache.begin(),
-                         end = engineCache.end();
-    while(it != end) {
-        if (it.value().data->ref != 0 || it.key().screen == 0) {
-            ++it;
-            continue;
-        }
-
-        FC_DEBUG("    %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
-                 it.value().data, it.value().timestamp, it.value().hits,
-                 int(it.value().data->ref), it.value().data->cache_count,
-                 it.value().data->name());
-
-        if (--it.value().data->cache_count == 0) {
-            FC_DEBUG("    DELETE: last occurrence in cache");
-
-            decreaseCost(it.value().data->cache_cost);
-            delete it.value().data;
-        }
-
-        engineCache.erase(it++);
-    }
-}
-#endif
-
 void QFontCache::timerEvent(QTimerEvent *)
 {
     FC_DEBUG("QFontCache::timerEvent: performing cache maintenance (timestamp %u)",
@@ -3029,17 +2766,9 @@ void QFontCache::timerEvent(QTimerEvent *)
 #ifdef QFONTCACHE_DEBUG
             FC_DEBUG("    %p: ref %2d", it.value(), int(it.value()->ref));
 
-#  if defined(Q_WS_X11) || defined(Q_WS_WIN)
-            // print out all engines
-            for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
-                if (! it.value()->engines[i])
-                    continue;
-                FC_DEBUG("      contains %p", it.value()->engines[i]);
-            }
-#  endif // Q_WS_X11 || Q_WS_WIN
 #endif // QFONTCACHE_DEBUG
 
-            if (it.value()->ref != 0)
+            if (it.value()->ref.load() != 0)
                 in_use_cost += engine_data_cost;
         }
     }
@@ -3052,10 +2781,10 @@ void QFontCache::timerEvent(QTimerEvent *)
         for (; it != end; ++it) {
             FC_DEBUG("    %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes",
                      it.value().data, it.value().timestamp, it.value().hits,
-                     int(it.value().data->ref), it.value().data->cache_count,
+                     it.value().data->ref.load(), it.value().data->cache_count,
                      it.value().data->cache_cost);
 
-            if (it.value().data->ref != 0)
+            if (it.value().data->ref.load() != 0)
                 in_use_cost += it.value().data->cache_cost / it.value().data->cache_count;
         }
 
@@ -3105,7 +2834,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         EngineDataCache::Iterator it = engineDataCache.begin(),
                                  end = engineDataCache.end();
         while (it != end) {
-            if (it.value()->ref != 0) {
+            if (it.value()->ref.load() != 0) {
                 ++it;
                 continue;
             }
@@ -3133,7 +2862,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         uint least_popular = ~0u;
 
         for (; it != end; ++it) {
-            if (it.value().data->ref != 0)
+            if (it.value().data->ref.load() != 0)
                 continue;
 
             if (it.value().timestamp < oldest &&
@@ -3146,7 +2875,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         FC_DEBUG("    oldest %u least popular %u", oldest, least_popular);
 
         for (it = engineCache.begin(); it != end; ++it) {
-            if (it.value().data->ref == 0 &&
+            if (it.value().data->ref.load() == 0 &&
                  it.value().timestamp == oldest &&
                  it.value().hits == least_popular)
                 break;
@@ -3155,7 +2884,7 @@ void QFontCache::timerEvent(QTimerEvent *)
         if (it != end) {
             FC_DEBUG("    %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
                      it.value().data, it.value().timestamp, it.value().hits,
-                     int(it.value().data->ref), it.value().data->cache_count,
+                     it.value().data->ref.load(), it.value().data->cache_count,
                      it.value().data->name());
 
             if (--it.value().data->cache_count == 0) {