Skip to content

Commit

Permalink
Fix QFontMetricsF memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
trig-ger committed Sep 6, 2014
1 parent 1cbb713 commit 6da8c08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions libmscore/sym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5361,7 +5361,7 @@ void ScoreFont::load()
qDebug("Json parse error in <%s>(offset: %d): %s", qPrintable(fi.fileName()),
error.offset, qPrintable(error.errorString()));

_fm = new QFontMetricsF(font());
_fm = QFontMetricsF(font());
QFontMetrics fm2(font2); // See comment above
for (auto i : o.keys()) {
bool ok;
Expand All @@ -5373,7 +5373,7 @@ void ScoreFont::load()
Sym* sym = &_symbols[int(symId)];
sym->setString(codeToString(code));
sym->setWidth((fm2.width(sym->string()))/100.0); // Renormalization; see comment above
sym->setBbox(QRectF(_fm->tightBoundingRect(sym->string())));
sym->setBbox(QRectF(_fm.tightBoundingRect(sym->string())));
}
//else
// qDebug("unknown glyph: %s", qPrintable(i));
Expand Down Expand Up @@ -5506,7 +5506,7 @@ void ScoreFont::load()
for (SymId id : c.rids)
s += _symbols[int(id)].string();
sym->setString(s);
sym->setBbox(QRectF(_fm->tightBoundingRect(s)));
sym->setBbox(QRectF(_fm.tightBoundingRect(s)));
}
}

Expand Down Expand Up @@ -5544,7 +5544,7 @@ void ScoreFont::load()
if (ok) {
QString s = codeToString(code);
sym->setString(s);
sym->setBbox(QRectF(_fm->tightBoundingRect(s)));
sym->setBbox(QRectF(_fm.tightBoundingRect(s)));
}
break;
}
Expand Down Expand Up @@ -5572,14 +5572,14 @@ void ScoreFont::load()
for (const UnicodeAlternate& unicode : unicodes) {
Sym* sym = &_symbols[int(unicode.id)];
sym->setString(unicode.string);
sym->setBbox(QRectF(_fm->tightBoundingRect(sym->string())));
sym->setBbox(QRectF(_fm.tightBoundingRect(sym->string())));
}


// add space symbol
Sym* sym = &_symbols[int(SymId::space)];
sym->setString("\u0020");
sym->setBbox(QRectF(_fm->tightBoundingRect(sym->string())));
sym->setBbox(QRectF(_fm.tightBoundingRect(sym->string())));

/*for (int i = 1; i < int(SymId::lastSym); ++i) {
Sym sym = _symbols[i];
Expand Down Expand Up @@ -5642,7 +5642,7 @@ const QRectF ScoreFont::bbox(SymId id, qreal mag) const

const QRectF ScoreFont::bbox(const QString& s, qreal mag) const
{
QRectF r(_fm->tightBoundingRect(s));
QRectF r(_fm.tightBoundingRect(s));
return QRectF(r.x() * mag, r.y() * mag, r.width() * mag, r.height() * mag);
}

Expand Down
10 changes: 5 additions & 5 deletions libmscore/sym.h
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ class Sym {

class ScoreFont {
QFont _font;
QFontMetricsF* _fm = 0;
QFontMetricsF _fm;
QVector<Sym> _symbols;
QString _name;
QString _family;
Expand All @@ -2530,9 +2530,9 @@ class ScoreFont {
void load();

public:
ScoreFont() {}
ScoreFont() : _fm(_font) {}
ScoreFont(const char* n, const char* f, const char* p, const char* fn)
: _name(n), _family(f), _fontPath(p), _filename(fn) {
: _fm(_font), _name(n), _family(f), _fontPath(p), _filename(fn) {
_symbols = QVector<Sym>(int(SymId::lastSym) + 1);
}

Expand All @@ -2554,9 +2554,9 @@ class ScoreFont {
QString symToHtml(SymId, SymId, int leftMargin=0);
QPixmap sym2pixmap(SymId id, qreal mag);

qreal height(SymId id, qreal mag) const { return _fm->tightBoundingRect(toString(id)).height() * mag; }
qreal height(SymId id, qreal mag) const { return _fm.tightBoundingRect(toString(id)).height() * mag; }
qreal width(SymId id, qreal mag) const { return _symbols[int(id)].width() * mag; }
qreal width(const QString& s, qreal mag) const { return _fm->width(s) * mag; }
qreal width(const QString& s, qreal mag) const { return _fm.width(s) * mag; }
const QRectF bbox(SymId id, qreal mag) const;
const QRectF bbox(const QString& s, qreal mag) const;
QPointF attach(SymId id, qreal mag) const { return _symbols[int(id)].attach() * mag; }
Expand Down

0 comments on commit 6da8c08

Please sign in to comment.