Skip to content

Commit

Permalink
remove collision between music and footer
Browse files Browse the repository at this point in the history
fix style changes

fix failing tests
  • Loading branch information
Nick-Mazuk committed Sep 20, 2021
1 parent a36b599 commit 0f3fb37
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/engraving/layout/layoutpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void LayoutPage::collectPage(const LayoutOptions& options, LayoutContext& ctx)
{
const qreal slb = ctx.score()->styleP(Sid::staffLowerBorder);
bool breakPages = ctx.score()->layoutMode() != LayoutMode::SYSTEM;
qreal ey = ctx.page->height() - ctx.page->bm();
qreal footerExtension = qMax(0.0, ctx.page->footerHeight() - ctx.score()->styleP(Sid::footerOffset)); // how much the footer extends above the margin
qreal endY = ctx.page->height() - ctx.page->bm() - footerExtension;
qreal y = 0.0;

System* nextSystem = 0;
Expand Down Expand Up @@ -206,12 +207,12 @@ void LayoutPage::collectPage(const LayoutOptions& options, LayoutContext& ctx)
qreal margin = qMax(ctx.curSystem->minBottom(), ctx.curSystem->spacerDistance(false));
dist += qMax(margin, slb);
}
breakPage = (y + dist) >= ey && breakPages;
breakPage = (y + dist) >= endY && breakPages;
}
if (breakPage) {
qreal dist = qMax(ctx.prevSystem->minBottom(), ctx.prevSystem->spacerDistance(false));
dist = qMax(dist, slb);
layoutPage(ctx, ctx.page, ey - (y + dist));
layoutPage(ctx, ctx.page, endY - (y + dist));
// if we collected a system we cannot fit onto this page,
// we need to collect next page in order to correctly set system positions
if (collected) {
Expand Down
104 changes: 99 additions & 5 deletions src/engraving/libmscore/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,26 @@ void Page::draw(mu::draw::Painter* painter) const
//---------------------------------------------------------

void Page::drawHeaderFooter(mu::draw::Painter* p, int area, const QString& ss) const
{
Text* text = layoutHeaderFooter(area, ss);
if (!text) {
return;
}
p->translate(text->pos());
text->draw(p);
p->translate(-text->pos());
text->moveToDummy();
}

//---------------------------------------------------------
// layoutHeaderFooter
//---------------------------------------------------------

Text* Page::layoutHeaderFooter(int area, const QString& ss) const
{
QString s = replaceTextMacros(ss);
if (s.isEmpty()) {
return;
return nullptr;
}

Text* text;
Expand Down Expand Up @@ -216,10 +232,88 @@ void Page::drawHeaderFooter(mu::draw::Painter* p, int area, const QString& ss) c
text->setAlign(flags);
text->setXmlText(s);
text->layout();
p->translate(text->pos());
text->draw(p);
p->translate(-text->pos());
text->moveToDummy();
return text;
}

//---------------------------------------------------------
// headerHeight
//---------------------------------------------------------

qreal Page::headerHeight() const
{
if (!score()->isLayoutMode(LayoutMode::PAGE)) {
return 0.0;
}

int n = no() + 1 + score()->pageNumberOffset();

QString s1, s2, s3;

if (score()->styleB(Sid::showHeader) && (no() || score()->styleB(Sid::headerFirstPage))) {
bool odd = (n & 1) || !score()->styleB(Sid::headerOddEven);
if (odd) {
s1 = score()->styleSt(Sid::oddHeaderL);
s2 = score()->styleSt(Sid::oddHeaderC);
s3 = score()->styleSt(Sid::oddHeaderR);
} else {
s1 = score()->styleSt(Sid::evenHeaderL);
s2 = score()->styleSt(Sid::evenHeaderC);
s3 = score()->styleSt(Sid::evenHeaderR);
}

Text* headerLeft = layoutHeaderFooter(0, s1);
Text* headerCenter = layoutHeaderFooter(1, s2);
Text* headerRight = layoutHeaderFooter(2, s3);

qreal headerLeftHeight = headerLeft ? headerLeft->height() : 0.0;
qreal headerCenterHeight = headerCenter ? headerCenter->height() : 0.0;
qreal headerRightHeight = headerRight ? headerRight->height() : 0.0;
return qMax(headerLeftHeight, qMax(headerCenterHeight, headerRightHeight));
}

return 0.0;
}

//---------------------------------------------------------
// footerHeight
//---------------------------------------------------------

qreal Page::footerHeight() const
{
if (!score()->isLayoutMode(LayoutMode::PAGE)) {
return 0.0;
}

int n = no() + 1 + score()->pageNumberOffset();

QString s1, s2, s3;

if (score()->styleB(Sid::showFooter) && (no() || score()->styleB(Sid::footerFirstPage))) {
bool odd = (n & 1) || !score()->styleB(Sid::footerOddEven);
if (odd) {
s1 = score()->styleSt(Sid::oddFooterL);
s2 = score()->styleSt(Sid::oddFooterC);
s3 = score()->styleSt(Sid::oddFooterR);
} else {
s1 = score()->styleSt(Sid::evenFooterL);
s2 = score()->styleSt(Sid::evenFooterC);
s3 = score()->styleSt(Sid::evenFooterR);
}

Text* footerLeft = layoutHeaderFooter(3, s1);
Text* footerCenter = layoutHeaderFooter(4, s2);
Text* footerRight = layoutHeaderFooter(5, s3);

qreal footerLeftHeight = footerLeft ? footerLeft->height() : 0.0;
qreal footerCenterHeight = footerCenter ? footerCenter->height() : 0.0;
qreal footerRightHeight = footerRight ? footerRight->height() : 0.0;

qreal footerHeight = qMax(footerLeftHeight, qMax(footerCenterHeight, footerRightHeight));

return footerHeight;
}

return 0.0;
}

//---------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/libmscore/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Page final : public EngravingItem

QString replaceTextMacros(const QString&) const;
void drawHeaderFooter(mu::draw::Painter*, int area, const QString&) const;
Text* layoutHeaderFooter(int area, const QString& ss) const;

public:

Expand Down Expand Up @@ -86,6 +87,8 @@ class Page final : public EngravingItem
qreal bm() const;
qreal lm() const;
qreal rm() const;
qreal headerHeight() const;
qreal footerHeight() const;

void draw(mu::draw::Painter*) const override;
void scanElements(void* data, void (* func)(void*, EngravingItem*), bool all=true) override;
Expand Down
7 changes: 6 additions & 1 deletion src/engraving/libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2008,15 +2008,20 @@ void TextBase::layout1()
}
RectF bb;
qreal y = 0;

// adjust the bounding box for the text item
for (int i = 0; i < rows(); ++i) {
TextBlock* t = &_layout[i];
t->layout(this);
// if the text block is empty, ignore it
const RectF* r = &t->boundingRect();

if (r->height() == 0) {
r = &_layout[i - i].boundingRect();
}
y += t->lineSpacing();
if (t->columns() != 0) {
y += t->lineSpacing();
}
t->setY(y);
bb |= r->translated(0.0, y);
}
Expand Down

0 comments on commit 0f3fb37

Please sign in to comment.