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

Fix magnification issues #15949

Merged
merged 6 commits into from Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/engraving/libmscore/beam.cpp
Expand Up @@ -968,8 +968,7 @@ void Beam::createBeamletSegment(ChordRest* cr, bool isBefore, int level)
const double startX = chordBeamAnchorX(cr, isBefore ? ChordBeamAnchorType::End : ChordBeamAnchorType::Start);

const double beamletLength = score()->styleMM(Sid::beamMinLen).val()
* cr->mag()
* cr->staff()->staffMag(cr);
* cr->mag();

const double endX = startX + (isBefore ? -beamletLength : beamletLength);

Expand Down
36 changes: 13 additions & 23 deletions src/engraving/libmscore/chord.cpp
Expand Up @@ -1449,7 +1449,7 @@ int Chord::calcMinStemLength()
// buzz roll's height is actually half of the visual height,
// so we need to multiply it by 2 to get the actual height
int buzzRollMultiplier = _tremolo->isBuzzRoll() ? 2 : 1;
minStemLength += ceil(_tremolo->minHeight() / _relativeMag * 4.0 * buzzRollMultiplier);
minStemLength += ceil(_tremolo->minHeight() / intrinsicMag() * 4.0 * buzzRollMultiplier);
int outSidePadding = score()->styleMM(Sid::tremoloOutSidePadding).val() / _spatium * 4.0;
int noteSidePadding = score()->styleMM(Sid::tremoloNoteSidePadding).val() / _spatium * 4.0;

