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 <Friedemann.Kleint@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Konstantin Ritt 2013-09-09 11:46:50 +03:00 committed by The Qt Project
parent 8b124a7dde
commit 106843ad1a
10 changed files with 27 additions and 28 deletions

View File

@ -206,7 +206,7 @@ Q_AUTOTEST_EXPORT QList<QFontEngine *> QFontEngine_stopCollectingEngines()
// QFontEngine // QFontEngine
QFontEngine::QFontEngine() QFontEngine::QFontEngine()
: QObject(), ref(0), : ref(0),
font_(0), font_destroy_func(0), font_(0), font_destroy_func(0),
face_(0), face_destroy_func(0) face_(0), face_destroy_func(0)
{ {

View File

@ -86,9 +86,8 @@ enum HB_Compat_Error {
typedef void (*qt_destroy_func_t) (void *user_data); typedef void (*qt_destroy_func_t) (void *user_data);
class Q_GUI_EXPORT QFontEngine : public QObject class Q_GUI_EXPORT QFontEngine
{ {
Q_OBJECT
public: public:
enum Type { enum Type {
Box, Box,
@ -300,9 +299,13 @@ public:
QImage currentlyLockedAlphaMap; QImage currentlyLockedAlphaMap;
int m_subPixelPositionCount; // Number of positions within a single pixel for this cache int m_subPixelPositionCount; // Number of positions within a single pixel for this cache
inline QVariant userData() const { return m_userData; }
protected: protected:
QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round = false); QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round = false);
inline void setUserData(const QVariant &userData) { m_userData = userData; }
private: private:
struct GlyphCacheEntry { struct GlyphCacheEntry {
const void *context; const void *context;
@ -311,6 +314,9 @@ private:
}; };
mutable QLinkedList<GlyphCacheEntry> m_glyphCaches; mutable QLinkedList<GlyphCacheEntry> m_glyphCaches;
private:
QVariant m_userData;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QFontEngine::ShaperFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(QFontEngine::ShaperFlags)
@ -368,7 +374,6 @@ private:
class Q_GUI_EXPORT QFontEngineMulti : public QFontEngine class Q_GUI_EXPORT QFontEngineMulti : public QFontEngine
{ {
Q_OBJECT
public: public:
explicit QFontEngineMulti(int engineCount); explicit QFontEngineMulti(int engineCount);
~QFontEngineMulti(); ~QFontEngineMulti();

View File

@ -687,7 +687,6 @@ void QFontEngineMultiQPA::init(QFontEngine *fe)
engines[0] = fe; engines[0] = fe;
fe->ref.ref(); fe->ref.ref();
fontDef = engines[0]->fontDef; fontDef = engines[0]->fontDef;
setObjectName(QStringLiteral("QFontEngineMultiQPA"));
cache_cost = fe->cache_cost; cache_cost = fe->cache_cost;
} }
@ -754,7 +753,9 @@ QFontEngine* QFontEngineMultiQPA::createMultiFontEngine(QFontEngine *fe, int scr
QFontCache::EngineCache::Iterator it = fc->engineCache.find(key), QFontCache::EngineCache::Iterator it = fc->engineCache.find(key),
end = fc->engineCache.end(); end = fc->engineCache.end();
while (it != end && it.key() == key) { while (it != end && it.key() == key) {
QFontEngineMulti *cachedEngine = qobject_cast<QFontEngineMulti *>(it.value().data); QFontEngineMulti *cachedEngine = 0;
if (it.value().data->type() == QFontEngine::Multi)
cachedEngine = static_cast<QFontEngineMulti *>(it.value().data);
if (faceIsLocal || (cachedEngine && fe == cachedEngine->engine(0))) { if (faceIsLocal || (cachedEngine && fe == cachedEngine->engine(0))) {
engine = cachedEngine; engine = cachedEngine;
fc->updateHitCountAndTimeStamp(it.value()); fc->updateHitCountAndTimeStamp(it.value());

View File

@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE
class QFontEngineMultiFontConfig : public QFontEngineMultiQPA class QFontEngineMultiFontConfig : public QFontEngineMultiQPA
{ {
Q_OBJECT
public: public:
explicit QFontEngineMultiFontConfig(QFontEngine *fe, int script); explicit QFontEngineMultiFontConfig(QFontEngine *fe, int script);

View File

@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE
class QRawFontPrivate; class QRawFontPrivate;
class QCoreTextFontEngine : public QFontEngine class QCoreTextFontEngine : public QFontEngine
{ {
Q_OBJECT
public: public:
QCoreTextFontEngine(CTFontRef font, const QFontDef &def); QCoreTextFontEngine(CTFontRef font, const QFontDef &def);
QCoreTextFontEngine(CGFontRef font, const QFontDef &def); QCoreTextFontEngine(CGFontRef font, const QFontDef &def);

View File

@ -1759,7 +1759,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ
QFontEngine *fe = 0; QFontEngine *fe = 0;
if (!useDirectWrite) { if (!useDirectWrite) {
QWindowsFontEngine *few = new QWindowsFontEngine(request.family, hfont, stockFont, lf, data); QWindowsFontEngine *few = new QWindowsFontEngine(request.family, hfont, stockFont, lf, data);
few->setObjectName(QStringLiteral("QWindowsFontEngine_") + request.family);
if (preferClearTypeAA) if (preferClearTypeAA)
few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask; few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask;
@ -1788,7 +1787,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ
request.pixelSize, request.pixelSize,
data); data);
fedw->initFontInfo(request, dpi, directWriteFont); fedw->initFontInfo(request, dpi, directWriteFont);
fedw->setObjectName(QStringLiteral("QWindowsFontEngineDirectWrite_") + request.family);
fe = fedw; fe = fedw;
} else { } else {
qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__); qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__);
@ -1806,7 +1804,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(int script, const QFontDef &requ
QStringList list = family_list; QStringList list = family_list;
list.append(extraFonts); list.append(extraFonts);
QFontEngine *mfe = new QWindowsMultiFontEngine(fe, list); QFontEngine *mfe = new QWindowsMultiFontEngine(fe, list);
mfe->setObjectName(QStringLiteral("QWindowsMultiFontEngine_") + request.family);
mfe->fontDef = fe->fontDef; mfe->fontDef = fe->fontDef;
fe = mfe; fe = mfe;
} }

View File

@ -336,6 +336,13 @@ QWindowsFontEngine::QWindowsFontEngine(const QString &name,
if (!resolvedGetCharWidthI) if (!resolvedGetCharWidthI)
resolveGetCharWidthI(); 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() QWindowsFontEngine::~QWindowsFontEngine()
@ -1366,7 +1373,7 @@ void QWindowsMultiFontEngine::loadEngine(int at)
#endif #endif
{ {
QWindowsFontEngine *fe = static_cast<QWindowsFontEngine*>(fontEngine); QWindowsFontEngine *fe = static_cast<QWindowsFontEngine*>(fontEngine);
lf = fe->logFont(); lf = fe->m_logfont;
data = fe->fontEngineData(); data = fe->fontEngineData();
} }
@ -1391,8 +1398,6 @@ void QWindowsMultiFontEngine::loadEngine(int at)
QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace,
fontEngine->fontDef.pixelSize, fontEngine->fontDef.pixelSize,
data); data);
fedw->setObjectName(QStringLiteral("QWindowsFontEngineDirectWrite_") + fontEngine->fontDef.family);
fedw->fontDef = fontDef; fedw->fontDef = fontDef;
fedw->ref.ref(); fedw->ref.ref();
engines[at] = fedw; engines[at] = fedw;

View File

@ -68,10 +68,7 @@ class QWindowsFontEngineData;
class QWindowsFontEngine : public QFontEngine class QWindowsFontEngine : public QFontEngine
{ {
Q_OBJECT friend class QWindowsMultiFontEngine;
Q_PROPERTY(HFONT hFont READ hFont STORED false)
Q_PROPERTY(LOGFONT logFont READ logFont STORED false)
Q_PROPERTY(bool trueType READ trueType STORED false)
public: public:
QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT, QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT,
@ -137,11 +134,6 @@ public:
const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; } const QSharedPointer<QWindowsFontEngineData> &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; } void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; }
private: private:

View File

@ -61,7 +61,6 @@ QT_BEGIN_NAMESPACE
class QWindowsFontEngineDirectWrite : public QFontEngine class QWindowsFontEngineDirectWrite : public QFontEngine
{ {
Q_OBJECT
public: public:
explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace, explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace,
qreal pixelSize, qreal pixelSize,

View File

@ -364,8 +364,9 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
|| ti.fontEngine->type() != QFontEngine::Win; || ti.fontEngine->type() != QFontEngine::Win;
if (!fallBack) { if (!fallBack) {
const QVariant hFontV = ti.fontEngine->property("hFont"); const QVariantMap userData = ti.fontEngine->userData().toMap();
const QVariant logFontV = ti.fontEngine->property("logFont"); const QVariant hFontV = userData.value(QStringLiteral("hFont"));
const QVariant logFontV = userData.value(QStringLiteral("logFont"));
if (hFontV.canConvert<HFONT>() && logFontV.canConvert<LOGFONT>()) { if (hFontV.canConvert<HFONT>() && logFontV.canConvert<LOGFONT>()) {
const HFONT hfont = hFontV.value<HFONT>(); const HFONT hfont = hFontV.value<HFONT>();
const LOGFONT logFont = logFontV.value<LOGFONT>(); const LOGFONT logFont = logFontV.value<LOGFONT>();
@ -1806,8 +1807,9 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h
bool ttf = false; bool ttf = false;
if (ti.fontEngine->type() == QFontEngine::Win) { if (ti.fontEngine->type() == QFontEngine::Win) {
const QVariant hfontV = ti.fontEngine->property("hFont"); const QVariantMap userData = ti.fontEngine->userData().toMap();
const QVariant ttfV = ti.fontEngine->property("trueType"); const QVariant hfontV = userData.value(QStringLiteral("hFont"));
const QVariant ttfV = userData.value(QStringLiteral("trueType"));
if (ttfV.type() == QVariant::Bool && hfontV.canConvert<HFONT>()) { if (ttfV.type() == QVariant::Bool && hfontV.canConvert<HFONT>()) {
hfont = hfontV.value<HFONT>(); hfont = hfontV.value<HFONT>();
ttf = ttfV.toBool(); ttf = ttfV.toBool();