Skip to content

Commit

Permalink
Merge pull request musescore#23768 from mike-spa/prepareForNewLelandC…
Browse files Browse the repository at this point in the history
…utouts

Implement cutout shapes for clefs and dynamics in preparation of new Leland release
  • Loading branch information
RomanPudashkin committed Aug 20, 2024
1 parent f0b92dd commit bd347b3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/engraving/dom/clef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ void Clef::undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps)
}
}

bool Clef::isMidMeasureClef() const
{
return segment() && segment()->rtick().isNotZero();
}

void Clef::manageExclusionFromParts(bool exclude)
{
if (exclude) {
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/clef.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class Clef final : public EngravingItem
bool isHeader() const { return m_isHeader; }
void setIsHeader(bool val) { m_isHeader = val; }

bool isMidMeasureClef() const;

bool canBeExcludedFromOtherParts() const override { return !isHeader(); }
void manageExclusionFromParts(bool exclude) override;

Expand Down
19 changes: 17 additions & 2 deletions src/engraving/dom/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "barline.h"
#include "box.h"
#include "dynamic.h"
#include "instrumentname.h"
#include "measure.h"
#include "mscore.h"
Expand Down Expand Up @@ -1058,7 +1059,8 @@ void TextBlock::layout(const TextBase* t)
for (auto fi = m_fragments.begin(); fi != m_fragments.end(); ++fi) {
TextFragment& f = *fi;
f.pos.setX(x);
FontMetrics fm(f.font(t));
Font fragmentFont = f.font(t);
FontMetrics fm(fragmentFont);
if (f.format.valign() != VerticalAlignment::AlignNormal) {
double voffset = fm.xHeight() / subScriptSize; // use original height
if (f.format.valign() == VerticalAlignment::AlignSubScript) {
Expand All @@ -1078,7 +1080,20 @@ void TextBlock::layout(const TextBase* t)
x += w;
}

m_shape.add(fm.tightBoundingRect(f.text).translated(f.pos), t);
RectF textBRect = fm.tightBoundingRect(f.text).translated(f.pos);
bool useDynamicSymShape = fragmentFont.type() == Font::Type::MusicSymbol && t->isDynamic();
if (useDynamicSymShape) {
const Dynamic* dyn = toDynamic(t);
SymId symId = TConv::symId(dyn->dynamicType());
if (symId != SymId::noSym) {
m_shape.add(dyn->symShapeWithCutouts(symId).translated(f.pos));
} else {
m_shape.add(textBRect, t);
}
} else {
m_shape.add(textBRect, t);
}

Font font = f.font(t);
if (font.type() == Font::Type::MusicSymbol || font.type() == Font::Type::MusicSymbolText) {
// SEMI-HACK: Music fonts can have huge linespacing because of tall symbols, so instead of using the
Expand Down
8 changes: 6 additions & 2 deletions src/engraving/rendering/dev/horizontalspacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ void HorizontalSpacing::spaceRightAlignedSegments(Measure* m, double segmentShap
// Compute spacing
for (Segment* raSegment : rightAlignedSegments) {
// 1) right-align the segment against the following ones
double minDistAfter = -DBL_MAX;
double minDistAfter = 0.0;
for (Segment* seg = raSegment->nextActive(); seg; seg = seg->nextActive()) {
double xDiff = seg->x() - raSegment->x();
double minDist = minHorizontalCollidingDistance(raSegment, seg, segmentShapeSqueezeFactor);
minDistAfter = std::max(minDistAfter, minDist - xDiff);
}
if (minDistAfter != -DBL_MAX && raSegment->prevActive()) {
if (raSegment->prevActive()) {
Segment* prevSegment = raSegment->prevActive();
prevSegment->setWidth(prevSegment->width() - minDistAfter);
prevSegment->setWidthOffset(prevSegment->widthOffset() - minDistAfter);
Expand Down Expand Up @@ -539,6 +539,10 @@ bool HorizontalSpacing::isNeverKernable(const EngravingItem* item)

switch (type) {
case ElementType::CLEF:
if (toClef(item)->isMidMeasureClef()) {
return false;
}
// fall through
case ElementType::TIMESIG:
case ElementType::KEYSIG:
case ElementType::BAR_LINE:
Expand Down
11 changes: 8 additions & 3 deletions src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,15 @@ void TLayout::layoutClef(const Clef* item, Clef::LayoutData* ldata, const Layout
}
// clefs on palette or at start of system/measure are left aligned
// other clefs are right aligned
RectF r(item->symBbox(ldata->symId));
double x = item->segment() && item->segment()->rtick().isNotZero() ? -r.right() : 0.0;
Shape shape(item->symShapeWithCutouts(ldata->symId));
bool isMidMeasureClef = item->isMidMeasureClef();
double x = isMidMeasureClef ? -shape.right() : 0.0;
ldata->setPos(PointF(x, yoff * _spatium + (stepOffset * 0.5 * _spatium)));
ldata->setBbox(r);
if (item->isMidMeasureClef()) {
ldata->setShape(shape);
} else {
ldata->setBbox(item->symBbox(ldata->symId));
}
}

void TLayout::layoutCapo(const Capo* item, Capo::LayoutData* ldata, const LayoutContext&)
Expand Down

0 comments on commit bd347b3

Please sign in to comment.