Skip to content

Commit 793aa49

Browse files
committed
Encode line breaks as <br> tags for file saving
1 parent 42dd45f commit 793aa49

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

src/engraving/dom/textbase.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,32 @@ void TextBase::createBlocks(LayoutData* ldata) const
18151815
cursor.setRow(0);
18161816
cursor.setColumn(0);
18171817

1818+
auto insertNewBlock = [](LayoutData* ldata, TextCursor& cursor) {
1819+
if (ldata->rows() <= cursor.row()) {
1820+
ldata->blocks.push_back(TextBlock());
1821+
}
1822+
1823+
if (cursor.row() < ldata->rows()) {
1824+
if (ldata->blocks.at(cursor.row()).fragments().size() == 0) {
1825+
ldata->blocks[cursor.row()].insertEmptyFragmentIfNeeded(&cursor); // used to preserve the Font size of the line (font info is held in TextFragments, see PR #5881)
1826+
}
1827+
1828+
ldata->blocks[cursor.row()].setEol(true);
1829+
}
1830+
1831+
cursor.setRow(cursor.row() + 1);
1832+
cursor.setColumn(0);
1833+
if (ldata->rows() <= cursor.row()) {
1834+
ldata->blocks.push_back(TextBlock());
1835+
}
1836+
1837+
if (cursor.row() < ldata->rows()) {
1838+
if (ldata->blocks.at(cursor.row()).fragments().size() == 0) {
1839+
ldata->blocks[cursor.row()].insertEmptyFragmentIfNeeded(&cursor); // an empty fragment may be needed on either side of the newline
1840+
}
1841+
}
1842+
};
1843+
18181844
int state = 0;
18191845
String token;
18201846
String sym;
@@ -1829,29 +1855,7 @@ void TextBase::createBlocks(LayoutData* ldata) const
18291855
state = 2;
18301856
token.clear();
18311857
} else if (c == '\n') {
1832-
if (ldata->rows() <= cursor.row()) {
1833-
ldata->blocks.push_back(TextBlock());
1834-
}
1835-
1836-
if (cursor.row() < ldata->rows()) {
1837-
if (ldata->blocks.at(cursor.row()).fragments().size() == 0) {
1838-
ldata->blocks[cursor.row()].insertEmptyFragmentIfNeeded(&cursor); // used to preserve the Font size of the line (font info is held in TextFragments, see PR #5881)
1839-
}
1840-
1841-
ldata->blocks[cursor.row()].setEol(true);
1842-
}
1843-
1844-
cursor.setRow(cursor.row() + 1);
1845-
cursor.setColumn(0);
1846-
if (ldata->rows() <= cursor.row()) {
1847-
ldata->blocks.push_back(TextBlock());
1848-
}
1849-
1850-
if (cursor.row() < ldata->rows()) {
1851-
if (ldata->blocks.at(cursor.row()).fragments().size() == 0) {
1852-
ldata->blocks[cursor.row()].insertEmptyFragmentIfNeeded(&cursor); // an empty fragment may be needed on either side of the newline
1853-
}
1854-
}
1858+
insertNewBlock(ldata, cursor);
18551859
} else {
18561860
if (symState) {
18571861
sym += c;
@@ -1887,6 +1891,8 @@ void TextBase::createBlocks(LayoutData* ldata) const
18871891
} else {
18881892
LOGD("unknown symbol <%s>", muPrintable(sym));
18891893
}
1894+
} else if (token == "br") {
1895+
insertNewBlock(ldata, cursor);
18901896
}
18911897
} else {
18921898
token += c;
@@ -2256,7 +2262,7 @@ String TextBase::genText(const LayoutData* ldata) const
22562262
fmt = format;
22572263
}
22582264
if (block.eol()) {
2259-
text += Char::LineFeed;
2265+
text += String("<br></br>");
22602266
}
22612267
}
22622268
while (!xmlNesting.empty()) {
@@ -3725,7 +3731,7 @@ String TextBase::stripText(bool removeStyle, bool removeSize, bool removeFace) c
37253731
fmt = format;
37263732
}
37273733
if (block.eol()) {
3728-
_txt += Char::LineFeed;
3734+
_txt += String(u"<br></br>");
37293735
}
37303736
}
37313737
while (!xmlNesting.empty()) {

vtest/scores/newline-1.mscz

23.6 KB
Binary file not shown.

vtest/scores/newline-2.mscz

20.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)