Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/engraving/compat/engravingcompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void EngravingCompat::doPreLayoutCompatIfNeeded(MasterScore* score)
{
int mscVersion = score->mscVersion();

if (mscVersion < 470) {
adjustTextOffset(score);
}

if (mscVersion < 460) {
resetMarkerLeftFontSize(score);
resetRestVerticalOffsets(score);
Expand Down Expand Up @@ -233,6 +237,39 @@ void EngravingCompat::adjustVBoxDistances(MasterScore* masterScore)
}
}

void EngravingCompat::adjustTextOffset(MasterScore* masterScore)
{
auto doAdjustTextOffset = [](EngravingItem* item) {
if (!item->isTextBase()) {
return;
}

TextBase* text = toTextBase(item);

// Staff text, system text, and harp pedal diagrams are the only types which are attached to notes and weren't already
// placed with their left edges / centres / right edges aligned to the left / centre / right of the notehead
if (text->positionRelativeToNoteheadRest() && (text->isStaffText() || text->isSystemText() || text->isHarpPedalDiagram())) {
double mag = item->staff() ? item->staff()->staffMag(item) : 1.0;
double xAdj = item->symWidth(SymId::noteheadBlack) * mag;

switch (text->position()) {
case AlignH::HCENTER:
text->setProperty(Pid::OFFSET, PointF(text->offset().x() - xAdj / 2, text->offset().y()));
break;
case AlignH::RIGHT:
text->setProperty(Pid::OFFSET, PointF(text->offset().x() - xAdj, text->offset().y()));
break;
default:
break;
}
}
};

for (Score* score : masterScore->scoreList()) {
score->scanElements(doAdjustTextOffset);
}
}

void EngravingCompat::doPostLayoutCompatIfNeeded(MasterScore* score)
{
bool needRelayout = false;
Expand Down
1 change: 1 addition & 0 deletions src/engraving/compat/engravingcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class EngravingCompat
static void resetMarkerLeftFontSize(MasterScore* masterScore);
static void resetRestVerticalOffsets(MasterScore* masterScore);
static void adjustVBoxDistances(MasterScore* masterScore);
static void adjustTextOffset(MasterScore* masterScore);

static bool relayoutUserModifiedCrossStaffBeams(MasterScore* score);
static bool resetHookHeightSign(MasterScore* masterScore);
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class Dynamic final : public TextBase

bool isEditAllowed(EditData&) const override;

bool positionRelativeToNoteheadRest() const override { return true; }

Hairpin* leftHairpin() const { return m_leftHairpin; }
Hairpin* rightHairpin() const { return m_rightHairpin; }

Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ class Expression final : public TextBase
bool hasVoiceAssignmentProperties() const override { return true; }

void reset() override;

bool positionRelativeToNoteheadRest() const override { return true; }
};
}
2 changes: 2 additions & 0 deletions src/engraving/dom/figuredbass.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class FiguredBass final : public TextBase
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid) const override;

bool positionRelativeToNoteheadRest() const override { return true; }

size_t itemsCount() const { return m_items.size(); }
void appendItem(FiguredBassItem* item) { m_items.push_back(item); }
const std::vector<FiguredBassItem*>& items() const { return m_items; }
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/fingering.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Fingering final : public TextBase
String accessibleInfo() const override;

bool isOnCrossBeamSide() const;

bool positionRelativeToNoteheadRest() const override { return false; }
};
} // namespace mu::engraving
#endif
2 changes: 2 additions & 0 deletions src/engraving/dom/guitarbend.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,7 @@ class GuitarBendText final : public TextBase
GuitarBendText* clone() const override { return new GuitarBendText(*this); }

bool isEditable() const override { return false; }

bool positionRelativeToNoteheadRest() const override { return false; }
};
}
2 changes: 2 additions & 0 deletions src/engraving/dom/hammeronpulloff.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class HammerOnPullOffText final : public TextBase

PropertyValue propertyDefault(Pid id) const override;

bool positionRelativeToNoteheadRest() const override { return false; }

private:
Chord* m_startChord = nullptr;
Chord* m_endChord = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,11 @@ PropertyValue Harmony::propertyDefault(Pid id) const
return v;
}

bool Harmony::positionRelativeToNoteheadRest() const
{
return !parent()->isFretDiagram();
}

//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/harmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Harmony final : public TextBase
bool setProperty(Pid propertyId, const PropertyValue& v) override;
PropertyValue propertyDefault(Pid id) const override;

