Skip to content

Commit

Permalink
fix blank lines (empty text fragments) incorrect bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
SKefalidis committed Jul 10, 2020
1 parent f469566 commit 44ac994
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,35 @@ void TextBlock::layout(TextBase* t)
break;
}
}

if (_fragments.empty()) {
QFontMetricsF fm = t->fontMetrics();
_bbox.setRect(0.0, -fm.ascent(), 1.0, fm.descent());
_lineSpacing = fm.lineSpacing();
}
else if (_fragments.size() == 1 && _fragments.at(0).text == "") {
auto fi = _fragments.begin();
TextFragment& f = *fi;
f.pos.setX(x);
QFontMetricsF fm(f.font(t), MScore::paintDevice());
if (f.format.valign() != VerticalAlignment::AlignNormal) {
qreal voffset = fm.xHeight() / subScriptSize; // use original height
if (f.format.valign() == VerticalAlignment::AlignSubScript)
voffset *= subScriptOffset;
else
voffset *= superScriptOffset;
f.pos.setY(voffset);
}
else {
f.pos.setY(0.0);
}
// -fm.ascent() * 0.27 is approximately the (incorrect and in need of improvement)
// position of the TextCursor while editing
// deleting 0.27 positions the text at the place it should be (if the cursor was not out of bounds)
QRectF temp(0.0, -fm.ascent() * 0.27, 1.0, fm.descent());
_bbox |= temp;
_lineSpacing = qMax(_lineSpacing, fm.lineSpacing());
}
else {
const auto fiLast = --_fragments.end();
for (auto fi = _fragments.begin(); fi != _fragments.end(); ++fi) {
Expand All @@ -955,8 +979,9 @@ void TextBlock::layout(TextBase* t)
voffset *= superScriptOffset;
f.pos.setY(voffset);
}
else
else {
f.pos.setY(0.0);
}

// Optimization: don't calculate character position
// for the next fragment if there is no next fragment
Expand Down

0 comments on commit 44ac994

Please sign in to comment.