Skip to content

Commit

Permalink
Merge pull request #3821 from brdvd/feat/vertical-justification
Browse files Browse the repository at this point in the history
Change vertical justification of last page
  • Loading branch information
lpugin authored Oct 11, 2024
2 parents d11c268 + 0c3c685 commit 329d6db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
4 changes: 2 additions & 2 deletions include/vrv/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ class Page : public Object {
void AdjustSylSpacingByVerse(const IntTree &verseTree, Doc *doc);

/**
* Check whether vertical justification is required for the current page
* Reduces the justifiable height based on the --justification-max-vertical option
*/
bool IsJustificationRequired(const Doc *doc);
void ReduceJustifiableHeight(const Doc *doc);

//
public:
Expand Down
2 changes: 1 addition & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ Options::Options()

m_justificationMaxVertical.SetInfo("Maximum ratio of justifiable height for page",
"Maximum ratio of justifiable height to page height that can be used for the vertical justification");
m_justificationMaxVertical.Init(0.3, 0.0, 1.0);
m_justificationMaxVertical.Init(0.2, 0.0, 1.0);
this->Register(&m_justificationMaxVertical, "justificationMaxVertical", &m_generalLayout);

m_ledgerLineThickness.SetInfo("Ledger line thickness", "The thickness of the ledger lines");
Expand Down
40 changes: 11 additions & 29 deletions src/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ void Page::JustifyVertically()
return;
}

// Ignore vertical justification if it's not required
if (!this->IsJustificationRequired(doc)) return;
this->ReduceJustifiableHeight(doc);

// Justify Y position
JustifyYFunctor justifyY(doc);
Expand All @@ -643,42 +642,25 @@ void Page::JustifyVertically()
}
}

bool Page::IsJustificationRequired(const Doc *doc)
void Page::ReduceJustifiableHeight(const Doc *doc)
{
const Pages *pages = doc->GetPages();
assert(pages);

const int childSystems = this->GetChildCount(SYSTEM);
// Last page and justification of last page is not enabled
double maxRatio = doc->GetOptions()->m_justificationMaxVertical.GetValue();
// Special handling for justification of last page
if (pages->GetLast() == this) {
const int idx = this->GetIdx();
if (idx > 0) {
const Page *previousPage = dynamic_cast<const Page *>(pages->GetPrevious(this));
assert(previousPage);
const int previousJustifiableHeight = previousPage->m_drawingJustifiableHeight;
const int previousJustificationSum = previousPage->m_justificationSum;

if (previousJustifiableHeight < m_drawingJustifiableHeight) {
m_drawingJustifiableHeight = previousJustifiableHeight;
const Page *previousPage = vrv_cast<const Page *>(pages->GetPrevious(this, PAGE));
if (previousPage) {
const int systemCount = this->GetChildCount(SYSTEM);
const int previousSystemCount = previousPage->GetChildCount(SYSTEM);
if (systemCount < previousSystemCount) {
maxRatio *= (double)systemCount / (double)previousSystemCount;
}

const int maxSystemsPerPage = doc->GetOptions()->m_systemMaxPerPage.GetValue();
if ((childSystems <= 2) || (childSystems < maxSystemsPerPage)) {
m_justificationSum = previousJustificationSum;
}
}
else {
const int stavesPerSystem = m_drawingScoreDef.GetDescendantCount(STAFFDEF);
if (childSystems * stavesPerSystem < 8) return false;
}
}
const double ratio = (double)m_drawingJustifiableHeight / (double)doc->m_drawingPageHeight;
if (ratio > doc->GetOptions()->m_justificationMaxVertical.GetValue()) {
m_drawingJustifiableHeight
= doc->m_drawingPageHeight * doc->GetOptions()->m_justificationMaxVertical.GetValue();
}

return true;
m_drawingJustifiableHeight = std::min<int>(doc->m_drawingPageHeight * maxRatio, m_drawingJustifiableHeight);
}

void Page::LayOutPitchPos()
Expand Down

0 comments on commit 329d6db

Please sign in to comment.