@@ -159,34 +159,27 @@ void PageLayout::collectPage(LayoutContext& ctx)
159159 //
160160 // calculate distance to previous system
161161 //
162- double distance;
162+ double distance = 0.0 ;
163163 if (ctx.state ().prevSystem ()) {
164164 distance = SystemLayout::minDistance (ctx.state ().prevSystem (), ctx.state ().curSystem (), ctx);
165165 } else {
166166 // this is the first system on page
167167 if (ctx.state ().curSystem ()->vbox ()) {
168168 // if the header exists and there is a frame, move the frame downwards
169169 // to avoid collisions
170- distance = headerExtension ? headerExtension + headerFooterPadding : 0.0 ;
170+ if (!ctx.conf ().styleB (Sid::alignSystemToMarginVertically)) {
171+ distance = headerExtension ? headerExtension + headerFooterPadding : 0.0 ;
172+ }
171173 } else {
172174 distance = ctx.conf ().styleMM (Sid::staffUpperBorder);
173- bool fixedDistance = false ;
174175 for (MeasureBase* mb : ctx.mutState ().curSystem ()->measures ()) {
175176 if (mb->isMeasure ()) {
176- Measure* m = toMeasure (mb);
177- Spacer* sp = m->vspacerUp (0 );
178- if (sp) {
179- if (sp->spacerType () == SpacerType::FIXED) {
180- distance = sp->absoluteGap ();
181- fixedDistance = true ;
182- break ;
183- } else {
184- distance = std::max (distance, sp->absoluteGap ());
185- }
177+ if (Spacer* sp = toMeasure (mb)->vspacerUp (0 )) {
178+ distance = std::max (distance, sp->absoluteGap ());
186179 }
187180 }
188181 }
189- if (!fixedDistance ) {
182+ if (!ctx. conf (). styleB (Sid::alignSystemToMarginVertically) ) {
190183 double top = ctx.state ().curSystem ()->minTop ();
191184 // ensure it doesn't collide with header
192185 if (headerExtension > 0.0 ) {
@@ -247,24 +240,33 @@ void PageLayout::collectPage(LayoutContext& ctx)
247240 dist += footerExtension;
248241 }
249242 } else if (!ctx.state ().prevSystem ()->hasFixedDownDistance ()) {
250- double margin = std::max (ctx.state ().curSystem ()->minBottom (), ctx.state ().curSystem ()->spacerDistance (false ));
251- // ensure it doesn't collide with footer
252- if (footerExtension > 0 ) {
253- margin += footerExtension + headerFooterPadding;
243+ if (ctx.conf ().styleB (Sid::alignSystemToMarginVertically)) {
244+ dist += std::max (ctx.state ().curSystem ()->spacerDistance (false ), slb);
245+ } else {
246+ double margin = std::max (ctx.state ().curSystem ()->minBottom (), ctx.state ().curSystem ()->spacerDistance (false ));
247+ // ensure it doesn't collide with footer
248+ if (footerExtension > 0 ) {
249+ margin += footerExtension + headerFooterPadding;
250+ }
251+ dist += std::max (margin, slb);
254252 }
255- dist += std::max (margin, slb);
256253 }
257254 isPageBreak = (y + dist) >= endY && breakPages;
258255 }
259256 if (isPageBreak) {
260- double dist = std::max (ctx.state ().prevSystem ()->minBottom (), ctx.state ().prevSystem ()->spacerDistance (false ));
261- double footerPadding = 0.0 ;
262- // ensure it doesn't collide with footer
263- if (footerExtension > 0 ) {
264- footerPadding = footerExtension + headerFooterPadding;
265- dist += footerPadding;
257+ double dist = 0.0 ;
258+ if (ctx.conf ().styleB (Sid::alignSystemToMarginVertically)) {
259+ dist = std::max (ctx.state ().curSystem ()->spacerDistance (false ), slb);
260+ } else {
261+ dist = std::max (ctx.state ().prevSystem ()->minBottom (), ctx.state ().prevSystem ()->spacerDistance (false ));
262+ double footerPadding = 0.0 ;
263+ // ensure it doesn't collide with footer
264+ if (footerExtension > 0 ) {
265+ footerPadding = footerExtension + headerFooterPadding;
266+ dist += footerPadding;
267+ }
268+ dist = std::max (dist, slb);
266269 }
267- dist = std::max (dist, slb);
268270 layoutPage (ctx, page, endY - (y + dist), footerPadding);
269271 // if we collected a system we cannot fit onto this page,
270272 // we need to collect next page in order to correctly set system positions
0 commit comments