Skip to content

Commit

Permalink
Cast off based on available system drawing height
Browse files Browse the repository at this point in the history
  • Loading branch information
brdvd committed Oct 10, 2024
1 parent 355d15e commit acdc65d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
8 changes: 7 additions & 1 deletion include/vrv/castofffunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,20 @@ class CastOffPagesFunctor : public DocFunctor {
protected:
//
private:
//
/*
* Returns the available height for system drawing on the current page
*/
int GetAvailableDrawingHeight() const;

public:
//
private:
// The page we are taking the content from
Page *m_contentPage;
// The current page
Page *m_currentPage;
// Indicates whether the current page is the first
bool m_firstCastOffPage;
// The cumulated shift (m_drawingYRel of the first system of the current page)
int m_shift;
// The page heights
Expand Down
28 changes: 16 additions & 12 deletions src/castofffunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ CastOffPagesFunctor::CastOffPagesFunctor(Page *contentPage, Doc *doc, Page *curr
{
m_contentPage = contentPage;
m_currentPage = currentPage;
m_shift = 0;
m_firstCastOffPage = true;
m_shift = VRV_UNSET;
m_pageHeight = 0;
m_pgHeadHeight = 0;
m_pgFootHeight = 0;
Expand Down Expand Up @@ -341,19 +342,16 @@ FunctorCode CastOffPagesFunctor::VisitScore(Score *score)

FunctorCode CastOffPagesFunctor::VisitSystem(System *system)
{
int currentShift = m_shift;
// We use m_pageHeadHeight to check if we have passed the first page already
if (m_pgHeadHeight != VRV_UNSET) {
currentShift += m_pgHeadHeight + m_pgFootHeight;
}
else {
currentShift += m_pgHead2Height + m_pgFoot2Height;
// Check if this is the first system
if (m_shift == VRV_UNSET) {
m_shift = system->GetDrawingYRel();
}

const int systemMaxPerPage = m_doc->GetOptions()->m_systemMaxPerPage.GetValue();
const int systemChildCount = m_currentPage->GetChildCount(SYSTEM);
if ((systemMaxPerPage && (systemMaxPerPage == systemChildCount))
|| ((systemChildCount > 0) && (system->GetDrawingYRel() - system->GetHeight() - currentShift < 0))) {
|| ((systemChildCount > 0)
&& (m_shift - system->GetDrawingYRel() + system->GetHeight() > this->GetAvailableDrawingHeight()))) {
// If this is the last system in the list, it doesn't fit the page and it's a leftover system (has just one
// measure) => add the system content to the previous system
Object *nextSystem = m_contentPage->GetNext(system, SYSTEM);
Expand All @@ -367,11 +365,10 @@ FunctorCode CastOffPagesFunctor::VisitSystem(System *system)
}

m_currentPage = new Page();
// Use VRV_UNSET value as a flag
m_pgHeadHeight = VRV_UNSET;
assert(m_doc->GetPages());
m_doc->GetPages()->AddChild(m_currentPage);
m_shift = system->GetDrawingYRel() - m_pageHeight;
m_shift = system->GetDrawingYRel();
m_firstCastOffPage = false;
}

// First add all pending objects
Expand All @@ -391,6 +388,13 @@ FunctorCode CastOffPagesFunctor::VisitSystem(System *system)
return FUNCTOR_SIBLINGS;
}

int CastOffPagesFunctor::GetAvailableDrawingHeight() const
{
const int pageHeadAndFootHeight
= m_firstCastOffPage ? (m_pgHeadHeight + m_pgFootHeight) : (m_pgHead2Height + m_pgFoot2Height);
return m_pageHeight - pageHeadAndFootHeight;
}

//----------------------------------------------------------------------------
// CastOffEncodingFunctor
//----------------------------------------------------------------------------
Expand Down

0 comments on commit acdc65d

Please sign in to comment.