Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/rism-digital/verovio int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
lpugin committed Oct 11, 2024
2 parents 6e6bd93 + 0d36ed9 commit dee17a9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion include/vrv/fraction.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: faction.h
// Name: fraction.h
// Author: Laurent Pugin
// Created: 2024
// Copyright (c) Authors and others. All rights reserved.
Expand Down
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 dee17a9

Please sign in to comment.