diff --git a/include/vrv/page.h b/include/vrv/page.h index f1751100c99..6ef18fe2850 100644 --- a/include/vrv/page.h +++ b/include/vrv/page.h @@ -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: diff --git a/src/options.cpp b/src/options.cpp index a7e4b91058f..395e53b47cd 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -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"); diff --git a/src/page.cpp b/src/page.cpp index a5de8172a24..020baa87e82 100644 --- a/src/page.cpp +++ b/src/page.cpp @@ -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); @@ -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(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(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(doc->m_drawingPageHeight * maxRatio, m_drawingJustifiableHeight); } void Page::LayOutPitchPos()