cache symbol width

This commit is contained in:
ws 2014-02-13 12:08:21 +01:00
parent 8162e16dab
commit da4926d4f2
3 changed files with 5 additions and 2 deletions

View file

@ -4313,6 +4313,7 @@ void ScoreFont::load()
SymId symId = Sym::lnhash.value(i);
Sym* sym = &_symbols[int(symId)];
sym->setString(codeToString(code));
sym->setWidth(_fm->width(sym->string()));
}
// else
// qDebug("unknown glyph: %s", qPrintable(i));

View file

@ -1951,6 +1951,7 @@ enum class SymId {
class Sym {
QString _string;
QPointF _attach;
qreal _width; // cached width
public:
Sym() { }
@ -1960,6 +1961,8 @@ class Sym {
bool isValid() const { return !_string.isEmpty(); }
QPointF attach() const { return _attach; }
void setAttach(const QPointF& r) { _attach = r; }
void setWidth(qreal val) { _width = val; }
qreal width() const { return _width; }
static SymId name2id(const QString& s) { return lnhash.value(s, SymId::noSym); } // return noSym if not found
static SymId oldName2id(const QString s) { return lonhash.value(s, SymId::noSym);}
@ -2018,7 +2021,7 @@ class ScoreFont {
QPixmap sym2pixmap(SymId id, qreal mag);
qreal height(SymId id, qreal mag) const { return _fm->tightBoundingRect(toString(id)).height() * mag; }
qreal width(SymId id, qreal mag) const { return _fm->width(toString(id)) * 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; }
const QRectF bbox(SymId id, qreal mag) const;
const QRectF bbox(const QString& s, qreal mag) const;

View file

@ -1868,7 +1868,6 @@ void Text::textStyleChanged()
{
if (_styleIndex != TEXT_STYLE_UNKNOWN)
setTextStyle(score()->textStyle(_styleIndex));
setText(text()); // destroy formatting
score()->setLayoutAll(true);
}