bool positionRelativeToNoteheadRest() const override;

double mag() const override;

double bassScale() const { return m_bassScale; }
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/harppedaldiagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class HarpPedalDiagram final : public TextBase
bool isTpcPlayable(int tpc);
const std::set<int>& playableTpcs() const { return m_playableTpcs; }

bool positionRelativeToNoteheadRest() const override { return true; }

private:

std::array<PedalPosition, HARP_STRING_NO> m_pedalState;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/instrchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class InstrumentChange final : public TextBase

PropertyValue propertyDefault(Pid) const override;

bool positionRelativeToNoteheadRest() const override { return true; }

bool placeMultiple() const override { return false; }

private:
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/instrumentname.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class InstrumentName final : public TextBase
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid) const override;

bool positionRelativeToNoteheadRest() const override { return false; }

private:

InstrumentNameType m_instrumentNameType = InstrumentNameType::LONG;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/jump.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Jump final : public TextBase
EngravingItem* prevSegmentElement() override;
String accessibleInfo() const override;

bool positionRelativeToNoteheadRest() const override { return false; }

private:
String m_jumpTo;
String m_playUntil;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/lyrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Lyrics final : public TextBase
bool isEditAllowed(EditData&) const override;
void endEdit(EditData&) override;

bool positionRelativeToNoteheadRest() const override { return true; }

const Fraction& ticks() const { return m_ticks; }
void setTicks(const Fraction& tick) { m_ticks = tick; }
Fraction endTick() const;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Marker final : public TextBase
EngravingItem* prevSegmentElement() override;
String accessibleInfo() const override;

bool positionRelativeToNoteheadRest() const override { return false; }

bool centerOnSymbol() const { return m_centerOnSymbol; }
void setCenterOnSymbol(bool val) { m_centerOnSymbol = val; }

Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/measurenumberbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MeasureNumberBase : public TextBase
Measure* measure() const { return toMeasure(explicitParent()); }

bool isEditable() const override { return false; } // The measure numbers' text should not be editable
bool positionRelativeToNoteheadRest() const override { return false; }
};
} // namespace mu::engraving

Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/playcounttext.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class PlayCountText final : public TextBase
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid propertyId) const override;

bool positionRelativeToNoteheadRest() const override { return false; }

private:
friend class Factory;
PlayCountText(Segment* parent, TextStyleType tid = TextStyleType::REPEAT_PLAY_COUNT);
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/rehearsalmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class RehearsalMark final : public TextBase

void styleChanged() override;

bool positionRelativeToNoteheadRest() const override { return false; }

private:
void applyTypeStyle();

Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/stafftextbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class StaffTextBase : public TextBase
bool swing() const { return m_swing; }
int capo() const { return m_capo; }

bool positionRelativeToNoteheadRest() const override { return true; }

private:

String m_channelNames[4];
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/sticking.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Sticking final : public TextBase
Measure* measure() const { return (Measure*)explicitParent()->explicitParent(); }

bool isEditAllowed(EditData&) const override;

bool positionRelativeToNoteheadRest() const override { return true; }
};
} // namespace mu::engraving
#endif
2 changes: 2 additions & 0 deletions src/engraving/dom/tapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ class TappingText final : public TextBase
TappingText* clone() const override { return new TappingText(*this); }

Color curColor(const rendering::PaintOptions& opt) const override;

bool positionRelativeToNoteheadRest() const override { return true; }
};
} // namespace mu::engraving
2 changes: 2 additions & 0 deletions src/engraving/dom/tempotext.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class TempoText final : public TextBase
PropertyValue propertyDefault(Pid id) const override;
String accessibleInfo() const override;

bool positionRelativeToNoteheadRest() const override { return true; }

String tempoInfo() const;

static constexpr double DEFAULT_SYM_SIZE_RATIO = 5.0 / 3.0;
Expand Down
9 changes: 9 additions & 0 deletions src/engraving/dom/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,13 @@ bool mu::engraving::Text::collectForDrawing() const
{
return !(parent() && parent()->isTuplet());
}

bool Text::positionRelativeToNoteheadRest() const
{
if (parent()->isBox() || parent()->isTuplet() || parent()->isSpannerSegment()) {
return false;
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/engraving/dom/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Text final : public TextBase
VoiceAssignment voiceAssignment() const;

bool collectForDrawing() const override;

bool positionRelativeToNoteheadRest() const override;
};
} // namespace mu::engraving

