Skip to content

Commit

Permalink
fix #22696 Lyrics dont overlap stave elements
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Aug 29, 2016
1 parent de8ea53 commit 962076f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ Shape ChordRest::shape() const
x2 = qMax(x2, x1 + l->bbox().width() + margin);
}
if (x2 > x1)
shape.add(QRectF(x1, 0.0, x2-x1, 1.0));
shape.add(QRectF(x1, -2.0, x2-x1, 0.0));
return shape;
}

Expand Down
6 changes: 2 additions & 4 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,12 +1996,12 @@ qreal Score::computeMinWidth(Segment* s, bool isFirstMeasureInSystem)
// this is time consuming (ca. +5%) and probably requires more optimization

int n = 1;
for (Segment* ps = ss;;) {
for (Segment* ps = ss; ps != s;) {
qreal ww;
ps = ps->prev();
if (ps == s)
ww = ns->minLeft(ls) - ss->x();
else {
ps = ps->prev();
if (ps->isChordRestType())
++n;
ww = ps->minHorizontalDistance(ns, false) - (ss->x() - ps->x());
Expand Down Expand Up @@ -2029,8 +2029,6 @@ qreal Score::computeMinWidth(Segment* s, bool isFirstMeasureInSystem)
x = xx;
break;
}
if (ps == s)
break;
}
#endif
}
Expand Down
7 changes: 2 additions & 5 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,17 +1366,15 @@ qreal Segment::minHorizontalDistance(Segment* ns, bool systemHeaderGap) const
Segment::Type st = segmentType();
Segment::Type nst = ns ? ns->segmentType() : Segment::Type::Invalid;

// printf("minHDist %s - %s\n", subTypeName(), ns->subTypeName());

qreal w = 0.0;
for (unsigned staffIdx = 0; staffIdx < _shapes.size(); ++staffIdx) {
qreal d = staffShape(staffIdx).minHorizontalDistance(ns->staffShape(staffIdx));
w = qMax(w, d);
}

if (st == Segment::Type::ChordRest) {
if (isChordRestType()) {
if (nst == Segment::Type::EndBarLine)
// w = qMax(w, score()->noteHeadWidth()) + score()->styleP(StyleIdx::noteBarDistance);
w += score()->styleP(StyleIdx::noteBarDistance);
else if (nst == Segment::Type::Clef)
w = qMax(w, score()->styleP(StyleIdx::clefLeftMargin));
Expand All @@ -1397,7 +1395,7 @@ qreal Segment::minHorizontalDistance(Segment* ns, bool systemHeaderGap) const
w = qMax(w, score()->noteHeadWidth()) + score()->styleP(StyleIdx::minNoteDistance);
}
}
else if (st != Segment::Type::ChordRest && nst == Segment::Type::ChordRest) {
else if (nst == Segment::Type::ChordRest) {
qreal d;
if (systemHeaderGap) {
if (st == Segment::Type::TimeSig)
Expand Down Expand Up @@ -1451,7 +1449,6 @@ qreal Segment::minHorizontalDistance(Segment* ns, bool systemHeaderGap) const
w = 0.0;
if (ns)
w += ns->extraLeadingSpace().val() * spatium();
// printf(" == %f %s %s\n", w, subTypeName(), ns ? ns->subTypeName() : "-0-");
return w;
}

Expand Down
9 changes: 5 additions & 4 deletions libmscore/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ qreal Shape::minHorizontalDistance(const Shape& a) const
for (const QRectF& r1 : *this) {
qreal ay1 = r1.top();
qreal ay2 = r1.bottom();
// if ((ay1 >= by1 && ay1 < by2) || (ay2 >= by1 && ay2 < by2) || (ay1 < by1 && ay2 >= by2))
if (intersects(ay1, ay2, by1, by2))
if (intersects(ay1, ay2, by1, by2)
|| ((r1.height() == 0.0) && (r2.height() == 0.0) && (ay1 == by1))
|| ((r1.width() == 0.0) || (r2.width() == 0.0)))
// if (intersects(ay1, ay2, by1, by2))
dist = qMax(dist, r1.right() - r2.left());
}
}
Expand All @@ -89,7 +91,6 @@ qreal Shape::minVerticalDistance(const Shape& a) const
for (const QRectF& r1 : *this) {
qreal ax1 = r1.left();
qreal ax2 = r1.right();
// if ((ax1 >= bx1 && ax1 < bx2) || (ax2 >= bx1 && ax2 < bx2) || (ax1 < bx1 && ax2 >= bx2))
if (intersects(ax1, ax2, bx1, bx2))
dist = qMax(dist, r1.bottom() - r2.top());
}
Expand All @@ -106,7 +107,7 @@ qreal Shape::left() const
{
qreal dist = 0.0;
for (const QRectF& r : *this) {
if (r.left() < dist)
if (r.height() != 0.0 && r.left() < dist)
dist = r.left();
}
return -dist;
Expand Down
2 changes: 2 additions & 0 deletions libmscore/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ inline static bool intersects(qreal a, qreal b, qreal c, qreal d)
// return (a >= c && a < d) || (b >= c && b < d) || (a < c && b >= b);
// return (std::max(a,b) > std::min(c,d)) && (std::min(a,b) < std::max(c,d));
// if we can assume a <= b and c <= d
if (a == b || c == d) // zero height
return false;
return (b > c) && (a < d);
}

Expand Down

0 comments on commit 962076f

Please sign in to comment.