Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support/use musical font files' x-offset for stems #672

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fonts/gootville/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6587,7 +6587,7 @@
-0.168
],
"stemUpSE": [
1.18,
1.26,
0.168
]
},
Expand Down Expand Up @@ -7091,7 +7091,7 @@
-0.168
],
"stemUpSE": [
1.18,
1.26,
0.168
]
},
Expand Down Expand Up @@ -8472,4 +8472,4 @@
]
}
}
}
}
4 changes: 2 additions & 2 deletions fonts/mscore/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
-0.2347675
],
"stemUpSE": [
1.6452225,
1.3152225,
0.2347675
]
},
Expand Down Expand Up @@ -1256,7 +1256,7 @@
-0.196
],
"stemUpSE": [
1.364,
1.387,
0.192
]
},
Expand Down
69 changes: 58 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,66 @@ 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();
SymId symId = n->noteHead();
if ((u && !m) || (!u && m)) {
// default offsets for all fonts, fits for most
x = n->stemUpSE().x() - 0.5 * lw;
y1 = n->stemUpSE().y();
if (symId == SymId::noteheadDoubleWhole) {
x += n->headWidth();
y1 -= 0.5 * spatium();
}
// some fonts' qlyphs need special treatment, suitable offsets found after lots of trial and error
QString muscicalFont = score()->styleSt(Sid::musicalSymbolFont);
if (muscicalFont == "AloisenGrooveU") {
if (symId == SymId::noteheadHalf || symId == SymId::noteheadBlack)
x += n->headWidth() - 0.075 * lw; // sticks out of the notehead a bit, but does so for downstem too
}
else if (muscicalFont == "AloisenU" || muscicalFont == "Bravura") {
if (symId == SymId::noteheadHalf || symId == SymId::noteheadBlack)
x += 1.1 * lw; // apparently these glyphs` stemUpSE cater for stemwidth, but need an extra 0.1 to prevent a slight 'hump'
}
#if 0 // fixing the metadata instead
else if (muscicalFont == "Emmentaler") {
if (symId == SymId::noteheadHalf)
x += 0.2 * lw; // to prevent a slight 'hump', we should be able to fix this in the metadata
else if (symId == SymId::noteheadBlack)
x -= 2.5 * lw; // pure madness, but we should be able to fix this in the metadata
}
else if (muscicalFont == "Gonville") {
if (symId == SymId::noteheadHalf || symId == SymId::noteheadBlack)
x += 0.7 * lw; // we should be able to fix this in the metadata
}
#endif
else if (muscicalFont == "Legato") {
if (symId == SymId::noteheadDoubleWhole) // so far the only font with correct metadata for this notehead
x -= n->headWidth();
}
else if (muscicalFont == "Petaluma") {
if (symId == SymId::noteheadDoubleWhole)
x -= 0.25 * lw;
else if (symId == SymId::noteheadHalf)
x += 0.25 * lw;
}
}
else { // here all fonts seem to agree;
x = n->stemDownNW().x() + 0.5 * lw;
y1 = n->stemDownNW().y();
if (symId == SymId::noteheadDoubleWhole)
y1 += 0.5 * spatium();
}
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
Loading