@@ -1317,7 +1317,7 @@ static void handleSpannerStop(SLine* cur_sp, int track2, const Fraction& tick, M
13171317// ---------------------------------------------------------
13181318
13191319MusicXMLParserPass2::MusicXMLParserPass2 (Score* score, MusicXMLParserPass1& pass1, MxmlLogger* logger)
1320- : _divs(0 ), _score(score), _pass1(pass1), _logger(logger)
1320+ : _divs(0 ), _score(score), _pass1(pass1), _logger(logger), _hasInferredHeaderText( false )
13211321 {
13221322 // nothing
13231323 }
@@ -1460,6 +1460,48 @@ static void cleanFretDiagrams(Measure* measure)
14601460 }
14611461 }
14621462 }
1463+
1464+ // ---------------------------------------------------------
1465+ // reformatHeaderVBox
1466+ // ---------------------------------------------------------
1467+ /* *
1468+ Due to inconsistencies with spacing and inferred text,
1469+ the header VBox frequently has collisions. This cleans
1470+ those (as a temporary fix for a more robust collision-prevention
1471+ system in Boxes).
1472+ */
1473+
1474+ static void reformatHeaderVBox (MeasureBase* mb)
1475+ {
1476+ if (!mb->isVBox ())
1477+ return ;
1478+
1479+ VBox* headerVBox = toVBox (mb);
1480+ Score* score = mb->score ();
1481+ qreal totalHeight = 0 ;
1482+ qreal offsetHeight = 0 ;
1483+ qreal verticalPadding = score->styleS (Sid::minVerticalDistance).val () * score->spatium ();
1484+
1485+ for (auto e : headerVBox->el ()) {
1486+ if (!e->isText ())
1487+ continue ;
1488+ Text* t = toText (e);
1489+ t->layout ();
1490+
1491+ totalHeight += t->height ();
1492+ if (Align (t->align () & Align::VMASK) == Align::TOP) {
1493+ totalHeight += verticalPadding;
1494+ t->setOffset (t->offset ().x (), offsetHeight);
1495+ t->setPropertyFlags (Pid::OFFSET, PropertyFlags::UNSTYLED);
1496+ offsetHeight += t->height ();
1497+ offsetHeight += verticalPadding;
1498+ }
1499+ }
1500+
1501+ headerVBox->setBoxHeight (Spatium (totalHeight / score->spatium ()));
1502+ headerVBox->setPropertyFlags (Pid::BOX_HEIGHT, PropertyFlags::UNSTYLED);
1503+ }
1504+
14631505// ---------------------------------------------------------
14641506// initPartState
14651507// ---------------------------------------------------------
@@ -1856,6 +1898,8 @@ void MusicXMLParserPass2::scorePartwise()
18561898 _score->connectArpeggios ();
18571899 _score->fixupLaissezVibrer ();
18581900 cleanFretDiagrams (_score->firstMeasure ());
1901+ if (_hasInferredHeaderText)
1902+ reformatHeaderVBox (_score->measures ()->first ());
18591903 cleanUpLayoutBreaks (_score, _logger);
18601904 }
18611905
@@ -2878,12 +2922,15 @@ void MusicXMLParserDirection::direction(const QString& partId,
28782922 return ;
28792923 else if (isLikelyCredit (tick)) {
28802924 Text* inferredText = addTextToHeader (Tid::COMPOSER);
2881- if (inferredText)
2925+ if (inferredText) {
2926+ _pass2.setHasInferredHeaderText (true );
28822927 hideRedundantHeaderText (inferredText, {" lyricist" , " composer" , " poet" });
2928+ }
28832929 }
28842930 else if (isLikelySource (tick)) {
28852931 Text* inferredText = addTextToHeader (Tid::SUBTITLE);
28862932 if (inferredText) {
2933+ _pass2.setHasInferredHeaderText (true );
28872934 if (_score->metaTag (" source" ).isEmpty ())
28882935 _score->setMetaTag (" source" , inferredText->plainText ());
28892936 hideRedundantHeaderText (inferredText, {" source" });
0 commit comments