Index: qtextengine.cpp =================================================================== --- qtextengine.cpp (revision 1953) +++ qtextengine.cpp (working copy) @@ -1132,8 +1132,17 @@ si.glyph_data_offset = layoutData->used; - QFontEngine *font = fontEngine(si, &si.ascent, &si.descent, &si.leading); + class QFontEngineDeref + { + public: + static inline void cleanup (QFontEngine *engine) + { + engine->ref.deref(); + } + }; + QScopedPointer font(fontEngine(si, &si.ascent, &si.descent, &si.leading)); + bool kerningEnabled = this->font(si).d->kerning; HB_ShaperItem entire_shaper_item; @@ -1175,7 +1184,7 @@ } QGlyphLayout initialGlyphs = availableGlyphs(&si).mid(0, entire_shaper_item.num_glyphs); - if (!stringToGlyphs(&entire_shaper_item, &initialGlyphs, font)) { + if (!stringToGlyphs(&entire_shaper_item, &initialGlyphs, font.data())) { if (! ensureSpace(entire_shaper_item.num_glyphs)) { if (hasCaseChange(si)) delete [] const_cast(entire_shaper_item.string); @@ -1183,7 +1192,7 @@ } initialGlyphs = availableGlyphs(&si).mid(0, entire_shaper_item.num_glyphs); - if (!stringToGlyphs(&entire_shaper_item, &initialGlyphs, font)) { + if (!stringToGlyphs(&entire_shaper_item, &initialGlyphs, font.data())) { // ############ if this happens there's a bug in the fontengine if (hasCaseChange(si) && entire_shaper_item.string != upperCased) delete [] const_cast(entire_shaper_item.string); @@ -1236,12 +1245,12 @@ if (shaper_item.num_glyphs < shaper_item.item.length) shaper_item.num_glyphs = shaper_item.item.length; - QFontEngine *actualFontEngine = font; + QFontEngine *actualFontEngine = font.data(); uint engineIdx = 0; if (font->type() == QFontEngine::Multi) { engineIdx = uint(availableGlyphs(&si).glyphs[glyph_pos] >> 24); - actualFontEngine = static_cast(font)->engine(engineIdx); + actualFontEngine = static_cast(font.data())->engine(engineIdx); } shaper_item.font = actualFontEngine->harfbuzzFont();