Skip to content

Commit

Permalink
Support/use musical font files' x-offset for stems
Browse files Browse the repository at this point in the history
Resolves https://musescore.org/en/node/369769#comment-1261591

See also the port to mu4/master at musescore#25050
  • Loading branch information
Jojo-Schmitz committed Oct 6, 2024
1 parent 806ef55 commit 85a0d8a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 25 deletions.
63 changes: 52 additions & 11 deletions libmscore/stem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ qreal Stem::stemLen() const

void Stem::layout()
{
qreal l = _len + _userLen;
qreal _up = up() ? -1.0 : 1.0;
l *= _up;

qreal y1 = 0.0; // vertical displacement to match note attach point
qreal _up = up() ? -1.0 : 1.0;
qreal l = (_len + _userLen) * _up;
qreal x = 0.0; // horizontal displacement to match note attach point
qreal y1 = 0.0; // vertical displacement to match note attach point
const Staff* stf = staff();
if (chord()) {
setMag(chord()->mag());
Expand All @@ -106,18 +105,60 @@ void Stem::layout()
}
else { // non-TAB
// move stem start to note attach point
Note* n = up() ? chord()->downNote() : chord()->upNote();
if ((up() && !n->mirror()) || (!up() && n->mirror()))
y1 += n->stemUpSE().y();
else
y1 += n->stemDownNW().y();
bool u = up();
Note* n = u ? chord()->downNote() : chord()->upNote();
bool m = n->mirror();
qreal lw = lineWidthMag();
if ((u && !m) || (!u && m)) {
QString muscicalFont = score()->styleSt(Sid::musicalSymbolFont);
x = n->stemUpSE().x();
if (muscicalFont == "Bravura") {
if (n->chord()->durationType() == TDuration::DurationType::V_LONG)
x += n->headWidth() - 0.5 * lw; // standard
else
x += 0.6 * lw; // + rather than -, and 0.1 more to prevent a slight 'hump'
}
else if (muscicalFont == "Emmentaler") {
if (n->chord()->durationType() == TDuration::DurationType::V_LONG)
x += n->headWidth() - 0.5 * lw; // standard
else if (n->chord()->durationType() == TDuration::DurationType::V_HALF)
x -= 0.3 * lw; // we should be able to fix this in the matadata
else
x -= 3 * lw; // pure madness, but we should be able to fix this in the metadata
}
else if (muscicalFont == "Gonville") {
if (n->chord()->durationType() == TDuration::DurationType::V_LONG)
x += n->headWidth() - 0.5 * lw; // standard
else
x += 0.2 * lw; // we should be able to fix this in the matadata
}
else if (muscicalFont == "Petaluma") {
if (n->chord()->durationType() == TDuration::DurationType::V_LONG)
x += n->headWidth() - 0.25 * lw;
else if (n->chord()->durationType() == TDuration::DurationType::V_HALF)
x += 0.25 * lw;
x -= 0.5 * lw; // standard
}
else { // seems all other fonts more more less agree on this
if (n->chord()->durationType() == TDuration::DurationType::V_LONG)
x += n->headWidth();
x -= 0.5 * lw;
}
y1 = n->stemUpSE().y();
}
else {
x = n->stemDownNW().x();
x += 0.5 * lw; // here all fonts seem to agree
y1 = n->stemDownNW().y();
}
rxpos() = n->rxpos();
rypos() = n->rypos();
}
}

qreal lw5 = 0.5 * lineWidthMag();

line.setLine(0.0, y1, 0.0, l);
line.setLine(x, y1, x, l);

// compute bounding rectangle
QRectF r(line.p1(), line.p2());
Expand Down
28 changes: 14 additions & 14 deletions mtest/musicxml/io/testSystemDistance_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
<bar-style>light-light</bar-style>
</barline>
</measure>
<measure number="20" width="87.55">
<measure number="20" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -431,7 +431,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="21" width="87.55">
<measure number="21" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -453,7 +453,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="22" width="87.55">
<measure number="22" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -475,7 +475,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="23" width="87.55">
<measure number="23" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -497,7 +497,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="24" width="87.55">
<measure number="24" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -519,7 +519,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="25" width="87.55">
<measure number="25" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -541,7 +541,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="26" width="87.55">
<measure number="26" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand All @@ -563,7 +563,7 @@
<stem>up</stem>
</note>
</measure>
<measure number="27" width="87.55">
<measure number="27" width="87.56">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -635,7 +635,7 @@
<voice>1</voice>
</note>
</measure>
<measure number="31" width="85.46">
<measure number="31" width="85.47">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -676,7 +676,7 @@
<voice>1</voice>
</note>
</measure>
<measure number="34" width="85.46">
<measure number="34" width="85.47">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -717,7 +717,7 @@
<voice>1</voice>
</note>
</measure>
<measure number="37" width="85.46">
<measure number="37" width="85.47">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -758,7 +758,7 @@
<voice>1</voice>
</note>
</measure>
<measure number="40" width="85.46">
<measure number="40" width="85.47">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -799,7 +799,7 @@
<voice>1</voice>
</note>
</measure>
<measure number="43" width="85.46">
<measure number="43" width="85.47">
<note default-x="13.00" default-y="-25.00">
<pitch>
<step>A</step>
Expand Down Expand Up @@ -1074,7 +1074,7 @@
<system-layout>
<system-margins>
<left-margin>0.00</left-margin>
<right-margin>-0.00</right-margin>
<right-margin>0.00</right-margin>
</system-margins>
<system-distance>150.00</system-distance>
</system-layout>
Expand Down

0 comments on commit 85a0d8a

Please sign in to comment.