Expand All @@ -1472,7 +1472,7 @@ int Chord::calcMinStemLength()
if (_hook) {
bool straightFlags = score()->styleB(Sid::useStraightNoteFlags);
double smuflAnchor = _hook->smuflAnchor().y() * (_up ? 1 : -1);
int hookOffset = floor((_hook->height() / _relativeMag + smuflAnchor) / _spatium * 4) - (straightFlags ? 0 : 2);
int hookOffset = floor((_hook->height() / intrinsicMag() + smuflAnchor) / _spatium * 4) - (straightFlags ? 0 : 2);
// some fonts have hooks that extend very far down (making the height of the hook very large)
// so we constrain to a reasonable maximum for hook length
hookOffset = std::min(hookOffset, 11);
Expand Down Expand Up @@ -1566,7 +1566,7 @@ int Chord::maxReduction(int extensionOutsideStaff) const
int extensionHalfSpaces = floor(extensionOutsideStaff / 2.0);
extensionHalfSpaces = std::min(extensionHalfSpaces, 4);
int reduction = maxReductions[beamCount][extensionHalfSpaces];
if (_relativeMag < 1) {
if (intrinsicMag() < 1) {
// there is an exception for grace-sized stems with hooks.
// reducing by the full amount puts the hooks too low. Limit reduction to 0.5sp
if (hasTradHook) {
Expand Down Expand Up @@ -1659,7 +1659,7 @@ double Chord::calcDefaultStemLength()
}
// extraHeight represents the extra vertical distance between notehead and stem start
// eg. slashed noteheads etc
double extraHeight = (_up ? upNote()->stemUpSE().y() : downNote()->stemDownNW().y()) / _relativeMag / _spatium;
double extraHeight = (_up ? upNote()->stemUpSE().y() : downNote()->stemDownNW().y()) / intrinsicMag() / _spatium;
int shortestStem = score()->styleB(Sid::useWideBeams) ? 12 : (score()->styleD(Sid::shortestStem) + abs(extraHeight)) * 4;
int quarterSpacesPerLine = std::floor(lineDistance * 2);
int chordHeight = (downLine() - upLine()) * quarterSpacesPerLine; // convert to quarter spaces
Expand All @@ -1675,7 +1675,7 @@ double Chord::calcDefaultStemLength()
int middleLine = minStaffOverlap(_up, staffLineCount, beams(), !!_hook, useWideBeams ? 4 : 3, useWideBeams, !(isGrace() || isSmall()));
if (up()) {
int stemEndPosition = upLine() * quarterSpacesPerLine - defaultStemLength;
double stemEndPositionMag = (double)upLine() * quarterSpacesPerLine - (defaultStemLength * _relativeMag);
double stemEndPositionMag = (double)upLine() * quarterSpacesPerLine - (defaultStemLength * intrinsicMag());
int idealStemLength = defaultStemLength;

if (stemEndPositionMag <= -shortStemStart) {
Expand All @@ -1691,7 +1691,7 @@ double Chord::calcDefaultStemLength()
stemLength = std::max(idealStemLength, minStemLengthQuarterSpaces);
} else {
int stemEndPosition = downLine() * quarterSpacesPerLine + defaultStemLength;
double stemEndPositionMag = (double)downLine() * quarterSpacesPerLine + (defaultStemLength * _relativeMag);
double stemEndPositionMag = (double)downLine() * quarterSpacesPerLine + (defaultStemLength * intrinsicMag());
int idealStemLength = defaultStemLength;

int downShortStemStart = (staffLineCount - 1) * (2 * quarterSpacesPerLine) + shortStemStart;
Expand All @@ -1712,7 +1712,7 @@ double Chord::calcDefaultStemLength()
stemLength = calc4BeamsException(stemLength);
}

double finalStemLength = (chordHeight / 4.0 * _spatium) + ((stemLength / 4.0 * _spatium) * _relativeMag);
double finalStemLength = (chordHeight / 4.0 * _spatium) + ((stemLength / 4.0 * _spatium) * intrinsicMag());

// when the chord's magnitude is < 1, the stem length with mag can find itself below the middle line.
// in those cases, we have to add the extra amount to it to bring it to a minimum.
Expand Down Expand Up @@ -1837,17 +1837,6 @@ void Chord::layoutHook()
_hook->layout();
}

void Chord::calcRelativeMag()
{
_relativeMag = 1;
if (isSmall()) {
_relativeMag *= score()->styleD(Sid::smallNoteMag);
}
if (isGrace()) {
_relativeMag *= score()->styleD(Sid::graceNoteMag);
}
}

//! May be called again when the chord is added to or removed from a beam.
void Chord::layoutStem()
{
Expand All @@ -1867,7 +1856,7 @@ void Chord::layoutStem()
removeStem();
return;
}
calcRelativeMag();

if (!_stem) {
createStem();
}
Expand Down Expand Up @@ -2050,7 +2039,6 @@ void Chord::layout()
if (_notes.empty()) {
return;
}
calcRelativeMag();
if (onTabStaff()) {
layoutTablature();
} else {
Expand Down Expand Up @@ -3227,10 +3215,12 @@ void Chord::removeMarkings(bool keepTremolo)
}

//---------------------------------------------------------
// chordMag
// intrinsicMag
// returns the INTRINSIC mag of the chord (i.e. NOT scaled
// by staff size)
//---------------------------------------------------------

double Chord::chordMag() const
double Chord::intrinsicMag() const
{
double m = 1.0;
if (isSmall()) {
Expand All @@ -3249,7 +3239,7 @@ double Chord::chordMag() const
double Chord::mag() const
{
const Staff* st = staff();
return (st ? st->staffMag(this) : 1.0) * chordMag();
return (st ? st->staffMag(this) : 1.0) * intrinsicMag();
}

//---------------------------------------------------------
Expand Down
5 changes: 1 addition & 4 deletions src/engraving/libmscore/chord.h
Expand Up @@ -119,7 +119,6 @@ class Chord final : public ChordRest

double _defaultStemLength;
double _minStemLength;
double _relativeMag = 1; // mag() but relative to the staff size

bool _isUiItem = false;

Expand Down Expand Up @@ -173,7 +172,6 @@ class Chord final : public ChordRest
int calcMinStemLength();
int calc4BeamsException(int stemLength) const;
double calcDefaultStemLength();
void calcRelativeMag();

public:

Expand All @@ -194,9 +192,8 @@ class Chord final : public ChordRest
void undoUnlink() override;

void setScore(Score* s) override;
double chordMag() const;
double intrinsicMag() const override;
double mag() const override;
double relativeMag() const { return _relativeMag; }
double noteHeadWidth() const;

void write(XmlWriter& xml) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/chordline.cpp
Expand Up @@ -94,7 +94,7 @@ void ChordLine::layout()
if (!modified) {
double x2 = 0;
double y2 = 0;
double baseLength = spatium() * (chord() ? chord()->chordMag() : 1);
double baseLength = spatium() * (chord() ? chord()->intrinsicMag() : 1);
double horBaseLength = 1.2 * baseLength; // let the symbols extend a bit more horizontally
x2 += isToTheLeft() ? -horBaseLength : horBaseLength;
y2 += isBelow() ? baseLength : -baseLength;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/libmscore/chordrest.h
Expand Up @@ -210,6 +210,8 @@ class ChordRest : public DurationElement
bool isBefore(const ChordRest*) const;

void undoAddAnnotation(EngravingItem*);

virtual double intrinsicMag() const = 0;
};
} // namespace mu::engraving
#endif
1 change: 1 addition & 0 deletions src/engraving/libmscore/engravingitem.cpp
Expand Up @@ -2603,6 +2603,7 @@ void EngravingItem::autoplaceMeasureElement(bool above, bool add)
sk.add(sh);
d = ss->skyline().south().minDistance(sk);
}
minDistance *= staff()->staffMag(this);
if (d > -minDistance) {
double yd = d + minDistance;
if (above) {
Expand Down
12 changes: 12 additions & 0 deletions src/engraving/libmscore/rest.cpp
Expand Up @@ -760,6 +760,18 @@ void Rest::setTrack(track_idx_t val)
double Rest::mag() const
{
double m = staff() ? staff()->staffMag(this) : 1.0;
return m * intrinsicMag();
}

//---------------------------------------------------------
// intrinsicMag
// returns the INTRINSIC mag of the rest (i.e. NOT scaled
// by staff size)
//---------------------------------------------------------

double Rest::intrinsicMag() const
{
double m = 1.0;
if (isSmall()) {
m *= score()->styleD(Sid::smallNoteMag);
}
Expand Down
1 change: 1 addition & 0 deletions src/engraving/libmscore/rest.h
Expand Up @@ -55,6 +55,7 @@ class Rest : public ChordRest
EngravingItem* linkedClone() override { return new Rest(*this, true); }
Measure* measure() const override { return explicitParent() ? toMeasure(explicitParent()->explicitParent()) : 0; }
double mag() const override;
double intrinsicMag() const override;

void draw(mu::draw::Painter*) const override;
void scanElements(void* data, void (* func)(void*, EngravingItem*), bool all = true) override;
Expand Down
22 changes: 11 additions & 11 deletions src/engraving/libmscore/slur.cpp
Expand Up @@ -1087,9 +1087,9 @@ void Slur::slurPos(SlurPos* sp)
// clear the stem (x)
// allow slight overlap (y)
// don't allow overlap with hook if not disabling the autoplace checks against start/end segments in SlurSegment::layoutSegment()
double yadj = -stemSideInset* sc->mag();
double yadj = -stemSideInset* sc->intrinsicMag();
yadj *= _spatium * __up;
double offset = std::max(stemOffsetX * sc->mag(), minOffset);
double offset = std::max(stemOffsetX * sc->intrinsicMag(), minOffset);
pt += PointF(offset * _spatium, yadj);
// account for articulations
fixArticulations(pt, sc, __up, true);
Expand Down Expand Up @@ -1142,7 +1142,7 @@ void Slur::slurPos(SlurPos* sp)
yadj = -stemSideInset;
}
yadj *= _spatium * __up;
double offset = std::max(stemOffsetX * ec->mag(), minOffset);
double offset = std::max(stemOffsetX * ec->intrinsicMag(), minOffset);
pt += PointF(-offset * _spatium, yadj);
// account for articulations
fixArticulations(pt, ec, __up, true);
Expand Down Expand Up @@ -1173,7 +1173,7 @@ void Slur::slurPos(SlurPos* sp)
po.ry() = scr->bbox().top() + scr->height();
}
double offset = useTablature ? 0.75 : 0.9;
po.ry() += scr->mag() * _spatium * offset * __up;
po.ry() += scr->intrinsicMag() * _spatium * offset * __up;

// adjustments for stem and/or beam
Tremolo* trem = sc ? sc->tremolo() : nullptr;
Expand All @@ -1186,14 +1186,14 @@ void Slur::slurPos(SlurPos* sp)

// in these cases, layout start of slur to stem
double beamWidthSp = score()->styleS(Sid::beamWidth).val() * beam1->magS();
double offset = std::max(beamClearance * sc->mag(), minOffset) * _spatium;
double offset = std::max(beamClearance * sc->intrinsicMag(), minOffset) * _spatium;
double sh = stem1->length() + (beamWidthSp / 2) + offset;
if (_up) {
po.ry() = sc->stemPos().y() - sc->pagePos().y() - sh;
} else {
po.ry() = sc->stemPos().y() - sc->pagePos().y() + sh;
}
po.rx() = sc->stemPosX() + (beamAnchorInset * _spatium * sc->mag()) + (stem1->lineWidthMag() / 2 * __up);
po.rx() = sc->stemPosX() + (beamAnchorInset * _spatium * sc->intrinsicMag()) + (stem1->lineWidthMag() / 2 * __up);

// account for articulations
fixArticulations(po, sc, __up, true);
Expand All @@ -1205,7 +1205,7 @@ void Slur::slurPos(SlurPos* sp)
trem->layout();
Note* note = _up ? sc->upNote() : sc->downNote();
double stemHeight = stem1 ? stem1->length() : trem->defaultStemLengthStart();
double offset = std::max(beamClearance * sc->mag(), minOffset) * _spatium;
double offset = std::max(beamClearance * sc->intrinsicMag(), minOffset) * _spatium;
double sh = stemHeight + offset;

if (_up) {
Expand All @@ -1216,7 +1216,7 @@ void Slur::slurPos(SlurPos* sp)
if (!stem1) {
po.rx() = note->noteheadCenterX();
} else {
po.rx() = sc->stemPosX() + (beamAnchorInset * _spatium * sc->mag()) + (stem1->lineWidthMag() / 2. * __up);
po.rx() = sc->stemPosX() + (beamAnchorInset * _spatium * sc->intrinsicMag()) + (stem1->lineWidthMag() / 2. * __up);
}
fixArticulations(po, sc, __up, true);

Expand Down Expand Up @@ -1301,7 +1301,7 @@ void Slur::slurPos(SlurPos* sp)
po.ry() = endCR()->bbox().top() + endCR()->height();
}
double offset = useTablature ? 0.75 : 0.9;
po.ry() += ecr->mag() * _spatium * offset * __up;
po.ry() += ecr->intrinsicMag() * _spatium * offset * __up;

// adjustments for stem and/or beam
Tremolo* trem = ec ? ec->tremolo() : nullptr;
Expand Down Expand Up @@ -1332,7 +1332,7 @@ void Slur::slurPos(SlurPos* sp)
double beamWidthSp = beam2 ? score()->styleS(Sid::beamWidth).val() : 0;
Note* note = _up ? sc->upNote() : sc->downNote();
double stemHeight = stem2 ? stem2->length() + (beamWidthSp / 2) : trem->defaultStemLengthEnd();
double offset = std::max(beamClearance * ec->mag(), minOffset) * _spatium;
double offset = std::max(beamClearance * ec->intrinsicMag(), minOffset) * _spatium;
double sh = stemHeight + offset;

if (_up) {
Expand All @@ -1344,7 +1344,7 @@ void Slur::slurPos(SlurPos* sp)
// tremolo whole notes
po.setX(note->noteheadCenterX());
} else {
po.setX(ec->stemPosX() + (stem2->lineWidthMag() / 2 * __up) - (beamAnchorInset * _spatium * ec->mag()));
po.setX(ec->stemPosX() + (stem2->lineWidthMag() / 2 * __up) - (beamAnchorInset * _spatium * ec->intrinsicMag()));
}

// account for articulations
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/libmscore/tremolo.cpp
Expand Up @@ -85,7 +85,7 @@ void Tremolo::setParent(Chord* ch)

double Tremolo::chordMag() const
{
return explicitParent() ? toChord(explicitParent())->chordMag() : 1.0;
return explicitParent() ? toChord(explicitParent())->intrinsicMag() : 1.0;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -283,7 +283,7 @@ void Tremolo::layoutOneNoteTremolo(double x, double y, double h, double spatium)

bool up = chord()->up();
int upValue = up ? -1 : 1;
double mag = chord()->relativeMag();
double mag = chord()->intrinsicMag();
spatium *= mag;

double yOffset = h - score()->styleMM(Sid::tremoloOutSidePadding).val() * mag;
Expand Down Expand Up @@ -649,7 +649,7 @@ void Tremolo::layout()
}
}
y = anchor1->y();
h = (score()->styleMM(Sid::tremoloNoteSidePadding).val() + bbox().height()) * _chord1->relativeMag();
h = (score()->styleMM(Sid::tremoloNoteSidePadding).val() + bbox().height()) * _chord1->intrinsicMag();
}

if (twoNotes()) {
Expand Down
19 changes: 10 additions & 9 deletions src/engraving/libmscore/tuplet.cpp
Expand Up @@ -270,18 +270,19 @@ void Tuplet::layout()
}

_hasBracket = calcHasBracket(cr1, cr2);
setMag((cr1->mag() + cr2->mag()) / 2);

//
// calculate bracket start and end point p1 p2
//
double maxSlope = score()->styleD(Sid::tupletMaxSlope);
bool outOfStaff = score()->styleB(Sid::tupletOufOfStaff);
double vHeadDistance = score()->styleMM(Sid::tupletVHeadDistance);
double vStemDistance = score()->styleMM(Sid::tupletVStemDistance);
double stemLeft = score()->styleMM(Sid::tupletStemLeftDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2;
double stemRight = score()->styleMM(Sid::tupletStemRightDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2;
double noteLeft = score()->styleMM(Sid::tupletNoteLeftDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2;
double noteRight = score()->styleMM(Sid::tupletNoteRightDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2;
double vHeadDistance = score()->styleMM(Sid::tupletVHeadDistance) * mag();
double vStemDistance = score()->styleMM(Sid::tupletVStemDistance) * mag();
double stemLeft = (score()->styleMM(Sid::tupletStemLeftDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2) * cr1->mag();
double stemRight = (score()->styleMM(Sid::tupletStemRightDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2) * cr2->mag();
double noteLeft = (score()->styleMM(Sid::tupletNoteLeftDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2) * cr1->mag();
double noteRight = (score()->styleMM(Sid::tupletNoteRightDistance) - score()->styleMM(Sid::tupletBracketWidth) / 2) * cr2->mag();

int move = 0;
setStaffIdx(cr1->vStaffIdx());
Expand All @@ -298,7 +299,7 @@ void Tuplet::layout()
}
}

double l1 = score()->styleMM(Sid::tupletBracketHookHeight);
double l1 = score()->styleMM(Sid::tupletBracketHookHeight) * mag();
double l2l = vHeadDistance; // left bracket vertical distance
double l2r = vHeadDistance; // right bracket vertical distance right

Expand Down Expand Up @@ -743,7 +744,7 @@ void Tuplet::draw(mu::draw::Painter* painter) const
painter->translate(-pos);
}
if (_hasBracket) {
painter->setPen(Pen(color, _bracketWidth.val()));
painter->setPen(Pen(color, _bracketWidth.val() * mag()));
if (!_number) {
painter->drawPolyline(bracketL, 4);
} else {
Expand Down Expand Up @@ -778,7 +779,7 @@ Shape Tuplet::shape() const
{
Shape s;
if (_hasBracket) {
double w = _bracketWidth.val();
double w = _bracketWidth.val() * mag();
s.add(TupletRect(bracketL[0], bracketL[1], w));
s.add(TupletRect(bracketL[1], bracketL[2], w));
if (_number) {
Expand Down
Binary file added vtest/scores/staff-scaling-1.mscz
Binary file not shown.