From 106843ad1afa2f5c0aedaa748088d4ebacd6d73d Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 9 Sep 2013 11:46:50 +0300 Subject: [PATCH] Make QFontEngine not derive from QObject Whilst having the objectName set for each engine is somewhat handy when debugging, deriving from QObject just for that is a wasting of memory in all other cases. This also broke the font engine abstraction by allowing qobject_cast() to access some private data; the only sane way to distinguish engines is querying their Type value. Change-Id: Ib1d195692859eb39089f6d8d9016cb8f9dcc0400 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/gui/text/qfontengine.cpp | 2 +- src/gui/text/qfontengine_p.h | 11 ++++++++--- src/gui/text/qfontengine_qpa.cpp | 5 +++-- .../fontconfig/qfontenginemultifontconfig_p.h | 1 - .../fontdatabases/mac/qfontengine_coretext_p.h | 1 - .../platforms/windows/qwindowsfontdatabase.cpp | 3 --- src/plugins/platforms/windows/qwindowsfontengine.cpp | 11 ++++++++--- src/plugins/platforms/windows/qwindowsfontengine.h | 10 +--------- .../platforms/windows/qwindowsfontenginedirectwrite.h | 1 - src/printsupport/kernel/qprintengine_win.cpp | 10 ++++++---- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index d561fcf823..88a24b5e6a 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -206,7 +206,7 @@ Q_AUTOTEST_EXPORT QList QFontEngine_stopCollectingEngines() // QFontEngine QFontEngine::QFontEngine() - : QObject(), ref(0), + : ref(0), font_(0), font_destroy_func(0), face_(0), face_destroy_func(0) { diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 4427000d03..1a6862898d 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -86,9 +86,8 @@ enum HB_Compat_Error { typedef void (*qt_destroy_func_t) (void *user_data); -class Q_GUI_EXPORT QFontEngine : public QObject +class Q_GUI_EXPORT QFontEngine { - Q_OBJECT public: enum Type { Box, @@ -300,9 +299,13 @@ public: QImage currentlyLockedAlphaMap; int m_subPixelPositionCount; // Number of positions within a single pixel for this cache + inline QVariant userData() const { return m_userData; } + protected: QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round = false); + inline void setUserData(const QVariant &userData) { m_userData = userData; } + private: struct GlyphCacheEntry { const void *context; @@ -311,6 +314,9 @@ private: }; mutable QLinkedList m_glyphCaches; + +private: + QVariant m_userData; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QFontEngine::ShaperFlags) @@ -368,7 +374,6 @@ private: class Q_GUI_EXPORT QFontEngineMulti : public QFontEngine { - Q_OBJECT public: explicit QFontEngineMulti(int engineCount); ~QFontEngineMulti(); diff --git a/src/gui/text/qfontengine_qpa.cpp b/src/gui/text/qfontengine_qpa.cpp index 0a730abcac..9b21d61aad 100644 --- a/src/gui/text/qfontengine_qpa.cpp +++ b/src/gui/text/qfontengine_qpa.cpp @@ -687,7 +687,6 @@ void QFontEngineMultiQPA::init(QFontEngine *fe) engines[0] = fe; fe->ref.ref(); fontDef = engines[0]->fontDef; - setObjectName(QStringLiteral("QFontEngineMultiQPA")); cache_cost = fe->cache_cost; } @@ -754,7 +753,9 @@ QFontEngine* QFontEngineMultiQPA::createMultiFontEngine(QFontEngine *fe, int scr QFontCache::EngineCache::Iterator it = fc->engineCache.find(key), end = fc->engineCache.end(); while (it != end && it.key() == key) { - QFontEngineMulti *cachedEngine = qobject_cast(it.value().data); + QFontEngineMulti *cachedEngine = 0; + if (it.value().data->type() == QFontEngine::Multi) + cachedEngine = static_cast(it.value().data); if (faceIsLocal || (cachedEngine && fe == cachedEngine->engine(0))) { engine = cachedEngine; fc->updateHitCountAndTimeStamp(it.value()); diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontenginemultifontconfig_p.h b/src/platformsupport/fontdatabases/fontconfig/qfontenginemultifontconfig_p.h index d895da35bf..2d93d236e5 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontenginemultifontconfig_p.h +++ b/src/platformsupport/fontdatabases/fontconfig/qfontenginemultifontconfig_p.h @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE class QFontEngineMultiFontConfig : public QFontEngineMultiQPA { - Q_OBJECT public: explicit QFontEngineMultiFontConfig(QFontEngine *fe, int script); diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 577bb25e95..7ef9f0dfbb 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE class QRawFontPrivate; class QCoreTextFontEngine : public QFontEngine { - Q_OBJECT public: QCoreTextFontEngine(CTFontRef font, const QFontDef &def); QCoreTextFontEngine(CGFontRef font, const QFontDef &def); diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index a6bce6502b..22be4418a9 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1759,7 +1759,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ QFontEngine *fe = 0; if (!useDirectWrite) { QWindowsFontEngine *few = new QWindowsFontEngine(request.family, hfont, stockFont, lf, data); - few->setObjectName(QStringLiteral("QWindowsFontEngine_") + request.family); if (preferClearTypeAA) few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask; @@ -1788,7 +1787,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ request.pixelSize, data); fedw->initFontInfo(request, dpi, directWriteFont); - fedw->setObjectName(QStringLiteral("QWindowsFontEngineDirectWrite_") + request.family); fe = fedw; } else { qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__); @@ -1806,7 +1804,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ QStringList list = family_list; list.append(extraFonts); QFontEngine *mfe = new QWindowsMultiFontEngine(fe, list); - mfe->setObjectName(QStringLiteral("QWindowsMultiFontEngine_") + request.family); mfe->fontDef = fe->fontDef; fe = mfe; } diff --git a/src/plugins/platforms/windows/qwindowsfontengine.cpp b/src/plugins/platforms/windows/qwindowsfontengine.cpp index 64457f4b67..ac57a1b396 100644 --- a/src/plugins/platforms/windows/qwindowsfontengine.cpp +++ b/src/plugins/platforms/windows/qwindowsfontengine.cpp @@ -336,6 +336,13 @@ QWindowsFontEngine::QWindowsFontEngine(const QString &name, if (!resolvedGetCharWidthI) resolveGetCharWidthI(); + + // ### Properties accessed by QWin32PrintEngine (QtPrintSupport) + QVariantMap userData; + userData.insert(QStringLiteral("logFont"), QVariant::fromValue(m_logfont)); + userData.insert(QStringLiteral("hFont"), QVariant::fromValue(hfont)); + userData.insert(QStringLiteral("trueType"), QVariant(bool(ttf))); + setUserData(userData); } QWindowsFontEngine::~QWindowsFontEngine() @@ -1366,7 +1373,7 @@ void QWindowsMultiFontEngine::loadEngine(int at) #endif { QWindowsFontEngine *fe = static_cast(fontEngine); - lf = fe->logFont(); + lf = fe->m_logfont; data = fe->fontEngineData(); } @@ -1391,8 +1398,6 @@ void QWindowsMultiFontEngine::loadEngine(int at) QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, fontEngine->fontDef.pixelSize, data); - fedw->setObjectName(QStringLiteral("QWindowsFontEngineDirectWrite_") + fontEngine->fontDef.family); - fedw->fontDef = fontDef; fedw->ref.ref(); engines[at] = fedw; diff --git a/src/plugins/platforms/windows/qwindowsfontengine.h b/src/plugins/platforms/windows/qwindowsfontengine.h index 60ff61fcb9..d783b6048c 100644 --- a/src/plugins/platforms/windows/qwindowsfontengine.h +++ b/src/plugins/platforms/windows/qwindowsfontengine.h @@ -68,10 +68,7 @@ class QWindowsFontEngineData; class QWindowsFontEngine : public QFontEngine { - Q_OBJECT - Q_PROPERTY(HFONT hFont READ hFont STORED false) - Q_PROPERTY(LOGFONT logFont READ logFont STORED false) - Q_PROPERTY(bool trueType READ trueType STORED false) + friend class QWindowsMultiFontEngine; public: QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT, @@ -137,11 +134,6 @@ public: const QSharedPointer &fontEngineData() const { return m_fontEngineData; } - // Properties accessed by QWin32PrintEngine (Qt Print Support) - LOGFONT logFont() const { return m_logfont; } - HFONT hFont() const { return hfont; } - bool trueType() const { return ttf; } - void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; } private: diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h index ab14cb49eb..57a6a3ba1d 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h @@ -61,7 +61,6 @@ QT_BEGIN_NAMESPACE class QWindowsFontEngineDirectWrite : public QFontEngine { - Q_OBJECT public: explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace, qreal pixelSize, diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 36dd7ecb0c..acaa32304e 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -364,8 +364,9 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem || ti.fontEngine->type() != QFontEngine::Win; if (!fallBack) { - const QVariant hFontV = ti.fontEngine->property("hFont"); - const QVariant logFontV = ti.fontEngine->property("logFont"); + const QVariantMap userData = ti.fontEngine->userData().toMap(); + const QVariant hFontV = userData.value(QStringLiteral("hFont")); + const QVariant logFontV = userData.value(QStringLiteral("logFont")); if (hFontV.canConvert() && logFontV.canConvert()) { const HFONT hfont = hFontV.value(); const LOGFONT logFont = logFontV.value(); @@ -1806,8 +1807,9 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h bool ttf = false; if (ti.fontEngine->type() == QFontEngine::Win) { - const QVariant hfontV = ti.fontEngine->property("hFont"); - const QVariant ttfV = ti.fontEngine->property("trueType"); + const QVariantMap userData = ti.fontEngine->userData().toMap(); + const QVariant hfontV = userData.value(QStringLiteral("hFont")); + const QVariant ttfV = userData.value(QStringLiteral("trueType")); if (ttfV.type() == QVariant::Bool && hfontV.canConvert()) { hfont = hfontV.value(); ttf = ttfV.toBool();