-
Notifications
You must be signed in to change notification settings - Fork 3.1k
XML fixes #29197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
XML fixes #29197
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
39a5c13
Only apply word-font size when config option is off
miiizen a5587d1
Remove duplicate hbox at codas
miiizen d0fed87
Resize title box to avoid collisions
miiizen a2bf9db
Fix import of staff scaling & line distance
miiizen 35adb8e
Don't apply offsets to credit text
miiizen 7abc28b
Ignore "pedal" chords when importing xml
miiizen ad751af
Fix scaling copyright text
miiizen 4b45e5f
Fix tests
miiizen 3724a8a
Update staff-size in xml export
miiizen 0a3266b
Don't apply vbox adjustment when testing
miiizen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -762,22 +762,20 @@ static void scaleTitle(Score* score, Text* text); | |
| Also sets Align and Yoff. | ||
| */ | ||
|
|
||
| static void addText2(VBox* vbx, Score* score, const String& strTxt, const TextStyleType stl, const Align align, const double yoffs) | ||
| static void addText2(VBox* vbx, Score* score, const String& strTxt, const TextStyleType stl, const Align align) | ||
| { | ||
| if (stl != TextStyleType::COMPOSER && overrideTextStyleForComposer(strTxt)) { | ||
| // HACK: in some Dolet 8 files the composer is written as a subtitle, which leads to stupid formatting. | ||
| // This overrides the formatting and introduces proper composer text | ||
| Text* text = Factory::createText(vbx, TextStyleType::COMPOSER); | ||
| text->setXmlText(strTxt.trimmed()); | ||
| text->setOffset(muse::PointF(0.0, yoffs)); | ||
| text->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED); | ||
| vbx->add(text); | ||
| } else if (!strTxt.isEmpty()) { | ||
| Text* text = Factory::createText(vbx, stl); | ||
| text->setXmlText(strTxt.trimmed()); | ||
| text->setAlign(align); | ||
| text->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED); | ||
| text->setOffset(muse::PointF(0.0, yoffs)); | ||
| text->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED); | ||
| vbx->add(text); | ||
| if (stl == TextStyleType::TITLE) { | ||
|
|
@@ -994,6 +992,37 @@ static void inferFromTitle(String& title, String& inferredSubtitle, String& infe | |
| inferredCredits = creditLines.join(u"\n"); | ||
| } | ||
|
|
||
| static void resizeTitleBox(VBox* vbox) | ||
| { | ||
| double calculatedVBoxHeight = 0; | ||
| ElementList elist = vbox->el(); | ||
| Score* score = vbox->score(); | ||
| for (EngravingItem* e : elist) { | ||
| score->renderer()->layoutItem(e); | ||
| } | ||
|
|
||
| double padding = vbox->spatium(); | ||
|
|
||
| for (EngravingItem* e : elist) { | ||
| if (e->isText()) { | ||
| Text* txt = toText(e); | ||
| Text::LayoutData* txtLD = txt->mutldata(); | ||
|
|
||
| LD_CONDITION(txtLD->isSetBbox()); | ||
|
|
||
| RectF bbox = txtLD->bbox(); | ||
| bbox.moveTop(0.0); | ||
| txtLD->setBbox(bbox); | ||
| calculatedVBoxHeight += txtLD->bbox().height() + padding; | ||
| } | ||
| } | ||
|
|
||
| double heightInSp = calculatedVBoxHeight / vbox->spatium(); | ||
| if (heightInSp > vbox->propertyDefault(Pid::BOX_HEIGHT).toDouble()) { | ||
| vbox->undoChangeProperty(Pid::BOX_HEIGHT, heightInSp); | ||
| } | ||
| } | ||
|
|
||
| //--------------------------------------------------------- | ||
| // addCreditWords | ||
| //--------------------------------------------------------- | ||
|
|
@@ -1037,12 +1066,11 @@ static VBox* addCreditWords(Score* score, const CreditWordsList& crWords, const | |
| if (mustAddWordToVbox(w->type)) { | ||
| const TextStyleType tid = top ? tidForCreditWords(w, words, pageSize.width()) : TextStyleType::DEFAULT; | ||
| const Align align = alignForCreditWords(w, pageSize.width(), tid); | ||
| double yoffs = tid == TextStyleType::COMPOSER ? 0.0 : (maxy - w->defaultY) * score->style().spatium() / 10; | ||
| if (!vbox) { | ||
| Fraction vBoxTick = top ? Fraction(0, 1) : tick; | ||
| vbox = MusicXmlParserPass1::createAndAddVBoxForCreditWords(score, vBoxTick); | ||
| } | ||
| addText2(vbox, score, w->words, tid, align, yoffs); | ||
| addText2(vbox, score, w->words, tid, align); | ||
| } else if (w->type == u"rights" && score->metaTag(u"copyright").empty()) { | ||
| // Add rights to footer, not a vbox | ||
| static const std::regex tagRe("(<.*?>)"); | ||
|
|
@@ -1052,6 +1080,11 @@ static VBox* addCreditWords(Score* score, const CreditWordsList& crWords, const | |
| } | ||
| } | ||
|
|
||
| if (vbox && !MScore::testMode) { | ||
| // Correct size | ||
| resizeTitleBox(vbox); | ||
| } | ||
|
|
||
| return vbox; | ||
| } | ||
|
|
||
|
|
@@ -1799,6 +1832,7 @@ static void updateStyles(Score* score, | |
| // The MusicXML specification does not specify to which kinds of text | ||
| // the word-font setting applies. Setting all sizes to the size specified | ||
| // gives bad results, so a selection is made: | ||
| // Only apply word-font style when "Apply default typeface" is unchecked | ||
| // exclude lyrics odd and even lines (handled separately), | ||
| // Roman numeral analysis and harp pedal diagrams (special case, leave untouched) | ||
| // and text types used in the title frame | ||
|
|
@@ -1810,7 +1844,7 @@ static void updateStyles(Score* score, | |
| continue; | ||
| } | ||
|
|
||
| bool needUseDefaultSize = tid == TextStyleType::HARMONY_ROMAN | ||
| bool needUseDefaultSize = configuration()->needUseDefaultFont() || tid == TextStyleType::HARMONY_ROMAN | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using `this? bool needUseDefaultSize = needUseDefaultFont || tid == TextStyleType::HARMONY_ROMAN |
||
| || tid == TextStyleType::HAMMER_ON_PULL_OFF | ||
| || isTitleFrameStyle(tid) | ||
| || isHarpPedalStyle(tid); | ||
|
|
@@ -1866,9 +1900,14 @@ static double scaleText(const String& str, const Sid fontFaceSid, const double f | |
| const double pagePrintableWidth = style.styleV(Sid::pagePrintableWidth).value<double>() * DPI; | ||
| const double pageWidth = style.styleV(Sid::pageWidth).value<double>() * DPI; | ||
| const double pageHeight = style.styleV(Sid::pageHeight).value<double>() * DPI; | ||
| const double textWidth = fm.boundingRect(RectF(0, 0, pageWidth, pageHeight), TextShowMnemonic, str).width(); | ||
|
|
||
| return pagePrintableWidth / textWidth; | ||
| double longestLine = 0.0; | ||
| for (const String& line : str.split(u"\n")) { | ||
| const double textWidth = fm.boundingRect(RectF(0, 0, pageWidth, pageHeight), TextShowMnemonic, line).width(); | ||
| longestLine = std::max(longestLine, textWidth); | ||
| } | ||
|
|
||
| return pagePrintableWidth / longestLine; | ||
| } | ||
|
|
||
| static void scaleCopyrightText(Score* score) | ||
|
|
@@ -1878,12 +1917,12 @@ static void scaleCopyrightText(Score* score) | |
| return; | ||
| } | ||
|
|
||
| const double fontSize = score->style().styleV(Sid::footerFontSize).value<double>(); | ||
| const double sizeRatio = scaleText(copyright, Sid::footerFontFace, fontSize, score); | ||
| const double fontSize = score->style().styleV(Sid::copyrightFontSize).value<double>(); | ||
| const double sizeRatio = scaleText(copyright, Sid::copyrightFontFace, fontSize, score); | ||
|
|
||
| if (sizeRatio < 1) { | ||
| const double newSize = floor(fontSize * sizeRatio * 10) / 10; | ||
| score->style().set(Sid::footerFontSize, newSize); | ||
| score->style().set(Sid::copyrightFontSize, newSize); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3163,8 +3163,10 @@ void MusicXmlParserPass2::staffDetails(const String& partId, Measure* measure) | |
| } else if (m_e.name() == "staff-tuning") { | ||
| staffTuning(&stringData); | ||
| } else if (m_e.name() == "staff-size") { | ||
| const double scale = m_e.doubleAttribute("scale", 1.0); | ||
| const double val = m_e.readDouble() / 100; | ||
| m_score->staff(staffIdx)->setProperty(Pid::MAG, val); | ||
| m_score->staff(staffIdx)->setProperty(Pid::MAG, scale); | ||
| m_score->staff(staffIdx)->setProperty(Pid::LINE_DISTANCE, val); | ||
|
Comment on lines
+3168
to
+3169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this then also be adjusted in the export? |
||
| } else { | ||
| skipLogCurrElem(); | ||
| } | ||
|
|
@@ -4699,7 +4701,9 @@ void MusicXmlParserDirection::handleRepeats(Measure* measure, const Fraction tic | |
| measure = measure->nextMeasure(); | ||
| } | ||
| // Temporary solution to indent codas - add a horizontal frame at start of system or midway through | ||
| if (tb->isMarker() && toMarker(tb)->markerType() == MarkerType::CODA) { | ||
| MeasureBase* prevMeasureBase = measure->prev(); | ||
| bool hbox = prevMeasureBase && prevMeasureBase->isHBox(); | ||
| if (tb->isMarker() && toMarker(tb)->markerType() == MarkerType::CODA && !hbox) { | ||
| MeasureBase* gap = m_score->insertBox(ElementType::HBOX, measure); | ||
| toHBox(gap)->setBoxWidth(Spatium(10)); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not this?
double heightInSp = calculatedVBoxHeight / padding;