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:
parent
8b124a7dde
commit
106843ad1a
@ -206,7 +206,7 @@ Q_AUTOTEST_EXPORT QList<QFontEngine *> QFontEngine_stopCollectingEngines()
|
||||
// QFontEngine
|
||||
|
||||
QFontEngine::QFontEngine()
|
||||
: QObject(), ref(0),
|
||||
: ref(0),
|
||||
font_(0), font_destroy_func(0),
|
||||
face_(0), face_destroy_func(0)
|
||||
{
|
||||
|
@ -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<GlyphCacheEntry> 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();
|
||||
|
@ -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<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))) {
|
||||
engine = cachedEngine;
|
||||
fc->updateHitCountAndTimeStamp(it.value());
|
||||
|
@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
class QFontEngineMultiFontConfig : public QFontEngineMultiQPA
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QFontEngineMultiFontConfig(QFontEngine *fe, int script);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<QWindowsFontEngine*>(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;
|
||||
|
@ -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<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; }
|
||||
|
||||
private:
|
||||
|
@ -61,7 +61,6 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsFontEngineDirectWrite : public QFontEngine
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace,
|
||||
qreal pixelSize,
|
||||
|
@ -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<HFONT>() && logFontV.canConvert<LOGFONT>()) {
|
||||
const HFONT hfont = hFontV.value<HFONT>();
|
||||
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;
|
||||
|
||||
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>()) {
|
||||
hfont = hfontV.value<HFONT>();
|
||||
ttf = ttfV.toBool();
|
||||
|
Loading…
Reference in New Issue
Block a user