Expand Down
9 changes: 9 additions & 0 deletions src/engraving/dom/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,15 @@ void TextBase::layoutFrame(LayoutData* ldata) const
ldata->setBbox(ldata->frame.adjusted(-w, -w, w, w));
}

// bool TextBase::positionRelativeToNoteheadRest() const
// {
// if (!parent()) {
// return false;
// }

// return true;
// }

//---------------------------------------------------------
// lineSpacing
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ class TextBase : public EngravingItem
//! At the moment it's: Text, Jump, Marker
bool layoutToParentWidth() const { return m_layoutToParentWidth; }

virtual bool positionRelativeToNoteheadRest() const = 0;

void setVoiceAssignment(VoiceAssignment v) { m_voiceAssignment = v; }
VoiceAssignment voiceAssignment() const { return m_voiceAssignment; }
void setDirection(DirectionV v) { m_direction = v; }
Expand Down
6 changes: 0 additions & 6 deletions src/engraving/rendering/score/dynamicslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ void DynamicsLayout::doLayoutDynamic(Dynamic* item, Dynamic::LayoutData* ldata,
return;
}

bool centerOnNote = item->centerOnNotehead() || (!item->centerOnNotehead() && item->position() == AlignH::HCENTER);
double mag = item->staff()->staffMag(item);
double noteHeadWidth = item->score()->noteHeadWidth() * mag;

ldata->moveX(noteHeadWidth * (centerOnNote ? 0.5 : 1));

if (!item->centerOnNotehead()) {
return;
}
Expand Down
5 changes: 1 addition & 4 deletions src/engraving/rendering/score/lyricslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,16 @@ void LyricsLayout::layout(Lyrics* item, LayoutContext& ctx)
}
}

double nominalWidth = item->symWidth(SymId::noteheadBlack);
if (item->position() == AlignH::HCENTER) {
//
// center under notehead, not origin
// however, lyrics that are melismas or have verse numbers will be forced to left alignment
//
// center under note head
x += nominalWidth * .5 - centerAdjust * 0.5;
x += -centerAdjust * 0.5;
} else if (item->position() == AlignH::LEFT) {
// even for left aligned syllables, ignore leading verse numbers and/or punctuation
x -= leftAdjust;
} else if (item->position() == AlignH::RIGHT) {
x += nominalWidth;
}

ldata->setPosX(x);
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/rendering/score/textlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ void TextLayout::textHorizontalLayout(const TextBase* item, Shape& shape, double
default:
ASSERT_X("Lay out to parent width only valid for items with page or frame as parent");
}
} else if (item->positionRelativeToNoteheadRest()) {
// For items aligned to notehead/rests
double mag = item->staff() ? item->staff()->staffMag(item) : 1.0;
layoutWidth = item->symWidth(SymId::noteheadBlack) * mag;
}

// Position and alignment
Expand All @@ -217,6 +221,7 @@ void TextLayout::textHorizontalLayout(const TextBase* item, Shape& shape, double
shape.add(textBlock.shape().translated(PointF(0.0, textBlock.y())));
continue;
}

// Align relative to the longest line
AlignH alignH = item->align().horizontal;
if (alignH == AlignH::HCENTER) {
Expand Down
21 changes: 0 additions & 21 deletions src/engraving/rendering/score/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5319,27 +5319,6 @@ void TLayout::layoutSticking(const Sticking* item, Sticking::LayoutData* ldata)
LAYOUT_CALL_ITEM(item);
TextLayout::layoutBaseTextBase(item, ldata);

AlignH itemPosition = item->position();
if (itemPosition != AlignH::LEFT) {
const Segment* seg = item->segment();
const Chord* chord = nullptr;
track_idx_t sTrack = trackZeroVoice(item->track());
track_idx_t eTrack = sTrack + VOICES;
for (track_idx_t track = sTrack; track < eTrack; ++track) {
EngravingItem* el = seg->element(track);
if (el && el->isChord()) {
chord = toChord(el);
break;
}
}

if (chord) {
const Note* refNote = item->placeAbove() ? chord->upNote() : chord->downNote();
double noteWidth = refNote->ldata()->bbox().width();
ldata->moveX(itemPosition == AlignH::HCENTER ? 0.5 * noteWidth : noteWidth);
}
}

if (item->autoplace() && item->explicitParent()) {
const Segment* s = toSegment(item->explicitParent());
const Measure* m = s->measure();
Expand Down
Loading
Loading