-
Notifications
You must be signed in to change notification settings - Fork 3k
Header/footer fixes (#28875 and #25245) #28890
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
Header/footer fixes (#28875 and #25245) #28890
Conversation
mathesoncalum
left a comment
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.
Thank you very much for this @Thomas-Ganter! This part of the code is incredibly fragile but I think your changes will work. There are a couple of cleanup points I'd like to address as well because it seems the current implementation of style was rendered somewhat redundant after #24442...
The following lines can be deleted because replaceTextMacros/formatForMacro should (hopefully) handle the unique formatting of copyright and page numbers:
MuseScore/src/engraving/dom/page.cpp
Lines 99 to 109 in 6d16859
| //! NOTE: Keep in sync with replaceTextMacros | |
| std::wregex copyrightSearch(LR"(\$[cC])"); | |
| std::wregex pageNumberSearch(LR"(\$[pPnN])"); | |
| bool containsCopyright = s.contains(copyrightSearch); | |
| bool containsPageNumber = s.contains(pageNumberSearch); | |
| // Slight hack - we'll use copyright/page number styling if the string contains copyright or page number | |
| // macros (hack because any non-copyright text in the same block will also adopt these style values) | |
| TextStyleType style = containsCopyright ? TextStyleType::COPYRIGHT | |
| : (containsPageNumber ? TextStyleType::PAGE_NUMBER | |
| : (isHeader ? TextStyleType::HEADER : TextStyleType::FOOTER)); |
Then, at the second formatting pass:
MuseScore/src/engraving/dom/page.cpp
Lines 166 to 169 in fa0f99c
| // second formatting pass - replace macros and apply their unique formatting (if any) | |
| std::vector<TextBlock> newBlocks; | |
| for (const TextBlock& oldBlock : text->ldata()->blocks) { | |
| Text* dummyText = Factory::createText(score()->dummy(), style); |
Declare style like this:
// second formatting pass - replace macros and apply their unique formatting (if any)
const TextStyleType style = isHeader ? TextStyleType::HEADER : TextStyleType::FOOTER;
std::vector<TextBlock> newBlocks;
for (const TextBlock& oldBlock : text->ldata()->blocks) {
Text* dummyText = Factory::createText(score()->dummy(), style);
Hopefully that all works. Once we're done we'll need to test that copyright and page number formatting still works as expected, alongside custom XML formatting. If you have any questions let me know!
|
Hi @mathesoncalum , first time I even heard about custom XML formatting was reading it in the code. A brief manual search came back inconclusive. Can you give me a pointer then I'll see that it won't break doing these changes. |
|
... and yes, I figured the code being fragile and somewhat redundant, but I wanted to make the minimum change possible without a clearer understanding of things like custom XML formatting ... Still, this formatting issue was so annoying to my sense of beautiful sheet music I had to do something. "How hard can it be, I was pretty good in C forty years ago ..." I thought. 😁 |
Sure - from what I can tell it's not such a well known feature but it allows you to use XML formatting tags in the header and footer fields. In this example I put Playing around with it myself I didn't notice any regressions after applying your changes. There are some known bugs in this area though - see #25245 (something else on my todo list)... |
|
Uah -- I immediately can think of 100+ things that can go wrong allowing arbitrary XML in text fields like this … beginning with what if I actually want xml-like tags in head/ footer fields? But as I already have embarked on making some modifications here I'll have a look at that as well. Only your |
|
Sorry, The Coding Style script does not run on my Mac ... Are there steps missing (or did I miss a step) in the "set up your environment" documentation? |
|
@Thomas-Ganter the secret is that you specifically need Uncrustify version 0.74, which you will have to compile yourself. If that still doesn't work, an easier way to fix the code style might be running Regarding the |
|
There still were issues with text after a (the remaining empty custom XML formatting tags issue depicted above I will also fix) |
|
@Thomas-Ganter if you think you have a fix (or improvement) ready for #25245 then absolutely feel free to include it in this PR. Quick aside - it looks like there was maybe some problem rebasing this PR. It now includes a bunch of extra commits. |
4014d32 to
d1399ce
Compare
mathesoncalum
left a comment
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.
Thanks @Thomas-Ganter! A few requested changes for you...
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.
Almost there @Thomas-Ganter - left a couple of tiny tweaks for you and a tip about the unit tests.
Once you're done could you squash your commits (ideally into 2 commits - one for #28875 and one for #28875) and try to sign the CLA again?
Cheers!
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
4bcdeed to
76392a5
Compare
|
With all the changes and the tests fixed, the original intent is still fulfilled: Header (and footer) formatting works again. Squashing into separate commits is not easily possible, as the fixes are intertwined. Tried to separate them out as much as possible. @mathesoncalum hope everything is hunky-dory now. |
mathesoncalum
left a comment
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.
Hunky-dory indeed 😁
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
0d8788d to
9f241ed
Compare
This comment was marked as outdated.
This comment was marked as outdated.
9f241ed to
4b8b91f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
* Rebased to latest upstream/master as there was some mixup. * Cleanup of debug #pragmas * Added safeguarding against invalid font size in text.
4b8b91f to
1432b81
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
OK, I'm able to demonstrate that the deviation is due to the fix for #27519 : Now ... adding Text into the footers gives: I'll add a fix ontop of #27519 insofar that it will only include empty lines if the empty line is not the only line in header/footer. |
Combined fix for issue musescore#27519 that was causing problems. This consolidates the previous two separate commits into one.
1432b81 to
ef1dd09
Compare
|
@mathesoncalum fixing the fix fixed the tests |
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.
Nicely done @Thomas-Ganter - cheers!
@zacjansheski ready for re-testing
| String fontFamily() const { return m_fontFamily; } | ||
| void setValign(VerticalAlignment val) { m_valign = val; } | ||
| void setFontSize(double val) { m_fontSize = val; } | ||
| void setFontSize(double val) { m_fontSize = muse::RealIsEqualOrLess(val, 0.0) ? 1.0 : val; } // Font Size 0 will cause a crash |
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.
@Thomas-Ganter @mathesoncalum this check turned out to be problematic, see #29906. The problem is that we use a variable called UNDEFINED_FONT_SIZE which is equal to -1 (i.e. intentionally invalid) but this check means that we write a valid pt size instead. If this was covering a crash, we need to find a proper solution for it.







Resolves: #28875
Resolves: #25245
Headers and Footers were wrongly formatted because the Page Number and Copyright overrides were used as the default styles instead of the Header and Footer presets. These two changes fixes that.